[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:       Alessandro Diaferia <alediaferia () gmail ! com>
Date:       2009-08-18 11:44:50
Message-ID: 65627f3a0908180444yc61fb62i4f1628cf3db1f975 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


2009/8/17 Sebastian Kügler <sebas@kde.org>

>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://reviewboard.kde.org/r/632/#review2065
> -----------------------------------------------------------
>
>
> I've tested the patch on current trunk, about to commit it, but I don't see
> any progress bar showing up. The patch probably needs updating.
>
> - Sebastian
>
>
> On 2009-05-12 14:28:58, mck182 wrote:
> >
> > -----------------------------------------------------------
> > This is an automatically generated e-mail. To reply, visit:
> > http://reviewboard.kde.org/r/632/
> > -----------------------------------------------------------
> >
> > (Updated 2009-05-12 14:28:58)
> >
> >
> > Review request for Plasma.
> >
> >
> > Summary
> > -------
> >
> > This patch adds a KCapacityBar into the device notifier plasmoid to show
> the device's free space.
> >
> >
> > Diffs
> > -----
> >
> >
> trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/CMakeLists.txt
> 965209
> >
> trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicenotifier.cpp
> 965209
> >
> 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
> 965209
> >
> trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierdialog.cpp
> 965209
> >
> trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierview.cpp
> 965209
> >
> > Diff: http://reviewboard.kde.org/r/632/diff
> >
> >
> > Testing
> > -------
> >
> >
> > Thanks,
> >
> > mck182
> >
> >
>
> _______________________________________________
> Plasma-devel mailing list
> Plasma-devel@kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
>

I've updated the patch and now it correctly shows the capacity bar. There's
only a little issue: as soon as the device gets "mounted" the engine does
not return a valid "Free Space" data. This is probably a problem with the
engine or, worse, with solid.. Will check it out though..



-- 
Alessandro Diaferia
KDE Developer

[Attachment #5 (text/html)]

<br><br><div class="gmail_quote">2009/8/17 Sebastian Kügler <span dir="ltr">&lt;<a \
href="mailto:sebas@kde.org">sebas@kde.org</a>&gt;</span><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>
</div><a href="http://reviewboard.kde.org/r/632/#review2065" \
                target="_blank">http://reviewboard.kde.org/r/632/#review2065</a><br>
-----------------------------------------------------------<br>
<br>
<br>
I&#39;ve tested the patch on current trunk, about to commit it, but I don&#39;t see \
any progress bar showing up. The patch probably needs updating.<br> <br>
- Sebastian<br>
<div class="im"><br>
<br>
On 2009-05-12 14:28:58, mck182 wrote:<br>
&gt;<br>
&gt; -----------------------------------------------------------<br>
&gt; This is an automatically generated e-mail. To reply, visit:<br>
&gt; <a href="http://reviewboard.kde.org/r/632/" \
target="_blank">http://reviewboard.kde.org/r/632/</a><br> &gt; \
-----------------------------------------------------------<br> &gt;<br>
</div>&gt; (Updated 2009-05-12 14:28:58)<br>
&gt;<br>
&gt;<br>
&gt; Review request for Plasma.<br>
<div class="im">&gt;<br>
&gt;<br>
&gt; Summary<br>
&gt; -------<br>
&gt;<br>
&gt; This patch adds a KCapacityBar into the device notifier plasmoid to show the \
device&#39;s free space.<br> &gt;<br>
&gt;<br>
&gt; Diffs<br>
</div><div class="im">&gt; -----<br>
&gt;<br>
&gt;    trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/CMakeLists.txt \
965209<br> &gt;    trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicenotifier.cpp \
965209<br> &gt;    trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfodelegate.h \
PRE-CREATION<br> &gt;    \
trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/devicespaceinfodelegate.cpp \
PRE-CREATION<br> &gt;    \
trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierdialog.h 965209<br> \
&gt;    trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierdialog.cpp \
965209<br> &gt;    trunk/KDE/kdebase/workspace/plasma/applets/devicenotifier/notifierview.cpp \
965209<br> &gt;<br>
&gt; Diff: <a href="http://reviewboard.kde.org/r/632/diff" \
target="_blank">http://reviewboard.kde.org/r/632/diff</a><br> &gt;<br>
&gt;<br>
&gt; Testing<br>
&gt; -------<br>
&gt;<br>
&gt;<br>
&gt; Thanks,<br>
&gt;<br>
&gt; mck182<br>
&gt;<br>
&gt;<br>
<br>
</div><div><div></div><div \
class="h5">_______________________________________________<br> Plasma-devel mailing \
list<br> <a href="mailto:Plasma-devel@kde.org">Plasma-devel@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/plasma-devel" \
target="_blank">https://mail.kde.org/mailman/listinfo/plasma-devel</a><br> \
</div></div></blockquote></div><br>I&#39;ve updated the patch and now it correctly \
shows the capacity bar. There&#39;s only a little issue: as soon as the device gets \
&quot;mounted&quot; the engine does not return a valid &quot;Free Space&quot; data. \
This is probably a problem with the engine or, worse, with solid.. Will check it out \
though..<br> <br><br clear="all"><br>-- <br>Alessandro Diaferia<br>KDE Developer<br>

--0015174c0f0ccf62130471690b37--


["notifier_latest.diff" (text/plain)]

Index: devicenotifier.cpp
===================================================================
--- devicenotifier.cpp	(revision 1012848)
+++ devicenotifier.cpp	(working copy)
@@ -180,6 +180,10 @@ void DeviceNotifier::dataUpdated(const Q
 
         //data from soliddevice engine
     } else if (data["Device Types"].toStringList().contains("Storage Access")) {
+        QList<QVariant> freeSpaceData;
+        freeSpaceData << QVariant(0) << QVariant(0);
+        m_dialog->setDeviceData(source, QVariant(freeSpaceData), \
NotifierDialog::DeviceFreeSpaceRole); +
         //kDebug() << "DeviceNotifier::solidDeviceEngine updated" << source;
         if (data["Accessible"].toBool() == true) {
             m_dialog->setUnMount(true,source);
@@ -188,6 +192,12 @@ void DeviceNotifier::dataUpdated(const Q
             QStringList overlays;
             overlays << "emblem-mounted";
             m_dialog->setDeviceData(source, \
KIcon(m_dialog->getDeviceData(source,NotifierDialog::IconNameRole).toString(), NULL, \
overlays), Qt::DecorationRole); + 
+            if (data["Free Space"].isValid()) {
+                QList<QVariant> freeSpaceData;
+                freeSpaceData << data["Size"] << data["Free Space"];
+                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);
Index: notifierdialog.cpp
===================================================================
--- notifierdialog.cpp	(revision 1012848)
+++ notifierdialog.cpp	(working copy)
@@ -51,6 +51,7 @@
 //own
 #include "notifierview.h"
 #include "devicenotifier.h"
+#include "devicespaceinfodelegate.h"
 
 using namespace Notifier;
 using namespace Plasma;
@@ -273,7 +274,9 @@ void NotifierDialog::buildDialog()
     m_notifierView->setMinimumSize(150,300);
     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);
Index: devicespaceinfodelegate.cpp
===================================================================
--- devicespaceinfodelegate.cpp	(revision 0)
+++ devicespaceinfodelegate.cpp	(revision 0)
@@ -0,0 +1,73 @@
+/*  Copyright 2009 by Martin Klapetek <martin.klapetek@gmail.com>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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 Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+#include "devicespaceinfodelegate.h"
+
+#include <kcapacitybar.h>
+#include <KLocale>
+#include <KGlobal>
+#include <KDebug>
+
+DeviceSpaceInfoDelegate::DeviceSpaceInfoDelegate(QObject* parent)
+    : Plasma::Delegate(parent),
+    m_capacityBar(0)
+{
+    m_capacityBar = new KCapacityBar(KCapacityBar::DrawTextInline);
+    m_capacityBar->setMaximumWidth(200);
+    m_capacityBar->setMinimumWidth(200);
+}
+
+DeviceSpaceInfoDelegate::~DeviceSpaceInfoDelegate()
+{
+    delete m_capacityBar;
+}
+
+void DeviceSpaceInfoDelegate::paint(QPainter* painter, const QStyleOptionViewItem& \
option, const QModelIndex& index) const +{
+    painter->save();
+    Plasma::Delegate::paint(painter, option, index);
+
+    QVariantList sizes = index.data(Qt::UserRole + 7).value<QVariantList>(); // \
DeviceFreeSpaceRole =  Qt::UserRole + 7 +    qulonglong size = 0;
+    if (sizes.count() == 2) {
+        kDebug() << sizes[0].typeName();
+	kDebug() << sizes[1].typeName();
+        size = qulonglong(sizes[0].toULongLong());
+	kDebug() << size;
+        qulonglong freeSpace = qulonglong(sizes[1].toULongLong());
+        qulonglong usedSpace = size - freeSpace;
+
+	m_capacityBar->setText(i18nc("@info:status Free disk space", "%1  free", \
KGlobal::locale()->formatByteSize(freeSpace))); +        \
m_capacityBar->setUpdatesEnabled(false); +        m_capacityBar->setValue(size > 0 ? \
(usedSpace * 100) / size : 0); +        m_capacityBar->setUpdatesEnabled(true);
+    }
+    if (size) {
+        m_capacityBar->drawCapacityBar(painter, QRect(QPoint(option.rect.x()+48, \
Plasma::Delegate::rectAfterTitle(option, index).bottom()-5),  QSize(120, 14))); +    \
} +    painter->restore();
+}
+
+QSize DeviceSpaceInfoDelegate::sizeHint(const QStyleOptionViewItem& option, const \
QModelIndex& index) const +{
+    Q_UNUSED(option)
+    Q_UNUSED(index)
+
+    QSize size = Plasma::Delegate::sizeHint(option, index);
+    size.setHeight(size.height()+m_capacityBar->barHeight()+14); //+14 is for \
kcapacitybar padding +    return size;
+}
Index: notifierdialog.h
===================================================================
--- notifierdialog.h	(revision 1012848)
+++ notifierdialog.h	(working copy)
@@ -69,9 +69,10 @@ namespace Notifier
               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
Index: devicespaceinfodelegate.h
===================================================================
--- devicespaceinfodelegate.h	(revision 0)
+++ devicespaceinfodelegate.h	(revision 0)
@@ -0,0 +1,45 @@
+/* Copyright 2009 by Martin Klapetek <martin.klapetek@gmail.com>
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public
+   License version 2 as published by the Free Software Foundation.
+
+   This library 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 Library General Public License
+   along with this library; see the file COPYING.LIB.  If not, write to
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
+*/
+
+#ifndef DEVICESPACEINFODELEGATE_H
+#define DEVICESPACEINFODELEGATE_H
+
+#include <plasma/delegate.h>
+
+#include <QStyleOptionViewItem>
+#include <QModelIndex>
+
+#include <QStandardItemModel>
+#include <QPainter>
+
+
+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; +protected:
+    virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex & \
index) const; +private:
+    KCapacityBar *m_capacityBar;
+};
+
+#endif // DEVICESPACEINFODELEGATE_H
Index: notifierview.cpp
===================================================================
--- notifierview.cpp	(revision 1012848)
+++ notifierview.cpp	(working copy)
@@ -18,6 +18,8 @@
 */
 
 #include "notifierview.h"
+#include "devicespaceinfodelegate.h"
+#include "notifierdialog.h"
 
 // Qt
 
@@ -280,7 +282,10 @@ void NotifierView::paintItem(QPainter &p
     if (index == currentIndex()) {
         option.state |= QStyle::State_HasFocus;
     }
-
+    QList<QVariant> freeSpaceData = \
index.data(NotifierDialog::DeviceFreeSpaceRole).toList(); +    if \
(freeSpaceData.count() > 0) { +        \
((DeviceSpaceInfoDelegate*)itemDelegate(index))->setData(freeSpaceData[0], \
freeSpaceData[1]); +    }
     itemDelegate(index)->paint(&painter,option,index);
 }
 
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 1012848)
+++ CMakeLists.txt	(working copy)
@@ -3,7 +3,8 @@ project(plasma-devicenotifier)
 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})



_______________________________________________
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