Git-Url:
http://git.frugalware.org/gitweb/gitweb.cgi?p=gfpm.git;a=commitdiff;h=be8fdfa6f92068cd06bd80d4305075b685754fd0
commit be8fdfa6f92068cd06bd80d4305075b685754fd0
Author: Priyank <[EMAIL PROTECTED]>
Date: Sun Oct 14 01:20:59 2007 +0530
Implemented hicolor iconcache updater
* gfpm_icmonitor: It automatically checks /usr/share/icons/hicolor directory
for any changes (using inotify)
after every package removal / install / upgrade and if something was changed,
it auto-updates the hicolor
iconcache. (Thanks crazy for the idea)
* gfpm_util: added gfpm_update_iconcache()
diff --git a/src/Makefile.am b/src/Makefile.am
index 30a9571..8156e1d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,7 +15,8 @@ gfpm_SOURCES= \
gfpm-optimizedb.c \
gfpm-quickpane.c \
gfpm-about.c \
+ gfpm-icmonitor.c \
gfpm.c
-gfpm_LDADD= @GFPM_LIBS@ -lpacman
+gfpm_LDADD= @GFPM_LIBS@ -lpacman -linotifytools
diff --git a/src/gfpm-icmonitor.c b/src/gfpm-icmonitor.c
new file mode 100644
index 0000000..910dd53
--- /dev/null
+++ b/src/gfpm-icmonitor.c
@@ -0,0 +1,140 @@
+/*
+ * gfpm-icmonitor.c for gfpm
+ * Gfpm Icon cache monitor
+ *
+ * Copyright (C) 2006-2007 by Priyank Gosalia <[EMAIL PROTECTED]>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define MON_DIR "/usr/share/icons/hicolor"
+
+#include <inotifytools/inotifytools.h>
+#include <inotifytools/inotify.h>
+#include "gfpm-icmonitor.h"
+
+static gboolean changed;
+static gboolean inited;
+static gboolean stop = FALSE;
+struct inotify_event *event;
+
+static gboolean gfpm_icmonitor (void);
+
+int
+gfpm_icmonitor_init (void)
+{
+ if (!inotifytools_initialize())
+ {
+ inited = FALSE;
+ return -1;
+ }
+
+ if (!inotifytools_watch_recursively(MON_DIR, IN_ALL_EVENTS))
+ {
+ inited = FALSE;
+ return -1;
+ }
+
+ inited = TRUE;
+
+ return 0;
+}
+
+/* execute the monitor function every 0.5 second to monitor changes
+ in the MON_DIR
+*/
+static gboolean
+gfpm_icmonitor_monitor (void)
+{
+ if (stop == TRUE)
+ {
+ return FALSE;
+ }
+ if (changed)
+ {
+ return TRUE;
+ }
+ g_print ("monitoring..\n");
+ event = inotifytools_next_event (-1);
+ while (event)
+ {
+ switch (event->mask)
+ {
+ case IN_ALL_EVENTS:
+ case IN_ACCESS:
+ case IN_CREATE:
+ case IN_DELETE:
+ case IN_MODIFY:
+ {
+ changed = TRUE;
+ return TRUE;
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ event = inotifytools_next_event (-1);
+ }
+
+ return TRUE;
+}
+
+void
+gfpm_icmonitor_start_monitor (void)
+{
+ if (inited)
+ {
+ if (changed)
+ return;
+ stop = FALSE;
+ /* start the timer */
+ g_timeout_add (100, (GSourceFunc)gfpm_icmonitor_monitor, NULL);
+ }
+
+ return;
+}
+
+void
+gfpm_icmonitor_stop_monitor (void)
+{
+ stop = TRUE;
+}
+
+void
+gfpm_icmonitor_reset_ic (void)
+{
+ changed = FALSE;
+}
+
+gboolean
+gfpm_icmonitor_is_ic_changed (void)
+{
+ if (inited)
+ return changed;
+
+ return FALSE;
+}
+
+gboolean
+gfpm_icmonitor_is_running (void)
+{
+ if (stop == TRUE)
+ return FALSE;
+
+ return TRUE;
+}
+
diff --git a/src/gfpm-icmonitor.h b/src/gfpm-icmonitor.h
new file mode 100644
index 0000000..a81ce2e
--- /dev/null
+++ b/src/gfpm-icmonitor.h
@@ -0,0 +1,25 @@
+#ifndef __GFPM_ICMONITOR_H__
+#define __GFPM_ICMONITOR_H__
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <locale.h>
+#include <libintl.h>
+#include <gtk/gtk.h>
+
+int gfpm_icmonitor_init (void);
+
+void gfpm_icmonitor_start_monitor (void);
+
+void gfpm_icmonitor_stop_monitor (void);
+
+void gfpm_icmonitor_reset_ic (void);
+
+gboolean gfpm_icmonitor_is_ic_changed (void);
+
+gboolean gfpm_icmonitor_is_running (void);
+
+#endif
+
diff --git a/src/gfpm-interface.c b/src/gfpm-interface.c
index 8fa79bc..ef5c108 100644
--- a/src/gfpm-interface.c
+++ b/src/gfpm-interface.c
@@ -40,6 +40,7 @@
#include "gfpm-progress.h"
#include "gfpm-optimizedb.h"
#include "gfpm-quickpane.h"
+#include "gfpm-icmonitor.h"
#include "gfpm-util.h"
#include "gfpm-about.h"
#include "gfpm-db.h"
@@ -278,6 +279,7 @@ gfpm_interface_init (void)
gfpm_progress_init ();
gfpm_optimize_db_dlg_init ();
gfpm_quickpane_init ();
+ gfpm_icmonitor_init ();
gtk_widget_hide (gfpm_splash);
title = g_strdup_printf ("%s (%s)", PACKAGE_STRING, GFPM_RELEASE_NAME);
@@ -318,6 +320,7 @@ cb_gfpm_apply_btn_clicked (GtkButton *button, gpointer data)
}
gfpm_apply_dlg_hide ();
+
/* process remove list first */
if (gfpm_package_list_is_empty(GFPM_REMOVE_LIST))
{
@@ -358,6 +361,8 @@ try: if (pacman_trans_init(PM_TRANS_TYPE_REMOVE, flags,
gfpm_progress_event, cb_
pkgs = pacman_trans_getinfo (PM_TRANS_PACKAGES);
if (pkgs == NULL) g_print ("pkgs is null.. bad bad bad!\n");
+ /* start iconcache montior */
+ gfpm_icmonitor_start_monitor ();
/* commit transaction */
ret = gfpm_trans_commit (&pdata);
@@ -412,8 +417,12 @@ itry: if (pacman_trans_init(PM_TRANS_TYPE_SYNC,
flags, gfpm_progress_event, cb_g
pkgs = pacman_trans_getinfo (PM_TRANS_PACKAGES);
if (pkgs == NULL) gfpm_error (_("Error"), _("Error getting transaction info"));
+ /* start iconcache montior if it wasn't already started */
+ if (gfpm_icmonitor_is_running()==FALSE)
+ gfpm_icmonitor_start_monitor ();
/* commit transaction */
- ret = gfpm_trans_commit (pdata);
+ ret = gfpm_trans_commit (&pdata);
+
cleanup:
/* release the transaction */
@@ -426,8 +435,13 @@ itry: if (pacman_trans_init(PM_TRANS_TYPE_SYNC,
flags, gfpm_progress_event, cb_g
gfpm_progress_show (FALSE);
}
gfpm_db_reset_localdb ();
- //gfpm_progress_show (FALSE);
+ gfpm_icmonitor_stop_monitor ();
+ if (gfpm_icmonitor_is_ic_changed() == TRUE)
+ {
+ gfpm_icmonitor_reset_ic ();
+ gfpm_update_iconcache ();
+ }
if (current_group != NULL)
gfpm_load_pkgs_tvw ((const char*)current_group);
diff --git a/src/gfpm-util.c b/src/gfpm-util.c
index 97da9be..c4433e2 100644
--- a/src/gfpm-util.c
+++ b/src/gfpm-util.c
@@ -85,3 +85,17 @@ gfpm_check_if_package_updatable (const gchar *package)
return ret;
}
+void
+gfpm_update_iconcache (void)
+{
+ if (!g_file_test("/usr/bin/gtk-update-icon-cache", G_FILE_TEST_EXISTS))
+ return;
+
+ g_print ("updating iconcache..\n");
+ while (gtk_events_pending()) gtk_main_iteration ();
+ system ("gtk-update-icon-cache -f -t /usr/share/icons/hicolor >
/dev/null 2>&1");
+ while (gtk_events_pending()) gtk_main_iteration ();
+
+ return;
+}
+
diff --git a/src/gfpm-util.h b/src/gfpm-util.h
index 233ff51..444d232 100644
--- a/src/gfpm-util.h
+++ b/src/gfpm-util.h
@@ -20,4 +20,6 @@ GdkPixbuf *gfpm_get_icon (const char *, int);
gint gfpm_check_if_package_updatable (const gchar *);
+void gfpm_update_iconcache (void);
+
#endif
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git