1
/***************************************************************************
2
* Copyright (C) 2009 by Ben Cooksley <ben@eclipse.endoftheinternet.org> *
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. *
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. *
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
***************************************************************************/
20
#include "SolidActionData.h"
23
#include <QMetaProperty>
26
#include <kdesktopfileactions.h>
27
#include <KStandardDirs>
28
#include <KStringHandler>
29
#include <KDesktopFile>
30
#include <KConfigGroup>
32
#include <Solid/AcAdapter>
33
#include <Solid/AudioInterface>
34
#include <Solid/Battery>
35
#include <Solid/Block>
36
#include <Solid/Button>
37
#include <Solid/Camera>
38
#include <Solid/DvbInterface>
39
#include <Solid/GenericInterface>
40
#include <Solid/NetworkInterface>
41
#include <Solid/PortableMediaPlayer>
42
#include <Solid/Processor>
43
#include <Solid/StorageAccess>
44
#include <Solid/StorageDrive>
45
#include <Solid/OpticalDrive>
46
#include <Solid/StorageVolume>
47
#include <Solid/OpticalDisc>
48
#include <solid/video.h>
49
#include <solid/serialinterface.h>
50
#include <solid/smartcardreader.h>
52
static SolidActionData * actData = 0;
54
SolidActionData::SolidActionData(bool includeFiles)
56
QStringList allPossibleDevices;
57
int propertyOffset = Solid::DeviceInterface::staticMetaObject.propertyOffset();
59
QList<QMetaObject> interfaceList = fillInterfaceList();
60
foreach( const QMetaObject &interface, interfaceList ) {
61
QString ifaceName = interface.className();
62
ifaceName.remove(0, ifaceName.lastIndexOf(':') + 1);
63
Solid::DeviceInterface::Type ifaceDev = Solid::DeviceInterface::stringToType( ifaceName );
64
QString cleanName = Solid::DeviceInterface::typeDescription( ifaceDev );
65
types.insert( ifaceDev, cleanName );
67
QMap<QString, QString> deviceValues;
68
for( int doneProps = propertyOffset; interface.propertyCount() > doneProps; doneProps = doneProps + 1 ) {
69
QMetaProperty ifaceProp = interface.property(doneProps);
70
deviceValues.insert( ifaceProp.name(), generateUserString(ifaceProp.name()) );
72
values.insert( ifaceDev, deviceValues );
76
// Fill the lists of possible device types / device values
77
allPossibleDevices = KGlobal::dirs()->findAllResources("data", "solid/devices/");
78
// List all the known device actions, then add their name and all values to the appropriate lists
79
foreach( const QString &desktop, allPossibleDevices ) {
80
KDesktopFile deviceFile(desktop);
81
KConfigGroup deviceType = deviceFile.desktopGroup(); // Retrieve the configuration group where the user friendly name is
83
QString ifaceName = deviceType.readEntry("X-KDE-Solid-Actions-Type");
84
Solid::DeviceInterface::Type ifaceDev = Solid::DeviceInterface::stringToType( ifaceName );
85
QString cleanName = Solid::DeviceInterface::typeDescription( ifaceDev );
87
types.insert( ifaceDev, cleanName ); // Read the user friendly name
89
QMap<QString,QString> deviceValues = values.value( ifaceDev );
90
foreach( const QString &text, deviceFile.readActions() ) { // We want every single action
91
KConfigGroup actionType = deviceFile.actionGroup( text );
92
deviceValues.insert( text, actionType.readEntry("Name") ); // Add to the type - actions map
94
values.insert( ifaceDev, deviceValues );
99
QList<QString> SolidActionData::propertyList( Solid::DeviceInterface::Type devInterface )
101
return values.value( devInterface ).values();
104
QList<QString> SolidActionData::propertyInternalList( Solid::DeviceInterface::Type devInterface )
106
return values.value( devInterface ).keys();
109
QString SolidActionData::propertyInternal( Solid::DeviceInterface::Type devInterface, QString property )
111
return values.value( devInterface ).key( property );
114
QString SolidActionData::propertyName( Solid::DeviceInterface::Type devInterface, QString property )
116
return values.value( devInterface ).value( property );
119
int SolidActionData::propertyPosition( Solid::DeviceInterface::Type devInterface, QString property )
121
return values.value( devInterface ).keys().indexOf( property );
124
QList<QString> SolidActionData::interfaceList()
126
return types.values();
129
QList<Solid::DeviceInterface::Type> SolidActionData::interfaceTypeList()
134
Solid::DeviceInterface::Type SolidActionData::interfaceFromName( const QString& name )
136
return types.key( name );
139
QString SolidActionData::nameFromInterface( Solid::DeviceInterface::Type devInterface )
141
return types.value( devInterface );
144
int SolidActionData::interfacePosition( Solid::DeviceInterface::Type devInterface )
146
return types.keys().indexOf( devInterface );
149
QString SolidActionData::generateUserString( QString className )
152
QRegExp camelCase("([A-Z])"); // Create the split regexp
154
finalString = className.remove(0, className.lastIndexOf(':') + 1); // Remove any Class information
155
finalString = finalString.replace( camelCase, " \\1" ); // Use Camel Casing to add spaces
156
finalString = KStringHandler::capwords( finalString ); // Captialise everything
157
return finalString.trimmed();
160
SolidActionData * SolidActionData::instance()
163
actData = new SolidActionData( true );
168
QList<QMetaObject> SolidActionData::fillInterfaceList()
170
QList<QMetaObject> interfaces;
171
interfaces.append( Solid::AcAdapter::staticMetaObject );
172
interfaces.append( Solid::AudioInterface::staticMetaObject );
173
interfaces.append( Solid::Battery::staticMetaObject );
174
interfaces.append( Solid::Block::staticMetaObject );
175
interfaces.append( Solid::Button::staticMetaObject );
176
interfaces.append( Solid::Camera::staticMetaObject );
177
interfaces.append( Solid::DvbInterface::staticMetaObject );
178
interfaces.append( Solid::NetworkInterface::staticMetaObject );
179
interfaces.append( Solid::PortableMediaPlayer::staticMetaObject );
180
interfaces.append( Solid::Processor::staticMetaObject );
181
interfaces.append( Solid::SerialInterface::staticMetaObject );
182
interfaces.append( Solid::StorageAccess::staticMetaObject );
183
interfaces.append( Solid::StorageDrive::staticMetaObject );
184
interfaces.append( Solid::OpticalDrive::staticMetaObject );
185
interfaces.append( Solid::StorageVolume::staticMetaObject );
186
interfaces.append( Solid::OpticalDisc::staticMetaObject );
187
interfaces.append( Solid::Video::staticMetaObject );
188
interfaces.append( Solid::SmartCardReader::staticMetaObject );
192
#include "SolidActionData.moc"