[Goodies-commits] r2474 - in xfce4-volstatus-icon/trunk: . po xfce4-volstatus-icon

Brian Tarricone kelnos at xfce.org
Fri Feb 2 02:23:56 CET 2007


Author: kelnos
Date: 2007-02-02 01:23:56 +0000 (Fri, 02 Feb 2007)
New Revision: 2474

Added:
   xfce4-volstatus-icon/trunk/po/xfce4-volstatus-icon.pot
   xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-common.c
   xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-common.h
   xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-dialog.c
   xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-dialog.h
Modified:
   xfce4-volstatus-icon/trunk/TODO
   xfce4-volstatus-icon/trunk/po/POTFILES.in
   xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/Makefile.am
   xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/main.c
   xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-icon.c
   xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-icon.h
Log:
* move common stuff to xfce-volstatus-common.{c,h}
* set window icon
* add dialog to show all volumes, info about them, and allow removal


Modified: xfce4-volstatus-icon/trunk/TODO
===================================================================
--- xfce4-volstatus-icon/trunk/TODO	2007-02-01 21:06:51 UTC (rev 2473)
+++ xfce4-volstatus-icon/trunk/TODO	2007-02-02 01:23:56 UTC (rev 2474)
@@ -2,3 +2,4 @@
   this even possible?  is thunar_vfs_volume_is_mounted() valid on the
   volumes-removed signal?
 * icon activate should pop up dialog with info about volumes
+* libnotify support?

Modified: xfce4-volstatus-icon/trunk/po/POTFILES.in
===================================================================
--- xfce4-volstatus-icon/trunk/po/POTFILES.in	2007-02-01 21:06:51 UTC (rev 2473)
+++ xfce4-volstatus-icon/trunk/po/POTFILES.in	2007-02-02 01:23:56 UTC (rev 2474)
@@ -1 +1,3 @@
+xfce4-volstatus-icon/xfce-volstatus-common.c
+xfce4-volstatus-icon/xfce-volstatus-dialog.c
 xfce4-volstatus-icon/xfce-volstatus-icon.c

Added: xfce4-volstatus-icon/trunk/po/xfce4-volstatus-icon.pot
===================================================================
--- xfce4-volstatus-icon/trunk/po/xfce4-volstatus-icon.pot	                        (rev 0)
+++ xfce4-volstatus-icon/trunk/po/xfce4-volstatus-icon.pot	2007-02-02 01:23:56 UTC (rev 2474)
@@ -0,0 +1,116 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-02-01 17:22-0800\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+"Language-Team: LANGUAGE <LL at li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: xfce4-volstatus-icon/xfce-volstatus-common.c:42
+#, c-format
+msgid "Unable to remove \"%s\""
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-common.c:44
+msgid "Removal Failure"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:111
+msgid "Data CD"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:113
+msgid "Recordable CD"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:115
+msgid "Rewritable CD"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:117
+msgid "Data or Video DVD"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:119
+msgid "Rewritable DVD (DVD-RAM)"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:122
+msgid "Recordable DVD"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:125
+msgid "Rewritable DVD"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:127
+msgid "Floppy Disk"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:129
+msgid "Hard Disk"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:131
+msgid "USB Flash Disk"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:133
+msgid "Audio Player"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:135
+msgid "Audio CD"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:137
+msgid "Memory Card"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:139
+msgid "Disk"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:142
+msgid "Unknown"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:316
+msgid "Name:"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:321
+msgid "Kind:"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:326
+msgid "Mount Point:"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:371
+msgid "Removable Volumes"
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-dialog.c:372
+msgid "Use the list below to safely remove removable volumes."
+msgstr ""
+
+#: xfce4-volstatus-icon/xfce-volstatus-icon.c:172
+#, c-format
+msgid "Safely remove \"%s\""
+msgstr ""
+
+#. this shouldn't happen, but just to be safe...
+#: xfce4-volstatus-icon/xfce-volstatus-icon.c:189
+msgid "(no removable volumes"
+msgstr ""

Modified: xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/Makefile.am
===================================================================
--- xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/Makefile.am	2007-02-01 21:06:51 UTC (rev 2473)
+++ xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/Makefile.am	2007-02-02 01:23:56 UTC (rev 2474)
@@ -2,6 +2,10 @@
 
 xfce4_volstatus_icon_SOURCES = \
 	main.c \
