Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@57
|
2
|
Chris@57
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
Chris@57
|
5
|
Chris@57
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@57
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@57
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@57
|
10
|
Chris@57
|
11 This program is free software; you can redistribute it and/or
|
Chris@57
|
12 modify it under the terms of the GNU General Public License as
|
Chris@57
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@57
|
14 License, or (at your option) any later version. See the file
|
Chris@57
|
15 COPYING included with this distribution for more information.
|
Chris@57
|
16 */
|
jtkorhonen@0
|
17
|
jtkorhonen@0
|
18 #include "hgrunner.h"
|
Chris@57
|
19 #include "debug.h"
|
Chris@50
|
20
|
Chris@50
|
21 #include <QPushButton>
|
Chris@50
|
22 #include <QListWidget>
|
Chris@50
|
23 #include <QDialog>
|
Chris@50
|
24 #include <QLabel>
|
Chris@50
|
25 #include <QVBoxLayout>
|
jtkorhonen@0
|
26
|
Chris@43
|
27 #include <iostream>
|
jtkorhonen@0
|
28 #include <unistd.h>
|
jtkorhonen@0
|
29
|
jtkorhonen@0
|
30 HgRunner::HgRunner(QWidget * parent): QProgressBar(parent)
|
jtkorhonen@0
|
31 {
|
jtkorhonen@0
|
32 proc = new QProcess(this);
|
jtkorhonen@0
|
33
|
cannam@45
|
34 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
cannam@45
|
35 env.insert("LANG", "en_US.utf8");
|
cannam@45
|
36 env.insert("LC_ALL", "en_US.utf8");
|
cannam@45
|
37 proc->setProcessEnvironment(env);
|
cannam@45
|
38
|
jtkorhonen@0
|
39 setTextVisible(false);
|
jtkorhonen@0
|
40 setVisible(false);
|
jtkorhonen@0
|
41 isRunning = false;
|
jtkorhonen@0
|
42
|
jtkorhonen@0
|
43 stdOut.clear();
|
jtkorhonen@0
|
44 stdErr.clear();
|
jtkorhonen@0
|
45
|
jtkorhonen@0
|
46 connect(proc, SIGNAL(started()), this, SLOT(started()));
|
jtkorhonen@0
|
47 connect(proc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError)));
|
jtkorhonen@0
|
48 connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
|
jtkorhonen@0
|
49 }
|
jtkorhonen@0
|
50
|
jtkorhonen@0
|
51 HgRunner::~HgRunner()
|
jtkorhonen@0
|
52 {
|
jtkorhonen@0
|
53 delete proc;
|
jtkorhonen@0
|
54 }
|
jtkorhonen@0
|
55
|
jtkorhonen@0
|
56 void HgRunner::started()
|
jtkorhonen@0
|
57 {
|
jtkorhonen@0
|
58 proc -> closeWriteChannel();
|
jtkorhonen@0
|
59 }
|
jtkorhonen@0
|
60
|
jtkorhonen@0
|
61 void HgRunner::setProcExitInfo(int procExitCode, QProcess::ExitStatus procExitStatus)
|
jtkorhonen@0
|
62 {
|
jtkorhonen@0
|
63 exitCode = procExitCode;
|
jtkorhonen@0
|
64 exitStatus = procExitStatus;
|
cannam@45
|
65 stdOut = QString::fromUtf8(proc -> readAllStandardOutput());
|
cannam@45
|
66 stdErr = QString::fromUtf8(proc -> readAllStandardError());
|
Chris@58
|
67
|
Chris@59
|
68 DEBUG << "setProcExitInfo: " << stdOut.split("\n").size() << " line(s) of stdout, " << stdErr.split("\n").size() << " line(s) of stderr";
|
Chris@58
|
69
|
Chris@58
|
70 // std::cerr << "stdout was " << stdOut.toStdString() << std::endl;
|
jtkorhonen@0
|
71 }
|
jtkorhonen@0
|
72
|
jtkorhonen@0
|
73 void HgRunner::presentErrorToUser()
|
jtkorhonen@0
|
74 {
|
jtkorhonen@0
|
75 QPushButton *okButton;
|
jtkorhonen@0
|
76 QListWidget *stdoL;
|
jtkorhonen@0
|
77 QListWidget *stdeL;
|
jtkorhonen@0
|
78 QString tmp;
|
jtkorhonen@0
|
79
|
jtkorhonen@0
|
80 QDialog *dlg = new QDialog(this);
|
jtkorhonen@0
|
81 dlg -> setMinimumWidth(800);
|
jtkorhonen@0
|
82 QVBoxLayout layout;
|
jtkorhonen@0
|
83
|
jtkorhonen@0
|
84 dlg -> setWindowTitle(tr("Mercurial error / warning"));
|
jtkorhonen@0
|
85
|
jtkorhonen@0
|
86 tmp.sprintf("%s: %d, %s: %d", "Exitcode", exitCode, "Exit status", exitStatus);
|
jtkorhonen@0
|
87 layout.addWidget(new QLabel(getLastCommandLine()));
|
jtkorhonen@0
|
88 layout.addWidget(new QLabel(tmp));
|
jtkorhonen@0
|
89 layout.addWidget(new QLabel(tr("Standard out:")));
|
jtkorhonen@0
|
90 stdoL = new QListWidget();
|
jtkorhonen@0
|
91 stdoL -> addItems(stdOut.split("\n"));
|
jtkorhonen@0
|
92 layout.addWidget(stdoL);
|
jtkorhonen@0
|
93
|
jtkorhonen@0
|
94 layout.addWidget(new QLabel(tr("Standard error:")));
|
jtkorhonen@0
|
95 stdeL = new QListWidget();
|
jtkorhonen@0
|
96 stdeL -> addItems(stdErr.split("\n"));
|
jtkorhonen@0
|
97 layout.addWidget(stdeL);
|
jtkorhonen@0
|
98
|
jtkorhonen@0
|
99 okButton = new QPushButton("Ok");
|
jtkorhonen@0
|
100 layout.addWidget(okButton);
|
jtkorhonen@0
|
101
|
jtkorhonen@0
|
102 connect(okButton, SIGNAL(clicked()), dlg, SLOT(accept()));
|
jtkorhonen@0
|
103 dlg -> setLayout(&layout);
|
jtkorhonen@0
|
104
|
jtkorhonen@0
|
105 dlg -> setModal(true);
|
jtkorhonen@0
|
106 dlg -> exec();
|
jtkorhonen@0
|
107 }
|
jtkorhonen@0
|
108
|
jtkorhonen@0
|
109
|
jtkorhonen@0
|
110
|
jtkorhonen@0
|
111 void HgRunner::error(QProcess::ProcessError)
|
jtkorhonen@0
|
112 {
|
jtkorhonen@0
|
113 setProcExitInfo(proc -> exitCode(), proc -> exitStatus());
|
jtkorhonen@0
|
114
|
jtkorhonen@11
|
115 if (reportErrors)
|
jtkorhonen@11
|
116 {
|
jtkorhonen@11
|
117 presentErrorToUser();
|
jtkorhonen@11
|
118 }
|
jtkorhonen@0
|
119
|
jtkorhonen@0
|
120 isRunning = false;
|
jtkorhonen@0
|
121 }
|
jtkorhonen@0
|
122
|
jtkorhonen@0
|
123 QString HgRunner::getLastCommandLine()
|
jtkorhonen@0
|
124 {
|
jtkorhonen@0
|
125 return QString("Command line: " + lastHgCommand + " " + lastParams);
|
jtkorhonen@0
|
126 }
|
jtkorhonen@0
|
127
|
jtkorhonen@0
|
128 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus)
|
jtkorhonen@0
|
129 {
|
jtkorhonen@0
|
130 setProcExitInfo(procExitCode, procExitStatus);
|
jtkorhonen@0
|
131
|
jtkorhonen@0
|
132 if (reportErrors)
|
jtkorhonen@0
|
133 {
|
jtkorhonen@0
|
134 if ((exitCode == 0) && (exitStatus == QProcess::NormalExit))
|
jtkorhonen@0
|
135 {
|
jtkorhonen@0
|
136 //All ok
|
jtkorhonen@0
|
137 }
|
jtkorhonen@0
|
138 else
|
jtkorhonen@0
|
139 {
|
jtkorhonen@0
|
140 presentErrorToUser();
|
jtkorhonen@0
|
141 }
|
jtkorhonen@0
|
142 }
|
jtkorhonen@0
|
143
|
jtkorhonen@0
|
144 isRunning = false;
|
jtkorhonen@0
|
145 }
|
jtkorhonen@0
|
146
|
jtkorhonen@0
|
147 bool HgRunner::isProcRunning()
|
jtkorhonen@0
|
148 {
|
jtkorhonen@0
|
149 return isRunning;
|
jtkorhonen@0
|
150 }
|
jtkorhonen@0
|
151
|
jtkorhonen@0
|
152 void HgRunner::killProc()
|
jtkorhonen@0
|
153 {
|
jtkorhonen@0
|
154 if (isProcRunning())
|
jtkorhonen@0
|
155 {
|
jtkorhonen@0
|
156 proc -> kill();
|
jtkorhonen@0
|
157 }
|
jtkorhonen@0
|
158 }
|
jtkorhonen@0
|
159
|
jtkorhonen@0
|
160
|
jtkorhonen@0
|
161 void HgRunner::startProc(QString hgExePathAndName, QString workingDir, QStringList params, bool reportErrors)
|
jtkorhonen@0
|
162 {
|
jtkorhonen@0
|
163 this -> reportErrors = reportErrors;
|
jtkorhonen@0
|
164 isRunning = true;
|
jtkorhonen@0
|
165 setRange(0, 0);
|
jtkorhonen@0
|
166 setVisible(true);
|
jtkorhonen@0
|
167 stdOut.clear();
|
jtkorhonen@0
|
168 stdErr.clear();
|
jtkorhonen@0
|
169 exitCode = 0;
|
jtkorhonen@0
|
170 exitStatus = QProcess::NormalExit;
|
jtkorhonen@0
|
171
|
jtkorhonen@0
|
172 if (!workingDir.isEmpty())
|
jtkorhonen@0
|
173 {
|
jtkorhonen@0
|
174 proc -> setWorkingDirectory(workingDir);
|
jtkorhonen@0
|
175 }
|
jtkorhonen@0
|
176
|
jtkorhonen@0
|
177 lastHgCommand = hgExePathAndName;
|
jtkorhonen@0
|
178 lastParams = params.join(" ");
|
jtkorhonen@0
|
179
|
Chris@57
|
180 QString cmdline = hgExePathAndName;
|
Chris@57
|
181 foreach (QString param, params) cmdline += " " + param;
|
Chris@57
|
182 DEBUG << "HgRunner: starting: " << cmdline;
|
Chris@43
|
183
|
jtkorhonen@0
|
184 proc -> start(hgExePathAndName, params);
|
jtkorhonen@0
|
185
|
jtkorhonen@0
|
186 }
|
jtkorhonen@0
|
187
|
jtkorhonen@0
|
188 int HgRunner::getExitCode()
|
jtkorhonen@0
|
189 {
|
jtkorhonen@0
|
190 return exitCode;
|
jtkorhonen@0
|
191 }
|
jtkorhonen@0
|
192
|
jtkorhonen@0
|
193 QString HgRunner::getStdOut()
|
jtkorhonen@0
|
194 {
|
jtkorhonen@0
|
195 return stdOut;
|
jtkorhonen@0
|
196 }
|
jtkorhonen@0
|
197
|
jtkorhonen@0
|
198 void HgRunner::hideProgBar()
|
jtkorhonen@0
|
199 {
|
jtkorhonen@0
|
200 setVisible(false);
|
jtkorhonen@0
|
201 }
|
jtkorhonen@0
|
202
|
jtkorhonen@0
|
203
|