Version 2.6
[qgit4/redivivus.git] / src / consoleimpl.cpp
bloba243085891804aa684e96dbd181a35f26b0f79ff
1 /*
2 Description: stdout viewer
4 Author: Marco Costalba (C) 2006-2007
6 Copyright: See COPYING file that comes with this distribution
8 */
9 #include <QSettings>
10 #include <QStatusBar>
11 #include <QMessageBox>
12 #include "myprocess.h"
13 #include "git.h"
14 #include "consoleimpl.h"
16 ConsoleImpl::ConsoleImpl(const QString& nm, Git* g) : git(g), actionName(nm) {
18 setAttribute(Qt::WA_DeleteOnClose);
19 setupUi(this);
20 textEditOutput->setFont(QGit::TYPE_WRITER_FONT);
21 QFont f = textLabelCmd->font();
22 f.setBold(true);
23 textLabelCmd->setFont(f);
24 setWindowTitle("\'" + actionName + "\' output window - QGit");
25 QGit::restoreGeometrySetting(QGit::CON_GEOM_KEY, this);
28 void ConsoleImpl::typeWriterFontChanged() {
30 QTextEdit* te = textEditOutput;
31 te->setFont(QGit::TYPE_WRITER_FONT);
32 te->setPlainText(te->toPlainText());
33 te->moveCursor(QTextCursor::End);
36 void ConsoleImpl::pushButtonOk_clicked() {
38 close();
41 void ConsoleImpl::pushButtonTerminate_clicked() {
43 git->cancelProcess(proc);
44 procFinished();
47 void ConsoleImpl::closeEvent(QCloseEvent* ce) {
49 if (proc && proc->state() == QProcess::Running)
50 if (QMessageBox::question(this, "Action output window - QGit",
51 "Action is still running.\nAre you sure you want to close "
52 "the window and leave the action running in background?",
53 "&Yes", "&No", QString(), 1, 1) == 1) {
54 ce->ignore();
55 return;
57 if (QApplication::overrideCursor())
58 QApplication::restoreOverrideCursor();
60 QGit::saveGeometrySetting(QGit::CON_GEOM_KEY, this);
61 QMainWindow::closeEvent(ce);
64 bool ConsoleImpl::start(const QString& cmd, const QString& cmdArgs) {
66 statusBar()->showMessage("Executing \'" + actionName + "\' action...");
68 // in case of a multi-sequence, line arguments are bounded to first command only
69 QString txt = cmd.section('\n', 0, 0).trimmed();
70 QString args = cmdArgs.trimmed();
71 QString tail(cmd.section('\n', 1).trimmed());
73 if (!args.isEmpty())
74 txt.append(' ' + args);
76 if (!tail.isEmpty()) // any one-line command followed by a newline would fail
77 txt.append('\n' + tail);
79 textLabelCmd->setText(txt);
80 if (tail.isEmpty())
81 proc = git->runAsync(txt, this);
82 else
83 proc = git->runAsScript(txt.append('\n'), this); // wrap in a script
85 if (proc.isNull())
86 deleteLater();
87 else
88 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
90 return !proc.isNull();
93 void ConsoleImpl::procReadyRead(const QByteArray& data) {
95 QString newParagraph;
96 if (QGit::stripPartialParaghraps(data, &newParagraph, &inpBuf))
97 // QTextEdit::append() adds a new paragraph,
98 // i.e. inserts a LF if not already present.
99 textEditOutput->append(newParagraph);
102 void ConsoleImpl::procFinished() {
104 textEditOutput->append(inpBuf);
105 inpBuf = "";
106 QApplication::restoreOverrideCursor();
107 statusBar()->showMessage("End of \'" + actionName + "\' execution.");
108 pushButtonTerminate->setEnabled(false);
109 emit customAction_exited(actionName);