File indexing completed on 2024-05-12 05:39:40

0001 /*************************************************************************
0002  *   Copyright (C) 2007 by Romain Campioni                               *
0003  *   Copyright (C) 2009 by Renaud Guezennec                              *
0004  *   Copyright (C) 2011 by Joseph Boudou                                 *
0005  *   https://rolisteam.org/                                           *
0006  *                                                                       *
0007  *   Rolisteam is free software; you can redistribute it and/or modify   *
0008  *   it under the terms of the GNU General Public License as published   *
0009  *   by the Free Software Foundation; either version 2 of the License,   *
0010  *   or (at your option) any later version.                              *
0011  *                                                                       *
0012  *   This program is distributed in the hope that it will be useful,     *
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of      *
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
0015  *   GNU General Public License for more details.                        *
0016  *                                                                       *
0017  *   You should have received a copy of the GNU General Public License   *
0018  *   along with this program; if not, write to the                       *
0019  *   Free Software Foundation, Inc.,                                     *
0020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           *
0021  *************************************************************************/
0022 
0023 #include <QApplication>
0024 #include <QCommandLineOption>
0025 #include <QCommandLineParser>
0026 #include <QDateTime>
0027 #include <QDebug>
0028 #include <QLoggingCategory>
0029 #include <QQuickStyle>
0030 #include <QResource>
0031 #include <QTranslator>
0032 #include <QUuid>
0033 #include <exception>
0034 
0035 #include "common_qml/theme.h"
0036 #include "mainwindow.h"
0037 #include "rolisteamapplication.h"
0038 #include "uiwatchdog.h"
0039 #include "version.h"
0040 
0041 #include "applicationstate.h"
0042 
0043 Q_DECLARE_LOGGING_CATEGORY(rNetwork);
0044 Q_LOGGING_CATEGORY(rNetwork, "rolisteam.network");
0045 Q_DECLARE_LOGGING_CATEGORY(rDice);
0046 Q_LOGGING_CATEGORY(rDice, "rolisteam.dice");
0047 
0048 /**
0049  * @mainpage Rolisteam
0050  * @tableofcontents
0051  * @author Renaud Guezennec
0052  *
0053  *  @section intro_sec Introduction
0054  * Rolisteam help you to manage role playing games with your friend all over the world.<br/>
0055  * Rolisteam is a free software under GNU/GPL. Its purpose is to provide all features required to<br/>
0056  * perform Role playing games with remote friends.<br/>
0057  * It is based on Client/server architecture and it is written in C++ with Qt.<br/>
0058  *
0059  * @section features_sec Features:
0060  * - Chat with one, many and all players
0061  * - Sharing images and many other media type
0062  * - Drawing maps on the fly
0063  * - Sharing environment sound
0064  * - Multi-platform: Windows, Linux and Mac OS X
0065  * - Powerful die rolling syntax
0066  * - Theme and skin: make your own skin, save it, share it.
0067  * - Useful preferences systems
0068  *
0069  *
0070  *
0071  * @section install_sec Installation
0072  * To get documentation on how to install rolisteam: http://doc.rolisteam.org/
0073  *
0074  * @section How to stay in touch ?
0075  * Please, visit: https://rolisteam.org/
0076  *
0077  * @section tools_subsec Dependencies:
0078  * Qt5, zlib, QML,
0079  * @subpage DiceParser
0080  *
0081  * @section copyright Copyright and License
0082  * GNU/GPLv2
0083  *
0084  * <BR><BR>
0085  *
0086  *
0087  */
0088 
0089 namespace {
0090 constexpr auto profilSelection{"profil_selection"};
0091 constexpr auto quit{"quit"};
0092 constexpr auto playing("playing");
0093 constexpr auto exitState{"exit"};
0094 constexpr auto connected{"connected"};
0095 constexpr auto disconnected{"disconnected"};
0096 }
0097 
0098 /**
0099  * @brief main
0100  * @param argc
0101  * @param argv
0102  * @return
0103  */
0104 int main(int argc, char* argv[])
0105 {
0106     // Application creation
0107     RolisteamApplication app(QString("rolisteam"), version::version, argc, argv);
0108 
0109     Q_INIT_RESOURCE(viewsqml);
0110     Q_INIT_RESOURCE(charactersheet);
0111     Q_INIT_RESOURCE(textedit);
0112     Q_INIT_RESOURCE(rolisteam);
0113     Q_INIT_RESOURCE(resources);
0114 
0115     // INIT STYLE
0116     QQuickStyle::setStyle("rolistyle");
0117     QQuickStyle::setFallbackStyle("Fusion");
0118 
0119     // Ressources
0120     QResource::registerResource("rolisteam.rcc");
0121     customization::Theme::setPath(":/resources/stylesheet/qml/theme.ini");
0122     /*if(true)
0123         QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << ":/resources/rolistheme");
0124     else
0125         QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << ":/resources/rolistheme-dark");*/
0126 
0127 #ifdef Q_OS_WIN
0128     {
0129 
0130 
0131         QString cmdLine("\"%2\rolisteam.exe\" \"-l %1\"");
0132         QSettings fooKey("HKEY_CLASSES_ROOT\\rolisteam", QSettings::NativeFormat);
0133         fooKey.setValue(".", "URL:rolisteam Protocol");
0134         fooKey.setValue("URL Protocol", "");
0135         fooKey.sync();
0136         // qDebug() << fooKey.status();
0137         QSettings fooOpenKey("HKEY_CLASSES_ROOT\\rolisteam\\shell\\open\\command", QSettings::NativeFormat);
0138         QFileInfo info(QCoreApplication::applicationFilePath());
0139         fooOpenKey.setValue(".", cmdLine.arg("%1").arg(info.absoluteFilePath()));
0140         fooOpenKey.sync();
0141         // qDebug() << fooOpenKey.status();
0142     }
0143 #endif
0144 
0145 #ifndef UNIT_TESTS
0146     //UiWatchdog dog;
0147     //dog.start();
0148 #endif
0149     ApplicationState states;
0150     SelectConnectionProfileDialog connectionDialog(app.gameCtrl());
0151     MainWindow mainWindow(app.gameCtrl(), app.arguments());
0152 
0153     states.connectToState(profilSelection, QScxmlStateMachine::onEntry([&connectionDialog,&mainWindow](){
0154         qDebug() << "on Select profile";
0155         connectionDialog.setVisible(true);
0156         mainWindow.makeVisible(false);
0157     }));
0158     states.connectToState(playing, QScxmlStateMachine::onEntry([&connectionDialog,&mainWindow](){
0159         qDebug() << "on playing";
0160         connectionDialog.accept();
0161         mainWindow.makeVisible(true);
0162         connectionDialog.setVisible(false);
0163     }));
0164     states.connectToState(exitState, QScxmlStateMachine::onEntry([&states, &connectionDialog,&mainWindow, &app](){
0165                               qDebug() << "on exit";
0166                               states.stop();
0167                               mainWindow.makeVisible(false);
0168                               connectionDialog.setVisible(false);
0169                               QMetaObject::invokeMethod(&app, &RolisteamApplication::quit, Qt::QueuedConnection);
0170                           }));
0171 
0172     QObject::connect(&app, &RolisteamApplication::quitApp, &states, [&states](){
0173         qDebug() << "on quit app event";
0174         states.submitEvent(quit);
0175     });
0176 
0177     QObject::connect(&app, &RolisteamApplication::connectStatusChanged, &states, [&states](bool b){
0178         qDebug() << "on status changed" << b;
0179         if(b)
0180             states.submitEvent(connected);
0181         else
0182             states.submitEvent(disconnected);
0183     });
0184 
0185     states.start();
0186     return app.exec();
0187 }