messagecopyhelper.cpp
00001 /* 00002 Copyright (c) 2007 Volker Krause <vkrause@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #include "messagecopyhelper.h" 00021 00022 #include "kmcommands.h" 00023 #include "kmfolder.h" 00024 #include "kmmsgdict.h" 00025 00026 using namespace KMail; 00027 using namespace KPIM; 00028 00029 MessageCopyHelper::MessageCopyHelper( const TQValueList< TQ_UINT32 > & msgs, 00030 KMFolder * dest, bool move, TQObject * parent ) : 00031 TQObject( parent ) 00032 { 00033 if ( msgs.isEmpty() || !dest ) 00034 return; 00035 00036 KMFolder *f = 0; 00037 int index; 00038 TQPtrList<KMMsgBase> list; 00039 00040 for ( TQValueList<TQ_UINT32>::ConstIterator it = msgs.constBegin(); it != msgs.constEnd(); ++it ) { 00041 KMMsgDict::instance()->getLocation( *it, &f, &index ); 00042 if ( !f ) // not found 00043 continue; 00044 if ( f == dest ) 00045 continue; // already there 00046 if ( !mOpenFolders.contains( f ) ) {// not yet opened 00047 f->open( "messagecopyhelper" ); 00048 mOpenFolders.insert( f, 0 ); 00049 } 00050 KMMsgBase *msgBase = f->getMsgBase( index ); 00051 if ( msgBase ) 00052 list.append( msgBase ); 00053 } 00054 00055 if ( list.isEmpty() ) 00056 return; // nothing to do 00057 00058 KMCommand *command; 00059 if ( move ) { 00060 command = new KMMoveCommand( dest, list ); 00061 } else { 00062 command = new KMCopyCommand( dest, list ); 00063 } 00064 00065 connect( command, TQT_SIGNAL(completed(KMCommand*)), TQT_SLOT(copyCompleted(KMCommand*)) ); 00066 command->start(); 00067 } 00068 00069 void MessageCopyHelper::copyCompleted(KMCommand * cmd) 00070 { 00071 Q_UNUSED( cmd ); 00072 00073 // close all folders we opened 00074 for ( TQMap<TQGuardedPtr<KMFolder>, int>::ConstIterator it = mOpenFolders.constBegin(); 00075 it != mOpenFolders.constEnd(); ++it ) { 00076 it.key()->close( "messagecopyhelper" ); 00077 } 00078 mOpenFolders.clear(); 00079 deleteLater(); 00080 } 00081 00082 TQValueList< TQ_UINT32 > MessageCopyHelper::serNumListFromMailList(const KPIM::MailList & list) 00083 { 00084 TQValueList<TQ_UINT32> rv; 00085 for ( MailList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it ) 00086 rv.append( (*it).serialNumber() ); 00087 return rv; 00088 } 00089 00090 TQValueList< TQ_UINT32 > MessageCopyHelper::serNumListFromMsgList(TQPtrList< KMMsgBase > list) 00091 { 00092 TQValueList<TQ_UINT32> rv; 00093 KMMsgBase* msg = list.first(); 00094 while( msg ) { 00095 rv.append( msg->getMsgSerNum() ); 00096 msg = list.next(); 00097 } 00098 return rv; 00099 } 00100 00101 bool MessageCopyHelper::inReadOnlyFolder(const TQValueList< TQ_UINT32 > & sernums) 00102 { 00103 KMFolder *f = 0; 00104 int index; 00105 for ( TQValueList<TQ_UINT32>::ConstIterator it = sernums.begin(); it != sernums.end(); ++it ) { 00106 KMMsgDict::instance()->getLocation( *it, &f, &index ); 00107 if ( !f ) // not found 00108 continue; 00109 if ( f->isReadOnly() ) 00110 return true; 00111 } 00112 return false; 00113 } 00114 00115 #include "messagecopyhelper.moc"