Browse Source

added show log button

Enrico Tassi 11 years ago
parent
commit
006379b5a1
3 changed files with 156 additions and 1 deletions
  1. 0
    1
      TODO
  2. 80
    0
      smd-applet.ui
  3. 76
    0
      smd-applet.vala

+ 0
- 1
TODO View File

@@ -1,2 +1 @@
1 1
 - if an avoidable error, but not a network one, happend, show something
2
-- allow to show log in the applet

+ 80
- 0
smd-applet.ui View File

@@ -14,6 +14,14 @@
14 14
         <property name="always_show_image">True</property>
15 15
       </object>
16 16
     </child>
17
+    <child>
18
+      <object class="GtkImageMenuItem" id="miLog">
19
+        <property name="label" translatable="yes">Logs</property>
20
+        <property name="visible">True</property>
21
+        <property name="image">image4</property>
22
+        <property name="use_stock">False</property>
23
+      </object>
24
+    </child>
17 25
     <child>
18 26
       <object class="GtkImageMenuItem" id="miAbout">
19 27
         <property name="label">gtk-about</property>
@@ -1380,4 +1388,76 @@ Public License instead of this License.  But first, please read
1380 1388
       </object>
1381 1389
     </child>
1382 1390
   </object>
1391
+  <object class="GtkWindow" id="wLog">
1392
+    <property name="window_position">center</property>
1393
+    <property name="icon_name">emblem-documents</property>
1394
+    <child>
1395
+      <object class="GtkVBox" id="vbLog">
1396
+        <property name="visible">True</property>
1397
+        <property name="border_width">4</property>
1398
+        <property name="orientation">vertical</property>
1399
+        <property name="spacing">2</property>
1400
+        <child>
1401
+          <placeholder/>
1402
+        </child>
1403
+        <child>
1404
+          <object class="GtkScrolledWindow" id="scrolledwindow2">
1405
+            <property name="visible">True</property>
1406
+            <property name="can_focus">True</property>
1407
+            <property name="hscrollbar_policy">automatic</property>
1408
+            <property name="vscrollbar_policy">automatic</property>
1409
+            <child>
1410
+              <object class="GtkTextView" id="tvLog">
1411
+                <property name="height_request">200</property>
1412
+                <property name="width_request">500</property>
1413
+                <property name="visible">True</property>
1414
+                <property name="can_focus">True</property>
1415
+                <property name="editable">False</property>
1416
+              </object>
1417
+            </child>
1418
+          </object>
1419
+          <packing>
1420
+            <property name="position">1</property>
1421
+          </packing>
1422
+        </child>
1423
+        <child>
1424
+          <object class="GtkHSeparator" id="hseparator1">
1425
+            <property name="visible">True</property>
1426
+          </object>
1427
+          <packing>
1428
+            <property name="expand">False</property>
1429
+            <property name="position">2</property>
1430
+          </packing>
1431
+        </child>
1432
+        <child>
1433
+          <object class="GtkHButtonBox" id="hbuttonbox5">
1434
+            <property name="visible">True</property>
1435
+            <property name="layout_style">end</property>
1436
+            <child>
1437
+              <object class="GtkButton" id="bLogClose">
1438
+                <property name="label">gtk-close</property>
1439
+                <property name="visible">True</property>
1440
+                <property name="can_focus">True</property>
1441
+                <property name="receives_default">True</property>
1442
+                <property name="use_stock">True</property>
1443
+              </object>
1444
+              <packing>
1445
+                <property name="expand">False</property>
1446
+                <property name="fill">False</property>
1447
+                <property name="position">0</property>
1448
+              </packing>
1449
+            </child>
1450
+          </object>
1451
+          <packing>
1452
+            <property name="expand">False</property>
1453
+            <property name="position">3</property>
1454
+          </packing>
1455
+        </child>
1456
+      </object>
1457
+    </child>
1458
+  </object>
1459
+  <object class="GtkImage" id="image4">
1460
+    <property name="visible">True</property>
1461
+    <property name="icon_name">emblem-documents</property>
1462
+  </object>
1383 1463
 </interface>

+ 76
- 0
smd-applet.vala View File

