[Xfce4-commits] <xfce4-notes-plugin:master> Add desktop file and autostart code for standalone app

Mike Massonnet noreply at xfce.org
Tue Dec 1 23:04:02 CET 2009


Updating branch refs/heads/master
         to a48528137201c54eb1653e1ea835973653bca564 (commit)
       from 65ef5662c844a5b01b7c9b3ca438d88abe1bd0e1 (commit)

commit a48528137201c54eb1653e1ea835973653bca564
Author: Mike Massonnet <mmassonnet at gmail.com>
Date:   Tue Dec 1 22:05:01 2009 +0100

    Add desktop file and autostart code for standalone app

 ChangeLog                                     |    4 +
 Makefile.am                                   |    5 +
 panel-plugin/Makefile.am                      |   26 ++++--
 panel-plugin/main-status-icon.vala            |    5 +-
 panel-plugin/xfce-autostart.c                 |  126 +++++++++++++++++++++++++
 panel-plugin/{color.h => xfce-autostart.h}    |   27 ++----
 panel-plugin/xfce-autostart.vapi              |    5 +
 panel-plugin/xfce4-notes-autostart.desktop.in |   10 ++
 xfce4-notes.desktop.in                        |   12 +++
 9 files changed, 193 insertions(+), 27 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6661699..6fc2d0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-12-01  Mike Massonnet <mmassonnet at xfce.org>
 
+Add desktop file and autostart code for standalone app
+
+2009-12-01  Mike Massonnet <mmassonnet at xfce.org>
+
 Do as for Clipman, let the plugin be a standalone app
 	* panel-plugin/Makefile.am:
 	  - Update Makefile to build both plugin and binary C.
diff --git a/Makefile.am b/Makefile.am
index 9dd8263..1cf03e2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,6 +8,11 @@ SUBDIRS =								\
 distclean-local:
 	rm -rf *.cache *~
 
+desktopdir = $(datadir)/applications
+desktop_in_files = xfce4-notes.desktop.in
+desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
+ at INTLTOOL_DESKTOP_RULE@
+
 EXTRA_DIST =								\
 	AUTHORS								\
 	ChangeLog							\
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 0a3057f..44fb002 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -52,7 +52,8 @@ xfce4_notes_settings_LDADD =						\
 notes_VAPISOURCES =							\
 	config.vapi							\
 	color.vapi							\
-	popup.vapi
+	popup.vapi							\
+	xfce-autostart.vapi
 
 notes_VALASOURCES =							\
 	hypertextview.vala						\
@@ -73,17 +74,17 @@ notes_status_icon_VALABUILTSOURCES = $(notes_status_icon_VALASOURCES:.vala=.c)
 if MAINTAINER_MODE
 if HAVE_LIBXFCE4PANEL47
 DEFINES=-D HAVE_LIBXFCE4PANEL47
-PACKAGES=--pkg=libxfcegui4-1.0 --pkg=gtk+-2.0
+PACKAGES=--pkg=config --pkg=color --pkg=popup --pkg=libxfcegui4-1.0 --pkg=gtk+-2.0
 else
-PACKAGES=--pkg=gtk+-2.0
+PACKAGES=--pkg=config --pkg=color --pkg=popup --pkg=gtk+-2.0
 endif
 BUILT_SOURCES = vala.stamp
 vala.stamp: $(notes_VALASOURCES) $(notes_panel_plugin_VALASOURCES) $(notes_status_icon_VALASOURCES)
-	$(VALAC) $(DEFINES) --vapidir=$(srcdir) --pkg=config --pkg=color --pkg=popup	\
-		 --pkg=libxfconf-0 $(PACKAGES) --pkg=libxfce4panel-1.0			\
+	$(VALAC) $(DEFINES) --vapidir=$(srcdir) $(PACKAGES)				\
+		 --pkg=libxfconf-0 --pkg=libxfce4panel-1.0				\
 		 $(notes_VALASOURCES) $(notes_panel_plugin_VALASOURCES) -C
-	$(VALAC) $(DEFINES) --vapidir=$(srcdir) --pkg=config --pkg=color --pkg=popup	\
-		 --pkg=libxfconf-0 --pkg=libxfce4util-1.0 $(PACKAGES)						\
+	$(VALAC) $(DEFINES) --vapidir=$(srcdir) $(PACKAGES)				\
+		 --pkg=xfce-autostart --pkg=libxfconf-0 --pkg=libxfce4util-1.0		\
 		 $(notes_VALASOURCES) $(notes_status_icon_VALASOURCES) -C
 	touch $@
 endif
