~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kmail/messagecopyhelper.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
26
 
using namespace KMail;
27
 
using namespace KPIM;
28
 
 
29
 
MessageCopyHelper::MessageCopyHelper( const QList<quint32> & msgs,
30
 
                                      KMFolder * dest, bool move, QObject * parent ) :
31
 
    QObject( parent )
32
 
{
33
 
  if ( msgs.isEmpty() || !dest )
34
 
    return;
35
 
 
36
 
  KMFolder *f = 0;
37
 
  int index;
38
 
  QList<KMMsgBase*> list;
39
 
 
40
 
  for ( QList<quint32>::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( "messagecopy" );
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, SIGNAL(completed(KMCommand*)), SLOT(copyCompleted(KMCommand*)) );
66
 
  command->start();
67
 
}
68
 
 
69
 
void MessageCopyHelper::copyCompleted(KMCommand * cmd)
70
 
{
71
 
  Q_UNUSED( cmd );
72
 
 
73
 
  // close all folders we opened
74
 
  for ( QMap<QPointer<KMFolder>, int>::ConstIterator it = mOpenFolders.constBegin();
75
 
        it != mOpenFolders.constEnd(); ++it ) {
76
 
    it.key()->close( "messagecopy" );
77
 
  }
78
 
  mOpenFolders.clear();
79
 
  deleteLater();
80
 
}
81
 
 
82
 
QList<quint32> MessageCopyHelper::serNumListFromMailList(const KPIM::MailList & list)
83
 
{
84
 
  QList<quint32> rv;
85
 
  for ( MailList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
86
 
    rv.append( (*it).serialNumber() );
87
 
  return rv;
88
 
}
89
 
 
90
 
QList<quint32> MessageCopyHelper::serNumListFromMsgList(QList<KMMsgBase*> list)
91
 
{
92
 
  QList<quint32> rv;
93
 
  foreach ( KMMsgBase *msg, list )
94
 
    if ( msg )
95
 
      rv.append( msg->getMsgSerNum() );
96
 
  return rv;
97
 
}
98
 
 
99
 
bool MessageCopyHelper::inReadOnlyFolder(const QList< quint32 > & sernums)
100
 
{
101
 
  KMFolder *f = 0;
102
 
  int index;
103
 
  for ( QList<quint32>::ConstIterator it = sernums.begin(); it != sernums.end(); ++it ) {
104
 
    KMMsgDict::instance()->getLocation( *it, &f, &index );
105
 
    if ( !f ) // not found
106
 
      continue;
107
 
    if ( f->isReadOnly() )
108
 
      return true;
109
 
  }
110
 
  return false;
111
 
}
112
 
 
113
 
KMFolder * MessageCopyHelper::firstSourceFolder( const QList<quint32> &sernums )
114
 
{
115
 
  KMFolder *f = 0;
116
 
  int index;
117
 
  for ( QList<quint32>::ConstIterator it = sernums.begin(); it != sernums.end(); ++it ) {
118
 
    KMMsgDict::instance()->getLocation( *it, &f, &index );
119
 
    if ( !f ) // not found
120
 
      continue;
121
 
    return f;
122
 
  }
123
 
  return 0;
124
 
}
125
 
 
126
 
 
127
 
#include "messagecopyhelper.moc"