@@ -75,6 +75,7 @@ class Event {
75 75
 static const string SMD_LOOP = "/bin/smd-loop";
76 76
 static const string SMD_PUSH = "/bin/smd-push";
77 77
 static const string SMD_APPLET_UI = "/share/syncmaildir-applet/smd-applet.ui";
78
+static string SMD_LOGS_DIR;
78 79
 static string SMD_LOOP_CFG;
79 80
 static string SMD_PP_DEF_CFG;
80 81
 
@@ -103,8 +104,13 @@ class smdApplet {
103 104
 	Gtk.StatusIcon si = null;
104 105
 	Gtk.Window win = null;
105 106
 	Gtk.Window err_win = null;
107
+	Gtk.Window log_win = null;
106 108
 	Gtk.AboutDialog about_win = null;
107 109
 
110
+	// Stuff for logs display
111
+	Gtk.ComboBox cblogs = null;
112
+	Gee.ArrayList<string> lognames = null;
113
+
108 114
 	// the gconf client handler
109 115
 	GConf.Client gconf = null;
110 116
 
@@ -147,6 +153,31 @@ class smdApplet {
147 153
 		win = builder.get_object("wPrefs") as Gtk.Window;
148 154
 		err_win = builder.get_object("wError") as Gtk.Window;
149 155
 		about_win = builder.get_object("wAbout") as Gtk.AboutDialog;
156
+		log_win = builder.get_object("wLog") as Gtk.Window;
157
+		var logs_vb = builder.get_object("vbLog") as Gtk.VBox;
158
+		cblogs = new Gtk.ComboBox.text();
159
+		lognames = new Gee.ArrayList<string>();
160
+		logs_vb.pack_start(cblogs,false,true,0);
161
+		logs_vb.reorder_child(cblogs,0);
162
+		cblogs.show();
163
+		cblogs.changed += (cb) => {
164
+			int selected = cblogs.get_active();
165
+			if (selected >= 0) {
166
+				string file = lognames.get(selected);
167
+				string content;
168
+				if (GLib.FileUtils.get_contents(SMD_LOGS_DIR+file,out content)){
169
+					var tv = builder.get_object("tvLog") as Gtk.TextView;
170
+					var b = tv.get_buffer();
171
+					b.set_text(content,-1);
172
+				} else {
173
+					stderr.printf("Unable to read %s\n", SMD_LOGS_DIR + file);
174
+				}
175
+			}
176
+		};
177
+
178
+		var close_log = builder.get_object("bLogClose") as Gtk.Button;
179
+		close_log.clicked += close_logs_action;
180
+		log_win.delete_event += close_logs_event;
150 181
 
151 182
 		var close = builder.get_object("bClosePrefs") as Gtk.Button;
152 183
 		close.clicked += close_prefs_action;
@@ -215,6 +246,11 @@ class smdApplet {
215 246
 			SMDConf.VERSION);
216 247
 		var prefs = builder.get_object ("miPrefs") as Gtk.MenuItem;
217 248
 		prefs.activate += (b) => {  win.show(); };
249
+		var logs = builder.get_object ("miLog") as Gtk.MenuItem;
250
+		logs.activate += (b) => { 
251
+			update_loglist();
252
+			log_win.show(); 
253
+		};
218 254
 
219 255
 		si = new Gtk.StatusIcon.from_icon_name("mail-send-receive");
220 256
 		si.set_tooltip_text("smd-applet is running");
@@ -626,6 +662,16 @@ class smdApplet {
626 662
 		}
627 663
 	}
628 664
 
665
+	// close logs win
666
+	private void close_logs(){ log_win.hide(); }
667
+
668
+	// these are just wrappers for close_logs
669
+	private void close_logs_action(Gtk.Button b){ close_logs(); }
670
+	private bool close_logs_event(Gdk.Event e){
671
+		close_logs();
672
+		return true;
673
+	}
674
+
629 675
 	// these are names for gtk_main_quit(), they are needed
630 676
 	// in order to remove signal handlers
631 677
 	private void my_gtk_main_quit_button(Gtk.Button b) { Gtk.main_quit(); }
@@ -658,6 +704,35 @@ class smdApplet {
658 704
 		return a && b;
659 705
 	}
660 706
 
707
+	// ======================== log window ================================
708
+	private void update_loglist(){
709
+			
710
+		var tv = builder.get_object("tvLog") as Gtk.TextView;
711
+		var b = tv.get_buffer();
712
+
713
+		try {
714
+			Dir d = GLib.Dir.open(SMD_LOGS_DIR);
715
+			string file;
716
+
717
+			((Gtk.ListStore)cblogs.get_model()).clear();
718
+			lognames.clear();
719
+
720
+			while ( (file = d.read_name()) != null ){
721
+				lognames.add(file);
722
+				cblogs.append_text(file);
723
+			}
724
+	
725
+			if (lognames.size == 0) {
726
+				b.set_text("No logs in %s".printf(SMD_LOGS_DIR),-1);
727
+			} else {
728
+				cblogs.set_title("Choose log file");
729
+				cblogs.set_active(0);
730
+			}
731
+		} catch (GLib.FileError e) {
732
+			b.set_text("Unable to list directory %s".printf(SMD_LOGS_DIR),-1);
733
+		}
734
+	}
735
+
661 736
 	// ====================== public methods ==============================
662 737
 
663 738
 	// starts the thread and the timeout handler
@@ -748,6 +823,7 @@ static int main(string[] args){
748 823
 		smdApplet.smd_applet_ui = PREFIX + SMD_APPLET_UI; 
749 824
 	}
750 825
 
826
+	SMD_LOGS_DIR = GLib.Environment.get_home_dir()+"/.smd/log/";
751 827
 	SMD_LOOP_CFG = GLib.Environment.get_home_dir()+"/.smd/loop";
752 828
 	SMD_PP_DEF_CFG = GLib.Environment.get_home_dir()+"/.smd/config.default";
753 829
 

Loading…
Cancel
Save