Commit d681abf9 authored by Alexander A. Maly's avatar Alexander A. Maly

Disabled warnings in pipe mode

Changed non-gui mode determination for all platforms
parent 8eeb0ef6
...@@ -1184,7 +1184,7 @@ class Settings: ...@@ -1184,7 +1184,7 @@ class Settings:
assert isinstance(entry, SettingsEntry) assert isinstance(entry, SettingsEntry)
result += entry.get_entry_cpp_implementation("entries") result += entry.get_entry_cpp_implementation("entries")
result += """ result += """
bool guiAvailable = true; bool guiAvailable = (qobject_cast<QApplication*>(qApp) != 0);
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
guiAvailable = 0 != getenv("DISPLAY"); guiAvailable = 0 != getenv("DISPLAY");
#endif #endif
...@@ -2703,7 +2703,8 @@ class ModuleBaseCppClass(CppClassBase): ...@@ -2703,7 +2703,8 @@ class ModuleBaseCppClass(CppClassBase):
%s::%s(ExtensionSystem::KPlugin* parent) %s::%s(ExtensionSystem::KPlugin* parent)
: QObject(parent) : QObject(parent)
{ {
bool hasGui = true; //bool hasGui = true;
bool hasGui = (qobject_cast<QApplication*>(qApp) != 0);
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
hasGui = getenv("DISPLAY")!=0; hasGui = getenv("DISPLAY")!=0;
#endif #endif
...@@ -2794,7 +2795,8 @@ class ModuleBaseCppClass(CppClassBase): ...@@ -2794,7 +2795,8 @@ class ModuleBaseCppClass(CppClassBase):
return """ return """
/* public */ QList<QMenu*> %s::moduleMenus() const /* public */ QList<QMenu*> %s::moduleMenus() const
{ {
bool hasGui = true; //bool hasGui = true;
bool hasGui = (qobject_cast<QApplication*>(qApp) != 0);
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
hasGui = getenv("DISPLAY")!=0; hasGui = getenv("DISPLAY")!=0;
#endif #endif
...@@ -3366,6 +3368,7 @@ every build time ...@@ -3366,6 +3368,7 @@ every build time
#include "$moduleBaseHeaderFileName" #include "$moduleBaseHeaderFileName"
#include "$moduleHeaderFileName" #include "$moduleHeaderFileName"
#include <kumir2-libs/widgets/declarativesettingspage.h> #include <kumir2-libs/widgets/declarativesettingspage.h>
#include <QApplication>
namespace $namespace { namespace $namespace {
...@@ -3484,6 +3487,7 @@ every build time ...@@ -3484,6 +3487,7 @@ every build time
// Qt includes // Qt includes
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include <QApplication>
namespace $namespace { namespace $namespace {
......
...@@ -279,12 +279,17 @@ QString RobotModule::initialize( ...@@ -279,12 +279,17 @@ QString RobotModule::initialize(
qDebug() << "FIELD: |" << fName << "| "; qDebug() << "FIELD: |" << fName << "| ";
} }
DISPLAY = true; DISPLAY = (qobject_cast<QApplication*>(qApp) != 0);
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QProcessEnvironment pe = QProcessEnvironment::systemEnvironment(); QProcessEnvironment pe = QProcessEnvironment::systemEnvironment();
qDebug() << "Display" << pe.value("DISPLAY"); qDebug() << "Display" << pe.value("DISPLAY");
if (pe.keys().indexOf("DISPLAY") < 0 || pe.value("DISPLAY").isEmpty()) { if (pe.keys().indexOf("DISPLAY") < 0 || pe.value("DISPLAY").isEmpty()) {
DISPLAY = false;
}
#endif
if (!DISPLAY) {
qDebug() << "Robot:Console mode"; qDebug() << "Robot:Console mode";
curConsoleField = new ConsoleField(10, 15); curConsoleField = new ConsoleField(10, 15);
DISPLAY = false; DISPLAY = false;
...@@ -295,7 +300,6 @@ QString RobotModule::initialize( ...@@ -295,7 +300,6 @@ QString RobotModule::initialize(
} }
qDebug() << "Robot:GuiMode"; qDebug() << "Robot:GuiMode";
#endif
if (!configurationParameters.contains("tablesOnly")) { if (!configurationParameters.contains("tablesOnly")) {
createGui(); createGui();
......
...@@ -12,6 +12,16 @@ ...@@ -12,6 +12,16 @@
#include <kumir2-libs/extensionsystem/pluginmanager.h> #include <kumir2-libs/extensionsystem/pluginmanager.h>
#include <kumir2-libs/extensionsystem/logger.h> #include <kumir2-libs/extensionsystem/logger.h>
static bool guiMode = false, pipeMode = false;
static bool versionMode = false, helpMode = false;
#ifdef CONFIGURATION_TEMPLATE
static QByteArray currentTemplate = CONFIGURATION_TEMPLATE;
#else
#error No default configuration passed to GCC
#endif
static QString resolvePath(const char *what) static QString resolvePath(const char *what)
{ {
static QString ExecDir = QString::fromLatin1(KUMIR2_EXEC_DIR); static QString ExecDir = QString::fromLatin1(KUMIR2_EXEC_DIR);
...@@ -29,9 +39,9 @@ static QString resolvePath(const char *what) ...@@ -29,9 +39,9 @@ static QString resolvePath(const char *what)
} }
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
void GuiMessageOutput(QtMsgType type, const char *msg) static void LoggerMessageOutput(QtMsgType type, const char *msg)
#else #else
void GuiMessageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg) static void LoggerMessageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg)
#endif #endif
{ {
ExtensionSystem::Logger *logger = ExtensionSystem::Logger::instance(); ExtensionSystem::Logger *logger = ExtensionSystem::Logger::instance();
...@@ -53,7 +63,11 @@ void GuiMessageOutput(QtMsgType type, const QMessageLogContext &, const QString ...@@ -53,7 +63,11 @@ void GuiMessageOutput(QtMsgType type, const QMessageLogContext &, const QString
} }
} }
void ConsoleMessageOutput(QtMsgType type, const char *msg) #if QT_VERSION < 0x050000
static void ConsoleMessageOutput(QtMsgType type, const char *msg)
#else
static void ConsoleMessageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg)
#endif
{ {
switch (type) { switch (type) {
case QtDebugMsg: case QtDebugMsg:
...@@ -63,31 +77,26 @@ void ConsoleMessageOutput(QtMsgType type, const char *msg) ...@@ -63,31 +77,26 @@ void ConsoleMessageOutput(QtMsgType type, const char *msg)
// fprintf(stderr, "Warning: %s\n", msg); // fprintf(stderr, "Warning: %s\n", msg);
break; break;
case QtCriticalMsg: case QtCriticalMsg:
fprintf(stderr, "Critical: %s\n", msg); fprintf(stderr, "Critical: %s\n", msg.toLocal8Bit().data());
break; break;
case QtFatalMsg: case QtFatalMsg:
fprintf(stderr, "Fatal: %s\n", msg); fprintf(stderr, "Fatal: %s\n", msg.toLocal8Bit().data());
abort(); abort();
default: default:
break; break;
} }
} }
void showErrorMessage(const QString &text) static void showErrorMessage(const QString &text)
{ {
bool gui = true; if (guiMode) {
#ifdef Q_OS_LINUX
gui = gui && getenv("DISPLAY") != 0;
#endif
if (gui) {
QMessageBox::critical(0, "Kumir 2 Launcher", text); QMessageBox::critical(0, "Kumir 2 Launcher", text);
} else { } else {
fprintf(stderr, "%s", qPrintable(text)); fprintf(stderr, "%s\n", qPrintable(text));
} }
} }
QString getLanguage() static QString getLanguage()
{ {
return "ru"; // TODO implement sometime in future... return "ru"; // TODO implement sometime in future...
} }
...@@ -98,7 +107,7 @@ QList<QDir> translationsDirs() ...@@ -98,7 +107,7 @@ QList<QDir> translationsDirs()
QList<QDir> result; QList<QDir> result;
// Translations dir from base distribution // Translations dir from base distribution
const QString sharePath = resolvePath(KUMIR2_RESOURCES_DIR); QString sharePath = resolvePath(KUMIR2_RESOURCES_DIR);
QDir baseTranslationsDir(sharePath + "/translations"); QDir baseTranslationsDir(sharePath + "/translations");
if (baseTranslationsDir.exists()) { if (baseTranslationsDir.exists()) {
result.append(baseTranslationsDir); result.append(baseTranslationsDir);
...@@ -106,8 +115,8 @@ QList<QDir> translationsDirs() ...@@ -106,8 +115,8 @@ QList<QDir> translationsDirs()
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
// Search additional paths // Search additional paths
const QString homePath = QString::fromLocal8Bit(::getenv("HOME")); QString homePath = QString::fromLocal8Bit(::getenv("HOME"));
const QStringList extraPaths = QStringList() QStringList extraPaths = QStringList()
<< "/usr/share/kumir2/translations" << "/usr/share/kumir2/translations"
<< "/usr/local/share/kumir2/translations" << "/usr/local/share/kumir2/translations"
<< "/opt/kumir2/share/translations" << "/opt/kumir2/share/translations"
...@@ -136,8 +145,9 @@ public: ...@@ -136,8 +145,9 @@ public:
, _timerId(-1) , _timerId(-1)
, _splashScreen(nullptr) , _splashScreen(nullptr)
, _started(false) , _started(false)
, _gui(gui)
{ {
if (gui) { if (_gui) {
_qApp = new QApplication(argc, argv); _qApp = new QApplication(argc, argv);
} else { } else {
_qApp = new QCoreApplication(argc, argv); _qApp = new QCoreApplication(argc, argv);
...@@ -154,25 +164,7 @@ public: ...@@ -154,25 +164,7 @@ public:
{ {
QStringList arguments = _qApp->arguments(); QStringList arguments = _qApp->arguments();
qDebug() << "Arguments: " << arguments; qDebug() << "Arguments: " << arguments;
bool mustShowHelpAndExit = false;
bool mustShowVersionAndExit = false;
for (int i = 1; i < arguments.size(); i++) {
const QString &argument = arguments[i];
if (argument == "--help" || argument == "-h" || argument == "/?") {
mustShowHelpAndExit = true;
break;
} else if (argument == "--version") {
mustShowVersionAndExit = true;
break;
} else if (!argument.startsWith("-")) {
break;
}
}
bool gui = true;
#ifdef Q_OS_LINUX
gui = gui && getenv("DISPLAY") != 0;
#endif
const QList<QDir> tsDirs = translationsDirs(); const QList<QDir> tsDirs = translationsDirs();
Q_FOREACH (const QDir &translationsDir, tsDirs) { Q_FOREACH (const QDir &translationsDir, tsDirs) {
QStringList ts_files = translationsDir.entryList(QStringList() << "*_" + getLanguage() + ".qm"); QStringList ts_files = translationsDir.entryList(QStringList() << "*_" + getLanguage() + ".qm");
...@@ -185,7 +177,7 @@ public: ...@@ -185,7 +177,7 @@ public:
} }
} }
const QString sharePath = resolvePath(KUMIR2_RESOURCES_DIR); QString sharePath = resolvePath(KUMIR2_RESOURCES_DIR);
_qApp->setProperty("sharePath", sharePath); _qApp->setProperty("sharePath", sharePath);
QSettings::setDefaultFormat(QSettings::IniFormat); QSettings::setDefaultFormat(QSettings::IniFormat);
...@@ -196,12 +188,8 @@ public: ...@@ -196,12 +188,8 @@ public:
manager->setSharePath(sharePath); manager->setSharePath(sharePath);
QString error; QString error;
qDebug() << "Initialized plugin manager"; qDebug() << "Initialized plugin manager";
#ifdef CONFIGURATION_TEMPLATE
const QByteArray defaultTemplate = CONFIGURATION_TEMPLATE; QByteArray templ = currentTemplate;
#else
#error No default configuration passed to GCC
#endif
QByteArray templ = defaultTemplate;
for (int i = 1; i < arguments.size(); i++) { for (int i = 1; i < arguments.size(); i++) {
QByteArray arg = arguments[i].toLatin1(); QByteArray arg = arguments[i].toLatin1();
if (arg.startsWith("[") && arg.endsWith("]")) { if (arg.startsWith("[") && arg.endsWith("]")) {
...@@ -210,33 +198,31 @@ public: ...@@ -210,33 +198,31 @@ public:
} }
qDebug() << "Loading plugins by template: " << templ; qDebug() << "Loading plugins by template: " << templ;
error = manager->loadPluginsByTemplate(templ); error = manager->loadPluginsByTemplate(templ);
if (!gui && manager->isGuiRequired()) { if (!_gui && manager->isGuiRequired()) {
if (_splashScreen) { if (_splashScreen) {
_splashScreen->finish(0); _splashScreen->finish(0);
} }
showErrorMessage("Requires X11 session to run this configuration"); showErrorMessage("Requires X11 session to run this configuration");
_qApp->exit(1); _qApp->exit(1);
return;
} }
// qInstallMsgHandler(manager->isGuiRequired()
// ? GuiMessageOutput
// : ConsoleMessageOutput);
if (!error.isEmpty()) { if (!error.isEmpty()) {
if (_splashScreen) { if (_splashScreen) {
_splashScreen->finish(0); _splashScreen->finish(0);
} }
showErrorMessage(error); showErrorMessage(error);
_qApp->exit(1); _qApp->exit(1);
return;
} }
qDebug() << "Done loading all plugins by template"; qDebug() << "Done loading all plugins by template";
if (mustShowHelpAndExit) { if (helpMode) {
if (_splashScreen) { if (_splashScreen) {
_splashScreen->finish(0); _splashScreen->finish(0);
} }
const QString msg = manager->commandLineHelp(); QString msg = manager->commandLineHelp();
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
QTextCodec *codec = QTextCodec::codecForName("CP866"); QTextCodec *codec = QTextCodec::codecForName("CP866");
fprintf(stderr, "%s", codec->fromUnicode(msg).constData()); fprintf(stderr, "%s", codec->fromUnicode(msg).constData());
...@@ -247,11 +233,15 @@ public: ...@@ -247,11 +233,15 @@ public:
return; return;
} }
if (mustShowVersionAndExit) { if (versionMode) {
if (_splashScreen) {
_splashScreen->finish(0);
}
fprintf(stderr, "%s\n", qPrintable(_qApp->applicationVersion())); fprintf(stderr, "%s\n", qPrintable(_qApp->applicationVersion()));
_qApp->exit(0); _qApp->exit(0);
return; return;
} }
qDebug() << "Begin plugins initialization"; qDebug() << "Begin plugins initialization";
error = manager->initializePlugins(); error = manager->initializePlugins();
if (!error.isEmpty()) { if (!error.isEmpty()) {
...@@ -261,24 +251,30 @@ public: ...@@ -261,24 +251,30 @@ public:
showErrorMessage(error); showErrorMessage(error);
_qApp->exit(_qApp->property("returnCode").isValid() _qApp->exit(_qApp->property("returnCode").isValid()
? _qApp->property("returnCode").toInt() : 1); ? _qApp->property("returnCode").toInt() : 1);
return;
} }
// GUI requirement may be changed as result of plugins initialization, // GUI requirement may be changed as result of plugins initialization,
// so check it again // so check it again
qDebug() << "Plugins initialization done"; qDebug() << "Plugins initialization done";
if (!gui && manager->isGuiRequired()) { if (!_gui && manager->isGuiRequired()) {
if (_splashScreen) {
_splashScreen->finish(0);
}
showErrorMessage("Requires X11 session to run this configuration"); showErrorMessage("Requires X11 session to run this configuration");
_qApp->exit(_qApp->property("returnCode").isValid() _qApp->exit(_qApp->property("returnCode").isValid()
? _qApp->property("returnCode").toInt() : 1); ? _qApp->property("returnCode").toInt() : 1);
return;
} }
if (_splashScreen) { if (_splashScreen) {
_splashScreen->finish(0); _splashScreen->finish(0);
_splashScreen = 0;
} }
qDebug() << "Starting entry point plugin"; qDebug() << "Starting entry point plugin";
error = manager->start(); error = manager->start();
if (!error.isEmpty()) { if (!error.isEmpty()) {
if (_splashScreen) {
_splashScreen->finish(0);
}
showErrorMessage(error); showErrorMessage(error);
_qApp->exit(_qApp->property("returnCode").isValid() _qApp->exit(_qApp->property("returnCode").isValid()
? _qApp->property("returnCode").toInt() : 1); ? _qApp->property("returnCode").toInt() : 1);
...@@ -304,7 +300,8 @@ public: ...@@ -304,7 +300,8 @@ public:
int main() int main()
{ {
_timerId = _qApp->startTimer(250); int dt = _splashScreen ? 250 : 50;
_timerId = _qApp->startTimer(dt);
int ret = _qApp->exec(); int ret = _qApp->exec();
if (ret == 0) { if (ret == 0) {
return _qApp->property("returnCode").isValid() return _qApp->property("returnCode").isValid()
...@@ -318,13 +315,12 @@ private: ...@@ -318,13 +315,12 @@ private:
QCoreApplication *_qApp; QCoreApplication *_qApp;
int _timerId; int _timerId;
QSplashScreen *_splashScreen; QSplashScreen *_splashScreen;
bool _started; bool _started, _gui;
}; };
bool static bool
setup_custom_vendor_information(QCoreApplication *app) setup_custom_vendor_information()
{ {
QString appName; QString appName;
QString appVendor; QString appVendor;
...@@ -362,45 +358,70 @@ setup_custom_vendor_information(QCoreApplication *app) ...@@ -362,45 +358,70 @@ setup_custom_vendor_information(QCoreApplication *app)
appAboutFileName = ":/kumir2-launcher/" + QString::fromLatin1(APP_ABOUT_ru); appAboutFileName = ":/kumir2-launcher/" + QString::fromLatin1(APP_ABOUT_ru);
#endif #endif
if (appName.length() > 0) { if (appName.length() > 0) {
app->setProperty("customAppName", appName); qApp->setProperty("customAppName", appName);
} }
if (appVendor.length() > 0) { if (appVendor.length() > 0) {
app->setProperty("customAppVendor", appVendor); qApp->setProperty("customAppVendor", appVendor);
} }
if (appVersion.length() > 0) { if (appVersion.length() > 0) {
app->setProperty("customAppVersion", appVersion); qApp->setProperty("customAppVersion", appVersion);
} }
if (appLicenseFileName.length() > 0) { if (appLicenseFileName.length() > 0) {
app->setProperty("customAppLicense", appLicenseFileName); qApp->setProperty("customAppLicense", appLicenseFileName);
} }
if (appAboutFileName.length() > 0) { if (appAboutFileName.length() > 0) {
app->setProperty("customAppAbout", appAboutFileName); qApp->setProperty("customAppAbout", appAboutFileName);
} }
return result; return result;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
#if QT_VERSION < 0x050000 guiMode = false;
qInstallMsgHandler(GuiMessageOutput); pipeMode = false;
#else versionMode = false;
qInstallMessageHandler(GuiMessageOutput); helpMode = false;
#endif
QString gitHash = QString::fromLatin1(GIT_HASH);
QString gitTag = QString::fromLatin1(GIT_TAG);
QString gitBranch = QString::fromLatin1(GIT_BRANCH);
QDateTime gitTimeStamp = QDateTime::fromTime_t(QString::fromLatin1(GIT_TIMESTAMP).toUInt());
bool gui = true; #if defined(WINDOW_ICON) || defined(SPLASHSCREEN)
guiMode = true;
#endif
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
gui = gui && getenv("DISPLAY") != 0; guiMode = guiMode && getenv("DISPLAY") != 0;
#endif
for (int i = 1; i < argc; i++) {
QString arg = argv[i];
if (arg == "--help" || arg == "-h" || arg == "/?") {
helpMode = true;
} else if (arg == "--version") {
versionMode = true;
} else if (arg == "--pipe" || arg == "-p") {
pipeMode = true;
} else if (arg == "--nopipe") {
pipeMode = false;
} else if (arg == "--gui") {
guiMode = true;
} else if (arg == "--nogui") {
guiMode = false;
} else if (arg.startsWith("--template=")) {
currentTemplate = arg.toLatin1().mid(11);
} else if (!arg.startsWith("-")) {
break;
}
}
#if QT_VERSION < 0x050000
qInstallMsgHandler((!pipeMode) ? LoggerMessageOutput : ConsoleMessageOutput);
#else
qInstallMessageHandler((!pipeMode) ? LoggerMessageOutput : ConsoleMessageOutput);
#endif #endif
Application *app = new Application(argc, argv, gui); Application *app = new Application(argc, argv, guiMode);
#ifdef WINDOW_ICON #ifdef WINDOW_ICON
if (gui) { if (guiMode) {
QApplication *guiApp = qobject_cast<QApplication *>(qApp); QApplication *guiApp = qobject_cast<QApplication *>(qApp);
QString imgPath = ":/kumir2-launcher/" + QString::fromLatin1(WINDOW_ICON); QString imgPath = ":/kumir2-launcher/" + QString::fromLatin1(WINDOW_ICON);
QIcon icon(imgPath); QIcon icon(imgPath);
...@@ -414,38 +435,21 @@ int main(int argc, char **argv) ...@@ -414,38 +435,21 @@ int main(int argc, char **argv)
qApp->addLibraryPath(resolvePath(KUMIR2_LIBS_DIR)); qApp->addLibraryPath(resolvePath(KUMIR2_LIBS_DIR));
qApp->addLibraryPath(resolvePath(KUMIR2_PLUGINS_DIR)); qApp->addLibraryPath(resolvePath(KUMIR2_PLUGINS_DIR));
QString gitHash = QString::fromLatin1(GIT_HASH);
QString gitTag = QString::fromLatin1(GIT_TAG);
QString gitBranch = QString::fromLatin1(GIT_BRANCH);
QDateTime gitTimeStamp = QDateTime::fromTime_t(QString::fromLatin1(GIT_TIMESTAMP).toUInt());
qApp->setApplicationVersion(gitTag.length() > 0 && gitTag != "unknown" qApp->setApplicationVersion(gitTag.length() > 0 && gitTag != "unknown"
? gitTag : gitBranch + "/" + gitHash); ? gitTag : gitBranch + "/" + gitHash);
qApp->setProperty("gitTimeStamp", gitTimeStamp); qApp->setProperty("gitTimeStamp", gitTimeStamp);
bool customInfo = setup_custom_vendor_information();
QString sharePath = resolvePath(KUMIR2_RESOURCES_DIR); Q_UNUSED(customInfo);
QStringList arguments = QCoreApplication::instance()->arguments();
bool mustShowHelpAndExit = false;
bool mustShowVersionAndExit = false;
for (int i = 1; i < arguments.size(); i++) {
const QString &argument = arguments[i];
if (argument == "--help" || argument == "-h" || argument == "/?") {
mustShowHelpAndExit = true;
break;
} else if (argument == "--version") {
mustShowVersionAndExit = true;
break;
} else if (!argument.startsWith("-")) {
break;
}