Commit daabe27b authored by Tomas Mecir's avatar Tomas Mecir
Browse files

Replace the 'Recent URLs' tab with a 'Recent Files' one, which shows the same...

Replace the 'Recent URLs' tab with a 'Recent Files' one, which shows the same files as the recently opened menu item does.

Motivation as per 331011 in bugzilla.

BUG: 331011
parent 07892d4c
......@@ -44,6 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <lib/historymodel.h>
#include <lib/hud/hudmessagebubble.h>
#include <lib/mimetypeutils.h>
#include <lib/recentfilesmodel.h>
#include <lib/semanticinfo/semanticinfodirmodel.h>
#include <lib/semanticinfo/sorteddirmodel.h>
#include <lib/transformimageoperation.h>
......@@ -60,7 +61,7 @@ struct GvCorePrivate
MainWindow* mMainWindow;
SortedDirModel* mDirModel;
HistoryModel* mRecentFoldersModel;
HistoryModel* mRecentUrlsModel;
RecentFilesModel* mRecentFilesModel;
QPalette mPalettes[4];
bool showSaveAsDialog(const QUrl &url, QUrl* outUrl, QByteArray* format)
......@@ -151,7 +152,7 @@ GvCore::GvCore(MainWindow* mainWindow, SortedDirModel* dirModel)
d->mMainWindow = mainWindow;
d->mDirModel = dirModel;
d->mRecentFoldersModel = 0;
d->mRecentUrlsModel = 0;
d->mRecentFilesModel = 0;
d->setupPalettes();
......@@ -172,12 +173,12 @@ QAbstractItemModel* GvCore::recentFoldersModel() const
return d->mRecentFoldersModel;
}
QAbstractItemModel* GvCore::recentUrlsModel() const
QAbstractItemModel* GvCore::recentFilesModel() const
{
if (!d->mRecentUrlsModel) {
d->mRecentUrlsModel = new HistoryModel(const_cast<GvCore*>(this), KStandardDirs::locateLocal("appdata", "recenturls/"));
if (!d->mRecentFilesModel) {
d->mRecentFilesModel = new RecentFilesModel(const_cast<GvCore*>(this));
}
return d->mRecentUrlsModel;
return d->mRecentFilesModel;
}
AbstractSemanticInfoBackEnd* GvCore::semanticInfoBackEnd() const
......@@ -205,13 +206,13 @@ void GvCore::addUrlToRecentFolders(QUrl url)
d->mRecentFoldersModel->addUrl(url);
}
void GvCore::addUrlToRecentUrls(const QUrl &url)
void GvCore::addUrlToRecentFiles(const QUrl &url)
{
if (!GwenviewConfig::historyEnabled()) {
return;
}
recentUrlsModel();
d->mRecentUrlsModel->addUrl(url);
recentFilesModel();
d->mRecentFilesModel->addUrl(url);
}
void GvCore::saveAll()
......@@ -359,7 +360,7 @@ void GvCore::slotConfigChanged()
{
if (!GwenviewConfig::historyEnabled()) {
clearModel(recentFoldersModel());
clearModel(recentUrlsModel());
clearModel(recentFilesModel());
}
d->setupPalettes();
}
......
......@@ -57,12 +57,12 @@ public:
};
QAbstractItemModel* recentFoldersModel() const;
QAbstractItemModel* recentUrlsModel() const;
QAbstractItemModel* recentFilesModel() const;
SortedDirModel* sortedDirModel() const;
AbstractSemanticInfoBackEnd* semanticInfoBackEnd() const;
void addUrlToRecentFolders(QUrl);
void addUrlToRecentUrls(const QUrl &url);
void addUrlToRecentFiles(const QUrl &);
QPalette palette(PaletteType type) const;
......
......@@ -845,9 +845,6 @@ void MainWindow::setInitialUrl(const QUrl &_url)
{
Q_ASSERT(_url.isValid());
QUrl url = UrlUtils::fixUserEnteredUrl(_url);
if (url.scheme() == "http" || url.scheme() == "https") {
d->mGvCore->addUrlToRecentUrls(url);
}
if (UrlUtils::urlIsDirectory(url)) {
d->mBrowseAction->trigger();
openDirUrl(url);
......@@ -1092,6 +1089,7 @@ void MainWindow::slotPartCompleted()
QUrl url = d->mViewMainPage->url();
if (!url.isEmpty()) {
d->mFileOpenRecentAction->addUrl(url);
d->mGvCore->addUrlToRecentFiles(url);
}
if (!KProtocolManager::supportsListing(url)) {
return;
......@@ -1450,6 +1448,9 @@ void MainWindow::loadConfig()
d->mDirModel->adjustKindFilter(MimeTypeUtils::KIND_VIDEO, GwenviewConfig::listVideos());
d->mFileOpenRecentAction->loadEntries(KConfigGroup(KSharedConfig::openConfig(), "Recent Files"));
foreach(QUrl url, d->mFileOpenRecentAction->urls()) {
d->mGvCore->addUrlToRecentFiles(url);
}
d->mStartMainPage->loadConfig();
d->mViewMainPage->loadConfig();
d->mBrowseMainPage->loadConfig();
......
......@@ -46,6 +46,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <lib/gwenviewconfig.h>
#include <lib/thumbnailview/abstractthumbnailviewhelper.h>
#include <lib/thumbnailview/previewitemdelegate.h>
#include <lib/thumbnailprovider/thumbnailprovider.h>
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
#include <lib/semanticinfo/tagmodel.h>
......@@ -74,33 +75,12 @@ public:
}
};
/**
* Inherit from QStyledItemDelegate to match KFilePlacesViewDelegate sizeHint
* height.
*/
class HistoryViewDelegate : public QStyledItemDelegate
{
public:
HistoryViewDelegate(QObject* parent = 0)
: QStyledItemDelegate(parent)
{}
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QSize sh = QStyledItemDelegate::sizeHint(option, index);
int iconSize = static_cast<QAbstractItemView*>(parent())->iconSize().height();
// Copied from KFilePlacesViewDelegate::sizeHint()
int height = option.fontMetrics.height() / 2 + qMax(iconSize, option.fontMetrics.height());
sh.setHeight(qMax(sh.height(), height));
return sh;
}
};
struct StartMainPagePrivate : public Ui_StartMainPage
{
StartMainPage* q;
GvCore* mGvCore;
KFilePlacesModel* mBookmarksModel;
ThumbnailProvider *mRecentFilesThumbnailProvider;
bool mSearchUiInitialized;
void setupSearchUi()
......@@ -120,6 +100,22 @@ struct StartMainPagePrivate : public Ui_StartMainPage
mHistoryWidget->setVisible(GwenviewConfig::historyEnabled());
mHistoryDisabledLabel->setVisible(!GwenviewConfig::historyEnabled());
}
void setupHistoryView(ThumbnailView *view)
{
view->setThumbnailViewHelper(new HistoryThumbnailViewHelper(view));
PreviewItemDelegate* delegate = new PreviewItemDelegate(view);
delegate->setContextBarActions(PreviewItemDelegate::NoAction);
delegate->setTextElideMode(Qt::ElideLeft);
view->setItemDelegate(delegate);
view->setThumbnailWidth(128);
view->setCreateThumbnailsForRemoteUrls(false);
QModelIndex index = view->model()->index(0, 0);
if (index.isValid()) {
view->setCurrentIndex(index);
}
}
};
static void initViewPalette(QAbstractItemView* view, const QColor& fgColor)
......@@ -146,6 +142,7 @@ StartMainPage::StartMainPage(QWidget* parent, GvCore* gvCore)
: QFrame(parent)
, d(new StartMainPagePrivate)
{
d->mRecentFilesThumbnailProvider = 0;
d->q = this;
d->mGvCore = gvCore;
d->mSearchUiInitialized = false;
......@@ -180,15 +177,7 @@ StartMainPage::StartMainPage(QWidget* parent, GvCore* gvCore)
connect(d->mRecentFoldersView, &Gwenview::ThumbnailView::customContextMenuRequested, this, &StartMainPage::showRecentFoldersViewContextMenu);
// Url bag view
d->mRecentUrlsView->setItemDelegate(new HistoryViewDelegate(d->mRecentUrlsView));
connect(d->mRecentUrlsView, &QListView::customContextMenuRequested, this, &StartMainPage::showRecentFoldersViewContextMenu);
if (KGlobalSettings::changeCursorOverIcon()) {
d->mRecentUrlsView->setCursor(Qt::PointingHandCursor);
}
connect(d->mRecentUrlsView, &QListView::activated, this, &StartMainPage::slotListViewActivated);
connect(d->mRecentFilesView, &Gwenview::ThumbnailView::indexActivated, this, &StartMainPage::slotListViewActivated);
d->updateHistoryTab();
connect(GwenviewConfig::self(), &GwenviewConfig::configChanged, this, &StartMainPage::loadConfig);
......@@ -198,6 +187,7 @@ StartMainPage::StartMainPage(QWidget* parent, GvCore* gvCore)
StartMainPage::~StartMainPage()
{
delete d->mRecentFilesThumbnailProvider;
delete d;
}
......@@ -228,7 +218,7 @@ void StartMainPage::applyPalette(const QPalette& newPalette)
initViewPalette(d->mBookmarksView, fgColor);
initViewPalette(d->mTagView, fgColor);
initViewPalette(d->mRecentFoldersView, fgColor);
initViewPalette(d->mRecentUrlsView, fgColor);
initViewPalette(d->mRecentFilesView, fgColor);
}
void StartMainPage::slotListViewActivated(const QModelIndex& index)
......@@ -251,21 +241,14 @@ void StartMainPage::showEvent(QShowEvent* event)
{
if (GwenviewConfig::historyEnabled()) {
if (!d->mRecentFoldersView->model()) {
d->mRecentFoldersView->setThumbnailViewHelper(new HistoryThumbnailViewHelper(d->mRecentFoldersView));
d->mRecentFoldersView->setModel(d->mGvCore->recentFoldersModel());
PreviewItemDelegate* delegate = new PreviewItemDelegate(d->mRecentFoldersView);
delegate->setContextBarActions(PreviewItemDelegate::NoAction);
delegate->setTextElideMode(Qt::ElideLeft);
d->mRecentFoldersView->setItemDelegate(delegate);
d->mRecentFoldersView->setThumbnailWidth(128);
d->mRecentFoldersView->setCreateThumbnailsForRemoteUrls(false);
QModelIndex index = d->mRecentFoldersView->model()->index(0, 0);
if (index.isValid()) {
d->mRecentFoldersView->setCurrentIndex(index);
}
d->setupHistoryView(d->mRecentFoldersView);
}
if (!d->mRecentUrlsView->model()) {
d->mRecentUrlsView->setModel(d->mGvCore->recentUrlsModel());
if (!d->mRecentFilesView->model()) {
d->mRecentFilesView->setModel(d->mGvCore->recentFilesModel());
d->mRecentFilesThumbnailProvider = new ThumbnailProvider();
d->mRecentFilesView->setThumbnailProvider(d->mRecentFilesThumbnailProvider);
d->setupHistoryView(d->mRecentFilesView);
}
}
if (!d->mSearchUiInitialized) {
......@@ -287,9 +270,8 @@ void StartMainPage::showRecentFoldersViewContextMenu(const QPoint& pos)
// Create menu
QMenu menu(this);
bool fromRecentUrls = view == d->mRecentUrlsView;
QAction* addToPlacesAction = fromRecentUrls ? 0 : menu.addAction(QIcon::fromTheme("bookmark-new"), i18n("Add to Places"));
QAction* removeAction = menu.addAction(QIcon::fromTheme("edit-delete"), fromRecentUrls ? i18n("Forget this URL") : i18n("Forget this Folder"));
QAction* addToPlacesAction = menu.addAction(QIcon::fromTheme("bookmark-new"), i18n("Add to Places"));
QAction* removeAction = menu.addAction(QIcon::fromTheme("edit-delete"), i18n("Forget this Folder"));
menu.addSeparator();
QAction* clearAction = menu.addAction(QIcon::fromTheme("edit-delete-all"), i18n("Forget All"));
......
......@@ -62,26 +62,14 @@
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Recent URLs</string>
<string>Recent Files</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QListView" name="mRecentUrlsView">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<widget class="Gwenview::ThumbnailView" name="mRecentFilesView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
</layout>
......
......@@ -101,6 +101,7 @@ set(gwenviewlib_SRCS
binder.cpp
eventwatcher.cpp
historymodel.cpp
recentfilesmodel.cpp
archiveutils.cpp
datewidget.cpp
exiv2imageloader.cpp
......
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
Copyright 2014 Tomas Mecir <mecirt@gmail.com>
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 "recentfilesmodel.h"
// Qt
#include <QDebug>
#include <QUrl>
#include <QMimeDatabase>
// KDE
#include <KDirModel>
#include <KFileItem>
#include <KFilePlacesModel>
#include <KFormat>
// Local
#include <lib/urlutils.h>
namespace Gwenview
{
struct RecentFilesItem : public QStandardItem
{
QUrl url() const
{
return mUrl;
}
RecentFilesItem(const QUrl &url)
: mUrl(url) {
QUrl urlForView = mUrl;
setText(urlForView.toDisplayString());
QMimeDatabase db;
const QString iconName = db.mimeTypeForUrl(mUrl).iconName();
setIcon(QIcon::fromTheme(iconName));
setData(mUrl, KFilePlacesModel::UrlRole);
KFileItem fileItem(mUrl);
setData(QVariant(fileItem), KDirModel::FileItemRole);
}
private:
QUrl mUrl;
};
struct RecentFilesModelPrivate
{
RecentFilesModel* q;
QMap<QUrl, RecentFilesItem*> mRecentFilesItemForUrl;
};
RecentFilesModel::RecentFilesModel(QObject* parent)
: QStandardItemModel(parent)
, d(new RecentFilesModelPrivate)
{
d->q = this;
}
RecentFilesModel::~RecentFilesModel()
{
delete d;
}
void RecentFilesModel::addUrl(const QUrl &url)
{
RecentFilesItem* historyItem = d->mRecentFilesItemForUrl.value(url);
if (!historyItem) {
historyItem = new RecentFilesItem(url);
if (!historyItem) return;
d->mRecentFilesItemForUrl.insert(url, historyItem);
appendRow(historyItem);
}
sort(0);
}
bool RecentFilesModel::removeRows(int start, int count, const QModelIndex& parent)
{
Q_ASSERT(!parent.isValid());
for (int row = start + count - 1; row >= start ; --row) {
RecentFilesItem* historyItem = static_cast<RecentFilesItem*>(item(row, 0));
Q_ASSERT(historyItem);
d->mRecentFilesItemForUrl.remove(historyItem->url());
}
return QStandardItemModel::removeRows(start, count, parent);
}
} // namespace
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
Copyright 2014 Tomas Mecir <mecirt@gmail.com>
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 RECENTFILESMODEL_H
#define RECENTFILESMODEL_H
// Qt
#include <QStandardItemModel>
// KDE
// Local
#include <lib/gwenviewlib_export.h>
class QUrl;
namespace Gwenview
{
struct RecentFilesModelPrivate;
/**
* 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 RecentFilesModel : public QStandardItemModel
{
Q_OBJECT
public:
RecentFilesModel(QObject* parent);
~RecentFilesModel();
void addUrl(const QUrl&);
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
private:
RecentFilesModelPrivate* const d;
};
} // namespace
#endif /* RECENTFILESMODEL_H */
Supports Markdown
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