diff options
Diffstat (limited to 'src/nautilus-compress-dialog-controller.c')
-rw-r--r-- | src/nautilus-compress-dialog-controller.c | 415 |
1 files changed, 217 insertions, 198 deletions
diff --git a/src/nautilus-compress-dialog-controller.c b/src/nautilus-compress-dialog-controller.c index ea4a78a37..284b05a21 100644 --- a/src/nautilus-compress-dialog-controller.c +++ b/src/nautilus-compress-dialog-controller.c @@ -11,19 +11,20 @@ #define TAR_XZ_DESCRIPTION _("Smaller archives but Linux and Mac only.") #define SEVEN_ZIP_DESCRIPTION _("Smaller archives but must be installed on Windows and Mac.") -struct _NautilusCompressDialogController { - NautilusFileNameWidgetController parent_instance; +struct _NautilusCompressDialogController +{ + NautilusFileNameWidgetController parent_instance; - GtkWidget *compress_dialog; - GtkWidget *description_label; - GtkWidget *name_entry; - GtkWidget *zip_radio_button; - GtkWidget *tar_xz_radio_button; - GtkWidget *seven_zip_radio_button; + GtkWidget *compress_dialog; + GtkWidget *description_label; + GtkWidget *name_entry; + GtkWidget *zip_radio_button; + GtkWidget *tar_xz_radio_button; + GtkWidget *seven_zip_radio_button; - const char *extension; + const char *extension; - gint response_handler_id; + gint response_handler_id; }; G_DEFINE_TYPE (NautilusCompressDialogController, nautilus_compress_dialog_controller, NAUTILUS_TYPE_FILE_NAME_WIDGET_CONTROLLER); @@ -33,46 +34,54 @@ nautilus_compress_dialog_controller_name_is_valid (NautilusFileNameWidgetControl gchar *name, gchar **error_message) { - if (strlen (name) == 0) { - return FALSE; - } - - if (strstr (name, "/") != NULL) { - *error_message = _("Archive names cannot contain “/”."); - } else if (strcmp (name, ".") == 0){ - *error_message = _("An archive cannot be called “.”."); - } else if (strcmp (name, "..") == 0){ - *error_message = _("An archive cannot be called “..”."); - } - - return *error_message == NULL; + if (strlen (name) == 0) + { + return FALSE; + } + + if (strstr (name, "/") != NULL) + { + *error_message = _("Archive names cannot contain “/”."); + } + else if (strcmp (name, ".") == 0) + { + *error_message = _("An archive cannot be called “.”."); + } + else if (strcmp (name, "..") == 0) + { + *error_message = _("An archive cannot be called “..”."); + } + + return *error_message == NULL; } static gchar * nautilus_compress_dialog_controller_get_new_name (NautilusFileNameWidgetController *controller) { - NautilusCompressDialogController *self; - g_autofree gchar *basename; - gchar *error_message = NULL; - gboolean valid_name; - - self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (controller); - - basename = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (nautilus_compress_dialog_controller_parent_class)->get_new_name (controller); - /* Do not check or add the extension if the name is invalid */ - valid_name = nautilus_compress_dialog_controller_name_is_valid (controller, - basename, - &error_message); - - if (!valid_name) { - return g_strdup (basename); - } - - if (g_str_has_suffix (basename, self->extension)) { - return g_strdup (basename); - } - - return g_strconcat (basename, self->extension, NULL); + NautilusCompressDialogController *self; + g_autofree gchar *basename; + gchar *error_message = NULL; + gboolean valid_name; + + self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (controller); + + basename = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (nautilus_compress_dialog_controller_parent_class)->get_new_name (controller); + /* Do not check or add the extension if the name is invalid */ + valid_name = nautilus_compress_dialog_controller_name_is_valid (controller, + basename, + &error_message); + + if (!valid_name) + { + return g_strdup (basename); + } + + if (g_str_has_suffix (basename, self->extension)) + { + return g_strdup (basename); + } + + return g_strconcat (basename, self->extension, NULL); } static void @@ -80,107 +89,115 @@ compress_dialog_controller_on_response (GtkDialog *dialog, gint response_id, gpointer user_data) { - NautilusCompressDialogController *controller; + NautilusCompressDialogController *controller; - controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data); + controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data); - if (response_id != GTK_RESPONSE_OK) { - g_signal_emit_by_name (controller, "cancelled"); - } + if (response_id != GTK_RESPONSE_OK) + { + g_signal_emit_by_name (controller, "cancelled"); + } } static void update_selected_format (NautilusCompressDialogController *self, NautilusCompressionFormat format) { - const char *extension; - const char *description; - GtkWidget *active_button; - - switch (format) { - case NAUTILUS_COMPRESSION_ZIP: - extension = ".zip"; - description = ZIP_DESCRIPTION; - active_button = self->zip_radio_button; - break; - case NAUTILUS_COMPRESSION_TAR_XZ: - extension = ".tar.xz"; - description = TAR_XZ_DESCRIPTION; - active_button = self->tar_xz_radio_button; - break; - case NAUTILUS_COMPRESSION_7ZIP: - extension = ".7z"; - description = SEVEN_ZIP_DESCRIPTION; - active_button = self->seven_zip_radio_button; - break; - default: - g_assert_not_reached (); - break; - } - - self->extension = extension; - - gtk_label_set_text (GTK_LABEL (self->description_label), - description); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (active_button), - TRUE); - - g_settings_set_enum (nautilus_compression_preferences, - NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT, - format); - /* Since the extension changes when the button is toggled, force a - * verification of the new file name by simulating an entry change - */ - g_signal_emit_by_name (self->name_entry, "changed"); + const char *extension; + const char *description; + GtkWidget *active_button; + + switch (format) + { + case NAUTILUS_COMPRESSION_ZIP: + extension = ".zip"; + description = ZIP_DESCRIPTION; + active_button = self->zip_radio_button; + break; + + case NAUTILUS_COMPRESSION_TAR_XZ: + extension = ".tar.xz"; + description = TAR_XZ_DESCRIPTION; + active_button = self->tar_xz_radio_button; + break; + + case NAUTILUS_COMPRESSION_7ZIP: + extension = ".7z"; + description = SEVEN_ZIP_DESCRIPTION; + active_button = self->seven_zip_radio_button; + break; + + default: + g_assert_not_reached (); + break; + } + + self->extension = extension; + + gtk_label_set_text (GTK_LABEL (self->description_label), + description); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (active_button), + TRUE); + + g_settings_set_enum (nautilus_compression_preferences, + NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT, + format); + /* Since the extension changes when the button is toggled, force a + * verification of the new file name by simulating an entry change + */ + g_signal_emit_by_name (self->name_entry, "changed"); } static void zip_radio_button_on_toggled (GtkToggleButton *toggle_button, gpointer user_data) { - NautilusCompressDialogController *controller; + NautilusCompressDialogController *controller; - controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data); + controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data); - if (!gtk_toggle_button_get_active (toggle_button)) { - return; - } + if (!gtk_toggle_button_get_active (toggle_button)) + { + return; + } - update_selected_format (controller, - NAUTILUS_COMPRESSION_ZIP); + update_selected_format (controller, + NAUTILUS_COMPRESSION_ZIP); } static void tar_xz_radio_button_on_toggled (GtkToggleButton *toggle_button, gpointer user_data) { - NautilusCompressDialogController *controller; + NautilusCompressDialogController *controller; - controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data); + controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data); - if (!gtk_toggle_button_get_active (toggle_button)) { - return; - } + if (!gtk_toggle_button_get_active (toggle_button)) + { + return; + } - update_selected_format (controller, - NAUTILUS_COMPRESSION_TAR_XZ); + update_selected_format (controller, + NAUTILUS_COMPRESSION_TAR_XZ); } static void seven_zip_radio_button_on_toggled (GtkToggleButton *toggle_button, gpointer user_data) { - NautilusCompressDialogController *controller; + NautilusCompressDialogController *controller; - controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data); + controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data); - if (!gtk_toggle_button_get_active (toggle_button)) { - return; - } + if (!gtk_toggle_button_get_active (toggle_button)) + { + return; + } - update_selected_format (controller, - NAUTILUS_COMPRESSION_7ZIP); + update_selected_format (controller, + NAUTILUS_COMPRESSION_7ZIP); } NautilusCompressDialogController * @@ -188,110 +205,112 @@ nautilus_compress_dialog_controller_new (GtkWindow *parent_window, NautilusDirectory *destination_directory, gchar *initial_name) { - NautilusCompressDialogController *self; - g_autoptr (GtkBuilder) builder; - GtkWidget *compress_dialog; - GtkWidget *error_revealer; - GtkWidget *error_label; - GtkWidget *name_entry; - GtkWidget *activate_button; - GtkWidget *description_label; - GtkWidget *zip_radio_button; - GtkWidget *tar_xz_radio_button; - GtkWidget *seven_zip_radio_button; - NautilusCompressionFormat format; - - builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-compress-dialog.ui"); - compress_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "compress_dialog")); - error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer")); - error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label")); - name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry")); - activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "activate_button")); - zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "zip_radio_button")); - tar_xz_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "tar_xz_radio_button")); - seven_zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "seven_zip_radio_button")); - description_label = GTK_WIDGET (gtk_builder_get_object (builder, "description_label")); - - gtk_window_set_transient_for (GTK_WINDOW (compress_dialog), - parent_window); - - self = g_object_new (NAUTILUS_TYPE_COMPRESS_DIALOG_CONTROLLER, - "error-revealer", error_revealer, - "error-label", error_label, - "name-entry", name_entry, - "activate-button", activate_button, - "containing-directory", destination_directory, NULL); - - self->compress_dialog = compress_dialog; - self->zip_radio_button = zip_radio_button; - self->tar_xz_radio_button = tar_xz_radio_button; - self->seven_zip_radio_button = seven_zip_radio_button; - self->description_label = description_label; - self->name_entry = name_entry; - - self->response_handler_id = g_signal_connect (compress_dialog, - "response", - (GCallback)compress_dialog_controller_on_response, - self); - - gtk_builder_add_callback_symbols (builder, - "zip_radio_button_on_toggled", - G_CALLBACK (zip_radio_button_on_toggled), - "tar_xz_radio_button_on_toggled", - G_CALLBACK (tar_xz_radio_button_on_toggled), - "seven_zip_radio_button_on_toggled", - G_CALLBACK (seven_zip_radio_button_on_toggled), - NULL); - gtk_builder_connect_signals (builder, self); - - format = g_settings_get_enum (nautilus_compression_preferences, - NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT); - - update_selected_format (self, format); - - if (initial_name != NULL) { - gtk_entry_set_text (GTK_ENTRY (name_entry), initial_name); - } - - gtk_widget_show_all (compress_dialog); - - return self; + NautilusCompressDialogController *self; + g_autoptr (GtkBuilder) builder; + GtkWidget *compress_dialog; + GtkWidget *error_revealer; + GtkWidget *error_label; + GtkWidget *name_entry; + GtkWidget *activate_button; + GtkWidget *description_label; + GtkWidget *zip_radio_button; + GtkWidget *tar_xz_radio_button; + GtkWidget *seven_zip_radio_button; + NautilusCompressionFormat format; + + builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-compress-dialog.ui"); + compress_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "compress_dialog")); + error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer")); + error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label")); + name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry")); + activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "activate_button")); + zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "zip_radio_button")); + tar_xz_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "tar_xz_radio_button")); + seven_zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "seven_zip_radio_button")); + description_label = GTK_WIDGET (gtk_builder_get_object (builder, "description_label")); + + gtk_window_set_transient_for (GTK_WINDOW (compress_dialog), + parent_window); + + self = g_object_new (NAUTILUS_TYPE_COMPRESS_DIALOG_CONTROLLER, + "error-revealer", error_revealer, + "error-label", error_label, + "name-entry", name_entry, + "activate-button", activate_button, + "containing-directory", destination_directory, NULL); + + self->compress_dialog = compress_dialog; + self->zip_radio_button = zip_radio_button; + self->tar_xz_radio_button = tar_xz_radio_button; + self->seven_zip_radio_button = seven_zip_radio_button; + self->description_label = description_label; + self->name_entry = name_entry; + + self->response_handler_id = g_signal_connect (compress_dialog, + "response", + (GCallback) compress_dialog_controller_on_response, + self); + + gtk_builder_add_callback_symbols (builder, + "zip_radio_button_on_toggled", + G_CALLBACK (zip_radio_button_on_toggled), + "tar_xz_radio_button_on_toggled", + G_CALLBACK (tar_xz_radio_button_on_toggled), + "seven_zip_radio_button_on_toggled", + G_CALLBACK (seven_zip_radio_button_on_toggled), + NULL); + gtk_builder_connect_signals (builder, self); + + format = g_settings_get_enum (nautilus_compression_preferences, + NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT); + + update_selected_format (self, format); + + if (initial_name != NULL) + { + gtk_entry_set_text (GTK_ENTRY (name_entry), initial_name); + } + + gtk_widget_show_all (compress_dialog); + + return self; } static void nautilus_compress_dialog_controller_init (NautilusCompressDialogController *self) { - } static void nautilus_compress_dialog_controller_finalize (GObject *object) { - NautilusCompressDialogController *self; - - self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (object); - - if (self->compress_dialog != NULL) { - if (self->response_handler_id > 0) { - g_signal_handler_disconnect (self->compress_dialog, - self->response_handler_id); - self->response_handler_id = 0; - } - gtk_widget_destroy (self->compress_dialog); - self->compress_dialog = NULL; + NautilusCompressDialogController *self; + + self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (object); + + if (self->compress_dialog != NULL) + { + if (self->response_handler_id > 0) + { + g_signal_handler_disconnect (self->compress_dialog, + self->response_handler_id); + self->response_handler_id = 0; } + gtk_widget_destroy (self->compress_dialog); + self->compress_dialog = NULL; + } - G_OBJECT_CLASS (nautilus_compress_dialog_controller_parent_class)->finalize (object); + G_OBJECT_CLASS (nautilus_compress_dialog_controller_parent_class)->finalize (object); } static void nautilus_compress_dialog_controller_class_init (NautilusCompressDialogControllerClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - NautilusFileNameWidgetControllerClass *parent_class = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NautilusFileNameWidgetControllerClass *parent_class = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (klass); - object_class->finalize = nautilus_compress_dialog_controller_finalize; + object_class->finalize = nautilus_compress_dialog_controller_finalize; - parent_class->get_new_name = nautilus_compress_dialog_controller_get_new_name; - parent_class->name_is_valid = nautilus_compress_dialog_controller_name_is_valid; + parent_class->get_new_name = nautilus_compress_dialog_controller_get_new_name; + parent_class->name_is_valid = nautilus_compress_dialog_controller_name_is_valid; } |