2 This file is part of libkdepim.
4 Copyright (C) 2002 Carsten Burghardt <burghardt@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
23 This file defines a generic subscription widget and some support classes.
26 #ifndef KDEPIM_KSUBSCRIPTION_H
27 #define KDEPIM_KSUBSCRIPTION_H
29 #include "kdepim_export.h"
34 #include <QTreeWidget>
46 //==========================================================================
48 class KDEPIM_EXPORT KGroupInfo
58 explicit KGroupInfo( const QString
&name
,
59 const QString
&description
= QString(),
60 bool newGroup
= false, bool subscribed
= false,
61 Status status
= unknown
,
62 const QString
&path
= QString() );
64 QString name
, description
;
65 bool newGroup
, subscribed
;
69 bool operator== ( const KGroupInfo
&gi2
);
70 bool operator< ( const KGroupInfo
&gi2
);
74 //==========================================================================
76 /** A class representing a single group item (what's that?) */
77 class KDEPIM_EXPORT GroupItem
: public QObject
, public QTreeWidgetItem
82 GroupItem( QTreeWidget
*v
, const KGroupInfo
&gi
, KSubscription
*browser
,
83 bool isCheckItem
= false );
84 GroupItem( QTreeWidgetItem
*i
, const KGroupInfo
&gi
, KSubscription
*browser
,
85 bool isCheckItem
= false );
88 * Get/Set the KGroupInfo
90 KGroupInfo
info() { return mInfo
; }
91 void setInfo( KGroupInfo info
);
94 * Get/Set the original parent
96 QTreeWidgetItem
*originalParent() { return mOriginalParent
; }
97 void setOriginalParent( QTreeWidgetItem
*parent
) { mOriginalParent
= parent
; }
100 * Get/Set the last open state
102 bool lastOpenState() { return mLastOpenState
; }
103 void setLastOpenState( bool last
) { mLastOpenState
= last
; }
106 * Sets the description from the KGroupInfo
107 * Reimplement this for special cases
109 virtual void setDescription();
112 * Get if this is a checkable item
114 bool isCheckItem() const { return mIsCheckItem
; }
117 * Get/Set if state changes should be ignored
119 bool ignoreStateChange() { return mIgnoreStateChange
; }
120 void setIgnoreStateChange( bool ignore
) { mIgnoreStateChange
= ignore
; }
123 * Sets the subscribed property (only while items are loaded)
125 void setOn( bool on
);
130 * Sets items invisible or disabled or even moves them
132 void setVisible( bool b
);
137 * Calls KSubscription::changeItemState if mIgnoreStateChange == false
139 void stateChange( QTreeWidgetItem
* item
);
143 static const int customType
= 15689;
145 KSubscription
*mBrowser
;
146 QTreeWidgetItem
*mOriginalParent
;
147 // remember last open state
149 bool mLastCheckState
;
150 // is this a checkable item
152 // ignore state changes
153 bool mIgnoreStateChange
;
156 //==========================================================================
159 * This class provides a generic subscription widget
160 * The dialog itself has a main listview that holds all items and two listviews that
161 * show all changes. The user can change the state of the items via checkable items.
162 * When you construct a new instance you need to provide an account and a caption
163 * After inserting your items (checkable or not) you need to call slotLoadingComplete()
164 * You should at least connect slots to the signals okClicked() (to save your changes)
165 * and user1Clicked() (to reload the list)
166 * You can hide unwanted checkboxes via the respective hide<checkboxname> methods
169 class KDEPIM_EXPORT KSubscription
: public KDialog
175 * The direction of the buttons
182 KSubscription( QWidget
*parent
, const QString
&caption
, KAccount
*acct
,
183 KDialog::ButtonCodes buttons
= 0,
184 const QString
&user1
= QString(),
185 bool descriptionColumn
= true );
190 * Get/Set the account
192 KAccount
*account() { return mAcct
; }
193 void setAccount( KAccount
*acct
) { mAcct
= acct
; }
196 * Access to the treewidget that holds the GroupItems
198 QTreeWidget
*folderTree() { return groupView
; }
201 * Access to the searchfield
203 KLineEdit
*searchField() { return filterEdit
; }
206 * The item that should be selected on startup
208 void setStartItem( const KGroupInfo
&info
);
211 * Removes the item from the listview
213 void removeListItem( QTreeWidget
*view
, const KGroupInfo
&gi
);
216 * Gets the item from the listview
217 * Returns 0 if the item can't be found
219 QTreeWidgetItem
*getListItem( QTreeWidget
*view
, const KGroupInfo
&gi
);
222 * Is the item in the given listview
224 bool itemInListView( QTreeWidget
*view
, const KGroupInfo
&gi
);
227 * Makes all changes after an item is toggled
228 * called by the item's stateChange-method
230 void changeItemState( GroupItem
*item
, bool on
);
233 * Get/Set the direction of button1
235 Direction
directionButton1() { return mDirButton1
; }
236 void setDirectionButton1( Direction dir
);
239 * Get/Set the direction of button2
241 Direction
directionButton2() { return mDirButton2
; }
242 void setDirectionButton2( Direction dir
);
245 * Returns true if items are being constructed
246 * Call 'slotLoadingComplete' to switch this
248 bool isLoading() { return mLoading
; }
251 * Hide 'Disable tree view' checkbox
253 void hideTreeCheckbox() { noTreeCB
->hide(); }
256 * Hide 'New Only' checkbox
258 void hideNewOnlyCheckbox() { newCB
->hide(); }
261 * Update the item-states (visible, enabled) when a filter
264 void filterChanged( QTreeWidgetItem
*item
= 0,
265 const QString
&text
= QString() );
268 * The amount of items that are visible and enabled
270 int activeItemCount();
273 * Moves all items from toplevel back to their original position
275 void restoreOriginalParent();
278 * Saves the open states
280 void saveOpenStates();
283 * Restores the saved open state
285 void restoreOpenStates();
289 * Call this slot when you have created all items
291 void slotLoadingComplete();
294 * Changes the current state of the buttons
296 void slotChangeButtonState( QTreeWidgetItem
* );
299 * Buttons are clicked
305 * Updates the status-label
307 void slotUpdateStatusLabel();
310 * The reload-button is pressed
312 void slotLoadFolders();
316 * Slot for the checkboxes
318 void slotCBToggled();
321 * Filter text changed
323 void slotFilterTextChanged( const QString
&text
);
327 * Emitted when the amount of items in the
328 * groupView changes (e.g. on filtering)
338 QTreeWidget
*groupView
;
339 QTreeWidget
*subView
, *unsubView
;
340 KLineEdit
*filterEdit
;
341 QCheckBox
*noTreeCB
, *subCB
, *newCB
;
342 QPushButton
*arrowBtn1
, *arrowBtn2
;
343 QIcon pmRight
, pmLeft
;
345 QLabel
*leftLabel
, *rightLabel
;
347 // false if all items are loaded
351 Direction mDirButton1
;
352 Direction mDirButton2
;
354 // remember last searchtext