Browse Source

configuration window is now decent

Enrico Tassi 11 years ago
parent
commit
755ec31f50
2 changed files with 324 additions and 58 deletions
  1. 241
    55
      smd-applet.ui
  2. 83
    3
      smd-applet.vala

+ 241
- 55
smd-applet.ui View File

@@ -42,71 +42,140 @@
42 42
   </object>
43 43
   <object class="GtkWindow" id="wPrefs">
44 44
     <property name="window_position">center</property>
45
+    <property name="icon_name">mail-send-receive</property>
45 46
     <child>
46
-      <object class="GtkHBox" id="hbox1">
47
+      <object class="GtkVBox" id="vbox1">
47 48
         <property name="visible">True</property>
49
+        <property name="orientation">vertical</property>
48 50
         <child>
49
-          <object class="GtkVBox" id="vbox1">
51
+          <object class="GtkVBox" id="vbox2">
50 52
             <property name="visible">True</property>
51 53
             <property name="orientation">vertical</property>
52 54
             <child>
53
-              <object class="GtkVBox" id="vbox2">
55
+              <object class="GtkLabel" id="lErrLoop">
56
+                <property name="xalign">0</property>
57
+                <property name="label" translatable="yes">&lt;b&gt;error:&lt;/b&gt; smd-applet needs smd-loop to be properly configured</property>
58
+                <property name="use_markup">True</property>
59
+              </object>
60
+              <packing>
61
+                <property name="position">0</property>
62
+              </packing>
63
+            </child>
64
+            <child>
65
+              <object class="GtkLabel" id="lErrPushPull">
66
+                <property name="label" translatable="yes">&lt;b&gt;error:&lt;/b&gt; smd-applet needs smd-push/pull  to be properly configured</property>
67
+                <property name="use_markup">True</property>
68
+              </object>
69
+              <packing>
70
+                <property name="position">1</property>
71
+              </packing>
72
+            </child>
73
+          </object>
74
+          <packing>
75
+            <property name="position">0</property>
76
+          </packing>
77
+        </child>
78
+        <child>
79
+          <object class="GtkNotebook" id="notebook1">
80
+            <property name="visible">True</property>
81
+            <property name="can_focus">True</property>
82
+            <child>
83
+              <object class="GtkFrame" id="frame1">
54 84
                 <property name="visible">True</property>
55
-                <property name="orientation">vertical</property>
56
-                <property name="spacing">2</property>
85
+                <property name="label_xalign">0</property>
86
+                <property name="shadow_type">none</property>
57 87
                 <child>
58
-                  <object class="GtkFrame" id="frame1">
88
+                  <object class="GtkAlignment" id="alignment1">
59 89
                     <property name="visible">True</property>
60
-                    <property name="label_xalign">0</property>
61
-                    <property name="shadow_type">none</property>
90
+                    <property name="top_padding">12</property>
91
+                    <property name="bottom_padding">12</property>
92
+                    <property name="left_padding">12</property>
93
+                    <property name="right_padding">12</property>
62 94
                     <child>
63
-                      <object class="GtkAlignment" id="alignment1">
95
+                      <object class="GtkVBox" id="vbox3">
64 96
                         <property name="visible">True</property>
65
-                        <property name="top_padding">12</property>
66
-                        <property name="bottom_padding">12</property>
67
-                        <property name="left_padding">12</property>
68
-                        <property name="right_padding">12</property>
97
+                        <property name="orientation">vertical</property>
69 98
                         <child>
70
-                          <object class="GtkVBox" id="vbox3">
99
+                          <object class="GtkCheckButton" id="cbIcon">
100
+                            <property name="label" translatable="yes">Display icon only on errors</property>
71 101
                             <property name="visible">True</property>
