summaryrefslogtreecommitdiffstats
path: root/kresources/scalix/scalixadmin/jobs.cpp
blob: f1bce9f2ca7db85ae42fc5982c1e637fe32d235d (plain)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 *   This file is part of ScalixAdmin.
 *
 *   Copyright (C) 2007 Trolltech ASA. All rights reserved.
 *
 *   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 <kio/scheduler.h>
#include <klocale.h>

#include "jobs.h"

using namespace Scalix;

Delegate::Delegate()
  : mRights( -1 )
{
}

Delegate::Delegate( const TQString &email, int rights )
  : mEmail( email ), mRights( rights )
{
}

bool Delegate::isValid() const
{
  return ( !mEmail.isEmpty() && mRights != -1 );
}

TQString Delegate::email() const
{
  return mEmail;
}

int Delegate::rights() const
{
  return mRights;
}

TQString Delegate::rightsAsString( int rights )
{
  TQStringList rightNames;

  if ( rights & SendOnBehalfOf )
    rightNames.append( i18n( "Send on behalf of" ) );
  if ( rights & SeePrivate )
    rightNames.append( i18n( "See private" ) );
  if ( rights & GetMeetings )
    rightNames.append( i18n( "Get meetings" ) );
  if ( rights & InsteadOfMe )
    rightNames.append( i18n( "Instead of me" ) );

  return rightNames.join( ", " );
}


SetPasswordJob* Scalix::setPassword( KIO::Slave* slave, const KURL& url,
                                     const TQString &oldPassword, const TQString& newPassword )
{
  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int)'X' << (int)'N'
         << TQString( "X-SCALIX-PASSWORD" ) << TQString( "%1 %2" ).arg( oldPassword ).arg( newPassword );

  SetPasswordJob* job = new SetPasswordJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

SetDelegateJob* Scalix::setDelegate( KIO::Slave* slave, const KURL& url, const TQString& email, int params )
{
  TQStringList types;
  if ( params & SendOnBehalfOf )
    types.append( "SOBO" );
  if ( params & SeePrivate )
    types.append( "SEEPRIVATE" );
  if ( params & GetMeetings )
    types.append( "GETMEETINGS" );
  if ( params & InsteadOfMe )
    types.append( "INSTEADOFME" );

  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int)'X' << (int)'N'
         << TQString( "X-SET-DELEGATE" ) << TQString( "%1 %2" ).arg( email ).arg( types.join( " " ) );

  SetDelegateJob* job = new SetDelegateJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

DeleteDelegateJob* Scalix::deleteDelegate( KIO::Slave* slave, const KURL& url, const TQString& email )
{
  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int)'X' << (int)'N'
         << TQString( "X-DELETE-DELEGATE" ) << email;

  DeleteDelegateJob* job = new DeleteDelegateJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

GetDelegatesJob* Scalix::getDelegates( KIO::Slave* slave, const KURL& url )
{
  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int)'X' << (int)'N' << TQString( "X-GET-DELEGATES" ) << TQString();

  GetDelegatesJob* job = new GetDelegatesJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

AddOtherUserJob* Scalix::addOtherUser( KIO::Slave* slave, const KURL& url, const TQString& email )
{
  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int)'X' << (int)'N'
         << TQString( "X-ADD-OTHER-USER" ) << email;

  AddOtherUserJob* job = new AddOtherUserJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

DeleteOtherUserJob* Scalix::deleteOtherUser( KIO::Slave* slave, const KURL& url, const TQString& email )
{
  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int)'X' << (int)'N'
         << TQString( "X-DELETE-OTHER-USER" ) << email;

  DeleteOtherUserJob* job = new DeleteOtherUserJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

GetOtherUsersJob* Scalix::getOtherUsers( KIO::Slave* slave, const KURL& url )
{
  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int)'X' << (int)'N'
         << TQString( "X-GET-OTHER-USERS" ) << TQString();

  GetOtherUsersJob* job = new GetOtherUsersJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

SetOutOfOfficeJob* Scalix::setOutOfOffice( KIO::Slave* slave, const KURL& url, bool enabled, const TQString& msg )
{
  const TQString argument = msg;
  const TQString command = TQString( "X-SET-OUT-OF-OFFICE %1 %2 {%3}" ).arg( enabled ? "ENABLED" : "DISABLED" )
                                                .arg( "UTF-8" )
                                                .arg( msg.utf8().length() );

  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int) 'X' << (int)'E' << command << argument;

  SetOutOfOfficeJob* job = new SetOutOfOfficeJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

GetOutOfOfficeJob* Scalix::getOutOfOffice( KIO::Slave* slave, const KURL& url )
{
  TQByteArray packedArgs;
  TQDataStream stream( packedArgs, IO_WriteOnly );
  stream << (int)'X' << (int)'N'
         << TQString( "X-GET-OUT-OF-OFFICE" ) << TQString();

  GetOutOfOfficeJob* job = new GetOutOfOfficeJob( url, packedArgs, false );
  KIO::Scheduler::assignJobToSlave( slave, job );
  return job;
}

SetPasswordJob::SetPasswordJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
}

SetDelegateJob::SetDelegateJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
}

DeleteDelegateJob::DeleteDelegateJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
}

GetDelegatesJob::GetDelegatesJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
  connect( this, TQT_SIGNAL( infoMessage( KIO::Job*, const TQString& ) ),
           this, TQT_SLOT( slotInfoMessage( KIO::Job*, const TQString& ) ) );
}

Delegate::List GetDelegatesJob::delegates() const
{
  return mDelegates;
}

void GetDelegatesJob::slotInfoMessage( KIO::Job*, const TQString &data )
{
  /**
   * The passed data have the following form:
   *
   * "[email protected]:right1,right2,right4 [email protected]:right3,right5"
   */
  TQStringList delegates = TQStringList::split( ' ', data );
  for ( uint i = 0; i < delegates.count(); ++i ) {
    TQStringList delegate = TQStringList::split( ':', delegates[ i ] );

    const TQString email = delegate[ 0 ];
    int rights = 0;

    TQStringList rightsList = TQStringList::split( ',', delegate[ 1 ] );
    for ( uint j = 0; j < rightsList.count(); ++j ) {
      if ( rightsList[ j ] == "SOBO" )
        rights |= SendOnBehalfOf;
      else if ( rightsList[ j ] == "SEEPRIVATE" )
        rights |= SeePrivate;
      else if ( rightsList[ j ] == "GETMEETINGS" )
        rights |= GetMeetings;
      else if ( rightsList[ j ] == "INSTEADOFME" )
        rights |= InsteadOfMe;
    }

    mDelegates.append( Delegate( email, rights ) );
  }
}

AddOtherUserJob::AddOtherUserJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
}

DeleteOtherUserJob::DeleteOtherUserJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
}

GetOtherUsersJob::GetOtherUsersJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
  connect( this, TQT_SIGNAL( infoMessage( KIO::Job*, const TQString& ) ),
           this, TQT_SLOT( slotInfoMessage( KIO::Job*, const TQString& ) ) );
}

TQStringList GetOtherUsersJob::otherUsers() const
{
  return mOtherUsers;
}

void GetOtherUsersJob::slotInfoMessage( KIO::Job*, const TQString &data )
{
  mOtherUsers = TQStringList::split( ' ', data );
}

SetOutOfOfficeJob::SetOutOfOfficeJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
}

GetOutOfOfficeJob::GetOutOfOfficeJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo )
  : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
{
  connect( this, TQT_SIGNAL( infoMessage( KIO::Job*, const TQString& ) ),
           this, TQT_SLOT( slotInfoMessage( KIO::Job*, const TQString& ) ) );
}

bool GetOutOfOfficeJob::enabled() const
{
  return mEnabled;
}

TQString GetOutOfOfficeJob::message() const
{
  return mMessage;
}

void GetOutOfOfficeJob::slotInfoMessage( KIO::Job*, const TQString &data )
{
  const TQStringList fields = TQStringList::split( '^', data );

  mEnabled = ( fields[ 0 ] == "ENABLED" );
  mMessage = fields[ 1 ];
}

#include "jobs.moc"