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 KDialogBase::DialogType dialogType,
00051 int dialogButtons,
00052 KDialogBase::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(KDialogBase::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 a page after the dialog has been shown.";
00103 return;
00104 }
00105 switch(d->type)
00106 {
00107 case KDialogBase::TreeList:
00108 case KDialogBase::IconList:
00109 case KDialogBase::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 KDialogBase::Swallow:
00118 {
00119 page->reparent(this, 0, QPoint());
00120 setMainWidget(page);
00121 }
00122 break;
00123
00124 case KDialogBase::Plain:
00125 {
00126 page->reparent(this, 0, QPoint());
00127 QFrame *page = plainPage();
00128 QVBoxLayout *topLayout = new QVBoxLayout( page, 0, 0 );
00129 page->reparent(((QWidget*)page), 0, QPoint());
00130 topLayout->addWidget( page );
00131 setMainWidget(page);
00132 }
00133 break;
00134
00135 default:
00136 kdDebug(240) << "KConfigDialog::addWidget" << " unknown type.";
00137 }
00138 if(manage)
00139 d->mgr->addWidget(page);
00140 }
00141
00142 KConfigDialog* KConfigDialog::exists(const char* name)
00143 {
00144 return openDialogs.find(name);
00145 }
00146
00147 bool KConfigDialog::showDialog(const char* name)
00148 {
00149 KConfigDialog *dialog = exists(name);
00150 if(dialog)
00151 dialog->show();
00152 return (dialog != NULL);
00153 }
00154
00155 void KConfigDialog::updateButtons()
00156 {
00157 static bool only_once = false;
00158 if (only_once) return;
00159 only_once = true;
00160 enableButton(KDialogBase::Apply, d->mgr->hasChanged() || hasChanged());
00161 enableButton(KDialogBase::Default, !(d->mgr->isDefault() && isDefault()));
00162 emit widgetModified();
00163 only_once = false;
00164 }
00165
00166 void KConfigDialog::settingsChangedSlot()
00167 {
00168
00169 updateButtons();
00170 emit (settingsChanged(name()));
00171 }
00172
00173 void KConfigDialog::show()
00174 {
00175 updateWidgets();
00176 d->mgr->updateWidgets();
00177 enableButton(KDialogBase::Apply, d->mgr->hasChanged() || hasChanged());
00178 enableButton(KDialogBase::Default, !(d->mgr->isDefault() && isDefault()));
00179 d->shown = true;
00180 KDialogBase::show();
00181 }
00182
00183 void KConfigDialog::updateSettings()
00184 {
00185 }
00186
00187 void KConfigDialog::updateWidgets()
00188 {
00189 }
00190
00191 void KConfigDialog::updateWidgetsDefault()
00192 {
00193 }