72
-                            <property name="orientation">vertical</property>
73
-                            <child>
74
-                              <object class="GtkCheckButton" id="cbIcon">
75
-                                <property name="label" translatable="yes">Display icon only on errors</property>
76
-                                <property name="visible">True</property>
77
-                                <property name="can_focus">True</property>
78
-                                <property name="receives_default">False</property>
79
-                                <property name="draw_indicator">True</property>
80
-                              </object>
81
-                              <packing>
82
-                                <property name="position">0</property>
83
-                              </packing>
84
-                            </child>
85
-                            <child>
86
-                              <object class="GtkCheckButton" id="cbNotify">
87
-                                <property name="label" translatable="yes">Notify when new mail is pulled</property>
88
-                                <property name="visible">True</property>
89
-                                <property name="can_focus">True</property>
90
-                                <property name="receives_default">False</property>
91
-                                <property name="draw_indicator">True</property>
92
-                              </object>
93
-                              <packing>
94
-                                <property name="position">1</property>
95
-                              </packing>
96
-                            </child>
97
-                            <child>
98
-                              <placeholder/>
99
-                            </child>
102
+                            <property name="can_focus">True</property>
103
+                            <property name="receives_default">False</property>
104
+                            <property name="draw_indicator">True</property>
100 105
                           </object>
106
+                          <packing>
107
+                            <property name="position">0</property>
108
+                          </packing>
109
+                        </child>
110
+                        <child>
111
+                          <object class="GtkCheckButton" id="cbNotify">
112
+                            <property name="label" translatable="yes">Notify when new mail is pulled</property>
113
+                            <property name="visible">True</property>
114
+                            <property name="can_focus">True</property>
115
+                            <property name="receives_default">False</property>
116
+                            <property name="draw_indicator">True</property>
117
+                          </object>
118
+                          <packing>
119
+                            <property name="position">1</property>
120
+                          </packing>
101 121
                         </child>
102 122
                       </object>
103 123
                     </child>
104
-                    <child type="label">
105
-                      <object class="GtkLabel" id="label1">
124
+                  </object>
125
+                </child>
126
+                <child type="label">
127
+                  <object class="GtkLabel" id="label4">
128
+                    <property name="visible">True</property>
129
+                    <property name="label" translatable="yes">&lt;b&gt;Preferences&lt;/b&gt;</property>
130
+                    <property name="use_markup">True</property>
131
+                  </object>
132
+                </child>
133
+              </object>
134
+            </child>
135
+            <child type="tab">
136
+              <object class="GtkLabel" id="label1">
137
+                <property name="visible">True</property>
138
+                <property name="label" translatable="yes">smd-applet</property>
139
+              </object>
140
+              <packing>
141
+                <property name="tab_fill">False</property>
142
+              </packing>
143
+            </child>
144
+            <child>
145
+              <object class="GtkVBox" id="vbox6">
146
+                <property name="visible">True</property>
147
+                <property name="orientation">vertical</property>
148
+                <property name="spacing">2</property>
149
+                <child>
150
+                  <object class="GtkHBox" id="hbox2">
151
+                    <property name="visible">True</property>
152
+                    <child>
153
+                      <object class="GtkImage" id="image2">
154
+                        <property name="visible">True</property>
155
+                        <property name="stock">gtk-help</property>
156
+                        <property name="icon-size">6</property>
157
+                      </object>
158
+                      <packing>
159
+                        <property name="expand">False</property>
160
+                        <property name="fill">False</property>
161
+                        <property name="position">0</property>
162
+                      </packing>
163
+                    </child>
164
+                    <child>
165
+                      <object class="GtkLabel" id="label6">
106 166
                         <property name="visible">True</property>
107
-                        <property name="label" translatable="yes">&lt;b&gt;Preferences&lt;/b&gt;</property>
108
-                        <property name="use_markup">True</property>
167
+                        <property name="xalign">0</property>
168
+                        <property name="label" translatable="yes">smd-loop controls the frequency of synchronizations, and is run by smd-applet.
169
+
170
+The configuration file is like oriented. 
171
+Each line is composed of three space separated fields:
172
+pull-frequency,  push-frequency  and  endpoint-name.</property>
173
+                        <property name="wrap">True</property>
109 174
                       </object>
175
+                      <packing>
176
+                        <property name="expand">False</property>
177
+                        <property name="position">1</property>
178
+                      </packing>
110 179
                     </child>
111 180
                   </object>
112 181
                   <packing>
@@ -114,40 +183,156 @@
114 183
                   </packing>
115 184
                 </child>
116 185
                 <child>
117
-                  <object class="GtkHButtonBox" id="hbuttonbox1">
186
+                  <object class="GtkHButtonBox" id="hbuttonbox2">
118 187
                     <property name="visible">True</property>
119
-                    <property name="layout_style">end</property>
188
+                    <property name="layout_style">center</property>
120 189
                     <child>
