network-manager-applet r526 - in trunk: . src/connection-editor



Author: dcbw
Date: Thu Feb 14 17:26:23 2008
New Revision: 526
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=526&view=rev

Log:
2008-02-14  Dan Williams  <dcbw redhat com>

	* src/connection-editor/nm-connection-editor.glade
	  src/connection-editor/nm-connection-list.c
	  src/connection-editor/nm-connection-list.h
		- Revamp the connection list; tabs for each connection type, show the
			time the last time the network was used, and hook up the
			double-click handler



Modified:
   trunk/ChangeLog
   trunk/src/connection-editor/nm-connection-editor.glade
   trunk/src/connection-editor/nm-connection-list.c
   trunk/src/connection-editor/nm-connection-list.h

Modified: trunk/src/connection-editor/nm-connection-editor.glade
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.glade	(original)
+++ trunk/src/connection-editor/nm-connection-editor.glade	Thu Feb 14 17:26:23 2008
@@ -227,91 +227,480 @@
       </child>
 
       <child>
-	<widget class="GtkHBox" id="hbox1">
-	  <property name="border_width">5</property>
+	<widget class="GtkNotebook" id="list_notebook">
 	  <property name="visible">True</property>
-	  <property name="homogeneous">False</property>
-	  <property name="spacing">6</property>
+	  <property name="can_focus">True</property>
+	  <property name="show_tabs">True</property>
+	  <property name="show_border">True</property>
+	  <property name="tab_pos">GTK_POS_TOP</property>
+	  <property name="scrollable">False</property>
+	  <property name="enable_popup">False</property>
 
 	  <child>
-	    <widget class="GtkScrolledWindow" id="scrolledwindow4">
+	    <widget class="GtkHBox" id="wired_child">
+	      <property name="border_width">6</property>
 	      <property name="visible">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
-	      <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
-	      <property name="shadow_type">GTK_SHADOW_IN</property>
-	      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
 
 	      <child>
-		<widget class="GtkTreeView" id="connection_list">
+		<widget class="GtkScrolledWindow" id="scolledwindow1">
 		  <property name="visible">True</property>
 		  <property name="can_focus">True</property>
-		  <property name="headers_visible">False</property>
-		  <property name="rules_hint">True</property>
-		  <property name="reorderable">False</property>
-		  <property name="enable_search">True</property>
-		  <property name="fixed_height_mode">False</property>
-		  <property name="hover_selection">False</property>
-		  <property name="hover_expand">False</property>
+		  <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="shadow_type">GTK_SHADOW_IN</property>
+		  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+		  <child>
+		    <widget class="GtkTreeView" id="wired_list">
+		      <property name="visible">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="headers_visible">False</property>
+		      <property name="rules_hint">True</property>
+		      <property name="reorderable">False</property>
+		      <property name="enable_search">True</property>
+		      <property name="fixed_height_mode">False</property>
+		      <property name="hover_selection">False</property>
+		      <property name="hover_expand">False</property>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkVButtonBox" id="vbuttonbox2">
+		  <property name="visible">True</property>
+		  <property name="layout_style">GTK_BUTTONBOX_START</property>
+		  <property name="spacing">6</property>
+
+		  <child>
+		    <widget class="GtkButton" id="wired_add">
+		      <property name="visible">True</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-add</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkButton" id="wired_edit">
+		      <property name="visible">True</property>
+		      <property name="sensitive">False</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-edit</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkButton" id="wired_delete">
+		      <property name="visible">True</property>
+		      <property name="sensitive">False</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-delete</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
 		</widget>
+		<packing>
+		  <property name="padding">6</property>
+		  <property name="expand">False</property>
+		  <property name="fill">True</property>
+		</packing>
 	      </child>
 	    </widget>
 	    <packing>
-	      <property name="padding">0</property>
-	      <property name="expand">True</property>
-	      <property name="fill">True</property>
+	      <property name="tab_expand">False</property>
+	      <property name="tab_fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkLabel" id="wired_label">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">Wired</property>
+	      <property name="use_underline">False</property>
+	      <property name="use_markup">False</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0.5</property>
+	      <property name="yalign">0.5</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
+	    </widget>
+	    <packing>
+	      <property name="type">tab</property>
 	    </packing>
 	  </child>
 
 	  <child>
