/* 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 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; try{ Portal.get_instance(); send_to_installed = true; } catch (Error error) { send_to_installed = false; } } 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() { // FIXME: Check if portal is available return send_to_installed; } public async void files_send_to(File[] files) { if (files.length == 0) return; var file_names = new StringBuilder(); var files_builder = new VariantBuilder (new VariantType ("ah")); var file_descriptors = new UnixFDList (); for (int i=0; i (str_hash, str_equal); options.insert ("subject", _("Send files per Mail: ") + file_names.str); options.insert ("attachment_fds", files_builder.end()); options.insert ("addresses", new Variant ("as", null)); AppWindow.get_instance().set_busy_cursor(); try{ var response = yield Portal.get_instance().compose_email (options, file_descriptors); if (response == null){ throw new DBusError.FAILED("Did not get response"); } } catch (Error e){ AppWindow.error_message(_("Unable to send file %s, %s").printf( file_names.str, e.message)); } AppWindow.get_instance().set_normal_cursor(); } 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