Skip to content

Commit c478514

Browse files
authored
Merge pull request #177 from kenmcgaugh/feature_custom_uri
Modifications to allow data_source plugins to handle custom URI's.
2 parents 5f2b423 + 4ef216f commit c478514

File tree

4 files changed

+95
-29
lines changed

4 files changed

+95
-29
lines changed

src/playlist/src/playlist_actor.cpp

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,47 @@ void blocking_loader(
185185
rp.deliver(result);
186186
}
187187

188+
void blocking_loader_other(
189+
blocking_actor *self,
190+
caf::typed_response_promise<std::vector<UuidActor>> rp,
191+
UuidActor dst,
192+
const caf::uri &path,
193+
const FrameRate &default_rate,
194+
const bool auto_gather,
195+
const caf::actor &session,
196+
const caf::actor &pm,
197+
const utility::Uuid &before) {
198+
199+
anon_mail(playlist::loading_media_atom_v, true).send(dst.actor());
200+
201+
self->mail(data_source::use_data_atom_v, path, default_rate, false)
202+
.request(pm, infinite)
203+
.receive(
204+
[=](const utility::UuidActorVector &uav) mutable {
205+
self->mail(playlist::add_media_atom_v, uav, before)
206+
.request(dst.actor(), infinite)
207+
.receive(
208+
[=](const bool) mutable {
209+
if (auto_gather) {
210+
for (const auto &i : uav) {
211+
anon_mail(media_hook::gather_media_sources_atom_v, i.actor(), default_rate)
212+
.send(session);
213+
}
214+
}
215+
anon_mail(loading_media_atom_v, false).send(dst.actor());
216+
rp.deliver(uav);
217+
},
218+
[=](error &err) mutable {
219+
anon_mail(loading_media_atom_v, false).send(dst.actor());
220+
rp.deliver(std::move(err));
221+
});
222+
},
223+
[=](error &err) mutable {
224+
anon_mail(loading_media_atom_v, false).send(dst.actor());
225+
rp.deliver(std::move(err));
226+
});
227+
}
228+
188229

189230
PlaylistActor::PlaylistActor(
190231
caf::actor_config &cfg, const utility::JsonStore &jsn, const caf::actor &session)
@@ -597,18 +638,37 @@ caf::message_handler PlaylistActor::message_handler() {
597638
const utility::FrameRate &rate,
598639
const utility::Uuid &uuid_before) -> result<std::vector<UuidActor>> {
599640
auto rp = make_response_promise<std::vector<UuidActor>>();
600-
spawn(
601-
blocking_loader,
602-
rp,
603-
UuidActor(base_.uuid(), actor_cast<caf::actor>(this)),
604-
path,
605-
recursive,
606-
rate,
607-
auto_gather_sources_,
608-
actor_cast<caf::actor>(session_),
609-
uuid_before);
610641

611642
mail(utility::event_atom_v, loading_media_atom_v, true).send(base_.event_group());
643+
644+
if (path.scheme() == "file" or
645+
path.scheme().find("http") == 0) {
646+
spawn(
647+
blocking_loader,
648+
rp,
649+
UuidActor(base_.uuid(), actor_cast<caf::actor>(this)),
650+
path,
651+
recursive,
652+
rate,
653+
auto_gather_sources_,
654+
actor_cast<caf::actor>(session_),
655+
uuid_before);
656+
657+
} else {
658+
// Unrecognised URI scheme, so see if one of the plugins can do something with it
659+
auto pm = system().registry().template get<caf::actor>(plugin_manager_registry);
660+
spawn(
661+
blocking_loader_other,
662+
rp,
663+
UuidActor(base_.uuid(), actor_cast<caf::actor>(this)),
664+
path,
665+
rate,
666+
auto_gather_sources_,
667+
actor_cast<caf::actor>(session_),
668+
pm,
669+
uuid_before);
670+
}
671+
612672
return rp;
613673
},
614674

src/timeline/src/timeline_actor.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,8 @@ void timeline_importer(
859859
}
860860

861861
// active_path maybe relative..
862-
if (not active_path.empty() and not caf::make_uri(active_path)) {
862+
const auto uri = caf::make_uri(active_path);
863+
if (not uri) {
863864
// not uri....
864865
// assume relative ?
865866
if (active_path[0] != '/') {
@@ -892,6 +893,22 @@ void timeline_importer(
892893
spdlog::warn("{} {}", __PRETTY_FUNCTION__, err.what());
893894
}
894895

896+
if (uri and uri->scheme() != "file" and
897+
not uri->scheme().starts_with("http")) {
898+
// unrecognized URI scheme, so send it to the data_source plugins
899+
auto pm = self->system().registry().template get<caf::actor>(plugin_manager_registry);
900+
caf::scoped_actor sys(self->system());
901+
auto plugin_media_tmp = request_receive<UuidActorVector>(
902+
*sys, pm, data_source::use_data_atom_v, *uri, timeline_rate, false);
903+
if (not plugin_media_tmp.empty()) {
904+
target_url_map[active_path] = plugin_media_tmp[0];
905+
if (not clip_metadata.is_null())
906+
anon_mail(json_store::set_json_atom_v, clip_metadata, "/metadata/timeline")
907+
.send(target_url_map[active_path].actor());
908+
continue;
909+
}
910+
}
911+
895912
// check we're not adding the same media twice.
896913
UuidActorVector sources;
897914

ui/qml/xstudio/windows/drag_drop/XsGlobalDragDropHandler.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ DropArea {
7272
keys: [
7373
"text/uri-list",
7474
"xstudio/media-ids",
75+
"text/plain",
7576
"application/x-dneg-ivy-entities-v1"
7677
]
7778

ui/qml/xstudio/windows/main_menu_bar/file_menu/XsFileFunctions.qml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,13 @@ Item {
321321

322322
function addMediaFromClipboard() {
323323
if(clipboard.text.length) {
324-
let ct = ""
325-
clipboard.text.split("\n").forEach(function (item, index) {
326-
// replace #'s
327-
// item.replace(/[#]+/, "*")
328-
ct = ct + "file://" + item + "\n"
329-
}
330-
)
331-
if(!sessionSelectionModel.currentIndex.valid) {
332-
var index = theSessionData.createPlaylist("Add Media")
333-
Future.promise(index.model.handleDropFuture(Qt.CopyAction, {"text/uri-list": ct}, index)).then(function(quuids){
334-
mediaSelectionModel.selectFirstNewMedia(index, quuids)
335-
})
336-
}
337-
else {
338-
let index = sessionSelectionModel.currentIndex
339-
Future.promise(index.model.handleDropFuture(Qt.CopyAction, {"text/uri-list": ct}, index)).then(function(quuids){
340-
mediaSelectionModel.selectFirstNewMedia(index, quuids)
341-
})
324+
var index = sessionSelectionModel.currentIndex
325+
if (!index.valid) {
326+
index = theSessionData.createPlaylist("Add Media")
342327
}
328+
Future.promise(index.model.handleDropFuture(Qt.CopyAction, {"text/plain": clipboard.text}, index)).then(function(quuids){
329+
mediaSelectionModel.selectFirstNewMedia(index, quuids)
330+
})
343331
}
344332
}
345333

0 commit comments

Comments
 (0)