23 #include "maillistdrag.h"
25 #include <tqdatastream.h>
26 #include <tqeventloop.h>
27 #include <tdeapplication.h>
28 #include <tdelocale.h>
29 #include <kprogress.h>
33 MailSummary::MailSummary( TQ_UINT32 serialNumber, TQString messageId,
34 TQString subject, TQString from, TQString to,
36 : mSerialNumber( serialNumber ), mMessageId( messageId ),
37 mSubject( subject ), mFrom( from ), mTo( to ), mDate( date )
40 TQ_UINT32 MailSummary::serialNumber()
const
45 TQString MailSummary::messageId()
50 TQString MailSummary::subject()
55 TQString MailSummary::from()
60 TQString MailSummary::to()
65 time_t MailSummary::date()
70 void MailSummary::set( TQ_UINT32 serialNumber, TQString messageId,
71 TQString subject, TQString from, TQString to, time_t date )
73 mSerialNumber = serialNumber;
74 mMessageId = messageId;
81 MailListDrag::MailListDrag( MailList mailList, TQWidget * parent, MailTextSource *src )
82 : TQStoredDrag( MailListDrag::format(), parent ), _src(src)
84 setMailList( mailList );
87 MailListDrag::~MailListDrag()
93 const char* MailListDrag::format()
95 return "x-kmail-drag/message-list";
98 bool MailListDrag::canDecode( TQMimeSource *e )
100 return e->provides( MailListDrag::format() );
104 TQDataStream& operator<< ( TQDataStream &s, MailSummary &d )
106 s << d.serialNumber();
115 TQDataStream& operator>> ( TQDataStream &s, MailSummary &d )
117 TQ_UINT32 serialNumber;
118 TQString messageId, subject, from, to;
126 d.set( serialNumber, messageId, subject, from, to, date );
130 TQDataStream& operator<< ( TQDataStream &s, MailList &mailList )
132 MailList::iterator it;
133 for (it = mailList.begin(); it != mailList.end(); ++it) {
134 MailSummary mailDrag = *it;
140 TQDataStream& operator>> ( TQDataStream &s, MailList &mailList )
143 MailSummary mailDrag;
146 mailList.append( mailDrag );
151 bool MailListDrag::decode( TQDropEvent* e, MailList& mailList )
153 TQByteArray payload = e->encodedData( MailListDrag::format() );
154 TQDataStream buffer( payload, IO_ReadOnly );
155 if ( payload.size() ) {
163 bool MailListDrag::decode( TQByteArray& payload, MailList& mailList )
165 TQDataStream stream( payload, IO_ReadOnly );
166 if ( payload.size() ) {
173 bool MailListDrag::decode( TQDropEvent* e, TQByteArray &a )
176 if (decode( e, mailList )) {
177 MailList::iterator it;
178 TQBuffer buffer( a );
179 buffer.open( IO_WriteOnly );
180 TQDataStream stream( &buffer );
181 for (it = mailList.begin(); it != mailList.end(); ++it) {
182 MailSummary mailDrag = *it;
183 stream << mailDrag.serialNumber();
191 void MailListDrag::setMailList( MailList mailList )
194 TQBuffer buffer( array );
195 buffer.open( IO_WriteOnly);
196 TQDataStream stream( array, IO_WriteOnly );
199 setEncodedData( array );
202 const char *MailListDrag::format(
int i)
const
206 return "message/rfc822";
208 return TQStoredDrag::format(i - 1);
212 return TQStoredDrag::format(i);
215 bool MailListDrag::provides(
const char *mimeType)
const
217 if (_src && TQCString(mimeType) ==
"message/rfc822") {
221 return TQStoredDrag::provides(mimeType);
224 TQByteArray MailListDrag::encodedData(
const char *mimeType)
const
226 if (TQCString(mimeType) !=
"message/rfc822") {
227 return TQStoredDrag::encodedData(mimeType);
233 TQByteArray enc = TQStoredDrag::encodedData(format());
236 KProgressDialog *dlg =
new KProgressDialog(0, 0, TQString(), i18n(
"Retrieving and storing messages..."),
true);
237 dlg->setAllowCancel(
true);
238 dlg->progressBar()->setTotalSteps(ml.count());
240 dlg->progressBar()->setValue(i);
243 TQTextStream *ts =
new TQTextStream(rc, IO_WriteOnly);
244 for (MailList::ConstIterator it = ml.begin(); it != ml.end(); ++it) {
245 MailSummary mailDrag = *it;
246 *ts << _src->text(mailDrag.serialNumber());
247 if (dlg->wasCancelled()) {
250 dlg->progressBar()->setValue(++i);
251 kapp->eventLoop()->processEvents(TQEventLoop::ExcludeSocketNotifiers);
TDEPIM classes for drag and drop of mails.