patch for baobab 2.0.30: consider only files owned by current user



Hello Folks,

Attached please find a patch for baobab 2.0.30 (the version that came
with Ubuntu 10.04 LTS, which runs on my desktop) that implements a new
option to consider only files owned by current user; after checking it
on in the Edit/Preferences dialog, baobab will only take into account
files owned by the user running it. This is very useful for your
spouse to find which files/directories are using up her quota...

This seems to be working OK on my system.

I contribute it here in hope it can be useful to someone else, and I
will also keep a current version on
http://www.durval.com/gnome-utils-2.30.0_-_baobab_-_consider_only_files_owned_by_current_user.patch
in case any fixes or modifications come up.

Cheers,
--
  Durval Menezes.
#gnome-utils-2.30.0_-_baobab_-_consider_only_files_owned_by_current_user.patch
#
#patch to implement a "Consider only files owned by current user" option
#in gnome-utils-2.30.0/Baobab.
#
#Very useful for spouses who can't find where they are using up all their
#disk quota.
#
#To compile and install:
#  tar xjf gnome-utils-2.30.0.tar.bz2 
#  patch -p0 <gnome-utils-2.30.0_-_baobab_-_consider_only_files_owned_by_current_user.patch 
#  cd gnome-utils-2.30.0
#  ./configure --prefix=/usr
#  cd baobab/
#  make
#  sudo mv /usr/bin/baobab{,.orig-20110625}
#  sudo install src/baobab -o root -g root -m 755 /usr/bin/
#  sudo mv /usr/share/baobab/baobab-dialog-scan-props.ui{,.orig-20110625}
#  sudo install data/baobab-dialog-scan-props.ui -o root -g root -m 755 /usr/share/baobab
#
#To activate, just check the corresponding option in the "Edit/Preferences"
#configuration dialog window; it will be saved by gconf, so the setting will
#be remembered the next time you use the program.
#
#This patch and the above procedure were tested on a Ubuntu Lucid 10.04.02 LTS
#system. I had to add a whole lot of "dev" packages on my system so that 
#./configure would run without errors, but the rest went OK. 
#
#2011/06/25 Durval Menezes

--- gnome-utils-2.30.0/baobab/data/baobab-dialog-scan-props.ui	2011/06/25 16:39:14	1.1
+++ gnome-utils-2.30.0/baobab/data/baobab-dialog-scan-props.ui	2011/06/25 16:39:54
@@ -161,6 +161,24 @@
                 <property name="fill">False</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkCheckButton" id="check_onlyowner">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="label" translatable="yes">_Consider only files owned by current user</property>
+                <property name="use_underline">True</property>
+                <property name="relief">GTK_RELIEF_NORMAL</property>
+                <property name="focus_on_click">True</property>
+                <property name="active">True</property>
+                <property name="inconsistent">False</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="padding">0</property>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="padding">0</property>
--- gnome-utils-2.30.0/baobab/src/baobab-prefs.c	2011/06/25 14:57:56	1.1
+++ gnome-utils-2.30.0/baobab/src/baobab-prefs.c	2011/06/25 15:15:05
@@ -56,6 +56,8 @@
 static void enable_home_cb (GtkToggleButton * togglebutton,
 			    gpointer user_data);
 
+static void enable_owner_cb (GtkToggleButton * togglebutton,
+			    gpointer user_data);
 
 void
 props_notify (GConfClient *client,
@@ -103,7 +105,7 @@
 void
 create_props (void)
 {
-	GtkWidget *dlg, *check_enablehome;
+	GtkWidget *dlg, *check_enablehome, *check_onlyowner;
 	GtkBuilder *builder;
 	GError *error = NULL;
 
@@ -139,6 +141,14 @@
 				"toggled", G_CALLBACK (enable_home_cb),
 				NULL);
 
+	check_onlyowner = GTK_WIDGET (gtk_builder_get_object (builder, "check_onlyowner"));
+	gtk_toggle_button_set_active ((GtkToggleButton *) check_onlyowner,
+				      baobab.bbOnlyOwner);
+
+	g_signal_connect_after ((GtkToggleButton *) check_onlyowner,
+				"toggled", G_CALLBACK (enable_owner_cb),
+				NULL);
+
 	g_signal_connect (dlg, "response",
 		    	  G_CALLBACK (filechooser_response_cb),
 		    	  NULL);
@@ -415,3 +425,13 @@
 			       baobab.bbEnableHomeMonitor, NULL);
 
 }
