Browse Source

added --configure to run just the config win

Enrico Tassi 11 years ago
parent
commit
504896284d
2 changed files with 32 additions and 18 deletions
  1. 1
    1
      smd-applet.ui
  2. 31
    17
      smd-applet.vala

+ 1
- 1
smd-applet.ui View File

@@ -118,7 +118,7 @@
118 118
                     <property name="visible">True</property>
119 119
                     <property name="layout_style">end</property>
120 120
                     <child>
121
-                      <object class="GtkButton" id="bClose">
121
+                      <object class="GtkButton" id="bClosePrefs">
122 122
                         <property name="label" translatable="yes">gtk-close</property>
123 123
                         <property name="visible">True</property>
124 124
                         <property name="can_focus">True</property>

+ 31
- 17
smd-applet.vala View File

@@ -100,7 +100,7 @@ class smdApplet {
100 100
 		// load widgets and attach callbacks
101 101
 		win = builder.get_object("wPrefs") as Gtk.Window;
102 102
 		err_win = builder.get_object("wError") as Gtk.Window;
103
-		var close = builder.get_object("bClose") as Gtk.Button;
103
+		var close = builder.get_object("bClosePrefs") as Gtk.Button;
104 104
 		close.clicked += (b) =>  { win.hide(); };
105 105
 		var bicon = builder.get_object("cbIcon") as Gtk.CheckButton;
106 106
 		bicon.set_active( gconf.get_bool(key_icon));
@@ -122,8 +122,6 @@ class smdApplet {
122 122
 			si.set_blinking(false);
123 123
 			// XXX do something else?
124 124
 		};
125
-		win.delete_event += win.hide_on_delete;
126
-		err_win.delete_event += err_win.hide_on_delete;
127 125
 
128 126
 		// menu popped up when the user clicks on the notification area
129 127
         menu = builder.get_object ("mMain") as Gtk.Menu;
@@ -156,6 +154,7 @@ class smdApplet {
156 154
 		bool rc = true;
157 155
 		while(rc){
158 156
 			rc = run_smd_loop();
157
+			stderr.printf("restarting smd-loop\n");
159 158
 		}
160 159
 	
161 160
 		return null;
@@ -239,7 +238,7 @@ class smdApplet {
239 238
 				l_cause.set_text(i_cause.fetch(1));
240 239
 				if ( i_human.fetch(1) != "required" ){
241 240
 					stderr.printf("smd-loop giving an avoidable error: %s\n",
242
-						i_human.fetch(1));
241
+						args);
243 242
 					return true;
244 243
 				}
245 244
 				bool display_permissions = false;
@@ -348,9 +347,10 @@ class smdApplet {
348 347
 	}
349 348
 
350 349
 	public bool run_smd_loop() {
351
-		//string[] cmd = { smd_loop_cmd, "-v" };
350
+		string[] cmd = { smd_loop_cmd, "-v" };
351
+
352 352
 		//string[] cmd = {"/bin/echo","default: smd-client@localhost: TAGS: stats::new-mails(1), del-mails(3)"};
353
-		string[] cmd = {"/bin/echo","default: smd-client@foo: TAGS: error::context(testing smd-applet), probable-cause(generated on purpose), human-intervention(required), suggested-actions(display-permissions(/home/tassi) display-mail(/home/tassi/Mail/inbox/cur/1096282515.31281_2.garfield:2,S) run(echo a) run(echo b))"};
353
+		//string[] cmd = {"/bin/echo","default: smd-client@foo: TAGS: error::context(testing smd-applet), probable-cause(generated on purpose), human-intervention(required), suggested-actions(display-permissions(/home/tassi) display-mail(/home/tassi/Mail/inbox/cur/1096282515.31281_2.garfield:2,S) run(echo a) run(echo b))"};
354 354
 		int child_in;
355 355
 		int child_out;
356 356
 		int child_err;
@@ -368,7 +368,7 @@ class smdApplet {
368 368
 				while ( !stop && (s = input.gets(buff)) != null ) {
369 369
 					stop = eval_smd_loop_message(s);
370 370
 				}
371
-				return false;
371
+				return stop;
372 372
 			} else {
373 373
 				stderr.printf("Unable to execute "+smd_loop_cmd+"\n");
374 374
 				throw new Exit.ABORT("Unable to run smd-loop");
@@ -378,8 +378,6 @@ class smdApplet {
378 378
 				smd_loop_cmd+": "+e.message+"\n");
379 379
 			return false;
380 380
 		}
381
-
382
-		return true;
383 381
 	}
384 382
 
385 383
 	// process an event in the events queue by notifying the user
@@ -430,9 +428,23 @@ class smdApplet {
430 428
 			throw new Exit.ABORT("Unable to spawn a thread");
431 429
 		}
432 430
 
431
+		// windows will last for the whole execution,
432
+		// so the (x) button should just hide them
433
+		win.delete_event += win.hide_on_delete;
434
+		err_win.delete_event += err_win.hide_on_delete;
435
+
433 436
 		Gtk.main(); 
434 437
 		thread.join();
435 438
 	}
439
+
440
+	// just displays the config win
441
+	public void configure() {
442
+		var close = builder.get_object("bClosePrefs") as Gtk.Button;
443
+		close.clicked += (b) =>  { Gtk.main_quit(); };
444
+		win.delete_event += (e) => { Gtk.main_quit(); };
445
+		win.show();	
446
+		Gtk.main(); 
447
+	}
436 448
 }
