~ubuntu-branches/ubuntu/precise/gwibber/precise-proposed

« back to all changes in this revision

Viewing changes to libgwibber/messages.vala

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2011-07-15 17:14:14 UTC
  • mto: This revision was merged to the branch mainline in revision 80.
  • Revision ID: james.westby@ubuntu.com-20110715171414-80ca971vzd56gtmh
Tags: upstream-3.1.2
ImportĀ upstreamĀ versionĀ 3.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright(C) 2010 Neil Jagdish Patel
 
3
 * Copyright(C) 2010 Canonical Ltd.
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU Lesser General Public License
 
7
 * version 3.0 as published by the Free Software Foundation.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU Lesser General Public License version 3.0 for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library. If not, see
 
16
 * <http://www.gnu.org/licenses/>.
 
17
 *
 
18
 * Authored by Neil Jagdish Patel <neil.patel@canonical.com>
 
19
 * Authored by Ken VaDine <ken.vandine@canonical.com>
 
20
 */
 
21
 
 
22
 
 
23
[DBus (name = "com.Gwibber.Messages")]
 
24
private interface MessagesInterface : Object {
 
25
        public signal void Message (string change, string data);
 
26
        public abstract string Get (string mid) throws GLib.IOError;
 
27
}
 
28
 
 
29
namespace Gwibber
 
30
{
 
31
    public class Messages : Object
 
32
    {
 
33
        private const string messages_name  = "com.Gwibber.Messages";
 
34
        private const string messages_path  = "/com/gwibber/Messages";
 
35
 
 
36
        private MessagesInterface messages_service;
 
37
        private Gwibber.Utils utils;
 
38
 
 
39
        /** 
 
40
            Messages::is_available:
 
41
            @arg0: The current state
 
42
 
 
43
            Emitted when com.Gwibber.Messages availability state changes
 
44
        */
 
45
        public signal void is_available(bool is_up);
 
46
 
 
47
        /**
 
48
            Messages::message:
 
49
            @arg0: change
 
50
            @arg1: message
 
51
 
 
52
            Emitted when there is a new message
 
53
        */
 
54
        public signal void message(string change, string data);
 
55
 
 
56
        public Messages ()
 
57
        {
 
58
            try
 
59
            {
 
60
                this.messages_service = Bus.get_proxy_sync(BusType.SESSION,
 
61
                                                           this.messages_name,
 
62
                                                           this.messages_path);
 
63
                this.utils = new Gwibber.Utils();
 
64
                this.utils.setup(this.messages_name);
 
65
                this.utils.available.connect(this.messages_available);
 
66
                messages_service.Message.connect((change, data) => {
 
67
                    this.on_new_message (change, data);
 
68
                });
 
69
            }
 
70
            catch (GLib.IOError e)
 
71
            {
 
72
                warning ("Unable to get Gwibber Messages "+e.message);
 
73
            }
 
74
        }
 
75
 
 
76
 
 
77
        /**
 
78
         * com.Gwibber.Messages
 
79
         **/
 
80
        /*
 
81
        public GLib.Array stream(string stream, string account, int time, string transient, string recipient, string orderby, string order, int limit)
 
82
        {
 
83
            try
 
84
            {
 
85
                return messages_service.Stream(stream, account, time, transient, recipient, orderby, order, limit);
 
86
            }
 
87
            catch (GLib.IOError e)
 
88
            {
 
89
                warning (e.message);
 
90
                return null;
 
91
            }
 
92
          
 
93
        }   
 
94
        */
 
95
 
 
96
        public string get_message (string mid)
 
97
        {
 
98
            try
 
99
            {
 
100
                return messages_service.Get(mid);
 
101
            }
 
102
            catch (GLib.IOError e)
 
103
            {
 
104
                warning (e.message);
 
105
                return "";
 
106
            }
 
107
          
 
108
        }
 
109
 
 
110
        public void on_new_message(string change, string data)
 
111
        {
 
112
                this.message(change, data);
 
113
        }
 
114
        
 
115
        private void messages_available(bool is_up)
 
116
        {
 
117
                this.is_available(is_up);
 
118
        }
 
119
    }
 
120
}