kmail

foldersetselector.cpp

00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "foldersetselector.h"
00020 
00021 #include "globalsettings.h"
00022 #include "kmfoldertree.h"
00023 #include "simplefoldertree.h"
00024 #include "kmfoldercachedimap.h"
00025 
00026 #include <tqvbox.h>
00027 
00028 using namespace KMail;
00029 
00030 FolderSetSelector::FolderSetSelector( KMFolderTree *ft, TQWidget * parent )
00031   : KDialogBase( parent, "FolderSetSelector", true, TQString(), Ok|Cancel, Ok, true )
00032 {
00033   assert( ft );
00034 
00035   mTreeView = new KMail::SimpleFolderTreeBase<TQCheckListItem>( makeVBoxMainWidget(), ft,
00036       GlobalSettings::self()->lastSelectedFolder(), false );
00037   mTreeView->setFocus();
00038 
00039   TQListViewItemIterator it( mTreeView );
00040   while ( it.current() ) {
00041     SimpleFolderTreeItem<TQCheckListItem> *item = dynamic_cast<SimpleFolderTreeItem<TQCheckListItem>*>( it.current() );
00042     ++it;
00043     if ( !item )
00044       continue;
00045     if ( !item->folder() ) {
00046       item->setEnabled( false );
00047       continue;
00048     }
00049     if ( item->folder()->folderType() == KMFolderTypeCachedImap
00050          && static_cast<const KMFolderCachedImap*>( item->folder()->storage() )->imapPath() == "/INBOX/" ) {
00051         item->setOn( true );
00052     }
00053     if ( item->folder()->folderType() != KMFolderTypeCachedImap ) {
00054       item->setEnabled( false );
00055     }
00056   }
00057 
00058 }
00059 
00060 TQValueList< int > FolderSetSelector::selectedFolders()
00061 {
00062   TQValueList<int> rv;
00063   TQListViewItemIterator it( mTreeView );
00064   while ( it.current() ) {
00065     SimpleFolderTreeItem<TQCheckListItem> *item = dynamic_cast<SimpleFolderTreeItem<TQCheckListItem>*>( it.current() );
00066     if ( item && item->isOn() && item->folder() )
00067       rv.append( item->folder()->id() );
00068     ++it;
00069   }
00070   return rv;
00071 }
00072 
00073 void FolderSetSelector::setSelectedFolders(const TQValueList< int > & folderIds)
00074 {
00075   TQListViewItemIterator it( mTreeView );
00076   while ( it.current() ) {
00077     SimpleFolderTreeItem<TQCheckListItem> *item = dynamic_cast<SimpleFolderTreeItem<TQCheckListItem>*>( it.current() );
00078     if ( item && item->folder() ) {
00079       if ( folderIds.contains( item->folder()->id() ) )
00080         item->setOn( true );
00081       else
00082         item->setOn( false );
00083     }
00084     ++it;
00085   }
00086 }
00087 
00088 #include "foldersetselector.moc"