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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
/*
Copyright (c) 2007 Volker Krause <vkrause@kde.org>
Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
Copyright (c) Stefan Taferner <taferner@kde.org>
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 KMAIL_SIMPLEFOLDERTREE_H
#define KMAIL_SIMPLEFOLDERTREE_H
#include "kmfolder.h"
#include "kmfoldertree.h"
#include "treebase.h"
#include <kdebug.h>
#include <klistview.h>
#include <kpopupmenu.h>
#include <kiconloader.h>
class KMFolder;
class KMFolderTree;
namespace KMail {
static int recurseFilter( TQListViewItem * item, const TQString& filter, int column )
{
if ( item == 0 )
return 0;
TQListViewItem * child;
child = item->firstChild();
int enabled = 0;
while ( child ) {
enabled += recurseFilter( child, filter, column );
child = child->nextSibling();
}
if ( filter.length() == 0 ||
item->text( column ).find( filter, 0, false ) >= 0 ) {
item->setVisible( true );
++enabled;
}
else {
item->setVisible( !!enabled );
item->setEnabled( false );
}
return enabled;
}
class TreeItemBase
{
public :
TreeItemBase()
: mFolder( 0 )
{
kdDebug(5006) << k_funcinfo << endl;
}
virtual ~TreeItemBase() { }
void setFolder( KMFolder * folder ) { mFolder = folder; };
const KMFolder * folder() { return mFolder; };
// Set the flag which determines if this is an alternate row
void setAlternate ( bool alternate ) {
mAlternate = alternate;
}
private:
KMFolder * mFolder;
bool mAlternate;
};
template <class T> class SimpleFolderTreeItem : public T, public TreeItemBase
{
public:
SimpleFolderTreeItem( TQListView * listView ) :
T( listView ), TreeItemBase()
{
kdDebug(5006) << k_funcinfo << endl;
}
SimpleFolderTreeItem( TQListView * listView, TQListViewItem * afterListViewItem ) :
T( listView, afterListViewItem ) , TreeItemBase()
{
kdDebug(5006) << k_funcinfo << endl;
}
SimpleFolderTreeItem( TQListViewItem * listViewItem ) : T( listViewItem ) , TreeItemBase()
{
kdDebug(5006) << k_funcinfo << endl;
}
SimpleFolderTreeItem( TQListViewItem * listViewItem, TQListViewItem * afterListViewItem ) :
T( listViewItem, afterListViewItem ) , TreeItemBase()
{
kdDebug(5006) << k_funcinfo << endl;
}
};
template <> class SimpleFolderTreeItem<TQCheckListItem> : public TQCheckListItem, public TreeItemBase
{
public:
SimpleFolderTreeItem( TQListView * listView ) :
TQCheckListItem( listView, TQString(), CheckBox ), TreeItemBase() {}
SimpleFolderTreeItem( TQListView * listView, TQListViewItem * afterListViewItem ) :
TQCheckListItem( listView, afterListViewItem, TQString(), CheckBox ), TreeItemBase() {}
SimpleFolderTreeItem( TQListViewItem * listViewItem ) :
TQCheckListItem( listViewItem, TQString(), CheckBox ) {}
SimpleFolderTreeItem( TQListViewItem * listViewItem, TQListViewItem * afterListViewItem ) :
TQCheckListItem( listViewItem, afterListViewItem, TQString(), CheckBox ) {}
};
template <class T> class SimpleFolderTreeBase : public TreeBase
{
public:
inline SimpleFolderTreeBase( TQWidget * parent, KMFolderTree *folderTree,
const TQString &preSelection, bool mustBeReadWrite )
: TreeBase( parent, folderTree, preSelection, mustBeReadWrite )
{
assert( folderTree );
setFolderColumn( addColumn( i18n( "Folder" ) ) );
setPathColumn( addColumn( i18n( "Path" ) ) );
setRootIsDecorated( true );
setSorting( -1 );
reload( mustBeReadWrite, true, true, preSelection );
}
virtual SimpleFolderTreeItem<T>* createItem( TQListView * parent )
{
return new SimpleFolderTreeItem<T>( parent );
}
virtual SimpleFolderTreeItem<T>* createItem( TQListView * parent, TQListViewItem* afterListViewItem )
{
return new SimpleFolderTreeItem<T>( parent, afterListViewItem );
}
virtual SimpleFolderTreeItem<T>* createItem( TQListViewItem * parent, TQListViewItem* afterListViewItem )
{
return new SimpleFolderTreeItem<T>( parent, afterListViewItem );
}
virtual SimpleFolderTreeItem<T>* createItem( TQListViewItem * parent )
{
return new SimpleFolderTreeItem<T>( parent );
}
inline void keyPressEvent( TQKeyEvent *e )
{
const char ascii = e->ascii();
if ( ascii == 8 || ascii == 127 ) {
if ( mFilter.length() > 0 ) {
mFilter.truncate( mFilter.length()-1 );
applyFilter( mFilter );
}
} else if ( !e->text().isEmpty() && e->text().length() == 1 && e->text().at( 0 ).isPrint() ) {
applyFilter( mFilter + e->text() );
} else {
TDEListView::keyPressEvent( e );
}
}
void applyFilter( const TQString& filter )
{
kdDebug(5006) << k_funcinfo << filter << endl ;
// Reset all items to visible, enabled, and open
TQListViewItemIterator clean( this );
while ( clean.current() ) {
TQListViewItem * item = clean.current();
item->setEnabled( true );
item->setVisible( true );
item->setOpen( true );
++clean;
}
mFilter = filter;
if ( filter.isEmpty() ) {
setColumnText( pathColumn(), i18n("Path") );
return;
}
// Set the visibility and enabled status of each list item.
// The recursive algorithm is necessary because visiblity
// changes are automatically applied to child nodes by TQt.
TQListViewItemIterator it( this );
while ( it.current() ) {
TQListViewItem * item = it.current();
if ( item->depth() <= 0 )
recurseFilter( item, filter, pathColumn() );
++it;
}
// Recolor the rows appropriately
recolorRows();
// Iterate through the list to find the first selectable item
TQListViewItemIterator first ( this );
while ( first.current() ) {
SimpleFolderTreeItem<T> * item = static_cast< SimpleFolderTreeItem<T> * >( first.current() );
if ( item->isVisible() && item->isSelectable() ) {
setSelected( item, true );
ensureItemVisible( item );
break;
}
++first;
}
// Display and save the current filter
if ( filter.length() > 0 )
setColumnText( pathColumn(), i18n("Path") + " ( " + filter + " )" );
else
setColumnText( pathColumn(), i18n("Path") );
mFilter = filter;
}
};
typedef SimpleFolderTreeBase<TDEListViewItem> SimpleFolderTree;
}
#endif
|