1
/***************************************************************************
3
* Copyright 2011 Sebastian Kügler <sebas@kde.org> *
4
* Copyright 2011 Marco Martin <mart@kde.org> *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20
***************************************************************************/
22
#include "filebrowser.h"
23
#include "kdeclarativeview.h"
25
#include <QDeclarativeContext>
29
#include <KCmdLineArgs>
30
#include <KConfigGroup>
32
#include <KStandardAction>
33
#include <KStandardDirs>
34
#include <KServiceTypeTrader>
36
#include <kio/copyjob.h>
37
#include <Plasma/Theme>
40
FileBrowser::FileBrowser()
41
: KDeclarativeMainWindow(),
44
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
46
declarativeView()->setPackageName("org.kde.active.filebrowser");
48
declarativeView()->rootContext()->setContextProperty("exclusiveResourceType", args->getOption("resourceType"));
50
QString mimeString = args->getOption("mimeTypes");
51
if (mimeString.isEmpty()) {
52
declarativeView()->rootContext()->setContextProperty("exclusiveMimeTypes", QStringList());
54
QStringList mimeTypes = mimeString.split(',');
55
declarativeView()->rootContext()->setContextProperty("exclusiveMimeTypes", mimeTypes);
58
//FIXME: need more elegant and pluggable way
59
if (args->getOption("resourceType") == "nfo:Image") {
60
setWindowIcon(KIcon("active-image-viewer"));
61
setPlainCaption(i18n("Images"));
65
FileBrowser::~FileBrowser()
69
QString FileBrowser::packageForMimeType(const QString &mimeType)
71
KService::List services = KServiceTypeTrader::self()->query("Active/FileBrowserPart", QString("'%1' in MimeTypes").arg(mimeType));
73
foreach (const KService::Ptr &service, services) {
74
if (service->noDisplay()) {
78
if (!service->genericName().isEmpty() && service->genericName() != service->name()) {
79
description = service->genericName();
80
} else if (!service->comment().isEmpty()) {
81
description = service->comment();
83
//kDebug() << service->property("X-KDE-PluginInfo-Name") << " :: " << description;
84
kDebug() << service->property("X-KDE-PluginInfo-Name") << "\t\t" << description.toLocal8Bit().data();
85
return service->property("X-KDE-PluginInfo-Name").toString();
90
void FileBrowser::emptyTrash()
92
// We can't use KonqOperations here. To avoid duplicating its code (small, though),
93
// we can simply call ktrash.
99
m_emptyProcess = new KProcess(this);
100
connect(m_emptyProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
101
this, SLOT(emptyFinished(int,QProcess::ExitStatus)));
102
(*m_emptyProcess) << KStandardDirs::findExe("ktrash") << "--empty";
103
m_emptyProcess->start();
106
void FileBrowser::emptyFinished(int exitCode, QProcess::ExitStatus exitStatus)
111
//TODO: check the exit status and let the user know if it fails
112
delete m_emptyProcess;
116
void FileBrowser::copy(const QVariantList &src, const QString &dest)
119
foreach (const QVariant &var, src) {
122
KIO::copy(urls, KUrl(dest));
125
void FileBrowser::trash(const QVariantList &files)
128
foreach (const QVariant &var, files) {
134
#include "filebrowser.moc"