437 449
 
438 450
 // =================== main =====================================
@@ -442,6 +454,8 @@ static int main(string[] args){
442 454
 
443 455
 	// handle prefix
444 456
 	if (! GLib.FileUtils.test(PREFIX + SMD_APPLET_UI,GLib.FileTest.EXISTS)) {
457
+		stderr.printf("error: file not found: %s + %s\n", 
458
+			PREFIX, SMD_APPLET_UI);
445 459
 		smdApplet.smd_loop_cmd = GLib.Environment.get_variable("HOME") + 
446 460
 			"/Projects/syncmaildir/smd-loop";
447 461
 		stderr.printf("smd-applet not installed, " +
@@ -459,24 +473,24 @@ static int main(string[] args){
459 473
 	Gtk.init (ref args);
460 474
 	Notify.init("smd-applet");
461 475
 
462
-	bool foo=false;
476
+	bool config_only=false;
463 477
 	GLib.OptionEntry[] oe = new GLib.OptionEntry[2];
464
-	oe[0].long_name = "foo";
465
-	oe[0].short_name = 'f';
478
+	oe[0].long_name = "configure";
479
+	oe[0].short_name = 'c';
466 480
 	oe[0].flags = GLib.OptionFlags.NO_ARG;
467 481
 	oe[0].arg = GLib.OptionArg.NONE;
468
-	oe[0].arg_data = &foo;
469
-	oe[0].description = "ffff";
482
+	oe[0].arg_data = &config_only;
483
+	oe[0].description = "show config window, don't really run the applet";
470 484
 	oe[0].arg_description = null;
471 485
 	oe[1].long_name = null;
472 486
 	var oc = new GLib.OptionContext(" - syncmaildir applet");
473 487
 	oc.add_main_entries(oe,null);
474
-	oc.parse(ref args);
475
-	// XXX if foo then just show the confi win
488
+	try { oc.parse(ref args); }
489
+	catch (GLib.OptionError e) { stderr.printf("%s\n",e.message); return 1; } 
476 490
 
477 491
 	// go!
478 492
 	var smd_applet = new smdApplet();
479
-	try { smd_applet.run(); }
493
+	try { if (config_only) smd_applet.configure(); else smd_applet.run(); }
480 494
 	catch (Exit e) { stderr.printf("abort: %s\n",e.message); }
481 495
 	
482 496
 	return 0;

Loading…
Cancel
Save