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

List:       kde-panel-devel
Subject:    Re: Review Request: Patch to add free space indicator into device
From:       Christopher Blauvelt <cblauvelt () gmail ! com>
Date:       2009-05-01 11:38:47
Message-ID: ffa898c90905010438v54e7262coca6897501c4f954e () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Tue, Apr 28, 2009 at 7:29 AM, <martin.klapetek@gmail.com> wrote:

>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://reviewboard.kde.org/r/632/
> -----------------------------------------------------------
>
> (Updated 2009-04-28 04:29:44.782996)
>
>
> Review request for Plasma.
>
>
> Summary
> -------
>
> This is more like a proof of concept, for me to see if I'm on the right way
> with this one
>
>
> Diffs (updated)
> -----
>
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/CMakeLists.txt
> 958067
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicenotifier.h
> 958067
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicenotifier.cpp
> 958067
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfo.h
> PRE-CREATION
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfo.cpp
> PRE-CREATION
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfodelegate.h
> PRE-CREATION
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfodelegate.cpp
> PRE-CREATION
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierdialog.h
> 958067
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierdialog.cpp
> 958067
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierview.h
> 958067
>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierview.cpp
> 958067
>
> Diff: http://reviewboard.kde.org/r/632/diff
>
>
> Testing
> -------
>
>
> Thanks,
>
> mck182
>
>
I've gone through and changed a few things that needed to be done.  These
changes use the soliddevice data engine to get free space and updates to
that value.  This has the effect of:
a) using values that are already present and being collected, less memory
usage.
b) avoids using an internal timer but instead uses the one that is already
set through the dataengine
c) only changes things in the delegate when the view says so

I've tested it and it works.  The only bug is that the view will only update
while the mouse is over the applet.
Chris

[Attachment #5 (text/html)]

<br><br><div class="gmail_quote">On Tue, Apr 28, 2009 at 7:29 AM,  <span \
dir="ltr">&lt;<a href="mailto:martin.klapetek@gmail.com">martin.klapetek@gmail.com</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, \
204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div class="im"><br>
-----------------------------------------------------------<br>
This is an automatically generated e-mail. To reply, visit:<br>
<a href="http://reviewboard.kde.org/r/632/" \
                target="_blank">http://reviewboard.kde.org/r/632/</a><br>
-----------------------------------------------------------<br>
<br>
</div>(Updated 2009-04-28 04:29:44.782996)<br>
<br>
<br>
Review request for Plasma.<br>
<div class="im"><br>
<br>
Summary<br>
-------<br>
<br>
This is more like a proof of concept, for me to see if I&#39;m on the right way with \
this one<br> <br>
<br>
Diffs (updated)<br>
-----<br>
<br>
  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/CMakeLists.txt 958067<br>
  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicenotifier.h \
958067<br> </div>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicenotifier.cpp \
958067<br> <div><div></div><div class="h5">  \
trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfo.h \
PRE-CREATION<br>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfo.cpp \
PRE-CREATION<br>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfodelegate.h \
PRE-CREATION<br>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfodelegate.cpp \
PRE-CREATION<br>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierdialog.h \
958067<br>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierdialog.cpp \
958067<br>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierview.h \
958067<br>  trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierview.cpp \
958067<br> <br>
Diff: <a href="http://reviewboard.kde.org/r/632/diff" \
target="_blank">http://reviewboard.kde.org/r/632/diff</a><br> <br>
<br>
Testing<br>
-------<br>
<br>
<br>
Thanks,<br>
<br>
mck182<br>
<br>
</div></div></blockquote></div><br>I&#39;ve gone through and changed a few things \
that needed to be done.  These changes use the soliddevice data engine to get free \
space and updates to that value.  This has the effect of:<br> a) using values that \
are already present and being collected, less memory usage.<br>b) avoids using an \
internal timer but instead uses the one that is already set through the \
dataengine<br>c) only changes things in the delegate when the view says so<br> \
<br>I&#39;ve tested it and it works.  The only bug is that the view will only update \
while the mouse is over the applet.<br>Chris<br>

--0016e64642627d71430468d8416b--


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

Index: devicenotifier.cpp
===================================================================
--- devicenotifier.cpp	(revision 960780)
+++ devicenotifier.cpp	(working copy)
@@ -117,6 +117,7 @@
             Solid::Device device = Solid::Device(source);
             Solid::Device parentDevice = device.parent();
             Solid::StorageDrive *drive = parentDevice.as<Solid::StorageDrive>();
+
             if (drive && (drive->isHotpluggable() || drive->isRemovable())) {
                 onSourceAdded(source);
             }
