summaryrefslogtreecommitdiffstats
path: root/lib/util/configwidgetproxy.h
blob: ee9a3fb0f38c9361378a7df29fc27058f127747f (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* This file is part of the KDE project
   Copyright (C) 2004 Jens Dagerbo <jens.dagerbo@swipnet.se>

   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.
*/

#ifndef _CONFIGWIDGETPROXY_H
#define _CONFIGWIDGETPROXY_H

#include <tqobject.h>
#include <tqstring.h>
#include <tqmap.h>

class KDevCore;
class KDialogBase;

/**
@file configwidgetproxy.h
Configuration widget proxy class.
*/

/**
This class can be used to implement demand-loading of config pages.
In order to avoid the potentially heavy and unneccessary creation
of a config page that might not be needed, this class can be used
to delay the config page creation until the user explicitly asks
for it.
 
A typical case looks like this:
@code
#define GLOBALDOC_OPTIONS 1
#define PROJECTDOC_OPTIONS 2

_configProxy = new ConfigWidgetProxy( core() );
_configProxy->createGlobalConfigPage( i18n("My Part"), GLOBALDOC_OPTIONS, info()->icon() );
_configProxy->createProjectConfigPage( i18n("My Part"), PROJECTDOC_OPTIONS, info()->icon() );
connect( _configProxy, TQ_SIGNAL(insertConfigWidget(const TQObject*, TQWidget*, unsigned int )), 
    this, TQ_SLOT(insertConfigWidget(const TQObject*, TQWidget*, unsigned int )) );

...
...

void MyPart::insertConfigWidget( TQObject const * dlg, TQWidget * page, unsigned int pagenumber )
{
    if ( pagenumber == PROJECTDOC_OPTIONS ) {
        MyPartGlobalSettings * w = new MyPartGlobalSettings( this, page );
        connect( dlg, TQ_SIGNAL(okClicked()), w, TQ_SLOT(slotAccept()) );
    } else if ( pagenumber == PROJECTDOC_OPTIONS ) {
        MyPartProjectSettings * w = new MyPartProjectSettings( this, page );
        connect( dlg, TQ_SIGNAL(okClicked()), w, TQ_SLOT(slotAccept()) );
    }
}
@endcode

Note that this replaces the functionality of typical KDevCore::configWidget() and
KDevCore::projectConfigWidget() slots.
*/
class ConfigWidgetProxy : public TQObject
{
TQ_OBJECT
  

public:
	/**Constructor.
	@param core An instance of KDevelop Core.*/
	ConfigWidgetProxy( KDevCore * core );
	virtual ~ConfigWidgetProxy();
    
	/**
	* Tells the proxy you want a page in the Global Settings. 
	* @param title The title of the config page, shown in the settings dialog.
	* @param pagenumber A per-proxy unique identifier, used when responding to insertConfigWidget() signal.
	* @param icon The name of the icon to use.
	*/
	void createGlobalConfigPage( TQString const & title, unsigned int pagenumber, TQString const & icon = "tdevelop" );
	
	/**
	* Tells the proxy you want a page in the Project Settings. 
	* @param title The title of the config page, shown in the settings dialog.
	* @param pagenumber A per-proxy unique identifier, used when responding to insertConfigWidget() signal.
	* @param icon The name of the icon to use.
	*/
	void createProjectConfigPage( TQString const & title, unsigned int pagenumber, TQString const & icon = "tdevelop" );
	
	/**
	* Removes a config page from the proxy. Next time the settings dialog opens, this page will not be available.
	* @param pagenumber The identifier set in createGlobalConfigPage() or createProjectConfigPage().
	*/
	void removeConfigPage( int pagenumber );

signals:
	/**
	* The proxy emits this signal to notify the client that a specific config page has been requested.
	* @param dlg The settings dialog. The client should connect to its okClicked() signal.
	* @param page The setting page. The client should use this as parent to the config widget.
	* @param pagenumber The identifier set in createGlobalConfigPage() or createProjectConfigPage(). Identifies the requested config page.
	*/
	void insertConfigWidget( const KDialogBase * dlg, TQWidget * page, unsigned int pagenumber );

private slots:
	void slotConfigWidget( KDialogBase * );
	void slotProjectConfigWidget( KDialogBase * );
	void slotConfigWidgetDestroyed();	
	void slotAboutToShowPage( TQWidget * page );

private:
	typedef TQMap<unsigned int, TQPair<TQString,TQString> > TitleMap;
	typedef TQMap<TQWidget*, int> PageMap;
	
	TitleMap _globalTitleMap;
	TitleMap _projectTitleMap;
	PageMap _pageMap;
};

#endif