@@ -159,6 +160,8 @@ xfce4_notes_SOURCES =							\
 	color.h								\
 	popup.c								\
 	popup.h								\
+	xfce-autostart.c						\
+	xfce-autostart.h						\
 	$(notes_VALABUILTSOURCES)					\
 	$(notes_status_icon_VALABUILTSOURCES)
 
@@ -198,6 +201,15 @@ endif
 		$< > $@
 
 #
+# Autostart file
+#
+
+autostartdir = $(sysconfdir)/xdg/autostart
+autostart_in_files = xfce4-notes-autostart.desktop.in
+autostart_DATA = $(autostart_in_files:.desktop.in=.desktop)
+ at INTLTOOL_DESKTOP_RULE@
+
+#
 # Extra
 #
 
diff --git a/panel-plugin/main-status-icon.vala b/panel-plugin/main-status-icon.vala
index 66dd058..fd84021 100644
--- a/panel-plugin/main-status-icon.vala
+++ b/panel-plugin/main-status-icon.vala
@@ -116,7 +116,7 @@ public class Notes : GLib.Object {
 
 		mi = new Gtk.ImageMenuItem.from_stock (Gtk.STOCK_REMOVE, null);
 		mi.activate += () => {
-			// Set autostart file hidden
+			Xfce.Autostart. at set ("xfce4-notes-autostart", "xfce4-notes", true);
 			Gtk.main_quit ();
 		};
 		menu.append (mi);
@@ -130,8 +130,7 @@ public class Notes : GLib.Object {
 		Gtk.init (ref args);
 		GLib.Environment.set_application_name (_("Notes"));
 		var notes = new Notes ();
-		// Install initial autostart file
-		//Xfce.Autostart.set ("Notes", "xfce4-notes", true);
+		Xfce.Autostart. at set ("xfce4-notes-autostart", "xfce4-notes", false);
 		Gtk.main ();
 		notes = null;
 		return 0;
diff --git a/panel-plugin/xfce-autostart.c b/panel-plugin/xfce-autostart.c
new file mode 100644
index 0000000..2183de9
--- /dev/null
+++ b/panel-plugin/xfce-autostart.c
@@ -0,0 +1,126 @@
+/*
+ *  xfce-autostart - convenience functions to handle autostart files
+ *  Copyright (C) 2009  Mike Massonnet <mmassonnet at xfce.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <glib.h>
+#include <libxfce4util/libxfce4util.h>
+
+void        xfce_autostart_set              (gchar *name,
+                                             gchar *exec,
+                                             gboolean hidden);
+void        xfce_autostart_set_full         (gchar *name,
+                                             gchar *exec,
+                                             gboolean hidden,
+                                             gboolean terminal,
+                                             gchar *comment,
+                                             gchar *icon);
+
+/**
+ * xfce_autostart_set:
+ * @name:   name of the autostart also used for the filename
+ * @exec:   command to execute
+ * @hidden: set to FALSE to make the file visible and enable the autostart
+ *
+ * Simple version of xfce_autostart_set_full() that passes FALSE to @terminal
+ * and %NULL to comment and icon. See xfce_autostart_set_full() for more info.
+ */
+void
+xfce_autostart_set (gchar *name,
+                    gchar *exec,
+                    gboolean hidden)
+{
+  xfce_autostart_set_full (name, exec, hidden, FALSE, NULL, NULL);
+}
+
+/**
+ * xfce_autostart_set_full:
+ * @name:       name of the autostart also used for the filename
+ * @exec:       command to execute
+ * @hidden:     set to FALSE to make the file visible and enable the autostart
+ * @terminal:   set to TRUE to run the program within a terminal
+ * @comment:    comment/description of the program
+ * @icon:       icon name
+ *
+ * Convenience function to install and modify an autostart file within the home
+ * directory of the user. If none previously exists and an autostart file is
+ * found on the system it will first be copied then modified otherwise it will
+ * be created.
+ */
+void
+xfce_autostart_set_full (gchar *name,
+                         gchar *exec,
+                         gboolean hidden,
+                         gboolean terminal,
+                         gchar *comment,
+                         gchar *icon)
+{
+  gchar *relpath = NULL;
+  gchar *usrfile = NULL;
+  gchar *sysfile = NULL;
+  GKeyFile *keyfile;
+  gchar *data;
+
+  g_return_if_fail (G_LIKELY (name != NULL));
+  g_return_if_fail (G_LIKELY (exec != NULL));
+
+  keyfile = g_key_file_new ();
+
+  relpath = g_strdup_printf ("autostart/%s.desktop", name);
+  usrfile = g_strdup_printf ("%s/%s", g_get_user_config_dir (), relpath);
+
+  if (g_file_test (usrfile, G_FILE_TEST_EXISTS))
+    {
+      TRACE ("User file exists, load it");
+      g_key_file_load_from_file (keyfile, usrfile, G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
+    }
+  else
+    {
+      TRACE ("User file doesn't exist, lookup for a system-wide file");
+      sysfile = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, relpath);
+      if (sysfile != NULL)
+        {
+          TRACE ("System-wide file found, load it");
+          g_key_file_load_from_file (keyfile, sysfile, G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
+        }
+      else
+        {
+          TRACE ("No file found, iniate one");
+          g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE,
+                                 G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
+          g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, name);
+        }
+    }
+
+  g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, exec);
+  g_key_file_set_boolean (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, hidden);
+  g_key_file_set_boolean (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, terminal);
+  if (comment != NULL)
+    g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, comment);
+  if (icon != NULL)
+    g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, icon);
+
+  data = g_key_file_to_data (keyfile, NULL, NULL);
+  g_file_set_contents (usrfile, data, -1, NULL);
+  TRACE ("File updated:\n%s", data);
+
+  g_free (relpath);
+  g_free (usrfile);
+  g_free (sysfile);
+  g_free (data);
+}
+
diff --git a/panel-plugin/color.h b/panel-plugin/xfce-autostart.h
similarity index 56%
copy from panel-plugin/color.h
copy to panel-plugin/xfce-autostart.h
index 53af846..41d843f 100644
--- a/panel-plugin/color.h
+++ b/panel-plugin/xfce-autostart.h
@@ -1,5 +1,5 @@
 /*
- *  Notes - panel plugin for Xfce Desktop Environment
+ *  xfce-autostart - convenience functions to handle autostart files
  *  Copyright (C) 2009  Mike Massonnet <mmassonnet at xfce.org>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -17,22 +17,15 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#ifndef COLOR_H
-#define COLOR_H
-
 #include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-
-void                    color_set_background            (const gchar *background);
-void                    __gdk_color_contrast            (GdkColor *color,
-                                                         gdouble contrast);
-#if !GTK_CHECK_VERSION (2,12,0)
-gchar *                 gdk_color_to_string             (const GdkColor *color);
-#endif
-#if !GTK_CHECK_VERSION (2,14,0)
-GtkWidget*              gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel);
-#endif
 
-#endif
+void        xfce_autostart_set              (gchar *name,
+                                             gchar *exec,
+                                             gboolean hidden);
+void        xfce_autostart_set_full         (gchar *name,
+                                             gchar *exec,
+                                             gboolean hidden,
+                                             gboolean terminal,
+                                             gchar *comment,
+                                             gchar *icon);
 
diff --git a/panel-plugin/xfce-autostart.vapi b/panel-plugin/xfce-autostart.vapi
new file mode 100644
index 0000000..bf12829
--- /dev/null
+++ b/panel-plugin/xfce-autostart.vapi
@@ -0,0 +1,5 @@
+[CCode (cheader_filename = "popup.h")]
+namespace Xfce.Autostart {
+	public static void @set (string name, string exec, bool hidden);
+	public static void set_full (string name, string exec, bool hidden, bool terminal, string? comment, string? icon);
+}
diff --git a/panel-plugin/xfce4-notes-autostart.desktop.in b/panel-plugin/xfce4-notes-autostart.desktop.in
new file mode 100644
index 0000000..73371f1
--- /dev/null
+++ b/panel-plugin/xfce4-notes-autostart.desktop.in
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Type=Application
+_Name=Notes
+_Comment=Ideal for your quick notes
+TryExec=xfce4-notes
+Exec=xfce4-notes
+Icon=xfce4-notes-plugin
+OnlyShowIn=XFCE;GNOME;
+Terminal=false
+Hidden=true
diff --git a/xfce4-notes.desktop.in b/xfce4-notes.desktop.in
new file mode 100644
index 0000000..abe9b6b
--- /dev/null
+++ b/xfce4-notes.desktop.in
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Version=1.0
+Type=Application
+_Name=Notes
+_Comment=Ideal for your quick notes
+TryExec=xfce4-notes
+Exec=xfce4-notes
+Icon=xfce4-notes-plugin
+Terminal=false
+Categories=GTK;Utility;TrayIcon;
+OnlyShowIn=XFCE;GNOME;
+StartupNotify=false



More information about the Xfce4-commits mailing list