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@62
|
36 << ": system path is " << path;
|
Chris@62
|
37 #ifdef Q_OS_WIN32
|
Chris@62
|
38 QChar pathSep = ';';
|
Chris@62
|
39 #else
|
Chris@62
|
40 QChar pathSep = ':';
|
Chris@62
|
41 #endif
|
Chris@62
|
42 QStringList elements = path.split(pathSep, QString::SkipEmptyParts);
|
Chris@62
|
43 foreach (QString element, elements) {
|
Chris@62
|
44 QString full = QString("%1/%2").arg(element).arg(name);
|
Chris@62
|
45 QFileInfo fi(full);
|
Chris@62
|
46 if (fi.exists() && fi.isFile() && fi.isExecutable()) {
|
Chris@62
|
47 name = full;
|
Chris@62
|
48 break;
|
Chris@62
|
49 }
|
Chris@62
|
50 }
|
Chris@62
|
51 }
|
Chris@62
|
52 }
|
Chris@62
|
53 return name;
|
Chris@62
|
54 }
|
Chris@62
|
55
|
jtkorhonen@0
|
56 QString getSystem()
|
jtkorhonen@0
|
57 {
|
jtkorhonen@0
|
58 #ifdef Q_WS_X11
|
jtkorhonen@0
|
59 return QString("Linux");
|
jtkorhonen@0
|
60 #endif
|
jtkorhonen@0
|
61
|
jtkorhonen@0
|
62 #ifdef Q_WS_MAC
|
jtkorhonen@0
|
63 return QString("Mac");
|
jtkorhonen@0
|
64 #endif
|
jtkorhonen@0
|
65
|
jtkorhonen@0
|
66 #ifdef Q_WS_WIN
|
jtkorhonen@0
|
67 return QString("Windows");
|
jtkorhonen@0
|
68 #endif
|
jtkorhonen@0
|
69
|
jtkorhonen@0
|
70 return QString("");
|
jtkorhonen@0
|
71 }
|
jtkorhonen@0
|
72
|
jtkorhonen@0
|
73 QString getHgDirName()
|
jtkorhonen@0
|
74 {
|
jtkorhonen@0
|
75 if (getSystem() == "Windows")
|
jtkorhonen@0
|
76 {
|
jtkorhonen@0
|
77 return QString(".hg\\");
|
jtkorhonen@0
|
78 }
|
jtkorhonen@0
|
79 else
|
jtkorhonen@0
|
80 {
|
jtkorhonen@0
|
81 return QString(".hg/");
|
jtkorhonen@0
|
82 }
|
jtkorhonen@0
|
83 }
|
jtkorhonen@0
|
84
|
Chris@62
|
85 #ifdef Q_OS_WIN32
|
Chris@62
|
86 QString getUserRealName()
|
Chris@62
|
87 {
|
Chris@62
|
88 const int maxlen = 1023;
|
Chris@62
|
89 TCHAR buf[maxlen + 2];
|
Chris@62
|
90 LPTSTR info = buf;
|
jtkorhonen@0
|
91
|
Chris@62
|
92 if (!GetUserNameEx(NameDisplay, info, maxlen)) {
|
Chris@62
|
93 return "";
|
Chris@62
|
94 }
|
jtkorhonen@0
|
95
|
Chris@62
|
96 return QString::fromUcs2(info);
|
Chris@62
|
97 }
|
luisf@71
|
98 #else
|
luisf@71
|
99 #ifdef Q_OS_MAC
|
Chris@62
|
100 // Nothing here: definition is in common_osx.mm
|
Chris@62
|
101 #else
|
Chris@62
|
102 QString getUserRealName()
|
Chris@62
|
103 {
|
Chris@62
|
104 const int maxlen = 1023;
|
Chris@62
|
105 char buf[maxlen + 2];
|
jtkorhonen@0
|
106
|
Chris@62
|
107 if (getlogin_r(buf, maxlen)) return "";
|
jtkorhonen@0
|
108
|
Chris@62
|
109 struct passwd *p = getpwnam(buf);
|
Chris@62
|
110 if (!p) return "";
|
Chris@62
|
111
|
Chris@62
|
112 QString s(p->pw_gecos);
|
Chris@62
|
113 if (s != "") s = s.split(',')[0];
|
Chris@62
|
114 return s;
|
Chris@62
|
115 }
|
Chris@62
|
116 #endif
|
luisf@71
|
117 #endif
|
jtkorhonen@0
|
118
|