You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
260 lines
7.3 KiB
260 lines
7.3 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE libraries
|
||
13 years ago
|
* Copyright (C) 2003 Benjamin C Meyer (ben+tdelibs at meyerhome dot net)
|
||
15 years ago
|
* Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
|
||
|
* Copyright (C) 2004 Michael Brade <brade@kde.org>
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
12 years ago
|
#include "tdeconfigdialog.h"
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeconfigskeleton.h>
|
||
|
#include <tdeconfigdialogmanager.h>
|
||
15 years ago
|
#include <klocale.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqvbox.h>
|
||
|
#include <tqmap.h>
|
||
15 years ago
|
|
||
12 years ago
|
TQAsciiDict<TDEConfigDialog> TDEConfigDialog::openDialogs;
|
||
15 years ago
|
|
||
|
// This class is here purly so we don't break binary compatibility down the road.
|
||
12 years ago
|
class TDEConfigDialog::TDEConfigDialogPrivate
|
||
15 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
TDEConfigDialogPrivate(KDialogBase::DialogType t)
|
||
15 years ago
|
: shown(false), type(t), manager(0) { }
|
||
|
|
||
|
bool shown;
|
||
|
KDialogBase::DialogType type;
|
||
12 years ago
|
TDEConfigDialogManager *manager;
|
||
|
TQMap<TQWidget *, TDEConfigDialogManager *> managerForPage;
|
||
15 years ago
|
};
|
||
|
|
||
12 years ago
|
TDEConfigDialog::TDEConfigDialog( TQWidget *parent, const char *name,
|
||
|
TDEConfigSkeleton *config,
|
||
15 years ago
|
DialogType dialogType,
|
||
|
int dialogButtons,
|
||
|
ButtonCode defaultButton,
|
||
|
bool modal ) :
|
||
14 years ago
|
KDialogBase( dialogType, (WFlags)TQt::WStyle_DialogBorder,
|
||
15 years ago
|
parent, name, modal, i18n("Configure"), dialogButtons, defaultButton ),
|
||
12 years ago
|
d(new TDEConfigDialogPrivate(dialogType))
|
||
15 years ago
|
{
|
||
|
if ( name ) {
|
||
|
openDialogs.insert(name, this);
|
||
|
} else {
|
||
15 years ago
|
TQCString genericName;
|
||
15 years ago
|
genericName.sprintf("SettingsDialog-%p", this);
|
||
|
openDialogs.insert(genericName, this);
|
||
|
setName(genericName);
|
||
|
}
|
||
|
|
||
15 years ago
|
connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(updateSettings()));
|
||
|
connect(this, TQT_SIGNAL(applyClicked()), this, TQT_SLOT(updateSettings()));
|
||
|
connect(this, TQT_SIGNAL(applyClicked()), this, TQT_SLOT(updateButtons()));
|
||
|
connect(this, TQT_SIGNAL(defaultClicked()), this, TQT_SLOT(updateWidgetsDefault()));
|
||
|
connect(this, TQT_SIGNAL(defaultClicked()), this, TQT_SLOT(updateButtons()));
|
||
15 years ago
|
|
||
12 years ago
|
d->manager = new TDEConfigDialogManager(this, config);
|
||
15 years ago
|
setupManagerConnections(d->manager);
|
||
|
|
||
|
enableButton(Apply, false);
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEConfigDialog::~TDEConfigDialog()
|
||
15 years ago
|
{
|
||
|
openDialogs.remove(name());
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::addPage(TQWidget *page,
|
||
15 years ago
|
const TQString &itemName,
|
||
|
const TQString &pixmapName,
|
||
|
const TQString &header,
|
||
15 years ago
|
bool manage)
|
||
|
{
|
||
|
addPageInternal(page, itemName, pixmapName, header);
|
||
|
if(manage)
|
||
|
d->manager->addWidget(page);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::addPage(TQWidget *page,
|
||
|
TDEConfigSkeleton *config,
|
||
15 years ago
|
const TQString &itemName,
|
||
|
const TQString &pixmapName,
|
||
|
const TQString &header)
|
||
15 years ago
|
{
|
||
|
addPageInternal(page, itemName, pixmapName, header);
|
||
12 years ago
|
d->managerForPage[page] = new TDEConfigDialogManager(page, config);
|
||
15 years ago
|
setupManagerConnections(d->managerForPage[page]);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::addPageInternal(TQWidget *page,
|
||
15 years ago
|
const TQString &itemName,
|
||
|
const TQString &pixmapName,
|
||
|
const TQString &header)
|
||
15 years ago
|
{
|
||
|
if(d->shown)
|
||
|
{
|
||
12 years ago
|
kdDebug(240) << "TDEConfigDialog::addPage: can not add a page after the dialog has been shown.";
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
switch(d->type)
|
||
|
{
|
||
|
case TreeList:
|
||
|
case IconList:
|
||
|
case Tabbed: {
|
||
15 years ago
|
TQVBox *frame = addVBoxPage(itemName, header, SmallIcon(pixmapName, 32));
|
||
15 years ago
|
frame->setSpacing( 0 );
|
||
|
frame->setMargin( 0 );
|
||
15 years ago
|
page->reparent(((TQWidget*)frame), 0, TQPoint());
|
||
15 years ago
|
}
|
||
|
break;
|
||
|
|
||
|
case Swallow:
|
||
|
{
|
||
15 years ago
|
page->reparent(this, 0, TQPoint());
|
||
15 years ago
|
setMainWidget(page);
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case Plain:
|
||
|
{
|
||
15 years ago
|
TQFrame *main = plainPage();
|
||
|
TQVBoxLayout *topLayout = new TQVBoxLayout( main, 0, 0 );
|
||
|
page->reparent(((TQWidget*)main), 0, TQPoint());
|
||
15 years ago
|
topLayout->addWidget( page );
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
default:
|
||
12 years ago
|
kdDebug(240) << "TDEConfigDialog::addpage: unknown type.";
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::setupManagerConnections(TDEConfigDialogManager *manager)
|
||
15 years ago
|
{
|
||
15 years ago
|
connect(manager, TQT_SIGNAL(settingsChanged()), this, TQT_SLOT(settingsChangedSlot()));
|
||
|
connect(manager, TQT_SIGNAL(widgetModified()), this, TQT_SLOT(updateButtons()));
|
||
15 years ago
|
|
||
15 years ago
|
connect(this, TQT_SIGNAL(okClicked()), manager, TQT_SLOT(updateSettings()));
|
||
|
connect(this, TQT_SIGNAL(applyClicked()), manager, TQT_SLOT(updateSettings()));
|
||
|
connect(this, TQT_SIGNAL(defaultClicked()), manager, TQT_SLOT(updateWidgetsDefault()));
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEConfigDialog* TDEConfigDialog::exists(const char* name)
|
||
15 years ago
|
{
|
||
13 years ago
|
return openDialogs.find(name);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
bool TDEConfigDialog::showDialog(const char* name)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEConfigDialog *dialog = exists(name);
|
||
15 years ago
|
if(dialog)
|
||
|
dialog->show();
|
||
|
return (dialog != NULL);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::updateButtons()
|
||
15 years ago
|
{
|
||
|
static bool only_once = false;
|
||
|
if (only_once) return;
|
||
|
only_once = true;
|
||
|
|
||
12 years ago
|
TQMap<TQWidget *, TDEConfigDialogManager *>::iterator it;
|
||
15 years ago
|
|
||
|
bool has_changed = d->manager->hasChanged() || hasChanged();
|
||
|
for (it = d->managerForPage.begin();
|
||
|
it != d->managerForPage.end() && !has_changed;
|
||
|
++it)
|
||
|
{
|
||
|
has_changed |= (*it)->hasChanged();
|
||
|
}
|
||
|
|
||
|
enableButton(Apply, has_changed);
|
||
|
|
||
|
bool is_default = d->manager->isDefault() && isDefault();
|
||
|
for (it = d->managerForPage.begin();
|
||
|
it != d->managerForPage.end() && is_default;
|
||
|
++it)
|
||
|
{
|
||
|
is_default &= (*it)->isDefault();
|
||
|
}
|
||
|
|
||
|
enableButton(Default, !is_default);
|
||
|
|
||
|
emit widgetModified();
|
||
|
only_once = false;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::settingsChangedSlot()
|
||
15 years ago
|
{
|
||
|
// Update the buttons
|
||
|
updateButtons();
|
||
|
emit settingsChanged();
|
||
|
emit settingsChanged(name());
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::show()
|
||
15 years ago
|
{
|
||
12 years ago
|
TQMap<TQWidget *, TDEConfigDialogManager *>::iterator it;
|
||
15 years ago
|
|
||
|
updateWidgets();
|
||
|
d->manager->updateWidgets();
|
||
|
for (it = d->managerForPage.begin(); it != d->managerForPage.end(); ++it)
|
||
|
(*it)->updateWidgets();
|
||
|
|
||
|
bool has_changed = d->manager->hasChanged() || hasChanged();
|
||
|
for (it = d->managerForPage.begin();
|
||
|
it != d->managerForPage.end() && !has_changed;
|
||
|
++it)
|
||
|
{
|
||
|
has_changed |= (*it)->hasChanged();
|
||
|
}
|
||
|
|
||
|
enableButton(Apply, has_changed);
|
||
|
|
||
|
bool is_default = d->manager->isDefault() && isDefault();
|
||
|
for (it = d->managerForPage.begin();
|
||
|
it != d->managerForPage.end() && is_default;
|
||
|
++it)
|
||
|
{
|
||
|
is_default &= (*it)->isDefault();
|
||
|
}
|
||
|
|
||
|
enableButton(Default, !is_default);
|
||
|
d->shown = true;
|
||
|
KDialogBase::show();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::updateSettings()
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::updateWidgets()
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEConfigDialog::updateWidgetsDefault()
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
#include "tdeconfigdialog.moc"
|