diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ae1e9b45..9d9cb1f60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(Subsurface) cmake_minimum_required(VERSION 2.8.11) + # global settings set(CMAKE_AUTOMOC ON) @@ -11,8 +12,8 @@ option(LIBGIT2_FROM_PKGCONFIG "use pkg-config to retrieve libgit2" OFF) option(LIBDC_FROM_PKGCONFIG "use pkg-config to retrieve libdivecomputer" OFF) option(LIBGRANTLEE_FROM_PKGCONFIG "use pkg-config to retrieve grantlee" OFF) option(LIBMARBLE_FROM_PKGCONFIG "use pkg-config to retrieve marble" OFF) +option(MAKE_TESTS "Make the tests" ON) option(NO_MARBLE "disable the marble widget" OFF) -option(NO_TESTS "disable the tests" OFF) option(NO_DOCS "disable the docs" OFF) option(NO_PRINTING "disable the printing support" OFF) option(NO_USERMANUAL "don't include a viewer for the user manual" OFF) @@ -23,6 +24,12 @@ option(FBSUPPORT "allow posting to Facebook" ON) option(BTSUPPORT "enable support for QtBluetooth (requires Qt5.4 or newer)" ON) option(FTDISUPPORT "enable support for libftdi based serial" OFF) +add_definitions(-DSUBSURFACE_SOURCE="${CMAKE_SOURCE_DIR}") + +if(BTSUPPORT) + add_definitions(-DBT_SUPPORT) +endif() + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${${PROJECT_NAME}_SOURCE_DIR}/cmake/Modules @@ -31,9 +38,11 @@ set(CMAKE_MODULE_PATH include_directories(. ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR} - qt-ui + ${CMAKE_BINARY_DIR}/desktop-widgets + desktop-widgets/ qt-models - qt-ui/profile + desktop-widgets/profile + subsurface-core/ ) # get the version string -- this is only used for Mac Bundle at this point @@ -47,9 +56,19 @@ execute_process( message(STATUS "Creating build files for Subsurface ${SSRF_VERSION_STRING}") -# compiler specific settings -if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 ") +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 ") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 ") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + # using Intel C++ +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # using Visual Studio C++ endif() # pkgconfig for required libraries @@ -136,7 +155,6 @@ if(FTDISUPPORT) if (NOT LIBFTDI_FOUND) pkg_config_library(LIBFTDI libftdi1 REQUIRED) endif() - set(SERIAL_FTDI serial_ftdi.c) add_definitions(-DSERIAL_FTDI) endif() @@ -159,13 +177,6 @@ else() find_package(Grantlee5 REQUIRED) set(GRANTLEE_LIBRARIES Grantlee5::Templates) endif() - set(SUBSURFACE_PRINTING_SRCS - printer.cpp - templatelayout.cpp - qt-ui/templateedit.cpp - qt-ui/printdialog.cpp - qt-ui/printoptions.cpp - ) set(PRINTING_PKG PrintSupport) set(PRINTING_LIB Qt5::PrintSupport) endif() @@ -174,7 +185,6 @@ if(NO_USERMANUAL) message(STATUS "building without usermanual") add_definitions(-DNO_USERMANUAL) else() - set(USERMANUAL qt-ui/usermanual.cpp) set(WEBKIT_PKG WebKitWidgets) set(WEBKIT_LIB Qt5::WebKitWidgets) endif() @@ -273,22 +283,18 @@ add_custom_target( ) # set up the different target platforms -set(PLATFORM_SRC unknown_platform.c) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(SUBSURFACE_TARGET subsurface) - set(PLATFORM_SRC linux.c) # in some builds we appear to be missing libz for some strange reason... set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} -lz) endif() if(ANDROID) - set(PLATFORM_SRC android.cpp) set(SUBSURFACE_TARGET subsurface) # To allow us to debug log to logcat set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} -llog) endif() if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(SUBSURFACE_TARGET Subsurface) - set(PLATFORM_SRC macos.c) find_library(APP_SERVICES_LIBRARY ApplicationServices) find_library(HID_LIB HidApi) set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} ${HID_LIB}) @@ -307,201 +313,36 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") endif() if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(SUBSURFACE_TARGET subsurface) - set(PLATFORM_SRC windows.c) set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} -lwsock32 -lws2_32) remove_definitions(-DUNICODE) add_definitions(-mwindows -D_WIN32) endif() +qt5_add_resources(SUBSURFACE_RESOURCES subsurface.qrc) + # include translations add_subdirectory(translations) - -if(BTSUPPORT) - add_definitions(-DBT_SUPPORT) - set(BT_SRC_FILES qt-ui/btdeviceselectiondialog.cpp) - set(BT_CORE_SRC_FILES qtserialbluetooth.cpp) -endif() - -# compile the core library, in C. -set(SUBSURFACE_CORE_LIB_SRCS - cochran.c - datatrak.c - deco.c - device.c - dive.c - divesite.c - divesite.cpp # some new stuff that is not c code but belongs to divesite. - divelist.c - equipment.c - file.c - git-access.c - libdivecomputer.c - liquivision.c - load-git.c - membuffer.c - ostctools.c - parse-xml.c - planner.c - profile.c - gaspressures.c - worldmap-save.c - save-git.c - save-xml.c - save-html.c - sha1.c - statistics.c - strtod.c - subsurfacestartup.c - time.c - uemis.c - uemis-downloader.c - version.c - # gettextfrommoc should be added because we are using it on the c-code. - gettextfromc.cpp - # dirk ported some core functionality to c++. - qthelper.cpp - divecomputer.cpp - exif.cpp - subsurfacesysinfo.cpp - devicedetails.cpp - configuredivecomputer.cpp - configuredivecomputerthreads.cpp - divesitehelpers.cpp - taxonomy.c - checkcloudconnection.cpp - windowtitleupdate.cpp - divelogexportlogic.cpp - qt-init.cpp - ${BT_CORE_SRC_FILES} - ${SERIAL_FTDI} - ${PLATFORM_SRC} -) -source_group("Subsurface Core" FILES ${SUBSURFACE_CORE_LIB_SRCS}) +add_subdirectory(subsurface-core) +add_subdirectory(qt-models) +add_subdirectory(profile-widget) +add_subdirectory(desktop-widgets) if(FBSUPPORT) add_definitions(-DFBSUPPORT) - set(SOCIALNETWORKS qt-ui/socialnetworks.cpp) endif() -# the data models that will interface -# with the views. -set(SUBSURFACE_MODELS_LIB_SRCS - qt-models/cleanertablemodel.cpp - qt-models/cylindermodel.cpp - qt-models/diveplannermodel.cpp - qt-models/models.cpp - qt-models/filtermodels.cpp - qt-models/tankinfomodel.cpp - qt-models/weigthsysteminfomodel.cpp - qt-models/weightmodel.cpp - qt-models/divecomputermodel.cpp - qt-models/treemodel.cpp - qt-models/tableprintmodel.cpp - qt-models/yearlystatisticsmodel.cpp - qt-models/divetripmodel.cpp - qt-models/divecomputerextradatamodel.cpp - qt-models/completionmodels.cpp - qt-models/profileprintmodel.cpp - qt-models/divepicturemodel.cpp - qt-models/diveplotdatamodel.cpp - qt-models/divelocationmodel.cpp - qt-models/divesitepicturesmodel.cpp - qt-models/ssrfsortfilterproxymodel.cpp -) -source_group("Subsurface Models" FILES ${SUBSURFACE_MODELS}) - -# the interface, in C++ -set(SUBSURFACE_INTERFACE - qt-ui/updatemanager.cpp - qt-ui/about.cpp - qt-ui/divecomputermanagementdialog.cpp - qt-ui/divelistview.cpp - qt-ui/diveplanner.cpp - qt-ui/diveshareexportdialog.cpp - qt-ui/downloadfromdivecomputer.cpp - qt-ui/globe.cpp - qt-ui/graphicsview-common.cpp - qt-ui/kmessagewidget.cpp - qt-ui/maintab.cpp - qt-ui/mainwindow.cpp - qt-ui/modeldelegates.cpp - qt-ui/metrics.cpp - qt-ui/notificationwidget.cpp - qt-ui/preferences.cpp - qt-ui/simplewidgets.cpp - qt-ui/starwidget.cpp - qt-ui/subsurfacewebservices.cpp - qt-ui/tableview.cpp - qt-ui/divelogimportdialog.cpp - qt-ui/tagwidget.cpp - qt-ui/groupedlineedit.cpp - ${USERMANUAL} - qt-ui/divelogexportdialog.cpp - qt-ui/divepicturewidget.cpp - qt-ui/usersurvey.cpp - qt-ui/configuredivecomputerdialog.cpp - qt-ui/undocommands.cpp - qt-ui/locationinformation.cpp - qt-ui/qtwaitingspinner.cpp - ${SUBSURFACE_PRINTING_SRCS} - ${SOCIALNETWORKS} - ${BT_SRC_FILES} -) -source_group("Subsurface Interface" FILES ${SUBSURFACE_INTERFACE}) - -# the profile widget -set(SUBSURFACE_PROFILE_LIB_SRCS - qt-ui/profile/profilewidget2.cpp - qt-ui/profile/diverectitem.cpp - qt-ui/profile/divepixmapitem.cpp - qt-ui/profile/divelineitem.cpp - qt-ui/profile/divetextitem.cpp - qt-ui/profile/animationfunctions.cpp - qt-ui/profile/divecartesianaxis.cpp - qt-ui/profile/diveprofileitem.cpp - qt-ui/profile/diveeventitem.cpp - qt-ui/profile/divetooltipitem.cpp - qt-ui/profile/ruleritem.cpp - qt-ui/profile/tankitem.cpp -) -source_group("Subsurface Profile" FILES ${SUBSURFACE_PROFILE_LIB_SRCS}) - -# the yearly statistics widget. -set(SUBSURFACE_STATISTICS_LIB_SRCS - qt-ui/statistics/statisticswidget.cpp - qt-ui/statistics/yearstatistics.cpp - qt-ui/statistics/statisticsbar.cpp - qt-ui/statistics/monthstatistics.cpp -) -source_group("Subsurface Statistics" FILES ${SUBSURFACE_STATISTICS_LIB_SRCS}) +if(BTSUPPORT) + add_definitions(-DBT_SUPPORT) +endif() # the main app. set(SUBSURFACE_APP - main.cpp - qt-gui.cpp - qthelper.cpp + subsurface-desktop-main.cpp + subsurface-desktop-helper.cpp ) + source_group("Subsurface App" FILES ${SUBSURFACE_APP}) -# create the libraries -file(GLOB SUBSURFACE_UI qt-ui/*.ui) -qt5_wrap_ui(SUBSURFACE_UI_HDRS ${SUBSURFACE_UI}) -qt5_add_resources(SUBSURFACE_RESOURCES subsurface.qrc) -source_group("Subsurface Interface Files" FILES ${SUBSURFACE_UI}) - -add_library(subsurface_corelib STATIC ${SUBSURFACE_CORE_LIB_SRCS} ) -target_link_libraries(subsurface_corelib ${QT_LIBRARIES}) -add_library(subsurface_models STATIC ${SUBSURFACE_MODELS_LIB_SRCS}) -target_link_libraries(subsurface_models ${QT_LIBRARIES}) -add_library(subsurface_profile STATIC ${SUBSURFACE_PROFILE_LIB_SRCS}) -target_link_libraries(subsurface_profile ${QT_LIBRARIES}) -add_library(subsurface_statistics STATIC ${SUBSURFACE_STATISTICS_LIB_SRCS}) -target_link_libraries(subsurface_statistics ${QT_LIBRARIES}) -add_library(subsurface_generated_ui STATIC ${SUBSURFACE_UI_HDRS}) -target_link_libraries(subsurface_generated_ui ${QT_LIBRARIES}) -add_library(subsurface_interface STATIC ${SUBSURFACE_INTERFACE}) -target_link_libraries(subsurface_interface ${QT_LIBRARIES} ${MARBLE_LIBRARIES}) - # add pthread to the end of the library list on Linux # this is only needed on Ubuntu (why do these idiots break everything?) # but shouldn't hurt on other Linux versions @@ -511,13 +352,19 @@ endif() # 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 @@ -528,26 +375,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) @@ -568,32 +416,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") endif() # build an automated html exporter -add_executable(export-html EXCLUDE_FROM_ALL export-html.cpp qt-init.cpp qthelper.cpp ${SUBSURFACE_RESOURCES}) +add_executable(export-html EXCLUDE_FROM_ALL export-html.cpp ${SUBSURFACE_RESOURCES}) target_link_libraries(export-html subsurface_corelib ${SUBSURFACE_LINK_LIBRARIES}) -# QTest based tests -macro(TEST NAME FILE) - add_executable(${NAME} EXCLUDE_FROM_ALL tests/${FILE} ${SUBSURFACE_RESOURCES}) - target_link_libraries(${NAME} subsurface_corelib ${QT_TEST_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES}) - add_test(NAME ${NAME}_build COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${NAME}) - add_test(NAME ${NAME}_run COMMAND ${NAME}) - set_tests_properties(${NAME}_run PROPERTIES DEPENDS ${NAME}_build) -endmacro() - -add_definitions(-DSUBSURFACE_SOURCE="${CMAKE_SOURCE_DIR}") -add_definitions(-g) -if(NOT NO_TESTS) - enable_testing() - TEST(TestUnitConversion testunitconversion.cpp) - TEST(TestProfile testprofile.cpp) - TEST(TestGpsCoords testgpscoords.cpp) - TEST(TestParse testparse.cpp) - TEST(TestPlan testplan.cpp) - TEST(TestDiveSiteDuplication testdivesiteduplication.cpp) - TEST(TestRenumber testrenumber.cpp) - TEST(TestGitStorage testgitstorage.cpp) -endif() - # install a few things so that one can run Subsurface from the build # directory if(NOT insource) @@ -804,7 +629,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") install(DIRECTORY marbledata/bitmaps DESTINATION share/subsurface/data) install(FILES subsurface.debug DESTINATION bin) install(FILES subsurface.desktop DESTINATION share/applications) - install(FILES subsurface-icon.svg DESTINATION share/icons/hicolor/scalable/apps) + install(FILES icons/subsurface-icon.svg DESTINATION share/icons/hicolor/scalable/apps) install(DIRECTORY Documentation/images DESTINATION share/subsurface/Documentation) install(FILES ${DOCFILES} DESTINATION share/subsurface/Documentation) install(DIRECTORY theme DESTINATION share/subsurface) @@ -822,7 +647,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") ) endif() endif() + # get_cmake_property(_variableNames VARIABLES) # foreach (_variableName ${_variableNames}) # message(STATUS "${_variableName}=${${_variableName}}") # endforeach() + +if (MAKE_TESTS) + add_subdirectory(tests) +endif() diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt new file mode 100644 index 000000000..0a0059ee3 --- /dev/null +++ b/desktop-widgets/CMakeLists.txt @@ -0,0 +1,93 @@ +# create the libraries +file(GLOB SUBSURFACE_UI *.ui) +qt5_wrap_ui(SUBSURFACE_UI_HDRS ${SUBSURFACE_UI}) +source_group("Subsurface Interface Files" FILES ${SUBSURFACE_UI}) + +if(BTSUPPORT) + set(BT_SRC_FILES btdeviceselectiondialog.cpp) +endif() + +include_directories(. + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} +) + +add_subdirectory(preferences) +add_subdirectory(plugins) + +# the interface, in C++ +set(SUBSURFACE_INTERFACE + updatemanager.cpp + about.cpp + divecomputermanagementdialog.cpp + divelistview.cpp + diveplanner.cpp + diveshareexportdialog.cpp + downloadfromdivecomputer.cpp + globe.cpp + kmessagewidget.cpp + maintab.cpp + mainwindow.cpp + modeldelegates.cpp + notificationwidget.cpp + simplewidgets.cpp + starwidget.cpp + subsurfacewebservices.cpp + tableview.cpp + divelogimportdialog.cpp + tagwidget.cpp + groupedlineedit.cpp + divelogexportdialog.cpp + divepicturewidget.cpp + usersurvey.cpp + configuredivecomputerdialog.cpp + undocommands.cpp + locationinformation.cpp + qtwaitingspinner.cpp +) + +if(NOT NO_USERMANUAL) + set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE} + usermanual.cpp + ) +endif() + +if(NOT NO_PRINTING) + set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE} + templateedit.cpp + printdialog.cpp + printoptions.cpp + printer.cpp + templatelayout.cpp + ) +endif() + +if (FBSUPPORT) + set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE} + socialnetworks.cpp + ) +endif() + +if (BTSUPPORT) + set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE} + btdeviceselectiondialog.cpp + ) +endif() + +source_group("Subsurface Interface" FILES ${SUBSURFACE_INTERFACE}) + +# the yearly statistics widget. +set(SUBSURFACE_STATISTICS_LIB_SRCS + statistics/statisticswidget.cpp + statistics/yearstatistics.cpp + statistics/statisticsbar.cpp + statistics/monthstatistics.cpp +) +source_group("Subsurface Statistics" FILES ${SUBSURFACE_STATISTICS_LIB_SRCS}) + +add_library(subsurface_statistics STATIC ${SUBSURFACE_STATISTICS_LIB_SRCS}) +target_link_libraries(subsurface_statistics ${QT_LIBRARIES}) +add_library(subsurface_generated_ui STATIC ${SUBSURFACE_UI_HDRS}) +target_link_libraries(subsurface_generated_ui ${QT_LIBRARIES}) +add_library(subsurface_interface STATIC ${SUBSURFACE_INTERFACE}) +target_link_libraries(subsurface_interface ${QT_LIBRARIES} ${MARBLE_LIBRARIES} subsurface_desktop_preferences) diff --git a/qt-ui/about.cpp b/desktop-widgets/about.cpp similarity index 100% rename from qt-ui/about.cpp rename to desktop-widgets/about.cpp diff --git a/qt-ui/about.h b/desktop-widgets/about.h similarity index 100% rename from qt-ui/about.h rename to desktop-widgets/about.h diff --git a/qt-ui/about.ui b/desktop-widgets/about.ui similarity index 100% rename from qt-ui/about.ui rename to desktop-widgets/about.ui diff --git a/qt-ui/btdeviceselectiondialog.cpp b/desktop-widgets/btdeviceselectiondialog.cpp similarity index 100% rename from qt-ui/btdeviceselectiondialog.cpp rename to desktop-widgets/btdeviceselectiondialog.cpp diff --git a/qt-ui/btdeviceselectiondialog.h b/desktop-widgets/btdeviceselectiondialog.h similarity index 100% rename from qt-ui/btdeviceselectiondialog.h rename to desktop-widgets/btdeviceselectiondialog.h diff --git a/qt-ui/btdeviceselectiondialog.ui b/desktop-widgets/btdeviceselectiondialog.ui similarity index 100% rename from qt-ui/btdeviceselectiondialog.ui rename to desktop-widgets/btdeviceselectiondialog.ui diff --git a/qt-ui/configuredivecomputerdialog.cpp b/desktop-widgets/configuredivecomputerdialog.cpp similarity index 100% rename from qt-ui/configuredivecomputerdialog.cpp rename to desktop-widgets/configuredivecomputerdialog.cpp diff --git a/qt-ui/configuredivecomputerdialog.h b/desktop-widgets/configuredivecomputerdialog.h similarity index 98% rename from qt-ui/configuredivecomputerdialog.h rename to desktop-widgets/configuredivecomputerdialog.h index be76644a9..9ad30ac67 100644 --- a/qt-ui/configuredivecomputerdialog.h +++ b/desktop-widgets/configuredivecomputerdialog.h @@ -4,7 +4,7 @@ #include #include #include "ui_configuredivecomputerdialog.h" -#include "../libdivecomputer.h" +#include "subsurface-core/libdivecomputer.h" #include "configuredivecomputer.h" #include #include diff --git a/qt-ui/configuredivecomputerdialog.ui b/desktop-widgets/configuredivecomputerdialog.ui similarity index 100% rename from qt-ui/configuredivecomputerdialog.ui rename to desktop-widgets/configuredivecomputerdialog.ui diff --git a/qt-ui/css/tableviews.css b/desktop-widgets/css/tableviews.css similarity index 100% rename from qt-ui/css/tableviews.css rename to desktop-widgets/css/tableviews.css diff --git a/qt-ui/divecomponentselection.ui b/desktop-widgets/divecomponentselection.ui similarity index 100% rename from qt-ui/divecomponentselection.ui rename to desktop-widgets/divecomponentselection.ui diff --git a/qt-ui/divecomputermanagementdialog.cpp b/desktop-widgets/divecomputermanagementdialog.cpp similarity index 100% rename from qt-ui/divecomputermanagementdialog.cpp rename to desktop-widgets/divecomputermanagementdialog.cpp diff --git a/qt-ui/divecomputermanagementdialog.h b/desktop-widgets/divecomputermanagementdialog.h similarity index 100% rename from qt-ui/divecomputermanagementdialog.h rename to desktop-widgets/divecomputermanagementdialog.h diff --git a/qt-ui/divecomputermanagementdialog.ui b/desktop-widgets/divecomputermanagementdialog.ui similarity index 100% rename from qt-ui/divecomputermanagementdialog.ui rename to desktop-widgets/divecomputermanagementdialog.ui diff --git a/qt-ui/divelistview.cpp b/desktop-widgets/divelistview.cpp similarity index 100% rename from qt-ui/divelistview.cpp rename to desktop-widgets/divelistview.cpp diff --git a/qt-ui/divelistview.h b/desktop-widgets/divelistview.h similarity index 100% rename from qt-ui/divelistview.h rename to desktop-widgets/divelistview.h diff --git a/qt-ui/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp similarity index 100% rename from qt-ui/divelogexportdialog.cpp rename to desktop-widgets/divelogexportdialog.cpp diff --git a/qt-ui/divelogexportdialog.h b/desktop-widgets/divelogexportdialog.h similarity index 100% rename from qt-ui/divelogexportdialog.h rename to desktop-widgets/divelogexportdialog.h diff --git a/qt-ui/divelogexportdialog.ui b/desktop-widgets/divelogexportdialog.ui similarity index 100% rename from qt-ui/divelogexportdialog.ui rename to desktop-widgets/divelogexportdialog.ui diff --git a/qt-ui/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp similarity index 100% rename from qt-ui/divelogimportdialog.cpp rename to desktop-widgets/divelogimportdialog.cpp diff --git a/qt-ui/divelogimportdialog.h b/desktop-widgets/divelogimportdialog.h similarity index 97% rename from qt-ui/divelogimportdialog.h rename to desktop-widgets/divelogimportdialog.h index 03bb14029..2d12c7cac 100644 --- a/qt-ui/divelogimportdialog.h +++ b/desktop-widgets/divelogimportdialog.h @@ -9,8 +9,8 @@ #include #include -#include "../dive.h" -#include "../divelist.h" +#include "subsurface-core/dive.h" +#include "subsurface-core/divelist.h" namespace Ui { class DiveLogImportDialog; diff --git a/qt-ui/divelogimportdialog.ui b/desktop-widgets/divelogimportdialog.ui similarity index 100% rename from qt-ui/divelogimportdialog.ui rename to desktop-widgets/divelogimportdialog.ui diff --git a/qt-ui/divepicturewidget.cpp b/desktop-widgets/divepicturewidget.cpp similarity index 100% rename from qt-ui/divepicturewidget.cpp rename to desktop-widgets/divepicturewidget.cpp diff --git a/qt-ui/divepicturewidget.h b/desktop-widgets/divepicturewidget.h similarity index 100% rename from qt-ui/divepicturewidget.h rename to desktop-widgets/divepicturewidget.h diff --git a/qt-ui/diveplanner.cpp b/desktop-widgets/diveplanner.cpp similarity index 99% rename from qt-ui/diveplanner.cpp rename to desktop-widgets/diveplanner.cpp index b4413d11a..fd14944f0 100644 --- a/qt-ui/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -5,7 +5,7 @@ #include "helpers.h" #include "cylindermodel.h" #include "models.h" -#include "profile/profilewidget2.h" +#include "profile-widget/profilewidget2.h" #include "diveplannermodel.h" #include @@ -104,7 +104,7 @@ void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { ui.setupUi(this); - ui.dateEdit->setDisplayFormat(getDateFormat()); + ui.dateEdit->setDisplayFormat(prefs.date_format); ui.tableWidget->setTitle(tr("Dive planner points")); ui.tableWidget->setModel(plannerModel); plannerModel->setRecalc(true); @@ -328,11 +328,11 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f) modeMapper->setMapping(ui.recreational_deco, int(RECREATIONAL)); modeMapper->setMapping(ui.buehlmann_deco, int(BUEHLMANN)); modeMapper->setMapping(ui.vpmb_deco, int(VPMB)); - + connect(ui.recreational_deco, SIGNAL(clicked()), modeMapper, SLOT(map())); connect(ui.buehlmann_deco, SIGNAL(clicked()), modeMapper, SLOT(map())); connect(ui.vpmb_deco, SIGNAL(clicked()), modeMapper, SLOT(map())); - + connect(ui.lastStop, SIGNAL(toggled(bool)), plannerModel, SLOT(setLastStop6m(bool))); connect(ui.verbatim_plan, SIGNAL(toggled(bool)), plannerModel, SLOT(setVerbatim(bool))); connect(ui.display_duration, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayDuration(bool))); diff --git a/qt-ui/diveplanner.h b/desktop-widgets/diveplanner.h similarity index 100% rename from qt-ui/diveplanner.h rename to desktop-widgets/diveplanner.h diff --git a/qt-ui/diveplanner.ui b/desktop-widgets/diveplanner.ui similarity index 100% rename from qt-ui/diveplanner.ui rename to desktop-widgets/diveplanner.ui diff --git a/qt-ui/diveshareexportdialog.cpp b/desktop-widgets/diveshareexportdialog.cpp similarity index 100% rename from qt-ui/diveshareexportdialog.cpp rename to desktop-widgets/diveshareexportdialog.cpp diff --git a/qt-ui/diveshareexportdialog.h b/desktop-widgets/diveshareexportdialog.h similarity index 100% rename from qt-ui/diveshareexportdialog.h rename to desktop-widgets/diveshareexportdialog.h diff --git a/qt-ui/diveshareexportdialog.ui b/desktop-widgets/diveshareexportdialog.ui similarity index 100% rename from qt-ui/diveshareexportdialog.ui rename to desktop-widgets/diveshareexportdialog.ui diff --git a/qt-ui/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp similarity index 100% rename from qt-ui/downloadfromdivecomputer.cpp rename to desktop-widgets/downloadfromdivecomputer.cpp diff --git a/qt-ui/downloadfromdivecomputer.h b/desktop-widgets/downloadfromdivecomputer.h similarity index 100% rename from qt-ui/downloadfromdivecomputer.h rename to desktop-widgets/downloadfromdivecomputer.h diff --git a/qt-ui/downloadfromdivecomputer.ui b/desktop-widgets/downloadfromdivecomputer.ui similarity index 100% rename from qt-ui/downloadfromdivecomputer.ui rename to desktop-widgets/downloadfromdivecomputer.ui diff --git a/qt-ui/filterwidget.ui b/desktop-widgets/filterwidget.ui similarity index 100% rename from qt-ui/filterwidget.ui rename to desktop-widgets/filterwidget.ui diff --git a/qt-ui/globe.cpp b/desktop-widgets/globe.cpp similarity index 100% rename from qt-ui/globe.cpp rename to desktop-widgets/globe.cpp diff --git a/qt-ui/globe.h b/desktop-widgets/globe.h similarity index 100% rename from qt-ui/globe.h rename to desktop-widgets/globe.h diff --git a/qt-ui/groupedlineedit.cpp b/desktop-widgets/groupedlineedit.cpp similarity index 100% rename from qt-ui/groupedlineedit.cpp rename to desktop-widgets/groupedlineedit.cpp diff --git a/qt-ui/groupedlineedit.h b/desktop-widgets/groupedlineedit.h similarity index 100% rename from qt-ui/groupedlineedit.h rename to desktop-widgets/groupedlineedit.h diff --git a/qt-ui/kmessagewidget.cpp b/desktop-widgets/kmessagewidget.cpp similarity index 100% rename from qt-ui/kmessagewidget.cpp rename to desktop-widgets/kmessagewidget.cpp diff --git a/qt-ui/kmessagewidget.h b/desktop-widgets/kmessagewidget.h similarity index 100% rename from qt-ui/kmessagewidget.h rename to desktop-widgets/kmessagewidget.h diff --git a/qt-ui/listfilter.ui b/desktop-widgets/listfilter.ui similarity index 100% rename from qt-ui/listfilter.ui rename to desktop-widgets/listfilter.ui diff --git a/qt-ui/locationInformation.ui b/desktop-widgets/locationInformation.ui similarity index 100% rename from qt-ui/locationInformation.ui rename to desktop-widgets/locationInformation.ui diff --git a/qt-ui/locationinformation.cpp b/desktop-widgets/locationinformation.cpp similarity index 100% rename from qt-ui/locationinformation.cpp rename to desktop-widgets/locationinformation.cpp diff --git a/qt-ui/locationinformation.h b/desktop-widgets/locationinformation.h similarity index 100% rename from qt-ui/locationinformation.h rename to desktop-widgets/locationinformation.h diff --git a/qt-ui/maintab.cpp b/desktop-widgets/maintab.cpp similarity index 99% rename from qt-ui/maintab.cpp rename to desktop-widgets/maintab.cpp index 0afb7b4c0..c7961735a 100644 --- a/qt-ui/maintab.cpp +++ b/desktop-widgets/maintab.cpp @@ -13,7 +13,7 @@ #include "diveplannermodel.h" #include "divelistview.h" #include "display.h" -#include "profile/profilewidget2.h" +#include "profile-widget/profilewidget2.h" #include "diveplanner.h" #include "divesitehelpers.h" #include "cylindermodel.h" @@ -43,7 +43,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), currentTrip(0) { ui.setupUi(this); - ui.dateEdit->setDisplayFormat(getDateFormat()); + ui.dateEdit->setDisplayFormat(prefs.date_format); memset(&displayed_dive, 0, sizeof(displayed_dive)); memset(&displayedTrip, 0, sizeof(displayedTrip)); diff --git a/qt-ui/maintab.h b/desktop-widgets/maintab.h similarity index 100% rename from qt-ui/maintab.h rename to desktop-widgets/maintab.h diff --git a/qt-ui/maintab.ui b/desktop-widgets/maintab.ui similarity index 99% rename from qt-ui/maintab.ui rename to desktop-widgets/maintab.ui index 2c515a225..7bc516b1a 100644 --- a/qt-ui/maintab.ui +++ b/desktop-widgets/maintab.ui @@ -525,8 +525,8 @@ 0 0 - 70 - 16 + 445 + 754 @@ -1229,7 +1229,7 @@ TagWidget QPlainTextEdit -
qt-ui/tagwidget.h
+
tagwidget.h
DivePictureWidget diff --git a/qt-ui/mainwindow.cpp b/desktop-widgets/mainwindow.cpp similarity index 97% rename from qt-ui/mainwindow.cpp rename to desktop-widgets/mainwindow.cpp index e0476381f..dc45d1d8d 100644 --- a/qt-ui/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -11,17 +11,17 @@ #include #include #include + #include "version.h" #include "divelistview.h" #include "downloadfromdivecomputer.h" -#include "preferences.h" #include "subsurfacewebservices.h" #include "divecomputermanagementdialog.h" #include "about.h" #include "updatemanager.h" #include "planner.h" #include "filtermodels.h" -#include "profile/profilewidget2.h" +#include "profile-widget/profilewidget2.h" #include "globe.h" #include "divecomputer.h" #include "maintab.h" @@ -40,6 +40,7 @@ #include "divesitehelpers.h" #include "windowtitleupdate.h" #include "locationinformation.h" +#include "preferences/preferencesdialog.h" #ifndef NO_USERMANUAL #include "usermanual.h" @@ -50,6 +51,9 @@ #include #include #include +#include "subsurface-core/color.h" +#include "subsurface-core/isocialnetworkintegration.h" +#include "subsurface-core/pluginmanager.h" #if defined(FBSUPPORT) #include "socialnetworks.h" @@ -250,6 +254,26 @@ MainWindow::MainWindow() : QMainWindow(), ui.actionFacebook->setEnabled(false); #endif + if(PluginManager::instance().socialNetworkIntegrationPlugins().count()) { + QMenu *connections = new QMenu(tr("Connect to")); + for(ISocialNetworkIntegration *plugin : PluginManager::instance().socialNetworkIntegrationPlugins()){ + QAction *toggle_connection = new QAction(this); + toggle_connection->setText(plugin->socialNetworkName()); + toggle_connection->setIcon(QIcon(plugin->socialNetworkIcon())); + toggle_connection->setData(QVariant::fromValue(plugin)); + + QAction *share_on = new QAction(this); + share_on->setText(plugin->socialNetworkName()); + share_on->setIcon(QIcon(plugin->socialNetworkIcon())); + share_on->setData(QVariant::fromValue(plugin)); + ui.menuShare_on->addAction(share_on); + connections->addAction(toggle_connection); + } + ui.menuShare_on->addSeparator(); + ui.menuShare_on->addMenu(connections); + } else { + ui.menubar->removeAction(ui.menuShare_on->menuAction()); + } ui.menubar->show(); set_git_update_cb(&updateProgress); @@ -1164,7 +1188,7 @@ void MainWindow::initialUiSetup() show(); } -const char *getSetting(QSettings &s, QString name) +const char *getSetting(const QSettings &s,const QString& name) { QVariant v; v = s.value(name); @@ -1758,6 +1782,7 @@ void MainWindow::editCurrentDive() } } +// TODO: Remove the dependency to the PreferencesDialog here. #define PREF_PROFILE(QT_PREFS) \ QSettings s; \ s.beginGroup("TecDetails"); \ @@ -1897,8 +1922,7 @@ void MainWindow::setApplicationState(const QByteArray& state) { void MainWindow::showProgressBar() { - if (progressDialog) - delete progressDialog; + delete progressDialog; progressDialog = new QProgressDialog(tr("Contacting cloud service..."), tr("Cancel"), 0, 100, this); progressDialog->setWindowModality(Qt::WindowModal); diff --git a/qt-ui/mainwindow.h b/desktop-widgets/mainwindow.h similarity index 100% rename from qt-ui/mainwindow.h rename to desktop-widgets/mainwindow.h diff --git a/qt-ui/mainwindow.ui b/desktop-widgets/mainwindow.ui similarity index 99% rename from qt-ui/mainwindow.ui rename to desktop-widgets/mainwindow.ui index 5e3200cfc..c62e1df7f 100644 --- a/qt-ui/mainwindow.ui +++ b/desktop-widgets/mainwindow.ui @@ -142,7 +142,6 @@ Share on - diff --git a/qt-ui/marble/GeoDataTreeModel.h b/desktop-widgets/marble/GeoDataTreeModel.h similarity index 100% rename from qt-ui/marble/GeoDataTreeModel.h rename to desktop-widgets/marble/GeoDataTreeModel.h diff --git a/qt-ui/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp similarity index 99% rename from qt-ui/modeldelegates.cpp rename to desktop-widgets/modeldelegates.cpp index 881037a83..1b1a31c0b 100644 --- a/qt-ui/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -5,7 +5,7 @@ #include "cylindermodel.h" #include "models.h" #include "starwidget.h" -#include "profile/profilewidget2.h" +#include "profile-widget/profilewidget2.h" #include "tankinfomodel.h" #include "weigthsysteminfomodel.h" #include "weightmodel.h" diff --git a/qt-ui/modeldelegates.h b/desktop-widgets/modeldelegates.h similarity index 100% rename from qt-ui/modeldelegates.h rename to desktop-widgets/modeldelegates.h diff --git a/qt-ui/notificationwidget.cpp b/desktop-widgets/notificationwidget.cpp similarity index 100% rename from qt-ui/notificationwidget.cpp rename to desktop-widgets/notificationwidget.cpp diff --git a/qt-ui/notificationwidget.h b/desktop-widgets/notificationwidget.h similarity index 100% rename from qt-ui/notificationwidget.h rename to desktop-widgets/notificationwidget.h diff --git a/qt-ui/plannerDetails.ui b/desktop-widgets/plannerDetails.ui similarity index 100% rename from qt-ui/plannerDetails.ui rename to desktop-widgets/plannerDetails.ui diff --git a/qt-ui/plannerSettings.ui b/desktop-widgets/plannerSettings.ui similarity index 100% rename from qt-ui/plannerSettings.ui rename to desktop-widgets/plannerSettings.ui diff --git a/desktop-widgets/plugins/CMakeLists.txt b/desktop-widgets/plugins/CMakeLists.txt new file mode 100644 index 000000000..f424e172e --- /dev/null +++ b/desktop-widgets/plugins/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(facebook) \ No newline at end of file diff --git a/desktop-widgets/plugins/facebook/CMakeLists.txt b/desktop-widgets/plugins/facebook/CMakeLists.txt new file mode 100644 index 000000000..8628bd070 --- /dev/null +++ b/desktop-widgets/plugins/facebook/CMakeLists.txt @@ -0,0 +1,6 @@ +set(FACEBOOK_PLUGIN_SRCS facebook_integration.cpp) + +add_library(facebook_integration SHARED ${FACEBOOK_PLUGIN_SRCS}) + +target_link_libraries(facebook_integration subsurface_corelib ${QT_LIBRARIES}) +add_dependencies(facebook_integration subsurface_corelib) \ No newline at end of file diff --git a/desktop-widgets/plugins/facebook/facebook_integration.cpp b/desktop-widgets/plugins/facebook/facebook_integration.cpp new file mode 100644 index 000000000..e9b2297a0 --- /dev/null +++ b/desktop-widgets/plugins/facebook/facebook_integration.cpp @@ -0,0 +1,36 @@ +#include "facebook_integration.h" + +FacebookPlugin::FacebookPlugin(QObject* parent): QObject(parent) +{ + +} + +bool FacebookPlugin::isConnected() +{ + +} + +void FacebookPlugin::requestLogin() +{ + +} + +void FacebookPlugin::requestLogoff() +{ + +} + +QString FacebookPlugin::socialNetworkIcon() const +{ + return QString(); +} + +QString FacebookPlugin::socialNetworkName() const +{ + return tr("Facebook"); +} + +void FacebookPlugin::uploadCurrentDive() +{ + +} diff --git a/desktop-widgets/plugins/facebook/facebook_integration.h b/desktop-widgets/plugins/facebook/facebook_integration.h new file mode 100644 index 000000000..a9d212e7e --- /dev/null +++ b/desktop-widgets/plugins/facebook/facebook_integration.h @@ -0,0 +1,21 @@ +#ifndef FACEBOOK_INTEGRATION_H +#define FACEBOOK_INTEGRATION_H + +#include "subsurface-core/isocialnetworkintegration.h" +#include + +class FacebookPlugin : public QObject, public ISocialNetworkIntegration { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.subsurface.plugins.ISocialNetworkIntegration") + Q_INTERFACES(ISocialNetworkIntegration) +public: + explicit FacebookPlugin(QObject* parent = 0); + virtual bool isConnected(); + virtual void requestLogin(); + virtual void requestLogoff(); + virtual QString socialNetworkIcon() const; + virtual QString socialNetworkName() const; + virtual void uploadCurrentDive(); +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp new file mode 100644 index 000000000..29e9d2458 --- /dev/null +++ b/desktop-widgets/preferences.cpp @@ -0,0 +1,173 @@ +#include "preferences.h" +#include "mainwindow.h" +#include "models.h" +#include "divelocationmodel.h" +#include "prefs-macros.h" +#include "qthelper.h" +#include "subsurfacestartup.h" + +#include +#include +#include +#include +#include +#include + +#include "subsurfacewebservices.h" + +#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) +#include "socialnetworks.h" +#include +#endif + +PreferencesDialog *PreferencesDialog::instance() +{ + static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance()); + return dialog; +} + +PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) +{ + ui.setupUi(this); + setAttribute(Qt::WA_QuitOnClose, false); + +#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) + FacebookManager *fb = FacebookManager::instance(); + facebookWebView = new QWebView(this); + ui.fbWebviewContainer->layout()->addWidget(facebookWebView); + if (fb->loggedIn()) { + facebookLoggedIn(); + } else { + facebookDisconnect(); + } + connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin); + connect(fb, &FacebookManager::justLoggedIn, this, &PreferencesDialog::facebookLoggedIn); + connect(ui.fbDisconnect, &QPushButton::clicked, fb, &FacebookManager::logout); + connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect); +#endif + + connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); + + // connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double))); + QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); + connect(close, SIGNAL(activated()), this, SLOT(close())); + QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); + connect(quit, SIGNAL(activated()), parent, SLOT(close())); + loadSettings(); + setUiFromPrefs(); + rememberPrefs(); +} + +void PreferencesDialog::facebookLoggedIn() +{ +#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) + ui.fbDisconnect->show(); + ui.fbWebviewContainer->hide(); + ui.fbWebviewContainer->setEnabled(false); + ui.FBLabel->setText(tr("To disconnect Subsurface from your Facebook account, use the button below")); +#endif +} + +void PreferencesDialog::facebookDisconnect() +{ +#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) + // remove the connect/disconnect button + // and instead add the login view + ui.fbDisconnect->hide(); + ui.fbWebviewContainer->show(); + ui.fbWebviewContainer->setEnabled(true); + ui.FBLabel->setText(tr("To connect to Facebook, please log in. This enables Subsurface to publish dives to your timeline")); + if (facebookWebView) { + facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar()); + facebookWebView->setUrl(FacebookManager::instance()->connectUrl()); + } +#endif +} + +void PreferencesDialog::showEvent(QShowEvent *event) +{ + setUiFromPrefs(); + rememberPrefs(); + QDialog::showEvent(event); +} + +void PreferencesDialog::setUiFromPrefs() +{ + +} + +void PreferencesDialog::restorePrefs() +{ + prefs = oldPrefs; + setUiFromPrefs(); +} + +void PreferencesDialog::rememberPrefs() +{ + oldPrefs = prefs; +} + +void PreferencesDialog::syncSettings() +{ +} + +void PreferencesDialog::loadSettings() +{ + // This code was on the mainwindow, it should belong nowhere, but since we didn't + // correctly fixed this code yet ( too much stuff on the code calling preferences ) + // force this here. + loadPreferences(); + QSettings s; + QVariant v; +} + +void PreferencesDialog::buttonClicked(QAbstractButton *button) +{ + switch (ui.buttonBox->standardButton(button)) { + case QDialogButtonBox::Discard: + restorePrefs(); + syncSettings(); + close(); + break; + case QDialogButtonBox::Apply: + syncSettings(); + break; + case QDialogButtonBox::FirstButton: + syncSettings(); + close(); + break; + default: + break; // ignore warnings. + } +} +#undef SB + +#if 0 +// TODO: Copy this later. +void PreferencesDialog::on_resetSettings_clicked() +{ + QSettings s; + QMessageBox response(this); + response.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + response.setDefaultButton(QMessageBox::Cancel); + response.setWindowTitle(tr("Warning")); + response.setText(tr("If you click OK, all settings of Subsurface will be reset to their default values. This will be applied immediately.")); + response.setWindowModality(Qt::WindowModal); + + int result = response.exec(); + if (result == QMessageBox::Ok) { + copy_prefs(&default_prefs, &prefs); + setUiFromPrefs(); + Q_FOREACH (QString key, s.allKeys()) { + s.remove(key); + } + syncSettings(); + close(); + } +} +#endif + +void PreferencesDialog::emitSettingsChanged() +{ + emit settingsChanged(); +} diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui new file mode 100644 index 000000000..8d0b18900 --- /dev/null +++ b/desktop-widgets/preferences.ui @@ -0,0 +1,241 @@ + + + PreferencesDialog + + + + 0 + 0 + 835 + 698 + + + + Preferences + + + + :/subsurface-icon + + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + 0 + 0 + + + + + 120 + 0 + + + + + 120 + 16777215 + + + + + 24 + 24 + + + + Qt::ElideNone + + + QListView::Static + + + true + + + QListView::Batched + + + 0 + + + + 110 + 40 + + + + QListView::ListMode + + + true + + + true + + + -1 + + + + Facebook + + + + :/facebook + + + + + + + + + + 0 + 0 + + + + 0 + + + + + 0 + 0 + + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + + 0 + 0 + + + + Connect to facebook text placeholder + + + + + + + + + + + + Disconnect + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Discard|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PreferencesDialog + accept() + + + 264 + 720 + + + 157 + 274 + + + + + buttonBox + rejected() + PreferencesDialog + reject() + + + 332 + 720 + + + 286 + 274 + + + + + listWidget + currentRowChanged(int) + stackedWidget + setCurrentIndex(int) + + + 37 + 97 + + + 282 + 18 + + + + + diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt new file mode 100644 index 000000000..4e506ed73 --- /dev/null +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -0,0 +1,27 @@ +# the profile widget +include_directories(. + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} +) + +file(GLOB SUBSURFACE_PREFERENCES_UI *.ui) +qt5_wrap_ui(SUBSURFACE_PREFERENCES_UI_HDRS ${SUBSURFACE_PREFERENCES_UI}) + +source_group("Subsurface Interface Files" FILES ${SUBSURFACE_PREFERENCES_UI}) + +set(SUBSURFACE_PREFERENCES_LIB_SRCS + abstractpreferenceswidget.cpp + preferencesdialog.cpp + preferences_language.cpp + preferences_georeference.cpp + preferences_defaults.cpp + preferences_units.cpp + preferences_graph.cpp + preferences_network.cpp +) + +source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) + +add_library(subsurface_desktop_preferences STATIC ${SUBSURFACE_PREFERENCES_LIB_SRCS} ${SUBSURFACE_PREFERENCES_UI_HDRS}) +target_link_libraries(subsurface_desktop_preferences ${QT_LIBRARIES}) + diff --git a/desktop-widgets/preferences/abstractpreferenceswidget.cpp b/desktop-widgets/preferences/abstractpreferenceswidget.cpp new file mode 100644 index 000000000..9334c74ed --- /dev/null +++ b/desktop-widgets/preferences/abstractpreferenceswidget.cpp @@ -0,0 +1,21 @@ +#include "abstractpreferenceswidget.h" + +AbstractPreferencesWidget::AbstractPreferencesWidget(const QString& name, const QIcon& icon, float positionHeight) +: QWidget(), _name(name), _icon(icon), _positionHeight(positionHeight) +{ +} + +QIcon AbstractPreferencesWidget::icon() const +{ + return _icon; +} + +QString AbstractPreferencesWidget::name() const +{ + return _name; +} + +float AbstractPreferencesWidget::positionHeight() const +{ + return _positionHeight; +} diff --git a/desktop-widgets/preferences/abstractpreferenceswidget.h b/desktop-widgets/preferences/abstractpreferenceswidget.h new file mode 100644 index 000000000..2f607c4c9 --- /dev/null +++ b/desktop-widgets/preferences/abstractpreferenceswidget.h @@ -0,0 +1,27 @@ +#ifndef ABSTRACTPREFERENCESWIDGET_H +#define ABSTRACTPREFERENCESWIDGET_H + +#include +#include + +class AbstractPreferencesWidget : public QWidget { + Q_OBJECT +public: + AbstractPreferencesWidget(const QString& name, const QIcon& icon, float positionHeight); + QIcon icon() const; + QString name() const; + float positionHeight() const; + + /* gets the values from the preferences and should set the correct values in + * the interface */ + virtual void refreshSettings() = 0; + + /* gets the values from the interface and set in the preferences object. */ + virtual void syncSettings() = 0; + +private: + QIcon _icon; + QString _name; + float _positionHeight; +}; +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp new file mode 100644 index 000000000..45888ebec --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -0,0 +1,103 @@ +#include "preferences_defaults.h" +#include "ui_preferences_defaults.h" +#include "dive.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +PreferencesDefaults::PreferencesDefaults(): AbstractPreferencesWidget(tr("Defaults"), QIcon(":defaults"), 0 ), ui(new Ui::PreferencesDefaults()) +{ + ui->setupUi(this); +} + +PreferencesDefaults::~PreferencesDefaults() +{ + delete ui; +} + +void PreferencesDefaults::on_chooseFile_clicked() +{ + QFileInfo fi(system_default_filename()); + QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)")); + + if (!choosenFileName.isEmpty()) + ui->defaultfilename->setText(choosenFileName); +} + +void PreferencesDefaults::on_btnUseDefaultFile_toggled(bool toggle) +{ + if (toggle) { + ui->defaultfilename->setText(system_default_filename()); + ui->defaultfilename->setEnabled(false); + } else { + ui->defaultfilename->setEnabled(true); + } +} + +void PreferencesDefaults::on_localDefaultFile_toggled(bool toggle) +{ + ui->defaultfilename->setEnabled(toggle); + ui->btnUseDefaultFile->setEnabled(toggle); + ui->chooseFile->setEnabled(toggle); +} + +void PreferencesDefaults::refreshSettings() +{ + ui->font->setCurrentFont(QString(prefs.divelist_font)); + ui->fontsize->setValue(prefs.font_size); + ui->defaultfilename->setText(prefs.default_filename); + ui->noDefaultFile->setChecked(prefs.default_file_behavior == NO_DEFAULT_FILE); + ui->cloudDefaultFile->setChecked(prefs.default_file_behavior == CLOUD_DEFAULT_FILE); + ui->localDefaultFile->setChecked(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + + ui->default_cylinder->clear(); + for (int i = 0; tank_info[i].name != NULL; i++) { + ui->default_cylinder->addItem(tank_info[i].name); + if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0) + ui->default_cylinder->setCurrentIndex(i); + } + ui->displayinvalid->setChecked(prefs.display_invalid_dives); + ui->velocitySlider->setValue(prefs.animation_speed); + ui->btnUseDefaultFile->setChecked(prefs.use_default_file); + + if (prefs.cloud_verification_status == CS_VERIFIED) { + ui->cloudDefaultFile->setEnabled(true); + } else { + if (ui->cloudDefaultFile->isChecked()) + ui->noDefaultFile->setChecked(true); + ui->cloudDefaultFile->setEnabled(false); + } + + ui->defaultfilename->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui->btnUseDefaultFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui->chooseFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); +} + +void PreferencesDefaults::syncSettings() +{ + QSettings s; + s.beginGroup("GeneralSettings"); + s.setValue("default_filename", ui->defaultfilename->text()); + s.setValue("default_cylinder", ui->default_cylinder->currentText()); + s.setValue("use_default_file", ui->btnUseDefaultFile->isChecked()); + if (ui->noDefaultFile->isChecked()) + s.setValue("default_file_behavior", NO_DEFAULT_FILE); + else if (ui->localDefaultFile->isChecked()) + s.setValue("default_file_behavior", LOCAL_DEFAULT_FILE); + else if (ui->cloudDefaultFile->isChecked()) + s.setValue("default_file_behavior", CLOUD_DEFAULT_FILE); + s.endGroup(); + + s.beginGroup("Display"); + SAVE_OR_REMOVE_SPECIAL("divelist_font", system_divelist_default_font, ui->font->currentFont().toString(), ui->font->currentFont()); + SAVE_OR_REMOVE("font_size", system_divelist_default_font_size, ui->fontsize->value()); + s.setValue("displayinvalid", ui->displayinvalid->isChecked()); + s.endGroup(); + s.sync(); + + // Animation + s.beginGroup("Animations"); + s.setValue("animation_speed", ui->velocitySlider->value()); + s.endGroup(); +} diff --git a/desktop-widgets/preferences/preferences_defaults.h b/desktop-widgets/preferences/preferences_defaults.h new file mode 100644 index 000000000..c72be31a6 --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.h @@ -0,0 +1,28 @@ +#ifndef PREFERENCES_DEFAULTS_H +#define PREFERENCES_DEFAULTS_H + +#include "abstractpreferenceswidget.h" +#include "subsurface-core/pref.h" + +namespace Ui { + class PreferencesDefaults; +} + +class PreferencesDefaults : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesDefaults(); + virtual ~PreferencesDefaults(); + virtual void refreshSettings(); + virtual void syncSettings(); +public slots: + void on_chooseFile_clicked(); + void on_btnUseDefaultFile_toggled(bool toggled); + void on_localDefaultFile_toggled(bool toggled); + +private: + Ui::PreferencesDefaults *ui; +}; + + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_defaults.ui b/desktop-widgets/preferences/preferences_defaults.ui new file mode 100644 index 000000000..632e82763 --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.ui @@ -0,0 +1,251 @@ + + + PreferencesDefaults + + + + 0 + 0 + 555 + 558 + + + + Form + + + + + + Lists and tables + + + + 5 + + + + + Font + + + + + + + + + + Font size + + + + + + + + + + + + + Dives + + + + 5 + + + 5 + + + 5 + + + + + Default dive log file + + + + + + + + + No default file + + + + + + + &Local default file + + + + + + + Clo&ud storage default file + + + + + + + + + Local dive log file + + + + + + + + + + + + Use default + + + true + + + + + + + ... + + + + + + + + + Display invalid + + + + + + + + + + + + + + + + + Default cylinder + + + + 5 + + + 5 + + + 5 + + + + + Use default cylinder + + + + + + + + + + + + + + + + + Animations + + + + 5 + + + + + Speed + + + + + + + 500 + + + Qt::Horizontal + + + + + + + 500 + + + + + + + + + + Clear all settings + + + + 5 + + + 5 + + + + + Reset all settings to their default value + + + + + + + + + + Qt::Vertical + + + + 0 + 195 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferences_georeference.cpp b/desktop-widgets/preferences/preferences_georeference.cpp new file mode 100644 index 000000000..7e8ccec9d --- /dev/null +++ b/desktop-widgets/preferences/preferences_georeference.cpp @@ -0,0 +1,45 @@ +#include "preferences_georeference.h" +#include "ui_prefs_georeference.h" +#include "prefs-macros.h" +#include "qthelper.h" +#include "qt-models/divelocationmodel.h" + +#include +#include + +PreferencesGeoreference::PreferencesGeoreference() : AbstractPreferencesWidget(tr("Georeference"), QIcon(":/georeference"), 9) +{ + ui = new Ui::PreferencesGeoreference(); + ui->setupUi(this); + ui->first_item->setModel(GeoReferencingOptionsModel::instance()); + ui->second_item->setModel(GeoReferencingOptionsModel::instance()); + ui->third_item->setModel(GeoReferencingOptionsModel::instance()); +} + +PreferencesGeoreference::~PreferencesGeoreference() +{ + delete ui; +} + +void PreferencesGeoreference::refreshSettings() +{ + ui->enable_geocoding->setChecked(prefs.geocoding.enable_geocoding); + ui->parse_without_gps->setChecked(prefs.geocoding.parse_dive_without_gps); + ui->tag_existing_dives->setChecked(prefs.geocoding.tag_existing_dives); + ui->first_item->setCurrentIndex(prefs.geocoding.category[0]); + ui->second_item->setCurrentIndex(prefs.geocoding.category[1]); + ui->third_item->setCurrentIndex(prefs.geocoding.category[2]); +} + +void PreferencesGeoreference::syncSettings() +{ + QSettings s; + s.beginGroup("geocoding"); + s.setValue("enable_geocoding", ui->enable_geocoding->isChecked()); + s.setValue("parse_dives_without_gps", ui->parse_without_gps->isChecked()); + s.setValue("tag_existing_dives", ui->tag_existing_dives->isChecked()); + s.setValue("cat0", ui->first_item->currentIndex()); + s.setValue("cat1", ui->second_item->currentIndex()); + s.setValue("cat2", ui->third_item->currentIndex()); + s.endGroup(); +} \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_georeference.h b/desktop-widgets/preferences/preferences_georeference.h new file mode 100644 index 000000000..5dd4bc445 --- /dev/null +++ b/desktop-widgets/preferences/preferences_georeference.h @@ -0,0 +1,21 @@ +#ifndef PREFERENCES_GEOREFERENCE_H +#define PREFERENCES_GEOREFERENCE_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesGeoreference; +} + +class PreferencesGeoreference : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesGeoreference(); + virtual ~PreferencesGeoreference(); + virtual void refreshSettings(); + virtual void syncSettings(); +private: + Ui::PreferencesGeoreference *ui; +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_graph.cpp b/desktop-widgets/preferences/preferences_graph.cpp new file mode 100644 index 000000000..327557692 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.cpp @@ -0,0 +1,77 @@ +#include "preferences_graph.h" +#include "ui_preferences_graph.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +#include "qt-models/models.h" + +PreferencesGraph::PreferencesGraph() : AbstractPreferencesWidget(tr("Graph"), QIcon(":graph"), 5) +{ + ui = new Ui::PreferencesGraph(); + ui->setupUi(this); +} + +PreferencesGraph::~PreferencesGraph() +{ + delete ui; +} + +void PreferencesGraph::refreshSettings() +{ + ui->pheThreshold->setValue(prefs.pp_graphs.phe_threshold); + ui->po2Threshold->setValue(prefs.pp_graphs.po2_threshold); + ui->pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold); + ui->maxpo2->setValue(prefs.modpO2); + ui->red_ceiling->setChecked(prefs.redceiling); + + ui->gflow->setValue(prefs.gflow); + ui->gfhigh->setValue(prefs.gfhigh); + ui->gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth); + ui->show_ccr_setpoint->setChecked(prefs.show_ccr_setpoint); + ui->show_ccr_sensors->setChecked(prefs.show_ccr_sensors); + ui->defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0); + ui->psro2rate->setValue(prefs.o2consumption / 1000.0); + ui->pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); + + ui->display_unused_tanks->setChecked(prefs.display_unused_tanks); + ui->show_average_depth->setChecked(prefs.show_average_depth); +} + +void PreferencesGraph::syncSettings() +{ + QSettings s; + + s.beginGroup("GeneralSettings"); + s.setValue("defaultsetpoint", rint(ui->defaultSetpoint->value() * 1000.0)); + s.setValue("o2consumption", rint(ui->psro2rate->value() *1000.0)); + s.setValue("pscr_ratio", rint(1000.0 / ui->pscrfactor->value())); + s.endGroup(); + + s.beginGroup("TecDetails"); + SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui->pheThreshold->value()); + SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui->po2Threshold->value()); + SAVE_OR_REMOVE("pn2threshold", default_prefs.pp_graphs.pn2_threshold, ui->pn2Threshold->value()); + SAVE_OR_REMOVE("modpO2", default_prefs.modpO2, ui->maxpo2->value()); + SAVE_OR_REMOVE("redceiling", default_prefs.redceiling, ui->red_ceiling->isChecked()); + SAVE_OR_REMOVE("gflow", default_prefs.gflow, ui->gflow->value()); + SAVE_OR_REMOVE("gfhigh", default_prefs.gfhigh, ui->gfhigh->value()); + SAVE_OR_REMOVE("gf_low_at_maxdepth", default_prefs.gf_low_at_maxdepth, ui->gf_low_at_maxdepth->isChecked()); + SAVE_OR_REMOVE("show_ccr_setpoint", default_prefs.show_ccr_setpoint, ui->show_ccr_setpoint->isChecked()); + SAVE_OR_REMOVE("show_ccr_sensors", default_prefs.show_ccr_sensors, ui->show_ccr_sensors->isChecked()); + SAVE_OR_REMOVE("display_unused_tanks", default_prefs.display_unused_tanks, ui->display_unused_tanks->isChecked()); + SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui->show_average_depth->isChecked()); + s.endGroup(); +} + +#define DANGER_GF (gf > 100) ? "* { color: red; }" : "" +void PreferencesGraph::on_gflow_valueChanged(int gf) +{ + ui->gflow->setStyleSheet(DANGER_GF); +} +void PreferencesGraph::on_gfhigh_valueChanged(int gf) +{ + ui->gfhigh->setStyleSheet(DANGER_GF); +} +#undef DANGER_GF \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_graph.h b/desktop-widgets/preferences/preferences_graph.h new file mode 100644 index 000000000..ca40c0a92 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.h @@ -0,0 +1,27 @@ +#ifndef PREFERENCES_GRAPH_H +#define PREFERENCES_GRAPH_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesGraph; +} + +class PreferencesGraph : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesGraph(); + virtual ~PreferencesGraph(); + virtual void refreshSettings(); + virtual void syncSettings(); + +private slots: + void on_gflow_valueChanged(int gf); + void on_gfhigh_valueChanged(int gf); + +private: + Ui::PreferencesGraph *ui; + +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_graph.ui b/desktop-widgets/preferences/preferences_graph.ui new file mode 100644 index 000000000..bdbbc75d3 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.ui @@ -0,0 +1,268 @@ + + + PreferencesGraph + + + + 0 + 0 + 505 + 623 + + + + Form + + + + + + Show + + + + + + true + + + Threshold when showing pO₂ + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Threshold when showing pN₂ + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Threshold when showing pHe + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Max pO₂ when showing MOD + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Draw dive computer reported ceiling red + + + + + + + Show unused cylinders in Equipment tab + + + + + + + Show average depth + + + + + + + + + + Misc + + + + + + 1 + + + 150 + + + + + + + bar + + + 2 + + + 10.000000000000000 + + + 0.100000000000000 + + + + + + + Default CCR set-point for dive planning + + + + + + + pSCR O₂ metabolism rate + + + + + + + GFLow + + + + + + + GFHigh + + + + + + + 1 + + + 150 + + + + + + + ℓ/min + + + 3 + + + + + + + pSCR ratio + + + + + + + + + + 1: + + + + + + + CCR: show individual O₂ sensor values when viewing pO₂ + + + + + + + CCR: show setpoints when viewing pO₂ + + + + + + + GFLow at max depth + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp new file mode 100644 index 000000000..31bbd1c20 --- /dev/null +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -0,0 +1,72 @@ +#include "preferences_language.h" +#include "ui_prefs_language.h" +#include "subsurface-core/helpers.h" + +#include +#include +#include +#include + +#include "qt-models/models.h" + +PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Language"), QIcon(":/language"), 4) +{ + ui = new Ui::PreferencesLanguage(); + ui->setupUi(this); + + QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); + filterModel->setSourceModel(LanguageModel::instance()); + filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + ui->languageDropdown->setModel(filterModel); + filterModel->sort(0); + connect(ui->languageFilter, &QLineEdit::textChanged, + filterModel, &QSortFilterProxyModel::setFilterFixedString); +} + +PreferencesLanguage::~PreferencesLanguage() +{ + delete ui; +} + +void PreferencesLanguage::refreshSettings() +{ + QSettings s; + s.beginGroup("Language"); + ui->languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool()); + ui->timeFormatSystemDefault->setChecked(!s.value("time_format_override", false).toBool()); + ui->dateFormatSystemDefault->setChecked(!s.value("date_format_override", false).toBool()); + ui->timeFormatEntry->setText(s.value("time_format").toString()); + ui->dateFormatEntry->setText(s.value("date_format").toString()); + ui->shortDateFormatEntry->setText(s.value("date_format_short").toString()); + QAbstractItemModel *m = ui->languageDropdown->model(); + QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString()); + if (languages.count()) + ui->languageDropdown->setCurrentIndex(languages.first().row()); + s.endGroup(); +} + +void PreferencesLanguage::syncSettings() +{ + QSettings s; + s.beginGroup("Language"); + bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); + QAbstractItemModel *m = ui->languageDropdown->model(); + QString currentText = m->data(m->index(ui->languageDropdown->currentIndex(),0), Qt::UserRole).toString(); + if (useSystemLang != ui->languageSystemDefault->isChecked() || + (!useSystemLang && s.value("UiLanguage").toString() != currentText)) { + QMessageBox::warning(this, tr("Restart required"), + tr("To correctly load a new language you must restart Subsurface.")); + } + s.setValue("UiLanguage", currentText); + s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked()); + s.setValue("time_format_override", !ui->timeFormatSystemDefault->isChecked()); + s.setValue("date_format_override", !ui->dateFormatSystemDefault->isChecked()); + if (!ui->timeFormatSystemDefault->isChecked()) + s.setValue("time_format", ui->timeFormatEntry->text()); + if (!ui->dateFormatSystemDefault->isChecked()) { + s.setValue("date_format", ui->dateFormatEntry->text()); + s.setValue("date_format_short", ui->shortDateFormatEntry->text()); + } + s.endGroup(); + uiLanguage(NULL); +} diff --git a/desktop-widgets/preferences/preferences_language.h b/desktop-widgets/preferences/preferences_language.h new file mode 100644 index 000000000..43014c0fd --- /dev/null +++ b/desktop-widgets/preferences/preferences_language.h @@ -0,0 +1,21 @@ +#ifndef PREFERENCES_LANGUAGE_H +#define PREFERENCES_LANGUAGE_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesLanguage; +} + +class PreferencesLanguage : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesLanguage(); + virtual ~PreferencesLanguage(); + virtual void refreshSettings(); + virtual void syncSettings(); +private: + Ui::PreferencesLanguage *ui; +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_network.cpp b/desktop-widgets/preferences/preferences_network.cpp new file mode 100644 index 000000000..3780a6c91 --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.cpp @@ -0,0 +1,172 @@ +#include "preferences_network.h" +#include "ui_preferences_network.h" +#include "dive.h" +#include "subsurfacewebservices.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +PreferencesNetwork::PreferencesNetwork() : AbstractPreferencesWidget(tr("Network"),QIcon(":network"), 9), ui(new Ui::PreferencesNetwork()) +{ + ui->setupUi(this); + + ui->proxyType->clear(); + ui->proxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy); + ui->proxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy); + ui->proxyType->addItem(tr("HTTP proxy"), QNetworkProxy::HttpProxy); + ui->proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); + ui->proxyType->setCurrentIndex(-1); + + connect(ui->proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); +} + +PreferencesNetwork::~PreferencesNetwork() +{ + delete ui; +} + +void PreferencesNetwork::refreshSettings() +{ + QSettings s; + + ui->proxyHost->setText(prefs.proxy_host); + ui->proxyPort->setValue(prefs.proxy_port); + ui->proxyAuthRequired->setChecked(prefs.proxy_auth); + ui->proxyUsername->setText(prefs.proxy_user); + ui->proxyPassword->setText(prefs.proxy_pass); + ui->proxyType->setCurrentIndex(ui->proxyType->findData(prefs.proxy_type)); + ui->cloud_storage_email->setText(prefs.cloud_storage_email); + ui->cloud_storage_password->setText(prefs.cloud_storage_password); + ui->save_password_local->setChecked(prefs.save_password_local); + ui->cloud_background_sync->setChecked(prefs.cloud_background_sync); + ui->save_uid_local->setChecked(prefs.save_userid_local); + ui->default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); + + cloudPinNeeded(); +} + +void PreferencesNetwork::syncSettings() +{ + QSettings s; + s.setValue("subsurface_webservice_uid", ui->default_uid->text().toUpper()); + set_save_userid_local(ui->save_uid_local->checkState()); + + s.beginGroup("Network"); + s.setValue("proxy_type", ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt()); + s.setValue("proxy_host", ui->proxyHost->text()); + s.setValue("proxy_port", ui->proxyPort->value()); + SB("proxy_auth", ui->proxyAuthRequired); + s.setValue("proxy_user", ui->proxyUsername->text()); + s.setValue("proxy_pass", ui->proxyPassword->text()); + s.endGroup(); + + s.beginGroup("CloudStorage"); + QString email = ui->cloud_storage_email->text(); + QString password = ui->cloud_storage_password->text(); + QString newpassword = ui->cloud_storage_new_passwd->text(); + if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { + // deal with password change + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull())); + QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); + ui->cloud_storage_new_passwd->setText(""); + free(prefs.cloud_storage_newpassword); + prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword)); + } + } + } else if (prefs.cloud_verification_status == CS_UNKNOWN || + prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || + email != prefs.cloud_storage_email || + password != prefs.cloud_storage_password) { + + // different credentials - reset verification status + prefs.cloud_verification_status = CS_UNKNOWN; + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password); + } + } + } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { + QString pin = ui->cloud_storage_pin->text(); + if (!pin.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password, pin); + } + } + SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); + SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui->save_password_local->isChecked()); + if (ui->save_password_local->isChecked()) { + SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password); + } else { + s.remove("password"); + free(prefs.cloud_storage_password); + prefs.cloud_storage_password = strdup(qPrintable(password)); + } + SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status); + SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui->cloud_background_sync->isChecked()); + + // at this point we intentionally do not have a UI for changing this + // it could go into some sort of "advanced setup" or something + SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); + s.endGroup(); +} + +void PreferencesNetwork::cloudPinNeeded() +{ + ui->cloud_storage_pin->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + if (prefs.cloud_verification_status == CS_VERIFIED) { + ui->cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); + } else { + ui->cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); + } + //TODO: Do not call mainWindow here. Verify things on SettingsChanged. + //MainWindow::instance()->enableDisableCloudActions(); +} + +void PreferencesNetwork::proxyType_changed(int idx) +{ + if (idx == -1) { + return; + } + + int proxyType = ui->proxyType->itemData(idx).toInt(); + bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy); + ui->proxyHost->setEnabled(hpEnabled); + ui->proxyPort->setEnabled(hpEnabled); + ui->proxyAuthRequired->setEnabled(hpEnabled); + ui->proxyUsername->setEnabled(hpEnabled & ui->proxyAuthRequired->isChecked()); + ui->proxyPassword->setEnabled(hpEnabled & ui->proxyAuthRequired->isChecked()); + ui->proxyAuthRequired->setChecked(ui->proxyAuthRequired->isChecked()); +} + +void PreferencesNetwork::passwordUpdateSuccessfull() +{ + ui->cloud_storage_password->setText(prefs.cloud_storage_password); +} \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_network.h b/desktop-widgets/preferences/preferences_network.h new file mode 100644 index 000000000..3e17d51b0 --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.h @@ -0,0 +1,28 @@ +#ifndef PREFERENCES_NETWORK_H +#define PREFERENCES_NETWORK_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesNetwork; +} + +class PreferencesNetwork : public AbstractPreferencesWidget { + Q_OBJECT + +public: + PreferencesNetwork(); + virtual ~PreferencesNetwork(); + virtual void refreshSettings(); + virtual void syncSettings(); + +public slots: + void proxyType_changed(int i); + +private: + Ui::PreferencesNetwork *ui; + void cloudPinNeeded(); + void passwordUpdateSuccessfull(); +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_network.ui b/desktop-widgets/preferences/preferences_network.ui new file mode 100644 index 000000000..8bb9bf9a0 --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.ui @@ -0,0 +1,293 @@ + + + PreferencesNetwork + + + + 0 + 0 + 713 + 558 + + + + Form + + + + + + Proxy + + + + + + + 0 + 0 + + + + Port + + + + + + + Host + + + + + + + Proxy type + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Username + + + + + + + + 1 + 0 + + + + 65535 + + + 80 + + + + + + + + 2 + 0 + + + + 64 + + + + + + + + + + Qt::LeftToRight + + + Requires authentication + + + + + + + + 0 + 0 + + + + 32 + + + + + + + Password + + + + + + + + 0 + 0 + + + + 32 + + + QLineEdit::Password + + + + + + + + + + + 0 + 0 + + + + + 0 + 129 + + + + Subsurface cloud storage + + + + + + + + + Email address + + + + + + + Password + + + + + + + Verification PIN + + + + + + + New password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + Sync to cloud in the background? + + + + + + + Save Password locally? + + + + + + + + + + Subsurface web service + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Default user ID + + + + + + + + + + Save user ID locally? + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferences_units.cpp b/desktop-widgets/preferences/preferences_units.cpp new file mode 100644 index 000000000..cc77e51bb --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.cpp @@ -0,0 +1,60 @@ +#include "preferences_units.h" +#include "ui_preferences_units.h" +#include "prefs-macros.h" +#include "qthelper.h" + +#include + +PreferencesUnits::PreferencesUnits(): AbstractPreferencesWidget(tr("Units"),QIcon(":units"),1), ui(new Ui::PreferencesUnits()) +{ + ui->setupUi(this); +} + +PreferencesUnits::~PreferencesUnits() +{ + +} + +void PreferencesUnits::refreshSettings() +{ + switch(prefs.unit_system) { + case METRIC: ui->metric->setChecked(true); break; + case IMPERIAL: ui->imperial->setChecked(true); break; + default: ui->personalize->setChecked(true); break; + } + + ui->gpsTraditional->setChecked(prefs.coordinates_traditional); + ui->gpsDecimal->setChecked(!prefs.coordinates_traditional); + + ui->celsius->setChecked(prefs.units.temperature == units::CELSIUS); + ui->fahrenheit->setChecked(prefs.units.temperature == units::FAHRENHEIT); + ui->meter->setChecked(prefs.units.length == units::METERS); + ui->feet->setChecked(prefs.units.length == units::FEET); + ui->bar->setChecked(prefs.units.pressure == units::BAR); + ui->psi->setChecked(prefs.units.pressure == units::PSI); + ui->liter->setChecked(prefs.units.volume == units::LITER); + ui->cuft->setChecked(prefs.units.volume == units::CUFT); + ui->kg->setChecked(prefs.units.weight == units::KG); + ui->lbs->setChecked(prefs.units.weight == units::LBS); + ui->units_group->setEnabled(ui->personalize->isChecked()); + + ui->vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); + ui->vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); +} + +void PreferencesUnits::syncSettings() +{ + QSettings s; + s.beginGroup("Units"); + QString unitSystem[] = {"metric", "imperial", "personal"}; + short unitValue = ui->metric->isChecked() ? METRIC : (ui->imperial->isChecked() ? IMPERIAL : PERSONALIZE); + SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); + s.setValue("temperature", ui->fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS); + s.setValue("length", ui->feet->isChecked() ? units::FEET : units::METERS); + s.setValue("pressure", ui->psi->isChecked() ? units::PSI : units::BAR); + s.setValue("volume", ui->cuft->isChecked() ? units::CUFT : units::LITER); + s.setValue("weight", ui->lbs->isChecked() ? units::LBS : units::KG); + s.setValue("vertical_speed_time", ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); + s.setValue("coordinates", ui->gpsTraditional->isChecked()); + s.endGroup(); +} diff --git a/desktop-widgets/preferences/preferences_units.h b/desktop-widgets/preferences/preferences_units.h new file mode 100644 index 000000000..21a7f4404 --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.h @@ -0,0 +1,21 @@ +#ifndef PREFERENCES_UNITS_H +#define PREFERENCES_UNITS_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesUnits; +} + +class PreferencesUnits : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesUnits(); + virtual ~PreferencesUnits(); + virtual void refreshSettings(); + virtual void syncSettings(); +private: + Ui::PreferencesUnits *ui; +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_units.ui b/desktop-widgets/preferences/preferences_units.ui new file mode 100644 index 000000000..bb1ffba66 --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.ui @@ -0,0 +1,251 @@ + + + PreferencesUnits + + + + 0 + 0 + 400 + 374 + + + + Form + + + + + + Unit system + + + + + + System + + + + + + + &Metric + + + + + + + Imperial + + + + + + + Personali&ze + + + + + + + + + + Individual settings + + + false + + + false + + + + + + Depth + + + + + + + meter + + + + + + + feet + + + + + + + Pressure + + + + + + + bar + + + + + + + psi + + + + + + + Volume + + + + + + + &liter + + + + + + + cu ft + + + + + + + Temperature + + + + + + + celsius + + + + + + + fahrenheit + + + + + + + Weight + + + + + + + kg + + + + + + + lbs + + + + + + + + + + Time units + + + + + + Ascent/descent speed denominator + + + + + + + Minutes + + + + + + + Seconds + + + + + + + + + + GPS coordinates + + + + + + Location Display + + + + + + + traditional (dms) + + + + + + + decimal + + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp new file mode 100644 index 000000000..d8798879a --- /dev/null +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -0,0 +1,140 @@ +#include "preferencesdialog.h" + +#include "abstractpreferenceswidget.h" +#include "preferences_language.h" +#include "preferences_georeference.h" +#include "preferences_defaults.h" +#include "preferences_units.h" +#include "preferences_graph.h" +#include "preferences_network.h" + +#include "subsurface-core/qthelper.h" + +#include +#include +#include +#include +#include +#include +#include + +PreferencesDialog* PreferencesDialog::instance() +{ + static PreferencesDialog *self = new PreferencesDialog(); + return self; +} + +void PreferencesDialog::emitSettingsChanged() +{ + emit settingsChanged(); +} + +PreferencesDialog::PreferencesDialog() +{ + loadPreferences(); //TODO: Move this code out of the qthelper.cpp + + pagesList = new QListWidget(); + pagesStack = new QStackedWidget(); + buttonBox = new QDialogButtonBox( + QDialogButtonBox::Save | + QDialogButtonBox::Apply | + QDialogButtonBox::Cancel); + + pagesList->setMinimumWidth(120); + pagesList->setMaximumWidth(120); + + QHBoxLayout *h = new QHBoxLayout(); + h->addWidget(pagesList); + h->addWidget(pagesStack); + QVBoxLayout *v = new QVBoxLayout(); + v->addLayout(h); + v->addWidget(buttonBox); + + setLayout(v); + + addPreferencePage(new PreferencesLanguage()); + addPreferencePage(new PreferencesGeoreference()); + addPreferencePage(new PreferencesDefaults()); + addPreferencePage(new PreferencesUnits()); + addPreferencePage(new PreferencesGraph()); + addPreferencePage(new PreferencesNetwork()); + refreshPages(); + + connect(pagesList, &QListWidget::currentRowChanged, + pagesStack, &QStackedWidget::setCurrentIndex); + connect(buttonBox, &QDialogButtonBox::clicked, + this, &PreferencesDialog::buttonClicked); +} + +PreferencesDialog::~PreferencesDialog() +{ +} + +void PreferencesDialog::buttonClicked(QAbstractButton* btn) +{ + QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(btn); + switch(role) { + case QDialogButtonBox::ApplyRole : applyRequested(false); return; + case QDialogButtonBox::AcceptRole : applyRequested(true); return; + case QDialogButtonBox::RejectRole : cancelRequested(); return; + case QDialogButtonBox::ResetRole : defaultsRequested(); return; + } +} + +bool abstractpreferenceswidget_lessthan(AbstractPreferencesWidget *p1, AbstractPreferencesWidget *p2) +{ + return p1->positionHeight() <= p2->positionHeight(); +} + +void PreferencesDialog::addPreferencePage(AbstractPreferencesWidget *page) +{ + pages.push_back(page); + qSort(pages.begin(), pages.end(), abstractpreferenceswidget_lessthan); +} + +void PreferencesDialog::refreshPages() +{ + // Remove things + pagesList->clear(); + while(pagesStack->count()) { + QWidget *curr = pagesStack->widget(0); + pagesStack->removeWidget(curr); + curr->setParent(0); + } + + // Readd things. + Q_FOREACH(AbstractPreferencesWidget *page, pages) { + QListWidgetItem *item = new QListWidgetItem(page->icon(), page->name()); + pagesList->addItem(item); + pagesStack->addWidget(page); + page->refreshSettings(); + } +} + +void PreferencesDialog::applyRequested(bool closeIt) +{ + Q_FOREACH(AbstractPreferencesWidget *page, pages) { + page->syncSettings(); + } + emit settingsChanged(); + if (closeIt) + accept(); +} + +void PreferencesDialog::cancelRequested() +{ + Q_FOREACH(AbstractPreferencesWidget *page, pages) { + page->refreshSettings(); + } + reject(); +} + +void PreferencesDialog::defaultsRequested() +{ + prefs = default_prefs; + Q_FOREACH(AbstractPreferencesWidget *page, pages) { + page->refreshSettings(); + } + emit settingsChanged(); + accept(); +} diff --git a/desktop-widgets/preferences/preferencesdialog.h b/desktop-widgets/preferences/preferencesdialog.h new file mode 100644 index 000000000..5f7f5f979 --- /dev/null +++ b/desktop-widgets/preferences/preferencesdialog.h @@ -0,0 +1,35 @@ +#ifndef PREFERENCES_WIDGET_H +#define PREFERENCES_WIDGET_H + +#include +#include "pref.h" + +class AbstractPreferencesWidget; +class QListWidget; +class QStackedWidget; +class QDialogButtonBox; +class QAbstractButton; + +class PreferencesDialog : public QDialog { + Q_OBJECT +public: + static PreferencesDialog* instance(); + virtual ~PreferencesDialog(); + void addPreferencePage(AbstractPreferencesWidget *page); + void refreshPages(); + void emitSettingsChanged(); +signals: + void settingsChanged(); +private: + PreferencesDialog(); + void cancelRequested(); + void applyRequested(bool closeIt); + void defaultsRequested(); + void buttonClicked(QAbstractButton *btn); + QList pages; + QListWidget *pagesList; + QStackedWidget *pagesStack; + QDialogButtonBox *buttonBox; +}; + +#endif diff --git a/desktop-widgets/preferences/prefs_georeference.ui b/desktop-widgets/preferences/prefs_georeference.ui new file mode 100644 index 000000000..7d4f0907e --- /dev/null +++ b/desktop-widgets/preferences/prefs_georeference.ui @@ -0,0 +1,123 @@ + + + PreferencesGeoreference + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Dive site geo lookup + + + + + + Enable geocoding for dive site management + + + + + + + Parse site without GPS data + + + + + + + Same format for existing dives + + + + + + + + + + Dive Site Layout + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + / + + + + + + + + 0 + 0 + + + + + + + + / + + + + + + + + 0 + 0 + + + + + + + + + + + Qt::Vertical + + + + 20 + 109 + + + + + + + + + diff --git a/desktop-widgets/preferences/prefs_language.ui b/desktop-widgets/preferences/prefs_language.ui new file mode 100644 index 000000000..af3a0ad87 --- /dev/null +++ b/desktop-widgets/preferences/prefs_language.ui @@ -0,0 +1,260 @@ + + + PreferencesLanguage + + + + 0 + 0 + 621 + 523 + + + + Form + + + + + + + 0 + 0 + + + + UI language + + + + + + Use system default + + + + + + + + + + Qt::Horizontal + + + + 203 + 20 + + + + + + + + Filter + + + + + + + + + + + + + + 0 + 0 + + + + Date format + + + + + + <html><head/><body><p>Preferred date format. Commonly used fields are</p><p>d (day of month)</p><p>ddd (abbr. day name)</p><p>M (month number)</p><p>MMM (abbr. month name)</p><p>yy/yyyy (2/4 digit year)</p></body></html> + + + + + + + Use UI language default + + + + + + + + + + This is used in places where there is less space to show the full date + + + Short format + + + + + + + Qt::Horizontal + + + + 203 + 20 + + + + + + + + + + + + 0 + 0 + + + + Time format + + + + + + Use UI language default + + + + + + + <html><head/><body><p>Preferred time format</p><p>Commonly used format specifiers are</p><p>h (hours in 12h format)</p><p>H (hours in 24h format)</p><p>mm (2 digit minutes)</p><p>ss (2 digit seconds)</p><p>t/tt (a/p or am/pm)</p></body></html> + + + + + + + Qt::Horizontal + + + + 203 + 20 + + + + + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + languageSystemDefault + toggled(bool) + languageDropdown + setDisabled(bool) + + + 73 + 273 + + + 179 + 273 + + + + + languageSystemDefault + toggled(bool) + languageFilter + setDisabled(bool) + + + 73 + 273 + + + 539 + 273 + + + + + dateFormatSystemDefault + toggled(bool) + dateFormatEntry + setDisabled(bool) + + + 79 + 132 + + + 264 + 132 + + + + + timeFormatSystemDefault + toggled(bool) + timeFormatEntry + setDisabled(bool) + + + 79 + 210 + + + 264 + 210 + + + + + dateFormatSystemDefault + toggled(bool) + shortDateFormatEntry + setDisabled(bool) + + + 99 + 132 + + + 293 + 169 + + + + + diff --git a/qt-ui/printdialog.cpp b/desktop-widgets/printdialog.cpp similarity index 100% rename from qt-ui/printdialog.cpp rename to desktop-widgets/printdialog.cpp diff --git a/qt-ui/printdialog.h b/desktop-widgets/printdialog.h similarity index 100% rename from qt-ui/printdialog.h rename to desktop-widgets/printdialog.h diff --git a/printer.cpp b/desktop-widgets/printer.cpp similarity index 99% rename from printer.cpp rename to desktop-widgets/printer.cpp index f0197d446..33ee71b55 100644 --- a/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "profile-widget/profilewidget2.h" Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode) { diff --git a/printer.h b/desktop-widgets/printer.h similarity index 96% rename from printer.h rename to desktop-widgets/printer.h index 979cacd6a..e5f16d77d 100644 --- a/printer.h +++ b/desktop-widgets/printer.h @@ -6,7 +6,6 @@ #include #include -#include "profile/profilewidget2.h" #include "printoptions.h" #include "templateedit.h" diff --git a/qt-ui/printoptions.cpp b/desktop-widgets/printoptions.cpp similarity index 100% rename from qt-ui/printoptions.cpp rename to desktop-widgets/printoptions.cpp diff --git a/qt-ui/printoptions.h b/desktop-widgets/printoptions.h similarity index 100% rename from qt-ui/printoptions.h rename to desktop-widgets/printoptions.h diff --git a/qt-ui/printoptions.ui b/desktop-widgets/printoptions.ui similarity index 100% rename from qt-ui/printoptions.ui rename to desktop-widgets/printoptions.ui diff --git a/qt-ui/qtwaitingspinner.cpp b/desktop-widgets/qtwaitingspinner.cpp similarity index 100% rename from qt-ui/qtwaitingspinner.cpp rename to desktop-widgets/qtwaitingspinner.cpp diff --git a/qt-ui/qtwaitingspinner.h b/desktop-widgets/qtwaitingspinner.h similarity index 100% rename from qt-ui/qtwaitingspinner.h rename to desktop-widgets/qtwaitingspinner.h diff --git a/qt-ui/renumber.ui b/desktop-widgets/renumber.ui similarity index 100% rename from qt-ui/renumber.ui rename to desktop-widgets/renumber.ui diff --git a/qt-ui/searchbar.ui b/desktop-widgets/searchbar.ui similarity index 100% rename from qt-ui/searchbar.ui rename to desktop-widgets/searchbar.ui diff --git a/qt-ui/setpoint.ui b/desktop-widgets/setpoint.ui similarity index 100% rename from qt-ui/setpoint.ui rename to desktop-widgets/setpoint.ui diff --git a/qt-ui/shiftimagetimes.ui b/desktop-widgets/shiftimagetimes.ui similarity index 100% rename from qt-ui/shiftimagetimes.ui rename to desktop-widgets/shiftimagetimes.ui diff --git a/qt-ui/shifttimes.ui b/desktop-widgets/shifttimes.ui similarity index 100% rename from qt-ui/shifttimes.ui rename to desktop-widgets/shifttimes.ui diff --git a/qt-ui/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp similarity index 99% rename from qt-ui/simplewidgets.cpp rename to desktop-widgets/simplewidgets.cpp index 62a9cc646..43ad1ddc0 100644 --- a/qt-ui/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -14,7 +14,7 @@ #include "libdivecomputer/parser.h" #include "divelistview.h" #include "display.h" -#include "profile/profilewidget2.h" +#include "profile-widget/profilewidget2.h" #include "undocommands.h" class MinMaxAvgWidgetPrivate { diff --git a/qt-ui/simplewidgets.h b/desktop-widgets/simplewidgets.h similarity index 100% rename from qt-ui/simplewidgets.h rename to desktop-widgets/simplewidgets.h diff --git a/qt-ui/socialnetworks.cpp b/desktop-widgets/socialnetworks.cpp similarity index 99% rename from qt-ui/socialnetworks.cpp rename to desktop-widgets/socialnetworks.cpp index 6e191267a..0794c764e 100644 --- a/qt-ui/socialnetworks.cpp +++ b/desktop-widgets/socialnetworks.cpp @@ -16,7 +16,7 @@ #include #include #include "mainwindow.h" -#include "profile/profilewidget2.h" +#include "profile-widget/profilewidget2.h" #include "pref.h" #include "helpers.h" #include "ui_socialnetworksdialog.h" diff --git a/qt-ui/socialnetworks.h b/desktop-widgets/socialnetworks.h similarity index 100% rename from qt-ui/socialnetworks.h rename to desktop-widgets/socialnetworks.h diff --git a/qt-ui/socialnetworksdialog.ui b/desktop-widgets/socialnetworksdialog.ui similarity index 100% rename from qt-ui/socialnetworksdialog.ui rename to desktop-widgets/socialnetworksdialog.ui diff --git a/qt-ui/starwidget.cpp b/desktop-widgets/starwidget.cpp similarity index 100% rename from qt-ui/starwidget.cpp rename to desktop-widgets/starwidget.cpp diff --git a/qt-ui/starwidget.h b/desktop-widgets/starwidget.h similarity index 100% rename from qt-ui/starwidget.h rename to desktop-widgets/starwidget.h diff --git a/qt-ui/statistics/monthstatistics.cpp b/desktop-widgets/statistics/monthstatistics.cpp similarity index 100% rename from qt-ui/statistics/monthstatistics.cpp rename to desktop-widgets/statistics/monthstatistics.cpp diff --git a/qt-ui/statistics/monthstatistics.h b/desktop-widgets/statistics/monthstatistics.h similarity index 100% rename from qt-ui/statistics/monthstatistics.h rename to desktop-widgets/statistics/monthstatistics.h diff --git a/qt-ui/statistics/statisticsbar.cpp b/desktop-widgets/statistics/statisticsbar.cpp similarity index 100% rename from qt-ui/statistics/statisticsbar.cpp rename to desktop-widgets/statistics/statisticsbar.cpp diff --git a/qt-ui/statistics/statisticsbar.h b/desktop-widgets/statistics/statisticsbar.h similarity index 100% rename from qt-ui/statistics/statisticsbar.h rename to desktop-widgets/statistics/statisticsbar.h diff --git a/qt-ui/statistics/statisticswidget.cpp b/desktop-widgets/statistics/statisticswidget.cpp similarity index 100% rename from qt-ui/statistics/statisticswidget.cpp rename to desktop-widgets/statistics/statisticswidget.cpp diff --git a/qt-ui/statistics/statisticswidget.h b/desktop-widgets/statistics/statisticswidget.h similarity index 100% rename from qt-ui/statistics/statisticswidget.h rename to desktop-widgets/statistics/statisticswidget.h diff --git a/qt-ui/statistics/yearstatistics.cpp b/desktop-widgets/statistics/yearstatistics.cpp similarity index 100% rename from qt-ui/statistics/yearstatistics.cpp rename to desktop-widgets/statistics/yearstatistics.cpp diff --git a/qt-ui/statistics/yearstatistics.h b/desktop-widgets/statistics/yearstatistics.h similarity index 100% rename from qt-ui/statistics/yearstatistics.h rename to desktop-widgets/statistics/yearstatistics.h diff --git a/qt-ui/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp similarity index 100% rename from qt-ui/subsurfacewebservices.cpp rename to desktop-widgets/subsurfacewebservices.cpp diff --git a/qt-ui/subsurfacewebservices.h b/desktop-widgets/subsurfacewebservices.h similarity index 100% rename from qt-ui/subsurfacewebservices.h rename to desktop-widgets/subsurfacewebservices.h diff --git a/qt-ui/tableview.cpp b/desktop-widgets/tableview.cpp similarity index 100% rename from qt-ui/tableview.cpp rename to desktop-widgets/tableview.cpp diff --git a/qt-ui/tableview.h b/desktop-widgets/tableview.h similarity index 100% rename from qt-ui/tableview.h rename to desktop-widgets/tableview.h diff --git a/qt-ui/tableview.ui b/desktop-widgets/tableview.ui similarity index 100% rename from qt-ui/tableview.ui rename to desktop-widgets/tableview.ui diff --git a/qt-ui/tagwidget.cpp b/desktop-widgets/tagwidget.cpp similarity index 100% rename from qt-ui/tagwidget.cpp rename to desktop-widgets/tagwidget.cpp diff --git a/qt-ui/tagwidget.h b/desktop-widgets/tagwidget.h similarity index 100% rename from qt-ui/tagwidget.h rename to desktop-widgets/tagwidget.h diff --git a/qt-ui/templateedit.cpp b/desktop-widgets/templateedit.cpp similarity index 100% rename from qt-ui/templateedit.cpp rename to desktop-widgets/templateedit.cpp diff --git a/qt-ui/templateedit.h b/desktop-widgets/templateedit.h similarity index 100% rename from qt-ui/templateedit.h rename to desktop-widgets/templateedit.h diff --git a/qt-ui/templateedit.ui b/desktop-widgets/templateedit.ui similarity index 100% rename from qt-ui/templateedit.ui rename to desktop-widgets/templateedit.ui diff --git a/templatelayout.cpp b/desktop-widgets/templatelayout.cpp similarity index 100% rename from templatelayout.cpp rename to desktop-widgets/templatelayout.cpp diff --git a/templatelayout.h b/desktop-widgets/templatelayout.h similarity index 100% rename from templatelayout.h rename to desktop-widgets/templatelayout.h diff --git a/qt-ui/undocommands.cpp b/desktop-widgets/undocommands.cpp similarity index 100% rename from qt-ui/undocommands.cpp rename to desktop-widgets/undocommands.cpp diff --git a/qt-ui/undocommands.h b/desktop-widgets/undocommands.h similarity index 100% rename from qt-ui/undocommands.h rename to desktop-widgets/undocommands.h diff --git a/qt-ui/updatemanager.cpp b/desktop-widgets/updatemanager.cpp similarity index 100% rename from qt-ui/updatemanager.cpp rename to desktop-widgets/updatemanager.cpp diff --git a/qt-ui/updatemanager.h b/desktop-widgets/updatemanager.h similarity index 100% rename from qt-ui/updatemanager.h rename to desktop-widgets/updatemanager.h diff --git a/qt-ui/urldialog.ui b/desktop-widgets/urldialog.ui similarity index 100% rename from qt-ui/urldialog.ui rename to desktop-widgets/urldialog.ui diff --git a/qt-ui/usermanual.cpp b/desktop-widgets/usermanual.cpp similarity index 100% rename from qt-ui/usermanual.cpp rename to desktop-widgets/usermanual.cpp diff --git a/qt-ui/usermanual.h b/desktop-widgets/usermanual.h similarity index 100% rename from qt-ui/usermanual.h rename to desktop-widgets/usermanual.h diff --git a/qt-ui/usersurvey.cpp b/desktop-widgets/usersurvey.cpp similarity index 100% rename from qt-ui/usersurvey.cpp rename to desktop-widgets/usersurvey.cpp diff --git a/qt-ui/usersurvey.h b/desktop-widgets/usersurvey.h similarity index 100% rename from qt-ui/usersurvey.h rename to desktop-widgets/usersurvey.h diff --git a/qt-ui/usersurvey.ui b/desktop-widgets/usersurvey.ui similarity index 100% rename from qt-ui/usersurvey.ui rename to desktop-widgets/usersurvey.ui diff --git a/qt-ui/webservices.ui b/desktop-widgets/webservices.ui similarity index 100% rename from qt-ui/webservices.ui rename to desktop-widgets/webservices.ui diff --git a/satellite.svg b/icons/satellite.svg similarity index 100% rename from satellite.svg rename to icons/satellite.svg diff --git a/subsurface-icon.svg b/icons/subsurface-icon.svg similarity index 100% rename from subsurface-icon.svg rename to icons/subsurface-icon.svg diff --git a/subsurface-mobile-icon.svg b/icons/subsurface-mobile-icon.svg similarity index 100% rename from subsurface-mobile-icon.svg rename to icons/subsurface-mobile-icon.svg diff --git a/profile-widget/CMakeLists.txt b/profile-widget/CMakeLists.txt new file mode 100644 index 000000000..f0a1d8439 --- /dev/null +++ b/profile-widget/CMakeLists.txt @@ -0,0 +1,19 @@ +# the profile widget +set(SUBSURFACE_PROFILE_LIB_SRCS + profilewidget2.cpp + diverectitem.cpp + divepixmapitem.cpp + divelineitem.cpp + divetextitem.cpp + animationfunctions.cpp + divecartesianaxis.cpp + diveprofileitem.cpp + diveeventitem.cpp + divetooltipitem.cpp + ruleritem.cpp + tankitem.cpp +) +source_group("Subsurface Profile" FILES ${SUBSURFACE_PROFILE_LIB_SRCS}) + +add_library(subsurface_profile STATIC ${SUBSURFACE_PROFILE_LIB_SRCS}) +target_link_libraries(subsurface_profile ${QT_LIBRARIES}) \ No newline at end of file diff --git a/qt-ui/profile/animationfunctions.cpp b/profile-widget/animationfunctions.cpp similarity index 100% rename from qt-ui/profile/animationfunctions.cpp rename to profile-widget/animationfunctions.cpp diff --git a/qt-ui/profile/animationfunctions.h b/profile-widget/animationfunctions.h similarity index 100% rename from qt-ui/profile/animationfunctions.h rename to profile-widget/animationfunctions.h diff --git a/qt-ui/profile/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp similarity index 99% rename from qt-ui/profile/divecartesianaxis.cpp rename to profile-widget/divecartesianaxis.cpp index bf5a5380c..f40e1c3e5 100644 --- a/qt-ui/profile/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -1,7 +1,7 @@ #include "divecartesianaxis.h" #include "divetextitem.h" #include "helpers.h" -#include "preferences.h" +#include "preferences/preferencesdialog.h" #include "diveplotdatamodel.h" #include "animationfunctions.h" #include "mainwindow.h" diff --git a/qt-ui/profile/divecartesianaxis.h b/profile-widget/divecartesianaxis.h similarity index 98% rename from qt-ui/profile/divecartesianaxis.h rename to profile-widget/divecartesianaxis.h index 27cfa62d8..cc7d0bcf7 100644 --- a/qt-ui/profile/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -3,7 +3,7 @@ #include #include -#include +#include "subsurface-core/color.h" class QPropertyAnimation; class DiveTextItem; diff --git a/qt-ui/profile/diveeventitem.cpp b/profile-widget/diveeventitem.cpp similarity index 100% rename from qt-ui/profile/diveeventitem.cpp rename to profile-widget/diveeventitem.cpp diff --git a/qt-ui/profile/diveeventitem.h b/profile-widget/diveeventitem.h similarity index 100% rename from qt-ui/profile/diveeventitem.h rename to profile-widget/diveeventitem.h diff --git a/qt-ui/profile/divelineitem.cpp b/profile-widget/divelineitem.cpp similarity index 100% rename from qt-ui/profile/divelineitem.cpp rename to profile-widget/divelineitem.cpp diff --git a/qt-ui/profile/divelineitem.h b/profile-widget/divelineitem.h similarity index 100% rename from qt-ui/profile/divelineitem.h rename to profile-widget/divelineitem.h diff --git a/qt-ui/profile/divepixmapitem.cpp b/profile-widget/divepixmapitem.cpp similarity index 98% rename from qt-ui/profile/divepixmapitem.cpp rename to profile-widget/divepixmapitem.cpp index 581f6f9b4..627473c2f 100644 --- a/qt-ui/profile/divepixmapitem.cpp +++ b/profile-widget/divepixmapitem.cpp @@ -1,7 +1,7 @@ #include "divepixmapitem.h" #include "animationfunctions.h" #include "divepicturemodel.h" -#include +#include "preferences/preferencesdialog.h" #include #include diff --git a/qt-ui/profile/divepixmapitem.h b/profile-widget/divepixmapitem.h similarity index 100% rename from qt-ui/profile/divepixmapitem.h rename to profile-widget/divepixmapitem.h diff --git a/qt-ui/profile/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp similarity index 99% rename from qt-ui/profile/diveprofileitem.cpp rename to profile-widget/diveprofileitem.cpp index 2c814678a..14efa9123 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -5,13 +5,13 @@ #include "animationfunctions.h" #include "dive.h" #include "profile.h" -#include "preferences.h" +#include "preferences/preferencesdialog.h" #include "diveplannermodel.h" #include "helpers.h" #include "libdivecomputer/parser.h" #include "mainwindow.h" #include "maintab.h" -#include "profile/profilewidget2.h" +#include "profilewidget2.h" #include "diveplanner.h" #include diff --git a/qt-ui/profile/diveprofileitem.h b/profile-widget/diveprofileitem.h similarity index 99% rename from qt-ui/profile/diveprofileitem.h rename to profile-widget/diveprofileitem.h index 2160782f7..0bba7f7a3 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/profile-widget/diveprofileitem.h @@ -5,7 +5,6 @@ #include #include -#include "graphicsview-common.h" #include "divelineitem.h" /* This is the Profile Item, it should be used for quite a lot of things diff --git a/qt-ui/profile/diverectitem.cpp b/profile-widget/diverectitem.cpp similarity index 100% rename from qt-ui/profile/diverectitem.cpp rename to profile-widget/diverectitem.cpp diff --git a/qt-ui/profile/diverectitem.h b/profile-widget/diverectitem.h similarity index 100% rename from qt-ui/profile/diverectitem.h rename to profile-widget/diverectitem.h diff --git a/qt-ui/profile/divetextitem.cpp b/profile-widget/divetextitem.cpp similarity index 98% rename from qt-ui/profile/divetextitem.cpp rename to profile-widget/divetextitem.cpp index 9c7848cd4..3bf00d68f 100644 --- a/qt-ui/profile/divetextitem.cpp +++ b/profile-widget/divetextitem.cpp @@ -1,6 +1,9 @@ #include "divetextitem.h" #include "mainwindow.h" #include "profilewidget2.h" +#include "subsurface-core/color.h" + +#include DiveTextItem::DiveTextItem(QGraphicsItem *parent) : QGraphicsItemGroup(parent), internalAlignFlags(Qt::AlignHCenter | Qt::AlignVCenter), diff --git a/qt-ui/profile/divetextitem.h b/profile-widget/divetextitem.h similarity index 94% rename from qt-ui/profile/divetextitem.h rename to profile-widget/divetextitem.h index 3991fe7f3..be0adf292 100644 --- a/qt-ui/profile/divetextitem.h +++ b/profile-widget/divetextitem.h @@ -3,8 +3,8 @@ #include #include -#include "graphicsview-common.h" -#include + +class QBrush; /* A Line Item that has animated-properties. */ class DiveTextItem : public QObject, public QGraphicsItemGroup { diff --git a/qt-ui/profile/divetooltipitem.cpp b/profile-widget/divetooltipitem.cpp similarity index 100% rename from qt-ui/profile/divetooltipitem.cpp rename to profile-widget/divetooltipitem.cpp diff --git a/qt-ui/profile/divetooltipitem.h b/profile-widget/divetooltipitem.h similarity index 100% rename from qt-ui/profile/divetooltipitem.h rename to profile-widget/divetooltipitem.h diff --git a/qt-ui/profile/profilewidget2.cpp b/profile-widget/profilewidget2.cpp similarity index 99% rename from qt-ui/profile/profilewidget2.cpp rename to profile-widget/profilewidget2.cpp index d47467038..653818556 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -29,7 +29,7 @@ #include #endif #include "mainwindow.h" -#include +#include "preferences/preferencesdialog.h" /* This is the global 'Item position' variable. * it should tell you where to position things up diff --git a/qt-ui/profile/profilewidget2.h b/profile-widget/profilewidget2.h similarity index 99% rename from qt-ui/profile/profilewidget2.h rename to profile-widget/profilewidget2.h index 23e939869..ce3fda083 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -13,7 +13,6 @@ // * // * It needs to be dynamic, things should *flow* on it, not just appear / disappear. // */ -#include "graphicsview-common.h" #include "divelineitem.h" #include "diveprofileitem.h" #include "display.h" diff --git a/qt-ui/profile/ruleritem.cpp b/profile-widget/ruleritem.cpp similarity index 99% rename from qt-ui/profile/ruleritem.cpp rename to profile-widget/ruleritem.cpp index 830985552..a5a61c0fe 100644 --- a/qt-ui/profile/ruleritem.cpp +++ b/profile-widget/ruleritem.cpp @@ -1,5 +1,5 @@ #include "ruleritem.h" -#include "preferences.h" +#include "preferences/preferencesdialog.h" #include "mainwindow.h" #include "profilewidget2.h" #include "display.h" diff --git a/qt-ui/profile/ruleritem.h b/profile-widget/ruleritem.h similarity index 100% rename from qt-ui/profile/ruleritem.h rename to profile-widget/ruleritem.h diff --git a/qt-ui/profile/tankitem.cpp b/profile-widget/tankitem.cpp similarity index 100% rename from qt-ui/profile/tankitem.cpp rename to profile-widget/tankitem.cpp diff --git a/qt-ui/profile/tankitem.h b/profile-widget/tankitem.h similarity index 100% rename from qt-ui/profile/tankitem.h rename to profile-widget/tankitem.h diff --git a/qt-models/CMakeLists.txt b/qt-models/CMakeLists.txt new file mode 100644 index 000000000..c9bcf5c3d --- /dev/null +++ b/qt-models/CMakeLists.txt @@ -0,0 +1,29 @@ +# the data models that will interface +# with the views. +set(SUBSURFACE_MODELS_LIB_SRCS + cleanertablemodel.cpp + cylindermodel.cpp + diveplannermodel.cpp + models.cpp + filtermodels.cpp + tankinfomodel.cpp + weigthsysteminfomodel.cpp + weightmodel.cpp + divecomputermodel.cpp + treemodel.cpp + tableprintmodel.cpp + yearlystatisticsmodel.cpp + divetripmodel.cpp + divecomputerextradatamodel.cpp + completionmodels.cpp + profileprintmodel.cpp + divepicturemodel.cpp + diveplotdatamodel.cpp + divelocationmodel.cpp + divesitepicturesmodel.cpp + ssrfsortfilterproxymodel.cpp +) + +source_group("Subsurface Models" FILES ${SUBSURFACE_MODELS}) +add_library(subsurface_models STATIC ${SUBSURFACE_MODELS_LIB_SRCS}) +target_link_libraries(subsurface_models ${QT_LIBRARIES}) \ No newline at end of file diff --git a/qt-models/completionmodels.cpp b/qt-models/completionmodels.cpp index 838d239d2..a8b61aed5 100644 --- a/qt-models/completionmodels.cpp +++ b/qt-models/completionmodels.cpp @@ -1,6 +1,7 @@ #include "completionmodels.h" #include "dive.h" -#include "mainwindow.h" +#include +#include #define CREATE_UPDATE_METHOD(Class, diveStructMember) \ void Class::updateModel() \ diff --git a/qt-models/diveplotdatamodel.cpp b/qt-models/diveplotdatamodel.cpp index f219947ac..de156bfac 100644 --- a/qt-models/diveplotdatamodel.cpp +++ b/qt-models/diveplotdatamodel.cpp @@ -1,8 +1,8 @@ #include "diveplotdatamodel.h" #include "dive.h" #include "profile.h" -#include "graphicsview-common.h" #include "divelist.h" +#include "subsurface-core/color.h" DivePlotDataModel::DivePlotDataModel(QObject *parent) : QAbstractTableModel(parent), diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index 80ed0cfd5..f56f4be1c 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -1,8 +1,9 @@ #include "filtermodels.h" -#include "mainwindow.h" #include "models.h" -#include "divelistview.h" #include "display.h" +#include "divetripmodel.h" + +#include #define CREATE_INSTANCE_METHOD( CLASS ) \ CLASS *CLASS::instance() \ @@ -355,9 +356,16 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s void MultiFilterSortModel::myInvalidate() { + //WARNING: + //TODO: + // THIS CODE BELOW IS COMPLETELY BROKEN. I KNOW, I WROTE IT. + // REMOVE THIS, MAKE IT SANE. + // GRRRRR. + +#if 0 int i; struct dive *d; - DiveListView *dlv = MainWindow::instance()->dive_list(); + // DiveListView *dlv = MainWindow::instance()->dive_list(); divesDisplayed = 0; @@ -395,6 +403,7 @@ void MultiFilterSortModel::myInvalidate() if (curr_dive_site) { dlv->expandAll(); } +#endif } void MultiFilterSortModel::addFilterModel(MultiFilterInterface *model) diff --git a/qt-models/models.h b/qt-models/models.h index c9212195e..f152af469 100644 --- a/qt-models/models.h +++ b/qt-models/models.h @@ -15,9 +15,9 @@ #include "metrics.h" -#include "../dive.h" -#include "../divelist.h" -#include "../divecomputer.h" +#include "subsurface-core/dive.h" +#include "subsurface-core/divelist.h" +#include "subsurface-core/divecomputer.h" #include "cleanertablemodel.h" #include "treemodel.h" diff --git a/qt-ui/graphicsview-common.h b/qt-ui/graphicsview-common.h deleted file mode 100644 index 3c1cb75a0..000000000 --- a/qt-ui/graphicsview-common.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef GRAPHICSVIEW_COMMON_H -#define GRAPHICSVIEW_COMMON_H - -#include "../color.h" -#include -#include -#include - -#define SAC_COLORS_START_IDX SAC_1 -#define SAC_COLORS 9 -#define VELOCITY_COLORS_START_IDX VELO_STABLE -#define VELOCITY_COLORS 5 - -typedef enum { - /* SAC colors. Order is important, the SAC_COLORS_START_IDX define above. */ - SAC_1, - SAC_2, - SAC_3, - SAC_4, - SAC_5, - SAC_6, - SAC_7, - SAC_8, - SAC_9, - - /* Velocity colors. Order is still important, ref VELOCITY_COLORS_START_IDX. */ - VELO_STABLE, - VELO_SLOW, - VELO_MODERATE, - VELO_FAST, - VELO_CRAZY, - - /* gas colors */ - PO2, - PO2_ALERT, - PN2, - PN2_ALERT, - PHE, - PHE_ALERT, - O2SETPOINT, - CCRSENSOR1, - CCRSENSOR2, - CCRSENSOR3, - PP_LINES, - - /* Other colors */ - TEXT_BACKGROUND, - ALERT_BG, - ALERT_FG, - EVENTS, - SAMPLE_DEEP, - SAMPLE_SHALLOW, - SMOOTHED, - MINUTE, - TIME_GRID, - TIME_TEXT, - DEPTH_GRID, - MEAN_DEPTH, - HR_TEXT, - HR_PLOT, - HR_AXIS, - DEPTH_TOP, - DEPTH_BOTTOM, - TEMP_TEXT, - TEMP_PLOT, - SAC_DEFAULT, - BOUNDING_BOX, - PRESSURE_TEXT, - BACKGROUND, - BACKGROUND_TRANS, - CEILING_SHALLOW, - CEILING_DEEP, - CALC_CEILING_SHALLOW, - CALC_CEILING_DEEP, - TISSUE_PERCENTAGE, - GF_LINE, - AMB_PRESSURE_LINE -} color_indice_t; - - -/* profile_color[color indice] = COLOR(screen color, b/w printer color, color printer}} printer & screen colours could be different */ - -extern QMap > profile_color; -void fill_profile_color(); -QColor getColor(const color_indice_t i, bool isGrayscale = false); -QColor getSacColor(int sac, int diveSac); -struct text_render_options { - double size; - color_indice_t color; - double hpos, vpos; -}; - -typedef text_render_options text_render_options_t; -#endif // GRAPHICSVIEW_COMMON_H diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp deleted file mode 100644 index 6450c41cb..000000000 --- a/qt-ui/preferences.cpp +++ /dev/null @@ -1,559 +0,0 @@ -#include "preferences.h" -#include "mainwindow.h" -#include "models.h" -#include "divelocationmodel.h" -#include "prefs-macros.h" -#include "qthelper.h" -#include "subsurfacestartup.h" - -#include -#include -#include -#include -#include -#include - -#include "subsurfacewebservices.h" - -#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) -#include "socialnetworks.h" -#include -#endif - -PreferencesDialog *PreferencesDialog::instance() -{ - static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance()); - return dialog; -} - -PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) -{ - ui.setupUi(this); - setAttribute(Qt::WA_QuitOnClose, false); - -#if defined(Q_OS_ANDROID) || !defined(FBSUPPORT) - for (int i = 0; i < ui.listWidget->count(); i++) { - if (ui.listWidget->item(i)->text() == "Facebook") { - delete ui.listWidget->item(i); - QWidget *fbpage = ui.stackedWidget->widget(i); - ui.stackedWidget->removeWidget(fbpage); - } - } -#endif - - ui.proxyType->clear(); - ui.proxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy); - ui.proxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy); - ui.proxyType->addItem(tr("HTTP proxy"), QNetworkProxy::HttpProxy); - ui.proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); - ui.proxyType->setCurrentIndex(-1); - - ui.first_item->setModel(GeoReferencingOptionsModel::instance()); - ui.second_item->setModel(GeoReferencingOptionsModel::instance()); - ui.third_item->setModel(GeoReferencingOptionsModel::instance()); - // Facebook stuff: -#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) - FacebookManager *fb = FacebookManager::instance(); - facebookWebView = new QWebView(this); - ui.fbWebviewContainer->layout()->addWidget(facebookWebView); - if (fb->loggedIn()) { - facebookLoggedIn(); - } else { - facebookDisconnect(); - } - connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin); - connect(fb, &FacebookManager::justLoggedIn, this, &PreferencesDialog::facebookLoggedIn); - connect(ui.fbDisconnect, &QPushButton::clicked, fb, &FacebookManager::logout); - connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect); -#endif - connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); - connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); - connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int))); - connect(ui.gfhigh, SIGNAL(valueChanged(int)), this, SLOT(gfhighChanged(int))); - // connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double))); - QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); - connect(close, SIGNAL(activated()), this, SLOT(close())); - QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); - connect(quit, SIGNAL(activated()), parent, SLOT(close())); - loadSettings(); - setUiFromPrefs(); - rememberPrefs(); -} - -void PreferencesDialog::facebookLoggedIn() -{ -#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) - ui.fbDisconnect->show(); - ui.fbWebviewContainer->hide(); - ui.fbWebviewContainer->setEnabled(false); - ui.FBLabel->setText(tr("To disconnect Subsurface from your Facebook account, use the button below")); -#endif -} - -void PreferencesDialog::facebookDisconnect() -{ -#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) - // remove the connect/disconnect button - // and instead add the login view - ui.fbDisconnect->hide(); - ui.fbWebviewContainer->show(); - ui.fbWebviewContainer->setEnabled(true); - ui.FBLabel->setText(tr("To connect to Facebook, please log in. This enables Subsurface to publish dives to your timeline")); - if (facebookWebView) { - facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar()); - facebookWebView->setUrl(FacebookManager::instance()->connectUrl()); - } -#endif -} - -void PreferencesDialog::cloudPinNeeded() -{ - ui.cloud_storage_pin->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); - if (prefs.cloud_verification_status == CS_VERIFIED) { - ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); - ui.cloudDefaultFile->setEnabled(true); - } else { - ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); - if (ui.cloudDefaultFile->isChecked()) - ui.noDefaultFile->setChecked(true); - ui.cloudDefaultFile->setEnabled(false); - } - MainWindow::instance()->enableDisableCloudActions(); -} - -#define DANGER_GF (gf > 100) ? "* { color: red; }" : "" -void PreferencesDialog::gflowChanged(int gf) -{ - ui.gflow->setStyleSheet(DANGER_GF); -} -void PreferencesDialog::gfhighChanged(int gf) -{ - ui.gfhigh->setStyleSheet(DANGER_GF); -} -#undef DANGER_GF - -void PreferencesDialog::showEvent(QShowEvent *event) -{ - setUiFromPrefs(); - rememberPrefs(); - QDialog::showEvent(event); -} - -void PreferencesDialog::setUiFromPrefs() -{ - // graphs - ui.pheThreshold->setValue(prefs.pp_graphs.phe_threshold); - ui.po2Threshold->setValue(prefs.pp_graphs.po2_threshold); - ui.pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold); - ui.maxpo2->setValue(prefs.modpO2); - ui.red_ceiling->setChecked(prefs.redceiling); - ui.units_group->setEnabled(ui.personalize->isChecked()); - - ui.gflow->setValue(prefs.gflow); - ui.gfhigh->setValue(prefs.gfhigh); - ui.gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth); - ui.show_ccr_setpoint->setChecked(prefs.show_ccr_setpoint); - ui.show_ccr_sensors->setChecked(prefs.show_ccr_sensors); - ui.defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0); - ui.psro2rate->setValue(prefs.o2consumption / 1000.0); - ui.pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); - - // units - if (prefs.unit_system == METRIC) - ui.metric->setChecked(true); - else if (prefs.unit_system == IMPERIAL) - ui.imperial->setChecked(true); - else - ui.personalize->setChecked(true); - ui.gpsTraditional->setChecked(prefs.coordinates_traditional); - ui.gpsDecimal->setChecked(!prefs.coordinates_traditional); - - ui.celsius->setChecked(prefs.units.temperature == units::CELSIUS); - ui.fahrenheit->setChecked(prefs.units.temperature == units::FAHRENHEIT); - ui.meter->setChecked(prefs.units.length == units::METERS); - ui.feet->setChecked(prefs.units.length == units::FEET); - ui.bar->setChecked(prefs.units.pressure == units::BAR); - ui.psi->setChecked(prefs.units.pressure == units::PSI); - ui.liter->setChecked(prefs.units.volume == units::LITER); - ui.cuft->setChecked(prefs.units.volume == units::CUFT); - ui.kg->setChecked(prefs.units.weight == units::KG); - ui.lbs->setChecked(prefs.units.weight == units::LBS); - - ui.font->setCurrentFont(QString(prefs.divelist_font)); - ui.fontsize->setValue(prefs.font_size); - ui.defaultfilename->setText(prefs.default_filename); - ui.noDefaultFile->setChecked(prefs.default_file_behavior == NO_DEFAULT_FILE); - ui.cloudDefaultFile->setChecked(prefs.default_file_behavior == CLOUD_DEFAULT_FILE); - ui.localDefaultFile->setChecked(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - ui.default_cylinder->clear(); - for (int i = 0; tank_info[i].name != NULL; i++) { - ui.default_cylinder->addItem(tank_info[i].name); - if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0) - ui.default_cylinder->setCurrentIndex(i); - } - ui.displayinvalid->setChecked(prefs.display_invalid_dives); - ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); - ui.show_average_depth->setChecked(prefs.show_average_depth); - ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); - ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); - ui.velocitySlider->setValue(prefs.animation_speed); - - QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); - filterModel->setSourceModel(LanguageModel::instance()); - filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - ui.languageView->setModel(filterModel); - filterModel->sort(0); - connect(ui.languageFilter, SIGNAL(textChanged(QString)), filterModel, SLOT(setFilterFixedString(QString))); - - QSettings s; - - ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); - ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); - - s.beginGroup("Language"); - ui.languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool()); - QAbstractItemModel *m = ui.languageView->model(); - QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString()); - if (languages.count()) - ui.languageView->setCurrentIndex(languages.first()); - - s.endGroup(); - - ui.proxyHost->setText(prefs.proxy_host); - ui.proxyPort->setValue(prefs.proxy_port); - ui.proxyAuthRequired->setChecked(prefs.proxy_auth); - ui.proxyUsername->setText(prefs.proxy_user); - ui.proxyPassword->setText(prefs.proxy_pass); - ui.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type)); - ui.btnUseDefaultFile->setChecked(prefs.use_default_file); - - ui.cloud_storage_email->setText(prefs.cloud_storage_email); - ui.cloud_storage_password->setText(prefs.cloud_storage_password); - ui.save_password_local->setChecked(prefs.save_password_local); - cloudPinNeeded(); - ui.cloud_background_sync->setChecked(prefs.cloud_background_sync); - ui.default_uid->setText(prefs.userid); - - // GeoManagement -#ifdef DISABLED - ui.enable_geocoding->setChecked( prefs.geocoding.enable_geocoding ); - ui.parse_without_gps->setChecked(prefs.geocoding.parse_dive_without_gps); - ui.tag_existing_dives->setChecked(prefs.geocoding.tag_existing_dives); -#endif - ui.first_item->setCurrentIndex(prefs.geocoding.category[0]); - ui.second_item->setCurrentIndex(prefs.geocoding.category[1]); - ui.third_item->setCurrentIndex(prefs.geocoding.category[2]); -} - -void PreferencesDialog::restorePrefs() -{ - prefs = oldPrefs; - setUiFromPrefs(); -} - -void PreferencesDialog::rememberPrefs() -{ - oldPrefs = prefs; -} - -void PreferencesDialog::syncSettings() -{ - QSettings s; - - s.setValue("subsurface_webservice_uid", ui.default_uid->text().toUpper()); - set_save_userid_local(ui.save_uid_local->checkState()); - - // Graph - s.beginGroup("TecDetails"); - SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui.pheThreshold->value()); - SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui.po2Threshold->value()); - SAVE_OR_REMOVE("pn2threshold", default_prefs.pp_graphs.pn2_threshold, ui.pn2Threshold->value()); - SAVE_OR_REMOVE("modpO2", default_prefs.modpO2, ui.maxpo2->value()); - SAVE_OR_REMOVE("redceiling", default_prefs.redceiling, ui.red_ceiling->isChecked()); - SAVE_OR_REMOVE("gflow", default_prefs.gflow, ui.gflow->value()); - SAVE_OR_REMOVE("gfhigh", default_prefs.gfhigh, ui.gfhigh->value()); - SAVE_OR_REMOVE("gf_low_at_maxdepth", default_prefs.gf_low_at_maxdepth, ui.gf_low_at_maxdepth->isChecked()); - SAVE_OR_REMOVE("show_ccr_setpoint", default_prefs.show_ccr_setpoint, ui.show_ccr_setpoint->isChecked()); - SAVE_OR_REMOVE("show_ccr_sensors", default_prefs.show_ccr_sensors, ui.show_ccr_sensors->isChecked()); - SAVE_OR_REMOVE("display_unused_tanks", default_prefs.display_unused_tanks, ui.display_unused_tanks->isChecked()); - SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui.show_average_depth->isChecked()); - s.endGroup(); - - // Units - s.beginGroup("Units"); - QString unitSystem[] = {"metric", "imperial", "personal"}; - short unitValue = ui.metric->isChecked() ? METRIC : (ui.imperial->isChecked() ? IMPERIAL : PERSONALIZE); - SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); - s.setValue("temperature", ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS); - s.setValue("length", ui.feet->isChecked() ? units::FEET : units::METERS); - s.setValue("pressure", ui.psi->isChecked() ? units::PSI : units::BAR); - s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER); - s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG); - s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); - s.setValue("coordinates", ui.gpsTraditional->isChecked()); - s.endGroup(); - - // Defaults - s.beginGroup("GeneralSettings"); - s.setValue("default_filename", ui.defaultfilename->text()); - s.setValue("default_cylinder", ui.default_cylinder->currentText()); - s.setValue("use_default_file", ui.btnUseDefaultFile->isChecked()); - if (ui.noDefaultFile->isChecked()) - s.setValue("default_file_behavior", NO_DEFAULT_FILE); - else if (ui.localDefaultFile->isChecked()) - s.setValue("default_file_behavior", LOCAL_DEFAULT_FILE); - else if (ui.cloudDefaultFile->isChecked()) - s.setValue("default_file_behavior", CLOUD_DEFAULT_FILE); - s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0)); - s.setValue("o2consumption", rint(ui.psro2rate->value() *1000.0)); - s.setValue("pscr_ratio", rint(1000.0 / ui.pscrfactor->value())); - s.endGroup(); - - s.beginGroup("Display"); - SAVE_OR_REMOVE_SPECIAL("divelist_font", system_divelist_default_font, ui.font->currentFont().toString(), ui.font->currentFont()); - SAVE_OR_REMOVE("font_size", system_divelist_default_font_size, ui.fontsize->value()); - s.setValue("displayinvalid", ui.displayinvalid->isChecked()); - s.endGroup(); - s.sync(); - - // Locale - QLocale loc; - s.beginGroup("Language"); - bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); - if (useSystemLang != ui.languageSystemDefault->isChecked() || - (!useSystemLang && s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole))) { - QMessageBox::warning(MainWindow::instance(), tr("Restart required"), - tr("To correctly load a new language you must restart Subsurface.")); - } - s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked()); - s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole)); - s.endGroup(); - - // Animation - s.beginGroup("Animations"); - s.setValue("animation_speed", ui.velocitySlider->value()); - s.endGroup(); - - s.beginGroup("Network"); - s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); - s.setValue("proxy_host", ui.proxyHost->text()); - s.setValue("proxy_port", ui.proxyPort->value()); - SB("proxy_auth", ui.proxyAuthRequired); - s.setValue("proxy_user", ui.proxyUsername->text()); - s.setValue("proxy_pass", ui.proxyPassword->text()); - s.endGroup(); - - s.beginGroup("CloudStorage"); - QString email = ui.cloud_storage_email->text(); - QString password = ui.cloud_storage_password->text(); - QString newpassword = ui.cloud_storage_new_passwd->text(); - if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { - // deal with password change - if (!email.isEmpty() && !password.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } else { - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull())); - QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); - ui.cloud_storage_new_passwd->setText(""); - free(prefs.cloud_storage_newpassword); - prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword)); - } - } - } else if (prefs.cloud_verification_status == CS_UNKNOWN || - prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || - email != prefs.cloud_storage_email || - password != prefs.cloud_storage_password) { - - // different credentials - reset verification status - prefs.cloud_verification_status = CS_UNKNOWN; - if (!email.isEmpty() && !password.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } else { - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->backend(email, password); - } - } - } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { - QString pin = ui.cloud_storage_pin->text(); - if (!pin.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->backend(email, password, pin); - } - } - SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); - SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui.save_password_local->isChecked()); - if (ui.save_password_local->isChecked()) { - SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password); - } else { - s.remove("password"); - free(prefs.cloud_storage_password); - prefs.cloud_storage_password = strdup(qPrintable(password)); - } - SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status); - SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui.cloud_background_sync->isChecked()); - - // at this point we intentionally do not have a UI for changing this - // it could go into some sort of "advanced setup" or something - SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); - s.endGroup(); - - s.beginGroup("geocoding"); -#ifdef DISABLED - s.setValue("enable_geocoding", ui.enable_geocoding->isChecked()); - s.setValue("parse_dive_without_gps", ui.parse_without_gps->isChecked()); - s.setValue("tag_existing_dives", ui.tag_existing_dives->isChecked()); -#endif - s.setValue("cat0", ui.first_item->currentIndex()); - s.setValue("cat1", ui.second_item->currentIndex()); - s.setValue("cat2", ui.third_item->currentIndex()); - s.endGroup(); - - loadSettings(); - emit settingsChanged(); -} - -void PreferencesDialog::loadSettings() -{ - // This code was on the mainwindow, it should belong nowhere, but since we didn't - // correctly fixed this code yet ( too much stuff on the code calling preferences ) - // force this here. - loadPreferences(); - QSettings s; - QVariant v; - - ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); - ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); - - ui.defaultfilename->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - ui.btnUseDefaultFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - ui.chooseFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); -} - -void PreferencesDialog::buttonClicked(QAbstractButton *button) -{ - switch (ui.buttonBox->standardButton(button)) { - case QDialogButtonBox::Discard: - restorePrefs(); - syncSettings(); - close(); - break; - case QDialogButtonBox::Apply: - syncSettings(); - break; - case QDialogButtonBox::FirstButton: - syncSettings(); - close(); - break; - default: - break; // ignore warnings. - } -} -#undef SB - -void PreferencesDialog::on_chooseFile_clicked() -{ - QFileInfo fi(system_default_filename()); - QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)")); - - if (!choosenFileName.isEmpty()) - ui.defaultfilename->setText(choosenFileName); -} - -void PreferencesDialog::on_resetSettings_clicked() -{ - QSettings s; - - QMessageBox response(this); - response.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - response.setDefaultButton(QMessageBox::Cancel); - response.setWindowTitle(tr("Warning")); - response.setText(tr("If you click OK, all settings of Subsurface will be reset to their default values. This will be applied immediately.")); - response.setWindowModality(Qt::WindowModal); - - int result = response.exec(); - if (result == QMessageBox::Ok) { - copy_prefs(&default_prefs, &prefs); - setUiFromPrefs(); - Q_FOREACH (QString key, s.allKeys()) { - s.remove(key); - } - syncSettings(); - close(); - } -} - -void PreferencesDialog::passwordUpdateSuccessfull() -{ - ui.cloud_storage_password->setText(prefs.cloud_storage_password); -} - -void PreferencesDialog::emitSettingsChanged() -{ - emit settingsChanged(); -} - -void PreferencesDialog::proxyType_changed(int idx) -{ - if (idx == -1) { - return; - } - - int proxyType = ui.proxyType->itemData(idx).toInt(); - bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy); - ui.proxyHost->setEnabled(hpEnabled); - ui.proxyPort->setEnabled(hpEnabled); - ui.proxyAuthRequired->setEnabled(hpEnabled); - ui.proxyUsername->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); - ui.proxyPassword->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); - ui.proxyAuthRequired->setChecked(ui.proxyAuthRequired->isChecked()); -} - -void PreferencesDialog::on_btnUseDefaultFile_toggled(bool toggle) -{ - if (toggle) { - ui.defaultfilename->setText(system_default_filename()); - ui.defaultfilename->setEnabled(false); - } else { - ui.defaultfilename->setEnabled(true); - } -} - -void PreferencesDialog::on_noDefaultFile_toggled(bool toggle) -{ - prefs.default_file_behavior = NO_DEFAULT_FILE; -} - -void PreferencesDialog::on_localDefaultFile_toggled(bool toggle) -{ - ui.defaultfilename->setEnabled(toggle); - ui.btnUseDefaultFile->setEnabled(toggle); - ui.chooseFile->setEnabled(toggle); - prefs.default_file_behavior = LOCAL_DEFAULT_FILE; -} - -void PreferencesDialog::on_cloudDefaultFile_toggled(bool toggle) -{ - prefs.default_file_behavior = CLOUD_DEFAULT_FILE; -} diff --git a/qt-ui/preferences.h b/qt-ui/preferences.h deleted file mode 100644 index 326b1f964..000000000 --- a/qt-ui/preferences.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef PREFERENCES_H -#define PREFERENCES_H - -#include -#include "pref.h" - -#include "ui_preferences.h" - -#ifndef Q_OS_ANDROID - class QWebView; -#endif - -class QAbstractButton; - -class PreferencesDialog : public QDialog { - Q_OBJECT -public: - static PreferencesDialog *instance(); - void showEvent(QShowEvent *); - void emitSettingsChanged(); - -signals: - void settingsChanged(); -public -slots: - void buttonClicked(QAbstractButton *button); - void on_chooseFile_clicked(); - void on_resetSettings_clicked(); - void syncSettings(); - void loadSettings(); - void restorePrefs(); - void rememberPrefs(); - void gflowChanged(int gf); - void gfhighChanged(int gf); - void proxyType_changed(int idx); - void on_btnUseDefaultFile_toggled(bool toggle); - void on_noDefaultFile_toggled(bool toggle); - void on_localDefaultFile_toggled(bool toggle); - void on_cloudDefaultFile_toggled(bool toggle); - void facebookLoggedIn(); - void facebookDisconnect(); - void cloudPinNeeded(); - void passwordUpdateSuccessfull(); -private: - explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); - void setUiFromPrefs(); - Ui::PreferencesDialog ui; - struct preferences oldPrefs; - #ifndef Q_OS_ANDROID - QWebView *facebookWebView; - #endif -}; - -#endif // PREFERENCES_H diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui deleted file mode 100644 index de2d79b91..000000000 --- a/qt-ui/preferences.ui +++ /dev/null @@ -1,1883 +0,0 @@ - - - PreferencesDialog - - - - 0 - 0 - 711 - 662 - - - - Preferences - - - - :/subsurface-icon - - - - - 5 - - - - - - - - 0 - 0 - - - - - 120 - 0 - - - - - 120 - 16777215 - - - - - 24 - 24 - - - - Qt::ElideNone - - - QListView::Static - - - true - - - QListView::Batched - - - 0 - - - - 110 - 40 - - - - QListView::ListMode - - - true - - - true - - - -1 - - - - Defaults - - - - :/subsurface-icon - - - - - - Units - - - - :/units - - - - - - Graph - - - - :/graph - - - - - - Language - - - - :/advanced - - - - - - Network - - - - :/network - - - - - - Facebook - - - - :/facebook - - - - - - Georeference - - - - :/georeference - - - - - - - - - - 0 - 0 - - - - 4 - - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Lists and tables - - - - 5 - - - - - Font - - - - - - - - - - Font size - - - - - - - - - - - - - Dives - - - - 5 - - - 5 - - - 5 - - - - - Default dive log file - - - - - - - - - No default file - - - defaultFileGroup - - - - - - - &Local default file - - - defaultFileGroup - - - - - - - Clo&ud storage default file - - - defaultFileGroup - - - - - - - - - Local dive log file - - - - - - - - - - - - Use default - - - true - - - - - - - ... - - - - - - - - - Display invalid - - - - - - - - - - - - - - - - - Default cylinder - - - - 5 - - - 5 - - - 5 - - - - - Use default cylinder - - - - - - - - - - - - - - - - - Animations - - - - 5 - - - - - Speed - - - - - - - 500 - - - Qt::Horizontal - - - - - - - 500 - - - - - - - - - - Clear all settings - - - - 5 - - - 5 - - - - - Reset all settings to their default value - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Unit system - - - - - - System - - - - - - - &Metric - - - buttonGroup_6 - - - - - - - Imperial - - - buttonGroup_6 - - - - - - - Personali&ze - - - buttonGroup_6 - - - - - - - - - - Individual settings - - - false - - - false - - - - - - Depth - - - - - - - meter - - - buttonGroup - - - - - - - feet - - - buttonGroup - - - - - - - Pressure - - - - - - - bar - - - buttonGroup_2 - - - - - - - psi - - - buttonGroup_2 - - - - - - - Volume - - - - - - - &liter - - - buttonGroup_3 - - - - - - - cu ft - - - buttonGroup_3 - - - - - - - Temperature - - - - - - - celsius - - - buttonGroup_4 - - - - - - - fahrenheit - - - buttonGroup_4 - - - - - - - Weight - - - - - - - kg - - - buttonGroup_5 - - - - - - - lbs - - - buttonGroup_5 - - - - - - - - - - - - Time units - - - - - - Ascent/descent speed denominator - - - - - - - Minutes - - - verticalSpeed - - - - - - - Seconds - - - verticalSpeed - - - - - - - - - - - - GPS coordinates - - - - - - Location Display - - - - - - - traditional (dms) - - - buttonGroup_7 - - - - - - - decimal - - - buttonGroup_7 - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Show - - - - - - - - true - - - Threshold when showing pO₂ - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Threshold when showing pN₂ - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Threshold when showing pHe - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Max pO₂ when showing MOD - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Draw dive computer reported ceiling red - - - - - - - - - - - Show unused cylinders in Equipment tab - - - - - - - - - - - Show average depth - - - - - - - - - - - - Misc - - - - - - GFLow - - - - - - - 1 - - - 150 - - - - - - - GFHigh - - - - - - - 1 - - - 150 - - - - - - - GFLow at max depth - - - - - - - CCR: show setpoints when viewing pO₂ - - - - - - - CCR: show individual O₂ sensor values when viewing pO₂ - - - - - - - Default CCR set-point for dive planning - - - - - - - bar - - - 2 - - - 10.000000000000000 - - - 0.100000000000000 - - - - - - - pSCR O₂ metabolism rate - - - - - - - pSCR ratio - - - - - - - ℓ/min - - - 3 - - - - - - - - - - 1: - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - 0 - 0 - - - - - 5 - - - QLayout::SetNoConstraint - - - 5 - - - - - - 0 - 0 - - - - UI language - - - - - - System default - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Filter - - - - - - - - - - - - - - 0 - 0 - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Proxy - - - - - - - 0 - 0 - - - - Port - - - - - - - - - - Host - - - - - - - Qt::LeftToRight - - - Requires authentication - - - - - - - Proxy type - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Username - - - - - - - - 1 - 0 - - - - 65535 - - - 80 - - - - - - - - 0 - 0 - - - - 32 - - - - - - - - 2 - 0 - - - - 64 - - - - - - - Password - - - - - - - - 0 - 0 - - - - 32 - - - QLineEdit::Password - - - - - - - - - - - 0 - 0 - - - - - 0 - 129 - - - - Subsurface cloud storage - - - - - - - - - Email address - - - - - - - Password - - - - - - - Verification PIN - - - - - - - New password - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - Sync to cloud in the background? - - - - - - - Save Password locally? - - - - - - - - - - Subsurface web service - - - - 5 - - - 5 - - - - - Default user ID - - - - - - - - - - Save user ID locally? - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - - - - - 0 - 0 - - - - Connect to facebook text placeholder - - - - - - - - - - - - Disconnect - - - - - - - - - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Dive Site Layout - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - / - - - - - - - - 0 - 0 - - - - - - - - / - - - - - - - - 0 - 0 - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Apply|QDialogButtonBox::Discard|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - PreferencesDialog - accept() - - - 264 - 720 - - - 157 - 274 - - - - - buttonBox - rejected() - PreferencesDialog - reject() - - - 332 - 720 - - - 286 - 274 - - - - - listWidget - currentRowChanged(int) - stackedWidget - setCurrentIndex(int) - - - 37 - 97 - - - 282 - 18 - - - - - personalize - toggled(bool) - units_group - setEnabled(bool) - - - 185 - 19 - - - 186 - 23 - - - - - languageSystemDefault - toggled(bool) - languageView - setDisabled(bool) - - - 231 - 26 - - - 186 - 30 - - - - - languageSystemDefault - toggled(bool) - languageFilter - setDisabled(bool) - - - 231 - 26 - - - 185 - 20 - - - - - imperial - toggled(bool) - feet - setChecked(bool) - - - 164 - 19 - - - 175 - 34 - - - - - metric - toggled(bool) - meter - setChecked(bool) - - - 142 - 19 - - - 153 - 34 - - - - - imperial - toggled(bool) - psi - setChecked(bool) - - - 164 - 19 - - - 175 - 33 - - - - - metric - toggled(bool) - bar - setChecked(bool) - - - 142 - 19 - - - 153 - 33 - - - - - imperial - toggled(bool) - cuft - setChecked(bool) - - - 164 - 19 - - - 175 - 31 - - - - - metric - toggled(bool) - liter - setChecked(bool) - - - 142 - 19 - - - 153 - 31 - - - - - imperial - toggled(bool) - fahrenheit - setChecked(bool) - - - 164 - 19 - - - 175 - 29 - - - - - metric - toggled(bool) - celsius - setChecked(bool) - - - 142 - 19 - - - 153 - 29 - - - - - imperial - toggled(bool) - lbs - setChecked(bool) - - - 164 - 19 - - - 175 - 28 - - - - - metric - toggled(bool) - kg - setChecked(bool) - - - 142 - 19 - - - 153 - 28 - - - - - velocitySlider - valueChanged(int) - velocitySpinBox - setValue(int) - - - 236 - 52 - - - 236 - 52 - - - - - velocitySpinBox - valueChanged(int) - velocitySlider - setValue(int) - - - 236 - 52 - - - 236 - 52 - - - - - proxyAuthRequired - toggled(bool) - proxyUsername - setEnabled(bool) - - - 409 - 123 - - - 409 - 153 - - - - - proxyAuthRequired - toggled(bool) - proxyPassword - setEnabled(bool) - - - 409 - 123 - - - 409 - 183 - - - - - btnUseDefaultFile - toggled(bool) - chooseFile - setHidden(bool) - - - 236 - 44 - - - 236 - 44 - - - - - - - - - - - - - - - - diff --git a/qt-gui.cpp b/subsurface-android-helper.cpp similarity index 85% rename from qt-gui.cpp rename to subsurface-android-helper.cpp index a4997a6fe..7b5d5df56 100644 --- a/qt-gui.cpp +++ b/subsurface-android-helper.cpp @@ -2,7 +2,7 @@ /* Qt UI implementation */ #include "dive.h" #include "display.h" -#include "qt-ui/mainwindow.h" +#include "desktop-widgets/mainwindow.h" #include "helpers.h" #include @@ -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-core/CMakeLists.txt b/subsurface-core/CMakeLists.txt new file mode 100644 index 000000000..e56f8bb34 --- /dev/null +++ b/subsurface-core/CMakeLists.txt @@ -0,0 +1,84 @@ +set(PLATFORM_SRC unknown_platform.c) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(PLATFORM_SRC linux.c) +elseif(ANDROID) + set(PLATFORM_SRC android.cpp) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(PLATFORM_SRC macos.c) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(PLATFORM_SRC windows.c) +endif() + +if(FTDISUPPORT) + set(SERIAL_FTDI serial_ftdi.c) +endif() + +if(BTSUPPORT) + add_definitions(-DBT_SUPPORT) + set(BT_SRC_FILES qt-ui/btdeviceselectiondialog.cpp) + set(BT_CORE_SRC_FILES qtserialbluetooth.cpp) +endif() + +# compile the core library, in C. +set(SUBSURFACE_CORE_LIB_SRCS + cochran.c + datatrak.c + deco.c + device.c + dive.c + divesite.c + divesite.cpp + divelist.c + equipment.c + file.c + git-access.c + libdivecomputer.c + liquivision.c + load-git.c + membuffer.c + ostctools.c + parse-xml.c + planner.c + profile.c + gaspressures.c + worldmap-save.c + save-git.c + save-xml.c + save-html.c + sha1.c + statistics.c + strtod.c + subsurfacestartup.c + time.c + uemis.c + uemis-downloader.c + version.c + # gettextfrommoc should be added because we are using it on the c-code. + gettextfromc.cpp + # dirk ported some core functionality to c++. + qthelper.cpp + divecomputer.cpp + exif.cpp + subsurfacesysinfo.cpp + devicedetails.cpp + configuredivecomputer.cpp + configuredivecomputerthreads.cpp + divesitehelpers.cpp + taxonomy.c + checkcloudconnection.cpp + windowtitleupdate.cpp + divelogexportlogic.cpp + qt-init.cpp + qtserialbluetooth.cpp + metrics.cpp + color.cpp + pluginmanager.cpp + ${SERIAL_FTDI} + ${PLATFORM_SRC} + ${BT_CORE_SRC_FILES} +) +source_group("Subsurface Core" FILES ${SUBSURFACE_CORE_LIB_SRCS}) + +add_library(subsurface_corelib STATIC ${SUBSURFACE_CORE_LIB_SRCS} ) +target_link_libraries(subsurface_corelib ${QT_LIBRARIES}) + diff --git a/android.cpp b/subsurface-core/android.cpp similarity index 100% rename from android.cpp rename to subsurface-core/android.cpp diff --git a/checkcloudconnection.cpp b/subsurface-core/checkcloudconnection.cpp similarity index 100% rename from checkcloudconnection.cpp rename to subsurface-core/checkcloudconnection.cpp diff --git a/checkcloudconnection.h b/subsurface-core/checkcloudconnection.h similarity index 100% rename from checkcloudconnection.h rename to subsurface-core/checkcloudconnection.h diff --git a/cochran.c b/subsurface-core/cochran.c similarity index 100% rename from cochran.c rename to subsurface-core/cochran.c diff --git a/cochran.h b/subsurface-core/cochran.h similarity index 100% rename from cochran.h rename to subsurface-core/cochran.h diff --git a/qt-ui/graphicsview-common.cpp b/subsurface-core/color.cpp similarity index 99% rename from qt-ui/graphicsview-common.cpp rename to subsurface-core/color.cpp index a1813ce2d..cf6f43916 100644 --- a/qt-ui/graphicsview-common.cpp +++ b/subsurface-core/color.cpp @@ -1,4 +1,4 @@ -#include "graphicsview-common.h" +#include "color.h" QMap > profile_color; diff --git a/color.h b/subsurface-core/color.h similarity index 67% rename from color.h rename to subsurface-core/color.h index 7938e59a6..57ad77242 100644 --- a/color.h +++ b/subsurface-core/color.h @@ -5,6 +5,8 @@ from http://chir.ag/projects/name-that-color */ #include +#include +#include // Greens #define CAMARONE1 QColor::fromRgbF(0.0, 0.4, 0.0, 1) @@ -64,4 +66,87 @@ // Magentas #define MEDIUMREDVIOLET1_HIGHER_TRANS QColor::fromRgbF(0.7, 0.2, 0.7, 0.1) +#define SAC_COLORS_START_IDX SAC_1 +#define SAC_COLORS 9 +#define VELOCITY_COLORS_START_IDX VELO_STABLE +#define VELOCITY_COLORS 5 + +typedef enum { + /* SAC colors. Order is important, the SAC_COLORS_START_IDX define above. */ + SAC_1, + SAC_2, + SAC_3, + SAC_4, + SAC_5, + SAC_6, + SAC_7, + SAC_8, + SAC_9, + + /* Velocity colors. Order is still important, ref VELOCITY_COLORS_START_IDX. */ + VELO_STABLE, + VELO_SLOW, + VELO_MODERATE, + VELO_FAST, + VELO_CRAZY, + + /* gas colors */ + PO2, + PO2_ALERT, + PN2, + PN2_ALERT, + PHE, + PHE_ALERT, + O2SETPOINT, + CCRSENSOR1, + CCRSENSOR2, + CCRSENSOR3, + PP_LINES, + + /* Other colors */ + TEXT_BACKGROUND, + ALERT_BG, + ALERT_FG, + EVENTS, + SAMPLE_DEEP, + SAMPLE_SHALLOW, + SMOOTHED, + MINUTE, + TIME_GRID, + TIME_TEXT, + DEPTH_GRID, + MEAN_DEPTH, + HR_TEXT, + HR_PLOT, + HR_AXIS, + DEPTH_TOP, + DEPTH_BOTTOM, + TEMP_TEXT, + TEMP_PLOT, + SAC_DEFAULT, + BOUNDING_BOX, + PRESSURE_TEXT, + BACKGROUND, + BACKGROUND_TRANS, + CEILING_SHALLOW, + CEILING_DEEP, + CALC_CEILING_SHALLOW, + CALC_CEILING_DEEP, + TISSUE_PERCENTAGE, + GF_LINE, + AMB_PRESSURE_LINE +} color_indice_t; + +extern QMap > profile_color; +void fill_profile_color(); +QColor getColor(const color_indice_t i, bool isGrayscale = false); +QColor getSacColor(int sac, int diveSac); +struct text_render_options { + double size; + color_indice_t color; + double hpos, vpos; +}; + +typedef text_render_options text_render_options_t; + #endif // COLOR_H diff --git a/configuredivecomputer.cpp b/subsurface-core/configuredivecomputer.cpp similarity index 100% rename from configuredivecomputer.cpp rename to subsurface-core/configuredivecomputer.cpp diff --git a/configuredivecomputer.h b/subsurface-core/configuredivecomputer.h similarity index 100% rename from configuredivecomputer.h rename to subsurface-core/configuredivecomputer.h diff --git a/configuredivecomputerthreads.cpp b/subsurface-core/configuredivecomputerthreads.cpp similarity index 100% rename from configuredivecomputerthreads.cpp rename to subsurface-core/configuredivecomputerthreads.cpp diff --git a/configuredivecomputerthreads.h b/subsurface-core/configuredivecomputerthreads.h similarity index 100% rename from configuredivecomputerthreads.h rename to subsurface-core/configuredivecomputerthreads.h diff --git a/datatrak.c b/subsurface-core/datatrak.c similarity index 100% rename from datatrak.c rename to subsurface-core/datatrak.c diff --git a/datatrak.h b/subsurface-core/datatrak.h similarity index 100% rename from datatrak.h rename to subsurface-core/datatrak.h diff --git a/deco.c b/subsurface-core/deco.c similarity index 100% rename from deco.c rename to subsurface-core/deco.c diff --git a/deco.h b/subsurface-core/deco.h similarity index 100% rename from deco.h rename to subsurface-core/deco.h diff --git a/device.c b/subsurface-core/device.c similarity index 100% rename from device.c rename to subsurface-core/device.c diff --git a/device.h b/subsurface-core/device.h similarity index 100% rename from device.h rename to subsurface-core/device.h diff --git a/devicedetails.cpp b/subsurface-core/devicedetails.cpp similarity index 100% rename from devicedetails.cpp rename to subsurface-core/devicedetails.cpp diff --git a/devicedetails.h b/subsurface-core/devicedetails.h similarity index 100% rename from devicedetails.h rename to subsurface-core/devicedetails.h diff --git a/display.h b/subsurface-core/display.h similarity index 100% rename from display.h rename to subsurface-core/display.h diff --git a/dive.c b/subsurface-core/dive.c similarity index 100% rename from dive.c rename to subsurface-core/dive.c diff --git a/dive.h b/subsurface-core/dive.h similarity index 100% rename from dive.h rename to subsurface-core/dive.h diff --git a/divecomputer.cpp b/subsurface-core/divecomputer.cpp similarity index 100% rename from divecomputer.cpp rename to subsurface-core/divecomputer.cpp diff --git a/divecomputer.h b/subsurface-core/divecomputer.h similarity index 100% rename from divecomputer.h rename to subsurface-core/divecomputer.h diff --git a/divelist.c b/subsurface-core/divelist.c similarity index 100% rename from divelist.c rename to subsurface-core/divelist.c diff --git a/divelist.h b/subsurface-core/divelist.h similarity index 100% rename from divelist.h rename to subsurface-core/divelist.h diff --git a/divelogexportlogic.cpp b/subsurface-core/divelogexportlogic.cpp similarity index 100% rename from divelogexportlogic.cpp rename to subsurface-core/divelogexportlogic.cpp diff --git a/divelogexportlogic.h b/subsurface-core/divelogexportlogic.h similarity index 100% rename from divelogexportlogic.h rename to subsurface-core/divelogexportlogic.h diff --git a/divesite.c b/subsurface-core/divesite.c similarity index 100% rename from divesite.c rename to subsurface-core/divesite.c diff --git a/divesite.cpp b/subsurface-core/divesite.cpp similarity index 100% rename from divesite.cpp rename to subsurface-core/divesite.cpp diff --git a/divesite.h b/subsurface-core/divesite.h similarity index 100% rename from divesite.h rename to subsurface-core/divesite.h diff --git a/divesitehelpers.cpp b/subsurface-core/divesitehelpers.cpp similarity index 100% rename from divesitehelpers.cpp rename to subsurface-core/divesitehelpers.cpp diff --git a/divesitehelpers.h b/subsurface-core/divesitehelpers.h similarity index 100% rename from divesitehelpers.h rename to subsurface-core/divesitehelpers.h diff --git a/equipment.c b/subsurface-core/equipment.c similarity index 100% rename from equipment.c rename to subsurface-core/equipment.c diff --git a/exif.cpp b/subsurface-core/exif.cpp similarity index 100% rename from exif.cpp rename to subsurface-core/exif.cpp diff --git a/exif.h b/subsurface-core/exif.h similarity index 100% rename from exif.h rename to subsurface-core/exif.h diff --git a/file.c b/subsurface-core/file.c similarity index 100% rename from file.c rename to subsurface-core/file.c diff --git a/file.h b/subsurface-core/file.h similarity index 100% rename from file.h rename to subsurface-core/file.h diff --git a/gaspressures.c b/subsurface-core/gaspressures.c similarity index 100% rename from gaspressures.c rename to subsurface-core/gaspressures.c diff --git a/gaspressures.h b/subsurface-core/gaspressures.h similarity index 100% rename from gaspressures.h rename to subsurface-core/gaspressures.h diff --git a/gettext.h b/subsurface-core/gettext.h similarity index 100% rename from gettext.h rename to subsurface-core/gettext.h diff --git a/gettextfromc.cpp b/subsurface-core/gettextfromc.cpp similarity index 100% rename from gettextfromc.cpp rename to subsurface-core/gettextfromc.cpp diff --git a/gettextfromc.h b/subsurface-core/gettextfromc.h similarity index 100% rename from gettextfromc.h rename to subsurface-core/gettextfromc.h diff --git a/git-access.c b/subsurface-core/git-access.c similarity index 100% rename from git-access.c rename to subsurface-core/git-access.c diff --git a/git-access.h b/subsurface-core/git-access.h similarity index 100% rename from git-access.h rename to subsurface-core/git-access.h diff --git a/helpers.h b/subsurface-core/helpers.h similarity index 98% rename from helpers.h rename to subsurface-core/helpers.h index 5f2f2f2c5..b5c119870 100644 --- a/helpers.h +++ b/subsurface-core/helpers.h @@ -40,7 +40,6 @@ bool is_same_day (timestamp_t trip_when, timestamp_t dive_when); QString get_trip_date_string(timestamp_t when, int nr, bool getday); QString uiLanguage(QLocale *callerLoc); QLocale getLocale(); -QString getDateFormat(); void selectedDivesGasUsed(QVector > &gasUsed); QString getUserAgent(); diff --git a/subsurface-core/isocialnetworkintegration.h b/subsurface-core/isocialnetworkintegration.h new file mode 100644 index 000000000..778a171b3 --- /dev/null +++ b/subsurface-core/isocialnetworkintegration.h @@ -0,0 +1,72 @@ +#ifndef ISOCIALNETWORKINTEGRATION_H +#define ISOCIALNETWORKINTEGRATION_H + +#include + +/* This Interface represents a Plugin for Social Network integration, + * with it you may be able to create plugins for facebook, instagram, + * twitpic, google plus and any other thing you may imagine. + * + * We bundle facebook integration as an example. + */ + +class ISocialNetworkIntegration { +public: + /*! + * @name socialNetworkName + * @brief The name of this social network + * @return The name of this social network + * + * The name of this social network will be used to populate the Menu to toggle states + * between connected/disconnected, and also submit stuff to it. + */ + virtual QString socialNetworkName() const = 0; + + /*! + * @name socialNetworkIcon + * @brief The icon of this social network + * @return The icon of this social network + * + * The icon of this social network will be used to populate the menu, and can also be + * used on a toolbar if requested. + */ + virtual QString socialNetworkIcon() const = 0; + + /*! + * @name isConnected + * @brief returns true if connected to this social network, false otherwise + * @return true if connected to this social network, false otherwise + */ + virtual bool isConnected() = 0; + + /*! + * @name requestLogin + * @brief try to login on this social network. + * + * Try to login on this social network. All widget implementation that + * manages login should be done inside this function. + */ + virtual void requestLogin() = 0; + + /*! + * @name requestLogoff + * @brief tries to logoff from this social network + * + * Try to logoff from this social network. + */ + virtual void requestLogoff() = 0; + + /*! + * @name uploadCurrentDive + * @brief send the current dive info to the Social Network + * + * Should format all the options and pixmaps from the current dive + * to update to the social network. All widget stuff related to sendint + * dive information should be executed inside this function. + */ + virtual void uploadCurrentDive() = 0; +}; + +Q_DECLARE_INTERFACE(ISocialNetworkIntegration, "org.subsurface.ISocialNetworkIntegration.v1") +Q_DECLARE_METATYPE(ISocialNetworkIntegration*); +#endif \ No newline at end of file diff --git a/libdivecomputer.c b/subsurface-core/libdivecomputer.c similarity index 100% rename from libdivecomputer.c rename to subsurface-core/libdivecomputer.c diff --git a/libdivecomputer.h b/subsurface-core/libdivecomputer.h similarity index 100% rename from libdivecomputer.h rename to subsurface-core/libdivecomputer.h diff --git a/linux.c b/subsurface-core/linux.c similarity index 100% rename from linux.c rename to subsurface-core/linux.c diff --git a/liquivision.c b/subsurface-core/liquivision.c similarity index 100% rename from liquivision.c rename to subsurface-core/liquivision.c diff --git a/load-git.c b/subsurface-core/load-git.c similarity index 100% rename from load-git.c rename to subsurface-core/load-git.c diff --git a/macos.c b/subsurface-core/macos.c similarity index 100% rename from macos.c rename to subsurface-core/macos.c diff --git a/membuffer.c b/subsurface-core/membuffer.c similarity index 100% rename from membuffer.c rename to subsurface-core/membuffer.c diff --git a/membuffer.h b/subsurface-core/membuffer.h similarity index 100% rename from membuffer.h rename to subsurface-core/membuffer.h diff --git a/qt-ui/metrics.cpp b/subsurface-core/metrics.cpp similarity index 100% rename from qt-ui/metrics.cpp rename to subsurface-core/metrics.cpp diff --git a/qt-ui/metrics.h b/subsurface-core/metrics.h similarity index 100% rename from qt-ui/metrics.h rename to subsurface-core/metrics.h diff --git a/ostctools.c b/subsurface-core/ostctools.c similarity index 100% rename from ostctools.c rename to subsurface-core/ostctools.c diff --git a/parse-xml.c b/subsurface-core/parse-xml.c similarity index 100% rename from parse-xml.c rename to subsurface-core/parse-xml.c diff --git a/planner.c b/subsurface-core/planner.c similarity index 100% rename from planner.c rename to subsurface-core/planner.c diff --git a/planner.h b/subsurface-core/planner.h similarity index 100% rename from planner.h rename to subsurface-core/planner.h diff --git a/subsurface-core/pluginmanager.cpp b/subsurface-core/pluginmanager.cpp new file mode 100644 index 000000000..5c0f22525 --- /dev/null +++ b/subsurface-core/pluginmanager.cpp @@ -0,0 +1,51 @@ +#include "pluginmanager.h" + +#include +#include +#include +#include + +static QList _socialNetworks; + +PluginManager& PluginManager::instance() +{ + static PluginManager self; + return self; +} + +PluginManager::PluginManager() +{ +} + +void PluginManager::loadPlugins() +{ + QDir pluginsDir(qApp->applicationDirPath()); + +#if defined(Q_OS_WIN) + if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release") + pluginsDir.cdUp(); +#elif defined(Q_OS_MAC) + if (pluginsDir.dirName() == "MacOS") { + pluginsDir.cdUp(); + pluginsDir.cdUp(); + pluginsDir.cdUp(); + } +#endif + pluginsDir.cd("plugins"); + + qDebug() << "Plugins Directory: " << pluginsDir; + foreach (const QString& fileName, pluginsDir.entryList(QDir::Files)) { + QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); + QObject *plugin = loader.instance(); + if(!plugin) + continue; + + if (ISocialNetworkIntegration *social = qobject_cast(plugin)) + _socialNetworks.push_back(social); + } +} + +QList PluginManager::socialNetworkIntegrationPlugins() const +{ + return _socialNetworks; +} diff --git a/subsurface-core/pluginmanager.h b/subsurface-core/pluginmanager.h new file mode 100644 index 000000000..c4943895c --- /dev/null +++ b/subsurface-core/pluginmanager.h @@ -0,0 +1,19 @@ +#ifndef PLUGINMANAGER_H +#define PLUGINMANAGER_H + +#include + +#include "isocialnetworkintegration.h" + +class PluginManager { +public: + static PluginManager& instance(); + void loadPlugins(); + QList socialNetworkIntegrationPlugins() const; +private: + PluginManager(); + PluginManager(const PluginManager&) = delete; + PluginManager& operator=(const PluginManager&) = delete; +}; + +#endif \ No newline at end of file diff --git a/pref.h b/subsurface-core/pref.h similarity index 95% rename from pref.h rename to subsurface-core/pref.h index 84975aaaa..9f5f587e2 100644 --- a/pref.h +++ b/subsurface-core/pref.h @@ -44,6 +44,11 @@ struct preferences { const char *default_cylinder; const char *cloud_base_url; const char *cloud_git_url; + const char *time_format; + const char *date_format; + const char *date_format_short; + bool time_format_override; + bool date_format_override; double font_size; partial_pressure_graphs_t pp_graphs; short mod; diff --git a/prefs-macros.h b/subsurface-core/prefs-macros.h similarity index 100% rename from prefs-macros.h rename to subsurface-core/prefs-macros.h diff --git a/profile.c b/subsurface-core/profile.c similarity index 100% rename from profile.c rename to subsurface-core/profile.c diff --git a/profile.h b/subsurface-core/profile.h similarity index 100% rename from profile.h rename to subsurface-core/profile.h diff --git a/qt-gui.h b/subsurface-core/qt-gui.h similarity index 100% rename from qt-gui.h rename to subsurface-core/qt-gui.h diff --git a/qt-init.cpp b/subsurface-core/qt-init.cpp similarity index 100% rename from qt-init.cpp rename to subsurface-core/qt-init.cpp diff --git a/qthelper.cpp b/subsurface-core/qthelper.cpp similarity index 95% rename from qthelper.cpp rename to subsurface-core/qthelper.cpp index a12d25333..40c507a7e 100644 --- a/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -33,9 +33,6 @@ #include const char *existing_filename; -static QString shortDateFormat; -static QString dateFormat; -static QString timeFormat; static QLocale loc; #define translate(_context, arg) trGettext(arg) @@ -168,8 +165,8 @@ void Dive::put_date_time() { QDateTime localTime = QDateTime::fromTime_t(dive->when - gettimezoneoffset(displayed_dive.when)); localTime.setTimeSpec(Qt::UTC); - m_date = localTime.date().toString(dateFormat); - m_time = localTime.time().toString(timeFormat); + m_date = localTime.date().toString(prefs.date_format); + m_time = localTime.time().toString(prefs.time_format); } void Dive::put_timestamp() @@ -721,7 +718,11 @@ QString getUserAgent() QString uiLanguage(QLocale *callerLoc) { + QString shortDateFormat; + QString dateFormat; + QString timeFormat; QSettings s; + QVariant v; s.beginGroup("Language"); if (!s.value("UseSystemLanguage", true).toBool()) { @@ -731,6 +732,11 @@ QString uiLanguage(QLocale *callerLoc) } QString uiLang = loc.uiLanguages().first(); + GET_BOOL("time_format_override", time_format_override); + GET_BOOL("date_format_override", date_format_override); + GET_TXT("time_format", time_format); + GET_TXT("date_format", date_format); + GET_TXT("date_format_short", date_format_short); s.endGroup(); // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info @@ -742,18 +748,33 @@ QString uiLanguage(QLocale *callerLoc) if (callerLoc) *callerLoc = loc; - // the short format is fine - // the long format uses long weekday and month names, so replace those with the short ones - // for time we don't want the time zone designator and don't want leading zeroes on the hours - shortDateFormat = loc.dateFormat(QLocale::ShortFormat); - dateFormat = loc.dateFormat(QLocale::LongFormat); - dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM"); - // special hack for Swedish as our switching from long weekday names to short weekday names - // messes things up there - dateFormat.replace("'en' 'den' d:'e'", " d"); - timeFormat = loc.timeFormat(); - timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", ""); - timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", ""); + if (!prefs.date_format_override || same_string(prefs.date_format_short, "") || same_string(prefs.date_format, "")) { + // derive our standard date format from what the locale gives us + // the short format is fine + // the long format uses long weekday and month names, so replace those with the short ones + // for time we don't want the time zone designator and don't want leading zeroes on the hours + shortDateFormat = loc.dateFormat(QLocale::ShortFormat); + dateFormat = loc.dateFormat(QLocale::LongFormat); + dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM"); + // special hack for Swedish as our switching from long weekday names to short weekday names + // messes things up there + dateFormat.replace("'en' 'den' d:'e'", " d"); + if (!prefs.date_format_override || same_string(prefs.date_format, "")) { + free((void*)prefs.date_format); + prefs.date_format = strdup(qPrintable(dateFormat)); + } + if (!prefs.date_format_override || same_string(prefs.date_format_short, "")) { + free((void*)prefs.date_format_short); + prefs.date_format_short = strdup(qPrintable(shortDateFormat)); + } + } + if (!prefs.time_format_override || same_string(prefs.time_format, "")) { + timeFormat = loc.timeFormat(); + timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", ""); + timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", ""); + free((void*)prefs.time_format); + prefs.time_format = strdup(qPrintable(timeFormat)); + } return uiLang; } @@ -762,10 +783,6 @@ QLocale getLocale() return loc; } -QString getDateFormat() -{ - return dateFormat; -} void set_filename(const char *filename, bool force) { if (!force && existing_filename) @@ -1034,14 +1051,14 @@ QString get_dive_date_string(timestamp_t when) { QDateTime ts; ts.setMSecsSinceEpoch(when * 1000L); - return loc.toString(ts.toUTC(), dateFormat + " " + timeFormat); + return loc.toString(ts.toUTC(), QString(prefs.date_format) + " " + prefs.time_format); } QString get_short_dive_date_string(timestamp_t when) { QDateTime ts; ts.setMSecsSinceEpoch(when * 1000L); - return loc.toString(ts.toUTC(), shortDateFormat + " " + timeFormat); + return loc.toString(ts.toUTC(), QString(prefs.date_format_short) + " " + prefs.time_format); } const char *get_dive_date_c_string(timestamp_t when) @@ -1076,7 +1093,7 @@ QString get_trip_date_string(timestamp_t when, int nr, bool getday) QString suffix = " " + QObject::tr("(%n dive(s))", "", nr); if (getday) { - ret = localTime.date().toString(dateFormat) + suffix; + ret = localTime.date().toString(prefs.date_format) + suffix; } else { ret = localTime.date().toString("MMM yy") + suffix; } diff --git a/qthelper.h b/subsurface-core/qthelper.h similarity index 100% rename from qthelper.h rename to subsurface-core/qthelper.h diff --git a/qthelperfromc.h b/subsurface-core/qthelperfromc.h similarity index 100% rename from qthelperfromc.h rename to subsurface-core/qthelperfromc.h diff --git a/qtserialbluetooth.cpp b/subsurface-core/qtserialbluetooth.cpp similarity index 100% rename from qtserialbluetooth.cpp rename to subsurface-core/qtserialbluetooth.cpp diff --git a/save-git.c b/subsurface-core/save-git.c similarity index 100% rename from save-git.c rename to subsurface-core/save-git.c diff --git a/save-html.c b/subsurface-core/save-html.c similarity index 100% rename from save-html.c rename to subsurface-core/save-html.c diff --git a/save-html.h b/subsurface-core/save-html.h similarity index 100% rename from save-html.h rename to subsurface-core/save-html.h diff --git a/save-xml.c b/subsurface-core/save-xml.c similarity index 100% rename from save-xml.c rename to subsurface-core/save-xml.c diff --git a/serial_ftdi.c b/subsurface-core/serial_ftdi.c similarity index 100% rename from serial_ftdi.c rename to subsurface-core/serial_ftdi.c diff --git a/sha1.c b/subsurface-core/sha1.c similarity index 100% rename from sha1.c rename to subsurface-core/sha1.c diff --git a/sha1.h b/subsurface-core/sha1.h similarity index 100% rename from sha1.h rename to subsurface-core/sha1.h diff --git a/statistics.c b/subsurface-core/statistics.c similarity index 100% rename from statistics.c rename to subsurface-core/statistics.c diff --git a/statistics.h b/subsurface-core/statistics.h similarity index 100% rename from statistics.h rename to subsurface-core/statistics.h diff --git a/strndup.h b/subsurface-core/strndup.h similarity index 100% rename from strndup.h rename to subsurface-core/strndup.h diff --git a/strtod.c b/subsurface-core/strtod.c similarity index 100% rename from strtod.c rename to subsurface-core/strtod.c diff --git a/subsurfacestartup.c b/subsurface-core/subsurfacestartup.c similarity index 98% rename from subsurfacestartup.c rename to subsurface-core/subsurfacestartup.c index 1286885ee..0bde2a070 100644 --- a/subsurfacestartup.c +++ b/subsurface-core/subsurfacestartup.c @@ -291,6 +291,9 @@ void copy_prefs(struct preferences *src, struct preferences *dest) dest->proxy_host = copy_string(src->proxy_host); dest->proxy_user = copy_string(src->proxy_user); dest->proxy_pass = copy_string(src->proxy_pass); + dest->time_format = copy_string(src->time_format); + dest->date_format = copy_string(src->date_format); + dest->date_format_short = copy_string(src->date_format_short); dest->cloud_storage_password = copy_string(src->cloud_storage_password); dest->cloud_storage_newpassword = copy_string(src->cloud_storage_newpassword); dest->cloud_storage_email = copy_string(src->cloud_storage_email); diff --git a/subsurfacestartup.h b/subsurface-core/subsurfacestartup.h similarity index 100% rename from subsurfacestartup.h rename to subsurface-core/subsurfacestartup.h diff --git a/subsurfacesysinfo.cpp b/subsurface-core/subsurfacesysinfo.cpp similarity index 100% rename from subsurfacesysinfo.cpp rename to subsurface-core/subsurfacesysinfo.cpp diff --git a/subsurfacesysinfo.h b/subsurface-core/subsurfacesysinfo.h similarity index 100% rename from subsurfacesysinfo.h rename to subsurface-core/subsurfacesysinfo.h diff --git a/taxonomy.c b/subsurface-core/taxonomy.c similarity index 100% rename from taxonomy.c rename to subsurface-core/taxonomy.c diff --git a/taxonomy.h b/subsurface-core/taxonomy.h similarity index 100% rename from taxonomy.h rename to subsurface-core/taxonomy.h diff --git a/time.c b/subsurface-core/time.c similarity index 100% rename from time.c rename to subsurface-core/time.c diff --git a/uemis-downloader.c b/subsurface-core/uemis-downloader.c similarity index 100% rename from uemis-downloader.c rename to subsurface-core/uemis-downloader.c diff --git a/uemis.c b/subsurface-core/uemis.c similarity index 100% rename from uemis.c rename to subsurface-core/uemis.c diff --git a/uemis.h b/subsurface-core/uemis.h similarity index 100% rename from uemis.h rename to subsurface-core/uemis.h diff --git a/units.h b/subsurface-core/units.h similarity index 100% rename from units.h rename to subsurface-core/units.h diff --git a/version.c b/subsurface-core/version.c similarity index 100% rename from version.c rename to subsurface-core/version.c diff --git a/version.h b/subsurface-core/version.h similarity index 100% rename from version.h rename to subsurface-core/version.h diff --git a/webservice.h b/subsurface-core/webservice.h similarity index 100% rename from webservice.h rename to subsurface-core/webservice.h diff --git a/windows.c b/subsurface-core/windows.c similarity index 100% rename from windows.c rename to subsurface-core/windows.c diff --git a/windowtitleupdate.cpp b/subsurface-core/windowtitleupdate.cpp similarity index 100% rename from windowtitleupdate.cpp rename to subsurface-core/windowtitleupdate.cpp diff --git a/windowtitleupdate.h b/subsurface-core/windowtitleupdate.h similarity index 100% rename from windowtitleupdate.h rename to subsurface-core/windowtitleupdate.h diff --git a/worldmap-options.h b/subsurface-core/worldmap-options.h similarity index 100% rename from worldmap-options.h rename to subsurface-core/worldmap-options.h diff --git a/worldmap-save.c b/subsurface-core/worldmap-save.c similarity index 100% rename from worldmap-save.c rename to subsurface-core/worldmap-save.c diff --git a/worldmap-save.h b/subsurface-core/worldmap-save.h similarity index 100% rename from worldmap-save.h rename to subsurface-core/worldmap-save.h diff --git a/subsurface-desktop-helper.cpp b/subsurface-desktop-helper.cpp new file mode 100644 index 000000000..420f75249 --- /dev/null +++ b/subsurface-desktop-helper.cpp @@ -0,0 +1,65 @@ +/* qt-gui.cpp */ +/* Qt UI implementation */ +#include "dive.h" +#include "display.h" +#include "desktop-widgets/mainwindow.h" +#include "helpers.h" +#include "pluginmanager.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(); + + PluginManager::instance().loadPlugins(); + + 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 95% rename from main.cpp rename to subsurface-desktop-main.cpp index 171876abf..e7259c3f3 100644 --- a/main.cpp +++ b/subsurface-desktop-main.cpp @@ -8,9 +8,9 @@ #include "dive.h" #include "qt-gui.h" #include "subsurfacestartup.h" -#include "qt-ui/mainwindow.h" -#include "qt-ui/diveplanner.h" -#include "qt-ui/graphicsview-common.h" +#include "desktop-widgets/mainwindow.h" +#include "desktop-widgets/diveplanner.h" +#include "subsurface-core/color.h" #include "qthelper.h" #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..23642fb3c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,28 @@ +# QTest based tests +macro(TEST NAME FILE) + add_executable(${NAME} ${FILE} ) + target_link_libraries(${NAME} subsurface_corelib ${QT_TEST_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES}) + add_test(NAME ${NAME} COMMAND $) +endmacro() + +enable_testing() +add_definitions(-g) +TEST(TestUnitConversion testunitconversion.cpp) +TEST(TestProfile testprofile.cpp) +TEST(TestGpsCoords testgpscoords.cpp) +TEST(TestParse testparse.cpp) +TEST(TestPlan testplan.cpp) +TEST(TestDiveSiteDuplication testdivesiteduplication.cpp) +TEST(TestRenumber testrenumber.cpp) +TEST(TestGitStorage testgitstorage.cpp) + +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} + DEPENDS + TestUnitConversion + TestProfile + TestGpsCoords + TestParse + TestGitStorage + TestPlan + TestDiveSiteDuplication +) \ No newline at end of file