21 #ifndef KMAIL_SIMPLEFOLDERTREE_H
22 #define KMAIL_SIMPLEFOLDERTREE_H
25 #include "kmfoldertree.h"
29 #include <tdelistview.h>
30 #include <tdepopupmenu.h>
31 #include <kiconloader.h>
38 static int recurseFilter( TQListViewItem * item,
const TQString& filter,
int column )
43 TQListViewItem * child;
44 child = item->firstChild();
48 enabled += recurseFilter( child, filter, column );
49 child = child->nextSibling();
52 if ( filter.length() == 0 ||
53 item->text( column ).find( filter, 0,
false ) >= 0 ) {
54 item->setVisible(
true );
58 item->setVisible( !!enabled );
59 item->setEnabled(
false );
71 kdDebug(5006) << k_funcinfo << endl;
73 virtual ~TreeItemBase() { }
75 void setFolder(
KMFolder * folder ) { mFolder = folder; };
76 const KMFolder * folder() {
return mFolder; };
79 void setAlternate (
bool alternate ) {
80 mAlternate = alternate;
89 template <
class T>
class SimpleFolderTreeItem :
public T,
public TreeItemBase
92 SimpleFolderTreeItem( TQListView * listView ) :
93 T( listView ), TreeItemBase()
95 kdDebug(5006) << k_funcinfo << endl;
97 SimpleFolderTreeItem( TQListView * listView, TQListViewItem * afterListViewItem ) :
98 T( listView, afterListViewItem ) , TreeItemBase()
100 kdDebug(5006) << k_funcinfo << endl;
102 SimpleFolderTreeItem( TQListViewItem * listViewItem ) : T( listViewItem ) , TreeItemBase()
104 kdDebug(5006) << k_funcinfo << endl;
107 SimpleFolderTreeItem( TQListViewItem * listViewItem, TQListViewItem * afterListViewItem ) :
108 T( listViewItem, afterListViewItem ) , TreeItemBase()
110 kdDebug(5006) << k_funcinfo << endl;
115 template <>
class SimpleFolderTreeItem<TQCheckListItem> :
public TQCheckListItem,
public TreeItemBase
118 SimpleFolderTreeItem( TQListView * listView ) :
119 TQCheckListItem( listView, TQString(), CheckBox ), TreeItemBase() {}
120 SimpleFolderTreeItem( TQListView * listView, TQListViewItem * afterListViewItem ) :
121 TQCheckListItem( listView, afterListViewItem, TQString(), CheckBox ), TreeItemBase() {}
122 SimpleFolderTreeItem( TQListViewItem * listViewItem ) :
123 TQCheckListItem( listViewItem, TQString(), CheckBox ) {}
124 SimpleFolderTreeItem( TQListViewItem * listViewItem, TQListViewItem * afterListViewItem ) :
125 TQCheckListItem( listViewItem, afterListViewItem, TQString(), CheckBox ) {}
130 template <
class T>
class SimpleFolderTreeBase :
public TreeBase
136 inline SimpleFolderTreeBase( TQWidget * parent, KMFolderTree *folderTree,
137 const TQString &preSelection,
bool mustBeReadWrite )
138 : TreeBase( parent, folderTree, preSelection, mustBeReadWrite )
140 assert( folderTree );
141 setFolderColumn( addColumn( i18n(
"Folder" ) ) );
142 setPathColumn( addColumn( i18n(
"Path" ) ) );
144 setRootIsDecorated(
true );
147 reload( mustBeReadWrite,
true,
true, preSelection );
151 virtual SimpleFolderTreeItem<T>* createItem( TQListView * parent )
153 return new SimpleFolderTreeItem<T>( parent );
156 virtual SimpleFolderTreeItem<T>* createItem( TQListView * parent, TQListViewItem* afterListViewItem )
158 return new SimpleFolderTreeItem<T>( parent, afterListViewItem );
161 virtual SimpleFolderTreeItem<T>* createItem( TQListViewItem * parent, TQListViewItem* afterListViewItem )
163 return new SimpleFolderTreeItem<T>( parent, afterListViewItem );
166 virtual SimpleFolderTreeItem<T>* createItem( TQListViewItem * parent )
168 return new SimpleFolderTreeItem<T>( parent );
171 inline void keyPressEvent( TQKeyEvent *e )
173 const char ascii = e->ascii();
174 if ( ascii == 8 || ascii == 127 ) {
175 if ( mFilter.length() > 0 ) {
176 mFilter.truncate( mFilter.length()-1 );
177 applyFilter( mFilter );
179 }
else if ( !e->text().isEmpty() && e->text().length() == 1 && e->text().at( 0 ).isPrint() ) {
180 applyFilter( mFilter + e->text() );
182 TDEListView::keyPressEvent( e );
186 void applyFilter(
const TQString& filter )
188 kdDebug(5006) << k_funcinfo << filter << endl ;
190 TQListViewItemIterator clean(
this );
191 while ( clean.current() ) {
192 TQListViewItem * item = clean.current();
193 item->setEnabled(
true );
194 item->setVisible(
true );
195 item->setOpen(
true );
201 if ( filter.isEmpty() ) {
202 setColumnText( pathColumn(), i18n(
"Path") );
209 TQListViewItemIterator it(
this );
210 while ( it.current() ) {
211 TQListViewItem * item = it.current();
212 if ( item->depth() <= 0 )
213 recurseFilter( item, filter, pathColumn() );
221 TQListViewItemIterator first (
this );
222 while ( first.current() ) {
223 SimpleFolderTreeItem<T> * item =
static_cast< SimpleFolderTreeItem<T> *
>( first.current() );
225 if ( item->isVisible() && item->isSelectable() ) {
226 setSelected( item,
true );
227 ensureItemVisible( item );
235 if ( filter.length() > 0 )
236 setColumnText( pathColumn(), i18n(
"Path") +
" ( " + filter +
" )" );
238 setColumnText( pathColumn(), i18n(
"Path") );
245 typedef SimpleFolderTreeBase<TDEListViewItem> SimpleFolderTree;