kmail

messagecopyhelper.cpp
1/*
2 Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "messagecopyhelper.h"
21
22#include "kmcommands.h"
23#include "kmfolder.h"
24#include "kmmsgdict.h"
25
26using namespace KMail;
27using namespace KPIM;
28
29MessageCopyHelper::MessageCopyHelper( const TQValueList< TQ_UINT32 > & msgs,
30 KMFolder * dest, bool move, TQObject * parent ) :
31 TQObject( parent )
32{
33 if ( msgs.isEmpty() || !dest )
34 return;
35
36 KMFolder *f = 0;
37 int index;
38 TQPtrList<KMMsgBase> list;
39
40 for ( TQValueList<TQ_UINT32>::ConstIterator it = msgs.constBegin(); it != msgs.constEnd(); ++it ) {
41 KMMsgDict::instance()->getLocation( *it, &f, &index );
42 if ( !f ) // not found
43 continue;
44 if ( f == dest )
45 continue; // already there
46 if ( !mOpenFolders.contains( f ) ) {// not yet opened
47 f->open( "messagecopyhelper" );
48 mOpenFolders.insert( f, 0 );
49 }
50 KMMsgBase *msgBase = f->getMsgBase( index );
51 if ( msgBase )
52 list.append( msgBase );
53 }
54
55 if ( list.isEmpty() )
56 return; // nothing to do
57
58 KMCommand *command;
59 if ( move ) {
60 command = new KMMoveCommand( dest, list );
61 } else {
62 command = new KMCopyCommand( dest, list );
63 }
64
65 connect( command, TQ_SIGNAL(completed(KMCommand*)), TQ_SLOT(copyCompleted(KMCommand*)) );
66 command->start();
67}
68
69void MessageCopyHelper::copyCompleted(KMCommand * cmd)
70{
71 Q_UNUSED( cmd );
72
73 // close all folders we opened
74 for ( TQMap<TQGuardedPtr<KMFolder>, int>::ConstIterator it = mOpenFolders.constBegin();
75 it != mOpenFolders.constEnd(); ++it ) {
76 it.key()->close( "messagecopyhelper" );
77 }
78 mOpenFolders.clear();
79 deleteLater();
80}
81
82TQValueList< TQ_UINT32 > MessageCopyHelper::serNumListFromMailList(const KPIM::MailList & list)
83{
84 TQValueList<TQ_UINT32> rv;
85 for ( MailList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
86 rv.append( (*it).serialNumber() );
87 return rv;
88}
89
90TQValueList< TQ_UINT32 > MessageCopyHelper::serNumListFromMsgList(TQPtrList< KMMsgBase > list)
91{
92 TQValueList<TQ_UINT32> rv;
93 KMMsgBase* msg = list.first();
94 while( msg ) {
95 rv.append( msg->getMsgSerNum() );
96 msg = list.next();
97 }
98 return rv;
99}
100
101bool MessageCopyHelper::inReadOnlyFolder(const TQValueList< TQ_UINT32 > & sernums)
102{
103 KMFolder *f = 0;
104 int index;
105 for ( TQValueList<TQ_UINT32>::ConstIterator it = sernums.begin(); it != sernums.end(); ++it ) {
106 KMMsgDict::instance()->getLocation( *it, &f, &index );
107 if ( !f ) // not found
108 continue;
109 if ( f->isReadOnly() )
110 return true;
111 }
112 return false;
113}
114
115#include "messagecopyhelper.moc"
Mail folder.
Definition: kmfolder.h:69
const KMMsgBase * getMsgBase(int idx) const
Provides access to the basic message fields that are also stored in the index.
Definition: kmfolder.cpp:360
int open(const char *owner)
Open folder for access.
Definition: kmfolder.cpp:479
bool isReadOnly() const
Is the folder read-only?
Definition: kmfolder.cpp:561
void getLocation(unsigned long key, KMFolder **retFolder, int *retIndex) const
Returns the folder the message represented by the serial number key is in and the index in that folde...
Definition: kmmsgdict.cpp:319
static const KMMsgDict * instance()
Access the globally unique MessageDict.
Definition: kmmsgdict.cpp:167
static bool inReadOnlyFolder(const TQValueList< TQ_UINT32 > &sernums)
Checks of any of the given messages comes from a read-only source.
static TQValueList< TQ_UINT32 > serNumListFromMsgList(TQPtrList< KMMsgBase > list)
Converts a KMMsgsBase* list into a serial number list.
static TQValueList< TQ_UINT32 > serNumListFromMailList(const KPIM::MailList &list)
Converts a MailList into a serial number list.
folderdiaquotatab.h
Definition: aboutdata.cpp:40