[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: [Panel-devel] trashcan applet
From:       Marco Martin <martkive () gmail ! com>
Date:       2007-11-23 19:04:43
Message-ID: 200711232004.43643.martkive () gmail ! com
[Download RAW message or body]

On Friday 23 November 2007, Aaron J. Seigo wrote:
> On Thursday 22 November 2007, Marco Martin wrote:
> > > what i'll do is this then: i've committed it to svn in
> > > trunk/playground/plasma/applets/trash ... maybe you can work on it
> > > there, send patches to me and i can apply (kind of odd given it's your
> > > own code ;) and if you stick around for a few weeks we'll hook you up
> > > with an account. sound good?
> >
> > yeah, definitely, i will post them on this thread, ok?
>
> that's perfect =)

This patch adds the usual confirmation dialog when something is dropped in the 
trash and now the icon changes accordingly to full or empty.
btw i've spotted another problem: it seems that if multiple files are dropped 
only the first it's seen, tomorrow i will try to investigate why

Cheers,
Marco Martin

["trash-patch.diff" (text/x-diff)]

Common subdirectories: /opt/svn/trash/.svn and /home/diau/trash/.svn
diff -Eb -U 3 -d /opt/svn/trash/trash.cpp /home/diau/trash/trash.cpp
--- /opt/svn/trash/trash.cpp	2007-11-23 19:34:17.000000000 +0100
+++ /home/diau/trash/trash.cpp	2007-11-22 22:23:35.000000000 +0100
@@ -40,7 +40,8 @@
 Trash::Trash(QObject *parent, const QVariantList &args)
     : Plasma::Applet(parent, args),
       m_icon(0),
-      m_trashUrl(KUrl("trash:/"))
+      m_trashUrl(KUrl("trash:/")),
+      m_count(0)
 {
     KConfigGroup cg = config();
     int size = globalConfig().readEntry("IconSize", IconSize(KIconLoader::Desktop));
@@ -49,13 +50,24 @@
     createMenu();
 
     new Plasma::HBoxLayout(this);
+
     m_icon = new Plasma::Icon(KIcon("user-trash"),QString(),this);
-    connect(m_icon, SIGNAL(pressed(bool, QGraphicsSceneMouseEvent*)), this, \
SLOT(popup(bool,QGraphicsSceneMouseEvent*))); +    connect(m_icon, \
SIGNAL(pressed(bool, QGraphicsSceneMouseEvent*)), +            this, \
SLOT(popup(bool,QGraphicsSceneMouseEvent*)));  m_icon->setIconSize(size, size);
-    //icon->setFlag(ItemIsMovable, false);
     resize(m_icon->sizeHint());
 
     setAcceptDrops(true);
+
+    m_dirLister = new KDirLister();
+    connect( m_dirLister, SIGNAL( clear() ),
+             this, SLOT( slotClear() ) );
+    connect( m_dirLister, SIGNAL( completed() ),
+             this, SLOT( slotCompleted() ) );
+    connect( m_dirLister, SIGNAL( deleteItem( KFileItem * ) ),
+             this, SLOT( slotDeleteItem( KFileItem * ) ) );
+
+    m_dirLister->openUrl(m_trashUrl);
 }
 
 Trash::~Trash()
@@ -128,6 +140,33 @@
     }
 }
 
+void Trash::setIcon()
+{
+    if (m_count > 0){
+        m_icon->setIcon(KIcon("user-trash-full"));
+    }else{
+        m_icon->setIcon(KIcon("user-trash"));
+    }
+}
+
+void Trash::slotClear()
+{
+    m_count = 0;
+    setIcon();
+}
+
+void Trash::slotCompleted()
+{
+    m_count = m_dirLister->items(KDirLister::AllItems).count();
+    setIcon();
+}
+
+void Trash::slotDeleteItem(KFileItem *)
+{
+    m_count--;
+    setIcon();
+}
+
 QList<QAction*> Trash::contextActions()
 {
   return actions;
@@ -150,7 +189,7 @@
 
         if (urls.count() > 0) {
             event->accept();
-            KonqOperations::copy( &m_menu, KonqOperations::MOVE, urls, m_trashUrl );
+            KonqOperations::del( &m_menu, KonqOperations::TRASH, urls );
         }
     }
 
diff -Eb -U 3 -d /opt/svn/trash/trash.h /home/diau/trash/trash.h
--- /opt/svn/trash/trash.h	2007-11-23 19:34:17.000000000 +0100
+++ /home/diau/trash/trash.h	2007-11-22 22:13:34.000000000 +0100
@@ -25,6 +25,8 @@
 #include <QAction>
 #include <QMenu>
 #include <QGraphicsView>
+#include <KFileItem>
+#include <KDirLister>
 
 #include <plasma/applet.h>
 
@@ -52,18 +54,24 @@
         void dropEvent(QGraphicsSceneDragDropEvent *event);
         void saveState(KConfigGroup *cg);
         void createMenu();
+        void setIcon();
         //void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget = 0);  
     protected slots:
         //void acceptedPropertiesDialog();
         void popup(bool pressed, QGraphicsSceneMouseEvent *event);
+        void slotClear();
+        void slotCompleted();
+        void slotDeleteItem(KFileItem *);
 
     private:
         Plasma::Icon* m_icon;
         QList<QAction*> actions;
         //KPropertiesDialog *m_dialog;
+        KDirLister *m_dirLister;
         KUrl m_trashUrl;
         QMenu m_menu;
+        int m_count;
 };
 
 K_EXPORT_PLASMA_APPLET(trash, Trash)



_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic