annotate common.cpp @ 74:10eb97683aa9

* Show branch names even for changes with children, if those children are on a different branch * Pick up remote repo path from local repo via hg paths * Some work towards breaking down files into various groups based on status * Add /usr/local/bin to path for hg (temporary hack I hope)
author Chris Cannam
date Fri, 19 Nov 2010 14:54:19 +0000
parents eaabc54de103
children d575a8f76a53
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@57 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
jtkorhonen@0 17
Chris@62 18 #include "common.h"
Chris@62 19 #include "debug.h"
jtkorhonen@0 20
Chris@62 21 #include <QFileInfo>
Chris@62 22 #include <QProcessEnvironment>
Chris@62 23 #include <QStringList>
jtkorhonen@0 24
Chris@62 25 #include <sys/types.h>
Chris@62 26 #include <pwd.h>
Chris@62 27
Chris@62 28 QString findExecutable(QString name)
Chris@62 29 {
Chris@62 30 if (name != "") {
Chris@62 31 if (name[0] != '/') {
Chris@62 32 name = QFileInfo(name).fileName();
Chris@62 33 QString path =
Chris@62 34 QProcessEnvironment::systemEnvironment().value("PATH");
Chris@62 35 DEBUG << "findExecutable: seeking location for binary " << name
Chris@74 36 << ": system path is " << path << endl;
Chris@74 37 #ifndef Q_OS_WIN32
Chris@74 38 path = path + ":/usr/local/bin";
Chris@74 39 DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)"
Chris@74 40 << endl;
Chris@74 41 #endif
Chris@62 42 #ifdef Q_OS_WIN32
Chris@62 43 QChar pathSep = ';';
Chris@62 44 #else
Chris@62 45 QChar pathSep = ':';
Chris@62 46 #endif
Chris@62 47 QStringList elements = path.split(pathSep, QString::SkipEmptyParts);
Chris@62 48 foreach (QString element, elements) {
Chris@62 49 QString full = QString("%1/%2").arg(element).arg(name);
Chris@62 50 QFileInfo fi(full);
Chris@62 51 if (fi.exists() && fi.isFile() && fi.isExecutable()) {
Chris@62 52 name = full;
Chris@62 53 break;
Chris@62 54 }
Chris@62 55 }
Chris@62 56 }
Chris@62 57 }
Chris@62 58 return name;
Chris@62 59 }
Chris@62 60
jtkorhonen@0 61 QString getSystem()
jtkorhonen@0 62 {
jtkorhonen@0 63 #ifdef Q_WS_X11
jtkorhonen@0 64 return QString("Linux");
jtkorhonen@0 65 #endif
jtkorhonen@0 66
jtkorhonen@0 67 #ifdef Q_WS_MAC
jtkorhonen@0 68 return QString("Mac");
jtkorhonen@0 69 #endif
jtkorhonen@0 70
jtkorhonen@0 71 #ifdef Q_WS_WIN
jtkorhonen@0 72 return QString("Windows");
jtkorhonen@0 73 #endif
jtkorhonen@0 74
jtkorhonen@0 75 return QString("");
jtkorhonen@0 76 }
jtkorhonen@0 77
jtkorhonen@0 78 QString getHgDirName()
jtkorhonen@0 79 {
jtkorhonen@0 80 if (getSystem() == "Windows")
jtkorhonen@0 81 {
jtkorhonen@0 82 return QString(".hg\\");
jtkorhonen@0 83 }
jtkorhonen@0 84 else
jtkorhonen@0 85 {
jtkorhonen@0 86 return QString(".hg/");
jtkorhonen@0 87 }
jtkorhonen@0 88 }
jtkorhonen@0 89
Chris@62 90 #ifdef Q_OS_WIN32
Chris@62 91 QString getUserRealName()
Chris@62 92 {
Chris@62 93 const int maxlen = 1023;
Chris@62 94 TCHAR buf[maxlen + 2];
Chris@62 95 LPTSTR info = buf;
jtkorhonen@0 96
Chris@62 97 if (!GetUserNameEx(NameDisplay, info, maxlen)) {
Chris@62 98 return "";
Chris@62 99 }
jtkorhonen@0 100
Chris@62 101 return QString::fromUcs2(info);
Chris@62 102 }
luisf@71 103 #else
luisf@71 104 #ifdef Q_OS_MAC
Chris@62 105 // Nothing here: definition is in common_osx.mm
Chris@62 106 #else
Chris@62 107 QString getUserRealName()
Chris@62 108 {
Chris@62 109 const int maxlen = 1023;
Chris@62 110 char buf[maxlen + 2];
jtkorhonen@0 111
Chris@62 112 if (getlogin_r(buf, maxlen)) return "";
jtkorhonen@0 113
Chris@62 114 struct passwd *p = getpwnam(buf);
Chris@62 115 if (!p) return "";
Chris@62 116
Chris@62 117 QString s(p->pw_gecos);
Chris@62 118 if (s != "") s = s.split(',')[0];
Chris@62 119 return s;
Chris@62 120 }
Chris@62 121 #endif
luisf@71 122 #endif
jtkorhonen@0 123