kdeui Library API Documentation

kconfigdialog.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (C) 2003 Benjamin C Meyer (ben+kdelibs at meyerhome dot net)
00004  *  Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  *  Boston, MA 02111-1307, USA.
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 // This class is here purly so we don't break binary compatibility down the road.
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   // TODO: Emit settingsChanged signal from slot to guarantee sequence
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   // Update the buttons
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 }
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:34:15 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003