| 1 | #include "utilvago.h" | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | namespace UtilVago{ | 
 
 
 
 
 | 4 |  | 
 
 
 
 
 | 5 | void openLogFile(){ | 
 
 
 
 
 | 6 | QDesktopServices::openUrl(QUrl("file:///"+getAppPath()+"/"+GlobalVars::AppLogName)); | 
 
 
 
 
 | 7 | } | 
 
 
 
 
 | 8 |  | 
 
 
 
 
 | 9 | void showAndLogWarningPopUp(const QString &message){ | 
 
 
 
 
 | 10 | LOG_WARNING << message; | 
 
 
 
 
 | 11 |  | 
 
 
 
 
 | 12 | QMessageBox msgBox; | 
 
 
 
 
 | 13 | msgBox.setIcon(QMessageBox::Warning); | 
 
 
 
 
 | 14 | msgBox.setText(message); | 
 
 
 
 
 | 15 | msgBox.exec(); | 
 
 
 
 
 | 16 | } | 
 
 
 
 
 | 17 |  | 
 
 
 
 
 | 18 | //Same of above but allow open log file (doesn't write in log file!!) | 
 
 
 
 
 | 19 | void showWarningPopUpLogButton(const QString &message){ | 
 
 
 
 
 | 20 | QMessageBox msgBox; | 
 
 
 
 
 | 21 | msgBox.setIcon(QMessageBox::Warning); | 
 
 
 
 
 | 22 | msgBox.setText(message); | 
 
 
 
 
 | 23 | QPushButton *viewb = msgBox.addButton("View log", QMessageBox::ActionRole); | 
 
 
 
 
 | 24 | msgBox.setStandardButtons(QMessageBox::Close); | 
 
 
 
 
 | 25 | msgBox.exec(); | 
 
 
 
 
 | 26 | if(msgBox.clickedButton() == (QAbstractButton*)(viewb)){ | 
 
 
 
 
 | 27 | openLogFile(); | 
 
 
 
 
 | 28 | } | 
 
 
 
 
 | 29 | } | 
 
 
 
 
 | 30 |  | 
 
 
 
 
 | 31 | //Same of above but also writtes directly to the log file the error | 
 
 
 
 
 | 32 | void showAndLogWarningPopUpLogButton(const QString &message){ | 
 
 
 
 
 | 33 |  | 
 
 
 
 
 | 34 | LOG_WARNING << message; | 
 
 
 
 
 | 35 |  | 
 
 
 
 
 | 36 | QMessageBox msgBox; | 
 
 
 
 
 | 37 | msgBox.setIcon(QMessageBox::Warning); | 
 
 
 
 
 | 38 | msgBox.setText(message); | 
 
 
 
 
 | 39 | QPushButton *viewb = msgBox.addButton("View log", QMessageBox::ActionRole); | 
 
 
 
 
 | 40 | msgBox.setStandardButtons(QMessageBox::Close); | 
 
 
 
 
 | 41 | msgBox.exec(); | 
 
 
 
 
 | 42 | if(msgBox.clickedButton() == (QAbstractButton*)(viewb)){ | 
 
 
 
 
 | 43 | openLogFile(); | 
 
 
 
 
 | 44 | } | 
 
 
 
 
 | 45 | } | 
 
 
 
 
 | 46 |  | 
 
 
 
 
 | 47 | void showAndLogErrorPopUp(const QString &message){ | 
 
 
 
 
 | 48 |  | 
 
 
 
 
 | 49 | LOG_ERROR << message; | 
 
 
 
 
 | 50 |  | 
 
 
 
 
 | 51 | QMessageBox msgBox; | 
 
 
 
 
 | 52 | msgBox.setIcon(QMessageBox::Critical); | 
 
 
 
 
 | 53 | msgBox.setText(message); | 
 
 
 
 
 | 54 | msgBox.exec(); | 
 
 
 
 
 | 55 | } | 
 
 
 
 
 | 56 |  | 
 
 
 
 
 | 57 | //Same of above but allow open log file (doesn't write in log file!!) | 
 
 
 
 
 | 58 | void showErrorPopUpLogButton(const QString &message){ | 
 
 
 
 
 | 59 | QMessageBox msgBox; | 
 
 
 
 
 | 60 | msgBox.setIcon(QMessageBox::Critical); | 
 
 
 
 
 | 61 | msgBox.setText(message); | 
 
 
 
 
 | 62 | QPushButton *viewb = msgBox.addButton("View log", QMessageBox::ActionRole); | 
 
 
 
 
 | 63 | msgBox.setStandardButtons(QMessageBox::Close); | 
 
 
 
 
 | 64 | msgBox.exec(); | 
 
 
 
 
 | 65 | if(msgBox.clickedButton() == (QAbstractButton*)(viewb)){ | 
 
 
 
 
 | 66 | openLogFile(); | 
 
 
 
 
 | 67 | } | 
 
 
 
 
 | 68 | } | 
 
 
 
 
 | 69 |  | 
 
 
 
 
 | 70 | //Same of above but also writtes directly to the log file the error | 
 
 
 
 
 | 71 | void showAndLogErrorPopUpLogButton(const QString &message){ | 
 
 
 
 
 | 72 |  | 
 
 
 
 
 | 73 | LOG_ERROR << message; | 
 
 
 
 
 | 74 |  | 
 
 
 
 
 | 75 | QMessageBox msgBox; | 
 
 
 
 
 | 76 | msgBox.setIcon(QMessageBox::Critical); | 
 
 
 
 
 | 77 | msgBox.setText(message); | 
 
 
 
 
 | 78 | QPushButton *viewb = msgBox.addButton("View log", QMessageBox::ActionRole); | 
 
 
 
 
 | 79 | msgBox.setStandardButtons(QMessageBox::Close); | 
 
 
 
 
 | 80 | msgBox.exec(); | 
 
 
 
 
 | 81 | if(msgBox.clickedButton() == (QAbstractButton*)(viewb)){ | 
 
 
 
 
 | 82 | openLogFile(); | 
 
 
 
 
 | 83 | } | 
 
 
 
 
 | 84 | } | 
 
 
 
 
 | 85 |  | 
 
 
 
 
 | 86 | /** | 
 
 
 
 
 | 87 | Gets application directory. In mac os gets the .app directory | 
 
 
 
 
 | 88 | **/ | 
 
 
 
 
 | 89 | QString getOSIndependentAppPath(){ | 
 
 
 
 
 | 90 | #ifdef Q_OS_MAC | 
 
 
 
 
 | 91 | QDir dir = QDir(QCoreApplication::applicationDirPath()); | 
 
 
 
 
 | 92 | if(dir.absolutePath().contains(".app")){ // include bundle, but we don't want it | 
 
 
 
 
 | 93 | dir.cdUp(); | 
 
 
 
 
 | 94 | dir.cdUp(); | 
 
 
 
 
 | 95 | dir.cdUp(); | 
 
 
 
 
 | 96 | } | 
 
 
 
 
 | 97 | return dir.absolutePath(); | 
 
 
 
 
 | 98 | #else | 
 
 
 
 
 | 99 | return  QDir::currentPath(); | 
 
 
 
 
 | 100 | #endif | 
 
 
 
 
 | 101 | } | 
 
 
 
 
 | 102 |  | 
 
 
 
 
 | 103 | QString getAppPath(){ | 
 
 
 
 
 | 104 | return getOSIndependentAppPath(); | 
 
 
 
 
 | 105 | } | 
 
 
 
 
 | 106 |  | 
 
 
 
 
 | 107 | // Absolute paths | 
 
 
 
 
 | 108 | QString getOniSplitExecutableAbsolutePath(){ | 
 
 
 
 
 | 109 | return getAppPath() + "/" + GlobalVars::ToolsFolder + "/" + GlobalVars::OniSplitString; | 
 
 
 
 
 | 110 | } | 
 
 
 
 
 | 111 |  | 
 
 
 
 
 | 112 | QString getXmlToolsExecutableAbsolutePath(){ | 
 
 
 
 
 | 113 | return getAppPath() + "/" + GlobalVars::ToolsFolder + "/" + GlobalVars::XmlToolsString; | 
 
 
 
 
 | 114 | } | 
 
 
 
 
 | 115 |  | 
 
 
 
 
 | 116 | // Executables (includes mono if necessary) | 
 
 
 
 
 | 117 | QString getOniSplitExecutable(){ | 
 
 
 
 
 | 118 |  | 
 
 
 
 
 | 119 | #ifdef Q_OS_MAC | 
 
 
 
 
 | 120 | return getMonoExecutablePath() + " " + Util::String::insertQuotes(getOniSplitExecutableAbsolutePath()); | 
 
 
 
 
 | 121 | #else | 
 
 
 
 
 | 122 | return Util::String::insertQuotes(getOniSplitExecutableAbsolutePath()); | 
 
 
 
 
 | 123 | #endif | 
 
 
 
 
 | 124 | } | 
 
 
 
 
 | 125 |  | 
 
 
 
 
 | 126 | QString getXmlToolsExecutable(){ | 
 
 
 
 
 | 127 | return Util::String::insertQuotes(getXmlToolsExecutableAbsolutePath()); | 
 
 
 
 
 | 128 | } | 
 
 
 
 
 | 129 |  | 
 
 
 
 
 | 130 | #ifdef Q_OS_MAC | 
 
 
 
 
 | 131 | QString getMonoExecutablePath(){ | 
 
 
 
 
 | 132 |  | 
 
 
 
 
 | 133 | // Only way that I found to get mono working in 10.11 | 
 
 
 
 
 | 134 | QString possibleMonoDir = "/usr/local/bin/mono"; | 
 
 
 
 
 | 135 | QFileInfo checkFile(possibleMonoDir); | 
 
 
 
 
 | 136 |  | 
 
 
 
 
 | 137 | if (checkFile.exists() && checkFile.isFile()) { | 
 
 
 
 
 | 138 | return possibleMonoDir; | 
 
 
 
 
 | 139 | } else { | 
 
 
 
 
 | 140 | return "mono"; | 
 
 
 
 
 | 141 | } | 
 
 
 
 
 | 142 |  | 
 
 
 
 
 | 143 | } | 
 
 
 
 
 | 144 | #endif | 
 
 
 
 
 | 145 |  | 
 
 
 
 
 | 146 | QString getDateTimeFormatForFilename(const QDateTime ¤tDateTime){ | 
 
 
 
 
 | 147 | return currentDateTime.toString("yyyy-MM-dd_hh-mm-ss"); | 
 
 
 
 
 | 148 | } | 
 
 
 
 
 | 149 |  | 
 
 
 
 
 | 150 | } |