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>
33 check_path(const QStringList
& paths
, const QString
& exec
) {
34 QList
<QString
>::const_iterator iter
;
37 for (iter
=paths
.constBegin();
38 iter
!=paths
.constEnd();
43 .arg(QDir::fromNativeSeparators(*iter
))
46 tmp
= QDir::toNativeSeparators(tmp
);
48 if (QFile::exists(tmp
)) {
57 verify_version_output(
70 proc
.setEnvironment(QStringList() << "CCLIVE_NO_CONFIG=1");
71 proc
.setProcessChannelMode(QProcess::MergedChannels
);
72 proc
.start(path
, QStringList() << "--version");
75 *isCcliveFlag
= false;
77 if (!proc
.waitForFinished()) {
78 throw NoCcliveException(path
,
79 proc
.exitCode(), proc
.errorString());
82 const QString output
=
83 QString::fromLocal8Bit( proc
.readAll() );
89 const QString versionOutput
= output
;
90 // qDebug() << versionOutput;
92 const QStringList tmp
=
93 versionOutput
.split("\n", QString::SkipEmptyParts
);
95 bool enoughOutputFlag
= false;
97 if (tmp
.size() >= 1) {
99 const QStringList lst
=
100 tmp
[0].split(" ", QString::SkipEmptyParts
);
102 if (lst
.size() >= 6) {
104 *isCcliveFlag
= (lst
[0] == "cclive");
110 enoughOutputFlag
= true;
114 if (!enoughOutputFlag
) {
115 throw NoCcliveException(path
,
117 tr("Not c/clive or it is an unsupported "
122 throw NoCcliveException(path
, exitCode
, output
);
135 const QStringList env
=
136 QProcess::systemEnvironment();
138 QRegExp
re("^PATH=(.*)", Qt::CaseInsensitive
);
141 const QString capt
= re
.capturedTexts()[1].simplified();
142 QStringList paths
= capt
.split(":");
144 if (paths
.size() < 2) // w32
145 paths
= capt
.split(";");
147 if (paths
.size() < 2)
150 path
= check_path(paths
, "cclive");
152 path
= check_path(paths
, "clive");
154 if (path
.isEmpty()) {
155 // Detection from $PATH failed. Prompt user
156 // to specify the path in preferences manually.
157 throw NoCcliveException(
159 "Neither cclive or clive not was found in the path.\n"
160 "Please specify the path to either command in the\n"
166 // Check --version output.
167 verify_version_output(
178 Util::verifyCclivePath(
183 bool *isCcliveFlag
/*=NULL*/)
185 verify_version_output(
196 const QTreeWidget
*w
,
197 const Qt::CheckState
& st
,
198 const int column
/*=0*/)
200 QTreeWidgetItemIterator
iter(const_cast<QTreeWidget
*>(w
));
202 (*iter
)->setCheckState(column
, st
);
208 Util::invertAllCheckableItems(
209 const QTreeWidget
*w
,
210 const int column
/*=0*/)
212 QTreeWidgetItemIterator
iter(const_cast<QTreeWidget
*>(w
));
214 (*iter
)->setCheckState(column
,
215 (*iter
)->checkState(column
) == Qt::Checked
224 Util::appendLog(const QTextEdit
* w
, const QString
& s
) {
225 QDateTime now
= QDateTime::currentDateTime();
226 QString dt
= now
.toString(Qt::ISODate
);
227 const_cast<QTextEdit
*>(w
)->append(dt
+": "+s
);
231 Util::countItems(const QTreeWidget
*w
) {
233 QTreeWidgetItemIterator
iter(const_cast<QTreeWidget
*>(w
));
241 NoCcliveException::NoCcliveException(const QString
& errmsg
)
246 static const QString defmsg
=
247 QObject::tr("Undefined path to c/clive command");
249 NoCcliveException::NoCcliveException(
251 const QString
& errmsg
)
254 if (!path
.isEmpty()) {
256 QString("error: %1:\n%2").arg(path
).arg(errmsg
);
260 NoCcliveException::NoCcliveException(
263 const QString
& output
)
266 if (!path
.isEmpty()) {
267 this->errmsg
= QString(
269 tr("%1 exited with %2:\n%3")
278 NoCcliveException::what() const {