Commit 2a3d2ea8 authored by Harald Sitter's avatar Harald Sitter 🦄

merge part and mainwindow

this is really messy right now. the final merge really ought to get some
refactoring done to detangle business logic form representation
parent a21ee9b9
......@@ -23,7 +23,6 @@ set(filelight_SRCS
radialMap/map.cpp
radialMap/widgetEvents.cpp
radialMap/labels.cpp
part.cpp
scan.cpp
progressBox.cpp
Config.cpp
......
This diff is collapsed.
......@@ -23,17 +23,32 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "part.h"
#include <QUrl>
#include <KXmlGuiWindow>
class QLabel;
namespace RadialMap {
class Widget;
}
class Folder;
class KSqueezedTextLabel;
class KHistoryComboBox;
class KRecentFilesAction;
class ProgressBox;
class HistoryCollection;
namespace Filelight {
class MainWindow : public Part // Maybe use qmainwindow
class ScanManager;
class SummaryWidget;
class MainWindow : public KXmlGuiWindow // Maybe use qmainwindow
{
Q_OBJECT
......@@ -44,6 +59,12 @@ public:
slotScanUrl(u);
}
signals:
void started(); // FIXME: Could be replaced by direct func call once merged with mainwindow
void completed();
void canceled(QString);
void setWindowCaption(QString);
private slots:
void slotUp();
void slotComboScan();
......@@ -76,6 +97,46 @@ private:
void setupStatusBar();
void setupActions();
public slots:
bool openUrl(const QUrl&);
void configFilelight();
void rescan();
private slots:
void postInit();
void folderScanCompleted(Folder*);
void mapChanged(const Folder*);
void updateURL(const QUrl &);
private:
bool closeUrl();
QString prettyUrl() const;
void showSummary();
bool start(const QUrl&);
QLayout *m_layout;
SummaryWidget *m_summary;
RadialMap::Widget *m_map;
ProgressBox *m_stateWidget;
ScanManager *m_manager;
QLabel *m_numberOfFiles;
bool m_started;
// Compat
public:
QUrl url() const;
QWidget *widget() const; // Should get ported to centralWidget() I think
private:
void setUrl(const QUrl &url);
void setWidget(QWidget *widget);
QWidget *m_widget = nullptr;
QUrl m_url;
};
} // namespace Filelight
......
/***********************************************************************
* Copyright 2003-2004 Max Howell <max.howell@methylblue.com>
* Copyright 2008-2013 Martin Sandsmark <martin.sandsmark@kde.org>
* Copyright 2017 Harald Sitter <sitter@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
***********************************************************************/
#include "part.h"
#include "Config.h"
#include "define.h"
#include "fileTree.h"
#include "progressBox.h"
#include "radialMap/widget.h"
#include "scan.h"
#include "settingsDialog.h"
#include "summaryWidget.h"
#include <KActionCollection>
#include <KMessageBox> //::start()
#include <QStatusBar>
#include <KLocalizedString>
#include <QFile> //encodeName()
#include <QTimer> //postInit() hack
#include <QByteArray>
#include <QDir>
#include <QScrollArea>
#include <unistd.h> //access()
#include <iostream>
namespace Filelight {
Part::Part()
: KXmlGuiWindow()
, m_summary(nullptr)
, m_map(nullptr)
, m_started(false)
, m_widget(nullptr)
{
Config::read();
QScrollArea *scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
setWidget(scrollArea);
QWidget *partWidget = new QWidget(scrollArea);
scrollArea->setWidget(partWidget);
partWidget->setBackgroundRole(QPalette::Base);
partWidget->setAutoFillBackground(true);
m_layout = new QGridLayout();
partWidget->setLayout(m_layout);
m_manager = new ScanManager(partWidget);
m_map = new RadialMap::Widget(partWidget);
m_layout->addWidget(m_map);
m_stateWidget = new ProgressBox(statusBar(), this, m_manager);
m_layout->addWidget(m_stateWidget);
m_stateWidget->hide();
m_numberOfFiles = new QLabel();
statusBar()->addPermanentWidget(m_numberOfFiles);
KStandardAction::zoomIn(m_map, &RadialMap::Widget::zoomIn, actionCollection());
KStandardAction::zoomOut(m_map, &RadialMap::Widget::zoomOut, actionCollection());
KStandardAction::preferences(this, &Part::configFilelight, actionCollection());
connect(m_map, &RadialMap::Widget::folderCreated, this, static_cast<void (Part::*)()>(&Part::completed));
connect(m_map, &RadialMap::Widget::folderCreated, this, &Part::mapChanged);
connect(m_map, &RadialMap::Widget::activated, this, &Part::updateURL);
// TODO make better system
connect(m_map, &RadialMap::Widget::giveMeTreeFor, this, &Part::updateURL);
connect(m_map, &RadialMap::Widget::giveMeTreeFor, this, &Part::openUrl);
connect(m_manager, &ScanManager::completed, this, &Part::scanCompleted);
connect(m_manager, &ScanManager::aboutToEmptyCache, m_map, &RadialMap::Widget::invalidate);
QTimer::singleShot(0, this, SLOT(postInit()));
}
void
Part::postInit()
{
if (url().isEmpty()) //if url is not empty openUrl() has been called immediately after ctor, which happens
{
m_map->hide();
showSummary();
//FIXME KXMLGUI is b0rked, it should allow us to set this
//BEFORE createGUI is called but it doesn't
stateChanged(QLatin1String( "scan_failed" ));
}
}
bool
Part::openUrl(const QUrl &u)
{
//TODO everyone hates dialogs, instead render the text in big fonts on the Map
//TODO should have an empty QUrl until scan is confirmed successful
//TODO probably should set caption to QString::null while map is unusable
#define KMSG(s) KMessageBox::information(widget(), s)
QUrl uri = u.adjusted(QUrl::NormalizePathSegments);
const QString path = uri.path();
const QByteArray path8bit = QFile::encodeName(path);
const bool isLocal = uri.scheme() == QLatin1String( "file" );
if (uri.isEmpty())
{
//do nothing, chances are the user accidently pressed ENTER
}
else if (!uri.isValid())
{
KMSG(i18n("The entered URL cannot be parsed; it is invalid."));
}
else if ((!isLocal && path[0] != QLatin1Char( '/' )) || (isLocal && !QDir::isAbsolutePath(path)))
{
KMSG(i18n("Filelight only accepts absolute paths, eg. /%1", path));
}
else if (isLocal && access(path8bit, F_OK) != 0) //stat(path, &statbuf) == 0
{
KMSG(i18n("Folder not found: %1", path));
}
else if (isLocal && !QDir(path).isReadable()) //access(path8bit, R_OK | X_OK) != 0 doesn't work on win32
{
KMSG(i18n("Unable to enter: %1\nYou do not have access rights to this location.", path));
}
else
{
//we don't want to be using the summary screen anymore
if (m_summary != 0)
m_summary->hide();
m_stateWidget->show();
m_layout->addWidget(m_stateWidget);
return start(uri);
}
return false;
}
bool
Part::closeUrl()
{
if (m_manager->abort())
statusBar()->showMessage(i18n("Aborting Scan..."));
m_map->hide();
m_stateWidget->hide();
showSummary();
return true;
}
QString Part::prettyUrl() const {
return url().isLocalFile() ? url().toLocalFile() : url().toString();
}
void
Part::updateURL(const QUrl &u)
{
if (m_manager->running())
m_manager->abort();
if (u == url())
m_manager->emptyCache(); //same as rescan()
//do this last, or it breaks Konqi location bar
setUrl(u);
}
QUrl Part::url() const
{
return m_url;
}
void Part::setUrl(const QUrl &url)
{
m_url = url;
}
void Part::setWidget(QWidget *widget)
{
m_widget = widget;
}
QWidget *Part::widget() const
{
return m_widget;
}
void
Part::configFilelight()
{
SettingsDialog *dialog = new SettingsDialog(widget());
connect(dialog, &SettingsDialog::canvasIsDirty, m_map, &RadialMap::Widget::refresh);
connect(dialog, &SettingsDialog::mapIsInvalid, m_manager, &ScanManager::emptyCache);
dialog->show(); //deletes itself
}
bool
Part::start(const QUrl &url)
{
if (!m_started) {
connect(m_map, SIGNAL(mouseHover(QString)), statusBar(), SLOT(showMessage(const QString&)));
connect(m_map, &RadialMap::Widget::folderCreated, statusBar(), &QStatusBar::clearMessage);
m_started = true;
}
if (m_manager->running())
m_manager->abort();
m_numberOfFiles->setText(QString());
if (m_manager->start(url)) {
setUrl(url);
const QString s = i18n("Scanning: %1", prettyUrl());
stateChanged(QLatin1String( "scan_started" ));
emit started(); //as a Part, we have to do this
emit setWindowCaption(s);
statusBar()->showMessage(s);
m_map->hide();
m_map->invalidate(); //to maintain ui consistency
return true;
}
return false;
}
void
Part::rescan()
{
if (m_summary && !m_summary->isHidden()) {
delete m_summary;
m_summary = 0;
showSummary();
return;
}
//FIXME we have to empty the cache because otherwise rescan picks up the old tree..
m_manager->emptyCache(); //causes canvas to invalidate
m_map->hide();
m_stateWidget->show();
start(url());
}
void
Part::scanCompleted(Folder *tree)
{
if (tree) {
statusBar()->showMessage(i18n("Scan completed, generating map..."));
m_stateWidget->hide();
m_map->show();
m_map->create(tree);
stateChanged(QLatin1String( "scan_complete" ));
}
else {
stateChanged(QLatin1String( "scan_failed" ));
emit canceled(i18n("Scan failed: %1", prettyUrl()));
emit setWindowCaption(QString());
statusBar()->clearMessage();
m_map->hide();
m_stateWidget->hide();
showSummary();
setUrl(QUrl());
}
}
void
Part::mapChanged(const Folder *tree)
{
//IMPORTANT -> url() has already been set
emit setWindowCaption(prettyUrl());
const int fileCount = tree->children();
const QString text = ( fileCount == 0 ) ?
i18n("No files.") :
i18np("1 file", "%1 files",fileCount);
m_numberOfFiles->setText(text);
}
void
Part::showSummary()
{
if (m_summary == 0) {
m_summary = new SummaryWidget(widget());
m_summary->setObjectName(QStringLiteral( "summaryWidget" ));
connect(m_summary, &SummaryWidget::activated, this, &Part::openUrl);
m_summary->show();
m_layout->addWidget(m_summary);
}
else m_summary->show();
}
} //namespace Filelight
#include "part.moc"
/***********************************************************************
* Copyright 2003-2004 Max Howell <max.howell@methylblue.com>
* Copyright 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* Copyright 2017 Harald Sitter <sitter@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
***********************************************************************/
#ifndef FILELIGHTPART_H
#define FILELIGHTPART_H
#include <QUrl>
#include <KXmlGuiWindow>
class QLabel;
namespace RadialMap {
class Widget;
}
class Folder;
namespace Filelight
{
class Part;
class ScanManager;
class SummaryWidget;
class Part : public KXmlGuiWindow
{
Q_OBJECT
public:
Part();
bool closeUrl();
QString prettyUrl() const;
signals:
void started(); // FIXME: Could be replaced by direct func call once merged with mainwindow
void completed();
void canceled(QString);
void setWindowCaption(QString);
public slots:
virtual bool openUrl(const QUrl&);
void configFilelight();
void rescan();
private slots:
void postInit();
void scanCompleted(Folder*);
void mapChanged(const Folder*);
private:
void showSummary();
QLayout *m_layout;
SummaryWidget *m_summary;
RadialMap::Widget *m_map;
QWidget *m_stateWidget;
ScanManager *m_manager;
QLabel *m_numberOfFiles;
bool m_started;
private:
bool start(const QUrl&);
private slots:
void updateURL(const QUrl &);
// Compat
public:
QUrl url() const;
QWidget *widget() const;
private:
void setUrl(const QUrl &url);
void setWidget(QWidget *widget);
QWidget *m_widget = nullptr;
QUrl m_url;
};
}
#endif
......@@ -22,7 +22,7 @@
#include "progressBox.h"
#include "scan.h"
#include "part.h"
#include "mainWindow.h"
#include <KColorScheme>
#include <KIO/Job>
......@@ -36,8 +36,7 @@
#include <math.h>
ProgressBox::ProgressBox(QWidget *parent, Filelight::Part *part, Filelight::ScanManager *scanManager)
ProgressBox::ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Filelight::ScanManager *scanManager)
: QWidget(parent)
, m_manager(scanManager)
, m_colorScheme(QPalette::Active, KColorScheme::Tooltip)
......@@ -54,9 +53,9 @@ ProgressBox::ProgressBox(QWidget *parent, Filelight::Part *part, Filelight::Scan
setMinimumSize(300, 300);
connect(&m_timer, &QTimer::timeout, this, &ProgressBox::report);
connect(part, &Filelight::Part::started, this, &ProgressBox::start);
connect(part, static_cast<void (Filelight::Part::*)()>(&Filelight::Part::completed), this, &ProgressBox::stop);
connect(part, &Filelight::Part::canceled, this, &ProgressBox::halt);
connect(mainWindow, &Filelight::MainWindow::started, this, &ProgressBox::start);
connect(mainWindow, &Filelight::MainWindow::completed, this, &ProgressBox::stop);
connect(mainWindow, &Filelight::MainWindow::canceled, this, &ProgressBox::halt);
}
void
......
......@@ -28,7 +28,7 @@
namespace Filelight {
class ScanManager;
class Part;
class MainWindow;
}
class ProgressBox : public QWidget
......@@ -36,7 +36,7 @@ class ProgressBox : public QWidget
Q_OBJECT
public:
ProgressBox(QWidget *parent, Filelight::Part *part, Filelight::ScanManager *scanManager);
ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Filelight::ScanManager *scanManager);
void setText(int);
......@@ -48,7 +48,7 @@ public slots:
protected:
void paintEvent(QPaintEvent *event);
private:
QTimer m_timer;
Filelight::ScanManager* m_manager;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment