Browse Source

smd-applet code for the popen thread almost there

note: requires valac 0.7.3
Enrico Tassi 12 years ago
parent
commit
bf54fa09c8
3 changed files with 300 additions and 3 deletions
  1. 2
    1
      Makefile
  2. 247
    0
      smd-applet.ui
  3. 51
    2
      smd-applet.vala

+ 2
- 1
Makefile View File

@@ -9,7 +9,8 @@ VERSION=0.9.6
9 9
 all: check-build $(BINARIES) 
10 10
 
11 11
 %: %.vala 
12
-	valac --pkg gtk+-2.0 --pkg libnotify --pkg gconf-2.0 -o $@ $<
12
+	valac -o $@ $< --thread --pkg glib-2.0 --pkg gtk+-2.0 \
13
+		--pkg libnotify --pkg gconf-2.0 --pkg posix
13 14
 
14 15
 %: %.c
15 16
 	gcc -Wall -Wextra -g $< -o $@ \

+ 247
- 0
smd-applet.ui View File

@@ -41,6 +41,7 @@
41 41
     </columns>
42 42
   </object>
43 43
   <object class="GtkWindow" id="wPrefs">
44
+    <property name="window_position">center</property>
44 45
     <child>
45 46
       <object class="GtkHBox" id="hbox1">
46 47
         <property name="visible">True</property>
@@ -57,6 +58,7 @@
57 58
                   <object class="GtkFrame" id="frame1">
58 59
                     <property name="visible">True</property>
59 60
                     <property name="label_xalign">0</property>
61
+                    <property name="shadow_type">none</property>
60 62
                     <child>
61 63
                       <object class="GtkAlignment" id="alignment1">
62 64
                         <property name="visible">True</property>
@@ -167,4 +169,249 @@
167 169
     <property name="page_increment">10</property>
168 170
     <property name="page_size">10</property>
169 171
   </object>
