10 |
|
return path.remove(0,path.lastIndexOf('/')).remove('"'); |
11 |
|
} |
12 |
|
|
13 |
< |
QString insertQuotes(QString path){ |
14 |
< |
return "\""+path+"\""; |
13 |
> |
QString cutNameWithoutBackSlash(QString path){ |
14 |
> |
return cutName(path).remove('/'); |
15 |
> |
} |
16 |
> |
|
17 |
> |
QString insertQuotes(const QString &currString){ |
18 |
> |
return "\""+currString+"\""; |
19 |
|
} |
20 |
|
|
21 |
|
QString normalizeAndQuote(QString path){ |
22 |
|
return insertQuotes(normalizePath(path)); |
23 |
|
} |
24 |
|
|
25 |
< |
void showPopUp(QString message){ |
25 |
> |
void showPopUp(const QString &message){ |
26 |
|
QMessageBox msgBox; |
27 |
|
msgBox.setIcon(QMessageBox::Information); |
28 |
|
msgBox.setText(message); |
29 |
|
msgBox.exec(); |
30 |
|
} |
31 |
|
|
32 |
< |
void showRichPopUp(QString message){ |
32 |
> |
void showRichPopUp(const QString &message){ |
33 |
|
QMessageBox msgBox; |
34 |
|
msgBox.setTextFormat(Qt::RichText); |
35 |
|
msgBox.setIcon(QMessageBox::Information); |
37 |
|
msgBox.exec(); |
38 |
|
} |
39 |
|
|
40 |
< |
void showWarningPopUp(QString message){ |
40 |
> |
void showWarningPopUp(const QString &message){ |
41 |
|
QMessageBox msgBox; |
42 |
|
msgBox.setIcon(QMessageBox::Warning); |
43 |
|
msgBox.setText(message); |
44 |
|
msgBox.exec(); |
45 |
|
} |
46 |
|
|
47 |
< |
void showErrorPopUp(QString message){ |
47 |
> |
void showErrorPopUp(const QString &message){ |
48 |
|
QMessageBox msgBox; |
49 |
|
msgBox.setIcon(QMessageBox::Critical); |
50 |
|
msgBox.setText(message); |
51 |
|
msgBox.exec(); |
52 |
|
} |
53 |
|
|
54 |
< |
//Same of above but allow open log file (doesn't right in log file!!) |
51 |
< |
void showErrorLogPopUp(QString message){ |
52 |
< |
QMessageBox msgBox; |
53 |
< |
msgBox.setIcon(QMessageBox::Critical); |
54 |
< |
msgBox.setText(message); |
55 |
< |
QPushButton *viewb = msgBox.addButton("View log", QMessageBox::ActionRole); |
56 |
< |
msgBox.setStandardButtons(QMessageBox::Close); |
57 |
< |
msgBox.exec(); |
58 |
< |
if(msgBox.clickedButton() == (QAbstractButton*) viewb){ |
59 |
< |
openLogFile(); |
60 |
< |
} |
61 |
< |
} |
62 |
< |
|
63 |
< |
void showRichErrorPopUp(QString message){ |
54 |
> |
void showRichErrorPopUp(const QString &message){ |
55 |
|
QMessageBox msgBox; |
56 |
|
msgBox.setIcon(QMessageBox::Critical); |
57 |
|
msgBox.setText(message); |
130 |
|
return isDouble; |
131 |
|
} |
132 |
|
|
133 |
< |
// from here: https://gzeki.com/blog/view/Recursive_copy_files_from_one_directory_to_another_in_C++_(Qt_5) |
134 |
< |
bool copyDir(QString from_dir, QString to_dir, bool replace_on_conflit) |
135 |
< |
{ |
136 |
< |
QDir dir; |
146 |
< |
dir.setPath(from_dir); |
133 |
> |
// Created from scratch |
134 |
> |
bool copyDir(const QString &fromPath, QString toPath, const bool isRecursive){ |
135 |
> |
QDir fromDir(fromPath); |
136 |
> |
QDir toDir(toPath); |
137 |
|
|
138 |
< |
from_dir += QDir::separator(); |
139 |
< |
to_dir += QDir::separator(); |
138 |
> |
if(!toDir.mkdir(fromDir.dirName())){ // create the folder in the destination |
139 |
> |
return false; |
140 |
> |
} |
141 |
|
|
142 |
< |
foreach (QString copy_file, dir.entryList(QDir::Files)) |
143 |
< |
{ |
144 |
< |
QString from = from_dir + copy_file; |
154 |
< |
QString to = to_dir + copy_file; |
155 |
< |
|
156 |
< |
if (QFile::exists(to)) |
157 |
< |
{ |
158 |
< |
if (replace_on_conflit) |
159 |
< |
{ |
160 |
< |
if (QFile::remove(to) == false) |
161 |
< |
{ |
162 |
< |
return false; |
163 |
< |
} |
164 |
< |
} |
165 |
< |
else |
166 |
< |
{ |
167 |
< |
continue; |
168 |
< |
} |
169 |
< |
} |
142 |
> |
// Update toPath to include the folder from "fromPath" |
143 |
> |
toPath = toPath + "/" + fromDir.dirName(); |
144 |
> |
toDir = QDir(toPath); |
145 |
|
|
146 |
< |
if (QFile::copy(from, to) == false) |
172 |
< |
{ |
173 |
< |
return false; |
174 |
< |
} |
175 |
< |
} |
146 |
> |
for(const QFileInfo &currFileInfo : fromDir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)){ |
147 |
|
|
148 |
< |
foreach (QString copy_dir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) |
149 |
< |
{ |
150 |
< |
QString from = from_dir + copy_dir; |
151 |
< |
QString to = to_dir + copy_dir; |
152 |
< |
|
153 |
< |
if (dir.mkpath(to) == false) |
154 |
< |
{ |
184 |
< |
return false; |
148 |
> |
if(currFileInfo.isFile()){ |
149 |
> |
|
150 |
> |
QFile destFile(toPath + "/" + currFileInfo.fileName()); |
151 |
> |
|
152 |
> |
if(!QFile::copy(currFileInfo.absoluteFilePath(),toPath + "/" + currFileInfo.fileName())){ |
153 |
> |
return false; |
154 |
> |
} |
155 |
|
} |
156 |
+ |
else if(isRecursive && currFileInfo.isDir() && currFileInfo.absoluteFilePath() != fromDir.absolutePath()){ |
157 |
|
|
158 |
< |
if (copyDir(from, to, replace_on_conflit) == false) |
159 |
< |
{ |
160 |
< |
return false; |
158 |
> |
if(!copyDir(currFileInfo.absoluteFilePath(), toPath, isRecursive)){ |
159 |
> |
return false; |
160 |
> |
} |
161 |
|
} |
162 |
|
} |
163 |
|
|
192 |
|
return str; |
193 |
|
} |
194 |
|
|
224 |
– |
void openLogFile(){ |
225 |
– |
QDesktopServices::openUrl(QUrl("file:///"+Util::getAppPath()+"/"+GlobalVars::AppLogName)); |
226 |
– |
} |
227 |
– |
|
195 |
|
//Searches for the QString "toSearch" in the "myString" variable backward |
196 |
|
//Returns the index of the first match or -1 if not found |
197 |
|
int indexOfBackward(QString myString, QString toSearch, int from){ |
243 |
|
return widget.availableGeometry(widget.primaryScreen()); // or screenGeometry(), depending on your needs |
244 |
|
} |
245 |
|
|
279 |
– |
/** |
280 |
– |
Gets application directory. In mac os gets the .app directory |
281 |
– |
**/ |
282 |
– |
QString getOSIndependentAppPath(){ |
283 |
– |
#ifdef Q_OS_MAC |
284 |
– |
QDir dir = QDir(QCoreApplication::applicationDirPath()); |
285 |
– |
if(dir.absolutePath().contains(".app")){ // include bundle, but we don't want it |
286 |
– |
dir.cdUp(); |
287 |
– |
dir.cdUp(); |
288 |
– |
dir.cdUp(); |
289 |
– |
} |
290 |
– |
return dir.absolutePath(); |
291 |
– |
#else |
292 |
– |
return QDir::currentPath(); |
293 |
– |
#endif |
294 |
– |
} |
295 |
– |
|
296 |
– |
QString getAppPath(){ |
297 |
– |
return getOSIndependentAppPath(); |
298 |
– |
} |
299 |
– |
|
300 |
– |
QString getOniSplitExeName(){ |
301 |
– |
|
302 |
– |
#ifdef Q_OS_MAC |
303 |
– |
return getMonoExecutablePath() + " " + GlobalVars::OniSplitString; |
304 |
– |
#elif |
305 |
– |
return GlobalVars::OniSplitString; |
306 |
– |
#endif |
307 |
– |
} |
308 |
– |
|
309 |
– |
QString getXmlToolsExeName(){ |
310 |
– |
|
311 |
– |
#ifdef Q_OS_MAC |
312 |
– |
return getMonoExecutablePath() + " " + GlobalVars::XmlToolsString; |
313 |
– |
#elif |
314 |
– |
return GlobalVars::XmlToolsString; |
315 |
– |
#endif |
316 |
– |
} |
317 |
– |
|
318 |
– |
#ifdef Q_OS_MAC |
319 |
– |
QString getMonoExecutablePath(){ |
320 |
– |
|
321 |
– |
// Only way that I found to get mono working in 10.11 |
322 |
– |
QString possibleMonoDir = "/usr/local/bin/mono"; |
323 |
– |
QFileInfo checkFile(possibleMonoDir); |
324 |
– |
|
325 |
– |
if (checkFile.exists() && checkFile.isFile()) { |
326 |
– |
return possibleMonoDir; |
327 |
– |
} else { |
328 |
– |
return "mono"; |
329 |
– |
} |
330 |
– |
|
331 |
– |
} |
332 |
– |
#endif |
333 |
– |
|
246 |
|
} |