not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / screensaver / advanceddialog.cpp
blob9bfec8cdb34ecf348286d62aaa8bf52e84673dbd
1 #include <klocale.h>
2 #include <kstandarddirs.h>
3 #include <QComboBox>
4 //Added by qt3to4:
5 #include <QPixmap>
6 #include <kdebug.h>
10 #include <config-workspace.h>
12 #include "advanceddialog.h"
13 #include "stdlib.h"
15 #include "advanceddialog.moc"
17 KScreenSaverAdvancedDialog::KScreenSaverAdvancedDialog(QWidget *parent)
18 : KDialog( parent )
20 setModal( true );
21 setCaption( i18n( "Advanced Options" ) );
22 setButtons( Ok | Cancel );
23 showButtonSeparator( true );
25 dialog = new AdvancedDialog(this);
26 setMainWidget(dialog);
28 readSettings();
30 connect(dialog->qcbPriority, SIGNAL(activated(int)),
31 this, SLOT(slotPriorityChanged(int)));
33 connect(dialog->qcbTopLeft, SIGNAL(activated(int)),
34 this, SLOT(slotChangeTopLeftCorner(int)));
35 connect(dialog->qcbTopRight, SIGNAL(activated(int)),
36 this, SLOT(slotChangeTopLeftCorner(int)));
37 connect(dialog->qcbBottomLeft, SIGNAL(activated(int)),
38 this, SLOT(slotChangeTopLeftCorner(int)));
39 connect(dialog->qcbBottomRight, SIGNAL(activated(int)),
40 this, SLOT(slotChangeTopLeftCorner(int)));
42 #ifndef HAVE_SETPRIORITY
43 dialog->qgbPriority->setEnabled(false);
44 #endif
47 void KScreenSaverAdvancedDialog::readSettings()
49 KConfigGroup config(KSharedConfig::openConfig("kscreensaverrc"), "ScreenSaver");
51 mPriority = config.readEntry("Priority", 19);
52 if (mPriority < 0) mPriority = 0;
53 if (mPriority > 19) mPriority = 19;
55 dialog->qcbTopLeft->setCurrentIndex(config.readEntry("ActionTopLeft", 0));
56 dialog->qcbTopRight->setCurrentIndex(config.readEntry("ActionTopRight", 0));
57 dialog->qcbBottomLeft->setCurrentIndex(config.readEntry("ActionBottomLeft", 0));
58 dialog->qcbBottomRight->setCurrentIndex(config.readEntry("ActionBottomRight", 0));
60 switch(mPriority)
62 case 19: // Low
63 dialog->qcbPriority->setCurrentIndex(0);
64 kDebug() << "setting low";
65 break;
66 case 10: // Medium
67 dialog->qcbPriority->setCurrentIndex(1);
68 kDebug() << "setting medium";
69 break;
70 case 0: // High
71 dialog->qcbPriority->setCurrentIndex(2);
72 kDebug() << "setting high";
73 break;
76 mChanged = false;
79 void KScreenSaverAdvancedDialog::slotPriorityChanged(int val)
81 switch (val)
83 case 0: // Low
84 mPriority = 19;
85 kDebug() << "low priority";
86 break;
87 case 1: // Medium
88 mPriority = 10;
89 kDebug() << "medium priority";
90 break;
91 case 2: // High
92 mPriority = 0;
93 kDebug() << "high priority";
94 break;
96 mChanged = true;
99 void KScreenSaverAdvancedDialog::accept()
101 if (mChanged)
103 KConfig *config = new KConfig("kscreensaverrc");
104 KConfigGroup group= config->group("ScreenSaver");
106 group.writeEntry("Priority", mPriority);
107 group.writeEntry(
108 "ActionTopLeft", dialog->qcbTopLeft->currentIndex());
109 group.writeEntry(
110 "ActionTopRight", dialog->qcbTopRight->currentIndex());
111 group.writeEntry(
112 "ActionBottomLeft", dialog->qcbBottomLeft->currentIndex());
113 group.writeEntry(
114 "ActionBottomRight", dialog->qcbBottomRight->currentIndex());
115 group.sync();
116 delete config;
119 KDialog::accept();
122 void KScreenSaverAdvancedDialog::slotChangeBottomRightCorner(int)
124 mChanged = true;
127 void KScreenSaverAdvancedDialog::slotChangeBottomLeftCorner(int)
129 mChanged = true;
132 void KScreenSaverAdvancedDialog::slotChangeTopRightCorner(int)
134 mChanged = true;
137 void KScreenSaverAdvancedDialog::slotChangeTopLeftCorner(int)
139 mChanged = true;
142 /* =================================================================================================== */
144 AdvancedDialog::AdvancedDialog(QWidget *parent) : AdvancedDialogImpl(parent)
146 monitorLabel->setPixmap(QPixmap(KStandardDirs::locate("data", "kcontrol/pics/monitor.png")));
147 qcbPriority->setWhatsThis( "<qt>" + i18n("Specify the priority that the screensaver will run at. A higher priority may mean that the screensaver runs faster, though may reduce the speed that other programs run at while the screensaver is active.") + "</qt>");
148 QString qsTopLeft("<qt>" + i18n("The action to take when the mouse cursor is located in the top left corner of the screen for 15 seconds.") + "</qt>");
149 QString qsTopRight("<qt>" + i18n("The action to take when the mouse cursor is located in the top right corner of the screen for 15 seconds.") + "</qt>");
150 QString qsBottomLeft("<qt>" + i18n("The action to take when the mouse cursor is located in the bottom left corner of the screen for 15 seconds.") + "</qt>");
151 QString qsBottomRight("<qt>" + i18n("The action to take when the mouse cursor is located in the bottom right corner of the screen for 15 seconds.") + "</qt>");
152 qlTopLeft->setWhatsThis( qsTopLeft);
153 qcbTopLeft->setWhatsThis( qsTopLeft);
154 qlTopRight->setWhatsThis( qsTopRight);
155 qcbTopRight->setWhatsThis( qsTopRight);
156 qlBottomLeft->setWhatsThis( qsBottomLeft);
157 qcbBottomLeft->setWhatsThis( qsBottomLeft);
158 qlBottomRight->setWhatsThis( qsBottomRight);
159 qcbBottomRight->setWhatsThis( qsBottomRight);
162 AdvancedDialog::~AdvancedDialog()
167 void AdvancedDialog::setMode(QComboBox *box, int i)
169 box->setCurrentIndex(i);
172 int AdvancedDialog::mode(QComboBox *box)
174 return box->currentIndex();