Chris@57: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@57: Chris@57: /* Chris@57: EasyMercurial Chris@57: Chris@57: Based on HgExplorer by Jari Korhonen Chris@57: Copyright (c) 2010 Jari Korhonen Chris@57: Copyright (c) 2010 Chris Cannam Chris@57: Copyright (c) 2010 Queen Mary, University of London Chris@57: Chris@57: This program is free software; you can redistribute it and/or Chris@57: modify it under the terms of the GNU General Public License as Chris@57: published by the Free Software Foundation; either version 2 of the Chris@57: License, or (at your option) any later version. See the file Chris@57: COPYING included with this distribution for more information. Chris@57: */ jtkorhonen@0: Chris@62: #include "common.h" Chris@62: #include "debug.h" jtkorhonen@0: Chris@62: #include Chris@62: #include Chris@62: #include jtkorhonen@0: Chris@62: #include Chris@76: Chris@76: #ifdef Q_OS_WIN32 Chris@76: #define _WIN32_WINNT 0x0500 Chris@76: #include Chris@76: #include Chris@76: #else Chris@62: #include Chris@76: #endif Chris@62: Chris@62: QString findExecutable(QString name) Chris@62: { Chris@62: if (name != "") { Chris@62: if (name[0] != '/') { Chris@62: name = QFileInfo(name).fileName(); Chris@62: QString path = Chris@62: QProcessEnvironment::systemEnvironment().value("PATH"); Chris@62: DEBUG << "findExecutable: seeking location for binary " << name Chris@74: << ": system path is " << path << endl; Chris@74: #ifndef Q_OS_WIN32 Chris@74: path = path + ":/usr/local/bin"; Chris@74: DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)" Chris@74: << endl; Chris@74: #endif Chris@62: #ifdef Q_OS_WIN32 Chris@62: QChar pathSep = ';'; Chris@62: #else Chris@62: QChar pathSep = ':'; Chris@62: #endif Chris@62: QStringList elements = path.split(pathSep, QString::SkipEmptyParts); Chris@62: foreach (QString element, elements) { Chris@62: QString full = QString("%1/%2").arg(element).arg(name); Chris@62: QFileInfo fi(full); Chris@62: if (fi.exists() && fi.isFile() && fi.isExecutable()) { Chris@62: name = full; Chris@62: break; Chris@62: } Chris@62: } Chris@62: } Chris@62: } Chris@62: return name; Chris@62: } Chris@62: jtkorhonen@0: QString getSystem() jtkorhonen@0: { jtkorhonen@0: #ifdef Q_WS_X11 jtkorhonen@0: return QString("Linux"); jtkorhonen@0: #endif jtkorhonen@0: jtkorhonen@0: #ifdef Q_WS_MAC jtkorhonen@0: return QString("Mac"); jtkorhonen@0: #endif jtkorhonen@0: jtkorhonen@0: #ifdef Q_WS_WIN jtkorhonen@0: return QString("Windows"); jtkorhonen@0: #endif jtkorhonen@0: jtkorhonen@0: return QString(""); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: QString getHgDirName() jtkorhonen@0: { jtkorhonen@0: if (getSystem() == "Windows") jtkorhonen@0: { jtkorhonen@0: return QString(".hg\\"); jtkorhonen@0: } jtkorhonen@0: else jtkorhonen@0: { jtkorhonen@0: return QString(".hg/"); jtkorhonen@0: } jtkorhonen@0: } jtkorhonen@0: Chris@62: #ifdef Q_OS_WIN32 Chris@62: QString getUserRealName() Chris@62: { Chris@76: TCHAR buf[1024]; Chris@76: long unsigned int maxlen = 1000; Chris@62: LPTSTR info = buf; jtkorhonen@0: Chris@76: if (!GetUserNameEx(NameDisplay, info, &maxlen)) { Chris@76: DEBUG << "GetUserNameEx failed: " << GetLastError() << endl; Chris@62: return ""; Chris@62: } jtkorhonen@0: Chris@76: #ifdef UNICODE Chris@76: return QString::fromUtf16((const unsigned short *)info); Chris@76: #else Chris@76: return QString::fromLocal8Bit(info); Chris@76: #endif Chris@62: } luisf@71: #else luisf@71: #ifdef Q_OS_MAC Chris@62: // Nothing here: definition is in common_osx.mm Chris@62: #else Chris@62: QString getUserRealName() Chris@62: { Chris@62: const int maxlen = 1023; Chris@62: char buf[maxlen + 2]; jtkorhonen@0: Chris@62: if (getlogin_r(buf, maxlen)) return ""; jtkorhonen@0: Chris@62: struct passwd *p = getpwnam(buf); Chris@62: if (!p) return ""; Chris@62: Chris@62: QString s(p->pw_gecos); Chris@62: if (s != "") s = s.split(',')[0]; Chris@62: return s; Chris@62: } Chris@62: #endif luisf@71: #endif jtkorhonen@0: