diff options
| author | 2010-09-19 16:37:19 +0000 | |
|---|---|---|
| committer | 2010-09-19 16:37:19 +0000 | |
| commit | c4d955d4020712843ce724625f9bf49dde57d218 (patch) | |
| tree | 8cb5093869df206385b3f19cc4a3fad448b87d6e /src/modules/help | |
| parent | removed logviewer progress dialog; added inline progressbar; fixes #968 (diff) | |
| download | KVIrc-c4d955d4020712843ce724625f9bf49dde57d218.tar.gz KVIrc-c4d955d4020712843ce724625f9bf49dde57d218.tar.bz2 KVIrc-c4d955d4020712843ce724625f9bf49dde57d218.zip | |
module help: removed modal progress dialog, implemented inline progress bar
module logviewer: reworked a bit the progressbar
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5022 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/help')
| -rw-r--r-- | src/modules/help/helpwindow.cpp | 95 | ||||
| -rw-r--r-- | src/modules/help/helpwindow.h | 11 | ||||
| -rw-r--r-- | src/modules/help/index.cpp | 60 | ||||
| -rw-r--r-- | src/modules/help/index.h | 10 |
4 files changed, 109 insertions, 67 deletions
diff --git a/src/modules/help/helpwindow.cpp b/src/modules/help/helpwindow.cpp index 162f2099d..982cc35ab 100644 --- a/src/modules/help/helpwindow.cpp +++ b/src/modules/help/helpwindow.cpp @@ -37,6 +37,7 @@ #include <QFileInfo> #include <QLineEdit> #include <QMessageBox> +#include <QPushButton> #include <QRegExp> #include <QToolTip> #include <QTimer> @@ -49,22 +50,6 @@ bool g_bIndexingDone = FALSE; KviHelpWindow::KviHelpWindow(KviFrame * lpFrm,const char * name) : KviWindow(KVI_WINDOW_TYPE_HELP,lpFrm,name) { - if(!g_bIndexingDone) - { - g_bIndexingDone=TRUE; - QString szDoclist,szDict; - - g_pApp->getLocalKvircDirectory(szDoclist,KviApp::Help,"help.doclist." KVI_SOURCES_DATE); - g_pApp->getLocalKvircDirectory(szDict,KviApp::Help,"help.dict." KVI_SOURCES_DATE); - - if ( QFileInfo( szDoclist ).exists() && QFileInfo( szDict ).exists() ) { - g_pDocIndex->readDict(); - } else { - g_pDocIndex->makeIndex(); - g_pDocIndex->writeDict(); - } - } - g_pHelpWindowList->append(this); m_pSplitter = new KviTalSplitter(Qt::Horizontal,this); m_pSplitter->setObjectName("main_splitter"); @@ -72,10 +57,16 @@ KviHelpWindow::KviHelpWindow(KviFrame * lpFrm,const char * name) m_pHelpWidget = new KviHelpWidget(m_pSplitter,lpFrm); - m_pToolBar=new KviTalVBox(m_pSplitter); - + m_pToolBar=new KviTalVBox(m_pSplitter); m_pTabWidget = new QTabWidget(m_pToolBar); + m_pBottomLayout = new KviTalHBox(m_pToolBar); + m_pProgressBar = new QProgressBar(m_pBottomLayout); + m_pCancelButton = new QPushButton(m_pBottomLayout); + m_pCancelButton->setText(__tr2qs_ctx("Cancel","logview")); + connect(m_pCancelButton,SIGNAL(clicked()),g_pDocIndex,SLOT(setLastWinClosed())); + m_pBottomLayout->setVisible(false); + m_pIndexTab = new KviTalVBox(m_pTabWidget); m_pTabWidget->addTab(m_pIndexTab,__tr2qs("Index")); @@ -86,16 +77,13 @@ KviHelpWindow::KviHelpWindow(KviFrame * lpFrm,const char * name) connect( m_pIndexSearch, SIGNAL( returnPressed() ), this, SLOT( showIndexTopic() ) ); - QToolButton* pBtnRefreshIndex = new QToolButton(pSearchBox); - pBtnRefreshIndex->setIcon(*g_pIconManager->getBigIcon(KVI_REFRESH_IMAGE_NAME)); - connect(pBtnRefreshIndex,SIGNAL(clicked()),this,SLOT(refreshIndex())); - pBtnRefreshIndex->setToolTip(__tr2qs("Refresh index") ); + m_pBtnRefreshIndex = new QPushButton(pSearchBox); + m_pBtnRefreshIndex->setIcon(*g_pIconManager->getBigIcon(KVI_REFRESH_IMAGE_NAME)); + connect(m_pBtnRefreshIndex,SIGNAL(clicked()),this,SLOT(refreshIndex())); + m_pBtnRefreshIndex->setToolTip(__tr2qs("Refresh index") ); m_pIndexListWidget = new KviTalListWidget(m_pIndexTab); - QStringList docList=g_pDocIndex->titlesList(); - m_pIndexListWidget->addItems(docList); connect(m_pIndexListWidget,SIGNAL(itemActivated(QListWidgetItem *)),this,SLOT(indexSelected (QListWidgetItem * ))); - m_pIndexListWidget->sortItems(); m_pSearchTab = new KviTalVBox(m_pTabWidget); m_pTabWidget->addTab(m_pSearchTab,__tr2qs("Search")); @@ -113,7 +101,11 @@ KviHelpWindow::KviHelpWindow(KviFrame * lpFrm,const char * name) li.append(80); m_pSplitter->setSizes(li); - QTimer::singleShot(0,m_pIndexSearch,SLOT(setFocus())); + connect(g_pDocIndex, SIGNAL(indexingStart(int)), this, SLOT(indexingStart(int))); + connect(g_pDocIndex, SIGNAL(indexingProgress(int)), this, SLOT(indexingProgress(int))); + connect(g_pDocIndex, SIGNAL(indexingEnd()), this, SLOT(indexingEnd())); + + QTimer::singleShot(0,this,SLOT(initialSetup())); } KviHelpWindow::~KviHelpWindow() @@ -121,6 +113,50 @@ KviHelpWindow::~KviHelpWindow() g_pHelpWindowList->removeRef(this); } +void KviHelpWindow::initialSetup() +{ + m_pIndexSearch->setFocus(); + + if(!g_bIndexingDone) + { + g_bIndexingDone=TRUE; + QString szDoclist,szDict; + + g_pApp->getLocalKvircDirectory(szDoclist,KviApp::Help,"help.doclist." KVI_SOURCES_DATE); + g_pApp->getLocalKvircDirectory(szDict,KviApp::Help,"help.dict." KVI_SOURCES_DATE); + + if ( QFileInfo( szDoclist ).exists() && QFileInfo( szDict ).exists() ) { + g_pDocIndex->readDict(); + } else { + g_pDocIndex->makeIndex(); + } + } +} + +void KviHelpWindow::indexingStart( int iNum ) +{ + m_pBtnRefreshIndex->setEnabled(false); + m_pBottomLayout->setVisible(true); + m_pProgressBar->setRange(0, iNum); + m_pProgressBar->setValue(0); +} +void KviHelpWindow::indexingProgress( int iNum ) +{ + m_pProgressBar->setValue(iNum); +} + +void KviHelpWindow::indexingEnd() +{ + m_pProgressBar->setValue(0); + m_pBottomLayout->setVisible(false); + g_pDocIndex->writeDict(); + m_pIndexListWidget->clear(); + QStringList docList=g_pDocIndex->titlesList(); + m_pIndexListWidget->addItems(docList); + m_pIndexListWidget->sortItems(); + m_pBtnRefreshIndex->setEnabled(true); +} + void KviHelpWindow::saveProperties(KviConfig *cfg) { KviWindow::saveProperties(cfg); @@ -139,18 +175,11 @@ void KviHelpWindow::loadProperties(KviConfig *cfg) void KviHelpWindow::refreshIndex() { - m_pIndexListWidget->clear(); g_pDocIndex->makeIndex(); - g_pDocIndex->writeDict(); - g_bIndexingDone=TRUE; - QStringList docList=g_pDocIndex->titlesList(); - m_pIndexListWidget->addItems(docList); - m_pIndexListWidget->sortItems(); } void KviHelpWindow::startSearch() { - QString str = m_pTermsEdit->text(); str = str.replace( "\'", "\"" ); str = str.replace( "`", "\"" ); diff --git a/src/modules/help/helpwindow.h b/src/modules/help/helpwindow.h index 2bcad355a..38fd895a5 100644 --- a/src/modules/help/helpwindow.h +++ b/src/modules/help/helpwindow.h @@ -32,6 +32,8 @@ #include <QTabWidget> #include <QLineEdit> +class QProgressBar; +class QPushButton; class QTextBrowser; class KviHelpWidget; @@ -47,6 +49,9 @@ protected: QTabWidget * m_pTabWidget; KviTalVBox * m_pIndexTab; KviTalVBox * m_pSearchTab; + KviTalHBox * m_pBottomLayout; + QPushButton * m_pCancelButton; + QProgressBar * m_pProgressBar; KviTalListWidget* m_pIndexListWidget; QLineEdit * m_pIndexSearch; @@ -54,6 +59,7 @@ protected: QStringList m_terms; KviTalListWidget* m_pResultBox; QLineEdit * m_pTermsEdit; + QPushButton * m_pBtnRefreshIndex; public: KviHelpWidget * helpWidget(){ return m_pHelpWidget; }; protected: @@ -71,6 +77,11 @@ public slots: void startSearch(); void searchSelected ( QListWidgetItem * ); void refreshIndex(); + + void initialSetup(); + void indexingStart( int iNum ); + void indexingProgress( int iNum ); + void indexingEnd(); }; #endif //_KVI_HELPWINDOW_H_ diff --git a/src/modules/help/index.cpp b/src/modules/help/index.cpp index 2db4979e6..0bd2a0033 100644 --- a/src/modules/help/index.cpp +++ b/src/modules/help/index.cpp @@ -48,8 +48,7 @@ #include <QTextCodec> #include <ctype.h> #include <QTextDocument> -#include <QProgressDialog> -#include "kvi_locale.h" +#include <QTimer> QT_BEGIN_NAMESPACE @@ -85,6 +84,11 @@ Index::Index( const QString &dp, const QString &hp ) lastWindowClosed = false; connect( qApp, SIGNAL(lastWindowClosed()), this, SLOT(setLastWinClosed()) ); + + m_pTimer = new QTimer(this); + m_pTimer->setSingleShot(true); + m_pTimer->setInterval(0); + connect(m_pTimer, SIGNAL(timeout()), this, SLOT(filterNext())); } Index::Index( const QStringList &dl, const QString &hp ) @@ -118,38 +122,30 @@ void Index::setDocList( const QStringList &lst ) docList = lst; } -int Index::makeIndex() +void Index::makeIndex() { - if ( !alreadyHaveDocList ) - setupDocumentList(); - if ( docList.isEmpty() ) - return 1; - QStringList::Iterator it = docList.begin(); - int steps = docList.count() / 100; - if ( !steps ) - steps++; - int prog = 0; - - QProgressDialog* pProgressDialog = new QProgressDialog( __tr2qs("Indexing help files"), __tr2qs("Cancel"), 0, docList.count() ); - pProgressDialog->setWindowTitle(__tr2qs("KVIrc")); - pProgressDialog->setMinimumDuration(500); - pProgressDialog->setWindowModality(Qt::WindowModal); + if ( !alreadyHaveDocList ) + setupDocumentList(); - for ( int i = 0; it != docList.end(); ++it, ++i ) { - if ( lastWindowClosed ||pProgressDialog->wasCanceled()) { - delete pProgressDialog; - return -1; - } - QUrl url(*it); - parseDocument( url.toLocalFile(), i ); - pProgressDialog->setValue(i); - if ( i%steps == 0 ) { - prog++; - emit indexingProgress( prog ); - } - } - delete pProgressDialog; - return 0; + lastWindowClosed = false; + emit indexingStart( docList.count() ); + dict.clear(); + m_iCurItem = 0; + m_pTimer->start(); //singleshot +} + +void Index::filterNext() +{ + if(m_iCurItem < docList.count() && !lastWindowClosed) + { + QUrl url(docList.at(m_iCurItem)); + parseDocument( url.toLocalFile(), m_iCurItem ); + emit indexingProgress( m_iCurItem ); + m_iCurItem++; + m_pTimer->start(); //singleshot + } else { + emit indexingEnd(); + } } void Index::setupDocumentList() diff --git a/src/modules/help/index.h b/src/modules/help/index.h index 4f18f1731..3d5970645 100644 --- a/src/modules/help/index.h +++ b/src/modules/help/index.h @@ -46,6 +46,8 @@ #include <QFile> #include <QVector> +class QTimer; + QT_BEGIN_NAMESPACE struct Document { @@ -88,7 +90,7 @@ public: Index( const QStringList &dl, const QString &hp ); void writeDict(); void readDict(); - int makeIndex(); + void makeIndex(); QStringList query( const QStringList&, const QStringList&, const QStringList& ); QString getDocumentTitle( const QString& ); void setDictionaryFile( const QString& ); @@ -99,11 +101,13 @@ public: const QStringList& titlesList() { return titleList; }; signals: + void indexingStart( int ); void indexingProgress( int ); + void indexingEnd(); private slots: void setLastWinClosed(); - + void filterNext(); private: void setupDocumentList(); void parseDocument( const QString&, int ); @@ -126,6 +130,8 @@ private: bool alreadyHaveDocList; bool lastWindowClosed; QHash<QString, QString> documentTitleCache; + QTimer * m_pTimer; + int m_iCurItem; }; #endif |
