/* An application is valid if: * * 1) The file exists * 2) The user has permissions to run the file */ static gboolean check_application (CajaOpenWithDialog *dialog) { char *command; char *path = NULL; char **argv = NULL; int argc; GError *error = NULL; gint retval = TRUE; command = NULL; if (dialog->details->selected_app_info != NULL) { command = g_strdup (g_app_info_get_executable (dialog->details->selected_app_info)); } if (command == NULL) { command = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->details->entry))); } g_shell_parse_argv (command, &argc, &argv, &error); if (error) { eel_show_error_dialog (_("Could not run application"), error->message, GTK_WINDOW (dialog)); g_error_free (error); retval = FALSE; goto cleanup; } path = g_find_program_in_path (argv[0]); if (!path) { char *error_message; error_message = g_strdup_printf (_("Could not find '%s'"), argv[0]); eel_show_error_dialog (_("Could not find application"), error_message, GTK_WINDOW (dialog)); g_free (error_message); retval = FALSE; goto cleanup; } cleanup: g_strfreev (argv); g_free (path); g_free (command); return retval; }
gboolean eel_gconf_handle_error (GError **error) { char *message; static gboolean shown_dialog = FALSE; g_return_val_if_fail (error != NULL, FALSE); if (*error != NULL) { g_warning (_("GConf error:\n %s"), (*error)->message); if (! shown_dialog) { shown_dialog = TRUE; message = g_strdup_printf (_("GConf error: %s"), (*error)->message); eel_show_error_dialog (message, _("All further errors shown " "only on terminal."), NULL); g_free (message); } g_error_free (*error); *error = NULL; return TRUE; } return FALSE; }
static void remove_clicked_cb (GtkMenuItem *item, gpointer user_data) { NemoMimeApplicationChooser *chooser = user_data; GError *error; GAppInfo *info; info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget)); if (info) { error = NULL; if (!g_app_info_remove_supports_type (info, chooser->details->content_type, &error)) { eel_show_error_dialog (_("Could not forget association"), error->message, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser)))); g_error_free (error); } gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget)); g_object_unref (info); } g_signal_emit_by_name (nemo_signaller_get_current (), "mime_data_changed"); }
static void add_clicked_cb (GtkButton *button, gpointer user_data) { NautilusMimeApplicationChooser *chooser = user_data; GAppInfo *info; gchar *message; GError *error = NULL; info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget)); if (info == NULL) return; g_app_info_set_as_last_used_for_type (info, chooser->details->content_type, &error); if (error != NULL) { message = g_strdup_printf (_("Error while adding “%s”: %s"), g_app_info_get_display_name (info), error->message); eel_show_error_dialog (_("Could not add application"), message, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser)))); g_error_free (error); g_free (message); } else { gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget)); g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed"); } g_object_unref (info); }
void nautilus_report_error_loading_directory (NautilusFile *file, GError *error, GtkWindow *parent_window) { char *file_name; char *message; if (error == NULL || error->message == NULL) { return; } if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_MOUNTED) { /* This case is retried automatically */ return; } file_name = nautilus_file_get_display_name (file); if (error->domain == G_IO_ERROR) { switch (error->code) { case G_IO_ERROR_PERMISSION_DENIED: { message = g_strdup_printf (_("You do not have the permissions necessary to view the contents of “%s”."), file_name); } break; case G_IO_ERROR_NOT_FOUND: { message = g_strdup_printf (_("“%s” could not be found. Perhaps it has recently been deleted."), file_name); } break; default: message = g_strdup_printf (_("Sorry, could not display all the contents of “%s”: %s"), file_name, error->message); } } else { message = g_strdup (error->message); } eel_show_error_dialog (_("This location could not be displayed."), message, parent_window); g_free (file_name); g_free (message); }
void nautilus_report_error_setting_group (NautilusFile *file, GError *error, GtkWindow *parent_window) { char *file_name; char *message; if (error == NULL) { return; } file_name = nautilus_file_get_display_name (file); message = NULL; if (error->domain == G_IO_ERROR) { switch (error->code) { case G_IO_ERROR_PERMISSION_DENIED: { message = g_strdup_printf (_("You do not have the permissions necessary to change the group of “%s”."), file_name); } break; default: { } break; } } if (message == NULL) { /* We should invent decent error messages for every case we actually experience. */ g_warning ("Hit unhandled case %s:%d in nautilus_report_error_setting_group", g_quark_to_string (error->domain), error->code); /* fall through */ message = g_strdup_printf (_("Sorry, could not change the group of “%s”: %s"), file_name, error->message); } eel_show_error_dialog (_("The group could not be changed."), message, parent_window); g_free (file_name); g_free (message); }
static void nautilus_emblem_sidebar_delete_cb (GtkWidget *menu_item, NautilusEmblemSidebar *emblem_sidebar) { char *error; if (nautilus_emblem_remove_emblem (emblem_sidebar->details->popup_emblem_keyword)) { send_emblems_changed (); } else { error = g_strdup_printf (_("Could not remove emblem with name '%s'."), emblem_sidebar->details->popup_emblem_display_name); eel_show_error_dialog (error, _("This is probably because the emblem is a permanent one, and not one that you added yourself."), NULL); g_free (error); } }
static void rename_dialog_response_cb (GtkWidget *dialog, int response, CajaEmblemSidebar *emblem_sidebar) { GtkWidget *entry; char *keyword, *name, *error; keyword = g_object_get_data (G_OBJECT (dialog), "emblem-keyword"); if (response == GTK_RESPONSE_CANCEL) { g_free (keyword); gtk_widget_destroy (dialog); return; } else if (response == GTK_RESPONSE_HELP) { g_message ("Implement me!"); return; } entry = g_object_get_data (G_OBJECT (dialog), "entry"); name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); gtk_widget_destroy (dialog); if (caja_emblem_rename_emblem (keyword, name)) { send_emblems_changed (); } else { error = g_strdup_printf (_("Could not rename emblem with name '%s'."), name); eel_show_error_dialog (error, _("This is probably because the emblem is a permanent one, and not one that you added yourself."), NULL); g_free (error); } g_free (keyword); g_free (name); }
void nautilus_report_error_setting_permissions (NautilusFile *file, GError *error, GtkWindow *parent_window) { char *file_name; char *message; if (error == NULL) { return; } file_name = nautilus_file_get_display_name (file); message = g_strdup_printf (_("Sorry, could not change the permissions of “%s”: %s"), file_name, error->message); eel_show_error_dialog (_("The permissions could not be changed."), message, parent_window); g_free (file_name); g_free (message); }
void athena_report_error_setting_owner (AthenaFile *file, GError *error, GtkWindow *parent_window) { char *file_name; char *message; if (error == NULL) { return; } file_name = athena_file_get_display_name (file); message = g_strdup_printf (_("Sorry, could not change the owner of \"%s\": %s"), file_name, error->message); eel_show_error_dialog (_("The owner could not be changed."), message, parent_window); g_free (file_name); g_free (message); }
GtkDialog * eel_show_error_dialog_with_details (const char *primary_text, const char *secondary_text, const char *detailed_error_message, GtkWindow *parent) { GtkDialog *dialog; g_return_val_if_fail (primary_text != NULL, NULL); g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL); if (detailed_error_message == NULL || strcmp (primary_text, detailed_error_message) == 0) { return eel_show_error_dialog (primary_text, secondary_text, parent); } dialog = show_message_dialog (primary_text, secondary_text, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, detailed_error_message, parent); return dialog; }
void caja_launch_desktop_file (GdkScreen *screen, const char *desktop_file_uri, const GList *parameter_uris, GtkWindow *parent_window) { GError *error; char *message, *desktop_file_path; const GList *p; GList *files; int total, count; GFile *file, *desktop_file; GDesktopAppInfo *app_info; GdkAppLaunchContext *context; /* Don't allow command execution from remote locations * to partially mitigate the security * risk of executing arbitrary commands. */ desktop_file = g_file_new_for_uri (desktop_file_uri); desktop_file_path = g_file_get_path (desktop_file); if (!g_file_is_native (desktop_file)) { g_free (desktop_file_path); g_object_unref (desktop_file); eel_show_error_dialog (_("Sorry, but you cannot execute commands from " "a remote site."), _("This is disabled due to security considerations."), parent_window); return; } g_object_unref (desktop_file); app_info = g_desktop_app_info_new_from_filename (desktop_file_path); g_free (desktop_file_path); if (app_info == NULL) { eel_show_error_dialog (_("There was an error launching the application."), NULL, parent_window); return; } /* count the number of uris with local paths */ count = 0; total = g_list_length ((GList *) parameter_uris); files = NULL; for (p = parameter_uris; p != NULL; p = p->next) { file = g_file_new_for_uri ((const char *) p->data); if (g_file_is_native (file)) { count++; } files = g_list_prepend (files, file); } /* check if this app only supports local files */ if (g_app_info_supports_files (G_APP_INFO (app_info)) && !g_app_info_supports_uris (G_APP_INFO (app_info)) && parameter_uris != NULL) { if (count == 0) { /* all files are non-local */ eel_show_error_dialog (_("This drop target only supports local files."), _("To open non-local files copy them to a local folder and then" " drop them again."), parent_window); g_list_free_full (files, g_object_unref); g_object_unref (app_info); return; } else if (count != total) { /* some files are non-local */ eel_show_warning_dialog (_("This drop target only supports local files."), _("To open non-local files copy them to a local folder and then" " drop them again. The local files you dropped have already been opened."), parent_window); } } error = NULL; context = gdk_app_launch_context_new (); /* TODO: Ideally we should accept a timestamp here instead of using GDK_CURRENT_TIME */ gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME); gdk_app_launch_context_set_screen (context, gtk_window_get_screen (parent_window)); if (count == total) { /* All files are local, so we can use g_app_info_launch () with * the file list we constructed before. */ g_app_info_launch (G_APP_INFO (app_info), files, G_APP_LAUNCH_CONTEXT (context), &error); } else { /* Some files are non local, better use g_app_info_launch_uris (). */ g_app_info_launch_uris (G_APP_INFO (app_info), (GList *) parameter_uris, G_APP_LAUNCH_CONTEXT (context), &error); } if (error != NULL) { message = g_strconcat (_("Details: "), error->message, NULL); eel_show_error_dialog (_("There was an error launching the application."), message, parent_window); g_error_free (error); g_free (message); } g_list_free_full (files, g_object_unref); g_object_unref (context); g_object_unref (app_info); }
static gboolean check_required_directories (NemoApplication *application) { char *user_directory; char *desktop_directory; GSList *directories; gboolean ret; g_assert (NEMO_IS_APPLICATION (application)); ret = TRUE; user_directory = nemo_get_user_directory (); desktop_directory = nemo_get_desktop_directory (); directories = NULL; if (!g_file_test (user_directory, G_FILE_TEST_IS_DIR)) { directories = g_slist_prepend (directories, user_directory); } if (!g_file_test (desktop_directory, G_FILE_TEST_IS_DIR)) { directories = g_slist_prepend (directories, desktop_directory); } if (directories != NULL) { int failed_count; GString *directories_as_string; GSList *l; char *error_string; const char *detail_string; GtkDialog *dialog; ret = FALSE; failed_count = g_slist_length (directories); directories_as_string = g_string_new ((const char *)directories->data); for (l = directories->next; l != NULL; l = l->next) { g_string_append_printf (directories_as_string, ", %s", (const char *)l->data); } if (failed_count == 1) { error_string = g_strdup_printf (_("Nemo could not create the required folder \"%s\"."), directories_as_string->str); detail_string = _("Before running Nemo, please create the following folder, or " "set permissions such that Nemo can create it."); } else { error_string = g_strdup_printf (_("Nemo could not create the following required folders: " "%s."), directories_as_string->str); detail_string = _("Before running Nemo, please create these folders, or " "set permissions such that Nemo can create them."); } dialog = eel_show_error_dialog (error_string, detail_string, NULL); /* We need the main event loop so the user has a chance to see the dialog. */ gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (dialog)); g_string_free (directories_as_string, TRUE); g_free (error_string); } g_slist_free (directories); g_free (user_directory); g_free (desktop_directory); return ret; }
static gboolean check_required_directories (NautilusApplication *application) { char *user_directory; char *desktop_directory; GSList *directories; gboolean ret; g_assert (NAUTILUS_IS_APPLICATION (application)); nautilus_profile_start (NULL); ret = TRUE; user_directory = nautilus_get_user_directory (); desktop_directory = nautilus_get_desktop_directory (); directories = NULL; if (!g_file_test (user_directory, G_FILE_TEST_IS_DIR)) { directories = g_slist_prepend (directories, user_directory); } if (!g_file_test (desktop_directory, G_FILE_TEST_IS_DIR)) { directories = g_slist_prepend (directories, desktop_directory); } if (directories != NULL) { int failed_count; GString *directories_as_string; GSList *l; char *error_string; const char *detail_string; GtkDialog *dialog; ret = FALSE; failed_count = g_slist_length (directories); directories_as_string = g_string_new ((const char *)directories->data); for (l = directories->next; l != NULL; l = l->next) { g_string_append_printf (directories_as_string, ", %s", (const char *)l->data); } error_string = _("Oops! Something went wrong."); if (failed_count == 1) { detail_string = g_strdup_printf (_("Unable to create a required folder. " "Please create the following folder, or " "set permissions such that it can be created:\n%s"), directories_as_string->str); } else { detail_string = g_strdup_printf (_("Unable to create required folders. " "Please create the following folders, or " "set permissions such that they can be created:\n%s"), directories_as_string->str); } dialog = eel_show_error_dialog (error_string, detail_string, NULL); /* We need the main event loop so the user has a chance to see the dialog. */ gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (dialog)); g_string_free (directories_as_string, TRUE); } g_slist_free (directories); g_free (user_directory); g_free (desktop_directory); nautilus_profile_end (NULL); return ret; }
void fm_report_error_renaming_file (CajaFile *file, const char *new_name, GError *error, GtkWindow *parent_window) { char *original_name, *original_name_truncated; char *new_name_truncated; char *message; /* Truncate names for display since very long file names with no spaces * in them won't get wrapped, and can create insanely wide dialog boxes. */ original_name = caja_file_get_display_name (file); original_name_truncated = eel_str_middle_truncate (original_name, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH); g_free (original_name); new_name_truncated = eel_str_middle_truncate (new_name, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH); message = NULL; if (error->domain == G_IO_ERROR) { switch (error->code) { case G_IO_ERROR_EXISTS: message = g_strdup_printf (_("The name \"%s\" is already used in this folder. " "Please use a different name."), new_name_truncated); break; case G_IO_ERROR_NOT_FOUND: message = g_strdup_printf (_("There is no \"%s\" in this folder. " "Perhaps it was just moved or deleted?"), original_name_truncated); break; case G_IO_ERROR_PERMISSION_DENIED: message = g_strdup_printf (_("You do not have the permissions necessary to rename \"%s\"."), original_name_truncated); break; case G_IO_ERROR_INVALID_FILENAME: if (strchr (new_name, '/') != NULL) { message = g_strdup_printf (_("The name \"%s\" is not valid because it contains the character \"/\". " "Please use a different name."), new_name_truncated); } else { message = g_strdup_printf (_("The name \"%s\" is not valid. " "Please use a different name."), new_name_truncated); } break; default: break; } } if (message == NULL) { /* We should invent decent error messages for every case we actually experience. */ g_warning ("Hit unhandled case %s:%d in fm_report_error_renaming_file", g_quark_to_string (error->domain), error->code); /* fall through */ message = g_strdup_printf (_("Sorry, could not rename \"%s\" to \"%s\": %s"), original_name_truncated, new_name_truncated, error->message); } g_free (original_name_truncated); g_free (new_name_truncated); eel_show_error_dialog (_("The item could not be renamed."), message, parent_window); g_free (message); }
/* 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; }
static void caja_emblem_sidebar_drag_received_cb (GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint info, guint time, CajaEmblemSidebar *emblem_sidebar) { GSList *emblems; Emblem *emblem; GdkPixbuf *pixbuf; char *uri, *error, *uri_utf8; char **uris; GFile *f; int i; gboolean had_failure; gint data_format, data_length; const guchar *data_data; had_failure = FALSE; emblems = NULL; data_format = gtk_selection_data_get_format (data); data_length = gtk_selection_data_get_length (data); data_data = gtk_selection_data_get_data (data); switch (info) { case TARGET_URI_LIST: if (data_format != 8 || data_length == 0) { g_message ("URI list had wrong format (%d) or length (%d)\n", data_format, data_length); return; } uris = g_uri_list_extract_uris (data_data); if (uris == NULL) { break; } for (i = 0; uris[i] != NULL; ++i) { f = g_file_new_for_uri (uris[i]); pixbuf = caja_emblem_load_pixbuf_for_emblem (f); if (pixbuf == NULL) { /* this one apparently isn't an image, or * at least not one that we know how to read */ had_failure = TRUE; g_object_unref (f); continue; } emblem = g_new (Emblem, 1); emblem->uri = g_file_get_uri (f); emblem->name = NULL; /* created later on by the user */ emblem->keyword = NULL; emblem->pixbuf = pixbuf; g_object_unref (f); emblems = g_slist_prepend (emblems, emblem); } g_strfreev (uris); if (had_failure && emblems != NULL) { eel_show_error_dialog (_("Some of the files could not be added as emblems."), _("The emblems do not appear to be valid images."), NULL); } else if (had_failure && emblems == NULL) { eel_show_error_dialog (_("None of the files could be added as emblems."), _("The emblems do not appear to be valid images."), NULL); } if (emblems != NULL) { show_add_emblems_dialog (emblem_sidebar, emblems); } break; case TARGET_URI: if (data_format != 8 || data_length == 0) { g_warning ("URI had wrong format (%d) or length (%d)\n", data_format, data_length); return; } uri = g_strndup (data_data, data_length); f = g_file_new_for_uri (uri); pixbuf = caja_emblem_load_pixbuf_for_emblem (f); if (pixbuf != NULL) { emblem = g_new (Emblem, 1); emblem->uri = uri; emblem->name = NULL; emblem->keyword = NULL; emblem->pixbuf = pixbuf; emblems = g_slist_prepend (NULL, emblem); show_add_emblems_dialog (emblem_sidebar, emblems); } else { uri_utf8 = g_file_get_parse_name (f); if (uri_utf8) { error = g_strdup_printf (_("The file '%s' does not appear to be a valid image."), uri_utf8); g_free (uri_utf8); } else { error = g_strdup (_("The dragged file does not appear to be a valid image.")); } eel_show_error_dialog (_("The emblem cannot be added."), error, NULL); g_free (error); g_free (uri_utf8); } g_object_unref (f); g_free (uri); break; case TARGET_NETSCAPE_URL: if (data_format != 8 || data_length == 0) { g_message ("URI had wrong format (%d) or length (%d)\n", data_format, data_length); return; } /* apparently, this is a URI/title pair? or just a pair * of identical URIs? Regardless, this seems to work... */ uris = g_uri_list_extract_uris (data_data); if (uris == NULL) { break; } uri = uris[0]; if (uri == NULL) { g_strfreev (uris); break; } f = g_file_new_for_uri (uri); pixbuf = caja_emblem_load_pixbuf_for_emblem (f); g_object_unref (f); if (pixbuf != NULL) { emblem = g_new (Emblem, 1); emblem->uri = g_strdup (uri); emblem->name = NULL; emblem->keyword = NULL; emblem->pixbuf = pixbuf; emblems = g_slist_prepend (NULL, emblem); show_add_emblems_dialog (emblem_sidebar, emblems); } else { g_warning ("Tried to load '%s', but failed.\n", uri); error = g_strdup_printf (_("The file '%s' does not appear to be a valid image."), uri); eel_show_error_dialog (_("The emblem cannot be added."), error, NULL); g_free (error); } g_strfreev (uris); break; } }