kio Library: uiserver.cpp Source File (kio Library)

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

# uiserver.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2000 Matej Koss <koss@miesto.sk>
    00003                       David Faure <faure@kde.org>
    00004                  2001 George Staikos <staikos@kde.org>
    00005
    00006    This library is free software; you can redistribute it and/or
    00007    modify it under the terms of the GNU Library General Public
    00008    License version 2 as published by the Free Software Foundation.
    00009
    00010    This library is distributed in the hope that it will be useful,
    00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013    Library General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Library General Public License
    00016    along with this library; see the file COPYING.LIB.  If not, write to
    00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018    Boston, MA 02111-1307, USA.
    00019 */
    00020 // -*- mode: c++; c-basic-offset: 4 -*-
    00021
    00022 #include <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   const QString tmps = KIO::DefaultProgress::makePercentString( percent, m_iTotalSize, m_iTotalFiles );
    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          QString tmps= "Enabled" + QString::number(i);
    00570          config.writeEntry( tmps, false );
    00571          continue;
    00572       }
    00573       m_lpcc[i].width=columnWidth(m_lpcc[i].index);
    00574       QString tmps="Col"+QString::number(i);
    00575       config.writeEntry( tmps, m_lpcc[i].width);
    00576    }
    00577    config.writeEntry("ShowListHeader", m_showHeader);
    00578    config.writeEntry("FixedColumnWidths", m_fixedColumnWidths);
    00579    config.sync();
    00580 }
    00581
    00582
    00583 //------------------------------------------------------------
    00584
    00585
    00586 UIServer::UIServer()
    00587 :KMainWindow(0, "")
    00588 ,DCOPObject("UIServer")
    00589 ,m_shuttingDown(false)
    00590 ,m_configDialog(0)
    00591 ,m_contextMenu(0)
    00592 ,m_systemTray(0)
    00593 {
    00594
    00595   readSettings();
    00596
    00597   // setup toolbar
    00598   toolBar()->insertButton("editdelete", TOOL_CANCEL,
    00599                           SIGNAL(clicked()), this,
    00600                           SLOT(slotCancelCurrent()), FALSE, i18n("Cancel"));
    00601   toolBar()->insertButton("configure", TOOL_CONFIGURE,
    00602                           SIGNAL(clicked()), this,
    00603                           SLOT(slotConfigure()), true, i18n("Settings..."));
    00604
    00605   toolBar()->setBarPos( KToolBar::Left );
    00606
    00607   // setup statusbar
    00608   statusBar()->insertItem( i18n(" Files: %1 ").arg( 0 ), ID_TOTAL_FILES);
    00609   statusBar()->insertItem( i18n("Remaining Size", " Rem. Size: %1 kB ").arg( "0" ), ID_TOTAL_SIZE);
    00610   statusBar()->insertItem( i18n("Remaining Time", " Rem. Time: 00:00:00 "), ID_TOTAL_TIME);
    00611   statusBar()->insertItem( i18n(" %1 kB/s ").arg("0"), ID_TOTAL_SPEED);
    00612
    00613   // setup listview
    00614   listProgress = new ListProgress( this, "progresslist" );
    00615
    00616   setCentralWidget( listProgress );
    00617
    00618   connect( listProgress, SIGNAL( selectionChanged() ),
    00619            SLOT( slotSelection() ) );
    00620   connect( listProgress, SIGNAL( executed( QListViewItem* ) ),
    00621            SLOT( slotToggleDefaultProgress( QListViewItem* ) ) );
    00622   connect( listProgress, SIGNAL( contextMenu( KListView*, QListViewItem *, const QPoint &)),
    00623            SLOT(slotShowContextMenu(KListView*, QListViewItem *, const QPoint&)));
    00624
    00625
    00626   // setup animation timer
    00627   updateTimer = new QTimer( this );
    00628   connect( updateTimer, SIGNAL( timeout() ),
    00629            SLOT( slotUpdate() ) );
    00630   m_bUpdateNewJob=false;
    00631
    00632   setCaption(i18n("Progress Dialog"));
    00633   setMinimumSize( 150, 50 );
    00634   resize( m_initWidth, m_initHeight);
    00635
    00636   applySettings();
    00637
    00638 /*  if ((m_bShowList) && (m_keepListOpen))
    00639   {
    00640      cerr<<"show() !"<<endl;
    00641      show();
    00642   }
    00643   else*/
    00644   hide();
    00645 }
    00646
    00647 UIServer::~UIServer() {
    00648   updateTimer->stop();
    00649 }
    00650
    00651 void UIServer::applySettings()
    00652 {
    00653   if ((m_showSystemTray) && (m_systemTray==0))
    00654   {
    00655      m_systemTray=new UIServerSystemTray(this);
    00656      m_systemTray->show();
    00657   }
    00658   else if ((m_showSystemTray==false) && (m_systemTray!=0))
    00659   {
    00660      delete m_systemTray;
    00661      m_systemTray=0;
    00662   }
    00663
    00664   if (m_showStatusBar==false)
    00665      statusBar()->hide();
    00666   else
    00667      statusBar()->show();
    00668   if (m_showToolBar==false)
    00669      toolBar()->hide();
    00670   else
    00671      toolBar()->show();
    00672 }
    00673
    00674 void UIServer::slotShowContextMenu(KListView*, QListViewItem* item, const QPoint& pos)
    00675 {
    00676    if (m_contextMenu==0)
    00677    {
    00678       m_contextMenu=new QPopupMenu(this);
    00679       m_idCancelItem = m_contextMenu->insertItem(i18n("Cancel Job"), this, SLOT(slotCancelCurrent()));
    00680 //      m_contextMenu->insertItem(i18n("Toggle Progress"), this, SLOT(slotToggleDefaultProgress()));
    00681       m_contextMenu->insertSeparator();
    00682       m_contextMenu->insertItem(i18n("Settings..."), this, SLOT(slotConfigure()));
    00683    }
    00684    if ( item )
    00685        item->setSelected( true );
    00686    bool enabled = false;
    00687    QListViewItemIterator it( listProgress );
    00688    for ( ; it.current(); ++it ) {
    00689      if ( it.current()->isSelected() ) {
    00690        enabled = true;
    00691        break;
    00692      }
    00693    }
    00694    m_contextMenu->setItemEnabled( m_idCancelItem, enabled);
    00695
    00696    m_contextMenu->popup(pos);
    00697 }
    00698
    00699 void UIServer::slotRemoveSystemTrayIcon()
    00700 {
    00701    m_showSystemTray=false;
    00702    applySettings();
    00703    writeSettings();
    00704 }
    00705
    00706 void UIServer::slotConfigure()
    00707 {
    00708    if (m_configDialog==0)
    00709    {
    00710       m_configDialog=new ProgressConfigDialog(0);
    00711 //      connect(m_configDialog,SIGNAL(cancelClicked()), this, SLOT(slotCancelConfig()));
    00712       connect(m_configDialog,SIGNAL(okClicked()), this, SLOT(slotApplyConfig()));
    00713       connect(m_configDialog,SIGNAL(applyClicked()), this, SLOT(slotApplyConfig()));
    00714    }
    00715    m_configDialog->m_showSystemTrayCb->setChecked(m_showSystemTray);
    00716    m_configDialog->m_keepOpenCb->setChecked(m_keepListOpen);
    00717    m_configDialog->m_toolBarCb->setChecked(m_showToolBar);
    00718    m_configDialog->m_statusBarCb->setChecked(m_showStatusBar);
    00719    m_configDialog->m_headerCb->setChecked(listProgress->m_showHeader);
    00720    m_configDialog->m_fixedWidthCb->setChecked(listProgress->m_fixedColumnWidths);
    00721    for (int i=0; i<ListProgress::TB_MAX; i++)
    00722    {
    00723       m_configDialog->setChecked(i, listProgress->m_lpcc[i].enabled);
    00724    }
    00725    m_configDialog->show();
    00726 }
    00727
    00728 void UIServer::slotApplyConfig()
    00729 {
    00730    m_showSystemTray=m_configDialog->m_showSystemTrayCb->isChecked();
    00731    m_keepListOpen=m_configDialog->m_keepOpenCb->isChecked();
    00732    m_showToolBar=m_configDialog->m_toolBarCb->isChecked();
    00733    m_showStatusBar=m_configDialog->m_statusBarCb->isChecked();
    00734    listProgress->m_showHeader=m_configDialog->m_headerCb->isChecked();
    00735    listProgress->m_fixedColumnWidths=m_configDialog->m_fixedWidthCb->isChecked();
    00736    for (int i=0; i<ListProgress::TB_MAX; i++)
    00737       listProgress->m_lpcc[i].enabled=m_configDialog->isChecked(i);
    00738
    00739
    00740    applySettings();
    00741    listProgress->applySettings();
    00742    writeSettings();
    00743    listProgress->writeSettings();
    00744 }
    00745
    00746 int UIServer::newJob( QCString observerAppId, bool showProgress )
    00747 {
    00748   kdDebug(7024) << "UIServer::newJob observerAppId=" << observerAppId << ". "
    00749             << "Giving id=" << s_jobId+1 << endl;
    00750
    00751   QListViewItemIterator it( listProgress );
    00752   for ( ; it.current(); ++it ) {
    00753     if ( it.current()->itemBelow() == 0L ) { // this will find the end of list
    00754       break;
    00755     }
    00756   }
    00757
    00758   // increment counter
    00759   s_jobId++;
    00760
    00761   bool show = !m_bShowList && showProgress;
    00762
    00763   ProgressItem *item = new ProgressItem( listProgress, it.current(), observerAppId, s_jobId, show );
    00764   connect( item, SIGNAL( jobCanceled( ProgressItem* ) ),
    00765            SLOT( slotJobCanceled( ProgressItem* ) ) );
    00766
    00767   if ( m_bShowList && !updateTimer->isActive() )
    00768     updateTimer->start( 1000 );
    00769
    00770   m_bUpdateNewJob=true;
    00771
    00772   return s_jobId;
    00773 }
    00774
    00775
    00776 ProgressItem* UIServer::findItem( int id )
    00777 {
    00778   QListViewItemIterator it( listProgress );
    00779
    00780   ProgressItem *item;
    00781
    00782   for ( ; it.current(); ++it ) {
    00783     item = (ProgressItem*) it.current();
    00784     if ( item->jobId() == id ) {
    00785       return item;
    00786     }
    00787   }
    00788
    00789   return 0L;
    00790 }
    00791
    00792
    00793 void UIServer::setItemVisible( ProgressItem * item, bool visible )
    00794 {
    00795   item->setVisible( visible );
    00796   // Check if we were the last one to be visible
    00797   // or the first one -> hide/show the list in that case
    00798   // (Note that the user could have hidden the listview by hand yet, no time)
    00799   if ( m_bShowList ) {
    00800       m_bUpdateNewJob = true;
    00801       slotUpdate();
    00802   }
    00803 }
    00804
    00805 // Called by Observer when opening a skip or rename dialog
    00806 void UIServer::setJobVisible( int id, bool visible )
    00807 {
    00808   kdDebug(7024) << "UIServer::setJobVisible id=" << id << " visible=" << visible << endl;
    00809   ProgressItem *item = findItem( id );
    00810   Q_ASSERT( item );
    00811   if ( item )
    00812       setItemVisible( item, visible );
    00813 }
    00814
    00815 void UIServer::jobFinished( int id )
    00816 {
    00817   kdDebug(7024) << "UIServer::jobFinished id=" << id << endl;
    00818   ProgressItem *item = findItem( id );
    00819
    00820   // remove item from the list and delete the corresponding defaultprogress
    00821   if ( item ) {
    00822     if ( item->keepOpen() )
    00823       item->finished();
    00824     else
    00825     delete item;
    00826   }
    00827 }
    00828
    00829
    00830 void UIServer::totalSize( int id, unsigned long size )
    00831 { totalSize64(id, size); }
    00832
    00833 void UIServer::totalSize64( int id, KIO::filesize_t size )
    00834 {
    00835 //  kdDebug(7024) << "UIServer::totalSize " << id << " " << KIO::number(size) << endl;
    00836
    00837   ProgressItem *item = findItem( id );
    00838   if ( item ) {
    00839     item->setTotalSize( size );
    00840   }
    00841 }
    00842
    00843 void UIServer::totalFiles( int id, unsigned long files )
    00844 {
    00845   kdDebug(7024) << "UIServer::totalFiles " << id << " " << (unsigned int) files << endl;
    00846
    00847   ProgressItem *item = findItem( id );
    00848   if ( item ) {
    00849     item->setTotalFiles( files );
    00850   }
    00851 }
    00852
    00853 void UIServer::totalDirs( int id, unsigned long dirs )
    00854 {
    00855   kdDebug(7024) << "UIServer::totalDirs " << id << " " << (unsigned int) dirs << endl;
    00856
    00857   ProgressItem *item = findItem( id );
    00858   if ( item ) {
    00859     item->setTotalDirs( dirs );
    00860   }
    00861 }
    00862
    00863 void UIServer::processedSize( int id, unsigned long size )
    00864 { processedSize64(id, size); }
    00865
    00866 void UIServer::processedSize64( int id, KIO::filesize_t size )
    00867 {
    00868   //kdDebug(7024) << "UIServer::processedSize " << id << " " << KIO::number(size) << endl;
    00869
    00870   ProgressItem *item = findItem( id );
    00871   if ( item ) {
    00872     item->setProcessedSize( size );
    00873   }
    00874 }
    00875
    00876 void UIServer::processedFiles( int id, unsigned long files )
    00877 {
    00878   //kdDebug(7024) << "UIServer::processedFiles " << id << " " << (unsigned int) files << endl;
    00879
    00880   ProgressItem *item = findItem( id );
    00881   if ( item ) {
    00882     item->setProcessedFiles( files );
    00883   }
    00884 }
    00885
    00886 void UIServer::processedDirs( int id, unsigned long dirs )
    00887 {
    00888   kdDebug(7024) << "UIServer::processedDirs " << id << " " << (unsigned int) dirs << endl;
    00889
    00890   ProgressItem *item = findItem( id );
    00891   if ( item ) {
    00892     item->setProcessedDirs( dirs );
    00893   }
    00894 }
    00895
    00896 void UIServer::percent( int id, unsigned long ipercent )
    00897 {
    00898   //kdDebug(7024) << "UIServer::percent " << id << " " << (unsigned int) ipercent << endl;
    00899
    00900   ProgressItem *item = findItem( id );
    00901   if ( item ) {
    00902     item->setPercent( ipercent );
    00903   }
    00904 }
    00905
    00906 void UIServer::speed( int id, unsigned long bytes_per_second )
    00907 {
    00908   //kdDebug(7024) << "UIServer::speed " << id << " " << (unsigned int) bytes_per_second << endl;
    00909
    00910   ProgressItem *item = findItem( id );
    00911   if ( item ) {
    00912     item->setSpeed( bytes_per_second );
    00913   }
    00914 }
    00915
    00916 void UIServer::infoMessage( int id, const QString & msg )
    00917 {
    00918   //kdDebug(7024) << "UIServer::infoMessage " << id << " " << msg << endl;
    00919
    00920   ProgressItem *item = findItem( id );
    00921   if ( item ) {
    00922     item->setInfoMessage( msg );
    00923   }
    00924 }
    00925
    00926 void UIServer::canResume( int id, unsigned long offset )
    00927 { canResume64(id, offset); }
    00928
    00929 void UIServer::canResume64( int id, KIO::filesize_t offset )
    00930 {
    00931   //kdDebug(7024) << "UIServer::canResume " << id << " " << offset << endl;
    00932
    00933   ProgressItem *item = findItem( id );
    00934   if ( item ) {
    00935     item->setCanResume( offset );
    00936   }
    00937 }
    00938
    00939 void UIServer::copying( int id, KURL from, KURL to )
    00940 {
    00941   //kdDebug(7024) << "UIServer::copying " << id << " " << from.url() << "  " << to.url() << endl;
    00942
    00943   ProgressItem *item = findItem( id );
    00944   if ( item ) {
    00945     item->setCopying( from, to );
    00946   }
    00947 }
    00948
    00949 void UIServer::moving( int id, KURL from, KURL to )
    00950 {
    00951   //kdDebug(7024) << "UIServer::moving " << id << " " << from.url() << "  " << to.url() << endl;
    00952
    00953   ProgressItem *item = findItem( id );
    00954   if ( item ) {
    00955     item->setMoving( from, to );
    00956   }
    00957 }
    00958
    00959 void UIServer::deleting( int id, KURL url )
    00960 {
    00961   //kdDebug(7024) << "UIServer::deleting " << id << " " << url.url() << endl;
    00962
    00963   ProgressItem *item = findItem( id );
    00964   if ( item ) {
    00965     item->setDeleting( url );
    00966   }
    00967 }
    00968
    00969 void UIServer::transferring( int id, KURL url )
    00970 {
    00971   //kdDebug(7024) << "UIServer::transferring " << id << " " << url.url() << endl;
    00972
    00973   ProgressItem *item = findItem( id );
    00974   if ( item ) {
    00975     item->setTransferring( url );
    00976   }
    00977 }
    00978
    00979 void UIServer::creatingDir( int id, KURL dir )
    00980 {
    00981   kdDebug(7024) << "UIServer::creatingDir " << id << " " << dir.url() << endl;
    00982
    00983   ProgressItem *item = findItem( id );
    00984   if ( item ) {
    00985     item->setCreatingDir( dir );
    00986   }
    00987 }
    00988
    00989 void UIServer::stating( int id, KURL url )
    00990 {
    00991   kdDebug(7024) << "UIServer::stating " << id << " " << url.url() << endl;
    00992
    00993   ProgressItem *item = findItem( id );
    00994   if ( item ) {
    00995     item->setStating( url );
    00996   }
    00997 }
    00998
    00999 void UIServer::mounting( int id, QString dev, QString point )
    01000 {
    01001   kdDebug(7024) << "UIServer::mounting " << id << " " << dev << " " << point << endl;
    01002
    01003   ProgressItem *item = findItem( id );
    01004   if ( item ) {
    01005     item->setMounting( dev, point );
    01006   }
    01007 }
    01008
    01009 void UIServer::unmounting( int id, QString point )
    01010 {
    01011   kdDebug(7024) << "UIServer::unmounting " << id << " " << point << endl;
    01012
    01013   ProgressItem *item = findItem( id );
    01014   if ( item ) {
    01015     item->setUnmounting( point );
    01016   }
    01017 }
    01018
    01019 void UIServer::killJob( QCString observerAppId, int progressId )
    01020 {
    01021     // Contact the object "KIO::Observer" in the application <appId>
    01022     Observer_stub observer( observerAppId, "KIO::Observer" );
    01023     // Tell it to kill the job
    01024     observer.killJob( progressId );
    01025 }
    01026
    01027 void UIServer::slotJobCanceled( ProgressItem *item ) {
    01028   kdDebug(7024) << "UIServer::slotJobCanceled appid=" << item->appId() << " jobid=" << item->jobId() << endl;
    01029   // kill the corresponding job
    01030   killJob( item->appId(), item->jobId() );
    01031
    01032   // KIO::Job, when killed, should call back jobFinished(), but we can't
    01033   // really rely on that - the app may have crashed
    01034   delete item;
    01035 }
    01036
    01037
    01038 void UIServer::slotQuit()
    01039 {
    01040   m_shuttingDown = true;
    01041   kapp->quit();
    01042 }
    01043
    01044 void UIServer::slotUpdate() {
    01045   // don't do anything if we don't have any inserted progress item
    01046   // or if they're all hidden
    01047    QListViewItemIterator lvit( listProgress );
    01048    bool visible = false;
    01049    for ( ; lvit.current(); ++lvit )
    01050       if ( ((ProgressItem*)lvit.current())->isVisible() ) {
    01051          visible = true;
    01052          break;
    01053       }
    01054
    01055    if ( !visible || !m_bShowList ) {
    01056       if (!m_keepListOpen) hide();
    01057       updateTimer->stop();
    01058       return;
    01059    }
    01060
    01061   // Calling show() is conditional, so that users can close the window
    01062   // and it only pops up back when a new job is started
    01063   if (m_bUpdateNewJob)
    01064   {
    01065     m_bUpdateNewJob=false;
    01066     show();
    01067
    01068     // Make sure we'll be called back
    01069     if ( m_bShowList && !updateTimer->isActive() )
    01070       updateTimer->start( 1000 );
    01071   }
    01072
    01073   int iTotalFiles = 0;
    01074   KIO::filesize_t iTotalSize = 0;
    01075   int iTotalSpeed = 0;
    01076   QTime totalRemTime;
    01077
    01078   ProgressItem *item;
    01079
    01080   // count totals for statusbar
    01081   QListViewItemIterator it( listProgress );
    01082
    01083   for ( ; it.current(); ++it ) {
    01084     item = (ProgressItem*) it.current();
    01085     if ( item->totalSize() != 0 ) {
    01086       iTotalSize += ( item->totalSize() - item->processedSize() );
    01087     }
    01088     iTotalFiles += ( item->totalFiles() - item->processedFiles() );
    01089     iTotalSpeed += item->speed();
    01090
    01091     if ( item->remainingTime() > totalRemTime ) {
    01092       totalRemTime = item->remainingTime();
    01093     }
    01094   }
    01095
    01096   // update statusbar
    01097   statusBar()->changeItem( i18n( " Files: %1 ").arg( iTotalFiles ), ID_TOTAL_FILES);
    01098   statusBar()->changeItem( i18n( "Remaining Size", " Rem. Size: %1 ").arg( KIO::convertSize( iTotalSize ) ),
    01099                            ID_TOTAL_SIZE);
    01100   statusBar()->changeItem( i18n( "Remaining Time", " Rem. Time: %1 ").arg( totalRemTime.toString() ),
    01101                            ID_TOTAL_TIME);
    01102   statusBar()->changeItem( i18n( " %1/s ").arg( KIO::convertSize( iTotalSpeed ) ),
    01103                            ID_TOTAL_SPEED);
    01104
    01105 }
    01106
    01107 void UIServer::setListMode( bool list )
    01108 {
    01109   m_bShowList = list;
    01110   QListViewItemIterator it( listProgress );
    01111   for ( ; it.current(); ++it ) {
    01112     // When going to list mode -> hide all progress dialogs
    01113     // When going back to separate dialogs -> show them all
    01114     ((ProgressItem*) it.current())->setDefaultProgressVisible( !list );
    01115   }
    01116
    01117   if (m_bShowList)
    01118   {
    01119     show();
    01120     updateTimer->start( 1000 );
    01121   }
    01122   else
    01123   {
    01124     hide();
    01125     updateTimer->stop();
    01126   }
    01127 }
    01128
    01129 void UIServer::slotToggleDefaultProgress( QListViewItem *item ) {
    01130   ((ProgressItem*) item )->slotToggleDefaultProgress();
    01131 }
    01132
    01133
    01134 void UIServer::slotSelection() {
    01135   QListViewItemIterator it( listProgress );
    01136
    01137   for ( ; it.current(); ++it ) {
    01138     if ( it.current()->isSelected() ) {
    01139       toolBar()->setItemEnabled( TOOL_CANCEL, TRUE);
    01140       return;
    01141     }
    01142   }
    01143   toolBar()->setItemEnabled( TOOL_CANCEL, FALSE);
    01144 }
    01145
    01146 // This code is deprecated, slaves go to Observer::openPassDlg now,
    01147 // but this is kept for compat (DCOP calls to kio_uiserver).
    01148 QByteArray UIServer::openPassDlg( const KIO::AuthInfo &info )
    01149 {
    01150     kdDebug(7024) << "UIServer::openPassDlg: User= " << info.username
    01151                   << ", Msg= " << info.prompt << endl;
    01152     KIO::AuthInfo inf(info);
    01153     int result = KIO::PasswordDialog::getNameAndPassword( inf.username, inf.password,
    01154                                                           &inf.keepPassword, inf.prompt,
    01155                                                           inf.readOnly, inf.caption,
    01156                                                           inf.comment, inf.commentLabel );
    01157     QByteArray data;
    01158     QDataStream stream( data, IO_WriteOnly );
    01159     if ( result == QDialog::Accepted )
    01160         inf.setModified( true );
    01161     else
    01162         inf.setModified( false );
    01163     stream << inf;
    01164     return data;
    01165 }
    01166
    01167 int UIServer::messageBox( int progressId, int type, const QString &text, const QString &caption, const QString &buttonYes, const QString &buttonNo )
    01168 {
    01169     return Observer::messageBox( progressId, type, text, caption, buttonYes, buttonNo );
    01170 }
    01171
    01172 void UIServer::showSSLInfoDialog(const QString &url, const KIO::MetaData &meta)
    01173 {
    01174     return showSSLInfoDialog(url,meta,0);
    01175 }
    01176
    01177 void UIServer::showSSLInfoDialog(const QString &url, const KIO::MetaData &meta, int mainwindow)
    01178 {
    01179    KSSLInfoDlg *kid = new KSSLInfoDlg(meta["ssl_in_use"].upper()=="TRUE", 0L /*parent?*/, 0L, true);
    01180    KSSLCertificate *x = KSSLCertificate::fromString(meta["ssl_peer_certificate"].local8Bit());
    01181    if (x) {
    01182       // Set the chain back onto the certificate
    01183       QStringList cl =
    01184                       QStringList::split(QString("\n"), meta["ssl_peer_chain"]);
    01185       QPtrList<KSSLCertificate> ncl;
    01186
    01187       ncl.setAutoDelete(true);
    01188       for (QStringList::Iterator it = cl.begin(); it != cl.end(); ++it) {
    01189          KSSLCertificate *y = KSSLCertificate::fromString((*it).local8Bit());
    01190          if (y) ncl.append(y);
    01191       }
    01192
    01193       if (ncl.count() > 0)
    01194          x->chain().setChain(ncl);
    01195
    01196       kdDebug(7024) << "ssl_cert_errors=" << meta["ssl_cert_errors"] << endl;
    01197       kid->setCertState(meta["ssl_cert_errors"]);
    01198       kid->setup( x,
    01199                   meta["ssl_peer_ip"],
    01200                   url, // the URL
    01201                   meta["ssl_cipher"],
    01202                   meta["ssl_cipher_desc"],
    01203                   meta["ssl_cipher_version"],
    01204                   meta["ssl_cipher_used_bits"].toInt(),
    01205                   meta["ssl_cipher_bits"].toInt(),
    01206                   KSSLCertificate::KSSLValidation(meta["ssl_cert_state"].toInt()));
    01207       kdDebug(7024) << "Showing SSL Info dialog" << endl;
    01208 #ifndef Q_WS_WIN
    01209       if( mainwindow != 0 )
    01210           KWin::setMainWindow( kid, mainwindow );
    01211 #endif
    01212       kid->exec();
    01213       delete x;
    01214       kdDebug(7024) << "SSL Info dialog closed" << endl;
    01215    } else {
    01216       KMessageBox::information( 0L, // parent ?
    01217                               i18n("The peer SSL certificate appears to be corrupt."), i18n("SSL") );
    01218    }
    01219    // Don't delete kid!!
    01220 }
    01221
    01222 KSSLCertDlgRet UIServer::showSSLCertDialog(const QString& host, const QStringList& certList)
    01223 {
    01224     return showSSLCertDialog( host, certList, 0 );
    01225 }
    01226
    01227 KSSLCertDlgRet UIServer::showSSLCertDialog(const QString& host, const QStringList& certList, int mainwindow)
    01228 {
    01229    KSSLCertDlgRet rc;
    01230    rc.ok = false;
    01231    if (!certList.isEmpty()) {
    01232       KSSLCertDlg *kcd = new KSSLCertDlg(0L, 0L, true);
    01233       kcd->setupDialog(certList);
    01234       kcd->setHost(host);
    01235       kdDebug(7024) << "Showing SSL certificate dialog" << endl;
    01236 #ifndef Q_WS_WIN
    01237       if( mainwindow != 0 )
    01238           KWin::setMainWindow( kcd, mainwindow );
    01239 #endif
    01240       kcd->exec();
    01241       rc.ok = true;
    01242       rc.choice = kcd->getChoice();
    01243       rc.save = kcd->saveChoice();
    01244       rc.send = kcd->wantsToSend();
    01245       kdDebug(7024) << "SSL certificate dialog closed" << endl;
    01246       delete kcd;
    01247    }
    01248    return rc;
    01249 }
    01250
    01251
    01252 QByteArray UIServer::open_RenameDlg( int id,
    01253                                      const QString & caption,
    01254                                      const QString& src, const QString & dest,
    01255                                      int mode,
    01256                                      unsigned long sizeSrc,
    01257                                      unsigned long sizeDest,
    01258                                      unsigned long ctimeSrc,
    01259                                      unsigned long ctimeDest,
    01260                                      unsigned long mtimeSrc,
    01261                                      unsigned long mtimeDest
    01262                                      )
    01263 { return open_RenameDlg64(id, caption, src, dest, mode, sizeSrc, sizeDest,
    01264                           ctimeSrc, ctimeDest, mtimeSrc, mtimeDest); }
    01265
    01266
    01267 QByteArray UIServer::open_RenameDlg64( int id,
    01268                                      const QString & caption,
    01269                                      const QString& src, const QString & dest,
    01270                                      int mode,
    01271                                      KIO::filesize_t sizeSrc,
    01272                                      KIO::filesize_t sizeDest,
    01273                                      unsigned long ctimeSrc,
    01274                                      unsigned long ctimeDest,
    01275                                      unsigned long mtimeSrc,
    01276                                      unsigned long mtimeDest
    01277                                      )
    01278 {
    01279   // Hide existing dialog box if any
    01280   ProgressItem *item = findItem( id );
    01281   if ( item )
    01282     setItemVisible( item, false );
    01283   QString newDest;
    01284   kdDebug(7024) << "Calling KIO::open_RenameDlg" << endl;
    01285   KIO::RenameDlg_Result result = KIO::open_RenameDlg( caption, src, dest,
    01286                                                       (KIO::RenameDlg_Mode) mode, newDest,
    01287                                                       sizeSrc, sizeDest,
    01288                                                       (time_t)ctimeSrc, (time_t)ctimeDest,
    01289                                                       (time_t)mtimeSrc, (time_t)mtimeDest );
    01290   kdDebug(7024) << "KIO::open_RenameDlg done" << endl;
    01291   QByteArray data;
    01292   QDataStream stream( data, IO_WriteOnly );
    01293   stream << Q_UINT8(result) << newDest;
    01294   if ( item && result != KIO::R_CANCEL )
    01295     setItemVisible( item, true );
    01296   return data;
    01297 }
    01298
    01299 int UIServer::open_SkipDlg( int id,
    01300                             int /*bool*/ multi,
    01301                             const QString & error_text )
    01302 {
    01303   // Hide existing dialog box if any
    01304   ProgressItem *item = findItem( id );
    01305   if ( item )
    01306     setItemVisible( item, false );
    01307   kdDebug(7024) << "Calling KIO::open_SkipDlg" << endl;
    01308   KIO::SkipDlg_Result result = KIO::open_SkipDlg( (bool)multi, error_text );
    01309   if ( item && result != KIO::S_CANCEL )
    01310     setItemVisible( item, true );
    01311   return (KIO::SkipDlg_Result) result;
    01312 }
    01313
    01314
    01315 void UIServer::readSettings() {
    01316   KConfig config("uiserverrc");
    01317   config.setGroup( "UIServer" );
    01318   m_showStatusBar=config.readBoolEntry("ShowStatusBar",false);
    01319   m_showToolBar=config.readBoolEntry("ShowToolBar",true);
    01320   m_keepListOpen=config.readBoolEntry("KeepListOpen",false);
    01321   m_initWidth=config.readNumEntry("InitialWidth",460);
    01322   m_initHeight=config.readNumEntry("InitialHeight",150);
    01323   m_bShowList = config.readBoolEntry( "ShowList", false );
    01324   m_showSystemTray=config.readBoolEntry("ShowSystemTray", false);
    01325 }
    01326
    01327 void UIServer::writeSettings() {
    01328   KConfig config("uiserverrc");
    01329   config.setGroup( "UIServer" );
    01330   config.writeEntry("InitialWidth",width());
    01331   config.writeEntry("InitialHeight",height());
    01332   config.writeEntry("ShowStatusBar", m_showStatusBar);
    01333   config.writeEntry("ShowToolBar", m_showToolBar);
    01334   config.writeEntry("KeepListOpen", m_keepListOpen);
    01335   config.writeEntry("ShowList", m_bShowList);
    01336   config.writeEntry("ShowSystemTray", m_showSystemTray);
    01337 }
    01338
    01339
    01340 void UIServer::slotCancelCurrent() {
    01341   QListViewItemIterator it( listProgress );
    01342   ProgressItem *item;
    01343
    01344   // kill selected jobs
    01345   for ( ; it.current() ; ++it )
    01346   {
    01347     if ( it.current()->isSelected() ) {
    01348       item = (ProgressItem*) it.current();
    01349       killJob( item->appId(), item->jobId() );
    01350       return;
    01351     }
    01352   }
    01353 }
    01354
    01355 void UIServer::resizeEvent(QResizeEvent* e)
    01356 {
    01357    KMainWindow::resizeEvent(e);
    01358    writeSettings();
    01359 }
    01360
    01361 bool UIServer::queryClose()
    01362 {
    01363   if (( !m_shuttingDown ) && !kapp->sessionSaving()) {
    01364     hide();
    01365     return false;
    01366   }
    01367   return true;
    01368 }
    01369
    01370 UIServer* UIServer::createInstance()
    01371 {
    01372     return new UIServer;
    01373 }
    01374
    01375 //------------------------------------------------------------
    01376
    01377 extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
    01378 {
    01379     KLocale::setMainCatalogue("kdelibs");
    01380     //  GS 5/2001 - I changed the name to "KDE" to make it look better
    01381     //              in the titles of dialogs which are displayed.
    01382     KAboutData aboutdata("kio_uiserver", I18N_NOOP("KDE"),
    01383                          "0.8", I18N_NOOP("KDE Progress Information UI Server"),
    01384                          KAboutData::License_GPL, "(C) 2000, David Faure & Matt Koss");
    01385     // Who's the maintainer ? :)
    01386     aboutdata.addAuthor("David Faure",I18N_NOOP("Developer"),"faure@kde.org");
    01387     aboutdata.addAuthor("Matej Koss",I18N_NOOP("Developer"),"koss@miesto.sk");
    01388
    01389     KCmdLineArgs::init( argc, argv, &aboutdata );
    01390     // KCmdLineArgs::addCmdLineOptions( options );
    01391     KUniqueApplication::addCmdLineOptions();
    01392
    01393     if (!KUniqueApplication::start())
    01394     {
    01395       kdDebug(7024) << "kio_uiserver is already running!" << endl;
    01396       return (0);
    01397     }
    01398
    01399     KUniqueApplication app;
    01400
    01401     // This app is started automatically, no need for session management
    01402     app.disableSessionManagement();
    01403     app.dcopClient()->setDaemonMode( true );
    01404
    01405     uiserver = UIServer::createInstance();
    01406
    01407 //    app.setMainWidget( uiserver );
    01408
    01409     return app.exec();
    01410 }
    01411
    01412 #include "uiserver.moc"

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:24:08 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003