@@ -149,6 +150,7 @@
         if (!data["predicateFiles"].isNull()) {
             int nb_actions = 0;
             QString lastActionLabel;
+
             foreach (const QString &desktop, data["predicateFiles"].toStringList()) \
                {
                 QString filePath = KStandardDirs::locate("data", "solid/actions/" + \
                desktop);
                 QList<KServiceAction> services = \
KDesktopFileActions::userDefinedServices(filePath, true); @@ -157,6 +159,7 @@
                     lastActionLabel = QString(services[0].text());
                 }
             }
+
             m_dialog->setDeviceData(source,data["predicateFiles"],NotifierDialog::PredicateFilesRole);
                
             m_dialog->setDeviceData(source,data["text"], Qt::DisplayRole);
 
@@ -165,6 +168,7 @@
             //icon data
             m_dialog->setDeviceData(source,KIcon(data["icon"].toString()), \
Qt::DecorationRole);  
+
             if (nb_actions > 1) {
                 QString s = i18np("1 action for this device",
                                   "%1 actions for this device",
@@ -185,6 +189,11 @@
                     QStringList overlays;
                     overlays << "emblem-mounted";
                     m_dialog->setDeviceData(source, \
KIcon(m_dialog->getDeviceData(source,NotifierDialog::IconNameRole).toString(), NULL, \
overlays), Qt::DecorationRole); +                    if ( \
data["FreeSpace"].isValid()) { +                        QList<QVariant> \
freeSpaceData; +                        freeSpaceData << data["Size"] << \
data["FreeSpace"]; +                        m_dialog->setDeviceData(source, \
QVariant(freeSpaceData), NotifierDialog::DeviceFreeSpaceRole); +                    }
                 } else if (data["Device \
Types"].toStringList().contains("OpticalDisc")) {  //Unmounted optical drive
                     m_dialog->setDeviceData(source, KIcon("media-eject"), \
Qt::DecorationRole); @@ -196,6 +205,9 @@
 
                     //set icon to unmounted device
                     m_dialog->setDeviceData(source, \
KIcon(m_dialog->getDeviceData(source,NotifierDialog::IconNameRole).toString()), \
Qt::DecorationRole); +                    QList<QVariant> freeSpaceData;
+                    freeSpaceData << QVariant(0) << QVariant(0);
+                    m_dialog->setDeviceData(source, QVariant(freeSpaceData), \
NotifierDialog::DeviceFreeSpaceRole);  }
             }
             // actions specific for other types of devices will go here
Index: notifierdialog.cpp
===================================================================
--- notifierdialog.cpp	(revision 960780)
+++ notifierdialog.cpp	(working copy)
@@ -18,6 +18,7 @@
 */
 
 #include "notifierdialog.h"
+#include "devicespaceinfodelegate.h"
 
 //Qt
 #include <QStandardItemModel>
@@ -140,6 +141,7 @@
     QString udi = item->data(SolidUdiRole).toString();
     if(!udi.isNull()) {
         Solid::Device device(udi);
+
         QString categoryOfInsertedDevice = getCategoryNameOfDevice(device);
         QStandardItem *currentCategory = \
searchOrCreateDeviceCategory(categoryOfInsertedDevice);  if(currentCategory)
@@ -162,7 +164,7 @@
     m_notifierView->calculateRects();
 }
 
