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
|
/***************************************************************************
* 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 "ccontextlistener.h"
#include "tdesvnsettings.h"
#include "authdialogimpl.h"
#include "logmsg_impl.h"
#include "ssltrustprompt_impl.h"
#include "pwstorage.h"
#include <tdelocale.h>
#include <kapp.h>
#include <kinputdialog.h>
#include <kpassdlg.h>
#include <kdebug.h>
#include <tdefiledialog.h>
#include <tqmap.h>
#include <tqtextstream.h>
#include <tqthread.h>
class CContextListenerData
{
public:
CContextListenerData();
virtual ~CContextListenerData();
// data
bool m_cancelMe;
TQMutex m_CancelMutex;
bool noDialogs;
};
CContextListenerData::CContextListenerData()
: m_cancelMe(false),m_CancelMutex(),noDialogs(false)
{
}
CContextListenerData::~CContextListenerData()
{
}
const int CContextListener::smax_actionstring=svn_wc_notify_failed_unlock+1;
const TQString CContextListener::action_strings[]={
I18N_NOOP("Add to revision control"),
I18N_NOOP("Copy"),
I18N_NOOP("Delete"),
I18N_NOOP("Restore missing"),
I18N_NOOP("Revert"),
I18N_NOOP("Revert failed"),
I18N_NOOP("Resolved"),
I18N_NOOP("Skip"),
I18N_NOOP("Deleted"),
I18N_NOOP("Added"),
I18N_NOOP("Update"), //svn_wc_notify_update_update
I18N_NOOP("Update complete"),
I18N_NOOP("Update external module"),
TQString(), // status completed - will not send is just noisy
I18N_NOOP("Status on external"), //svn_wc_notify_status_external
I18N_NOOP("Commit Modified"),
I18N_NOOP("Commit Added"),
I18N_NOOP("Commit Deleted"),
I18N_NOOP("Commit Replaced"),
TQString(), //tx delta -> making ticks instead
TQString(), //svn_wc_notify_blame_revision - using ticks
I18N_NOOP("Locking"),
I18N_NOOP("Unlocked"),
I18N_NOOP("Lock failed"),
I18N_NOOP("Unlock failed")
};
const TQString CContextListener::notify_state_strings[]={
TQString(), // = 0
TQString(),
I18N_NOOP("unchanged"),
I18N_NOOP("item wasn't present"),
I18N_NOOP("unversioned item obstructed work"),
// I18N_NOOP("Pristine state was modified."), // should send a signal with path instead of message?
TQString(),
I18N_NOOP("Modified state had mods merged in."),
I18N_NOOP("Modified state got conflicting mods.")
};
TQString CContextListener::NotifyAction(svn_wc_notify_action_t action)
{
if (action>=smax_actionstring||action<0) {
return TQString();
}
return action_strings[action].isEmpty()?TQString():i18n(action_strings[action].ascii());
}
TQString CContextListener::NotifyState(svn_wc_notify_state_t state)
{
if (state > svn_wc_notify_state_conflicted || state<0) return TQString();
return notify_state_strings[state].isEmpty()?TQString():i18n(notify_state_strings[state].ascii());
}
CContextListener::CContextListener(TQObject *parent, const char *name)
: TQObject(parent, name), svn::ContextListener(),ref_count()
{
m_Data = new CContextListenerData();
}
CContextListener::~CContextListener()
{
disconnect();
delete m_Data;
}
bool CContextListener::contextGetCachedLogin (const TQString & realm,TQString & username,TQString & password)
{
PwStorage::self()->getCachedLogin(realm,username,password);
return true;
}
bool CContextListener::contextGetSavedLogin (const TQString & realm,TQString & username,TQString & password)
{
PwStorage::self()->getLogin(realm,username,password);
PwStorage::self()->setCachedLogin(realm,username,password);
/* the return value isn't interesting to us... */
return true;
}
bool CContextListener::contextGetLogin (
const TQString & realm,
TQString & username,
TQString & password,
bool & maySave)
{
maySave = false;
emit waitShow(true);
emit sendNotify(realm);
AuthDialogImpl auth(realm,username);
if (auth.exec()==TQDialog::Accepted) {
username=auth.Username();
password=auth.Password();
maySave = (Kdesvnsettings::passwords_in_wallet()?false:auth.maySave());
if (Kdesvnsettings::passwords_in_wallet() && auth.maySave()) {
PwStorage::self()->setLogin(realm,username,password);
}
if (Kdesvnsettings::use_password_cache()) {
PwStorage::self()->setCachedLogin(realm,username,password);
}
emit waitShow(false);
return true;
}
emit waitShow(false);
return false;
}
void CContextListener::contextNotify(const TQString&aMsg)
{
if (aMsg.isEmpty()) {
emit tickProgress();
} else {
emit sendNotify(aMsg);
}
}
void CContextListener::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)
{
TQString msg;
TQString aString = NotifyAction(action);
if (!aString.isEmpty()) {
TQTextStream ts(&msg,IO_WriteOnly);
ts << NotifyAction(action) << " " << TQString::FROMUTF8(path);
if (revision>-1) {
ts << " (Rev "<<revision<<")";
}
aString = NotifyState(content_state);
if (!aString.isEmpty()) {
ts << "\n" << aString;
}
}
contextNotify(msg);
}
void CContextListener::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);
}
void CContextListener::sendTick()
{
emit tickProgress();
}
bool CContextListener::contextCancel()
{
{
TQMutexLocker lock(&(m_Data->m_CancelMutex));
if (m_Data->m_cancelMe) {
m_Data->m_cancelMe=false;
return true;
}
}
// otherwise deadlock!
sendTick();
return false;
}
bool CContextListener::contextGetLogMessage (TQString & msg,const svn::CommitItemList&items)
{
bool isOk = false;
emit waitShow(true);
TQString logMessage = Logmsg_impl::getLogmessage(items,&isOk,0,0,0);
if (isOk) {
msg = logMessage;
}
emit waitShow(false);
return isOk;
}
svn::ContextListener::SslServerTrustAnswer CContextListener::contextSslServerTrustPrompt (
const svn::ContextListener::SslServerTrustData & data , apr_uint32_t & acceptedFailures )
{
bool ok,saveit;
emit waitShow(true);
if (!SslTrustPrompt_impl::sslTrust(
data.hostname,
data.fingerprint,
data.validFrom,
data.validUntil,
data.issuerDName,
data.realm,
failure2Strings(acceptedFailures),
&ok,&saveit)) {
return DONT_ACCEPT;
}
emit waitShow(false);
if (!saveit) {
return ACCEPT_TEMPORARILY;
}
return ACCEPT_PERMANENTLY;
}
bool CContextListener::contextSslClientCertPrompt (TQString & certFile)
{
kdDebug()<<"CContextListener::contextSslClientCertPrompt "
<< certFile << endl;
emit waitShow(true);
TQString afile = KFileDialog::getOpenFileName(TQString(),
TQString(),
0,
i18n("Open a file with a #PKCS12 certificate"));
emit waitShow(false);
if (afile.isEmpty()) {
return false;
}
certFile = afile;
return true;
}
bool CContextListener::contextLoadSslClientCertPw(TQString&password,const TQString&realm)
{
PwStorage::self()->getCertPw(realm,password);
return true;
}
bool CContextListener::contextSslClientCertPwPrompt (TQString & password,
const TQString & realm, bool & maysave)
{
maysave = false;
emit waitShow(true);
TQCString npass;
int keep = 1;
int res = KPasswordDialog::getPassword(npass,
i18n("Enter password for realm %1").arg(realm),
&keep);
emit waitShow(false);
if (res!=KPasswordDialog::Accepted) {
return false;
}
maysave = (Kdesvnsettings::passwords_in_wallet()?false:keep!=0);
if (Kdesvnsettings::store_passwords() && keep) {
PwStorage::self()->setCertPw(realm,password);
}
password = npass;
return true;
}
void CContextListener::setCanceled(bool how)
{
TQMutexLocker lock(&(m_Data->m_CancelMutex));
m_Data->m_cancelMe = how;
}
TQStringList CContextListener::failure2Strings(apr_uint32_t acceptedFailures)
{
TQStringList res;
if (acceptedFailures&SVN_AUTH_SSL_UNKNOWNCA) {
res << i18n("The certificate is not issued by a trusted authority. Use the fingerprint to validate the certificate manually!");
}
if (acceptedFailures&SVN_AUTH_SSL_CNMISMATCH) {
res<< i18n("The certificate hostname does not match.");
}
if (acceptedFailures&SVN_AUTH_SSL_NOTYETVALID) {
res << i18n("The certificate is not yet valid.");
}
if (acceptedFailures& SVN_AUTH_SSL_EXPIRED) {
res << i18n("The certificate has expired.");
}
if (acceptedFailures&SVN_AUTH_SSL_OTHER) {
res << i18n("The certificate has an unknown error.");
}
return res;
}
TQString CContextListener::translate(const TQString&what)
{
return i18n(what.ascii());
}
/*!
\fn CContextListener::contextProgress(long long int current, long long int max)
*/
void CContextListener::contextProgress(long long int current, long long int max)
{
emit netProgress(current,max);
}
#include "ccontextlistener.moc"
|