+	xfce-volstatus-common.c \
+	xfce-volstatus-common.h \
+	xfce-volstatus-dialog.c \
+	xfce-volstatus-dialog.h \
 	xfce-volstatus-icon.c \
 	xfce-volstatus-icon.h
 

Modified: xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/main.c
===================================================================
--- xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/main.c	2007-02-01 21:06:51 UTC (rev 2473)
+++ xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/main.c	2007-02-02 01:23:56 UTC (rev 2474)
@@ -31,6 +31,7 @@
 
 #include <thunar-vfs/thunar-vfs.h>
 
+#include "xfce-volstatus-common.h"
 #include "xfce-volstatus-icon.h"
 
 
@@ -96,6 +97,7 @@
 main(int argc,
      char **argv)
 {
+    const gchar *icon_name;
     GtkStatusIcon *icon;
     ThunarVfsVolumeManager *manager;
     GList *volumes;
@@ -106,6 +108,10 @@
     gtk_init(&argc, &argv);
     thunar_vfs_init();
     
+    icon_name = xfce_volstatus_get_icon_name();
+    if(icon_name)
+        gtk_window_set_default_icon_name(icon_name);
+    
     icon = xfce_volstatus_icon_new(NULL);
     gtk_status_icon_set_visible(icon, FALSE);
     

Added: xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-common.c
===================================================================
--- xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-common.c	                        (rev 0)
+++ xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-common.c	2007-02-02 01:23:56 UTC (rev 2474)
@@ -0,0 +1,66 @@
+/*
+ *  xfce4-volstatus-icon
+ *
+ *  Copyright (c) 2006 Brian Tarricone <bjt23 at cornell.edu>
+ *
+ *  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; version 2 of the License ONLY.
+ *
+ *  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 Library 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <libxfcegui4/libxfcegui4.h>
+
+#include "xfce-volstatus-common.h"
+
+gboolean
+xfce_volstatus_remove_volume(ThunarVfsVolume *volume)
+{
+    gboolean ret = TRUE;
+    GError *error = NULL;
+    
+    g_return_val_if_fail(THUNAR_VFS_IS_VOLUME(volume), FALSE);
+    
+    if(thunar_vfs_volume_is_ejectable(volume))
+        ret = thunar_vfs_volume_eject(volume, NULL, &error);
+    else if(thunar_vfs_volume_is_mounted(volume))
+        ret = thunar_vfs_volume_unmount(volume, NULL, &error);
+    
+    if(!ret && error) {
+        gchar *primary = g_strdup_printf(_("Unable to remove \"%s\""),
+                                         thunar_vfs_volume_get_name(volume));
+        xfce_message_dialog(NULL, _("Removal Failure"),
+                            GTK_STOCK_DIALOG_WARNING, primary, error->message,
+                            GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+        g_free(primary);
+        g_error_free(error);
+    }
+    
+    return ret;
+}
+
+const gchar *
+xfce_volstatus_get_icon_name()
+{
+    const gchar *icon_name = NULL;
+    GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
+    
+    if(gtk_icon_theme_has_icon(icon_theme, "drive-removable-media"))
+        icon_name = "drive-removable-media";
+    else if(gtk_icon_theme_has_icon(icon_theme, "gnome-dev-removable"))
+        icon_name = "gnome-dev-removable";
+    
+    return icon_name;
+}

Added: xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-common.h
===================================================================
--- xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-common.h	                        (rev 0)
+++ xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-common.h	2007-02-02 01:23:56 UTC (rev 2474)
@@ -0,0 +1,33 @@
+/*
+ *  xfce4-volstatus-icon
+ *
+ *  Copyright (c) 2006 Brian Tarricone <bjt23 at cornell.edu>
+ *
+ *  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; version 2 of the License ONLY.
+ *
+ *  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 Library 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.
+ */
+
+#ifndef __XFCE_VOLSTATUS_COMMON_H
+#define __XFCE_VOLSTATUS_COMMON_H
+
+#include <thunar-vfs/thunar-vfs.h>
+
+G_BEGIN_DECLS
+
+gboolean xfce_volstatus_remove_volume(ThunarVfsVolume *volume);
+
+const gchar *xfce_volstatus_get_icon_name();
+
+G_END_DECLS
+
+#endif  /* __XFCE_VOLSTATUS_COMMON_H */

Added: xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-dialog.c
===================================================================
--- xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-dialog.c	                        (rev 0)
+++ xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-dialog.c	2007-02-02 01:23:56 UTC (rev 2474)
@@ -0,0 +1,389 @@
+/*
+ *  xfce4-volstatus-icon
+ *
+ *  Copyright (c) 2006 Brian Tarricone <bjt23 at cornell.edu>
+ *
+ *  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; version 2 of the License ONLY.
+ *
+ *  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 Library 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <libxfcegui4/libxfcegui4.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "xfce-volstatus-common.h"
+#include "xfce-volstatus-dialog.h"
+
+#define BORDER 8
+
+
+struct _XfceVolstatusDialog
+{
+    XfceTitledDialog parent;
+    
+    XfceVolstatusIcon *icon;
+    
+    GtkListStore *ls;
+    GtkWidget *treeview;
+    
+    GtkWidget *name_lbl;
+    GtkWidget *kind_lbl;
+    GtkWidget *mntpt_lbl;
+};
+
+typedef struct _XfceVolstatusDialogClass
+{
+    XfceTitledDialogClass parent;
+} XfceVolstatusDialogClass;
+
+enum
+{
+    COL_PIXBUF = 0,
+    COL_NAME,
+    COL_VOLUME,
+};
+
+
+static void xfce_volstatus_dialog_class_init(XfceVolstatusDialogClass *klass);
+
+static void xfce_volstatus_dialog_init(XfceVolstatusDialog *dialog);
+static void xfce_volstatus_dialog_finalize(GObject *obj);
+
+static void xfce_volstatus_dialog_volume_added(XfceVolstatusIcon *icon,
+                                               ThunarVfsVolume *volume,
+                                               gpointer user_data);
+static void xfce_volstatus_dialog_volume_removed(XfceVolstatusIcon *icon,
+                                                 ThunarVfsVolume *volume,
+                                                 gpointer user_data);
+
+
+G_DEFINE_TYPE(XfceVolstatusDialog, xfce_volstatus_dialog, XFCE_TYPE_TITLED_DIALOG)
+
+
+static void
+xfce_volstatus_dialog_class_init(XfceVolstatusDialogClass *klass)
+{
+    GObjectClass *object_class = (GObjectClass *)klass;
+    
+    object_class->finalize = xfce_volstatus_dialog_finalize;
+}
+
+static void
+xfce_volstatus_dialog_init(XfceVolstatusDialog *dialog)
+{
+    
+}
+
+static void
+xfce_volstatus_dialog_finalize(GObject *obj)
+{
+    XfceVolstatusDialog *dialog = XFCE_VOLSTATUS_DIALOG(obj);
+    
+    g_signal_handlers_disconnect_by_func(G_OBJECT(dialog->icon),
+                                         G_CALLBACK(xfce_volstatus_dialog_volume_added),
+                                         dialog);
+    g_signal_handlers_disconnect_by_func(G_OBJECT(dialog->icon),
+                                         G_CALLBACK(xfce_volstatus_dialog_volume_removed),
+                                         dialog);
+    
+    G_OBJECT_CLASS(xfce_volstatus_dialog_parent_class)->finalize(obj);
+}
+
+
+static const gchar *
+xfce_volstatus_volkind_to_string(ThunarVfsVolumeKind kind)
+{
+    switch(kind) {
+        case THUNAR_VFS_VOLUME_KIND_CDROM:
+            return _("Data CD");
+        case THUNAR_VFS_VOLUME_KIND_CDR:
+            return _("Recordable CD");
+        case THUNAR_VFS_VOLUME_KIND_CDRW:
+            return _("Rewritable CD");
+        case THUNAR_VFS_VOLUME_KIND_DVDROM:
+            return _("Data or Video DVD");
+        case THUNAR_VFS_VOLUME_KIND_DVDRAM:
+            return _("Rewritable DVD (DVD-RAM)");
+        case THUNAR_VFS_VOLUME_KIND_DVDR:
+        case THUNAR_VFS_VOLUME_KIND_DVDPLUSR:
+            return _("Recordable DVD");
+        case THUNAR_VFS_VOLUME_KIND_DVDRW:
+        case THUNAR_VFS_VOLUME_KIND_DVDPLUSRW:
+            return _("Rewritable DVD");
+        case THUNAR_VFS_VOLUME_KIND_FLOPPY:
+            return _("Floppy Disk");
+        case THUNAR_VFS_VOLUME_KIND_HARDDISK:
+            return _("Hard Disk");
+        case THUNAR_VFS_VOLUME_KIND_USBSTICK:
+            return _("USB Flash Disk");
+        case THUNAR_VFS_VOLUME_KIND_AUDIO_PLAYER:
+            return _("Audio Player");
+        case THUNAR_VFS_VOLUME_KIND_AUDIO_CD:
+            return _("Audio CD");
+        case THUNAR_VFS_VOLUME_KIND_MEMORY_CARD:
+            return _("Memory Card");
+        case THUNAR_VFS_VOLUME_KIND_REMOVABLE_DISK:
+            return _("Disk");
+        case THUNAR_VFS_VOLUME_KIND_UNKNOWN:
+        default:
+            return _("Unknown");
+    }
+}
+
+static void
+xfce_volstatus_dialog_volume_added(XfceVolstatusIcon *icon,
+                                   ThunarVfsVolume *volume,
+                                   gpointer user_data)
+{
+    XfceVolstatusDialog *dialog = XFCE_VOLSTATUS_DIALOG(user_data);
+    GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
+    const gchar *icon_name;
+    gint w, h;
+    GdkPixbuf *pix = NULL;
+    GtkTreeIter iter;
+    
+    icon_name = thunar_vfs_volume_lookup_icon_name(volume, icon_theme);
+    if(icon_name) {
+        gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &w, &h);
+        pix = xfce_themed_icon_load(icon_name, w);
+    }
+    
+    gtk_list_store_append(dialog->ls, &iter);
+    gtk_list_store_set(dialog->ls, &iter,
+                       COL_PIXBUF, pix,
+                       COL_NAME, thunar_vfs_volume_get_name(volume),
+                       COL_VOLUME, volume,
+                       -1);
+}
+
+static void
+xfce_volstatus_dialog_volume_removed(XfceVolstatusIcon *icon,
+                                     ThunarVfsVolume *volume,
+                                     gpointer user_data)
+{
+    XfceVolstatusDialog *dialog = XFCE_VOLSTATUS_DIALOG(user_data);
+    GtkTreeIter iter;
+    ThunarVfsVolume *a_volume;
+    
+    /* FIXME: this is pretty inefficient */
+    
+    if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dialog->ls), &iter))
+        return;
+    
+    do {
+        gtk_tree_model_get(GTK_TREE_MODEL(dialog->ls), &iter,
+                           COL_VOLUME, &a_volume,
+                           -1);
+        if(a_volume == volume) {
+            gtk_list_store_remove(dialog->ls, &iter);
+            break;
+        }
+    } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(dialog->ls), &iter));
+}
+
+static void
+xfce_volstatus_dialog_remove_clicked(GtkWidget *widget,
+                                     gpointer user_data)
+{
+    XfceVolstatusDialog *dialog = XFCE_VOLSTATUS_DIALOG(user_data);
+    GtkTreeSelection *sel;
+    GtkTreeIter iter;
+    ThunarVfsVolume *volume = NULL;
+    
+    sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview));
+    if(!gtk_tree_selection_get_selected(sel, NULL, &iter))
+        return;
+    
+    gtk_tree_model_get(GTK_TREE_MODEL(dialog->ls), &iter,
+                       COL_VOLUME, &volume,
+                       -1);
+    if(!volume)
+        return;
+    
+    xfce_volstatus_remove_volume(volume);
+}
+
+static void
+xfce_volstatus_dialog_tree_selection_changed(GtkTreeSelection *sel,
+                                             gpointer user_data)
+{
+    XfceVolstatusDialog *dialog = XFCE_VOLSTATUS_DIALOG(user_data);
+    GtkTreeIter iter;
+    ThunarVfsVolume *volume = NULL;
+    
+    if(!gtk_tree_selection_get_selected(sel, NULL, &iter)) {
+        gtk_label_set_text(GTK_LABEL(dialog->name_lbl), "");
+        gtk_label_set_text(GTK_LABEL(dialog->kind_lbl), "");
+        gtk_label_set_text(GTK_LABEL(dialog->mntpt_lbl), "");
+    } else {
+        ThunarVfsPath *path;
+        
+        gtk_tree_model_get(GTK_TREE_MODEL(dialog->ls), &iter,
+                           COL_VOLUME, &volume,
+                           -1);
+        
+        gtk_label_set_text(GTK_LABEL(dialog->name_lbl),
+                                     thunar_vfs_volume_get_name(volume));
+        gtk_label_set_text(GTK_LABEL(dialog->kind_lbl),
+                           xfce_volstatus_volkind_to_string(thunar_vfs_volume_get_kind(volume)));
+        
+        path = thunar_vfs_volume_get_mount_point(volume);
+        if(path) {
+            gchar *path_str = thunar_vfs_path_dup_string(path);
+            gtk_label_set_text(GTK_LABEL(dialog->mntpt_lbl), path_str);
+            g_free(path_str);
+        } else
+            gtk_label_set_text(GTK_LABEL(dialog->mntpt_lbl), "");
+    }
+}
+
+static void
+xfce_volstatus_dialog_create(XfceVolstatusDialog *dialog)
+{
+    GtkWidget *topvbox, *hbox, *sw, *treeview, *btn, *table, *lbl;
+    GtkListStore *ls;
+    GtkTreeViewColumn *col;
+    GtkCellRenderer *render;
+    GtkTreeSelection *sel;
+    
+#if GTK_CHECK_VERSION(2, 12, 0)
+    gtk_window_set_screen(GTK_WINDOW(dialog),
+                          gtk_status_icon_get_screen(GTK_STATUS_ICON(dialog->icon)));
+#endif
+    
+    topvbox = GTK_DIALOG(dialog)->vbox;
+    gtk_container_set_border_width(GTK_CONTAINER(topvbox), BORDER);
+    gtk_box_set_spacing(GTK_BOX(topvbox), BORDER);
+    
+    sw = gtk_scrolled_window_new(NULL, NULL);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
+                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
+                                        GTK_SHADOW_ETCHED_IN);
+    gtk_widget_show(sw);
+    gtk_box_pack_start(GTK_BOX(topvbox), sw, TRUE, TRUE, 0);
+    
+    ls = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING,
+                            THUNAR_VFS_TYPE_VOLUME);
+    treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls));
+    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
+    gtk_widget_show(treeview);
+    gtk_container_add(GTK_CONTAINER(sw), treeview);
+    
+    col = gtk_tree_view_column_new();
+    render = gtk_cell_renderer_pixbuf_new();
+    gtk_tree_view_column_pack_start(col, render, FALSE);
+    gtk_tree_view_column_set_attributes(col, render,
+                                        "pixbuf", COL_PIXBUF, NULL);
+    render = gtk_cell_renderer_text_new();
+    gtk_tree_view_column_pack_start(col, render, TRUE);
+    gtk_tree_view_column_set_attributes(col, render, "text", COL_NAME, NULL);
+    g_object_set(G_OBJECT(render),
+                 "ellipsize", PANGO_ELLIPSIZE_END,
+                 "ellipsize-set", TRUE,
+                 "editable", FALSE,
+                 "editable-set", TRUE,
+                 NULL);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
+    
+    hbox = gtk_hbox_new(FALSE, BORDER);
+    gtk_widget_show(hbox);
+    gtk_box_pack_start(GTK_BOX(topvbox), hbox, FALSE, FALSE, 0);
+    
+    btn = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
+    gtk_widget_show(btn);
+    gtk_box_pack_end(GTK_BOX(hbox), btn, FALSE, FALSE, 0);
+    g_signal_connect(G_OBJECT(btn), "clicked",
+                     G_CALLBACK(xfce_volstatus_dialog_remove_clicked), dialog);
+    
+    table = gtk_table_new(3, 2, FALSE);
+    gtk_widget_show(table);
+    gtk_box_pack_start(GTK_BOX(topvbox), table, FALSE, FALSE, 0);
+    
+    lbl = gtk_label_new(_("Name:"));
+    gtk_misc_set_alignment(GTK_MISC(lbl), 0.0, 0.5);
+    gtk_widget_show(lbl);
+    gtk_table_attach_defaults(GTK_TABLE(table), lbl, 0, 1, 0, 1);
+    
+    lbl = gtk_label_new(_("Kind:"));
+    gtk_misc_set_alignment(GTK_MISC(lbl), 0.0, 0.5);
+    gtk_widget_show(lbl);
+    gtk_table_attach_defaults(GTK_TABLE(table), lbl, 0, 1, 1, 2);
+    
+    lbl = gtk_label_new(_("Mount Point:"));
+    gtk_misc_set_alignment(GTK_MISC(lbl), 0.0, 0.5);
+    gtk_widget_show(lbl);
+    gtk_table_attach_defaults(GTK_TABLE(table), lbl, 0, 1, 2, 3);
+    
+    dialog->name_lbl = gtk_label_new("");
+    gtk_misc_set_alignment(GTK_MISC(dialog->name_lbl), 0.0, 0.5);
+    gtk_widget_show(dialog->name_lbl);
+    gtk_table_attach_defaults(GTK_TABLE(table), dialog->name_lbl, 1, 2, 0, 1);
+    
+    dialog->kind_lbl = gtk_label_new("");
+    gtk_misc_set_alignment(GTK_MISC(dialog->kind_lbl), 0.0, 0.5);
+    gtk_widget_show(dialog->kind_lbl);
+    gtk_table_attach_defaults(GTK_TABLE(table), dialog->kind_lbl, 1, 2, 1, 2);
+    
+    dialog->mntpt_lbl = gtk_label_new("");
+    gtk_misc_set_alignment(GTK_MISC(dialog->mntpt_lbl), 0.0, 0.5);
+    gtk_widget_show(dialog->mntpt_lbl);
+    gtk_table_attach_defaults(GTK_TABLE(table), dialog->mntpt_lbl, 1, 2, 2, 3);
+    
+    gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE,
+                          GTK_RESPONSE_ACCEPT);
+    g_signal_connect(G_OBJECT(dialog), "response",
+                     G_CALLBACK(gtk_widget_destroy), NULL);
+    
+    dialog->ls = ls;
+    dialog->treeview = treeview;
+    
+    sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
+    gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
+    g_signal_connect(G_OBJECT(sel), "changed",
+                     G_CALLBACK(xfce_volstatus_dialog_tree_selection_changed),
+                     dialog);
+}
+
+
+
+/*
+ * public api
+ */
+GtkWidget *
+xfce_volstatus_dialog_new(XfceVolstatusIcon *icon)
+{
+    XfceVolstatusDialog *dialog =  g_object_new(XFCE_TYPE_VOLSTATUS_DIALOG,
+                                                "has-separator", FALSE,
+                                                "title", _("Removable Volumes"),
+                                                "subtitle", _("Use the list below to safely remove removable volumes."),
+                                                NULL);
+    GList *volumes, *l;
+    
+    dialog->icon = icon;
+    xfce_volstatus_dialog_create(dialog);
+    
+    volumes = xfce_volstatus_icon_list_volumes(dialog->icon);
+    for(l = volumes; l; l = l->next)
+        xfce_volstatus_dialog_volume_added(icon, l->data, dialog);
+    
+    g_signal_connect(G_OBJECT(icon), "volume-added",
+                     G_CALLBACK(xfce_volstatus_dialog_volume_added), dialog);
+    g_signal_connect(G_OBJECT(icon), "volume-removed",
+                     G_CALLBACK(xfce_volstatus_dialog_volume_removed), dialog);
+    
+    return GTK_WIDGET(dialog);
+}