-void NotifierDialog::setUnMount(bool unmount, const QString &name) 
+void NotifierDialog::setUnMount(bool unmount, const QString &name)
 {
     QModelIndex index = indexForUdi(name);
     if (!index.isValid()) {
@@ -253,10 +255,10 @@
     QVBoxLayout *l_layout = new QVBoxLayout(m_widget);
     l_layout->setSpacing(0);
     l_layout->setMargin(0);
-    
+
     m_label = new QLabel(m_widget);
     updateColors();
-    
+
     QLabel *icon = new QLabel(m_widget);
     icon->setPixmap(KIcon("emblem-mounted").pixmap(KIconLoader::SizeMedium, \
KIconLoader::SizeMedium));  
@@ -272,14 +274,16 @@
 
     m_notifierView = new NotifierView(m_widget);
     m_notifierView->setModel(m_hotplugModel);
-    m_notifierView->setMinimumSize(150,300);
+    m_notifierView->setMinimumSize(150,320);
     m_notifierView->setFocusPolicy(Qt::NoFocus);
-    
-    Plasma::Delegate *delegate = new Delegate(this);
+
+    DeviceSpaceInfoDelegate *delegate = new DeviceSpaceInfoDelegate(this);
+    //Plasma::Delegate *delegate = new Delegate(this);
     //map the roles of m_hotplugModel into the standard Plasma::Delegate roles
     delegate->setRoleMapping(Plasma::Delegate::SubTitleRole, ActionRole);
     delegate->setRoleMapping(Plasma::Delegate::ColumnTypeRole, ScopeRole);
     delegate->setRoleMapping(Plasma::Delegate::SubTitleMandatoryRole, \
SubTitleMandatoryRole); +
     m_notifierView->setItemDelegate(delegate);
 
     l_layout->addLayout(l_layout2);
Index: devicenotifier.h
===================================================================
--- devicenotifier.h	(revision 960780)
+++ devicenotifier.h	(working copy)
@@ -60,12 +60,12 @@
         * @param parent the parent of this object
         **/
         DeviceNotifier(QObject *parent, const QVariantList &args);
-        
+
         /**
         * Default destructor
         **/
         ~DeviceNotifier();
-        
+
         /**
         * initialize the applet (called by plasma automatically)
         **/
@@ -136,28 +136,28 @@
 
         ///The engine used to manage devices in the applet (unmount,...)
         Plasma::DataEngine *m_solidDeviceEngine;
-  
+
         ///the icon used when the applet is in the taskbar
         Plasma::IconWidget *m_icon;
-    
+
         ///default icon of the notifier
         QString m_iconName;
 
         ///The dialog where devices are displayed
         Notifier::NotifierDialog * m_dialog;
-        
+
         ///the time durin when the dialog will be show
         int m_displayTime;
-      
+
         ///the number of items displayed in the dialog
         int m_numberItems;
-      
+
         ///the time during when the item will be displayed
         int m_itemsValidity;
 
         ///the timer for different use cases
         QTimer *m_timer;
-       
+
         ///bool to know if notifications are enabled
         bool isNotificationEnabled;
 
Index: notifierdialog.h
===================================================================
--- notifierdialog.h	(revision 960780)
+++ notifierdialog.h	(working copy)
@@ -27,7 +27,6 @@
 //solid
 #include <solid/solidnamespace.h>
 
-
 //to remove
 #include <QTreeView>
 
@@ -60,10 +59,10 @@
   class NotifierDialog : public QObject
   {
   Q_OBJECT
-  
+
       public:
 
-          
+
           ///Specific role for the data-model
           enum SpecificRoles {
               SolidUdiRole = Qt::UserRole + 1,
@@ -71,9 +70,10 @@
               ActionRole = Qt::UserRole + 3,
               IconNameRole = Qt::UserRole + 4,
               ScopeRole = Qt::UserRole + 5,
-              SubTitleMandatoryRole = Qt::UserRole + 6
+              SubTitleMandatoryRole = Qt::UserRole + 6,
+              DeviceFreeSpaceRole =  Qt::UserRole + 7
           };
-  
+
           /**
           * Constructor of the dialog
           * @param notifier the notifier attached to this dialog
@@ -81,7 +81,7 @@
           * @param parent the parent of this object
           **/
           NotifierDialog(DeviceNotifier * notifier,QObject *parent = 0);
- 
+
           /**
           * Default destructor
           **/
@@ -91,7 +91,7 @@
           * Returns the related QWidget.
           **/
           QWidget * dialog();
-         
+
           /**
           * Hide the dialog
           **/
@@ -109,43 +109,43 @@
           void insertDevice(const QString &name);
 
           void setUnMount(bool unmount,const QString &name);
-  
+
           /**
           * Allow to set data which will be displayed by the view
-          * @param name the name of the device 
+          * @param name the name of the device
           * @param data the data
           * @param role the role in the data-model
           **/
           void setDeviceData(const QString &name, QVariant data, int role);
-          
+
           /**
           * Allow to get a data display by the view
-          * @param name the name of the device 
+          * @param name the name of the device
           * @param role the role where is the data
           **/
           QVariant getDeviceData(const QString &name, int role);
 
           /**
           * Remove a device in the dialog
-          * @param name the name of the device 
+          * @param name the name of the device
           **/
           void removeDevice(const QString &name);
-  
+
           /**
           * Remove a device in the view (provided by convenience)
-          * @param index the index where the data will be delete 
+          * @param index the index where the data will be delete
           **/
           void removeDevice(int index);
 
           /**
           * Return the number of items displayed
-          * 
+          *
           **/
           int countDevices();
 
           /**
           * get the udi of a device displayed in the dialog
-          * @param index the index of the device 
+          * @param index the index of the device
           **/
           QString getDeviceUdi(int index);
 
@@ -178,14 +178,14 @@
           * @param error type of error given by solid
           **/
           void storageTeardownDone(Solid::ErrorType error, QVariant errorData);
- 
+
           /**
           * @internal slot called to restore to the notifier his icon
           **/
           void resetNotifierIcon();
 
           /**
-          * @internal update the color of the label to follow plasma theme 
+          * @internal update the color of the label to follow plasma theme
           *
           **/
           void updateColors();
@@ -193,12 +193,12 @@
 
       private :
           /**
-          * @internal build the dialog depending where it is 
+          * @internal build the dialog depending where it is
           **/
           void buildDialog();
 
           /**
-          * @internal get the model index in the data-model by using the udi in \
parameter  +          * @internal get the model index in the data-model by using the \
                udi in parameter
           * @param udi the udi used to find the model index
           **/
           QModelIndex indexForUdi(const QString &udi) const;
Index: notifierview.cpp
===================================================================
--- notifierview.cpp	(revision 960780)
+++ notifierview.cpp	(working copy)
@@ -18,7 +18,8 @@
 */
 
 #include "notifierview.h"
-
+#include "devicespaceinfodelegate.h"
+#include "notifierdialog.h"
 // Qt
 
 #include <QtGui/QMouseEvent>
@@ -27,6 +28,7 @@
 #include <QtGui/QScrollBar>
 #include <QtGui/QHeaderView>
 #include <QtGui/QStandardItemModel>
+#include <QDebug>
 
 //KDE
 #include <KDebug>
@@ -46,6 +48,7 @@
     setRootIsDecorated(true);
     setHeaderHidden(true);
     setMouseTracking(true);
+
 }
 
 NotifierView::~NotifierView()
@@ -151,12 +154,14 @@
 
                 QStandardItemModel * currentModel = dynamic_cast<QStandardItemModel \
                *>(model());
                 QStandardItem *currentItem = currentModel->itemFromIndex(index);
+
                 // we display the children of this item
                 for (int k = 0; k < currentItem->rowCount(); ++k) {
                     for (int l = 0; l < currentItem->columnCount(); ++l) {
                         QStandardItem *childItem = currentItem->child(k, l);
                         QModelIndex childIndex = childItem->index();
                         QRect itemChildRect;
+
                         if (l % 2 == 0) {
                             QSize size(width() - \
                COLUMN_EJECT_SIZE,sizeHintForIndex(index).height());
                             itemChildRect = QRect(QPoint(HEADER_LEFT_MARGIN, \
verticalOffset), size); @@ -247,6 +252,8 @@
         option.state |= QStyle::State_HasFocus;
     }
 
+    QList<QVariant> freeSpaceData = \
index.data(NotifierDialog::DeviceFreeSpaceRole).toList(); +    \
((DeviceSpaceInfoDelegate*)itemDelegate(index))->setData(freeSpaceData[0], \
freeSpaceData[1]);  itemDelegate(index)->paint(&painter,option,index);
 }
 
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 960780)
+++ CMakeLists.txt	(working copy)
@@ -3,7 +3,8 @@
 set(devicenotifier_SRCS
     devicenotifier.cpp
     notifierdialog.cpp
-    notifierview.cpp)
+    notifierview.cpp
+    devicespaceinfodelegate.cpp)
 
 kde4_add_plugin(plasma_applet_devicenotifier ${devicenotifier_SRCS})
 target_link_libraries(plasma_applet_devicenotifier ${KDE4_PLASMA_LIBS} \
${KDE4_KIO_LIBS} ${KDE4_SOLID_LIBS})


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

diff -u /home/jackrabbit/devicenotifier/CMakeLists.txt ./CMakeLists.txt
--- /home/jackrabbit/devicenotifier/CMakeLists.txt	2009-04-29 00:32:36.000000000 \
                -0400
+++ ./CMakeLists.txt	2009-05-01 00:29:31.000000000 -0400
@@ -4,7 +4,6 @@
     devicenotifier.cpp
     notifierdialog.cpp
     notifierview.cpp
-    devicespaceinfo.cpp
     devicespaceinfodelegate.cpp)
 
 kde4_add_plugin(plasma_applet_devicenotifier ${devicenotifier_SRCS})
