| 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 |
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 |
|
| 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 |
|
| 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 |
|
| 75 |
|
| 76 |
|
| 77 |
public override void get_config (string cConfFilePath) |
| 78 |
{ |
| 79 |
|
| 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 |
|
| 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 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 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 |
|
| 194 |
|
| 195 |
public static void Main (string[] args) |
| 196 |
{ |
| 197 |
Applet myApplet = new Applet(); |
| 198 |
myApplet.run(); |
| 199 |
} |
| 200 |
} |
| 201 |
|