DesktopFileGenerator.cpp 3.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/***************************************************************************
 *   Copyright (C) 2009 by Ben Cooksley <ben@eclipse.endoftheinternet.org> *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
 ***************************************************************************/

Lukáš Tinkl's avatar
Lukáš Tinkl committed
20
21
22
23
#include <QDebug>
#include <QCoreApplication>
#include <QCommandLineParser>

24
#include <KAboutData>
Lukáš Tinkl's avatar
Lukáš Tinkl committed
25
26
#include <KLocalizedString>

27
28
29
30
31
32
33
#include <KDesktopFile>
#include <KConfigGroup>

#include "SolidActionData.h"

int main( int argc, char *argv[] )
{
Lukáš Tinkl's avatar
Lukáš Tinkl committed
34
    QCoreApplication application(argc, argv);
35
    KLocalizedString::setApplicationDomain("kcm_solid_actions");
Lukáš Tinkl's avatar
Lukáš Tinkl committed
36

37
    // About data
38
    KAboutData aboutData(QStringLiteral("solid-action-desktop-gen"), i18n("Solid Action Desktop File Generator"), QStringLiteral("0.4"),
Lukáš Tinkl's avatar
Lukáš Tinkl committed
39
40
                         i18n("Tool to automatically generate Desktop Files from Solid DeviceInterface classes for translation"),
                         KAboutLicense::GPL, i18n("(c) 2009, Ben Cooksley"));
41
    aboutData.addAuthor(i18n("Ben Cooksley"), i18n("Maintainer"), QStringLiteral("ben@eclipse.endoftheinternet.org"));
Lukáš Tinkl's avatar
Lukáš Tinkl committed
42
43
44
45
46
47
48
49
    KAboutData::setApplicationData(aboutData);

    QCommandLineParser parser;
    parser.addHelpOption();
    parser.addVersionOption();
    aboutData.setupCommandLine(&parser);
    parser.process(application);
    aboutData.processCommandLine(&parser);
50
51
52

    SolidActionData * availActions = SolidActionData::instance();
    foreach( Solid::DeviceInterface::Type internalType, availActions->interfaceTypeList() ) {
Lukáš Tinkl's avatar
Lukáš Tinkl committed
53
54
        const QString typeName = Solid::DeviceInterface::typeToString( internalType );
        KDesktopFile typeFile(QStandardPaths::GenericDataLocation, "solid/devices/solid-device-" + typeName + ".desktop" );
55
56
57
58
59
60
61
62
63
64
        KConfigGroup tConfig = typeFile.desktopGroup();

        tConfig.writeEntry( "Name", "Solid Device" );
        tConfig.writeEntry( "X-KDE-ServiceTypes", "SolidDevice" );
        tConfig.writeEntry( "Type", "Service" );

        if( !tConfig.hasKey("X-KDE-Solid-Actions-Type") ) {
            tConfig.writeEntry( "X-KDE-Solid-Actions-Type", typeName );
        }

Lukáš Tinkl's avatar
Lukáš Tinkl committed
65
        const QStringList typeValues = availActions->propertyInternalList( internalType );
66
        const QString actionText = typeValues.join(QStringLiteral(";")).append(";");
67
68
        tConfig.writeEntry( "Actions", actionText );

Lukáš Tinkl's avatar
Lukáš Tinkl committed
69
        qWarning() << "Desktop file created: " + typeFile.fileName();
70
71
72
73
74
75
76
77
78
79
80
        foreach( const QString &tValue, typeValues ) {
            KConfigGroup vConfig = typeFile.actionGroup( tValue );
            if( !vConfig.hasKey("Name") ) {
                vConfig.writeEntry( "Name", availActions->propertyName( internalType, tValue ) );
            }
            vConfig.sync();
        }
        tConfig.sync();
        typeFile.sync();
    }

Lukáš Tinkl's avatar
Lukáš Tinkl committed
81
    qWarning() << "Generation now completed";
82
83
    return 0;
}