[gnome-chat] Add ChatManager
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chat] Add ChatManager
- Date: Fri, 13 Sep 2013 16:27:36 +0000 (UTC)
commit 955d89eb57500bf4d010d86da02191b119c9c980
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Sep 13 17:12:59 2013 +0200
Add ChatManager
src/Makefile.am | 2 +
src/chat-constants.h | 2 +
src/chat-manager.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/chat-manager.h | 72 +++++++++++++++++++++++++
4 files changed, 221 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 897c0b9..38c6387 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,6 +40,8 @@ gnome_chat_SOURCES = \
chat-main-toolbar.h \
chat-main-window.c \
chat-main-window.h \
+ chat-manager.c \
+ chat-manager.h \
chat-mode-controller.c \
chat-mode-controller.h \
chat-settings.c \
diff --git a/src/chat-constants.h b/src/chat-constants.h
index 4ab003b..5ca9aea 100644
--- a/src/chat-constants.h
+++ b/src/chat-constants.h
@@ -24,6 +24,8 @@
G_BEGIN_DECLS
+#define CHAT_PROTOCOL_IRC "irc"
+
enum
{
CHAT_AVATAR_SIZE = 32, /* pixels */
diff --git a/src/chat-manager.c b/src/chat-manager.c
new file mode 100644
index 0000000..688c314
--- /dev/null
+++ b/src/chat-manager.c
@@ -0,0 +1,145 @@
+/*
+ * Chat - instant messaging client for GNOME
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * This program 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 program 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 program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <glib.h>
+#include <telepathy-glib/telepathy-glib.h>
+
+#include "chat-constants.h"
+#include "chat-manager.h"
+
+
+struct _ChatManagerPrivate
+{
+ TpBaseClient *handler;
+};
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (ChatManager, chat_manager, G_TYPE_OBJECT);
+
+
+static void
+chat_manager_handle_channels (TpSimpleHandler *handler,
+ TpAccount *account,
+ TpConnection *connection,
+ GList *channels,
+ GList *requests_satisfied,
+ gint64 user_action_time,
+ TpHandleChannelsContext *context,
+ gpointer user_data)
+{
+ GError *error;
+ const gchar *protocol;
+
+ protocol = tp_account_get_protocol_name (account);
+ if (g_strcmp0 (protocol, CHAT_PROTOCOL_IRC) == 0)
+ {
+ error = NULL;
+ g_set_error (&error, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED, "IRC is not implemented");
+ tp_handle_channels_context_fail (context, error);
+ g_error_free (error);
+ return;
+ }
+
+ tp_handle_channels_context_accept (context);
+}
+
+
+static GObject *
+chat_manager_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params)
+{
+ static GObject *self = NULL;
+
+ if (self == NULL)
+ {
+ self = G_OBJECT_CLASS (chat_manager_parent_class)->constructor (type, n_construct_params,
construct_params);
+ g_object_add_weak_pointer (self, (gpointer) &self);
+ return self;
+ }
+
+ return g_object_ref (self);
+}
+
+
+static void
+chat_manager_dispose (GObject *object)
+{
+ ChatManager *self = CHAT_MANAGER (object);
+ ChatManagerPrivate *priv = self->priv;
+
+ g_clear_object (&priv->handler);
+
+ G_OBJECT_CLASS (chat_manager_parent_class)->dispose (object);
+}
+
+
+static void
+chat_manager_init (ChatManager *self)
+{
+ ChatManagerPrivate *priv;
+ GError *error;
+ GHashTable *filter;
+ TpAccountManager *am;
+
+ self->priv = chat_manager_get_instance_private (self);
+ priv = self->priv;
+
+ am = tp_account_manager_dup ();
+ priv->handler = tp_simple_handler_new_with_am (am,
+ FALSE,
+ FALSE,
+ PACKAGE_NAME,
+ FALSE,
+ chat_manager_handle_channels,
+ self,
+ NULL);
+ g_object_unref (am);
+
+ filter = tp_asv_new (TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, TP_TYPE_HANDLE, TP_HANDLE_TYPE_CONTACT,
+ NULL);
+ tp_base_client_take_handler_filter (priv->handler, filter);
+
+ error = NULL;
+ if (!tp_base_client_register (priv->handler, &error))
+ {
+ g_critical ("Unable to register text handler: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+
+static void
+chat_manager_class_init (ChatManagerClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->constructor = chat_manager_constructor;
+ object_class->dispose = chat_manager_dispose;
+}
+
+
+ChatManager *
+chat_manager_dup_singleton (void)
+{
+ return g_object_new (CHAT_TYPE_MANAGER, NULL);
+}
diff --git a/src/chat-manager.h b/src/chat-manager.h
new file mode 100644
index 0000000..3b1dbc4
--- /dev/null
+++ b/src/chat-manager.h
@@ -0,0 +1,72 @@
+/*
+ * Chat - instant messaging client for GNOME
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * This program 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 program 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 program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#ifndef CHAT_MANAGER_H
+#define CHAT_MANAGER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define CHAT_TYPE_MANAGER (chat_manager_get_type ())
+
+#define CHAT_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ CHAT_TYPE_MANAGER, ChatManager))
+
+#define CHAT_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ CHAT_TYPE_MANAGER, ChatManagerClass))
+
+#define CHAT_IS_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ CHAT_TYPE_MANAGER))
+
+#define CHAT_IS_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ CHAT_TYPE_MANAGER))
+
+#define CHAT_MANAGER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ CHAT_TYPE_MANAGER, ChatManagerClass))
+
+typedef struct _ChatManager ChatManager;
+typedef struct _ChatManagerClass ChatManagerClass;
+typedef struct _ChatManagerPrivate ChatManagerPrivate;
+
+struct _ChatManager
+{
+ GObject parent_instance;
+ ChatManagerPrivate *priv;
+};
+
+struct _ChatManagerClass
+{
+ GObjectClass parent_class;
+};
+
+GType chat_manager_get_type (void) G_GNUC_CONST;
+
+ChatManager *chat_manager_dup_singleton (void);
+
+G_END_DECLS
+
+#endif /* CHAT_MANAGER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]