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