00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kconfigdialog.h"
00022 #include "kconfigdialog.moc"
00023
00024 #include <kconfigskeleton.h>
00025 #include <kconfigdialogmanager.h>
00026 #include <klocale.h>
00027 #include <kiconloader.h>
00028 #include <kdebug.h>
00029
00030 #include <qlayout.h>
00031 #include <qvbox.h>
00032
00033 QAsciiDict<KConfigDialog> KConfigDialog::openDialogs;
00034
00035
00036 class KConfigDialog::KConfigDialogPrivate
00037 {
00038
00039 public:
00040 KConfigDialogPrivate(KDialogBase::DialogType t)
00041 : shown(false), type(t), mgr(0) { }
00042
00043 bool shown;
00044 KDialogBase::DialogType type;
00045 KConfigDialogManager *mgr;
00046 };
00047
00048 KConfigDialog::KConfigDialog( QWidget *parent, const char *name,
00049 KConfigSkeleton *config,
00050 DialogType dialogType,
00051 int dialogButtons,
00052 ButtonCode defaultButton,
00053 bool modal ) :
00054 KDialogBase( dialogType, Qt::WStyle_DialogBorder,
00055 parent, name, modal, i18n("Configure"), dialogButtons, defaultButton ),
00056 d(new KConfigDialogPrivate(dialogType))
00057 {
00058 if ( name ) {
00059 openDialogs.insert(name, this);
00060 } else {
00061 QCString genericName;
00062 genericName.sprintf("SettingsDialog-%p", this);
00063 openDialogs.insert(genericName, this);
00064 setName(genericName);
00065 }
00066
00067 d->mgr = new KConfigDialogManager(this, config);
00068
00069
00070 connect(d->mgr, SIGNAL(settingsChanged()), this, SIGNAL(settingsChanged()));
00071 connect(d->mgr, SIGNAL(settingsChanged()), this, SLOT(settingsChangedSlot()));
00072 connect(d->mgr, SIGNAL(widgetModified()), this, SLOT(updateButtons()));
00073
00074 connect(this, SIGNAL(okClicked()), this, SLOT(updateSettings()));
00075 connect(this, SIGNAL(okClicked()), d->mgr, SLOT(updateSettings()));
00076
00077 connect(this, SIGNAL(applyClicked()), this, SLOT(updateSettings()));
00078 connect(this, SIGNAL(applyClicked()), d->mgr, SLOT(updateSettings()));
00079 connect(this, SIGNAL(applyClicked()), this, SLOT(updateButtons()));
00080
00081 connect(this, SIGNAL(defaultClicked()), this, SLOT(updateWidgetsDefault()));
00082 connect(this, SIGNAL(defaultClicked()), d->mgr, SLOT(updateWidgetsDefault()));
00083 connect(this, SIGNAL(defaultClicked()), this, SLOT(updateButtons()));
00084
00085 enableButton(Apply, false);
00086 }
00087
00088 KConfigDialog::~KConfigDialog()
00089 {
00090 openDialogs.remove(name());
00091 delete d;
00092 }
00093
00094 void KConfigDialog::addPage(QWidget *page,
00095 const QString &itemName,
00096 const QString &pixmapName,
00097 const QString &header,
00098 bool manage)
00099 {
00100 if(d->shown)
00101 {
00102 kdDebug(240) << "KConfigDialog::addPage: can not add a page after the dialog has been shown.";
00103 return;
00104 }
00105 switch(d->type)
00106 {
00107 case TreeList:
00108 case IconList:
00109 case Tabbed: {
00110 QVBox *frame = addVBoxPage(itemName, header, SmallIcon(pixmapName, 32));
00111 frame->setSpacing( 0 );
00112 frame->setMargin( 0 );
00113 page->reparent(((QWidget*)frame), 0, QPoint());
00114 }
00115 break;
00116
00117 case Swallow:
00118 {
00119 page->reparent(this, 0, QPoint());
00120 setMainWidget(page);
00121 }
00122 break;
00123
00124 case Plain:
00125 {
00126 QFrame *main = plainPage();
00127 QVBoxLayout *topLayout = new QVBoxLayout( main, 0, 0 );
00128 page->reparent(((QWidget*)main), 0, QPoint());
00129 topLayout->addWidget( page );
00130 }
00131 break;
00132
00133 default:
00134 kdDebug(240) << "KConfigDialog::addpage: unknown type.";
00135 }
00136 if(manage)
00137 d->mgr->addWidget(page);
00138 }
00139
00140 KConfigDialog* KConfigDialog::exists(const char* name)
00141 {
00142 return openDialogs.find(name);
00143 }
00144
00145 bool KConfigDialog::showDialog(const char* name)
00146 {
00147 KConfigDialog *dialog = exists(name);
00148 if(dialog)
00149 dialog->show();
00150 return (dialog != NULL);
00151 }
00152
00153 void KConfigDialog::updateButtons()
00154 {
00155 static bool only_once = false;
00156 if (only_once) return;
00157 only_once = true;
00158 enableButton(Apply, d->mgr->hasChanged() || hasChanged());
00159 enableButton(Default, !(d->mgr->isDefault() && isDefault()));
00160 emit widgetModified();
00161 only_once = false;
00162 }
00163
00164 void KConfigDialog::settingsChangedSlot()
00165 {
00166
00167 updateButtons();
00168 emit (settingsChanged(name()));
00169 }
00170
00171 void KConfigDialog::show()
00172 {
00173 updateWidgets();
00174 d->mgr->updateWidgets();
00175 enableButton(Apply, d->mgr->hasChanged() || hasChanged());
00176 enableButton(Default, !(d->mgr->isDefault() && isDefault()));
00177 d->shown = true;
00178 KDialogBase::show();
00179 }
00180
00181 void KConfigDialog::updateSettings()
00182 {
00183 }
00184
00185 void KConfigDialog::updateWidgets()
00186 {
00187 }
00188
00189 void KConfigDialog::updateWidgetsDefault()
00190 {
00191 }