diff options
author | Antenore Gatta <antenore@simbiosi.org> | 2019-03-15 03:27:34 +0300 |
---|---|---|
committer | Antenore Gatta <antenore@simbiosi.org> | 2019-03-15 03:27:34 +0300 |
commit | c69e301e2628ecf925273858093ec6427963f3d3 (patch) | |
tree | 501cd4c20cbb34bd07846a523f9dbf45d220e67e /src | |
parent | 7419fe16852b81cbe90b8853fd79294b5b7f2bbd (diff) |
Initial connection profile file name refactoring - UI
Diffstat (limited to 'src')
-rw-r--r-- | src/remmina_file.c | 38 | ||||
-rw-r--r-- | src/remmina_pref.c | 9 | ||||
-rw-r--r-- | src/remmina_pref.h | 1 | ||||
-rw-r--r-- | src/remmina_pref_dialog.c | 7 | ||||
-rw-r--r-- | src/remmina_pref_dialog.h | 1 |
5 files changed, 55 insertions, 1 deletions
diff --git a/src/remmina_file.c b/src/remmina_file.c index bece17623..84b6397fd 100644 --- a/src/remmina_file.c +++ b/src/remmina_file.c @@ -108,9 +108,47 @@ void remmina_file_generate_filename(RemminaFile *remminafile) GTimeVal gtime; GDir *dir; + /* File name restrictions: + * - Do not start with space + * - Do not end with space or dot + * - No more than 255 chars + * - Do not contain \0 + * - Avoid % and $ + * - Avoid underscores and spaces for interoperabiility with everything else + * - Better all lowercase + */ + gchar *invalid_chars = "\\%|/$?<>:* \""; + GString *filenamestr; + gchar *filename; + + + /** functions we can use + * g_strstrip( string ) + * Removes leading and trailing whitespace from a string + * g_strdelimit (str, invalid_chars, '-')) + * Convert each invalid_chars in a hyphen + * g_ascii_strdown(string) + * all lowercase + * To be safe we should remove control characters as well (but I'm lazy) + * https://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string#C + * g_utf8_strncpy (gchar *dest, const gchar *src, gsize n); + * copies a given number of characters instead of a given number of bytes. The src string must be valid UTF-8 encoded text. + * g_utf8_validate (const gchar *str, gssize max_len, const gchar **end); + * Validates UTF-8 encoded text. + */ + g_free(remminafile->filename); g_get_current_time(>ime); + filenamestr = g_string_new (g_strdup_printf("%s/%s.remmina", + remmina_file_get_datadir(), + remmina_pref.remmina_file_name)); + //remmina_utils_string_replace_all(filenamestr, "%N", + //remmina_file_get_string(remminafile, "name")); + filename = g_string_free(filenamestr, FALSE); + + g_print ("file name: %s\n", filename); + dir = g_dir_open(remmina_file_get_datadir(), 0, NULL); if (dir != NULL) remminafile->filename = g_strdup_printf("%s/%li%03li.remmina", remmina_file_get_datadir(), gtime.tv_sec, diff --git a/src/remmina_pref.c b/src/remmina_pref.c index 43fc9fdbf..84a0afaf4 100644 --- a/src/remmina_pref.c +++ b/src/remmina_pref.c @@ -403,6 +403,12 @@ void remmina_pref_init(void) remmina_pref.datadir_path = g_key_file_get_string(gkeyfile, "remmina_pref", "datadir_path", NULL); } + if (g_key_file_has_key(gkeyfile, "remmina_pref", "remmina_file_name", NULL)) { + remmina_pref.remmina_file_name = g_key_file_get_string(gkeyfile, "remmina_pref", "remmina_file_name", NULL); + }else{ + remmina_pref.remmina_file_name = g_strdup("%G_%P_%N_%h.remmina"); + } + if (g_key_file_has_key(gkeyfile, "remmina_pref", "screenshot_path", NULL)) { remmina_pref.screenshot_path = g_key_file_get_string(gkeyfile, "remmina_pref", "screenshot_path", NULL); }else{ @@ -660,8 +666,9 @@ gboolean remmina_pref_save(void) g_key_file_load_from_file(gkeyfile, remmina_pref_file, G_KEY_FILE_NONE, NULL); g_key_file_set_string(gkeyfile, "remmina_pref", "datadir_path", remmina_pref.datadir_path); + g_key_file_set_string(gkeyfile, "remmina_pref", "remmina_file_name", remmina_pref.remmina_file_name); g_key_file_set_string(gkeyfile, "remmina_pref", "screenshot_path", remmina_pref.screenshot_path); - g_key_file_set_string(gkeyfile, "remmina_pref", "screenshot_name", remmina_pref.screenshot_name); + g_key_file_set_string(gkeyfile, "remmina_pref", "remmina_file_name", remmina_pref.remmina_file_name); g_key_file_set_boolean(gkeyfile, "remmina_pref", "deny_screenshot_clipboard", remmina_pref.deny_screenshot_clipboard); g_key_file_set_boolean(gkeyfile, "remmina_pref", "save_view_mode", remmina_pref.save_view_mode); g_key_file_set_integer(gkeyfile, "remmina_pref", "floating_toolbar_placement", remmina_pref.floating_toolbar_placement); diff --git a/src/remmina_pref.h b/src/remmina_pref.h index 56161f8ce..ae6426f55 100644 --- a/src/remmina_pref.h +++ b/src/remmina_pref.h @@ -111,6 +111,7 @@ typedef struct _RemminaColorPref { typedef struct _RemminaPref { /* In RemminaPrefDialog options tab */ const gchar *datadir_path; + const gchar *remmina_file_name; const gchar *screenshot_path; gboolean deny_screenshot_clipboard; const gchar *screenshot_name; diff --git a/src/remmina_pref_dialog.c b/src/remmina_pref_dialog.c index fe70aae56..f08b3717b 100644 --- a/src/remmina_pref_dialog.c +++ b/src/remmina_pref_dialog.c @@ -161,6 +161,7 @@ void remmina_pref_on_dialog_destroy(GtkWidget *widget, gpointer user_data) gboolean rebuild_remmina_icon = FALSE; remmina_pref.datadir_path = gtk_file_chooser_get_filename(remmina_pref_dialog->filechooserbutton_options_datadir_path); + remmina_pref.remmina_file_name = gtk_entry_get_text(remmina_pref_dialog->entry_options_file_name); remmina_pref.screenshot_path = gtk_file_chooser_get_filename(remmina_pref_dialog->filechooserbutton_options_screenshots_path); remmina_pref.screenshot_name = gtk_entry_get_text(remmina_pref_dialog->entry_options_screenshot_name); remmina_pref.deny_screenshot_clipboard = gtk_switch_get_active(GTK_SWITCH(remmina_pref_dialog->switch_options_deny_screenshot_clipboard)); @@ -510,6 +511,11 @@ static void remmina_pref_dialog_init(void) if (remmina_pref.datadir_path != NULL) { gtk_file_chooser_set_filename(remmina_pref_dialog->filechooserbutton_options_datadir_path, remmina_pref.datadir_path); } + if (remmina_pref.remmina_file_name != NULL) { + gtk_entry_set_text(remmina_pref_dialog->entry_options_file_name, remmina_pref.remmina_file_name); + }else{ + gtk_entry_set_text(remmina_pref_dialog->entry_options_file_name, "%G_%P_%N_%h.remmina"); + } if (remmina_pref.screenshot_path != NULL) { gtk_file_chooser_set_filename(remmina_pref_dialog->filechooserbutton_options_screenshots_path, remmina_pref.screenshot_path); }else{ @@ -548,6 +554,7 @@ GtkDialog* remmina_pref_dialog_new(gint default_tab, GtkWindow *parent) remmina_pref_dialog->notebook_preferences = GTK_NOTEBOOK(GET_OBJECT("notebook_preferences")); remmina_pref_dialog->filechooserbutton_options_datadir_path = GTK_FILE_CHOOSER(GET_OBJECT("filechooserbutton_options_datadir_path")); + remmina_pref_dialog->entry_options_file_name = GTK_ENTRY(GET_OBJECT("entry_options_file_name")); remmina_pref_dialog->filechooserbutton_options_screenshots_path = GTK_FILE_CHOOSER(GET_OBJECT("filechooserbutton_options_screenshots_path")); remmina_pref_dialog->entry_options_screenshot_name = GTK_ENTRY(GET_OBJECT("entry_options_screenshot_name")); remmina_pref_dialog->switch_options_deny_screenshot_clipboard = GTK_SWITCH(GET_OBJECT("switch_options_deny_screenshot_clipboard")); diff --git a/src/remmina_pref_dialog.h b/src/remmina_pref_dialog.h index 1e2cbfb1f..8005df1d9 100644 --- a/src/remmina_pref_dialog.h +++ b/src/remmina_pref_dialog.h @@ -49,6 +49,7 @@ typedef struct _RemminaPrefDialog { GtkNotebook *notebook_preferences; GtkFileChooser *filechooserbutton_options_datadir_path; + GtkEntry *entry_options_file_name; GtkFileChooser *filechooserbutton_options_screenshots_path; GtkEntry *entry_options_screenshot_name; GtkSwitch *switch_options_deny_screenshot_clipboard; |