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