diff --git a/src/Compare.cpp b/src/Compare.cpp index a6d925752a..53ccc5b6d1 100644 --- a/src/Compare.cpp +++ b/src/Compare.cpp @@ -18,6 +18,7 @@ #include "insets/InsetText.h" #include "support/lassert.h" +#include "support/qstring_helpers.h" #include @@ -219,7 +220,7 @@ class Compare::Impl { public: /// Impl(Compare const & compare) - : abort_(false), compare_(compare) + : abort_(false), compare_(compare), recursion_level_(0), D_(0) {} /// @@ -234,6 +235,14 @@ public: /// Set to true to cancel the algorithm bool abort_; + /// + QString status() { + QString status; + status += toqstr("recursion level:") + " " + QString::number(recursion_level_) + + " " + toqstr("differences:") + " " + QString::number(D_); + return status; + } + private: /// Finds the middle snake and returns the length of the /// shortest edit script. @@ -322,6 +331,10 @@ private: compl_vector nrp; compl_vector ors; compl_vector nrs; + + /// The number of differences in the path the algorithm + /// is currently processing. + int D_; }; ///////////////////////////////////////////////////////////////////// @@ -335,6 +348,15 @@ Compare::Compare(Buffer const * new_buf, Buffer const * old_buf, : new_buffer(new_buf), old_buffer(old_buf), dest_buffer(dest_buf), options_(options), pimpl_(new Impl(*this)) { + connect(&status_timer_, SIGNAL(timeout()), + this, SLOT(doStatusMessage())); + status_timer_.start(1000); +} + + +void Compare::doStatusMessage() +{ + statusMessage(pimpl_->status()); } @@ -347,6 +369,8 @@ void Compare::run() dest_buffer->params() = options_.settings_from_new ? new_buffer->params() : old_buffer->params(); + doStatusMessage(); + // do the real work if (!doCompare()) return; @@ -605,6 +629,8 @@ int Compare::Impl::findMiddleSnake(DocRangePair const & rp, // different characters in the old and new chunk. int const D_max = ceil(((double)M_ + N_)/2); for (int D = 0; D <= D_max; ++D) { + // to be used in the status messages + D_ = D; // Forward and reverse paths for (int f = 0; f < 2; ++f) { diff --git a/src/Compare.h b/src/Compare.h index 39ba469671..f94761fc57 100644 --- a/src/Compare.h +++ b/src/Compare.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -73,6 +74,13 @@ Q_SIGNALS: /// Sets the maximum value of the progress bar in the dialog. void progressMax(int max) const; + /// A message describing the process + void statusMessage(QString msg) const; + +public Q_SLOTS: + /// Emits the status message signal + void doStatusMessage(); + public: /// QThread inherited methods //@{ @@ -99,6 +107,9 @@ private: /// QWaitCondition condition_; + /// Emit a statusMessage signal from time to time + QTimer status_timer_; + /// Use the Pimpl idiom to hide the internals. class Impl; /// diff --git a/src/frontends/qt4/GuiCompare.cpp b/src/frontends/qt4/GuiCompare.cpp index 03e64c2915..3366338150 100644 --- a/src/frontends/qt4/GuiCompare.cpp +++ b/src/frontends/qt4/GuiCompare.cpp @@ -106,6 +106,7 @@ void GuiCompare::updateContents() newFileCB->clear(); oldFileCB->clear(); progressBar->setValue(0); + statusBar->clearMessage(); BufferList::iterator it = theBufferList().begin(); BufferList::iterator const end = theBufferList().end(); for (; it != end; ++it) { @@ -211,6 +212,7 @@ void GuiCompare::finished(bool aborted) } setWindowTitle(window_title_); progressBar->setValue(0); + statusBar->showMessage(qt_("Aborted")); } else { hideView(); bc().ok(); @@ -218,6 +220,7 @@ void GuiCompare::finished(bool aborted) dispatch(FuncRequest(LFUN_BUFFER_SWITCH, dest_buffer_->absFileName())); } + statusBar->showMessage(qt_("Finished")); } } @@ -234,6 +237,13 @@ void GuiCompare::progressMax(int max) const } + +void GuiCompare::setStatusMessage(QString msg) +{ + statusBar->showMessage(msg); +} + + void GuiCompare::slotOK() { enableControls(false); @@ -247,10 +257,12 @@ void GuiCompare::slotCancel() if (compare_ && compare_->isRunning()) { window_title_ = windowTitle(); setWindowTitle(window_title_ + " " + qt_("(cancelling)")); + statusBar->showMessage(qt_("Aborting process...")); compare_->abort(); } else { GuiDialog::slotClose(); progressBar->setValue(0); + statusBar->clearMessage(); } } @@ -299,6 +311,8 @@ int GuiCompare::run() connect(compare_, SIGNAL(finished(bool)), this, SLOT(finished(bool))); connect(compare_, SIGNAL(progress(int)), this, SLOT(progress(int))); connect(compare_, SIGNAL(progressMax(int)), this, SLOT(progressMax(int))); + connect(compare_, SIGNAL(statusMessage(QString)), + this, SLOT(setStatusMessage(QString))); compare_->start(QThread::LowPriority); return 1; } diff --git a/src/frontends/qt4/GuiCompare.h b/src/frontends/qt4/GuiCompare.h index a972b7a6c0..0116890495 100644 --- a/src/frontends/qt4/GuiCompare.h +++ b/src/frontends/qt4/GuiCompare.h @@ -53,6 +53,8 @@ private Q_SLOTS: void progress(int); /// void progressMax(int) const; + /// + void setStatusMessage(QString); private: /// diff --git a/src/frontends/qt4/ui/CompareUi.ui b/src/frontends/qt4/ui/CompareUi.ui index 8602bb8598..730c43cb5f 100644 --- a/src/frontends/qt4/ui/CompareUi.ui +++ b/src/frontends/qt4/ui/CompareUi.ui @@ -1,7 +1,7 @@ - + CompareUi - - + + 0 0 @@ -9,211 +9,233 @@ 302 - + - + true - + + + 0 + - - - &New Document: + + + 9 - - newFileCB + + 9 - - - - - - - - - 0 - 0 - - - - true - - - - - - - &Browse... - - - false - - - - - - - - - &Old Document: + + 9 - - oldFileCB - - - - - - - - - - 0 - 0 - - - - true - - - - - - - Bro&wse... - - - false - - - - - - - - - - 0 - 0 - - - - Options - - - - - 20 - 40 - 151 - 18 - - - - New Document - - - - - - 20 - 60 - 151 - 18 - - - - Old Document - - - - - - 20 - 20 - 237 - 16 - - - - - 0 - 0 - - - - Copy Document Settings from: - - - true - - - - - - - - 24 - - - - - - - 6 - - + 0 - - - Qt::Horizontal + + + &New Document: - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - - - - &OK - - - true + + newFileCB - - - &Close + + + + + + 0 + 0 + + + + true + + + + + + + &Browse... + + + false + + + + + + + + + &Old Document: - - false - - - false + + oldFileCB + + + + + + + 0 + 0 + + + + true + + + + + + + Bro&wse... + + + false + + + + + + + + + + 0 + 0 + + + + Options + + + + + 20 + 40 + 151 + 18 + + + + New Document + + + + + + 20 + 60 + 151 + 18 + + + + Old Document + + + + + + 20 + 20 + 237 + 16 + + + + + 0 + 0 + + + + Copy Document Settings from: + + + true + + + + + + + + 24 + + + + + + + 6 + + + 0 + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + + + + &OK + + + true + + + + + + + &Close + + + false + + + false + + + + + + + + - qt_i18n.h + qt_i18n.h