diff --git a/CMakeLists.txt b/CMakeLists.txt index 74b9d0d94..620b496ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -347,9 +347,10 @@ source_group("Subsurface Models" FILES ${SUBSURFACE_MODELS}) # the main app. set(SUBSURFACE_APP - main.cpp - qt-gui.cpp + subsurface-desktop-main.cpp + subsurface-desktop-helper.cpp ) + source_group("Subsurface App" FILES ${SUBSURFACE_APP}) add_library(subsurface_models STATIC ${SUBSURFACE_MODELS_LIB_SRCS}) @@ -366,13 +367,19 @@ add_subdirectory(desktop-widgets) # create the executables if(SUBSURFACE_MOBILE) - set(MOBILE_SRC qt-mobile/qmlmanager.cpp qt-mobile/qmlprofile.cpp qt-models/divelistmodel.cpp) + set(MOBILE_SRC + qt-mobile/qmlmanager.cpp + qt-mobile/qmlprofile.cpp + qt-models/divelistmodel.cpp + subsurface-android-main.cpp + subsurface-android-helper.cpp + ) add_definitions(-DSUBSURFACE_MOBILE) qt5_add_resources(MOBILE_RESOURCES qt-mobile/mobile-resources.qrc) if(ANDROID) - add_library(subsurface-mobile SHARED ${MOBILE_SRC} ${SUBSURFACE_PKG} ${SUBSURFACE_APP} ${SUBSURFACE_RESOURCES} ${MOBILE_RESOURCES}) + add_library(subsurface-mobile SHARED ${MOBILE_SRC} ${SUBSURFACE_PKG} ${SUBSURFACE_RESOURCES} ${MOBILE_RESOURCES}) else() - add_executable(subsurface-mobile ${MOBILE_SRC} ${SUBSURFACE_PKG} ${SUBSURFACE_APP} ${SUBSURFACE_RESOURCES} ${MOBILE_RESOURCES}) + add_executable(subsurface-mobile ${MOBILE_SRC} ${SUBSURFACE_PKG} ${SUBSURFACE_RESOURCES} ${MOBILE_RESOURCES}) endif() target_link_libraries( subsurface-mobile @@ -383,26 +390,27 @@ if(SUBSURFACE_MOBILE) subsurface_models subsurface_corelib ${SUBSURFACE_LINK_LIBRARIES}) -else() - if(ANDROID) - # Produce a shared-library instead of a program. - # Something that androiddeployqt can work with. - add_library(${SUBSURFACE_TARGET} SHARED ${SUBSURFACE_PKG} ${SUBSURFACE_APP} ${SUBSURFACE_RESOURCES}) - else() - add_executable(${SUBSURFACE_TARGET} MACOSX_BUNDLE WIN32 ${SUBSURFACE_PKG} ${SUBSURFACE_APP} ${SUBSURFACE_RESOURCES}) - endif() - target_link_libraries( - ${SUBSURFACE_TARGET} - subsurface_generated_ui - subsurface_interface - subsurface_profile - subsurface_statistics - subsurface_models - subsurface_corelib - ${SUBSURFACE_LINK_LIBRARIES} -) endif() +if(ANDROID) + # Produce a shared-library instead of a program. + # Something that androiddeployqt can work with. + # this is the desktop version, running on android. + add_library(${SUBSURFACE_TARGET} SHARED ${SUBSURFACE_PKG} ${SUBSURFACE_APP} ${SUBSURFACE_RESOURCES}) +else() + add_executable(${SUBSURFACE_TARGET} MACOSX_BUNDLE WIN32 ${SUBSURFACE_PKG} ${SUBSURFACE_APP} ${SUBSURFACE_RESOURCES}) +endif() +target_link_libraries( + ${SUBSURFACE_TARGET} + subsurface_generated_ui + subsurface_interface + subsurface_profile + subsurface_statistics + subsurface_models + subsurface_corelib + ${SUBSURFACE_LINK_LIBRARIES} +) + add_dependencies(subsurface_statistics subsurface_generated_ui) add_dependencies(subsurface_profile subsurface_generated_ui) add_dependencies(subsurface_interface subsurface_generated_ui) diff --git a/qt-gui.cpp b/subsurface-android-helper.cpp similarity index 86% rename from qt-gui.cpp rename to subsurface-android-helper.cpp index 5c7157fe6..7b5d5df56 100644 --- a/qt-gui.cpp +++ b/subsurface-android-helper.cpp @@ -10,10 +10,8 @@ #include #include - #include "qt-gui.h" -#ifdef SUBSURFACE_MOBILE #include #include #include @@ -21,25 +19,16 @@ #include "qt-mobile/qmlmanager.h" #include "qt-models/divelistmodel.h" #include "qt-mobile/qmlprofile.h" -QObject *qqWindowObject = NULL; -#endif -static MainWindow *window = NULL; +QObject *qqWindowObject = NULL; void init_ui() { init_qt_late(); - - window = new MainWindow(); - if (existing_filename && existing_filename[0] != '\0') - window->setTitle(MWTF_FILENAME); - else - window->setTitle(MWTF_DEFAULT); } void run_ui() { -#ifdef SUBSURFACE_MOBILE window->hide(); qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "QMLManager"); qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile"); @@ -66,15 +55,11 @@ void run_ui() qml_window->setWidth(800); #endif qml_window->show(); -#else - window->show(); -#endif qApp->exec(); } void exit_ui() { - delete window; delete qApp; free((void *)existing_filename); free((void *)default_dive_computer_vendor); @@ -87,5 +72,3 @@ double get_screen_dpi() QDesktopWidget *mydesk = qApp->desktop(); return mydesk->physicalDpiX(); } - - diff --git a/subsurface-android-main.cpp b/subsurface-android-main.cpp new file mode 100644 index 000000000..db974119e --- /dev/null +++ b/subsurface-android-main.cpp @@ -0,0 +1,81 @@ +/* main.c */ +#include +#include +#include +#include +#include + +#include "dive.h" +#include "qt-gui.h" +#include "subsurfacestartup.h" +#include "desktop-widgets/mainwindow.h" +#include "desktop-widgets/diveplanner.h" +#include "subsurface-core/color.h" +#include "qthelper.h" + +#include +#include +#include +#include + +QTranslator *qtTranslator, *ssrfTranslator; + +int main(int argc, char **argv) +{ + int i; + bool no_filenames = true; + QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); + QApplication *application = new QApplication(argc, argv); + QStringList files; + QStringList importedFiles; + QStringList arguments = QCoreApplication::arguments(); + + bool dedicated_console = arguments.length() > 1 && + (arguments.at(1) == QString("--win32console")); + subsurface_console_init(dedicated_console); + + for (i = 1; i < arguments.length(); i++) { + QString a = arguments.at(i); + if (a.at(0) == '-') { + parse_argument(a.toLocal8Bit().data()); + continue; + } + if (imported) { + importedFiles.push_back(a); + } else { + no_filenames = false; + files.push_back(a); + } + } +#if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22 + git_threads_init(); +#else + git_libgit2_init(); +#endif + setup_system_prefs(); + prefs = default_prefs; + fill_profile_color(); + parse_xml_init(); + taglist_init_global(); + init_ui(); + if (no_filenames) { + if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE) { + QString defaultFile(prefs.default_filename); + if (!defaultFile.isEmpty()) + files.push_back(QString(prefs.default_filename)); + } else if (prefs.default_file_behavior == CLOUD_DEFAULT_FILE) { + QString cloudURL; + if (getCloudURL(cloudURL) == 0) + files.push_back(cloudURL); + } + } + + if (!quit) + run_ui(); + exit_ui(); + taglist_free(g_tag_list); + parse_xml_exit(); + subsurface_console_exit(); + free_prefs(); + return 0; +} diff --git a/subsurface-desktop-helper.cpp b/subsurface-desktop-helper.cpp new file mode 100644 index 000000000..af366fb84 --- /dev/null +++ b/subsurface-desktop-helper.cpp @@ -0,0 +1,62 @@ +/* qt-gui.cpp */ +/* Qt UI implementation */ +#include "dive.h" +#include "display.h" +#include "desktop-widgets/mainwindow.h" +#include "helpers.h" + +#include +#include +#include +#include + + +#include "qt-gui.h" + +#ifdef SUBSURFACE_MOBILE +#include +#include +#include +#include +#include "qt-mobile/qmlmanager.h" +#include "qt-models/divelistmodel.h" +#include "qt-mobile/qmlprofile.h" +QObject *qqWindowObject = NULL; +#endif + +static MainWindow *window = NULL; + +void init_ui() +{ + init_qt_late(); + + window = new MainWindow(); + if (existing_filename && existing_filename[0] != '\0') + window->setTitle(MWTF_FILENAME); + else + window->setTitle(MWTF_DEFAULT); +} + +void run_ui() +{ + window->show(); + qApp->exec(); +} + +void exit_ui() +{ + delete window; + delete qApp; + free((void *)existing_filename); + free((void *)default_dive_computer_vendor); + free((void *)default_dive_computer_product); + free((void *)default_dive_computer_device); +} + +double get_screen_dpi() +{ + QDesktopWidget *mydesk = qApp->desktop(); + return mydesk->physicalDpiX(); +} + + diff --git a/main.cpp b/subsurface-desktop-main.cpp similarity index 100% rename from main.cpp rename to subsurface-desktop-main.cpp