~ubuntu-branches/ubuntu/trusty/kdeplasma-addons/trusty

« back to all changes in this revision

Viewing changes to applets/lancelot/app/src/models/NewDocuments.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mfrom: (1.1.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100525095014-6mlrm9z9bkws0zkt
Tags: 4:4.4.80-0ubuntu1
* New upstream beta release:
  - Bump kde-sc-dev-latest build-dep version to 4.4.80
  - Refresh kubuntu_04_kimpanel_disable_scim.diff
  - Update various .install files
  - Drop liblancelot0a and liblancelot-dev packages; Upstream has broken ABI
    without an .so version bump, and after discussion with Debian it was
    decided it was not worth it to ship an unstable library.
  - Add liblancelot files to plasma-widget-lancelot, adding appropriate
    Replaces: entries
* Switch to source format 3.0 (quilt):
  - Bump debhelper build-depend version to 7.3.16 or greater

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   Copyright (C) 2007 Ivan Cukic <ivan.cukic(at)kde.org>
3
 
 *
4
 
 *   This program is free software; you can redistribute it and/or modify
5
 
 *   it under the terms of the GNU General Public License version 2,
6
 
 *   or (at your option) any later version, as published by the Free
7
 
 *   Software Foundation
8
 
 *
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
13
 
 *
14
 
 *   You should have received a copy of the GNU 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.
18
 
 */
19
 
 
20
 
#include "NewDocuments.h"
21
 
#include <KStandardDirs>
22
 
#include <KIcon>
23
 
 
24
 
namespace Models {
25
 
 
26
 
#define LinkOrCopy(source, destination)           \
27
 
    qDebug() << "Models::LinkOrCopy:"             \
28
 
                 << source << destination;        \
29
 
    if (!QFile::link((source), (destination))) {  \
30
 
        qDebug() << "Models::LinkOrCopy:"         \
31
 
                 << "Linking failed ... copying"; \
32
 
        QFile::copy((source), (destination));     \
33
 
    }
34
 
 
35
 
NewDocuments::NewDocuments()
36
 
    : FolderModel(NewDocuments::path(), QDir::Name)
37
 
{
38
 
    setSelfTitle(i18n("New:"));
39
 
    setSelfIcon(KIcon("document-new"));
40
 
 
41
 
    QDir dir(path());
42
 
    if (dir.entryList(QDir::Files | QDir::NoDotAndDotDot).size() == 0) {
43
 
 
44
 
        QStringList applications;
45
 
        applications
46
 
            << "ooo-writer|writer|kword"
47
 
            << "ooo-impress|impress|kpresenter"
48
 
            << "ooo-calc|calc|kspread"
49
 
            << "inkscape|karbon"
50
 
            << "gimp|krita";
51
 
 
52
 
        int index = 0;
53
 
 
54
 
        foreach (const QString & serviceAlternatives, applications) {
55
 
            foreach (const QString & serviceName, serviceAlternatives.split('|')) {
56
 
                const KService::Ptr service = KService::serviceByStorageId(serviceName);
57
 
                if (service) {
58
 
                    QFileInfo file(service->entryPath());
59
 
                    LinkOrCopy(
60
 
                        service->entryPath(),
61
 
                        dir.absolutePath() + '/' +
62
 
                        QString::number(index++) + '_' + file.fileName());
63
 
                    break;
64
 
                }
65
 
            }
66
 
        }
67
 
    }
68
 
}
69
 
 
70
 
NewDocuments::~NewDocuments()
71
 
{
72
 
}
73
 
 
74
 
QString NewDocuments::path()
75
 
{
76
 
    QString path = KStandardDirs::locateLocal("data", "lancelot", true);
77
 
    if (!path.endsWith('/')) {
78
 
        path += '/';
79
 
    }
80
 
    path += "/newdocuments/";
81
 
 
82
 
    QDir dir;
83
 
    dir.mkpath(path);
84
 
 
85
 
    return path;
86
 
}
87
 
 
88
 
} // namespace Models