/** * fm_choose_app_for_mime_type * @parent: (allow-none): a parent window * @mime_type: (allow-none): MIME type for list creation * @can_set_default: %TRUE if widget can set selected item as default for @mime_type * * Creates a dialog to choose application for @mime_type, lets user to * choose then returns the chosen application. * * If user creates custom application and @mime_type isn't %NULL then this * custom application will be added to list of supporting the @mime_type. * Otherwise that custom application file will be deleted after usage. * * Returns: user choise. * * Since: 0.1.0 */ GAppInfo* fm_choose_app_for_mime_type(GtkWindow* parent, FmMimeType* mime_type, gboolean can_set_default) { GAppInfo* app = NULL; GtkDialog* dlg = fm_app_chooser_dlg_new(mime_type, can_set_default); if(parent) gtk_window_set_transient_for(GTK_WINDOW(dlg), parent); if(gtk_dialog_run(dlg) == GTK_RESPONSE_OK) { gboolean set_default; app = fm_app_chooser_dlg_dup_selected_app(dlg, &set_default); if(app && mime_type && fm_mime_type_get_type(mime_type) && g_app_info_get_name(app)[0]) /* don't add empty name */ { GError* err = NULL; /* add this app to the mime-type */ #if GLIB_CHECK_VERSION(2, 27, 6) if(!g_app_info_set_as_last_used_for_type(app, #else if(!g_app_info_add_supports_type(app, #endif fm_mime_type_get_type(mime_type), &err)) { g_debug("error: %s", err->message); g_error_free(err); } /* if need to set default */ if(set_default) g_app_info_set_as_default_for_type(app, fm_mime_type_get_type(mime_type), NULL); }
static void set_as_default_clicked_cb (GtkButton *button, gpointer user_data) { NautilusMimeApplicationChooser *chooser = user_data; GAppInfo *info; GError *error = NULL; gchar *message = NULL; info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget)); g_app_info_set_as_default_for_type (info, chooser->details->content_type, &error); if (error != NULL) { message = g_strdup_printf (_("Error while setting “%s” as default application: %s"), g_app_info_get_display_name (info), error->message); eel_show_error_dialog (_("Could not set as default"), message, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser)))); } g_object_unref (info); gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget)); g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed"); }
static VALUE appinfo_set_as_default_for_type(VALUE self, VALUE value) { GError *error = NULL; if (!g_app_info_set_as_default_for_type(_SELF(self), RVAL2CSTR(value), &error)) rbgio_raise_error(error); return self; }
static void set_as_default_clicked_cb (GtkButton *button, gpointer user_data) { NemoMimeApplicationChooser *chooser = user_data; GAppInfo *info; if (!chooser->details->custom_info) { info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget)); g_app_info_set_as_default_for_type (info, chooser->details->content_type, NULL); } else { info = chooser->details->custom_info; g_app_info_set_as_default_for_type (info, chooser->details->content_type, NULL); } gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget)); gtk_entry_set_text (GTK_ENTRY (chooser->details->custom_entry), ""); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (chooser->details->file_button), ""); g_signal_emit_by_name (nemo_signaller_get_current (), "mime_data_changed"); }
static void autorun_dialog_response (GtkDialog *dialog, gint response, AutorunDialogData *data) { switch (response) { case AUTORUN_DIALOG_RESPONSE_EJECT: caja_file_operations_unmount_mount (GTK_WINDOW (dialog), data->mount, data->should_eject, FALSE); break; case GTK_RESPONSE_NONE: /* window was closed */ break; case GTK_RESPONSE_CANCEL: break; case GTK_RESPONSE_OK: /* do the selected action */ if (data->remember) { /* make sure we don't ask again */ caja_autorun_set_preferences (data->x_content_type, TRUE, data->selected_ignore, data->selected_open_folder); if (!data->selected_ignore && !data->selected_open_folder && data->selected_app != NULL) { g_app_info_set_as_default_for_type (data->selected_app, data->x_content_type, NULL); } } else { /* make sure we do ask again */ caja_autorun_set_preferences (data->x_content_type, FALSE, FALSE, FALSE); } if (!data->selected_ignore && !data->selected_open_folder && data->selected_app != NULL) { caja_autorun_launch_for_mount (data->mount, data->selected_app); } else if (!data->selected_ignore && data->selected_open_folder) { if (data->open_window_func != NULL) data->open_window_func (data->mount, data->user_data); } break; } autorun_dialog_destroy (data); }
/** * Set default application for URI's of a particular scheme * @param aURIScheme string containing the URI scheme * @return NS_OK when application was set as default for URI scheme, * NS_ERROR_FAILURE otherwise */ NS_IMETHODIMP nsGIOMimeApp::SetAsDefaultForURIScheme(nsACString const& aURIScheme) { GError *error = NULL; nsCAutoString contentType("x-scheme-handler/"); contentType.Append(aURIScheme); g_app_info_set_as_default_for_type(mApp, contentType.get(), &error); if (error) { g_warning("Cannot set application as default for URI scheme (%s): %s", PromiseFlatCString(aURIScheme).get(), error->message); g_error_free(error); return NS_ERROR_FAILURE; } return NS_OK; }
static void other_application_selected (CajaOpenWithDialog *dialog, GAppInfo *app_info, CajaAutorunComboBoxData *data) { if (data->changed_cb != NULL) { data->changed_cb (TRUE, FALSE, FALSE, app_info, data->user_data); } if (data->update_settings) { caja_autorun_set_preferences (data->x_content_type, TRUE, FALSE, FALSE); g_app_info_set_as_default_for_type (app_info, data->x_content_type, NULL); data->other_application_selected = TRUE; } /* rebuild so we include and select the new application in the list */ caja_autorun_rebuild_combo_box (data->combo_box); }
NS_IMETHODIMP nsGIOMimeApp::SetAsDefaultForMimeType(nsACString const& aMimeType) { char *content_type = get_content_type_from_mime_type(PromiseFlatCString(aMimeType).get()); if (!content_type) return NS_ERROR_FAILURE; GError *error = NULL; g_app_info_set_as_default_for_type(mApp, content_type, &error); if (error) { g_warning("Cannot set application as default for MIME type (%s): %s", PromiseFlatCString(aMimeType).get(), error->message); g_error_free(error); g_free(content_type); return NS_ERROR_FAILURE; } g_free(content_type); return NS_OK; }
/* This will check if the application the user wanted exists will return that * application. If it doesn't exist, it will create one and return that. * It also sets the app info as the default for this type. */ static GAppInfo * add_or_find_application (CajaOpenWithDialog *dialog) { GAppInfo *app; char *app_name; const char *commandline; GError *error; gboolean success, should_set_default; char *message; GList *applications; error = NULL; app = NULL; if (dialog->details->selected_app_info) { app = g_object_ref (dialog->details->selected_app_info); } else { commandline = gtk_entry_get_text (GTK_ENTRY (dialog->details->entry)); app_name = get_app_name (commandline, &error); if (app_name != NULL) { app = g_app_info_create_from_commandline (commandline, app_name, G_APP_INFO_CREATE_NONE, &error); g_free (app_name); } } if (app == NULL) { message = g_strdup_printf (_("Could not add application to the application database: %s"), error->message); eel_show_error_dialog (_("Could not add application"), message, GTK_WINDOW (dialog)); g_free (message); g_error_free (error); return NULL; } should_set_default = (dialog->details->add_mode) || (!dialog->details->add_mode && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->details->checkbox))); success = TRUE; if (should_set_default) { if (dialog->details->content_type) { success = g_app_info_set_as_default_for_type (app, dialog->details->content_type, &error); } else { success = g_app_info_set_as_default_for_extension (app, dialog->details->extension, &error); } } else { applications = g_app_info_get_all_for_type (dialog->details->content_type); if (dialog->details->content_type && applications != NULL) { /* we don't care about reporting errors here */ g_app_info_add_supports_type (app, dialog->details->content_type, NULL); } if (applications != NULL) { g_list_foreach(applications, (GFunc) g_object_unref, NULL); g_list_free(applications); } } if (!success && should_set_default) { message = g_strdup_printf (_("Could not set application as the default: %s"), error->message); eel_show_error_dialog (_("Could not set as default application"), message, GTK_WINDOW (dialog)); g_free (message); g_error_free (error); } g_signal_emit_by_name (caja_signaller_get_current (), "mime_data_changed"); return app; }
int main (int argc, char *argv[]) { GError *error; GOptionContext *context; const char *mimetype; gchar *param; gchar *summary; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); error = NULL; param = g_strdup_printf ("%s [%s]", _("MIMETYPE"), _("HANDLER")); summary = _("Get or set the handler for a mime-type."); context = g_option_context_new (param); g_option_context_set_summary (context, summary); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); g_free (param); if (error != NULL || (query == set && !show_version)) { g_printerr (_("Error parsing commandline options: %s\n"), error ? error->message : _("Specify either --query or --set")); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); if (error != NULL) g_error_free (error); return 1; } if (show_version) { g_print (PACKAGE_STRING "\n"); return 0; } if (query && argc != 2) { g_printerr (_("Must specify a single mime-type.\n")); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } else if (set && argc != 3) { g_printerr (_("Must specify the mime-type followed by the default handler.\n")); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } mimetype = argv[1]; if (query) { GAppInfo *info; info = g_app_info_get_default_for_type (mimetype, FALSE); if (!info) { g_print (_("No default applications for '%s'\n"), mimetype); } else { GList *list, *l; g_print (_("Default application for '%s': %s\n"), mimetype, g_app_info_get_id (info)); g_object_unref (info); list = g_app_info_get_all_for_type (mimetype); if (list != NULL) g_print (_("Registered applications:\n")); else g_print (_("No registered applications\n")); for (l = list; l != NULL; l = l->next) { info = l->data; g_print ("\t%s\n", g_app_info_get_id (info)); g_object_unref (info); } g_list_free (list); list = g_app_info_get_recommended_for_type (mimetype); if (list != NULL) g_print (_("Recommended applications:\n")); else g_print (_("No recommended applications\n")); for (l = list; l != NULL; l = l->next) { info = l->data; g_print ("\t%s\n", g_app_info_get_id (info)); g_object_unref (info); } g_list_free (list); } } else if (set) { const char *handler; GAppInfo *info; handler = argv[2]; info = get_app_info_for_id (handler); if (info == NULL) { g_printerr (_("Failed to load info for handler '%s'\n"), handler); return 1; } if (g_app_info_set_as_default_for_type (info, mimetype, &error) == FALSE) { g_printerr (_("Failed to set '%s' as the default handler for '%s': %s\n"), handler, mimetype, error->message); g_error_free (error); g_object_unref (info); return 1; } g_print ("Set %s as the default for %s\n", g_app_info_get_id (info), mimetype); g_object_unref (info); } return 0; }
static void combo_box_changed (GtkComboBox *combo_box, CajaAutorunComboBoxData *data) { GtkTreeIter iter; GtkTreeModel *model; GAppInfo *app_info; char *x_content_type; int type; model = NULL; app_info = NULL; x_content_type = NULL; if (!gtk_combo_box_get_active_iter (combo_box, &iter)) { goto out; } model = gtk_combo_box_get_model (combo_box); if (model == NULL) { goto out; } gtk_tree_model_get (model, &iter, COLUMN_AUTORUN_APP_INFO, &app_info, COLUMN_AUTORUN_X_CONTENT_TYPE, &x_content_type, COLUMN_AUTORUN_ITEM_TYPE, &type, -1); switch (type) { case AUTORUN_ASK: if (data->changed_cb != NULL) { data->changed_cb (TRUE, FALSE, FALSE, NULL, data->user_data); } if (data->update_settings) { caja_autorun_set_preferences (x_content_type, FALSE, FALSE, FALSE); } break; case AUTORUN_IGNORE: if (data->changed_cb != NULL) { data->changed_cb (FALSE, TRUE, FALSE, NULL, data->user_data); } if (data->update_settings) { caja_autorun_set_preferences (x_content_type, FALSE, TRUE, FALSE); } break; case AUTORUN_OPEN_FOLDER: if (data->changed_cb != NULL) { data->changed_cb (FALSE, FALSE, TRUE, NULL, data->user_data); } if (data->update_settings) { caja_autorun_set_preferences (x_content_type, FALSE, FALSE, TRUE); } break; case AUTORUN_APP: if (data->changed_cb != NULL) { /* TODO TODO?? */ data->changed_cb (TRUE, FALSE, FALSE, app_info, data->user_data); } if (data->update_settings) { caja_autorun_set_preferences (x_content_type, TRUE, FALSE, FALSE); g_app_info_set_as_default_for_type (app_info, x_content_type, NULL); } break; case AUTORUN_OTHER_APP: { GtkWidget *dialog; data->other_application_selected = FALSE; dialog = caja_add_application_dialog_new (NULL, x_content_type); gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (combo_box)))); g_signal_connect (dialog, "application_selected", G_CALLBACK (other_application_selected), data); g_signal_connect (dialog, "response", G_CALLBACK (dialog_response_cb), data); g_signal_connect (dialog, "destroy", G_CALLBACK (dialog_destroy_cb), data); gtk_widget_show (GTK_WIDGET (dialog)); break; } } out: if (app_info != NULL) { g_object_unref (app_info); } g_free (x_content_type); }
static void set_changed(GtkComboBox* combo, MateDACapplet* capplet, GList* list, gint type) { guint index; GAppInfo* item; GSettings* settings; index = gtk_combo_box_get_active(combo); if (index < g_list_length(list)) { item = (GAppInfo*) g_list_nth_data(list, index); switch (type) { case DA_TYPE_WEB_BROWSER: g_app_info_set_as_default_for_type(item, "x-scheme-handler/http", NULL); g_app_info_set_as_default_for_type(item, "x-scheme-handler/https", NULL); /* about:config is used by firefox and others */ g_app_info_set_as_default_for_type(item, "x-scheme-handler/about", NULL); break; case DA_TYPE_EMAIL: g_app_info_set_as_default_for_type(item, "x-scheme-handler/mailto", NULL); g_app_info_set_as_default_for_type(item, "application/x-extension-eml", NULL); g_app_info_set_as_default_for_type(item, "message/rfc822", NULL); break; case DA_TYPE_FILE: g_app_info_set_as_default_for_type(item, "inode/directory", NULL); break; case DA_TYPE_TEXT: g_app_info_set_as_default_for_type(item, "text/plain", NULL); break; case DA_TYPE_MEDIA: g_app_info_set_as_default_for_type(item, "audio/mpeg", NULL); g_app_info_set_as_default_for_type(item, "audio/x-mpegurl", NULL); g_app_info_set_as_default_for_type(item, "audio/x-scpls", NULL); g_app_info_set_as_default_for_type(item, "audio/x-vorbis+ogg", NULL); g_app_info_set_as_default_for_type(item, "audio/x-wav", NULL); break; case DA_TYPE_VIDEO: g_app_info_set_as_default_for_type(item, "video/mp4", NULL); g_app_info_set_as_default_for_type(item, "video/mpeg", NULL); g_app_info_set_as_default_for_type(item, "video/mp2t", NULL); g_app_info_set_as_default_for_type(item, "video/msvideo", NULL); g_app_info_set_as_default_for_type(item, "video/quicktime", NULL); g_app_info_set_as_default_for_type(item, "video/webm", NULL); g_app_info_set_as_default_for_type(item, "video/x-avi", NULL); g_app_info_set_as_default_for_type(item, "video/x-flv", NULL); g_app_info_set_as_default_for_type(item, "video/x-matroska", NULL); g_app_info_set_as_default_for_type(item, "video/x-mpeg", NULL); g_app_info_set_as_default_for_type(item, "video/x-ogm+ogg", NULL); break; case DA_TYPE_IMAGE: g_app_info_set_as_default_for_type(item, "image/bmp", NULL); g_app_info_set_as_default_for_type(item, "image/gif", NULL); g_app_info_set_as_default_for_type(item, "image/jpeg", NULL); g_app_info_set_as_default_for_type(item, "image/png", NULL); g_app_info_set_as_default_for_type(item, "image/tiff", NULL); break; case DA_TYPE_DOCUMENT: g_app_info_set_as_default_for_type(item, "application/pdf", NULL); break; case DA_TYPE_WORD: g_app_info_set_as_default_for_type(item, "application/vnd.oasis.opendocument.text", NULL); g_app_info_set_as_default_for_type(item, "application/msword", NULL); g_app_info_set_as_default_for_type(item, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", NULL); break; case DA_TYPE_SPREADSHEET: g_app_info_set_as_default_for_type(item, "application/vnd.oasis.opendocument.spreadsheet", NULL); g_app_info_set_as_default_for_type(item, "application/vnd.ms-excel", NULL); g_app_info_set_as_default_for_type(item, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", NULL); break; case DA_TYPE_TERMINAL: g_settings_set_string (capplet->terminal_settings, TERMINAL_KEY, g_app_info_get_executable (item)); break; case DA_TYPE_VISUAL: g_settings_set_string (capplet->visual_settings, VISUAL_KEY, g_app_info_get_executable (item)); break; case DA_TYPE_MOBILITY: g_settings_set_string (capplet->mobility_settings, MOBILITY_KEY, g_app_info_get_executable (item)); break; default: break; } } }
int main (int argc, char *argv[]) { GError *error; GOptionContext *context; const char *mimetype; setlocale (LC_ALL, ""); g_type_init (); error = NULL; context = g_option_context_new (_("- get/set handler for <mimetype>")); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL || query == set) { g_printerr (_("Error parsing commandline options: %s\n"), error ? error->message : _("Specify one of --query and --set")); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); if (error != NULL) g_error_free(error); return 1; } if (query && argc != 2) { g_printerr (_("Must specify a single mime-type.\n")); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } else if (set && argc != 3) { g_printerr (_("Must specify the mime-type followed by the default handler.\n")); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } mimetype = argv[1]; if (query) { GAppInfo *info; info = g_app_info_get_default_for_type (mimetype, FALSE); if (!info) { g_print (_("No default applications for '%s'\n"), mimetype); } else { GList *list, *l; g_print (_("Default application for '%s': %s\n"), mimetype, g_app_info_get_id (info)); g_object_unref (info); list = g_app_info_get_all_for_type (mimetype); if (list != NULL) g_print (_("Registered applications:\n")); for (l = list; l != NULL; l = l->next) { info = l->data; g_print ("\t%s\n", g_app_info_get_id (info)); g_object_unref (info); } g_list_free (list); list = g_app_info_get_recommended_for_type (mimetype); if (list != NULL) g_print (_("Recommended applications:\n")); for (l = list; l != NULL; l = l->next) { info = l->data; g_print ("\t%s\n", g_app_info_get_id (info)); g_object_unref (info); } g_list_free (list); } } else if (set) { const char *handler; GAppInfo *info; handler = argv[2]; info = get_app_info_for_id (handler); if (info == NULL) { g_printerr (_("Failed to load info for handler '%s'\n"), handler); return 1; } if (g_app_info_set_as_default_for_type (info, mimetype, &error) == FALSE) { g_printerr (_("Failed to set '%s' as the default handler for '%s': %s\n"), handler, mimetype, error->message); g_error_free (error); g_object_unref (info); return 1; } g_print ("Set %s as the default for %s\n", g_app_info_get_id (info), mimetype); g_object_unref (info); } return 0; }
static void set_changed(GtkComboBox* combo, MateDACapplet* capplet, GList* list, gint type) { guint index; GAppInfo* item; index = gtk_combo_box_get_active(combo); if (index < g_list_length(list)) { item = (GAppInfo*) g_list_nth_data(list, index); switch (type) { case DA_TYPE_WEB_BROWSER: /* establecemos el item */ g_app_info_set_as_default_for_type(item, "x-scheme-handler/http", NULL); g_app_info_set_as_default_for_type(item, "x-scheme-handler/https", NULL); /* about:config es usado por mozilla firefox y algunos otros con * webtoolkit */ g_app_info_set_as_default_for_type(item, "x-scheme-handler/about", NULL); break; case DA_TYPE_EMAIL: /* por alguna extraña razon, solo se usa mailto, en vez de mail. */ g_app_info_set_as_default_for_type(item, "x-scheme-handler/mailto", NULL); break; case DA_TYPE_FILE: /* falta agregar más mime-types */ g_app_info_set_as_default_for_type(item, "inode/directory", NULL); break; case DA_TYPE_TEXT: /* falta agregar más mime-types */ g_app_info_set_as_default_for_type(item, "text/plain", NULL); break; case DA_TYPE_MEDIA: /* por alguna extraña razon, solo se usa mailto, en vez de mail. */ g_app_info_set_as_default_for_type(item, "audio/x-vorbis+ogg", NULL); g_app_info_set_as_default_for_type(item, "audio/x-scpls", NULL); g_app_info_set_as_default_for_type(item, "audio/mpeg", NULL); g_app_info_set_as_default_for_type(item, "audio/x-wav", NULL); g_app_info_set_as_default_for_type(item, "audio/x-mpegurl", NULL); g_app_info_set_as_default_for_type(item, "video/webm", NULL); break; case DA_TYPE_VIDEO: /* por alguna extraña razon, solo se usa mailto, en vez de mail. */ g_app_info_set_as_default_for_type(item, "video/mpeg", NULL); g_app_info_set_as_default_for_type(item, "video/x-mpeg", NULL); g_app_info_set_as_default_for_type(item, "video/msvideo", NULL); g_app_info_set_as_default_for_type(item, "video/quicktime", NULL); g_app_info_set_as_default_for_type(item, "video/x-avi", NULL); g_app_info_set_as_default_for_type(item, "video/x-ogm+ogg", NULL); g_app_info_set_as_default_for_type(item, "video/x-matroska", NULL); g_app_info_set_as_default_for_type(item, "video/webm", NULL); g_app_info_set_as_default_for_type(item, "video/mp4", NULL); g_app_info_set_as_default_for_type(item, "video/x-flv", NULL); break; case DA_TYPE_IMAGE: /* por alguna extraña razon, solo se usa mailto, en vez de mail. */ g_app_info_set_as_default_for_type(item, "image/png", NULL); g_app_info_set_as_default_for_type(item, "image/jpeg", NULL); g_app_info_set_as_default_for_type(item, "image/gif", NULL); g_app_info_set_as_default_for_type(item, "image/bmp", NULL); g_app_info_set_as_default_for_type(item, "image/tiff", NULL); break; default:; break; } } }
void FilePropsDialog::accept() { // applications if(mimeType && ui->openWith->isChanged()) { GAppInfo* currentApp = ui->openWith->selectedApp(); g_app_info_set_as_default_for_type(currentApp, fm_mime_type_get_type(mimeType), NULL); } // check if chown or chmod is needed guint32 newUid = uidFromName(ui->owner->text()); guint32 newGid = gidFromName(ui->ownerGroup->text()); bool needChown = (newUid != -1 && newUid != uid) || (newGid != -1 && newGid != gid); int newOwnerPermSel = ui->ownerPerm->currentIndex(); int newGroupPermSel = ui->groupPerm->currentIndex(); int newOtherPermSel = ui->otherPerm->currentIndex(); Qt::CheckState newExecCheckState = ui->executable->checkState(); bool needChmod = ((newOwnerPermSel != ownerPermSel) || (newGroupPermSel != groupPermSel) || (newOtherPermSel != otherPermSel) || (newExecCheckState != execCheckState)); if(needChmod || needChown) { FmPathList* paths = fm_path_list_new_from_file_info_list(fileInfos_); FileOperation* op = new FileOperation(FileOperation::ChangeAttr, paths); fm_path_list_unref(paths); if(needChown) { // don't do chown if new uid/gid and the original ones are actually the same. if(newUid == uid) newUid = -1; if(newGid == gid) newGid = -1; op->setChown(newUid, newGid); } if(needChmod) { mode_t newMode = 0; mode_t newModeMask = 0; // FIXME: we need to make sure that folders with "r" permission also have "x" // at the same time. Otherwise, it's not able to browse the folder later. if(newOwnerPermSel != ownerPermSel && newOwnerPermSel != ACCESS_NO_CHANGE) { // owner permission changed newModeMask |= (S_IRUSR|S_IWUSR); // affect user bits if(newOwnerPermSel == ACCESS_READ_ONLY) newMode |= S_IRUSR; else if(newOwnerPermSel == ACCESS_READ_WRITE) newMode |= (S_IRUSR|S_IWUSR); } if(newGroupPermSel != groupPermSel && newGroupPermSel != ACCESS_NO_CHANGE) { qDebug("newGroupPermSel: %d", newGroupPermSel); // group permission changed newModeMask |= (S_IRGRP|S_IWGRP); // affect group bits if(newGroupPermSel == ACCESS_READ_ONLY) newMode |= S_IRGRP; else if(newGroupPermSel == ACCESS_READ_WRITE) newMode |= (S_IRGRP|S_IWGRP); } if(newOtherPermSel != otherPermSel && newOtherPermSel != ACCESS_NO_CHANGE) { // other permission changed newModeMask |= (S_IROTH|S_IWOTH); // affect other bits if(newOtherPermSel == ACCESS_READ_ONLY) newMode |= S_IROTH; else if(newOtherPermSel == ACCESS_READ_WRITE) newMode |= (S_IROTH|S_IWOTH); } if(newExecCheckState != execCheckState && newExecCheckState != Qt::PartiallyChecked) { // executable state changed newModeMask |= (S_IXUSR|S_IXGRP|S_IXOTH); if(newExecCheckState == Qt::Checked) newMode |= (S_IXUSR|S_IXGRP|S_IXOTH); } op->setChmod(newMode, newModeMask); if(hasDir) { // if there are some dirs in our selected files QMessageBox::StandardButton r = QMessageBox::question(this, tr("Apply changes"), tr("Do you want to recursively apply these changes to all files and sub-folders?"), QMessageBox::Yes|QMessageBox::No); if(r == QMessageBox::Yes) op->setRecursiveChattr(true); } } op->setAutoDestroy(true); op->run(); } QDialog::accept(); }
static void on_response (GtkDialog *dlg, int response, FmFilePropData *data) { if ( response == GTK_RESPONSE_OK ) { int sel; const char *new_owner = gtk_entry_get_text (GTK_ENTRY (data->owner)); const char *new_group = gtk_entry_get_text (GTK_ENTRY (data->group)); guint32 uid = -1, gid = -1; mode_t new_mode = 0, new_mode_mask = 0; if (!ensure_valid_owner (data) || !ensure_valid_group (data)) { g_signal_stop_emission_by_name (dlg, "response"); return; } /* FIXME_pcm: if all files are native, it's possible to check * if the names are legal user and group names on the local * machine prior to chown. */ if (new_owner && *new_owner && g_strcmp0 (data->orig_owner, new_owner)) { // change owner g_debug ("change owner to: %d", data->uid); } else data->uid = -1; if (new_group && *new_group && g_strcmp0 (data->orig_group, new_group)) { // change group g_debug ("change group to: %d", data->gid); } else data->gid = -1; // check if chmod is needed here. sel = gtk_combo_box_get_active (GTK_COMBO_BOX (data->owner_perm)); if ( sel != NO_CHANGE ) // need to change owner permission { if (data->owner_perm_sel != sel) // new value is different from original { new_mode_mask |= S_IRUSR|S_IWUSR; data->owner_perm_sel = sel; switch (sel) { case READ_WRITE: new_mode |= S_IRUSR|S_IWUSR; break; case READ_ONLY: new_mode |= S_IRUSR; break; case WRITE_ONLY: new_mode |= S_IWUSR; break; } } else // otherwise, no change data->owner_perm_sel = NO_CHANGE; } else data->owner_perm_sel = NO_CHANGE; sel = gtk_combo_box_get_active (GTK_COMBO_BOX (data->group_perm)); if ( sel != NO_CHANGE ) // need to change group permission { if (data->group_perm_sel != sel) // new value is different from original { new_mode_mask |= S_IRGRP|S_IWGRP; data->group_perm_sel = sel; switch (sel) { case READ_WRITE: new_mode |= S_IRGRP|S_IWGRP; break; case READ_ONLY: new_mode |= S_IRGRP; break; case WRITE_ONLY: new_mode |= S_IWGRP; break; } } else // otherwise, no change data->group_perm_sel = NO_CHANGE; } else data->group_perm_sel = NO_CHANGE; #if 0 sel = gtk_combo_box_get_active (GTK_COMBO_BOX (data->other_perm)); if ( sel != NO_CHANGE ) // need to change other permission { if (data->other_perm_sel != sel) // new value is different from original { new_mode_mask |= S_IROTH|S_IWOTH; switch (sel) { case READ_WRITE: new_mode |= S_IROTH|S_IWOTH; break; case READ_ONLY: new_mode |= S_IROTH; break; case WRITE_ONLY: new_mode |= S_IWOTH; break; } data->other_perm_sel = sel; } else // otherwise, no change data->other_perm_sel = NO_CHANGE; } else data->other_perm_sel = NO_CHANGE; if (!data->has_dir && !gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (data->exec)) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->exec)) != data->exec_state) { new_mode_mask |= (S_IXUSR|S_IXGRP|S_IXOTH); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->exec))) new_mode |= (S_IXUSR|S_IXGRP|S_IXOTH); } if (new_mode_mask || data->uid != -1 || data->gid != -1) { FmPathList *paths = fm_path_list_new_from_file_info_list (data->files); FmFileOpsJob *job = (FmFileOpsJob*) fm_file_ops_job_new (FM_FILE_OP_CHANGE_ATTR, paths); // need to chown if (data->uid != -1 || data->gid != -1) fm_file_ops_job_set_chown (job, data->uid, data->gid); // need to do chmod if (new_mode_mask) fm_file_ops_job_set_chmod (job, new_mode, new_mode_mask); if (data->has_dir) { if (fm_yes_no (GTK_WINDOW (data->dlg), NULL, _( "Do you want to recursively apply these changes to all files and sub-folders?" ), TRUE)) fm_file_ops_job_set_recursive (job, TRUE); } // show progress dialog fm_file_ops_job_run_with_progress (GTK_WINDOW (data->dlg), job); fm_list_unref (paths); } // change default application for the mime-type if needed if (data->mime_type && fm_mime_type_get_type (data->mime_type) && data->open_with) { GAppInfo *app; gboolean default_app_changed = FALSE; GError *err = NULL; app = fm_app_chooser_combo_box_get_selected (GTK_COMBO_BOX (data->open_with), &default_app_changed); if (app) { if (default_app_changed) { g_app_info_set_as_default_for_type (app, fm_mime_type_get_type (data->mime_type), &err); if (err) { fm_show_error (GTK_WINDOW (dlg), NULL, err->message); g_error_free (err); } } g_object_unref (app); } } if (data->single_file) // when only one file is shown { // if the user has changed its name if ( g_strcmp0 (data->file_info->disp_name, gtk_entry_get_text (GTK_ENTRY (data->name))) ) { // FIXME_pcm: rename the file or set display name for it. } } #endif } gtk_widget_destroy (GTK_WIDGET (dlg)); }