25 #include <tdeapplication.h>
26 #include <dcopclient.h>
29 #include "jobclasses.h"
32 #include "uiserver_stub.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>
44 using namespace TDEIO;
46 template class TQIntDict<TDEIO::Job>;
48 Observer * Observer::s_pObserver = 0L;
50 const int KDEBUG_OBSERVER = 7007;
52 Observer::Observer() : DCOPObject(
"TDEIO::Observer")
55 if (kapp && !kapp->dcopClient()->isAttached())
57 kapp->dcopClient()->attach();
60 if ( !kapp->dcopClient()->isApplicationRegistered(
"tdeio_uiserver" ) )
62 kdDebug(KDEBUG_OBSERVER) <<
"Starting tdeio_uiserver" << endl;
64 int ret = TDEApplication::startServiceByDesktopPath(
"tdeio_uiserver.desktop",
65 TQStringList(), &error );
68 kdError() <<
"Couldn't start tdeio_uiserver from tdeio_uiserver.desktop: " << error << endl;
70 kdDebug(KDEBUG_OBSERVER) <<
"startServiceByDesktopPath returned " << ret << endl;
73 if ( !kapp->dcopClient()->isApplicationRegistered(
"tdeio_uiserver" ) )
74 kdDebug(KDEBUG_OBSERVER) <<
"The application tdeio_uiserver is STILL NOT REGISTERED" << endl;
76 kdDebug(KDEBUG_OBSERVER) <<
"tdeio_uiserver registered" << endl;
78 m_uiserver =
new UIServer_stub(
"tdeio_uiserver",
"UIServer" );
85 int progressId = m_uiserver->newJob( kapp->dcopClient()->appId(), showProgress );
88 m_dctJobs.insert( progressId, job );
95 m_uiserver->jobFinished( progressId );
96 m_dctJobs.remove( progressId );
104 kdWarning() <<
"Can't find job to kill ! There is no job with progressId=" << progressId <<
" in this process" << endl;
120 m_uiserver->totalSize64( job->
progressId(), size );
123 void Observer::slotTotalFiles(
TDEIO::Job* job,
unsigned long files )
126 m_uiserver->totalFiles( job->
progressId(), files );
129 void Observer::slotTotalDirs(
TDEIO::Job* job,
unsigned long dirs )
132 m_uiserver->totalDirs( job->
progressId(), dirs );
138 m_uiserver->processedSize64( job->
progressId(), size );
141 void Observer::slotProcessedFiles(
TDEIO::Job* job,
unsigned long files )
144 m_uiserver->processedFiles( job->
progressId(), files );
147 void Observer::slotProcessedDirs(
TDEIO::Job* job,
unsigned long dirs )
150 m_uiserver->processedDirs( job->
progressId(), dirs );
153 void Observer::slotSpeed(
TDEIO::Job* job,
unsigned long speed )
156 m_uiserver->speed( job->
progressId(), speed );
159 void Observer::slotPercent(
TDEIO::Job* job,
unsigned long percent )
162 m_uiserver->percent( job->
progressId(), percent );
165 void Observer::slotInfoMessage(
TDEIO::Job* job,
const TQString & msg )
167 m_uiserver->infoMessage( job->
progressId(), msg );
170 void Observer::slotCopying(
TDEIO::Job* job,
const KURL& from,
const KURL& to )
173 m_uiserver->copying( job->
progressId(), from, to );
176 void Observer::slotMoving(
TDEIO::Job* job,
const KURL& from,
const KURL& to )
179 m_uiserver->moving( job->
progressId(), from, to );
182 void Observer::slotDeleting(
TDEIO::Job* job,
const KURL& url )
185 m_uiserver->deleting( job->
progressId(), url );
191 m_uiserver->transferring( job->
progressId(), url );
194 void Observer::slotCreatingDir(
TDEIO::Job* job,
const KURL& dir )
197 m_uiserver->creatingDir( job->
progressId(), dir );
203 m_uiserver->canResume64( job->
progressId(), offset );
206 void Observer::stating(
TDEIO::Job* job,
const KURL& url )
208 m_uiserver->stating( job->
progressId(), url );
211 void Observer::mounting(
TDEIO::Job* job,
const TQString & dev,
const TQString & point )
213 m_uiserver->mounting( job->
progressId(), dev, point );
216 void Observer::unmounting(
TDEIO::Job* job,
const TQString & point )
218 m_uiserver->unmounting( job->
progressId(), point );
222 TQString& pass,
bool readOnly )
240 kdDebug(KDEBUG_OBSERVER) <<
"Observer::openPassDlg: User= " << info.
username
241 <<
", Message= " << info.
prompt << endl;
246 if ( result == TQDialog::Accepted )
255 const TQString &caption,
const TQString &buttonYes,
256 const TQString &buttonNo )
258 return messageBox( progressId, type, text, caption, buttonYes, buttonNo, TQString::null );
262 const TQString &caption,
const TQString &buttonYes,
263 const TQString &buttonNo,
const TQString &dontAskAgainName )
265 kdDebug() <<
"Observer::messageBox " << type <<
" " << text <<
" - " << caption << endl;
267 TDEConfig *config =
new TDEConfig(
"tdeioslaverc");
268 KMessageBox::setDontShowAskAgainConfig(config);
271 case TDEIO::SlaveBase::QuestionYesNo:
272 result = KMessageBox::questionYesNo( 0L,
273 text, caption, buttonYes, buttonNo, dontAskAgainName );
275 case TDEIO::SlaveBase::WarningYesNo:
276 result = KMessageBox::warningYesNo( 0L,
277 text, caption, buttonYes, buttonNo, dontAskAgainName );
279 case TDEIO::SlaveBase::WarningContinueCancel:
280 result = KMessageBox::warningContinueCancel( 0L,
281 text, caption, buttonYes, dontAskAgainName );
283 case TDEIO::SlaveBase::WarningYesNoCancel:
284 result = KMessageBox::warningYesNoCancel( 0L,
285 text, caption, buttonYes, buttonNo, dontAskAgainName );
287 case TDEIO::SlaveBase::Information:
288 KMessageBox::information( 0L,
289 text, caption, dontAskAgainName );
292 case TDEIO::SlaveBase::SSLMessageBox:
294 TQCString observerAppId = caption.utf8();
297 Observer_stub observer( observerAppId,
"TDEIO::Observer" );
300 KSSLInfoDlg *kid =
new KSSLInfoDlg(meta[
"ssl_in_use"].upper()==
"TRUE", 0L , 0L,
true);
301 KSSLCertificate *x = KSSLCertificate::fromString(meta[
"ssl_peer_certificate"].local8Bit());
305 TQStringList::split(TQString(
"\n"), meta[
"ssl_peer_chain"]);
306 TQPtrList<KSSLCertificate> ncl;
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);
315 x->chain().setChain(ncl);
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;
329 kdDebug(7024) <<
"SSL Info dialog closed" << endl;
331 KMessageBox::information( 0L,
332 i18n(
"The peer SSL certificate appears to be corrupt."), i18n(
"SSL") );
339 kdWarning() <<
"Observer::messageBox: unknown type " << type << endl;
343 KMessageBox::setDontShowAskAgainConfig(0);
347 TQByteArray data, replyData;
349 TQDataStream arg( data, IO_WriteOnly );
356 if ( kapp->dcopClient()->call(
"tdeio_uiserver",
"UIServer",
"messageBox(int,int,TQString,TQString,TQString,TQString)", data, replyType, replyData,
true )
357 && replyType ==
"int" )
360 TQDataStream _reply_stream( replyData, IO_ReadOnly );
361 _reply_stream >> result;
362 kdDebug(KDEBUG_OBSERVER) <<
"Observer::messageBox got result " << result << endl;
365 kdDebug(KDEBUG_OBSERVER) <<
"Observer::messageBox call failed" << endl;
371 const TQString & caption,
372 const TQString& src,
const TQString & dest,
373 RenameDlg_Mode mode, TQString& newDest,
382 kdDebug(KDEBUG_OBSERVER) <<
"Observer::open_RenameDlg job=" << job << endl;
384 kdDebug(KDEBUG_OBSERVER) <<
" progressId=" << job->
progressId() << endl;
387 m_uiserver->setJobVisible( job->
progressId(),
false );
391 newDest, sizeSrc, sizeDest,
392 ctimeSrc, ctimeDest, mtimeSrc,
395 m_uiserver->setJobVisible( job->
progressId(),
true );
399 SkipDlg_Result Observer::open_SkipDlg(
TDEIO::Job* job,
401 const TQString& _error_text )
403 kdDebug(KDEBUG_OBSERVER) <<
"Observer::open_SkipDlg job=" << job <<
" progressId=" << job->
progressId() << endl;
406 m_uiserver->setJobVisible( job->
progressId(),
false );
408 SkipDlg_Result res = TDEIO::open_SkipDlg( _multi, _error_text );
410 m_uiserver->setJobVisible( job->
progressId(),
true );
414 void Observer::virtual_hook(
int id,
void* data )
415 { DCOPObject::virtual_hook(
id, data ); }
417 #include "observer.moc"
Observer for TDEIO::Job progress information.
static int messageBox(int progressId, int type, const TQString &text, const TQString &caption, const TQString &buttonYes, const TQString &buttonNo)
Popup a message box.
TDEIO::MetaData metadata(int progressId)
Called by the UI Server (using DCOP) to get all the metadata of the job.
bool openPassDlg(const TQString &prompt, TQString &user, TQString &pass, bool readOnly)
int newJob(TDEIO::Job *job, bool showProgress)
Called by the job constructor, to signal its presence to the UI Server.
void slotTransferring(TDEIO::Job *, const KURL &url)
void jobFinished(int progressId)
Called by the job destructor, to tell the UI Server that the job ended.
void killJob(int progressId)
Called by the UI Server (using DCOP) if the user presses cancel.
This class is intended to make it easier to prompt for, cache and retrieve authorization information.
TQString username
This is required for caching.
TQString prompt
Information to be displayed when prompting the user for authentication information.
TQString commentLabel
Descriptive label to be displayed in front of the comment when prompting the user for password.
TQString comment
Additional comment to be displayed when prompting the user for authentication information.
TQString password
This is required for caching.
bool keepPassword
Flag to indicate the persistence of the given password.
TQString caption
The text to displayed in the title bar of the password prompting dialog.
void setModified(bool flag)
Use this method to indicate that this object has been modified.
bool readOnly
Flag which if set forces the username field to be read-only.
The base class for all jobs.
int progressId() const
Returns the progress id for this job.
virtual void kill(bool quietly=true)
Abort this job.
MetaData metaData() const
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.
A namespace for TDEIO globals.
RenameDlg_Result
The result of open_RenameDlg().
TQ_ULLONG filesize_t
64-bit file size