[ekiga] Added a magical toolbar to the account window



commit f2f9f641d41a380487b42b1c16d96949627df895
Author: Julien Puydt <jpuydt gnome org>
Date:   Sun Jun 7 21:32:10 2009 +0200

    Added a magical toolbar to the account window
    
    The available actions should update automagically depending
    on the context.
---
 src/gui/accounts.cpp |   75 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/src/gui/accounts.cpp b/src/gui/accounts.cpp
index 5dbba1b..6d7b3a2 100644
--- a/src/gui/accounts.cpp
+++ b/src/gui/accounts.cpp
@@ -54,16 +54,19 @@
 #include "menu-builder-tools.h"
 #include "menu-builder-gtk.h"
 #include "form-dialog-gtk.h"
+#include "optional-buttons-gtk.h"
 
 typedef struct GmAccountsWindow_ {
 
-  GmAccountsWindow_ (Ekiga::ServiceCore & _core) : core (_core) {};
+  GmAccountsWindow_ (Ekiga::ServiceCore & _core) : core (_core)
+  {}
 
   GtkWidget *accounts_list;
   GtkWidget *menu_item_core;
   GtkAccelGroup *accel;
 
   Ekiga::ServiceCore &core;
+  OptionalButtonsGtk toolbar;
 
 } GmAccountsWindow;
 
@@ -112,6 +115,15 @@ static void account_toggled_cb (GtkCellRendererToggle *cell,
 				gchar *path_str,
 				gpointer data);
 
+/* DESCRIPTION  :  This callback is called when the user clicks
+ *                 on an account in the accounts window.
+ * BEHAVIOR     :  It updates the toolbar actions to point to the right account,
+ *                 and to be active/inactive depending if the action is
+ *                 really available or not.
+ * PRE          :  the 'data' is a pointer to the account window.
+ */
+static void on_selection_changed (GtkTreeSelection* /*selection*/,
+				  gpointer data);
 
 /* Columns for the VoIP accounts */
 enum {
@@ -313,6 +325,39 @@ account_toggled_cb (G_GNUC_UNUSED GtkCellRendererToggle *cell,
   gtk_tree_path_free (path);
 }
 
+static void
+on_selection_changed (GtkTreeSelection* /*selection*/,
+		      gpointer data)
+{
+  GmAccountsWindow* aw = (GmAccountsWindow*) data;
+  GtkTreeSelection* selection = NULL;
+  GtkTreeModel *model = NULL;
+  GtkTreeIter iter;
+  Ekiga::Account* account = NULL;
+
+  g_return_if_fail (aw != NULL);
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->accounts_list));
+
+  if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+
+    gtk_tree_model_get (model, &iter,
+			COLUMN_ACCOUNT, &account,
+			-1);
+    if (account) {
+
+      aw->toolbar.reset ();
+      account->populate_menu (aw->toolbar);
+    } else {
+
+      aw->toolbar.reset ();
+    }
+
+  } else {
+
+    aw->toolbar.reset ();
+  }
+}
 
 static void
 gm_accounts_window_add_account (GtkWidget *window,
@@ -486,6 +531,8 @@ gm_accounts_window_new (Ekiga::ServiceCore &core)
   GtkWidget *item = NULL;
   GtkWidget *event_box = NULL;
   GtkWidget *scroll_window = NULL;
+  GtkWidget* button_box = NULL;
+  GtkWidget* button = NULL;
 
   GtkWidget *frame = NULL;
   GtkWidget *hbox = NULL;
@@ -494,6 +541,8 @@ gm_accounts_window_new (Ekiga::ServiceCore &core)
   GtkListStore *list_store = NULL;
   GtkTreeViewColumn *column = NULL;
 
+  GtkTreeSelection* selection = NULL;
+
   AtkObject *aobj;
 
   const gchar *column_names [] = {
@@ -598,6 +647,11 @@ gm_accounts_window_new (Ekiga::ServiceCore &core)
   g_signal_connect (G_OBJECT (aw->accounts_list), "event_after",
 		    G_CALLBACK (account_clicked_cb), window);
 
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->accounts_list));
+  gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+  g_signal_connect (selection, "changed",
+		    G_CALLBACK (on_selection_changed), aw);
+
   /* The scrolled window with the accounts list store */
   scroll_window = gtk_scrolled_window_new (FALSE, FALSE);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll_window),
@@ -619,10 +673,27 @@ gm_accounts_window_new (Ekiga::ServiceCore &core)
   gtk_container_set_border_width (GTK_CONTAINER (aw->accounts_list), 0);
   gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
 
+  /* setting up a horizontal button box
+   * (each button with be dynamically disabled/enabled as needed)
+   */
+  button_box = gtk_hbutton_box_new ();
+  button = gtk_button_new_with_label (_("Enable"));
+  gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 0);
+  aw->toolbar.add_button ("enable", GTK_BUTTON (button));
+  button = gtk_button_new_with_label (_("Disable"));
+  gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 0);
+  aw->toolbar.add_button ("disable", GTK_BUTTON (button));
+  button = gtk_button_new_with_label (_("Edit"));
+  gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 0);
+  aw->toolbar.add_button ("edit", GTK_BUTTON (button));
+  button = gtk_button_new_with_label (_("Remove"));
+  gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 0);
+  aw->toolbar.add_button ("remove", GTK_BUTTON (button));
+
   populate_menu (window); // This will add static and dynamic actions
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), menu_bar, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), event_box, TRUE, TRUE, 0);
-
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button_box, TRUE, TRUE, 0);
 
   /* Generic signals */
   g_signal_connect_swapped (GTK_OBJECT (window),



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