diff -u /home/jackrabbit/devicenotifier/devicenotifier.cpp ./devicenotifier.cpp
--- /home/jackrabbit/devicenotifier/devicenotifier.cpp	2009-04-29 00:32:36.000000000 \
                -0400
+++ ./devicenotifier.cpp	2009-05-01 00:47:25.000000000 -0400
@@ -82,7 +82,7 @@
 
     m_solidEngine = dataEngine("hotplug");
     m_solidDeviceEngine = dataEngine("soliddevice");
-    
+
     m_icon = new Plasma::IconWidget(KIcon("device-notifier",NULL), QString());
     m_iconName = QString("device-notifier");
 
@@ -159,7 +159,7 @@
                     lastActionLabel = QString(services[0].text());
                 }
             }
-          
+
             m_dialog->setDeviceData(source,data["predicateFiles"],NotifierDialog::PredicateFilesRole);
                
             m_dialog->setDeviceData(source,data["text"], Qt::DisplayRole);
 
@@ -189,6 +189,11 @@
                     QStringList overlays;
                     overlays << "emblem-mounted";
                     m_dialog->setDeviceData(source, \
KIcon(m_dialog->getDeviceData(source,NotifierDialog::IconNameRole).toString(), NULL, \
overlays), Qt::DecorationRole); +                    if ( \
data["FreeSpace"].isValid()) { +                        QList<QVariant> \
freeSpaceData; +                        freeSpaceData << data["Size"] << \
data["FreeSpace"]; +                        m_dialog->setDeviceData(source, \
QVariant(freeSpaceData), NotifierDialog::DeviceFreeSpaceRole); +                    }
                 } else if (data["Device \
Types"].toStringList().contains("OpticalDisc")) {  //Unmounted optical drive
                     m_dialog->setDeviceData(source, KIcon("media-eject"), \
Qt::DecorationRole); @@ -200,6 +205,9 @@
 
                     //set icon to unmounted device
                     m_dialog->setDeviceData(source, \
KIcon(m_dialog->getDeviceData(source,NotifierDialog::IconNameRole).toString()), \
Qt::DecorationRole); +                    QList<QVariant> freeSpaceData;
+                    freeSpaceData << QVariant(0) << QVariant(0);
+                    m_dialog->setDeviceData(source, QVariant(freeSpaceData), \
NotifierDialog::DeviceFreeSpaceRole);  }
             }
             // actions specific for other types of devices will go here
