diff options
Diffstat (limited to 'src/statusbar')
| -rw-r--r-- | src/statusbar/dolphinstatusbar.cpp | 33 | ||||
| -rw-r--r-- | src/statusbar/dolphinstatusbar.h | 10 | ||||
| -rw-r--r-- | src/statusbar/mountpointobserver.cpp | 29 | ||||
| -rw-r--r-- | src/statusbar/mountpointobserver.h | 28 | ||||
| -rw-r--r-- | src/statusbar/mountpointobservercache.cpp | 44 | ||||
| -rw-r--r-- | src/statusbar/mountpointobservercache.h | 8 | ||||
| -rw-r--r-- | src/statusbar/spaceinfoobserver.cpp | 72 | ||||
| -rw-r--r-- | src/statusbar/spaceinfoobserver.h | 16 | ||||
| -rw-r--r-- | src/statusbar/spaceinfotoolsmenu.cpp | 103 | ||||
| -rw-r--r-- | src/statusbar/spaceinfotoolsmenu.h | 41 | ||||
| -rw-r--r-- | src/statusbar/statusbarspaceinfo.cpp | 21 | ||||
| -rw-r--r-- | src/statusbar/statusbarspaceinfo.h | 19 |
12 files changed, 294 insertions, 130 deletions
diff --git a/src/statusbar/dolphinstatusbar.cpp b/src/statusbar/dolphinstatusbar.cpp index e0fdc8703..166f6ab14 100644 --- a/src/statusbar/dolphinstatusbar.cpp +++ b/src/statusbar/dolphinstatusbar.cpp @@ -21,11 +21,9 @@ #include "dolphin_generalsettings.h" -#include <KIconLoader> -#include <KIcon> -#include <KLocale> -#include <KMenu> -#include <KVBox> +#include <QIcon> +#include <KLocalizedString> +#include <QMenu> #include "statusbarspaceinfo.h" @@ -33,10 +31,12 @@ #include <QHBoxLayout> #include <QLabel> #include <QProgressBar> -#include <QTextDocument> #include <QToolButton> #include <QTime> #include <QTimer> +#include <QSlider> +#include <QTextDocument> +#include <QHelpEvent> #include <views/dolphinview.h> #include <views/zoomlevelinfo.h> @@ -72,21 +72,21 @@ DolphinStatusBar::DolphinStatusBar(QWidget* parent) : m_zoomSlider->setPageStep(1); m_zoomSlider->setRange(ZoomLevelInfo::minimumLevel(), ZoomLevelInfo::maximumLevel()); - connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SIGNAL(zoomLevelChanged(int))); - connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(updateZoomSliderToolTip(int))); - connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(showZoomSliderToolTip(int))); + connect(m_zoomSlider, &QSlider::valueChanged, this, &DolphinStatusBar::zoomLevelChanged); + connect(m_zoomSlider, &QSlider::valueChanged, this, &DolphinStatusBar::updateZoomSliderToolTip); + connect(m_zoomSlider, &QSlider::sliderMoved, this, &DolphinStatusBar::showZoomSliderToolTip); // Initialize space information m_spaceInfo = new StatusBarSpaceInfo(this); // Initialize progress information m_stopButton = new QToolButton(this); - m_stopButton->setIcon(KIcon("process-stop")); + m_stopButton->setIcon(QIcon::fromTheme("process-stop")); m_stopButton->setAccessibleName(i18n("Stop")); m_stopButton->setAutoRaise(true); m_stopButton->setToolTip(i18nc("@tooltip", "Stop loading")); m_stopButton->hide(); - connect(m_stopButton, SIGNAL(clicked()), this, SIGNAL(stopPressed())); + connect(m_stopButton, &QToolButton::clicked, this, &DolphinStatusBar::stopPressed); m_progressTextLabel = new QLabel(this); m_progressTextLabel->hide(); @@ -97,12 +97,12 @@ DolphinStatusBar::DolphinStatusBar(QWidget* parent) : m_showProgressBarTimer = new QTimer(this); m_showProgressBarTimer->setInterval(500); m_showProgressBarTimer->setSingleShot(true); - connect(m_showProgressBarTimer, SIGNAL(timeout()), this, SLOT(updateProgressInfo())); + connect(m_showProgressBarTimer, &QTimer::timeout, this, &DolphinStatusBar::updateProgressInfo); m_resetToDefaultTextTimer = new QTimer(this); m_resetToDefaultTextTimer->setInterval(ResetToDefaultTimeout); m_resetToDefaultTextTimer->setSingleShot(true); - connect(m_resetToDefaultTextTimer, SIGNAL(timeout()), this, SLOT(slotResetToDefaultText())); + connect(m_resetToDefaultTextTimer, &QTimer::timeout, this, &DolphinStatusBar::slotResetToDefaultText); // Initialize top layout and size policies const int fontHeight = QFontMetrics(m_label->font()).height(); @@ -228,12 +228,12 @@ QString DolphinStatusBar::defaultText() const return m_defaultText; } -void DolphinStatusBar::setUrl(const KUrl& url) +void DolphinStatusBar::setUrl(const QUrl& url) { m_spaceInfo->setUrl(url); } -KUrl DolphinStatusBar::url() const +QUrl DolphinStatusBar::url() const { return m_spaceInfo->url(); } @@ -259,7 +259,7 @@ void DolphinStatusBar::contextMenuEvent(QContextMenuEvent* event) { Q_UNUSED(event); - KMenu menu(this); + QMenu menu(this); QAction* showZoomSliderAction = menu.addAction(i18nc("@action:inmenu", "Show Zoom Slider")); showZoomSliderAction->setCheckable(true); @@ -357,4 +357,3 @@ void DolphinStatusBar::setExtensionsVisible(bool visible) m_zoomSlider->setVisible(showZoomSlider); } -#include "dolphinstatusbar.moc" diff --git a/src/statusbar/dolphinstatusbar.h b/src/statusbar/dolphinstatusbar.h index 4d6dbb20f..1a4ccf682 100644 --- a/src/statusbar/dolphinstatusbar.h +++ b/src/statusbar/dolphinstatusbar.h @@ -23,7 +23,7 @@ #include <QTime> #include <QWidget> -class KUrl; +class QUrl; class StatusBarSpaceInfo; class QLabel; class QProgressBar; @@ -79,7 +79,7 @@ public: void setDefaultText(const QString& text); QString defaultText() const; - KUrl url() const; + QUrl url() const; int zoomLevel() const; /** @@ -89,7 +89,7 @@ public: public slots: void setText(const QString& text); - void setUrl(const KUrl& url); + void setUrl(const QUrl& url); void setZoomLevel(int zoomLevel); signals: @@ -101,8 +101,8 @@ signals: void zoomLevelChanged(int zoomLevel); protected: - virtual void contextMenuEvent(QContextMenuEvent* event); - virtual bool eventFilter(QObject* obj, QEvent* event); + virtual void contextMenuEvent(QContextMenuEvent* event) Q_DECL_OVERRIDE; + virtual bool eventFilter(QObject* obj, QEvent* event) Q_DECL_OVERRIDE; private slots: void showZoomSliderToolTip(int zoomLevel); diff --git a/src/statusbar/mountpointobserver.cpp b/src/statusbar/mountpointobserver.cpp index 4a23be6b6..df2a4898f 100644 --- a/src/statusbar/mountpointobserver.cpp +++ b/src/statusbar/mountpointobserver.cpp @@ -17,20 +17,21 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ +#include <KIO/FileSystemFreeSpaceJob> + #include "mountpointobserver.h" #include "mountpointobservercache.h" -MountPointObserver::MountPointObserver(const QString& mountPoint, QObject* parent) : +MountPointObserver::MountPointObserver(const QUrl& url, QObject* parent) : QObject(parent), - m_mountPoint(mountPoint), - m_referenceCount(0), - m_spaceInfo(KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint)) + m_url(url), + m_referenceCount(0) { } -MountPointObserver* MountPointObserver::observerForPath(const QString& path) +MountPointObserver* MountPointObserver::observerForUrl(const QUrl& url) { - MountPointObserver* observer = MountPointObserverCache::instance()->observerForPath(path); + MountPointObserver* observer = MountPointObserverCache::instance()->observerForUrl(url); return observer; } @@ -39,10 +40,16 @@ void MountPointObserver::update() if (m_referenceCount == 0) { delete this; } else { - const KDiskFreeSpaceInfo spaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(m_mountPoint); - if (spaceInfo.size() != m_spaceInfo.size() || spaceInfo.available() != m_spaceInfo.available()) { - m_spaceInfo = spaceInfo; - emit spaceInfoChanged(); - } + KIO::FileSystemFreeSpaceJob* job = KIO::fileSystemFreeSpace(m_url); + connect(job, &KIO::FileSystemFreeSpaceJob::result, this, &MountPointObserver::freeSpaceResult); + } +} + +void MountPointObserver::freeSpaceResult(KIO::Job* job, KIO::filesize_t size, KIO::filesize_t available) +{ + if (!job->error()) { + emit spaceInfoChanged(size, available); + } else { + emit spaceInfoChanged(0, 0); } } diff --git a/src/statusbar/mountpointobserver.h b/src/statusbar/mountpointobserver.h index ac5f8ecc3..c3d2aa677 100644 --- a/src/statusbar/mountpointobserver.h +++ b/src/statusbar/mountpointobserver.h @@ -20,9 +20,10 @@ #ifndef MOUNTPOINTOBSERVER_H #define MOUNTPOINTOBSERVER_H -#include <KDiskFreeSpaceInfo> +#include <KIO/Job> #include <QObject> +#include <QUrl> /** * A MountPointObserver can be used to determine the free space on a mount @@ -52,16 +53,11 @@ class MountPointObserver : public QObject { Q_OBJECT - explicit MountPointObserver(const QString& mountPoint, QObject* parent = 0); + explicit MountPointObserver(const QUrl& url, QObject* parent = 0); virtual ~MountPointObserver() {} public: /** - * Obtains information about the available space on the observed mount point. - */ - KDiskFreeSpaceInfo spaceInfo() const { return m_spaceInfo; } - - /** * Call this function to indicate that the caller intends to continue using this object. An * internal reference count is increased then. When the observer is not needed any more, * deref() should be called, which decreases the reference count again. @@ -80,28 +76,30 @@ public: } /** - * Returns a MountPointObserver for the given \a path. If the caller intends to continue using + * Returns a MountPointObserver for the given \a url. If the caller intends to continue using * the returned object, it must call its ref() method. */ - static MountPointObserver* observerForPath(const QString& path); + static MountPointObserver* observerForUrl(const QUrl& url); signals: /** - * This signal is emitted if the information that spaceInfo() will return has changed. + * This signal is emitted when the size has been retrieved. */ - void spaceInfoChanged(); + void spaceInfoChanged(quint64 size, quint64 available); public slots: /** - * If this slot is invoked, MountPointObserver checks if the available space on the observed - * mount point has changed, and emits spaceInfoChanged() if that is the case. + * If this slot is invoked, MountPointObserver starts a new driveSize job + * to get the drive's size. */ void update(); +private slots: + void freeSpaceResult(KIO::Job* job, KIO::filesize_t size, KIO::filesize_t available); + private: - const QString m_mountPoint; + const QUrl m_url; int m_referenceCount; - KDiskFreeSpaceInfo m_spaceInfo; friend class MountPointObserverCache; }; diff --git a/src/statusbar/mountpointobservercache.cpp b/src/statusbar/mountpointobservercache.cpp index aff0c8e2f..ab3744eac 100644 --- a/src/statusbar/mountpointobservercache.cpp +++ b/src/statusbar/mountpointobservercache.cpp @@ -21,7 +21,6 @@ #include "mountpointobserver.h" -#include <KGlobal> #include <KMountPoint> #include <QTimer> @@ -31,7 +30,7 @@ class MountPointObserverCacheSingleton public: MountPointObserverCache instance; }; -K_GLOBAL_STATIC(MountPointObserverCacheSingleton, s_MountPointObserverCache) +Q_GLOBAL_STATIC(MountPointObserverCacheSingleton, s_MountPointObserverCache) MountPointObserverCache::MountPointObserverCache() : @@ -51,33 +50,38 @@ MountPointObserverCache* MountPointObserverCache::instance() return &s_MountPointObserverCache->instance; } -MountPointObserver* MountPointObserverCache::observerForPath(const QString& path) +MountPointObserver* MountPointObserverCache::observerForUrl(const QUrl& url) { - // Try to share the observer with other paths that have the same mount point. - QString mountPointPath; - KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(path); - if (mountPoint) { - mountPointPath = mountPoint->mountPoint(); + QUrl cachedObserverUrl; + // If the url is a local path we can extract the root dir by checking the mount points. + if (url.isLocalFile()) { + // Try to share the observer with other paths that have the same mount point. + KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(url.toLocalFile()); + if (mountPoint) { + cachedObserverUrl = QUrl::fromLocalFile(mountPoint->mountPoint()); + } else { + // Even if determining the mount point failed, the observer might still + // be able to retrieve information about the url. + cachedObserverUrl = url.toLocalFile(); + } } else { - // Even if determining the mount point failed, KDiskFreeSpaceInfo might still - // be able to retrieve information about the path. - mountPointPath = path; + cachedObserverUrl = url.url(); } - MountPointObserver* observer = m_observerForMountPoint.value(mountPointPath); + MountPointObserver* observer = m_observerForMountPoint.value(cachedObserverUrl); if (!observer) { - observer = new MountPointObserver(mountPointPath, this); - m_observerForMountPoint.insert(mountPointPath, observer); - m_mountPointForObserver.insert(observer, mountPointPath); + observer = new MountPointObserver(cachedObserverUrl, this); + m_observerForMountPoint.insert(cachedObserverUrl, observer); + m_mountPointForObserver.insert(observer, cachedObserverUrl); Q_ASSERT(m_observerForMountPoint.count() == m_mountPointForObserver.count()); - connect(observer, SIGNAL(destroyed(QObject*)), this, SLOT(slotObserverDestroyed(QObject*))); + connect(observer, &MountPointObserver::destroyed, this, &MountPointObserverCache::slotObserverDestroyed); if (!m_updateTimer->isActive()) { m_updateTimer->start(10000); } - connect(m_updateTimer, SIGNAL(timeout()), observer, SLOT(update())); + connect(m_updateTimer, &QTimer::timeout, observer, &MountPointObserver::update); } return observer; @@ -86,9 +90,9 @@ MountPointObserver* MountPointObserverCache::observerForPath(const QString& path void MountPointObserverCache::slotObserverDestroyed(QObject* observer) { Q_ASSERT(m_mountPointForObserver.contains(observer)); - const QString& path = m_mountPointForObserver.value(observer); - Q_ASSERT(m_observerForMountPoint.contains(path)); - m_observerForMountPoint.remove(path); + const QUrl& url = m_mountPointForObserver.value(observer); + Q_ASSERT(m_observerForMountPoint.contains(url)); + m_observerForMountPoint.remove(url); m_mountPointForObserver.remove(observer); Q_ASSERT(m_observerForMountPoint.count() == m_mountPointForObserver.count()); diff --git a/src/statusbar/mountpointobservercache.h b/src/statusbar/mountpointobservercache.h index 425000645..8a1496d89 100644 --- a/src/statusbar/mountpointobservercache.h +++ b/src/statusbar/mountpointobservercache.h @@ -37,9 +37,9 @@ public: static MountPointObserverCache* instance(); /** - * Returns a MountPointObserver for the given \a path. A new observer is created if necessary. + * Returns a MountPointObserver for the given \a url. A new observer is created if necessary. */ - MountPointObserver* observerForPath(const QString& path); + MountPointObserver* observerForUrl(const QUrl& url); private slots: /** @@ -48,8 +48,8 @@ private slots: void slotObserverDestroyed(QObject* observer); private: - QHash<QString, MountPointObserver*> m_observerForMountPoint; - QHash<QObject*, QString> m_mountPointForObserver; + QHash<QUrl, MountPointObserver*> m_observerForMountPoint; + QHash<QObject*, QUrl> m_mountPointForObserver; QTimer* m_updateTimer; friend class MountPointObserverCacheSingleton; diff --git a/src/statusbar/spaceinfoobserver.cpp b/src/statusbar/spaceinfoobserver.cpp index 9125a9308..0fb018727 100644 --- a/src/statusbar/spaceinfoobserver.cpp +++ b/src/statusbar/spaceinfoobserver.cpp @@ -21,17 +21,18 @@ #include "mountpointobserver.h" -#include <KUrl> +#include <QUrl> -SpaceInfoObserver::SpaceInfoObserver(const KUrl& url, QObject* parent) : +SpaceInfoObserver::SpaceInfoObserver(const QUrl& url, QObject* parent) : QObject(parent), - m_mountPointObserver(0) + m_mountPointObserver(0), + m_dataSize(0), + m_dataAvailable(0) { - if (url.isLocalFile()) { - m_mountPointObserver = MountPointObserver::observerForPath(url.toLocalFile()); - m_mountPointObserver->ref(); - connect(m_mountPointObserver, SIGNAL(spaceInfoChanged()), this, SIGNAL(valuesChanged())); - } + m_mountPointObserver = MountPointObserver::observerForUrl(url); + m_mountPointObserver->ref(); + connect(m_mountPointObserver, &MountPointObserver::spaceInfoChanged, this, &SpaceInfoObserver::spaceInfoChanged); + m_mountPointObserver->update(); } SpaceInfoObserver::~SpaceInfoObserver() @@ -44,46 +45,41 @@ SpaceInfoObserver::~SpaceInfoObserver() quint64 SpaceInfoObserver::size() const { - if (m_mountPointObserver && m_mountPointObserver->spaceInfo().isValid()) { - return m_mountPointObserver->spaceInfo().size(); - } else { - return 0; - } + return m_dataSize; } quint64 SpaceInfoObserver::available() const { - if (m_mountPointObserver && m_mountPointObserver->spaceInfo().isValid()) { - return m_mountPointObserver->spaceInfo().available(); - } else { - return 0; - } + return m_dataAvailable; } -void SpaceInfoObserver::setUrl(const KUrl& url) +void SpaceInfoObserver::setUrl(const QUrl& url) { - if (url.isLocalFile()) { - MountPointObserver* newObserver = MountPointObserver::observerForPath(url.toLocalFile()); - if (newObserver != m_mountPointObserver) { - if (m_mountPointObserver) { - disconnect(m_mountPointObserver, SIGNAL(spaceInfoChanged()), this, SIGNAL(valuesChanged())); - m_mountPointObserver->deref(); - m_mountPointObserver = 0; - } - - m_mountPointObserver = newObserver; - m_mountPointObserver->ref(); - connect(m_mountPointObserver, SIGNAL(spaceInfoChanged()), this, SIGNAL(valuesChanged())); - - emit valuesChanged(); - } - } else { + MountPointObserver* newObserver = MountPointObserver::observerForUrl(url); + if (newObserver != m_mountPointObserver) { if (m_mountPointObserver) { - disconnect(m_mountPointObserver, SIGNAL(spaceInfoChanged()), this, SIGNAL(valuesChanged())); + disconnect(m_mountPointObserver, &MountPointObserver::spaceInfoChanged, this, &SpaceInfoObserver::spaceInfoChanged); m_mountPointObserver->deref(); m_mountPointObserver = 0; - - emit valuesChanged(); } + + m_mountPointObserver = newObserver; + m_mountPointObserver->ref(); + connect(m_mountPointObserver, &MountPointObserver::spaceInfoChanged, this, &SpaceInfoObserver::spaceInfoChanged); + + // If newObserver is cached it won't call update until the next timer update, + // so update the observer now. + m_mountPointObserver->update(); + } +} + +void SpaceInfoObserver::spaceInfoChanged(quint64 size, quint64 available) +{ + // Make sure that the size has actually changed + if (m_dataSize != size || m_dataAvailable != available) { + m_dataSize = size; + m_dataAvailable = available; + + emit valuesChanged(); } } diff --git a/src/statusbar/spaceinfoobserver.h b/src/statusbar/spaceinfoobserver.h index d2fb6ebf3..e1311abde 100644 --- a/src/statusbar/spaceinfoobserver.h +++ b/src/statusbar/spaceinfoobserver.h @@ -22,7 +22,9 @@ #include <QObject> -class KUrl; +#include <KIO/Job> + +class QUrl; class MountPointObserver; class SpaceInfoObserver : public QObject @@ -30,22 +32,28 @@ class SpaceInfoObserver : public QObject Q_OBJECT public: - explicit SpaceInfoObserver(const KUrl& url, QObject* parent = 0); + explicit SpaceInfoObserver(const QUrl& url, QObject* parent = 0); virtual ~SpaceInfoObserver(); quint64 size() const; quint64 available() const; - void setUrl(const KUrl& url); + void setUrl(const QUrl& url); signals: /** - * This signal is emitted if the information that size() and/or available() will return has changed. + * This signal is emitted when the size or available space changes. */ void valuesChanged(); +private slots: + void spaceInfoChanged(quint64 size, quint64 available); + private: MountPointObserver* m_mountPointObserver; + + quint64 m_dataSize; + quint64 m_dataAvailable; }; #endif diff --git a/src/statusbar/spaceinfotoolsmenu.cpp b/src/statusbar/spaceinfotoolsmenu.cpp new file mode 100644 index 000000000..bce5ba11d --- /dev/null +++ b/src/statusbar/spaceinfotoolsmenu.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (C) 2014 by Gregor Mi <[email protected]> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "spaceinfotoolsmenu.h" + +#include <QAction> +#include <QUrl> + +#include <KMountPoint> +#include <KLocalizedString> +#include <KRun> +#include <KService> + +SpaceInfoToolsMenu::SpaceInfoToolsMenu(QWidget* parent, QUrl url) + : QMenu(parent) +{ + const QString notInstalled = " [" + i18nc("@action:inmenu", "not installed") + "]"; + + // find service + // + const auto filelightService = KService::serviceByDesktopName("org.kde.filelight"); + if (filelightService && filelightService->isApplication()) { + const auto filelightIcon = QIcon::fromTheme(filelightService->icon()); + + if (url.isLocalFile()) { // 2015-01-12: Filelight can handle FTP connections but KIO/kioexec cannot (bug or feature?), so we don't offer it in this case + // add action and connect signals + // + const auto startFilelightDirectoryAction = addAction(filelightService->genericName() + " - " + + i18nc("@action:inmenu", "current folder")); + startFilelightDirectoryAction->setIcon(filelightIcon); + + connect(startFilelightDirectoryAction, &QAction::triggered, this, [filelightService, url](bool) { + KRun::runService(*filelightService, { url }, nullptr); + }); + } + + if (url.isLocalFile()) { // makes no sense for non-local URLs (e.g. FTP server), so we don't offer it in this case + // add action and connect signals + // + const auto startFilelightDeviceAction = addAction(filelightService->genericName() + " - " + + i18nc("@action:inmenu", "current device")); + startFilelightDeviceAction->setIcon(filelightIcon); + + connect(startFilelightDeviceAction, &QAction::triggered, this, [filelightService, url](bool) { + KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(url.toLocalFile()); + KRun::runService(*filelightService, { mountPoint->mountPoint() }, nullptr); + }); + } + + // add action and connect signals + // + const auto startFilelightAllDevicesAction = addAction(filelightService->genericName() + " - " + + i18nc("@action:inmenu", "all devices")); + startFilelightAllDevicesAction->setIcon(filelightIcon); + + connect(startFilelightAllDevicesAction, &QAction::triggered, this, [filelightService](bool) { + KRun::runService(*filelightService, { }, nullptr); + }); + } else { + const auto startFilelightDirectoryAction = addAction("Filelight" + notInstalled); + startFilelightDirectoryAction->setEnabled(false); + } + + // find service + // + const auto kdiskfreeService = KService::serviceByDesktopName("kdf"); + if (kdiskfreeService && kdiskfreeService->isApplication()) { + // + // add action and connect signals + // + const auto startKDiskFreeAction = addAction(kdiskfreeService->genericName()); + startKDiskFreeAction->setIcon(QIcon::fromTheme(kdiskfreeService->icon())); + + connect(startKDiskFreeAction, &QAction::triggered, this, [kdiskfreeService](bool) { + KRun::runService(*kdiskfreeService, { }, nullptr); + }); + } else { + const auto startKDiskFreeAction = addAction("KDiskFree" + notInstalled); + startKDiskFreeAction->setEnabled(false); + } +} + +SpaceInfoToolsMenu::~SpaceInfoToolsMenu() +{ +} + + diff --git a/src/statusbar/spaceinfotoolsmenu.h b/src/statusbar/spaceinfotoolsmenu.h new file mode 100644 index 000000000..3ca2e184f --- /dev/null +++ b/src/statusbar/spaceinfotoolsmenu.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (C) 2014 by Gregor Mi <[email protected]> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef SPACEINFOTOOLSMENU_H +#define SPACEINFOTOOLSMENU_H + +#include <QObject> +#include <QMenu> + +class QWidget; +class QUrl; + +/** + * A menu with tools that help to find out more about free disk space for the given url. + */ +class SpaceInfoToolsMenu : public QMenu +{ + Q_OBJECT + +public: + explicit SpaceInfoToolsMenu(QWidget* parent, QUrl url); + virtual ~SpaceInfoToolsMenu(); +}; + +#endif diff --git a/src/statusbar/statusbarspaceinfo.cpp b/src/statusbar/statusbarspaceinfo.cpp index 3692947b1..127641e60 100644 --- a/src/statusbar/statusbarspaceinfo.cpp +++ b/src/statusbar/statusbarspaceinfo.cpp @@ -21,11 +21,13 @@ #include "statusbarspaceinfo.h" #include "spaceinfoobserver.h" +#include "spaceinfotoolsmenu.h" -#include <KLocale> +#include <QMouseEvent> + +#include <KLocalizedString> #include <KIO/Job> -#include <QKeyEvent> StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget* parent) : KCapacityBar(KCapacityBar::DrawTextInline, parent), @@ -37,7 +39,7 @@ StatusBarSpaceInfo::~StatusBarSpaceInfo() { } -void StatusBarSpaceInfo::setUrl(const KUrl& url) +void StatusBarSpaceInfo::setUrl(const QUrl& url) { if (m_url != url) { m_url = url; @@ -47,7 +49,7 @@ void StatusBarSpaceInfo::setUrl(const KUrl& url) } } -KUrl StatusBarSpaceInfo::url() const +QUrl StatusBarSpaceInfo::url() const { return m_url; } @@ -57,7 +59,7 @@ void StatusBarSpaceInfo::showEvent(QShowEvent* event) KCapacityBar::showEvent(event); m_observer.reset(new SpaceInfoObserver(m_url, this)); slotValuesChanged(); - connect(m_observer.data(), SIGNAL(valuesChanged()), this, SLOT(slotValuesChanged())); + connect(m_observer.data(), &SpaceInfoObserver::valuesChanged, this, &StatusBarSpaceInfo::slotValuesChanged); } void StatusBarSpaceInfo::hideEvent(QHideEvent* event) @@ -66,6 +68,14 @@ void StatusBarSpaceInfo::hideEvent(QHideEvent* event) KCapacityBar::hideEvent(event); } +void StatusBarSpaceInfo::mousePressEvent(QMouseEvent* event) +{ + if (event->button() == Qt::LeftButton) { + SpaceInfoToolsMenu spaceInfoToolsMenu(this, m_url); + spaceInfoToolsMenu.exec(QCursor::pos()); + } +} + void StatusBarSpaceInfo::slotValuesChanged() { Q_ASSERT(m_observer); @@ -87,4 +97,3 @@ void StatusBarSpaceInfo::slotValuesChanged() } } -#include "statusbarspaceinfo.moc" diff --git a/src/statusbar/statusbarspaceinfo.h b/src/statusbar/statusbarspaceinfo.h index 1065d9f45..326c419ab 100644 --- a/src/statusbar/statusbarspaceinfo.h +++ b/src/statusbar/statusbarspaceinfo.h @@ -20,16 +20,14 @@ #ifndef STATUSBARSPACEINFO_H #define STATUSBARSPACEINFO_H -#include <KUrl> +#include <QUrl> -#include <QColor> -#include <QKeyEvent> -#include <QString> -#include <kcapacitybar.h> +#include <KCapacityBar> class QHideEvent; class QShowEvent; +class QMouseEvent; class SpaceInfoObserver; @@ -45,19 +43,20 @@ public: explicit StatusBarSpaceInfo(QWidget* parent = 0); virtual ~StatusBarSpaceInfo(); - void setUrl(const KUrl& url); - KUrl url() const; + void setUrl(const QUrl& url); + QUrl url() const; protected: - void showEvent(QShowEvent* event); - void hideEvent(QHideEvent* event); + void showEvent(QShowEvent* event) Q_DECL_OVERRIDE; + void hideEvent(QHideEvent* event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE; private slots: void slotValuesChanged(); private: QScopedPointer<SpaceInfoObserver> m_observer; - KUrl m_url; + QUrl m_url; }; #endif |
