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>
25 #include <QTreeWidget>
31 check_path(const QStringList
& paths
, const QString
& exec
) {
32 QList
<QString
>::const_iterator iter
;
35 for (iter
=paths
.constBegin();
36 iter
!=paths
.constEnd();
41 .arg(QDir::fromNativeSeparators(*iter
))
44 tmp
= QDir::toNativeSeparators(tmp
);
46 if (QFile::exists(tmp
)) {
55 verify_version_output(
68 proc
.setEnvironment(QStringList() << "CCLIVE_NO_CONFIG=1");
69 proc
.setProcessChannelMode(QProcess::MergedChannels
);
70 proc
.start(path
, QStringList() << "--version");
73 *isCcliveFlag
= false;
75 if (!proc
.waitForFinished()) {
76 throw NoCcliveException(path
,
77 proc
.exitCode(), proc
.errorString());
80 const QString output
=
81 QString::fromLocal8Bit( proc
.readAll() );
87 const QString versionOutput
= output
;
88 // qDebug() << versionOutput;
90 const QStringList tmp
=
91 versionOutput
.split("\n", QString::SkipEmptyParts
);
93 bool enoughOutputFlag
= false;
95 if (tmp
.size() >= 1) {
97 const QStringList lst
=
98 tmp
[0].split(" ", QString::SkipEmptyParts
);
100 if (lst
.size() >= 6) {
102 *isCcliveFlag
= (lst
[0] == "cclive");
108 enoughOutputFlag
= true;
112 if (!enoughOutputFlag
) {
113 throw NoCcliveException(path
,
115 tr("Not c/clive or it is an unsupported "
120 throw NoCcliveException(path
, exitCode
, output
);
133 const QStringList env
=
134 QProcess::systemEnvironment();
136 QRegExp
re("^PATH=(.*)", Qt::CaseInsensitive
);
139 const QString capt
= re
.capturedTexts()[1].simplified();
140 QStringList paths
= capt
.split(":");
142 if (paths
.size() < 2) // w32
143 paths
= capt
.split(";");
145 if (paths
.size() < 2)
148 path
= check_path(paths
, "cclive");
150 path
= check_path(paths
, "clive");
152 if (path
.isEmpty()) {
153 // Detection from $PATH failed. Prompt user
154 // to specify the path in preferences manually.
155 throw NoCcliveException(
157 "Neither cclive or clive not was found in the path.\n"
158 "Please specify the path to either command in the\n"
164 // Check --version output.
165 verify_version_output(
176 Util::verifyCclivePath(
181 bool *isCcliveFlag
/*=NULL*/)
183 verify_version_output(
194 const QTreeWidget
*w
,
195 const Qt::CheckState
& st
,
196 const int column
/*=0*/)
198 QTreeWidgetItemIterator
iter(const_cast<QTreeWidget
*>(w
));
200 (*iter
)->setCheckState(column
, st
);
206 Util::invertAllCheckableItems(
207 const QTreeWidget
*w
,
208 const int column
/*=0*/)
210 QTreeWidgetItemIterator
iter(const_cast<QTreeWidget
*>(w
));
212 (*iter
)->setCheckState(column
,
213 (*iter
)->checkState(column
) == Qt::Checked
221 NoCcliveException::NoCcliveException(const QString
& errmsg
)
226 static const QString defmsg
=
227 QObject::tr("Undefined path to c/clive command");
229 NoCcliveException::NoCcliveException(
231 const QString
& errmsg
)
234 if (!path
.isEmpty()) {
236 QString("error: %1:\n%2").arg(path
).arg(errmsg
);
240 NoCcliveException::NoCcliveException(
243 const QString
& output
)
246 if (!path
.isEmpty()) {
247 this->errmsg
= QString(
249 tr("%1 exited with %2:\n%3")
258 NoCcliveException::what() const {