00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <qlabel.h>
00010 #include <qtextedit.h>
00011 #include <qpushbutton.h>
00012 #include <qstatusbar.h>
00013 #include <qmessagebox.h>
00014 #include <qapplication.h>
00015 #include <qcursor.h>
00016 #include "myprocess.h"
00017 #include "git.h"
00018 #include "consoleimpl.h"
00019
00020 ConsoleImpl::ConsoleImpl(const QString& nm, Git* g) :
00021 Console(0, 0, Qt::WDestructiveClose), name(nm), git(g) {
00022
00023 textEditOutput->setFont(QGit::TYPE_WRITER_FONT);
00024 QFont f = textLabelCmd->font();
00025 f.setBold(true);
00026 textLabelCmd->setFont(f);
00027 setCaption("\'" + name + "\' output window - QGit");
00028 }
00029
00030 void ConsoleImpl::pushButtonOk_clicked() {
00031
00032 close();
00033 }
00034
00035 void ConsoleImpl::closeEvent(QCloseEvent* ce) {
00036
00037 if (proc && proc->isRunning())
00038 if (QMessageBox::question(this, "Action output window - QGit",
00039 "Action is still running.\nAre you sure you want to close "
00040 "the window and leave the action running in background?",
00041 "&Yes", "&No", QString::null, 1, 1) == 1) {
00042 ce->ignore();
00043 return;
00044 }
00045 if (QApplication::overrideCursor())
00046 QApplication::restoreOverrideCursor();
00047
00048 Console::closeEvent(ce);
00049 }
00050
00051 bool ConsoleImpl::start(const QString& cmd, const QString& cmdArgs, QStringList* env) {
00052
00053 statusBar()->message("Executing \'" + name + "\' action...");
00054
00055
00056 QString txt = cmd.section('\n', 0, 0).stripWhiteSpace();
00057 QString args = cmdArgs.stripWhiteSpace();
00058 QString tail(cmd.section('\n', 1).stripWhiteSpace());
00059
00060 if (!args.isEmpty())
00061 txt.append(' ' + args);
00062
00063 if (!tail.isEmpty())
00064 txt.append('\n' + tail);
00065
00066 textLabelCmd->setText(txt);
00067 if (tail.isEmpty())
00068 proc = git->runAsync(txt, this, "", env);
00069 else
00070 proc = git->runAsScript(txt.append('\n'), this, "", env);
00071
00072 if (proc.isNull())
00073 deleteLater();
00074 else
00075 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00076
00077 return !proc.isNull();
00078 }
00079
00080 void ConsoleImpl::on_procDataReady(const QByteArray& data) {
00081
00082 QString newParagraph;
00083 if (QGit::stripPartialParaghraps(data, &newParagraph, &inpBuf))
00084
00085
00086 textEditOutput->append(newParagraph);
00087 }
00088
00089 void ConsoleImpl::on_eof() {
00090
00091 textEditOutput->append(inpBuf);
00092 inpBuf = "";
00093 QApplication::restoreOverrideCursor();
00094 statusBar()->message("End of \'" + name + "\' execution.");
00095 pushButtonStop->setEnabled(false);
00096 emit customAction_exited(name);
00097 }
00098
00099 void ConsoleImpl::pushButtonStop_clicked() {
00100
00101 git->cancelProcess(proc);
00102 on_eof();
00103 }