~ubuntu-branches/ubuntu/quantal/cairo-dock-plug-ins/quantal-201208191523

« back to all changes in this revision

Viewing changes to Dbus/interfaces/vala/CDApplet.vala

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2011-04-20 20:46:51 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110420204651-ftnpzesj6uc7qeul
Tags: 2.3.0~1-0ubuntu1
* New Upstream Version (LP: #723995)
* Upstream short ChangeLog (since 2.3.0~0rc1):
 - Updated translations
 - Updated the integration of the new versions of kwin and compiz
    (Switcher, ShowDesktop, etc.)
 - Removed a lot of useless g_print
 - Updated a few plug-ins to fit with the new version of the API (gldit)
 - Fixed a few bugs
 - Updated MeMenu, MessagingMenu and Status-Notifier to works
    with the latest version of dbusmenu, etc.
* Switch to dpkg-source 3.0 (quilt) format
* debian/cairo-dock-plug-ins.install:
 - Added new files (interfaces for python, ruby, vala and mono)
* debian/control:
 - Added new dependences for new applets (sensors and zeitgeist)
    and new interfaces (python, valac, ruby and mono)
 - Updated the version of cairo-dock build-dependences
* debian/rules:
 - Added a new CMake flag to install python interface in debian/tmp
* Updated debian/watch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This is a part of the external applet for Cairo-Dock
 
2
 
 
3
Copyright : (C) 2010-2011 by Fabounet
 
4
E-mail : fabounet@glx-dock.org
 
5
 
 
6
This program is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License
 
8
as published by the Free Software Foundation; either version 2
 
9
of the License, or (at your option) any later version.
 
10
 
 
11
This program is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
GNU General Public License for more details.
 
15
http://www.gnu.org/licenses/licenses.html#GPL */
 
16
 
 
17
/// To compile it manually:
 
18
/// valac -q -C --disable-warnings --disable-dbus-transformation --pkg gio-2.0 --vapi=CDApplet-simple.vapi --internal-vapi=CDApplet.vapi --header=CDApplet-simple.h --internal-header=CDApplet.h CDApplet.vala
 
19
/// gcc --shared -fPIC -o CDApplet.so $(pkg-config --cflags --libs gobject-2.0 gio-2.0) CDApplet.c
 
20
 
 
21
  /////////////////////////
 
22
 ///// dependancies //////
 
23
/////////////////////////
 
24
using GLib;
 
25
 
 
26
namespace CairoDock.Applet
 
27
{
 
28
[DBus (name = "org.cairodock.CairoDock.applet")]
 
29
public interface IApplet : Object {
 
30
        public signal void on_click (int iState);
 
31
        public signal void on_middle_click ();
 
32
        public signal void on_build_menu ();
 
33
        public signal void on_menu_select(int iNumEntry);
 
34
        public signal void on_scroll(bool bScrollUp);
 
35
        public signal void on_drop_data(string cReceivedData);
 
36
        public signal void on_answer(Variant answer);
 
37
        public signal void on_answer_dialog(int iButton, Variant answer);
 
38
        public signal void on_shortkey(string cKey);
 
39
        public signal void on_change_focus(bool bIsActive);
 
40
        public signal void on_stop_module ();
 
41
        public signal void on_reload_module (bool bConfigHasChanged);
 
42
        public abstract Variant Get (string cProperty) throws IOError;
 
43
        public abstract HashTable<string,Variant> GetAll () throws IOError;
 
44
        public abstract void SetQuickInfo (string cQuickInfo) throws IOError;
 
45
        public abstract void SetLabel (string cLabel) throws IOError;
 
46
        public abstract void SetIcon (string cImage) throws IOError;
 
47
        public abstract void SetEmblem (string cImage, int iPosition) throws IOError;
 
48
        public abstract void Animate (string cAnimation, int iRounds) throws IOError;
 
49
        public abstract void DemandsAttention (bool bStart, string cAnimation) throws IOError;
 
50
        public abstract void ShowDialog (string cMessage, int iDuration) throws IOError;
 
51
        public abstract void PopupDialog (HashTable<string,Variant> hDialogAttributes, HashTable<string,Variant> hWidgetAttributes) throws IOError;
 
52
        public abstract void AddDataRenderer (string cType, int iNbValues, string cTheme) throws IOError;
 
53
        public abstract void RenderValues (double[] pValues) throws IOError;
 
54
        public abstract void ControlAppli (string cApplicationClass) throws IOError;
 
55
        public abstract void ShowAppli (bool bShow) throws IOError;
 
56
        public abstract void AddMenuItems (HashTable<string,Variant>[] pItems) throws IOError;
 
57
        public abstract void BindShortkey (string[] cShortkeys) throws IOError;
 
58
}
 
59
 
 
60
[DBus (name = "org.cairodock.CairoDock.subapplet")]
 
61
public interface ISubApplet : Object {
 
62
        public signal void on_click_sub_icon (int iState, string cIconID);
 
63
        public signal void on_middle_click_sub_icon (string cIconID);
 
64
        public signal void on_scroll_sub_icon (bool bScrollUp, string cIconID);
 
65
        public signal void on_drop_data_sub_icon (string cReceivedData, string cIconID);
 
66
        public signal void on_build_menu_sub_icon (string cIconID);
 
67
        public abstract void SetQuickInfo(string cQuickInfo, string cIconID) throws IOError;
 
68
        public abstract void SetLabel(string cLabel, string cIconID) throws IOError;
 
69
        public abstract void SetIcon(string cImage, string cIconID) throws IOError;
 
70
        public abstract void SetEmblem(string cImage, int iPosition, string cIconID) throws IOError;
 
71
        public abstract void Animate(string cAnimation, int iNbRounds, string cIconID) throws IOError;
 
72
        public abstract void ShowDialog(string message, int iDuration, string cIconID) throws IOError;
 
73
        public abstract void AddSubIcons(string[] pIconFields) throws IOError;
 
74
        public abstract void RemoveSubIcon(string cIconID) throws IOError;
 
75
}
 
76
 
 
77
public class CDApplet : GLib.Object
 
78
{
 
79
        // internal data.
 
80
        public IApplet icon;
 
81
        public ISubApplet sub_icons;
 
82
        public string cAppletName;
 
83
        public string cConfFile;
 
84
        public string cParentAppName;
 
85
        public string cBusPath;
 
86
        private MainLoop loop;
 
87
        private string _cMenuIconId;
 
88
        
 
89
        public enum ScreenPosition {
 
90
                BOTTOM = 0,
 
91
                TOP,
 
92
                RIGHT,
 
93
                LEFT
 
94
        }
 
95
        public enum ContainerType {
 
96
                DOCK = 0,
 
97
                DESKLET
 
98
        }
 
99
        public enum EmblemPosition {
 
100
                UPPER_LEFT = 0,
 
101
                LOWER_RIGHT,
 
102
                LOWER_LEFT,
 
103
                UPPER_RIGHT,
 
104
                MIDDLE
 
105
        }
 
106
        public enum MenuItemType {
 
107
                MENU_ENTRY = 0,
 
108
                MENU_SUB_MENU,
 
109
                MENU_SEPARATOR,
 
110
                MENU_CHECKBOX,
 
111
                MENU_RADIO_BUTTON
 
112
        }
 
113
        
 
114
        public enum MenuItemId {
 
115
                MAIN_MENU_ID = 0
 
116
        }
 
117
 
 
118
        public enum DialogKey {
 
119
                DIALOG_KEY_ENTER = -1,
 
120
                DIALOG_KEY_ESCAPE = -2
 
121
    }
 
122
        
 
123
        public CDApplet(string[] argv)
 
124
        {
 
125
                this.cAppletName = argv[0].substring(2,999);
 
126
                this.cBusPath = argv[2];
 
127
                this.cConfFile = argv[3];
 
128
                this.cParentAppName = argv[4];
 
129
                
 
130
                this._get_config();
 
131
                this._connect_to_bus();
 
132
                this._cMenuIconId = null;
 
133
        }
 
134
        
 
135
        public void run()
 
136
        {
 
137
                this.begin();
 
138
                this.loop = new MainLoop();
 
139
                this.loop.run();
 
140
        }
 
141
        
 
142
          ////////////////////////////////////////
 
143
         ////// callbacks on the main icon //////
 
144
        ////////////////////////////////////////
 
145
        public virtual void on_click(int iState)
 
146
        {
 
147
                print (">>> clic !\n");
 
148
        }
 
149
        public virtual void on_middle_click()
 
150
        {
 
151
                print (">>> middle clic !\n");
 
152
        }
 
153
        private void _on_build_menu()
 
154
        {
 
155
                this._cMenuIconId = null;
 
156
                this.on_build_menu();
 
157
        }
 
158
        public virtual void on_build_menu()
 
159
        {
 
160
                print (">>> build menu !\n");
 
161
        }
 
162
        private void _on_menu_select(int iNumEntry)
 
163
        {
 
164
                if (this._cMenuIconId == null)
 
165
                        this.on_menu_select (iNumEntry);
 
166
                else
 
167
                        this.on_menu_select_sub_icon (iNumEntry, this._cMenuIconId);
 
168
        }
 
169
        public virtual void on_menu_select(int iNumEntry)
 
170
        {
 
171
                print (">>> choice %d has been selected !\n", iNumEntry);
 
172
        }
 
173
        public virtual void on_scroll(bool bScrollUp)
 
174
        {
 
175
                print (">>> scroll (up:%d)\n", (int)bScrollUp);
 
176
        }
 
177
        public virtual void on_drop_data(string cReceivedData)
 
178
        {
 
179
                print (">>> received : %s\n",cReceivedData);
 
180
        }
 
181
        public virtual void on_answer(Variant answer)
 
182
        {
 
183
                print (">>> answer\n");
 
184
        }
 
185
        public virtual void on_answer_dialog(int iButton, Variant answer)
 
186
        {
 
187
                print (">>> answer dialog\n");
 
188
        }
 
189
        public virtual void on_shortkey(string cKey)
 
190
        {
 
191
                print (">>> shortkey : %s\n", cKey);
 
192
        }
 
193
        public virtual void on_change_focus(bool bIsActive)
 
194
        {
 
195
                print (">>> changed focus -> %d\n", (int)bIsActive);
 
196
        }
 
197
 
 
198
          ////////////////////////////////////////
 
199
         ////// callbacks on the sub-icons //////
 
200
        ////////////////////////////////////////
 
201
        public virtual void on_click_sub_icon(int iState, string cIconID)
 
202
        {
 
203
                print ("clic on the sub-icon '%s' !\n", cIconID);
 
204
        }
 
205
        
 
206
        public virtual void on_middle_click_sub_icon(string cIconID)
 
207
        {
 
208
                print ("middle-clic on the sub-icon '%s' !\n", cIconID);
 
209
        }
 
210
        
 
211
        public virtual void on_scroll_sub_icon(bool bScrollUp, string cIconID)
 
212
        {
 
213
                print ("scroll on the sub-icon '%s' !\n", cIconID);
 
214
        }
 
215
        
 
216
        public virtual void on_drop_data_sub_icon(string cReceivedData, string cIconID)
 
217
        {
 
218
                print ("drop on the sub-icon '%s' !\n", cIconID);
 
219
        }
 
220
        
 
221
        private void _on_build_menu_sub_icon(string cIconID)
 
222
        {
 
223
                this._cMenuIconId = cIconID;
 
224
                this.on_build_menu_sub_icon (cIconID);
 
225
        }
 
226
        public virtual void on_build_menu_sub_icon(string cIconID)
 
227
        {
 
228
                print ("build menu on the sub-icon '%s' !\n", cIconID);
 
229
        }
 
230
        public virtual void on_menu_select_sub_icon(int iNumEntry, string cIconID)
 
231
        {
 
232
                print (">>> choice %d has been selected on icon %s !\n", iNumEntry, cIconID);
 
233
        }
 
234
        
 
235
          /////////////////////////////////////
 
236
         ////// callbacks on the applet //////
 
237
        /////////////////////////////////////
 
238
        public virtual void begin()
 
239
        {
 
240
        }
 
241
        
 
242
        public virtual void end()
 
243
        {
 
244
        }
 
245
        private void _on_stop()
 
246
        {
 
247
                print (">>> applet '%s' is stopped\n", this.cAppletName);
 
248
                this.end();
 
249
                loop.quit();
 
250
        }
 
251
        
 
252
        public virtual void reload()
 
253
        {
 
254
        }
 
255
        private void _on_reload(bool bConfigHasChanged)
 
256
        {
 
257
                print (">>> our module is reloaded");
 
258
                if (bConfigHasChanged)
 
259
                {
 
260
                        print (">>>  and our config has changed");
 
261
                        this._get_config();
 
262
                        this.reload();
 
263
                }
 
264
        }
 
265
        
 
266
        public virtual void get_config(GLib.KeyFile keyfile)
 
267
        {
 
268
        }
 
269
        private void _get_config()
 
270
        {
 
271
                GLib.KeyFile keyfile = new GLib.KeyFile();
 
272
                try
 
273
                {
 
274
                        keyfile.load_from_file(this.cConfFile, GLib.KeyFileFlags.NONE);
 
275
                }
 
276
                catch (Error e)
 
277
                {
 
278
                        warning (e.message);
 
279
                }
 
280
                finally
 
281
                {
 
282
                        this.get_config(keyfile);
 
283
                }
 
284
        }
 
285
        
 
286
        private void _connect_to_bus()
 
287
        {
 
288
                ///string cBusPath = "/org/cairodock/CairoDock/"+cAppletName;  // path where our object is stored on the bus.
 
289
                try
 
290
                {
 
291
                        this.icon = Bus.get_proxy_sync (BusType.SESSION,
 
292
                                "org.cairodock.CairoDock",
 
293
                                this.cBusPath);
 
294
                }
 
295
                catch (IOError e)
 
296
                {
 
297
                        GLib.error (">>> module '%s' can't be found on the bus, exit.\nError was: %s", this.cAppletName, e.message);
 
298
                }
 
299
                try
 
300
                {
 
301
                        this.sub_icons = Bus.get_proxy_sync (BusType.SESSION,
 
302
                                "org.cairodock.CairoDock",
 
303
                                this.cBusPath+"/sub_icons");
 
304
                }
 
305
                catch (IOError e)
 
306
                {
 
307
                        GLib.error (">>> module '%s' can't be found on the bus, exit.\nError was: %s", this.cAppletName, e.message);
 
308
                }
 
309
                this.icon.on_click.connect(on_click);  // when the user left-clicks on our icon.
 
310
                this.icon.on_middle_click.connect(on_middle_click);  // when the user middle-clicks on our icon.
 
311
                this.icon.on_build_menu.connect(_on_build_menu);  // when the user right-clicks on our applet (which builds the menu)
 
312
                this.icon.on_menu_select.connect(_on_menu_select);  // when the user selects an entry of this menu.
 
313
                this.icon.on_scroll.connect(on_scroll);  // when the user scroll up or down on our icon.
 
314
                this.icon.on_drop_data.connect(on_drop_data);  // when the user drops something on our icon.
 
315
                this.icon.on_answer.connect(on_answer);  // when the user answer a question (deprecated).
 
316
                this.icon.on_answer_dialog.connect(on_answer_dialog);  // when the user answer a dialog.
 
317
                this.icon.on_shortkey.connect(on_shortkey);  // when the user presses a shortkey.
 
318
                this.icon.on_change_focus.connect(on_change_focus);  // when the focus of the applet's window changes.
 
319
                this.icon.on_stop_module.connect(_on_stop);  // when the user deactivate our applet (or the DBus plug-in, or when the Cairo-Dock is stopped).
 
320
                this.icon.on_reload_module.connect(_on_reload);  // when the user changes something in our config, or when the desklet is resized (with no change in the config).
 
321
                this.sub_icons.on_click_sub_icon.connect(on_click_sub_icon);  // when the user left-clicks on a sub-icon.
 
322
                this.sub_icons.on_middle_click_sub_icon.connect(on_middle_click_sub_icon);  // when the user middle-clicks on a sub-icon.
 
323
                this.sub_icons.on_scroll_sub_icon.connect(on_scroll_sub_icon);  // when the user scrolls on a sub-icon.
 
324
                this.sub_icons.on_drop_data_sub_icon.connect(on_drop_data_sub_icon);  // when the user drops sth on a sub-icon.
 
325
                this.sub_icons.on_build_menu_sub_icon.connect(_on_build_menu_sub_icon);  // when the user drops sth on a sub-icon.
 
326
        }
 
327
}
 
328
}