Browse Source

XDG compliant autorun for smd-applet

Enrico Tassi 9 years ago
parent
commit
a5cf1e2e2f
4 changed files with 935 additions and 759 deletions
  1. 3
    0
      ChangeLog
  2. 5
    4
      Makefile
  3. 889
    747
      smd-applet.ui
  4. 38
    8
      smd-applet.vala

+ 3
- 0
ChangeLog View File

@@ -20,6 +20,9 @@
20 20
 	  - new tool to ease the migration from offlineimap. When the mailboxes
21 21
 	    have roughly the same content but emails are named differently
22 22
 	    this tool can generate a shell script that renames local mails
23
+	* smd-applet:
24
+	  - XDG compliant autostart, with a button in the options window
25
+	  - target glib 2.32 and gtk 3.0 for the .ui file
23 26
 
24 27
 03/03/2012 - minor feature improvement - version 1.2.3
25 28
 	* smd-pull, smd-push:

+ 5
- 4
Makefile View File

@@ -24,8 +24,8 @@ BENCH_SUITES=benchmarks
24 24
 PKG_GTK=gtk+-3.0 
25 25
 SMD_APPLET_C=smd-applet.c 
26 26
 PKGS_VALA=glib-2.0 $(PKG_GTK) libnotify gconf-2.0 gee-1.0 gio-2.0
27
-MIN_GLIB_VERSION=2.19.1
28
-PKGCONFIG_CHECK_GLIB_VERSION=--atleast-version=$(MIN_GLIB_VERSION) glib-2.0
27
+TARGET_GLIB=2.32
28
+PKGCONFIG_CHECK_GLIB_VERSION=--atleast-version=$(TARGET_GLIB) glib-2.0
29 29
 PKGCONFIG_GLIB_VERSION=--modversion glib-2.0
30 30
 VALAC=valac-0.16
31 31
 H=@
@@ -66,6 +66,7 @@ smd-applet.c: smd-applet.vala smd-config.vapi
66 66
 	$H if which $(VALAC) >/dev/null; then \
67 67
 		echo "VALAC $^"; \
68 68
 		$(VALAC) -C $^ --thread --vapidir=./ \
69
+			--target-glib=$(TARGET_GLIB) \
69 70
 			--pkg posix $(patsubst %,--pkg %,$(PKGS_VALA)); \
70 71
 	elif [ -e smd-applet.c ]; then \
71 72
 		echo "** No $(VALAC), reusing precompiled .c files"; \
@@ -93,7 +94,7 @@ check-build: check-w-gcc check-w-$(VALAC)
93 94
 	$H pkg-config $(PKGCONFIG_CHECK_GLIB_VERSION) || \
94 95
 		(echo glib version too old: \
95 96
 			`pkg-config $(PKGCONFIG_GLIB_VERSION)`; \
96
-		 echo required version: $(MIN_GLIB_VERSION); \
97
+		 echo required version: $(TARGET_GLIB); \
97 98
 		 false)
98 99
 
99 100
 check-run: check-w-$(LUA) check-w-bash 
@@ -179,9 +180,9 @@ install-bin: $(BINARIES)
179 180
 
180 181
 install-misc: $(MANPAGES1) $(MANPAGES5)
181 182
 	mkdir -p $(DESTDIR)/etc/xdg/autostart
182
-	cp smd-applet.desktop $(DESTDIR)/etc/xdg/autostart
183 183
 	$(call mkdir-p,share/applications)
184 184
 	$(call install,smd-applet-configure.desktop,share/applications)
185
+	$(call install,smd-applet.desktop,share/applications)
185 186
 	$(call install,smd-applet.ui,share/$(PROJECTNAME)-applet)
186 187
 	$(call mkdir-p,share/man/man1)
187 188
 	$(call mkdir-p,share/man/man5)

+ 889
- 747
smd-applet.ui
File diff suppressed because it is too large
View File


+ 38
- 8
smd-applet.vala View File

@@ -105,9 +105,12 @@ class Event {
105 105
 static const string SMD_LOOP = "/bin/smd-loop";
106 106
 static const string SMD_PUSH = "/bin/smd-push";
107 107
 static const string SMD_APPLET_UI = "/share/syncmaildir-applet/smd-applet.ui";
108
+static const string SMD_APPLET_DESKTOP = "/share/applications/smd-applet.desktop";
109
+static const string GNOME_AUTOSTART_DISABLED ="X-GNOME-Autostart-enabled=false";
108 110
 static string SMD_LOGS_DIR;
109 111
 static string SMD_LOOP_CFG;
110 112
 static string SMD_PP_DEF_CFG;
113
+static string XDG_AUTORUN_FILE;
111 114
 
112 115
 // the main class containing all the data smd-applet will use
113 116
 class smdApplet {
@@ -123,6 +126,7 @@ class smdApplet {
123 126
 	public static string smd_loop_cmd = null;
124 127
 	public static string smd_applet_ui = null;
125 128
 	public static string smd_push_cmd = null;
129
+	public static string smd_applet_desktop = null;
126 130
 
127 131
 	// =================== the data =====================================
128 132
 
@@ -147,13 +151,13 @@ class smdApplet {
147 151
 	GConf.Client gconf = null;
148 152
 
149 153
 	// the thread to manage the child smd-loop instance
150
-	weak GLib.Thread<void *> thread = null;
154
+	GLib.Thread<void *> thread = null;
151 155
 	bool thread_die = false;
152 156
 	GLib.Pid pid; // smd-loop pid, initially set to 0
153 157
 	
154 158
 	// communication structure between the child process (managed by a thread
155 159
 	// and the notifier timeout handler).
156
-	GLib.Mutex events_lock = null;
160
+	Mutex events_lock = Mutex();
157 161
 	Gee.ArrayList<Event> events = null; 
158 162
 
159 163
 	// if the program is stuck
@@ -185,7 +189,6 @@ class smdApplet {
185 189
 	
186 190
 		// events queue and mutex
187 191
 		events = new Gee.ArrayList<Event>();
188
-		events_lock = new GLib.Mutex();
189 192
 
190 193
 		// connect to gconf
191 194
 		gconf = GConf.Client.get_default();
@@ -262,6 +265,25 @@ class smdApplet {
262 265
 			try { gconf.set_bool(key_newmail,b.active); }
263 266
 			catch (GLib.Error e) { stderr.printf("%s\n",e.message); }
264 267
 		});
268
+		var bautostart = builder.get_object("cbAutostart") as Gtk.CheckButton;
269
+		try { string content;
270
+		  if (GLib.FileUtils.get_contents(XDG_AUTORUN_FILE,out content)){
271
+			if (GLib.Regex.match_simple(GNOME_AUTOSTART_DISABLED,content))
272
+				bautostart.set_active(false);
273
+			else bautostart.set_active(true);
274
+		  } else bautostart.set_active(false);
275
+		} catch (FileError e) { stderr.printf("%s\n",e.message); }
276
+		bautostart.toggled.connect((b) => {
277
+			if (b.active) {
278
+				string content;
279
+				try {
280
+					GLib.FileUtils.get_contents(smd_applet_desktop,out content);
281
+					GLib.FileUtils.set_contents(XDG_AUTORUN_FILE,content);
282
+				} catch (FileError e) { stderr.printf("%s\n",e.message); }
283
+			} else {
284
+				GLib.FileUtils.remove(XDG_AUTORUN_FILE);
285
+			}
286
+		});
265 287
 		var bc = builder.get_object("bClose") as Gtk.Button;
266 288
 		bc.clicked.connect(close_err_action);
267 289
 
@@ -376,11 +398,7 @@ class smdApplet {
376 398
 			miPause.set_active(true);
377 399
 		} else {
378 400
 			// the thread fills the event queue
379
-			try { thread = GLib.Thread.create<void *>(smdThread,true); }
380
-			catch (GLib.ThreadError e) {
381
-				stderr.printf("Unable to start a thread\n");
382
-				Gtk.main_quit();
383
-			}
401
+			thread = new GLib.Thread<void *>(null, smdThread);
384 402
 		}
385 403
 	}
386 404
 
@@ -965,16 +983,28 @@ static int main(string[] args){
965 983
 		smdApplet.smd_push_cmd = "./smd-push";
966 984
 		stderr.printf("smd-applet not installed, " +
967 985
 			"assuming smd-push is: %s\n", smdApplet.smd_push_cmd);
986
+		smdApplet.smd_applet_desktop = "./smd-applet.desktop";
987
+		stderr.printf("smd-applet not installed, " +
988
+			"assuming smd-applet.desktop is: %s\n",
989
+			smdApplet.smd_applet_desktop);
968 990
 	} else {
969 991
 		smdApplet.smd_loop_cmd = PREFIX + SMD_LOOP;
970 992
 		smdApplet.smd_push_cmd = PREFIX + SMD_PUSH;
971 993
 		smdApplet.smd_applet_ui = PREFIX + SMD_APPLET_UI; 
994
+		smdApplet.smd_applet_desktop = PREFIX + SMD_APPLET_DESKTOP; 
972 995
 	}
973 996
 
974 997
 	var homedir = GLib.Environment.get_home_dir();
975 998
 	SMD_LOGS_DIR = homedir+"/.smd/log/";
976 999
 	SMD_LOOP_CFG = homedir+"/.smd/loop";
977 1000
 	SMD_PP_DEF_CFG = homedir+"/.smd/config.default";
1001
+	var conf_home = GLib.Environment.get_variable("XDG_CONFIG_HOME");
1002
+	if (conf_home != null)
1003
+		XDG_AUTORUN_FILE = conf_home+"/autostart/smd-applet.desktop";
1004
+	else 
1005
+		XDG_AUTORUN_FILE = homedir + "/.config/autostart/smd-applet.desktop";
1006
+	GLib.DirUtils.create_with_parents(
1007
+		GLib.Path.get_dirname(XDG_AUTORUN_FILE),0700);
978 1008
 
979 1009
 	// we init gtk+ and notify
980 1010
 	Gtk.init (ref args);

Loading…
Cancel
Save