1
/* This is a part of the external applet for Cairo-Dock
3
Copyright : (C) 2010-2011 by Fabounet
4
E-mail : fabounet@glx-dock.org
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.
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 */
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
21
/////////////////////////
22
///// dependancies //////
23
/////////////////////////
26
namespace CairoDock.Applet
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;
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;
77
public class CDApplet : GLib.Object
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;
89
public enum ScreenPosition {
95
public enum ContainerType {
99
public enum EmblemPosition {
106
public enum MenuItemType {
114
public enum MenuItemId {
118
public enum DialogKey {
119
DIALOG_KEY_ENTER = -1,
120
DIALOG_KEY_ESCAPE = -2
123
public CDApplet(string[] argv)
125
this.cAppletName = argv[0].substring(2,999);
126
this.cBusPath = argv[2];
127
this.cConfFile = argv[3];
128
this.cParentAppName = argv[4];
131
this._connect_to_bus();
132
this._cMenuIconId = null;
138
this.loop = new MainLoop();
142
////////////////////////////////////////
143
////// callbacks on the main icon //////
144
////////////////////////////////////////
145
public virtual void on_click(int iState)
147
print (">>> clic !\n");
149
public virtual void on_middle_click()
151
print (">>> middle clic !\n");
153
private void _on_build_menu()
155
this._cMenuIconId = null;
156
this.on_build_menu();
158
public virtual void on_build_menu()
160
print (">>> build menu !\n");
162
private void _on_menu_select(int iNumEntry)
164
if (this._cMenuIconId == null)
165
this.on_menu_select (iNumEntry);
167
this.on_menu_select_sub_icon (iNumEntry, this._cMenuIconId);
169
public virtual void on_menu_select(int iNumEntry)
171
print (">>> choice %d has been selected !\n", iNumEntry);
173
public virtual void on_scroll(bool bScrollUp)
175
print (">>> scroll (up:%d)\n", (int)bScrollUp);
177
public virtual void on_drop_data(string cReceivedData)
179
print (">>> received : %s\n",cReceivedData);
181
public virtual void on_answer(Variant answer)
183
print (">>> answer\n");
185
public virtual void on_answer_dialog(int iButton, Variant answer)
187
print (">>> answer dialog\n");
189
public virtual void on_shortkey(string cKey)
191
print (">>> shortkey : %s\n", cKey);
193
public virtual void on_change_focus(bool bIsActive)
195
print (">>> changed focus -> %d\n", (int)bIsActive);
198
////////////////////////////////////////
199
////// callbacks on the sub-icons //////
200
////////////////////////////////////////
201
public virtual void on_click_sub_icon(int iState, string cIconID)
203
print ("clic on the sub-icon '%s' !\n", cIconID);
206
public virtual void on_middle_click_sub_icon(string cIconID)
208
print ("middle-clic on the sub-icon '%s' !\n", cIconID);
211
public virtual void on_scroll_sub_icon(bool bScrollUp, string cIconID)
213
print ("scroll on the sub-icon '%s' !\n", cIconID);
216
public virtual void on_drop_data_sub_icon(string cReceivedData, string cIconID)
218
print ("drop on the sub-icon '%s' !\n", cIconID);
221
private void _on_build_menu_sub_icon(string cIconID)
223
this._cMenuIconId = cIconID;
224
this.on_build_menu_sub_icon (cIconID);
226
public virtual void on_build_menu_sub_icon(string cIconID)
228
print ("build menu on the sub-icon '%s' !\n", cIconID);
230
public virtual void on_menu_select_sub_icon(int iNumEntry, string cIconID)
232
print (">>> choice %d has been selected on icon %s !\n", iNumEntry, cIconID);
235
/////////////////////////////////////
236
////// callbacks on the applet //////
237
/////////////////////////////////////
238
public virtual void begin()
242
public virtual void end()
245
private void _on_stop()
247
print (">>> applet '%s' is stopped\n", this.cAppletName);
252
public virtual void reload()
255
private void _on_reload(bool bConfigHasChanged)
257
print (">>> our module is reloaded");
258
if (bConfigHasChanged)
260
print (">>> and our config has changed");
266
public virtual void get_config(GLib.KeyFile keyfile)
269
private void _get_config()
271
GLib.KeyFile keyfile = new GLib.KeyFile();
274
keyfile.load_from_file(this.cConfFile, GLib.KeyFileFlags.NONE);
282
this.get_config(keyfile);
286
private void _connect_to_bus()
288
///string cBusPath = "/org/cairodock/CairoDock/"+cAppletName; // path where our object is stored on the bus.
291
this.icon = Bus.get_proxy_sync (BusType.SESSION,
292
"org.cairodock.CairoDock",
297
GLib.error (">>> module '%s' can't be found on the bus, exit.\nError was: %s", this.cAppletName, e.message);
301
this.sub_icons = Bus.get_proxy_sync (BusType.SESSION,
302
"org.cairodock.CairoDock",
303
this.cBusPath+"/sub_icons");
307
GLib.error (">>> module '%s' can't be found on the bus, exit.\nError was: %s", this.cAppletName, e.message);
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.