-	    <widget class="GtkVButtonBox" id="vbuttonbox1">
+	    <widget class="GtkHBox" id="wireless_child">
+	      <property name="border_width">6</property>
 	      <property name="visible">True</property>
-	      <property name="layout_style">GTK_BUTTONBOX_START</property>
-	      <property name="spacing">6</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
 
 	      <child>
-		<widget class="GtkButton" id="add_connection_button">
+		<widget class="GtkScrolledWindow" id="scrolledwindow2">
 		  <property name="visible">True</property>
-		  <property name="can_default">True</property>
 		  <property name="can_focus">True</property>
-		  <property name="label">gtk-add</property>
-		  <property name="use_stock">True</property>
-		  <property name="relief">GTK_RELIEF_NORMAL</property>
-		  <property name="focus_on_click">True</property>
+		  <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="shadow_type">GTK_SHADOW_IN</property>
+		  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+		  <child>
+		    <widget class="GtkTreeView" id="wireless_list">
+		      <property name="visible">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="headers_visible">False</property>
+		      <property name="rules_hint">True</property>
+		      <property name="reorderable">False</property>
+		      <property name="enable_search">True</property>
+		      <property name="fixed_height_mode">False</property>
+		      <property name="hover_selection">False</property>
+		      <property name="hover_expand">False</property>
+		    </widget>
+		  </child>
 		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
 	      </child>
 
 	      <child>
-		<widget class="GtkButton" id="edit_connection_button">
+		<widget class="GtkVButtonBox" id="vbuttonbox3">
+		  <property name="visible">True</property>
+		  <property name="layout_style">GTK_BUTTONBOX_START</property>
+		  <property name="spacing">6</property>
+
+		  <child>
+		    <widget class="GtkButton" id="wireless_add">
+		      <property name="visible">True</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-add</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkButton" id="wireless_edit">
+		      <property name="visible">True</property>
+		      <property name="sensitive">False</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-edit</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkButton" id="wireless_delete">
+		      <property name="visible">True</property>
+		      <property name="sensitive">False</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-delete</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">6</property>
+		  <property name="expand">False</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="tab_expand">False</property>
+	      <property name="tab_fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkLabel" id="wireless_label">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">Wireless</property>
+	      <property name="use_underline">False</property>
+	      <property name="use_markup">False</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0.5</property>
+	      <property name="yalign">0.5</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
+	    </widget>
+	    <packing>
+	      <property name="type">tab</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkHBox" id="wwan_child">
+	      <property name="border_width">6</property>
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<widget class="GtkScrolledWindow" id="scrolledwindow3">
 		  <property name="visible">True</property>
-		  <property name="sensitive">False</property>
-		  <property name="can_default">True</property>
 		  <property name="can_focus">True</property>
-		  <property name="label">gtk-edit</property>
-		  <property name="use_stock">True</property>
-		  <property name="relief">GTK_RELIEF_NORMAL</property>
-		  <property name="focus_on_click">True</property>
+		  <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="shadow_type">GTK_SHADOW_IN</property>
+		  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+		  <child>
+		    <widget class="GtkTreeView" id="wwan_list">
+		      <property name="visible">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="headers_visible">False</property>
+		      <property name="rules_hint">True</property>
+		      <property name="reorderable">False</property>
+		      <property name="enable_search">True</property>
+		      <property name="fixed_height_mode">False</property>
+		      <property name="hover_selection">False</property>
+		      <property name="hover_expand">False</property>
+		    </widget>
+		  </child>
 		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
 	      </child>
 
 	      <child>
-		<widget class="GtkButton" id="delete_connection_button">
+		<widget class="GtkVButtonBox" id="vbuttonbox4">
+		  <property name="visible">True</property>
+		  <property name="layout_style">GTK_BUTTONBOX_START</property>
+		  <property name="spacing">6</property>
+
+		  <child>
+		    <widget class="GtkButton" id="wwan_add">
+		      <property name="visible">True</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-add</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkButton" id="wwan_edit">
+		      <property name="visible">True</property>
+		      <property name="sensitive">False</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-edit</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkButton" id="wwan_delete">
+		      <property name="visible">True</property>
+		      <property name="sensitive">False</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-delete</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">6</property>
+		  <property name="expand">False</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="tab_expand">False</property>
+	      <property name="tab_fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkLabel" id="wwan_label">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">Mobile Broadband</property>
+	      <property name="use_underline">False</property>
+	      <property name="use_markup">False</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0.5</property>
+	      <property name="yalign">0.5</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
+	    </widget>
+	    <packing>
+	      <property name="type">tab</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkHBox" id="vpn_child">
+	      <property name="border_width">6</property>
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<widget class="GtkScrolledWindow" id="scrolledwindow4">
 		  <property name="visible">True</property>
-		  <property name="sensitive">False</property>
-		  <property name="can_default">True</property>
 		  <property name="can_focus">True</property>
-		  <property name="label">gtk-delete</property>
-		  <property name="use_stock">True</property>
-		  <property name="relief">GTK_RELIEF_NORMAL</property>
-		  <property name="focus_on_click">True</property>
+		  <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="shadow_type">GTK_SHADOW_IN</property>
+		  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+		  <child>
+		    <widget class="GtkTreeView" id="vpn_list">
+		      <property name="visible">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="headers_visible">False</property>
+		      <property name="rules_hint">True</property>
+		      <property name="reorderable">False</property>
+		      <property name="enable_search">True</property>
+		      <property name="fixed_height_mode">False</property>
+		      <property name="hover_selection">False</property>
+		      <property name="hover_expand">False</property>
+		    </widget>
+		  </child>
 		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
 	      </child>
+
+	      <child>
+		<widget class="GtkVButtonBox" id="vbuttonbox5">
+		  <property name="visible">True</property>
+		  <property name="layout_style">GTK_BUTTONBOX_START</property>
+		  <property name="spacing">6</property>
+
+		  <child>
+		    <widget class="GtkButton" id="vpn_add">
+		      <property name="visible">True</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-add</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkButton" id="vpn_edit">
+		      <property name="visible">True</property>
+		      <property name="sensitive">False</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-edit</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkButton" id="vpn_delete">
+		      <property name="visible">True</property>
+		      <property name="sensitive">False</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label">gtk-delete</property>
+		      <property name="use_stock">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">6</property>
+		  <property name="expand">False</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="tab_expand">False</property>
+	      <property name="tab_fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkLabel" id="vpn_label">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">VPN</property>
+	      <property name="use_underline">False</property>
+	      <property name="use_markup">False</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0.5</property>
+	      <property name="yalign">0.5</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
 	    </widget>
 	    <packing>
-	      <property name="padding">0</property>
-	      <property name="expand">False</property>
-	      <property name="fill">False</property>
-	      <property name="pack_type">GTK_PACK_END</property>
+	      <property name="type">tab</property>
 	    </packing>
 	  </child>
 	</widget>

Modified: trunk/src/connection-editor/nm-connection-list.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-list.c	(original)
+++ trunk/src/connection-editor/nm-connection-list.c	Thu Feb 14 17:26:23 2008
@@ -30,7 +30,6 @@
 #include <gtk/gtkcellrenderertext.h>
 #include <gtk/gtkmessagedialog.h>
 #include <gtk/gtkstock.h>
-#include <gtk/gtkcellrendererpixbuf.h>
 #include <gconf/gconf-client.h>
 
 #include <glib/gi18n.h>
@@ -53,11 +52,12 @@
 #define CE_GCONF_PATH_TAG "ce-gconf-path"
 
 #define COL_ID 			0
-#define COL_ICON		1
-#define COL_CONNECTION	2
+#define COL_LAST_USED	1
+#define COL_TIMESTAMP	2
+#define COL_CONNECTION	3
 
 static NMConnection *
-get_connection_for_selection (NMConnectionList *list,
+get_connection_for_selection (GtkWidget *clist,
                               GtkTreeModel **model,
                               GtkTreeIter *iter)
 {
@@ -65,13 +65,14 @@
 	GList *selected_rows;
 	NMConnection *connection = NULL;
 
-	g_return_val_if_fail (list != NULL, NULL);
+	g_return_val_if_fail (clist != NULL, NULL);
+	g_return_val_if_fail (GTK_IS_TREE_VIEW (clist), NULL);
 	g_return_val_if_fail (model != NULL, NULL);
 	g_return_val_if_fail (*model == NULL, NULL);
 	g_return_val_if_fail (iter != NULL, NULL);
 
 	/* get selected row from the tree view */
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list->connection_list));
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (clist));
 	if (gtk_tree_selection_count_selected_rows (selection) != 1)
 		return NULL;
 
