[gthumb] Introduce the ability to shift dates by any offset



commit fe90526f62ff966cc5c7fc7804c7334c1b175314
Author: Thomas Bouffon <thomas bouffon gmail com>
Date:   Sun Nov 14 12:24:49 2010 +0100

    Introduce the ability to shift dates by any offset
    
    [bug #632298]

 extensions/change_date/data/ui/change-date.ui |  164 +++++++++++++++++++++++--
 extensions/change_date/dlg-change-date.c      |   17 ++-
 extensions/change_date/gth-change-date-task.c |   27 ++---
 extensions/change_date/gth-change-date-task.h |    4 +-
 4 files changed, 180 insertions(+), 32 deletions(-)
---
diff --git a/extensions/change_date/data/ui/change-date.ui b/extensions/change_date/data/ui/change-date.ui
index 0cff7e9..621fd3d 100644
--- a/extensions/change_date/data/ui/change-date.ui
+++ b/extensions/change_date/data/ui/change-date.ui
@@ -1,28 +1,39 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
+  <object class="GtkAdjustment" id="times_adjustment">
+    <property name="upper">59</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="timem_adjustment">
+    <property name="upper">59</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="timeh_adjustment">
+    <property name="upper">999999</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkDialog" id="change_date_dialog">
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Change Date</property>
     <property name="resizable">False</property>
     <property name="type_hint">normal</property>
-    <property name="has_separator">False</property>
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox1">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkVBox" id="vbox1">
             <property name="visible">True</property>
             <property name="border_width">5</property>
-            <property name="orientation">vertical</property>
             <property name="spacing">12</property>
             <child>
               <object class="GtkVBox" id="vbox2">
                 <property name="visible">True</property>
-                <property name="orientation">vertical</property>
                 <property name="spacing">6</property>
                 <child>
                   <object class="GtkLabel" id="label1">
@@ -45,7 +56,6 @@
                     <child>
                       <object class="GtkVBox" id="vbox57">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
                         <property name="spacing">6</property>
                         <child>
                           <object class="GtkCheckButton" id="change_last_modified_checkbutton">
@@ -107,7 +117,6 @@
             <child>
               <object class="GtkVBox" id="vbox3">
                 <property name="visible">True</property>
-                <property name="orientation">vertical</property>
                 <property name="spacing">6</property>
                 <child>
                   <object class="GtkLabel" id="label2">
@@ -130,12 +139,10 @@
                     <child>
                       <object class="GtkVBox" id="vbox48">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
                         <property name="spacing">6</property>
                         <child>
                           <object class="GtkVBox" id="vbox49">
                             <property name="visible">True</property>
-                            <property name="orientation">vertical</property>
                             <property name="spacing">6</property>
                             <child>
                               <object class="GtkRadioButton" id="to_following_date_radiobutton">
@@ -228,7 +235,6 @@
                         <child>
                           <object class="GtkVBox" id="vbox54">
                             <property name="visible">True</property>
-                            <property name="orientation">vertical</property>
                             <property name="spacing">6</property>
                             <child>
                               <object class="GtkHBox" id="hbox71">
@@ -258,7 +264,7 @@
                                       <object class="GtkSpinButton" id="adjust_timezone_spinbutton">
                                         <property name="visible">True</property>
                                         <property name="can_focus">True</property>
-                                        <property name="invisible_char">&#x25CF;</property>
+                                        <property name="invisible_char">â??</property>
                                         <property name="adjustment">timezone_adjustment</property>
                                         <property name="climb_rate">1</property>
                                         <property name="numeric">True</property>
@@ -296,6 +302,142 @@
                             <property name="position">4</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkVBox" id="vbox4">
+                            <property name="visible">True</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkHBox" id="hbox1">
+                                <property name="visible">True</property>
+                                <property name="spacing">6</property>
+                                <child>
+                                  <object class="GtkRadioButton" id="adjust_timehms_radiobutton">
+                                    <property name="label" translatable="yes">A_djust by</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="draw_indicator">True</property>
+                                    <property name="group">to_following_date_radiobutton</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkHBox" id="timehms_box">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">6</property>
+                                    <child>
+                                      <object class="GtkCheckButton" id="negative_offset">
+                                        <property name="label" translatable="yes">-</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="use_action_appearance">False</property>
+                                        <property name="draw_indicator">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkSpinButton" id="adjust_timeh_spinbutton">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="invisible_char">â??</property>
+                                        <property name="invisible_char_set">True</property>
+                                        <property name="adjustment">timeh_adjustment</property>
+                                        <property name="climb_rate">1</property>
+                                        <property name="numeric">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label3">
+                                        <property name="visible">True</property>
+                                        <property name="label" translatable="yes">h</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkSpinButton" id="adjust_timem_spinbutton">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="invisible_char">â??</property>
+                                        <property name="invisible_char_set">True</property>
+                                        <property name="adjustment">timem_adjustment</property>
+                                        <property name="climb_rate">1</property>
+                                        <property name="numeric">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">3</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label4">
+                                        <property name="visible">True</property>
+                                        <property name="label" translatable="yes">m</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">4</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkSpinButton" id="adjust_times_spinbutton">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="invisible_char">â??</property>
+                                        <property name="invisible_char_set">True</property>
+                                        <property name="adjustment">times_adjustment</property>
+                                        <property name="climb_rate">1</property>
+                                        <property name="numeric">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">5</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label5">
+                                        <property name="visible">True</property>
+                                        <property name="label" translatable="yes">s</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">6</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">5</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                   </object>
diff --git a/extensions/change_date/dlg-change-date.c b/extensions/change_date/dlg-change-date.c
index f638454..98993f5 100644
--- a/extensions/change_date/dlg-change-date.c
+++ b/extensions/change_date/dlg-change-date.c
@@ -27,6 +27,8 @@
 
 #define GET_WIDGET(x) (_gtk_builder_get_widget (data->builder, (x)))
 #define IS_ACTIVE(x) (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (x)))
+#define HOURS_TO_SECONDS(h) ((h) * 3600)
+#define MINS_TO_SECONDS(h) ((h) * 60)
 
 
 typedef struct {
@@ -82,10 +84,12 @@ ok_button_clicked (GtkWidget  *button,
 	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_timezone_radiobutton"))) {
-		change_type = GTH_CHANGE_ADJUST_TIMEZONE;
-		time_adjustment = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_timezone_spinbutton")));
-	}
-
+		change_type = GTH_CHANGE_ADJUST_TIME;
+		time_adjustment = HOURS_TO_SECONDS(gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_timezone_spinbutton"))));}
+	else if (IS_ACTIVE (GET_WIDGET ("adjust_timehms_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_timeh_spinbutton")))) + MINS_TO_SECONDS(gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_timem_spinbutton")))) + gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("adjust_times_spinbutton")));
+   if (IS_ACTIVE (GET_WIDGET ("negative_offset"))) { time_adjustment =-time_adjustment;}}
 	task = gth_change_date_task_new (gth_browser_get_location (data->browser),
 					 data->file_list,
 					 change_fields,
@@ -117,6 +121,7 @@ update_sensitivity (DialogData *data)
 				   || IS_ACTIVE (GET_WIDGET ("change_datetimeoriginal_checkbutton"))));
 	gtk_widget_set_sensitive (data->date_selector, IS_ACTIVE (GET_WIDGET ("to_following_date_radiobutton")));
 	gtk_widget_set_sensitive (GET_WIDGET ("timezone_box"), IS_ACTIVE (GET_WIDGET ("adjust_timezone_radiobutton")));
+	gtk_widget_set_sensitive (GET_WIDGET ("timehms_box"), IS_ACTIVE (GET_WIDGET ("adjust_timehms_radiobutton")));
 
 	if (IS_ACTIVE (GET_WIDGET ("change_last_modified_checkbutton"))) {
 		gtk_widget_set_sensitive (GET_WIDGET ("to_last_modified_date_radiobutton"), FALSE);
@@ -218,6 +223,10 @@ dlg_change_date (GthBrowser *browser,
 			  "clicked",
 			  G_CALLBACK (radio_button_clicked),
 			  data);
+	g_signal_connect (GET_WIDGET ("adjust_timehms_radiobutton"),
+			  "clicked",
+			  G_CALLBACK (radio_button_clicked),
+			  data);
 
 	/* run dialog. */
 
diff --git a/extensions/change_date/gth-change-date-task.c b/extensions/change_date/gth-change-date-task.c
index 57125e6..58dc3c6 100644
--- a/extensions/change_date/gth-change-date-task.c
+++ b/extensions/change_date/gth-change-date-task.c
@@ -23,9 +23,6 @@
 #include "gth-change-date-task.h"
 
 
-#define HOURS_TO_SECONDS(h) ((h) * 3600)
-
-
 struct _GthChangeDateTaskPrivate {
 	GFile           *location;
 	GList           *files; /* GFile */
@@ -33,7 +30,7 @@ struct _GthChangeDateTaskPrivate {
 	GthChangeFields  fields;
 	GthChangeType    change_type;
 	GthDateTime     *date_time;
-	int              timezone_offset;
+	int              time_offset;
 	int              n_files;
 	int              n_current;
 	GList           *current;
@@ -101,7 +98,7 @@ update_modification_time (GthChangeDateTask *self)
 			GTimeVal     timeval;
 
 			gth_datetime_clear (date_time);
-			if (self->priv->change_type == GTH_CHANGE_ADJUST_TIMEZONE)
+			if (self->priv->change_type == GTH_CHANGE_ADJUST_TIME)
 				set_date_time_from_change_type (self, date_time, GTH_CHANGE_TO_FILE_MODIFIED_DATE, file_data);
 			else
 				set_date_time_from_change_type (self, date_time, self->priv->change_type, file_data);
@@ -125,8 +122,8 @@ update_modification_time (GthChangeDateTask *self)
 				continue;
 
 			if (gth_datetime_to_timeval (date_time, &timeval)) {
-				if (self->priv->change_type == GTH_CHANGE_ADJUST_TIMEZONE)
-					timeval.tv_sec += HOURS_TO_SECONDS (self->priv->timezone_offset);
+				if (self->priv->change_type == GTH_CHANGE_ADJUST_TIME)
+					timeval.tv_sec += self->priv->time_offset;
 				if (! _g_file_set_modification_time (file_data->file,
 								     &timeval,
 								     gth_task_get_cancellable (GTH_TASK (self)),
@@ -174,18 +171,18 @@ static void
 set_date_metadata (GthFileData *file_data,
 		   const char  *attribute,
 		   GthDateTime *date_time,
-		   int          timezone_offset)
+		   int          time_offset)
 {
 	GthDateTime *new_date_time;
 
 	new_date_time = gth_datetime_new ();
 	gth_datetime_copy (date_time, new_date_time);
 
-	if (timezone_offset != 0) {
+	if (time_offset != 0) {
 		GTimeVal timeval;
 
 		gth_datetime_to_timeval (new_date_time, &timeval);
-		timeval.tv_sec += HOURS_TO_SECONDS (timezone_offset);
+		timeval.tv_sec += time_offset;
 		gth_datetime_from_timeval (new_date_time, &timeval);
 	}
 	else {
@@ -285,18 +282,18 @@ info_ready_cb (GList    *files,
 	for (scan = self->priv->file_list; scan; scan = scan->next) {
 		GthFileData *file_data = scan->data;
 
-		if (self->priv->change_type == GTH_CHANGE_ADJUST_TIMEZONE) {
+		if (self->priv->change_type == GTH_CHANGE_ADJUST_TIME) {
 			if (self->priv->fields & GTH_CHANGE_COMMENT_DATE) {
 				gth_datetime_clear (date_time);
 				set_date_time_from_field (self, date_time, GTH_CHANGE_COMMENT_DATE, file_data);
 				if (gth_datetime_valid (date_time))
-					set_date_metadata (file_data, "general::datetime", date_time, self->priv->timezone_offset);
+					set_date_metadata (file_data, "general::datetime", date_time, self->priv->time_offset);
 			}
 			if (self->priv->fields & GTH_CHANGE_EXIF_DATETIMEORIGINAL_TAG) {
 				gth_datetime_clear (date_time);
 				set_date_time_from_field (self, date_time, GTH_CHANGE_EXIF_DATETIMEORIGINAL_TAG, file_data);
 				if (gth_datetime_valid (date_time))
-					set_date_metadata (file_data, "Exif::Photo::DateTimeOriginal", date_time, self->priv->timezone_offset);
+					set_date_metadata (file_data, "Exif::Photo::DateTimeOriginal", date_time, self->priv->time_offset);
 			}
 		}
 		else {
@@ -412,7 +409,7 @@ gth_change_date_task_new (GFile             *location,
 			  GthChangeFields    fields,
 			  GthChangeType      change_type,
 			  GthDateTime       *date_time,
-			  int                timezone_offset)
+			  int                time_offset)
 {
 	GthChangeDateTask *self;
 
@@ -423,7 +420,7 @@ gth_change_date_task_new (GFile             *location,
 	self->priv->change_type = change_type;
 	if (date_time != NULL)
 		gth_datetime_copy (date_time, self->priv->date_time);
-	self->priv->timezone_offset = timezone_offset;
+	self->priv->time_offset = time_offset;
 
 	return (GthTask *) self;
 }
diff --git a/extensions/change_date/gth-change-date-task.h b/extensions/change_date/gth-change-date-task.h
index bb50400..879dad3 100644
--- a/extensions/change_date/gth-change-date-task.h
+++ b/extensions/change_date/gth-change-date-task.h
@@ -38,7 +38,7 @@ typedef enum {
 	GTH_CHANGE_TO_FILE_MODIFIED_DATE,
 	GTH_CHANGE_TO_FILE_CREATION_DATE,
 	GTH_CHANGE_TO_PHOTO_ORIGINAL_DATE,
-	GTH_CHANGE_ADJUST_TIMEZONE
+	GTH_CHANGE_ADJUST_TIME
 } GthChangeType;
 
 #define GTH_TYPE_CHANGE_DATE_TASK            (gth_change_date_task_get_type ())
@@ -67,7 +67,7 @@ GthTask *     gth_change_date_task_new       (GFile             *location,
 					      GthChangeFields    fields,
 					      GthChangeType      change_type,
 					      GthDateTime       *date_time,
-					      int                timezone_offset);
+					      int                time_offset);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]