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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// order of includes is important: first qapplication, then BALL includes
#include <QtWidgets/QApplication>
#include <QtWidgets/QMessageBox>
#include <QtCore/QTranslator>
#include "mainframe.h"
#include <BALL/SYSTEM/path.h>
#include <BALL/SYSTEM/directory.h>
void logMessages(QtMsgType type, const QMessageLogContext& context, const QString& message)
{
BALL::String s(message.toStdString());
if (s.hasPrefix("QTextBrowser")) return;
switch ( type ) {
case QtDebugMsg:
BALL::Log.info() << message.toStdString() << " " << (context.file ? context.file : "(unknown context)")
<< " " << context.line
<< " " << (context.function ? context.function : "(unknown function)") << std::endl;
break;
case QtWarningMsg:
BALL::Log.warn() << message.toStdString() << " " << (context.file ? context.file : "(unknown context)")
<< " " << context.line
<< " " << (context.function ? context.function : "(unknown function)") << std::endl;
break;
case QtFatalMsg:
fprintf( stderr, "Fatal: %s\n", message.toLatin1().constData() );
abort(); // deliberately core dump
case QtCriticalMsg:
fprintf( stderr, "Critical: %s\n", message.toLatin1().constData() );
abort(); // deliberately core dump
default:
break;
}
}
// uncomment this to use debugging to std::cout!
//#undef BALL_OS_WINDOWS
#ifndef BALL_OS_WINDOWS
int main(int argc, char **argv)
{
#else
int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR cmd_line, int)
{
int argc = __argc;
char** argv = __argv;
#endif
qInstallMessageHandler(logMessages);
// *sigh* this is required as long as Qt does not correctly paint on OpenGL 2 contexts
//QGL::setPreferredPaintEngine(QPaintEngine::OpenGL);
QApplication application(argc, argv);
QStringList arguments = application.arguments();
QStringList::const_iterator arg_it;
bool kiosk_mode = false;
for (arg_it = arguments.constBegin(); arg_it != arguments.constEnd(); ++arg_it)
{
if (arg_it->toLocal8Bit() == "-kiosk")
{
kiosk_mode = true;
}
}
if (kiosk_mode)
{
BALL::VIEW::UIOperationMode::instance().setMode(BALL::VIEW::UIOperationMode::MODE_KIOSK);
}
// =============== testing for opengl support ======================================
if (!QGLFormat::hasOpenGL())
{
QMessageBox::critical(0, "Error while starting BALLView",
"Your computer has no OpenGL support, please install the correct drivers. Aborting for now...",
QMessageBox::Ok, Qt::NoButton, Qt::NoButton);
return -1;
}
BALL::String home_dir = BALL::Directory::getUserHomeDir();
// =============== load translations =====================
BALL::INIFile f(home_dir + BALL::FileSystem::PATH_SEPARATOR + ".BALLView");
f.read();
if (f.hasEntry("GENERAL", "language"))
{
QString str = f.getValue("GENERAL", "language").c_str();
if (str != "en_US")
{
QString loc = "BALLView-" + str;
BALL::Path p;
QStringList dpaths = QString(p.getDataPath().c_str()).split("\n");
QTranslator* translator = new QTranslator(&application);
Q_FOREACH(QString s, dpaths)
{
translator->load(loc, s + "BALLView/translations");
if (!translator->isEmpty())
{
QCoreApplication::installTranslator(translator);
break;
}
}
}
}
// =============== testing if we can write in current directory =====================
if (home_dir == "")
{
try
{
BALL::String temp_file_name;
BALL::File::createTemporaryFilename(temp_file_name);
BALL::File out(temp_file_name, std::ios::out);
out << "test" << std::endl;
out.remove();
}
catch(...)
{
QMessageBox::warning(0, "Error while starting BALLView",
QString("You dont have write access to the current working directory\n") +
"and BALLView can not find your home directory. This can cause\n" +
"unexpected behaviour. Please start BALLView from your homedir with\n" +
"absolute path (e.g. C:\\Programs\\BALLView\\BALLView).\n");
}
}
// =============== initialize Mainframe ============================================
// Create the mainframe.
BALL::Mainframe mainframe(0, "Mainframe");
// can we use the users homedir as working dir?
if (home_dir != "")
{
mainframe.setWorkingDir(home_dir);
}
// Register the mainfram (required for Python support).
mainframe.setIdentifier("Mainframe");
mainframe.registerThis();
// Show the main window.
mainframe.show();
// =============== parsing command line arguments ==================================
// If there are additional command line arguments, interpret them as files to open or logging flag.
for (BALL::Index i = 1; i < argc; ++i)
{
BALL::String argument(argv[i]);
if (argument == "-l")
{
mainframe.enableLoggingToFile();
continue;
}
else if (argument == "-kiosk")
{
// the kiosk mode has already been handled
continue;
}
mainframe.openFile(argument);
}
// enable ending of program from python script
if (mainframe.isAboutToQuit())
{
mainframe.aboutToExit();
return 0;
}
// Hand over control to the application.
return application.exec();
}
|