• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revisionccd9ffcc6021ef09866f1237d1781bb0ffe329da (tree)
Time2018-05-10 23:15:18
AuthorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[Qt][COMMAND_LINE] Add --opengl , --envvar and --dump-envvar .

Change Summary

Incremental Difference

--- a/source/src/qt/common/qt_utils.cpp
+++ b/source/src/qt/common/qt_utils.cpp
@@ -17,6 +17,7 @@
1717 #include <QDateTime>
1818 #include <QDir>
1919 #include <QTranslator>
20+#include <QProcessEnvironment>
2021
2122 #include "common.h"
2223 #include "fileio.h"
@@ -608,8 +609,13 @@ QCommandLineOption *_opt_homedir;
608609 QCommandLineOption *_opt_cfgfile;
609610 QCommandLineOption *_opt_cfgdir;
610611 QCommandLineOption *_opt_resdir;
612+QCommandLineOption *_opt_opengl;
613+QCommandLineOption *_opt_envver;
614+QCommandLineOption *_opt_dump_envver;
611615 QCommandLineOption *_opt_dipsw_on;
612616 QCommandLineOption *_opt_dipsw_off;
617+QProcessEnvironment _envvers;
618+bool _b_dump_envver;
613619 std::string config_fullpath;
614620
615621 void SetFDOptions(QCommandLineParser *cmdparser)
@@ -910,6 +916,25 @@ void SetOptions(QCommandLineParser *cmdparser)
910916 _cl.append("dipsw-off");
911917 _opt_dipsw_off = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Turn off <offbit> of dip switch."), "offbit");
912918 _cl.clear();
919+
920+ _cl.append("g");
921+ _cl.append("gl");
922+ _cl.append("opengl");
923+ _cl.append("render");
924+ _opt_opengl = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Force set using renderer type."), "{ GL | GL2 | GLES}");
925+ _cl.clear();
926+
927+ _cl.append("v");
928+ _cl.append("env");
929+ _cl.append("envver");
930+ _opt_envver = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Set / Delete environment variable."), "{NAME[=VAL] | -NAME}");
931+ _cl.clear();
932+
933+ _cl.append("dump-env");
934+ _cl.append("dump-envver");
935+ _opt_dump_envver = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Dump environment variables."), "");
936+ _cl.clear();
937+
913938 for(int i = 0; i < 8; i++) {
914939 _opt_fds[i] = NULL;
915940 _opt_qds[i] = NULL;
@@ -923,12 +948,14 @@ void SetOptions(QCommandLineParser *cmdparser)
923948 _opt_cds[i] = NULL;
924949 }
925950
951+ cmdparser->addOption(*_opt_opengl);
926952 cmdparser->addOption(*_opt_homedir);
927953 cmdparser->addOption(*_opt_cfgfile);
928954 cmdparser->addOption(*_opt_cfgdir);
929955 cmdparser->addOption(*_opt_resdir);
930956 cmdparser->addOption(*_opt_dipsw_on);
931957 cmdparser->addOption(*_opt_dipsw_off);
958+
932959 SetFDOptions(cmdparser);
933960 //SetBinaryOptions(cmdparser); // Temporally disabled.
934961 SetCmtOptions(cmdparser);
@@ -938,6 +965,8 @@ void SetOptions(QCommandLineParser *cmdparser)
938965 SetLDOptions(cmdparser); // Temporally disabled.
939966 SetCDOptions(cmdparser);
940967
968+ cmdparser->addOption(*_opt_envver);
969+ cmdparser->addOption(*_opt_dump_envver);
941970 }
942971
943972 void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
@@ -959,7 +988,6 @@ void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
959988 SetProcCmdLD(cmdparser, _l);
960989 SetProcCmdCD(cmdparser, _l);
961990
962-
963991 memset(homedir, 0x00, PATH_MAX);
964992 if(cmdparser->isSet(*_opt_homedir)) {
965993 strncpy(homedir, cmdparser->value(*_opt_homedir).toLocal8Bit().constData(), PATH_MAX - 1);
@@ -1016,7 +1044,84 @@ void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
10161044 sRssDir.append(delim);
10171045 }
10181046 }
1019-
1047+ if(cmdparser->isSet(*_opt_opengl)) {
1048+ char tmps[128] = {0};
1049+ strncpy(tmps, cmdparser->value(*_opt_opengl).toLocal8Bit().constData(), 128 - 1);
1050+ if(strlen(tmps) > 0) {
1051+ QString render = QString::fromLocal8Bit(tmps).toUpper();
1052+ if((render == QString::fromUtf8("GL2")) ||
1053+ (render == QString::fromUtf8("GLV2"))) {
1054+ config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
1055+ config.render_major_version = 2;
1056+ config.render_minor_version = 0;
1057+ GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
1058+ GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
1059+ } else if((render == QString::fromUtf8("GL3")) ||
1060+ (render == QString::fromUtf8("GLV3")) ||
1061+ (render == QString::fromUtf8("OPENGLV3")) ||
1062+ (render == QString::fromUtf8("OPENGL")) ||
1063+ (render == QString::fromUtf8("GL"))) {
1064+ config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
1065+ config.render_major_version = 3;
1066+ config.render_minor_version = 0;
1067+ GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
1068+ GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
1069+ } else if((render == QString::fromUtf8("GLES2")) ||
1070+ (render == QString::fromUtf8("GLESV2")) ||
1071+ (render == QString::fromUtf8("GLES3")) ||
1072+ (render == QString::fromUtf8("GLESV3")) ||
1073+ (render == QString::fromUtf8("GLES"))) {
1074+ config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_ES;
1075+ config.render_major_version = 2;
1076+ config.render_minor_version = 1;
1077+ GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, false);
1078+ GuiMain->setAttribute(Qt::AA_UseOpenGLES, true);
1079+ }
1080+ }
1081+ }
1082+ if(cmdparser->isSet(*_opt_envver)) {
1083+ QStringList nList = cmdparser->values(*_opt_envver);
1084+ QString tv;
1085+ //QProcessEnvironment ev = QProcessEnvironment::systemEnvironment();
1086+ QProcessEnvironment ev = _envvers;
1087+ if(nList.size() > 0) {
1088+ for(int i = 0; i < nList.size(); i++) {
1089+ tv = nList.at(i);
1090+ if(tv.indexOf(QString::fromUtf8("-")) == 0) {
1091+ // Delete var
1092+ int n1 = tv.indexOf(QString::fromUtf8("="));
1093+ if(n1 > 0) {
1094+ tv = tv.left(n1).right(n1 - 1);
1095+ } else {
1096+ tv = tv.right(tv.length() - 1);
1097+ }
1098+ printf("DEBUG: DEL ENV:%s\n", tv.toLocal8Bit().constData());
1099+ ev.remove(tv);
1100+ } else if(tv.indexOf(QString::fromUtf8("=")) > 0) {
1101+ // Delete var
1102+ int n1 = tv.indexOf(QString::fromUtf8("="));
1103+ QString skey;
1104+ QString sval;
1105+ skey = tv.left(n1);
1106+ if((tv.length() - n1) < 1) {
1107+ sval = QString::fromUtf8("");
1108+ } else {
1109+ sval = tv.right(tv.length() - n1 - 1);
1110+ }
1111+ printf("DEBUG: SET ENV:%s to %s\n", skey.toLocal8Bit().constData(), sval.toLocal8Bit().constData());
1112+ if(skey.length() > 0) ev.insert(skey, sval);
1113+ } else if(tv.indexOf(QString::fromUtf8("=")) < 0) {
1114+ printf("DEBUG: SET ENV:%s to (NULL)\n", tv.toLocal8Bit().constData());
1115+ if(tv.length() > 0) ev.insert(tv, QString::fromUtf8(""));
1116+ }
1117+ }
1118+ _envvers.swap(ev);
1119+ }
1120+ }
1121+ _b_dump_envver = false;
1122+ if(cmdparser->isSet(*_opt_dump_envver)) {
1123+ _b_dump_envver = true;
1124+ }
10201125 uint32_t dipsw_onbits = 0x0000000;
10211126 uint32_t dipsw_offmask = 0xffffffff;
10221127 if(cmdparser->isSet(*_opt_dipsw_off)) {
@@ -1082,6 +1187,28 @@ void OpeningMessage(std::string archstr)
10821187
10831188 void SetupSDL(void)
10841189 {
1190+ QStringList _el = _envvers.toStringList();
1191+ if(_el.size() > 0) {
1192+ for(int i = 0; i < _el.size(); i++) {
1193+ QString _s = _el.at(i);
1194+ if(_s.startsWith("SDL_")) {
1195+ QString skey, svar;
1196+ int _nl;
1197+ _nl = _s.indexOf('=');
1198+ if(_nl >= 0) {
1199+ skey = _s.left(_nl);
1200+ svar = _s.right(_s.length() - _nl);
1201+ } else {
1202+ skey = _s;
1203+ svar = QString::fromUtf8("");
1204+ }
1205+ SDL_setenv(skey.toLocal8Bit().constData(), svar.toLocal8Bit().constData(), 1);
1206+ csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Note: SDL ENVIROMENT : %s to %s.",
1207+ skey.toLocal8Bit().constData(),
1208+ svar.toLocal8Bit().constData());
1209+ }
1210+ }
1211+ }
10851212 #if defined(USE_SDL2)
10861213 SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
10871214 #else
@@ -1092,6 +1219,7 @@ void SetupSDL(void)
10921219
10931220 void SetupLogger(std::string emustr, int _size)
10941221 {
1222+
10951223 csp_logger = new CSP_Logger(config.log_to_syslog, config.log_to_console, emustr.c_str()); // Write to syslog, console
10961224 csp_logger->set_log_stdout(CSP_LOG_DEBUG, true);
10971225 csp_logger->set_log_stdout(CSP_LOG_INFO, true);
@@ -1113,7 +1241,7 @@ int MainLoop(int argc, char *argv[])
11131241 std::string cfgstr(CONFIG_NAME);
11141242 std::string delim;
11151243 QString emudesc;
1116-
1244+
11171245 setup_logs();
11181246 #if defined(Q_OS_WIN)
11191247 delim = "\\";
@@ -1123,6 +1251,7 @@ int MainLoop(int argc, char *argv[])
11231251
11241252 GuiMain = new QApplication(argc, argv);
11251253 GuiMain->setObjectName(QString::fromUtf8("Gui_Main"));
1254+ _envvers = QProcessEnvironment::systemEnvironment();
11261255
11271256 QCommandLineParser cmdparser;
11281257
@@ -1136,6 +1265,7 @@ int MainLoop(int argc, char *argv[])
11361265 emustr = emustr + cfgstr;
11371266
11381267 SetupLogger(emustr, CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1);
1268+
11391269
11401270 archstr = "Generic";
11411271 #if defined(__x86_64__)
@@ -1170,6 +1300,18 @@ int MainLoop(int argc, char *argv[])
11701300 if(debugger_translator.load(s_locale, QLatin1String("csp_qt_debugger"), QLatin1String("_"), QLatin1String(":/"))) {
11711301 GuiMain->installTranslator(&debugger_translator);
11721302 }
1303+ //QProcessEnvironment::systemEnvironment() = _envvers;
1304+ if(_b_dump_envver) {
1305+ //QProcessEnvironment ev = QProcessEnvironment::systemEnvironment();
1306+ QProcessEnvironment ev = _envvers;
1307+ QStringList el = _envvers.toStringList();
1308+ if(el.size() > 0) {
1309+ csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Environment Variables:");
1310+ for(int i = 0; i < el.size(); i++) {
1311+ csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "#%d : %s", i, el.at(i).toLocal8Bit().constData());
1312+ }
1313+ }
1314+ }
11731315
11741316 rMainWindow = new META_MainWindow(using_flags, csp_logger);
11751317 rMainWindow->connect(rMainWindow, SIGNAL(sig_quit_all(void)), rMainWindow, SLOT(deleteLater(void)));
Show on old repository browser