121
-                      <object class="GtkButton" id="bClosePrefs">
122
-                        <property name="label" translatable="yes">gtk-close</property>
190
+                      <object class="GtkButton" id="bEditLoopCfg">
191
+                        <property name="label" translatable="yes">gtk-edit</property>
123 192
                         <property name="visible">True</property>
124 193
                         <property name="can_focus">True</property>
125 194
                         <property name="receives_default">True</property>
126 195
                         <property name="use_stock">True</property>
127 196
                       </object>
197
+                      <packing>
198
+                        <property name="expand">False</property>
199
+                        <property name="fill">False</property>
200
+                        <property name="padding">4</property>
201
+                        <property name="position">0</property>
202
+                      </packing>
203
+                    </child>
204
+                  </object>
205
+                  <packing>
206
+                    <property name="position">1</property>
207
+                  </packing>
208
+                </child>
209
+              </object>
210
+              <packing>
211
+                <property name="position">1</property>
212
+              </packing>
213
+            </child>
214
+            <child type="tab">
215
+              <object class="GtkLabel" id="label2">
216
+                <property name="visible">True</property>
217
+                <property name="label" translatable="yes">smd-loop</property>
218
+              </object>
219
+              <packing>
220
+                <property name="position">1</property>
221
+                <property name="tab_fill">False</property>
222
+              </packing>
223
+            </child>
224
+            <child>
225
+              <object class="GtkVBox" id="vbox4">
226
+                <property name="visible">True</property>
227
+                <property name="orientation">vertical</property>
228
+                <child>
229
+                  <object class="GtkHBox" id="hbox1">
230
+                    <property name="visible">True</property>
231
+                    <child>
232
+                      <object class="GtkImage" id="image1">
233
+                        <property name="visible">True</property>
234
+                        <property name="stock">gtk-help</property>
235
+                        <property name="icon-size">6</property>
236
+                      </object>
128 237
                       <packing>
129 238
                         <property name="expand">False</property>
130 239
                         <property name="fill">False</property>
131 240
                         <property name="position">0</property>
132 241
                       </packing>
133 242
                     </child>
243
+                    <child>
244
+                      <object class="GtkLabel" id="label5">
245
+                        <property name="visible">True</property>
246
+                        <property name="xalign">0</property>
247
+                        <property name="ypad">3</property>
248
+                        <property name="label" translatable="yes">smd-push and smd-pull are run timely by smd-loop.
249
+
250
+Each endpoint you want to sync with has to be configured properly, defining its name and the mail forlder path.
251
+This interface allows you to edit only the default endpoint.</property>
252
+                        <property name="wrap">True</property>
253
+                      </object>
254
+                      <packing>
255
+                        <property name="expand">False</property>
256
+                        <property name="position">1</property>
257
+                      </packing>
258
+                    </child>
259
+                  </object>
260
+                  <packing>
261
+                    <property name="position">0</property>
262
+                  </packing>
263
+                </child>
264
+                <child>
265
+                  <object class="GtkVBox" id="vbox5">
266
+                    <property name="visible">True</property>
267
+                    <property name="orientation">vertical</property>
268
+                    <child>
269
+                      <object class="GtkHButtonBox" id="hbuttonbox3">
270
+                        <property name="visible">True</property>
271
+                        <child>
272
+                          <object class="GtkButton" id="bEditPushPullCfg">
273
+                            <property name="label" translatable="yes">gtk-edit</property>
274
+                            <property name="visible">True</property>
275
+                            <property name="can_focus">True</property>
276
+                            <property name="receives_default">True</property>
277
+                            <property name="use_stock">True</property>
278
+                          </object>
279
+                          <packing>
280
+                            <property name="expand">False</property>
281
+                            <property name="fill">False</property>
282
+                            <property name="position">0</property>
283
+                          </packing>
284
+                        </child>
285
+                      </object>
286
+                      <packing>
287
+                        <property name="position">0</property>
288
+                      </packing>
289
+                    </child>
134 290
                   </object>
135 291
                   <packing>
136
-                    <property name="expand">False</property>
137
-                    <property name="padding">4</property>
138 292
                     <property name="position">1</property>
139 293
                   </packing>
140 294
                 </child>
141 295
               </object>
142 296
               <packing>
