diff options
author | Antonio Petricca <antonio.petricca@gmail.com> | 2022-08-05 10:31:30 +0300 |
---|---|---|
committer | Antenore Gatta (tmow) <antenore@simbiosi.org> | 2022-08-05 10:31:30 +0300 |
commit | 22a804b451a7012efdd54b61ba3c7d0bbabb99b7 (patch) | |
tree | fcff2c272ddde9c35644d87a5bd7c4f5379faa4f /src | |
parent | 1283ff2a3423ff5a910fff619124fcc1bc87dcbb (diff) |
Adding Labels/Tags
Diffstat (limited to 'src')
-rw-r--r-- | src/remmina_file_editor.c | 36 | ||||
-rw-r--r-- | src/remmina_file_manager.h | 1 | ||||
-rw-r--r-- | src/remmina_main.c | 71 |
3 files changed, 87 insertions, 21 deletions
diff --git a/src/remmina_file_editor.c b/src/remmina_file_editor.c index d22cd3138..19124b388 100644 --- a/src/remmina_file_editor.c +++ b/src/remmina_file_editor.c @@ -94,6 +94,7 @@ struct _RemminaFileEditorPriv { const gchar * avahi_service_type; GtkWidget * name_entry; + GtkWidget * labels_entry; GtkWidget * group_combo; GtkWidget * protocol_combo; GtkWidget * save_button; @@ -1636,6 +1637,8 @@ static GError* remmina_file_editor_update(RemminaFileEditor *gfe, remmina_file_set_string(priv->remmina_file, "name", gtk_entry_get_text(GTK_ENTRY(priv->name_entry))); + remmina_file_set_string(priv->remmina_file, "labels", gtk_entry_get_text(GTK_ENTRY(priv->labels_entry))); + remmina_file_set_string(priv->remmina_file, "group", (priv->group_combo ? remmina_public_combo_get_active_text(GTK_COMBO_BOX(priv->group_combo)) : NULL)); @@ -1926,6 +1929,8 @@ GtkWidget *remmina_file_editor_new_from_file(RemminaFile *remminafile) //remmina_public_create_group(GTK_GRID(grid), _("Profile"), 0, 4, 3); + gboolean profile_file_exists = (remmina_file_get_filename(remminafile) != NULL); + /* Profile: Name */ widget = gtk_label_new(_("Name")); gtk_widget_show(widget); @@ -1940,7 +1945,7 @@ GtkWidget *remmina_file_editor_new_from_file(RemminaFile *remminafile) gtk_entry_set_max_length(GTK_ENTRY(widget), 100); priv->name_entry = widget; - if (remmina_file_get_filename(remminafile) == NULL) { + if (!profile_file_exists) { gtk_entry_set_text(GTK_ENTRY(widget), _("Quick Connect")); #if GTK_CHECK_VERSION(3, 16, 0) gtk_entry_grab_focus_without_selecting(GTK_ENTRY(widget)); @@ -1969,16 +1974,41 @@ GtkWidget *remmina_file_editor_new_from_file(RemminaFile *remminafile) gtk_widget_set_tooltip_text(priv->group_combo, s); g_free(s); + /* Profile: Labels */ + widget = gtk_label_new(_("Labels")); + gtk_widget_show(widget); + gtk_widget_set_valign(widget, GTK_ALIGN_START); + gtk_widget_set_halign(widget, GTK_ALIGN_START); + gtk_grid_attach(GTK_GRID(grid), widget, 0, 9, 2, 1); + gtk_grid_set_column_spacing(GTK_GRID(grid), 10); + + widget = gtk_entry_new(); + gtk_widget_show(widget); + gtk_grid_attach(GTK_GRID(grid), widget, 1, 9, 3, 1); + gtk_entry_set_max_length(GTK_ENTRY(widget), 255); + priv->labels_entry = widget; + + if (!profile_file_exists) { + gtk_entry_set_text(GTK_ENTRY(widget), _("Label1,Label2")); +#if GTK_CHECK_VERSION(3, 16, 0) + gtk_entry_grab_focus_without_selecting(GTK_ENTRY(widget)); +#endif + g_signal_connect(G_OBJECT(widget), "changed", G_CALLBACK(remmina_file_editor_entry_on_changed), gfe); + } else { + cs = remmina_file_get_string(remminafile, "labels"); + gtk_entry_set_text(GTK_ENTRY(widget), cs ? cs : ""); + } + /* Profile: Protocol */ widget = gtk_label_new(_("Protocol")); gtk_widget_show(widget); gtk_widget_set_valign(widget, GTK_ALIGN_START); gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, 9, 2, 1); + gtk_grid_attach(GTK_GRID(grid), widget, 0, 12, 2, 1); widget = remmina_public_create_combo(TRUE); gtk_widget_show(widget); - gtk_grid_attach(GTK_GRID(grid), widget, 1, 9, 3, 1); + gtk_grid_attach(GTK_GRID(grid), widget, 1, 12, 3, 1); priv->protocol_combo = widget; remmina_plugin_manager_for_each_plugin(REMMINA_PLUGIN_TYPE_PROTOCOL, remmina_file_editor_iterate_protocol, gfe); g_signal_connect(G_OBJECT(widget), "changed", G_CALLBACK(remmina_file_editor_protocol_combo_on_changed), gfe); diff --git a/src/remmina_file_manager.h b/src/remmina_file_manager.h index 5cd5ab9ea..8c9c9c38a 100644 --- a/src/remmina_file_manager.h +++ b/src/remmina_file_manager.h @@ -43,6 +43,7 @@ typedef struct _RemminaGroupData { gchar * name; gchar * group; gchar * datetime; + gchar * labels; } RemminaGroupData; /* Initialize */ diff --git a/src/remmina_main.c b/src/remmina_main.c index bb259749a..1ef407335 100644 --- a/src/remmina_main.c +++ b/src/remmina_main.c @@ -75,6 +75,7 @@ enum { PLUGIN_COLUMN, DATE_COLUMN, FILENAME_COLUMN, + LABELS_COLUMN, N_COLUMNS }; @@ -366,6 +367,7 @@ static void remmina_main_load_file_list_callback(RemminaFile *remminafile, gpoin PLUGIN_COLUMN, remmina_file_get_string(remminafile, "protocol"), DATE_COLUMN, datetime, FILENAME_COLUMN, remmina_file_get_filename(remminafile), + LABELS_COLUMN, remmina_file_get_string(remminafile, "labels"), -1); g_free(datetime); } @@ -388,6 +390,7 @@ static gboolean remmina_main_load_file_tree_traverse(GNode *node, GtkTreeStore * GROUP_COLUMN, data->group, DATE_COLUMN, data->datetime, FILENAME_COLUMN, NULL, + LABELS_COLUMN, data->labels, -1); } for (child = g_node_first_child(node); child; child = g_node_next_sibling(child)) @@ -498,6 +501,7 @@ static void remmina_main_load_file_tree_callback(RemminaFile *remminafile, gpoin PLUGIN_COLUMN, remmina_file_get_string(remminafile, "protocol"), DATE_COLUMN, datetime, FILENAME_COLUMN, remmina_file_get_filename(remminafile), + LABELS_COLUMN, remmina_file_get_string(remminafile, "labels"), -1); g_free(datetime); } @@ -518,7 +522,7 @@ static gboolean remmina_main_filter_visible_func(GtkTreeModel *model, GtkTreeIte { TRACE_CALL(__func__); gchar *text; - gchar *protocol, *name, *group, *server, *plugin, *date, *s; + gchar *protocol, *name, *labels, *group, *server, *plugin, *date, *s; gboolean result = TRUE; text = g_ascii_strdown(gtk_entry_get_text(remminamain->entry_quick_connect_server), -1); @@ -530,6 +534,7 @@ static gboolean remmina_main_filter_visible_func(GtkTreeModel *model, GtkTreeIte SERVER_COLUMN, &server, PLUGIN_COLUMN, &plugin, DATE_COLUMN, &date, + LABELS_COLUMN, &labels, -1); if (g_strcmp0(protocol, "folder-symbolic") != 0) { s = g_ascii_strdown(name ? name : "", -1); @@ -547,10 +552,54 @@ static gboolean remmina_main_filter_visible_func(GtkTreeModel *model, GtkTreeIte s = g_ascii_strdown(date ? date : "", -1); g_free(date); date = s; - result = ( strstr(name, text) || strstr(group, text) || strstr(server, text) || strstr(plugin, text) || strstr(date, text)); + result = (strstr(name, text) || strstr(group, text) || strstr(server, text) || strstr(plugin, text) || strstr(date, text)); + + // Filter by labels + + s = g_ascii_strdown(labels ? labels : "", -1); + g_free(labels); + labels = s; + + if (strlen(labels) > 0) { + gboolean labels_result = TRUE; + gchar **labels_array = g_strsplit(labels, ",", -1); + gchar **text_array = g_strsplit(text, ",", -1); + + for (int t = 0; (NULL != text_array[t]); t++) { + if (0 == strlen(text_array[t])) { + continue; + } + + gboolean text_result = FALSE; + + for (int l = 0; (NULL != labels_array[l]); l++) { + if (0 == strlen(labels_array[l])) { + continue; + } + + text_result = (text_result || strstr(labels_array[l], text_array[t])); + + if (text_result) { + break; + } + } + + labels_result = (labels_result && text_result); + + if (!labels_result) { + break; + } + } + + result = (result || labels_result); + + g_strfreev(labels_array); + g_strfreev(text_array); + } } g_free(protocol); g_free(name); + g_free(labels); g_free(group); g_free(server); g_free(plugin); @@ -620,14 +669,7 @@ static void remmina_main_load_files() switch (view_file_mode) { case REMMINA_VIEW_FILE_TREE: /* Create new GtkTreeStore model */ - newmodel = GTK_TREE_MODEL(gtk_tree_store_new(7, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING)); + newmodel = GTK_TREE_MODEL(gtk_tree_store_new(8, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING)); /* Hide the Group column in the tree view mode */ gtk_tree_view_column_set_visible(remminamain->column_files_list_group, FALSE); /* Load groups first */ @@ -639,14 +681,7 @@ static void remmina_main_load_files() case REMMINA_VIEW_FILE_LIST: default: /* Create new GtkListStore model */ - newmodel = GTK_TREE_MODEL(gtk_list_store_new(7, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING)); + newmodel = GTK_TREE_MODEL(gtk_list_store_new(8, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING)); /* Show the Group column in the list view mode */ gtk_tree_view_column_set_visible(remminamain->column_files_list_group, TRUE); /* Load files list */ |