~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//
//
//This is a part of the external demo applet for Cairo-Dock
//
//Copyright : (C) 2010-2011 by Fabounet
//E-mail : fabounet@glx-dock.org
//
//
//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.
//http://www.gnu.org/licenses/licenses.html//GPL

// Base class for Cairo-Dock's applets.
// Make your own class derive from a CDApplet, and override the functions you need (the ones which don't start with an underscore).

// Compile it with the following command, then rename 'demo_mono.exe' to 'demo_mono'.
// gmcs /target:library CDApplet.cs ISubApplet.cs IApplet.cs -pkg:glib-sharp-2.0 -pkg:ndesk-dbus-1.0 -pkg:ndesk-dbus-glib-1.0
  //////////////////////////
 ////// dependancies //////
//////////////////////////
using System;  // Environment
using System.IO;  // Path, Directory
using System.Reflection;
using GLib;
using NDesk.DBus;
using CairoDock.Applet;

//namespace CairoDock.Applet
//{
public class CDApplet
{
	public string cAppletName = null;
	public string cParentAppName = null;
	public string cBusPath = null;
	public string cConfFile = null;
	public string cShareDataDir = null;
	public string cRootDataDir = null;
	public IApplet icon = null;
	public ISubApplet sub_icons= null;
	private GLib.MainLoop loop = null;
	private string cMenuIconId = null;
	
	public enum ScreenPosition {
		BOTTOM = 0,
		TOP,
		RIGHT,
		LEFT
	}
	public enum ContainerType {
		DOCK = 0,
		DESKLET
	}
	public enum EmblemPosition {
		EMBLEM_TOP_LEFT = 0,
		EMBLEM_BOTTOM_RIGHT,
		EMBLEM_BOTTOM_LEFT,
		EMBLEM_TOP_RIGHT,
		EMBLEM_MIDDLE,
		EMBLEM_BOTTOM,
		EMBLEM_TOP,
		EMBLEM_RIGHT,
		EMBLEM_LEFT
	}
	public enum MenuItemType {
		MENU_ENTRY = 0,
		MENU_SUB_MENU,
		MENU_SEPARATOR,
		MENU_CHECKBOX,
		MENU_RADIO_BUTTON
	}

	public enum MenuItemId {
		MAIN_MENU_ID = 0
    }
    
	public enum DialogKey {
		DIALOG_KEY_ENTER = -1,
		DIALOG_KEY_ESCAPE = -2
    }
	
	public CDApplet()
	{
		String[] argv = Environment.GetCommandLineArgs();
		this.cAppletName = argv[0].Substring(2);
		this.cBusPath = argv[2];
		this.cConfFile = argv[3];
		this.cRootDataDir = argv[4];
		this.cParentAppName = argv[5];
		//this.cShareDataDir = Environment.CurrentDir();  // not sure of the exact syntax...
		
		this._get_config ();
		this._connect_to_dock ();
	}
	
	public void run()
	{
		this.begin();
		loop = new GLib.MainLoop();
		loop.Run();
		Console.WriteLine(">>> Applet " + this.cAppletName + " terminated");
	}
	
	//////////////////////////////////
	/// callbacks on the main icon ///
	//////////////////////////////////
	
	public virtual void on_click (int iClickState)
	{
		Console.WriteLine(">>> click");
	}
	public virtual void on_middle_click ()
	{
		Console.WriteLine(">>> middle click");
	}
	public virtual void on_scroll (bool bScrollUp)
	{
		Console.WriteLine(">>> scroll up " + bScrollUp);
	}
	private void _on_build_menu ()
	{
		this.cMenuIconId = null;
		this.on_build_menu ();
	}
	public virtual void on_build_menu ()
	{
		Console.WriteLine(">>> build menu");
	}
	private void _on_menu_select (int iNumEntry)
	{
		if (this.cMenuIconId == null)
			this.on_menu_select (iNumEntry);
		else
			this.on_menu_select_sub_icon (iNumEntry, this.cMenuIconId);
	}
	public virtual void on_menu_select (int iNumEntry)
	{
		Console.WriteLine(">>> select entry : "+iNumEntry);
	}
	public virtual void on_drop_data (string cReceivedData)
	{
		Console.WriteLine(">>> drop : "+cReceivedData);
	}
	public virtual void on_answer (System.Object answer)
	{
		Console.WriteLine(">>> answer : "+answer);
	}
	public virtual void on_answer_dialog (int iButton, System.Object answer)
	{
		Console.WriteLine(">>> answer : "+answer);
	}
	public virtual void on_shortkey (string cKey)
	{
		Console.WriteLine(">>> key : "+cKey);
	}
	public virtual void on_change_focus (bool bIsActive)
	{
		Console.WriteLine(">>> focus changed : "+bIsActive);
	}
	