143
-                <property name="padding">6</property>
297
+                <property name="position">2</property>
298
+              </packing>
299
+            </child>
300
+            <child type="tab">
301
+              <object class="GtkLabel" id="label3">
302
+                <property name="visible">True</property>
303
+                <property name="label" translatable="yes">smd-push/pull</property>
304
+              </object>
305
+              <packing>
306
+                <property name="position">2</property>
307
+                <property name="tab_fill">False</property>
308
+              </packing>
309
+            </child>
310
+          </object>
311
+          <packing>
312
+            <property name="position">1</property>
313
+          </packing>
314
+        </child>
315
+        <child>
316
+          <object class="GtkHButtonBox" id="hbuttonbox1">
317
+            <property name="visible">True</property>
318
+            <property name="layout_style">end</property>
319
+            <child>
320
+              <object class="GtkButton" id="bClosePrefs">
321
+                <property name="label" translatable="yes">gtk-close</property>
322
+                <property name="visible">True</property>
323
+                <property name="can_focus">True</property>
324
+                <property name="receives_default">True</property>
325
+                <property name="use_stock">True</property>
326
+              </object>
327
+              <packing>
328
+                <property name="expand">False</property>
329
+                <property name="fill">False</property>
144 330
                 <property name="position">0</property>
145 331
               </packing>
146 332
             </child>
147 333
           </object>
148 334
           <packing>
149
-            <property name="padding">6</property>
150
-            <property name="position">0</property>
335
+            <property name="position">2</property>
151 336
           </packing>
152 337
         </child>
153 338
       </object>
@@ -172,6 +357,7 @@
172 357
   <object class="GtkWindow" id="wError">
173 358
     <property name="modal">True</property>
174 359
     <property name="window_position">center</property>
360
+    <property name="icon_name">dialog-error</property>
175 361
     <child>
176 362
       <object class="GtkVBox" id="vbox1">
177 363
         <property name="visible">True</property>

+ 83
- 3
smd-applet.vala View File

@@ -42,7 +42,10 @@ class Event {
42 42
 }
43 43
 
44 44
 static const string SMD_LOOP = "/bin/smd-loop";
45
+static const string SMD_PUSH = "/bin/smd-push";
45 46
 static const string SMD_APPLET_UI = "/share/syncmaildir-applet/smd-applet.ui";
47
+static string SMD_LOOP_CFG;
48
+static string SMD_PP_DEF_CFG;
46 49
 
47 50
 // the main class containing all the data smd-applet will use
