[Goodies-commits] r4829 - xfce4-mount-plugin/trunk/panel-plugin

Fabian Nowak timystery at xfce.org
Mon May 19 23:50:42 CEST 2008


Author: timystery
Date: 2008-05-19 21:50:42 +0000 (Mon, 19 May 2008)
New Revision: 4829

Modified:
   xfce4-mount-plugin/trunk/panel-plugin/devices.h
   xfce4-mount-plugin/trunk/panel-plugin/mount-plugin.c
   xfce4-mount-plugin/trunk/panel-plugin/mount-plugin.h
Log:
made mount infos and used space be only as large as necessary, but make every item be displayed. had lots of trouble because of people only hacking C and not programming after having thought in an object-oriented way.


Modified: xfce4-mount-plugin/trunk/panel-plugin/devices.h
===================================================================
--- xfce4-mount-plugin/trunk/panel-plugin/devices.h	2008-05-19 21:42:54 UTC (rev 4828)
+++ xfce4-mount-plugin/trunk/panel-plugin/devices.h	2008-05-19 21:50:42 UTC (rev 4829)
@@ -1,7 +1,7 @@
 /* devices.h */
 /*
 Copyright (C) 2005 Jean-Baptiste jb_dul at yahoo.com
-Copyright (C) 2007 Fabian Nowak <timystery at arcor.de>
+Copyright (C) 2007 , 2008Fabian Nowak <timystery at arcor.de>
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
@@ -24,6 +24,9 @@
 #include <glib.h>
 
 #include "helpers.h"
+/* #include "mount-plugin.h" */
+/* extern t_disk_display ; */
+/* People, learn to program in an object-oriented way! */
 
 #ifdef DEBUG
 #undef DEBUG
@@ -77,7 +80,8 @@
     char *device;                 /**< Device name, e.g. /dev/cdrom */
     char *mount_point;             /**< Device mount point, e.g. /mnt/cdrom */
     t_mount_info *  mount_info; /**< NULL if not mounted */
-    t_deviceclass dc;             /**<Ddevice classification */
+    /*`t_disk_display *disk_display; */ /* People, learn to program in an object-oriented way! */
+    t_deviceclass dc;             /**< Device classification */
 } t_disk;
 
 
@@ -163,10 +167,10 @@
 
 /**
  * Lookup given mountpoint and device for exclusion
- * @param excluded_FSs	Pointer to array of excluded filesystems
- * @param mountpoint	Mountpoint of device to search for
- * @param device		Original device path to search for
- * @return				TRUE, if device is to be excluded
+ * @param excluded_FSs  Pointer to array of excluded filesystems
+ * @param mountpoint    Mountpoint of device to search for
+ * @param device        Original device path to search for
+ * @return              TRUE, if device is to be excluded
  */
 gboolean exclude_filesystem (GPtrArray *excluded_FSs, gchar *mountpoint, gchar *device);
 
@@ -189,8 +193,8 @@
 
 /**
  * Checks, if disk is still mounted
- * @param disk			device name or mountpoint to check
- * @return				true, if mounted, else false.
+ * @param disk          device name or mountpoint to check
+ * @return              true, if mounted, else false.
  */
 gboolean disk_check_mounted (const char *disk);
 

Modified: xfce4-mount-plugin/trunk/panel-plugin/mount-plugin.c
===================================================================
--- xfce4-mount-plugin/trunk/panel-plugin/mount-plugin.c	2008-05-19 21:42:54 UTC (rev 4828)
+++ xfce4-mount-plugin/trunk/panel-plugin/mount-plugin.c	2008-05-19 21:50:42 UTC (rev 4829)
@@ -116,7 +116,34 @@
     *formatted_diskname = g_strdup_printf("LVM  %d:%d", volume, logvol);
 }
 
+/**
+ *  Set character sizes for all entries to maximum.
+ */
+static void
+disk_display_set_sizes (GPtrArray *array)
+{
+    int i, max_width_label_disk=0, max_width_label_mount_info=0, tmp;
+    t_disk_display *disk_display;
 
+    for (i=0; i<array->len; i++) {
+        disk_display= g_ptr_array_index (array, i); /* get the disk */
+        tmp = strlen(gtk_label_get_text(GTK_LABEL(disk_display->label_mount_info)));
+        if (tmp>max_width_label_mount_info)
+            max_width_label_mount_info = tmp;
+
+        tmp = strlen(gtk_label_get_text(GTK_LABEL(disk_display->label_disk)));
+        if (tmp>max_width_label_disk)
+            max_width_label_disk = tmp;
+    }
+
+    for (i=0; i<array->len; i++) {
+        disk_display = g_ptr_array_index (array, i); /* get the disk */
+        gtk_label_set_width_chars(GTK_LABEL(disk_display->label_disk), max_width_label_disk);
+        gtk_label_set_width_chars(GTK_LABEL(disk_display->label_mount_info), max_width_label_mount_info);
+    }
+
+}
+
 /**
  * Create a new t_disk_display from t_disk infos.
  */
