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 |
QString getOniSplitExeAbsolutePath(){ |
70 |
|
71 |
#ifdef Q_OS_MAC |
72 |
return getMonoExecutablePath() + " " + getAppPath() + "/" + GlobalVars::ToolsFolder + "/" + GlobalVars::OniSplitString; |
73 |
#else |
74 |
return getAppPath() + "/" + GlobalVars::ToolsFolder + "/" + GlobalVars::OniSplitString; |
75 |
#endif |
76 |
} |
77 |
|
78 |
QString getXmlToolsExeAbsolutePath(){ |
79 |
return getAppPath() + "/" + GlobalVars::ToolsFolder + "/" + GlobalVars::XmlToolsString; |
80 |
} |
81 |
|
82 |
#ifdef Q_OS_MAC |
83 |
QString getMonoExecutablePath(){ |
84 |
|
85 |
// Only way that I found to get mono working in 10.11 |
86 |
QString possibleMonoDir = "/usr/local/bin/mono"; |
87 |
QFileInfo checkFile(possibleMonoDir); |
88 |
|
89 |
if (checkFile.exists() && checkFile.isFile()) { |
90 |
return possibleMonoDir; |
91 |
} else { |
92 |
return "mono"; |
93 |
} |
94 |
|
95 |
} |
96 |
#endif |
97 |
|
98 |
} |