diff -u /home/jackrabbit/devicenotifier/devicenotifier.h ./devicenotifier.h
--- /home/jackrabbit/devicenotifier/devicenotifier.h	2009-04-29 00:32:36.000000000 \
                -0400
+++ ./devicenotifier.h	2009-04-29 02:01:31.000000000 -0400
@@ -22,7 +22,6 @@
 
 //Solid
 #include <solid/solidnamespace.h>
-#include <solid/storageaccess.h>
 
 //Plasma
 #include <Plasma/PopupApplet>
@@ -61,12 +60,12 @@
         * @param parent the parent of this object
         **/
         DeviceNotifier(QObject *parent, const QVariantList &args);
-        
+
         /**
         * Default destructor
         **/
         ~DeviceNotifier();
-        
+
         /**
         * initialize the applet (called by plasma automatically)
         **/
@@ -137,28 +136,28 @@
 
         ///The engine used to manage devices in the applet (unmount,...)
         Plasma::DataEngine *m_solidDeviceEngine;
-  
+
         ///the icon used when the applet is in the taskbar
         Plasma::IconWidget *m_icon;
-    
+
         ///default icon of the notifier
         QString m_iconName;
 
         ///The dialog where devices are displayed
         Notifier::NotifierDialog * m_dialog;
-        
+
         ///the time durin when the dialog will be show
         int m_displayTime;
-      
+
         ///the number of items displayed in the dialog
         int m_numberItems;
-      
+
         ///the time during when the item will be displayed
         int m_itemsValidity;
 
         ///the timer for different use cases
         QTimer *m_timer;
-       
+
         ///bool to know if notifications are enabled
         bool isNotificationEnabled;
 
Only in /home/jackrabbit/devicenotifier/: devicespaceinfo.cpp
diff -u /home/jackrabbit/devicenotifier/devicespaceinfodelegate.cpp \
                ./devicespaceinfodelegate.cpp
--- /home/jackrabbit/devicenotifier/devicespaceinfodelegate.cpp	2009-04-29 \
                00:32:36.000000000 -0400
+++ ./devicespaceinfodelegate.cpp	2009-05-01 01:32:14.000000000 -0400
@@ -14,56 +14,62 @@
    Boston, MA 02110-1301, USA.
 */
 #include <QPixmap>
-#include <QDebug>
-#include <QStandardItemModel>
-#include <QStandardItem>
-
-//Solid
-#include <solid/device.h>
-#include <solid/opticaldisc.h>
-#include <solid/storageaccess.h>
-#include <solid/opticaldrive.h>
-#include <solid/deviceinterface.h>
 
 #include "devicespaceinfodelegate.h"
