Skip to content
Snippets Groups Projects
main.cpp 4.15 KiB
Newer Older
SeeLook's avatar
SeeLook committed
/***************************************************************************
 *   Copyright (C) 2011-2015 by Tomasz Bojczuk                             *
SeeLook's avatar
SeeLook committed
 *   tomaszbojczuk@gmail.com                                               *
 *                                                                         *
 *   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 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *  You should have received a copy of the GNU General Public License      *
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/

#include "mainwindow.h"
#if defined (Q_OS_ANDROID)
  #include "ttouchstyle.h"
  // #include <QtWidgets/qstylefactory.h>
SeeLook's avatar
SeeLook committed
#include <tinitcorelib.h>
#include <QtCore/qpointer.h>
#include <QtCore/qfile.h>
#include <QtCore/qsettings.h>
#include <QtWidgets/qapplication.h>
#include <QtCore/qdebug.h>
#include <QtCore/qtranslator.h>
#include <QtCore/qdatetime.h>
SeeLook's avatar
SeeLook committed

/** It allows to grab all debug messages into nootka-log.txt file */
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
  Q_UNUSED(type)
//   if (type == QtDebugMsg) {
#if defined (Q_OS_ANDROID)
    QFile outFile(qgetenv("EXTERNAL_STORAGE") + QStringLiteral("/nootka-log.txt"));
#else
    QFile outFile(QStringLiteral("nootka-log.txt"));
#endif
    outFile.open(QIODevice::WriteOnly | QIODevice::Append);
    QTextStream ts(&outFile);
    ts << msg << endl;
SeeLook's avatar
SeeLook committed
Tglobals *gl;
bool resetConfig;

SeeLook's avatar
SeeLook committed
int main(int argc, char *argv[])
{
#if defined (Q_OS_ANDROID)
  {
    QString logFile(qgetenv("EXTERNAL_STORAGE") + QStringLiteral("/nootka-log.txt"));
    if (QFile::exists(logFile))
      QFile::remove(logFile);
  }
  qInstallMessageHandler(myMessageOutput);
  qDebug() << "==== NOOTKA LOG =======\n" << QDateTime::currentDateTime().toString();
#endif
	QTranslator qtTranslator;
	QTranslator nooTranslator;
SeeLook's avatar
SeeLook committed
	QPointer<QApplication> a = 0;
SeeLook's avatar
SeeLook committed
	int exitCode;
	bool firstTime = true;
	QString confFile;
	resetConfig = false;
SeeLook's avatar
SeeLook committed
		if (a) delete a;
		if (resetConfig) { // delete config file - new Nootka instance will start with first run wizard
				QFile f(confFile);
				f.remove();
		}
		resetConfig = false;
SeeLook's avatar
SeeLook committed
		a = new QApplication(argc, argv);
    a->setStyle(new TtouchStyle);
//     a->setStyle(QStyleFactory::create("Fusion"));
SeeLook's avatar
SeeLook committed
		gl = new Tglobals();
		gl->path = Tglobals::getInstPath(qApp->applicationDirPath());
		confFile = gl->config->fileName();
		prepareTranslations(a, qtTranslator, nooTranslator);
SeeLook's avatar
SeeLook committed
		if (!loadNootkaFont(a))
			return 111;
SeeLook's avatar
SeeLook committed
// creating main window
    w = new MainWindow();

#if defined (Q_OS_MAC)
SeeLook's avatar
SeeLook committed
	// to allow opening nootka files by clicking them in MacOs finder
SeeLook's avatar
SeeLook committed
    a->installEventFilter(w);
#endif
#if defined (Q_OS_ANDROID)
    qDebug() << "params" << argc;
    w->showFullScreen();
#else
SeeLook's avatar
SeeLook committed
    w->show();
    if (firstTime && argc > 1)
        w->openFile(QString::fromLocal8Bit(argv[argc - 1]));
SeeLook's avatar
SeeLook committed
		firstTime = false;
		exitCode = a->exec();
		delete w;
#if defined (Q_OS_ANDROID)
    if (resetConfig) { // delete config file - new Nootka instance will start with first run wizard
        QFile f(confFile);
        f.remove();
    }
    resetConfig = false; // Close Android app anyway - it doesn't support restarting
#endif
  delete a;
SeeLook's avatar
SeeLook committed
}