gboolean gth_time_selector_real_focus (GtkWidget *base, GtkDirectionType direction) { GthTimeSelector *self = GTH_TIME_SELECTOR (base); gtk_widget_grab_focus (self->priv->date_entry); return TRUE; }
void dlg_catalog_properties (GthBrowser *browser, GthFileData *file_data) { DialogData *data; g_return_if_fail (file_data != NULL); data = g_new0 (DialogData, 1); data->browser = browser; data->file_data = gth_file_data_dup (file_data); data->original_file = g_file_dup (data->file_data->file); data->builder = _gtk_builder_new_from_file ("catalog-properties.ui", "catalogs"); /* Set widgets data. */ data->dialog = g_object_new (GTK_TYPE_DIALOG, "title", _("Properties"), "transient-for", GTK_WINDOW (browser), "modal", TRUE, "destroy-with-parent", FALSE, "use-header-bar", _gtk_settings_get_dialogs_use_header (), NULL); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))), _gtk_builder_get_widget (data->builder, "dialog_content")); gtk_dialog_add_buttons (GTK_DIALOG (data->dialog), _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL, _GTK_LABEL_SAVE, GTK_RESPONSE_OK, NULL); _gtk_dialog_add_class_to_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, GTK_STYLE_CLASS_SUGGESTED_ACTION); data->time_selector = gth_time_selector_new (); gth_time_selector_show_time (GTH_TIME_SELECTOR (data->time_selector), FALSE, FALSE); gtk_widget_show (data->time_selector); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("date_container_box")), data->time_selector, TRUE, TRUE, 0); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (destroy_cb), data); g_signal_connect (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK), "clicked", G_CALLBACK (save_button_clicked_cb), data); g_signal_connect_swapped (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_CANCEL), "clicked", G_CALLBACK (gtk_widget_destroy), data->dialog); /* run dialog. */ gtk_widget_grab_focus (GET_WIDGET ("name_entry")); gth_catalog_load_from_file_async (file_data->file, NULL, catalog_ready_cb, data); }
static void gth_time_selector_unmap (GtkWidget *widget) { GthTimeSelector *self; self = GTH_TIME_SELECTOR (widget); _gth_time_selector_ungrab_devices (self, GDK_CURRENT_TIME); GTK_WIDGET_CLASS (gth_time_selector_parent_class)->unmap (widget); }
static void save_button_clicked_cb (GtkButton *button, DialogData *data) { GthDateTime *date_time; GFile *gio_file; char *buffer; gsize size; if (strcmp (gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry"))), "") != 0) { GFile *parent; char *uri; char *clean_name; char *display_name; GFile *new_file; parent = g_file_get_parent (data->original_file); uri = g_file_get_uri (data->original_file); clean_name = _g_filename_clear_for_file (gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry")))); display_name = g_strconcat (clean_name, _g_uri_get_file_extension (uri), NULL); new_file = g_file_get_child_for_display_name (parent, display_name, NULL); if ((new_file != NULL) && ! g_file_equal (new_file, data->original_file)) gth_file_data_set_file (data->file_data, new_file); _g_object_unref (new_file); g_free (display_name); g_free (clean_name); g_free (uri); g_object_unref (parent); } gth_catalog_set_name (data->catalog, gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry")))); date_time = gth_datetime_new (); gth_time_selector_get_value (GTH_TIME_SELECTOR (data->time_selector), date_time); gth_catalog_set_date (data->catalog, date_time); gth_datetime_free (date_time); /* invoke the hook to save derived catalogs such as searches */ gth_hook_invoke ("dlg-catalog-properties-save", data->builder, data->file_data, data->catalog); gio_file = gth_catalog_file_to_gio_file (data->file_data->file); buffer = gth_catalog_to_data (data->catalog, &size); _g_file_write_async (gio_file, buffer, size, TRUE, G_PRIORITY_DEFAULT, NULL, catalog_saved_cb, data); g_object_unref (gio_file); }
static void gth_time_selector_finalize (GObject *object) { GthTimeSelector *self; self = GTH_TIME_SELECTOR (object); gtk_widget_destroy (self->priv->calendar_popup); gth_datetime_free (self->priv->date_time); G_OBJECT_CLASS (gth_time_selector_parent_class)->finalize (object); }
void dlg_catalog_properties (GthBrowser *browser, GthFileData *file_data) { DialogData *data; g_return_if_fail (file_data != NULL); data = g_new0 (DialogData, 1); data->browser = browser; data->file_data = gth_file_data_dup (file_data); data->original_file = g_file_dup (data->file_data->file); data->builder = _gtk_builder_new_from_file ("catalog-properties.ui", "catalogs"); data->dialog = GET_WIDGET ("properties_dialog"); /* Set widgets data. */ data->time_selector = gth_time_selector_new (); gth_time_selector_show_time (GTH_TIME_SELECTOR (data->time_selector), FALSE, FALSE); gtk_widget_show (data->time_selector); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("date_container_box")), data->time_selector, TRUE, TRUE, 0); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (destroy_cb), data); g_signal_connect (G_OBJECT (GET_WIDGET ("save_button")), "clicked", G_CALLBACK (save_button_clicked_cb), data); g_signal_connect_swapped (G_OBJECT (GET_WIDGET ("cancel_button")), "clicked", G_CALLBACK (gtk_widget_destroy), data->dialog); g_signal_connect (G_OBJECT (GET_WIDGET ("help_button")), "clicked", G_CALLBACK (help_button_clicked_cb), data); /* run dialog. */ gtk_widget_grab_focus (GET_WIDGET ("name_entry")); gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE); gth_catalog_load_from_file_async (file_data->file, NULL, catalog_ready_cb, data); }
static void catalog_ready_cb (GObject *object, GError *error, gpointer user_data) { DialogData *data = user_data; if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW(data->browser), _("Could not load the catalog"), error); gtk_widget_destroy (data->dialog); return; } data->catalog = g_object_ref (object); if (gth_catalog_get_name (data->catalog) != NULL) { gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), gth_catalog_get_name (data->catalog)); } else if (! gth_datetime_valid_date (gth_catalog_get_date (data->catalog))) { char *basename; char *name; char *utf8_name; basename = g_file_get_basename (data->file_data->file); name = _g_uri_remove_extension (basename); utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), utf8_name); g_free (utf8_name); g_free (name); g_free (basename); } gth_time_selector_set_value (GTH_TIME_SELECTOR (data->time_selector), gth_catalog_get_date (data->catalog)); gth_hook_invoke ("dlg-catalog-properties", data->builder, data->file_data, data->catalog); gtk_widget_show (data->dialog); g_object_unref (object); }
static void ok_button_clicked (GtkWidget *button, DialogData *data) { GthChangeFields change_fields; GthChangeType change_type; GthDateTime *date_time; int time_adjustment; GthTask *task; date_time = NULL; change_fields = 0; if (IS_ACTIVE (GET_WIDGET ("change_last_modified_checkbutton"))) change_fields |= GTH_CHANGE_LAST_MODIFIED_DATE; if (IS_ACTIVE (GET_WIDGET ("change_comment_checkbutton"))) change_fields |= GTH_CHANGE_COMMENT_DATE; change_type = 0; time_adjustment = 0; if (IS_ACTIVE (GET_WIDGET ("to_following_date_radiobutton"))) { change_type = GTH_CHANGE_TO_FOLLOWING_DATE; date_time = gth_datetime_new (); gth_time_selector_get_value (GTH_TIME_SELECTOR (data->date_selector), date_time); } else if (IS_ACTIVE (GET_WIDGET ("to_last_modified_date_radiobutton"))) change_type = GTH_CHANGE_TO_FILE_MODIFIED_DATE; else if (IS_ACTIVE (GET_WIDGET ("to_creation_date_radiobutton"))) change_type = GTH_CHANGE_TO_FILE_CREATION_DATE; else if (IS_ACTIVE (GET_WIDGET ("to_photo_original_date_radiobutton"))) change_type = GTH_CHANGE_TO_PHOTO_ORIGINAL_DATE; else if (IS_ACTIVE (GET_WIDGET ("adjust_time_radiobutton"))) { change_type = GTH_CHANGE_ADJUST_TIME; time_adjustment = (HOURS_TO_SECONDS (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_time_h_spinbutton")))) + MINS_TO_SECONDS (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_time_m_spinbutton")))) + gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_time_s_spinbutton")))); if (gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("adjust_sign_combobox"))) == 1) time_adjustment = -time_adjustment; } /* save the preferences */ g_settings_set_boolean (data->settings, PREF_CHANGE_DATE_SET_LAST_MODIFIED_DATE, (change_fields & GTH_CHANGE_LAST_MODIFIED_DATE) == GTH_CHANGE_LAST_MODIFIED_DATE); g_settings_set_boolean (data->settings, PREF_CHANGE_DATE_SET_COMMENT_DATE, (change_fields & GTH_CHANGE_COMMENT_DATE) == GTH_CHANGE_COMMENT_DATE); g_settings_set_boolean (data->settings, PREF_CHANGE_DATE_TO_FOLLOWING_DATE, change_type == GTH_CHANGE_TO_FOLLOWING_DATE); if (change_type == GTH_CHANGE_TO_FOLLOWING_DATE) { char *s; s = gth_datetime_to_exif_date (date_time); g_settings_set_string (data->settings, PREF_CHANGE_DATE_DATE, s); g_free (s); } g_settings_set_boolean (data->settings, PREF_CHANGE_DATE_TO_FILE_MODIFIED_DATE, change_type == GTH_CHANGE_TO_FILE_MODIFIED_DATE); g_settings_set_boolean (data->settings, PREF_CHANGE_DATE_TO_FILE_CREATION_DATE, change_type == GTH_CHANGE_TO_FILE_CREATION_DATE); g_settings_set_boolean (data->settings, PREF_CHANGE_DATE_TO_PHOTO_ORIGINAL_DATE, change_type == GTH_CHANGE_TO_PHOTO_ORIGINAL_DATE); g_settings_set_boolean (data->settings, PREF_CHANGE_DATE_ADJUST_TIME, change_type == GTH_CHANGE_ADJUST_TIME); if (change_type == GTH_CHANGE_ADJUST_TIME) g_settings_set_int (data->settings, PREF_CHANGE_DATE_TIME_ADJUSTMENT, time_adjustment); /* exec the task */ task = gth_change_date_task_new (gth_browser_get_location (data->browser), data->file_list, change_fields, change_type, date_time, time_adjustment); gth_browser_exec_task (data->browser, task, FALSE); gtk_widget_destroy (data->dialog); g_object_unref (task); gth_datetime_free (date_time); }
void dlg_change_date (GthBrowser *browser, GList *file_list) { DialogData *data; GTimeVal timeval; GthDateTime *datetime; data = g_new0 (DialogData, 1); data->browser = browser; data->file_list = _g_object_list_ref (file_list); data->builder = _gtk_builder_new_from_file ("change-date.ui", "change_date"); data->settings = g_settings_new (GTHUMB_CHANGE_DATE_SCHEMA); /* Get the widgets. */ data->dialog = GET_WIDGET ("change_date_dialog"); data->date_selector = gth_time_selector_new (); gth_time_selector_show_time (GTH_TIME_SELECTOR (data->date_selector), TRUE, TRUE); gtk_widget_show (data->date_selector); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("date_selector_box")), data->date_selector, TRUE, TRUE, 0); /* Set widgets data. */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("change_last_modified_checkbutton")), g_settings_get_boolean (data->settings, PREF_CHANGE_DATE_SET_LAST_MODIFIED_DATE)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("change_comment_checkbutton")), g_settings_get_boolean (data->settings, PREF_CHANGE_DATE_SET_COMMENT_DATE)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("to_following_date_radiobutton")), g_settings_get_boolean (data->settings, PREF_CHANGE_DATE_TO_FOLLOWING_DATE)); datetime = gth_datetime_new (); g_get_current_time (&timeval); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("to_following_date_radiobutton")))) { char *s; s = g_settings_get_string (data->settings, PREF_CHANGE_DATE_DATE); if (strcmp (s, "") != 0) gth_datetime_from_exif_date (datetime, s); else gth_datetime_from_timeval (datetime, &timeval); g_free (s); } else gth_datetime_from_timeval (datetime, &timeval); gth_time_selector_set_value (GTH_TIME_SELECTOR (data->date_selector), datetime); gth_datetime_free (datetime); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("to_last_modified_date_radiobutton")), g_settings_get_boolean (data->settings, PREF_CHANGE_DATE_TO_FILE_MODIFIED_DATE)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("to_creation_date_radiobutton")), g_settings_get_boolean (data->settings, PREF_CHANGE_DATE_TO_FILE_CREATION_DATE)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("to_photo_original_date_radiobutton")), g_settings_get_boolean (data->settings, PREF_CHANGE_DATE_TO_PHOTO_ORIGINAL_DATE)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("adjust_time_radiobutton")), g_settings_get_boolean (data->settings, PREF_CHANGE_DATE_ADJUST_TIME)); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("adjust_time_radiobutton")))) { int adjustement; int sign; int hours; int minutes; int seconds; adjustement = g_settings_get_int (data->settings, PREF_CHANGE_DATE_TIME_ADJUSTMENT); if (adjustement < 0) { sign = -1; adjustement = - adjustement; } else sign = 1; hours = adjustement / 3600; adjustement = adjustement % 3600; minutes = adjustement / 60; adjustement = adjustement % 60; seconds = adjustement; gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_time_h_spinbutton")), hours); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_time_m_spinbutton")), minutes); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_time_s_spinbutton")), seconds); gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("adjust_sign_combobox")), (sign >= 0) ? 0 : 1); } update_sensitivity (data); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (dialog_destroy_cb), data); g_signal_connect_swapped (GET_WIDGET ("close_button"), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (data->dialog)); g_signal_connect (GET_WIDGET ("ok_button"), "clicked", G_CALLBACK (ok_button_clicked), data); g_signal_connect (GET_WIDGET ("change_last_modified_checkbutton"), "clicked", G_CALLBACK (radio_button_clicked), data); g_signal_connect (GET_WIDGET ("change_comment_checkbutton"), "clicked", G_CALLBACK (radio_button_clicked), data); g_signal_connect (GET_WIDGET ("to_following_date_radiobutton"), "clicked", G_CALLBACK (radio_button_clicked), data); g_signal_connect (GET_WIDGET ("to_last_modified_date_radiobutton"), "clicked", G_CALLBACK (radio_button_clicked), data); g_signal_connect (GET_WIDGET ("to_creation_date_radiobutton"), "clicked", G_CALLBACK (radio_button_clicked), data); g_signal_connect (GET_WIDGET ("to_photo_original_date_radiobutton"), "clicked", G_CALLBACK (radio_button_clicked), data); g_signal_connect (GET_WIDGET ("adjust_time_radiobutton"), "clicked", G_CALLBACK (radio_button_clicked), data); /* run dialog. */ gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_widget_show (data->dialog); }