1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
/***************************************************************************
* 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 *
***************************************************************************/
#include "SolidActionData.h"
#include <QList>
#include <QMetaProperty>
#include <KGlobal>
#include <kdesktopfileactions.h>
#include <KStandardDirs>
#include <KStringHandler>
#include <KDesktopFile>
#include <KConfigGroup>
#include <Solid/AcAdapter>
#include <Solid/AudioInterface>
#include <Solid/Battery>
#include <Solid/Block>
#include <Solid/Button>
#include <Solid/Camera>
#include <Solid/DvbInterface>
#include <Solid/GenericInterface>
#include <Solid/NetworkInterface>
#include <Solid/PortableMediaPlayer>
#include <Solid/Processor>
#include <Solid/StorageAccess>
#include <Solid/StorageDrive>
#include <Solid/OpticalDrive>
#include <Solid/StorageVolume>
#include <Solid/OpticalDisc>
#include <solid/video.h>
#include <solid/serialinterface.h>
#include <solid/smartcardreader.h>
static SolidActionData * actData = 0;
SolidActionData::SolidActionData(bool includeFiles)
{
QStringList allPossibleDevices;
int propertyOffset = Solid::DeviceInterface::staticMetaObject.propertyOffset();
QList<QMetaObject> interfaceList = fillInterfaceList();
foreach( const QMetaObject &interface, interfaceList ) {
QString ifaceName = interface.className();
ifaceName.remove(0, ifaceName.lastIndexOf(':') + 1);
Solid::DeviceInterface::Type ifaceDev = Solid::DeviceInterface::stringToType( ifaceName );
QString cleanName = Solid::DeviceInterface::typeDescription( ifaceDev );
types.insert( ifaceDev, cleanName );
QMap<QString, QString> deviceValues;
for( int doneProps = propertyOffset; interface.propertyCount() > doneProps; doneProps = doneProps + 1 ) {
QMetaProperty ifaceProp = interface.property(doneProps);
deviceValues.insert( ifaceProp.name(), generateUserString(ifaceProp.name()) );
}
values.insert( ifaceDev, deviceValues );
}
if( includeFiles ) {
// Fill the lists of possible device types / device values
allPossibleDevices = KGlobal::dirs()->findAllResources("data", "solid/devices/");
// List all the known device actions, then add their name and all values to the appropriate lists
foreach( const QString &desktop, allPossibleDevices ) {
KDesktopFile deviceFile(desktop);
KConfigGroup deviceType = deviceFile.desktopGroup(); // Retrieve the configuration group where the user friendly name is
QString ifaceName = deviceType.readEntry("X-KDE-Solid-Actions-Type");
Solid::DeviceInterface::Type ifaceDev = Solid::DeviceInterface::stringToType( ifaceName );
QString cleanName = Solid::DeviceInterface::typeDescription( ifaceDev );
types.insert( ifaceDev, cleanName ); // Read the user friendly name
QMap<QString,QString> deviceValues = values.value( ifaceDev );
foreach( const QString &text, deviceFile.readActions() ) { // We want every single action
KConfigGroup actionType = deviceFile.actionGroup( text );
deviceValues.insert( text, actionType.readEntry("Name") ); // Add to the type - actions map
}
values.insert( ifaceDev, deviceValues );
}
}
}
QList<QString> SolidActionData::propertyList( Solid::DeviceInterface::Type devInterface )
{
return values.value( devInterface ).values();
}
QList<QString> SolidActionData::propertyInternalList( Solid::DeviceInterface::Type devInterface )
{
return values.value( devInterface ).keys();
}
QString SolidActionData::propertyInternal( Solid::DeviceInterface::Type devInterface, QString property )
{
return values.value( devInterface ).key( property );
}
QString SolidActionData::propertyName( Solid::DeviceInterface::Type devInterface, QString property )
{
return values.value( devInterface ).value( property );
}
int SolidActionData::propertyPosition( Solid::DeviceInterface::Type devInterface, QString property )
{
return values.value( devInterface ).keys().indexOf( property );
}
QList<QString> SolidActionData::interfaceList()
{
return types.values();
}
QList<Solid::DeviceInterface::Type> SolidActionData::interfaceTypeList()
{
return types.keys();
}
Solid::DeviceInterface::Type SolidActionData::interfaceFromName( const QString& name )
{
return types.key( name );
}
QString SolidActionData::nameFromInterface( Solid::DeviceInterface::Type devInterface )
{
return types.value( devInterface );
}
int SolidActionData::interfacePosition( Solid::DeviceInterface::Type devInterface )
{
return types.keys().indexOf( devInterface );
}
QString SolidActionData::generateUserString( QString className )
{
QString finalString;
QRegExp camelCase("([A-Z])"); // Create the split regexp
finalString = className.remove(0, className.lastIndexOf(':') + 1); // Remove any Class information
finalString = finalString.replace( camelCase, " \\1" ); // Use Camel Casing to add spaces
finalString = KStringHandler::capwords( finalString ); // Captialise everything
return finalString.trimmed();
}
SolidActionData * SolidActionData::instance()
{
if( actData == 0 ) {
actData = new SolidActionData( true );
}
return actData;
}
QList<QMetaObject> SolidActionData::fillInterfaceList()
{
QList<QMetaObject> interfaces;
interfaces.append( Solid::AcAdapter::staticMetaObject );
interfaces.append( Solid::AudioInterface::staticMetaObject );
interfaces.append( Solid::Battery::staticMetaObject );
interfaces.append( Solid::Block::staticMetaObject );
interfaces.append( Solid::Button::staticMetaObject );
interfaces.append( Solid::Camera::staticMetaObject );
interfaces.append( Solid::DvbInterface::staticMetaObject );
interfaces.append( Solid::NetworkInterface::staticMetaObject );
interfaces.append( Solid::PortableMediaPlayer::staticMetaObject );
interfaces.append( Solid::Processor::staticMetaObject );
interfaces.append( Solid::SerialInterface::staticMetaObject );
interfaces.append( Solid::StorageAccess::staticMetaObject );
interfaces.append( Solid::StorageDrive::staticMetaObject );
interfaces.append( Solid::OpticalDrive::staticMetaObject );
interfaces.append( Solid::StorageVolume::staticMetaObject );
interfaces.append( Solid::OpticalDisc::staticMetaObject );
interfaces.append( Solid::Video::staticMetaObject );
interfaces.append( Solid::SmartCardReader::staticMetaObject );
return interfaces;
}
#include "SolidActionData.moc"
|