Debian Codegraph @

Dbus/demos/demo_mono/demo_mono.cs

raw symbols SCIP
1 //
2 //
3 //This is a part of the external demo applet for Cairo-Dock
4 //
5 //Copyright : (C) 2010-2011 by Fabounet
6 //E-mail : [email protected]
7 //
8 //
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.
13 //
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
19
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)
24 //
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.
31
32 // Compile it with the following command, then rename 'demo_mono.exe' to 'demo_mono'.
33 // gmcs demo_mono.cs -r:/usr/lib/cli/CDApplet.dll
34 // ln -s demo_mono.exe demo_mono
35
36 //////////////////////////
37 ////// dependancies //////
38 //////////////////////////
39 using System;
40 using System.Collections.Generic;
41 using CairoDock.Applet;
42
43 public struct Config {
44 public string cTheme;
45 public int iMaxValue;
46 public bool yesno;
47 }
48
49 ////////////////////
50 /// Applet class ///
51 ////////////////////
52 public class Applet : CDApplet
53 {
54 private Config config;
55 private int count = 0;
56
57 public Applet()
58 {
59
60 }
61
62 ////////////////////////////
63 ////// private methods //////
64 ////////////////////////////
65
66 private void set_counter(int n)
67 {
68 this.count = n;
69 this.icon.RenderValues(new double[] {(double)n/this.config.iMaxValue});
70 this.icon.SetQuickInfo(String.Format(n.ToString()));
71 }
72
73 ///////////////////////////////
74 ////// applet definition //////
75 ///////////////////////////////
76
77 public override void get_config (string cConfFilePath)
78 {
79 /// read cConfFilePath...
80 this.config.iMaxValue = 100;
81 this.config.cTheme = "Turbo-night";
82 this.config.yesno = true;
83 }
84
85 public override void end()
86 {
87 Console.WriteLine("*** Bye !");
88 }
89
90 public override void begin()
91 {
92 this.icon.ShowDialog ("I'm connected to Cairo-Dock !", 4);
93 this.icon.AddDataRenderer("gauge", 1, this.config.cTheme);
94 this.set_counter (0);
95 }
96
97 public override void reload()
98 {
99 this.icon.AddDataRenderer("gauge", 1, this.config.cTheme);
100 this.set_counter (Math.Min (this.count, this.config.iMaxValue));
101 }
102
103 ////////////////////////////////////////
104 ////// callbacks on the main icon //////
105 ////////////////////////////////////////
106
107 public override void on_click (int iClickState)
108 {
109 Console.WriteLine("*** click");
110 }
111
112 public override void on_middle_click ()
113 {
114 Console.WriteLine("*** middle click");
115 Dictionary<string, object> dialog_attributes = new Dictionary<string, object> () {
116 {"icon" , "stock_properties"},
117 {"message" , "Set the value you want"},
118 {"buttons" , "ok;cancel"} };
119 Dictionary<string, object> widget_attributes = new Dictionary<string, object> () {
120 {"widget-type" , "scale"},
121 {"max-value" , this.config.iMaxValue},
122 {"message" , "Set the value you want"} };
123
124 this.icon.PopupDialog(dialog_attributes, widget_attributes);
125 }
126
127 public override void on_scroll (bool bScrollUp)
128 {
129 Console.WriteLine("*** scroll up " + bScrollUp);
130 int n;
131 if (bScrollUp)
132 n = Math.Min(100, this.count+1);
133 else
134 n = Math.Max(0, this.count-1);
135 this.set_counter(n);
136 }
137
138 public override void on_build_menu ()
139 {
140 Console.WriteLine("*** build menu");
141 /// Warning : the AddMenuItems fails with DBus Sharp 0.6.0; until this is fixed, use the PopulateMenu method.
142 /**Dictionary<string, object>[] pItems = new Dictionary<string, object>[] {
143 new Dictionary<string, object>()
144 {
145 {"label", "set min value"},
146 {"icon", "gtk-zoom-out"},
147 {"id", 0}
148 },
149 new Dictionary<string, object>()
150 {
151 {"label", "set medium value"},
152 {"icon", "gtk-zoom-fit"},
153 {"id", 1}
154 },
155 new Dictionary<string, object>()
156 {
157 {"label", "set max value"},
158 {"icon", "gtk-zoom-in"},
159 {"id", 2}
160 }
161 };
162 Console.WriteLine("*** item 1:"+pItems[0]["icon"]);
163 this.icon.AddMenuItems(pItems);*/
164 this.icon.PopulateMenu(new string[] {"set min value", "set medium value", "set max value"});
165 }
166
167 public override void on_menu_select (int iNumEntry)
168 {
169 Console.WriteLine("*** select entry : "+iNumEntry);
170 if (iNumEntry == 0)
171 this.set_counter(0);
172 else if (iNumEntry == 1)
173 this.set_counter(this.config.iMaxValue/2);
174 else if (iNumEntry == 2)
175 this.set_counter(this.config.iMaxValue);
176 }
177 public override void on_drop_data (string cReceivedData)
178 {
179 Console.WriteLine("*** drop : "+cReceivedData);
180 this.icon.SetLabel(cReceivedData);
181 }
182 public override void on_answer_dialog (int iButton, System.Object answer)
183 {
184 Console.WriteLine("*** answer : "+(double)answer);
185 if (iButton == 0)
186 {
187 double x = (double)answer;
188 this.set_counter((int) x);
189 }
190 }
191
192 //////////////////
193 ////// main //////
194 //////////////////
195 public static void Main (string[] args)
196 {
197 Applet myApplet = new Applet();
198 myApplet.run();
199 }
200 }
201