22 #include "kmfoldertree.h"
23 #include "simplefoldertree.h"
26 #include <tdelistview.h>
28 using namespace KMail;
30 TreeBase::TreeBase( TQWidget *parent, KMFolderTree *folderTree,
31 const TQString &preSelection,
bool mustBeReadWrite )
32 : TDEListView( parent ), mFolderTree( folderTree )
34 Q_UNUSED( preSelection );
35 Q_UNUSED( mustBeReadWrite );
36 kdDebug(5006) << k_funcinfo << endl;
38 connect(
this, TQ_SIGNAL(collapsed(TQListViewItem*)), TQ_SLOT(recolorRows()));
39 connect(
this, TQ_SIGNAL(expanded(TQListViewItem*)), TQ_SLOT(recolorRows()));
40 connect(
this, TQ_SIGNAL( contextMenuRequested( TQListViewItem*,
const TQPoint &,
int ) ),
41 this, TQ_SLOT( slotContextMenuRequested( TQListViewItem*,
const TQPoint & ) ) );
45 const KMFolder * TreeBase::folder()
const
47 TQListViewItem * item = currentItem();
49 TreeItemBase *base =
dynamic_cast<TreeItemBase*
>( item );
51 const KMFolder * folder = base->folder();
57 void TreeBase::setFolder(
KMFolder *folder )
59 for ( TQListViewItemIterator it(
this ) ; it.current() ; ++it )
61 const KMFolder *fld =
dynamic_cast<TreeItemBase*
>( it.current() )->folder();
64 setSelected( it.current(),
true );
65 ensureItemVisible( it.current() );
70 void TreeBase::addChildFolder()
72 kdDebug(5006) << k_funcinfo << endl;
76 mFolderTree->addChildFolder( (
KMFolder *) fld, parentWidget() );
77 reload( mLastMustBeReadWrite, mLastShowOutbox, mLastShowImapFolders );
82 void TreeBase::slotContextMenuRequested( TQListViewItem *lvi,
const TQPoint &p )
84 kdDebug(5006) << k_funcinfo << endl;
88 setCurrentItem( lvi );
89 setSelected( lvi, TRUE );
91 const KMFolder * folder =
dynamic_cast<TreeItemBase*
>( lvi )->folder();
95 TDEPopupMenu *folderMenu =
new TDEPopupMenu;
96 folderMenu->insertTitle( folder->
label() );
97 folderMenu->insertSeparator();
98 folderMenu->insertItem(SmallIconSet(
"folder-new"),
99 i18n(
"&New Subfolder..."),
this,
100 TQ_SLOT(addChildFolder()));
101 kmkernel->setContextMenuShown(
true );
102 folderMenu->exec (p, 0);
103 kmkernel->setContextMenuShown(
false );
108 void TreeBase::recolorRows()
110 kdDebug(5006) << k_funcinfo << endl;
114 TQListViewItemIterator it (
this );
115 while ( it.current() ) {
116 TQListViewItem * item = it.current() ;
117 if ( item->isVisible() ) {
119 TQListViewItem * parent = item->parent();
121 if (!parent->isOpen()) {
125 parent = parent->parent();
129 TreeItemBase * treeItemBase =
dynamic_cast<TreeItemBase*
>( item );
130 treeItemBase->setAlternate( alt );
138 void TreeBase::reload(
bool mustBeReadWrite,
bool showOutbox,
bool showImapFolders,
139 const TQString& preSelection )
143 mLastMustBeReadWrite = mustBeReadWrite;
144 mLastShowOutbox = showOutbox;
145 mLastShowImapFolders = showImapFolders;
147 TQListViewItem * lastItem = 0;
148 TQListViewItem * lastTopItem = 0;
149 TQListViewItem * selectedItem = 0;
155 for ( TQListViewItemIterator it( mFolderTree ) ; it.current() ; ++it ) {
156 KMFolderTreeItem * fti =
dynamic_cast<KMFolderTreeItem *
>( it.current() );
158 if ( !fti || fti->protocol() == KFolderTreeItem::Search )
161 int depth = fti->depth();
164 TQListViewItem * item = 0;
168 item = createItem(
this, lastTopItem );
170 item = createItem(
this );
176 if ( depth > lastDepth ) {
178 item = createItem( lastItem );
179 lastItem->setOpen(
true );
183 path = path.section(
'/', 0, -2 - (lastDepth-depth) );
184 if ( depth == lastDepth )
186 item = createItem( lastItem->parent(), lastItem );
187 else if ( depth < lastDepth ) {
190 while ( ( depth <= --lastDepth ) && lastItem->parent() ) {
191 lastItem =
static_cast<TQListViewItem *
>( lastItem->parent() );
193 if ( lastItem->parent() )
194 item = createItem( lastItem->parent(), lastItem );
197 kdDebug( 5006 ) <<
"You shouldn't get here: depth=" << depth
198 <<
"folder name=" << fti->text( 0 ) << endl;
199 item = createItem(
this );
208 path += fti->text( 0 );
211 item->setText( mFolderColumn, fti->text( 0 ) );
212 item->setText( mPathColumn, path );
215 if ( !fti->folder() || depth == 0 || ( mustBeReadWrite && fti->folder()->isReadOnly() ) ) {
216 item->setSelectable(
false );
218 TreeItemBase * treeItemBase =
dynamic_cast<TreeItemBase*
>( item );
219 assert(treeItemBase);
220 treeItemBase->setFolder( fti->folder() );
221 if ( preSelection == treeItemBase->folder()->idString() )
228 if ( selectedItem ) {
229 setSelected( selectedItem,
true );
230 ensureItemVisible( selectedItem );
235 #include "treebase.moc"
virtual TQString label() const
Returns the label of the folder for visualization.
bool noChildren() const
Returns, if the folder can't have children.
bool noContent() const
Returns, if the folder can't contain mails, but only subfolder.