Commit 6d064394 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Refactored: moved recent folders model from StartPage to GvCore.

svn path=/trunk/KDE/kdegraphics/gwenview/; revision=955570
parent abba79dd
......@@ -27,10 +27,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <QFutureWatcher>
#include <QList>
#include <QProgressDialog>
#include <QStandardItemModel>
#include <QtConcurrentMap>
#include <QWidget>
// KDE
#include <kfileplacesmodel.h>
#include <kfiledialog.h>
#include <kimageio.h>
#include <kio/netaccess.h>
......@@ -52,8 +54,10 @@ namespace Gwenview {
struct GvCorePrivate {
GvCore* q;
QWidget* mParent;
SortedDirModel* mDirModel;
QStandardItemModel* mRecentFoldersModel;
bool showSaveAsDialog(const KUrl& url, KUrl* outUrl, QByteArray* format) {
KFileDialog dialog(url, QString(), mParent);
......@@ -95,14 +99,40 @@ struct GvCorePrivate {
*outUrl = dialog.selectedUrl();
return true;
}
void updateRecentFoldersModel() {
if (!mRecentFoldersModel) {
mRecentFoldersModel = new QStandardItemModel(q);
}
const QStringList list = GwenviewConfig::recentFolders();
mRecentFoldersModel->clear();
Q_FOREACH(const QString& urlString, list) {
KUrl url(urlString);
QStandardItem* item = new QStandardItem;
item->setText(url.pathOrUrl());
QString iconName = KMimeType::iconNameForUrl(url);
item->setIcon(KIcon(iconName));
item->setData(QVariant(url), KFilePlacesModel::UrlRole);
mRecentFoldersModel->appendRow(item);
}
}
};
GvCore::GvCore(QWidget* parent, SortedDirModel* dirModel)
: QObject(parent)
, d(new GvCorePrivate) {
d->q = this;
d->mParent = parent;
d->mDirModel = dirModel;
d->mRecentFoldersModel = 0;
}
......@@ -111,6 +141,19 @@ GvCore::~GvCore() {
}
QAbstractItemModel* GvCore::recentFoldersModel() const {
if (!d->mRecentFoldersModel) {
d->updateRecentFoldersModel();
}
return d->mRecentFoldersModel;
}
AbstractSemanticInfoBackEnd* GvCore::semanticInfoBackEnd() const {
return d->mDirModel->semanticInfoBackEnd();
}
void GvCore::addUrlToRecentFolders(const KUrl& _url) {
KUrl url(_url);
url.cleanPath();
......@@ -135,6 +178,7 @@ void GvCore::addUrlToRecentFolders(const KUrl& _url) {
}
GwenviewConfig::setRecentFolders(list);
d->updateRecentFoldersModel();
}
......
......@@ -30,9 +30,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
class KUrl;
class QAbstractItemModel;
namespace Gwenview {
class SortedDirModel;
class AbstractSemanticInfoBackEnd;
class GvCorePrivate;
class GvCore : public QObject {
......@@ -41,6 +44,9 @@ public:
GvCore(QWidget* mainWindow, SortedDirModel*);
~GvCore();
QAbstractItemModel* recentFoldersModel() const;
AbstractSemanticInfoBackEnd* semanticInfoBackEnd() const;
void addUrlToRecentFolders(const KUrl&);
public Q_SLOTS:
......
......@@ -256,7 +256,7 @@ struct MainWindow::Private {
}
void setupStartPage(QWidget* parent) {
mStartPage = new StartPage(parent, mDirModel->semanticInfoBackEnd());
mStartPage = new StartPage(parent, mGvCore);
connect(mStartPage, SIGNAL(urlSelected(const KUrl&)),
mWindow, SLOT(slotStartPageUrlSelected(const KUrl&)) );
}
......
......@@ -25,7 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// Qt
#include <QListView>
#include <QStandardItemModel>
// KDE
#include <kfileplacesmodel.h>
......@@ -33,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <kmimetype.h>
// Local
#include <gvcore.h>
#include <ui_startpage.h>
#include <lib/flowlayout.h>
#include <lib/gwenviewconfig.h>
......@@ -50,27 +50,8 @@ namespace Gwenview {
struct StartPagePrivate : public Ui_StartPage{
StartPage* that;
GvCore* mGvCore;
KFilePlacesModel* mBookmarksModel;
QStandardItemModel* mRecentFoldersModel;
void updateRecentFoldersModel() {
const QStringList list = GwenviewConfig::recentFolders();
mRecentFoldersModel->clear();
Q_FOREACH(const QString& urlString, list) {
KUrl url(urlString);
QStandardItem* item = new QStandardItem;
item->setText(url.pathOrUrl());
QString iconName = KMimeType::iconNameForUrl(url);
item->setIcon(KIcon(iconName));
item->setData(QVariant(url), KFilePlacesModel::UrlRole);
mRecentFoldersModel->appendRow(item);
}
}
void setupSearchUi(AbstractSemanticInfoBackEnd* backEnd) {
#ifdef GWENVIEW_SEMANTICINFO_BACKEND_NEPOMUK
......@@ -93,19 +74,18 @@ struct StartPagePrivate : public Ui_StartPage{
};
StartPage::StartPage(QWidget* parent, AbstractSemanticInfoBackEnd* backEnd)
StartPage::StartPage(QWidget* parent, GvCore* gvCore)
: QFrame(parent)
, d(new StartPagePrivate) {
d->that = this;
d->mGvCore = gvCore;
d->setupUi(this);
setFrameStyle(QFrame::NoFrame);
d->mBookmarksModel = new KFilePlacesModel(this);
d->mRecentFoldersModel = new QStandardItemModel(this);
d->mBookmarksView->setModel(d->mBookmarksModel);
d->mBookmarksView->setAutoResizeItemsEnabled(false);
d->mRecentFoldersView->setModel(d->mRecentFoldersModel);
connect(d->mBookmarksView, SIGNAL(urlChanged(const KUrl&)),
SIGNAL(urlSelected(const KUrl&)) );
......@@ -116,7 +96,7 @@ StartPage::StartPage(QWidget* parent, AbstractSemanticInfoBackEnd* backEnd)
connect(d->mTagView, SIGNAL(clicked(const QModelIndex&)),
SLOT(slotTagViewClicked(const QModelIndex&)));
d->setupSearchUi(backEnd);
d->setupSearchUi(gvCore->semanticInfoBackEnd());
}
......@@ -180,7 +160,9 @@ void StartPage::slotListViewClicked(const QModelIndex& index) {
void StartPage::showEvent(QShowEvent* event) {
d->updateRecentFoldersModel();
if (!d->mRecentFoldersView->model()) {
d->mRecentFoldersView->setModel(d->mGvCore->recentFoldersModel());
}
QFrame::showEvent(event);
}
......
......@@ -37,13 +37,13 @@ class KUrl;
namespace Gwenview {
class AbstractSemanticInfoBackEnd;
class GvCore;
class StartPagePrivate;
class StartPage : public QFrame {
Q_OBJECT
public:
StartPage(QWidget* parent, AbstractSemanticInfoBackEnd*);
StartPage(QWidget* parent, GvCore*);
~StartPage();
void applyPalette(const QPalette&);
......
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