summaryrefslogtreecommitdiffstats
path: root/src/kiosvn/kiolistener.cpp
blob: 16ff6e4ea16fd89f3fe84c444fd4112a5b50ac68 (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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/***************************************************************************
 *   Copyright (C) 2005-2007 by Rajko Albrecht                             *
 *   ral@alwins-world.de                                                   *
 *                                                                         *
 *   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 "kiolistener.h"
#include "kiosvn.h"

#include <kdebug.h>
#include <klocale.h>
#include <dcopclient.h>

namespace KIO {

KioListener::KioListener(KIO::kio_svnProtocol*_par)
    : svn::ContextListener(),m_notifyCounter(0),m_External(false),m_HasChanges(false),m_FirstTxDelta(false),m_Canceld(false)
{
    par = _par;
}


KioListener::~KioListener()
{
}




/*!
    \fn KioListener::contextCancel()
 */
bool KioListener::contextCancel()
{
    return par->wasKilled()||m_Canceld;
}


/*!
    \fn KioListener::contextGetLogMessage (TQString & msg)
 */
bool KioListener::contextGetLogMessage (TQString & msg,const svn::CommitItemList&_items)
{
#if 1
    TQByteArray reply;
    TQByteArray params;
    TQCString replyType;
    TQDataStream stream(params,IO_WriteOnly);

    if (_items.count()>0) {
        TQMap<TQString,TQString> list;
        for (unsigned i = 0;i<_items.count();++i) {
            if (_items[i].path().isEmpty()) {
                list[_items[i].url()]=TQChar(_items[i].actionType());
            } else {
                list[_items[i].path()]=TQChar(_items[i].actionType());
            }
        }
        stream << list;
        if (!par->dcopClient()->call("kded","tdesvnd","get_logmsg(TQMap<TQString,TQString>)",params,replyType,reply)) {
            msg = "Communication with dcop failed";
            kdWarning()<<msg<<endl;
            return false;
        }
    } else {
        if (!par->dcopClient()->call("kded","tdesvnd","get_logmsg()",params,replyType,reply)) {
            msg = "Communication with dcop failed";
            kdWarning()<<msg<<endl;
            return false;
        }
    }

    if (replyType!=TQSTRINGLIST_OBJECT_NAME_STRING) {
        msg = "Wrong reply type";
        kdWarning()<<msg<<endl;
        return false;
    }
    TQDataStream stream2(reply,IO_ReadOnly);
    TQStringList lt;
    stream2>>lt;
    if (lt.count()!=1) {
        msg = "Wrong or missing log (may cancel pressed).";
        kdDebug()<< msg << endl;
        return false;
    }
    msg = lt[0];
#else
    msg = "Made with a kio::svn client";
#endif
    return true;
}

/*! the content of that method is taken from the notify in kio::svn in KDE SDK */
/* this moment we don't use it full 'cause not all is made via KIO */
void KioListener::contextNotify (const char * path,svn_wc_notify_action_t action,svn_node_kind_t kind ,const char * mime_type ,svn_wc_notify_state_t content_state, svn_wc_notify_state_t prop_state,svn_revnum_t revision)
{
    if (par->wasKilled()) {
        return;
    }
    TQString userstring;

    switch(action) {
        case svn_wc_notify_add:
        {
            if (mime_type && (svn_mime_type_is_binary (mime_type)))
                userstring = i18n( "A (bin) %1" ).arg( path );
            else
                userstring = i18n( "A %1" ).arg( path );
            break;
        }
        break;
        case svn_wc_notify_copy: //copy
            break;
        case svn_wc_notify_delete: //delete
            m_HasChanges = TRUE;
            userstring = i18n( "D %1" ).arg( path );
            break;
        case svn_wc_notify_restore : //restore
            userstring=i18n( "Restored %1." ).arg( path );
            break;
        case svn_wc_notify_revert : //revert
            userstring=i18n( "Reverted %1." ).arg( path );
            break;
        case svn_wc_notify_failed_revert: //failed revert
            userstring=i18n( "Failed to revert %1.\nTry updating instead." ).arg( path );
            break;
        case svn_wc_notify_resolved: //resolved
            userstring=i18n( "Resolved conflicted state of %1." ).arg( path );
            break;
        case svn_wc_notify_skip: //skip
            if ( content_state == svn_wc_notify_state_missing )
                userstring=i18n("Skipped missing target %1.").arg( path );
            else
                userstring=i18n("Skipped %1.").arg( path );
            break;
        case svn_wc_notify_update_delete: //update_delete
            m_HasChanges = TRUE;
            userstring=i18n( "D %1" ).arg( path );
            break;
        case svn_wc_notify_update_add: //update_add
            m_HasChanges = TRUE;
            userstring=i18n( "A %1" ).arg( path );
            break;
        case svn_wc_notify_update_update: //update_update
            {
                /* If this is an inoperative dir change, do no notification.
                   An inoperative dir change is when a directory gets closed
                   without any props having been changed. */
                if (! ((kind == svn_node_dir)
                            && ((prop_state == svn_wc_notify_state_inapplicable)
                                || (prop_state == svn_wc_notify_state_unknown)
                                || (prop_state == svn_wc_notify_state_unchanged)))) {
                    m_HasChanges = TRUE;

                    if (kind == svn_node_file) {
                        if (content_state == svn_wc_notify_state_conflicted)
                            userstring = "C";
                        else if (content_state == svn_wc_notify_state_merged)
                            userstring = "G";
                        else if (content_state == svn_wc_notify_state_changed)
                            userstring = "U";
                    }

                    if (prop_state == svn_wc_notify_state_conflicted)
                        userstring += "C";
                    else if (prop_state == svn_wc_notify_state_merged)
                        userstring += "G";
                    else if (prop_state == svn_wc_notify_state_changed)
                        userstring += "U";
                    else
                        userstring += " ";

                    if (! ((content_state == svn_wc_notify_state_unchanged
                                    || content_state == svn_wc_notify_state_unknown)
                                && (prop_state == svn_wc_notify_state_unchanged
                                    || prop_state == svn_wc_notify_state_unknown)))
                        userstring += TQString( " " ) + path;
                }
                break;
            }
        case svn_wc_notify_update_completed: //update_completed
            {
                if (!m_External) {
                    if (SVN_IS_VALID_REVNUM(revision)) {
                        userstring = i18n("Finished at revision %1.").arg(revision);
                    } else {
                        userstring = i18n("Finished.");
                    }
                } else {
                    if (SVN_IS_VALID_REVNUM(revision)) {
                        userstring = i18n("Finished external at revision %1.").arg(revision);
                    } else {
                        userstring = i18n("Finished external.");
                    }
                }
            }
            if (m_External)
                m_External = FALSE;
            break;
        case svn_wc_notify_update_external: //update_external
            m_External = TRUE;
            userstring = i18n("Fetching external item into %1." ).arg( path );
            break;
        case svn_wc_notify_status_completed: //status_completed
            if (SVN_IS_VALID_REVNUM (revision))
                userstring = i18n( "Status against revision: %1.").arg( revision );
            break;
        case svn_wc_notify_status_external: //status_external
             userstring = i18n("Performing status on external item at %1.").arg( path );
            break;
        case svn_wc_notify_commit_modified: //commit_modified
            userstring = i18n( "Sending %1.").arg( path );
            break;
        case svn_wc_notify_commit_added: //commit_added
            if (mime_type && svn_mime_type_is_binary (mime_type)) {
                userstring = i18n( "Adding (bin) %1.").arg( path );
            } else {
                userstring = i18n( "Adding %1.").arg( path );
            }
            break;
        case svn_wc_notify_commit_deleted: //commit_deleted
            userstring = i18n( "Deleting %1.").arg( path );
            break;
        case svn_wc_notify_commit_replaced: //commit_replaced
            userstring = i18n( "Replacing %1.").arg( path );
            break;
        case svn_wc_notify_commit_postfix_txdelta: //commit_postfix_txdelta
            if (!m_FirstTxDelta) {
                m_FirstTxDelta = TRUE;
		// check fullstops!
                userstring=i18n("Transmitting file data ");
            } else {
                userstring=".";
            }
            break;

            break;
        case svn_wc_notify_blame_revision: //blame_revision
            break;
        default:
            break;
    }
    par->setMetaData(TQString::number(counter()).rightJustify( 10,'0' )+ "path" , TQString::FROMUTF8( path ));
    par->setMetaData(TQString::number( counter() ).rightJustify( 10,'0' )+ "action", TQString::number( action ));
    par->setMetaData(TQString::number( counter() ).rightJustify( 10,'0' )+ "kind", TQString::number( kind ));
    par->setMetaData(TQString::number( counter() ).rightJustify( 10,'0' )+ "mime_t", TQString::FROMUTF8( mime_type ));
    par->setMetaData(TQString::number( counter() ).rightJustify( 10,'0' )+ "content", TQString::number( content_state ));
    par->setMetaData(TQString::number( counter() ).rightJustify( 10,'0' )+ "prop", TQString::number( prop_state ));
    par->setMetaData(TQString::number( counter() ).rightJustify( 10,'0' )+ "rev", TQString::number( revision ));
    par->setMetaData(TQString::number( counter() ).rightJustify( 10,'0' )+ "string", userstring );
    incCounter();
}

void KioListener::contextNotify (const svn_wc_notify_t *action)
{
    if (!action) return;
//    if (action->action<svn_wc_notify_locked) {
        contextNotify(action->path,action->action,action->kind,action->mime_type,
            action->content_state,action->prop_state,action->revision);
//        return;
//    }
//    TQString aString = NotifyAction(action->action);
}

svn::ContextListener::SslServerTrustAnswer
KioListener::contextSslServerTrustPrompt (const SslServerTrustData & data, apr_uint32_t & acceptedFailures)
{
    TQByteArray reply;
    TQByteArray params;
    TQCString replyType;
    TQDataStream stream(params,IO_WriteOnly);
    stream << data.hostname
        << data.fingerprint
        << data.validFrom
        << data.validUntil
        << data.issuerDName
        << data.realm;

    if (!par->dcopClient()->call("kded","tdesvnd",
        "get_sslaccept(TQString,TQString,TQString,TQString,TQString,TQString)",
        params,replyType,reply)) {
        kdWarning()<<"Communication with dcop failed"<<endl;
        return DONT_ACCEPT;
    }
    if (replyType!="int") {
        kdWarning()<<"Wrong reply type"<<endl;
        return DONT_ACCEPT;
    }
    TQDataStream stream2(reply,IO_ReadOnly);
    int res;
    stream2>>res;
    switch (res) {
        case -1:
            return DONT_ACCEPT;
            break;
        case 1:
            return ACCEPT_PERMANENTLY;
            break;
        default:
        case 0:
            return ACCEPT_TEMPORARILY;
            break;
    }
    /* avoid compiler warnings */
    return ACCEPT_TEMPORARILY;
}

bool KioListener::contextLoadSslClientCertPw(TQString&password,const TQString&realm)
{
    return PwStorage::self()->getCertPw(realm,password);
}

bool KioListener::contextSslClientCertPrompt (TQString & certFile)
{
    TQByteArray reply;
    TQByteArray params;
    TQCString replyType;
    if (!par->dcopClient()->call("kded","tdesvnd",
        "get_sslclientcertfile()",
        params,replyType,reply)) {
        kdWarning()<<"Communication with dcop failed"<<endl;
        return false;
    }
    if (replyType!=TQSTRING_OBJECT_NAME_STRING) {
        kdWarning()<<"Wrong reply type"<<endl;
        return false;
    }
    TQDataStream stream2(reply,IO_ReadOnly);
    stream2>>certFile;
    if (certFile.isEmpty()) {
        return false;
    }
    return true;
}

bool KioListener::contextSslClientCertPwPrompt (TQString & password,
                                   const TQString & realm, bool & maySave)
{
    return false;
}

bool KioListener::contextGetSavedLogin (const TQString & realm,TQString & username,TQString & password)
{
    PwStorage::self()->getLogin(realm,username,password);
    return true;
}

bool KioListener::contextGetCachedLogin (const TQString & realm,TQString & username,TQString & password)
{
    return true;
}

bool KioListener::contextGetLogin (const TQString & realm, TQString & username, TQString & password, bool & maySave)
{
    TQByteArray reply;
    TQByteArray params;
    TQCString replyType;

    TQDataStream stream(params,IO_WriteOnly);
    stream << realm;
    stream << username;

    if (!par->dcopClient()->call("kded","tdesvnd","get_login(TQString,TQString)",params,replyType,reply)) {
        kdWarning()<<"Communication with dcop failed"<<endl;
        return false;
    }
    if (replyType!=TQSTRINGLIST_OBJECT_NAME_STRING) {
        kdWarning()<<"Wrong reply type"<<endl;
        return false;
    }
    TQDataStream stream2(reply,IO_ReadOnly);
    TQStringList lt;
    stream2>>lt;
    if (lt.count()!=3) {
        kdDebug()<<"Wrong or missing auth list (may cancel pressed)." << endl;
        return false;
    }
    username = lt[0];
    password = lt[1];
    maySave = lt[2]=="true";
    return true;
}


/*!
    \fn KioListener::contextProgress(long long int current, long long int max)
 */
void KioListener::contextProgress(long long int cur, long long int max)
{
    if (par) {
        par->contextProgress(cur,max);
    }
}

} // namespace KIO