X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiCompare.cpp;h=09139597469be938ccc75fe36574e6d08d32897f;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=aa376c19b69d66d494f462445ab4140c615e9b18;hpb=0e4d0ad7e99832c292bd6a909a104a8f8140ba5b;p=lyx.git diff --git a/src/frontends/qt4/GuiCompare.cpp b/src/frontends/qt4/GuiCompare.cpp index aa376c19b6..0913959746 100644 --- a/src/frontends/qt4/GuiCompare.cpp +++ b/src/frontends/qt4/GuiCompare.cpp @@ -16,6 +16,7 @@ #include "BufferView.h" #include "BufferList.h" #include "buffer_funcs.h" +#include "Compare.h" #include "FuncRequest.h" #include "GuiView.h" #include "LyXRC.h" @@ -40,7 +41,7 @@ namespace frontend { GuiCompare::GuiCompare(GuiView & lv) : GuiDialog(lv, "compare", qt_("Compare LyX files")), - dest_buffer_(0) + compare_(0), dest_buffer_(0), old_buffer_(0), new_buffer_(0) { setupUi(this); setModal(Qt::WindowModal); @@ -48,29 +49,33 @@ GuiCompare::GuiCompare(GuiView & lv) connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotCancel())); - connect(newFilePB, SIGNAL(clicked()), this, SLOT(select_newfile())); - connect(oldFilePB, SIGNAL(clicked()), this, SLOT(select_oldfile())); + connect(newFilePB, SIGNAL(clicked()), this, SLOT(selectNewFile())); + connect(oldFilePB, SIGNAL(clicked()), this, SLOT(selectOldFile())); connect(newFileCB, SIGNAL(currentIndexChanged(int)), - this, SLOT(change_adaptor())); + this, SLOT(changeAdaptor())); connect(newFileCB, SIGNAL(editTextChanged(const QString &)), - this, SLOT(change_adaptor())); + this, SLOT(changeAdaptor())); connect(oldFileCB, SIGNAL(currentIndexChanged(int)), - this, SLOT(change_adaptor())); + this, SLOT(changeAdaptor())); connect(oldFileCB, SIGNAL(editTextChanged(const QString &)), - this, SLOT(change_adaptor())); + this, SLOT(changeAdaptor())); newSettingsRB->setChecked(true); progressBar->setValue(0); progressBar->setEnabled(false); + closePB->setCursor(Qt::ArrowCursor); + bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy); bc().setOK(okPB); } GuiCompare::~GuiCompare() { + if (compare_) + delete compare_; } void GuiCompare::closeEvent(QCloseEvent *) @@ -79,7 +84,7 @@ void GuiCompare::closeEvent(QCloseEvent *) } -void GuiCompare::change_adaptor() +void GuiCompare::changeAdaptor() { changed(); } @@ -95,11 +100,15 @@ bool GuiCompare::isValid() void GuiCompare::updateContents() { + if (compare_ && compare_->isRunning()) + return; + QString restore_filename1 = newFileCB->currentText(); QString restore_filename2 = oldFileCB->currentText(); newFileCB->clear(); oldFileCB->clear(); progressBar->setValue(0); + statusBar->clearMessage(); BufferList::iterator it = theBufferList().begin(); BufferList::iterator const end = theBufferList().end(); for (; it != end; ++it) { @@ -124,7 +133,7 @@ void GuiCompare::updateContents() } -void GuiCompare::select_newfile() +void GuiCompare::selectNewFile() { QString name = browse(newFileCB->currentText()); if (!name.isEmpty()) @@ -133,7 +142,7 @@ void GuiCompare::select_newfile() } -void GuiCompare::select_oldfile() +void GuiCompare::selectOldFile() { QString name = browse(oldFileCB->currentText()); if (!name.isEmpty()) @@ -163,8 +172,12 @@ QString GuiCompare::browse(QString const & in_name) const } -void GuiCompare::enableControls(bool enable) const +void GuiCompare::enableControls(bool enable) { + // Set the hourglass cursor for the dialog, but + // never for the cancel button. + setCursor(enable ? Qt::ArrowCursor : Qt::WaitCursor); + newFileLA->setEnabled(enable); newFilePB->setEnabled(enable); newFileCB->setEnabled(enable); @@ -182,50 +195,76 @@ void GuiCompare::enableControls(bool enable) const } +void GuiCompare::error() +{ + Alert::error(_("Error"), _("Error while comparing documents.")); + finished(true); +} + void GuiCompare::finished(bool aborted) { enableControls(true); + + if (compare_) { + delete compare_; + compare_ = 0; + } if (aborted) { - dest_buffer_->markClean(); - theBufferList().release(dest_buffer_); - setWindowTitle(window_title_); + if (dest_buffer_) { + dest_buffer_->markClean(); + theBufferList().release(dest_buffer_); + } progressBar->setValue(0); + statusBar->showMessage(qt_("Aborted"), 5000); } else { hideView(); bc().ok(); - dispatch(FuncRequest(LFUN_BUFFER_SWITCH, dest_buffer_->absFileName())); + if (dest_buffer_) { + dispatch(FuncRequest(LFUN_BUFFER_SWITCH, + dest_buffer_->absFileName())); + } + statusBar->showMessage(qt_("Finished"), 5000); } } -void GuiCompare::nextIt(int val) +void GuiCompare::progress(int val) { progressBar->setValue(progressBar->value() + val); } -void GuiCompare::progress_max(int max) const +void GuiCompare::progressMax(int max) const { progressBar->setMaximum(max); } - + + +void GuiCompare::setStatusMessage(QString msg) +{ + statusBar->showMessage(msg); +} + void GuiCompare::slotOK() { enableControls(false); - if (!run()) { - Alert::error(_("Error"), - _("Unable to compare files.")); - finished(true); - } + if (!run()) + error(); } void GuiCompare::slotCancel() { - GuiDialog::slotClose(); - progressBar->setValue(0); + if (compare_ && compare_->isRunning()) { + statusBar->showMessage(qt_("Aborting process...")); + compare_->abort(); + } else { + GuiDialog::slotClose(); + progressBar->setValue(0); + statusBar->clearMessage(); + } } @@ -256,10 +295,27 @@ int GuiCompare::run() // new buffer that will carry the output FileName initpath(lyxrc.document_path); dest_buffer_ = newUnnamedFile(initpath, to_utf8(_("differences"))); - dest_buffer_->changed(); + + if (!new_buffer_ || !old_buffer_ || !dest_buffer_) + return 0; + + dest_buffer_->changed(true); dest_buffer_->markDirty(); - return 0; + // get the options from the dialog + CompareOptions options; + options.settings_from_new = newSettingsRB->isChecked(); + + // init the compare object and start it + compare_ = new Compare(new_buffer_, old_buffer_, dest_buffer_, options); + connect(compare_, SIGNAL(error()), this, SLOT(error())); + 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; }