+#include <kcapacitybar.h>
+#include <KLocale>
+#include <KDebug>
+
+DeviceSpaceInfoDelegate::DeviceSpaceInfoDelegate(QObject* parent)
+    : Plasma::Delegate(parent),
+    m_capacityBar(0),
+    m_size(0),
+    m_freeSpace(0),
+    m_usedSpace(0)
+{
+    m_capacityBar = new KCapacityBar(KCapacityBar::DrawTextInline);
+    m_capacityBar->setMaximumWidth(200);
+    m_capacityBar->setMinimumWidth(200);
+}
+
+DeviceSpaceInfoDelegate::~DeviceSpaceInfoDelegate()
+{
+    delete m_capacityBar;
+}
+
+void DeviceSpaceInfoDelegate::setData(QVariant size, QVariant freeSpace)
+{
+    if (!size.isValid() || !freeSpace.isValid()) {
+        m_size = qulonglong(0);
+        m_freeSpace = qulonglong(0);
+        m_usedSpace = qulonglong(0);
+        return;
+    }
+
+    m_size = qulonglong(size.toULongLong());
+    m_freeSpace = qulonglong(freeSpace.toULongLong());
+    m_usedSpace = m_size - m_freeSpace;
+
+    m_capacityBar->setText(i18nc("@info:status Free disk space", "%1 free", \
m_freeSpace)); +    m_capacityBar->setUpdatesEnabled(false);
+    m_capacityBar->setValue(m_size > 0 ? (m_usedSpace * 100) / m_size : 0);
+    m_capacityBar->setUpdatesEnabled(true);
+}
+
+void DeviceSpaceInfoDelegate::paint(QPainter* painter, const QStyleOptionViewItem& \
option, const QModelIndex& index) const +{
+    painter->save();
+    Plasma::Delegate::paint(painter, option, index);
+    if(m_size) {
+        m_capacityBar->drawCapacityBar(painter, QRect(QPoint(option.rect.x()+48, \
Plasma::Delegate::rectAfterTitle(option, index).bottom()-5),  QSize(100, 10))); +    \
} +    painter->restore();
+}
+
+QSize DeviceSpaceInfoDelegate::sizeHint(const QStyleOptionViewItem& option, const \
QModelIndex& index) const +{
+    Q_UNUSED(option)
+    Q_UNUSED(index)
 
-DeviceSpaceInfoDelegate::DeviceSpaceInfoDelegate(QObject* parent) {
-      m_spaceInfo = new DeviceSpaceInfo();
-      //m_spaceInfo->setUrl(KUrl("/"));
-}
-
-bool DeviceSpaceInfoDelegate::isSpaceInfoAvailable(QString udi) const {
-      if(!udi.isNull()) {
-	  Solid::Device device(udi);
-	  if (device.is<Solid::StorageAccess>()
-	  && device.as<Solid::StorageAccess>()->isAccessible()) {
-	      Solid::StorageAccess *access = device.as<Solid::StorageAccess>();
-	      m_spaceInfo->setUrl(access->filePath());
-	      return true;
-	  }
-	  else return false;
-      }
-      else return false;
-}
-
-
-void DeviceSpaceInfoDelegate::paint(QPainter* painter, const QStyleOptionViewItem& \
                option, const QModelIndex& index) const {
-      painter->save();
-      Plasma::Delegate::paint(painter, option, index);
-      if(isSpaceInfoAvailable(index.data(Qt::UserRole+1).value<QString>()))
-	  m_spaceInfo->drawCapacityBar(painter, QRect(QPoint(option.rect.x()+48, \
Plasma::Delegate::rectAfterTitle(option, index).bottom()-5),  QSize(100, 10))); \
                //Plasma::Delegate::emptyRect(option, index)
-//QRect(QPoint(Plasma::Delegate::rectAfterTitle(option, index).x(), \
                Plasma::Delegate::rectAfterTitle(option, index).y()),  QSize(100, \
                15))
-      painter->restore();
-}
-
-void DeviceSpaceInfoDelegate::setUrl(KUrl url) {
-      m_url = url;
-      m_spaceInfo->setUrl(m_url);
-}
-
-KUrl DeviceSpaceInfoDelegate::url() {
-      return m_url;
-}
-QSize DeviceSpaceInfoDelegate::sizeHint(const QStyleOptionViewItem& option, const \
                QModelIndex& index) const {
-      return QSize(184,60);
+    return QSize(184,60);
 }
diff -u /home/jackrabbit/devicenotifier/devicespaceinfodelegate.h \
                ./devicespaceinfodelegate.h
--- /home/jackrabbit/devicenotifier/devicespaceinfodelegate.h	2009-04-29 \
                00:32:36.000000000 -0400
+++ ./devicespaceinfodelegate.h	2009-05-01 00:55:18.000000000 -0400
@@ -25,23 +25,23 @@
 #include <QStandardItemModel>
 #include <QPainter>
 
-#include <KUrl>
 
