From c507eaac568e21756ecdd2bdbc555c823d12d282 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Mon, 16 Jul 2018 00:31:28 +0200 Subject: [PATCH] Change date format in thunar from english to german (Bug #14527) TODO: Make code pretty --- thunar/thunar-dialogs.c | 6 ++-- thunar/thunar-enum-types.c | 5 +++- thunar/thunar-enum-types.h | 3 ++ thunar/thunar-file.c | 12 +++++--- thunar/thunar-file.h | 6 ++-- thunar/thunar-list-model.c | 57 ++++++++++++++++++++++++++++++++++++-- thunar/thunar-preferences-dialog.c | 20 +++++++++++-- thunar/thunar-preferences.c | 14 ++++++++++ thunar/thunar-properties-dialog.c | 8 ++++-- thunar/thunar-standard-view.c | 1 + thunar/thunar-util.c | 30 ++++++++++++++++---- thunar/thunar-util.h | 3 +- 12 files changed, 142 insertions(+), 23 deletions(-) diff --git a/thunar/thunar-dialogs.c b/thunar/thunar-dialogs.c index c152928d..d5c02253 100644 --- a/thunar/thunar-dialogs.c +++ b/thunar/thunar-dialogs.c @@ -528,6 +528,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, GtkWidget *image; GtkWidget *label; GdkPixbuf *icon; + gchar *date_custom_style; gchar *date_string; gchar *size_string; gchar *text; @@ -541,6 +542,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, /* determine the style used to format dates */ preferences = thunar_preferences_get (); g_object_get (G_OBJECT (preferences), "misc-date-style", &date_style, NULL); + g_object_get (G_OBJECT (preferences), "misc-date-custom-style", &date_custom_style, NULL); g_object_get (G_OBJECT (preferences), "misc-file-size-binary", &file_size_binary, NULL); g_object_unref (G_OBJECT (preferences)); @@ -628,7 +630,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, gtk_widget_show (image); size_string = thunar_file_get_size_string_long (dst_file, file_size_binary); - date_string = thunar_file_get_date_string (dst_file, THUNAR_FILE_DATE_MODIFIED, date_style); + date_string = thunar_file_get_date_string (dst_file, THUNAR_FILE_DATE_MODIFIED, date_style, date_custom_style); text = g_strdup_printf ("%s %s\n%s %s", _("Size:"), size_string, _("Modified:"), date_string); label = gtk_label_new (text); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); @@ -664,7 +666,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, gtk_widget_show (image); size_string = thunar_file_get_size_string_long (src_file, file_size_binary); - date_string = thunar_file_get_date_string (src_file, THUNAR_FILE_DATE_MODIFIED, date_style); + date_string = thunar_file_get_date_string (src_file, THUNAR_FILE_DATE_MODIFIED, date_style, date_custom_style); text = g_strdup_printf ("%s %s\n%s %s", _("Size:"), size_string, _("Modified:"), date_string); label = gtk_label_new (text); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c index 5585f4a7..6cff14d3 100644 --- a/thunar/thunar-enum-types.c +++ b/thunar/thunar-enum-types.c @@ -68,7 +68,10 @@ thunar_date_style_get_type (void) { THUNAR_DATE_STYLE_SIMPLE, "THUNAR_DATE_STYLE_SIMPLE", "simple", }, { THUNAR_DATE_STYLE_SHORT, "THUNAR_DATE_STYLE_SHORT", "short", }, { THUNAR_DATE_STYLE_LONG, "THUNAR_DATE_STYLE_LONG", "long", }, - { THUNAR_DATE_STYLE_ISO, "THUNAR_DATE_STYLE_ISO", "iso", }, + { THUNAR_DATE_STYLE_ISO, "THUNAR_DATE_STYLE_ISO", "iso", }, // asian style + { THUNAR_DATE_STYLE_ISO_US, "THUNAR_DATE_STYLE_ISO_US", "iso_us", }, + { THUNAR_DATE_STYLE_ISO_EU, "THUNAR_DATE_STYLE_ISO_EU", "iso_eu", }, + { THUNAR_DATE_STYLE_CUSTOM, "THUNAR_DATE_STYLE_CUSTOM", "custom", }, { 0, NULL, NULL, }, }; diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h index e5e6aa97..1e167487 100644 --- a/thunar/thunar-enum-types.h +++ b/thunar/thunar-enum-types.h @@ -63,6 +63,9 @@ typedef enum THUNAR_DATE_STYLE_SHORT, THUNAR_DATE_STYLE_LONG, THUNAR_DATE_STYLE_ISO, + THUNAR_DATE_STYLE_ISO_US, + THUNAR_DATE_STYLE_ISO_EU, + THUNAR_DATE_STYLE_CUSTOM, } ThunarDateStyle; GType thunar_date_style_get_type (void) G_GNUC_CONST; diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 6ace63f7..0d8e8976 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -2187,6 +2187,7 @@ thunar_file_get_date (const ThunarFile *file, * @file : a #ThunarFile instance. * @date_type : the kind of date you are interested to know about @file. * @date_style : the style used to format the date. + * @date_custom_style : custom style to apply, if @date_style is set to custom * * Tries to determine the @date_type of @file, and if @file supports the * given @date_type, it'll be formatted as string and returned. The @@ -2198,9 +2199,10 @@ thunar_file_get_date (const ThunarFile *file, gchar* thunar_file_get_date_string (const ThunarFile *file, ThunarFileDateType date_type, - ThunarDateStyle date_style) + ThunarDateStyle date_style, + gchar *date_custom_style) { - return thunar_util_humanize_file_time (thunar_file_get_date (file, date_type), date_style); + return thunar_util_humanize_file_time (thunar_file_get_date (file, date_type), date_style, date_custom_style); } @@ -3177,6 +3179,7 @@ thunar_file_get_display_name (const ThunarFile *file) * thunar_file_get_deletion_date: * @file : a #ThunarFile instance. * @date_style : the style used to format the date. + * @date_custom_style : custom style to apply, if @date_style is set to custom * * Returns the deletion date of the @file if the @file * is located in the trash. Otherwise %NULL will be @@ -3190,7 +3193,8 @@ thunar_file_get_display_name (const ThunarFile *file) **/ gchar* thunar_file_get_deletion_date (const ThunarFile *file, - ThunarDateStyle date_style) + ThunarDateStyle date_style, + gchar *date_custom_style) { const gchar *date; time_t deletion_time; @@ -3206,7 +3210,7 @@ thunar_file_get_deletion_date (const ThunarFile *file, deletion_time = thunar_util_time_from_rfc3339 (date); /* humanize the time value */ - return thunar_util_humanize_file_time (deletion_time, date_style); + return thunar_util_humanize_file_time (deletion_time, date_style, date_custom_style); } diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h index 73000e4c..1e85e51e 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -165,7 +165,8 @@ guint64 thunar_file_get_date (const ThunarFile gchar *thunar_file_get_date_string (const ThunarFile *file, ThunarFileDateType date_type, - ThunarDateStyle date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; + ThunarDateStyle date_style, + gchar *date_custom_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; gchar *thunar_file_get_mode_string (const ThunarFile *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; gchar *thunar_file_get_size_string (const ThunarFile *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; gchar *thunar_file_get_size_in_bytes_string (const ThunarFile *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; @@ -212,7 +213,8 @@ gboolean thunar_file_is_desktop_file (const ThunarFile const gchar *thunar_file_get_display_name (const ThunarFile *file) G_GNUC_CONST; gchar *thunar_file_get_deletion_date (const ThunarFile *file, - ThunarDateStyle date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; + ThunarDateStyle date_style, + gchar *date_custom_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; const gchar *thunar_file_get_original_path (const ThunarFile *file); guint32 thunar_file_get_item_count (const ThunarFile *file); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 2821b673..c60f5968 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -46,6 +46,7 @@ enum PROP_0, PROP_CASE_SENSITIVE, PROP_DATE_STYLE, + PROP_DATE_CUSTOM_STYLE, PROP_FOLDER, PROP_FOLDERS_FIRST, PROP_NUM_FILES, @@ -185,6 +186,9 @@ static void thunar_list_model_set_case_sensitive (ThunarListMod static ThunarDateStyle thunar_list_model_get_date_style (ThunarListModel *store); static void thunar_list_model_set_date_style (ThunarListModel *store, ThunarDateStyle date_style); +static const char* thunar_list_model_get_date_custom_style (ThunarListModel *store); +static void thunar_list_model_set_date_custom_style (ThunarListModel *store, + const char *date_custom_style); static gint thunar_list_model_get_num_files (ThunarListModel *store); static gboolean thunar_list_model_get_folders_first (ThunarListModel *store); @@ -217,6 +221,7 @@ struct _ThunarListModel gboolean show_hidden : 1; gboolean file_size_binary : 1; ThunarDateStyle date_style; + char *date_custom_style; /* Use the shared ThunarFileMonitor instance, so we * do not need to connect "changed" handler to every @@ -287,6 +292,18 @@ thunar_list_model_class_init (ThunarListModelClass *klass) EXO_PARAM_READWRITE); /** + * ThunarListModel:date-custom-style: + * + * The custom style used to format dates. + **/ + list_model_props[PROP_DATE_CUSTOM_STYLE] = + g_param_spec_string ("date-custom-style", + "DateCustomStyle", + NULL, + "%d.%m.%Y - %H:%M:%S", + EXO_PARAM_READWRITE); + + /** * ThunarListModel:folder: * * The folder presented by this #ThunarListModel. @@ -481,6 +498,10 @@ thunar_list_model_get_property (GObject *object, g_value_set_enum (value, thunar_list_model_get_date_style (store)); break; + case PROP_DATE_CUSTOM_STYLE: + g_value_set_enum (value, thunar_list_model_get_date_custom_style (store)); + break; + case PROP_FOLDER: g_value_set_object (value, thunar_list_model_get_folder (store)); break; @@ -527,6 +548,10 @@ thunar_list_model_set_property (GObject *object, thunar_list_model_set_date_style (store, g_value_get_enum (value)); break; + case PROP_DATE_CUSTOM_STYLE: + thunar_list_model_set_date_custom_style (store, g_value_get_string (value)); + break; + case PROP_FOLDER: thunar_list_model_set_folder (store, g_value_get_object (value)); break; @@ -686,13 +711,13 @@ thunar_list_model_get_value (GtkTreeModel *model, { case THUNAR_COLUMN_DATE_ACCESSED: g_value_init (value, G_TYPE_STRING); - str = thunar_file_get_date_string (file, THUNAR_FILE_DATE_ACCESSED, THUNAR_LIST_MODEL (model)->date_style); + str = thunar_file_get_date_string (file, THUNAR_FILE_DATE_ACCESSED, THUNAR_LIST_MODEL (model)->date_style, THUNAR_LIST_MODEL (model)->date_custom_style); g_value_take_string (value, str); break; case THUNAR_COLUMN_DATE_MODIFIED: g_value_init (value, G_TYPE_STRING); - str = thunar_file_get_date_string (file, THUNAR_FILE_DATE_MODIFIED, THUNAR_LIST_MODEL (model)->date_style); + str = thunar_file_get_date_string (file, THUNAR_FILE_DATE_MODIFIED, THUNAR_LIST_MODEL (model)->date_style, THUNAR_LIST_MODEL (model)->date_custom_style); g_value_take_string (value, str); break; @@ -1770,6 +1795,34 @@ thunar_list_model_set_date_style (ThunarListModel *store, +static const char* +thunar_list_model_get_date_custom_style (ThunarListModel *store) +{ + _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), THUNAR_DATE_STYLE_SIMPLE); + return store->date_custom_style; +} +static void +thunar_list_model_set_date_custom_style (ThunarListModel *store, + const char *date_custom_style) +{ + _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); + + printf("thunar_list_model_set_date_custom_style 1 \n"); + /* check if we have a new setting */ + if (g_strcmp0(store->date_custom_style,date_custom_style) != 0) + { + printf("thunar_list_model_set_date_custom_style 2 \n"); + /* apply the new setting */ + store->date_custom_style = g_strdup(date_custom_style); + + /* notify listeners */ + g_object_notify_by_pspec (G_OBJECT (store), list_model_props[PROP_DATE_CUSTOM_STYLE]); + + /* emit a "changed" signal for each row, so the display is reloaded with the new date style */ + gtk_tree_model_foreach (GTK_TREE_MODEL (store), (GtkTreeModelForeachFunc) gtk_tree_model_row_changed, NULL); + } +} + /** * thunar_list_model_get_folder: * @store : a valid #ThunarListModel object. diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c index 88f4bf9f..68f559b8 100644 --- a/thunar/thunar-preferences-dialog.c +++ b/thunar/thunar-preferences-dialog.c @@ -196,7 +196,15 @@ thunar_preferences_dialog_class_init (ThunarPreferencesDialogClass *klass) gtkdialog_class->response = thunar_preferences_dialog_response; } - +gboolean +on_date_format_changed (GtkWidget *combo, GtkWidget *customFormat) +{ + gint comboValue = gtk_combo_box_get_active (combo); + if( comboValue == THUNAR_DATE_STYLE_CUSTOM) + gtk_widget_set_visible (customFormat, TRUE); + else + gtk_widget_set_visible (customFormat, FALSE); +} static void thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog) @@ -362,18 +370,24 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog) gtk_widget_show (label); combo = gtk_combo_box_text_new (); - for (date_style = THUNAR_DATE_STYLE_SIMPLE; date_style <= THUNAR_DATE_STYLE_ISO; ++date_style) + for (date_style = THUNAR_DATE_STYLE_SIMPLE; date_style <= THUNAR_DATE_STYLE_ISO_EU; ++date_style) { - date = thunar_util_humanize_file_time (time (NULL), date_style); + date = thunar_util_humanize_file_time (time (NULL), date_style, NULL); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), date); g_free (date); } + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "custom"); exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-date-style", G_OBJECT (combo), "active"); gtk_widget_set_hexpand (combo, TRUE); gtk_grid_attach (GTK_GRID (grid), combo, 1, 0, 1, 1); thunar_gtk_label_set_a11y_relation (GTK_LABEL (label), combo); gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); gtk_widget_show (combo); + GtkWidget *entry = gtk_entry_new (); + exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-date-custom-style", G_OBJECT (entry), "text"); + g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(on_date_format_changed), entry); + gtk_grid_attach (GTK_GRID (grid), entry, 1, 1, 1, 1); + gtk_widget_show (entry); /* diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 4b3efc2b..c9f4226b 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -75,6 +75,7 @@ enum PROP_MISC_VOLUME_MANAGEMENT, PROP_MISC_CASE_SENSITIVE, PROP_MISC_DATE_STYLE, + PROP_MISC_DATE_CUSTOM_STYLE, PROP_EXEC_SHELL_SCRIPTS_BY_DEFAULT, PROP_MISC_FOLDERS_FIRST, PROP_MISC_FULL_PATH_IN_TITLE, @@ -493,6 +494,19 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) THUNAR_DATE_STYLE_SIMPLE, EXO_PARAM_READWRITE); + + /** + * ThunarPreferences:misc-date-custom-style: + * + * If 'custom' is selected, this date-style will be used + **/ + preferences_props[PROP_MISC_DATE_CUSTOM_STYLE] = + g_param_spec_string ("misc-date-custom-style", + "MiscDateCustomStyle", + NULL, + "%d.%m.%Y - %H:%M:%S", + EXO_PARAM_READWRITE); + /** * ThunarPreferences:misc-execute-shell-scripts-by-default: * diff --git a/thunar/thunar-properties-dialog.c b/thunar/thunar-properties-dialog.c index b2da0a86..4168b53f 100644 --- a/thunar/thunar-properties-dialog.c +++ b/thunar/thunar-properties-dialog.c @@ -908,6 +908,7 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog) GVolume *volume; GIcon *gicon; glong offset; + gchar *date_custom_style; gchar *date; gchar *display_name; gchar *fs_string; @@ -939,6 +940,7 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog) /* determine the style used to format dates */ g_object_get (G_OBJECT (dialog->preferences), "misc-date-style", &date_style, NULL); + g_object_get (G_OBJECT (dialog->preferences), "misc-date-custom-style", &date_custom_style, NULL); /* update the properties dialog title */ str = g_strdup_printf (_("%s - Properties"), thunar_file_get_display_name (file)); @@ -1056,7 +1058,7 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog) } /* update the deleted time */ - date = thunar_file_get_deletion_date (file, date_style); + date = thunar_file_get_deletion_date (file, date_style, date_custom_style); if (G_LIKELY (date != NULL)) { gtk_label_set_text (GTK_LABEL (dialog->deleted_label), date); @@ -1069,7 +1071,7 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog) } /* update the modified time */ - date = thunar_file_get_date_string (file, THUNAR_FILE_DATE_MODIFIED, date_style); + date = thunar_file_get_date_string (file, THUNAR_FILE_DATE_MODIFIED, date_style, date_custom_style); if (G_LIKELY (date != NULL)) { gtk_label_set_text (GTK_LABEL (dialog->modified_label), date); @@ -1082,7 +1084,7 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog) } /* update the accessed time */ - date = thunar_file_get_date_string (file, THUNAR_FILE_DATE_ACCESSED, date_style); + date = thunar_file_get_date_string (file, THUNAR_FILE_DATE_ACCESSED, date_style, date_custom_style); if (G_LIKELY (date != NULL)) { gtk_label_set_text (GTK_LABEL (dialog->accessed_label), date); diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index cd6924d6..004388d3 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -721,6 +721,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS g_signal_connect (G_OBJECT (standard_view->model), "error", G_CALLBACK (thunar_standard_view_error), standard_view); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-case-sensitive", G_OBJECT (standard_view->model), "case-sensitive"); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-date-style", G_OBJECT (standard_view->model), "date-style"); + exo_binding_new (G_OBJECT (standard_view->preferences), "misc-date-custom-style", G_OBJECT (standard_view->model), "date-custom-style"); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-folders-first", G_OBJECT (standard_view->model), "folders-first"); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-file-size-binary", G_OBJECT (standard_view->model), "file-size-binary"); diff --git a/thunar/thunar-util.c b/thunar/thunar-util.c index c61a73b9..01738687 100644 --- a/thunar/thunar-util.c +++ b/thunar/thunar-util.c @@ -358,7 +358,8 @@ thunar_util_expand_filename (const gchar *filename, /** * thunar_util_humanize_file_time: * @file_time : a #guint64 timestamp. - * @date_format : the #ThunarDateFormat used to humanize the @file_time. + * @date_style : the #ThunarDateFormat used to humanize the @file_time. + * @date_custom_style : custom style to apply, if @date_style is set to custom * * Returns a human readable date representation of the specified * @file_time. The caller is responsible to free the returned @@ -368,8 +369,9 @@ thunar_util_expand_filename (const gchar *filename, * according to the @date_format. **/ gchar* -thunar_util_humanize_file_time (guint64 file_time, - ThunarDateStyle date_style) +thunar_util_humanize_file_time (guint64 file_time, + ThunarDateStyle date_style, + gchar *date_custom_style) { const gchar *date_format; struct tm *tfile; @@ -443,11 +445,29 @@ thunar_util_humanize_file_time (guint64 file_time, /* use long, date(1)-like format string */ return exo_strdup_strftime ("%c", tfile); } - else /* if (date_style == THUNAR_DATE_STYLE_ISO) */ + else if (date_style == THUNAR_DATE_STYLE_ISO) { - /* use ISO date formatting */ + /* use ISO Asia date formatting */ return exo_strdup_strftime ("%Y-%m-%d %H:%M:%S", tfile); } + else if (date_style == THUNAR_DATE_STYLE_ISO_US) + { + /* use ISO US date formatting */ + return exo_strdup_strftime ("%m-%d-%Y %H:%M:%S", tfile); + } + else if (date_style == THUNAR_DATE_STYLE_ISO_EU) + { + /* use ISO Europe date formatting */ + return exo_strdup_strftime ("%d-%m-%Y %H:%M:%S", tfile); + } + else /* if (date_style == THUNAR_DATE_STYLE_CUSTOM) */ + { + if(date_custom_style == NULL) + return g_strdup (""); + + /* use custom date formatting */ + return exo_strdup_strftime (date_custom_style, tfile); + } } /* the file_time is invalid */ diff --git a/thunar/thunar-util.h b/thunar/thunar-util.h index d0f277c6..a4474525 100644 --- a/thunar/thunar-util.h +++ b/thunar/thunar-util.h @@ -54,7 +54,8 @@ gchar *thunar_util_expand_filename (const gchar *filename, GError **error) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; gchar *thunar_util_humanize_file_time (guint64 file_time, - ThunarDateStyle date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; + ThunarDateStyle date_style, + gchar *date_custom_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; GdkScreen *thunar_util_parse_parent (gpointer parent, GtkWindow **window_return) G_GNUC_WARN_UNUSED_RESULT; -- 2.11.0