• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
observer.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Matej Koss <koss@miesto.sk>
3 David Faure <faure@kde.org>
4
5 $Id$
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License version 2 as published by the Free Software Foundation.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include <assert.h>
23
24#include <kdebug.h>
25#include <tdeapplication.h>
26#include <dcopclient.h>
27#include <kurl.h>
28
29#include "jobclasses.h"
30#include "observer.h"
31
32#include "uiserver_stub.h"
33
34#include "passdlg.h"
35#include "slavebase.h"
36#include "observer_stub.h"
37#include <tdemessagebox.h>
38#include <ksslinfodlg.h>
39#include <ksslcertdlg.h>
40#include <ksslcertificate.h>
41#include <ksslcertchain.h>
42#include <tdelocale.h>
43
44using namespace TDEIO;
45
46template class TQIntDict<TDEIO::Job>;
47
48Observer * Observer::s_pObserver = 0L;
49
50const int KDEBUG_OBSERVER = 7007; // Should be 7028
51
52Observer::Observer() : DCOPObject("TDEIO::Observer")
53{
54 // Register app as able to receive DCOP messages
55 if (tdeApp && !tdeApp->dcopClient()->isAttached())
56 {
57 tdeApp->dcopClient()->attach();
58 }
59
60 if ( !tdeApp->dcopClient()->isApplicationRegistered( "tdeio_uiserver" ) )
61 {
62 kdDebug(KDEBUG_OBSERVER) << "Starting tdeio_uiserver" << endl;
63 TQString error;
64 int ret = TDEApplication::startServiceByDesktopPath( "tdeio_uiserver.desktop",
65 TQStringList(), &error );
66 if ( ret > 0 )
67 {
68 kdError() << "Couldn't start tdeio_uiserver from tdeio_uiserver.desktop: " << error << endl;
69 } else
70 kdDebug(KDEBUG_OBSERVER) << "startServiceByDesktopPath returned " << ret << endl;
71
72 }
73 if ( !tdeApp->dcopClient()->isApplicationRegistered( "tdeio_uiserver" ) )
74 kdDebug(KDEBUG_OBSERVER) << "The application tdeio_uiserver is STILL NOT REGISTERED" << endl;
75 else
76 kdDebug(KDEBUG_OBSERVER) << "tdeio_uiserver registered" << endl;
77
78 m_uiserver = new UIServer_stub( "tdeio_uiserver", "UIServer" );
79}
80
81int Observer::newJob( TDEIO::Job * job, bool showProgress )
82{
83 // Tell the UI Server about this new job, and give it the application id
84 // at the same time
85 int progressId = m_uiserver->newJob( tdeApp->dcopClient()->appId(), showProgress );
86
87 // Keep the result in a dict
88 m_dctJobs.insert( progressId, job );
89
90 return progressId;
91}
92
93void Observer::jobFinished( int progressId )
94{
95 m_uiserver->jobFinished( progressId );
96 m_dctJobs.remove( progressId );
97}
98
99void Observer::killJob( int progressId )
100{
101 TDEIO::Job * job = m_dctJobs[ progressId ];
102 if (!job)
103 {
104 kdWarning() << "Can't find job to kill ! There is no job with progressId=" << progressId << " in this process" << endl;
105 return;
106 }
107 job->kill( false /* not quietly */ );
108}
109
110MetaData Observer::metadata( int progressId )
111{
112 TDEIO::Job * job = m_dctJobs[ progressId ];
113 assert(job);
114 return job->metaData();
115}
116
117void Observer::slotTotalSize( TDEIO::Job* job, TDEIO::filesize_t size )
118{
119 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotTotalSize " << job << " " << TDEIO::number(size) << endl;
120 m_uiserver->totalSize64( job->progressId(), size );
121}
122
123void Observer::slotTotalFiles( TDEIO::Job* job, unsigned long files )
124{
125 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotTotalFiles " << job << " " << files << endl;
126 m_uiserver->totalFiles( job->progressId(), files );
127}
128
129void Observer::slotTotalDirs( TDEIO::Job* job, unsigned long dirs )
130{
131 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotTotalDirs " << job << " " << dirs << endl;
132 m_uiserver->totalDirs( job->progressId(), dirs );
133}
134
135void Observer::slotProcessedSize( TDEIO::Job* job, TDEIO::filesize_t size )
136{
137 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotProcessedSize " << job << " " << job->progressId() << " " << TDEIO::number(size) << endl;
138 m_uiserver->processedSize64( job->progressId(), size );
139}
140
141void Observer::slotProcessedFiles( TDEIO::Job* job, unsigned long files )
142{
143 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotProcessedFiles " << job << " " << files << endl;
144 m_uiserver->processedFiles( job->progressId(), files );
145}
146
147void Observer::slotProcessedDirs( TDEIO::Job* job, unsigned long dirs )
148{
149 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotProcessedDirs " << job << " " << dirs << endl;
150 m_uiserver->processedDirs( job->progressId(), dirs );
151}
152
153void Observer::slotSpeed( TDEIO::Job* job, unsigned long speed )
154{
155 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotSpeed " << job << " " << speed << endl;
156 m_uiserver->speed( job->progressId(), speed );
157}
158
159void Observer::slotPercent( TDEIO::Job* job, unsigned long percent )
160{
161 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotPercent " << job << " " << percent << endl;
162 m_uiserver->percent( job->progressId(), percent );
163}
164
165void Observer::slotInfoMessage( TDEIO::Job* job, const TQString & msg )
166{
167 m_uiserver->infoMessage( job->progressId(), msg );
168}
169
170void Observer::slotCopying( TDEIO::Job* job, const KURL& from, const KURL& to )
171{
172 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotCopying " << job << " " << from.url() << " " << to.url() << endl;
173 m_uiserver->copying( job->progressId(), from, to );
174}
175
176void Observer::slotMoving( TDEIO::Job* job, const KURL& from, const KURL& to )
177{
178 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotMoving " << job << " " << from.url() << " " << to.url() << endl;
179 m_uiserver->moving( job->progressId(), from, to );
180}
181
182void Observer::slotDeleting( TDEIO::Job* job, const KURL& url )
183{
184 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotDeleting " << job << " " << url.url() << endl;
185 m_uiserver->deleting( job->progressId(), url );
186}
187
188void Observer::slotTransferring( TDEIO::Job* job, const KURL& url )
189{
190 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotTransferring " << job << " " << url.url() << endl;
191 m_uiserver->transferring( job->progressId(), url );
192}
193
194void Observer::slotCreatingDir( TDEIO::Job* job, const KURL& dir )
195{
196 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotCreatingDir " << job << " " << dir.url() << endl;
197 m_uiserver->creatingDir( job->progressId(), dir );
198}
199
200void Observer::slotCanResume( TDEIO::Job* job, TDEIO::filesize_t offset )
201{
202 //kdDebug(KDEBUG_OBSERVER) << "** Observer::slotCanResume " << job << " " << TDEIO::number(offset) << endl;
203 m_uiserver->canResume64( job->progressId(), offset );
204}
205
206void Observer::stating( TDEIO::Job* job, const KURL& url )
207{
208 m_uiserver->stating( job->progressId(), url );
209}
210
211void Observer::mounting( TDEIO::Job* job, const TQString & dev, const TQString & point )
212{
213 m_uiserver->mounting( job->progressId(), dev, point );
214}
215
216void Observer::unmounting( TDEIO::Job* job, const TQString & point )
217{
218 m_uiserver->unmounting( job->progressId(), point );
219}
220
221bool Observer::openPassDlg( const TQString& prompt, TQString& user,
222 TQString& pass, bool readOnly )
223{
224 AuthInfo info;
225 info.prompt = prompt;
226 info.username = user;
227 info.password = pass;
228 info.readOnly = readOnly;
229 bool result = openPassDlg ( info );
230 if ( result )
231 {
232 user = info.username;
233 pass = info.password;
234 }
235 return result;
236}
237
238bool Observer::openPassDlg( TDEIO::AuthInfo& info )
239{
240 kdDebug(KDEBUG_OBSERVER) << "Observer::openPassDlg: User= " << info.username
241 << ", Message= " << info.prompt << endl;
242 int result = TDEIO::PasswordDialog::getNameAndPassword( info.username, info.password,
243 &info.keepPassword, info.prompt,
244 info.readOnly, info.caption,
245 info.comment, info.commentLabel );
246 if ( result == TQDialog::Accepted )
247 {
248 info.setModified( true );
249 return true;
250 }
251 return false;
252}
253
254int Observer::messageBox( int progressId, int type, const TQString &text,
255 const TQString &caption, const TQString &buttonYes,
256 const TQString &buttonNo )
257{
258 return messageBox( progressId, type, text, caption, buttonYes, buttonNo, TQString::null );
259}
260
261int Observer::messageBox( int progressId, int type, const TQString &text,
262 const TQString &caption, const TQString &buttonYes,
263 const TQString &buttonNo, const TQString &dontAskAgainName )
264{
265 kdDebug() << "Observer::messageBox " << type << " " << text << " - " << caption << endl;
266 int result = -1;
267 TDEConfig *config = new TDEConfig("tdeioslaverc");
268 KMessageBox::setDontShowAskAgainConfig(config);
269
270 switch (type) {
271 case TDEIO::SlaveBase::QuestionYesNo:
272 result = KMessageBox::questionYesNo( 0L, // parent ?
273 text, caption, buttonYes, buttonNo, dontAskAgainName );
274 break;
275 case TDEIO::SlaveBase::WarningYesNo:
276 result = KMessageBox::warningYesNo( 0L, // parent ?
277 text, caption, buttonYes, buttonNo, dontAskAgainName );
278 break;
279 case TDEIO::SlaveBase::WarningContinueCancel:
280 result = KMessageBox::warningContinueCancel( 0L, // parent ?
281 text, caption, buttonYes, dontAskAgainName );
282 break;
283 case TDEIO::SlaveBase::WarningYesNoCancel:
284 result = KMessageBox::warningYesNoCancel( 0L, // parent ?
285 text, caption, buttonYes, buttonNo, dontAskAgainName );
286 break;
287 case TDEIO::SlaveBase::Information:
288 KMessageBox::information( 0L, // parent ?
289 text, caption, dontAskAgainName );
290 result = 1; // whatever
291 break;
292 case TDEIO::SlaveBase::SSLMessageBox:
293 {
294 TQCString observerAppId = caption.utf8(); // hack, see slaveinterface.cpp
295 // Contact the object "TDEIO::Observer" in the application <appId>
296 // Yes, this could be the same application we are, but not necessarily.
297 Observer_stub observer( observerAppId, "TDEIO::Observer" );
298
299 TDEIO::MetaData meta = observer.metadata( progressId );
300 KSSLInfoDlg *kid = new KSSLInfoDlg(meta["ssl_in_use"].upper()=="TRUE", 0L /*parent?*/, 0L, true);
301 KSSLCertificate *x = KSSLCertificate::fromString(meta["ssl_peer_certificate"].local8Bit());
302 if (x) {
303 // Set the chain back onto the certificate
304 TQStringList cl =
305 TQStringList::split(TQString("\n"), meta["ssl_peer_chain"]);
306 TQPtrList<KSSLCertificate> ncl;
307
308 ncl.setAutoDelete(true);
309 for (TQStringList::Iterator it = cl.begin(); it != cl.end(); ++it) {
310 KSSLCertificate *y = KSSLCertificate::fromString((*it).local8Bit());
311 if (y) ncl.append(y);
312 }
313
314 if (ncl.count() > 0)
315 x->chain().setChain(ncl);
316
317 kid->setup( x,
318 meta["ssl_peer_ip"],
319 text, // the URL
320 meta["ssl_cipher"],
321 meta["ssl_cipher_desc"],
322 meta["ssl_cipher_version"],
323 meta["ssl_cipher_used_bits"].toInt(),
324 meta["ssl_cipher_bits"].toInt(),
325 KSSLCertificate::KSSLValidation(meta["ssl_cert_state"].toInt()));
326 kdDebug(7024) << "Showing SSL Info dialog" << endl;
327 kid->exec();
328 delete x;
329 kdDebug(7024) << "SSL Info dialog closed" << endl;
330 } else {
331 KMessageBox::information( 0L, // parent ?
332 i18n("The peer SSL certificate appears to be corrupt."), i18n("SSL") );
333 }
334 // This doesn't have to get deleted. It deletes on it's own.
335 result = 1; // whatever
336 break;
337 }
338 default:
339 kdWarning() << "Observer::messageBox: unknown type " << type << endl;
340 result = 0;
341 break;
342 }
343 KMessageBox::setDontShowAskAgainConfig(0);
344 delete config;
345 return result;
346#if 0
347 TQByteArray data, replyData;
348 TQCString replyType;
349 TQDataStream arg( data, IO_WriteOnly );
350 arg << progressId;
351 arg << type;
352 arg << text;
353 arg << caption;
354 arg << buttonYes;
355 arg << buttonNo;
356 if ( tdeApp->dcopClient()->call( "tdeio_uiserver", "UIServer", "messageBox(int,int,TQString,TQString,TQString,TQString)", data, replyType, replyData, true )
357 && replyType == "int" )
358 {
359 int result;
360 TQDataStream _reply_stream( replyData, IO_ReadOnly );
361 _reply_stream >> result;
362 kdDebug(KDEBUG_OBSERVER) << "Observer::messageBox got result " << result << endl;
363 return result;
364 }
365 kdDebug(KDEBUG_OBSERVER) << "Observer::messageBox call failed" << endl;
366 return 0;
367#endif
368}
369
370RenameDlg_Result Observer::open_RenameDlg( TDEIO::Job* job,
371 const TQString & caption,
372 const TQString& src, const TQString & dest,
373 RenameDlg_Mode mode, TQString& newDest,
374 TDEIO::filesize_t sizeSrc,
375 TDEIO::filesize_t sizeDest,
376 time_t ctimeSrc,
377 time_t ctimeDest,
378 time_t mtimeSrc,
379 time_t mtimeDest
380 )
381{
382 kdDebug(KDEBUG_OBSERVER) << "Observer::open_RenameDlg job=" << job << endl;
383 if (job)
384 kdDebug(KDEBUG_OBSERVER) << " progressId=" << job->progressId() << endl;
385 // Hide existing dialog box if any
386 if (job && job->progressId())
387 m_uiserver->setJobVisible( job->progressId(), false );
388 // We now do it in process => KDE4: move this code out of Observer (back to job.cpp), so that
389 // opening the rename dialog doesn't start uiserver for nothing if progressId=0 (e.g. F2 in konq)
390 RenameDlg_Result res = TDEIO::open_RenameDlg( caption, src, dest, mode,
391 newDest, sizeSrc, sizeDest,
392 ctimeSrc, ctimeDest, mtimeSrc,
393 mtimeDest );
394 if (job && job->progressId())
395 m_uiserver->setJobVisible( job->progressId(), true );
396 return res;
397}
398
399SkipDlg_Result Observer::open_SkipDlg( TDEIO::Job* job,
400 bool _multi,
401 const TQString& _error_text )
402{
403 kdDebug(KDEBUG_OBSERVER) << "Observer::open_SkipDlg job=" << job << " progressId=" << job->progressId() << endl;
404 // Hide existing dialog box if any
405 if (job && job->progressId())
406 m_uiserver->setJobVisible( job->progressId(), false );
407 // We now do it in process. So this method is a useless wrapper around TDEIO::open_RenameDlg.
408 SkipDlg_Result res = TDEIO::open_SkipDlg( _multi, _error_text );
409 if (job && job->progressId())
410 m_uiserver->setJobVisible( job->progressId(), true );
411 return res;
412}
413
414void Observer::virtual_hook( int id, void* data )
415{ DCOPObject::virtual_hook( id, data ); }
416
417#include "observer.moc"
Observer
Observer for TDEIO::Job progress information.
Definition: observer.h:55
Observer::messageBox
static int messageBox(int progressId, int type, const TQString &text, const TQString &caption, const TQString &buttonYes, const TQString &buttonNo)
Popup a message box.
Definition: observer.cpp:254
Observer::metadata
TDEIO::MetaData metadata(int progressId)
Called by the UI Server (using DCOP) to get all the metadata of the job.
Definition: observer.cpp:110
Observer::openPassDlg
bool openPassDlg(const TQString &prompt, TQString &user, TQString &pass, bool readOnly)
Definition: observer.cpp:221
Observer::newJob
int newJob(TDEIO::Job *job, bool showProgress)
Called by the job constructor, to signal its presence to the UI Server.
Definition: observer.cpp:81
Observer::slotTransferring
void slotTransferring(TDEIO::Job *, const KURL &url)
Definition: observer.cpp:188
Observer::jobFinished
void jobFinished(int progressId)
Called by the job destructor, to tell the UI Server that the job ended.
Definition: observer.cpp:93
Observer::killJob
void killJob(int progressId)
Called by the UI Server (using DCOP) if the user presses cancel.
Definition: observer.cpp:99
TDEIO::AuthInfo
This class is intended to make it easier to prompt for, cache and retrieve authorization information.
Definition: authinfo.h:52
TDEIO::AuthInfo::username
TQString username
This is required for caching.
Definition: authinfo.h:99
TDEIO::AuthInfo::prompt
TQString prompt
Information to be displayed when prompting the user for authentication information.
Definition: authinfo.h:115
TDEIO::AuthInfo::commentLabel
TQString commentLabel
Descriptive label to be displayed in front of the comment when prompting the user for password.
Definition: authinfo.h:159
TDEIO::AuthInfo::comment
TQString comment
Additional comment to be displayed when prompting the user for authentication information.
Definition: authinfo.h:150
TDEIO::AuthInfo::password
TQString password
This is required for caching.
Definition: authinfo.h:104
TDEIO::AuthInfo::keepPassword
bool keepPassword
Flag to indicate the persistence of the given password.
Definition: authinfo.h:220
TDEIO::AuthInfo::caption
TQString caption
The text to displayed in the title bar of the password prompting dialog.
Definition: authinfo.h:126
TDEIO::AuthInfo::setModified
void setModified(bool flag)
Use this method to indicate that this object has been modified.
Definition: authinfo.h:82
TDEIO::AuthInfo::readOnly
bool readOnly
Flag which if set forces the username field to be read-only.
Definition: authinfo.h:207
TDEIO::Job
The base class for all jobs.
Definition: jobclasses.h:67
TDEIO::Job::progressId
int progressId() const
Returns the progress id for this job.
Definition: jobclasses.h:100
TDEIO::Job::kill
virtual void kill(bool quietly=true)
Abort this job.
Definition: job.cpp:260
TDEIO::Job::metaData
MetaData metaData() const
Definition: job.cpp:417
TDEIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:516
TDEIO::PasswordDialog::getNameAndPassword
static int getNameAndPassword(TQString &user, TQString &pass, bool *keep, const TQString &prompt=TQString::null, bool readOnly=false, const TQString &caption=TQString::null, const TQString &comment=TQString::null, const TQString &label=TQString::null)
A convienence static method for obtaining authorization information from the end user.
Definition: passdlg.cpp:330
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29
TDEIO::RenameDlg_Result
RenameDlg_Result
The result of open_RenameDlg().
Definition: renamedlg.h:40
TDEIO::filesize_t
TQ_ULLONG filesize_t
64-bit file size
Definition: global.h:39

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.4
This website is maintained by Timothy Pearson.