-#include "devicespaceinfo.h"
+class KCapacityBar;
 
 class DeviceSpaceInfoDelegate : public Plasma::Delegate
 {
     Q_OBJECT
 public:
     DeviceSpaceInfoDelegate(QObject *parent = 0);
+    virtual ~DeviceSpaceInfoDelegate();
     virtual void paint(QPainter *painter, const QStyleOptionViewItem & option, const \
                QModelIndex & index) const;
     virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex & \
                index) const;
-    KUrl url();
-    void setUrl(KUrl url);
-    bool isSpaceInfoAvailable(QString udi) const;
+    void setData(QVariant size, QVariant freeSpace);
 private:
-    KUrl m_url;
-    DeviceSpaceInfo* m_spaceInfo;
+    KCapacityBar *m_capacityBar;
+    qulonglong m_size;
+    qulonglong m_freeSpace;
+    qulonglong m_usedSpace;
 };
 
 #endif // DEVICESPACEINFODELEGATE_H
Only in /home/jackrabbit/devicenotifier/: devicespaceinfo.h
diff -u /home/jackrabbit/devicenotifier/notifierdialog.cpp ./notifierdialog.cpp
--- /home/jackrabbit/devicenotifier/notifierdialog.cpp	2009-04-29 00:32:36.000000000 \
                -0400
+++ ./notifierdialog.cpp	2009-05-01 01:40:54.000000000 -0400
@@ -55,7 +55,6 @@
 #include "notifierview.h"
 #include "devicenotifier.h"
 
-
 using namespace Notifier;
 using namespace Plasma;
 
@@ -130,11 +129,10 @@
 void NotifierDialog::insertDevice(const QString &name)
 {
     QStandardItem *item = new QStandardItem();
-
     item->setData(name, SolidUdiRole);
     item->setData(Plasma::Delegate::MainColumn, ScopeRole);
     item->setData(false, SubTitleMandatoryRole);
-    
+
     QStandardItem *actionItem = new QStandardItem();
     actionItem->setData(name, SolidUdiRole);
     actionItem->setData(Plasma::Delegate::SecondaryActionColumn, ScopeRole);
@@ -166,7 +164,7 @@
     m_notifierView->calculateRects();
 }
 
