summaryrefslogtreecommitdiff
path: root/src
diff options
authorStefano Candori <stefano.candori@gmail.com>2011-01-28 11:09:52 +0100
committerStefano Candori <stefano.candori@gmail.com>2011-01-28 11:09:52 +0100
commit8e3013367737a9857418c26c7b2a09b45d216701 (patch)
treed3181d41c7d73857564fadd87b5f53befe9e759c /src
parentc25c21944e7390e0a775ab85e1e8acd8b268267b (diff)
Added quicklist for trashbin
(bzr r798.3.1)
Diffstat (limited to 'src')
-rw-r--r--src/TrashLauncherIcon.cpp121
-rw-r--r--src/TrashLauncherIcon.h8
2 files changed, 127 insertions, 2 deletions
diff --git a/src/TrashLauncherIcon.cpp b/src/TrashLauncherIcon.cpp
index ffb2b3dd7..2c09bae47 100644
--- a/src/TrashLauncherIcon.cpp
+++ b/src/TrashLauncherIcon.cpp
@@ -18,6 +18,11 @@
*/
#include "TrashLauncherIcon.h"
+#include "Launcher.h"
+#include "Nux/WindowCompositor.h"
+
+#include "QuicklistManager.h"
+#include "QuicklistMenuItemLabel.h"
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
@@ -62,6 +67,29 @@ TrashLauncherIcon::GlowColor ()
}
void
+TrashLauncherIcon::EnsureMenuItemsReady ()
+{
+ DbusmenuMenuitem *menu_item;
+
+ /* Empty Trash */
+ if (_menu_items.find ("Empty") == _menu_items.end ())
+ {
+ menu_item = dbusmenu_menuitem_new ();
+ g_object_ref (menu_item);
+
+ dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Empty Trash"));
+ dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
+ dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
+
+ g_signal_connect (menu_item,
+ DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
+ (GCallback)&TrashLauncherIcon::OnEmptyTrash, this);
+
+ _menu_items["Empty"] = menu_item;
+ }
+}
+
+void
TrashLauncherIcon::OnMouseClick (int button)
{
SimpleLauncherIcon::OnMouseClick (button);
@@ -75,6 +103,90 @@ TrashLauncherIcon::OnMouseClick (int button)
if (error)
g_error_free (error);
}
+ else if (button == 3 && _empty == FALSE)
+ {
+ EnsureMenuItemsReady ();
+
+ _quicklist->RemoveAllMenuItem ();
+ QuicklistMenuItemLabel* item = new QuicklistMenuItemLabel (_menu_items["Empty"], NUX_TRACKER_LOCATION);
+ _quicklist->AddMenuItem (item);
+
+ int tip_x = _launcher->GetBaseWidth () + 1; //icon_x + icon_w;
+ nux::Point3 center = GetCenter ();
+ int tip_y = center.y;
+ QuicklistManager::Default ()->ShowQuicklist (_quicklist, tip_x, tip_y);
+ nux::GetWindowCompositor ().SetAlwaysOnFrontWindow (_quicklist);
+ }
+}
+
+void
+TrashLauncherIcon::OnEmptyTrash(DbusmenuMenuitem *item, int time, TrashLauncherIcon *self)
+{
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_CANCEL,
+ NULL);
+
+ g_object_set (GTK_DIALOG (dialog),
+ "text", _("Empty all items from Trash?"),
+ "secondary-text", _("All items in the Trash will be permanently deleted."),
+ NULL);
+ gtk_dialog_add_button (GTK_DIALOG (dialog), "Empty Trash", GTK_RESPONSE_OK );
+
+ QuicklistManager::Default ()->HideQuicklist (self->_quicklist);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+ g_thread_create ((GThreadFunc)&TrashLauncherIcon::EmptyTrashAction, NULL, FALSE, NULL);
+
+ gtk_widget_destroy (dialog);
+
+}
+
+void
+TrashLauncherIcon::EmptyTrashAction()
+{
+ // This function runs in a different thread
+ // created in TrashLauncherIcon::OnEmptyTrash
+ GFile *location;
+ location = g_file_new_for_uri ("trash:///");
+
+ RecursiveDelete (location);
+
+ g_object_unref (location);
+
+}
+void
+TrashLauncherIcon::RecursiveDelete(GFile *location)
+{
+
+ GFileInfo *info;
+ GFile *child;
+ GFileEnumerator *enumerator;
+
+ enumerator = g_file_enumerate_children (location,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL,
+ NULL);
+ if (enumerator)
+ {
+ while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
+ {
+ child = g_file_get_child (location, g_file_info_get_name (info));
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) RecursiveDelete (child);
+
+ g_file_delete (child, NULL, NULL);
+ g_object_unref (child);
+ g_object_unref (info);
+
+ }
+
+ g_file_enumerator_close (enumerator, NULL, NULL);
+ g_object_unref (enumerator);
+ }
+
}
void
@@ -91,7 +203,7 @@ TrashLauncherIcon::UpdateTrashIcon ()
&TrashLauncherIcon::UpdateTrashIconCb,
this);
- g_object_unref(location);
+ g_object_unref (location);
}
void
@@ -102,12 +214,17 @@ TrashLauncherIcon::UpdateTrashIconCb (GObject *source,
TrashLauncherIcon *self = (TrashLauncherIcon*) data;
GFileInfo *info;
GIcon *icon;
+ gchar *icon_name;
info = g_file_query_info_finish (G_FILE (source), res, NULL);
if (info != NULL) {
icon = g_file_info_get_icon (info);
- self->SetIconName (g_icon_to_string (icon));
+ icon_name = g_icon_to_string (icon);
+ self->SetIconName (icon_name);
+
+ if (g_strcmp0 (icon_name, "user-trash") == 0) self->_empty = TRUE;
+ else self->_empty = FALSE;
g_object_unref(info);
}
diff --git a/src/TrashLauncherIcon.h b/src/TrashLauncherIcon.h
index b47c85080..030809098 100644
--- a/src/TrashLauncherIcon.h
+++ b/src/TrashLauncherIcon.h
@@ -37,10 +37,18 @@ protected:
void UpdateTrashIcon ();
private:
+ std::map<std::string, DbusmenuMenuitem *> _menu_items;
GFileMonitor *m_TrashMonitor;
+ gboolean _empty;
+
+ void EnsureMenuItemsReady ();
+
static void UpdateTrashIconCb (GObject *source, GAsyncResult *res, gpointer data);
static void OnTrashChanged (GFileMonitor *monitor, GFile *file, GFile *other_file,
GFileMonitorEvent event_type, gpointer data);
+ static void OnEmptyTrash (DbusmenuMenuitem *item, int time, TrashLauncherIcon *self);
+ static void EmptyTrashAction ();
+ static void RecursiveDelete (GFile *location);
};