1 /***************************************************************************
2 * Copyright (C) 2008 by Dario Freddi <drf@kdemod.ath.cx> *
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 ***************************************************************************/
22 #include "PowerDevilSettings.h"
24 #include <solid/control/powermanager.h>
25 #include <solid/device.h>
26 #include <solid/deviceinterface.h>
27 #include <solid/processor.h>
29 #include <QtDBus/QDBusMessage>
30 #include <QtDBus/QDBusReply>
31 #include <QtDBus/QDBusConnection>
33 #include <KStandardDirs>
36 #include <config-workspace.h>
38 #include <KConfigGroup>
41 #include <QFormLayout>
43 #include <KFileDialog>
44 #include <KMessageBox>
45 #include <KIconButton>
48 EditPage::EditPage(QWidget
*parent
)
50 m_profileEdited(false)
54 m_profilesConfig
= KSharedConfig::openConfig("powerdevilprofilesrc", KConfig::SimpleConfig
);
56 if (m_profilesConfig
->groupList().isEmpty()) {
57 // Let's add some basic profiles, huh?
59 KConfigGroup
*performance
= new KConfigGroup(m_profilesConfig
, "Performance");
61 performance
->writeEntry("brightness", 100);
62 performance
->writeEntry("cpuPolicy", (int) Solid::Control::PowerManager::Performance
);
63 performance
->writeEntry("idleAction", 0);
64 performance
->writeEntry("idleTime", 50);
65 performance
->writeEntry("lidAction", 0);
66 performance
->writeEntry("turnOffIdle", false);
67 performance
->writeEntry("turnOffIdleTime", 120);
71 kDebug() << performance
->readEntry("brightness");
83 void EditPage::fillUi()
85 m_toolBar
= new KToolBar(this);
86 listLayout
->addWidget(m_toolBar
);
88 m_toolBar
->addAction(actionNewProfile
);
89 m_toolBar
->addAction(actionDeleteProfile
);
90 m_toolBar
->addSeparator();
91 m_toolBar
->addAction(actionImportProfiles
);
92 m_toolBar
->addAction(actionExportProfiles
);
93 m_toolBar
->setToolButtonStyle(Qt::ToolButtonIconOnly
);
95 actionNewProfile
->setIcon(KIcon("document-new"));
96 actionDeleteProfile
->setIcon(KIcon("edit-delete-page"));
97 actionImportProfiles
->setIcon(KIcon("document-import"));
98 actionExportProfiles
->setIcon(KIcon("document-export"));
100 idleCombo
->addItem(KIcon("dialog-cancel"), i18n("Do nothing"), (int) None
);
101 idleCombo
->addItem(KIcon("system-shutdown"), i18n("Shutdown"), (int) Shutdown
);
102 idleCombo
->addItem(KIcon("system-lock-screen"), i18n("Lock Screen"), (int) Lock
);
103 laptopClosedCombo
->addItem(KIcon("dialog-cancel"), i18n("Do nothing"), (int) None
);
104 laptopClosedCombo
->addItem(KIcon("system-shutdown"), i18n("Shutdown"), (int) Shutdown
);
105 laptopClosedCombo
->addItem(KIcon("system-lock-screen"), i18n("Lock Screen"), (int) Lock
);
106 sleepButtonCombo
->addItem(KIcon("dialog-cancel"), i18n("Do nothing"), (int) None
);
107 sleepButtonCombo
->addItem(KIcon("system-shutdown"), i18n("Shutdown"), (int) Shutdown
);
108 sleepButtonCombo
->addItem(KIcon("system-lock-screen"), i18n("Lock Screen"), (int) Lock
);
109 sleepButtonCombo
->addItem(KIcon("system-log-out"), i18n("Prompt Log out dialog"), (int) ShutdownDialog
);
110 powerButtonCombo
->addItem(KIcon("dialog-cancel"), i18n("Do nothing"), (int) None
);
111 powerButtonCombo
->addItem(KIcon("system-shutdown"), i18n("Shutdown"), (int) Shutdown
);
112 powerButtonCombo
->addItem(KIcon("system-lock-screen"), i18n("Lock Screen"), (int) Lock
);
113 powerButtonCombo
->addItem(KIcon("system-log-out"), i18n("Prompt Log out dialog"), (int) ShutdownDialog
);
115 Solid::Control::PowerManager::SuspendMethods methods
= Solid::Control::PowerManager::supportedSuspendMethods();
117 Solid::Control::PowerManager::BrightnessControlsList bControls
=
118 Solid::Control::PowerManager::brightnessControlsAvailable();
120 brightnessSlider
->setEnabled(bControls
.values().contains(Solid::Control::PowerManager::Screen
));
122 if (methods
& Solid::Control::PowerManager::ToDisk
) {
123 idleCombo
->addItem(KIcon("system-suspend-hibernate"), i18n("Suspend to Disk"), (int) S2Disk
);
124 laptopClosedCombo
->addItem(KIcon("system-suspend-hibernate"), i18n("Suspend to Disk"), (int) S2Disk
);
125 sleepButtonCombo
->addItem(KIcon("system-suspend-hibernate"), i18n("Suspend to Disk"), (int) S2Disk
);
126 powerButtonCombo
->addItem(KIcon("system-suspend-hibernate"), i18n("Suspend to Disk"), (int) S2Disk
);
129 if (methods
& Solid::Control::PowerManager::ToRam
) {
130 idleCombo
->addItem(KIcon("system-suspend"), i18n("Suspend to Ram"), (int) S2Ram
);
131 laptopClosedCombo
->addItem(KIcon("system-suspend"), i18n("Suspend to Ram"), (int) S2Ram
);
132 sleepButtonCombo
->addItem(KIcon("system-suspend"), i18n("Suspend to Ram"), (int) S2Ram
);
133 powerButtonCombo
->addItem(KIcon("system-suspend"), i18n("Suspend to Ram"), (int) S2Ram
);
136 if (methods
& Solid::Control::PowerManager::Standby
) {
137 idleCombo
->addItem(KIcon("system-suspend"), i18n("Standby"), (int) Standby
);
138 laptopClosedCombo
->addItem(KIcon("system-suspend"), i18n("Standby"), (int) Standby
);
139 sleepButtonCombo
->addItem(KIcon("system-suspend"), i18n("Standby"), (int) Standby
);
140 powerButtonCombo
->addItem(KIcon("system-suspend"), i18n("Standby"), (int) Standby
);
143 Solid::Control::PowerManager::CpuFreqPolicies policies
= Solid::Control::PowerManager::supportedCpuFreqPolicies();
145 if (policies
& Solid::Control::PowerManager::Performance
) {
146 freqCombo
->addItem(KIcon("preferences-system-performance"), i18n("Performance"),
147 (int) Solid::Control::PowerManager::Performance
);
150 if (policies
& Solid::Control::PowerManager::OnDemand
) {
151 freqCombo
->addItem(KIcon("system-switch-user"),
152 i18n("Dynamic (ondemand)"), (int) Solid::Control::PowerManager::OnDemand
);
155 if (policies
& Solid::Control::PowerManager::Conservative
) {
156 freqCombo
->addItem(KIcon("user-invisible"), i18n("Dynamic (conservative)"),
157 (int) Solid::Control::PowerManager::Conservative
);
160 if (policies
& Solid::Control::PowerManager::Powersave
) {
161 freqCombo
->addItem(KIcon("preferences-system-power-management"), i18n("Powersave"),
162 (int) Solid::Control::PowerManager::Powersave
);
165 if (policies
& Solid::Control::PowerManager::Userspace
) {
166 freqCombo
->addItem(KIcon("kuser"), i18n("Userspace"),
167 (int) Solid::Control::PowerManager::Userspace
);
170 schemeCombo
->addItems(Solid::Control::PowerManager::supportedSchemes());
172 foreach(const Solid::Device
&device
, Solid::Device::listFromType(Solid::DeviceInterface::Processor
, QString())) {
173 Solid::Device d
= device
;
174 Solid::Processor
*processor
= qobject_cast
<Solid::Processor
*> (d
.asDeviceInterface(Solid::DeviceInterface::Processor
));
176 QString text
= i18n("CPU <numid>%1</numid>", processor
->number());
178 QCheckBox
*checkBox
= new QCheckBox(this);
180 checkBox
->setText(text
);
181 checkBox
->setToolTip(i18n("Disable CPU <numid>%1</numid>", processor
->number()));
182 checkBox
->setWhatsThis(i18n("If this box is checked, the CPU <numid>%1</numid> "
183 "will be disabled", processor
->number()));
185 checkBox
->setEnabled(Solid::Control::PowerManager::canDisableCpu(processor
->number()));
187 connect(checkBox
, SIGNAL(stateChanged(int)), SLOT(emitChanged()));
189 CPUListLayout
->addWidget(checkBox
);
192 reloadAvailableProfiles();
194 toolBox
->setItemIcon(0, KIcon("preferences-system-session-services"));
195 toolBox
->setItemIcon(1, KIcon("video-display"));
196 toolBox
->setItemIcon(2, KIcon("cpu"));
198 DPMSLabel
->setUrl("http://www.energystar.gov");
199 DPMSLabel
->setPixmap(QPixmap(KStandardDirs::locate("data", "kcontrol/pics/energybig.png")));
200 DPMSLabel
->setTipText(i18n("Learn more about the Energy Star program"));
201 DPMSLabel
->setUseTips(true);
202 connect(DPMSLabel
, SIGNAL(leftClickedUrl(const QString
&)), SLOT(openUrl(const QString
&)));
205 DPMSEnable
->setEnabled(false);
206 DPMSSuspend
->setEnabled(false);
207 DPMSStandby
->setEnabled(false);
208 DPMSPowerOff
->setEnabled(false);
211 // modified fields...
213 connect(brightnessSlider
, SIGNAL(valueChanged(int)), SLOT(setProfileChanged()));
214 connect(disableCompositing
, SIGNAL(stateChanged(int)), SLOT(setProfileChanged()));
215 connect(dimDisplayOnIdle
, SIGNAL(stateChanged(int)), SLOT(setProfileChanged()));
216 connect(dimOnIdleTime
, SIGNAL(valueChanged(int)), SLOT(setProfileChanged()));
217 connect(idleTime
, SIGNAL(valueChanged(int)), SLOT(setProfileChanged()));
218 connect(idleCombo
, SIGNAL(currentIndexChanged(int)), SLOT(setProfileChanged()));
219 connect(freqCombo
, SIGNAL(currentIndexChanged(int)), SLOT(setProfileChanged()));
220 connect(laptopClosedCombo
, SIGNAL(currentIndexChanged(int)), SLOT(setProfileChanged()));
221 connect(sleepButtonCombo
, SIGNAL(currentIndexChanged(int)), SLOT(setProfileChanged()));
222 connect(powerButtonCombo
, SIGNAL(currentIndexChanged(int)), SLOT(setProfileChanged()));
224 connect(dimDisplayOnIdle
, SIGNAL(stateChanged(int)), SLOT(enableBoxes()));
226 connect(schemeCombo
, SIGNAL(currentIndexChanged(int)), SLOT(setProfileChanged()));
227 connect(scriptRequester
, SIGNAL(textChanged(const QString
&)), SLOT(setProfileChanged()));
230 connect(DPMSEnable
, SIGNAL(stateChanged(int)), SLOT(enableBoxes()));
231 connect(DPMSEnable
, SIGNAL(stateChanged(int)), SLOT(setProfileChanged()));
232 connect(DPMSSuspendTime
, SIGNAL(valueChanged(int)), SLOT(setProfileChanged()));
233 connect(DPMSStandbyTime
, SIGNAL(valueChanged(int)), SLOT(setProfileChanged()));
234 connect(DPMSPowerOffTime
, SIGNAL(valueChanged(int)), SLOT(setProfileChanged()));
235 connect(DPMSSuspendEnabled
, SIGNAL(stateChanged(int)), SLOT(setProfileChanged()));
236 connect(DPMSStandbyEnabled
, SIGNAL(stateChanged(int)), SLOT(setProfileChanged()));
237 connect(DPMSPowerOffEnabled
, SIGNAL(stateChanged(int)), SLOT(setProfileChanged()));
239 connect(DPMSSuspendEnabled
, SIGNAL(stateChanged(int)), SLOT(enableBoxes()));
240 connect(DPMSStandbyEnabled
, SIGNAL(stateChanged(int)), SLOT(enableBoxes()));
241 connect(DPMSPowerOffEnabled
, SIGNAL(stateChanged(int)), SLOT(enableBoxes()));
244 connect(profilesList
, SIGNAL(currentItemChanged(QListWidgetItem
*, QListWidgetItem
*)),
245 SLOT(switchProfile(QListWidgetItem
*, QListWidgetItem
*)));
247 connect(actionDeleteProfile
, SIGNAL(triggered()), SLOT(deleteCurrentProfile()));
248 connect(actionNewProfile
, SIGNAL(triggered()), SLOT(createProfile()));
249 //connect(editProfileButton, SIGNAL(clicked()), SLOT(editProfile()));
250 connect(actionImportProfiles
, SIGNAL(triggered()), SLOT(importProfiles()));
251 connect(actionExportProfiles
, SIGNAL(triggered()), SLOT(exportProfiles()));
254 void EditPage::load()
261 void EditPage::save()
266 void EditPage::emitChanged()
271 void EditPage::enableBoxes()
274 if (DPMSEnable
->isChecked()) {
275 DPMSSuspendEnabled
->setEnabled(true);
276 DPMSStandbyEnabled
->setEnabled(true);
277 DPMSPowerOffEnabled
->setEnabled(true);
278 DPMSSuspendTime
->setEnabled(DPMSSuspendEnabled
->isChecked());
279 DPMSStandbyTime
->setEnabled(DPMSStandbyEnabled
->isChecked());
280 DPMSPowerOffTime
->setEnabled(DPMSPowerOffEnabled
->isChecked());
282 DPMSSuspendEnabled
->setEnabled(false);
283 DPMSStandbyEnabled
->setEnabled(false);
284 DPMSPowerOffEnabled
->setEnabled(false);
285 DPMSSuspendTime
->setEnabled(false);
286 DPMSStandbyTime
->setEnabled(false);
287 DPMSPowerOffTime
->setEnabled(false);
291 dimOnIdleTime
->setEnabled(dimDisplayOnIdle
->isChecked());
294 void EditPage::loadProfile()
296 kDebug() << "Loading a profile";
298 if (!profilesList
->currentItem())
301 kDebug() << profilesList
->currentItem()->text();
303 KConfigGroup
*group
= new KConfigGroup(m_profilesConfig
, profilesList
->currentItem()->text());
305 if (!group
->isValid()) {
309 kDebug() << "Ok, KConfigGroup ready";
311 kDebug() << group
->readEntry("brightness");
313 brightnessSlider
->setValue(group
->readEntry("brightness").toInt());
314 disableCompositing
->setChecked(group
->readEntry("disableCompositing", false));
315 dimDisplayOnIdle
->setChecked(group
->readEntry("dimOnIdle", false));
316 dimOnIdleTime
->setValue(group
->readEntry("dimOnIdleTime").toInt());
317 idleTime
->setValue(group
->readEntry("idleTime").toInt());
318 idleCombo
->setCurrentIndex(idleCombo
->findData(group
->readEntry("idleAction").toInt()));
319 freqCombo
->setCurrentIndex(freqCombo
->findData(group
->readEntry("cpuPolicy").toInt()));
320 schemeCombo
->setCurrentIndex(schemeCombo
->findText(group
->readEntry("scheme")));
321 scriptRequester
->setPath(group
->readEntry("scriptpath"));
323 laptopClosedCombo
->setCurrentIndex(laptopClosedCombo
->findData(group
->readEntry("lidAction").toInt()));
324 sleepButtonCombo
->setCurrentIndex(sleepButtonCombo
->findData(group
->readEntry("sleepButtonAction").toInt()));
325 powerButtonCombo
->setCurrentIndex(powerButtonCombo
->findData(group
->readEntry("powerButtonAction").toInt()));
328 DPMSEnable
->setChecked(group
->readEntry("DPMSEnabled", false));
329 DPMSStandbyTime
->setValue(group
->readEntry("DPMSStandby", 10));
330 DPMSSuspendTime
->setValue(group
->readEntry("DPMSSuspend", 30));
331 DPMSPowerOffTime
->setValue(group
->readEntry("DPMSPowerOff", 60));
332 DPMSStandbyEnabled
->setChecked(group
->readEntry("DPMSStandbyEnabled", false));
333 DPMSSuspendEnabled
->setChecked(group
->readEntry("DPMSSuspendEnabled", false));
334 DPMSPowerOffEnabled
->setChecked(group
->readEntry("DPMSPowerOffEnabled", false));
337 QVariant var
= group
->readEntry("disabledCPUs", QVariant());
338 QList
<QVariant
> list
= var
.toList();
340 foreach(const QVariant
&ent
, list
) {
341 QCheckBox
*box
= qobject_cast
<QCheckBox
*> (CPUListLayout
->itemAt(ent
.toInt())->widget());
346 box
->setChecked(true);
351 m_profileEdited
= false;
355 void EditPage::saveProfile(const QString
&p
)
357 if (!profilesList
->currentItem() && p
.isEmpty()) {
364 profile
= profilesList
->currentItem()->text();
369 KConfigGroup
*group
= new KConfigGroup(m_profilesConfig
, profile
);
371 if (!group
->isValid() || !group
->entryMap().size()) {
376 group
->writeEntry("brightness", brightnessSlider
->value());
377 group
->writeEntry("cpuPolicy", freqCombo
->itemData(freqCombo
->currentIndex()).toInt());
378 group
->writeEntry("dimOnIdle", dimDisplayOnIdle
->isChecked());
379 group
->writeEntry("dimOnIdleTime", dimOnIdleTime
->value());
380 group
->writeEntry("idleAction", idleCombo
->itemData(idleCombo
->currentIndex()).toInt());
381 group
->writeEntry("idleTime", idleTime
->value());
382 group
->writeEntry("lidAction", laptopClosedCombo
->itemData(laptopClosedCombo
->currentIndex()).toInt());
383 group
->writeEntry("sleepButtonAction", sleepButtonCombo
->itemData(sleepButtonCombo
->currentIndex()).toInt());
384 group
->writeEntry("powerButtonAction", powerButtonCombo
->itemData(powerButtonCombo
->currentIndex()).toInt());
385 group
->writeEntry("scheme", schemeCombo
->currentText());
386 group
->writeEntry("scriptpath", scriptRequester
->url().path());
387 group
->writeEntry("disableCompositing", disableCompositing
->isChecked());
390 group
->writeEntry("DPMSEnabled", DPMSEnable
->isChecked());
391 group
->writeEntry("DPMSStandby", DPMSStandbyTime
->value());
392 group
->writeEntry("DPMSSuspend", DPMSSuspendTime
->value());
393 group
->writeEntry("DPMSPowerOff", DPMSPowerOffTime
->value());
394 group
->writeEntry("DPMSStandbyEnabled", DPMSStandbyEnabled
->isChecked());
395 group
->writeEntry("DPMSSuspendEnabled", DPMSSuspendEnabled
->isChecked());
396 group
->writeEntry("DPMSPowerOffEnabled", DPMSPowerOffEnabled
->isChecked());
401 for (int i
= 0;i
< CPUListLayout
->count();++i
) {
402 QCheckBox
*box
= qobject_cast
<QCheckBox
*> (CPUListLayout
->itemAt(i
)->widget());
407 if (box
->isChecked())
411 group
->writeEntry("disabledCPUs", list
);
417 m_profileEdited
= false;
420 emit
profilesChanged();
423 void EditPage::reloadAvailableProfiles()
425 profilesList
->clear();
427 m_profilesConfig
->reparseConfiguration();
429 if (m_profilesConfig
->groupList().isEmpty()) {
430 kDebug() << "No available profiles!";
434 foreach(const QString
&ent
, m_profilesConfig
->groupList()) {
435 KConfigGroup
*group
= new KConfigGroup(m_profilesConfig
, ent
);
436 QListWidgetItem
*itm
= new QListWidgetItem(KIcon(group
->readEntry("iconname")),
438 profilesList
->addItem(itm
);
442 profilesList
->setCurrentRow(0);
445 void EditPage::deleteCurrentProfile()
447 if (!profilesList
->currentItem() || profilesList
->currentItem()->text().isEmpty())
450 m_profilesConfig
->deleteGroup(profilesList
->currentItem()->text());
452 m_profilesConfig
->sync();
454 reloadAvailableProfiles();
456 emit
profilesChanged();
459 void EditPage::createProfile(const QString
&name
, const QString
&icon
)
463 KConfigGroup
*group
= new KConfigGroup(m_profilesConfig
, name
);
465 group
->writeEntry("brightness", 80);
466 group
->writeEntry("cpuPolicy", (int) Solid::Control::PowerManager::Powersave
);
467 group
->writeEntry("idleAction", 0);
468 group
->writeEntry("idleTime", 50);
469 group
->writeEntry("lidAction", 0);
470 group
->writeEntry("turnOffIdle", false);
471 group
->writeEntry("turnOffIdleTime", 50);
472 group
->writeEntry("iconname", icon
);
478 reloadAvailableProfiles();
480 emit
profilesChanged();
483 void EditPage::createProfile()
485 KDialog
*dialog
= new KDialog(this);
486 QWidget
*wg
= new QWidget();
487 KLineEdit
*ed
= new KLineEdit(wg
);
488 QLabel
*lb
= new QLabel(wg
);
489 QFormLayout
*lay
= new QFormLayout();
490 KIconButton
*ibt
= new KIconButton(wg
);
492 ibt
->setIconSize(KIconLoader::SizeSmall
);
494 lb
->setText(i18n("Please enter a name for the new profile"));
496 lb
->setToolTip(i18n("The name for the new profile"));
497 lb
->setWhatsThis(i18n("Enter here the name for the profile you are creating"));
499 ed
->setToolTip(i18n("The name for the new profile"));
500 ed
->setWhatsThis(i18n("Enter here the name for the profile you are creating"));
503 lay
->addRow(ibt
, ed
);
507 dialog
->setMainWidget(wg
);
510 if (dialog
->exec() == KDialog::Accepted
) {
511 createProfile(ed
->text(), ibt
->icon());
516 void EditPage::editProfile(const QString
&prevname
, const QString
&icon
)
518 if (prevname
.isEmpty())
521 KConfigGroup
*group
= new KConfigGroup(m_profilesConfig
, prevname
);
523 group
->writeEntry("iconname", icon
);
529 reloadAvailableProfiles();
531 emit
profilesChanged();
534 void EditPage::editProfile()
536 if (!profilesList
->currentItem())
539 KDialog
*dialog
= new KDialog(this);
540 QWidget
*wg
= new QWidget();
541 KLineEdit
*ed
= new KLineEdit(wg
);
542 QLabel
*lb
= new QLabel(wg
);
543 QFormLayout
*lay
= new QFormLayout();
544 KIconButton
*ibt
= new KIconButton(wg
);
546 ibt
->setIconSize(KIconLoader::SizeSmall
);
548 lb
->setText(i18n("Please enter a name for this profile"));
550 lb
->setToolTip(i18n("The name for the new profile"));
551 lb
->setWhatsThis(i18n("Enter here the name for the profile you are creating"));
553 ed
->setToolTip(i18n("The name for the new profile"));
554 ed
->setWhatsThis(i18n("Enter here the name for the profile you are creating"));
555 ed
->setEnabled(false);
557 ed
->setText(profilesList
->currentItem()->text());
559 KConfigGroup
*group
= new KConfigGroup(m_profilesConfig
, profilesList
->currentItem()->text());
561 ibt
->setIcon(group
->readEntry("iconname"));
564 lay
->addRow(ibt
, ed
);
568 dialog
->setMainWidget(wg
);
571 if (dialog
->exec() == KDialog::Accepted
) {
572 editProfile(profilesList
->currentItem()->text(), ibt
->icon());
579 void EditPage::importProfiles()
581 QString fileName
= KFileDialog::getOpenFileName(KUrl(), "*.powerdevilprofiles|PowerDevil Profiles "
582 "(*.powerdevilprofiles)", this, i18n("Import PowerDevil profiles"));
584 if (fileName
.isEmpty()) {
588 KConfig
toImport(fileName
, KConfig::SimpleConfig
);
590 foreach(const QString
&ent
, toImport
.groupList()) {
591 KConfigGroup
copyFrom(&toImport
, ent
);
592 KConfigGroup
copyTo(m_profilesConfig
, ent
);
594 copyFrom
.copyTo(©To
);
597 m_profilesConfig
->sync();
599 reloadAvailableProfiles();
601 emit
profilesChanged();
604 void EditPage::exportProfiles()
606 QString fileName
= KFileDialog::getSaveFileName(KUrl(), "*.powerdevilprofiles|PowerDevil Profiles "
607 "(*.powerdevilprofiles)", this, i18n("Export PowerDevil profiles"));
609 if (fileName
.isEmpty()) {
613 kDebug() << "Filename is" << fileName
;
615 KConfig
*toExport
= m_profilesConfig
->copyTo(fileName
);
622 void EditPage::switchProfile(QListWidgetItem
*current
, QListWidgetItem
*previous
)
626 if (!m_profileEdited
) {
629 int result
= KMessageBox::warningYesNoCancel(this, i18n("The current profile has not been saved.\n"
630 "Do you want to save it?"), i18n("Save Profile"));
632 if (result
== KMessageBox::Yes
) {
633 saveProfile(previous
->text());
635 } else if (result
== KMessageBox::No
) {
637 } else if (result
== KMessageBox::Cancel
) {
638 disconnect(profilesList
, SIGNAL(currentItemChanged(QListWidgetItem
*, QListWidgetItem
*)),
639 this, SLOT(switchProfile(QListWidgetItem
*, QListWidgetItem
*)));
640 profilesList
->setCurrentItem(previous
);
641 connect(profilesList
, SIGNAL(currentItemChanged(QListWidgetItem
*, QListWidgetItem
*)),
642 SLOT(switchProfile(QListWidgetItem
*, QListWidgetItem
*)));
647 void EditPage::setProfileChanged()
649 m_profileEdited
= true;
653 void EditPage::enableSaveProfile()
657 void EditPage::openUrl(const QString
&url
)
659 new KRun(KUrl(url
), this);
662 #include "EditPage.moc"