]> git.0d.be Git - empathy.git/commitdiff
Create balance widget, tie it to the action
authorDanielle Madeley <danielle.madeley@collabora.co.uk>
Fri, 15 Apr 2011 06:18:33 +0000 (16:18 +1000)
committerDanielle Madeley <danielle.madeley@collabora.co.uk>
Thu, 5 May 2011 07:12:27 +0000 (17:12 +1000)
TODO:
 - show and hide balance widgets in response to a toggleaction

src/empathy-main-window.c
src/empathy-main-window.ui

index 80bfd92d5a6378070d1f54f91ff3b03dd8fb91cf..c02fccb022ae26b76287383397c20ff37eeba7ec 100644 (file)
@@ -950,6 +950,50 @@ main_window_setup_balance_create_action (EmpathyMainWindow *window,
        return action;
 }
 
+static GtkWidget *
+main_window_setup_balance_create_widget (EmpathyMainWindow *window,
+                                        GtkAction         *action)
+{
+       EmpathyMainWindowPriv *priv = GET_PRIV (window);
+       GtkWidget *hbox, *image, *label, *button;
+
+       if (action == NULL)
+               return NULL;
+
+       hbox = gtk_hbox_new (FALSE, 6);
+
+       image = gtk_image_new ();
+       gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0);
+       gtk_widget_show (image);
+
+       label = gtk_label_new ("");
+       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+       gtk_widget_show (label);
+
+       button = gtk_button_new_with_label (_("Top Up..."));
+       gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
+       gtk_widget_show (button);
+
+       gtk_box_pack_start (GTK_BOX (priv->balance_vbox), hbox, FALSE, TRUE, 0);
+       gtk_widget_show_all (hbox);
+
+       /* bind the properties from the action to the widgets -- I could have
+        * written a widget that implemented GtkActivatable, but effort */
+       g_object_bind_property (action, "label", label, "label",
+               G_BINDING_SYNC_CREATE);
+       g_object_bind_property (action, "icon-name", image, "icon-name",
+               G_BINDING_SYNC_CREATE);
+       g_signal_connect_swapped (button, "clicked",
+               G_CALLBACK (gtk_action_activate), action);
+
+       /* tie the lifetime of the widget to the lifetime of the action */
+       g_object_weak_ref (G_OBJECT (action),
+               (GWeakNotify) gtk_widget_destroy, hbox);
+
+       return hbox;
+}
+
 static void
 main_window_setup_balance_conn_ready (GObject      *conn,
                                      GAsyncResult *result,
@@ -958,6 +1002,7 @@ main_window_setup_balance_conn_ready (GObject      *conn,
        EmpathyMainWindow *window = user_data;
        TpAccount *account = g_object_get_data (conn, "account");
        GtkAction *action;
+       GtkWidget *widget;
        GError *error = NULL;
 
        if (!tp_proxy_prepare_finish (conn, result, &error)) {
@@ -978,6 +1023,9 @@ main_window_setup_balance_conn_ready (GObject      *conn,
        /* create the action */
        action = main_window_setup_balance_create_action (window, account);
 
+       /* create the display widget */
+       widget = main_window_setup_balance_create_widget (window, action);
+
        /* request the current balance and monitor for any changes */
        tp_cli_dbus_properties_call_get_all (conn, -1,
                TP_IFACE_CONNECTION_INTERFACE_BALANCE,
@@ -2026,7 +2074,7 @@ empathy_main_window_init (EmpathyMainWindow *window)
        filename = empathy_file_lookup ("empathy-main-window.ui", "src");
        gui = empathy_builder_get_file (filename,
                                       "main_vbox", &priv->main_vbox,
-                                      "balance_box", &priv->balance_vbox,
+                                      "balance_vbox", &priv->balance_vbox,
                                       "errors_vbox", &priv->errors_vbox,
                                       "auth_vbox", &priv->auth_vbox,
                                       "ui_manager", &priv->ui_manager,
@@ -2204,6 +2252,9 @@ empathy_main_window_init (EmpathyMainWindow *window)
        /* Set window size. */
        empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
 
+       /* FIXME: bind balance_vbox to action */
+       gtk_widget_show (priv->balance_vbox);
+
        /* Enable event handling */
        priv->call_observer = empathy_call_observer_dup_singleton ();
        priv->event_manager = empathy_event_manager_dup_singleton ();
index 91b493b567f14da71a99655dd5d6a51709ba8d42..7852de15153ee3a2d4d3a434b01c3cc82cb64a8b 100644 (file)
           </packing>
         </child>
         <child>
-          <object class="GtkVBox" id="errors_vbox">
+          <object class="GtkVBox" id="balance_vbox">
             <child>
               <placeholder/>
             </child>
             <property name="expand">False</property>
             <property name="fill">False</property>
             <property name="position">2</property>
+           <property name="spacing">3</property>
           </packing>
         </child>
         <child>
-          <object class="GtkVBox" id="auth_vbox">
+          <object class="GtkVBox" id="errors_vbox">
             <child>
               <placeholder/>
             </child>
             <property name="position">3</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkVBox" id="auth_vbox">
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">4</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkNotebook" id="notebook">
             <property name="visible">True</property>
             </child>
           </object>
           <packing>
-            <property name="position">4</property>
+            <property name="position">5</property>
           </packing>
         </child>
       </object>