]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-account-widget.c
use gtk_box_new() instead of gtk_[h,v]box_new()
[empathy.git] / libempathy-gtk / empathy-account-widget.c
index 8df91745deeb3ca02414610b882771cdf80731d9..f1b463c039ebf226dcf89b0567be5fa8c3daecbe 100644 (file)
@@ -74,7 +74,7 @@ static ServiceInfo services_infos[N_SERVICES] = {
 typedef struct {
   EmpathyAccountSettings *settings;
 
-  GtkWidget *table_common_settings;
+  GtkWidget *grid_common_settings;
   GtkWidget *apply_button;
   GtkWidget *cancel_button;
   GtkWidget *entry_password;
@@ -735,32 +735,39 @@ account_widget_generic_format_param_name (const gchar *param_name)
 
 static void
 accounts_widget_generic_setup (EmpathyAccountWidget *self,
-    GtkWidget *table_common_settings,
-    GtkWidget *table_advanced_settings)
+    GtkWidget *grid_common_settings,
+    GtkWidget *grid_advanced_settings)
 {
   TpConnectionManagerParam *params, *param;
   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+  guint row_common = 0, row_advanced = 0;
 
   params = empathy_account_settings_get_tp_params (priv->settings);
 
   for (param = params; param != NULL && param->name != NULL; param++)
     {
-      GtkWidget       *table_settings;
-      guint            n_rows = 0;
+      GtkWidget       *grid_settings;
+      guint           row;
       GtkWidget       *widget = NULL;
       gchar           *param_name_formatted;
 
       if (param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)
-        table_settings = table_common_settings;
+        {
+          grid_settings = grid_common_settings;
+          row = row_common++;
+        }
       else if (priv->simple)
-        return;
+        {
+          return;
+        }
       else
-        table_settings = table_advanced_settings;
+        {
+          grid_settings = grid_advanced_settings;
+          row = row_advanced++;
+        }
 
       param_name_formatted = account_widget_generic_format_param_name
         (param->name);
-      g_object_get (table_settings, "n-rows", &n_rows, NULL);
-      gtk_table_resize (GTK_TABLE (table_settings), ++n_rows, 2);
 
       if (param->dbus_signature[0] == 's')
         {
@@ -771,12 +778,9 @@ accounts_widget_generic_setup (EmpathyAccountWidget *self,
           gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
           g_free (str);
 
-          gtk_table_attach (GTK_TABLE (table_settings),
-              widget,
-              0, 1,
-              n_rows - 1, n_rows,
-              GTK_FILL, 0,
-              0, 0);
+          gtk_grid_attach (GTK_GRID (grid_settings),
+              widget, 0, row, 1, 1);
+
           gtk_widget_show (widget);
 
           widget = gtk_entry_new ();
@@ -786,12 +790,10 @@ accounts_widget_generic_setup (EmpathyAccountWidget *self,
                   G_CALLBACK (gtk_widget_grab_focus),
                   NULL);
             }
-          gtk_table_attach (GTK_TABLE (table_settings),
-              widget,
-              1, 2,
-              n_rows - 1, n_rows,
-              GTK_FILL | GTK_EXPAND, 0,
-              0, 0);
+
+          gtk_grid_attach (GTK_GRID (grid_settings),
+              widget, 1, row, 1, 1);
+
           gtk_widget_show (widget);
         }
       /* int types: ynqiuxt. double type is 'd' */
@@ -828,32 +830,20 @@ accounts_widget_generic_setup (EmpathyAccountWidget *self,
           gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
           g_free (str);
 
-          gtk_table_attach (GTK_TABLE (table_settings),
-              widget,
-              0, 1,
-              n_rows - 1, n_rows,
-              GTK_FILL, 0,
-              0, 0);
+          gtk_grid_attach (GTK_GRID (grid_settings),
+              widget, 0, row, 1, 1);
           gtk_widget_show (widget);
 
           widget = gtk_spin_button_new_with_range (minint, maxint, step);
-          gtk_table_attach (GTK_TABLE (table_settings),
-              widget,
-              1, 2,
-              n_rows - 1, n_rows,
-              GTK_FILL | GTK_EXPAND, 0,
-              0, 0);
+          gtk_grid_attach (GTK_GRID (grid_settings),
+              widget, 1, row, 1, 1);
           gtk_widget_show (widget);
         }
       else if (param->dbus_signature[0] == 'b')
         {
           widget = gtk_check_button_new_with_label (param_name_formatted);
-          gtk_table_attach (GTK_TABLE (table_settings),
-              widget,
-              0, 2,
-              n_rows - 1, n_rows,
-              GTK_FILL | GTK_EXPAND, 0,
-              0, 0);
+          gtk_grid_attach (GTK_GRID (grid_settings),
+              widget, 0, row, 2, 1);
           gtk_widget_show (widget);
         }
       else
@@ -1043,16 +1033,16 @@ account_widget_apply_clicked_cb (GtkWidget *button,
 static void
 account_widget_setup_generic (EmpathyAccountWidget *self)
 {
-  GtkWidget *table_common_settings;
-  GtkWidget *table_advanced_settings;
+  GtkWidget *grid_common_settings;
+  GtkWidget *grid_advanced_settings;
 
-  table_common_settings = GTK_WIDGET (gtk_builder_get_object
-      (self->ui_details->gui, "table_common_settings"));
-  table_advanced_settings = GTK_WIDGET (gtk_builder_get_object
-      (self->ui_details->gui, "table_advanced_settings"));
+  grid_common_settings = GTK_WIDGET (gtk_builder_get_object
+      (self->ui_details->gui, "grid_common_settings"));
+  grid_advanced_settings = GTK_WIDGET (gtk_builder_get_object
+      (self->ui_details->gui, "grid_advanced_settings"));
 
-  accounts_widget_generic_setup (self, table_common_settings,
-      table_advanced_settings);
+  accounts_widget_generic_setup (self, grid_common_settings,
+      grid_advanced_settings);
 
   g_object_unref (self->ui_details->gui);
 }
@@ -1077,7 +1067,7 @@ account_widget_build_generic (EmpathyAccountWidget *self,
   GtkWidget *expander_advanced;
 
   self->ui_details->gui = empathy_builder_get_file (filename,
-      "table_common_settings", &priv->table_common_settings,
+      "grid_common_settings", &priv->grid_common_settings,
       "vbox_generic_settings", &self->ui_details->widget,
       "expander_advanced_settings", &expander_advanced,
       NULL);
@@ -1097,6 +1087,30 @@ account_widget_build_generic (EmpathyAccountWidget *self,
 static void
 account_widget_launch_external_clicked (GtkWidget *button,
     TpAccount *account)
+{
+  GdkAppLaunchContext *context = NULL;
+  GdkDisplay *display;
+  GAppInfo *app_info;
+  GError *error = NULL;
+
+  app_info = g_object_get_data (G_OBJECT (button), "app-info");
+
+  g_return_if_fail (G_IS_APP_INFO (app_info));
+
+  display = gdk_display_get_default ();
+  context = gdk_display_get_app_launch_context (display);
+
+  if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
+        &error))
+    {
+      g_critical ("Failed to bisho: %s", error->message);
+      g_clear_error (&error);
+    }
+}
+
+static void
+account_widget_launch_external_clicked_meego (GtkWidget *button,
+    TpAccount *account)
 {
   if (!tp_strdiff (tp_account_get_storage_provider (account),
         "com.meego.libsocialweb"))
@@ -1155,17 +1169,35 @@ account_widget_build_external (EmpathyAccountWidget *self,
   TpAccount *account = empathy_account_settings_get_account (settings);
   GtkWidget *bar, *widget;
   gchar *str;
+  const gchar *provider, *name = NULL;
+  GDesktopAppInfo *desktop_info = NULL;
 
-  self->ui_details->widget = gtk_vbox_new (FALSE, 6);
-  priv->table_common_settings = gtk_table_new (1, 2, FALSE);
+  self->ui_details->widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  priv->grid_common_settings = gtk_grid_new ();
 
-  if (!tp_strdiff (tp_account_get_storage_provider (account),
-        "com.meego.libsocialweb"))
+  provider = tp_account_get_storage_provider (account);
+
+  if (!tp_strdiff (provider, "com.meego.libsocialweb"))
+    {
+      name = _("My Web Accounts");
+    }
+  else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
+    {
+      /* FIXME: we should publish the .desktop file in some general way */
+      desktop_info = g_desktop_app_info_new (
+          "gnome-online-accounts-panel.desktop");
+
+      if (desktop_info == NULL)
+        g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
+      else
+        name = g_app_info_get_name (G_APP_INFO (desktop_info));
+    }
+
+  if (name != NULL)
     {
-      /* we know how to handle this external provider */
       str = g_strdup_printf (
-          _("The account %s is edited via My Web Accounts."),
-          empathy_account_settings_get_display_name (settings));
+          _("The account %s is edited via %s."),
+          empathy_account_settings_get_display_name (settings), name);
     }
   else
     {
@@ -1185,23 +1217,40 @@ account_widget_build_external (EmpathyAccountWidget *self,
       widget);
   gtk_container_set_border_width (GTK_CONTAINER (bar), 6);
 
-  if (!tp_strdiff (tp_account_get_storage_provider (account),
-        "com.meego.libsocialweb"))
+  if (!tp_strdiff (provider, "com.meego.libsocialweb"))
     {
       /* we know how to handle this external provider */
       widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
           _("Launch My Web Accounts"), RESPONSE_LAUNCH);
 
+      g_signal_connect (widget, "clicked",
+          G_CALLBACK (account_widget_launch_external_clicked_meego), account);
+    }
+  else if (desktop_info != NULL)
+    {
+      /* general handler */
+      str = g_strdup_printf (_("Edit %s"), name);
+
+      widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+          str, RESPONSE_LAUNCH);
+
+      g_object_set_data_full (G_OBJECT (widget), "app-info",
+          g_object_ref (desktop_info), g_object_unref);
+
       g_signal_connect (widget, "clicked",
           G_CALLBACK (account_widget_launch_external_clicked), account);
+
+      g_free (str);
     }
 
   gtk_box_pack_start (GTK_BOX (self->ui_details->widget), bar,
       FALSE, TRUE, 0);
   gtk_box_pack_start (GTK_BOX (self->ui_details->widget),
-      priv->table_common_settings, FALSE, TRUE, 0);
+      priv->grid_common_settings, FALSE, TRUE, 0);
 
   gtk_widget_show_all (self->ui_details->widget);
+
+  tp_clear_object (&desktop_info);
 }
 
 static void
@@ -1212,7 +1261,7 @@ account_widget_build_salut (EmpathyAccountWidget *self,
   GtkWidget *expander_advanced;
 
   self->ui_details->gui = empathy_builder_get_file (filename,
-      "table_common_settings", &priv->table_common_settings,
+      "grid_common_settings", &priv->grid_common_settings,
       "vbox_salut_settings", &self->ui_details->widget,
       "expander_advanced_settings", &expander_advanced,
       NULL);
@@ -1251,7 +1300,7 @@ account_widget_build_irc (EmpathyAccountWidget *self,
   else
     {
       priv->irc_network_chooser = empathy_account_widget_irc_build (self,
-          filename, &priv->table_common_settings);
+          filename, &priv->grid_common_settings);
     }
 }
 
@@ -1261,7 +1310,7 @@ account_widget_build_sip (EmpathyAccountWidget *self,
 {
   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
   empathy_account_widget_sip_build (self, filename,
-    &priv->table_common_settings);
+    &priv->grid_common_settings);
 
   if (priv->simple)
     {
@@ -1303,7 +1352,7 @@ account_widget_build_msn (EmpathyAccountWidget *self,
   else
     {
       self->ui_details->gui = empathy_builder_get_file (filename,
-          "table_common_msn_settings", &priv->table_common_settings,
+          "grid_common_msn_settings", &priv->grid_common_settings,
           "vbox_msn_settings", &self->ui_details->widget,
           NULL);
 
@@ -1506,7 +1555,7 @@ account_widget_build_jabber (EmpathyAccountWidget *self,
 
       /* Full widget for XMPP, Google Talk and Facebook*/
       self->ui_details->gui = empathy_builder_get_file (filename,
-          "table_common_settings", &priv->table_common_settings,
+          "grid_common_settings", &priv->grid_common_settings,
           "vbox_jabber_settings", &self->ui_details->widget,
           "spinbutton_port", &spinbutton_port,
           "checkbutton_ssl", &checkbutton_ssl,
@@ -1600,7 +1649,7 @@ account_widget_build_icq (EmpathyAccountWidget *self,
   else
     {
       self->ui_details->gui = empathy_builder_get_file (filename,
-          "table_common_settings", &priv->table_common_settings,
+          "grid_common_settings", &priv->grid_common_settings,
           "vbox_icq_settings", &self->ui_details->widget,
           "spinbutton_port", &spinbutton_port,
           NULL);
@@ -1646,7 +1695,7 @@ account_widget_build_aim (EmpathyAccountWidget *self,
   else
     {
       self->ui_details->gui = empathy_builder_get_file (filename,
-          "table_common_settings", &priv->table_common_settings,
+          "grid_common_settings", &priv->grid_common_settings,
           "vbox_aim_settings", &self->ui_details->widget,
           "spinbutton_port", &spinbutton_port,
           NULL);
@@ -1693,7 +1742,7 @@ account_widget_build_yahoo (EmpathyAccountWidget *self,
   else
     {
       self->ui_details->gui = empathy_builder_get_file (filename,
-          "table_common_settings", &priv->table_common_settings,
+          "grid_common_settings", &priv->grid_common_settings,
           "vbox_yahoo_settings", &self->ui_details->widget,
           NULL);
 
@@ -1738,7 +1787,7 @@ account_widget_build_groupwise (EmpathyAccountWidget *self,
   else
     {
       self->ui_details->gui = empathy_builder_get_file (filename,
-          "table_common_groupwise_settings", &priv->table_common_settings,
+          "grid_common_groupwise_settings", &priv->grid_common_settings,
           "vbox_groupwise_settings", &self->ui_details->widget,
           NULL);
 
@@ -1902,7 +1951,7 @@ account_manager_ready_cb (GObject *source_object,
   GError *error = NULL;
   TpConnectionPresenceType state;
 
-  if (!tp_account_manager_prepare_finish (account_manager, result, &error))
+  if (!tp_proxy_prepare_finish (account_manager, result, &error))
     {
       DEBUG ("Failed to prepare account manager: %s", error->message);
       g_error_free (error);
@@ -2133,7 +2182,7 @@ do_constructed (GObject *obj)
   priv->account_manager = tp_account_manager_dup ();
 
   g_object_ref (self);
-  tp_account_manager_prepare_async (priv->account_manager, NULL,
+  tp_proxy_prepare_async (priv->account_manager, NULL,
       account_manager_ready_cb, self);
 
   /* handle apply and cancel button */
@@ -2141,9 +2190,11 @@ do_constructed (GObject *obj)
       !(storage_restrictions &
         TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS))
     {
-      GtkWidget *hbox = gtk_hbox_new (TRUE, 3);
+      GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
       GtkWidget *image;
 
+      gtk_box_set_homogeneous (hbox, TRUE);
+
       /*  We can't use the stock button as its accelerator ('C') clashes with
        *  the Close button. */
       priv->cancel_button = gtk_button_new ();
@@ -2305,7 +2356,7 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
   signals[HANDLE_APPLY] =
     g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        g_cclosure_marshal_VOID__BOOLEAN,
+        g_cclosure_marshal_generic,
         G_TYPE_NONE,
         1, G_TYPE_BOOLEAN);
 
@@ -2313,14 +2364,14 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
   signals[ACCOUNT_CREATED] =
       g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
           G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-          g_cclosure_marshal_VOID__OBJECT,
+          g_cclosure_marshal_generic,
           G_TYPE_NONE,
           1, G_TYPE_OBJECT);
 
   signals[CANCELLED] =
       g_signal_new ("cancelled", G_TYPE_FROM_CLASS (klass),
           G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-          g_cclosure_marshal_VOID__VOID,
+          g_cclosure_marshal_generic,
           G_TYPE_NONE,
           0);
 
@@ -2428,7 +2479,7 @@ empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
           default_display_name = g_strdup_printf (_("%1$s on %2$s"),
               login_id, empathy_irc_network_get_name (network));
         }
-      else if (service == FACEBOOK_SERVICE)
+      else if (service == FACEBOOK_SERVICE && priv->jid_suffix != NULL)
         {
           gchar *tmp;