48 51
 class smdApplet {
@@ -57,6 +60,7 @@ class smdApplet {
57 60
 	// installation path
58 61
 	public static string smd_loop_cmd = null;
59 62
 	public static string smd_applet_ui = null;
63
+	public static string smd_push_cmd = null;
60 64
 
61 65
 	// =================== the data =====================================
62 66
 
@@ -139,6 +143,36 @@ class smdApplet {
139 143
 				stderr.printf("Unable to re-start a thread\n"); 
140 144
 				Gtk.main_quit();
141 145
 			}
146
+		}; 
147
+		var bel = builder.get_object("bEditLoopCfg") as Gtk.Button;
148
+		bel.clicked += (b) => {
149
+			// if not existent, create the template first
150
+			try {
151
+				if (!is_smd_loop_configured()){
152
+			 		GLib.Process.spawn_command_line_sync(
153
+						"%s -t".printf(smd_loop_cmd));
154
+			 	}
155
+				string cmd = "gnome-open %s".printf(SMD_LOOP_CFG);
156
+				GLib.Process.spawn_command_line_async(cmd);
157
+				is_smd_loop_configured();
158
+			} catch (GLib.SpawnError e) {
159
+				stderr.printf("%s\n",e.message);
160
+			}
161
+		};
162
+		var bepp = builder.get_object("bEditPushPullCfg") as Gtk.Button;
163
+		bepp.clicked += (b) => {
164
+			// if not existent, create the template first
165
+			try {
166
+				if (!is_smd_pushpull_configured()){
167
+			 		GLib.Process.spawn_command_line_sync(
168
+						"%s -t".printf(smd_push_cmd));
169
+			 	}
170
+				string cmd = "gnome-open %s".printf(SMD_PP_DEF_CFG);
171
+				GLib.Process.spawn_command_line_async(cmd);
172
+				is_smd_pushpull_configured();
173
+			} catch (GLib.SpawnError e) {
174
+				stderr.printf("%s\n",e.message);
175
+			}
142 176
 		};
143 177
 
144 178
 		// menu popped up when the user clicks on the notification area
@@ -498,13 +532,46 @@ class smdApplet {
498 532
 		thread.join();
499 533
 	}
500 534
 
535
+	private void my_gtk_main_quit_button(Gtk.Button b) {
536
+		Gtk.main_quit();
537
+	}
538
+
539
+	private bool my_gtk_main_quit_event(Gdk.Event b) {
540
+		Gtk.main_quit();
541
+		return false;
542
+	}
543
+
501 544
 	// just displays the config win
502 545
 	public void configure() {
503 546
 		var close = builder.get_object("bClosePrefs") as Gtk.Button;
504
-		close.clicked += (b) =>  { Gtk.main_quit(); };
505
-		win.delete_event += (e) => { Gtk.main_quit(); };
547
+		close.clicked += my_gtk_main_quit_button;
548
+		win.delete_event += my_gtk_main_quit_event;
506 549
 		win.show();	
507 550
 		Gtk.main(); 
551
+		close.clicked -= my_gtk_main_quit_button;
552
+		win.delete_event -= my_gtk_main_quit_event;
553
+	}
554
+
555
+    public bool is_smd_loop_configured() {
556
+		bool rc = GLib.FileUtils.test(SMD_LOOP_CFG,GLib.FileTest.EXISTS);
557
+		Gtk.Label l = builder.get_object("lErrLoop") as Gtk.Label;
558
+		if (!rc) { l.show(); } 
559
+		else { l.hide(); }
560
+		return rc;
561
+	}
562
+
563
+    public bool is_smd_pushpull_configured() {
564
+		bool rc = GLib.FileUtils.test(SMD_PP_DEF_CFG,GLib.FileTest.EXISTS);
565
+		Gtk.Label l = builder.get_object("lErrPushPull") as Gtk.Label;
566
+		if (!rc) { l.show(); } 
567
+		else { l.hide(); }
568
+		return rc;
569
+	}
570
+
571
+	public bool is_smd_stack_configured() {
572
+		var a = is_smd_loop_configured();
573
+		var b = is_smd_pushpull_configured();
574
+		return a && b;
508 575
 	}
509 576
 
510 577
 }
@@ -524,11 +591,18 @@ static int main(string[] args){
524 591
 		smdApplet.smd_applet_ui = "./smd-applet.ui";
525 592
 		stderr.printf("smd-applet not installed, " +
526 593
 			"assuming smd-applet.ui is: %s\n", smdApplet.smd_applet_ui);
594
+		smdApplet.smd_push_cmd = "./smd-push";
595
+		stderr.printf("smd-applet not installed, " +
596
+			"assuming smd-push is: %s\n", smdApplet.smd_push_cmd);
527 597
 	} else {
528 598
 		smdApplet.smd_loop_cmd = PREFIX + SMD_LOOP;
599
+		smdApplet.smd_push_cmd = PREFIX + SMD_PUSH;
529 600
 		smdApplet.smd_applet_ui = PREFIX + SMD_APPLET_UI; 
530 601
 	}
531 602
 
603
+	SMD_LOOP_CFG = GLib.Environment.get_home_dir()+"/.smd/loop";
604
+	SMD_PP_DEF_CFG = GLib.Environment.get_home_dir()+"/.smd/config.default";
605
+
532 606
 	// we init gtk+ and notify
533 607
 	Gtk.init (ref args);
534 608
 	Notify.init("smd-applet");
@@ -564,7 +638,13 @@ static int main(string[] args){
564 638
 	// go!
565 639
 	try { 
566 640
 		var smd_applet = new smdApplet();
567
-    	if (config_only) smd_applet.configure(); else smd_applet.run();
641
+    	if (config_only) {
642
+			smd_applet.configure();
643
+		} else {
644
+			while(!smd_applet.is_smd_stack_configured())
645
+				smd_applet.configure();
646
+			smd_applet.run();
647
+		}
568 648
 	} catch (Exit e) { 
569 649
 		stderr.printf("abort: %s\n",e.message); 
570 650
 	}

Loading…
Cancel
Save