libkdepim Library API Documentation

maillistdrag.cpp

00001 /* 00002 This file is part of libkdepim. 00003 00004 Copyright (c) 2003 Don Sanders <sanders@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #include "maillistdrag.h" 00023 #include "qdatastream.h" 00024 #include "qbuffer.h" 00025 00026 using namespace KPIM; 00027 00028 MailSummary::MailSummary( Q_UINT32 serialNumber, QString messageId, 00029 QString subject, QString from, QString to, 00030 time_t date ) 00031 : mSerialNumber( serialNumber ), mMessageId( messageId ), 00032 mSubject( subject ), mFrom( from ), mTo( to ), mDate( date ) 00033 {} 00034 00035 Q_UINT32 MailSummary::serialNumber() 00036 { 00037 return mSerialNumber; 00038 } 00039 00040 QString MailSummary::messageId() 00041 { 00042 return mMessageId; 00043 } 00044 00045 QString MailSummary::subject() 00046 { 00047 return mSubject; 00048 } 00049 00050 QString MailSummary::from() 00051 { 00052 return mFrom; 00053 } 00054 00055 QString MailSummary::to() 00056 { 00057 return mTo; 00058 } 00059 00060 time_t MailSummary::date() 00061 { 00062 return mDate; 00063 } 00064 00065 void MailSummary::set( Q_UINT32 serialNumber, QString messageId, 00066 QString subject, QString from, QString to, time_t date ) 00067 { 00068 mSerialNumber = serialNumber; 00069 mMessageId = messageId; 00070 mSubject = subject; 00071 mFrom = from; 00072 mTo = to; 00073 mDate = date; 00074 } 00075 00076 MailListDrag::MailListDrag( MailList mailList, QWidget * parent ) 00077 : QStoredDrag( MailListDrag::format(), parent ) 00078 { 00079 setMailList( mailList ); 00080 } 00081 00082 const char* MailListDrag::format() 00083 { 00084 return "x-kmail-drag/message-list"; 00085 } 00086 00087 bool MailListDrag::canDecode( QMimeSource *e ) 00088 { 00089 return e->provides( MailListDrag::format() ); 00090 } 00091 00092 // Have to define before use 00093 QDataStream& operator<< ( QDataStream &s, MailSummary &d ) 00094 { 00095 s << d.serialNumber(); 00096 s << d.messageId(); 00097 s << d.subject(); 00098 s << d.from(); 00099 s << d.to(); 00100 s << d.date(); 00101 return s; 00102 } 00103 00104 QDataStream& operator>> ( QDataStream &s, MailSummary &d ) 00105 { 00106 Q_UINT32 serialNumber; 00107 QString messageId, subject, from, to; 00108 time_t date; 00109 s >> serialNumber; 00110 s >> messageId; 00111 s >> subject; 00112 s >> from; 00113 s >> to; 00114 s >> date; 00115 d.set( serialNumber, messageId, subject, from, to, date ); 00116 return s; 00117 } 00118 00119 QDataStream& operator<< ( QDataStream &s, MailList &mailList ) 00120 { 00121 MailList::iterator it; 00122 for (it = mailList.begin(); it != mailList.end(); ++it) { 00123 MailSummary mailDrag = *it; 00124 s << mailDrag; 00125 } 00126 return s; 00127 } 00128 00129 QDataStream& operator>> ( QDataStream &s, MailList &mailList ) 00130 { 00131 mailList.clear(); 00132 MailSummary mailDrag; 00133 while (!s.atEnd()) { 00134 s >> mailDrag; 00135 mailList.append( mailDrag ); 00136 } 00137 return s; 00138 } 00139 00140 bool MailListDrag::decode( QDropEvent* e, MailList& mailList ) 00141 { 00142 QByteArray payload = e->encodedData( MailListDrag::format() ); 00143 QDataStream buffer( payload, IO_ReadOnly ); 00144 if ( payload.size() ) { 00145 e->accept(); 00146 buffer >> mailList; 00147 return TRUE; 00148 } 00149 return FALSE; 00150 } 00151 00152 bool MailListDrag::decode( QByteArray& payload, MailList& mailList ) 00153 { 00154 QDataStream stream( payload, IO_ReadOnly ); 00155 if ( payload.size() ) { 00156 stream >> mailList; 00157 return TRUE; 00158 } 00159 return FALSE; 00160 } 00161 00162 bool MailListDrag::decode( QDropEvent* e, QByteArray &a ) 00163 { 00164 MailList mailList; 00165 if (decode( e, mailList )) { 00166 MailList::iterator it; 00167 QBuffer buffer( a ); 00168 buffer.open( IO_WriteOnly ); 00169 QDataStream stream( &buffer ); 00170 for (it = mailList.begin(); it != mailList.end(); ++it) { 00171 MailSummary mailDrag = *it; 00172 stream << mailDrag.serialNumber(); 00173 } 00174 buffer.close(); 00175 return TRUE; 00176 } 00177 return FALSE; 00178 } 00179 00180 void MailListDrag::setMailList( MailList mailList ) 00181 { 00182 QByteArray array; 00183 QBuffer buffer( array ); 00184 buffer.open( IO_WriteOnly); 00185 QDataStream stream( array, IO_WriteOnly ); 00186 stream << mailList; 00187 buffer.close(); 00188 setEncodedData( array ); 00189 }
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:46 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003