1 |
#include "utilvago.h" |
2 |
|
3 |
namespace UtilVago{ |
4 |
|
5 |
void openLogFile(){ |
6 |
QDesktopServices::openUrl(QUrl("file:///"+getAppPath()+"/"+GlobalVars::AppLogName)); |
7 |
} |
8 |
|
9 |
void showAndLogErrorPopUp(Logger *logger, const QString &message){ |
10 |
|
11 |
logger->writeString(message); |
12 |
|
13 |
QMessageBox msgBox; |
14 |
msgBox.setIcon(QMessageBox::Critical); |
15 |
msgBox.setText(message); |
16 |
msgBox.exec(); |
17 |
} |
18 |
|
19 |
//Same of above but allow open log file (doesn't write in log file!!) |
20 |
void showErrorPopUpLogButton(const QString &message){ |
21 |
QMessageBox msgBox; |
22 |
msgBox.setIcon(QMessageBox::Critical); |
23 |
msgBox.setText(message); |
24 |
QPushButton *viewb = msgBox.addButton("View log", QMessageBox::ActionRole); |
25 |
msgBox.setStandardButtons(QMessageBox::Close); |
26 |
msgBox.exec(); |
27 |
if(msgBox.clickedButton() == (QAbstractButton*)(viewb)){ |
28 |
openLogFile(); |
29 |
} |
30 |
} |
31 |
|
32 |
//Same of above but also writtes directly to the log file the error |
33 |
void showAndLogErrorPopUpLogButton(Logger *logger, const QString &message){ |
34 |
|
35 |
logger->writeString(message); |
36 |
|
37 |
QMessageBox msgBox; |
38 |
msgBox.setIcon(QMessageBox::Critical); |
39 |
msgBox.setText(message); |
40 |
QPushButton *viewb = msgBox.addButton("View log", QMessageBox::ActionRole); |
41 |
msgBox.setStandardButtons(QMessageBox::Close); |
42 |
msgBox.exec(); |
43 |
if(msgBox.clickedButton() == (QAbstractButton*)(viewb)){ |
44 |
openLogFile(); |
45 |
} |
46 |
} |
47 |
|
48 |
/** |
49 |
Gets application directory. In mac os gets the .app directory |
50 |
**/ |
51 |
QString getOSIndependentAppPath(){ |
52 |
#ifdef Q_OS_MAC |
53 |
QDir dir = QDir(QCoreApplication::applicationDirPath()); |
54 |
if(dir.absolutePath().contains(".app")){ // include bundle, but we don't want it |
55 |
dir.cdUp(); |
56 |
dir.cdUp(); |
57 |
dir.cdUp(); |
58 |
} |
59 |
return dir.absolutePath(); |
60 |
#else |
61 |
return QDir::currentPath(); |
62 |
#endif |
63 |
} |
64 |
|
65 |
QString getAppPath(){ |
66 |
return getOSIndependentAppPath(); |
67 |
} |
68 |
|
69 |
// Absolute paths |
70 |
QString getOniSplitExecutableAbsolutePath(){ |
71 |
return getAppPath() + "/" + GlobalVars::ToolsFolder + "/" + GlobalVars::OniSplitString; |
72 |
} |
73 |
|
74 |
QString getXmlToolsExecutableAbsolutePath(){ |
75 |
return getAppPath() + "/" + GlobalVars::ToolsFolder + "/" + GlobalVars::XmlToolsString; |
76 |
} |
77 |
|
78 |
// Executables (includes mono if necessary) |
79 |
QString getOniSplitExecutable(){ |
80 |
|
81 |
#ifdef Q_OS_MAC |
82 |
return getMonoExecutablePath() + " " + getOniSplitExecutableAbsolutePath(); |
83 |
#else |
84 |
return getOniSplitExecutableAbsolutePath(); |
85 |
#endif |
86 |
} |
87 |
|
88 |
QString getXmlToolsExecutable(){ |
89 |
return getXmlToolsExecutableAbsolutePath(); |
90 |
} |
91 |
|
92 |
#ifdef Q_OS_MAC |
93 |
QString getMonoExecutablePath(){ |
94 |
|
95 |
// Only way that I found to get mono working in 10.11 |
96 |
QString possibleMonoDir = "/usr/local/bin/mono"; |
97 |
QFileInfo checkFile(possibleMonoDir); |
98 |
|
99 |
if (checkFile.exists() && checkFile.isFile()) { |
100 |
return possibleMonoDir; |
101 |
} else { |
102 |
return "mono"; |
103 |
} |
104 |
|
105 |
} |
106 |
#endif |
107 |
|
108 |
} |