Loading...
Searching...
No Matches
ProcessDropHandler.hpp
1#pragma once
2#include <Process/ProcessMimeSerialization.hpp>
3#include <Process/TimeValue.hpp>
4
5#include <score/command/AggregateCommand.hpp>
6#include <score/command/Dispatchers/RuntimeDispatcher.hpp>
7#include <score/plugins/Interface.hpp>
8#include <score/plugins/InterfaceList.hpp>
9#include <score/tools/FilePath.hpp>
10
11#include <ossia/detail/hash_map.hpp>
12
13#include <QByteArray>
14#include <QMimeData>
15
16#include <score_lib_process_export.h>
17
18#include <string>
19#include <vector>
20
21namespace Process
22{
23class ProcessModel;
24
25class SCORE_LIB_PROCESS_EXPORT ProcessDropHandler : public score::InterfaceBase
26{
27 SCORE_INTERFACE(ProcessDropHandler, "e0908e4a-9e88-4029-9a61-7658cc695152")
28public:
30 {
31 ProcessData creation;
32 std::optional<TimeVal> duration;
33 std::function<void(Process::ProcessModel&, score::Dispatcher&)> setup;
34 };
35
37 {
38 score::FilePath filename;
39 QByteArray data;
40 };
41
43 ~ProcessDropHandler() override;
44
45 void getCustomDrops(
46 std::vector<ProcessDrop>& drops, const QMimeData& mime,
47 const score::DocumentContext& ctx) const noexcept;
48
49 void getMimeDrops(
50 std::vector<ProcessDrop>& drops, const QMimeData& mime, const QString& fmt,
51 const score::DocumentContext& ctx) const noexcept;
52
53 void getFileDrops(
54 std::vector<ProcessDrop>& drops, const QMimeData& mime,
55 const score::FilePath& path, const score::DocumentContext& ctx) const noexcept;
56
57 virtual QSet<QString> mimeTypes() const noexcept;
58 virtual QSet<QString> fileExtensions() const noexcept;
59
60protected:
61 virtual void dropCustom(
62 std::vector<ProcessDrop>& drops, const QMimeData& mime,
63 const score::DocumentContext& ctx) const;
64
65 virtual void dropPath(
66 std::vector<ProcessDrop>& drops, const score::FilePath& path,
67 const score::DocumentContext& ctx) const noexcept;
68
69 virtual void dropData(
70 std::vector<ProcessDrop>& drops, const DroppedFile& data,
71 const score::DocumentContext& ctx) const noexcept;
72};
73
74class SCORE_LIB_PROCESS_EXPORT ProcessDropHandlerList final
75 : public score::InterfaceList<ProcessDropHandler>
76{
77public:
78 ~ProcessDropHandlerList() override;
79
80 std::vector<ProcessDropHandler::ProcessDrop>
81 getDrop(const QMimeData& mime, const score::DocumentContext& ctx) const noexcept;
82
83 static std::optional<TimeVal>
84 getMaxDuration(const std::vector<ProcessDropHandler::ProcessDrop>&);
85
86private:
87 void initCaches() const;
88 mutable ossia::hash_map<std::string, ProcessDropHandler*> m_perMimeTypes{};
89 // Several handlers legitimately claim one extension -- four shader families
90 // share ".fs" and tell each other apart by reading the file header -- so each
91 // of them gets its turn and the ones the file does not belong to say nothing.
92 mutable ossia::hash_map<std::string, std::vector<ProcessDropHandler*>>
93 m_perFileExtension{};
94 mutable std::size_t m_lastCacheSize{};
95};
96}
Definition ProcessDropHandler.hpp:26
Definition ProcessDropHandler.hpp:76
The Process class.
Definition score-lib-process/Process/Process.hpp:80
Base class for plug-in interfaces.
Definition Interface.hpp:52
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
Base toolkit upon which the software is built.
Definition Application.cpp:83
STL namespace.
Definition ProcessMimeSerialization.hpp:34
Definition ProcessDropHandler.hpp:37
Definition ProcessDropHandler.hpp:30
Definition RuntimeDispatcher.hpp:7
Definition DocumentContext.hpp:18
Definition FilePath.hpp:47