• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • misc
maillistdrag.cpp
Go to the documentation of this file.
1 /*
2  This file is part of libkdepim.
3 
4  Copyright (c) 2003 Don Sanders <sanders@kde.org>
5  Copyright (c) 2005 George Staikos <staikos@kde.org>
6  Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
7  Copyright (c) 2008 Thomas McGuire <mcguire@kde.org>
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Library General Public
11  License as published by the Free Software Foundation; either
12  version 2 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Library General Public License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to
21  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  Boston, MA 02110-1301, USA.
23 */
24 
25 #include "maillistdrag.h"
26 
27 #include <KDateTime>
28 #include <KLocale>
29 #include <KProgressDialog>
30 #include <KUrl>
31 
32 #include <QBuffer>
33 #include <QDataStream>
34 #include <QEventLoop>
35 #include <QProgressBar>
36 #include <QTextStream>
37 #include <QDropEvent>
38 
39 using namespace KPIM;
40 
41 
42 // Have to define before use
43 QDataStream& operator<< ( QDataStream &s, const MailSummary &d )
44 {
45  s << d.serialNumber();
46  s << d.messageId();
47  s << d.subject();
48  s << d.from();
49  s << d.to();
50  KDateTime tempTime;
51  tempTime.setTime_t( d.date() );
52  s << tempTime.dateTime();
53  return s;
54 }
55 
56 QDataStream& operator>> ( QDataStream &s, MailSummary &d )
57 {
58  quint32 serialNumber;
59  QString messageId, subject, from, to;
60  time_t date;
61  s >> serialNumber;
62  s >> messageId;
63  s >> subject;
64  s >> from;
65  s >> to;
66  QDateTime tempTime;
67  s >> tempTime;
68  date = KDateTime( tempTime ).toTime_t();
69  d.set( serialNumber, messageId, subject, from, to, date );
70  return s;
71 }
72 
73 QDataStream& operator<< ( QDataStream &s, const MailList &mailList )
74 {
75  MailList::const_iterator it;
76  MailList::const_iterator end( mailList.constEnd() );
77  for (it = mailList.constBegin(); it!=end; ++it) {
78  MailSummary mailDrag = *it;
79  s << mailDrag;
80  }
81  return s;
82 }
83 
84 QDataStream& operator>> ( QDataStream &s, MailList &mailList )
85 {
86  mailList.clear();
87  MailSummary mailDrag;
88  while (!s.atEnd()) {
89  s >> mailDrag;
90  mailList.append( mailDrag );
91  }
92  return s;
93 }
94 
95 MailSummary::MailSummary( quint32 serialNumber, const QString &messageId,
96  const QString &subject, const QString &from, const QString &to,
97  time_t date )
98  : mSerialNumber( serialNumber ), mMessageId( messageId ),
99  mSubject( subject ), mFrom( from ), mTo( to ), mDate( date )
100 {}
101 
102 quint32 MailSummary::serialNumber() const
103 {
104  return mSerialNumber;
105 }
106 
107 QString MailSummary::messageId() const
108 {
109  return mMessageId;
110 }
111 
112 QString MailSummary::subject() const
113 {
114  return mSubject;
115 }
116 
117 QString MailSummary::from() const
118 {
119  return mFrom;
120 }
121 
122 QString MailSummary::to() const
123 {
124  return mTo;
125 }
126 
127 time_t MailSummary::date() const
128 {
129  return mDate;
130 }
131 
132 void MailSummary::set( quint32 serialNumber, const QString &messageId,
133  const QString &subject, const QString &from, const QString &to, time_t date )
134 {
135  mSerialNumber = serialNumber;
136  mMessageId = messageId;
137  mSubject = subject;
138  mFrom = from;
139  mTo = to;
140  mDate = date;
141 }
142 
143 #ifdef Q_CC_MSVC
144 MailSummary::operator KUrl() const { return KUrl(); }
145 #endif
146 
147 QString MailList::mimeDataType()
148 {
149  return QLatin1String( "x-kmail-drag/message-list" );
150 }
151 
152 bool MailList::canDecode( const QMimeData *md )
153 {
154  return md->hasFormat( mimeDataType() );
155 }
156 
157 void MailList::populateMimeData( QMimeData *md )
158 {
159  /* We have three different possible mime types: x-kmail-drag/message-list, message/rfc822, and URL
160  Add them in this order */
161 
162  /* Popuplate the MimeData with the custom streaming x-kmail-drag/message-list mime type */
163  if ( count() ) {
164  QByteArray array;
165  QBuffer buffer( &array, 0 );
166  buffer.open( QIODevice::WriteOnly);
167  QDataStream stream( &buffer );
168  stream << (*this);
169  buffer.close();
170  md->setData( MailList::mimeDataType(), array );
171  }
172 }
173 
174 MailList MailList::fromMimeData( const QMimeData *md )
175 {
176  if ( canDecode(md) ) {
177  return decode( md->data( mimeDataType() ) );
178  } else {
179  return MailList();
180  }
181 }
182 
183 MailList MailList::decode( const QByteArray& payload )
184 {
185  MailList mailList;
186  // A read-only data stream
187  QDataStream stream( payload );
188  if ( payload.size() ) {
189  stream >> mailList;
190  }
191  return mailList;
192 }
193 
194 QByteArray MailList::serialsFromMimeData( const QMimeData *md )
195 {
196  MailList mailList = fromMimeData( md );
197  if ( mailList.count() ) {
198  MailList::const_iterator it;
199  QByteArray a;
200  QBuffer buffer( &a );
201  buffer.open( QIODevice::WriteOnly );
202  QDataStream stream( &buffer );
203  MailList::const_iterator end( mailList.constEnd() );
204  for (it = mailList.constBegin(); it != end; ++it) {
205  MailSummary mailDrag = *it;
206  stream << mailDrag.serialNumber();
207  }
208  buffer.close();
209  return a;
210  } else {
211  return QByteArray();
212  }
213 }
214 
215 MailListMimeData::MailListMimeData( MailTextSource *src )
216  : mMailTextSource( src )
217 {
218 }
219 
220 MailListMimeData::~MailListMimeData()
221 {
222  delete mMailTextSource;
223  mMailTextSource = 0;
224 }
225 
226 bool MailListMimeData::hasFormat ( const QString & mimeType ) const
227 {
228  if ( mimeType == QLatin1String( "message/rfc822" ) && mMailTextSource )
229  return true;
230  else
231  return QMimeData::hasFormat( mimeType );
232 }
233 
234 QStringList MailListMimeData::formats () const
235 {
236  QStringList theFormats = QMimeData::formats();
237  if ( mMailTextSource )
238  theFormats.prepend( QLatin1String( "message/rfc822" ) );
239  return theFormats;
240 }
241 
242 QVariant MailListMimeData::retrieveData( const QString & mimeType,
243  QVariant::Type type ) const
244 {
245  if ( ( mimeType == QLatin1String( "message/rfc822" ) ) && mMailTextSource ) {
246 
247  if ( mMails.isEmpty() ) {
248  MailList list = MailList::fromMimeData( this );
249  KProgressDialog *dlg = new KProgressDialog( 0, QString(),
250  i18n("Retrieving and storing messages...") );
251  dlg->setWindowModality( Qt::WindowModal );
252  dlg->setAllowCancel( true );
253  dlg->progressBar()->setMaximum( list.size() );
254  int i = 0;
255  dlg->progressBar()->setValue( i );
256  dlg->show();
257  MailList::ConstIterator end( list.constEnd() );
258  for ( MailList::ConstIterator it = list.constBegin(); it != end; ++it ) {
259 
260  // Get the serial number from the mail summary and use the mail text source
261  // to get the actual text of the mail.
262  MailSummary mailSummary = *it;
263  mMails.append( mMailTextSource->text( mailSummary.serialNumber() ) );
264  if ( dlg->wasCancelled() ) {
265  break;
266  }
267  dlg->progressBar()->setValue(++i);
268 #ifdef __GNUC__
269 #warning Port me!
270 #endif
271  //kapp->eventLoop()->processEvents(QEventLoop::ExcludeSocketNotifiers);
272  }
273  delete dlg;
274  }
275  return mMails;
276  }
277  else
278  return QMimeData::retrieveData( mimeType, type );
279 }
KPIM::MailTextSource::text
virtual QByteArray text(quint32 serialNumber) const =0
KPIM::MailSummary::date
time_t date() const
Date the message was sent.
Definition: maillistdrag.cpp:127
KPIM::MailListMimeData::retrieveData
virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const
Reimplemented so that the message/rfc822 mimetype data can be retrieved from mMailTextSource.
Definition: maillistdrag.cpp:242
KPIM::MailTextSource
Object for the drag object to call-back for message fulltext.
Definition: maillistdrag.h:106
KPIM::MailList::populateMimeData
void populateMimeData(QMimeData *md)
Definition: maillistdrag.cpp:157
KPIM::MailListMimeData::hasFormat
virtual bool hasFormat(const QString &mimeType) const
Definition: maillistdrag.cpp:226
KPIM::MailSummary::from
QString from() const
Simplified from address.
Definition: maillistdrag.cpp:117
KPIM::MailList::fromMimeData
static MailList fromMimeData(const QMimeData *md)
Definition: maillistdrag.cpp:174
KPIM::MailSummary::messageId
QString messageId() const
MD5 checksum of message identification string.
Definition: maillistdrag.cpp:107
maillistdrag.h
KPIM::MailSummary::to
QString to() const
Simplified to address.
Definition: maillistdrag.cpp:122
KPIM::MailSummary::subject
QString subject() const
Subject of the message including prefixes.
Definition: maillistdrag.cpp:112
KPIM::MailListMimeData::~MailListMimeData
~MailListMimeData()
Definition: maillistdrag.cpp:220
KPIM::MailListMimeData::formats
virtual QStringList formats() const
Definition: maillistdrag.cpp:234
QMimeData
KPIM::MailList::decode
static MailList decode(const QByteArray &payload)
Definition: maillistdrag.cpp:183
KPIM::MailList::canDecode
static bool canDecode(const QMimeData *md)
Definition: maillistdrag.cpp:152
operator>>
QDataStream & operator>>(QDataStream &s, MailSummary &d)
Definition: maillistdrag.cpp:56
KPIM::MailSummary::set
void set(quint32, const QString &, const QString &, const QString &, const QString &, time_t)
Set fields for this mail summary.
Definition: maillistdrag.cpp:132
KPIM::MailSummary
Represents a single dragged mail.
Definition: maillistdrag.h:59
KPIM::MailList::serialsFromMimeData
static QByteArray serialsFromMimeData(const QMimeData *md)
Definition: maillistdrag.cpp:194
KPIM::MailList
List of mail summaries.
Definition: maillistdrag.h:117
operator<<
QDataStream & operator<<(QDataStream &s, const MailSummary &d)
Definition: maillistdrag.cpp:43
KPIM::MailSummary::serialNumber
quint32 serialNumber() const
KMail unique identification number.
Definition: maillistdrag.cpp:102
KPIM::MailList::mimeDataType
static QString mimeDataType()
Definition: maillistdrag.cpp:147
KPIM::MailSummary::MailSummary
MailSummary()
Definition: maillistdrag.h:64
KPIM::MailListMimeData::MailListMimeData
MailListMimeData(MailTextSource *src=0)
Definition: maillistdrag.cpp:215
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal