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 <qtimer.h>
00023 
00024 #include <qregexp.h>
00025 #include <qheader.h>
00026 #include <qevent.h>
00027 
00028 #include <ksqueezedtextlabel.h>
00029 #include <kconfig.h>
00030 #include <kstandarddirs.h>
00031 #include <kuniqueapplication.h>
00032 #include <kaboutdata.h>
00033 #include <kcmdlineargs.h>
00034 #include <kglobal.h>
00035 #include <klocale.h>
00036 #include <dcopclient.h>
00037 #include <kstatusbar.h>
00038 #include <kdebug.h>
00039 #include <kmessagebox.h>
00040 #include <kdesu/client.h>
00041 #include <kwin.h>
00042 #include <kdialog.h>
00043 #include <ksystemtray.h>
00044 #include <kpopupmenu.h>
00045 #include <kaction.h>
00046 
00047 #include <qcheckbox.h>
00048 #include <qlabel.h>
00049 #include <qlayout.h>
00050 #include <qpopupmenu.h>
00051 #include <qheader.h>
00052 
00053 #include "observer_stub.h"
00054 #include "observer.h" // for static methods only
00055 #include "kio/defaultprogress.h"
00056 #include "kio/jobclasses.h"
00057 #include "uiserver.h"
00058 #include "passdlg.h"
00059 #include "kio/renamedlg.h"
00060 #include "kio/skipdlg.h"
00061 #include "slavebase.h" // for QuestionYesNo etc.
00062 #include <ksslinfodlg.h>
00063 #include <ksslcertdlg.h>
00064 #include <ksslcertificate.h>
00065 #include <ksslcertchain.h>
00066 
00067 
00068 // pointer for main instance of UIServer
00069 UIServer* uiserver;
00070 
00071 // ToolBar field IDs
00072 enum { TOOL_CANCEL, TOOL_CONFIGURE };
00073 
00074 // StatusBar field IDs
00075 enum { ID_TOTAL_FILES = 1, ID_TOTAL_SIZE, ID_TOTAL_TIME, ID_TOTAL_SPEED };
00076 
00077 //static
00078 int UIServer::s_jobId = 0;
00079 
00080 static const int defaultColumnWidth[] = { 70,  // SIZE_OPERATION
00081                                     160, // LOCAL_FILENAME
00082                                     40,  // RESUME
00083                                     60,  // COUNT
00084                                     30,  // PROGRESS
00085                                     65,  // TOTAL
00086                                     70,  // SPEED
00087                                     70,  // REMAINING_TIME
00088                                     450  // URL
00089 };
00090 
00091 class UIServerSystemTray:public KSystemTray
00092 {
00093    public:
00094       UIServerSystemTray(UIServer* uis)
00095          :KSystemTray(uis)
00096       {
00097          KPopupMenu* pop= contextMenu();
00098          pop->insertItem(i18n("Settings..."), uis, SLOT(slotConfigure()));
00099          pop->insertItem(i18n("Remove"), uis, SLOT(slotRemoveSystemTrayIcon()));
00100          setPixmap(loadIcon("filesave"));
00101          //actionCollection()->action("file_quit")->setEnabled(true);
00102          KStdAction::quit(uis, SLOT(slotQuit()), actionCollection());
00103       }
00104 };
00105 
00106 class ProgressConfigDialog:public KDialogBase
00107 {
00108    public:
00109       ProgressConfigDialog(QWidget* parent);
00110       ~ProgressConfigDialog()  {}
00111       void setChecked(int i, bool on);
00112       bool isChecked(int i) const;
00113       friend class UIServer;
00114    private:
00115       QCheckBox *m_showSystemTrayCb;
00116       QCheckBox *m_keepOpenCb;
00117       QCheckBox *m_toolBarCb;
00118       QCheckBox *m_statusBarCb;
00119       QCheckBox *m_headerCb;
00120       QCheckBox *m_fixedWidthCb;
00121       KListView *m_columns;
00122       QCheckListItem *(m_items[ListProgress::TB_MAX]);
00123 };
00124 
00125 ProgressConfigDialog::ProgressConfigDialog(QWidget *parent)
00126 :KDialogBase(KDialogBase::Plain,i18n("Configure Network Operation Window"),KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Cancel,
00127              KDialogBase::Ok, parent, "configprog", false)
00128 {
00129    QVBoxLayout *layout=new QVBoxLayout(plainPage(),spacingHint());
00130    m_showSystemTrayCb=new QCheckBox(i18n("Show system tray icon"), plainPage());
00131    m_keepOpenCb=new QCheckBox(i18n("Keep network operation window always open"), plainPage());
00132    m_headerCb=new QCheckBox(i18n("Show column headers"), plainPage());
00133    m_toolBarCb=new QCheckBox(i18n("Show toolbar"), plainPage());
00134    m_statusBarCb=new QCheckBox(i18n("Show statusbar"), plainPage());
00135    m_fixedWidthCb=new QCheckBox(i18n("Column widths are user adjustable"), plainPage());
00136    QLabel *label=new QLabel(i18n("Show information:"), plainPage());
00137    m_columns=new KListView(plainPage());
00138 
00139    m_columns->addColumn("info");
00140    m_columns->setSorting(-1);
00141    m_columns->header()->hide();
00142 
00143    m_items[ListProgress::TB_ADDRESS]        =new QCheckListItem(m_columns, i18n("URL"), QCheckListItem::CheckBox);
00144    m_items[ListProgress::TB_REMAINING_TIME] =new QCheckListItem(m_columns, i18n("Rem. Time"), QCheckListItem::CheckBox);
00145    m_items[ListProgress::TB_SPEED]          =new QCheckListItem(m_columns, i18n("Speed"), QCheckListItem::CheckBox);
00146    m_items[ListProgress::TB_TOTAL]          =new QCheckListItem(m_columns, i18n("Size"), QCheckListItem::CheckBox);
00147    m_items[ListProgress::TB_PROGRESS]       =new QCheckListItem(m_columns, i18n("%"), QCheckListItem::CheckBox);
00148    m_items[ListProgress::TB_COUNT]          =new QCheckListItem(m_columns, i18n("Count"), QCheckListItem::CheckBox);
00149    m_items[ListProgress::TB_RESUME]         =new QCheckListItem(m_columns, i18n("Resume", "Res."), QCheckListItem::CheckBox);
00150    m_items[ListProgress::TB_LOCAL_FILENAME] =new QCheckListItem(m_columns, i18n("Local Filename"), QCheckListItem::CheckBox);
00151    m_items[ListProgress::TB_OPERATION]      =new QCheckListItem(m_columns, i18n("Operation"), QCheckListItem::CheckBox);
00152 
00153    layout->addWidget(m_showSystemTrayCb);
00154    layout->addWidget(m_keepOpenCb);
00155    layout->addWidget(m_headerCb);
00156    layout->addWidget(m_toolBarCb);
00157    layout->addWidget(m_statusBarCb);
00158    layout->addWidget(m_fixedWidthCb);
00159    layout->addWidget(label);
00160    layout->addWidget(m_columns);
00161 }
00162 
00163 void ProgressConfigDialog::setChecked(int i, bool on)
00164 {
00165    if (i>=ListProgress::TB_MAX)
00166       return;
00167    m_items[i]->setOn(on);
00168 }
00169 
00170 bool ProgressConfigDialog::isChecked(int i) const
00171 {
00172    if (i>=ListProgress::TB_MAX)
00173       return false;
00174    return m_items[i]->isOn();
00175 }
00176 
00177 ProgressItem::ProgressItem( ListProgress* view, QListViewItem *after, QCString app_id, int job_id,
00178                             bool showDefault )
00179   : QListViewItem( view, after ) {
00180 
00181   listProgress = view;
00182 
00183   m_iTotalSize = 0;
00184   m_iTotalFiles = 0;
00185   m_iProcessedSize = 0;
00186   m_iProcessedFiles = 0;
00187   m_iSpeed = 0;
00188 
00189   m_sAppId = app_id;
00190   m_iJobId = job_id;
00191   m_visible = true;
00192   m_defaultProgressVisible = true;
00193 
00194   // create dialog, but don't show it
00195   defaultProgress = new KIO::DefaultProgress( false );
00196   defaultProgress->setOnlyClean( true );
00197   connect ( defaultProgress, SIGNAL( stopped() ), this, SLOT( slotCanceled() ) );
00198   connect ( &m_showTimer, SIGNAL( timeout() ), this, SLOT(slotShowDefaultProgress()) );
00199 
00200   if ( showDefault ) {
00201     m_showTimer.start( 500, true );
00202   }
00203 }
00204 
00205 
00206 ProgressItem::~ProgressItem() {
00207     delete defaultProgress;
00208 }
00209 
00210 
00211 void ProgressItem::setTotalSize( KIO::filesize_t size ) {
00212   m_iTotalSize = size;
00213 
00214   // It's already in the % column...
00215   //setText( listProgress->lv_total, KIO::convertSize( m_iTotalSize ) );
00216 
00217   defaultProgress->slotTotalSize( 0, m_iTotalSize );
00218 }
00219 
00220 
00221 void ProgressItem::setTotalFiles( unsigned long files ) {
00222   m_iTotalFiles = files;
00223 
00224   defaultProgress->slotTotalFiles( 0, m_iTotalFiles );
00225 }
00226 
00227 
00228 void ProgressItem::setTotalDirs( unsigned long dirs ) {
00229   defaultProgress->slotTotalDirs( 0, dirs );
00230 }
00231 
00232 
00233 void ProgressItem::setProcessedSize( KIO::filesize_t size ) {
00234   m_iProcessedSize = size;
00235 
00236   setText( ListProgress::TB_TOTAL, KIO::convertSize( size ) );
00237 
00238   defaultProgress->slotProcessedSize( 0, size );
00239 }
00240 
00241 
00242 void ProgressItem::setProcessedFiles( unsigned long files ) {
00243   m_iProcessedFiles = files;
00244 
00245   QString tmps = i18n("%1 / %2").arg( m_iProcessedFiles ).arg( m_iTotalFiles );
00246   setText( ListProgress::TB_COUNT, tmps );
00247 
00248   defaultProgress->slotProcessedFiles( 0, m_iProcessedFiles );
00249 }
00250 
00251 
00252 void ProgressItem::setProcessedDirs( unsigned long dirs ) {
00253   defaultProgress->slotProcessedDirs( 0, dirs );
00254 }
00255 
00256 
00257 void ProgressItem::setPercent( unsigned long percent ) {
00258   QString tmps = i18n( "%1 % of %2 ").arg( percent ).arg( KIO::convertSize(m_iTotalSize));
00259   setText( ListProgress::TB_PROGRESS, tmps );
00260 
00261   defaultProgress->slotPercent( 0, percent );
00262 }
00263 
00264 void ProgressItem::setInfoMessage( const QString & msg ) {
00265   QString plainTextMsg(msg);
00266   plainTextMsg.replace( QRegExp( "</?b>" ), QString::null );
00267   plainTextMsg.replace( QRegExp( "<img.*>" ), QString::null );
00268   setText( ListProgress::TB_PROGRESS, plainTextMsg );
00269 
00270   defaultProgress->slotInfoMessage( 0, msg );
00271 }
00272 
00273 void ProgressItem::setSpeed( unsigned long bytes_per_second ) {
00274   m_iSpeed = bytes_per_second;
00275   m_remainingTime = KIO::calculateRemaining( m_iTotalSize, m_iProcessedSize, m_iSpeed );
00276 
00277   QString tmps, tmps2;
00278   if ( m_iSpeed == 0 ) {
00279     tmps = i18n( "Stalled");
00280     tmps2 = tmps;
00281   } else {
00282     tmps = i18n( "%1/s").arg( KIO::convertSize( m_iSpeed ));
00283     tmps2 = m_remainingTime.toString();
00284   }
00285   setText( ListProgress::TB_SPEED, tmps );
00286   setText( ListProgress::TB_REMAINING_TIME, tmps2 );
00287 
00288   defaultProgress->slotSpeed( 0, m_iSpeed );
00289 }
00290 
00291 
00292 void ProgressItem::setCopying( const KURL& from, const KURL& to ) {
00293    setText( ListProgress::TB_OPERATION, i18n("Copying") );
00294    setText( ListProgress::TB_ADDRESS, from.url() );
00295    setText( ListProgress::TB_LOCAL_FILENAME, to.fileName() );
00296 
00297   defaultProgress->slotCopying( 0, from, to );
00298 }
00299 
00300 
00301 void ProgressItem::setMoving( const KURL& from, const KURL& to ) {
00302    setText( ListProgress::TB_OPERATION, i18n("Moving") );
00303    setText( ListProgress::TB_ADDRESS, from.url() );
00304    setText( ListProgress::TB_LOCAL_FILENAME, to.fileName() );
00305 
00306   defaultProgress->slotMoving( 0, from, to );
00307 }
00308 
00309 
00310 void ProgressItem::setCreatingDir( const KURL& dir ) {
00311    setText( ListProgress::TB_OPERATION, i18n("Creating") );
00312    setText( ListProgress::TB_ADDRESS, dir.url() );
00313    setText( ListProgress::TB_LOCAL_FILENAME, dir.fileName() );
00314 
00315   defaultProgress->slotCreatingDir( 0, dir );
00316 }
00317 
00318 
00319 void ProgressItem::setDeleting( const KURL& url ) {
00320    setText( ListProgress::TB_OPERATION, i18n("Deleting") );
00321    setText( ListProgress::TB_ADDRESS, url.url() );
00322    setText( ListProgress::TB_LOCAL_FILENAME, url.fileName() );
00323 
00324   defaultProgress->slotDeleting( 0, url );
00325 }
00326 
00327 void ProgressItem::setTransferring( const KURL& url ) {
00328    setText( ListProgress::TB_OPERATION, i18n("Loading") );
00329    setText( ListProgress::TB_ADDRESS, url.url() );
00330    setText( ListProgress::TB_LOCAL_FILENAME, url.fileName() );
00331 
00332   defaultProgress->slotTransferring( 0, url );
00333 }
00334 
00335 void ProgressItem::setText(ListProgress::ListProgressFields field, const QString& text)
00336 {
00337   if (listProgress->m_lpcc[field].enabled)
00338   {
00339      QString t=text;
00340      if ((field==ListProgress::TB_ADDRESS) && (listProgress->m_fixedColumnWidths))
00341 //     if (((field==ListProgress::TB_LOCAL_FILENAME) || (field==ListProgress::TB_ADDRESS)) && (listProgress->m_fixedColumnWidths))
00342      {
00343         m_fullLengthAddress=text;
00344         listProgress->m_squeezer->resize(listProgress->columnWidth(listProgress->m_lpcc[field].index),50);
00345         listProgress->m_squeezer->setText(t);
00346         t=listProgress->m_squeezer->text();
00347      }
00348      QListViewItem::setText(listProgress->m_lpcc[field].index,t);
00349   }
00350 }
00351 
00352 void ProgressItem::setStating( const KURL& url ) {
00353    setText( ListProgress::TB_OPERATION, i18n("Examining") );
00354    setText( ListProgress::TB_ADDRESS, url.url() );
00355    setText( ListProgress::TB_LOCAL_FILENAME, url.fileName() );
00356 
00357   defaultProgress->slotStating( 0, url );
00358 }
00359 
00360 void ProgressItem::setMounting( const QString& dev, const QString & point ) {
00361    setText( ListProgress::TB_OPERATION, i18n("Mounting") );
00362    setText( ListProgress::TB_ADDRESS, point ); // ?
00363    setText( ListProgress::TB_LOCAL_FILENAME, dev ); // ?
00364 
00365   defaultProgress->slotMounting( 0, dev, point );
00366 }
00367 
00368 void ProgressItem::setUnmounting( const QString & point ) {
00369    setText( ListProgress::TB_OPERATION, i18n("Unmounting") );
00370    setText( ListProgress::TB_ADDRESS, point ); // ?
00371    setText( ListProgress::TB_LOCAL_FILENAME, "" ); // ?
00372 
00373   defaultProgress->slotUnmounting( 0, point );
00374 }
00375 
00376 void ProgressItem::setCanResume( KIO::filesize_t offset ) {
00377   /*
00378   QString tmps;
00379   // set canResume
00380   if ( _resume ) {
00381     tmps = i18n("Yes");
00382   } else {
00383     tmps = i18n("No");
00384   }
00385   setText( listProgress->lv_resume, tmps );
00386   */
00387   defaultProgress->slotCanResume( 0, offset );
00388 }
00389 
00390 
00391 void ProgressItem::slotCanceled() {
00392   emit jobCanceled( this );
00393 }
00394 
00395 // Called 0.5s after the job has been started
00396 void ProgressItem::slotShowDefaultProgress() {
00397   if (defaultProgress)
00398   {
00399     if ( m_visible && m_defaultProgressVisible )
00400       defaultProgress->show();
00401     else
00402       defaultProgress->hide();
00403   }
00404 }
00405 
00406 void ProgressItem::slotToggleDefaultProgress() {
00407   setDefaultProgressVisible( !m_defaultProgressVisible );
00408 }
00409 
00410 // Called when a rename or skip dialog pops up
00411 // We want to prevent someone from killing the job in the uiserver then
00412 void ProgressItem::setVisible( bool visible ) {
00413   if ( m_visible != visible )
00414   {
00415     m_visible = visible;
00416     updateVisibility();
00417   }
00418 }
00419 
00420 // Can be toggled by the user
00421 void ProgressItem::setDefaultProgressVisible( bool visible ) {
00422   if ( m_defaultProgressVisible != visible )
00423   {
00424     m_defaultProgressVisible = visible;
00425     updateVisibility();
00426   }
00427 }
00428 
00429 // Update according to state
00430 void ProgressItem::updateVisibility()
00431 {
00432   if (defaultProgress)
00433   {
00434     if ( m_visible && m_defaultProgressVisible )
00435     {
00436       m_showTimer.start(250, true); // Show delayed
00437     }
00438     else
00439     {
00440       m_showTimer.stop();
00441       defaultProgress->hide();
00442     }
00443   }
00444 }
00445 
00446 
00447 //-----------------------------------------------------------------------------
00448 ListProgress::ListProgress (QWidget *parent, const char *name)
00449 : KListView (parent, name)
00450 {
00451 
00452   // enable selection of more than one item
00453   setMultiSelection( true );
00454 
00455   setAllColumnsShowFocus( true );
00456 
00457   m_lpcc[TB_OPERATION].title=i18n("Operation");
00458   m_lpcc[TB_LOCAL_FILENAME].title=i18n("Local Filename");
00459   m_lpcc[TB_RESUME].title=i18n("Resume", "Res.");
00460   m_lpcc[TB_COUNT].title=i18n("Count");
00461   m_lpcc[TB_PROGRESS].title=i18n("%");
00462   m_lpcc[TB_TOTAL].title=i18n("Size");
00463   m_lpcc[TB_SPEED].title=i18n("Speed");
00464   m_lpcc[TB_REMAINING_TIME].title=i18n("Rem. Time");
00465   m_lpcc[TB_ADDRESS].title=i18n("URL");
00466   readSettings();
00467 
00468   applySettings();
00469 
00470   //used for squeezing the text in local file name and url
00471   m_squeezer=new KSqueezedTextLabel(this);
00472   m_squeezer->hide();
00473   connect(header(),SIGNAL(sizeChange(int,int,int)),this,SLOT(columnWidthChanged(int)));
00474 }
00475 
00476 
00477 ListProgress::~ListProgress() {
00478 }
00479 
00480 void ListProgress::applySettings()
00481 {
00482   int iEnabledCols=0;
00483 
00484   // Update listcolumns to show
00485   for (int i=0; i<TB_MAX; i++)
00486   {
00487     if ( !m_lpcc[i].enabled )
00488       continue;
00489 
00490     iEnabledCols++;
00491 
00492     // Add new or reuse existing column
00493     if ( iEnabledCols > columns() )
00494       m_lpcc[i].index=addColumn(m_lpcc[i].title, m_fixedColumnWidths?m_lpcc[i].width:-1);
00495     else
00496     {
00497       m_lpcc[i].index = iEnabledCols - 1;
00498       setColumnText(m_lpcc[i].index, m_lpcc[i].title);
00499     }
00500 
00501     setColumnWidth(m_lpcc[i].index, m_lpcc[i].width); //yes, this is required here, alexxx
00502     if (m_fixedColumnWidths)
00503         setColumnWidthMode(m_lpcc[i].index, Manual);
00504   }
00505 
00506   // Remove unused columns. However we must keep one column left
00507   // Otherwise the listview will be emptied
00508   while( iEnabledCols < columns() && columns() > 1 )
00509      removeColumn( columns() - 1 );
00510 
00511   if ( columns() == 0 )
00512     addColumn( "" );
00513 
00514   if ( !m_showHeader || iEnabledCols == 0 )
00515     header()->hide();
00516   else
00517     header()->show();
00518 }
00519 
00520 void ListProgress::readSettings() {
00521   KConfig config("uiserverrc");
00522 
00523   // read listview geometry properties
00524   config.setGroup( "ProgressList" );
00525   for ( int i = 0; i < TB_MAX; i++ ) {
00526      QString tmps="Col"+QString::number(i);
00527      m_lpcc[i].width=config.readNumEntry( tmps, 0);
00528      if (m_lpcc[i].width==0) m_lpcc[i].width=defaultColumnWidth[i];
00529 
00530      tmps="Enabled"+QString::number(i);
00531      m_lpcc[i].enabled=config.readBoolEntry(tmps,true);
00532   }
00533   m_showHeader=config.readBoolEntry("ShowListHeader",true);
00534   m_fixedColumnWidths=config.readBoolEntry("FixedColumnWidths",false);
00535 
00536   m_lpcc[TB_RESUME].enabled=false;
00537 }
00538 
00539 void ListProgress::columnWidthChanged(int column)
00540 {
00541    //resqueeze if necessary
00542    if ((m_lpcc[TB_ADDRESS].enabled) && (column==m_lpcc[TB_ADDRESS].index))
00543    {
00544       for (QListViewItem* lvi=firstChild(); lvi!=0; lvi=lvi->nextSibling())
00545       {
00546          ProgressItem *pi=(ProgressItem*)lvi;
00547          pi->setText(TB_ADDRESS,pi->fullLengthAddress());
00548       }
00549    }
00550    writeSettings();
00551 }
00552 
00553 void ListProgress::writeSettings() {
00554    KConfig config("uiserverrc");
00555 
00556    // write listview geometry properties
00557    config.setGroup( "ProgressList" );
00558    for ( int i = 0; i < TB_MAX; i++ ) {
00559       if (!m_lpcc[i].enabled)
00560          continue;
00561       m_lpcc[i].width=columnWidth(m_lpcc[i].index);
00562       QString tmps="Col"+QString::number(i);
00563       config.writeEntry( tmps, m_lpcc[i].width);
00564    }
00565    config.writeEntry("ShowListHeader", m_showHeader);
00566    config.writeEntry("FixedColumnWidths", m_fixedColumnWidths);
00567    config.sync();
00568 }
00569 
00570 
00571 //------------------------------------------------------------
00572 
00573 
00574 UIServer::UIServer()
00575 :KMainWindow(0, "")
00576 ,DCOPObject("UIServer")
00577 ,m_shuttingDown(false)
00578 ,m_configDialog(0)
00579 ,m_contextMenu(0)
00580 ,m_systemTray(0)
00581 {
00582 
00583   readSettings();
00584 
00585   // setup toolbar
00586   toolBar()->insertButton("editdelete", TOOL_CANCEL,
00587                           SIGNAL(clicked()), this,
00588                           SLOT(slotCancelCurrent()), FALSE, i18n("Cancel"));
00589   toolBar()->insertButton("configure", TOOL_CONFIGURE,
00590                           SIGNAL(clicked()), this,
00591                           SLOT(slotConfigure()), true, i18n("Settings..."));
00592 
00593   toolBar()->setBarPos( KToolBar::Left );
00594 
00595   // setup statusbar
00596   statusBar()->insertItem( i18n(" Files: %1 ").arg( 0 ), ID_TOTAL_FILES);
00597   statusBar()->insertItem( i18n(" Size: %1 kB ").arg( "0" ), ID_TOTAL_SIZE);
00598   statusBar()->insertItem( i18n(" Time: 00:00:00 "), ID_TOTAL_TIME);
00599   statusBar()->insertItem( i18n(" %1 kB/s ").arg("0"), ID_TOTAL_SPEED);
00600 
00601   // setup listview
00602   listProgress = new ListProgress( this, "progresslist" );
00603 
00604   setCentralWidget( listProgress );
00605 
00606   connect( listProgress, SIGNAL( selectionChanged() ),
00607            SLOT( slotSelection() ) );
00608   connect( listProgress, SIGNAL( executed( QListViewItem* ) ),
00609            SLOT( slotToggleDefaultProgress( QListViewItem* ) ) );
00610   connect( listProgress, SIGNAL( contextMenu( KListView*, QListViewItem *, const QPoint &)),
00611            SLOT(slotShowContextMenu(KListView*, QListViewItem *, const QPoint&)));
00612 
00613 
00614   // setup animation timer
00615   updateTimer = new QTimer( this );
00616   connect( updateTimer, SIGNAL( timeout() ),
00617            SLOT( slotUpdate() ) );
00618   m_bUpdateNewJob=false;
00619 
00620   setCaption(i18n("Progress Dialog"));
00621   setMinimumSize( 150, 50 );
00622   resize( m_initWidth, m_initHeight);
00623 
00624   applySettings();
00625 
00626 /*  if ((m_bShowList) && (m_keepListOpen))
00627   {
00628      cerr<<"show() !"<<endl;
00629      show();
00630   }
00631   else*/
00632   hide();
00633 }
00634 
00635 UIServer::~UIServer() {
00636   updateTimer->stop();
00637 }
00638 
00639 void UIServer::applySettings()
00640 {
00641   if ((m_showSystemTray) && (m_systemTray==0))
00642   {
00643      m_systemTray=new UIServerSystemTray(this);
00644      m_systemTray->show();
00645   }
00646   else if ((m_showSystemTray==false) && (m_systemTray!=0))
00647   {
00648      delete m_systemTray;
00649      m_systemTray=0;
00650   }
00651 
00652   if (m_showStatusBar==false)
00653      statusBar()->hide();
00654   else
00655      statusBar()->show();
00656   if (m_showToolBar==false)
00657      toolBar()->hide();
00658   else
00659      toolBar()->show();
00660 }
00661 
00662 void UIServer::slotShowContextMenu(KListView*, QListViewItem* /*item*/, const QPoint& pos)
00663 {
00664    if (m_contextMenu==0)
00665    {
00666       m_contextMenu=new QPopupMenu(this);
00667       m_idCancelItem = m_contextMenu->insertItem(i18n("Cancel Job"), this, SLOT(slotCancelCurrent()));
00668 //      m_contextMenu->insertItem(i18n("Toggle Progress"), this, SLOT(slotToggleDefaultProgress()));
00669       m_contextMenu->insertSeparator();
00670       m_contextMenu->insertItem(i18n("Settings..."), this, SLOT(slotConfigure()));
00671    }
00672    bool enabled = false;
00673    QListViewItemIterator it( listProgress );
00674    for ( ; it.current(); ++it ) {
00675      if ( it.current()->isSelected() ) {
00676        enabled = true;
00677        break;
00678      }
00679    }
00680    m_contextMenu->setItemEnabled( m_idCancelItem, enabled);
00681 
00682    m_contextMenu->popup(pos);
00683 }
00684 
00685 void UIServer::slotRemoveSystemTrayIcon()
00686 {
00687    m_showSystemTray=false;
00688    applySettings();
00689    writeSettings();
00690 }
00691 
00692 void UIServer::slotConfigure()
00693 {
00694    if (m_configDialog==0)
00695    {
00696       m_configDialog=new ProgressConfigDialog(0);
00697 //      connect(m_configDialog,SIGNAL(cancelClicked()), this, SLOT(slotCancelConfig()));
00698       connect(m_configDialog,SIGNAL(okClicked()), this, SLOT(slotApplyConfig()));
00699       connect(m_configDialog,SIGNAL(applyClicked()), this, SLOT(slotApplyConfig()));
00700    }
00701    m_configDialog->m_showSystemTrayCb->setChecked(m_showSystemTray);
00702    m_configDialog->m_keepOpenCb->setChecked(m_keepListOpen);
00703    m_configDialog->m_toolBarCb->setChecked(m_showToolBar);
00704    m_configDialog->m_statusBarCb->setChecked(m_showStatusBar);
00705    m_configDialog->m_headerCb->setChecked(listProgress->m_showHeader);
00706    m_configDialog->m_fixedWidthCb->setChecked(listProgress->m_fixedColumnWidths);
00707    for (int i=0; i<ListProgress::TB_MAX; i++)
00708    {
00709       m_configDialog->setChecked(i, listProgress->m_lpcc[i].enabled);
00710    }
00711    m_configDialog->show();
00712 }
00713 
00714 void UIServer::slotApplyConfig()
00715 {
00716    m_showSystemTray=m_configDialog->m_showSystemTrayCb->isChecked();
00717    m_keepListOpen=m_configDialog->m_keepOpenCb->isChecked();
00718    m_showToolBar=m_configDialog->m_toolBarCb->isChecked();
00719    m_showStatusBar=m_configDialog->m_statusBarCb->isChecked();
00720    listProgress->m_showHeader=m_configDialog->m_headerCb->isChecked();
00721    listProgress->m_fixedColumnWidths=m_configDialog->m_fixedWidthCb->isChecked();
00722    for (int i=0; i<ListProgress::TB_MAX; i++)
00723       listProgress->m_lpcc[i].enabled=m_configDialog->isChecked(i);
00724 
00725 
00726    applySettings();
00727    listProgress->applySettings();
00728    writeSettings();
00729    listProgress->writeSettings();
00730 }
00731 
00732 int UIServer::newJob( QCString observerAppId, bool showProgress )
00733 {
00734   kdDebug(7024) << "UIServer::newJob observerAppId=" << observerAppId << ". "
00735             << "Giving id=" << s_jobId+1 << endl;
00736 
00737   QListViewItemIterator it( listProgress );
00738   for ( ; it.current(); ++it ) {
00739     if ( it.current()->itemBelow() == 0L ) { // this will find the end of list
00740       break;
00741     }
00742   }
00743 
00744   // increment counter
00745   s_jobId++;
00746 
00747   bool show = !m_bShowList && showProgress;
00748 
00749   ProgressItem *item = new ProgressItem( listProgress, it.current(), observerAppId, s_jobId, show );
00750   connect( item, SIGNAL( jobCanceled( ProgressItem* ) ),
00751            SLOT( slotJobCanceled( ProgressItem* ) ) );
00752 
00753   if ( m_bShowList && !updateTimer->isActive() )
00754     updateTimer->start( 1000 );
00755 
00756   m_bUpdateNewJob=true;
00757 
00758   return s_jobId;
00759 }
00760 
00761 
00762 ProgressItem* UIServer::findItem( int id )
00763 {
00764   QListViewItemIterator it( listProgress );
00765 
00766   ProgressItem *item;
00767 
00768   for ( ; it.current(); ++it ) {
00769     item = (ProgressItem*) it.current();
00770     if ( item->jobId() == id ) {
00771       return item;
00772     }
00773   }
00774 
00775   return 0L;
00776 }
00777 
00778 
00779 void UIServer::setItemVisible( ProgressItem * item, bool visible )
00780 {
00781   item->setVisible( visible );
00782   // Check if we were the last one to be visible
00783   // or the first one -> hide/show the list in that case
00784   // (Note that the user could have hidden the listview by hand yet, no time)
00785   if ( m_bShowList ) {
00786       m_bUpdateNewJob = true;
00787       slotUpdate();
00788   }
00789 }
00790 
00791 // Called by Observer when opening a skip or rename dialog
00792 void UIServer::setJobVisible( int id, bool visible )
00793 {
00794   kdDebug(7024) << "UIServer::setJobVisible id=" << id << " visible=" << visible << endl;
00795   ProgressItem *item = findItem( id );
00796   Q_ASSERT( item );
00797   if ( item )
00798       setItemVisible( item, visible );
00799 }
00800 
00801 void UIServer::jobFinished( int id )
00802 {
00803   kdDebug(7024) << "UIServer::jobFinished id=" << id << endl;
00804   ProgressItem *item = findItem( id );
00805 
00806   // remove item from the list and delete the corresponding defaultprogress
00807   if ( item ) {
00808     delete item;
00809   }
00810 }
00811 
00812 
00813 void UIServer::totalSize( int id, unsigned long size )
00814 { totalSize64(id, size); }
00815 
00816 void UIServer::totalSize64( int id, KIO::filesize_t size )
00817 {
00818 //  kdDebug(7024) << "UIServer::totalSize " << id << " " << KIO::number(size) << endl;
00819 
00820   ProgressItem *item = findItem( id );
00821   if ( item ) {
00822     item->setTotalSize( size );
00823   }
00824 }
00825 
00826 void UIServer::totalFiles( int id, unsigned long files )
00827 {
00828   kdDebug(7024) << "UIServer::totalFiles " << id << " " << (unsigned int) files << endl;
00829 
00830   ProgressItem *item = findItem( id );
00831   if ( item ) {
00832     item->setTotalFiles( files );
00833   }
00834 }
00835 
00836 void UIServer::totalDirs( int id, unsigned long dirs )
00837 {
00838   kdDebug(7024) << "UIServer::totalDirs " << id << " " << (unsigned int) dirs << endl;
00839 
00840   ProgressItem *item = findItem( id );
00841   if ( item ) {
00842     item->setTotalDirs( dirs );
00843   }
00844 }
00845 
00846 void UIServer::processedSize( int id, unsigned long size )
00847 { processedSize64(id, size); }
00848 
00849 void UIServer::processedSize64( int id, KIO::filesize_t size )
00850 {
00851   //kdDebug(7024) << "UIServer::processedSize " << id << " " << KIO::number(size) << endl;
00852 
00853   ProgressItem *item = findItem( id );
00854   if ( item ) {
00855     item->setProcessedSize( size );
00856   }
00857 }
00858 
00859 void UIServer::processedFiles( int id, unsigned long files )
00860 {
00861   //kdDebug(7024) << "UIServer::processedFiles " << id << " " << (unsigned int) files << endl;
00862 
00863   ProgressItem *item = findItem( id );
00864   if ( item ) {
00865     item->setProcessedFiles( files );
00866   }
00867 }
00868 
00869 void UIServer::processedDirs( int id, unsigned long dirs )
00870 {
00871   kdDebug(7024) << "UIServer::processedDirs " << id << " " << (unsigned int) dirs << endl;
00872 
00873   ProgressItem *item = findItem( id );
00874   if ( item ) {
00875     item->setProcessedDirs( dirs );
00876   }
00877 }
00878 
00879 void UIServer::percent( int id, unsigned long ipercent )
00880 {
00881   //kdDebug(7024) << "UIServer::percent " << id << " " << (unsigned int) ipercent << endl;
00882 
00883   ProgressItem *item = findItem( id );
00884   if ( item ) {
00885     item->setPercent( ipercent );
00886   }
00887 }
00888 
00889 void UIServer::speed( int id, unsigned long bytes_per_second )
00890 {
00891   //kdDebug(7024) << "UIServer::speed " << id << " " << (unsigned int) bytes_per_second << endl;
00892 
00893   ProgressItem *item = findItem( id );
00894   if ( item ) {
00895     item->setSpeed( bytes_per_second );
00896   }
00897 }
00898 
00899 void UIServer::infoMessage( int id, const QString & msg )
00900 {
00901   //kdDebug(7024) << "UIServer::infoMessage " << id << " " << msg << endl;
00902 
00903   ProgressItem *item = findItem( id );
00904   if ( item ) {
00905     item->setInfoMessage( msg );
00906   }
00907 }
00908 
00909 void UIServer::canResume( int id, unsigned long offset )
00910 { canResume64(id, offset); }
00911 
00912 void UIServer::canResume64( int id, KIO::filesize_t offset )
00913 {
00914   //kdDebug(7024) << "UIServer::canResume " << id << " " << offset << endl;
00915 
00916   ProgressItem *item = findItem( id );
00917   if ( item ) {
00918     item->setCanResume( offset );
00919   }
00920 }
00921 
00922 void UIServer::copying( int id, KURL from, KURL to )
00923 {
00924   //kdDebug(7024) << "UIServer::copying " << id << " " << from.url() << "  " << to.url() << endl;
00925 
00926   ProgressItem *item = findItem( id );
00927   if ( item ) {
00928     item->setCopying( from, to );
00929   }
00930 }
00931 
00932 void UIServer::moving( int id, KURL from, KURL to )
00933 {
00934   //kdDebug(7024) << "UIServer::moving " << id << " " << from.url() << "  " << to.url() << endl;
00935 
00936   ProgressItem *item = findItem( id );
00937   if ( item ) {
00938     item->setMoving( from, to );
00939   }
00940 }
00941 
00942 void UIServer::deleting( int id, KURL url )
00943 {
00944   //kdDebug(7024) << "UIServer::deleting " << id << " " << url.url() << endl;
00945 
00946   ProgressItem *item = findItem( id );
00947   if ( item ) {
00948     item->setDeleting( url );
00949   }
00950 }
00951 
00952 void UIServer::transferring( int id, KURL url )
00953 {
00954   //kdDebug(7024) << "UIServer::transferring " << id << " " << url.url() << endl;
00955 
00956   ProgressItem *item = findItem( id );
00957   if ( item ) {
00958     item->setTransferring( url );
00959   }
00960 }
00961 
00962 void UIServer::creatingDir( int id, KURL dir )
00963 {
00964   kdDebug(7024) << "UIServer::creatingDir " << id << " " << dir.url() << endl;
00965 
00966   ProgressItem *item = findItem( id );
00967   if ( item ) {
00968     item->setCreatingDir( dir );
00969   }
00970 }
00971 
00972 void UIServer::stating( int id, KURL url )
00973 {
00974   kdDebug(7024) << "UIServer::stating " << id << " " << url.url() << endl;
00975 
00976   ProgressItem *item = findItem( id );
00977   if ( item ) {
00978     item->setStating( url );
00979   }
00980 }
00981 
00982 void UIServer::mounting( int id, QString dev, QString point )
00983 {
00984   kdDebug(7024) << "UIServer::mounting " << id << " " << dev << " " << point << endl;
00985 
00986   ProgressItem *item = findItem( id );
00987   if ( item ) {
00988     item->setMounting( dev, point );
00989   }
00990 }
00991 
00992 void UIServer::unmounting( int id, QString point )
00993 {
00994   kdDebug(7024) << "UIServer::unmounting " << id << " " << point << endl;
00995 
00996   ProgressItem *item = findItem( id );
00997   if ( item ) {
00998     item->setUnmounting( point );
00999   }
01000 }
01001 
01002 void UIServer::killJob( QCString observerAppId, int progressId )
01003 {
01004     // Contact the object "KIO::Observer" in the application <appId>
01005     Observer_stub observer( observerAppId, "KIO::Observer" );
01006     // Tell it to kill the job
01007     observer.killJob( progressId );
01008 }
01009 
01010 void UIServer::slotJobCanceled( ProgressItem *item ) {
01011   kdDebug(7024) << "UIServer::slotJobCanceled appid=" << item->appId() << " jobid=" << item->jobId() << endl;
01012   // kill the corresponding job
01013   killJob( item->appId(), item->jobId() );
01014 
01015   // KIO::Job, when killed, should call back jobFinished(), but we can't
01016   // really rely on that - the app may have crashed
01017   delete item;
01018 }
01019 
01020 
01021 void UIServer::slotQuit()
01022 {
01023   m_shuttingDown = true;
01024   kapp->quit();
01025 }
01026 
01027 void UIServer::slotUpdate() {
01028   // don't do anything if we don't have any inserted progress item
01029   // or if they're all hidden
01030    QListViewItemIterator lvit( listProgress );
01031    bool visible = false;
01032    for ( ; lvit.current(); ++lvit )
01033       if ( ((ProgressItem*)lvit.current())->isVisible() ) {
01034          visible = true;
01035          break;
01036       }
01037 
01038    if ( !visible || !m_bShowList ) {
01039       if (!m_keepListOpen) hide();
01040       updateTimer->stop();
01041       return;
01042    }
01043 
01044   // Calling show() is conditional, so that users can close the window
01045   // and it only pops up back when a new job is started
01046   if (m_bUpdateNewJob)
01047   {
01048     m_bUpdateNewJob=false;
01049     show();
01050 
01051     // Make sure we'll be called back
01052     if ( m_bShowList && !updateTimer->isActive() )
01053       updateTimer->start( 1000 );
01054   }
01055 
01056   int iTotalFiles = 0;
01057   int iTotalSize = 0;
01058   int iTotalSpeed = 0;
01059   QTime totalRemTime;
01060 
01061   ProgressItem *item;
01062 
01063   // count totals for statusbar
01064   QListViewItemIterator it( listProgress );
01065 
01066   for ( ; it.current(); ++it ) {
01067     item = (ProgressItem*) it.current();
01068     if ( item->totalSize() != 0 ) {
01069       iTotalSize += ( item->totalSize() - item->processedSize() );
01070     }
01071     iTotalFiles += ( item->totalFiles() - item->processedFiles() );
01072     iTotalSpeed += item->speed();
01073 
01074     if ( item->remainingTime() > totalRemTime ) {
01075       totalRemTime = item->remainingTime();
01076     }
01077   }
01078 
01079   // update statusbar
01080   statusBar()->changeItem( i18n( " Files: %1 ").arg( iTotalFiles ), ID_TOTAL_FILES);
01081   statusBar()->changeItem( i18n( " Size: %1 ").arg( KIO::convertSize( iTotalSize ) ),
01082                            ID_TOTAL_SIZE);
01083   statusBar()->changeItem( i18n( " Time: %1 ").arg( totalRemTime.toString() ), ID_TOTAL_TIME);
01084   statusBar()->changeItem( i18n( " %1/s ").arg( KIO::convertSize( iTotalSpeed ) ),
01085                            ID_TOTAL_SPEED);
01086 
01087 }
01088 
01089 void UIServer::setListMode( bool list )
01090 {
01091   m_bShowList = list;
01092   QListViewItemIterator it( listProgress );
01093   for ( ; it.current(); ++it ) {
01094     // When going to list mode -> hide all progress dialogs
01095     // When going back to separate dialogs -> show them all
01096     ((ProgressItem*) it.current())->setDefaultProgressVisible( !list );
01097   }
01098 
01099   if (m_bShowList)
01100   {
01101     show();
01102     updateTimer->start( 1000 );
01103   }
01104   else
01105   {
01106     hide();
01107     updateTimer->stop();
01108   }
01109 }
01110 
01111 void UIServer::slotToggleDefaultProgress( QListViewItem *item ) {
01112   ((ProgressItem*) item )->slotToggleDefaultProgress();
01113 }
01114 
01115 
01116 void UIServer::slotSelection() {
01117   QListViewItemIterator it( listProgress );
01118 
01119   for ( ; it.current(); ++it ) {
01120     if ( it.current()->isSelected() ) {
01121       toolBar()->setItemEnabled( TOOL_CANCEL, TRUE);
01122       return;
01123     }
01124   }
01125   toolBar()->setItemEnabled( TOOL_CANCEL, FALSE);
01126 }
01127 
01128 // This code is deprecated, slaves go to Observer::openPassDlg now,
01129 // but this is kept for compat (DCOP calls to kio_uiserver).
01130 QByteArray UIServer::openPassDlg( const KIO::AuthInfo &info )
01131 {
01132     kdDebug(7024) << "UIServer::openPassDlg: User= " << info.username
01133                   << ", Msg= " << info.prompt << endl;
01134     KIO::AuthInfo inf(info);
01135     int result = KIO::PasswordDialog::getNameAndPassword( inf.username, inf.password,
01136                                                           &inf.keepPassword, inf.prompt,
01137                                                           inf.readOnly, inf.caption,
01138                                                           inf.comment, inf.commentLabel );
01139     QByteArray data;
01140     QDataStream stream( data, IO_WriteOnly );
01141     if ( result == QDialog::Accepted )
01142         inf.setModified( true );
01143     else
01144         inf.setModified( false );
01145     stream << inf;
01146     return data;
01147 }
01148 
01149 int UIServer::messageBox( int progressId, int type, const QString &text, const QString &caption, const QString &buttonYes, const QString &buttonNo )
01150 {
01151     return Observer::messageBox( progressId, type, text, caption, buttonYes, buttonNo );
01152 }
01153 
01154 void UIServer::showSSLInfoDialog(const QString &url, const KIO::MetaData &meta)
01155 {
01156    KSSLInfoDlg *kid = new KSSLInfoDlg(meta["ssl_in_use"].upper()=="TRUE", 0L /*parent?*/, 0L, true);
01157    KSSLCertificate *x = KSSLCertificate::fromString(meta["ssl_peer_certificate"].local8Bit());
01158    if (x) {
01159       // Set the chain back onto the certificate
01160       QStringList cl =
01161                       QStringList::split(QString("\n"), meta["ssl_peer_chain"]);
01162       QPtrList<KSSLCertificate> ncl;
01163 
01164       ncl.setAutoDelete(true);
01165       for (QStringList::Iterator it = cl.begin(); it != cl.end(); ++it) {
01166          KSSLCertificate *y = KSSLCertificate::fromString((*it).local8Bit());
01167          if (y) ncl.append(y);
01168       }
01169 
01170       if (ncl.count() > 0)
01171          x->chain().setChain(ncl);
01172 
01173       kdDebug(7024) << "ssl_cert_errors=" << meta["ssl_cert_errors"] << endl;
01174       kid->setCertState(meta["ssl_cert_errors"]);
01175       kid->setup( x,
01176                   meta["ssl_peer_ip"],
01177                   url, // the URL
01178                   meta["ssl_cipher"],
01179                   meta["ssl_cipher_desc"],
01180                   meta["ssl_cipher_version"],
01181                   meta["ssl_cipher_used_bits"].toInt(),
01182                   meta["ssl_cipher_bits"].toInt(),
01183                   KSSLCertificate::KSSLValidation(meta["ssl_cert_state"].toInt()));
01184       kdDebug(7024) << "Showing SSL Info dialog" << endl;
01185       kid->exec();
01186       delete x;
01187       kdDebug(7024) << "SSL Info dialog closed" << endl;
01188    } else {
01189       KMessageBox::information( 0L, // parent ?
01190                               i18n("The peer SSL certificate appears to be corrupt."), i18n("SSL") );
01191    }
01192    // Don't delete kid!!
01193 }
01194 
01195 KSSLCertDlgRet UIServer::showSSLCertDialog(const QString& host, const QStringList& certList)
01196 {
01197    KSSLCertDlgRet rc;
01198    rc.ok = false;
01199    if (!certList.isEmpty()) {
01200       KSSLCertDlg *kcd = new KSSLCertDlg(0L, 0L, true);
01201       kcd->setupDialog(certList);
01202       kcd->setHost(host);
01203       kdDebug(7024) << "Showing SSL certificate dialog" << endl;
01204       kcd->exec();
01205       rc.ok = true;
01206       rc.choice = kcd->getChoice();
01207       rc.save = kcd->saveChoice();
01208       rc.send = kcd->wantsToSend();
01209       kdDebug(7024) << "SSL certificate dialog closed" << endl;
01210       delete kcd;
01211    }
01212    return rc;
01213 }
01214 
01215 
01216 QByteArray UIServer::open_RenameDlg( int id,
01217                                      const QString & caption,
01218                                      const QString& src, const QString & dest,
01219                                      int mode,
01220                                      unsigned long sizeSrc,
01221                                      unsigned long sizeDest,
01222                                      unsigned long ctimeSrc,
01223                                      unsigned long ctimeDest,
01224                                      unsigned long mtimeSrc,
01225                                      unsigned long mtimeDest
01226                                      )
01227 { return open_RenameDlg64(id, caption, src, dest, mode, sizeSrc, sizeDest,
01228                           ctimeSrc, ctimeDest, mtimeSrc, mtimeDest); }
01229 
01230 
01231 QByteArray UIServer::open_RenameDlg64( int id,
01232                                      const QString & caption,
01233                                      const QString& src, const QString & dest,
01234                                      int mode,
01235                                      KIO::filesize_t sizeSrc,
01236                                      KIO::filesize_t sizeDest,
01237                                      unsigned long ctimeSrc,
01238                                      unsigned long ctimeDest,
01239                                      unsigned long mtimeSrc,
01240                                      unsigned long mtimeDest
01241                                      )
01242 {
01243   // Hide existing dialog box if any
01244   ProgressItem *item = findItem( id );
01245   if ( item )
01246     setItemVisible( item, false );
01247   QString newDest;
01248   kdDebug(7024) << "Calling KIO::open_RenameDlg" << endl;
01249   KIO::RenameDlg_Result result = KIO::open_RenameDlg( caption, src, dest,
01250                                                       (KIO::RenameDlg_Mode) mode, newDest,
01251                                                       sizeSrc, sizeDest,
01252                                                       (time_t)ctimeSrc, (time_t)ctimeDest,
01253                                                       (time_t)mtimeSrc, (time_t)mtimeDest );
01254   kdDebug(7024) << "KIO::open_RenameDlg done" << endl;
01255   QByteArray data;
01256   QDataStream stream( data, IO_WriteOnly );
01257   stream << Q_UINT8(result) << newDest;
01258   if ( item && result != KIO::R_CANCEL )
01259     setItemVisible( item, true );
01260   return data;
01261 }
01262 
01263 int UIServer::open_SkipDlg( int id,
01264                             int /*bool*/ multi,
01265                             const QString & error_text )
01266 {
01267   // Hide existing dialog box if any
01268   ProgressItem *item = findItem( id );
01269   if ( item )
01270     setItemVisible( item, false );
01271   kdDebug(7024) << "Calling KIO::open_SkipDlg" << endl;
01272   KIO::SkipDlg_Result result = KIO::open_SkipDlg( (bool)multi, error_text );
01273   if ( item && result != KIO::S_CANCEL )
01274     setItemVisible( item, true );
01275   return (KIO::SkipDlg_Result) result;
01276 }
01277 
01278 
01279 void UIServer::readSettings() {
01280   KConfig config("uiserverrc");
01281   config.setGroup( "UIServer" );
01282   m_showStatusBar=config.readBoolEntry("ShowStatusBar",false);
01283   m_showToolBar=config.readBoolEntry("ShowToolBar",true);
01284   m_keepListOpen=config.readBoolEntry("KeepListOpen",false);
01285   m_initWidth=config.readNumEntry("InitialWidth",460);
01286   m_initHeight=config.readNumEntry("InitialHeight",150);
01287   m_bShowList = config.readBoolEntry( "ShowList", false );
01288   m_showSystemTray=config.readBoolEntry("ShowSystemTray", false);
01289 }
01290 
01291 void UIServer::writeSettings() {
01292   KConfig config("uiserverrc");
01293   config.setGroup( "UIServer" );
01294   config.writeEntry("InitialWidth",width());
01295   config.writeEntry("InitialHeight",height());
01296   config.writeEntry("ShowStatusBar", m_showStatusBar);
01297   config.writeEntry("ShowToolBar", m_showToolBar);
01298   config.writeEntry("KeepListOpen", m_keepListOpen);
01299   config.writeEntry("ShowList", m_bShowList);
01300   config.writeEntry("ShowSystemTray", m_showSystemTray);
01301 }
01302 
01303 
01304 void UIServer::slotCancelCurrent() {
01305   QListViewItemIterator it( listProgress );
01306   ProgressItem *item;
01307 
01308   // kill selected jobs
01309   for ( ; it.current() ; ++it )
01310   {
01311     if ( it.current()->isSelected() ) {
01312       item = (ProgressItem*) it.current();
01313       killJob( item->appId(), item->jobId() );
01314       return;
01315     }
01316   }
01317 }
01318 
01319 void UIServer::resizeEvent(QResizeEvent* e)
01320 {
01321    KMainWindow::resizeEvent(e);
01322    writeSettings();
01323 }
01324 
01325 bool UIServer::queryClose()
01326 {
01327   if ( !m_shuttingDown ) {
01328     hide();
01329     return false;
01330   }
01331   return true;
01332 }
01333 
01334 UIServer* UIServer::createInstance()
01335 {
01336     return new UIServer;
01337 }
01338 
01339 //------------------------------------------------------------
01340 
01341 extern "C" int kdemain(int argc, char **argv)
01342 {
01343     KLocale::setMainCatalogue("kdelibs");
01344     //  GS 5/2001 - I changed the name to "KDE" to make it look better
01345     //              in the titles of dialogs which are displayed.
01346     KAboutData aboutdata("kio_uiserver", I18N_NOOP("KDE"),
01347                          "0.8", I18N_NOOP("KDE Progress Information UI Server"),
01348                          KAboutData::License_GPL, "(C) 2000, David Faure & Matt Koss");
01349     // Who's the maintainer ? :)
01350     aboutdata.addAuthor("David Faure",I18N_NOOP("Developer"),"faure@kde.org");
01351     aboutdata.addAuthor("Matej Koss",I18N_NOOP("Developer"),"koss@miesto.sk");
01352 
01353     KCmdLineArgs::init( argc, argv, &aboutdata );
01354     // KCmdLineArgs::addCmdLineOptions( options );
01355     KUniqueApplication::addCmdLineOptions();
01356 
01357     if (!KUniqueApplication::start())
01358     {
01359       kdDebug(7024) << "kio_uiserver is already running!" << endl;
01360       return (0);
01361     }
01362 
01363     KUniqueApplication app;
01364 
01365     // This app is started automatically, no need for session management
01366     app.disableSessionManagement();
01367     app.dcopClient()->setDaemonMode( true );
01368 
01369     uiserver = UIServer::createInstance();
01370 
01371 //    app.setMainWidget( uiserver );
01372 
01373     return app.exec();
01374 }
01375 
01376 #include "uiserver.moc"
KDE Logo
This file is part of the documentation for kio Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:35:10 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003