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   openDialogs.insert(name, this);
00059 
00060   d->mgr = new KConfigDialogManager(this, config);
00061 
00062   
00063   connect(d->mgr, SIGNAL(settingsChanged()), this, SIGNAL(settingsChanged()));
00064   connect(d->mgr, SIGNAL(settingsChanged()), this, SLOT(settingsChangedSlot()));
00065   connect(d->mgr, SIGNAL(widgetModified()), this, SLOT(updateButtons()));
00066 
00067   connect(this, SIGNAL(okClicked()), this, SLOT(updateSettings()));
00068   connect(this, SIGNAL(okClicked()), d->mgr, SLOT(updateSettings()));
00069 
00070   connect(this, SIGNAL(applyClicked()), this, SLOT(updateSettings()));
00071   connect(this, SIGNAL(applyClicked()), d->mgr, SLOT(updateSettings()));
00072   connect(this, SIGNAL(applyClicked()), this, SLOT(updateButtons()));
00073 
00074   connect(this, SIGNAL(defaultClicked()), this, SLOT(updateWidgetsDefault()));
00075   connect(this, SIGNAL(defaultClicked()), d->mgr, SLOT(updateWidgetsDefault()));
00076   connect(this, SIGNAL(defaultClicked()), this, SLOT(updateButtons()));
00077 
00078   enableButton(KDialogBase::Apply, false);
00079 }
00080 
00081 KConfigDialog::~KConfigDialog()
00082 {
00083   openDialogs.remove(name());
00084   delete d;
00085 }
00086 
00087 void KConfigDialog::addPage(QWidget *page,
00088                                 const QString &itemName,
00089                                 const QString &pixmapName,
00090                                 const QString &header,
00091                                 bool manage)
00092 {
00093   if(d->shown)
00094   {
00095     kdDebug(240) << "KConfigDialog::addPage, can not a page after the dialog has been shown.";
00096     return;
00097   }
00098   switch(d->type)
00099   {
00100     case KDialogBase::TreeList:
00101     case KDialogBase::IconList:
00102     case KDialogBase::Tabbed: {
00103       QVBox *frame = addVBoxPage(itemName, header, SmallIcon(pixmapName, 32));
00104       frame->setSpacing( 0 );
00105       frame->setMargin( 0 );
00106       page->reparent(((QWidget*)frame), 0, QPoint());
00107     }
00108     break;
00109 
00110     case KDialogBase::Swallow: 
00111     {
00112       page->reparent(this, 0, QPoint());
00113       setMainWidget(page);
00114     }
00115     break;
00116 
00117     case KDialogBase::Plain:
00118     {
00119       page->reparent(this, 0, QPoint());
00120       QFrame *page = plainPage();
00121       QVBoxLayout *topLayout = new QVBoxLayout( page, 0, 0 );
00122       page->reparent(((QWidget*)page), 0, QPoint());
00123       topLayout->addWidget( page );
00124       setMainWidget(page);
00125     }
00126     break;
00127 
00128     default:
00129       kdDebug(240) << "KConfigDialog::addWidget" << " unknown type.";
00130   }
00131   if(manage)
00132     d->mgr->addWidget(page);
00133 }
00134 
00135 KConfigDialog* KConfigDialog::exists(const char* name)
00136 {
00137   return openDialogs.find(name);
00138 }
00139 
00140 bool KConfigDialog::showDialog(const char* name)
00141 {
00142   KConfigDialog *dialog = exists(name);
00143   if(dialog)
00144     dialog->show();
00145   return (dialog != NULL);
00146 }
00147 
00148 void KConfigDialog::updateButtons()
00149 {
00150   static bool only_once = false;
00151   if (only_once) return;
00152   only_once = true;
00153   enableButton(KDialogBase::Apply, d->mgr->hasChanged() || hasChanged());
00154   enableButton(KDialogBase::Default, !(d->mgr->isDefault() && isDefault()));
00155   emit widgetModified();
00156   only_once = false;
00157 }
00158 
00159 void KConfigDialog::settingsChangedSlot()
00160 {
00161   
00162   updateButtons();
00163   emit (settingsChanged(name()));
00164 }
00165 
00166 void KConfigDialog::show()
00167 {
00168   updateWidgets();
00169   d->mgr->updateWidgets();
00170   enableButton(KDialogBase::Apply, d->mgr->hasChanged() || hasChanged());
00171   enableButton(KDialogBase::Default, !(d->mgr->isDefault() && isDefault()));
00172   d->shown = true;
00173   KDialogBase::show();
00174 }
00175 
00176 void KConfigDialog::updateSettings()
00177 {
00178 }
00179 
00180 void KConfigDialog::updateWidgets()
00181 {
00182 }
00183 
00184 void KConfigDialog::updateWidgetsDefault()
00185 {
00186 }