2 * abby Copyright (C) 2009 Toni Gundogdu.
3 * This file is part of abby.
5 * abby is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * abby is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <QMessageBox>
23 #include <QTranslator>
30 check_path(const QStringList
& paths
, const QString
& exec
) {
31 QList
<QString
>::const_iterator iter
;
34 for (iter
=paths
.constBegin();
35 iter
!=paths
.constEnd();
40 .arg(QDir::fromNativeSeparators(*iter
))
43 tmp
= QDir::toNativeSeparators(tmp
);
45 if (QFile::exists(tmp
)) {
54 verify_version_output(
56 QString
& ccliveVersion
,
62 ccliveVersion
.clear();
66 proc
.setEnvironment(QStringList() << "CCLIVE_NO_CONFIG=1");
67 proc
.setProcessChannelMode(QProcess::MergedChannels
);
68 proc
.start(path
, QStringList() << "--version");
71 *isCcliveFlag
= false;
73 if (!proc
.waitForFinished()) {
74 throw NoCcliveException(path
,
75 proc
.exitCode(), proc
.errorString());
78 const QString output
=
79 QString::fromLocal8Bit( proc
.readAll() );
85 const QString versionOutput
= output
;
86 // qDebug() << versionOutput;
88 const QStringList tmp
=
89 versionOutput
.split("\n", QString::SkipEmptyParts
);
91 bool enoughOutputFlag
= false;
93 if (tmp
.size() >= 1) {
95 const QStringList lst
=
96 tmp
[0].split(" ", QString::SkipEmptyParts
);
98 if (lst
.size() >= 6) {
100 *isCcliveFlag
= (lst
[0] == "cclive");
101 ccliveVersion
= lst
[2];
103 curlVersion
= lst
[6];
105 enoughOutputFlag
= true;
109 if (!enoughOutputFlag
) {
110 throw NoCcliveException(path
,
112 tr("Not c/clive or it is an unsupported "
117 throw NoCcliveException(path
, exitCode
, output
);
124 QString
& ccliveVersion
,
125 QString
& curlVersion
,
130 const QStringList env
=
131 QProcess::systemEnvironment();
133 QRegExp
re("^PATH=(.*)", Qt::CaseInsensitive
);
136 const QString capt
= re
.capturedTexts()[1].simplified();
137 QStringList paths
= capt
.split(":");
139 if (paths
.size() < 2) // w32
140 paths
= capt
.split(";");
142 if (paths
.size() < 2)
145 path
= check_path(paths
, "cclive");
147 path
= check_path(paths
, "clive");
149 if (path
.isEmpty()) {
150 // Detection from $PATH failed. Prompt user
151 // to specify the path in preferences manually.
152 throw NoCcliveException(
154 "Neither cclive or clive not was found in the path.\n"
155 "Please specify the path to either command in the abby\n"
161 // Check --version output.
162 verify_version_output(
173 Util::verifyCclivePath(
175 QString
& ccliveVersion
,
176 QString
& curlVersion
,
178 bool *isCcliveFlag
/*=NULL*/)
180 verify_version_output(
189 NoCcliveException::NoCcliveException(const QString
& errmsg
)
194 static const QString defmsg
=
195 QObject::tr("Undefined path to c/clive command");
197 NoCcliveException::NoCcliveException(
199 const QString
& errmsg
)
202 if (!path
.isEmpty()) {
204 QString("error: %1:\n%2").arg(path
).arg(errmsg
);
208 NoCcliveException::NoCcliveException(
211 const QString
& output
)
214 if (!path
.isEmpty()) {
215 this->errmsg
= QString(
217 tr("%1 exited with %2:\n%3")
226 NoCcliveException::what() const {