[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE
From: Norbert Frese <nf2 () scheinwelt ! at>
Date: 2009-11-08 21:58:05
Message-ID: 1257717485.124357.23321.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1046506 by nfrese:
Factors out some useful information inside the model and avoids duplicated code in \
3rd parties.
New Roles:
* FixedDeviceRole: True for drives, which are (!hotpluggable && !removable)
* CapacityBarRecommendedRole: True for devices, which are: (accessible && !Cdrom)
See also: http://reviewboard.kde.org/r/1880/
M +3 -19 kdebase/workspace/plasma/desktop/applets/kickoff/core/systemmodel.cpp \
M +28 -0 kdelibs/kfile/kfileplacesitem.cpp
M +3 -1 kdelibs/kfile/kfileplacesmodel.h
M +12 -22 kdelibs/kfile/kfileplacesview.cpp
--- trunk/KDE/kdebase/workspace/plasma/desktop/applets/kickoff/core/systemmodel.cpp \
#1046505:1046506 @@ -143,16 +143,9 @@
if (!d->placesModel->isDevice(sourceIndex)) {
parent = index(BOOKMARKS_ROW, 0);
} else {
- Solid::Device dev = d->placesModel->deviceForIndex(sourceIndex);
+ bool isFixedDevice = d->placesModel->data(sourceIndex, \
KFilePlacesModel::FixedDeviceRole).toBool();
- Solid::StorageDrive *drive = 0;
- Solid::Device parentDevice = dev;
- while (parentDevice.isValid() && !drive) {
- drive = parentDevice.as<Solid::StorageDrive>();
- parentDevice = parentDevice.parent();
- }
-
- if (drive && (drive->isHotpluggable() || drive->isRemovable())) {
+ if (!isFixedDevice) {
parent = index(REMOVABLE_ROW, 0);
} else {
parent = index(FIXED_ROW, 0);
@@ -277,17 +270,8 @@
if (!isDevice && parent.row() == BOOKMARKS_ROW) {
wellPlaced = true;
} else if (isDevice) {
- Solid::Device dev = d->placesModel->deviceForIndex(sourceIndex);
+ bool fixed = d->placesModel->data(sourceIndex, \
KFilePlacesModel::FixedDeviceRole).toBool();
- Solid::StorageDrive *drive = 0;
- Solid::Device parentDevice = dev;
- while (parentDevice.isValid() && !drive) {
- drive = parentDevice.as<Solid::StorageDrive>();
- parentDevice = parentDevice.parent();
- }
-
- bool fixed = !drive || (!drive->isHotpluggable() && \
!drive->isRemovable());
-
if (!fixed && parent.row() == REMOVABLE_ROW) {
wellPlaced = true;
} else if (fixed && parent.row() == FIXED_ROW) {
--- trunk/KDE/kdelibs/kfile/kfileplacesitem.cpp #1046505:1046506
@@ -29,6 +29,7 @@
#include <solid/opticaldisc.h>
#include <solid/storageaccess.h>
#include <solid/storagevolume.h>
+#include <solid/storagedrive.h>
KFilePlacesItem::KFilePlacesItem(KBookmarkManager *manager,
@@ -183,6 +184,33 @@
} else {
return QVariant();
}
+
+ case KFilePlacesModel::FixedDeviceRole:
+ {
+ Solid::StorageDrive *drive = 0;
+ Solid::Device parentDevice = m_device;
+ while (parentDevice.isValid() && !drive) {
+ drive = parentDevice.as<Solid::StorageDrive>();
+ parentDevice = parentDevice.parent();
+ }
+ if (drive!=0) {
+ return !drive->isHotpluggable() && !drive->isRemovable();
+ }
+ return true;
+ }
+
+ case KFilePlacesModel::CapacityBarRecommendedRole:
+ {
+ bool accessible = m_access && m_access->isAccessible();
+ bool isCdrom =
+ ((m_device.is<Solid::StorageDrive>()
+ && m_device.as<Solid::StorageDrive>()->driveType() == \
Solid::StorageDrive::CdromDrive) + || \
(m_device.parent().is<Solid::StorageDrive>() + && \
m_device.parent().as<Solid::StorageDrive>()->driveType() == \
Solid::StorageDrive::CdromDrive)); +
+ return accessible && !isCdrom;
+ }
+
default:
return QVariant();
}
--- trunk/KDE/kdelibs/kfile/kfileplacesmodel.h #1046505:1046506
@@ -44,7 +44,9 @@
enum AdditionalRoles {
UrlRole = 0x069CD12B,
HiddenRole = 0x0741CAAC,
- SetupNeededRole = 0x059A935D
+ SetupNeededRole = 0x059A935D,
+ FixedDeviceRole = 0x332896C1,
+ CapacityBarRecommendedRole = 0x1548C5C4
};
KFilePlacesModel(QObject *parent=0);
--- trunk/KDE/kdelibs/kfile/kfileplacesview.cpp #1046505:1046506
@@ -149,19 +149,6 @@
}
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, \
painter);
const KFilePlacesModel *placesModel = static_cast<const \
KFilePlacesModel*>(index.model());
- bool isRemovableDevice = false;
- Solid::Device device;
- if (placesModel->isDevice(index)) {
- device = placesModel->deviceForIndex(index);
- if (((device.is<Solid::StorageAccess>() && \
device.as<Solid::StorageAccess>()->isAccessible()) ||
- (device.parent().is<Solid::StorageAccess>() && \
device.parent().as<Solid::StorageAccess>()->isAccessible())) &&
- ((device.is<Solid::StorageDrive>() && \
device.as<Solid::StorageDrive>()->isRemovable()) ||
- (device.parent().is<Solid::StorageDrive>() && \
device.parent().as<Solid::StorageDrive>()->isRemovable())) &&
- ((device.is<Solid::StorageDrive>() && \
device.as<Solid::StorageDrive>()->driveType() != \
Solid::StorageDrive::CdromDrive) ||
- (device.parent().is<Solid::StorageDrive>() && \
device.parent().as<Solid::StorageDrive>()->driveType() != \
Solid::StorageDrive::CdromDrive))) {
- isRemovableDevice = true;
- }
- }
bool isLTR = option.direction == Qt::LeftToRight;
@@ -176,7 +163,14 @@
}
QRect rectText;
- if (isRemovableDevice && contentsOpacity(index) > 0) {
+
+ QString mountPointPath = placesModel->url(index).toLocalFile();
+ KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mountPointPath);
+ bool drawCapacityBar = info.size() != 0 &&
+ placesModel->data(index, \
KFilePlacesModel::CapacityBarRecommendedRole).toBool(); +
+ if (drawCapacityBar && contentsOpacity(index) > 0)
+ {
painter->save();
painter->setOpacity(painter->opacity() * contentsOpacity(index));
@@ -185,13 +179,9 @@
: 0, option.rect.top() + (option.rect.height() / 2 - \
height / 2), option.rect.width() - m_iconSize - LATERAL_MARGIN * 2, \
option.fontMetrics.height()); painter->drawText(rectText, Qt::AlignLeft | \
Qt::AlignTop, option.fontMetrics.elidedText(index.model()->data(index).toString(), \
Qt::ElideRight, rectText.width()));
QRect capacityRect(isLTR ? rectText.x() : LATERAL_MARGIN, rectText.bottom() \
- 1, rectText.width() - LATERAL_MARGIN, CAPACITYBAR_HEIGHT);
- Solid::StorageAccess *storage = device.as<Solid::StorageAccess>();
- KDiskFreeSpaceInfo info = \
KDiskFreeSpaceInfo::freeSpaceInfo(storage->filePath());
- if (info.size()) {
- KCapacityBar capacityBar(KCapacityBar::DrawTextInline);
- capacityBar.setValue((info.used() * 100) / info.size());
- capacityBar.drawCapacityBar(painter, capacityRect);
- }
+ KCapacityBar capacityBar(KCapacityBar::DrawTextInline);
+ capacityBar.setValue((info.used() * 100) / info.size());
+ capacityBar.drawCapacityBar(painter, capacityRect);
painter->restore();
@@ -203,7 +193,7 @@
: 0, option.rect.top(), option.rect.width() - m_iconSize \
- LATERAL_MARGIN * 2, option.rect.height()); painter->drawText(rectText, \
Qt::AlignLeft | Qt::AlignVCenter, \
option.fontMetrics.elidedText(index.model()->data(index).toString(), Qt::ElideRight, \
rectText.width()));
- if (isRemovableDevice && contentsOpacity(index) > 0) {
+ if (drawCapacityBar && contentsOpacity(index) > 0) {
painter->restore();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic