summaryrefslogtreecommitdiffstats
path: root/kcontrol/konqhtml/domainlistview.h
blob: 7d0d30b82aa5913e0cadb693fd7bd4f26fa42f4a (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
  Copyright (c) 2002 Leo Savernik <[email protected]>
  Derived from jsopts.h and javaopts.h, code copied from there is
  copyrighted to its respective owners.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program 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 General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

#ifndef __DOMAINLISTVIEW_H__
#define __DOMAINLISTVIEW_H__

#include <tqgroupbox.h>
#include <tqmap.h>

class TQListViewItem;
class TQPushButton;
class TQStringList;

class KConfig;
class KListView;

class Policies;
class PolicyDialog;

/**
 * @short Provides a list view of domains which policies are attached to.
 *
 * This class resembles a list view of domain names and some buttons to
 * manipulate it. You should use this widget if you need to manage domains
 * whose policies are described by (derivatives of) Policies objects.
 *
 * The contained widgets can be accessed by respective getters for
 * fine-tuning/customizing them afterwards.
 *
 * To use this class you have to derive your own and implement most
 * (all) of the protected methods. You need these to customize this widget
 * for its special purpose.
 *
 * @author Leo Savernik
 */
class DomainListView : public TQGroupBox {
  Q_OBJECT
public:
  /** Enumerates the available buttons.
    */
  enum PushButton {
    AddButton, ChangeButton, DeleteButton, ImportButton, ExportButton
  };

  /**
   * constructor
   * @param config configuration to read from and to write to
   * @param title title to be used for enclosing group box
   * @param parent parent widget
   * @param name internal name for debugging
   */
  DomainListView(KConfig *config,const TQString &title,TQWidget *parent,
  		const char *name = 0);

  virtual ~DomainListView();

  /**
   * clears the list view.
   */
//  void clear();

  /**
   * returns the list view displaying the domains
   */
  KListView *listView() const { return domainSpecificLV; }

  /**
   * returns the add push-button.
   *
   * Note: The add button already tqcontains a default "what's this" text.
   */
  TQPushButton *addButton() const { return addDomainPB; }

  /**
   * returns the change push-button.
   *
   * Note: The change button already tqcontains a default "what's this" text.
   */
  TQPushButton *changeButton() const { return changeDomainPB; }

  /**
   * returns the delete push-button.
   *
   * Note: The delete button already tqcontains a default "what's this" text.
   */
  TQPushButton *deleteButton() const { return deleteDomainPB; }

  /**
   * returns the import push-button.
   */
  TQPushButton *importButton() const { return importDomainPB; }

  /**
   * returns the export push-button.
   */
  TQPushButton *exportButton() const { return exportDomainPB; }

  /**
   * Initializes the list view with the given list of domains as well
   * as the domain policy map.
   *
   * This method may be called multiple times on a DomainListView instance.
   *
   * @param domainList given list of domains
   */
  void initialize(const TQStringList &domainList);

  /**
   * saves the current state of all domains to the configuration object.
   * @param group the group the information is to be saved under
   * @param domainListKey the name of the key which the list of domains
   *	is stored under.
   */
  void save(const TQString &group, const TQString &domainListKey);


signals:
  /**
   * indicates that a configuration has been changed within this list view.
   * @param state true if changed, false if not
   */
  void changed(bool state);

protected:
  /**
   * factory method for creating a new domain-specific policies object.
   *
   * Example:
   * <pre>
   * JavaPolicies *JavaDomainListView::createPolicies() {
   *   return new JavaPolicies(m_pConfig,m_groupname,false);
   * }
   * </pre>
   */
  virtual Policies *createPolicies() = 0;

  /**
   * factory method for copying a policies object.
   *
   * Derived classes must interpret the given object as the same type
   * as those created by createPolicies and return a copy of this very type.
   *
   * Example:
   * <pre>
   * JavaPolicies *JavaDomainListView::copyPolicies(Policies *pol) {
   *   return new JavaPolicies(*static_cast<JavaPolicies *>(pol));
   * }
   * </pre>
   * @param pol policies object to be copied
   */
  virtual Policies *copyPolicies(Policies *pol) = 0;

  /**
   * allows derived classes to customize the policy dialog.
   *
   * The default implementation does nothing.
   * @param trigger triggered by which button
   * @param pDlg reference to policy dialog
   * @param copy policies object this dialog is used for changing. Derived
   *	classes can safely cast the @p copy object to the same type they
   *	returned in their createPolicies implementation.
   */
  virtual void setupPolicyDlg(PushButton trigger,PolicyDialog &pDlg,
  		Policies *copy);

private slots:
  void addPressed();
  void changePressed();
  void deletePressed();
  void importPressed();
  void exportPressed();
    void updateButton();

protected:

    KConfig *config;

  KListView *domainSpecificLV;

  TQPushButton* addDomainPB;
  TQPushButton* changeDomainPB;
  TQPushButton* deleteDomainPB;
  TQPushButton* importDomainPB;
  TQPushButton* exportDomainPB;

  typedef TQMap<TQListViewItem*, Policies *> DomainPolicyMap;
  DomainPolicyMap domainPolicies;
};

#endif		// __DOMAINLISTVIEW_H__