Code cleanup for main.cpp files

Remove ancient OS detection code, unneeded includes and ugly workarounds.
This commit is contained in:
Felix Kauselmann 2018-02-12 22:30:19 +01:00
parent 601e70fc85
commit f9ed9b19b5
3 changed files with 38 additions and 129 deletions

View File

@ -1,15 +1,7 @@
#include <QApplication>
#include <QPixmap>
#include <QLabel>
//#include <QMetaObject>
#include <QPushButton>
#include <QMainWindow>
#include <QtCore>
#include <QThread>
#include <QFile>
#include <QDataStream>
#include <QDir>
#include <QTranslator>
#include <QSysInfo>
#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 <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#define new DEBUG_NEW
#endif
#if defined(WIN32) && defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#define new DEBUG_NEW
#endif
#ifdef Q_OS_MAC
#include <QEvent>
#include <QFileOpenEvent>
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;
}

View File

@ -7,10 +7,9 @@
#include <QDir>
#include <QSysInfo>
#include <QFileInfo>
#include <QSettings>
#include <QLibrary>
#include <QMessageBox>
#include <QTextStream>
#ifndef use_unarr
#include <QLibrary>
#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"));
}

View File

@ -1,4 +1,7 @@
#include <QtCore>
//#include <QtCore>
#include <QCoreApplication>
#include <QSysInfo>
#include <QDir>
#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())