From f9ed9b19b546a7302d37b90411ea83468a91ec52 Mon Sep 17 00:00:00 2001 From: Felix Kauselmann <2039670+selmf@users.noreply.github.com> Date: Mon, 12 Feb 2018 22:30:19 +0100 Subject: [PATCH] Code cleanup for main.cpp files Remove ancient OS detection code, unneeded includes and ugly workarounds. --- YACReader/main.cpp | 56 +++++------------- YACReaderLibrary/main.cpp | 102 ++++++-------------------------- YACReaderLibraryServer/main.cpp | 9 ++- 3 files changed, 38 insertions(+), 129 deletions(-) diff --git a/YACReader/main.cpp b/YACReader/main.cpp index ebe4312f..0c7b3c1c 100644 --- a/YACReader/main.cpp +++ b/YACReader/main.cpp @@ -1,15 +1,7 @@ #include -#include -#include -//#include -#include -#include -#include -#include -#include -#include +#include #include -#include + #include "main_window_viewer.h" #include "configuration.h" #include "exit_check.h" @@ -19,16 +11,17 @@ using namespace QsLogging; - #if defined(WIN32) && defined(_DEBUG) - #define _CRTDBG_MAP_ALLOC - #include - #include - #define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ ) - #define new DEBUG_NEW - #endif +#if defined(WIN32) && defined(_DEBUG) + #define _CRTDBG_MAP_ALLOC + #include + #include + #define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ ) + #define new DEBUG_NEW +#endif #ifdef Q_OS_MAC #include +#include class YACReaderApplication: public QApplication { public: @@ -64,23 +57,14 @@ int main(int argc, char * argv[]) _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif -//fix for misplaced text in Qt4.8 and Mavericks #ifdef Q_OS_MAC - #if QT_VERSION < 0x050000 - if(QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) - QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); - #endif -#endif - - -#ifdef Q_OS_MAC - YACReaderApplication app(argc,argv); + YACReaderApplication app(argc,argv); #else QApplication app(argc, argv); #endif #ifdef FORCE_ANGLE - app.setAttribute(Qt::AA_UseOpenGLES); + app.setAttribute(Qt::AA_UseOpenGLES); #endif app.setApplicationName("YACReader"); @@ -126,7 +110,7 @@ int main(int argc, char * argv[]) QDir().mkpath(YACReader::getSettingsPath()); Logger& logger = Logger::instance(); - logger.setLoggingLevel(QsLogging::InfoLevel); + logger.setLoggingLevel(QsLogging::InfoLevel); DestinationPtr fileDestination(DestinationFactory::MakeFileDestination( destLog, EnableLogRotation, MaxSizeBytes(1048576), MaxOldLogCount(2))); @@ -165,22 +149,10 @@ int main(int argc, char * argv[]) app.setWindow(mwv); #endif mwv->show(); - int ret = app.exec(); - - delete mwv; + delete mwv; //Configuration::getConfiguration().save(); - YACReader::exitCheck(ret); - -#ifdef Q_OS_MAC - // ugly workaround to avoid crash when app exit on MacOS Sierra due to Qt's QColorDialog bug. - // cf. https://bugreports.qt.io/browse/QTBUG-56448 - QColorDialog colorDlg(0); - colorDlg.setOption(QColorDialog::NoButtons); - colorDlg.setCurrentColor(Qt::white); -#endif - return ret; } diff --git a/YACReaderLibrary/main.cpp b/YACReaderLibrary/main.cpp index 9e78a797..e333fb75 100644 --- a/YACReaderLibrary/main.cpp +++ b/YACReaderLibrary/main.cpp @@ -7,10 +7,9 @@ #include #include #include -#include -#include -#include -#include +#ifndef use_unarr + #include +#endif #include "yacreader_global.h" #include "startup.h" @@ -33,80 +32,25 @@ using namespace QsLogging; void logSystemAndConfig() { - QLOG_INFO() << "---------- System & configuration ----------"; -#if defined(Q_OS_WIN) - switch (QSysInfo::windowsVersion()) - { - case QSysInfo::WV_NT: - QLOG_INFO() << "SO : Windows NT"; - break; - case QSysInfo::WV_2000: - QLOG_INFO() << "SO : Windows 2000"; - break; - case QSysInfo::WV_XP: - QLOG_INFO() << "SO : Windows XP"; - break; - case QSysInfo::WV_2003: - QLOG_INFO() << "SO : Windows 2003"; - break; - case QSysInfo::WV_VISTA: - QLOG_INFO() << "SO : Windows Vista"; - break; - case QSysInfo::WV_WINDOWS7: - QLOG_INFO() << "SO : Windows 7"; - break; - case QSysInfo::WV_WINDOWS8: - QLOG_INFO() << "SO : Windows 8"; - break; - default: - QLOG_INFO() << "Windows (unknown version)"; - break; - } - -#elif defined(Q_OS_MAC) - - switch (QSysInfo::MacVersion()) - { - case QSysInfo::MV_SNOWLEOPARD: - QLOG_INFO() << "SO : MacOSX Snow Leopard"; - break; - case QSysInfo::MV_LION: - QLOG_INFO() << "SO : MacOSX Lion"; - break; - case QSysInfo::MV_MOUNTAINLION: - QLOG_INFO() << "SO : MacOSX Mountain Lion"; - break; -#if QT_VERSION >= 0x050000 - case QSysInfo::MV_MAVERICKS: - QLOG_INFO() << "SO : MacOSX Maverics"; - break; -#endif - default: - QLOG_INFO() << "SO : MacOSX (unknown version)"; - break; - } - -#elif defined(Q_OS_LINUX) - QLOG_INFO() << "SO : Linux (unknown version)"; - -#else - QLOG_INFO() << "SO : Unknown"; -#endif + QLOG_INFO() << "---------- System & configuration ----------"; + QLOG_INFO() << "OS:" << QSysInfo::prettyProductName() << "Version: " << QSysInfo::productVersion(); + QLOG_INFO() << "Kernel:" << QSysInfo::kernelType() << QSysInfo::kernelVersion() << "Architecture:" << QSysInfo::currentCpuArchitecture(); #ifndef use_unarr -#ifdef Q_OS_WIN + #ifdef Q_OS_WIN if(QLibrary::isLibrary(QApplication::applicationDirPath()+"/utils/7z.dll")) -#elif defined Q_OS_UNIX && !defined Q_OS_MAC + #elif defined Q_OS_UNIX && !defined Q_OS_MAC if(QLibrary::isLibrary(QString(LIBDIR)+"/yacreader/7z.so") | QLibrary::isLibrary(QString(LIBDIR)+"/p7zip/7z.so")) -#else + #else if(QLibrary::isLibrary(QApplication::applicationDirPath()+"/utils/7z.so")) -#endif - QLOG_INFO() << "7z : found"; + #endif + QLOG_INFO() << "7z : found"; else - QLOG_ERROR() << "7z : not found"; -#else + QLOG_ERROR() << "7z : not found"; +#else // use_unarr QLOG_INFO() << "using unarr decompression backend"; -#endif +#endif // use_unarr + #if defined Q_OS_UNIX && !defined Q_OS_MAC if(QFileInfo(QString(BINDIR)+"/qrencode").exists()) #else @@ -131,33 +75,23 @@ void logSystemAndConfig() OpenGLChecker checker; QLOG_INFO() << "OpenGL version : " << checker.textVersionDescription(); - QLOG_INFO() << "Libraries: " << DBHelper::getLibraries().getLibraries(); + QLOG_INFO() << "Libraries: " << DBHelper::getLibraries().getLibraries(); QLOG_INFO() << "--------------------------------------------"; } int main( int argc, char ** argv ) { - -//fix for misplaced text in Qt4.8 and Mavericks -#ifdef Q_OS_MAC - #if QT_VERSION < 0x050000 - if(QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) - QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); - #endif - -#endif - QApplication app( argc, argv ); #ifdef FORCE_ANGLE - app.setAttribute(Qt::AA_UseOpenGLES); + app.setAttribute(Qt::AA_UseOpenGLES); #endif app.setApplicationName("YACReaderLibrary"); app.setOrganizationName("YACReader"); app.setApplicationVersion(VERSION); - app.setAttribute(Qt::AA_UseHighDpiPixmaps); + if (QIcon::hasThemeIcon("YACReaderLibrary")) { app.setWindowIcon(QIcon::fromTheme("YACReaderLibrary")); } diff --git a/YACReaderLibraryServer/main.cpp b/YACReaderLibraryServer/main.cpp index 8b11c1bb..76bcffde 100644 --- a/YACReaderLibraryServer/main.cpp +++ b/YACReaderLibraryServer/main.cpp @@ -1,4 +1,7 @@ -#include +//#include +#include +#include +#include #include "comic_db.h" #include "db_helper.h" @@ -17,8 +20,8 @@ using namespace QsLogging; void logSystemAndConfig() { QLOG_INFO() << "---------- System & configuration ----------"; - QLOG_INFO() << "OS: " + QSysInfo::prettyProductName() + ", Version: " + QSysInfo::productVersion(); - QLOG_INFO() << "Kernel: " + QSysInfo::kernelType() + " " + QSysInfo::kernelVersion() + " Architecture: " + QSysInfo::currentCpuArchitecture(); + QLOG_INFO() << "OS:" << QSysInfo::prettyProductName() << "Version: " << QSysInfo::productVersion(); + QLOG_INFO() << "Kernel:" << QSysInfo::kernelType() << QSysInfo::kernelVersion() << "Architecture:" << QSysInfo::currentCpuArchitecture(); /* TODO: qrencode could be helpfull for showing a qr code in the web client for client devices #if defined Q_OS_UNIX && !defined Q_OS_MAC if(QFileInfo(QString(BINDIR)+"/qrencode").exists())