	//////////////////////////////////
	/// callbacks on the sub-icons ///
	//////////////////////////////////
	
	public virtual void on_click_sub_icon (int iClickState, string cIconID)
	{
		Console.WriteLine(">>> click on sub-icon "+cIconID);
	}
	
	public virtual void on_middle_click_sub_icon (string cIconID)
	{
		Console.WriteLine(">>> middle-click on sub-icon "+cIconID);
	}
	
	public virtual void on_scroll_sub_icon (bool bScrollUp, string cIconID)
	{
		Console.WriteLine(">>> scroll on sub-icon "+cIconID);
	}
	
	private void _on_build_menu_sub_icon (string cIconID)
	{
		this.cMenuIconId = cIconID;
		this.on_build_menu_sub_icon (cIconID);
	}
	public virtual void on_build_menu_sub_icon (string cIconID)
	{
		Console.WriteLine(">>> menu on sub-icon "+cIconID);
	}
	
	public virtual void on_menu_select_sub_icon (int iNumEntry, string cIconID)
	{
		Console.WriteLine(">>> menu entry "+iNumEntry+" selected on sub-icon "+cIconID);
	}
	
	public virtual void on_drop_data_sub_icon (string cReceivedData, string cIconID)
	{
		Console.WriteLine(">>> data "+cReceivedData+" dropped on sub-icon "+cIconID);
	}
	
	public virtual void on_answer_sub_icon (System.Object answer, string cIconID)
	{
		Console.WriteLine(">>> answer "+answer+" from sub-icon "+cIconID);
	}
	
	///////////////////////////////
	/// callbacks on the applet ///
	///////////////////////////////
	
	public virtual void begin ()
	{
		
	}
	
	public virtual void end ()
	{
		
	}
	
	private void _on_stop ()
	{
		this.end();
		this.loop.Quit();
	}
	
	public virtual void reload ()
	{
		
	}
	
	private void _on_reload (bool bConfigHasChanged)
	{
		if (bConfigHasChanged)
		{
			this._get_config();
			this.reload();
		}
	}
	
	public virtual void get_config (string cConfFile_path)
	{
		
	}
	
	private void _get_config()
	{
		this.get_config(this.cConfFile);
	}
	
	private void _connect_to_dock ()
	{
		NDesk.DBus.BusG.Init();
		NDesk.DBus.Bus bus = NDesk.DBus.Bus.Session;
		this.icon = bus.GetObject<IApplet> ("org.cairodock.CairoDock", new ObjectPath (this.cBusPath));
		this.icon.on_click 			+= new OnClickEvent (on_click);
		this.icon.on_middle_click 	+= new OnMiddleClickEvent (on_middle_click);
		this.icon.on_scroll 		+= new OnScrollEvent (on_scroll);
		this.icon.on_build_menu 	+= new OnBuildMenuEvent (_on_build_menu);
		this.icon.on_menu_select 	+= new OnMenuSelectEvent (_on_menu_select);
		this.icon.on_drop_data 		+= new OnDropDataEvent (on_drop_data);
		this.icon.on_answer 		+= new OnAnswerEvent (on_answer);
		this.icon.on_answer_dialog 	+= new OnAnswerDialogEvent (on_answer_dialog);
		this.icon._on_stop 			+= new OnStopModuleEvent (_on_stop);
		this.icon._on_reload 		+= new OnReloadModuleEvent (_on_reload);
		
		this.sub_icons = bus.GetObject<ISubApplet>("org.cairodock.CairoDock", new ObjectPath(this.cBusPath + "/sub_icons"));
		this.sub_icons.on_click_sub_icon			+= new OnClickSubIconEvent (on_click_sub_icon);
		this.sub_icons.on_middle_click_sub_icon 	+= new OnMiddleClickSubIconEvent (on_middle_click_sub_icon);
		this.sub_icons.on_scroll_sub_icon 		+= new OnScrollSubIconEvent (on_scroll_sub_icon);
		this.sub_icons.on_build_menu_sub_icon 	+= new OnBuildMenuSubIconEvent (_on_build_menu_sub_icon);
		this.sub_icons.on_menu_select_sub_icon 	+= new OnMenuSelectSubIconEvent (on_menu_select_sub_icon);
		this.sub_icons.on_drop_data_sub_icon 	+= new OnDropDataSubIconEvent (on_drop_data_sub_icon);
		this.sub_icons.on_answer_sub_icon 		+= new OnAnswerSubIconEvent (on_answer_sub_icon);
	}
}
//}