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>
This commit is contained in:
Tomaz Canabrava 2015-09-03 14:49:59 -03:00 committed by Dirk Hohndel
parent e49d6213ad
commit 45c9764073
5 changed files with 175 additions and 41 deletions

View file

@ -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)

View file

@ -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();
}

View file

@ -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;
}

View file

@ -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();
}