@@ -105,14 +106,13 @@
 static void
 edit_connection_cb (GtkButton *button, gpointer user_data)
 {
+	GtkWidget *clist = GTK_WIDGET (user_data);
 	NMConnectionEditor *editor;
 	NMConnection *connection;
 	GtkTreeModel *ignore1 = NULL;
 	GtkTreeIter ignore2;
 
-	connection = get_connection_for_selection (NM_CONNECTION_LIST (user_data),
-	                                           &ignore1,
-	                                           &ignore2);
+	connection = get_connection_for_selection (clist, &ignore1, &ignore2);
 	g_return_if_fail (connection != NULL);
 
 	editor = nm_connection_editor_new (connection);
@@ -123,7 +123,8 @@
 static void
 delete_connection_cb (GtkButton *button, gpointer user_data)
 {
-	NMConnectionList *list = NM_CONNECTION_LIST (user_data);
+	GtkWidget *clist = GTK_WIDGET (user_data);
+	NMConnectionList *list;
 	NMSettingConnection *s_con;
 	NMConnection *connection;
 	GtkWidget *dialog;
@@ -133,8 +134,7 @@
 	GtkTreeModel *model = NULL;
 	GtkTreeIter iter;
 
-	connection = get_connection_for_selection (NM_CONNECTION_LIST (user_data),
-	                                           &model, &iter);
+	connection = get_connection_for_selection (clist, &model, &iter);
 	g_return_if_fail (connection != NULL);
 	g_return_if_fail (model != NULL);
 
@@ -145,6 +145,9 @@
 	if (!s_con || !s_con->id)
 		return;
 
+	list = NM_CONNECTION_LIST (g_object_get_data (G_OBJECT (button), "nm-connection-list"));
+	g_return_if_fail (list != NULL);
+
 	dialog = gtk_message_dialog_new (GTK_WINDOW (list->dialog),
 	                                 GTK_DIALOG_DESTROY_WITH_PARENT,
 	                                 GTK_MESSAGE_QUESTION,
@@ -174,44 +177,6 @@
 }
 
 static void
-dialog_response_cb (GtkDialog *dialog, guint response, gpointer user_data)
-{
-	gtk_widget_hide (GTK_WIDGET (dialog));
-}
-
-static void
-hash_add_connection_to_list (gpointer key, gpointer value, gpointer user_data)
-{
-	NMConnectionList *list = NM_CONNECTION_LIST (user_data);
-	NMConnection *connection = (NMConnection *) value;
-	NMSettingConnection *s_con;
-	GtkTreeIter iter;
-	GdkPixbuf *pixbuf = list->unknown_icon;
-
-	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
-	if (!s_con)
-		return;
-
-	if (!strcmp (s_con->type, NM_SETTING_WIRED_SETTING_NAME))
-		pixbuf = list->wired_icon;
-	else if (!strcmp (s_con->type, NM_SETTING_WIRELESS_SETTING_NAME))
-		pixbuf = list->wireless_icon;
-	else if (!strcmp (s_con->type, NM_SETTING_VPN_SETTING_NAME))
-		pixbuf = list->vpn_icon;
-	else if (!strcmp (s_con->type, NM_SETTING_GSM_SETTING_NAME))
-		pixbuf = list->wwan_icon;
-	else if (!strcmp (s_con->type, NM_SETTING_CDMA_SETTING_NAME))
-		pixbuf = list->wwan_icon;
-
-	gtk_list_store_append (list->model, &iter);
-	gtk_list_store_set (list->model, &iter,
-	                    COL_ID, s_con->id,
-	                    COL_ICON, pixbuf,
-	                    COL_CONNECTION, connection,
-	                    -1);
-}
-
-static void
 load_connections (NMConnectionList *list)
 {
 	GSList *conf_list;
@@ -249,17 +214,284 @@
 static void
 list_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
 {
-	NMConnectionList *list = NM_CONNECTION_LIST (user_data);
+	GtkWidget *button = GTK_WIDGET (user_data);
 	GtkTreeIter iter;
 	GtkTreeModel *model;
 
-	if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
-		gtk_widget_set_sensitive (GTK_WIDGET (list->edit_button), TRUE);
-		gtk_widget_set_sensitive (GTK_WIDGET (list->delete_button), TRUE);
+	if (gtk_tree_selection_get_selected (selection, &model, &iter))
+		gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
+	else
+		gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
+}
+
+static void
+connection_double_clicked_cb (GtkTreeView *tree_view,
+                              GtkTreePath *path,
+                              GtkTreeViewColumn *column,
+                              gpointer user_data)
+{
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	NMConnectionEditor *editor;
+	NMConnection *connection;
+	gboolean success;
+
+	model = gtk_tree_view_get_model (tree_view);
+	g_return_if_fail (model != NULL);
+
+	success = gtk_tree_model_get_iter (model, &iter, path);
+	g_return_if_fail (success);
+	gtk_tree_model_get (model, &iter, COL_CONNECTION, &connection, -1);
+	g_return_if_fail (connection != NULL);
+
+	editor = nm_connection_editor_new (connection);
+	nm_connection_editor_run_and_close (editor);
+	g_object_unref (editor);
+}
+
+static char *
+format_last_used (guint64 timestamp)
+{
+	GTimeVal now_tv;
+	GDate *now, *last;
+	char *last_used = NULL;
+
+	if (!timestamp)
+		return g_strdup (_("never"));
+
+	g_get_current_time (&now_tv);
+	now = g_date_new ();
+	g_date_set_time_val (now, &now_tv);
+
+	last = g_date_new ();
+	g_date_set_time_t (last, (time_t) timestamp);
+
+	/* timestamp is now or in the future */
+	if (now_tv.tv_sec <= timestamp) {
+		last_used = g_strdup (_("now"));
+		goto out;
+	}
+
+	if (g_date_compare (now, last) <= 0) {
+		guint minutes, hours;
+
+		/* Same day */
+
+		minutes = (now_tv.tv_sec - timestamp) / 60;
+		if (minutes == 0) {
+			last_used = g_strdup (_("now"));
+			goto out;
+		}
+
+		hours = (now_tv.tv_sec - timestamp) / 3600;
+		if (hours == 0) {
+			/* less than an hour ago */
+			last_used = g_strdup_printf (ngettext ("%d minute ago", "%d minutes ago", minutes), minutes);
+			goto out;
+		}
+
+		last_used = g_strdup_printf (ngettext ("%d hour ago", "%d hours ago", hours), hours);
 	} else {
-		gtk_widget_set_sensitive (GTK_WIDGET (list->edit_button), FALSE);
-		gtk_widget_set_sensitive (GTK_WIDGET (list->delete_button), FALSE);
+		guint days, months, years;
+
+		days = g_date_get_julian (now) - g_date_get_julian (last);
+		if (days == 0) {
+			last_used = g_strdup ("today");
+			goto out;
+		}
+
+		months = days / 30;
+		if (months == 0) {
+			last_used = g_strdup_printf (ngettext ("%d day ago", "%d days ago", days), days);
+			goto out;
+		}
+
+		years = days / 365;
+		if (years == 0) {
+			last_used = g_strdup_printf (ngettext ("%d month ago", "%d months ago", months), months);
+			goto out;
+		}
+
+		last_used = g_strdup_printf (ngettext ("%d year ago", "%d years ago", years), years);
+	}
+
+out:
+	g_date_free (now);
+	g_date_free (last);
+	return last_used;
+}
+
+typedef struct {
+	GSList *types;
+	GtkListStore *model;
+} NewListInfo;
+
+static void
+hash_add_connection_to_list (gpointer key, gpointer value, gpointer user_data)
+{
+	NewListInfo *info = (NewListInfo *) user_data;
+	NMConnection *connection = (NMConnection *) value;
+	NMSettingConnection *s_con;
+	GtkTreeIter model_iter;
+	gboolean found = FALSE;
+	GSList *iter;
+	char *last_used;
+
+	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+	if (!s_con || !s_con->type)
+		return;
+
+	/* Filter on requested types */
+	for (iter = info->types; iter; iter = g_slist_next (iter)) {
+		if (!strcmp (s_con->type, (const char *) iter->data)) {
+			found = TRUE;
+			break;
+		}
 	}
+
+	if (!found)
+		return;
+
+	last_used = format_last_used (s_con->timestamp);
+
+	gtk_list_store_append (info->model, &model_iter);
+	gtk_list_store_set (info->model, &model_iter,
+	                    COL_ID, s_con->id,
+	                    COL_LAST_USED, last_used,
+	                    COL_TIMESTAMP, s_con->timestamp,
+	                    COL_CONNECTION, connection,
+	                    -1);
+	g_free (last_used);
+}
+
+static GtkWidget *
+new_connection_list (NMConnectionList *list,
+                     GSList *types,
+                     const char *prefix,
+                     GdkPixbuf *pixbuf,
+                     const char *label_text)
+{
+	GtkWidget *notebook;
+	GtkWidget *clist;
+	GtkListStore *model;
+	GtkTreeModel *sort_model;
+	char *name;
+	GtkWidget *image, *hbox, *button, *child;
+	GtkTreeSelection *select;
+	NewListInfo info;
+	GtkCellRenderer *renderer;
+	GValue val = { 0, };
+
+	name = g_strdup_printf ("%s_child", prefix);
+	child = glade_xml_get_widget (list->gui, name);
+	g_free (name);
+
+	/* Tab label with icon */
+	hbox = gtk_hbox_new (FALSE, 6);
+	image = gtk_image_new_from_pixbuf (pixbuf);
+	gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (label_text), FALSE, FALSE, 0);
+	gtk_widget_show_all (hbox);
+
+	notebook = glade_xml_get_widget (list->gui, "list_notebook");
+	gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), child, hbox);
+
+	name = g_strdup_printf ("%s_list", prefix);
+	clist = glade_xml_get_widget (list->gui, name);
+	g_free (name);
+
+	model = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_OBJECT);
+
+	info.types = types;
+	info.model = model;
+	g_hash_table_foreach (list->connections,
+	                      (GHFunc) hash_add_connection_to_list,
+	                      &info);
+
+	sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model));
+	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
+	                                      COL_TIMESTAMP, GTK_SORT_DESCENDING);
+	gtk_tree_view_set_model (GTK_TREE_VIEW (clist), GTK_TREE_MODEL (sort_model));
+
+	g_signal_connect (G_OBJECT (clist),
+	                  "row-activated", G_CALLBACK (connection_double_clicked_cb),
+	                  NULL);
+
+	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (clist),
+	                                             -1, "Name", gtk_cell_renderer_text_new (),
+	                                             "text", COL_ID,
+	                                             NULL);
+	gtk_tree_view_column_set_expand (gtk_tree_view_get_column (GTK_TREE_VIEW (clist), 0), TRUE);
+
+	renderer = gtk_cell_renderer_text_new ();
+	g_value_init (&val, G_TYPE_STRING);
+	g_value_set_string (&val, "SlateGray");
+	g_object_set_property (G_OBJECT (renderer), "foreground", &val);
+	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (clist),
+	                                             -1, "Last Used", renderer,
+	                                             "text", COL_LAST_USED,
+	                                             NULL);
+
+	select = gtk_tree_view_get_selection (GTK_TREE_VIEW (clist));
+	gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
+
+	name = g_strdup_printf ("%s_add", prefix);
+	button = glade_xml_get_widget (list->gui, name);
+	g_object_set_data (G_OBJECT (button), "nm-connection-list", list);
+	g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (add_connection_cb), clist);
+	g_free (name);
+
+	name = g_strdup_printf ("%s_edit", prefix);
+	button = glade_xml_get_widget (list->gui, name);
+	g_object_set_data (G_OBJECT (button), "nm-connection-list", list);
+	g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (edit_connection_cb), clist);
+	g_signal_connect (G_OBJECT (select),
+	                  "changed", G_CALLBACK (list_selection_changed_cb),
+	                  button);
+	g_free (name);
+
+	name = g_strdup_printf ("%s_delete", prefix);
+	button = glade_xml_get_widget (list->gui, name);
+	g_object_set_data (G_OBJECT (button), "nm-connection-list", list);
+	g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (delete_connection_cb), clist);
+	g_signal_connect (G_OBJECT (select),
+	                  "changed", G_CALLBACK (list_selection_changed_cb),
+	                  button);
+	g_free (name);
+
+	return clist;
+}
+
+static gboolean
+init_connection_lists (NMConnectionList *list)
+{
+	GSList *types = NULL;
+	GtkWidget *clist;
+
+	types = g_slist_append (NULL, NM_SETTING_WIRED_SETTING_NAME);
+	clist = new_connection_list (list, types, "wired", list->wired_icon, _("Wired"));
+	g_slist_free (types);
+
+	types = g_slist_append (NULL, NM_SETTING_WIRELESS_SETTING_NAME);
+	clist = new_connection_list (list, types, "wireless", list->wireless_icon, _("Wireless"));
+	g_slist_free (types);
+
+	types = g_slist_append (NULL, NM_SETTING_GSM_SETTING_NAME);
+	types = g_slist_append (types, NM_SETTING_CDMA_SETTING_NAME);
+	clist = new_connection_list (list, types, "wwan", list->wwan_icon, _("Mobile Broadband"));
+	g_slist_free (types);
+
+	types = g_slist_append (NULL, NM_SETTING_VPN_SETTING_NAME);
+	clist = new_connection_list (list, types, "vpn", list->vpn_icon, _("VPN"));
+	g_slist_free (types);
+
+	return TRUE;
+}
+
+static void
+dialog_response_cb (GtkDialog *dialog, guint response, gpointer user_data)
+{
+	gtk_widget_hide (GTK_WIDGET (dialog));
 }
 
 #define ICON_LOAD(x, y)	\
