2
* Copyright 2008 Sebastian Kügler <sebas@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "recentdocuments.h"
25
#include <KConfigGroup>
30
#include <KRecentDocument>
33
RecentDocuments::RecentDocuments(QObject *parent, const QVariantList& args)
34
: Plasma::AbstractRunner(parent, args)
37
setObjectName( QLatin1String("Recent Documents" ));
38
m_icon = KIcon("document-open-recent");
39
loadRecentDocuments();
40
// listen for changes to the list of recent documents
41
KDirWatch *recentDocWatch = new KDirWatch(this);
42
recentDocWatch->addDir(KRecentDocument::recentDocumentDirectory(), KDirWatch::WatchFiles);
43
connect(recentDocWatch,SIGNAL(created(QString)),this,SLOT(loadRecentDocuments()));
44
connect(recentDocWatch,SIGNAL(deleted(QString)),this,SLOT(loadRecentDocuments()));
45
connect(recentDocWatch,SIGNAL(dirty(QString)),this,SLOT(loadRecentDocuments()));
46
addSyntax(Plasma::RunnerSyntax(":q:", i18n("Looks for documents recently used with names matching :q:.")));
49
RecentDocuments::~RecentDocuments()
53
void RecentDocuments::loadRecentDocuments()
55
//kDebug() << "Refreshing recent documents.";
56
m_recentdocuments = KRecentDocument::recentDocuments();
60
void RecentDocuments::match(Plasma::RunnerContext &context)
62
if (m_recentdocuments.isEmpty()) {
66
const QString term = context.query();
67
if (term.length() < 3) {
71
foreach (const QString &document, m_recentdocuments) {
72
if (!context.isValid()) {
76
if (document.contains(term, Qt::CaseInsensitive)) {
77
KConfig _config( document, KConfig::SimpleConfig );
78
KConfigGroup config(&_config, "Desktop Entry" );
79
QString niceName = config.readEntry( "Name" );
80
Plasma::QueryMatch match(this);
81
match.setType(Plasma::QueryMatch::PossibleMatch);
82
match.setRelevance(1.0);
83
match.setIcon(KIcon(config.readEntry("Icon")));
84
match.setData(document); // TODO: Read URL[$e], or can we just pass the path to the .desktop file?
85
match.setText(niceName);
86
match.setSubtext(i18n("Recent Document"));
87
context.addMatch(term, match);
92
void RecentDocuments::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
95
QString url = match.data().toString();
96
kDebug() << "Opening Recent Document" << url;
100
QMimeData * RecentDocuments::mimeDataForMatch(const Plasma::QueryMatch * match)
102
QMimeData * result = new QMimeData();
104
urls << QUrl(match->data().toString());
105
result->setUrls(urls);
107
result->setText(match->data().toString());
111
#include "recentdocuments.moc"