1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/*
* Copyright (C) 2004, Mart Kelder ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dcopdrop.h"
#include "dcopdropif.h"
#include "intid.h"
#include "mailid.h"
#include "mailsubject.h"
#include <kconfigbase.h>
#include <kdebug.h>
#include <tqdatetime.h>
#include <tqmap.h>
#include <tqstring.h>
#include <tqtimer.h>
DCOPDrop::DCOPDrop()
: KMailDrop(),
_isRunning( false ),
_msgList( new TQMap< int, KornMailSubject* > ),
_name( new TQString( "" ) ),
_counter( 1 ),
_interface( 0 )
{
}
DCOPDrop::~DCOPDrop()
{
eraseList();
delete _interface;
delete _msgList;
delete _name;
}
void DCOPDrop::recheck()
{
emit changed( _msgList->count(), this );
emit rechecked();
}
bool DCOPDrop::startMonitor()
{
_isRunning = true;
return true;
}
bool DCOPDrop::stopMonitor()
{
_isRunning = false;
return true;
}
bool DCOPDrop::readConfigGroup( const KConfigGroup &cfg )
{
return KMailDrop::readConfigGroup( cfg );
}
bool DCOPDrop::readConfigGroup( const TQMap< TQString, TQString > &map, const Protocol * )
{
if( !map.contains( "dcopname" ) )
//The mapping MUST contain dcopname.
kdDebug() << "mapping is niet compleet" << endl;
this->setDCOPName( *map.find( "dcopname" ) );
return true;
}
bool DCOPDrop::writeConfigGroup( KConfigBase& cfg ) const
{
KMailDrop::writeConfigGroup( cfg );
KMailDrop::writeConfigGroup( cfg );
cfg.writeEntry( "dcopname", *_name );
return true;
}
TQString DCOPDrop::type() const
{
return TQString( "dcop" );
}
TQValueVector< KornMailSubject >* DCOPDrop::doReadSubjects( bool * )
{
emit readSubjectsTotalSteps( 1 );
/*
* This way, the function is really asynchrone.
* So, the return value arraves before any data arrives.
*/
TQTimer::singleShot( 1, this, TQT_SLOT( doReadSubjectsASync( void ) ) );
/*
* A empty TQValueVector is made here.
* After that, the size is expanded to the expected number of subjects.
* This way, reallocation of memmory is minimized, and thus more efficient.
*/
TQValueVector<KornMailSubject> *vector = new TQValueVector<KornMailSubject>( );
vector->reserve( _msgList->count() );
return vector;
}
bool DCOPDrop::deleteMails( TQPtrList<const KornMailId> * ids, bool * )
{
emit deleteMailsTotalSteps( 1 );
for( const KornMailId *it = ids->first(); it; it = ids->next() )
{
const KornIntId* id = dynamic_cast< const KornIntId* >( it );
if( _msgList->contains( id->getId() ) )
_msgList->erase( id->getId() );
}
emit deleteMailsProgress( 1 );
emit deleteMailsReady( true );
return true;
}
void DCOPDrop::eraseList( void )
{
TQMap<int, KornMailSubject* >::iterator it;
for( it = _msgList->begin(); it != _msgList->end(); ++it )
delete it.data();
_msgList->clear();
}
void DCOPDrop::doReadSubjectsASync( void )
{
TQMap<int, KornMailSubject* >::iterator it;
for( it = _msgList->begin(); it != _msgList->end(); ++it )
emit readSubject( new KornMailSubject( *it.data() ) );
emit readSubjectsProgress( 1 );
emit readSubjectsReady( true );
}
int DCOPDrop::addMessage( const TQString& subject, const TQString& message )
{
KornIntId *id = new KornIntId( _counter );
KornMailSubject *mailsubject = new KornMailSubject( id, this );
++_counter;
mailsubject->setSubject( subject );
mailsubject->setSender( TQString( "DCOP: %1" ).arg( *_name ) );
mailsubject->setHeader( message, true );
mailsubject->setSize( message.length() );
mailsubject->setDate( TQDateTime::currentDateTime().toTime_t() );
_msgList->insert( id->getId(), mailsubject );
emit changed( _msgList->count(), this );
return _counter - 1;
}
bool DCOPDrop::removeMessage( int id )
{
if( ! _msgList->contains( id ) )
return false;
delete (*_msgList)[ id ];
_msgList->erase( id );
emit changed( _msgList->count(), this );
return true;
}
TQString DCOPDrop::DCOPName() const
{
return *_name;
}
void DCOPDrop::setDCOPName( const TQString& name)
{
*_name = name;
if( _interface )
_interface->changeName( name );
else
_interface = new DCOPDropInterface( this, name.utf8() );
}
#include "dcopdrop.moc"
|