Re: date format in list view



On Don, 2004-07-15 at 09:48 +0200, Alexander Larsson wrote:
> On Wed, 2004-07-14 at 23:55, Raul Acevedo wrote:
> > In list view, the date format takes up way too much space, and because
> > it uses whole words for week day and month names, it's also actually
> > harder to read at a glance.  I know that sounds counter-intuitive, but
> > it's easier to visually parse a list of dates when they are in shorter
> > format that looks more like fixed width fields.
> > 
> > Is there a way to change this?  Ideally either Nautilus would
> > automatically use a format like "mm/dd/yyyy hh:mi", or I could configure
> > it via the List View tab in Preferences or even a GConf key that allows
> > me to enter the raw format string.
> 
> There is no way currently, but having a date format preference is
> probably the right thing to do here. And we should probably change the
> default setting to be more 'regular'.

Attached is a patch that adds a preference for the date format. One can
choose between '%c' ('the preferred representation for the current
locale'), iso-style (%Y-%m-%d %H:%M:%S) and the current format. The
patch changes the default format to '%c'.

-- 
Jürg Billeter <j bitron ch>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.6225
diff -u -r1.6225 ChangeLog
--- ChangeLog	7 Jul 2004 14:06:34 -0000	1.6225
+++ ChangeLog	15 Jul 2004 18:16:18 -0000
@@ -1,3 +1,17 @@
+2004-07-15  Jürg Billeter  <j bitron ch>
+
+	* libnautilus-private/apps_nautilus_preferences.schemas.in:
+	* libnautilus-private/nautilus-directory.c: (add_preferences_callbacks):
+	* libnautilus-private/nautilus-file.c: (date_format_changed_callback),
+	(nautilus_file_fit_date_as_string):
+	* libnautilus-private/nautilus-global-preferences.c:
+	* libnautilus-private/nautilus-global-preferences.h:
+	* src/nautilus-file-management-properties.c: (create_date_format_menu),
+	(nautilus_file_management_properties_dialog_setup):
+	* src/nautilus-file-management-properties.glade:
+	Add preference to choose date format. Set default date format to '%c',
+	'the preferred representation for the current locale'.
+
 2004-07-07  Alexander Larsson  <alexl redhat com>
 
 	* libnautilus-private/nautilus-file-operations.c (handle_transfer_overwrite):
Index: libnautilus-private/apps_nautilus_preferences.schemas.in
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/apps_nautilus_preferences.schemas.in,v
retrieving revision 1.18
diff -u -r1.18 apps_nautilus_preferences.schemas.in
--- libnautilus-private/apps_nautilus_preferences.schemas.in	14 May 2004 09:34:07 -0000	1.18
+++ libnautilus-private/apps_nautilus_preferences.schemas.in	15 Jul 2004 18:16:20 -0000
@@ -629,6 +629,21 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/nautilus/preferences/date_format</key>
+      <applyto>/apps/nautilus/preferences/date_format</applyto>
+      <owner>nautilus</owner>
+      <type>string</type>
+      <default>locale</default>
+      <locale name="C">
+         <short>Date Format</short>
+         <long>
+             The format of file dates. Possible values are "locale",
+             "iso", and "informal".
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/nautilus/preferences/hide_built_in_bookmarks</key>
       <applyto>/apps/nautilus/preferences/hide_built_in_bookmarks</applyto>
       <owner>nautilus</owner>
Index: libnautilus-private/nautilus-directory.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory.c,v
retrieving revision 1.252
diff -u -r1.252 nautilus-directory.c
--- libnautilus-private/nautilus-directory.c	11 Jan 2004 20:34:17 -0000	1.252
+++ libnautilus-private/nautilus-directory.c	15 Jul 2004 18:16:21 -0000
@@ -304,6 +304,9 @@
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
 				      async_data_preference_changed_callback,
 				      NULL);
+	eel_preferences_add_callback (NAUTILUS_PREFERENCES_DATE_FORMAT,
+				      async_data_preference_changed_callback,
+				      NULL);
 }
 
 char *
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.345
diff -u -r1.345 nautilus-file.c
--- libnautilus-private/nautilus-file.c	31 Mar 2004 09:24:55 -0000	1.345
+++ libnautilus-private/nautilus-file.c	15 Jul 2004 18:16:24 -0000
@@ -2993,6 +2993,14 @@
 	NULL
 };
 
+static NautilusDateFormat date_format;
+
+static void
+date_format_changed_callback (gpointer callback_data)
+{
+	date_format = eel_preferences_get_enum (NAUTILUS_PREFERENCES_DATE_FORMAT);
+}
+
 static char *
 nautilus_file_fit_date_as_string (NautilusFile *file,
 				  NautilusDateType date_type,
@@ -3012,12 +3020,31 @@
 	GDate *file_date;
 	guint32 file_date_age;
 	int i;
+	static gboolean date_format_callback_added = FALSE;
 
 	if (!nautilus_file_get_date (file, date_type, &file_time_raw)) {
 		return NULL;
 	}
 
+	/* Add the callback once for the life of our process */
+	if (!date_format_callback_added) {
+		eel_preferences_add_callback (NAUTILUS_PREFERENCES_DATE_FORMAT,
+						   date_format_changed_callback,
+						   NULL);
+		date_format_callback_added = TRUE;
+
+		/* Peek for the first time */
+		date_format_changed_callback (NULL);
+	}
+
 	file_time = localtime (&file_time_raw);
+
+	if (date_format == NAUTILUS_DATE_FORMAT_LOCALE) {
+		return eel_strdup_strftime ("%c", file_time);
+	} else if (date_format == NAUTILUS_DATE_FORMAT_ISO) {
+		return eel_strdup_strftime ("%Y-%m-%d %H:%M:%S", file_time);
+	}
+	
 	file_date = eel_g_date_new_tm (file_time);
 	
 	today = g_date_new ();
Index: libnautilus-private/nautilus-global-preferences.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-global-preferences.c,v
retrieving revision 1.215
diff -u -r1.215 nautilus-global-preferences.c
--- libnautilus-private/nautilus-global-preferences.c	20 Feb 2004 10:33:46 -0000	1.215
+++ libnautilus-private/nautilus-global-preferences.c	15 Jul 2004 18:16:25 -0000
@@ -204,6 +204,13 @@
 	{ NULL }
 };
 
+static EelEnumerationEntry date_format_entries[] = {
+	{ "locale",	   "Locale Default",	NAUTILUS_DATE_FORMAT_LOCALE },
+	{ "iso",	   "ISO Format",	NAUTILUS_DATE_FORMAT_ISO },
+	{ "informal",	   "Informal",		NAUTILUS_DATE_FORMAT_INFORMAL },
+	{ NULL }
+};
+
 /* These enumerations are used in the preferences dialog to 
  * populate widgets and route preferences changes between the
  * storage (GConf) and the displayed values.
@@ -218,6 +225,7 @@
 	{ "search_bar_type",		   search_bar_type_enum_entries },
 	{ "speed_tradeoff",		   speed_tradeoff_enum_entries },
 	{ "standard_font_size",		   standard_font_size_entries },
+	{ "date_format",		   date_format_entries },
 	{ NULL }
 };
 
@@ -403,6 +411,12 @@
 	  PREFERENCE_BOOLEAN,
 	  GINT_TO_POINTER (TRUE)
 	},
+	{ NAUTILUS_PREFERENCES_DATE_FORMAT,
+	  PREFERENCE_STRING,
+	  "locale",
+	  NULL, NULL,
+	  "date_format"
+	},
 
 	/* Home URI */
 	{ NAUTILUS_PREFERENCES_HOME_URI,
Index: libnautilus-private/nautilus-global-preferences.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-global-preferences.h,v
retrieving revision 1.123
diff -u -r1.123 nautilus-global-preferences.h
--- libnautilus-private/nautilus-global-preferences.h	14 May 2004 09:34:07 -0000	1.123
+++ libnautilus-private/nautilus-global-preferences.h	15 Jul 2004 18:16:25 -0000
@@ -59,6 +59,14 @@
 #define NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES  		"/desktop/gnome/file_views/show_hidden_files"
 #define NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES  		"/desktop/gnome/file_views/show_backup_files"
 #define NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS			"preferences/show_special_flags"
+#define NAUTILUS_PREFERENCES_DATE_FORMAT			"preferences/date_format"
+
+typedef enum
+{
+	NAUTILUS_DATE_FORMAT_LOCALE,
+	NAUTILUS_DATE_FORMAT_ISO,
+	NAUTILUS_DATE_FORMAT_INFORMAL
+} NautilusDateFormat;
 
 /* Sidebar panels  */
 #define NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES         "sidebar_panels/tree/show_only_directories"
Index: src/nautilus-file-management-properties.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-file-management-properties.c,v
retrieving revision 1.15
diff -u -r1.15 nautilus-file-management-properties.c
--- src/nautilus-file-management-properties.c	1 Jun 2004 19:54:26 -0000	1.15
+++ src/nautilus-file-management-properties.c	15 Jul 2004 18:16:26 -0000
@@ -27,6 +27,7 @@
 #include "nautilus-file-management-properties.h"
 
 #include <string.h>
+#include <time.h>
 #include <gtk/gtkdialog.h>
 #include <gtk/gtkmenu.h>
 #include <gtk/gtkmenuitem.h>
@@ -55,6 +56,7 @@
 #define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_ICON_VIEW_ZOOM_WIDGET "iconview_zoom_optionmenu"
 #define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_LIST_VIEW_ZOOM_WIDGET "listview_zoom_optionmenu"
 #define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_SORT_ORDER_WIDGET "sort_order_optionmenu"
+#define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_DATE_FORMAT_WIDGET "date_format_optionmenu"
 #define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_TEXT_WIDGET "preview_text_optionmenu"
 #define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_IMAGE_WIDGET "preview_image_optionmenu"
 #define NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_SOUND_WIDGET "preview_sound_optionmenu"
@@ -100,6 +102,13 @@
 	NULL
 };
 
