Import of original sources
[qcomicbook-oblomov] / src / miscutil.cpp
1 /*
2  * This file is a part of QComicBook.
3  *
4  * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
5  *
6  * QComicBook is free software; you can redestribute it and/or modify it
7  * under terms of GNU General Public License by Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY. See GPL for more details.
11  */
12
13 #include "miscutil.h"
14 #include <qstringlist.h>
15 #include <qfileinfo.h>
16 #include <stdlib.h>
17
18 QString Utility::which(const QString &command)
19 {
20         const QString paths = QString(getenv("PATH"));
21         QStringList plist = QStringList::split(":", paths, false);
22         for (QStringList::const_iterator it = plist.begin(); it != plist.end(); it++)
23         {
24                 QFileInfo finfo(*it + "/" + command);
25                 if (finfo.isExecutable())
26                         return finfo.absFilePath();
27         }
28         return QString::null;
29 }
30