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

Moved recent folders model to its own file.

svn path=/trunk/KDE/kdegraphics/gwenview/; revision=955571
parent 6d064394
......@@ -32,24 +32,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <QWidget>
// KDE
#include <kfileplacesmodel.h>
#include <kfiledialog.h>
#include <kimageio.h>
#include <kio/netaccess.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kurl.h>
// Local
#include <lib/document/documentfactory.h>
#include <lib/gwenviewconfig.h>
#include <lib/historymodel.h>
#include <lib/mimetypeutils.h>
#include <lib/semanticinfo/semanticinfodirmodel.h>
#include <lib/semanticinfo/sorteddirmodel.h>
#include <lib/transformimageoperation.h>
static const int MAX_RECENT_FOLDER = 20;
namespace Gwenview {
......@@ -57,7 +56,7 @@ struct GvCorePrivate {
GvCore* q;
QWidget* mParent;
SortedDirModel* mDirModel;
QStandardItemModel* mRecentFoldersModel;
HistoryModel* mRecentFoldersModel;
bool showSaveAsDialog(const KUrl& url, KUrl* outUrl, QByteArray* format) {
KFileDialog dialog(url, QString(), mParent);
......@@ -99,30 +98,6 @@ 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);
}
}
};
......@@ -143,7 +118,7 @@ GvCore::~GvCore() {
QAbstractItemModel* GvCore::recentFoldersModel() const {
if (!d->mRecentFoldersModel) {
d->updateRecentFoldersModel();
d->mRecentFoldersModel = new HistoryModel(const_cast<GvCore*>(this), KStandardDirs::locateLocal("data", "recentfolders/"));
}
return d->mRecentFoldersModel;
}
......@@ -154,31 +129,9 @@ AbstractSemanticInfoBackEnd* GvCore::semanticInfoBackEnd() const {
}
void GvCore::addUrlToRecentFolders(const KUrl& _url) {
KUrl url(_url);
url.cleanPath();
url.adjustPath(KUrl::RemoveTrailingSlash);
QString urlString = url.url();
QStringList list = GwenviewConfig::recentFolders();
int index = list.indexOf(urlString);
if (index == 0) {
// Nothing to do, it's already the first recent folder.
return;
} else if (index != -1) {
// Remove it from the list. This way it will get inserted at the
// beginning.
list.removeAt(index);
}
list.insert(0, urlString);
while (list.size() > MAX_RECENT_FOLDER) {
list.removeLast();
}
GwenviewConfig::setRecentFolders(list);
d->updateRecentFoldersModel();
void GvCore::addUrlToRecentFolders(const KUrl& url) {
recentFoldersModel();
d->mRecentFoldersModel->addUrl(url);
}
......
......@@ -34,6 +34,7 @@ set(gwenviewlib_SRCS
documentview/videoviewadapter.cpp
abstractimageoperation.cpp
abstractimageviewtool.cpp
historymodel.cpp
imagesequence.cpp
imagesequencecontroller.cpp
archiveutils.cpp
......
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@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) 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, Cambridge, MA 02110-1301, USA.
*/
// Self
#include "historymodel.moc"
// Qt
// KDE
#include <kfileplacesmodel.h>
#include <kmimetype.h>
// Local
#include <lib/gwenviewconfig.h>
namespace Gwenview {
static const int MAX_RECENT_FOLDER = 20;
struct HistoryModelPrivate {
HistoryModel* q;
void updateRecentFoldersModel() {
const QStringList list = GwenviewConfig::recentFolders();
q->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);
q->appendRow(item);
}
}
};
HistoryModel::HistoryModel(QObject* parent, const QString& storageDir)
: QStandardItemModel(parent)
, d(new HistoryModelPrivate) {
d->q = this;
d->updateRecentFoldersModel();
}
HistoryModel::~HistoryModel() {
delete d;
}
void HistoryModel::addUrl(const KUrl& _url) {
KUrl url(_url);
url.cleanPath();
url.adjustPath(KUrl::RemoveTrailingSlash);
QString urlString = url.url();
QStringList list = GwenviewConfig::recentFolders();
int index = list.indexOf(urlString);
if (index == 0) {
// Nothing to do, it's already the first recent folder.
return;
} else if (index != -1) {
// Remove it from the list. This way it will get inserted at the
// beginning.
list.removeAt(index);
}
list.insert(0, urlString);
while (list.size() > MAX_RECENT_FOLDER) {
list.removeLast();
}
GwenviewConfig::setRecentFolders(list);
d->updateRecentFoldersModel();
}
} // namespace
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@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) 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, Cambridge, MA 02110-1301, USA.
*/
#ifndef HISTORYMODEL_H
#define HISTORYMODEL_H
// Qt
#include <QStandardItemModel>
// KDE
// Local
#include <lib/gwenviewlib_export.h>
class KUrl;
namespace Gwenview {
class HistoryModelPrivate;
/**
* A model which maintains a list of urls in the dir specified by the
* storageDir parameter of its ctor.
* Each url is stored in a separate KConfig file to avoid concurrency issues.
*/
class GWENVIEWLIB_EXPORT HistoryModel : public QStandardItemModel {
Q_OBJECT
public:
HistoryModel(QObject* parent, const QString& storageDir);
~HistoryModel();
void addUrl(const KUrl&);
private:
HistoryModelPrivate* const d;
};
} // namespace
#endif /* HISTORYMODEL_H */
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