1 | /*************************************************************************** |
2 | * Copyright (C) 2009 by Ben Cooksley <ben@eclipse.endoftheinternet.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 as published by * |
6 | * the Free Software Foundation; either version 2 of the License, or * |
7 | * (at your option) any later version. * |
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 License * |
15 | * 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 <KAboutData> |
21 | #include <KCmdLineArgs> |
22 | #include <KLocale> |
23 | #include <KApplication> |
24 | #include <KDesktopFile> |
25 | #include <KDebug> |
26 | #include <KConfigGroup> |
27 | |
28 | #include "SolidActionData.h" |
29 | |
30 | #include <iostream> |
31 | |
32 | int main( int argc, char *argv[] ) |
33 | { |
34 | KLocale::setMainCatalog("solid-action-desktop-gen" ); |
35 | // About data |
36 | KAboutData aboutData("solid-action-desktop-gen" , 0, ki18n("Solid Action Desktop File Generator" ), "0.4" , ki18n("Tool to automatically generate Desktop Files from Solid DeviceInterface classes for translation" ), |
37 | KAboutData::License_GPL, ki18n("(c) 2009, Ben Cooksley" )); |
38 | aboutData.addAuthor(ki18n("Ben Cooksley" ), ki18n("Maintainer" ), "ben@eclipse.endoftheinternet.org" ); |
39 | KCmdLineArgs::init(argc, argv, &aboutData); |
40 | |
41 | KApplication application(false); |
42 | SolidActionData * availActions = SolidActionData::instance(); |
43 | foreach( Solid::DeviceInterface::Type internalType, availActions->interfaceTypeList() ) { |
44 | QString typeName = Solid::DeviceInterface::typeToString( internalType ); |
45 | KDesktopFile typeFile( "services" , "solid-device-" + typeName + ".desktop" ); |
46 | KConfigGroup tConfig = typeFile.desktopGroup(); |
47 | |
48 | tConfig.writeEntry( "Name" , "Solid Device" ); |
49 | tConfig.writeEntry( "X-KDE-ServiceTypes" , "SolidDevice" ); |
50 | tConfig.writeEntry( "Type" , "Service" ); |
51 | |
52 | if( !tConfig.hasKey("X-KDE-Solid-Actions-Type" ) ) { |
53 | tConfig.writeEntry( "X-KDE-Solid-Actions-Type" , typeName ); |
54 | } |
55 | |
56 | QStringList typeValues = availActions->propertyInternalList( internalType ); |
57 | QString actionText = typeValues.join(";" ).append(";" ); |
58 | tConfig.writeEntry( "Actions" , actionText ); |
59 | |
60 | kWarning() << "Desktop file created: " + typeFile.fileName(); |
61 | foreach( const QString &tValue, typeValues ) { |
62 | KConfigGroup vConfig = typeFile.actionGroup( tValue ); |
63 | if( !vConfig.hasKey("Name" ) ) { |
64 | vConfig.writeEntry( "Name" , availActions->propertyName( internalType, tValue ) ); |
65 | } |
66 | vConfig.sync(); |
67 | } |
68 | tConfig.sync(); |
69 | typeFile.sync(); |
70 | } |
71 | |
72 | kWarning() << "Generation now completed" ; |
73 | return 0; |
74 | } |
75 | |