Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Radu Andries
committed
Oct 15, 2012
1 parent
108051c
commit 84c27f5
Showing
23 changed files
with
344 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**~ | ||
.kdev4 | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
#include "dbusdefs.h" | ||
#include <QDBusMetaType> | ||
|
||
|
||
void init_dbus_metatype(){ | ||
qDBusRegisterMetaType< DeviceStruct >(); | ||
qDBusRegisterMetaType< DeviceList >(); | ||
} | ||
|
||
QDBusArgument &operator<<(QDBusArgument &argument, const DeviceStruct &d) | ||
{ | ||
|
||
argument.beginStructure(); | ||
argument << d.index << d.vendor << d.device << d.devtype << d.domain << d.bus << d.device << d.func << d.status; | ||
argument.endStructure(); | ||
|
||
|
||
return argument; | ||
} | ||
|
||
const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceStruct &d) | ||
{ | ||
argument.beginStructure(); | ||
argument >> d.index >> d.vendor >> d.device >> d.devtype >> d.domain >> d.bus >> d.device >> d.func >> d.status; | ||
argument.endStructure(); | ||
return argument; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef DBUSDEFS_H | ||
#define DBUSDEFS_H | ||
|
||
#include <QDBusArgument> | ||
|
||
struct Device{ | ||
int index; | ||
QString vendor; | ||
QString device; | ||
int devtype; | ||
int domain; | ||
int bus; | ||
int dev; | ||
int func; | ||
int status; | ||
}; | ||
typedef Device DeviceStruct; | ||
typedef QList< DeviceStruct > DeviceList; | ||
|
||
Q_DECLARE_METATYPE(DeviceStruct) | ||
Q_DECLARE_METATYPE(DeviceList) | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
set( KCM_SRCS switchablegraphics.cpp) | ||
|
||
set_property(SOURCE ../common/switchablegraphics.xml PROPERTY NO_NAMESPACE 1) | ||
set_property(SOURCE ../common/switchablegraphics.xml PROPERTY INCLUDE ../common/dbusdefs.h) | ||
QT4_ADD_DBUS_INTERFACE(KCM_DBUS ../common/switchablegraphics.xml SwitchableGraphicsIface) | ||
|
||
kde4_add_ui_files(KCM_SRCS switchablegraphicsconfig.ui) | ||
kde4_add_plugin(kcm_switchablegraphics ${KCM_SRCS} ${KCM_DBUS}) | ||
target_link_libraries(kcm_switchablegraphics | ||
${KDE4_KDEUI_LIBS} | ||
# Other necessary libraries go there | ||
) | ||
|
||
install(TARGETS kcm_switchablegraphics | ||
DESTINATION ${PLUGIN_INSTALL_DIR} | ||
) | ||
|
||
install(FILES switchablegraphicsconfig.desktop | ||
DESTINATION ${SERVICES_INSTALL_DIR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
<one line to give the program's name and a brief idea of what it does.> | ||
Copyright (C) 2012 Radu Andries <admiral0@tuxfamily.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 3 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, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include "switchablegraphics.h" | ||
|
||
#include <KPluginFactory> | ||
#include <KAboutData> | ||
#include <QDBusMetaType> | ||
#include "../common/dbusdefs.cpp" | ||
|
||
K_PLUGIN_FACTORY(SwitchableGraphicsFactory, registerPlugin<SwitchableGraphics>(); ) | ||
K_EXPORT_PLUGIN(SwitchableGraphicsFactory("kcm_switchablegraphics","kcm_switchablegraphics") ) | ||
|
||
SwitchableGraphics::SwitchableGraphics(QWidget* parent, const QVariantList& args): KCModule(SwitchableGraphicsFactory::componentData(), parent, args) | ||
{ | ||
init_dbus_metatype(); | ||
KAboutData *about = new KAboutData( | ||
"Switchable Graphics", 0, ki18n( "..." ), | ||
KDE_VERSION_STRING, KLocalizedString(), KAboutData::License_GPL_V3, | ||
ki18n( "Copyright 2012 Radu Andries" ) ); | ||
about->addAuthor( ki18n("Radu Andries") ); | ||
|
||
|
||
iface = new OrgAdmiral0SwitchablegraphicsInterface("org.admiral0.switchablegraphics","/org/admiral0/switchablegraphics",QDBusConnection::sessionBus()); | ||
setAboutData( about ); | ||
|
||
setButtons(Apply); | ||
|
||
config=new KConfig("switchablegraphicsrc"); | ||
setupUi(this); | ||
|
||
connectModifications(); | ||
} | ||
|
||
SwitchableGraphics::~SwitchableGraphics(){ | ||
delete config; | ||
iface->deleteLater(); | ||
} | ||
|
||
void SwitchableGraphics::connectModifications() | ||
{ | ||
connect(this->autoSwitch,SIGNAL(toggled(bool)),SLOT(changed())); | ||
connect(this->lowBatSwitchFlag,SIGNAL(toggled(bool)),SLOT(changed())); | ||
connect(this->sliderPerc,SIGNAL(valueChanged(int)),SLOT(changed())); | ||
connect(this->inputPerc,SIGNAL(valueChanged(int)),SLOT(changed())); | ||
connect(this->statusIconFlag,SIGNAL(toggled(bool)),SLOT(changed())); | ||
connect(this->notificationsFlag,SIGNAL(toggled(bool)),SLOT(changed())); | ||
} | ||
|
||
void SwitchableGraphics::load() | ||
{ | ||
this->autoSwitch->setChecked(config->group("General").readEntry<bool>("powerManagement",true)); | ||
this->lowBatSwitchFlag->setChecked(config->group("General").readEntry<bool>("lowBatteryManagement",true)); | ||
this->sliderPerc->setValue(config->group("General").readEntry<int>("lowBatteryPercentage",20)); | ||
this->inputPerc->setValue(config->group("General").readEntry<int>("lowBatteryPercentage",20)); | ||
this->statusIconFlag->setChecked(config->group("General").readEntry<bool>("displayNotifier",true)); | ||
this->notificationsFlag->setChecked(config->group("General").readEntry<bool>("displayNotifications",true)); | ||
|
||
QDBusPendingReply<DeviceList> devsDbus=iface->GetStatus(); | ||
devsDbus.waitForFinished(); | ||
QDBusPendingReply<QString> backendDbus=iface->Backend(); | ||
backendDbus.waitForFinished(); | ||
|
||
DeviceList devs=devsDbus.value(); | ||
QString backend=backendDbus.value(); | ||
QString istatus; | ||
|
||
istatus.append(i18n("<b>Backend:</b>")); | ||
istatus.append("<i>"); | ||
istatus.append(backend); | ||
istatus.append("</i><br>"); | ||
foreach(Device d,devs){ | ||
istatus.append("<b>"); | ||
istatus.append(d.vendor); | ||
istatus.append(" "); | ||
istatus.append(d.device); | ||
istatus.append(":</b> <i>"); | ||
istatus.append( (d.status==0) ? i18n("Off") : (d.status==1) ? i18n("On") : i18n("Powered") ); | ||
istatus.append("</i><br>"); | ||
} | ||
this->infoLabel->setText(istatus); | ||
|
||
} | ||
|
||
void SwitchableGraphics::save() | ||
{ | ||
KConfigGroup gen= config->group("General"); | ||
gen.writeEntry<bool>("powerManagement",this->autoSwitch->isChecked()); | ||
gen.writeEntry<bool>("lowBatteryManagement",this->lowBatSwitchFlag->isChecked()); | ||
gen.writeEntry<int>("lowBatteryPercentage",this->inputPerc->value()); | ||
gen.writeEntry<bool>("displayNotifier",this->statusIconFlag->isChecked()); | ||
gen.writeEntry<bool>("displayNotifications",this->notificationsFlag->isChecked()); | ||
config->sync(); | ||
iface->UpdateSettings(); | ||
} | ||
|
||
|
||
|
||
#include "switchablegraphics.moc" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
<one line to give the program's name and a brief idea of what it does.> | ||
Copyright (C) 2012 Radu Andries <admiral0@tuxfamily.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 3 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, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#ifndef SWITCHABLEGRAPHICS_H | ||
#define SWITCHABLEGRAPHICS_H | ||
|
||
#include <KCModule> | ||
#include "ui_switchablegraphicsconfig.h" | ||
#include "SwitchableGraphicsIface.h" | ||
|
||
class SwitchableGraphics : public KCModule, private Ui_switchablegraphics | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
SwitchableGraphics(QWidget* parent = 0, const QVariantList& args = QVariantList()); | ||
virtual ~SwitchableGraphics(); | ||
|
||
public slots: | ||
void load(); | ||
void save(); | ||
private: | ||
void connectModifications(); | ||
KConfig *config; | ||
OrgAdmiral0SwitchablegraphicsInterface *iface; | ||
}; | ||
|
||
#endif // SWITCHABLEGRAPHICS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[Desktop Entry] | ||
Exec=kcmshell4 kcm_switchablegraphics | ||
Icon=cpu | ||
Type=Service | ||
X-KDE-ServiceTypes=KCModule | ||
|
||
X-KDE-Library=kcm_switchablegraphics | ||
X-KDE-ParentApp=kcontrol | ||
|
||
X-KDE-System-Settings-Parent-Category=power-management | ||
X-KDE-Weight=150 | ||
|
||
Name=Switchable Graphics | ||
Name[it]=GPU Commutabili | ||
|
||
|
||
Comment=Configure Switchable Graphics | ||
Comment[it]=Gestisci le schede grafiche commutabili | ||
|
||
X-KDE-Keywords=system,power,power management,energy,laptop,battery,suspension,AC,suspend,hibernate,brightness,performance,lid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.