r3283 - in trunk/src/target/OM-2007.2/applications/openmoko-today2: . src

chris at sita.openmoko.org chris at sita.openmoko.org
Fri Oct 26 12:51:35 CEST 2007


Author: chris
Date: 2007-10-26 12:51:34 +0200 (Fri, 26 Oct 2007)
New Revision: 3283

Modified:
   trunk/src/target/OM-2007.2/applications/openmoko-today2/ChangeLog
   trunk/src/target/OM-2007.2/applications/openmoko-today2/configure.ac
   trunk/src/target/OM-2007.2/applications/openmoko-today2/src/Makefile.am
   trunk/src/target/OM-2007.2/applications/openmoko-today2/src/today-launcher.c
Log:
        * configure.ac:
        * src/Makefile.am:
        * src/today-launcher.c: (monitor), (find_and_destroy),
        (inotify_event), (load_data_dir),
	(today_launcher_page_create):
        Add inotify for .desktop files, copied from mb-desktop-2


Modified: trunk/src/target/OM-2007.2/applications/openmoko-today2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-today2/ChangeLog	2007-10-26 10:10:16 UTC (rev 3282)
+++ trunk/src/target/OM-2007.2/applications/openmoko-today2/ChangeLog	2007-10-26 10:51:34 UTC (rev 3283)
@@ -1,3 +1,11 @@
+2007-10-26  Chris Lord  <chris at openedhand.com>
+
+	* configure.ac:
+	* src/Makefile.am:
+	* src/today-launcher.c: (monitor), (find_and_destroy),
+	(inotify_event), (load_data_dir), (today_launcher_page_create):
+        Add inotify for .desktop files, copied from mb-desktop-2
+
 2007-10-25  Chris Lord  <chris at openedhand.com>
 
 	* src/Makefile.am:

Modified: trunk/src/target/OM-2007.2/applications/openmoko-today2/configure.ac
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-today2/configure.ac	2007-10-26 10:10:16 UTC (rev 3282)
+++ trunk/src/target/OM-2007.2/applications/openmoko-today2/configure.ac	2007-10-26 10:51:34 UTC (rev 3283)
@@ -24,6 +24,9 @@
 AC_SUBST(GETTEXT_PACKAGE)
 AM_GLIB_GNU_GETTEXT
 
+AC_CHECK_HEADERS([sys/inotify.h], inotify_support=yes, inotify_support=no)
+AM_CONDITIONAL(HAVE_INOTIFY, [test "$inotify_support" = "yes"])
+
 PKG_CHECK_MODULES(SEXY, libsexy,
                   [enable_sexy=yes
                    AC_DEFINE(HAVE_SEXY, 1, [We are sexy enough])],

Modified: trunk/src/target/OM-2007.2/applications/openmoko-today2/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-today2/src/Makefile.am	2007-10-26 10:10:16 UTC (rev 3282)
+++ trunk/src/target/OM-2007.2/applications/openmoko-today2/src/Makefile.am	2007-10-26 10:51:34 UTC (rev 3283)
@@ -32,5 +32,20 @@
 			@SN_LIBS@ @MOKOUI_LIBS@ @MOKOJOURNAL_LIBS@ \
 			@GCONF_LIBS@ @JANA_LIBS@
 
+# Optional inotify support
+if HAVE_INOTIFY
+AM_CPPFLAGS += -DWITH_INOTIFY
+openmoko_today_LDADD += libinotify.a
+
+noinst_LIBRARIES = libinotify.a
+libinotify_a_SOURCES = \
+	inotify/inotify-kernel.c inotify/inotify-kernel.h \
+	inotify/inotify-sub.c   inotify/inotify-sub.h \
+	inotify/inotify-path.c inotify/inotify-path.h \
+	inotify/inotify-missing.c inotify/inotify-missing.h \
+	inotify/inotify-diag.c inotify/inotify-diag.h \
+	inotify/local_inotify.h inotify/local_inotify_syscalls.h
+endif
+
 MAINTAINERCLEANFILES  = config.h.in Makefile.in
 

Modified: trunk/src/target/OM-2007.2/applications/openmoko-today2/src/today-launcher.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-today2/src/today-launcher.c	2007-10-26 10:10:16 UTC (rev 3282)
+++ trunk/src/target/OM-2007.2/applications/openmoko-today2/src/today-launcher.c	2007-10-26 10:51:34 UTC (rev 3283)
@@ -1,5 +1,8 @@
 
-#include <config.h>
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
 #include <string.h>
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -11,7 +14,16 @@
 #include <moko-search-bar.h>
 #include "today.h"
 
-/* NOTE: Following 4 functions (as well as libtaku) taken from
+/* inotify support derived/copied from code in matchbox-desktop-2 */
+#if WITH_INOTIFY
+#include "inotify/inotify-path.h"
+#include "inotify/local_inotify.h"
+
+static gboolean with_inotify;
+G_LOCK_DEFINE(inotify_lock);
+#endif
+
+/* NOTE: Following 6 functions (as well as libtaku) taken from
  * matchbox-desktop-2 and (slightly) modified where necessary
  */
 /*
@@ -172,7 +184,68 @@
 	return FALSE;
 }
 
+#if WITH_INOTIFY
 /*
+ * Monitor @directory with inotify, if available.
+ */
+static void
+monitor (const char *directory)
+{
+  inotify_sub *sub;
+
+  if (!with_inotify)
+    return;
+  
+  sub = _ih_sub_new (directory, NULL, NULL);
+  _ip_start_watching (sub);
+}
+
+/*
+ * Used to delete tiles when they are removed from disk.  @a is the tile, @b is
+ * the desktop filename to look for.
+ */
+static void
+find_and_destroy (GtkWidget *widget, gpointer data)
+{
+  TakuLauncherTile *tile;
+  const char *removed, *filename;
+
+  tile = TAKU_LAUNCHER_TILE (widget);
+  if (!tile)
+    return;
+  
+  removed = data;
+  
+  filename = taku_launcher_tile_get_filename (tile);
+  if (strcmp (removed, filename) == 0)
+    gtk_widget_destroy (widget);
+}
+
+static TodayData *data_static;
+static void
+inotify_event (ik_event_t *event, inotify_sub *sub)
+{
+  char *path;
+
+  if (event->mask & IN_MOVED_TO || event->mask & IN_CREATE) {
+    if (g_str_has_suffix (event->name, ".desktop")) {
+      LoadDesktopData *data = g_new0 (LoadDesktopData, 1);
+      data->name = g_strdup (event->name);
+      data->directory = g_strdup (sub->dirname);
+      data->table = (TakuTable *)data_static->launcher_table;
+      data->categories = data_static->categories;
+      load_desktop_cb (data);
+    }
+  } else if (event->mask & IN_MOVED_FROM || event->mask & IN_DELETE) {
+    path = g_build_filename (sub->dirname, event->name, NULL);
+    gtk_container_foreach (GTK_CONTAINER (data_static->launcher_table),
+                           find_and_destroy, path);
+    g_free (path);
+  }
+}
+#endif
+
+/*
  * Load all .desktop files in @datadir/applications/, and add them to @table.
  */
 static void
@@ -194,6 +267,10 @@
     return;
   }
 
+#if WITH_INOTIFY
+  monitor (directory);
+#endif
+
   dir = g_dir_open (directory, 0, &error);
   if (error) {
     g_warning ("Cannot read %s: %s", directory, error->message);
@@ -294,6 +371,11 @@
 	const char * const *dirs;
 	gchar *vfolder_dir;
 
+#if WITH_INOTIFY
+	data_static = data;
+	with_inotify = _ip_startup (inotify_event);
+#endif
+
 	main_vbox = gtk_vbox_new (FALSE, 0);
 	
 	/* search/filter bar */
@@ -362,7 +444,7 @@
 	g_signal_connect (G_OBJECT (data->search_bar), "toggled",
 		G_CALLBACK (today_launcher_search_toggle_cb), data);
 	
-	/* Populate the task list */
+	/* Populate the app list */
 	/* TODO: Do this incrementally during idle time to increase
 	 * start-up speed.
 	 */





More information about the commitlog mailing list