Hi,

For my work, i try to modify the mn-applet to order connection by there priority.

The priority for the nma-gconf-connection can be get by the path of this connection.

I have a probleme when i tried to get te connection path. It seems to have illegal caracter at the beginning of the path.

Maybe, any modification of char in gchar could cause it?

The get_path function give a char *.

If you know something about comparable error can you help me.

I search a lot about this errors and i don't found any help.

I attach the patch of my modification, maybe you could help me better if you see the code i generated.


Thank for any help

Sebastien
diff -ru original/NetworkManager/libnm-util/libnm-util.ver 
modifier/NetworkManager/libnm-util/libnm-util.ver
--- original/NetworkManager/libnm-util/libnm-util.ver   2010-04-07 
20:01:15.497274563 +0200
+++ modifier/NetworkManager/libnm-util/libnm-util.ver   2010-04-07 
19:36:51.000000000 +0200
@@ -22,6 +22,7 @@
        nm_connection_remove_setting;
        nm_connection_replace_settings;
        nm_connection_set_path;
+       nm_connection_exchange_path_and_folder;
        nm_connection_set_scope;
        nm_connection_to_hash;
        nm_connection_update_secrets;
diff -ru original/NetworkManager/libnm-util/nm-connection.c 
modifier/NetworkManager/libnm-util/nm-connection.c
--- original/NetworkManager/libnm-util/nm-connection.c  2010-04-07 
20:01:15.497274563 +0200
+++ modifier/NetworkManager/libnm-util/nm-connection.c  2010-04-07 
19:40:19.000000000 +0200
@@ -22,7 +22,8 @@
  * (C) Copyright 2007 - 2009 Red Hat, Inc.
  * (C) Copyright 2007 - 2008 Novell, Inc.
  */
-
+#include <glib.h>
+#include <glib/gstdio.h>
 #include <glib-object.h>
 #include <dbus/dbus-glib.h>
 #include <string.h>
