add more spacing
[personal-kdebase.git] / workspace / plasma / runners / recentdocuments / recentdocuments.cpp
blob676de05150617620a161eb6579dff578801e98f8
1 /*
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"
22 #include <KConfig>
23 #include <KConfigGroup>
24 #include <KDebug>
25 #include <KDirWatch>
26 #include <KIcon>
27 #include <KStandardDirs>
28 #include <KRun>
29 #include <KRecentDocument>
32 RecentDocuments::RecentDocuments(QObject *parent, const QVariantList& args)
33 : Plasma::AbstractRunner(parent, args)
35 Q_UNUSED(args);
36 KGlobal::locale()->insertCatalog("krunner_recentdocuments");
37 setObjectName("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()));
48 RecentDocuments::~RecentDocuments()
52 void RecentDocuments::loadRecentDocuments()
54 kDebug()<<" Refreshing recent documents.";
55 m_recentdocuments = KRecentDocument::recentDocuments();
59 void RecentDocuments::match(Plasma::RunnerContext &context)
61 if (m_recentdocuments.isEmpty()) {
62 return;
65 const QString term = context.query();
66 if (term.length() < 3) {
67 return;
70 foreach (const QString &document, m_recentdocuments) {
71 if (document.contains(term, Qt::CaseInsensitive)) {
72 KConfig _config( document, KConfig::SimpleConfig );
73 KConfigGroup config(&_config, "Desktop Entry" );
74 QString niceName = config.readEntry( "Name" );
75 Plasma::QueryMatch match(this);
76 match.setType(Plasma::QueryMatch::PossibleMatch);
77 match.setRelevance(1.0);
78 match.setIcon(KIcon(config.readEntry("Icon")));
79 match.setData(document); // TODO: Read URL[$e], or can we just pass the path to the .desktop file?
80 match.setText(niceName);
81 match.setSubtext(i18n("Recent Document"));
82 context.addMatch(term, match);
87 void RecentDocuments::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
89 Q_UNUSED(context)
90 QString url = match.data().toString();
91 kDebug() << "Opening Recent Document" << url;
92 new KRun(url, 0);
95 #include "recentdocuments.moc"