• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

SolidModules

ActionItem.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2009 by Ben Cooksley <ben@eclipse.endoftheinternet.org> *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU General Public License     *
00015  *   along with this program; if not, write to the                         *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
00018  ***************************************************************************/
00019 
00020 #include "ActionItem.h"
00021 #include "SolidActionData.h"
00022 
00023 #include <QString>
00024 
00025 #include <kdesktopfileactions.h>
00026 #include <KDesktopFile>
00027 #include <KConfigGroup>
00028 
00029 #include <Solid/DeviceInterface>
00030 
00031 ActionItem::ActionItem(QString pathToDesktop, QString action, QObject *parent)
00032 {
00033     Q_UNUSED(parent);
00034 
00035     desktopMasterPath = pathToDesktop;
00036     actionName = action;
00037     // Create the desktop file
00038     desktopFileMaster = new KDesktopFile(desktopMasterPath);
00039     desktopWritePath = desktopFileMaster->locateLocal(desktopMasterPath);
00040     desktopFileWrite = new KDesktopFile(desktopWritePath);
00041     // Now we can fill the action groups list
00042     configGroups.append(desktopFileMaster->desktopGroup());
00043     actionGroups.insertMulti(ActionItem::GroupDesktop, &configGroups.last());
00044     configGroups.append(desktopFileMaster->actionGroup(actionName));
00045     actionGroups.insertMulti(ActionItem::GroupAction, &configGroups.last());
00046     configGroups.append(desktopFileWrite->desktopGroup());
00047     actionGroups.insertMulti(ActionItem::GroupDesktop, &configGroups.last());
00048     configGroups.append(desktopFileWrite->actionGroup(actionName));
00049     actionGroups.insertMulti(ActionItem::GroupAction, &configGroups.last());
00050 
00051     QString predicateString = readKey(ActionItem::GroupDesktop, "X-KDE-Solid-Predicate", "");
00052     predicateItem = Solid::Predicate::fromString( predicateString );
00053 }
00054 
00055 ActionItem::~ActionItem()
00056 {
00057     delete desktopFileWrite;
00058     delete desktopFileMaster;
00059 }
00060 
00062 
00063 bool ActionItem::isUserSupplied()
00064 {
00065     return hasKey(ActionItem::GroupDesktop, "X-KDE-Action-Custom");
00066 }
00067 
00068 QString ActionItem::icon()
00069 {
00070     return readKey(ActionItem::GroupAction, "Icon", "");
00071 }
00072 
00073 QString ActionItem::exec()
00074 {
00075     return readKey(ActionItem::GroupAction, "Exec", "");
00076 }
00077 
00078 QString ActionItem::name()
00079 {
00080     return readKey(ActionItem::GroupAction, "Name", "");
00081 }
00082 
00083 Solid::Predicate ActionItem::predicate()
00084 {
00085     return predicateItem;
00086 }
00087 
00088 QString ActionItem::involvedTypes()
00089 {
00090     SolidActionData * actData = SolidActionData::instance();
00091     QSet<Solid::DeviceInterface::Type> devTypeList = predicateItem.usedTypes();
00092     QStringList deviceTypes;
00093     foreach( Solid::DeviceInterface::Type devType, devTypeList ) {
00094         deviceTypes << actData->nameFromInterface( devType );
00095     }
00096 
00097     return deviceTypes.join(", ");
00098 }
00099 
00100 void ActionItem::setIcon(QString nameOfIcon)
00101 {
00102     setKey(ActionItem::GroupAction, "Icon", nameOfIcon);
00103 }
00104 
00105 void ActionItem::setName(QString nameOfAction)
00106 {
00107     setKey(ActionItem::GroupAction, "Name", nameOfAction);
00108 }
00109 
00110 void ActionItem::setExec(QString execUrl)
00111 {
00112     setKey(ActionItem::GroupAction, "Exec", execUrl);
00113 }
00114 
00115 void ActionItem::setPredicate( QString newPredicate )
00116 {
00117     setKey(ActionItem::GroupDesktop, "X-KDE-Solid-Predicate", newPredicate);
00118     predicateItem = Solid::Predicate::fromString( newPredicate );
00119 }
00120 
00122 
00123 QString ActionItem::readKey(GroupType keyGroup, QString keyName, QString defaultValue)
00124 {
00125     return configItem(ActionItem::DesktopRead, keyGroup, keyName)->readEntry(keyName, defaultValue);
00126 }
00127 
00128 void ActionItem::setKey(GroupType keyGroup, QString keyName, QString keyContents)
00129 {
00130     configItem(ActionItem::DesktopWrite, keyGroup)->writeEntry(keyName, keyContents);
00131 }
00132 
00133 bool ActionItem::hasKey(GroupType keyGroup, QString keyName)
00134 {
00135     return configItem(ActionItem::DesktopRead, keyGroup, keyName)->hasKey(keyName);
00136 }
00137 
00138 KConfigGroup * ActionItem::configItem(DesktopAction actionType, GroupType keyGroup, QString keyName)
00139 {
00140     int countAccess = 0;
00141 
00142     if (actionType == ActionItem::DesktopRead) {
00143         foreach(KConfigGroup * possibleGroup, actionGroups.values(keyGroup)) {
00144             if (possibleGroup->hasKey(keyName)) {
00145                 return possibleGroup;
00146                 break;
00147             }
00148         }
00149     } else if (actionType == ActionItem::DesktopWrite) {
00150         if (isUserSupplied()) {
00151             countAccess = 1;
00152         }
00153         return actionGroups.values(keyGroup)[countAccess];
00154     }
00155     return actionGroups.values(keyGroup)[0]; // Implement a backstop so a valid value is always returned
00156 }
00157 
00158 #include "ActionItem.moc"

SolidModules

Skip menu "SolidModules"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KStyles
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •     Animators
  •     Applets
  •     Engines
  • Solid Modules
  • System Settings
  •   SystemSettingsView
Generated for API Reference by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal