3
//This is a part of the external demo applet for Cairo-Dock
5
//Copyright : (C) 2010 by Fabounet
6
//E-mail : fabounet@glx-dock.org
9
//This program is free software; you can redistribute it and/or
10
//modify it under the terms of the GNU General Public License
11
//as published by the Free Software Foundation; either version 2
12
//of the License, or (at your option) any later version.
14
//This program is distributed in the hope that it will be useful,
15
//but WITHOUT ANY WARRANTY; without even the implied warranty of
16
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
//GNU General Public License for more details.
18
//http://www.gnu.org/licenses/licenses.html//GPL
20
//The name of this applet is "demo_mono"; it is placed in a folder named "demo_mono", with a file named "auto-load.conf" which describes it.
21
//Copy this folder into ~/.config/cairo-dock/third-party to let the dock register it automatically.
22
//In the folder we have :
23
//"demo_mono" (the executable script), "demo_mono.conf" (the default config file), "auto-load.conf" (the file describing our applet), "icon" (the default icon of the applet) and "preview" (a preview of this applet)
25
//This very simple applet features a counter from 0 to iMaxValue It displays the counter on the icon with a gauge and a quick info.
26
//Scroll on the icon increase or decrease the counter.
27
//The menu offers the possibility to set some default value.
28
//Left click on the icon will set a random value.
29
//Middle click on the icon will raise a dialog asking you to set the value you want.
30
//If you drop some text on the icon, it will be used as the icon's label.
32
// Compile it with the following command, then rename 'demo_mono.exe' to 'demo_mono'.
33
//gmcs demo_mono.cs -r:/usr/lib/mono/gtk-sharp-2.0/glib-sharp.dll -r:/usr/lib/cli/ndesk-dbus-glib-1.0/NDesk.DBus.GLib.dll -r:/usr/lib/cli/ndesk-dbus-1.0/NDesk.DBus.dll
35
//////////////////////////
36
////// dependancies //////
37
//////////////////////////
42
////////////////////////////
43
////// DBus Interface //////
44
////////////////////////////
45
public delegate void OnClickEvent (int i);
46
public delegate void OnMiddleClickEvent ();
47
public delegate void OnScrollEvent (bool b);
48
public delegate void OnBuildMenuEvent ();
49
public delegate void OnMenuSelectEvent (int i);
50
public delegate void OnDropDataEvent (string s);
51
public delegate void OnChangeFocusEvent (bool b);
52
public delegate void OnAnswerEvent (System.Object v);
53
public delegate void OnStopModuleEvent ();
54
public delegate void OnReloadModuleEvent (bool b);
55
[NDesk.DBus.Interface ("org.cairodock.CairoDock.applet")]
56
public interface IIcon
58
System.Object Get (string s);
60
void SetLabel (string s);
61
void SetIcon (string s);
62
void SetEmblem (string s, int i);
63
void Animate (string s, int i);
64
void SetQuickInfo (string s);
65
void ShowDialog (string s, int i);
66
void AskQuestion (string s);
67
void AskValue (string s, double x, double y);
68
void AskText (string s, string t);
69
void AddDataRenderer (string s, int i, string t);
70
void RenderValues (double[] x);
71
void ControlAppli (string s);
72
void PopulateMenu (string[] s);
73
event OnClickEvent on_click;
74
event OnMiddleClickEvent on_middle_click;
75
event OnScrollEvent on_scroll;
76
event OnBuildMenuEvent on_build_menu;
77
event OnMenuSelectEvent on_menu_select;
78
event OnDropDataEvent on_drop_data;
79
event OnChangeFocusEvent on_change_focus;
80
event OnAnswerEvent on_answer;
81
event OnStopModuleEvent on_stop_module;
82
event OnReloadModuleEvent on_reload_module;
85
public struct Config {
93
public static string applet_name = "demo_mono"; // the name of the applet must the same as the folder.
94
public static string applet_path = "/org/cairodock/CairoDock/"+applet_name; // path where our object is stored on the bus.
95
public static string conf_file = Environment.GetEnvironmentVariable("HOME")+"/.config/cairo-dock/current_theme/plug-ins/"+applet_name+"/"+applet_name+".conf"; // path to the conf file of our applet.
96
public IIcon myIcon = null;
97
public Config myConfig;
98
private GLib.MainLoop loop = null;
99
private int count = 0;
105
myIcon.ShowDialog ("I'm connected to Cairo-Dock !", 4);
106
myIcon.AddDataRenderer("gauge", 1, myConfig.cTheme);
107
this.set_counter (0);
108
loop = new GLib.MainLoop();
115
public void connect_to_dock()
118
Bus bus = Bus.Session;
119
myIcon = bus.GetObject<IIcon> ("org.cairodock.CairoDock", new ObjectPath (applet_path));
120
myIcon.on_click += new OnClickEvent (action_on_click);
121
myIcon.on_middle_click += new OnMiddleClickEvent (action_on_middle_click);
122
myIcon.on_scroll += new OnScrollEvent (action_on_scroll);
123
myIcon.on_build_menu += new OnBuildMenuEvent (action_on_build_menu);
124
myIcon.on_menu_select += new OnMenuSelectEvent (action_on_menu_select);
125
myIcon.on_drop_data += new OnDropDataEvent (action_on_drop_data);
126
myIcon.on_answer += new OnAnswerEvent (action_on_answer);
127
myIcon.on_stop_module += new OnStopModuleEvent (action_on_stop_module);
128
myIcon.on_reload_module += new OnReloadModuleEvent (action_on_reload_module);
130
public void get_config ()
132
/// read this.conf_file ...
133
myConfig.iMaxValue = 100;
134
myConfig.cTheme = "Turbo-night";
135
myConfig.yesno = true;
137
////////////////////////////////////////
138
////// callbacks on the main icon //////
139
////////////////////////////////////////
140
private void action_on_click (int iClickState)
142
Console.WriteLine(">>> click");
144
private void action_on_middle_click ()
146
Console.WriteLine(">>> middle click");
147
myIcon.AskValue("Set the value you want", this.count, 100);
149
private void action_on_scroll (bool bScrollUp)
151
Console.WriteLine(">>> scroll up " + bScrollUp);
154
n = Math.Min(100, this.count+1);
156
n = Math.Max(0, this.count-1);
159
private void action_on_build_menu ()
161
Console.WriteLine(">>> build menu");
162
myIcon.PopulateMenu(new string [] {"set min value", "set medium value", "set max value"});
164
private void action_on_menu_select (int iNumEntry)
166
Console.WriteLine(">>> select entry : "+iNumEntry);
169
else if (iNumEntry == 1)
170
this.set_counter(100/2);
171
else if (iNumEntry == 2)
172
this.set_counter(100);
174
private void action_on_drop_data (string cReceivedData)
176
Console.WriteLine(">>> drop : "+cReceivedData);
177
myIcon.SetLabel(cReceivedData);
179
private void action_on_answer (System.Object answer)
181
Console.WriteLine(">>> answer : "+(double)answer);
182
double x = (double)answer;
183
this.set_counter((int) x);
185
/////////////////////////////////////
186
////// callbacks on the applet //////
187
/////////////////////////////////////
188
private void action_on_stop_module ()
190
Console.WriteLine(">>> stop");
193
private void action_on_reload_module (bool bConfigHasChanged)
195
Console.WriteLine(">>> our module is reloaded");
196
if (bConfigHasChanged)
198
Console.WriteLine (">>> and our config has changed");
200
myIcon.AddDataRenderer("gauge", 1, this.myConfig.cTheme);
201
this.set_counter (Math.Min (this.count, this.myConfig.iMaxValue));
205
////////////////////////////
206
////// applet methods //////
207
////////////////////////////
208
public void set_counter(int n)
211
myIcon.RenderValues(new double[] {(double)n/myConfig.iMaxValue});
212
myIcon.SetQuickInfo(String.Format(n.ToString()));
218
public static void Main ()
220
Applet myApplet = new Applet ();
222
Console.WriteLine(">>> bye");