@@ -1001,6 +1002,31 @@
 }
 
 /**
+ * nm_connection_exchange_path_and_folder:
+ * @first_connection: first #NMConnection
+ * @second_connection: second #NMConnection
+ *
+ * Modify path and folder for the connection's D-Bus.
+ **/
+void
+nm_connection_exchange_path_and_folder (NMConnection *first_connection,
+                                        NMConnection *second_connection)
+{
+       const gchar * first_path;
+       const gchar * second_path;
+
+       first_path = NM_CONNECTION_GET_PRIVATE (first_connection)->path;
+       second_path = NM_CONNECTION_GET_PRIVATE (second_connection)->path;
+
+       nm_connection_set_path(first_connection,second_path);
+       nm_connection_set_path(second_connection,first_path);
+
+       g_rename(first_path,"/temp");
+       g_rename(second_path,first_path);
+       g_rename("/temp",second_path);
+}
+
+/**
  * nm_connection_new:
  *
  * Creates a new #NMConnection object with no #NMSetting objects.
diff -ru original/NetworkManager/libnm-util/nm-connection.h 
modifier/NetworkManager/libnm-util/nm-connection.h
--- original/NetworkManager/libnm-util/nm-connection.h  2010-04-07 
20:01:15.497274563 +0200
+++ modifier/NetworkManager/libnm-util/nm-connection.h  2010-04-07 
19:34:26.000000000 +0200
@@ -147,6 +147,9 @@
 void             nm_connection_set_path (NMConnection *connection,
                                          const char *path);
 
+void                    nm_connection_exchange_path_and_folder (NMConnection 
*first_connection,
+                                                         NMConnection 
*second_connection);
+
 const char *     nm_connection_get_path (NMConnection *connection);
 
 void          nm_connection_for_each_setting_value (NMConnection *connection,
diff -ru 
original/network-manager-applet/src/connection-editor/nm-connection-list.c 
modifier/network-manager-applet/src/connection-editor/nm-connection-list.c
--- original/network-manager-applet/src/connection-editor/nm-connection-list.c  
2010-04-07 19:55:46.941750115 +0200
+++ modifier/network-manager-applet/src/connection-editor/nm-connection-list.c  
2010-04-07 19:47:32.000000000 +0200
@@ -25,6 +25,10 @@
 #include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <stdio.h>
+#include <string.h>
 
 #include <gtk/gtk.h>
 #include <gconf/gconf-client.h>
@@ -68,10 +72,11 @@
 
 static guint list_signals[LIST_LAST_SIGNAL] = { 0 };
 
-#define COL_ID                         0
+#define COL_ID         0
 #define COL_LAST_USED  1
 #define COL_TIMESTAMP  2
 #define COL_CONNECTION 3
+#define COL_PRIORITY   4
 
 typedef struct {
        NMConnectionList *list;
@@ -280,6 +285,31 @@
        return last_used;
 }
 
+
+
+static guint
+get_connection_priority(NMConnection * connection)
+{
+       const char * connection_path;
+       int length;
+       int priority;
+
+       if ( nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_USER )
+               connection_path = 
nma_gconf_connection_get_gconf_path(NMA_GCONF_CONNECTION(connection));
+       else
+               connection_path = nm_connection_get_path(connection);
+
+       length = strlen (connection_path);
+
+       while ( connection_path[length] != '/' ) {
+               length--;
+       }
+       sscanf (connection_path+length+1,"%d", &priority);
+
+       return priority;
+}
+
+
 static void
 update_connection_row (GtkListStore *store,
                        GtkTreeIter *iter,
@@ -297,6 +327,7 @@
                            COL_LAST_USED, last_used,
                            COL_TIMESTAMP, nm_setting_connection_get_timestamp 
(s_con),
                            COL_CONNECTION, connection,
+                           COL_PRIORITY,get_connection_priority(NM_CONNECTION 
(connection)),
                            -1);
        g_free (last_used);
 }
@@ -848,6 +879,162 @@
                delete_connection (info->list, connection, delete_result_cb, 
GTK_WINDOW (info->list->dialog));
 }
 
+
+static void
+connection_updated (NMSettingsConnectionInterface *connection,
+                    GHashTable *settings,
+                    gpointer user_data);
+
+
+/**
+ * This function exchange the path of connection ( in the code ) and exchange 
folder
+ */
+static void
+exchange_connection_priority (NMConnection *first_connection,
+                              NMConnection *second_connection,
+                              GConfClient *client)
+{
+       NMConnectionScope first_scope;
+       NMConnectionScope second_scope;
+
+       first_scope = nm_connection_get_scope (first_connection);
+       second_scope = nm_connection_get_scope ( second_connection);
+
+       /* we exchange priority only if they are in the same scope */
+       if ( first_scope != second_scope ) {
+               g_warning ("Impossible to exchange priorirty of connection of 
different scope");
+               return;
+               }
+
+       if ( first_scope == NM_CONNECTION_SCOPE_USER )
+               nma_gconf_connection_exchange_gconf_path_and_folder 
(NMA_GCONF_CONNECTION(first_connection),
+                                                             
NMA_GCONF_CONNECTION(second_connection),
+                                                             client);
+       else
+               nm_connection_exchange_path_and_folder (first_connection,
+                                                second_connection);
+}
+
+
+/*
+ * this function permit to retrieve the previous connection in the model of 
one given in argument
+ */
+static NMSettingsConnectionInterface *
+get_previous_connection_from_model (GtkTreeModel *model,
+                                  NMSettingsConnectionInterface *connection)
+{
+       GtkTreeIter iter;
+       NMSettingsConnectionInterface *previous = NULL;
+
+       if (!gtk_tree_model_get_iter_first (model, &iter))
+               return NULL;
+
+       do {
+               NMSettingsConnectionInterface *candidate = NULL;
+
+               gtk_tree_model_get (model, &iter, COL_CONNECTION, &candidate, 
-1);
+               if (candidate && (candidate == connection)) {
+                       if ( previous != NULL )
+                               return previous;
+                       else
+                               return NULL;
+               } else {
+                       previous = candidate;
+               }
+       } while (gtk_tree_model_iter_next (model, &iter));
+       return NULL;
+}
+
+static void
+up_clicked (GtkButton *button, gpointer user_data)
+{
+       NMSettingsConnectionInterface *connection;
+       NMSettingsConnectionInterface *connection_to_exchange_priority;
+       ActionInfo * info = (ActionInfo *) user_data;
+       GtkTreeIter iter;
+       GtkTreeModel *model;
+       GtkListStore *store;
+
+       model = gtk_tree_view_get_model (info->treeview);
+
+       connection = get_active_connection (info->treeview);
+       g_assert(connection);
+
+       if ( get_iter_for_connection (model,
+                                  connection,
+                                  &iter) ) {
+               connection_to_exchange_priority = 
get_previous_connection_from_model(model,
+                                                                             
connection);
+               if ( connection_to_exchange_priority == NULL ) {
+                       g_warning("Couldn't increase priority : there is no 
connection with higher priority");
+                       return;
+                       }
+
+               store = get_model_for_connection (info->list, 
connection_to_exchange_priority);
+
+               /* update connection file and path of two concerned connection 
*/
+               exchange_connection_priority (NM_CONNECTION (connection),
+                                      NM_CONNECTION 
(connection_to_exchange_priority),
+                                      info->list->client);
+
+               /* update the display of two concerned connection */
+               connection_updated (connection,
+                            nm_connection_to_hash (NM_CONNECTION (connection)),
+                            store);
+               connection_updated (connection_to_exchange_priority,
+                            nm_connection_to_hash (NM_CONNECTION 
(connection_to_exchange_priority)),
+                            store);
+
+       } else {
+               g_warning ( "Could not find iter for active connection");
+       }
+}
+
+static void
+down_clicked (GtkButton *button, gpointer user_data)
+{
+       NMSettingsConnectionInterface *connection;
+       NMSettingsConnectionInterface *connection_to_exchange_priority;
+       ActionInfo * info = (ActionInfo *) user_data;
+       GtkTreeIter iter;
+       GtkTreeModel *model;
+       GtkListStore *store;
+
+       model = gtk_tree_view_get_model (info->treeview);
+
+       connection = get_active_connection (info->treeview);
+       g_assert(connection);
+
+       if ( get_iter_for_connection (model,
+                                  connection,
+                                  &iter) ) {
+               if ( gtk_tree_model_iter_next(model,&iter) ) {
+                       gtk_tree_model_get (model, &iter,
+                                COL_CONNECTION, 
&connection_to_exchange_priority, -1);
+
+                       store = get_model_for_connection (info->list, 
connection_to_exchange_priority);
+
+                       /* update connection file of two concerned connection */
+                       exchange_connection_priority (NM_CONNECTION 
(connection),
+                                          NM_CONNECTION 
(connection_to_exchange_priority),
+                                          info->list->client);
+
+                       /* update the display of two concerned connection */
+                       connection_updated (connection,
+                                nm_connection_to_hash (NM_CONNECTION 
(connection)),
+                                store);
+                       connection_updated (connection_to_exchange_priority,
+                                nm_connection_to_hash (NM_CONNECTION 
(connection_to_exchange_priority)),
+                                store);
+
+               } else {
+                       g_warning ( "Couldn't decrease priority : there is no 
connection with lower priority");
+               }
+       } else {
+               g_warning ( "Could not find iter for active connection");
+       }
+}
+
 static void
 pk_button_selection_changed_cb (GtkTreeSelection *selection, gpointer 
user_data)
 {
@@ -1117,10 +1304,10 @@
        gtk_tree_view_set_headers_visible (treeview, TRUE);
 
        /* Model */
-       model = GTK_TREE_MODEL (gtk_list_store_new (4, G_TYPE_STRING, 
G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_OBJECT));
+       model = GTK_TREE_MODEL (gtk_list_store_new (5, G_TYPE_STRING, 
G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_OBJECT,G_TYPE_UINT));
        sort_model = gtk_tree_model_sort_new_with_model (model);
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
-                                             COL_TIMESTAMP, 
GTK_SORT_DESCENDING);
+                                             COL_PRIORITY, GTK_SORT_ASCENDING);
        gtk_tree_view_set_model (treeview, sort_model);
 
        /* Name column */
@@ -1141,6 +1328,12 @@
                                                     "text", COL_LAST_USED,
                                                     NULL);
 
+       /* Priority column */
+       gtk_tree_view_insert_column_with_attributes (treeview,
+                                                    -1, _("Priority"), 
gtk_cell_renderer_text_new (),
+                                                    "text", COL_PRIORITY,
+                                                    NULL);
+
        /* Selection */
        selection = gtk_tree_view_get_selection (treeview);
        gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
@@ -1271,6 +1464,38 @@
        g_signal_connect (selection, "changed", G_CALLBACK 
(pk_button_selection_changed_cb), info);
        pk_button_selection_changed_cb (selection, info);
 
+       /* Up */
+       info = action_info_new (self, treeview, GTK_WINDOW (self->dialog), 
NULL);
+       button = ce_polkit_button_new (_("Up"),
+                                      _("Increase the priority of the selected 
connection"),
+                                      _("Up"),
+                                      _("Authenticate to increase priority of 
the selected connection"),
+                                      GTK_STOCK_GO_UP,
+                                      self->system_settings,
+                                      
NM_SETTINGS_SYSTEM_PERMISSION_CONNECTION_MODIFY);
+       gtk_box_pack_end (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+
+       action_info_set_button (info, button);
+       g_signal_connect (button, "clicked", G_CALLBACK (up_clicked), info);
+       g_signal_connect (selection, "changed", G_CALLBACK 
(pk_button_selection_changed_cb), info);
+       pk_button_selection_changed_cb (selection, info);
+
+       /* Down */
+       info = action_info_new (self, treeview, GTK_WINDOW (self->dialog), 
NULL);
+       button = ce_polkit_button_new (_("Down"),
+                                      _("Decrease the priority of the selected 
connection"),
+                                      _("Down"),
+                                      _("Authenticate to decrease priority of 
the selected connection"),
+                                      GTK_STOCK_GO_DOWN,
+                                      self->system_settings,
+                                      
NM_SETTINGS_SYSTEM_PERMISSION_CONNECTION_MODIFY);
+       gtk_box_pack_end (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+
+       action_info_set_button (info, button);
+       g_signal_connect (button, "clicked", G_CALLBACK (down_clicked), info);
+       g_signal_connect (selection, "changed", G_CALLBACK 
(pk_button_selection_changed_cb), info);
+       pk_button_selection_changed_cb (selection, info);
+
        /* Import */
        name = g_strdup_printf ("%s_import", prefix);
        button = glade_xml_get_widget (self->gui, name);
@@ -1416,6 +1641,7 @@
                            COL_LAST_USED, last_used,
                            COL_TIMESTAMP, nm_setting_connection_get_timestamp 
(s_con),
                            COL_CONNECTION, connection,
+                           COL_PRIORITY,get_connection_priority(NM_CONNECTION 
(connection)),
                            -1);
 
        g_free (last_used);
diff -ru 
original/network-manager-applet/src/gconf-helpers/nma-gconf-connection.c 
modifier/network-manager-applet/src/gconf-helpers/nma-gconf-connection.c
--- original/network-manager-applet/src/gconf-helpers/nma-gconf-connection.c    
2010-04-07 19:55:46.941750115 +0200
+++ modifier/network-manager-applet/src/gconf-helpers/nma-gconf-connection.c    
2010-04-07 19:31:50.000000000 +0200
@@ -149,6 +149,57 @@
        return NMA_GCONF_CONNECTION_GET_PRIVATE (self)->dir;
 }
 
+
+void
+nma_gconf_connection_exchange_gconf_path_and_folder (NMAGConfConnection *first,
+                                                     NMAGConfConnection 
*second,
+                                                     GConfClient *client)
+{
+       NMAGConfConnectionPrivate *priv;
+       char * first_path;
+       char * second_path;
+       g_return_if_fail (NMA_IS_GCONF_CONNECTION (first));
+       g_return_if_fail (NMA_IS_GCONF_CONNECTION (second));
+
+       // set the gconf path in memory for the first one
+       priv = NMA_GCONF_CONNECTION_GET_PRIVATE (first);
+
+       first_path = priv->dir;
+
+       if (priv->dir) {
+               g_free (priv->dir);
+               priv->dir = NULL;
+       }
+
+       if (first_path)
+               priv->dir = g_strdup (first_path);
+
+       // set the gconf path in memory for the second one
+       priv = NMA_GCONF_CONNECTION_GET_PRIVATE (second);
+
+       second_path = priv->dir;
+
+       if (priv->dir) {
+               g_free (priv->dir);
+               priv->dir = NULL;
+       }
+
+       if (second_path)
+               priv->dir = g_strdup (second_path);
+
+       // move folder to be ok
+       nm_gconf_write_connection (NM_CONNECTION (first),
+                               client,
+                               second_path,
+                               FALSE);
+
+       nm_gconf_write_connection (NM_CONNECTION (second),
+                               client,
+                               first_path,
+                               FALSE);
+}
+
+
 static void
 add_vpn_user_name (NMConnection *connection)
 {
diff -ru 
original/network-manager-applet/src/gconf-helpers/nma-gconf-connection.h 
modifier/network-manager-applet/src/gconf-helpers/nma-gconf-connection.h
--- original/network-manager-applet/src/gconf-helpers/nma-gconf-connection.h    
2010-04-07 19:55:46.941750115 +0200
+++ modifier/network-manager-applet/src/gconf-helpers/nma-gconf-connection.h    
2010-04-07 19:00:18.000000000 +0200
@@ -74,6 +74,10 @@
 
 const char *nma_gconf_connection_get_gconf_path (NMAGConfConnection *self);
 
+void nma_gconf_connection_exchange_gconf_path_and_folder (NMAGConfConnection 
*first,
+                                                          NMAGConfConnection 
*second,
+                                                          GConfClient *client);
+
 void nma_gconf_connection_update (NMAGConfConnection *self,
                                   gboolean ignore_secrets);
 
_______________________________________________
networkmanager-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to