[gnome-utils] Rework monitoring of the home file dir
- From: Paolo Borelli <pborelli src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-utils] Rework monitoring of the home file dir
- Date: Sat, 25 Apr 2009 11:33:29 -0400 (EDT)
commit 4469f8b218ab201f36151cdcfcf3c4743c357f0f
Author: Paolo Borelli <porelli gnome org>
Date: Sat Apr 25 17:29:24 2009 +0200
Rework monitoring of the home file dir
Rework code that monitors file changes in the home dir. Show the
notification only if the currently scanned folder is a subdir of
home itself.
---
baobab/src/baobab-treeview.c | 55 +++++++++++++--------
baobab/src/baobab-utils.c | 14 ------
baobab/src/baobab-utils.h | 1 -
baobab/src/baobab.c | 106 +++++++++++++++++++++++++++++++----------
baobab/src/callbacks.c | 46 +------------------
baobab/src/callbacks.h | 8 ---
6 files changed, 115 insertions(+), 115 deletions(-)
diff --git a/baobab/src/baobab-treeview.c b/baobab/src/baobab-treeview.c
index e1237b0..d4d50db 100644
--- a/baobab/src/baobab-treeview.c
+++ b/baobab/src/baobab-treeview.c
@@ -74,7 +74,21 @@ on_tv_cur_changed (GtkTreeView *treeview, gpointer data)
gtk_tree_model_get (GTK_TREE_MODEL (baobab.model), &iter,
COL_H_PARSENAME, &parsename, -1);
}
+}
+
+static void
+contents_changed (void)
+{
+ baobab_get_filesystem (&g_fs);
+ set_label_scan (&g_fs);
+ show_label ();
+
+ if (messageyesno (_("Rescan your home folder?"),
+ _("The content of your home folder has changed. Select rescan to update the disk usage details."),
+ GTK_MESSAGE_QUESTION, _("_Rescan"), baobab.window) == GTK_RESPONSE_OK) {
+ baobab_rescan_current_dir ();
}
+}
static gboolean
on_tv_button_press (GtkWidget *widget,
@@ -83,14 +97,7 @@ on_tv_button_press (GtkWidget *widget,
{
GtkTreePath *path;
GtkTreeIter iter;
-
-
- if (baobab.CONTENTS_CHANGED_DELAYED) {
- baobab.CONTENTS_CHANGED_DELAYED = FALSE;
- if (baobab.STOP_SCANNING) {
- contents_changed ();
- }
- }
+ GFile *file;
gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
event->x, event->y,
@@ -98,32 +105,38 @@ on_tv_button_press (GtkWidget *widget,
if (!path)
return TRUE;
- /* check if a valid and scanned folder has been selected */
- if (baobab.selected_path) {
- g_free (baobab.selected_path);
- baobab.selected_path = NULL;
- }
-
+ /* get the selected path */
+ g_free (baobab.selected_path);
gtk_tree_model_get_iter (GTK_TREE_MODEL (baobab.model), &iter,
path);
gtk_tree_model_get (GTK_TREE_MODEL (baobab.model), &iter,
COL_H_PARSENAME, &baobab.selected_path, -1);
-
+
+ file = g_file_parse_name (baobab.selected_path);
+
+ if (baobab.CONTENTS_CHANGED_DELAYED) {
+ GFile *home_file;
+
+ home_file = g_file_new_for_path (g_get_home_dir ());
+ if (g_file_has_prefix (file, home_file)) {
+ baobab.CONTENTS_CHANGED_DELAYED = FALSE;
+ if (baobab.STOP_SCANNING) {
+ contents_changed ();
+ }
+ }
+ g_object_unref (home_file);
+ }
+
/* right-click */
if (event->button == 3) {
- GFile *file;
- file = g_file_parse_name (baobab.selected_path);
if (g_file_query_exists (file, NULL)) {
popupmenu_list (path, event, can_trash_file (file));
}
- gtk_tree_path_free (path);
- g_object_unref (file);
-
- return FALSE;
}
gtk_tree_path_free (path);
+ g_object_unref (file);
return FALSE;
}
diff --git a/baobab/src/baobab-utils.c b/baobab/src/baobab-utils.c
index f72bae8..85c1514 100644
--- a/baobab/src/baobab-utils.c
+++ b/baobab/src/baobab-utils.c
@@ -526,20 +526,6 @@ trash_file (GFile *file)
return TRUE;
}
-void
-contents_changed (void)
-{
- baobab_get_filesystem (&g_fs);
- set_label_scan (&g_fs);
- show_label ();
-
- if (messageyesno (_("Rescan your home folder?"),
- _("The content of your home folder has changed. Select rescan to update the disk usage details."),
- GTK_MESSAGE_QUESTION, _("_Rescan"), baobab.window) == GTK_RESPONSE_OK) {
- baobab_rescan_current_dir ();
- }
-}
-
gchar *
baobab_gconf_get_string_with_default (GConfClient *client,
const gchar *key,
diff --git a/baobab/src/baobab-utils.h b/baobab/src/baobab-utils.h
index 34c33d5..cf44748 100644
--- a/baobab/src/baobab-utils.h
+++ b/baobab/src/baobab-utils.h
@@ -43,7 +43,6 @@ void show_label (void);
void open_file_with_application (GFile *file);
gboolean can_trash_file (GFile *file);
gboolean trash_file (GFile *file);
-void contents_changed (void);
void set_ui_action_sens (const gchar *name, gboolean sens);
void set_ui_widget_sens (const gchar *name, gboolean sens);
gchar *baobab_gconf_get_string_with_default (GConfClient *client, const gchar *key, const gchar *def);
diff --git a/baobab/src/baobab.c b/baobab/src/baobab.c
index 7458c7c..cf39eb9 100644
--- a/baobab/src/baobab.c
+++ b/baobab/src/baobab.c
@@ -674,13 +674,86 @@ sanity_check_excluded_locations (void)
}
static void
-baobab_init (void)
+volume_changed (GVolumeMonitor *volume_monitor,
+ GVolume *volume,
+ gpointer user_data)
+{
+ /* filesystem has changed (mounted or unmounted device) */
+ baobab_get_filesystem (&g_fs);
+ set_label_scan (&g_fs);
+ show_label ();
+}
+
+static void
+home_contents_changed (GFileMonitor *file_monitor,
+ GFile *child,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ gpointer user_data)
+
+{
+ gchar *excluding;
+
+ if (!baobab.bbEnableHomeMonitor)
+ return;
+
+ if (baobab.CONTENTS_CHANGED_DELAYED)
+ return;
+
+ excluding = g_file_get_basename (child);
+ if (strcmp (excluding, ".recently-used") == 0 ||
+ strcmp (excluding, ".gnome2_private") == 0 ||
+ strcmp (excluding, ".xsession-errors") == 0 ||
+ strcmp (excluding, ".bash_history") == 0 ||
+ strcmp (excluding, ".gconfd") == 0) {
+ g_free (excluding);
+ return;
+ }
+ g_free (excluding);
+
+ baobab.CONTENTS_CHANGED_DELAYED = TRUE;
+}
+
+static void
+monitor_volume (void)
+{
+ monitor_vol = g_volume_monitor_get ();
+ g_signal_connect (monitor_vol, "volume_changed",
+ G_CALLBACK (volume_changed), NULL);
+}
+
+static void
+monitor_home_dir (void)
{
- GSList *uri_list;
GFile *file;
GError *error = NULL;
monitor_home = NULL;
+ file = g_file_new_for_path (g_get_home_dir ());
+ monitor_home = g_file_monitor_directory (file, 0, NULL, &error);
+ g_object_unref (file);
+
+ if (!monitor_home) {
+ message (_("Could not initialize monitoring"),
+ _("Changes to your home folder will not be monitored."),
+ GTK_MESSAGE_WARNING, NULL);
+ g_print ("homedir:%s\n", error->message);
+ g_error_free (error);
+ }
+ else {
+ g_signal_connect (monitor_home,
+ "changed",
+ G_CALLBACK (home_contents_changed),
+ NULL);
+ }
+}
+
+static void
+baobab_init (void)
+{
+ GSList *uri_list;
+ GError *error = NULL;
+
/* Load the UI */
baobab.main_ui = gtk_builder_new ();
gtk_builder_add_from_file (baobab.main_ui, BAOBAB_UI_FILE, &error);
@@ -724,36 +797,17 @@ baobab_init (void)
sanity_check_excluded_locations ();
- baobab.bbEnableHomeMonitor = gconf_client_get_bool (baobab.gconf_client,
- PROPS_ENABLE_HOME_MONITOR,
- NULL);
-
baobab_create_toolbar ();
baobab_create_statusbar ();
- /* start monitoring */
- monitor_vol = g_volume_monitor_get ();
- g_signal_connect (monitor_vol, "volume_changed",
- G_CALLBACK (volume_changed), NULL);
+ monitor_volume ();
- file = g_file_new_for_path (g_get_home_dir ());
- monitor_home = g_file_monitor_directory (file, 0, NULL, &error);
- g_object_unref (file);
+ baobab.bbEnableHomeMonitor = gconf_client_get_bool (baobab.gconf_client,
+ PROPS_ENABLE_HOME_MONITOR,
+ NULL);
- if (!monitor_home) {
- message (_("Could not initialize monitoring"),
- _("Changes to your home folder will not be monitored."),
- GTK_MESSAGE_WARNING, NULL);
- g_print ("homedir:%s\n", error->message);
- g_error_free (error);
- }
- else {
- g_signal_connect (monitor_home,
- "changed",
- G_CALLBACK (contents_changed_cb),
- NULL);
- }
+ monitor_home_dir ();
}
static void
diff --git a/baobab/src/callbacks.c b/baobab/src/callbacks.c
index fb40607..a43aa57 100644
--- a/baobab/src/callbacks.c
+++ b/baobab/src/callbacks.c
@@ -110,8 +110,7 @@ on_about_activate (GtkMenuItem *menuitem, gpointer user_data)
_("translator-credits"),
"wrap-license", TRUE,
NULL);
- g_free (license_trans);
-
+ g_free (license_trans);
}
void
@@ -238,55 +237,12 @@ trash_dir_cb (GtkMenuItem *pmenu, gpointer dummy)
5, &filesize, -1);
gtk_tree_store_remove (GTK_TREE_STORE (baobab.model),
&iter);
- if (baobab.bbEnableHomeMonitor)
- contents_changed ();
}
g_object_unref (file);
}
void
-volume_changed (GVolumeMonitor *volume_monitor,
- GVolume *volume,
- gpointer user_data)
-{
- /* filesystem has changed (mounted or unmounted device) */
- baobab_get_filesystem (&g_fs);
- set_label_scan (&g_fs);
- show_label ();
-}
-
-void
-contents_changed_cb (GFileMonitor *file_monitor,
- GFile *child,
- GFile *other_file,
- GFileMonitorEvent event_type,
- gpointer user_data)
-
-{
- gchar *excluding;
-
- if (!baobab.bbEnableHomeMonitor)
- return;
-
- if (baobab.CONTENTS_CHANGED_DELAYED)
- return;
-
- excluding = g_file_get_basename (child);
- if (strcmp (excluding, ".recently-used") == 0 ||
- strcmp (excluding, ".gnome2_private") == 0 ||
- strcmp (excluding, ".xsession-errors") == 0 ||
- strcmp (excluding, ".bash_history") == 0 ||
- strcmp (excluding, ".gconfd") == 0) {
- g_free (excluding);
- return;
- }
- g_free (excluding);
-
- baobab.CONTENTS_CHANGED_DELAYED = TRUE;
-}
-
-void
on_pref_menu (GtkMenuItem *menuitem, gpointer user_data)
{
create_props ();
diff --git a/baobab/src/callbacks.h b/baobab/src/callbacks.h
index f13e888..f55bbe8 100644
--- a/baobab/src/callbacks.h
+++ b/baobab/src/callbacks.h
@@ -45,15 +45,7 @@ void open_file_cb (GtkMenuItem *pmenu, gpointer dummy);
void scan_folder_cb (GtkMenuItem *pmenu, gpointer dummy);
void trash_dir_cb (GtkMenuItem *pmenu, gpointer dummy);
void list_all_cb (GtkMenuItem *pmenu, gpointer dummy);
-void contents_changed_cb (GFileMonitor *file_monitor,
- GFile *child,
- GFile *other_file,
- GFileMonitorEvent event_type,
- gpointer user_data);
void on_pref_menu (GtkMenuItem *menuitem, gpointer user_data);
-void volume_changed (GVolumeMonitor *volume_monitor,
- GVolume *volume,
- gpointer user_data);
void on_tb_scan_remote_clicked (GtkToolButton *toolbutton, gpointer user_data);
void on_menu_scan_rem_activate (GtkMenuItem *menuitem, gpointer user_data);
void on_view_tb_activate (GtkCheckMenuItem *checkmenuitem, gpointer user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]