kio Library API Documentation

uiserver.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2000 Matej Koss <koss@miesto.sk>
00003                       David Faure <faure@kde.org>
00004                  2001 George Staikos <staikos@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 // -*- mode: c++; c-basic-offset: 4 -*-
00021 
00022 #include <qregexp.h>
00023 
00024 #include <kconfig.h>
00025 #include <kstandarddirs.h>
00026 #include <kuniqueapplication.h>
00027 #include <kaboutdata.h>
00028 #include <kcmdlineargs.h>
00029 #include <kglobal.h>
00030 #include <klocale.h>
00031 #include <kiconloader.h>
00032 #include <dcopclient.h>
00033 #include <kstatusbar.h>
00034 #include <kdebug.h>
00035 #include <kmessagebox.h>
00036 #include <kdesu/client.h>
00037 #include <kwin.h>
00038 
00039 #include "observer_stub.h"
00040 #include "observer.h" // for static methods only
00041 #include "kio/defaultprogress.h"
00042 #include "kio/jobclasses.h"
00043 #include "uiserver.h"
00044 #include "passdlg.h"
00045 #include "kio/renamedlg.h"
00046 #include "kio/skipdlg.h"
00047 #include "slavebase.h" // for QuestionYesNo etc.
00048 #include <ksslinfodlg.h>
00049 #include <ksslcertdlg.h>
00050 #include <ksslcertificate.h>
00051 #include <ksslcertchain.h>
00052 
00053 
00054 // pointer for main instance of UIServer
00055 UIServer* uiserver;
00056 
00057 // ToolBar field IDs
00058 enum { TOOL_CANCEL };
00059 
00060 // StatusBar field IDs
00061 enum { ID_TOTAL_FILES = 1, ID_TOTAL_SIZE, ID_TOTAL_TIME, ID_TOTAL_SPEED };
00062 
00063 //static
00064 int UIServer::s_jobId = 0;
00065 
00066 static const int defaultColumnWidth[] = { 70,  // SIZE_OPERATION
00067                                     160, // LOCAL_FILENAME
00068                                     40,  // RESUME
00069                                     60,  // COUNT
00070                                     30,  // PROGRESS
00071                                     65,  // TOTAL
00072                                     70,  // SPEED
00073                                     70,  // REMAINING_TIME
00074                                     450  // URL
00075 };
00076 
00077 // number of listview columns
00078 #define NUM_COLS  9
00079 
00080 ProgressItem::ProgressItem( ListProgress* view, QListViewItem *after, QCString app_id, int job_id,
00081                             bool showDefault )
00082   : QListViewItem( view, after ) {
00083 
00084   listProgress = view;
00085 
00086   m_iTotalSize = 0;
00087   m_iTotalFiles = 0;
00088   m_iProcessedSize = 0;
00089   m_iProcessedFiles = 0;
00090   m_iSpeed = 0;
00091 
00092   m_sAppId = app_id;
00093   m_iJobId = job_id;
00094   m_visible = true;
00095   m_defaultProgressVisible = true;
00096 
00097   // create dialog, but don't show it
00098   defaultProgress = new KIO::DefaultProgress( false );
00099   defaultProgress->setOnlyClean( true );
00100   connect ( defaultProgress, SIGNAL( stopped() ), this, SLOT( slotCanceled() ) );
00101   connect ( &m_showTimer, SIGNAL( timeout() ), this, SLOT(slotShowDefaultProgress()) );
00102   
00103   if ( showDefault ) {
00104     m_showTimer.start( 500, true );
00105   }
00106 }
00107 
00108 
00109 ProgressItem::~ProgressItem() {
00110   if (defaultProgress->onlyClean())
00111     defaultProgress->finished();
00112   else
00113     delete defaultProgress;
00114 }
00115 
00116 
00117 void ProgressItem::setTotalSize( KIO::filesize_t size ) {
00118   m_iTotalSize = size;
00119 
00120   // It's already in the % column...
00121   //setText( listProgress->lv_total, KIO::convertSize( m_iTotalSize ) );
00122 
00123   defaultProgress->slotTotalSize( 0, m_iTotalSize );
00124 }
00125 
00126 
00127 void ProgressItem::setTotalFiles( unsigned long files ) {
00128   m_iTotalFiles = files;
00129 
00130   defaultProgress->slotTotalFiles( 0, m_iTotalFiles );
00131 }
00132 
00133 
00134 void ProgressItem::setTotalDirs( unsigned long dirs ) {
00135   defaultProgress->slotTotalDirs( 0, dirs );
00136 }
00137 
00138 
00139 void ProgressItem::setProcessedSize( KIO::filesize_t size ) {
00140   m_iProcessedSize = size;
00141 
00142   setText( listProgress->lv_size, KIO::convertSize( size ) );
00143 
00144   defaultProgress->slotProcessedSize( 0, size );
00145 }
00146 
00147 
00148 void ProgressItem::setProcessedFiles( unsigned long files ) {
00149   m_iProcessedFiles = files;
00150 
00151   QString tmps = i18n("%1 / %2").arg( m_iProcessedFiles ).arg( m_iTotalFiles );
00152   setText( listProgress->lv_count, tmps );
00153 
00154   defaultProgress->slotProcessedFiles( 0, m_iProcessedFiles );
00155 }
00156 
00157 
00158 void ProgressItem::setProcessedDirs( unsigned long dirs ) {
00159   defaultProgress->slotProcessedDirs( 0, dirs );
00160 }
00161 
00162 
00163 void ProgressItem::setPercent( unsigned long percent ) {
00164   QString tmps = i18n( "%1 % of %2 ").arg( percent ).arg( KIO::convertSize(m_iTotalSize));
00165   setText( listProgress->lv_progress, tmps );
00166 
00167   defaultProgress->slotPercent( 0, percent );
00168 }
00169 
00170 void ProgressItem::setInfoMessage( const QString & msg ) {
00171   QString plainTextMsg(msg);
00172   plainTextMsg.replace( QRegExp( "</?b>" ), QString::null );
00173   plainTextMsg.replace( QRegExp( "<img.*>" ), QString::null );
00174   setText( listProgress->lv_progress, plainTextMsg );
00175 
00176   defaultProgress->slotInfoMessage( 0, msg );
00177 }
00178 
00179 void ProgressItem::setSpeed( unsigned long bytes_per_second ) {
00180   m_iSpeed = bytes_per_second;
00181   m_remainingTime = KIO::calculateRemaining( m_iTotalSize, m_iProcessedSize, m_iSpeed );
00182 
00183   QString tmps, tmps2;
00184   if ( m_iSpeed == 0 ) {
00185     tmps = i18n( "Stalled");
00186     tmps2 = tmps;
00187   } else {
00188     tmps = i18n( "%1/s").arg( KIO::convertSize( m_iSpeed ));
00189     tmps2 = m_remainingTime.toString();
00190   }
00191   setText( listProgress->lv_speed, tmps );
00192   setText( listProgress->lv_remaining, tmps2 );
00193 
00194   defaultProgress->slotSpeed( 0, m_iSpeed );
00195 }
00196 
00197 
00198 void ProgressItem::setCopying( const KURL& from, const KURL& to ) {
00199   setText( listProgress->lv_operation, i18n("Copying") );
00200   setText( listProgress->lv_url, from.url() );
00201   setText( listProgress->lv_filename, to.fileName() );
00202 
00203   defaultProgress->slotCopying( 0, from, to );
00204 }
00205 
00206 
00207 void ProgressItem::setMoving( const KURL& from, const KURL& to ) {
00208   setText( listProgress->lv_operation, i18n("Moving") );
00209   setText( listProgress->lv_url, from.url() );
00210   setText( listProgress->lv_filename, to.fileName() );
00211 
00212   defaultProgress->slotMoving( 0, from, to );
00213 }
00214 
00215 
00216 void ProgressItem::setCreatingDir( const KURL& dir ) {
00217   setText( listProgress->lv_operation, i18n("Creating") );
00218   setText( listProgress->lv_url, dir.url() );
00219   setText( listProgress->lv_filename, dir.fileName() );
00220 
00221   defaultProgress->slotCreatingDir( 0, dir );
00222 }
00223 
00224 
00225 void ProgressItem::setDeleting( const KURL& url ) {
00226   setText( listProgress->lv_operation, i18n("Deleting") );
00227   setText( listProgress->lv_url, url.url() );
00228   setText( listProgress->lv_filename, url.fileName() );
00229 
00230   defaultProgress->slotDeleting( 0, url );
00231 }
00232 
00233 void ProgressItem::setTransferring( const KURL& url ) {
00234   setText( listProgress->lv_operation, i18n("Loading") );
00235   setText( listProgress->lv_url, url.url() );
00236   setText( listProgress->lv_filename, url.fileName() );
00237 
00238   defaultProgress->slotTransferring( 0, url );
00239 }
00240 
00241 void ProgressItem::setStating( const KURL& url ) {
00242   setText( listProgress->lv_operation, i18n("Examining") );
00243   setText( listProgress->lv_url, url.url() );
00244   setText( listProgress->lv_filename, url.fileName() );
00245 
00246   defaultProgress->slotStating( 0, url );
00247 }
00248 
00249 void ProgressItem::setMounting( const QString& dev, const QString & point ) {
00250   setText( listProgress->lv_operation, i18n("Mounting") );
00251   setText( listProgress->lv_url, point ); // ?
00252   setText( listProgress->lv_filename, dev ); // ?
00253 
00254   defaultProgress->slotMounting( 0, dev, point );
00255 }
00256 
00257 void ProgressItem::setUnmounting( const QString & point ) {
00258   setText( listProgress->lv_operation, i18n("Unmounting") );
00259   setText( listProgress->lv_url, point ); // ?
00260   setText( listProgress->lv_filename, "" ); // ?
00261 
00262   defaultProgress->slotUnmounting( 0, point );
00263 }
00264 
00265 void ProgressItem::setCanResume( KIO::filesize_t offset ) {
00266   /*
00267   QString tmps;
00268   // set canResume
00269   if ( _resume ) {
00270     tmps = i18n("Yes");
00271   } else {
00272     tmps = i18n("No");
00273   }
00274   setText( listProgress->lv_resume, tmps );
00275   */
00276   defaultProgress->slotCanResume( 0, offset );
00277 }
00278 
00279 
00280 void ProgressItem::slotCanceled() {
00281   emit jobCanceled( this );
00282 }
00283 
00284 // Called 0.5s after the job has been started
00285 void ProgressItem::slotShowDefaultProgress() {
00286   if (defaultProgress)
00287   {
00288     if ( m_visible && m_defaultProgressVisible )
00289       defaultProgress->show();
00290     else
00291       defaultProgress->hide();      
00292   }
00293 }
00294 
00295 void ProgressItem::slotToggleDefaultProgress() {
00296   setDefaultProgressVisible( !m_defaultProgressVisible );
00297 }
00298 
00299 // Called when a rename or skip dialog pops up
00300 // We want to prevent someone from killing the job in the uiserver then
00301 void ProgressItem::setVisible( bool visible ) {
00302   if ( m_visible != visible )
00303   {
00304     m_visible = visible;
00305     updateVisibility();
00306   }
00307 }
00308 
00309 // Can be toggled by the user
00310 void ProgressItem::setDefaultProgressVisible( bool visible ) {
00311   if ( m_defaultProgressVisible != visible )
00312   {
00313     m_defaultProgressVisible = visible;
00314     updateVisibility();
00315   }
00316 }
00317 
00318 // Update according to state
00319 void ProgressItem::updateVisibility()
00320 {
00321   if (defaultProgress)
00322   {
00323     if ( m_visible && m_defaultProgressVisible )
00324     {
00325       m_showTimer.start(250, true); // Show delayed
00326     }      
00327     else
00328     {
00329       m_showTimer.stop();
00330       defaultProgress->hide();
00331     }
00332   }
00333 }
00334 
00335 
00336 //-----------------------------------------------------------------------------
00337 
00338 ListProgress::ListProgress (QWidget *parent, const char *name)
00339   : KListView (parent, name) {
00340 
00341   // enable selection of more than one item
00342   setMultiSelection( true );
00343 
00344   setAllColumnsShowFocus( true );
00345 
00346   lv_operation = addColumn( i18n("Operation") );
00347   lv_filename = addColumn( i18n("Local Filename") );
00348   //lv_resume = addColumn( i18n("Res.") );
00349   lv_count = addColumn( i18n("Count") );
00350   lv_progress = addColumn( i18n("%") );
00351   //lv_total = addColumn( i18n("Total") );
00352   lv_size = addColumn( i18n("Size") );
00353   lv_speed = addColumn( i18n("Speed") );
00354   lv_remaining = addColumn( i18n("Rem. Time") );
00355   lv_url = addColumn( i18n("URL") );
00356 
00357   readConfig();
00358 }
00359 
00360 
00361 ListProgress::~ListProgress() {
00362   writeConfig();
00363 }
00364 
00365 
00366 void ListProgress::readConfig() {
00367   KConfig config("uiserverrc");
00368 
00369   // read listview geometry properties
00370   config.setGroup( "ProgressList" );
00371   for ( int i = 0; i < NUM_COLS; i++ ) {
00372     QString tmps;
00373     tmps.sprintf( "Col%d", i );
00374     setColumnWidth( i, config.readNumEntry( tmps, defaultColumnWidth[i] ) );
00375   }
00376 }
00377 
00378 
00379 void ListProgress::writeConfig() {
00380   KConfig config("uiserverrc");
00381 
00382   // write listview geometry properties
00383   config.setGroup( "ProgressList" );
00384   for ( int i = 0; i < NUM_COLS; i++ ) {
00385     QString tmps;
00386     tmps.sprintf( "Col%d", i );
00387     config.writeEntry( tmps, columnWidth( i ) );
00388   }
00389 
00390   config.sync();
00391 }
00392 
00393 
00394 //------------------------------------------------------------
00395 
00396 
00397 UIServer::UIServer() : KMainWindow(0, ""), DCOPObject("UIServer")
00398 {
00399 
00400   readSettings();
00401 
00402   // setup toolbar
00403   toolBar()->insertButton("editdelete", TOOL_CANCEL,
00404                           SIGNAL(clicked()), this,
00405                           SLOT(cancelCurrent()), FALSE, i18n("Cancel"));
00406 
00407   toolBar()->setBarPos( KToolBar::Left );
00408 
00409   // setup statusbar
00410   statusBar()->insertItem( i18n(" Files: %1 ").arg( 555 ), ID_TOTAL_FILES);
00411   statusBar()->insertItem( i18n(" Size: %1 kB ").arg( "134.56" ), ID_TOTAL_SIZE);
00412   statusBar()->insertItem( i18n(" Time: 00:00:00 "), ID_TOTAL_TIME);
00413   statusBar()->insertItem( i18n(" %1 kB/s ").arg("123.34"), ID_TOTAL_SPEED);
00414 
00415   // setup listview
00416   listProgress = new ListProgress( this, "progresslist" );
00417 
00418   setCentralWidget( listProgress );
00419 
00420   connect( listProgress, SIGNAL( selectionChanged() ),
00421            SLOT( slotSelection() ) );
00422   connect( listProgress, SIGNAL( executed( QListViewItem* ) ),
00423            SLOT( slotToggleDefaultProgress( QListViewItem* ) ) );
00424 
00425   // setup animation timer
00426   updateTimer = new QTimer( this );
00427   connect( updateTimer, SIGNAL( timeout() ),
00428            SLOT( slotUpdate() ) );
00429   m_bUpdateNewJob=false;
00430 
00431   setCaption(i18n("Progress Dialog"));
00432   setMinimumSize( 350, 150 );
00433   resize( 460, 150 );
00434 
00435   hide();
00436 }
00437 
00438 
00439 UIServer::~UIServer() {
00440   updateTimer->stop();
00441 }
00442 
00443 
00444 int UIServer::newJob( QCString observerAppId, bool showProgress )
00445 {
00446   kdDebug(7024) << "UIServer::newJob observerAppId=" << observerAppId << ". "
00447             << "Giving id=" << s_jobId+1 << endl;
00448 
00449   QListViewItemIterator it( listProgress );
00450   for ( ; it.current(); ++it ) {
00451     if ( it.current()->itemBelow() == 0L ) { // this will find the end of list
00452       break;
00453     }
00454   }
00455 
00456   // increment counter
00457   s_jobId++;
00458 
00459   bool show = !m_bShowList && showProgress;
00460 
00461   ProgressItem *item = new ProgressItem( listProgress, it.current(), observerAppId, s_jobId, show );
00462   connect( item, SIGNAL( jobCanceled( ProgressItem* ) ),
00463            SLOT( slotJobCanceled( ProgressItem* ) ) );
00464 
00465   if ( m_bShowList && !updateTimer->isActive() )
00466     updateTimer->start( 1000 );
00467 
00468   m_bUpdateNewJob=true;
00469 
00470   return s_jobId;
00471 }
00472 
00473 
00474 ProgressItem* UIServer::findItem( int id )
00475 {
00476   QListViewItemIterator it( listProgress );
00477 
00478   ProgressItem *item;
00479 
00480   for ( ; it.current(); ++it ) {
00481     item = (ProgressItem*) it.current();
00482     if ( item->jobId() == id ) {
00483       return item;
00484     }
00485   }
00486 
00487   return 0L;
00488 }
00489 
00490 
00491 void UIServer::setItemVisible( ProgressItem * item, bool visible )
00492 {
00493   item->setVisible( visible );
00494   // Check if we were the last one to be visible
00495   // or the first one -> hide/show the list in that case
00496   // (Note that the user could have hidden the listview by hand yet, no time)
00497   if ( m_bShowList ) {
00498       m_bUpdateNewJob = true;
00499       slotUpdate();
00500   }
00501 }
00502 
00503 // Called by Observer when opening a skip or rename dialog
00504 void UIServer::setJobVisible( int id, bool visible )
00505 {
00506   kdDebug(7024) << "UIServer::setJobVisible id=" << id << " visible=" << visible << endl;
00507   ProgressItem *item = findItem( id );
00508   Q_ASSERT( item );
00509   if ( item )
00510       setItemVisible( item, visible );
00511 }
00512 
00513 void UIServer::jobFinished( int id )
00514 {
00515   kdDebug(7024) << "UIServer::jobFinished id=" << id << endl;
00516   ProgressItem *item = findItem( id );
00517 
00518   // remove item from the list and delete the corresponding defaultprogress
00519   if ( item ) {
00520     delete item;
00521   }
00522 }
00523 
00524 
00525 void UIServer::totalSize( int id, unsigned long size )
00526 { totalSize64(id, size); }
00527 
00528 void UIServer::totalSize64( int id, KIO::filesize_t size )
00529 {
00530 //  kdDebug(7024) << "UIServer::totalSize " << id << " " << KIO::number(size) << endl;
00531 
00532   ProgressItem *item = findItem( id );
00533   if ( item ) {
00534     item->setTotalSize( size );
00535   }
00536 }
00537 
00538 void UIServer::totalFiles( int id, unsigned long files )
00539 {
00540   kdDebug(7024) << "UIServer::totalFiles " << id << " " << (unsigned int) files << endl;
00541 
00542   ProgressItem *item = findItem( id );
00543   if ( item ) {
00544     item->setTotalFiles( files );
00545   }
00546 }
00547 
00548 void UIServer::totalDirs( int id, unsigned long dirs )
00549 {
00550   kdDebug(7024) << "UIServer::totalDirs " << id << " " << (unsigned int) dirs << endl;
00551 
00552   ProgressItem *item = findItem( id );
00553   if ( item ) {
00554     item->setTotalDirs( dirs );
00555   }
00556 }
00557 
00558 void UIServer::processedSize( int id, unsigned long size )
00559 { processedSize64(id, size); }
00560 
00561 void UIServer::processedSize64( int id, KIO::filesize_t size )
00562 {
00563   //kdDebug(7024) << "UIServer::processedSize " << id << " " << KIO::number(size) << endl;
00564 
00565   ProgressItem *item = findItem( id );
00566   if ( item ) {
00567     item->setProcessedSize( size );
00568   }
00569 }
00570 
00571 void UIServer::processedFiles( int id, unsigned long files )
00572 {
00573   //kdDebug(7024) << "UIServer::processedFiles " << id << " " << (unsigned int) files << endl;
00574 
00575   ProgressItem *item = findItem( id );
00576   if ( item ) {
00577     item->setProcessedFiles( files );
00578   }
00579 }
00580 
00581 void UIServer::processedDirs( int id, unsigned long dirs )
00582 {
00583   kdDebug(7024) << "UIServer::processedDirs " << id << " " << (unsigned int) dirs << endl;
00584 
00585   ProgressItem *item = findItem( id );
00586   if ( item ) {
00587     item->setProcessedDirs( dirs );
00588   }
00589 }
00590 
00591 void UIServer::percent( int id, unsigned long ipercent )
00592 {
00593   //kdDebug(7024) << "UIServer::percent " << id << " " << (unsigned int) ipercent << endl;
00594 
00595   ProgressItem *item = findItem( id );
00596   if ( item ) {
00597     item->setPercent( ipercent );
00598   }
00599 }
00600 
00601 void UIServer::speed( int id, unsigned long bytes_per_second )
00602 {
00603   //kdDebug(7024) << "UIServer::speed " << id << " " << (unsigned int) bytes_per_second << endl;
00604 
00605   ProgressItem *item = findItem( id );
00606   if ( item ) {
00607     item->setSpeed( bytes_per_second );
00608   }
00609 }
00610 
00611 void UIServer::infoMessage( int id, const QString & msg )
00612 {
00613   //kdDebug(7024) << "UIServer::infoMessage " << id << " " << msg << endl;
00614 
00615   ProgressItem *item = findItem( id );
00616   if ( item ) {
00617     item->setInfoMessage( msg );
00618   }
00619 }
00620 
00621 void UIServer::canResume( int id, unsigned long offset )
00622 { canResume64(id, offset); }
00623 
00624 void UIServer::canResume64( int id, KIO::filesize_t offset )
00625 {
00626   //kdDebug(7024) << "UIServer::canResume " << id << " " << offset << endl;
00627 
00628   ProgressItem *item = findItem( id );
00629   if ( item ) {
00630     item->setCanResume( offset );
00631   }
00632 }
00633 
00634 void UIServer::copying( int id, KURL from, KURL to )
00635 {
00636   //kdDebug(7024) << "UIServer::copying " << id << " " << from.url() << "  " << to.url() << endl;
00637 
00638   ProgressItem *item = findItem( id );
00639   if ( item ) {
00640     item->setCopying( from, to );
00641   }
00642 }
00643 
00644 void UIServer::moving( int id, KURL from, KURL to )
00645 {
00646   //kdDebug(7024) << "UIServer::moving " << id << " " << from.url() << "  " << to.url() << endl;
00647 
00648   ProgressItem *item = findItem( id );
00649   if ( item ) {
00650     item->setMoving( from, to );
00651   }
00652 }
00653 
00654 void UIServer::deleting( int id, KURL url )
00655 {
00656   //kdDebug(7024) << "UIServer::deleting " << id << " " << url.url() << endl;
00657 
00658   ProgressItem *item = findItem( id );
00659   if ( item ) {
00660     item->setDeleting( url );
00661   }
00662 }
00663 
00664 void UIServer::transferring( int id, KURL url )
00665 {
00666   //kdDebug(7024) << "UIServer::transferring " << id << " " << url.url() << endl;
00667 
00668   ProgressItem *item = findItem( id );
00669   if ( item ) {
00670     item->setTransferring( url );
00671   }
00672 }
00673 
00674 void UIServer::creatingDir( int id, KURL dir )
00675 {
00676   kdDebug(7024) << "UIServer::creatingDir " << id << " " << dir.url() << endl;
00677 
00678   ProgressItem *item = findItem( id );
00679   if ( item ) {
00680     item->setCreatingDir( dir );
00681   }
00682 }
00683 
00684 void UIServer::stating( int id, KURL url )
00685 {
00686   kdDebug(7024) << "UIServer::stating " << id << " " << url.url() << endl;
00687 
00688   ProgressItem *item = findItem( id );
00689   if ( item ) {
00690     item->setStating( url );
00691   }
00692 }
00693 
00694 void UIServer::mounting( int id, QString dev, QString point )
00695 {
00696   kdDebug(7024) << "UIServer::mounting " << id << " " << dev << " " << point << endl;
00697 
00698   ProgressItem *item = findItem( id );
00699   if ( item ) {
00700     item->setMounting( dev, point );
00701   }
00702 }
00703 
00704 void UIServer::unmounting( int id, QString point )
00705 {
00706   kdDebug(7024) << "UIServer::unmounting " << id << " " << point << endl;
00707 
00708   ProgressItem *item = findItem( id );
00709   if ( item ) {
00710     item->setUnmounting( point );
00711   }
00712 }
00713 
00714 void UIServer::killJob( QCString observerAppId, int progressId )
00715 {
00716     // Contact the object "KIO::Observer" in the application <appId>
00717     Observer_stub observer( observerAppId, "KIO::Observer" );
00718     // Tell it to kill the job
00719     observer.killJob( progressId );
00720 }
00721 
00722 
00723 void UIServer::closeEvent( QCloseEvent * ){
00724 #ifndef Q_WS_QWS //FIXME(E): Implement for QT Embedded
00725    KWin::iconifyWindow(winId());
00726 #endif
00727 }
00728 
00729 
00730 void UIServer::slotJobCanceled( ProgressItem *item ) {
00731   kdDebug(7024) << "UIServer::slotJobCanceled appid=" << item->appId() << " jobid=" << item->jobId() << endl;
00732   // kill the corresponding job
00733   killJob( item->appId(), item->jobId() );
00734 
00735   // KIO::Job, when killed, should call back jobFinished(), but we can't
00736   // really rely on that - the app may have crashed
00737   delete item;
00738 }
00739 
00740 
00741 void UIServer::slotUpdate() {
00742   // don't do anything if we don't have any inserted progress item
00743   // or if they're all hidden
00744   QListViewItemIterator lvit( listProgress );
00745   bool visible = false;
00746   for ( ; lvit.current(); ++lvit )
00747     if ( ((ProgressItem*)lvit.current())->isVisible() ) {
00748       visible = true;
00749       break;
00750     }
00751 
00752   if ( !visible || !m_bShowList ) {
00753     hide();
00754     updateTimer->stop();
00755     return;
00756   }
00757 
00758   // Calling show() is conditional, so that users can close the window
00759   // and it only pops up back when a new job is started
00760   if (m_bUpdateNewJob)
00761   {
00762     m_bUpdateNewJob=false;
00763     show();
00764 
00765     // Make sure we'll be called back
00766     if ( m_bShowList && !updateTimer->isActive() )
00767       updateTimer->start( 1000 );
00768   }
00769 
00770   int iTotalFiles = 0;
00771   int iTotalSize = 0;
00772   int iTotalSpeed = 0;
00773   QTime totalRemTime;
00774 
00775   ProgressItem *item;
00776 
00777   // count totals for statusbar
00778   QListViewItemIterator it( listProgress );
00779 
00780   for ( ; it.current(); ++it ) {
00781     item = (ProgressItem*) it.current();
00782     if ( item->totalSize() != 0 ) {
00783       iTotalSize += ( item->totalSize() - item->processedSize() );
00784     }
00785     iTotalFiles += ( item->totalFiles() - item->processedFiles() );
00786     iTotalSpeed += item->speed();
00787 
00788     if ( item->remainingTime() > totalRemTime ) {
00789       totalRemTime = item->remainingTime();
00790     }
00791   }
00792 
00793   // update statusbar
00794   statusBar()->changeItem( i18n( " Files: %1 ").arg( iTotalFiles ), ID_TOTAL_FILES);
00795   statusBar()->changeItem( i18n( " Size: %1 ").arg( KIO::convertSize( iTotalSize ) ),
00796                            ID_TOTAL_SIZE);
00797   statusBar()->changeItem( i18n( " Time: %1 ").arg( totalRemTime.toString() ), ID_TOTAL_TIME);
00798   statusBar()->changeItem( i18n( " %1/s ").arg( KIO::convertSize( iTotalSpeed ) ),
00799                            ID_TOTAL_SPEED);
00800 
00801 }
00802 
00803 void UIServer::setListMode( bool list )
00804 {
00805   m_bShowList = list;
00806   QListViewItemIterator it( listProgress );
00807   for ( ; it.current(); ++it ) {
00808     // When going to list mode -> hide all progress dialogs
00809     // When going back to separate dialogs -> show them all
00810     ((ProgressItem*) it.current())->setDefaultProgressVisible( !list );
00811   }
00812 
00813   if (m_bShowList)
00814   {
00815     show();
00816     updateTimer->start( 1000 );
00817   }
00818   else
00819   {
00820     hide();
00821     updateTimer->stop();
00822   }
00823 }
00824 
00825 void UIServer::slotToggleDefaultProgress( QListViewItem *item ) {
00826   ((ProgressItem*) item )->slotToggleDefaultProgress();
00827 }
00828 
00829 
00830 void UIServer::slotSelection() {
00831   QListViewItemIterator it( listProgress );
00832 
00833   for ( ; it.current(); ++it ) {
00834     if ( it.current()->isSelected() ) {
00835       toolBar()->setItemEnabled( TOOL_CANCEL, TRUE);
00836       return;
00837     }
00838   }
00839   toolBar()->setItemEnabled( TOOL_CANCEL, FALSE);
00840 }
00841 
00842 // This code is deprecated, slaves go to Observer::openPassDlg now,
00843 // but this is kept for compat (DCOP calls to kio_uiserver).
00844 QByteArray UIServer::openPassDlg( const KIO::AuthInfo &info )
00845 {
00846     kdDebug(7024) << "UIServer::openPassDlg: User= " << info.username
00847                   << ", Msg= " << info.prompt << endl;
00848     KIO::AuthInfo inf(info);
00849     int result = KIO::PasswordDialog::getNameAndPassword( inf.username, inf.password,
00850                                                           &inf.keepPassword, inf.prompt,
00851                                                           inf.readOnly, inf.caption,
00852                                                           inf.comment, inf.commentLabel );
00853     QByteArray data;
00854     QDataStream stream( data, IO_WriteOnly );
00855     if ( result == QDialog::Accepted )
00856         inf.setModified( true );
00857     else
00858         inf.setModified( false );
00859     stream << inf;
00860     return data;
00861 }
00862 
00863 int UIServer::messageBox( int progressId, int type, const QString &text, const QString &caption, const QString &buttonYes, const QString &buttonNo )
00864 {
00865     return Observer::messageBox( progressId, type, text, caption, buttonYes, buttonNo );
00866 }
00867 
00868 void UIServer::showSSLInfoDialog(const QString &url, const KIO::MetaData &meta)
00869 {
00870    KSSLInfoDlg *kid = new KSSLInfoDlg(meta["ssl_in_use"].upper()=="TRUE", 0L /*parent?*/, 0L, true);
00871    KSSLCertificate *x = KSSLCertificate::fromString(meta["ssl_peer_certificate"].local8Bit());
00872    if (x) {
00873       // Set the chain back onto the certificate
00874       QStringList cl =
00875                       QStringList::split(QString("\n"), meta["ssl_peer_chain"]);
00876       QPtrList<KSSLCertificate> ncl;
00877 
00878       ncl.setAutoDelete(true);
00879       for (QStringList::Iterator it = cl.begin(); it != cl.end(); ++it) {
00880          KSSLCertificate *y = KSSLCertificate::fromString((*it).local8Bit());
00881          if (y) ncl.append(y);
00882       }
00883 
00884       if (ncl.count() > 0)
00885          x->chain().setChain(ncl);
00886 
00887       kid->setup( x,
00888                   meta["ssl_peer_ip"],
00889                   url, // the URL
00890                   meta["ssl_cipher"],
00891                   meta["ssl_cipher_desc"],
00892                   meta["ssl_cipher_version"],
00893                   meta["ssl_cipher_used_bits"].toInt(),
00894                   meta["ssl_cipher_bits"].toInt(),
00895                   KSSLCertificate::KSSLValidation(meta["ssl_cert_state"].toInt()));
00896       kdDebug(7024) << "Showing SSL Info dialog" << endl;
00897       kid->exec();
00898       delete x;
00899       kdDebug(7024) << "SSL Info dialog closed" << endl;
00900    } else {
00901       KMessageBox::information( 0L, // parent ?
00902                               i18n("The peer SSL certificate appears to be corrupt."), i18n("SSL") );
00903    }
00904    // Don't delete kid!!
00905 }
00906 
00907 KSSLCertDlgRet UIServer::showSSLCertDialog(const QString& host, const QStringList& certList)
00908 {
00909    KSSLCertDlgRet rc;
00910    rc.ok = false;
00911    if (!certList.isEmpty()) {
00912       KSSLCertDlg *kcd = new KSSLCertDlg(0L, 0L, true);
00913       kcd->setup(certList);
00914       kcd->setHost(host);
00915       kdDebug(7024) << "Showing SSL certificate dialog" << endl;
00916       kcd->exec();
00917       rc.ok = true;
00918       rc.choice = kcd->getChoice();
00919       rc.save = kcd->saveChoice();
00920       rc.send = kcd->wantsToSend();
00921       kdDebug(7024) << "SSL certificate dialog closed" << endl;
00922       delete kcd;
00923    }
00924    return rc;
00925 }
00926 
00927 
00928 QByteArray UIServer::open_RenameDlg( int id,
00929                                      const QString & caption,
00930                                      const QString& src, const QString & dest,
00931                                      int mode,
00932                                      unsigned long sizeSrc,
00933                                      unsigned long sizeDest,
00934                                      unsigned long ctimeSrc,
00935                                      unsigned long ctimeDest,
00936                                      unsigned long mtimeSrc,
00937                                      unsigned long mtimeDest
00938                                      )
00939 { return open_RenameDlg64(id, caption, src, dest, mode, sizeSrc, sizeDest,
00940                           ctimeSrc, ctimeDest, mtimeSrc, mtimeDest); }
00941 
00942 
00943 QByteArray UIServer::open_RenameDlg64( int id,
00944                                      const QString & caption,
00945                                      const QString& src, const QString & dest,
00946                                      int mode,
00947                                      KIO::filesize_t sizeSrc,
00948                                      KIO::filesize_t sizeDest,
00949                                      unsigned long ctimeSrc,
00950                                      unsigned long ctimeDest,
00951                                      unsigned long mtimeSrc,
00952                                      unsigned long mtimeDest
00953                                      )
00954 {
00955   // Hide existing dialog box if any
00956   ProgressItem *item = findItem( id );
00957   if ( item )
00958     setItemVisible( item, false );
00959   QString newDest;
00960   kdDebug(7024) << "Calling KIO::open_RenameDlg" << endl;
00961   KIO::RenameDlg_Result result = KIO::open_RenameDlg( caption, src, dest,
00962                                                       (KIO::RenameDlg_Mode) mode, newDest,
00963                                                       sizeSrc, sizeDest,
00964                                                       (time_t)ctimeSrc, (time_t)ctimeDest,
00965                                                       (time_t)mtimeSrc, (time_t)mtimeDest );
00966   kdDebug(7024) << "KIO::open_RenameDlg done" << endl;
00967   QByteArray data;
00968   QDataStream stream( data, IO_WriteOnly );
00969   stream << Q_UINT8(result) << newDest;
00970   if ( item && result != KIO::R_CANCEL )
00971     setItemVisible( item, true );
00972   return data;
00973 }
00974 
00975 int UIServer::open_SkipDlg( int id,
00976                             int /*bool*/ multi,
00977                             const QString & error_text )
00978 {
00979   // Hide existing dialog box if any
00980   ProgressItem *item = findItem( id );
00981   if ( item )
00982     setItemVisible( item, false );
00983   kdDebug(7024) << "Calling KIO::open_SkipDlg" << endl;
00984   KIO::SkipDlg_Result result = KIO::open_SkipDlg( (bool)multi, error_text );
00985   if ( item && result != KIO::S_CANCEL )
00986     setItemVisible( item, true );
00987   return (KIO::SkipDlg_Result) result;
00988 }
00989 
00990 
00991 void UIServer::readSettings() {
00992   KConfig config("uiserverrc");
00993   config.setGroup( "UIServer" );
00994 
00995   m_bShowList = config.readBoolEntry( "ShowList", false );
00996 }
00997 
00998 
00999 void UIServer::cancelCurrent() {
01000   QListViewItemIterator it( listProgress );
01001   ProgressItem *item;
01002 
01003   // kill selected jobs
01004   for ( ; it.current() ; ++it )
01005   {
01006     if ( it.current()->isSelected() ) {
01007       item = (ProgressItem*) it.current();
01008       killJob( item->appId(), item->jobId() );
01009       return;
01010     }
01011   }
01012 }
01013 
01014 //------------------------------------------------------------
01015 
01016 int main(int argc, char **argv)
01017 {
01018     KLocale::setMainCatalogue("kdelibs");
01019     //  GS 5/2001 - I changed the name to "KDE" to make it look better
01020     //              in the titles of dialogs which are displayed.
01021     KAboutData aboutdata("kio_uiserver", I18N_NOOP("KDE"),
01022                          "0.8", I18N_NOOP("KDE Progress Information UI Server"),
01023                          KAboutData::License_GPL, "(C) 2000, David Faure & Matt Koss");
01024     // Who's the maintainer ? :)
01025     aboutdata.addAuthor("David Faure",I18N_NOOP("Developer"),"faure@kde.org");
01026     aboutdata.addAuthor("Matej Koss",I18N_NOOP("Developer"),"koss@miesto.sk");
01027 
01028     KCmdLineArgs::init( argc, argv, &aboutdata );
01029     // KCmdLineArgs::addCmdLineOptions( options );
01030     KUniqueApplication::addCmdLineOptions();
01031 
01032     if (!KUniqueApplication::start())
01033     {
01034       kdDebug(7024) << "kio_uiserver is already running!" << endl;
01035       return (0);
01036     }
01037 
01038     KUniqueApplication app;
01039 
01040     // This app is started automatically, no need for session management
01041     app.disableSessionManagement();
01042     app.dcopClient()->setDaemonMode( true );
01043 
01044     uiserver = new UIServer;
01045 
01046     app.setMainWidget( uiserver );
01047 
01048     return app.exec();
01049 }
01050 
01051 #include "uiserver.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:33 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001