| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

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

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:43 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001