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@43
|
67 std::cerr << "stdout was " << stdOut.toStdString() << std::endl;
|
jtkorhonen@0
|
68 }
|
jtkorhonen@0
|
69
|
jtkorhonen@0
|
70 void HgRunner::presentErrorToUser()
|
jtkorhonen@0
|
71 {
|
jtkorhonen@0
|
72 QPushButton *okButton;
|
jtkorhonen@0
|
73 QListWidget *stdoL;
|
jtkorhonen@0
|
74 QListWidget *stdeL;
|
jtkorhonen@0
|
75 QString tmp;
|
jtkorhonen@0
|
76
|
jtkorhonen@0
|
77 QDialog *dlg = new QDialog(this);
|
jtkorhonen@0
|
78 dlg -> setMinimumWidth(800);
|
jtkorhonen@0
|
79 QVBoxLayout layout;
|
jtkorhonen@0
|
80
|
jtkorhonen@0
|
81 dlg -> setWindowTitle(tr("Mercurial error / warning"));
|
jtkorhonen@0
|
82
|
jtkorhonen@0
|
83 tmp.sprintf("%s: %d, %s: %d", "Exitcode", exitCode, "Exit status", exitStatus);
|
jtkorhonen@0
|
84 layout.addWidget(new QLabel(getLastCommandLine()));
|
jtkorhonen@0
|
85 layout.addWidget(new QLabel(tmp));
|
jtkorhonen@0
|
86 layout.addWidget(new QLabel(tr("Standard out:")));
|
jtkorhonen@0
|
87 stdoL = new QListWidget();
|
jtkorhonen@0
|
88 stdoL -> addItems(stdOut.split("\n"));
|
jtkorhonen@0
|
89 layout.addWidget(stdoL);
|
jtkorhonen@0
|
90
|
jtkorhonen@0
|
91 layout.addWidget(new QLabel(tr("Standard error:")));
|
jtkorhonen@0
|
92 stdeL = new QListWidget();
|
jtkorhonen@0
|
93 stdeL -> addItems(stdErr.split("\n"));
|
jtkorhonen@0
|
94 layout.addWidget(stdeL);
|
jtkorhonen@0
|
95
|
jtkorhonen@0
|
96 okButton = new QPushButton("Ok");
|
jtkorhonen@0
|
97 layout.addWidget(okButton);
|
jtkorhonen@0
|
98
|
jtkorhonen@0
|
99 connect(okButton, SIGNAL(clicked()), dlg, SLOT(accept()));
|
jtkorhonen@0
|
100 dlg -> setLayout(&layout);
|
jtkorhonen@0
|
101
|
jtkorhonen@0
|
102 dlg -> setModal(true);
|
jtkorhonen@0
|
103 dlg -> exec();
|
jtkorhonen@0
|
104 }
|
jtkorhonen@0
|
105
|
jtkorhonen@0
|
106
|
jtkorhonen@0
|
107
|
jtkorhonen@0
|
108 void HgRunner::error(QProcess::ProcessError)
|
jtkorhonen@0
|
109 {
|
jtkorhonen@0
|
110 setProcExitInfo(proc -> exitCode(), proc -> exitStatus());
|
jtkorhonen@0
|
111
|
jtkorhonen@11
|
112 if (reportErrors)
|
jtkorhonen@11
|
113 {
|
jtkorhonen@11
|
114 presentErrorToUser();
|
jtkorhonen@11
|
115 }
|
jtkorhonen@0
|
116
|
jtkorhonen@0
|
117 isRunning = false;
|
jtkorhonen@0
|
118 }
|
jtkorhonen@0
|
119
|
jtkorhonen@0
|
120 QString HgRunner::getLastCommandLine()
|
jtkorhonen@0
|
121 {
|
jtkorhonen@0
|
122 return QString("Command line: " + lastHgCommand + " " + lastParams);
|
jtkorhonen@0
|
123 }
|
jtkorhonen@0
|
124
|
jtkorhonen@0
|
125 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus)
|
jtkorhonen@0
|
126 {
|
jtkorhonen@0
|
127 setProcExitInfo(procExitCode, procExitStatus);
|
jtkorhonen@0
|
128
|
jtkorhonen@0
|
129 if (reportErrors)
|
jtkorhonen@0
|
130 {
|
jtkorhonen@0
|
131 if ((exitCode == 0) && (exitStatus == QProcess::NormalExit))
|
jtkorhonen@0
|
132 {
|
jtkorhonen@0
|
133 //All ok
|
jtkorhonen@0
|
134 }
|
jtkorhonen@0
|
135 else
|
jtkorhonen@0
|
136 {
|
jtkorhonen@0
|
137 presentErrorToUser();
|
jtkorhonen@0
|
138 }
|
jtkorhonen@0
|
139 }
|
jtkorhonen@0
|
140
|
jtkorhonen@0
|
141 isRunning = false;
|
jtkorhonen@0
|
142 }
|
jtkorhonen@0
|
143
|
jtkorhonen@0
|
144 bool HgRunner::isProcRunning()
|
jtkorhonen@0
|
145 {
|
jtkorhonen@0
|
146 return isRunning;
|
jtkorhonen@0
|
147 }
|
jtkorhonen@0
|
148
|
jtkorhonen@0
|
149 void HgRunner::killProc()
|
jtkorhonen@0
|
150 {
|
jtkorhonen@0
|
151 if (isProcRunning())
|
jtkorhonen@0
|
152 {
|
jtkorhonen@0
|
153 proc -> kill();
|
jtkorhonen@0
|
154 }
|
jtkorhonen@0
|
155 }
|
jtkorhonen@0
|
156
|
jtkorhonen@0
|
157
|
jtkorhonen@0
|
158 void HgRunner::startProc(QString hgExePathAndName, QString workingDir, QStringList params, bool reportErrors)
|
jtkorhonen@0
|
159 {
|
jtkorhonen@0
|
160 this -> reportErrors = reportErrors;
|
jtkorhonen@0
|
161 isRunning = true;
|
jtkorhonen@0
|
162 setRange(0, 0);
|
jtkorhonen@0
|
163 setVisible(true);
|
jtkorhonen@0
|
164 stdOut.clear();
|
jtkorhonen@0
|
165 stdErr.clear();
|
jtkorhonen@0
|
166 exitCode = 0;
|
jtkorhonen@0
|
167 exitStatus = QProcess::NormalExit;
|
jtkorhonen@0
|
168
|
jtkorhonen@0
|
169 if (!workingDir.isEmpty())
|
jtkorhonen@0
|
170 {
|
jtkorhonen@0
|
171 proc -> setWorkingDirectory(workingDir);
|
jtkorhonen@0
|
172 }
|
jtkorhonen@0
|
173
|
jtkorhonen@0
|
174 lastHgCommand = hgExePathAndName;
|
jtkorhonen@0
|
175 lastParams = params.join(" ");
|
jtkorhonen@0
|
176
|
Chris@57
|
177 QString cmdline = hgExePathAndName;
|
Chris@57
|
178 foreach (QString param, params) cmdline += " " + param;
|
Chris@57
|
179 DEBUG << "HgRunner: starting: " << cmdline;
|
Chris@43
|
180
|
jtkorhonen@0
|
181 proc -> start(hgExePathAndName, params);
|
jtkorhonen@0
|
182
|
jtkorhonen@0
|
183 }
|
jtkorhonen@0
|
184
|
jtkorhonen@0
|
185 int HgRunner::getExitCode()
|
jtkorhonen@0
|
186 {
|
jtkorhonen@0
|
187 return exitCode;
|
jtkorhonen@0
|
188 }
|
jtkorhonen@0
|
189
|
jtkorhonen@0
|
190 QString HgRunner::getStdOut()
|
jtkorhonen@0
|
191 {
|
jtkorhonen@0
|
192 return stdOut;
|
jtkorhonen@0
|
193 }
|
jtkorhonen@0
|
194
|
jtkorhonen@0
|
195 void HgRunner::hideProgBar()
|
jtkorhonen@0
|
196 {
|
jtkorhonen@0
|
197 setVisible(false);
|
jtkorhonen@0
|
198 }
|
jtkorhonen@0
|
199
|
jtkorhonen@0
|
200
|