00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kmconfiggeneral.h"
00021
00022 #include <qlayout.h>
00023 #include <qgroupbox.h>
00024 #include <qcheckbox.h>
00025 #include <qlabel.h>
00026 #include <qwhatsthis.h>
00027
00028 #include <kpushbutton.h>
00029 #include <klocale.h>
00030 #include <kurlrequester.h>
00031 #include <krun.h>
00032 #include <kmimemagic.h>
00033 #include <kconfig.h>
00034 #include <knuminput.h>
00035 #include <kmessagebox.h>
00036 #include <kcursor.h>
00037 #include <klineedit.h>
00038 #include <kguiitem.h>
00039 #include <kdialog.h>
00040
00041 KMConfigGeneral::KMConfigGeneral(QWidget *parent)
00042 : KMConfigPage(parent,"ConfigTimer")
00043 {
00044 setPageName(i18n("General"));
00045 setPageHeader(i18n("General Settings"));
00046 setPagePixmap("fileprint");
00047
00048 QGroupBox *m_timerbox = new QGroupBox(0, Qt::Vertical, i18n("Refresh Interval"), this);
00049 m_timer = new KIntNumInput(m_timerbox,"Timer");
00050 m_timer->setRange(0,30);
00051 m_timer->setSuffix( i18n( " sec" ) );
00052 m_timer->setSpecialValueText(i18n("Disabled"));
00053 QWhatsThis::add(m_timer, i18n("This time setting controls the refresh rate of various "
00054 "<b>KDE Print</b> components like the print manager "
00055 "and the job viewer."));
00056
00057 QGroupBox *m_testpagebox = new QGroupBox(0, Qt::Vertical, i18n("Test Page"), this);
00058 m_defaulttestpage = new QCheckBox(i18n("&Specify personal test page"), m_testpagebox, "TestPageCheck");
00059 m_testpage = new KURLRequester(m_testpagebox,"TestPage");
00060 m_preview = new KPushButton(KGuiItem(i18n("Preview..."), "filefind"), m_testpagebox);
00061 connect(m_defaulttestpage,SIGNAL(toggled(bool)),m_testpage,SLOT(setEnabled(bool)));
00062 connect(m_defaulttestpage,SIGNAL(toggled(bool)),this,SLOT(setEnabledPreviewButton(bool)));
00063 connect(m_preview,SIGNAL(clicked()),SLOT(slotTestPagePreview()));
00064 connect(m_testpage->lineEdit(),SIGNAL(textChanged ( const QString & )),this,SLOT(testPageChanged(const QString & )));
00065 m_testpage->setDisabled(true);
00066 m_preview->setDisabled(true);
00067 m_defaulttestpage->setCursor(KCursor::handCursor());
00068
00069 QGroupBox *m_statusbox = new QGroupBox(0, Qt::Vertical, i18n("Miscellaneous"), this);
00070 m_statusmsg = new QCheckBox(i18n("Sho&w printing status message box"), m_statusbox);
00071 m_uselast = new QCheckBox(i18n("De&faults to the last printer used in the application"), m_statusbox);
00072
00073
00074 QVBoxLayout *lay0 = new QVBoxLayout(this, 0, KDialog::spacingHint());
00075 lay0->addWidget(m_timerbox);
00076 lay0->addWidget(m_testpagebox);
00077 lay0->addWidget(m_statusbox);
00078 lay0->addStretch(1);
00079 QVBoxLayout *lay1 = new QVBoxLayout(m_timerbox->layout(),
00080 KDialog::spacingHint());
00081 lay1->addWidget(m_timer);
00082 QVBoxLayout *lay2 = new QVBoxLayout(m_testpagebox->layout(),
00083 KDialog::spacingHint());
00084 QHBoxLayout *lay3 = new QHBoxLayout(0, 0, 0);
00085 lay2->addWidget(m_defaulttestpage);
00086 lay2->addWidget(m_testpage);
00087 lay2->addLayout(lay3);
00088 lay3->addStretch(1);
00089 lay3->addWidget(m_preview);
00090 QVBoxLayout *lay4 = new QVBoxLayout(m_statusbox->layout(),
00091 KDialog::spacingHint());
00092 lay4->addWidget(m_statusmsg);
00093 lay4->addWidget(m_uselast);
00094 m_preview->setEnabled( !m_testpage->url().isEmpty());
00095 }
00096
00097 void KMConfigGeneral::testPageChanged(const QString &test )
00098 {
00099 m_preview->setEnabled( !test.isEmpty());
00100 }
00101
00102 void KMConfigGeneral::setEnabledPreviewButton(bool b)
00103 {
00104 m_preview->setEnabled(!m_testpage->url().isEmpty() && b);
00105 }
00106
00107 void KMConfigGeneral::loadConfig(KConfig *conf)
00108 {
00109 conf->setGroup("General");
00110 m_timer->setValue(conf->readNumEntry("TimerDelay",5));
00111 QString tpage = conf->readPathEntry("TestPage");
00112 if (!tpage.isEmpty())
00113 {
00114 m_defaulttestpage->setChecked(true);
00115 m_testpage->setURL(tpage);
00116 }
00117 m_statusmsg->setChecked(conf->readBoolEntry("ShowStatusMsg", true));
00118 m_uselast->setChecked(conf->readBoolEntry("UseLast", true));
00119 }
00120
00121 void KMConfigGeneral::saveConfig(KConfig *conf)
00122 {
00123 conf->setGroup("General");
00124 conf->writeEntry("TimerDelay",m_timer->value());
00125 conf->writePathEntry("TestPage",(m_defaulttestpage->isChecked() ? m_testpage->url() : QString::null));
00126 if (m_defaulttestpage->isChecked() && KMimeMagic::self()->findFileType(m_testpage->url())->mimeType() != "application/postscript")
00127 KMessageBox::sorry(this, i18n("The selected test page is not a PostScript file. You may not "
00128 "be able to test your printer anymore."));
00129 conf->writeEntry("ShowStatusMsg", m_statusmsg->isChecked());
00130 conf->writeEntry("UseLast", m_uselast->isChecked());
00131 }
00132
00133 void KMConfigGeneral::slotTestPagePreview()
00134 {
00135 QString tpage = m_testpage->url();
00136 if (tpage.isEmpty())
00137 KMessageBox::error(this, i18n("Empty file name."));
00138 else
00139 KRun::runURL(KURL( tpage ), KMimeMagic::self()->findFileType(tpage)->mimeType());
00140 }
00141
00142 #include "kmconfiggeneral.moc"