kmail
messagecopyhelper.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 QValueList< Q_UINT32 > & msgs,
00030 KMFolder * dest, bool move, QObject * parent ) :
00031 QObject( parent )
00032 {
00033 if ( msgs.isEmpty() || !dest )
00034 return;
00035
00036 KMFolder *f = 0;
00037 int index;
00038 QPtrList<KMMsgBase> list;
00039
00040 for ( QValueList<Q_UINT32>::ConstIterator it = msgs.constBegin(); it != msgs.constEnd(); ++it ) {
00041 KMMsgDict::instance()->getLocation( *it, &f, &index );
00042 if ( !f )
00043 continue;
00044 if ( f == dest )
00045 continue;
00046 if ( !mOpenFolders.contains( f ) ) {
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;
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, SIGNAL(completed(KMCommand*)), SLOT(copyCompleted(KMCommand*)) );
00066 command->start();
00067 }
00068
00069 void MessageCopyHelper::copyCompleted(KMCommand * cmd)
00070 {
00071 Q_UNUSED( cmd );
00072
00073
00074 for ( QMap<QGuardedPtr<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 QValueList< Q_UINT32 > MessageCopyHelper::serNumListFromMailList(const KPIM::MailList & list)
00083 {
00084 QValueList<Q_UINT32> rv;
00085 for ( MailList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
00086 rv.append( (*it).serialNumber() );
00087 return rv;
00088 }
00089
00090 QValueList< Q_UINT32 > MessageCopyHelper::serNumListFromMsgList(QPtrList< KMMsgBase > list)
00091 {
00092 QValueList<Q_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 QValueList< Q_UINT32 > & sernums)
00102 {
00103 KMFolder *f = 0;
00104 int index;
00105 for ( QValueList<Q_UINT32>::ConstIterator it = sernums.begin(); it != sernums.end(); ++it ) {
00106 KMMsgDict::instance()->getLocation( *it, &f, &index );
00107 if ( !f )
00108 continue;
00109 if ( f->isReadOnly() )
00110 return true;
00111 }
00112 return false;
00113 }
00114
00115 #include "messagecopyhelper.moc"
|