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@76
|
26
|
Chris@76
|
27 #ifdef Q_OS_WIN32
|
Chris@76
|
28 #define _WIN32_WINNT 0x0500
|
Chris@76
|
29 #include <windows.h>
|
Chris@76
|
30 #include <security.h>
|
Chris@76
|
31 #else
|
Chris@62
|
32 #include <pwd.h>
|
Chris@76
|
33 #endif
|
Chris@62
|
34
|
Chris@62
|
35 QString findExecutable(QString name)
|
Chris@62
|
36 {
|
Chris@62
|
37 if (name != "") {
|
Chris@62
|
38 if (name[0] != '/') {
|
Chris@62
|
39 name = QFileInfo(name).fileName();
|
Chris@62
|
40 QString path =
|
Chris@62
|
41 QProcessEnvironment::systemEnvironment().value("PATH");
|
Chris@62
|
42 DEBUG << "findExecutable: seeking location for binary " << name
|
Chris@74
|
43 << ": system path is " << path << endl;
|
Chris@74
|
44 #ifndef Q_OS_WIN32
|
Chris@74
|
45 path = path + ":/usr/local/bin";
|
Chris@74
|
46 DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)"
|
Chris@74
|
47 << endl;
|
Chris@74
|
48 #endif
|
Chris@62
|
49 #ifdef Q_OS_WIN32
|
Chris@62
|
50 QChar pathSep = ';';
|
Chris@62
|
51 #else
|
Chris@62
|
52 QChar pathSep = ':';
|
Chris@62
|
53 #endif
|
Chris@62
|
54 QStringList elements = path.split(pathSep, QString::SkipEmptyParts);
|
Chris@62
|
55 foreach (QString element, elements) {
|
Chris@62
|
56 QString full = QString("%1/%2").arg(element).arg(name);
|
Chris@62
|
57 QFileInfo fi(full);
|
Chris@62
|
58 if (fi.exists() && fi.isFile() && fi.isExecutable()) {
|
Chris@62
|
59 name = full;
|
Chris@62
|
60 break;
|
Chris@62
|
61 }
|
Chris@62
|
62 }
|
Chris@62
|
63 }
|
Chris@62
|
64 }
|
Chris@62
|
65 return name;
|
Chris@62
|
66 }
|
Chris@62
|
67
|
jtkorhonen@0
|
68 QString getSystem()
|
jtkorhonen@0
|
69 {
|
jtkorhonen@0
|
70 #ifdef Q_WS_X11
|
jtkorhonen@0
|
71 return QString("Linux");
|
jtkorhonen@0
|
72 #endif
|
jtkorhonen@0
|
73
|
jtkorhonen@0
|
74 #ifdef Q_WS_MAC
|
jtkorhonen@0
|
75 return QString("Mac");
|
jtkorhonen@0
|
76 #endif
|
jtkorhonen@0
|
77
|
jtkorhonen@0
|
78 #ifdef Q_WS_WIN
|
jtkorhonen@0
|
79 return QString("Windows");
|
jtkorhonen@0
|
80 #endif
|
jtkorhonen@0
|
81
|
jtkorhonen@0
|
82 return QString("");
|
jtkorhonen@0
|
83 }
|
jtkorhonen@0
|
84
|
jtkorhonen@0
|
85 QString getHgDirName()
|
jtkorhonen@0
|
86 {
|
jtkorhonen@0
|
87 if (getSystem() == "Windows")
|
jtkorhonen@0
|
88 {
|
jtkorhonen@0
|
89 return QString(".hg\\");
|
jtkorhonen@0
|
90 }
|
jtkorhonen@0
|
91 else
|
jtkorhonen@0
|
92 {
|
jtkorhonen@0
|
93 return QString(".hg/");
|
jtkorhonen@0
|
94 }
|
jtkorhonen@0
|
95 }
|
jtkorhonen@0
|
96
|
Chris@62
|
97 #ifdef Q_OS_WIN32
|
Chris@62
|
98 QString getUserRealName()
|
Chris@62
|
99 {
|
Chris@76
|
100 TCHAR buf[1024];
|
Chris@76
|
101 long unsigned int maxlen = 1000;
|
Chris@62
|
102 LPTSTR info = buf;
|
jtkorhonen@0
|
103
|
Chris@76
|
104 if (!GetUserNameEx(NameDisplay, info, &maxlen)) {
|
Chris@76
|
105 DEBUG << "GetUserNameEx failed: " << GetLastError() << endl;
|
Chris@62
|
106 return "";
|
Chris@62
|
107 }
|
jtkorhonen@0
|
108
|
Chris@76
|
109 #ifdef UNICODE
|
Chris@76
|
110 return QString::fromUtf16((const unsigned short *)info);
|
Chris@76
|
111 #else
|
Chris@76
|
112 return QString::fromLocal8Bit(info);
|
Chris@76
|
113 #endif
|
Chris@62
|
114 }
|
luisf@71
|
115 #else
|
luisf@71
|
116 #ifdef Q_OS_MAC
|
Chris@62
|
117 // Nothing here: definition is in common_osx.mm
|
Chris@62
|
118 #else
|
Chris@62
|
119 QString getUserRealName()
|
Chris@62
|
120 {
|
Chris@62
|
121 const int maxlen = 1023;
|
Chris@62
|
122 char buf[maxlen + 2];
|
jtkorhonen@0
|
123
|
Chris@62
|
124 if (getlogin_r(buf, maxlen)) return "";
|
jtkorhonen@0
|
125
|
Chris@62
|
126 struct passwd *p = getpwnam(buf);
|
Chris@62
|
127 if (!p) return "";
|
Chris@62
|
128
|
Chris@62
|
129 QString s(p->pw_gecos);
|
Chris@62
|
130 if (s != "") s = s.split(',')[0];
|
Chris@62
|
131 return s;
|
Chris@62
|
132 }
|
Chris@62
|
133 #endif
|
luisf@71
|
134 #endif
|
jtkorhonen@0
|
135
|