@@ -275,7 +507,6 @@
 static void
 nm_connection_list_init (NMConnectionList *list)
 {
-	GtkTreeSelection *select;
 	GError *error = NULL;
 
 	/* load GUI */
@@ -299,44 +530,10 @@
 	/* read connections */
 	list->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
 	load_connections (list);
+	init_connection_lists (list);
 
 	list->dialog = glade_xml_get_widget (list->gui, "NMConnectionList");
 	g_signal_connect (G_OBJECT (list->dialog), "response", G_CALLBACK (dialog_response_cb), list);
-
-	list->connection_list = glade_xml_get_widget (list->gui, "connection_list");
-
-	list->model = gtk_list_store_new (3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_OBJECT);
-	g_hash_table_foreach (list->connections,
-	                      (GHFunc) hash_add_connection_to_list,
-	                      list);
-	gtk_tree_view_set_model (GTK_TREE_VIEW (list->connection_list), GTK_TREE_MODEL (list->model));
-
-	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (list->connection_list),
-	                                             -1, "Name", gtk_cell_renderer_text_new (),
-	                                             "text", COL_ID,
-	                                             NULL);
-
-	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (list->connection_list),
-	                                             -1, "Type", gtk_cell_renderer_pixbuf_new (),
-	                                             "pixbuf", COL_ICON,
-	                                             NULL);
-
-	select = gtk_tree_view_get_selection (GTK_TREE_VIEW (list->connection_list));
-	gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
-	g_signal_connect (G_OBJECT (select),
-	                  "changed",
-	                  G_CALLBACK (list_selection_changed_cb),
-	                  list);
-
-	/* buttons */
-	list->add_button = glade_xml_get_widget (list->gui, "add_connection_button");
-	g_signal_connect (G_OBJECT (list->add_button), "clicked", G_CALLBACK (add_connection_cb), list);
-
-	list->edit_button = glade_xml_get_widget (list->gui, "edit_connection_button");
-	g_signal_connect (G_OBJECT (list->edit_button), "clicked", G_CALLBACK (edit_connection_cb), list);
-
-	list->delete_button = glade_xml_get_widget (list->gui, "delete_connection_button");
-	g_signal_connect (G_OBJECT (list->delete_button), "clicked", G_CALLBACK (delete_connection_cb), list);
 }
 
 static void

Modified: trunk/src/connection-editor/nm-connection-list.h
==============================================================================
--- trunk/src/connection-editor/nm-connection-list.h	(original)
+++ trunk/src/connection-editor/nm-connection-list.h	Thu Feb 14 17:26:23 2008
@@ -43,13 +43,7 @@
 	GConfClient *client;
 
 	GladeXML *gui;
-	GtkListStore *model;
-
 	GtkWidget *dialog;
-	GtkWidget *connection_list;
-	GtkWidget *add_button;
-	GtkWidget *edit_button;
-	GtkWidget *delete_button;
 
 	GdkPixbuf *wired_icon;
 	GdkPixbuf *wireless_icon;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]