summaryrefslogtreecommitdiffstats
path: root/noatun/library/pref.cpp
blob: 658e7951ffe5f985a6d504f57c392c2c6cc4b02c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "pref.h"

#include <klocale.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kdebug.h>
#include <tqlayout.h>
//#include <tqlabel.h>
#include "cmodule.h"

NoatunPreferences::NoatunPreferences(TQWidget *parent)
    : KDialogBase(TreeList, i18n("Preferences - Noatun"),
                  Ok|Apply|Cancel|Help, Ok, parent, "NoatunPreferences", false, true)
{
	resize(640, 480); // KDE is required to support 800x600 min.
	setShowIconsInTreeList(true);
	setRootIsDecorated(false);
}

void NoatunPreferences::slotOk()
{
	slotApply();
	hide();
}

void NoatunPreferences::show()
{
	for (CModule *i=mModules.first(); i != 0; i=mModules.next())
		i->reopen();
	KDialogBase::show();
}

void NoatunPreferences::show(CModule *page)
{
	int index = pageIndex( static_cast<TQWidget *>(page->parent()) );
	if (index != -1)
		showPage(index);
	show();
}

void NoatunPreferences::slotApply()
{
	for (CModule *i=mModules.first(); i != 0; i=mModules.next())
		i->save();
}

void NoatunPreferences::add(CModule *page)
{
	mModules.append(page);
}

void NoatunPreferences::remove(CModule *page)
{
	mModules.removeRef(page);
}

CModule::CModule(const TQString &name, const TQString &description, const TQString &icon, TQObject *owner)
	: TQWidget(napp->preferencesBox()->addPage(name, description, KGlobal::iconLoader()->loadIcon(
		icon, KIcon::Small,0, KIcon::DefaultState,0, true)))
{
	if (owner)
		connect(owner, TQT_SIGNAL(destroyed()), TQT_SLOT(ownerDeleted()));

	//kdDebug(66666) << k_funcinfo << "name = " << name << endl;

	napp->preferencesBox()->add(this);

	TQFrame *page=static_cast<TQFrame*>(parent());
	(new TQHBoxLayout(page))->addWidget(this);
}

CModule::~CModule()
{
	//kdDebug(66666) << k_funcinfo << endl;
#if QT_VERSION < 0x030102 && KDE_VERSION < KDE_MAKE_VERSION( 3, 1, 90 )
	// Due to a bug in Qt 3.1 and 3.1.1 no close events are sent to hidden
	// widgets, causing the KJanusWidget to crash. This workaround is
	// rather intrusive and should be used only in the affected versions
	// to avoid hard to track bugs in the future. KDE HEAD (to become 3.2)
	// has a workaround for this problem, and additionally it's fixed in
	// Qt 3.1.2.
 	napp->sendPostedEvents();
#endif

	napp->preferencesBox()->remove(this);
}

void CModule::ownerDeleted()
{
	TQObject *p=parent();
	delete this;
	p->deleteLater();
}

#include "pref.moc"