Added: xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-dialog.h
===================================================================
--- xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-dialog.h	                        (rev 0)
+++ xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-dialog.h	2007-02-02 01:23:56 UTC (rev 2474)
@@ -0,0 +1,41 @@
+/*
+ *  xfce4-volstatus-icon
+ *
+ *  Copyright (c) 2006 Brian Tarricone <bjt23 at cornell.edu>
+ *
+ *  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; version 2 of the License ONLY.
+ *
+ *  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 Library 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.
+ */
+
+#ifndef __XFCE_VOLSTATUS_DIALOG_H__
+#define __XFCE_VOLSTATUS_DIALOG_H__
+
+#include <gtk/gtk.h>
+
+#include "xfce-volstatus-icon.h"
+
+#define XFCE_TYPE_VOLSTATUS_DIALOG     (xfce_volstatus_dialog_get_type())
+#define XFCE_VOLSTATUS_DIALOG(obj)     (G_TYPE_CHECK_INSTANCE_CAST((obj), XFCE_TYPE_VOLSTATUS_DIALOG, XfceVolstatusDialog))
+#define XFCE_IS_VOLSTATUS_DIALOG(obj)  (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFCE_TYPE_VOLSTATUS_DIALOG))
+
+G_BEGIN_DECLS
+
+typedef struct _XfceVolstatusDialog XfceVolstatusDialog;
+
+GType xfce_volstatus_dialog_get_type() G_GNUC_CONST;
+
+GtkWidget *xfce_volstatus_dialog_new(XfceVolstatusIcon *icon);
+
+G_END_DECLS
+
+#endif  /* __XFCE_VOLSTATUS_DIALOG_H__ */

