?? statusbarbase.cpp
字號(hào):
QApplication::postEvent( this, e );}voidStatusBar::customEvent( QCustomEvent *e ){ if(e->type() == 1000 ){ QString *s = static_cast<QString*>( e->data() ); longMessage( *s ); delete s; }else if(e->type() == 2000 ){ EngineController::instance()->unplayableNotification(); }}/// application wide progress monitorinline boolStatusBar::allDone(){ for( ProgressMap::Iterator it = m_progressMap.begin(), end = m_progressMap.end(); it != end; ++it ) if( (*it)->m_done == false ) return false; return true;}ProgressBar&StatusBar::newProgressOperation( QObject *owner ){ SHOULD_BE_GUI if ( m_progressMap.contains( owner ) ) return *m_progressMap[owner]; if( allDone() ) // if we're allDone then we need to remove the old progressBars before // we start anything new or the total progress will not be accurate pruneProgressBars(); else toggleProgressWindowButton()->show(); QLabel *label = new QLabel( m_popupProgress ); m_progressMap.insert( owner, new ProgressBar( m_popupProgress, label ) ); m_popupProgress->reposition(); connect( owner, SIGNAL(destroyed( QObject* )), SLOT(endProgressOperation( QObject* )) ); // so we can show the correct progress information // after the ProgressBar is setup SingleShotPool::startTimer( 0, this, SLOT(updateProgressAppearance()) ); progressBox()->show(); cancelButton()->setEnabled( true ); return *m_progressMap[ owner ];}ProgressBar&StatusBar::newProgressOperation( KIO::Job *job ){ SHOULD_BE_GUI ProgressBar & bar = newProgressOperation( static_cast<QObject*>( job ) ); bar.setTotalSteps( 100 ); if(!allDone()) toggleProgressWindowButton()->show(); connect( job, SIGNAL(result( KIO::Job* )), SLOT(endProgressOperation()) ); //TODO connect( job, SIGNAL(infoMessage( KIO::Job *job, const QString& )), SLOT() ); connect( job, SIGNAL(percent( KIO::Job*, unsigned long )), SLOT(setProgress( KIO::Job*, unsigned long )) ); return bar;}voidStatusBar::endProgressOperation(){ QObject *owner = const_cast<QObject*>( sender() ); //HACK deconsting it KIO::Job *job = dynamic_cast<KIO::Job*>( owner ); //FIXME doesn't seem to work for KIO::DeleteJob, it has it's own error handler and returns no error too // if you try to delete http urls for instance <- KDE SUCKS! if( job && job->error() ) shortLongMessage( QString::null, job->errorString(), Error ); endProgressOperation( owner );}voidStatusBar::endProgressOperation( QObject *owner ){ //the owner of this progress operation has been deleted //we need to stop listening for progress from it //NOTE we don't delete it yet, as this upsets some //things, we just call setDone(). if ( !m_progressMap.contains( owner ) ) { SingleShotPool::startTimer( 2000, this, SLOT(hideMainProgressBar()) ); return ; } m_progressMap[owner]->setDone(); if( allDone() && !m_popupProgress->isShown() ) { cancelButton()->setEnabled( false ); SingleShotPool::startTimer( 2000, this, SLOT(hideMainProgressBar()) ); } updateTotalProgress();}voidStatusBar::abortAllProgressOperations() //slot{ for( ProgressMap::Iterator it = m_progressMap.begin(), end = m_progressMap.end(); it != end; ++it ) (*it)->m_abort->animateClick(); m_mainTextLabel->setText( i18n("Aborting all jobs...") ); cancelButton()->setEnabled( false );}voidStatusBar::toggleProgressWindow( bool show ) //slot{ m_popupProgress->reposition(); //FIXME shouldn't be needed, adding bars doesn't seem to do this m_popupProgress->setShown( show ); if( !show ) SingleShotPool::startTimer( 2000, this, SLOT(hideMainProgressBar()) );}voidStatusBar::showShortLongDetails(){ if( !m_shortLongText.isEmpty() ) longMessage( m_shortLongText, m_shortLongType ); m_shortLongType = Information; m_shortLongText = QString::null; shortLongButton()->hide();}voidStatusBar::showMainProgressBar(){ if( !allDone() ) progressBox()->show();}voidStatusBar::hideMainProgressBar(){ if( allDone() && !m_popupProgress->isShown() ) { pruneProgressBars(); resetMainText(); m_mainProgressBar->setProgress( 0 ); progressBox()->hide(); }}voidStatusBar::setProgress( int steps ){ setProgress( sender(), steps );}voidStatusBar::setProgress( KIO::Job *job, unsigned long percent ){ setProgress( static_cast<QObject*>( job ), percent );}voidStatusBar::setProgress( const QObject *owner, int steps ){ if ( !m_progressMap.contains( owner ) ) return ; m_progressMap[ owner ] ->setProgress( steps ); updateTotalProgress();}voidStatusBar::incrementProgressTotalSteps( const QObject *owner, int inc ){ if ( !m_progressMap.contains( owner ) ) return ; m_progressMap[ owner ] ->setTotalSteps( m_progressMap[ owner ] ->totalSteps() + inc ); updateTotalProgress();}voidStatusBar::setProgressStatus( const QObject *owner, const QString &text ){ if ( !m_progressMap.contains( owner ) ) return ; m_progressMap[owner]->setStatus( text );}void StatusBar::incrementProgress(){ incrementProgress( sender() );}voidStatusBar::incrementProgress( const QObject *owner ){ if ( !m_progressMap.contains( owner ) ) return; m_progressMap[owner]->setProgress( m_progressMap[ owner ] ->progress() + 1 ); updateTotalProgress();}voidStatusBar::updateTotalProgress(){ uint totalSteps = 0; uint progress = 0; foreachType( ProgressMap, m_progressMap ) { totalSteps += (*it)->totalSteps(); progress += (*it)->progress(); } if( totalSteps == 0 && progress == 0 ) return; m_mainProgressBar->setTotalSteps( totalSteps ); m_mainProgressBar->setProgress( progress ); pruneProgressBars();}voidStatusBar::updateProgressAppearance(){ toggleProgressWindowButton()->setShown( m_progressMap.count() > 1 ); resetMainText(); updateTotalProgress();}voidStatusBar::pruneProgressBars(){ ProgressMap::Iterator it = m_progressMap.begin(); const ProgressMap::Iterator end = m_progressMap.end(); int count = 0; bool removedBar = false; while( it != end ) if( (*it)->m_done == true ) { delete (*it)->m_label; delete (*it)->m_abort; delete (*it); ProgressMap::Iterator jt = it; ++it; m_progressMap.erase( jt ); removedBar = true; } else { ++it; ++count; } if(count==1 && removedBar) //if its gone from 2 or more bars to one bar... { resetMainText(); toggleProgressWindowButton()->hide(); m_popupProgress->setShown(false); }}/// Method which writes to a rotating log file.voidStatusBar::writeLogFile( const QString &text ){ if( text.isEmpty() ) return; const int counter = 4; // number of logs to keep const uint maxSize = 30000; // approximately 1000 lines per log file int c = counter; QString logBase = Amarok::saveLocation() + "statusbar.log."; QFile file; if( m_logCounter < 0 ) //find which log to write to { for( ; c > 0; c-- ) { QString log = logBase + QString::number(c); file.setName( log ); if( QFile::exists( log ) && file.size() <= maxSize ) break; } if( c == 0 ) file.setName( logBase + '0' ); m_logCounter = c; } else { file.setName( logBase + QString::number(m_logCounter) ); } if( file.size() > maxSize ) { m_logCounter++; m_logCounter = m_logCounter % counter; file.setName( logBase + QString::number(m_logCounter) ); // if we have overflown the log, then we want to overwrite the previous content if( !file.open( IO_WriteOnly ) ) return; } else if( !file.open( IO_WriteOnly|IO_Append ) ) return; QTextStream stream( &file ); stream.setEncoding( QTextStream::UnicodeUTF8 ); stream << "[" << KGlobal::locale()->formatDateTime( QDateTime::currentDateTime() ) << "] " << text << endl;}} //namespace KDE#include "statusBarBase.moc"
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -