Commit a7c65d17 authored by Jonathan Marten's avatar Jonathan Marten
Browse files

File Size View: Port away from KDElibs4Support

Differential Revision: https://phabricator.kde.org/D28486
parent 7b7c71bf
......@@ -13,6 +13,12 @@ set(libfsview_SRCS
inode.cpp
)
ecm_qt_declare_logging_category(libfsview_SRCS
HEADER fsviewdebug.h
IDENTIFIER FSVIEWLOG
CATEGORY_NAME org.kde.fsview
EXPORT fsview
DESCRIPTION "Konqueror FileSizeView plugin")
########### next target ###############
......@@ -20,7 +26,7 @@ set(fsview_SRCS main.cpp ${libfsview_SRCS} )
add_executable(fsview ${fsview_SRCS})
target_link_libraries(fsview KF5::KIOWidgets KF5::KDELibs4Support)
target_link_libraries(fsview KF5::KIOWidgets KF5::I18n KF5::IconThemes)
install(TARGETS fsview ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
......@@ -31,15 +37,17 @@ set(fsviewpart_PART_SRCS fsview_part.cpp ${libfsview_SRCS})
add_library(fsviewpart MODULE ${fsviewpart_PART_SRCS})
target_link_libraries(fsviewpart KF5::Parts KF5::KDELibs4Support)
target_link_libraries(fsviewpart KF5::Parts KF5::IconThemes)
install(TARGETS fsviewpart DESTINATION ${KDE_INSTALL_PLUGINDIR} )
install(TARGETS fsviewpart DESTINATION ${KDE_INSTALL_PLUGINDIR} )
########### install files ###############
install( FILES fsview_part.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )
install( FILES fsview_part.rc DESTINATION ${KDE_INSTALL_DATADIR}/fsview )
install( FILES fsview_part.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/fsview )
ecm_qt_install_logging_categories(EXPORT fsview DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})
ecm_install_icons( ICONS 22-apps-fsview.png 32-apps-fsview.png DESTINATION ${KDE_INSTALL_ICONDIR} THEME hicolor )
......@@ -25,10 +25,10 @@
#include <QDir>
#include <QTimer>
#include <QApplication>
#include <QDebug>
#include <KLocalizedString>
#include <kconfig.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kio/job.h>
......@@ -36,6 +36,8 @@
#include <kconfiggroup.h>
#include <kurlauthorized.h>
#include "fsviewdebug.h"
// FSView
QMap<QString, MetricEntry> FSView::_dirMetric;
......@@ -128,7 +130,7 @@ void FSView::setPath(const QString &p)
return;
}
//kDebug(90100) << "FSView::setPath " << p;
//qCDebug(FSVIEWLOG) << "FSView::setPath " << p;
// stop any previous updating
stop();
......@@ -181,10 +183,10 @@ bool FSView::getDirMetric(const QString &k,
d = (*it).dirCount;
if (0) {
kDebug(90100) << "getDirMetric " << k;
qCDebug(FSVIEWLOG) << "getDirMetric " << k;
}
if (0) {
kDebug(90100) << " - got size " << s << ", files " << f;
qCDebug(FSVIEWLOG) << " - got size " << s << ", files " << f;
}
return true;
......@@ -193,15 +195,15 @@ bool FSView::getDirMetric(const QString &k,
void FSView::setDirMetric(const QString &k,
double s, unsigned int f, unsigned int d)
{
if (0) kDebug(90100) << "setDirMetric '" << k << "': size "
<< s << ", files " << f << ", dirs " << d << endl;
if (0) qCDebug(FSVIEWLOG) << "setDirMetric '" << k << "': size "
<< s << ", files " << f << ", dirs " << d << endl;
_dirMetric.insert(k, MetricEntry(s, f, d));
}
void FSView::requestUpdate(Inode *i)
{
if (0) kDebug(90100) << "FSView::requestUpdate(" << i->path()
<< ")" << endl;
if (0) qCDebug(FSVIEWLOG) << "FSView::requestUpdate(" << i->path()
<< ")" << endl;
ScanDir *peer = i->dirPeer();
if (!peer) {
......@@ -276,10 +278,10 @@ void FSView::scanFinished(ScanDir *d)
_lastDir = d;
_dirsFinished++;
if (0) kDebug(90100) << "FSFiew::scanFinished: " << d->path()
<< ", Data " << data
<< ", Progress " << _progress << "/"
<< _progressSize << endl;
if (0) qCDebug(FSVIEWLOG) << "FSFiew::scanFinished: " << d->path()
<< ", Data " << data
<< ", Progress " << _progress << "/"
<< _progressSize << endl;
}
void FSView::selected(TreeMapItem *i)
......@@ -490,17 +492,17 @@ void FSView::doRedraw()
if ((_progress > 0) && (_progressSize > 0) && _lastDir) {
int percent = _progress * 100 / _progressSize;
if (0) kDebug(90100) << "FSView::progress "
<< _progress << "/" << _progressSize
<< "= " << percent << "%, "
<< _dirsFinished << " dirs read, in "
<< _lastDir->path() << endl;
if (0) qCDebug(FSVIEWLOG) << "FSView::progress "
<< _progress << "/" << _progressSize
<< "= " << percent << "%, "
<< _dirsFinished << " dirs read, in "
<< _lastDir->path() << endl;
emit progress(percent, _dirsFinished, _lastDir->path());
}
if (_allowRefresh && ((redrawCounter % 4) == 0)) {
if (0) {
kDebug(90100) << "doRedraw " << _sm.scanLength();
qCDebug(FSVIEWLOG) << "doRedraw " << _sm.scanLength();
}
redraw();
} else {
......@@ -526,7 +528,7 @@ void FSView::doUpdate()
_progressSize = 3 * _chunkSize1;
if (1) {
kDebug(90100) << "Phase 2: CSize " << _chunkSize1;
qCDebug(FSVIEWLOG) << "Phase 2: CSize " << _chunkSize1;
}
}
break;
......@@ -550,10 +552,10 @@ void FSView::doUpdate()
/* Go to maximally 66% by scaling with 1.5 */
_progressSize = _progressSize * 3 / 2;
if (1) kDebug(90100) << "Phase 3: CSize " << _chunkSize2
<< ", Todo " << todo
<< ", Progress " << _progress
<< "/" << _progressSize << endl;
if (1) qCDebug(FSVIEWLOG) << "Phase 3: CSize " << _chunkSize2
<< ", Todo " << todo
<< ", Progress " << _progress
<< "/" << _progressSize << endl;
}
break;
......@@ -570,10 +572,10 @@ void FSView::doUpdate()
_progressSize = (int)((double)todo / (1.0 - percent) + .5);
_progress = _progressSize - todo;
if (1) kDebug(90100) << "Phase 4: CSize " << _chunkSize3
<< ", Todo " << todo
<< ", Progress " << _progress
<< "/" << _progressSize << endl;
if (1) qCDebug(FSVIEWLOG) << "Phase 4: CSize " << _chunkSize3
<< ", Todo " << todo
<< ", Progress " << _progress
<< "/" << _progressSize << endl;
}
default:
......
......@@ -32,7 +32,6 @@
#include <kpluginfactory.h>
#include <kaboutdata.h>
#include <kglobalsettings.h>
#include <kprotocolmanager.h>
#include <kio/copyjob.h>
#include <kio/deletejob.h>
......@@ -46,14 +45,16 @@
#include <KIO/FileUndoManager>
#include <KJobWidgets>
#include <ktoolinvocation.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <KDebug>
#include <ksharedconfig.h>
#include <KLocalizedString>
#include <QApplication>
#include <QMimeData>
#include "fsviewdebug.h"
K_PLUGIN_FACTORY(FSViewPartFactory, registerPlugin<FSViewPart>();)
// FSJob, for progress
......@@ -147,9 +148,13 @@ FSViewPart::FSViewPart(QWidget *parentWidget,
QObject::connect(_colorMenu->menu(), SIGNAL(aboutToShow()),
SLOT(slotShowColorMenu()));
slotSettingsChanged(KGlobalSettings::SETTINGS_MOUSE);
connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)),
SLOT(slotSettingsChanged(int)));
// Both of these click signals are connected. Whether a single or
// double click activates an item is checked against the current
// style setting when the click happens.
QObject::connect(_view, SIGNAL(clicked(TreeMapItem*)),
_ext, SLOT(itemSingleClicked(TreeMapItem*)));
QObject::connect(_view, SIGNAL(doubleClicked(TreeMapItem*)),
_ext, SLOT(itemDoubleClicked(TreeMapItem*)));
QObject::connect(_view, SIGNAL(returnPressed(TreeMapItem*)),
_ext, SLOT(selected(TreeMapItem*)));
......@@ -177,8 +182,7 @@ FSViewPart::FSViewPart(QWidget *parentWidget,
moveToTrashAction->setText(i18nc("@action:inmenu File", "Move to Trash"));
moveToTrashAction->setIcon(QIcon::fromTheme(QStringLiteral("user-trash")));
actionCollection()->setDefaultShortcut(moveToTrashAction, QKeySequence(QKeySequence::Delete));
connect(moveToTrashAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)),
_ext, SLOT(trash(Qt::MouseButtons,Qt::KeyboardModifiers)));
connect(moveToTrashAction, SIGNAL(triggered()), _ext, SLOT(trash()));
QAction *deleteAction = actionCollection()->addAction(QStringLiteral("delete"));
deleteAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
......@@ -205,31 +209,12 @@ FSViewPart::FSViewPart(QWidget *parentWidget,
FSViewPart::~FSViewPart()
{
kDebug(90100) << "FSViewPart Destructor";
qCDebug(FSVIEWLOG);
delete _job;
_view->saveFSOptions();
}
void FSViewPart::slotSettingsChanged(int category)
{
if (category != KGlobalSettings::SETTINGS_MOUSE) {
return;
}
QObject::disconnect(_view, SIGNAL(clicked(TreeMapItem*)),
_ext, SLOT(selected(TreeMapItem*)));
QObject::disconnect(_view, SIGNAL(doubleClicked(TreeMapItem*)),
_ext, SLOT(selected(TreeMapItem*)));
if (_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick))
QObject::connect(_view, SIGNAL(clicked(TreeMapItem*)),
_ext, SLOT(selected(TreeMapItem*)));
else
QObject::connect(_view, SIGNAL(doubleClicked(TreeMapItem*)),
_ext, SLOT(selected(TreeMapItem*)));
}
void FSViewPart::showInfo()
{
QString info;
......@@ -262,7 +247,7 @@ void FSViewPart::completedSlot(int dirs)
_job = nullptr;
}
KConfigGroup cconfig(_view->config(), "MetricCache");
KConfigGroup cconfig = _view->config()->group("MetricCache");
_view->saveMetric(&cconfig);
emit completed();
......@@ -294,7 +279,7 @@ void FSViewPart::slotShowColorMenu()
bool FSViewPart::openFile() // never called since openUrl is reimplemented
{
kDebug(90100) << "FSViewPart::openFile " << localFilePath();
qCDebug(FSVIEWLOG) << localFilePath();
_view->setPath(localFilePath());
return true;
......@@ -302,7 +287,7 @@ bool FSViewPart::openFile() // never called since openUrl is reimplemented
bool FSViewPart::openUrl(const QUrl &url)
{
kDebug(90100) << "FSViewPart::openUrl " << url.path();
qCDebug(FSVIEWLOG) << url.path();
if (!url.isValid()) {
return false;
......@@ -321,7 +306,7 @@ bool FSViewPart::openUrl(const QUrl &url)
bool FSViewPart::closeUrl()
{
kDebug(90100) << "FSViewPart::closeUrl ";
qCDebug(FSVIEWLOG);
_view->stop();
......@@ -369,7 +354,7 @@ void FSViewPart::updateActions()
stateChanged(QStringLiteral("has_no_selection"));
}
kDebug(90100) << "FSViewPart::updateActions, deletable " << canDel;
qCDebug(FSVIEWLOG) << "deletable" << canDel;
}
void FSViewPart::contextMenu(TreeMapItem * /*item*/, const QPoint &p)
......@@ -476,9 +461,9 @@ void FSViewBrowserExtension::del()
}
}
void FSViewBrowserExtension::trash(Qt::MouseButtons, Qt::KeyboardModifiers modifiers)
void FSViewBrowserExtension::trash()
{
bool deleteNotTrash = ((modifiers & Qt::ShiftModifier) != 0);
bool deleteNotTrash = ((QGuiApplication::keyboardModifiers() & Qt::ShiftModifier) != 0);
if (deleteNotTrash) {
del();
} else {
......@@ -530,12 +515,27 @@ void FSViewBrowserExtension::refresh()
}
}
kDebug(90100) << "FSViewPart::refreshing "
<< ((Inode *)commonParent)->path() << endl;
qCDebug(FSVIEWLOG) << "refreshing"
<< ((Inode *)commonParent)->path() << endl;
_view->requestUpdate((Inode *)commonParent);
}
void FSViewBrowserExtension::itemSingleClicked(TreeMapItem *i)
{
if (_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) {
selected(i);
}
}
void FSViewBrowserExtension::itemDoubleClicked(TreeMapItem *i)
{
if (!_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) {
selected(i);
}
}
void FSViewBrowserExtension::selected(TreeMapItem *i)
{
if (!i) {
......
......@@ -53,10 +53,13 @@ protected slots:
{
copySelection(true);
}
void trash(Qt::MouseButtons, Qt::KeyboardModifiers modifiers);
void trash();
void del();
void editMimeType();
void itemSingleClicked(TreeMapItem *i);
void itemDoubleClicked(TreeMapItem *i);
private:
void copySelection(bool move);
......@@ -110,7 +113,6 @@ public slots:
void slotShowAreaMenu();
void slotShowDepthMenu();
void slotShowColorMenu();
void slotSettingsChanged(int);
void slotProperties();
protected:
......
......@@ -21,14 +21,16 @@
*/
#include "inode.h"
#include <kdebug.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <KLocalizedString>
#include <QMimeDatabase>
#include <QMimeType>
#include "scan.h"
#include "fsview.h"
#include "fsviewdebug.h"
// Inode
......@@ -74,8 +76,8 @@ Inode::Inode(ScanFile *f, Inode *parent)
Inode::~Inode()
{
if (0) kDebug(90100) << "~Inode [" << path()
<< "]" << endl;
if (0) qCDebug(FSVIEWLOG) << "~Inode [" << path()
<< "]" << endl;
/* reset Listener of old Peer */
if (_dirPeer) {
......@@ -108,8 +110,8 @@ QString Inode::path() const
void Inode::init(const QString &path)
{
if (0) kDebug(90100) << "Inode::init [" << path
<< "]" << endl;
if (0) qCDebug(FSVIEWLOG) << "Inode::init [" << path
<< "]" << endl;
_info = QFileInfo(path);
......@@ -143,16 +145,16 @@ void Inode::init(const QString &path)
/* ScanListener interface */
void Inode::sizeChanged(ScanDir *d)
{
if (0) kDebug(90100) << "Inode::sizeChanged [" << path() << "] in "
<< d->name() << ": size " << d->size() << endl;
if (0) qCDebug(FSVIEWLOG) << "Inode::sizeChanged [" << path() << "] in "
<< d->name() << ": size " << d->size() << endl;
_resortNeeded = true;
}
void Inode::scanFinished(ScanDir *d)
{
if (0) kDebug(90100) << "Inode::scanFinished [" << path() << "] in "
<< d->name() << ": size " << d->size() << endl;
if (0) qCDebug(FSVIEWLOG) << "Inode::scanFinished [" << path() << "] in "
<< d->name() << ": size " << d->size() << endl;
_resortNeeded = true;
......@@ -350,27 +352,7 @@ QString Inode::text(int i) const
return name;
}
if (i == 1) {
QString text;
double s = size();
if (s < 1000) {
text = QStringLiteral("%1 B").arg((int)(s + .5));
} else if (s < 10 * 1024) {
text = QStringLiteral("%1 kB").arg(KGlobal::locale()->formatNumber(s / 1024 + .005, 2));
} else if (s < 100 * 1024) {
text = QStringLiteral("%1 kB").arg(KGlobal::locale()->formatNumber(s / 1024 + .05, 1));
} else if (s < 1000 * 1024) {
text = QStringLiteral("%1 kB").arg((int)(s / 1024 + .5));
} else if (s < 10 * 1024 * 1024) {
text = QStringLiteral("%1 MB").arg(KGlobal::locale()->formatNumber(s / 1024 / 1024 + .005, 2));
} else if (s < 100 * 1024 * 1024) {
text = QStringLiteral("%1 MB").arg(KGlobal::locale()->formatNumber(s / 1024 / 1024 + .05, 1));
} else if (s < 1000 * 1024 * 1024) {
text = QStringLiteral("%1 MB").arg((int)(s / 1024 / 1024 + .5));
} else {
text = QStringLiteral("%1 GB").arg(KGlobal::locale()->formatNumber(s / 1024 / 1024 / 1024 + .005, 2));
}
QString text = KIO::convertSize(static_cast<KIO::filesize_t>(size()+0.5));
if (_sizeEstimation > 0) {
text += '+';
}
......
......@@ -23,11 +23,11 @@
#include <QSet>
#include <qplatformdefs.h>
#include <kdebug.h>
#include <kauthorized.h>
#include <kurlauthorized.h>
#include "inode.h"
#include "fsviewdebug.h"
// ScanManager
......@@ -104,8 +104,8 @@ void ScanManager::stopScan()
return;
}
if (0) kDebug(90100) << "ScanManager::stopScan, scanLength "
<< _list.count() << endl;
if (0) qCDebug(FSVIEWLOG) << "ScanManager::stopScan, scanLength "
<< _list.count() << endl;
while (!_list.isEmpty()) {
ScanItem *si = _list.takeFirst();
......@@ -336,8 +336,8 @@ void ScanDir::subScanFinished()
_dirsFinished++;
callSizeChanged();
if (0) kDebug(90100) << "ScanDir::subScanFinished [" << path()
<< "]: " << _dirsFinished << "/" << _dirs.count() << endl;
if (0) qCDebug(FSVIEWLOG) << "ScanDir::subScanFinished [" << path()
<< "]: " << _dirsFinished << "/" << _dirs.count() << endl;
if (_dirsFinished < _dirs.count()) {
return;
......@@ -386,8 +386,8 @@ void ScanDir::setupChildRescan()
void ScanDir::callScanStarted()
{
if (0) kDebug(90100) << "ScanDir:Started [" << path()
<< "]: size " << size() << ", files " << fileCount() << endl;
if (0) qCDebug(FSVIEWLOG) << "ScanDir:Started [" << path()
<< "]: size " << size() << ", files " << fileCount() << endl;
ScanListener *mListener = _manager ? _manager->listener() : nullptr;
......@@ -401,8 +401,8 @@ void ScanDir::callScanStarted()
void ScanDir::callSizeChanged()
{
if (0) kDebug(90100) << ". [" << path()
<< "]: size " << size() << ", files " << fileCount() << endl;
if (0) qCDebug(FSVIEWLOG) << ". [" << path()
<< "]: size " << size() << ", files " << fileCount() << endl;
_dirty = true;
......@@ -422,8 +422,8 @@ void ScanDir::callSizeChanged()
void ScanDir::callScanFinished()
{
if (0) kDebug(90100) << "ScanDir:Finished [" << path()
<< "]: size " << size() << ", files " << fileCount() << endl;
if (0) qCDebug(FSVIEWLOG) << "ScanDir:Finished [" << path()
<< "]: size " << size() << ", files " << fileCount() << endl;
ScanListener *mListener = _manager ? _manager->listener() : nullptr;
......
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include (ECMMarkAsTest)
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. )
include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. )
########### next target ###############
......@@ -10,6 +12,7 @@ set(libfsview_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../fsview.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../scan.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../inode.cpp
${CMAKE_CURRENT_BINARY_DIR}/../fsviewdebug.cpp
)
......@@ -18,6 +21,4 @@ set(scantest_SRCS scantest.cpp ${libfsview_SRCS})
add_executable(scantest ${scantest_SRCS})
ecm_mark_as_test(scantest)
target_link_libraries(scantest KF5::KIOCore KF5::KDELibs4Support Qt5::Widgets)
target_link_libraries(scantest KF5::KIOCore KF5::IconThemes KF5::I18n KF5::WidgetsAddons Qt5::Widgets)
......@@ -20,6 +20,8 @@
#include <stdio.h>
#include <qapplication.h>
#include "scan.h"
class MyListener: public ScanListener
......@@ -32,7 +34,7 @@ public:
void sizeChanged(ScanDir *d) override
{
printf("Change in %s: Dirs %d, Files %d",
printf("Change in %s: Dirs %d, Files %d ",
qPrintable(d->name()),
d->dirCount(), d->fileCount());
printf("Size %llu\n", (unsigned long long int)d->size());
......@@ -46,6 +48,8 @@ public:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ScanManager m(QStringLiteral("/opt"));
if (argc > 1) {
m.setTop(argv[1]);
......
......@@ -42,9 +42,10 @@
#include <KLocalizedString>
#include <kconfig.h>
#include <kdebug.h>
#include <kconfiggroup.h>
#include "fsviewdebug.h"
// set this to 1 to enable debug output
#define DEBUG_DRAWING 0
#define MAX_FIELD 12
......@@ -386,7 +387,7 @@ int findBreak(int &breakPos, QString text, QFontMetrics *fm, int maxWidth)
// does full text fit?
breakPos = text.length();
usedWidth = fm->width(text);
usedWidth = fm->horizontalAdvance(text);
if (usedWidth < maxWidth) {
return usedWidth;
}
......@@ -396,7 +397,7 @@ int findBreak(int &breakPos, QString text, QFontMetrics *fm, int maxWidth)
int bottomPos = 0;
while (qAbs(maxWidth - usedWidth) > 3 * fm->maxWidth()) {
int halfPos = (bottomPos + breakPos) / 2;
int halfWidth = fm->width(text, halfPos);
int halfWidth = fm->horizontalAdvance(text, halfPos);
if (halfWidth < maxWidth) {
bottomPos = halfPos;
} else {
......@@ -427,7 +428,7 @@ int findBreak(int &breakPos, QString text, QFontMetrics *fm, int maxWidth)
lastCat = cat;
breakPos = pos;
usedWidth = fm->width(text, breakPos);
usedWidth = fm->horizontalAdvance(text, breakPos);
if (usedWidth < maxWidth) {
break;
}
......@@ -448,7 +449,7 @@ int findBreakBackwards(int &breakPos, QString text, QFontMetrics *fm, int maxWid