172
+  <object class="GtkWindow" id="wError">
173
+    <child>
174
+      <object class="GtkVBox" id="vbox1">
175
+        <property name="visible">True</property>
176
+        <property name="orientation">vertical</property>
177
+        <property name="spacing">5</property>
178
+        <child>
179
+          <object class="GtkHBox" id="hbox1">
180
+            <property name="visible">True</property>
181
+            <child>
182
+              <object class="GtkImage" id="image1">
183
+                <property name="visible">True</property>
184
+                <property name="xpad">10</property>
185
+                <property name="ypad">10</property>
186
+                <property name="stock">gtk-dialog-error</property>
187
+                <property name="icon-size">6</property>
188
+              </object>
189
+              <packing>
190
+                <property name="expand">False</property>
191
+                <property name="position">0</property>
192
+              </packing>
193
+            </child>
194
+            <child>
195
+              <object class="GtkLabel" id="label4">
196
+                <property name="visible">True</property>
197
+                <property name="xalign">0</property>
198
+                <property name="xpad">10</property>
199
+                <property name="label" translatable="yes">Syncmaildir encountered an error and is asking your intervention.
200
+</property>
201
+                <property name="wrap">True</property>
202
+              </object>
203
+              <packing>
204
+                <property name="position">1</property>
205
+              </packing>
206
+            </child>
207
+          </object>
208
+          <packing>
209
+            <property name="position">0</property>
210
+          </packing>
211
+        </child>
212
+        <child>
213
+          <object class="GtkFrame" id="frame1">
214
+            <property name="visible">True</property>
215
+            <property name="label_xalign">0</property>
216
+            <property name="shadow_type">none</property>
217
+            <child>
218
+              <object class="GtkAlignment" id="alignment1">
219
+                <property name="visible">True</property>
220
+                <property name="left_padding">12</property>
221
+                <child>
222
+                  <object class="GtkLabel" id="lContext">
223
+                    <property name="visible">True</property>
224
+                    <property name="xalign">0</property>
225
+                    <property name="label" translatable="yes">label</property>
226
+                    <property name="wrap">True</property>
227
+                  </object>
228
+                </child>
229
+              </object>
230
+            </child>
231
+            <child type="label">
232
+              <object class="GtkLabel" id="label1">
233
+                <property name="visible">True</property>
234
+                <property name="label" translatable="yes">&lt;b&gt;Error context&lt;/b&gt;</property>
235
+                <property name="use_markup">True</property>
236
+              </object>
237
+            </child>
238
+          </object>
239
+          <packing>
240
+            <property name="position">1</property>
241
+          </packing>
242
+        </child>
243
+        <child>
244
+          <object class="GtkFrame" id="frame2">
245
+            <property name="visible">True</property>
246
+            <property name="label_xalign">0</property>
247
+            <property name="shadow_type">none</property>
248
+            <child>
249
+              <object class="GtkAlignment" id="alignment2">
250
+                <property name="visible">True</property>
251
+                <property name="left_padding">12</property>
252
+                <child>
253
+                  <object class="GtkLabel" id="lCause">
254
+                    <property name="visible">True</property>
255
+                    <property name="xalign">0</property>
256
+                    <property name="label" translatable="yes">label</property>
257
+                    <property name="wrap">True</property>
258
+                  </object>
259
+                </child>
260
+              </object>
261
+            </child>
262
+            <child type="label">
263
+              <object class="GtkLabel" id="label2">
264
+                <property name="visible">True</property>
265
+                <property name="label" translatable="yes">&lt;b&gt;Possible cause&lt;/b&gt;</property>
266
+                <property name="use_markup">True</property>
267
+              </object>
268
+            </child>
269
+          </object>
270
+          <packing>
271
+            <property name="position">2</property>
272
+          </packing>
273
+        </child>
274
+        <child>
275
+          <object class="GtkFrame" id="frame3">
276
+            <property name="visible">True</property>
277
+            <property name="label_xalign">0</property>
278
+            <property name="shadow_type">none</property>
279
+            <child>
280
+              <object class="GtkAlignment" id="alignment3">
281
+                <property name="visible">True</property>
282
+                <property name="left_padding">12</property>
283
+                <child>
284
+                  <object class="GtkVBox" id="vbox2">
285
+                    <property name="visible">True</property>
286
+                    <property name="orientation">vertical</property>
287
+                    <child>
288
+                      <object class="GtkFrame" id="frame6">
289
+                        <property name="visible">True</property>
290
+                        <property name="label_xalign">0</property>
291
+                        <property name="shadow_type">none</property>
292
+                        <child>
293
+                          <object class="GtkAlignment" id="alignment6">
294
+                            <property name="visible">True</property>
295
+                            <property name="left_padding">12</property>
296
+                            <child>
297
+                              <object class="GtkTextView" id="tvMail">
298
+                                <property name="visible">True</property>
299
+                                <property name="can_focus">True</property>
300
+                                <property name="editable">False</property>
301
+                              </object>
302
+                            </child>
303
+                          </object>
304
+                        </child>
305
+                        <child type="label">
306
+                          <object class="GtkLabel" id="label7">
307
+                            <property name="visible">True</property>
308
+                            <property name="label" translatable="yes">&lt;b&gt;Show mail message&lt;/b&gt;</property>
309
+                            <property name="use_markup">True</property>
310
+                          </object>
311
+                        </child>
312
+                      </object>
313
+                      <packing>
314
+                        <property name="position">0</property>
315
+                      </packing>
316
+                    </child>
317
+                    <child>
318
+                      <object class="GtkFrame" id="frame5">
319
+                        <property name="visible">True</property>
320
+                        <property name="label_xalign">0</property>
321
+                        <property name="shadow_type">none</property>
322
+                        <child>
323
+                          <object class="GtkAlignment" id="alignment5">
324
+                            <property name="visible">True</property>
325
+                            <property name="left_padding">12</property>
326
+                            <child>
327
+                              <object class="GtkLabel" id="lPermissions">
328
+                                <property name="visible">True</property>
329
+                                <property name="xalign">0</property>
330
+                                <property name="label" translatable="yes">label</property>
331
+                              </object>
332
+                            </child>
333
+                          </object>
334
+                        </child>
335
+                        <child type="label">
336
+                          <object class="GtkLabel" id="label6">
337
+                            <property name="visible">True</property>
338
+                            <property name="label" translatable="yes">&lt;b&gt;Check file permissions&lt;/b&gt;</property>
339
+                            <property name="use_markup">True</property>
340
+                          </object>
341
+                        </child>
342
+                      </object>
343
+                      <packing>
344
+                        <property name="position">1</property>
345
+                      </packing>
346
+                    </child>
347
+                    <child>
348
+                      <object class="GtkFrame" id="fRun">
349
+                        <property name="visible">True</property>
350
+                        <property name="label_xalign">0</property>
351
+                        <property name="shadow_type">none</property>
352
+                        <child>
353
+                          <object class="GtkAlignment" id="alignment4">
354
+                            <property name="visible">True</property>
355
+                            <property name="left_padding">12</property>
356
+                            <child>
357
+                              <placeholder/>
358
+                            </child>
359
+                          </object>
360
+                        </child>
361
+                        <child type="label">
362
+                          <object class="GtkLabel" id="label5">
363
+                            <property name="visible">True</property>
364
+                            <property name="label" translatable="yes">&lt;b&gt;Run command&lt;/b&gt;</property>
365
+                            <property name="use_markup">True</property>
366
+                          </object>
367
+                        </child>
368
+                      </object>
369
+                      <packing>
370
+                        <property name="position">2</property>
371
+                      </packing>
372
+                    </child>
373
+                  </object>
374
+                </child>
375
+              </object>
376
+            </child>
377
+            <child type="label">
378
+              <object class="GtkLabel" id="label3">
379
+                <property name="visible">True</property>
380
+                <property name="label" translatable="yes">&lt;b&gt;Proposed actions&lt;/b&gt;</property>
381
+                <property name="use_markup">True</property>
382
+              </object>
383
+            </child>
384
+          </object>
385
+          <packing>
386
+            <property name="position">3</property>
387
+          </packing>
388
+        </child>
389
+        <child>
390
+          <object class="GtkHButtonBox" id="hbuttonbox1">
391
+            <property name="visible">True</property>
392
+            <property name="layout_style">end</property>
393
+            <child>
394
+              <object class="GtkButton" id="button1">
395
+                <property name="label" translatable="yes">gtk-close</property>
396
+                <property name="visible">True</property>
397
+                <property name="can_focus">True</property>
398
+                <property name="receives_default">True</property>
399
+                <property name="use_stock">True</property>
400
+              </object>
401
+              <packing>
402
+                <property name="expand">False</property>
403
+                <property name="fill">False</property>
404
+                <property name="position">0</property>
405
+              </packing>
406
+            </child>
407
+          </object>
408
+          <packing>
409
+            <property name="expand">False</property>
410
+            <property name="padding">4</property>
411
+            <property name="position">4</property>
412
+          </packing>
413
+        </child>
414
+      </object>
415
+    </child>
416
+  </object>
170 417
 </interface>

