File: main.cpp

package info (click to toggle)
algobox 1.0.3+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,380 kB
  • sloc: cpp: 13,758; makefile: 13; xml: 8; sh: 5
file content (119 lines) | stat: -rw-r--r-- 3,723 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/***************************************************************************
  *   copyright       : (C) 2009-2019 by Pascal Brachet                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <QApplication>
#include <QTranslator>
#include <QFontDatabase>
#include <QDebug>
#include <QNetworkProxyFactory>
#include <qtwebenginewidgetsglobal.h>


#include "algobox.h"

#define STRINGIFY_INTERNAL(x) #x
#define STRINGIFY(x) STRINGIFY_INTERNAL(x)

#define VERSION_STR STRINGIFY(ALGOBOXVERSION)

char** appendCommandLineArguments(int argc, char **argv, const QStringList& args)
{
  size_t newSize = (argc + args.length() + 1) * sizeof(char*);
  char** newArgv = (char**)calloc(1, newSize);
  memcpy(newArgv, argv, (size_t)(argc * sizeof(char*)));

  int pos = argc;
  for(const QString& str : args)
    newArgv[pos++] = qstrdup(str.toUtf8().data());

  return newArgv;
}

class AlgoBoxApp : public QApplication
{
private:
    MainWindow *mw;
protected:
    bool event(QEvent *event);
public:
    AlgoBoxApp( int & argc, char ** argv );
    ~AlgoBoxApp();
};

AlgoBoxApp::AlgoBoxApp( int & argc, char ** argv ) : QApplication ( argc, argv )
{
QTranslator* basicTranslator=new QTranslator(this);
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
#ifdef USB_VERSION
QString transdir=QCoreApplication::applicationDirPath()+"/ressources";
#else
QString transdir=PREFIX"/share/algobox";
#endif
#endif
#if defined(Q_OS_MAC)
QString transdir=QCoreApplication::applicationDirPath() + "/../Resources";
#endif
#if defined(Q_OS_WIN32)
QString transdir=QCoreApplication::applicationDirPath()+"/ressources";
#endif
if (basicTranslator->load(QString("qt_fr"),transdir)) installTranslator(basicTranslator);
QFontDatabase::applicationFontFamilies(QFontDatabase::addApplicationFont(":/documents/LiberationMono-Regular.ttf"));
mw=new MainWindow();
mw->show();

for ( int i = 1; i < argc; ++i )
	{
	QString arg = argv[ i ];
	if ( arg[0] != '-' )    mw->OuvrirNouvelAlgo( arg );
	}
}

AlgoBoxApp::~AlgoBoxApp()
{
    delete mw;
}

bool AlgoBoxApp::event ( QEvent * event )
{
    if (event->type() == QEvent::FileOpen) {
        QFileOpenEvent *oe = static_cast<QFileOpenEvent *>(event);
        mw->OuvrirNouvelAlgo(oe->file());
    }
    return QApplication::event(event);
}

int main(int argc, char *argv[])
{
QStringList rawargs;
for ( int i = 0; i < argc; ++i )
	{
	rawargs.append( argv[ i ]);
	}
for (QStringList::Iterator it = ++(rawargs.begin()); it != rawargs.end(); it++)
    {
    if ( ( *it == "-dpiscale") && (++it != rawargs.end())) {qputenv("QT_SCALE_FACTOR", (*it).toUtf8());}
    }
QStringList g_qtFlags = {"--disable-gpu","--proxy-bypass-list","--no-proxy-server"};
char **newArgv = appendCommandLineArguments(argc, argv, g_qtFlags);
int newArgc = argc + g_qtFlags.size();
#if !defined(Q_OS_MAC)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QNetworkProxyFactory::setUseSystemConfiguration(false);
AlgoBoxApp a( newArgc, newArgv);
a.setApplicationName("Algobox");
a.setApplicationVersion(VERSION_STR);
a.setOrganizationName("xm1");
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
#endif
return a.exec();
}