+static const char *date_format_values[] = {
+	"locale",
+	"iso",
+	"informal",
+	NULL
+};
+
 static const char *preview_values[] = {
 	"always",
 	"local_only",
@@ -454,6 +463,43 @@
 }
 
 static void
+create_date_format_menu (GladeXML *xml_dialog)
+{
+	GtkWidget *option_menu;
+	GtkWidget *menu;
+	GtkWidget *menu_item;
+	gchar *date_string;
+	time_t now_raw;
+	struct tm* now;
+	option_menu = glade_xml_get_widget (xml_dialog,
+					    NAUTILUS_FILE_MANAGEMENT_PROPERTIES_DATE_FORMAT_WIDGET);
+	menu = gtk_menu_new ();
+
+	now_raw = time (NULL);
+	now = localtime (&now_raw);
+
+	date_string = eel_strdup_strftime ("%c", now);
+	menu_item = gtk_menu_item_new_with_label (date_string);
+	g_free (date_string);
+	gtk_widget_show (menu_item);
+	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+	date_string = eel_strdup_strftime ("%Y-%m-%d %H:%M:%S", now);
+	menu_item = gtk_menu_item_new_with_label (date_string);
+	g_free (date_string);
+	gtk_widget_show (menu_item);
+	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+	date_string = eel_strdup_strftime (N_("today at %-I:%M:%S %p"), now);
+	menu_item = gtk_menu_item_new_with_label (date_string);
+	g_free (date_string);
+	gtk_widget_show (menu_item);
+	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+	gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
+}
+
+static void
 set_columns_from_gconf (NautilusColumnChooser *chooser)
 {
 	GList *visible_columns;
@@ -525,6 +571,7 @@
 	nautilus_file_management_properties_size_group_create (xml_dialog,
 							       "preview_label",
 							       5);
+	create_date_format_menu (xml_dialog);
 
 	/* setup preferences */
 	eel_preferences_glade_connect_bool (xml_dialog,
@@ -590,6 +637,10 @@
 							       NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_FOLDER_WIDGET,
 							       NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
 							       preview_values);
+	eel_preferences_glade_connect_string_enum_option_menu (xml_dialog,
+							       NAUTILUS_FILE_MANAGEMENT_PROPERTIES_DATE_FORMAT_WIDGET,
+							       NAUTILUS_PREFERENCES_DATE_FORMAT,
+							       date_format_values);
 
 	eel_preferences_glade_connect_string_enum_radio_button (xml_dialog,
 								click_behavior_components,
Index: src/nautilus-file-management-properties.glade
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-file-management-properties.glade,v
retrieving revision 1.12
diff -u -r1.12 nautilus-file-management-properties.glade
--- src/nautilus-file-management-properties.glade	1 Jun 2004 19:54:26 -0000	1.12
+++ src/nautilus-file-management-properties.glade	15 Jul 2004 18:16:28 -0000
@@ -1841,6 +1841,151 @@
 		  <property name="fill">True</property>
 		</packing>
 	      </child>
+
+	      <child>
+		<widget class="GtkVBox" id="vbox31">
+		  <property name="visible">True</property>
+		  <property name="homogeneous">False</property>
+		  <property name="spacing">6</property>
+
+		  <child>
+		    <widget class="GtkLabel" id="label34">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">&lt;span weight=&quot;bold&quot;&gt;Date&lt;/span&gt;</property>
+		      <property name="use_underline">False</property>
+		      <property name="use_markup">True</property>
+		      <property name="justify">GTK_JUSTIFY_LEFT</property>
+		      <property name="wrap">False</property>
+		      <property name="selectable">False</property>
+		      <property name="xalign">0</property>
+		      <property name="yalign">0.5</property>
+		      <property name="xpad">0</property>
+		      <property name="ypad">0</property>
+		    </widget>
+		    <packing>
+		      <property name="padding">0</property>
+		      <property name="expand">False</property>
+		      <property name="fill">False</property>
+		    </packing>
+		  </child>
+
+		  <child>
+		    <widget class="GtkHBox" id="hbox32">
+		      <property name="visible">True</property>
+		      <property name="homogeneous">False</property>
+		      <property name="spacing">0</property>
+
+		      <child>
+			<widget class="GtkLabel" id="label35">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">    </property>
+			  <property name="use_underline">False</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">False</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0.5</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">False</property>
+			  <property name="fill">False</property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkHBox" id="hbox33">
+			  <property name="visible">True</property>
+			  <property name="homogeneous">False</property>
+			  <property name="spacing">12</property>
+
+			  <child>
+			    <widget class="GtkLabel" id="label36">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">_Format:</property>
+			      <property name="use_underline">True</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_LEFT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">0.5</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">0</property>
+			      <property name="ypad">0</property>
+			      <property name="mnemonic_widget">date_format_optionmenu</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
+
+			  <child>
+			    <widget class="GtkOptionMenu" id="date_format_optionmenu">
+			      <property name="visible">True</property>
+			      <property name="can_focus">True</property>
+			      <property name="history">0</property>
+
+			      <child>
+				<widget class="GtkMenu" id="menu17">
+
+				  <child>
+				    <widget class="GtkMenuItem" id="locale1">
+				      <property name="visible">True</property>
+				      <property name="label" translatable="yes">locale</property>
+				      <property name="use_underline">True</property>
+				    </widget>
+				  </child>
+
+				  <child>
+				    <widget class="GtkMenuItem" id="iso1">
+				      <property name="visible">True</property>
+				      <property name="label" translatable="yes">iso</property>
+				      <property name="use_underline">True</property>
+				    </widget>
+				  </child>
+
+				  <child>
+				    <widget class="GtkMenuItem" id="informal1">
+				      <property name="visible">True</property>
+				      <property name="label" translatable="yes">informal</property>
+				      <property name="use_underline">True</property>
+				    </widget>
+				  </child>
+				</widget>
+			      </child>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">True</property>
+			  <property name="fill">True</property>
+			</packing>
+		      </child>
+		    </widget>
+		    <packing>
+		      <property name="padding">0</property>
+		      <property name="expand">True</property>
+		      <property name="fill">True</property>
+		    </packing>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
 	    </widget>
 	    <packing>
 	      <property name="tab_expand">False</property>
@@ -1851,7 +1996,7 @@
 	  <child>
 	    <widget class="GtkLabel" id="label24">
 	      <property name="visible">True</property>
-	      <property name="label" translatable="yes">Icon Captions</property>
+	      <property name="label" translatable="yes">Display</property>
 	      <property name="use_underline">False</property>
 	      <property name="use_markup">False</property>
 	      <property name="justify">GTK_JUSTIFY_LEFT</property>


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