/* Copyright 2016 Software Freedom Conservancy Inc. * * This software is licensed under the GNU Lesser General Public License * (version 2.1 or later). See the COPYING file in this distribution. */ namespace DesktopIntegration { private const string SENDTO_EXEC = "nautilus-sendto"; private const string DESKTOP_SLIDESHOW_XML_FILENAME = "wallpaper.xml"; private int init_count = 0; private bool send_to_installed = false; private ExporterUI send_to_exporter = null; private ExporterUI desktop_slideshow_exporter = null; private double desktop_slideshow_transition = 0.0; private double desktop_slideshow_duration = 0.0; private bool set_desktop_background = false; private bool set_screensaver = false; public void init() { if (init_count++ != 0) return; send_to_installed = Environment.find_program_in_path(SENDTO_EXEC) != null; } public void terminate() { if (--init_count == 0) return; } public AppInfo? get_default_app_for_mime_types(string[] mime_types, Gee.ArrayList preferred_apps) { SortedList external_apps = get_apps_for_mime_types(mime_types); foreach (string preferred_app in preferred_apps) { foreach (AppInfo external_app in external_apps) { if (external_app.get_name().contains(preferred_app)) return external_app; } } return null; } // compare the app names, case insensitive public static int64 app_info_comparator(void *a, void *b) { return ((AppInfo) a).get_name().down().collate(((AppInfo) b).get_name().down()); } public SortedList get_apps_for_mime_types(string[] mime_types) { SortedList external_apps = new SortedList(app_info_comparator); if (mime_types.length == 0) return external_apps; // 3 loops because SortedList.contains() wasn't paying nicely with AppInfo, // probably because it has a special equality function foreach (string mime_type in mime_types) { string content_type = ContentType.from_mime_type(mime_type); if (content_type == null) break; foreach (AppInfo external_app in AppInfo.get_all_for_type(content_type)) { bool already_contains = false; foreach (AppInfo app in external_apps) { if (app.get_name() == external_app.get_name()) { already_contains = true; break; } } // dont add Shotwell to app list if (!already_contains && !external_app.get_name().contains(Resources.APP_TITLE)) external_apps.add(external_app); } } return external_apps; } public string? get_app_open_command(AppInfo app_info) { string? str = app_info.get_commandline(); return str != null ? str : app_info.get_executable(); } public bool is_send_to_installed() { return send_to_installed; } public void files_send_to(File[] files) { if (files.length == 0) return; string[] argv = new string[files.length + 1]; argv[0] = SENDTO_EXEC; for (int ctr = 0; ctr < files.length; ctr++) argv[ctr + 1] = files[ctr].get_path(); try { AppWindow.get_instance().set_busy_cursor(); Pid child_pid; Process.spawn_async( "/", argv, null, // environment SpawnFlags.SEARCH_PATH, null, // child setup out child_pid); AppWindow.get_instance().set_normal_cursor(); } catch (Error err) { AppWindow.get_instance().set_normal_cursor(); AppWindow.error_message(_("Unable to launch Nautilus Send-To: %s").printf(err.message)); } } public void send_to(Gee.Collection media) { if (media.size == 0 || send_to_exporter != null) return; ExportDialog dialog = new ExportDialog(_("Send To")); // determine the mix of media in the export collection -- if it contains only // videos then we can use the Video.export_many( ) fast path and not have to // worry about ExportFormatParameters or the Export... dialog if (MediaSourceCollection.has_video(media) && !MediaSourceCollection.has_photo(media)) { send_to_exporter = Video.export_many((Gee.Collection