~ubuntu-branches/ubuntu/raring/plasma-mobile/raring-proposed

« back to all changes in this revision

Viewing changes to applications/filebrowser/src/filebrowser.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-17 12:04:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120717120443-q3ig9u2fnltx67yg
Tags: 2.0+git2012071701-0ubuntu1
* New upstream snapshot
* Remove build-dep on kde-runtime-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                                                                         *
 
3
 *   Copyright 2011 Sebastian Kügler <sebas@kde.org>                       *
 
4
 *   Copyright 2011 Marco Martin <mart@kde.org>                            *
 
5
 *                                                                         *
 
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.                                   *
 
10
 *                                                                         *
 
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.                          *
 
15
 *                                                                         *
 
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
 ***************************************************************************/
 
21
 
 
22
#include "filebrowser.h"
 
23
#include "kdeclarativeview.h"
 
24
 
 
25
#include <QDeclarativeContext>
 
26
#include <QFileInfo>
 
27
 
 
28
#include <KAction>
 
29
#include <KCmdLineArgs>
 
30
#include <KConfigGroup>
 
31
#include <KIcon>
 
32
#include <KStandardAction>
 
33
#include <KStandardDirs>
 
34
#include <KServiceTypeTrader>
 
35
 
 
36
#include <kio/copyjob.h>
 
37
#include <Plasma/Theme>
 
38
 
 
39
 
 
40
FileBrowser::FileBrowser()
 
41
    : KDeclarativeMainWindow(),
 
42
      m_emptyProcess(0)
 
43
{
 
44
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
45
 
 
46
    declarativeView()->setPackageName("org.kde.active.filebrowser");
 
47
 
 
48
    declarativeView()->rootContext()->setContextProperty("exclusiveResourceType", args->getOption("resourceType"));
 
49
 
 
50
    QString mimeString = args->getOption("mimeTypes");
 
51
    if (mimeString.isEmpty()) {
 
52
        declarativeView()->rootContext()->setContextProperty("exclusiveMimeTypes", QStringList());
 
53
    } else {
 
54
        QStringList mimeTypes = mimeString.split(',');
 
55
        declarativeView()->rootContext()->setContextProperty("exclusiveMimeTypes", mimeTypes);
 
56
    }
 
57
 
 
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"));
 
62
    }
 
63
}
 
64
 
 
65
FileBrowser::~FileBrowser()
 
66
{
 
67
}
 
68
 
 
69
QString FileBrowser::packageForMimeType(const QString &mimeType)
 
70
{
 
71
     KService::List services = KServiceTypeTrader::self()->query("Active/FileBrowserPart", QString("'%1' in MimeTypes").arg(mimeType));
 
72
 
 
73
     foreach (const KService::Ptr &service, services) {
 
74
        if (service->noDisplay()) {
 
75
            continue;
 
76
        }
 
77
        QString description;
 
78
        if (!service->genericName().isEmpty() && service->genericName() != service->name()) {
 
79
            description = service->genericName();
 
80
        } else if (!service->comment().isEmpty()) {
 
81
            description = service->comment();
 
82
        }
 
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();
 
86
    }
 
87
    return QString();
 
88
}
 
89
 
 
90
void FileBrowser::emptyTrash()
 
91
{
 
92
    // We can't use KonqOperations here. To avoid duplicating its code (small, though),
 
93
    // we can simply call ktrash.
 
94
 
 
95
    if (m_emptyProcess) {
 
96
        return;
 
97
    }
 
98
 
 
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();
 
104
}
 
105
 
 
106
void FileBrowser::emptyFinished(int exitCode, QProcess::ExitStatus exitStatus)
 
107
{
 
108
    Q_UNUSED(exitCode)
 
109
    Q_UNUSED(exitStatus)
 
110
 
 
111
    //TODO: check the exit status and let the user know if it fails
 
112
    delete m_emptyProcess;
 
113
    m_emptyProcess = 0;
 
114
}
 
115
 
 
116
void FileBrowser::copy(const QVariantList &src, const QString &dest)
 
117
{
 
118
    KUrl::List urls;
 
119
    foreach (const QVariant &var, src) {
 
120
        urls << var.toUrl();
 
121
    }
 
122
    KIO::copy(urls, KUrl(dest));
 
123
}
 
124
 
 
125
void FileBrowser::trash(const QVariantList &files)
 
126
{
 
127
    KUrl::List urls;
 
128
    foreach (const QVariant &var, files) {
 
129
        urls << var.toUrl();
 
130
    }
 
131
    KIO::trash(urls);
 
132
}
 
133
 
 
134
#include "filebrowser.moc"