diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-09-03 14:49:59 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-10-30 10:36:49 -0700 |
commit | 45c97640739198cf9a9cc5c42e81fb9811702b46 (patch) | |
tree | 4390fe4387d073ac7802bb6bff3bc0bbe69a836d | |
parent | e49d6213ad129284a45d53c3fcdc03249e84efe2 (diff) | |
download | subsurface-45c97640739198cf9a9cc5c42e81fb9811702b46.tar.gz |
main.cpp -> {android-main, desktop-main}
This is needed to compile both in a single call to make. Also it will
help removing some of the mistakes in the current android version:
it always created the mainwindow, even without using it for anything,
so tons of memory will be freed now for the android version, making it
snappier and smoother.
This is a necessary move so we don't need to #ifdef all over the place
for the two different versions, and imo the changes needed to keep both
versions will not be that huge if we keep things in subsurface-core
sane.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | CMakeLists.txt | 52 | ||||
-rw-r--r-- | subsurface-android-helper.cpp (renamed from qt-gui.cpp) | 19 | ||||
-rw-r--r-- | subsurface-android-main.cpp | 81 | ||||
-rw-r--r-- | subsurface-desktop-helper.cpp | 62 | ||||
-rw-r--r-- | subsurface-desktop-main.cpp (renamed from main.cpp) | 0 |
5 files changed, 174 insertions, 40 deletions
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,25 +390,26 @@ if(SUBSURFACE_MOBILE) 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() - 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} -) + 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) diff --git a/qt-gui.cpp b/subsurface-android-helper.cpp index 5c7157fe6..7b5d5df56 100644 --- a/qt-gui.cpp +++ b/subsurface-android-helper.cpp @@ -10,10 +10,8 @@ #include <QNetworkProxy> #include <QLibraryInfo> - #include "qt-gui.h" -#ifdef SUBSURFACE_MOBILE #include <QQuickWindow> #include <QQmlApplicationEngine> #include <QQmlContext> @@ -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<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager"); qmlRegisterType<QMLProfile>("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 <locale.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> + +#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 <QStringList> +#include <QApplication> +#include <QLoggingCategory> +#include <git2.h> + +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 <QApplication> +#include <QDesktopWidget> +#include <QNetworkProxy> +#include <QLibraryInfo> + + +#include "qt-gui.h" + +#ifdef SUBSURFACE_MOBILE +#include <QQuickWindow> +#include <QQmlApplicationEngine> +#include <QQmlContext> +#include <QSortFilterProxyModel> +#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 index e7259c3f3..e7259c3f3 100644 --- a/main.cpp +++ b/subsurface-desktop-main.cpp |