Modified: xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-icon.c
===================================================================
--- xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-icon.c	2007-02-01 21:06:51 UTC (rev 2473)
+++ xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-icon.c	2007-02-02 01:23:56 UTC (rev 2474)
@@ -23,6 +23,8 @@
 
 #include <libxfcegui4/libxfcegui4.h>
 
+#include "xfce-volstatus-dialog.h"
+#include "xfce-volstatus-common.h"
 #include "xfce-volstatus-icon.h"
 
 
@@ -31,13 +33,27 @@
     GtkStatusIcon parent;
     
     GList *volumes;
+    GtkWidget *status_dialog;
 };
 
 typedef struct _XfceVolstatusIconClass
 {
     GtkStatusIconClass parent;
+    
+    /*< signals >*/
+    void (*volume_added)(XfceVolstatusIcon *icon,
+                         ThunarVfsVolume *volume);
+    void (*volume_removed)(XfceVolstatusIcon *icon,
+                           ThunarVfsVolume *volume);
 } XfceVolstatusIconClass;
 
+enum
+{
+    SIG_VOLUME_ADDED = 0,
+    SIG_VOLUME_REMOVED,
+    N_SIGS,
+};
+
 static void xfce_volstatus_icon_class_init(XfceVolstatusIconClass *klass);
 
 static void xfce_volstatus_icon_init(XfceVolstatusIcon *icon);
@@ -53,7 +69,9 @@
 static void xfce_volstatus_icon_volume_activate(GtkMenuItem *mi,
                                                 gpointer user_data);
 
+static guint xvsi_signals[N_SIGS] = { 0, };
 
+
 G_DEFINE_TYPE(XfceVolstatusIcon, xfce_volstatus_icon, GTK_TYPE_STATUS_ICON)
 
 
@@ -67,6 +85,26 @@
     
     icon_class->activate = xfce_volstatus_icon_activate;
     icon_class->popup_menu = xfce_volstatus_icon_popup_menu;
+    
+    xvsi_signals[SIG_VOLUME_ADDED] = g_signal_new("volume-added",
+                                                  XFCE_TYPE_VOLSTATUS_ICON,
+                                                  G_SIGNAL_RUN_LAST,
+                                                  G_STRUCT_OFFSET(XfceVolstatusIconClass,
+                                                                  volume_added),
+                                                  NULL, NULL,
+                                                  g_cclosure_marshal_VOID__OBJECT,
+                                                  G_TYPE_NONE, 1,
+                                                  THUNAR_VFS_TYPE_VOLUME);
+    
+    xvsi_signals[SIG_VOLUME_REMOVED] = g_signal_new("volume-removed",
+                                                    XFCE_TYPE_VOLSTATUS_ICON,
+                                                    G_SIGNAL_RUN_LAST,
+                                                    G_STRUCT_OFFSET(XfceVolstatusIconClass,
+                                                                    volume_removed),
+                                                    NULL, NULL,
+                                                    g_cclosure_marshal_VOID__OBJECT,
+                                                    G_TYPE_NONE, 1,
+                                                    THUNAR_VFS_TYPE_VOLUME);
 }
 
 static void
@@ -80,6 +118,12 @@
 {
     XfceVolstatusIcon *icon = XFCE_VOLSTATUS_ICON(obj);
     
+    if(icon->status_dialog) {
+        g_object_remove_weak_pointer(G_OBJECT(icon->status_dialog),
+                                     (gpointer)&icon->status_dialog);
+        gtk_widget_destroy(icon->status_dialog);
+    }
+    
     g_list_foreach(icon->volumes, (GFunc)g_object_unref, NULL);
     g_list_free(icon->volumes);
     
@@ -90,7 +134,17 @@
 static void
 xfce_volstatus_icon_activate(GtkStatusIcon *status_icon)
 {
-    /* FIXME: bring up a dialog with a list of stuff */
+    XfceVolstatusIcon *icon = XFCE_VOLSTATUS_ICON(status_icon);
+    
+    if(icon->status_dialog)
+        gtk_window_present(GTK_WINDOW(icon->status_dialog));
+    else {
+        icon->status_dialog = xfce_volstatus_dialog_new(icon);
+        gtk_widget_show(icon->status_dialog);
+        
+        g_object_add_weak_pointer(G_OBJECT(icon->status_dialog),
+                                  (gpointer)&icon->status_dialog);
+    }
 }
 
 static void
@@ -165,25 +219,7 @@
 {
     ThunarVfsVolume *volume = g_object_get_data(G_OBJECT(mi),
                                                 "thunar-vfs-volume");
-    gboolean ret = TRUE;
-    GError *error = NULL;
-    
-    g_return_if_fail(THUNAR_VFS_IS_VOLUME(volume));
-    
-    if(thunar_vfs_volume_is_ejectable(volume))
-        ret = thunar_vfs_volume_eject(volume, NULL, &error);
-    else if(thunar_vfs_volume_is_mounted(volume))
-        ret = thunar_vfs_volume_unmount(volume, NULL, &error);
-    
-    if(!ret && error) {
-        gchar *primary = g_strdup_printf(_("Unable to remove \"%s\""),
-                                         thunar_vfs_volume_get_name(volume));
-        xfce_message_dialog(NULL, _("Removal Failure"),
-                            GTK_STOCK_DIALOG_WARNING, primary, error->message,
-                            GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
-        g_free(primary);
-        g_error_free(error);
-    }
+    xfce_volstatus_remove_volume(volume);
 }
 
 
@@ -195,17 +231,11 @@
 GtkStatusIcon *
 xfce_volstatus_icon_new(GdkScreen *screen)
 {
-    GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
-    const gchar *icon_name = NULL;
+    const gchar *icon_name = xfce_volstatus_get_icon_name();
     
     if(!screen)
         screen = gdk_display_get_default_screen(gdk_display_get_default());
     
-    if(gtk_icon_theme_has_icon(icon_theme, "drive-removable-media"))
-        icon_name = "drive-removable-media";
-    else if(gtk_icon_theme_has_icon(icon_theme, "gnome-dev-removable"))
-        icon_name = "gnome-dev-removable";
-    
     return g_object_new(XFCE_TYPE_VOLSTATUS_ICON,
 #if GTK_CHECK_VERSION(2, 12, 0)
                         "screen", screen,
@@ -230,6 +260,8 @@
     
     g_object_ref(G_OBJECT(volume));
     icon->volumes = g_list_prepend(icon->volumes, volume);
+    
+    g_signal_emit(G_OBJECT(icon), xvsi_signals[SIG_VOLUME_ADDED], 0, volume);
 }
 
 void
@@ -243,8 +275,18 @@
         return;
     
     icon->volumes = g_list_remove(icon->volumes, volume);
+    
+    g_signal_emit(G_OBJECT(icon), xvsi_signals[SIG_VOLUME_REMOVED], 0, volume);
+    
     g_object_unref(G_OBJECT(volume));
     
     if(!icon->volumes)
         gtk_status_icon_set_visible(GTK_STATUS_ICON(icon), FALSE);
 }
+
+GList *
+xfce_volstatus_icon_list_volumes(XfceVolstatusIcon *icon)
+{
+    g_return_val_if_fail(XFCE_IS_VOLSTATUS_ICON(icon), NULL);
+    return icon->volumes;
+}

Modified: xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-icon.h
===================================================================
--- xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-icon.h	2007-02-01 21:06:51 UTC (rev 2473)
+++ xfce4-volstatus-icon/trunk/xfce4-volstatus-icon/xfce-volstatus-icon.h	2007-02-02 01:23:56 UTC (rev 2474)
@@ -40,6 +40,7 @@
                                     ThunarVfsVolume *volume);
 void xfce_volstatus_icon_remove_volume(XfceVolstatusIcon *icon,
                                        ThunarVfsVolume *volume);
+GList *xfce_volstatus_icon_list_volumes(XfceVolstatusIcon *icon);
 
 
 G_END_DECLS




More information about the Goodies-commits mailing list