aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-02-16 18:56:01 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-02-17 00:43:30 +0800
commitfea6df61fd35261aeebe2a94128d472e284a7280 (patch)
treebf74e59abc2ce02a140ce91450ad188bc836250f /libempathy-gtk
parent692672af8d6a30c6550571a424b4546a0dea98f7 (diff)
downloadgsoc2013-empathy-fea6df61fd35261aeebe2a94128d472e284a7280.tar
gsoc2013-empathy-fea6df61fd35261aeebe2a94128d472e284a7280.tar.gz
gsoc2013-empathy-fea6df61fd35261aeebe2a94128d472e284a7280.tar.bz2
gsoc2013-empathy-fea6df61fd35261aeebe2a94128d472e284a7280.tar.lz
gsoc2013-empathy-fea6df61fd35261aeebe2a94128d472e284a7280.tar.xz
gsoc2013-empathy-fea6df61fd35261aeebe2a94128d472e284a7280.tar.zst
gsoc2013-empathy-fea6df61fd35261aeebe2a94128d472e284a7280.zip
add empathy-local-xmpp-assistant-widget
All of this is duplicated code from empathy-account-assistant and empathy-auto-salut-account-helper but those are going away so I didn't bother refactoring them. https://bugzilla.gnome.org/show_bug.cgi?id=652669
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/Makefile.am4
-rw-r--r--libempathy-gtk/empathy-local-xmpp-assistant-widget.c282
-rw-r--r--libempathy-gtk/empathy-local-xmpp-assistant-widget.h58
3 files changed, 344 insertions, 0 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index 2713548e4..c32448fa5 100644
--- a/libempathy-gtk/Makefile.am
+++ b/libempathy-gtk/Makefile.am
@@ -15,6 +15,7 @@ AM_CPPFLAGS = \
$(GEOCODE_CFLAGS) \
$(MEEGO_CFLAGS) \
$(CHEESE_CFLAGS) \
+ $(EDS_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED)
@@ -64,6 +65,7 @@ libempathy_gtk_handwritten_source = \
empathy-irc-network-chooser.c \
empathy-irc-network-chooser-dialog.c \
empathy-irc-network-dialog.c \
+ empathy-local-xmpp-assistant-widget.c \
empathy-log-window.c \
empathy-new-account-dialog.c \
empathy-new-message-dialog.c \
@@ -129,6 +131,7 @@ libempathy_gtk_headers = \
empathy-irc-network-chooser.h \
empathy-irc-network-chooser-dialog.h \
empathy-irc-network-dialog.h \
+ empathy-local-xmpp-assistant-widget.h \
empathy-log-window.h \
empathy-new-account-dialog.h \
empathy-new-message-dialog.h \
@@ -177,6 +180,7 @@ libempathy_gtk_la_LIBADD = \
$(GCR_LIBS) \
$(MEEGO_LIBS) \
$(CHEESE_LIBS) \
+ $(EDS_LIBS) \
$(top_builddir)/libempathy/libempathy.la
check_c_sources = \
diff --git a/libempathy-gtk/empathy-local-xmpp-assistant-widget.c b/libempathy-gtk/empathy-local-xmpp-assistant-widget.c
new file mode 100644
index 000000000..5cf8ce976
--- /dev/null
+++ b/libempathy-gtk/empathy-local-xmpp-assistant-widget.c
@@ -0,0 +1,282 @@
+/*
+ * empathy-local-xmpp-assistant-widget.h - Source for
+ * EmpathyLocalXmppAssistantWidget
+ *
+ * Copyright (C) 2012 - Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with This library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "empathy-local-xmpp-assistant-widget.h"
+
+#include <glib/gi18n-lib.h>
+
+#if HAVE_EDS
+#include <libebook/e-book.h>
+#endif
+
+#include <libempathy/empathy-utils.h>
+
+#include <libempathy-gtk/empathy-account-widget.h>
+#include <libempathy-gtk/empathy-ui-utils.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
+#include <libempathy/empathy-debug.h>
+
+G_DEFINE_TYPE (EmpathyLocalXmppAssistantWidget,
+ empathy_local_xmpp_assistant_widget, GTK_TYPE_BOX)
+
+enum {
+ SIG_VALID = 1,
+ LAST_SIGNAL
+};
+
+static gulong signals[LAST_SIGNAL] = { 0, };
+
+struct _EmpathyLocalXmppAssistantWidgetPrivate
+{
+ EmpathyAccountSettings *settings;
+};
+
+static void
+empathy_local_xmpp_assistant_widget_init (EmpathyLocalXmppAssistantWidget *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
+ EMPATHY_TYPE_LOCAL_XMPP_ASSISTANT_WIDGET,
+ EmpathyLocalXmppAssistantWidgetPrivate);
+}
+
+static EmpathyAccountSettings *
+create_salut_account_settings (void)
+{
+ EmpathyAccountSettings *settings;
+#if HAVE_EDS
+ EBook *book;
+ EContact *contact;
+ gchar *nickname = NULL;
+ gchar *first_name = NULL;
+ gchar *last_name = NULL;
+ gchar *email = NULL;
+ gchar *jid = NULL;
+ GError *error = NULL;
+#endif
+
+ settings = empathy_account_settings_new ("salut", "local-xmpp", NULL,
+ _("People nearby"));
+
+#if HAVE_EDS
+ /* Get self EContact from EDS */
+ if (!e_book_get_self (&contact, &book, &error))
+ {
+ DEBUG ("Failed to get self econtact: %s", error->message);
+ g_error_free (error);
+ return settings;
+ }
+
+ nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
+ first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
+ last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
+ email = e_contact_get (contact, E_CONTACT_EMAIL_1);
+ jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
+
+ if (!tp_strdiff (nickname, "nickname"))
+ {
+ g_free (nickname);
+ nickname = NULL;
+ }
+
+ DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
+ "last-name=%s\nemail=%s\njid=%s\n",
+ nickname, first_name, last_name, email, jid);
+
+ empathy_account_settings_set_string (settings,
+ "nickname", nickname ? nickname : "");
+ empathy_account_settings_set_string (settings,
+ "first-name", first_name ? first_name : "");
+ empathy_account_settings_set_string (settings,
+ "last-name", last_name ? last_name : "");
+ empathy_account_settings_set_string (settings, "email", email ? email : "");
+ empathy_account_settings_set_string (settings, "jid", jid ? jid : "");
+
+ g_free (nickname);
+ g_free (first_name);
+ g_free (last_name);
+ g_free (email);
+ g_free (jid);
+ g_object_unref (contact);
+ g_object_unref (book);
+#endif
+
+ return settings;
+}
+
+static void
+handle_apply_cb (EmpathyAccountWidget *widget_object,
+ gboolean is_valid,
+ EmpathyLocalXmppAssistantWidget *self)
+{
+ g_signal_emit (self, signals[SIG_VALID], 0, is_valid);
+}
+
+static void
+empathy_local_xmpp_assistant_widget_constructed (GObject *object)
+{
+ EmpathyLocalXmppAssistantWidget *self = (EmpathyLocalXmppAssistantWidget *)
+ object;
+ GtkWidget *hbox, *w;
+ GdkPixbuf *pix;
+ GtkWidget *account_widget;
+ EmpathyAccountWidget *widget_object;
+ gchar *markup;
+
+ G_OBJECT_CLASS (empathy_local_xmpp_assistant_widget_parent_class)->
+ constructed (object);
+
+ gtk_container_set_border_width (GTK_CONTAINER (self), 12);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_box_pack_start (GTK_BOX (self), hbox, TRUE, TRUE, 0);
+ gtk_widget_show (hbox);
+
+ w = gtk_label_new (NULL);
+ markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
+ _("Empathy can automatically discover and chat with the people "
+ "connected on the same network as you. "
+ "If you want to use this feature, please check that the "
+ "details below are correct. "
+ "You can easily change these details later or disable this feature "
+ "by using the 'Accounts' dialog"),
+ _("Edit->Accounts"));
+ gtk_label_set_markup (GTK_LABEL (w), markup);
+ g_free (markup);
+ gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+ gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
+ gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+
+ pix = empathy_pixbuf_from_icon_name_sized ("im-local-xmpp", 80);
+ w = gtk_image_new_from_pixbuf (pix);
+ gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 6);
+ gtk_widget_show (w);
+
+ g_object_unref (pix);
+
+ self->priv->settings = create_salut_account_settings ();
+
+ widget_object = empathy_account_widget_new_for_protocol (self->priv->settings,
+ TRUE);
+ empathy_account_widget_hide_buttons (widget_object);
+
+ account_widget = empathy_account_widget_get_widget (widget_object);
+
+ g_signal_connect (widget_object, "handle-apply",
+ G_CALLBACK (handle_apply_cb), self);
+
+ gtk_box_pack_start (GTK_BOX (self), account_widget,
+ FALSE, FALSE, 0);
+ gtk_widget_show (account_widget);
+}
+
+static void
+empathy_local_xmpp_assistant_widget_dispose (GObject *object)
+{
+ EmpathyLocalXmppAssistantWidget *self = (EmpathyLocalXmppAssistantWidget *)
+ object;
+
+ g_clear_object (&self->priv->settings);
+
+ G_OBJECT_CLASS (empathy_local_xmpp_assistant_widget_parent_class)->
+ dispose (object);
+}
+
+static void
+empathy_local_xmpp_assistant_widget_class_init (
+ EmpathyLocalXmppAssistantWidgetClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = empathy_local_xmpp_assistant_widget_constructed;
+ object_class->dispose = empathy_local_xmpp_assistant_widget_dispose;
+
+ signals[SIG_VALID] =
+ g_signal_new ("valid",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ g_type_class_add_private (object_class,
+ sizeof (EmpathyLocalXmppAssistantWidgetPrivate));
+}
+
+GtkWidget *
+empathy_local_xmpp_assistant_widget_new ()
+{
+ return g_object_new (EMPATHY_TYPE_LOCAL_XMPP_ASSISTANT_WIDGET,
+ "orientation", GTK_ORIENTATION_VERTICAL,
+ NULL);
+}
+
+static void
+account_enabled_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpAccount *account = TP_ACCOUNT (source);
+ GError *error = NULL;
+ TpAccountManager *account_mgr;
+
+ if (!tp_account_set_enabled_finish (account, result, &error))
+ {
+ DEBUG ("Failed to enable account: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ account_mgr = tp_account_manager_dup ();
+
+ empathy_connect_new_account (account, account_mgr);
+
+ g_object_unref (account_mgr);
+}
+
+static void
+apply_account_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
+ TpAccount *account;
+ GError *error = NULL;
+
+ if (!empathy_account_settings_apply_finish (settings, result, NULL, &error))
+ {
+ DEBUG ("Failed to create account: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ /* enable the newly created account */
+ account = empathy_account_settings_get_account (settings);
+ tp_account_set_enabled_async (account, TRUE, account_enabled_cb, NULL);
+}
+
+void
+empathy_local_xmpp_assistant_widget_create_account (
+ EmpathyLocalXmppAssistantWidget *self)
+{
+ empathy_account_settings_apply_async (self->priv->settings,
+ apply_account_cb, NULL);
+}
diff --git a/libempathy-gtk/empathy-local-xmpp-assistant-widget.h b/libempathy-gtk/empathy-local-xmpp-assistant-widget.h
new file mode 100644
index 000000000..edb9b6a40
--- /dev/null
+++ b/libempathy-gtk/empathy-local-xmpp-assistant-widget.h
@@ -0,0 +1,58 @@
+/*
+ * empathy-local-xmpp-assistant-widget.h - Source for
+ * EmpathyLocalXmppAssistantWidget
+ *
+ * Copyright (C) 2012 - Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with This library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET_H__
+#define __EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EMPATHY_TYPE_LOCAL_XMPP_ASSISTANT_WIDGET (empathy_local_xmpp_assistant_widget_get_type ())
+#define EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_LOCAL_XMPP_ASSISTANT_WIDGET, EmpathyLocalXmppAssistantWidget))
+#define EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_LOCAL_XMPP_ASSISTANT_WIDGET, EmpathyLocalXmppAssistantWidgetClass))
+#define EMPATHY_IS_LOCAL_XMPP_ASSISTANT_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_LOCAL_XMPP_ASSISTANT_WIDGET))
+#define EMPATHY_IS_LOCAL_XMPP_ASSISTANT_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_LOCAL_XMPP_ASSISTANT_WIDGET))
+#define EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_LOCAL_XMPP_ASSISTANT_WIDGET, EmpathyLocalXmppAssistantWidgetClass))
+
+typedef struct _EmpathyLocalXmppAssistantWidget EmpathyLocalXmppAssistantWidget;
+typedef struct _EmpathyLocalXmppAssistantWidgetClass EmpathyLocalXmppAssistantWidgetClass;
+typedef struct _EmpathyLocalXmppAssistantWidgetPrivate EmpathyLocalXmppAssistantWidgetPrivate;
+
+struct _EmpathyLocalXmppAssistantWidget {
+ GtkBox parent;
+
+ EmpathyLocalXmppAssistantWidgetPrivate *priv;
+};
+
+struct _EmpathyLocalXmppAssistantWidgetClass {
+ GtkBoxClass parent_class;
+};
+
+GType empathy_local_xmpp_assistant_widget_get_type (void) G_GNUC_CONST;
+
+GtkWidget * empathy_local_xmpp_assistant_widget_new (void);
+
+void empathy_local_xmpp_assistant_widget_create_account (
+ EmpathyLocalXmppAssistantWidget *self);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET_H__ */