+
+void
+enable_owner_cb (GtkToggleButton *togglebutton, gpointer user_data)
+{
+	baobab.bbOnlyOwner = gtk_toggle_button_get_active (togglebutton);
+
+	gconf_client_set_bool (baobab.gconf_client, PROPS_ONLY_OWNER,
+			       baobab.bbOnlyOwner, NULL);
+
+}
--- gnome-utils-2.30.0/baobab/src/baobab-scan.c	2011/06/25 14:07:41	1.1
+++ gnome-utils-2.30.0/baobab/src/baobab-scan.c	2011/06/25 15:27:23
@@ -142,6 +142,7 @@
 	G_FILE_ATTRIBUTE_UNIX_NLINK "," \
 	G_FILE_ATTRIBUTE_UNIX_INODE "," \
 	G_FILE_ATTRIBUTE_UNIX_DEVICE "," \
+	G_FILE_ATTRIBUTE_OWNER_USER "," \
 	G_FILE_ATTRIBUTE_ACCESS_CAN_READ;
 
 
@@ -282,14 +283,26 @@
 
 		/* is it a regular file? */
 		else if (temp_type == G_FILE_TYPE_REGULAR) {
+
+ 			if (baobab.bbOnlyOwner &&
+			    g_file_info_has_attribute (temp_info, 
+							   G_FILE_ATTRIBUTE_OWNER_USER)) {
+				if (strcmp(g_get_user_name(), 
+				     g_file_info_get_attribute_string(temp_info,
+							   G_FILE_ATTRIBUTE_OWNER_USER)) != 0) {
+					/* not owned by current user: skip it */
+					g_object_unref (temp_info);
+					continue;
+				}
+			}
+ 
+			if (!baobab_hardlinks_array_add (hla, temp_info)) {
  
 			/* check for hard links only on local files */
 			if (g_file_info_has_attribute (temp_info,
 						       G_FILE_ATTRIBUTE_UNIX_NLINK) &&
 				g_file_info_get_attribute_uint32 (temp_info,
 							    G_FILE_ATTRIBUTE_UNIX_NLINK) > 1) {
- 
-				if (!baobab_hardlinks_array_add (hla, temp_info)) {
 
 					/* we already acconted for it */
 					tempHLsize += g_file_info_get_size (temp_info);
--- gnome-utils-2.30.0/baobab/src/baobab.c	2011/06/25 15:10:46	1.1
+++ gnome-utils-2.30.0/baobab/src/baobab.c	2011/06/25 15:12:41
@@ -855,6 +855,10 @@
 							    PROPS_ENABLE_HOME_MONITOR,
 							    NULL);
 
+	baobab.bbOnlyOwner = gconf_client_get_bool (baobab.gconf_client,
+							    PROPS_ONLY_OWNER,
+							    NULL);
+
 	monitor_home_dir ();
 }
 
--- gnome-utils-2.30.0/baobab/src/baobab.h	2011/06/25 15:10:46	1.1
+++ gnome-utils-2.30.0/baobab/src/baobab.h	2011/06/25 15:13:37
@@ -45,6 +45,7 @@
 #define BAOBAB_SUBFLSTIPS_VISIBLE_KEY   BAOBAB_KEY_DIR "/ui/baobab_subfoldertips_visible"
 #define PROPS_SCAN_KEY			BAOBAB_KEY_DIR "/properties/skip_scan_uri_list"
 #define PROPS_ENABLE_HOME_MONITOR	BAOBAB_KEY_DIR "/properties/enable_home_monitor"
+#define PROPS_ONLY_OWNER	BAOBAB_KEY_DIR "/properties/only_owner"
 #define SYSTEM_TOOLBAR_STYLE		"/desktop/gnome/interface/toolbar_style"
 
 typedef struct _ContextMenu ContextMenu;
@@ -76,6 +77,7 @@
 	gboolean CONTENTS_CHANGED_DELAYED;
 	GSList *excluded_locations;
 	gboolean bbEnableHomeMonitor;
+	gboolean bbOnlyOwner;
 	gchar *label_scan;
 	gboolean show_allocated;
 	gboolean is_local;
--- gnome-utils-2.30.0/baobab/src/callbacks.c	2011/06/25 15:32:49	1.1
+++ gnome-utils-2.30.0/baobab/src/callbacks.c	2011/06/25 15:39:42
@@ -71,6 +71,7 @@
 		"Paolo Borelli <pborelli katamail com>",
 		"Benoît Dejean <benoit placenet org>",
 		"Igalia (rings-chart and treemap widget) <www.igalia.com>",
+		"Durval Menezes ('consider only files owned by current user' option) <www.durval.com>",
 		NULL
 	};
 	
@@ -100,7 +101,8 @@
 	gtk_show_about_dialog (NULL,
 			       "name", _("Baobab"),
 			       "comments", _("A graphical tool to analyze "
-					     "disk usage."),
+					     "disk usage."
+						 "\nMODIFIED by Durval Menezes (see Credits)"),
 			       "version", VERSION,
 			       "copyright", copyright,
 			       "logo-icon-name", "baobab",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]