@@ -146,22 +173,22 @@
             formatted_diskname = g_strdup(disk->device);
 
         if (mounter->exclude_devicenames)
-        dd->label_disk = gtk_label_new (disk->mount_point);
-    else
-        dd->label_disk = gtk_label_new (g_strconcat(formatted_diskname, " -> ",
+            dd->label_disk = gtk_label_new (disk->mount_point);
+        else
+            dd->label_disk = gtk_label_new (g_strconcat(formatted_diskname, " -> ",
                                         disk->mount_point, NULL));
 
-    g_free (formatted_diskname);
+        g_free (formatted_diskname);
 
         /*change to uniform label size*/
-        gtk_label_set_width_chars(GTK_LABEL(dd->label_disk), 32);
+        /*gtk_label_set_width_chars(GTK_LABEL(dd->label_disk), 32); */
         /* gtk_label_set_justify(GTK_LABEL(dd->label_disk),GTK_JUSTIFY_LEFT); */
         gtk_misc_set_alignment(GTK_MISC(dd->label_disk),0.0, 0.5);
         gtk_box_pack_start(GTK_BOX(dd->hbox),dd->label_disk,FALSE,TRUE,0);
 
         dd->label_mount_info = gtk_label_new("");
         /*change to uniform label size*/
-        gtk_label_set_width_chars(GTK_LABEL(dd->label_mount_info),25);
+        /* gtk_label_set_width_chars(GTK_LABEL(dd->label_mount_info),25); */
         gtk_label_set_use_markup(GTK_LABEL(dd->label_mount_info),TRUE);
         /* gtk_label_set_justify (GTK_LABEL(dd->label_mount_info),
                                GTK_JUSTIFY_RIGHT); */
@@ -181,14 +208,16 @@
 
 
 static void
-disk_display_refresh (t_disk_display * disk_display,
-                                 t_mount_info * mount_info)
+disk_display_refresh (t_disk_display * disk_display)
 {
+    t_mount_info * mount_info;
     char * text;
     char * used;
     char * size;
     char * avail;
 
+    mount_info = disk_display->disk->mount_info;
+
     TRACE("enters disk_display_refresh");
 
     if (disk_display != NULL)
@@ -260,7 +289,7 @@
     int i, res;
     t_disk * disk;
     t_disk_display * disk_display;
-    GPtrArray *array =  NULL;
+    GPtrArray *array =  NULL, *disk_displays = NULL;
     char *dev_mp; /* device or mountpoint */
     gboolean removed_device;
 
@@ -286,14 +315,15 @@
 
     /* menu with menu_item */
     mt->menu = gtk_menu_new ();
-
+    disk_displays =g_ptr_array_new();
     for (i=0; i < mt->pdisks->len; i++)
     {
-        disk = g_ptr_array_index (mt->pdisks,i); /* get the disk */
-        disk_display = disk_display_new (disk,mt); /* creates a disk_display */
-
+        disk = g_ptr_array_index (mt->pdisks, i); /* get the disk */
+        disk_display = disk_display_new (disk, mt); /* creates a disk_display */
+        disk_display->disk = disk;
+        g_ptr_array_add(disk_displays, disk_display);
         /* fill in mount infos */
-        disk_display_refresh (disk_display,disk->mount_info);
+        disk_display_refresh (disk_display);
 
         /* add the menu_item to the menu */
         gtk_menu_shell_append (GTK_MENU_SHELL(mt->menu),
@@ -301,6 +331,8 @@
     }
     gtk_widget_show_all(mt->menu);
 
+    disk_display_set_sizes(disk_displays);
+
     mt->icon = PACKAGE_DATA_DIR"/icons/hicolor/scalable/apps/xfce-mount.svg";
     mt->mount_command = DEFAULT_MOUNT_COMMAND;
     mt->umount_command = DEFAULT_UMOUNT_COMMAND;

Modified: xfce4-mount-plugin/trunk/panel-plugin/mount-plugin.h
===================================================================
--- xfce4-mount-plugin/trunk/panel-plugin/mount-plugin.h	2008-05-19 21:42:54 UTC (rev 4828)
+++ xfce4-mount-plugin/trunk/panel-plugin/mount-plugin.h	2008-05-19 21:50:42 UTC (rev 4829)
@@ -91,6 +91,7 @@
     GtkWidget * label_disk;
     GtkWidget * label_mount_info;
     GtkWidget * progress_bar;
+    t_disk *disk; /* People, learn to program in an object-oriented way! */
 } t_disk_display;
 
 




More information about the Goodies-commits mailing list