Skip to content

Commit

Permalink
KCM done. Various bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Radu Andries committed Oct 15, 2012
1 parent 108051c commit 84c27f5
Show file tree
Hide file tree
Showing 23 changed files with 344 additions and 208 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
**~
.kdev4
build
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -10,4 +10,3 @@ include_directories( ${KDE4_INCLUDES} ${KDE4WORKSPACE_INCLUDE_DIR} ${QT_INCLUDES
add_subdirectory(kded)
add_subdirectory(kcm)
add_subdirectory(applet)
add_subdirectory(i18n)
28 changes: 28 additions & 0 deletions common/dbusdefs.cpp
@@ -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;
}
24 changes: 24 additions & 0 deletions common/dbusdefs.h
@@ -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
5 changes: 3 additions & 2 deletions common/switchablegraphics.xml
Expand Up @@ -12,8 +12,9 @@
<arg name="name" type="s" direction="out" />
</method>
<method name="GetStatus">
<arg name="devicelist" type="a(issiiiiii)" direction="out">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="DeviceList"/>
<arg name="devicelist" type="a(issiiiiii)" direction="out" />
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="DeviceList" />
</method>
<method name="UpdateSettings" />
</interface>
</node>
1 change: 0 additions & 1 deletion i18n/CMakeLists.txt

This file was deleted.

77 changes: 0 additions & 77 deletions i18n/switchablegraphics.pot

This file was deleted.

20 changes: 20 additions & 0 deletions kcm/CMakeLists.txt
@@ -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}
)
117 changes: 117 additions & 0 deletions kcm/switchablegraphics.cpp
@@ -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>&nbsp;<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"


44 changes: 44 additions & 0 deletions kcm/switchablegraphics.h
@@ -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
20 changes: 20 additions & 0 deletions kcm/switchablegraphicsconfig.desktop
@@ -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
17 changes: 13 additions & 4 deletions kcm/config.ui → kcm/switchablegraphicsconfig.ui
Expand Up @@ -13,7 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QGroupBox" name="autoSwitch">
<property name="title">
Expand Down Expand Up @@ -86,10 +86,19 @@
</widget>
</item>
<item>
<widget class="QLabel" name="infoLabel">
<property name="text">
<string/>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Info</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="infoLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
Expand Down

0 comments on commit 84c27f5

Please sign in to comment.