00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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"
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"
00062 #include <ksslinfodlg.h>
00063 #include <ksslcertdlg.h>
00064 #include <ksslcertificate.h>
00065 #include <ksslcertchain.h>
00066
00067
00068
00069 UIServer* uiserver;
00070
00071
00072 enum { TOOL_CANCEL, TOOL_CONFIGURE };
00073
00074
00075 enum { ID_TOTAL_FILES = 1, ID_TOTAL_SIZE, ID_TOTAL_TIME, ID_TOTAL_SPEED };
00076
00077
00078 int UIServer::s_jobId = 0;
00079
00080 static const int defaultColumnWidth[] = { 70,
00081 160,
00082 40,
00083 60,
00084 30,
00085 65,
00086 70,
00087 70,
00088 450
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
00102 KStdAction::quit(uis, SLOT(slotQuit()), actionCollection());
00103 }
00104 };
00105
00106 class ProgressConfigDialog:public KDialogBase
00107 {
00108 public:
00109 ProgressConfigDialog(QWidget* parent);
00110 ~ProgressConfigDialog() {}
00111 void setChecked(int i, bool on);
00112 bool isChecked(int i) const;
00113 friend class UIServer;
00114 private:
00115 QCheckBox *m_showSystemTrayCb;
00116 QCheckBox *m_keepOpenCb;
00117 QCheckBox *m_toolBarCb;
00118 QCheckBox *m_statusBarCb;
00119 QCheckBox *m_headerCb;
00120 QCheckBox *m_fixedWidthCb;
00121 KListView *m_columns;
00122 QCheckListItem *(m_items[ListProgress::TB_MAX]);
00123 };
00124
00125 ProgressConfigDialog::ProgressConfigDialog(QWidget *parent)
00126 :KDialogBase(KDialogBase::Plain,i18n("Configure Network Operation Window"),KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Cancel,
00127 KDialogBase::Ok, parent, "configprog", false)
00128 {
00129 QVBoxLayout *layout=new QVBoxLayout(plainPage(),spacingHint());
00130 m_showSystemTrayCb=new QCheckBox(i18n("Show system tray icon"), plainPage());
00131 m_keepOpenCb=new QCheckBox(i18n("Keep network operation window always open"), plainPage());
00132 m_headerCb=new QCheckBox(i18n("Show column headers"), plainPage());
00133 m_toolBarCb=new QCheckBox(i18n("Show toolbar"), plainPage());
00134 m_statusBarCb=new QCheckBox(i18n("Show statusbar"), plainPage());
00135 m_fixedWidthCb=new QCheckBox(i18n("Column widths are user adjustable"), plainPage());
00136 QLabel *label=new QLabel(i18n("Show information:"), plainPage());
00137 m_columns=new KListView(plainPage());
00138
00139 m_columns->addColumn("info");
00140 m_columns->setSorting(-1);
00141 m_columns->header()->hide();
00142
00143 m_items[ListProgress::TB_ADDRESS] =new QCheckListItem(m_columns, i18n("URL"), QCheckListItem::CheckBox);
00144 m_items[ListProgress::TB_REMAINING_TIME] =new QCheckListItem(m_columns, i18n("Rem. Time"), QCheckListItem::CheckBox);
00145 m_items[ListProgress::TB_SPEED] =new QCheckListItem(m_columns, i18n("Speed"), QCheckListItem::CheckBox);
00146 m_items[ListProgress::TB_TOTAL] =new QCheckListItem(m_columns, i18n("Size"), QCheckListItem::CheckBox);
00147 m_items[ListProgress::TB_PROGRESS] =new QCheckListItem(m_columns, i18n("%"), QCheckListItem::CheckBox);
00148 m_items[ListProgress::TB_COUNT] =new QCheckListItem(m_columns, i18n("Count"), QCheckListItem::CheckBox);
00149 m_items[ListProgress::TB_RESUME] =new QCheckListItem(m_columns, i18n("Resume", "Res."), QCheckListItem::CheckBox);
00150 m_items[ListProgress::TB_LOCAL_FILENAME] =new QCheckListItem(m_columns, i18n("Local Filename"), QCheckListItem::CheckBox);
00151 m_items[ListProgress::TB_OPERATION] =new QCheckListItem(m_columns, i18n("Operation"), QCheckListItem::CheckBox);
00152
00153 layout->addWidget(m_showSystemTrayCb);
00154 layout->addWidget(m_keepOpenCb);
00155 layout->addWidget(m_headerCb);
00156 layout->addWidget(m_toolBarCb);
00157 layout->addWidget(m_statusBarCb);
00158 layout->addWidget(m_fixedWidthCb);
00159 layout->addWidget(label);
00160 layout->addWidget(m_columns);
00161 }
00162
00163 void ProgressConfigDialog::setChecked(int i, bool on)
00164 {
00165 if (i>=ListProgress::TB_MAX)
00166 return;
00167 m_items[i]->setOn(on);
00168 }
00169
00170 bool ProgressConfigDialog::isChecked(int i) const
00171 {
00172 if (i>=ListProgress::TB_MAX)
00173 return false;
00174 return m_items[i]->isOn();
00175 }
00176
00177 ProgressItem::ProgressItem( ListProgress* view, QListViewItem *after, QCString app_id, int job_id,
00178 bool showDefault )
00179 : QListViewItem( view, after ) {
00180
00181 listProgress = view;
00182
00183 m_iTotalSize = 0;
00184 m_iTotalFiles = 0;
00185 m_iProcessedSize = 0;
00186 m_iProcessedFiles = 0;
00187 m_iSpeed = 0;
00188
00189 m_sAppId = app_id;
00190 m_iJobId = job_id;
00191 m_visible = true;
00192 m_defaultProgressVisible = true;
00193
00194
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
00224
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
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
00388
00389
00390
00391
00392
00393
00394
00395
00396 defaultProgress->slotCanResume( 0, offset );
00397 }
00398
00399
00400 void ProgressItem::slotCanceled() {
00401 emit jobCanceled( this );
00402 }
00403
00404
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
00420
00421 void ProgressItem::setVisible( bool visible ) {
00422 if ( m_visible != visible )
00423 {
00424 m_visible = visible;
00425 updateVisibility();
00426 }
00427 }
00428
00429
00430 void ProgressItem::setDefaultProgressVisible( bool visible ) {
00431 if ( m_defaultProgressVisible != visible )
00432 {
00433 m_defaultProgressVisible = visible;
00434 updateVisibility();
00435 }
00436 }
00437
00438
00439 void ProgressItem::updateVisibility()
00440 {
00441 if (defaultProgress)
00442 {
00443 if ( m_visible && m_defaultProgressVisible )
00444 {
00445 m_showTimer.start(250, true);
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
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("Rem. Time");
00474 m_lpcc[TB_ADDRESS].title=i18n("URL");
00475 readSettings();
00476
00477 applySettings();
00478
00479
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
00494 for (int i=0; i<TB_MAX; i++)
00495 {
00496 if ( !m_lpcc[i].enabled )
00497 continue;
00498
00499 iEnabledCols++;
00500
00501
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);
00511 if (m_fixedColumnWidths)
00512 setColumnWidthMode(m_lpcc[i].index, Manual);
00513 }
00514
00515
00516
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
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
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
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
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
00605 statusBar()->insertItem( i18n(" Files: %1 ").arg( 0 ), ID_TOTAL_FILES);
00606 statusBar()->insertItem( i18n(" Size: %1 kB ").arg( "0" ), ID_TOTAL_SIZE);
00607 statusBar()->insertItem( i18n(" Time: 00:00:00 "), ID_TOTAL_TIME);
00608 statusBar()->insertItem( i18n(" %1 kB/s ").arg("0"), ID_TOTAL_SPEED);
00609
00610
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
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
00636
00637
00638
00639
00640
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* , 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
00678 m_contextMenu->insertSeparator();
00679 m_contextMenu->insertItem(i18n("Settings..."), this, SLOT(slotConfigure()));
00680 }
00681 bool enabled = false;
00682 QListViewItemIterator it( listProgress );
00683 for ( ; it.current(); ++it ) {
00684 if ( it.current()->isSelected() ) {
00685 enabled = true;
00686 break;
00687 }
00688 }
00689 m_contextMenu->setItemEnabled( m_idCancelItem, enabled);
00690
00691 m_contextMenu->popup(pos);
00692 }
00693
00694 void UIServer::slotRemoveSystemTrayIcon()
00695 {
00696 m_showSystemTray=false;
00697 applySettings();
00698 writeSettings();
00699 }
00700
00701 void UIServer::slotConfigure()
00702 {
00703 if (m_configDialog==0)
00704 {
00705 m_configDialog=new ProgressConfigDialog(0);
00706
00707 connect(m_configDialog,SIGNAL(okClicked()), this, SLOT(slotApplyConfig()));
00708 connect(m_configDialog,SIGNAL(applyClicked()), this, SLOT(slotApplyConfig()));
00709 }
00710 m_configDialog->m_showSystemTrayCb->setChecked(m_showSystemTray);
00711 m_configDialog->m_keepOpenCb->setChecked(m_keepListOpen);
00712 m_configDialog->m_toolBarCb->setChecked(m_showToolBar);
00713 m_configDialog->m_statusBarCb->setChecked(m_showStatusBar);
00714 m_configDialog->m_headerCb->setChecked(listProgress->m_showHeader);
00715 m_configDialog->m_fixedWidthCb->setChecked(listProgress->m_fixedColumnWidths);
00716 for (int i=0; i<ListProgress::TB_MAX; i++)
00717 {
00718 m_configDialog->setChecked(i, listProgress->m_lpcc[i].enabled);
00719 }
00720 m_configDialog->show();
00721 }
00722
00723 void UIServer::slotApplyConfig()
00724 {
00725 m_showSystemTray=m_configDialog->m_showSystemTrayCb->isChecked();
00726 m_keepListOpen=m_configDialog->m_keepOpenCb->isChecked();
00727 m_showToolBar=m_configDialog->m_toolBarCb->isChecked();
00728 m_showStatusBar=m_configDialog->m_statusBarCb->isChecked();
00729 listProgress->m_showHeader=m_configDialog->m_headerCb->isChecked();
00730 listProgress->m_fixedColumnWidths=m_configDialog->m_fixedWidthCb->isChecked();
00731 for (int i=0; i<ListProgress::TB_MAX; i++)
00732 listProgress->m_lpcc[i].enabled=m_configDialog->isChecked(i);
00733
00734
00735 applySettings();
00736 listProgress->applySettings();
00737 writeSettings();
00738 listProgress->writeSettings();
00739 }
00740
00741 int UIServer::newJob( QCString observerAppId, bool showProgress )
00742 {
00743 kdDebug(7024) << "UIServer::newJob observerAppId=" << observerAppId << ". "
00744 << "Giving id=" << s_jobId+1 << endl;
00745
00746 QListViewItemIterator it( listProgress );
00747 for ( ; it.current(); ++it ) {
00748 if ( it.current()->itemBelow() == 0L ) {
00749 break;
00750 }
00751 }
00752
00753
00754 s_jobId++;
00755
00756 bool show = !m_bShowList && showProgress;
00757
00758 ProgressItem *item = new ProgressItem( listProgress, it.current(), observerAppId, s_jobId, show );
00759 connect( item, SIGNAL( jobCanceled( ProgressItem* ) ),
00760 SLOT( slotJobCanceled( ProgressItem* ) ) );
00761
00762 if ( m_bShowList && !updateTimer->isActive() )
00763 updateTimer->start( 1000 );
00764
00765 m_bUpdateNewJob=true;
00766
00767 return s_jobId;
00768 }
00769
00770
00771 ProgressItem* UIServer::findItem( int id )
00772 {
00773 QListViewItemIterator it( listProgress );
00774
00775 ProgressItem *item;
00776
00777 for ( ; it.current(); ++it ) {
00778 item = (ProgressItem*) it.current();
00779 if ( item->jobId() == id ) {
00780 return item;
00781 }
00782 }
00783
00784 return 0L;
00785 }
00786
00787
00788 void UIServer::setItemVisible( ProgressItem * item, bool visible )
00789 {
00790 item->setVisible( visible );
00791
00792
00793
00794 if ( m_bShowList ) {
00795 m_bUpdateNewJob = true;
00796 slotUpdate();
00797 }
00798 }
00799
00800
00801 void UIServer::setJobVisible( int id, bool visible )
00802 {
00803 kdDebug(7024) << "UIServer::setJobVisible id=" << id << " visible=" << visible << endl;
00804 ProgressItem *item = findItem( id );
00805 Q_ASSERT( item );
00806 if ( item )
00807 setItemVisible( item, visible );
00808 }
00809
00810 void UIServer::jobFinished( int id )
00811 {
00812 kdDebug(7024) << "UIServer::jobFinished id=" << id << endl;
00813 ProgressItem *item = findItem( id );
00814
00815
00816 if ( item ) {
00817 if ( item->keepOpen() )
00818 item->finished();
00819 else
00820 delete item;
00821 }
00822 }
00823
00824
00825 void UIServer::totalSize( int id, unsigned long size )
00826 { totalSize64(id, size); }
00827
00828 void UIServer::totalSize64( int id, KIO::filesize_t size )
00829 {
00830
00831
00832 ProgressItem *item = findItem( id );
00833 if ( item ) {
00834 item->setTotalSize( size );
00835 }
00836 }
00837
00838 void UIServer::totalFiles( int id, unsigned long files )
00839 {
00840 kdDebug(7024) << "UIServer::totalFiles " << id << " " << (unsigned int) files << endl;
00841
00842 ProgressItem *item = findItem( id );
00843 if ( item ) {
00844 item->setTotalFiles( files );
00845 }
00846 }
00847
00848 void UIServer::totalDirs( int id, unsigned long dirs )
00849 {
00850 kdDebug(7024) << "UIServer::totalDirs " << id << " " << (unsigned int) dirs << endl;
00851
00852 ProgressItem *item = findItem( id );
00853 if ( item ) {
00854 item->setTotalDirs( dirs );
00855 }
00856 }
00857
00858 void UIServer::processedSize( int id, unsigned long size )
00859 { processedSize64(id, size); }
00860
00861 void UIServer::processedSize64( int id, KIO::filesize_t size )
00862 {
00863
00864
00865 ProgressItem *item = findItem( id );
00866 if ( item ) {
00867 item->setProcessedSize( size );
00868 }
00869 }
00870
00871 void UIServer::processedFiles( int id, unsigned long files )
00872 {
00873
00874
00875 ProgressItem *item = findItem( id );
00876 if ( item ) {
00877 item->setProcessedFiles( files );
00878 }
00879 }
00880
00881 void UIServer::processedDirs( int id, unsigned long dirs )
00882 {
00883 kdDebug(7024) << "UIServer::processedDirs " << id << " " << (unsigned int) dirs << endl;
00884
00885 ProgressItem *item = findItem( id );
00886 if ( item ) {
00887 item->setProcessedDirs( dirs );
00888 }
00889 }
00890
00891 void UIServer::percent( int id, unsigned long ipercent )
00892 {
00893
00894
00895 ProgressItem *item = findItem( id );
00896 if ( item ) {
00897 item->setPercent( ipercent );
00898 }
00899 }
00900
00901 void UIServer::speed( int id, unsigned long bytes_per_second )
00902 {
00903
00904
00905 ProgressItem *item = findItem( id );
00906 if ( item ) {
00907 item->setSpeed( bytes_per_second );
00908 }
00909 }
00910
00911 void UIServer::infoMessage( int id, const QString & msg )
00912 {
00913
00914
00915 ProgressItem *item = findItem( id );
00916 if ( item ) {
00917 item->setInfoMessage( msg );
00918 }
00919 }
00920
00921 void UIServer::canResume( int id, unsigned long offset )
00922 { canResume64(id, offset); }
00923
00924 void UIServer::canResume64( int id, KIO::filesize_t offset )
00925 {
00926
00927
00928 ProgressItem *item = findItem( id );
00929 if ( item ) {
00930 item->setCanResume( offset );
00931 }
00932 }
00933
00934 void UIServer::copying( int id, KURL from, KURL to )
00935 {
00936
00937
00938 ProgressItem *item = findItem( id );
00939 if ( item ) {
00940 item->setCopying( from, to );
00941 }
00942 }
00943
00944 void UIServer::moving( int id, KURL from, KURL to )
00945 {
00946
00947
00948 ProgressItem *item = findItem( id );
00949 if ( item ) {
00950 item->setMoving( from, to );
00951 }
00952 }
00953
00954 void UIServer::deleting( int id, KURL url )
00955 {
00956
00957
00958 ProgressItem *item = findItem( id );
00959 if ( item ) {
00960 item->setDeleting( url );
00961 }
00962 }
00963
00964 void UIServer::transferring( int id, KURL url )
00965 {
00966
00967
00968 ProgressItem *item = findItem( id );
00969 if ( item ) {
00970 item->setTransferring( url );
00971 }
00972 }
00973
00974 void UIServer::creatingDir( int id, KURL dir )
00975 {
00976 kdDebug(7024) << "UIServer::creatingDir " << id << " " << dir.url() << endl;
00977
00978 ProgressItem *item = findItem( id );
00979 if ( item ) {
00980 item->setCreatingDir( dir );
00981 }
00982 }
00983
00984 void UIServer::stating( int id, KURL url )
00985 {
00986 kdDebug(7024) << "UIServer::stating " << id << " " << url.url() << endl;
00987
00988 ProgressItem *item = findItem( id );
00989 if ( item ) {
00990 item->setStating( url );
00991 }
00992 }
00993
00994 void UIServer::mounting( int id, QString dev, QString point )
00995 {
00996 kdDebug(7024) << "UIServer::mounting " << id << " " << dev << " " << point << endl;
00997
00998 ProgressItem *item = findItem( id );
00999 if ( item ) {
01000 item->setMounting( dev, point );
01001 }
01002 }
01003
01004 void UIServer::unmounting( int id, QString point )
01005 {
01006 kdDebug(7024) << "UIServer::unmounting " << id << " " << point << endl;
01007
01008 ProgressItem *item = findItem( id );
01009 if ( item ) {
01010 item->setUnmounting( point );
01011 }
01012 }
01013
01014 void UIServer::killJob( QCString observerAppId, int progressId )
01015 {
01016
01017 Observer_stub observer( observerAppId, "KIO::Observer" );
01018
01019 observer.killJob( progressId );
01020 }
01021
01022 void UIServer::slotJobCanceled( ProgressItem *item ) {
01023 kdDebug(7024) << "UIServer::slotJobCanceled appid=" << item->appId() << " jobid=" << item->jobId() << endl;
01024
01025 killJob( item->appId(), item->jobId() );
01026
01027
01028
01029 delete item;
01030 }
01031
01032
01033 void UIServer::slotQuit()
01034 {
01035 m_shuttingDown = true;
01036 kapp->quit();
01037 }
01038
01039 void UIServer::slotUpdate() {
01040
01041
01042 QListViewItemIterator lvit( listProgress );
01043 bool visible = false;
01044 for ( ; lvit.current(); ++lvit )
01045 if ( ((ProgressItem*)lvit.current())->isVisible() ) {
01046 visible = true;
01047 break;
01048 }
01049
01050 if ( !visible || !m_bShowList ) {
01051 if (!m_keepListOpen) hide();
01052 updateTimer->stop();
01053 return;
01054 }
01055
01056
01057
01058 if (m_bUpdateNewJob)
01059 {
01060 m_bUpdateNewJob=false;
01061 show();
01062
01063
01064 if ( m_bShowList && !updateTimer->isActive() )
01065 updateTimer->start( 1000 );
01066 }
01067
01068 int iTotalFiles = 0;
01069 KIO::filesize_t iTotalSize = 0;
01070 int iTotalSpeed = 0;
01071 QTime totalRemTime;
01072
01073 ProgressItem *item;
01074
01075
01076 QListViewItemIterator it( listProgress );
01077
01078 for ( ; it.current(); ++it ) {
01079 item = (ProgressItem*) it.current();
01080 if ( item->totalSize() != 0 ) {
01081 iTotalSize += ( item->totalSize() - item->processedSize() );
01082 }
01083 iTotalFiles += ( item->totalFiles() - item->processedFiles() );
01084 iTotalSpeed += item->speed();
01085
01086 if ( item->remainingTime() > totalRemTime ) {
01087 totalRemTime = item->remainingTime();
01088 }
01089 }
01090
01091
01092 statusBar()->changeItem( i18n( " Files: %1 ").arg( iTotalFiles ), ID_TOTAL_FILES);
01093 statusBar()->changeItem( i18n( " Size: %1 ").arg( KIO::convertSize( iTotalSize ) ),
01094 ID_TOTAL_SIZE);
01095 statusBar()->changeItem( i18n( " Time: %1 ").arg( totalRemTime.toString() ), ID_TOTAL_TIME);
01096 statusBar()->changeItem( i18n( " %1/s ").arg( KIO::convertSize( iTotalSpeed ) ),
01097 ID_TOTAL_SPEED);
01098
01099 }
01100
01101 void UIServer::setListMode( bool list )
01102 {
01103 m_bShowList = list;
01104 QListViewItemIterator it( listProgress );
01105 for ( ; it.current(); ++it ) {
01106
01107
01108 ((ProgressItem*) it.current())->setDefaultProgressVisible( !list );
01109 }
01110
01111 if (m_bShowList)
01112 {
01113 show();
01114 updateTimer->start( 1000 );
01115 }
01116 else
01117 {
01118 hide();
01119 updateTimer->stop();
01120 }
01121 }
01122
01123 void UIServer::slotToggleDefaultProgress( QListViewItem *item ) {
01124 ((ProgressItem*) item )->slotToggleDefaultProgress();
01125 }
01126
01127
01128 void UIServer::slotSelection() {
01129 QListViewItemIterator it( listProgress );
01130
01131 for ( ; it.current(); ++it ) {
01132 if ( it.current()->isSelected() ) {
01133 toolBar()->setItemEnabled( TOOL_CANCEL, TRUE);
01134 return;
01135 }
01136 }
01137 toolBar()->setItemEnabled( TOOL_CANCEL, FALSE);
01138 }
01139
01140
01141
01142 QByteArray UIServer::openPassDlg( const KIO::AuthInfo &info )
01143 {
01144 kdDebug(7024) << "UIServer::openPassDlg: User= " << info.username
01145 << ", Msg= " << info.prompt << endl;
01146 KIO::AuthInfo inf(info);
01147 int result = KIO::PasswordDialog::getNameAndPassword( inf.username, inf.password,
01148 &inf.keepPassword, inf.prompt,
01149 inf.readOnly, inf.caption,
01150 inf.comment, inf.commentLabel );
01151 QByteArray data;
01152 QDataStream stream( data, IO_WriteOnly );
01153 if ( result == QDialog::Accepted )
01154 inf.setModified( true );
01155 else
01156 inf.setModified( false );
01157 stream << inf;
01158 return data;
01159 }
01160
01161 int UIServer::messageBox( int progressId, int type, const QString &text, const QString &caption, const QString &buttonYes, const QString &buttonNo )
01162 {
01163 return Observer::messageBox( progressId, type, text, caption, buttonYes, buttonNo );
01164 }
01165
01166 void UIServer::showSSLInfoDialog(const QString &url, const KIO::MetaData &meta)
01167 {
01168 KSSLInfoDlg *kid = new KSSLInfoDlg(meta["ssl_in_use"].upper()=="TRUE", 0L , 0L, true);
01169 KSSLCertificate *x = KSSLCertificate::fromString(meta["ssl_peer_certificate"].local8Bit());
01170 if (x) {
01171
01172 QStringList cl =
01173 QStringList::split(QString("\n"), meta["ssl_peer_chain"]);
01174 QPtrList<KSSLCertificate> ncl;
01175
01176 ncl.setAutoDelete(true);
01177 for (QStringList::Iterator it = cl.begin(); it != cl.end(); ++it) {
01178 KSSLCertificate *y = KSSLCertificate::fromString((*it).local8Bit());
01179 if (y) ncl.append(y);
01180 }
01181
01182 if (ncl.count() > 0)
01183 x->chain().setChain(ncl);
01184
01185 kdDebug(7024) << "ssl_cert_errors=" << meta["ssl_cert_errors"] << endl;
01186 kid->setCertState(meta["ssl_cert_errors"]);
01187 kid->setup( x,
01188 meta["ssl_peer_ip"],
01189 url,
01190 meta["ssl_cipher"],
01191 meta["ssl_cipher_desc"],
01192 meta["ssl_cipher_version"],
01193 meta["ssl_cipher_used_bits"].toInt(),
01194 meta["ssl_cipher_bits"].toInt(),
01195 KSSLCertificate::KSSLValidation(meta["ssl_cert_state"].toInt()));
01196 kdDebug(7024) << "Showing SSL Info dialog" << endl;
01197 kid->exec();
01198 delete x;
01199 kdDebug(7024) << "SSL Info dialog closed" << endl;
01200 } else {
01201 KMessageBox::information( 0L,
01202 i18n("The peer SSL certificate appears to be corrupt."), i18n("SSL") );
01203 }
01204
01205 }
01206
01207 KSSLCertDlgRet UIServer::showSSLCertDialog(const QString& host, const QStringList& certList)
01208 {
01209 KSSLCertDlgRet rc;
01210 rc.ok = false;
01211 if (!certList.isEmpty()) {
01212 KSSLCertDlg *kcd = new KSSLCertDlg(0L, 0L, true);
01213 kcd->setupDialog(certList);
01214 kcd->setHost(host);
01215 kdDebug(7024) << "Showing SSL certificate dialog" << endl;
01216 kcd->exec();
01217 rc.ok = true;
01218 rc.choice = kcd->getChoice();
01219 rc.save = kcd->saveChoice();
01220 rc.send = kcd->wantsToSend();
01221 kdDebug(7024) << "SSL certificate dialog closed" << endl;
01222 delete kcd;
01223 }
01224 return rc;
01225 }
01226
01227
01228 QByteArray UIServer::open_RenameDlg( int id,
01229 const QString & caption,
01230 const QString& src, const QString & dest,
01231 int mode,
01232 unsigned long sizeSrc,
01233 unsigned long sizeDest,
01234 unsigned long ctimeSrc,
01235 unsigned long ctimeDest,
01236 unsigned long mtimeSrc,
01237 unsigned long mtimeDest
01238 )
01239 { return open_RenameDlg64(id, caption, src, dest, mode, sizeSrc, sizeDest,
01240 ctimeSrc, ctimeDest, mtimeSrc, mtimeDest); }
01241
01242
01243 QByteArray UIServer::open_RenameDlg64( int id,
01244 const QString & caption,
01245 const QString& src, const QString & dest,
01246 int mode,
01247 KIO::filesize_t sizeSrc,
01248 KIO::filesize_t sizeDest,
01249 unsigned long ctimeSrc,
01250 unsigned long ctimeDest,
01251 unsigned long mtimeSrc,
01252 unsigned long mtimeDest
01253 )
01254 {
01255
01256 ProgressItem *item = findItem( id );
01257 if ( item )
01258 setItemVisible( item, false );
01259 QString newDest;
01260 kdDebug(7024) << "Calling KIO::open_RenameDlg" << endl;
01261 KIO::RenameDlg_Result result = KIO::open_RenameDlg( caption, src, dest,
01262 (KIO::RenameDlg_Mode) mode, newDest,
01263 sizeSrc, sizeDest,
01264 (time_t)ctimeSrc, (time_t)ctimeDest,
01265 (time_t)mtimeSrc, (time_t)mtimeDest );
01266 kdDebug(7024) << "KIO::open_RenameDlg done" << endl;
01267 QByteArray data;
01268 QDataStream stream( data, IO_WriteOnly );
01269 stream << Q_UINT8(result) << newDest;
01270 if ( item && result != KIO::R_CANCEL )
01271 setItemVisible( item, true );
01272 return data;
01273 }
01274
01275 int UIServer::open_SkipDlg( int id,
01276 int multi,
01277 const QString & error_text )
01278 {
01279
01280 ProgressItem *item = findItem( id );
01281 if ( item )
01282 setItemVisible( item, false );
01283 kdDebug(7024) << "Calling KIO::open_SkipDlg" << endl;
01284 KIO::SkipDlg_Result result = KIO::open_SkipDlg( (bool)multi, error_text );
01285 if ( item && result != KIO::S_CANCEL )
01286 setItemVisible( item, true );
01287 return (KIO::SkipDlg_Result) result;
01288 }
01289
01290
01291 void UIServer::readSettings() {
01292 KConfig config("uiserverrc");
01293 config.setGroup( "UIServer" );
01294 m_showStatusBar=config.readBoolEntry("ShowStatusBar",false);
01295 m_showToolBar=config.readBoolEntry("ShowToolBar",true);
01296 m_keepListOpen=config.readBoolEntry("KeepListOpen",false);
01297 m_initWidth=config.readNumEntry("InitialWidth",460);
01298 m_initHeight=config.readNumEntry("InitialHeight",150);
01299 m_bShowList = config.readBoolEntry( "ShowList", false );
01300 m_showSystemTray=config.readBoolEntry("ShowSystemTray", false);
01301 }
01302
01303 void UIServer::writeSettings() {
01304 KConfig config("uiserverrc");
01305 config.setGroup( "UIServer" );
01306 config.writeEntry("InitialWidth",width());
01307 config.writeEntry("InitialHeight",height());
01308 config.writeEntry("ShowStatusBar", m_showStatusBar);
01309 config.writeEntry("ShowToolBar", m_showToolBar);
01310 config.writeEntry("KeepListOpen", m_keepListOpen);
01311 config.writeEntry("ShowList", m_bShowList);
01312 config.writeEntry("ShowSystemTray", m_showSystemTray);
01313 }
01314
01315
01316 void UIServer::slotCancelCurrent() {
01317 QListViewItemIterator it( listProgress );
01318 ProgressItem *item;
01319
01320
01321 for ( ; it.current() ; ++it )
01322 {
01323 if ( it.current()->isSelected() ) {
01324 item = (ProgressItem*) it.current();
01325 killJob( item->appId(), item->jobId() );
01326 return;
01327 }
01328 }
01329 }
01330
01331 void UIServer::resizeEvent(QResizeEvent* e)
01332 {
01333 KMainWindow::resizeEvent(e);
01334 writeSettings();
01335 }
01336
01337 bool UIServer::queryClose()
01338 {
01339 if (( !m_shuttingDown ) && !kapp->sessionSaving()) {
01340 hide();
01341 return false;
01342 }
01343 return true;
01344 }
01345
01346 UIServer* UIServer::createInstance()
01347 {
01348 return new UIServer;
01349 }
01350
01351
01352
01353 extern "C" int kdemain(int argc, char **argv)
01354 {
01355 KLocale::setMainCatalogue("kdelibs");
01356
01357
01358 KAboutData aboutdata("kio_uiserver", I18N_NOOP("KDE"),
01359 "0.8", I18N_NOOP("KDE Progress Information UI Server"),
01360 KAboutData::License_GPL, "(C) 2000, David Faure & Matt Koss");
01361
01362 aboutdata.addAuthor("David Faure",I18N_NOOP("Developer"),"faure@kde.org");
01363 aboutdata.addAuthor("Matej Koss",I18N_NOOP("Developer"),"koss@miesto.sk");
01364
01365 KCmdLineArgs::init( argc, argv, &aboutdata );
01366
01367 KUniqueApplication::addCmdLineOptions();
01368
01369 if (!KUniqueApplication::start())
01370 {
01371 kdDebug(7024) << "kio_uiserver is already running!" << endl;
01372 return (0);
01373 }
01374
01375 KUniqueApplication app;
01376
01377
01378 app.disableSessionManagement();
01379 app.dcopClient()->setDaemonMode( true );
01380
01381 uiserver = UIServer::createInstance();
01382
01383
01384
01385 return app.exec();
01386 }
01387
01388 #include "uiserver.moc"