+ 51
- 2
smd-applet.vala View File

@@ -8,6 +8,7 @@ class smdApplet {
8 8
 	Gtk.StatusIcon si = null;
9 9
 	Gtk.Window win = null;
10 10
 	GConf.Client gconf = null;
11
+	weak GLib.Thread thread = null;
11 12
 
12 13
 	static const string key_icon = "/apps/smd-applet/icon_only_on_errors";
13 14
 	static const string key_newmail = "/apps/smd-applet/notify_new_mail";
@@ -35,7 +36,7 @@ class smdApplet {
35 36
 		var quit = builder.get_object ("miQuit") as MenuItem;
36 37
 		quit.activate += (b) => { Gtk.main_quit(); };
37 38
 		var about = builder.get_object ("miAbout") as MenuItem;
38
-		about.activate += (b) => { Gtk.main_quit(); };
39
+		about.activate += (b) => { si.set_blinking(true); };
39 40
 		var prefs = builder.get_object ("miPrefs") as MenuItem;
40 41
 		prefs.activate += (b) => {  win.show(); };
41 42
 
@@ -51,7 +52,55 @@ class smdApplet {
51 52
 		// not.show();
52 53
 	}
53 54
 
54
-	void run() { Gtk.main(); }
55
+	public void *smdThread() {
56
+		int[] p = new int[2]; 
57
+		if (Posix.pipe(p) != 0) {
58
+			stderr.printf("pipe() failed\n");
59
+			return null;
60
+		}
61
+		Posix.pid_t pid;
62
+		if ( (pid = Posix.fork()) == 0 ){
63
+			// son
64
+			string cmd = "/usr/bin/cal";
65
+			Posix.dup2(p[1],1);
66
+			Posix.execl(cmd,cmd);
67
+			stderr.printf("Unable to exec "+cmd+"\n");
68
+			Posix.exit(1);
69
+		} else if (pid > 0) {
70
+			int size = 10;
71
+			char[] buff = new char[size];
72
+			Posix.timeval t = Posix.timeval();
73
+			t.tv_sec = 1;
74
+			t.tv_usec = 0;
75
+			Posix.fd_set fds = Posix.fd_set();
76
+			while(true){
77
+				Posix.FD_ZERO(fds);
78
+				Posix.FD_SET(p[0],fds);
79
+				int n = Posix.select(p[0]+1,fds,null,null,t);
80
+				if (n == 0) {
81
+					int rc;
82
+					int pi = Posix.waitpid(pid,out rc,1); // Posix.WNOHANG
83
+					if (pi == pid) break;
84
+				}
85
+				if (n > 0) {
86
+					ssize_t nread = Posix.read(p[0], buff, size);
87
+					Posix.write(0,buff,nread);
88
+				} else {
89
+					break;
90
+				}
91
+			}
92
+		} else {
93
+			stderr.printf("fork() failed\n");
94
+		}
95
+		return null;
96
+	}
97
+
98
+	void run() { 
99
+		try { thread = GLib.Thread.create(smdThread,true); }
100
+		catch (GLib.ThreadError e) { stderr.printf("unable to start\n"); }
101
+		Gtk.main(); 
102
+		thread.join();
103
+	}
55 104
 
56 105
 	static int main(string[] args){
57 106
 		Gtk.init (ref args);

Loading…
Cancel
Save