Browse Source

first skeleton of applet with notification baloons

Enrico Tassi 12 years ago
parent
commit
b6de2dbba9
2 changed files with 71 additions and 7 deletions
  1. 27
    0
      smd-applet.ui
  2. 44
    7
      smd-applet.vala

+ 27
- 0
smd-applet.ui View File

@@ -0,0 +1,27 @@
1
+<?xml version="1.0"?>
2
+<interface>
3
+  <requires lib="gtk+" version="2.16"/>
4
+  <!-- interface-naming-policy project-wide -->
5
+  <object class="GtkMenu" id="mMain">
6
+    <property name="visible">True</property>
7
+    <child>
8
+      <object class="GtkImageMenuItem" id="miAbout">
9
+        <property name="label">gtk-about</property>
10
+        <property name="visible">True</property>
11
+        <property name="tooltip_text" translatable="yes">About smd-applet</property>
12
+        <property name="use_underline">True</property>
13
+        <property name="use_stock">True</property>
14
+        <property name="always_show_image">True</property>
15
+      </object>
16
+    </child>
17
+    <child>
18
+      <object class="GtkImageMenuItem" id="miQuit">
19
+        <property name="label">gtk-quit</property>
20
+        <property name="visible">True</property>
21
+        <property name="use_underline">True</property>
22
+        <property name="use_stock">True</property>
23
+        <property name="always_show_image">True</property>
24
+      </object>
25
+    </child>
26
+  </object>
27
+</interface>

+ 44
- 7
smd-applet.vala View File

@@ -1,12 +1,49 @@
1 1
 using Gtk;
2
+using Notify;
2 3
 
3
-static int main(string[] args){
4
-	Gtk.init (ref args);
5
-	var si = new StatusIcon.from_stock(Gtk.STOCK_NETWORK);
6
-	si.set_visible(true);
7
-	si.activate += (s) => { Gtk.main_quit(); };
4
+class smdApplet {
8 5
 
9
-	Gtk.main();
6
+	Gtk.Menu menu = null;
7
+	Gtk.StatusIcon si = null;
8
+
9
+	smdApplet(Gtk.Builder builder) {
10
+        menu = builder.get_object ("mMain") as Menu;
11
+		si = new StatusIcon.from_stock(Gtk.STOCK_NETWORK);
12
+
13
+		var quit = builder.get_object ("miQuit") as MenuItem;
14
+		quit.activate += (b) => { Gtk.main_quit(); };
15
+		var about = builder.get_object ("miAbout") as MenuItem;
16
+		about.activate += (b) => { Gtk.main_quit(); };
17
+
18
+		si.activate += (s) => { 
19
+			menu.popup(null,null,si.position_menu,0,
20
+				Gtk.get_current_event_time());
21
+		};
10 22
 	
11
-	return 0;
23
+		si.set_visible(true);
24
+
25
+		var not = new Notify.Notification("foo","bar","gtk-about",null);
26
+		not.attach_to_status_icon(si);
27
+		not.show();
28
+	}
29
+
30
+	void run() { Gtk.main(); }
31
+
32
+	static int main(string[] args){
33
+		Gtk.init (ref args);
34
+		Notify.init("smd-applet");
35
+	
36
+		var builder = new Builder ();
37
+		try { builder.add_from_file ("smd-applet.ui"); } 
38
+		catch (GLib.Error e) { stderr.printf("%s\n",e.message); return 1; }
39
+	
40
+		var smd_applet = new smdApplet(builder);
41
+	
42
+		smd_applet.run();
43
+		
44
+		return 0;
45
+	}
46
+
12 47
 }
48
+
49
+// vim:set ts=4:

Loading…
Cancel
Save