[gnome-contacts] Break out some helper functions
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Break out some helper functions
- Date: Wed, 8 Jun 2011 20:35:17 +0000 (UTC)
commit e675f843cd1cadb1f304f314d4e042fc59583f7c
Author: Alexander Larsson <alexl redhat com>
Date: Wed Jun 8 12:55:22 2011 +0200
Break out some helper functions
src/Makefile.am | 1 +
src/contacts-app.vala | 17 ++---------------
src/contacts-utils.vala | 44 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 15 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index e735679..2f5eb87 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,7 @@ gnome_contacts_SOURCES = \
contacts-contact.vala \
contacts-menu-button.vala \
contacts-store.vala \
+ contacts-utils.vala \
main.vala \
$(NULL)
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 0e8d7c2..c92e6a0 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -286,10 +286,7 @@ public class Contacts.App : Window {
add_string_label (type, p.value, out row);
var button = add_button ("mail-unread-symbolic", ref row);
button.clicked.connect ( () => {
- try {
- Gtk.show_uri (null, "mailto:" + Uri.escape_string (p.value, "@" , false), 0);
- } catch {
- }
+ Utils.compose_mail (p.value);
});
}
}
@@ -309,17 +306,7 @@ public class Contacts.App : Window {
if (button != null) {
button.clicked.connect ( () => {
- var im_persona = contact.find_im_persona (protocol, id);
- var account = (im_persona.store as Tpf.PersonaStore).account;
- var request_dict = new HashTable<weak string,GLib.Value?>(str_hash, str_equal);
- request_dict.insert (TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE, TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT);
- request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE, (int) TelepathyGLib.HandleType.CONTACT);
- request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID, id);
-
- // TODO: Should really use the event time like:
- // tp_user_action_time_from_x11(gtk_get_current_event_time())
- var request = new TelepathyGLib.AccountChannelRequest(account, request_dict, int64.MAX);
- request.ensure_channel_async.begin ("org.freedesktop.Telepathy.Client.Empathy.Chat", null);
+ Utils.start_chat (contact, protocol, id);
});
}
}
diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala
new file mode 100644
index 0000000..1c0a0ea
--- /dev/null
+++ b/src/contacts-utils.vala
@@ -0,0 +1,44 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
+/*
+ * Copyright (C) 2011 Alexander Larsson <alexl redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+using Gtk;
+using Folks;
+
+public class Contacts.Utils : Object {
+ public static void compose_mail (string email) {
+ try {
+ Gtk.show_uri (null, "mailto:" + Uri.escape_string (email, "@" , false), 0);
+ } catch {
+ }
+ }
+
+ public static void start_chat (Contact contact, string protocol, string id) {
+ var im_persona = contact.find_im_persona (protocol, id);
+ var account = (im_persona.store as Tpf.PersonaStore).account;
+ var request_dict = new HashTable<weak string,GLib.Value?>(str_hash, str_equal);
+ request_dict.insert (TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE, TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT);
+ request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE, (int) TelepathyGLib.HandleType.CONTACT);
+ request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID, id);
+
+ // TODO: Should really use the event time like:
+ // tp_user_action_time_from_x11(gtk_get_current_event_time())
+ var request = new TelepathyGLib.AccountChannelRequest(account, request_dict, int64.MAX);
+ request.ensure_channel_async.begin ("org.freedesktop.Telepathy.Client.Empathy.Chat", null);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]