Order desklet saved connections by alphabet please
Project superseded by https://sourceforge.net/projects/remmina/
Brought to you by:
erickwoods
I have the icon on my taskbar, if I click it I nicely get a list with my saved connections. I can even make folders, which then fold out. Very cool, but it has one issue, it seems to be ordered randomly (probably by fs read) and that's kind of confusing. It would be awesome if it could be ordered by alphabet.
Logged In: YES
user_id=177137
Originator: NO
Below is a patch that outlines the changes that I made in order to get the tsclient applet to sort the connections, as well as the tsclient application itself. I'd like to attach these as a patchfile, but I'm new to submitting code changes with sourceforge. Hope this helps...
Index: src/rdpfile.h
--- src/rdpfile.h (revision 62)
+++ src/rdpfile.h (working copy)
@@ -67,5 +67,4 @@
int rdp_file_get_screen (rdp_file *rdp_in, GtkWidget *main_window);
int rdp_file_set_from_line (rdp_file *rdp_in, const char *str_in);
int rdp_load_profile_launcher (GtkWidget *main_window);
-int rdp_files_to_list (GSList** list);
-GHashTable* rdp_files_to_hash (void);
+GTree* rdp_files_to_tree (void);
Index: src/rdpfile.c
===================================================================
--- src/rdpfile.c (revision 62)
+++ src/rdpfile.c (working copy)
@@ -927,17 +927,25 @@
return 0;
}
+/***************************************
+ * *
+ * combo_append *
+ * *
+ ***************************************/
+void combo_append(gpointer key, gpointer value, gpointer combo) {
+ gtk_combo_box_append_text(combo, key);
+}
+
/***************************************
* *
* rdp_load_profile_launcher *
* *
***************************************/
-int rdp_load_profile_launcher (GtkWidget *main_window)
-{
+int rdp_load_profile_launcher (GtkWidget *main_window) {
GtkComboBox *opt;
- GSList *lptr = NULL;
+ GTree *tree = NULL;
gchar *text;
static gulong handler_id = 0;
gint n, i;
@@ -958,22 +966,17 @@
gtk_combo_box_append_text (opt, _("Quick Connect"));
- rdp_files_to_list (&lptr);
+ tree = rdp_files_to_tree();
- while (lptr) {
- gtk_combo_box_append_text (opt, lptr->data);
+ g_tree_foreach(tree, (GTraverseFunc)combo_append, opt);
- g_free (lptr->data);
- lptr = lptr->next;
- }
-
gtk_combo_box_set_active (opt, 0);
handler_id = g_signal_connect (opt,
"changed",
G_CALLBACK (tsc_quick_pick_activate),
NULL);
- g_slist_free (lptr);
+ g_tree_destroy(tree);
/* complete successfully */
return 0;
@@ -981,72 +984,10 @@
/***************************************
* *
-* read_dir_list *
-* *
-***************************************/
-void read_dir_list (gchar *dir_name, GSList **list, const gchar *value) {
- GError *error;
- GDir *dir;
- const gchar *name;
- gchar *tmp_name;
-
- dir = g_dir_open (dir_name, 0, &error);
- while ((name = g_dir_read_name (dir)) != NULL) {
- tmp_name = g_build_path ("/", dir_name, name, NULL);
- if (g_file_test (tmp_name, G_FILE_TEST_IS_DIR)) {
- read_dir_list (tmp_name, list, name);
- } else {
- if (g_str_has_suffix (name, ".rdp")){
- gchar *tmp;
- if (g_ascii_strcasecmp (value, "-1") == 0) {
- tmp = g_strdup (name);
- } else {
- tmp = g_build_path ("/", value, name, NULL);
- }
- *list = g_slist_append (*list, tmp);
- }
- }
- g_free (tmp_name);
- }
- g_dir_close (dir);
-}
-
-/***************************************
-* *
-* rdp_files_to_list *
-* *
-***************************************/
-
-int rdp_files_to_list (GSList** list)
-{
- gchar *path_name;
- gint i;
-
- #ifdef TSCLIENT_DEBUG
- printf ("rdp_files_to_list\n");
- #endif
-
- // create .tsclient dir in ~/
- path_name = tsc_home_path ();
-
- read_dir_list (path_name, list, "-1");
-
- #ifdef TSCLIENT_DEBUG
- printf ("rdp_files_to_list count: %d\n", g_slist_length (*list));
- #endif
-
- g_free (path_name);
- // complete successfully
- return 0;
-}
-
-
-/***************************************
-* *
* read_dir *
* *
***************************************/
-void read_dir (gchar *dir_name, GHashTable *hash, const gchar *value) {
+void read_dir (gchar *dir_name, GTree *tree, const gchar *value) {
GError *error;
GDir *dir;
const gchar *name;
@@ -1056,10 +997,10 @@
while ((name = g_dir_read_name (dir)) != NULL) {
tmp_name = g_build_path ("/", dir_name, name, NULL);
if (g_file_test (tmp_name, G_FILE_TEST_IS_DIR)) {
- read_dir (tmp_name, hash, name);
+ read_dir (tmp_name, tree, name);
} else {
if (g_str_has_suffix (name, ".rdp")){
- g_hash_table_insert (hash, g_strdup (name), g_strdup (value));
+ g_tree_insert (tree, g_strdup (name), g_strdup (value));
}
}
g_free (tmp_name);
@@ -1069,22 +1010,22 @@
/***************************************
* *
-* rdp_files_to_hash *
+* rdp_files_to_tree *
* *
***************************************/
-GHashTable* rdp_files_to_hash(void){
+GTree* rdp_files_to_tree (void){
gchar *path_name;
- GHashTable *hash;
+ GTree *tree;
- hash = g_hash_table_new (g_str_hash, g_str_equal);
+ tree = g_tree_new((GCompareFunc)strcmp);
#ifdef TSCLIENT_DEBUG
printf ("rdp_files_to_list\n");
#endif
path_name = g_build_path ("/", g_get_home_dir (), ".tsclient", NULL);
- read_dir (path_name, hash, "-1");
+ read_dir (path_name, tree, "-1");
g_free (path_name);
- return hash;
+ return tree;
};
Index: applet/applet.c
===================================================================
--- applet/applet.c (revision 62)
+++ applet/applet.c (working copy)
@@ -150,7 +150,7 @@
gtk_widget_show_all (GTK_WIDGET (g_data->applet));
}
-void
+gboolean
create_menu (gpointer key, gpointer value, gpointer menu)
{
GtkMenu* submenu = NULL;
@@ -202,6 +202,7 @@
gtk_widget_show (GTK_WIDGET (mi));
}
}
+ return FALSE;
}
@@ -211,7 +212,7 @@
{
GtkMenu *menu = NULL;
GtkMenuItem *mi = NULL;
- GHashTable* hash=NULL;
+ GTree *tree = NULL;
g_return_val_if_fail (widget != NULL, FALSE) ;
g_return_val_if_fail (event != NULL, FALSE) ;
@@ -222,10 +223,10 @@
if (event->button.button == 1) {
/*user pressed the left mouse button*/
- hash = rdp_files_to_hash ();
+ tree = rdp_files_to_tree ();
menu = GTK_MENU (gtk_menu_new ());
- g_hash_table_foreach (hash, create_menu, menu);
+ g_tree_foreach (tree, create_menu, menu);
mi = (GtkMenuItem *) gtk_separator_menu_item_new ();
gtk_menu_shell_append ((GtkMenuShell *) menu, GTK_WIDGET (mi));
@@ -241,7 +242,7 @@
gtk_get_current_event_time ());
data->popup = menu;
- g_hash_table_destroy (hash);
+ g_tree_destroy (tree);
return TRUE;
}
Logged In: NO
I absolutely agree.
Will this be assigned to someone please?