[gnome-commander/fileroller-plugin: 4/4] Adds strftime ability to file roller plugin
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/fileroller-plugin: 4/4] Adds strftime ability to file roller plugin
- Date: Mon, 26 Sep 2016 21:07:26 +0000 (UTC)
commit 5d22cb0a6ef1c78f65db686249a604ceec94ab2d
Author: Uwe Scholz <uwescholz src gnome org>
Date: Mon Sep 26 22:45:16 2016 +0200
Adds strftime ability to file roller plugin
Allot of changes had to be introduced here. Basically the most changes
are about extending the plugins configure widget and string replacement.
Also a repair took place so that gcmd won't crash if the 'About' button
in the plugin dialog is clicked.
data/org.gnome.gnome-commander.gschema.xml | 7 +
plugins/fileroller/file-roller-plugin.cc | 216 ++++++++++++++++++++++++----
src/gnome-cmd-about-plugin.cc | 6 +-
3 files changed, 202 insertions(+), 27 deletions(-)
---
diff --git a/data/org.gnome.gnome-commander.gschema.xml b/data/org.gnome.gnome-commander.gschema.xml
index 12c0e35..1bff58e 100644
--- a/data/org.gnome.gnome-commander.gschema.xml
+++ b/data/org.gnome.gnome-commander.gschema.xml
@@ -882,6 +882,13 @@
Default file suffix of archives created with the File Roller plugin.
</description>
</key>
+ <key name="prefix-pattern" type="s">
+ <default>'$N'</default>
+ <summary>Prefix pattern</summary>
+ <description>
+ The prefix pattern is used to build up the name for an archive created with the File Roller
plugin.
+ </description>
+ </key>
</schema>
<schema gettext-domain="gnome-commander" id="org.gnome.gnome-commander.plugins.general"
path="/org/gnome/gnome-commander/plugins/general/">
<key name="autoload" type="as">
diff --git a/plugins/fileroller/file-roller-plugin.cc b/plugins/fileroller/file-roller-plugin.cc
index 0d1f050..8b74fe8 100644
--- a/plugins/fileroller/file-roller-plugin.cc
+++ b/plugins/fileroller/file-roller-plugin.cc
@@ -19,19 +19,22 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include <config.h>
+#include <stdlib.h>
#include <libgcmd/libgcmd.h>
#include "file-roller-plugin.h"
#include "file-roller.xpm"
#include "file-roller-small.xpm"
-#define NAME "File Roller"
-#define COPYRIGHT "Copyright \xc2\xa9 2003-2006 Marcus Bjurman"
+#define NAME "File Roller Plugin"
+#define COPYRIGHT "Copyright \n\xc2\xa9 2003-2006 Marcus Bjurman\n\xc2\xa9 2013-2016 Uwe Scholz"
#define AUTHOR "Marcus Bjurman <marbj499 student liu se>"
+#define TRANSLATOR_CREDITS "Translations: https://l10n.gnome.org/module/gnome-commander/"
#define WEBPAGE "http://gcmd.github.io"
+#define VERSION "1.6.0"
#define GCMD_PLUGINS_FILE_ROLLER "org.gnome.gnome-commander.plugins.file-roller-plugin"
#define GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE "default-type"
+#define GCMD_PLUGINS_FILE_ROLLER_PREFIX_PATTERN "prefix-pattern"
static PluginInfo plugin_nfo = {
GNOME_CMD_PLUGIN_SYSTEM_CURRENT_VERSION,
@@ -41,12 +44,12 @@ static PluginInfo plugin_nfo = {
NULL,
NULL,
NULL,
- NULL,
+ TRANSLATOR_CREDITS,
WEBPAGE
};
-
-static const gchar *handled_extensions[] =
+#define NUMBER_OF_EXTENSIONS 26
+static const gchar *handled_extensions[NUMBER_OF_EXTENSIONS + 1] =
{
".7z", // 7-zip
".ar", // ar
@@ -132,10 +135,12 @@ struct _FileRollerPluginPrivate
{
GtkWidget *conf_dialog;
GtkWidget *conf_combo;
+ GtkWidget *conf_entry;
GnomeCmdState *state;
gchar *default_ext;
+ gchar *file_prefix_pattern;
PluginSettings *settings;
};
@@ -220,6 +225,64 @@ inline void do_add_to_archive (const gchar *name, GnomeCmdState *state)
}
+static gchar* new_string_with_replaced_keyword(const char* string, const char* keyword, const char*
replacement)
+{
+ gchar* new_string = NULL;
+ gchar* replacement_tmp;
+
+ if (keyword == NULL || strlen(keyword) == 0)
+ {
+ new_string = g_strdup(string);
+ return new_string;
+ }
+ if (replacement == NULL)
+ replacement_tmp = g_strdup("");
+ else
+ replacement_tmp = (char*) replacement;
+
+ if (gchar *temp_ptr = g_strrstr(string, keyword))
+ {
+ gchar *in_filename = (char*) string;
+ guint i = 0;
+
+ new_string = (char*) calloc(1, 2);
+ while (in_filename != temp_ptr)
+ {
+ if (new_string)
+ new_string = (char*) realloc(new_string, strlen(new_string) + 1);
+ else
+ new_string = (char*) calloc(1, 2);
+ new_string[i] = *(in_filename++);
+ ++i;
+ }
+
+ if (new_string)
+ new_string = (char*) realloc(new_string, strlen(new_string) + strlen(replacement_tmp) + 1);
+ else
+ new_string = (char*) calloc(1, strlen(replacement_tmp) + 1);
+
+ strcat(new_string, replacement_tmp);
+ i += strlen(replacement_tmp);
+ in_filename += strlen(keyword);
+ while (*in_filename != '\0')
+ {
+ new_string = (char*) realloc(new_string, strlen(new_string) + 2);
+ new_string[i] = *(in_filename++);
+ ++i;
+ new_string[i] = '\0';
+ }
+ }
+
+ if (replacement == NULL)
+ g_free(replacement_tmp);
+
+ if (!new_string)
+ new_string = g_strdup(string);
+
+ return new_string;
+}
+
+
static void on_add_to_archive (GtkMenuItem *item, FileRollerPlugin *plugin)
{
gint ret;
@@ -227,7 +290,7 @@ static void on_add_to_archive (GtkMenuItem *item, FileRollerPlugin *plugin)
GdkPixbuf *pixbuf;
GtkWidget *entry;
GtkWidget *hbox;
- gchar *t;
+ gchar *archive_name;
const gchar *name;
gboolean name_ok = FALSE;
GList *files;
@@ -258,13 +321,20 @@ static void on_add_to_archive (GtkMenuItem *item, FileRollerPlugin *plugin)
gtk_widget_show (entry);
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 6);
- t = g_strdup_printf (
- "%s%s",
- get_utf8 (GNOME_CMD_FILE_INFO (files->data)->info->name),
- plugin->priv->default_ext);
+ gchar *locale_format = g_locale_from_utf8 (plugin->priv->file_prefix_pattern, -1, NULL, NULL, NULL);
+ char s[256];
+ time_t t = time (NULL);
+
+ strftime (s, sizeof(s), locale_format, localtime (&t));
+ g_free (locale_format);
+ gchar *file_prefix = g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
+
+ gchar *archive_name_tmp = g_strdup_printf("%s%s", file_prefix, plugin->priv->default_ext);
+ archive_name = new_string_with_replaced_keyword(archive_name_tmp, "$N", GNOME_CMD_FILE_INFO
(files->data)->info->name);
+ gtk_entry_set_text (GTK_ENTRY (entry), archive_name);
+ g_free(archive_name);
+ g_free(archive_name_tmp);
- gtk_entry_set_text (GTK_ENTRY (entry), t);
- g_free (t);
pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)file_roller_xpm);
gtk_image_set_from_pixbuf (GTK_IMAGE (GTK_MESSAGE_DIALOG (dialog)->image), pixbuf);
@@ -400,18 +470,48 @@ static void update_main_menu_state (GnomeCmdPlugin *plugin, GnomeCmdState *state
static void on_configure_close (GtkButton *btn, FileRollerPlugin *plugin)
{
- plugin->priv->default_ext = g_strdup (get_combo_text (plugin->priv->conf_combo));
+ plugin->priv->default_ext = gtk_combo_box_text_get_active_text ((GtkComboBoxText*)
plugin->priv->conf_combo);
+ plugin->priv->file_prefix_pattern = g_strdup (get_entry_text (plugin->priv->conf_entry,
"file_prefix_pattern_entry"));
g_settings_set_string (plugin->priv->settings->file_roller_plugin,
GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE, plugin->priv->default_ext);
+ g_settings_set_string (plugin->priv->settings->file_roller_plugin,
GCMD_PLUGINS_FILE_ROLLER_PREFIX_PATTERN, plugin->priv->file_prefix_pattern);
gtk_widget_hide (plugin->priv->conf_dialog);
}
+static void on_date_format_update (GtkEditable *editable, GtkWidget *options_dialog)
+{
+ GtkWidget *format_entry = lookup_widget (options_dialog, "file_prefix_pattern_entry");
+ GtkWidget *test_label = lookup_widget (options_dialog, "date_format_test_label");
+ GtkWidget *combo_entry = lookup_widget (options_dialog, "combo");
+ gchar *file_suffix = gtk_combo_box_text_get_active_text ((GtkComboBoxText*) combo_entry);
+
+ const char *format = gtk_entry_get_text (GTK_ENTRY (format_entry));
+ gchar *locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
+
+ char s[256];
+ time_t t = time (NULL);
+
+ strftime (s, sizeof(s), locale_format, localtime (&t));
+ gchar *file_prefix = g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
+ gchar *filename_tmp = g_strdup_printf("%s%s", file_prefix, file_suffix);
+ gchar *replacement = g_strdup(_("File"));
+ gchar *filename = new_string_with_replaced_keyword(filename_tmp, "$N", replacement);
+ gtk_label_set_text (GTK_LABEL (test_label), filename);
+ g_free (file_prefix);
+ g_free (replacement);
+ g_free (filename);
+ g_free (filename_tmp);
+ g_free (file_suffix);
+ g_free (locale_format);
+}
+
+
static void configure (GnomeCmdPlugin *plugin)
{
- GList *items = NULL;
- GtkWidget *dialog, *table, *cat, *label, *combo, *vbox;
+ GtkWidget *dialog, *table, *cat, *label, *vbox, *entry;
+ GtkWidget *combo;
dialog = gnome_cmd_dialog_new (_("Options"));
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (main_win_widget));
@@ -424,26 +524,63 @@ static void configure (GnomeCmdPlugin *plugin)
gnome_cmd_dialog_add_expanding_category (GNOME_CMD_DIALOG (dialog), vbox);
- table = create_table (dialog, 2, 2);
+ table = create_table (dialog, 5, 2);
cat = create_category (dialog, table, _("File-roller options"));
gtk_box_pack_start (GTK_BOX (vbox), cat, FALSE, TRUE, 0);
- label = create_label (dialog, _("Default type"));
+ label = create_label (dialog, _("Default archive type"));
table_add (table, label, 0, 1, (GtkAttachOptions) 0);
- combo = create_combo (dialog);
+ combo = create_combo_new (dialog);
+ g_signal_connect (G_OBJECT(combo), "changed", G_CALLBACK (on_date_format_update), dialog);
table_add (table, combo, 1, 1, GTK_FILL);
+ // The pattern defining the file name prefix of the archive to be created
+ label = create_label (dialog, _("File prefix pattern"));
+ table_add (table, label, 0, 2, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
+
+ gchar *utf8_date_format = g_locale_to_utf8 (FILE_ROLLER_PLUGIN (plugin)->priv->file_prefix_pattern, -1,
NULL, NULL, NULL);
+ entry = create_entry (dialog, "file_prefix_pattern_entry", utf8_date_format);
+ g_free (utf8_date_format);
+ gtk_widget_grab_focus (entry);
+ g_signal_connect (entry, "realize", G_CALLBACK (on_date_format_update), dialog);
+ g_signal_connect (entry, "changed", G_CALLBACK (on_date_format_update), dialog);
+ table_add (table, entry, 1, 2, GTK_FILL);
+
+ label = create_label (dialog, _("Test result:"));
+ table_add (table, label, 0, 3, GTK_FILL);
+
+ label = create_label (dialog, "");
+ g_object_set_data (G_OBJECT (dialog), "date_format_test_label", label);
+ table_add (table, label, 1, 3, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
+
+ gchar* text = g_strdup_printf("<small>%s</small>",_("Use $N as a pattern for the original file name. See
the manual page for \"strftime\" for other patterns."));
+ label = create_label (dialog, text);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_markup (GTK_LABEL (label), text);
+ table_add (table, label, 1, 4, GTK_FILL);
+ g_free(text);
+
for (gint i=0; handled_extensions[i] != NULL; i++)
- items = g_list_append (items, (gpointer) handled_extensions[i]);
+ gtk_combo_box_text_append_text ((GtkComboBoxText*) combo, handled_extensions[i]);
- gtk_combo_set_popdown_strings (GTK_COMBO (combo), items);
+ for (gint i=0; handled_extensions[i]; ++i)
+ if (g_str_has_suffix (FILE_ROLLER_PLUGIN (plugin)->priv->default_ext, handled_extensions[i]))
+ gtk_combo_box_set_active((GtkComboBox*) combo, i);
- gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (combo)->entry),
- FILE_ROLLER_PLUGIN (plugin)->priv->default_ext);
+ // The text entry stored in default_ext (set in init()) should be the active entry in the combo now.
+ // If strlen of the active comby == 0, prepend the stored value to the list.
+ gchar* test = gtk_combo_box_text_get_active_text ((GtkComboBoxText*) combo);
+ if (test && strlen(test) == 0)
+ {
+ gtk_combo_box_text_prepend_text ((GtkComboBoxText*) combo, FILE_ROLLER_PLUGIN
(plugin)->priv->default_ext);
+ gtk_combo_box_set_active((GtkComboBox*) combo, 0);
+ }
+ g_free(test);
FILE_ROLLER_PLUGIN (plugin)->priv->conf_dialog = dialog;
FILE_ROLLER_PLUGIN (plugin)->priv->conf_combo = combo;
+ FILE_ROLLER_PLUGIN (plugin)->priv->conf_entry = entry;
gtk_widget_show (dialog);
}
@@ -458,6 +595,7 @@ static void destroy (GtkObject *object)
FileRollerPlugin *plugin = FILE_ROLLER_PLUGIN (object);
g_free (plugin->priv->default_ext);
+ g_free (plugin->priv->file_prefix_pattern);
g_free (plugin->priv);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
@@ -483,10 +621,38 @@ static void class_init (FileRollerPluginClass *klass)
static void init (FileRollerPlugin *plugin)
{
- plugin->priv = g_new (FileRollerPluginPrivate, 1);
+ GSettings *gsettings;
+ plugin->priv = g_new (FileRollerPluginPrivate, 1);
plugin->priv->settings = plugin_settings_new();
- plugin->priv->default_ext = g_settings_get_string (plugin->priv->settings->file_roller_plugin,
GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE);
+
+ gsettings = plugin->priv->settings->file_roller_plugin;
+ plugin->priv->default_ext = g_settings_get_string (gsettings, GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE);
+ plugin->priv->file_prefix_pattern = g_settings_get_string (gsettings,
GCMD_PLUGINS_FILE_ROLLER_PREFIX_PATTERN);
+
+ //Set gsettings values to default values if they are empty
+ if (strlen(plugin->priv->default_ext) == 0)
+ {
+ g_free(plugin->priv->default_ext);
+
+ GVariant *variant;
+ variant = g_settings_get_default_value (gsettings, GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE);
+ g_settings_set_string (gsettings, GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE,
g_variant_get_string(variant, NULL));
+ g_variant_unref (variant);
+
+ plugin->priv->default_ext = g_settings_get_string (gsettings, GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE);
+ }
+ if (strlen(plugin->priv->file_prefix_pattern) == 0)
+ {
+ g_free(plugin->priv->file_prefix_pattern);
+
+ GVariant *variant;
+ variant = g_settings_get_default_value (gsettings, GCMD_PLUGINS_FILE_ROLLER_PREFIX_PATTERN);
+ g_settings_set_string (gsettings, GCMD_PLUGINS_FILE_ROLLER_PREFIX_PATTERN,
g_variant_get_string(variant, NULL));
+ g_variant_unref (variant);
+
+ plugin->priv->file_prefix_pattern = (gchar*) g_settings_get_default_value (gsettings,
GCMD_PLUGINS_FILE_ROLLER_PREFIX_PATTERN);
+ }
}
diff --git a/src/gnome-cmd-about-plugin.cc b/src/gnome-cmd-about-plugin.cc
index 88c66d6..77d2ea9 100644
--- a/src/gnome-cmd-about-plugin.cc
+++ b/src/gnome-cmd-about-plugin.cc
@@ -146,6 +146,8 @@ static void gnome_cmd_about_plugin_update_translation_information_label (GnomeCm
g_string_append (string, tmp);
g_free (tmp);
+ g_string_append_c (string, '\n');
+
gtk_label_set_markup (GTK_LABEL (label), string->str);
g_string_free (string, TRUE);
}
@@ -732,8 +734,8 @@ void gnome_cmd_about_plugin_construct (GnomeCmdAboutPlugin *about,
"version", version,
"copyright", copyright,
"comments", comments,
- "authors", authors_array,
- "documenters", documenters_array,
+// "authors", authors_array,
+// "documenters", documenters_array,
"translator_credits", translator_credits,
"webpage", webpage,
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]