QtLingo 1
QtLingo is an Application to make Qt Computer Translations easier
MyOrgSettings.cpp
Go to the documentation of this file.
1
8#include "MyOrgSettings.h"
9
13MyOrgSettings::MyOrgSettings(QObject *parent) : QObject(parent)
14{
15 // Fixed random number, change it before using it, then leave it,
16 // all data stored with this key will only work with this key.
17 // Defined in MyOrgSettings.h
19 // Trigger for Update
20 connect(this, &MyOrgSettings::sendUpdateSettings, this, &MyOrgSettings::onUpdateSettings);
21
22 // Run after GUI loads
23 QTimer::singleShot(200, this, &MyOrgSettings::onRunOnStartup);
24}
25
30{
31
32}
33
38{
39 if (isDebugMessage)
40 {
41 setMessage("on Run On Start up", "onRunOnStartup", Debug);
42 // FIXME move to test project
43 QString theTest = "This is my Secret";
44 if (theTest != decryptThis(encryptThis(theTest)))
45 { setMessage(QObject::tr("Crypto Fail").toLocal8Bit(), tr("Crypto Fail: MyOrgSettings::onRunOnStartup()").toLocal8Bit(), Critical); }
46 }
47}
48
52void MyOrgSettings::onUpdateSettings()
53{
54 mySettings = getSettings();
55}
56
61{
62 return mySettings;
63}
64
69{
70 setMessage("get Settings", "getSettings", Debug);
72 {
73 if (!isFileMake(getAppDataLocation(), QString("%1.%2").arg(getIniFileName(), getIniFileExtension())))
74 {
75 setMessage("get Settings", QString("%1: %2").arg(QObject::tr("Failed to make File in getSettings"), getIniFullPath()), Critical);
76 }
77 }
78 return new QSettings(getIniFullPath(), QSettings::IniFormat);
79} // end qSettingsInstance
80
84bool MyOrgSettings::isSetting(const QString &thisFieldName)
85{
86 setMessage("is Setting", QString("isSetting(%1)").arg(thisFieldName), Debug);
87 return mySettings->contains(thisFieldName);
88} // end isSetting
89
93QString MyOrgSettings::readSettings(const QString &thisSetting, const QString &thisDefault)
94{
95 setMessage("read Settings", QString("readSettings(%1, %2)").arg(thisSetting, thisDefault), Debug);
96 mySettings->beginGroup("General");
97 QString theSetting = mySettings->value(thisSetting, thisDefault).toString();
98 mySettings->endGroup();
99 return theSetting;
100}
101
105QString MyOrgSettings::readSettings(const QString &thisSetting)
106{
107 setMessage("read Settings", QString("readSettings(%1)").arg(thisSetting), Debug);
108 mySettings->beginGroup("General");
109 QString theSetting = mySettings->value(thisSetting).toString();
110 mySettings->endGroup();
111 return theSetting;
112}
113
117bool MyOrgSettings::readSettingsBool(const QString &thisSetting, bool thisDefault)
118{
119 setMessage("read Settings Bool", QString("readSettingsBool(%1, %2)").arg(thisSetting, thisDefault), Debug);
120 mySettings->beginGroup("General");
121 bool theSetting = mySettings->value(thisSetting, thisDefault).toBool();
122 mySettings->endGroup();
123 return theSetting;
124}
125
129int MyOrgSettings::readSettingsInt(const QString &thisSetting, int thisDefault)
130{
131 setMessage("read Settings Int", QString("readSettingsInt(%1, %2)").arg(thisSetting, thisDefault), Debug);
132 mySettings->beginGroup("General");
133 int theSetting = mySettings->value(thisSetting, thisDefault).toInt();
134 mySettings->endGroup();
135 return theSetting;
136}
137
141void MyOrgSettings::writeSettings(const QString &thisSetting, const QString &thisValue)
142{
143 setMessage("write Settings", QString("writeSettings(%1, %2)").arg(thisSetting, thisValue), Debug);
144 mySettings->beginGroup("General");
145 mySettings->setValue(thisSetting, thisValue);
146 mySettings->endGroup();
147}
148
153QString MyOrgSettings::getDataPath(const QString &thisFileName)
154{
155 setMessage("get Data Path", QString("getDataPath(%1)").arg(thisFileName), Debug);
156 //
157 QDir settingsPath;
158 // FIXME this is where the exe is
159 QString myDataPath = QString("%1%2%3").arg(settingsPath.currentPath(), QDir::separator(), thisFileName);
160 setMessage("", "getDataPath = " + myDataPath, Debug);
161 return myDataPath;
162}
163
168{
169 if (myLastApplicationFolder.isEmpty())
170 {
171 //
172 QString theProjectPath = QCoreApplication::applicationFilePath();
173 if (!isPathExists(theProjectPath))
174 {
175 setMessage("get Last Application Path", QString("%1 getLastApplicationPath(%2) - %3").arg(tr("getLastApplicationPath not found"), myLastApplicationFolder, theProjectPath), Warning);
176 theProjectPath = QDir::currentPath();
177 }
179 }
180 setMessage("get Last Application Path", QString("getLastApplicationPath(%1)").arg(myLastApplicationFolder), Debug);
181 return myLastApplicationFolder;
182}
183
187void MyOrgSettings::setLastApplicationPath(const QString &thisPath)
188{
189 setMessage("set Last Application Path", QString("setLastApplicationPath(%1)").arg(thisPath), Debug);
190 myLastApplicationFolder = thisPath;
192}
193
198{
199 if (myOrganizationName.isEmpty()) { setOrgName(qApp->organizationName()); }
200 setMessage("get Org Name", QString("getOrgName(%1)").arg(myOrganizationName), Debug);
201 return myOrganizationName;
202} // end getOrgName
203
207void MyOrgSettings::setOrgName(const QString &thisOrgName)
208{
209 setMessage("set Org Name", QString("setOrgName(%1)").arg(thisOrgName), Debug);
210 if (QString::compare(myOrganizationName, thisOrgName, Qt::CaseInsensitive))
211 {
212 myOrganizationName = thisOrgName;
213 emit sendUpdateSettings();
214 }
215} // end setOrgName
216
221{
222 if (myOrganizationDomain.isEmpty()) { setOrgDomain(qApp->organizationDomain()); }
223 setMessage("get Org Domain", QString("getOrgDomain(%1)").arg(myOrganizationDomain), Debug);
224 return myOrganizationDomain;
225} // end getOrgDomain
226
230void MyOrgSettings::setOrgDomain(const QString &thisOrgDomain)
231{
232 setMessage("set Org Domain", QString("setOrgDomain(%1)").arg(thisOrgDomain), Debug);
233 if (QString::compare(myOrganizationDomain, thisOrgDomain, Qt::CaseInsensitive))
234 {
235 myOrganizationDomain = thisOrgDomain;
236 emit sendUpdateSettings();
237 }
238} // end setOrgDomain
239
244{
245 if (myApplicationName.isEmpty()) { setAppName(qApp->applicationName()); }
246 setMessage("get App Name", QString("getAppName(%1)").arg(myApplicationName), Debug);
247 return myApplicationName;
248} // end getAppName
249
253void MyOrgSettings::setAppName(const QString &thisAppName)
254{
255 setMessage("set App Name", QString("setAppName(%1)").arg(thisAppName), Debug);
256 if (QString::compare(myApplicationName, thisAppName, Qt::CaseInsensitive))
257 {
258 myApplicationName = thisAppName;
259 emit sendUpdateSettings();
260 }
261} // end setAppName
262
267{
268 setMessage("get Version", QString("getVersion(%1)").arg(myVersion), Debug);
269 return myVersion;
270}
271
276void MyOrgSettings::setVersion(const QString &thisVersion)
277{
278 setMessage("set Version", QString("setVersion(%1)").arg(thisVersion), Debug);
279 if (QString::compare(myVersion, thisVersion, Qt::CaseInsensitive))
280 {
281 myVersion = thisVersion;
282 emit sendUpdateSettings();
283 }
284}
285
290{
291 setMessage("get CheckInternetUrl", QString("getCheckInternetUrl(%1)").arg(myCheckInternetUrl), Debug);
292 if (myCheckInternetUrl.isEmpty())
294 return myCheckInternetUrl;
295}
296
301void MyOrgSettings::setCheckInternetUrl(const QString &thisCheckInternetUrl)
302{
303 setMessage("set CheckInternetUrl", QString("setCheckInternetUrl(%1)").arg(thisCheckInternetUrl), Debug);
304 if (QString::compare(myCheckInternetUrl, thisCheckInternetUrl, Qt::CaseInsensitive))
305 {
306 myCheckInternetUrl = thisCheckInternetUrl;
307 emit sendUpdateSettings();
308 }
309}
310
315{
316 if (myIniFileName.isEmpty())
318 setMessage("get Ini File", QString("getIniFile(%1)").arg(myIniFileName), Debug);
319 return myIniFileName;
320}
321
325void MyOrgSettings::setIniFileName(const QString &thisIniFileName)
326{
327 setMessage("set Ini File", QString("setIniFile(%1)").arg(thisIniFileName), Debug);
328 if (QString::compare(myIniFileName, thisIniFileName, Qt::CaseInsensitive))
329 {
330 myIniFileName = thisIniFileName;
331 emit sendUpdateSettings();
332 }
333}
334
339{
340 setMessage("get Ini File", QString("getIniFile(%1)").arg(myIniFileName), Debug);
341 if (myIniFileExtension.isEmpty())
343 return myIniFileExtension;
344}
345
349void MyOrgSettings::setIniFileExtension(const QString &thisIniFileNameExtension)
350{
351 setMessage("set Ini File", QString("setIniFile(%1)").arg(thisIniFileNameExtension), Debug);
352 if (QString::compare(myIniFileExtension, thisIniFileNameExtension, Qt::CaseInsensitive))
353 {
354 myIniFileExtension = thisIniFileNameExtension;
355 emit sendUpdateSettings();
356 }
357}
358
363{
364 setMessage("get Ini Full Path", "getIniFullPath", Debug);
365 if (myIniFullPath.isEmpty())
366 {
367 // organizationName, organizationDomain, applicationName and applicationName
368 // are set in main.cpp, and passed into Constuctor, so they are set
369 QCoreApplication::setOrganizationName(getOrgName());
370 QCoreApplication::setOrganizationDomain(getOrgDomain());
371 QCoreApplication::setApplicationName(getAppName());
372 //QCoreApplication::setApplicationDisplayName(getAppName());
373 // see *.pro file where it is: DEFINES *= APP_VERSION=$${VERSION}
374 // cmake does not have this yet, this is a hack till I FIXME
375 QCoreApplication::setApplicationVersion(getVersion());
376 setIniFullPath(QString("%1%2%3.%4").arg(getAppDataLocation(), QDir::separator(), getIniFileName(), getIniFileExtension()));
377 }
378 return myIniFullPath;
379}
380
384void MyOrgSettings::setIniFullPath(const QString &thisIniFileName)
385{
386 setMessage("set Ini Full Path", QString("%1(%2)").arg("setIniFullPath", thisIniFileName), Debug);
387 if (QString::compare(myIniFullPath, thisIniFileName, Qt::CaseInsensitive))
388 {
389 myIniFullPath = thisIniFileName;
390 emit sendUpdateSettings();
391 }
392}
393
397void MyOrgSettings::setGeometry(QByteArray thisGeometry)
398{
399 setMessage("set Geometry", "setGeometry", Debug);
400 mySettings->beginGroup("Geometry");
401 mySettings->setValue(MY_GEOMETRY, thisGeometry);
402 mySettings->endGroup();
403} // end setGeometry
404
409{
410 setMessage("get Geometry", "getGeometry", Debug);
411 // Geometry
412 mySettings->beginGroup("Geometry");
413 myGeometry = mySettings->value(MY_GEOMETRY).toByteArray();
414 mySettings->endGroup();
415 return myGeometry;
416} // end getGeometry
417
421void MyOrgSettings::setWindowState(QByteArray thisWindowState)
422{
423 setMessage("set Window State", "setWindowState", Debug);
424 mySettings->beginGroup("Geometry");
425 mySettings->setValue(MY_WINDOW_STATES, thisWindowState);
426 mySettings->endGroup();
427}
428
433{
434 setMessage("get Window State", "getWindowState", Debug);
435 // Window State
436 mySettings->beginGroup("Geometry");
437 myWindowState = mySettings->value(MY_WINDOW_STATES).toByteArray();
438 mySettings->endGroup();
439 return myWindowState;
440}
441
445QString MyOrgSettings::readFile(const QString &thisFileName)
446{
447 setMessage("read File", QString("readFile(%1)").arg(thisFileName), Debug);
448 QFile file(thisFileName);
449 if(!file.open(QFile::ReadOnly | QFile::Text))
450 {
451 setMessage(QObject::tr("Error opening file for reading").toLocal8Bit(), QString("%1: %2").arg(QObject::tr("Could not open file for reading"), thisFileName).toLocal8Bit(), Critical);
452 return "";
453 }
454 QTextStream in(&file);
455 QString thisText = in.readAll();
456 file.close();
457 return thisText;
458}
459
465bool MyOrgSettings::writeFile(const QString &thisFileName, const QString &thisContent)
466{
467 setMessage("write File", QString("writeFile(%1)").arg(thisFileName), Debug);
468 QFile theFile(thisFileName);
469 // Trying to open in WriteOnly and Text mode and Truncate file if contents exists
470 if(!theFile.open(QFile::WriteOnly | QFile::Text | QIODevice::Truncate))
471 {
472 setMessage(QObject::tr("Error opening file for writing").toLocal8Bit(), QString("%1: %2").arg(QObject::tr("Could not open file for writing"), thisFileName).toLocal8Bit(), Critical);
473 return false;
474 }
475 // Write to file
476 QTextStream theFileStream(&theFile);
477 theFileStream << thisContent;
478 theFile.flush();
479 theFile.close();
480 return true;
481} // end writeFile
482
486QString MyOrgSettings::encryptThis(const QString &thisSecret)
487{
488 setMessage("encrypt This", "encryptThis", Debug);
489 return myCrypto->encryptToString(thisSecret);
490}
491
495QString MyOrgSettings::decryptThis(const QString &thisSecret)
496{
497 setMessage("decryp tThis", "decryptThis", Debug);
498 return myCrypto->decryptToString(thisSecret);
499}
500
504QString MyOrgSettings::getFileInfo(MyOrgSettings::MyFileinfo thisInfo, const QString &thisFileFolder)
505{
506 setMessage("get File Info", QString("getFileInfo(%1)").arg(thisFileFolder), Debug);
507 if (thisFileFolder.isEmpty()) { return ""; }
508 //
509 QFileInfo theFileInfo(thisFileFolder);
510 //
511 switch (thisInfo)
512 {
513 case AbsoluteFilePath:
514 // The absolute path name consists of the full path and the file name.
515 return theFileInfo.absoluteFilePath();
516 case AbsolutePath:
517 // Returns a file's path absolute path. This doesn't include the file name..
518 return theFileInfo.absolutePath();
519 case BaseName:
520 // Returns the base name of the file without the path.
521 return theFileInfo.baseName();
522 case BirthTime:
523 // Returns the date and time when the file was created / born.
524 return theFileInfo.birthTime().toString();
525 case CanonicalPath:
526 // Returns the file's path canonical path (excluding the file name), i.e. an absolute path without symbolic links or redundant "." or ".." elements.
527 return theFileInfo.canonicalPath();
529 // Returns the canonical path including the file name, i.e. an absolute path without symbolic links or redundant "." or ".." elements.
530 return theFileInfo.canonicalFilePath();
531 case CompleteBaseName:
532 // Returns the complete base name of the file without the path.
533 // "/tmp/archive.tar.gz" == "archive.tar"
534 return theFileInfo.completeBaseName();
535 case CompleteSuffix:
536 // Returns the complete suffix (extension) of the file.
537 // "/tmp/archive.tar.gz" == "tar.gz"
538 return theFileInfo.completeSuffix();
539 case Directory:
540 // Returns the path of the object's parent directory as a QDir object.
541 return theFileInfo.dir().currentPath();
542 case FileName:
543 // Returns the name of the file, excluding the path. getFileInfo(FileName, "")
544 return theFileInfo.fileName();
545 case FilePath:
546 // Returns the file name, including the path (which may be absolute or relative).
547 return theFileInfo.filePath();
548 case IsWritable:
549 // Returns true if the user can write to the file; otherwise returns false.
550 if (theFileInfo.isWritable()) return "true"; else return "false";
551 case FileSize:
552 return QString::number(theFileInfo.size());
553 case IsFile:
554 if (isFileExists(thisFileFolder)) return "true"; else return "false";
555 case IsFolder:
556 if (isPathExists(thisFileFolder)) return "true"; else return "false";
557 case IsSymLink:
558 if (theFileInfo.isSymLink()) return "true"; else return "false";
559 case SymLinkTarget:
560 if (theFileInfo.isSymLink()) return theFileInfo.symLinkTarget(); else return "";
561 }
562 return "";
563}
564
568bool MyOrgSettings::isAppDataLocationGood(const QString &thisFolder)
569{
570 setMessage("is App Data Location Good", QString("isAppDataLocationGood(%1)").arg(thisFolder), Debug);
571 bool isGood = true;
572 if (isFileMake(thisFolder, "ReadMe.txt"))
573 {
574 if (getFileInfo(IsWritable, combinePathFileName(thisFolder, "ReadMe.txt")) == "false")
575 { isGood = false; }
576 }
577 else
578 { isGood = false; }
579 if (getFileInfo(IsFolder, thisFolder) == "false")
580 { isGood = false; }
581 return isGood;
582} // end isAppDataLocationGood
583
588{
589 if (myAppDataLocation.isEmpty())
590 {
591 QString theAppDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
592 if (theAppDataLocation.isEmpty())
593 {
594 theAppDataLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
595 if (theAppDataLocation.isEmpty())
596 { theAppDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); }
597 if (theAppDataLocation.isEmpty())
598 { theAppDataLocation = QDir::currentPath(); }
599 }
600 if (!isAppDataLocationGood(theAppDataLocation))
601 {
602 theAppDataLocation = QDir::currentPath(); // FIXME
603 }
604 setAppDataLocation(theAppDataLocation);
605 }
606 setMessage("get App Data Location", QString("getAppDataLocation(%1)").arg(myAppDataLocation), Debug);
607 return myAppDataLocation;
608} // end getAppDataLocation
609
613void MyOrgSettings::setAppDataLocation(const QString &thisAppDataLocation)
614{
615 if (QString::compare(myAppDataLocation, thisAppDataLocation, Qt::CaseInsensitive))
616 {
617 myAppDataLocation = thisAppDataLocation;
618 emit sendUpdateSettings();
619 }
620} // end setAppDataLocation
621
634QString MyOrgSettings::getEnvironmentVar(const QString &thisVar, const QString &thisDefault)
635{
636 setMessage("get Environment Var", QString("getEnvironmentVar(%1)").arg(thisVar), Debug);
637 QString theEnvValue = qEnvironmentVariable(thisVar.toLocal8Bit());
638 if (!theEnvValue.isNull())
639 { return theEnvValue; }
640 else
641 { return thisDefault; }
642}
643
647bool MyOrgSettings::isWord(const QString &thisString) const
648{
649 setMessage("is Word", QString("isWord(%1)").arg(thisString), Debug);
650 for(int i = 0; i < thisString.length(); i++)
651 {
652 if (thisString.at(i).isLetter())
653 { return true; }
654 }
655 return false;
656}
657
661void MyOrgSettings::delay(int thisSeconds)
662{
663 setMessage("idelay", QString("delay(%1)").arg(thisSeconds), Debug);
664 QEventLoop theDelayLoop;
665 QTimer::singleShot(thisSeconds * 1000, &theDelayLoop, &QEventLoop::quit);
666 theDelayLoop.exec();
667} // end delay
668
673//#define MY_INTERNET_CHECK_PING
674#ifdef MY_INTERNET_CHECK_PING
676{
677 setMessage("ping Internet", "pingInternet", Debug);
678 QStringList parameters;
679#if defined(WIN32)
680 parameters << "-n" << "1";
681#else
682 parameters << "-c 1";
683#endif
684 parameters << getCheckInternetUrl();
685 int exitCode = QProcess::execute("ping", parameters);
686 if (exitCode==0)
687 { return true; }
688 else
689 { return false; }
690} // end delay
691#else
692
697{
698 setMessage("connect Internet", "connectInternet", Debug);
699 bool isInternetAvailable = false;
700 QNetworkAccessManager *theNetworkManager = new QNetworkAccessManager;
701 QEventLoop theEventLoop;
702 QObject::connect(theNetworkManager, &QNetworkAccessManager::finished, &theEventLoop, &QEventLoop::quit);
703 QNetworkReply *reply = theNetworkManager->get(QNetworkRequest(QUrl(getCheckInternetUrl())));
704 theEventLoop.exec();
705 if (reply->bytesAvailable())
706 { isInternetAvailable = true; }
707 else
708 { isInternetAvailable = false; }
709 delete reply;
710 delete theNetworkManager;
711 return isInternetAvailable;
712} // end delay
713#endif
714
719{
720 setMessage("get Internet Wait", "getInternetWait", Debug);
721#ifdef MY_INTERNET_CHECK_PING
722 if (pingInternet()) { return true; }
723#else
724 if (connectInternet()) { return true; }
725#endif
726
727 bool isNotConnected = true;
728 while (isNotConnected)
729 {
730 delay(30);
731#ifdef MY_INTERNET_CHECK_PING
732 isNotConnected = pingInternet();
733#else
734 isNotConnected = connectInternet();
735#endif
737 }
738 return true;
739} // end delay
740
744int MyOrgSettings::fileNumberLines(const QString &thisFile)
745{
746 setMessage("file Number Lines", QString("fileNumberLines(%1)").arg(thisFile), Debug);
747 if (!isFileExists(thisFile)) { setMessage(QObject::tr("File not found").toLocal8Bit(), QString("%1: %2").arg(QObject::tr("File not found"), thisFile).toLocal8Bit(), Critical); return 0; }
748 std::ifstream inFile(thisFile.toLocal8Bit());
749 return std::count(std::istreambuf_iterator<char>(inFile), std::istreambuf_iterator<char>(), '\n');
750} // end fileNumberLines
751
755bool MyOrgSettings::removeAllFiles(const QString &thisFolder)
756{
757 setMessage("remove All Files", QString("removeAllFiles(%1)").arg(thisFolder), Debug);
758 if (!isPathExists(thisFolder)) { setMessage(QObject::tr("Folder not found").toLocal8Bit(), QString("%1: %2").arg(QObject::tr("Folder not found"), thisFolder).toLocal8Bit(), Critical); return false; }
759 QDir theDirFiles(thisFolder);
760 theDirFiles.setNameFilters(QStringList() << "*.*");
761 theDirFiles.setFilter(QDir::Files);
762 foreach(QString theDirFile, theDirFiles.entryList())
763 {
764 if (!theDirFiles.remove(theDirFile))
765 {
766 setMessage(QObject::tr("Files could not be removed").toLocal8Bit(), QString("%1: %2").arg(QObject::tr("Files could not be removed"), thisFolder).toLocal8Bit(), Critical);
767 return false;
768 }
769 }
770 return true;
771} // end removeAllFiles
772
776QString MyOrgSettings::combinePathFileName(const QString &thisPath,const QString &thisFileName)
777{
778 setMessage("combine Path File Name", QString("combinePathFileName(%1, %2)").arg(thisPath, thisFileName), Debug);
779 return QString("%1%2%3").arg(thisPath, QDir::separator(), thisFileName);
780} // end combinePathFileName
781
785bool MyOrgSettings::isPathExists(const QString &thisPath)
786{
787 setMessage("is Path Exists", QString("isPathExists(%1)").arg(thisPath), Debug);
788 return QDir(thisPath).exists() && QFileInfo(thisPath).isDir();
789} // end isPathExists
790
794bool MyOrgSettings::isFileExists(const QString &thisFile)
795{
796 setMessage("is File Exists", QString("isFileExists(%1)").arg(thisFile), Debug);
797 // check if file exists and if yes: Is it really a file and not directory?
798 return QFileInfo::exists(thisFile) && QFileInfo(thisFile).isFile();
799} // end isFileExists
800
804bool MyOrgSettings::removeFile(const QString &thisFile)
805{
806 setMessage("remove File", QString("removeFile(%1)").arg(thisFile), Debug);
807 if (isFileExists(thisFile))
808 { return QFile::remove(thisFile); }
809 return true;
810}
811
815bool MyOrgSettings::isFileMake(const QString &thisPath, const QString &thisFileName)
816{
817 setMessage("is File Make", QString("isFileMake(%1, %2)").arg(thisPath, thisFileName), Debug);
818 isCreated = false;
819 QString thePath = combinePathFileName(thisPath, thisFileName);
820 if (!isMakeDir(thisPath)) return false;
821 if (!isFileExists(thePath))
822 {
823 QFile theFile(thePath);
824 if (theFile.open(QIODevice::WriteOnly))
825 {
826 /* Point a QTextStream object at the file */
827 QTextStream outStream(&theFile);
828 /* Write the line to the file */
829 outStream << QString("%1 %2").arg(QObject::tr("This file was created to test if this folder is writeable by"), QCoreApplication::applicationName()).toLocal8Bit();
830 /* Close the file */
831 theFile.close();
832 if (isFileExists(thePath)) { isCreated = true; }
833 return isCreated;
834 }
835 else return false;
836 }
837 return true;
838} // end isFileMake
839
843bool MyOrgSettings::isMakeDir(const QString &thisPath)
844{
845 setMessage("is Make Dir", QString("isMakeDir(%1)").arg(thisPath), Debug);
846 QDir dir(thisPath);
847 if (!dir.exists())
848 {
849 if (!dir.mkpath("."))
850 { setMessage(QObject::tr("File System Error").toLocal8Bit(), QString("%1 %2").arg(tr("Error: cannot create file"), thisPath).toLocal8Bit(), Critical); }
851 else return true;
852 }
853 return isPathExists(thisPath);
854} // end isMakeDir
855
860{
861 isDebugMessage = thisState;
862 setMessage("set Debug Message", QString("setDebugMessage(%1)").arg(thisState), Debug);
863}
864
869{
870 setMessage("get Debug Message", QString("getDebugMessage(%1)").arg(isDebugMessage), Debug);
871 return isDebugMessage;
872}
873
877bool MyOrgSettings::questionYesNo(const char *thisTitle, const char *thisQuestion) const
878{
879 if (setMessage(thisTitle, thisQuestion, MyMessageTypes::Question) == "true")
880 { return true; }
881 else
882 { return false; }
883} // end questionYesNo
884
891QVariant MyOrgSettings::showMessageBox(const QString &thisTitle, const QString &thisMessage, MyMessageTypes thisMessageType) const
892{
893 return setMessage(thisTitle, thisMessage, thisMessageType);
894} // end showMessageBox
895
899QVariant MyOrgSettings::setMessage(const QString &thisTitle, const QString &thisMessage, MyMessageTypes thisMessageType) const
900{
901 switch (thisMessageType)
902 {
903 case Debug:
904 {
905#ifdef MY_QML
906#ifdef DEBUG
907 // FIXME
908 if (isDebugMessage)
909 {
910#ifdef QT_DEBUG
911 qDebug() << thisMessage;
912#else
913 std::cout << thisMessage.toStdString() << std::endl;
914#endif
915 }
916#else
917 if (isDebugMessage)
918 { std::cout << thisMessage.toStdString() << std::endl; }
919#endif
920 return "";
921#else
922 if (isDebugMessage)
923 {
924#ifdef QT_DEBUG
925 qDebug() << thisMessage;
926#else
927 std::cout << thisMessage.toStdString() << std::endl;
928#endif
929 }
930 return "";
931#endif
932 }
933 case Information:
934 {
935#ifdef MY_QML
936#ifdef QT_DEBUG
937 // FIXME
938 qInfo() << thisMessage;
939#else
940 std::cout << thisMessage.toStdString() << std::endl;
941#endif
942 return "";
943#else
944 return QMessageBox::information(nullptr, thisTitle, thisMessage, QMessageBox::Ok);
945#endif
946 }
947 case Question:
948 {
949#ifdef MY_QML
950 // FIXME
951#ifdef QT_DEBUG
952 qDebug() << thisMessage;
953#else
954 std::cout << thisMessage.toStdString() << std::endl;
955#endif
956 return "";
957#else
958 QMessageBox theMsgBox;
959 theMsgBox.setWindowTitle(QObject::tr(thisTitle.toLocal8Bit()));
960 theMsgBox.setText(QObject::tr(thisMessage.toLocal8Bit()));
961 theMsgBox.setStandardButtons(QMessageBox::Yes);
962 theMsgBox.addButton(QMessageBox::No);
963 theMsgBox.setDefaultButton(QMessageBox::No);
964 if(theMsgBox.exec() == QMessageBox::Yes)
965 {
966 setMessage("", QObject::tr("Yes was clicked"), Debug);
967 return true;
968 }
969 else
970 {
971 setMessage("", QObject::tr("Yes was not clicked"), Debug);
972 return false;
973 }
974
975#endif
976 }
977 case Warning:
978 {
979#ifdef MY_QML
980#ifdef QT_DEBUG
981 // FIXME
982 qWarning() << thisMessage;
983#else
984 std::cout << thisMessage.toStdString() << std::endl;
985#endif
986 return "";
987#else
988 return QMessageBox::warning(nullptr, thisTitle, thisMessage, QMessageBox::Ok);
989#endif
990 }
991 case Critical:
992 {
993#ifdef MY_QML
994#ifdef QT_DEBUG
995 // FIXME
996 qCritical() << thisMessage;
997#else
998 std::cout << thisMessage.toStdString() << std::endl;
999#endif
1000 return "";
1001#else
1002 return QMessageBox::critical(nullptr, thisTitle, thisMessage, QMessageBox::Ok);
1003#endif
1004 }
1005 } // end switch (thisMessageType)
1006 return QVariant();
1007} // end setMessage
1008
#define MY_CRYPTO_SEED
MY_CRYPTO_SEED
Definition: MyOrgSettings.h:28
QSettings * getSettings()
get Settings
void setLastApplicationPath(const QString &thisPath)
set Last Application Path
const QString MY_INTERNET_URL
MY_INTERNET_URL
Definition: MyOrgSettings.h:87
QString getLastApplicationPath()
get Last Application Path
QString combinePathFileName(const QString &thisPath, const QString &thisFileName)
combine Path File Name
bool isFileExists(const QString &thisFile)
File Functions.
bool connectInternet()
connect Internet
bool removeFile(const QString &thisFile)
remove File
MyMessageTypes
Message Types.
Definition: MyOrgSettings.h:71
@ Information
Information
Definition: MyOrgSettings.h:72
@ Critical
Critical
Definition: MyOrgSettings.h:75
@ Question
Question
Definition: MyOrgSettings.h:73
@ Warning
Warning
Definition: MyOrgSettings.h:74
void setOrgDomain(const QString &thisOrgDomain)
set Org Domain. setOrgDomain
const QString MY_INI_EXTENSION
MY_INI_EXTENSION
Definition: MyOrgSettings.h:85
const QString MY_WINDOW_STATES
MY_WINDOW_STATES
int readSettingsInt(const QString &thisSetting, int thisDefault)
read Settings Int
bool isAppDataLocationGood(const QString &thisFolder)
is AppData Location Good
~MyOrgSettings()
MyOrgSettings Destructor.
void setOrgName(const QString &thisOrgName)
set Org Name
QString getIniFullPath()
my Application IniFile
QString getAppDataLocation()
get AppData Location
SimpleCrypt * myCrypto
myCrypto
Definition: MyOrgSettings.h:81
void setIniFullPath(const QString &thisIniFileName)
set IniFile
QString getAppName()
my Application Name
void setIniFileName(const QString &thisIniFileName)
set IniFile
bool questionYesNo(const char *thisTitle, const char *thisQuestion) const
question Yes No
void setCheckInternetUrl(const QString &thisCheckInternetUrl)
set Check Internet Url
QString getCheckInternetUrl()
get Check Internet Url
QString getEnvironmentVar(const QString &thisVar, const QString &thisDefault)
get Windows Environment Var
const QString MY_GEOMETRY
ConstSettingsGeometry
QString getVersion()
my Application Version
void setIniFileExtension(const QString &thisIniFileNameExtension)
set Ini File Extension
bool isSetting(const QString &thisFieldName)
is Setting
QString getIniFileExtension()
getIniFileExtension
void setDebugMessage(bool thisState)
set Debug Message
bool isPathExists(const QString &thisPath)
is Path Exists
bool writeFile(const QString &thisFileName, const QString &thisContent)
write File
void sendInternetProgress()
send Internet Progress
bool pingInternet()
ping Internet
QString decryptThis(const QString &thisSecret)
decrypt This
QString getIniFileName()
my Application IniFile
QString encryptThis(const QString &thisSecret)
encrypt This
void delay(int thisSeconds)
delay
QString getFileInfo(MyOrgSettings::MyFileinfo thisInfo, const QString &thisFileFolder)
get File Info
MyOrgSettings(QObject *parent=nullptr)
MyOrgSettings Constructor.
int fileNumberLines(const QString &thisFile)
file Number Lines
QString getOrgDomain()
my Organization Domain
bool isFileMake(const QString &thisPath, const QString &thisFileName)
is File Make
bool isWord(const QString &thisString) const
is Word
QString getDataPath(const QString &thisFileName)
Get Data Path.
QVariant setMessage(const QString &thisTitle, const QString &thisMessage, MyMessageTypes thisMessageType) const
set Message
bool getDebugMessage()
get Debug Message
QByteArray getGeometry()
get Geometry
void sendUpdateSettings()
send Update Settings
QVariant showMessageBox(const QString &thisTitle, const QString &thisMessage, MyMessageTypes thisMessageType) const
show Message Box information, question, warning, critica
void setVersion(const QString &thisVersion)
set Version
const QString MY_LAST_PROJECT_FOLDER
MY_QT_PROJECT_NAME
Definition: MyOrgSettings.h:91
bool removeAllFiles(const QString &thisFolder)
remove All Files
void writeSettings(const QString &thisSetting, const QString &thisValue)
write Settings
void setAppDataLocation(const QString &thisAppDataLocation)
set AppData Location
QString getOrgName()
get Org Name
QString readFile(const QString &thisFileName)
read File
void setWindowState(QByteArray thisWindowState)
get Geometry Min
MyFileinfo
File Information.
Definition: MyOrgSettings.h:45
@ Directory
Directory
Definition: MyOrgSettings.h:54
@ CanonicalFilePath
CanonicalFilePath
Definition: MyOrgSettings.h:51
@ BirthTime
BirthTime
Definition: MyOrgSettings.h:49
@ IsWritable
IsWritable
Definition: MyOrgSettings.h:57
@ FileName
FileName
Definition: MyOrgSettings.h:55
@ BaseName
BaseName
Definition: MyOrgSettings.h:48
@ IsFile
IsFile
Definition: MyOrgSettings.h:58
@ AbsoluteFilePath
CanonicalPath
Definition: MyOrgSettings.h:47
@ SymLinkTarget
SymLinkTarget
Definition: MyOrgSettings.h:62
@ IsSymLink
IsSymLink
Definition: MyOrgSettings.h:61
@ CompleteSuffix
CompleteSuffix
Definition: MyOrgSettings.h:53
@ CanonicalPath
CanonicalPath
Definition: MyOrgSettings.h:50
@ AbsolutePath
AbsolutePath
Definition: MyOrgSettings.h:46
@ IsFolder
IsFolder
Definition: MyOrgSettings.h:59
@ CompleteBaseName
CompleteBaseName
Definition: MyOrgSettings.h:52
@ FileSize
FileSize
Definition: MyOrgSettings.h:60
@ FilePath
FilePath
Definition: MyOrgSettings.h:56
void onRunOnStartup()
Run On Startup.
QString readSettings(const QString &thisSetting, const QString &thisDefault)
read Settings
QSettings * getSetteings()
on Update Settings. onUpdateSettings
void setAppName(const QString &thisAppName)
set AppName
bool readSettingsBool(const QString &thisSetting, bool thisDefault)
read Settings Bool
bool getInternetWait()
get Internet Wait
QByteArray getWindowState()
get Geometry Min
bool isMakeDir(const QString &thisPath)
is Make Dir
void setGeometry(QByteArray thisGeometry)
Screen Geometry.
Simple encryption and decryption of strings and byte arrays.
Definition: SimpleCrypt.h:72
QString decryptToString(const QString &cyphertext)
decrypt To String QString. decryptToString
QString encryptToString(const QString &plaintext)
encrypt To String QString. encryptToString