-void NotifierDialog::setUnMount(bool unmount, const QString &name) 
+void NotifierDialog::setUnMount(bool unmount, const QString &name)
 {
     QModelIndex index = indexForUdi(name);
     if (!index.isValid()) {
@@ -257,10 +255,10 @@
     QVBoxLayout *l_layout = new QVBoxLayout(m_widget);
     l_layout->setSpacing(0);
     l_layout->setMargin(0);
-    
+
     m_label = new QLabel(m_widget);
     updateColors();
-    
+
     QLabel *icon = new QLabel(m_widget);
     icon->setPixmap(KIcon("emblem-mounted").pixmap(KIconLoader::SizeMedium, \
KIconLoader::SizeMedium));  
@@ -278,7 +276,7 @@
     m_notifierView->setModel(m_hotplugModel);
     m_notifierView->setMinimumSize(150,320);
     m_notifierView->setFocusPolicy(Qt::NoFocus);
-    
+
     DeviceSpaceInfoDelegate *delegate = new DeviceSpaceInfoDelegate(this);
     //Plasma::Delegate *delegate = new Delegate(this);
     //map the roles of m_hotplugModel into the standard Plasma::Delegate roles
diff -u /home/jackrabbit/devicenotifier/notifierdialog.h ./notifierdialog.h
--- /home/jackrabbit/devicenotifier/notifierdialog.h	2009-04-29 00:32:36.000000000 \
                -0400
+++ ./notifierdialog.h	2009-04-30 23:58:44.000000000 -0400
@@ -59,10 +59,10 @@
   class NotifierDialog : public QObject
   {
   Q_OBJECT
-  
+
       public:
 
-          
+
           ///Specific role for the data-model
           enum SpecificRoles {
               SolidUdiRole = Qt::UserRole + 1,
@@ -71,10 +71,9 @@
               IconNameRole = Qt::UserRole + 4,
               ScopeRole = Qt::UserRole + 5,
               SubTitleMandatoryRole = Qt::UserRole + 6,
-              DeviceFreeSpaceRole =  Qt::UserRole + 7,
-	      DeviceSizeRole =  Qt::UserRole + 8
+              DeviceFreeSpaceRole =  Qt::UserRole + 7
           };
-  
+
           /**
           * Constructor of the dialog
           * @param notifier the notifier attached to this dialog
@@ -82,7 +81,7 @@
           * @param parent the parent of this object
           **/
           NotifierDialog(DeviceNotifier * notifier,QObject *parent = 0);
- 
+
           /**
           * Default destructor
           **/
@@ -92,7 +91,7 @@
           * Returns the related QWidget.
           **/
           QWidget * dialog();
-         
+
           /**
           * Hide the dialog
           **/
@@ -110,43 +109,43 @@
           void insertDevice(const QString &name);
 
           void setUnMount(bool unmount,const QString &name);
-  
+
           /**
           * Allow to set data which will be displayed by the view
-          * @param name the name of the device 
+          * @param name the name of the device
           * @param data the data
           * @param role the role in the data-model
           **/
           void setDeviceData(const QString &name, QVariant data, int role);
-          
+
           /**
           * Allow to get a data display by the view
-          * @param name the name of the device 
+          * @param name the name of the device
           * @param role the role where is the data
           **/
           QVariant getDeviceData(const QString &name, int role);
 
           /**
           * Remove a device in the dialog
-          * @param name the name of the device 
+          * @param name the name of the device
           **/
           void removeDevice(const QString &name);
-  
+
           /**
           * Remove a device in the view (provided by convenience)
-          * @param index the index where the data will be delete 
+          * @param index the index where the data will be delete
           **/
           void removeDevice(int index);
 
           /**
           * Return the number of items displayed
-          * 
+          *
           **/
           int countDevices();
 
           /**
           * get the udi of a device displayed in the dialog
-          * @param index the index of the device 
+          * @param index the index of the device
           **/
           QString getDeviceUdi(int index);
 
@@ -179,14 +178,14 @@
           * @param error type of error given by solid
           **/
           void storageTeardownDone(Solid::ErrorType error, QVariant errorData);
- 
+
           /**
           * @internal slot called to restore to the notifier his icon
           **/
           void resetNotifierIcon();
 
           /**
-          * @internal update the color of the label to follow plasma theme 
+          * @internal update the color of the label to follow plasma theme
           *
           **/
           void updateColors();
@@ -194,12 +193,12 @@
 
       private :
           /**
-          * @internal build the dialog depending where it is 
+          * @internal build the dialog depending where it is
           **/
           void buildDialog();
 
           /**
-          * @internal get the model index in the data-model by using the udi in \
parameter  +          * @internal get the model index in the data-model by using the \
                udi in parameter
           * @param udi the udi used to find the model index
           **/
           QModelIndex indexForUdi(const QString &udi) const;
diff -u /home/jackrabbit/devicenotifier/notifierview.cpp ./notifierview.cpp
--- /home/jackrabbit/devicenotifier/notifierview.cpp	2009-04-29 00:32:36.000000000 \
                -0400
+++ ./notifierview.cpp	2009-05-01 00:51:09.000000000 -0400
@@ -19,6 +19,7 @@
 
 #include "notifierview.h"
 #include "devicespaceinfodelegate.h"
+#include "notifierdialog.h"
 // Qt
 
 #include <QtGui/QMouseEvent>
@@ -38,13 +39,6 @@
 //Plasma
 #include <Plasma/Delegate>
 
-//Solid
-#include <solid/device.h>
-#include <solid/opticaldisc.h>
-#include <solid/storageaccess.h>
-#include <solid/opticaldrive.h>
-#include <solid/deviceinterface.h>
-
 using namespace Notifier;
 
 NotifierView::NotifierView(QWidget *parent)
@@ -245,7 +239,7 @@
 {
     QStyleOptionViewItem option = viewOptions();
     option.rect = itemRect;
-    
+
     if (selectionModel()->isSelected(index)) {
         option.state |= QStyle::State_Selected;
     }
@@ -258,6 +252,8 @@
         option.state |= QStyle::State_HasFocus;
     }
 
+    QList<QVariant> freeSpaceData = \
index.data(NotifierDialog::DeviceFreeSpaceRole).toList(); +    \
((DeviceSpaceInfoDelegate*)itemDelegate(index))->setData(freeSpaceData[0], \
freeSpaceData[1]);  itemDelegate(index)->paint(&painter,option,index);
 }
 
diff -u /home/jackrabbit/devicenotifier/notifierview.h ./notifierview.h
--- /home/jackrabbit/devicenotifier/notifierview.h	2009-04-29 00:32:36.000000000 \
                -0400
+++ ./notifierview.h	2009-05-01 01:37:43.000000000 -0400
@@ -21,8 +21,6 @@
 // Qt
 #include <QTreeView>
 
-#include "devicespaceinfo.h"
-
 class QModelIndex;
 
 namespace Notifier
@@ -123,7 +121,6 @@
       ///The hovered index
       QPersistentModelIndex m_hoveredIndex;
       QHash<QModelIndex,QRect> itemRects;
-      //DeviceSpaceInfo* m_spaceInfo;
   };
 
 }
Common subdirectories: /home/jackrabbit/devicenotifier/.svn and ./.svn



_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


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

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