diff options
-rw-r--r-- | .travis.yml | 14 | ||||
-rw-r--r-- | CMakeLists.txt | 132 | ||||
-rw-r--r-- | cmake/QMatrixClientConfig.cmake | 1 | ||||
-rw-r--r-- | examples/CMakeLists.txt | 69 | ||||
-rw-r--r-- | lib/avatar.cpp (renamed from avatar.cpp) | 0 | ||||
-rw-r--r-- | lib/avatar.h (renamed from avatar.h) | 0 | ||||
-rw-r--r-- | lib/connection.cpp (renamed from connection.cpp) | 0 | ||||
-rw-r--r-- | lib/connection.h (renamed from connection.h) | 0 | ||||
-rw-r--r-- | lib/connectiondata.cpp (renamed from connectiondata.cpp) | 0 | ||||
-rw-r--r-- | lib/connectiondata.h (renamed from connectiondata.h) | 0 | ||||
-rw-r--r-- | lib/converters.h (renamed from converters.h) | 0 | ||||
-rw-r--r-- | lib/events/accountdataevents.h (renamed from events/accountdataevents.h) | 0 | ||||
-rw-r--r-- | lib/events/directchatevent.cpp (renamed from events/directchatevent.cpp) | 0 | ||||
-rw-r--r-- | lib/events/directchatevent.h (renamed from events/directchatevent.h) | 0 | ||||
-rw-r--r-- | lib/events/event.cpp (renamed from events/event.cpp) | 0 | ||||
-rw-r--r-- | lib/events/event.h (renamed from events/event.h) | 0 | ||||
-rw-r--r-- | lib/events/eventcontent.cpp (renamed from events/eventcontent.cpp) | 0 | ||||
-rw-r--r-- | lib/events/eventcontent.h (renamed from events/eventcontent.h) | 0 | ||||
-rw-r--r-- | lib/events/receiptevent.cpp (renamed from events/receiptevent.cpp) | 0 | ||||
-rw-r--r-- | lib/events/receiptevent.h (renamed from events/receiptevent.h) | 0 | ||||
-rw-r--r-- | lib/events/redactionevent.cpp (renamed from events/redactionevent.cpp) | 0 | ||||
-rw-r--r-- | lib/events/redactionevent.h (renamed from events/redactionevent.h) | 0 | ||||
-rw-r--r-- | lib/events/roomavatarevent.cpp (renamed from events/roomavatarevent.cpp) | 0 | ||||
-rw-r--r-- | lib/events/roomavatarevent.h (renamed from events/roomavatarevent.h) | 0 | ||||
-rw-r--r-- | lib/events/roommemberevent.cpp (renamed from events/roommemberevent.cpp) | 0 | ||||
-rw-r--r-- | lib/events/roommemberevent.h (renamed from events/roommemberevent.h) | 0 | ||||
-rw-r--r-- | lib/events/roommessageevent.cpp (renamed from events/roommessageevent.cpp) | 0 | ||||
-rw-r--r-- | lib/events/roommessageevent.h (renamed from events/roommessageevent.h) | 0 | ||||
-rw-r--r-- | lib/events/simplestateevents.h (renamed from events/simplestateevents.h) | 0 | ||||
-rw-r--r-- | lib/events/typingevent.cpp (renamed from events/typingevent.cpp) | 0 | ||||
-rw-r--r-- | lib/events/typingevent.h (renamed from events/typingevent.h) | 0 | ||||
-rw-r--r-- | lib/jobs/basejob.cpp (renamed from jobs/basejob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/basejob.h (renamed from jobs/basejob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/checkauthmethods.cpp (renamed from jobs/checkauthmethods.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/checkauthmethods.h (renamed from jobs/checkauthmethods.h) | 0 | ||||
-rw-r--r-- | lib/jobs/downloadfilejob.cpp (renamed from jobs/downloadfilejob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/downloadfilejob.h (renamed from jobs/downloadfilejob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/account-data.cpp (renamed from jobs/generated/account-data.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/account-data.h (renamed from jobs/generated/account-data.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/administrative_contact.cpp (renamed from jobs/generated/administrative_contact.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/administrative_contact.h (renamed from jobs/generated/administrative_contact.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/banning.cpp (renamed from jobs/generated/banning.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/banning.h (renamed from jobs/generated/banning.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/content-repo.cpp (renamed from jobs/generated/content-repo.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/content-repo.h (renamed from jobs/generated/content-repo.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/create_room.cpp (renamed from jobs/generated/create_room.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/create_room.h (renamed from jobs/generated/create_room.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/directory.cpp (renamed from jobs/generated/directory.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/directory.h (renamed from jobs/generated/directory.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/inviting.cpp (renamed from jobs/generated/inviting.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/inviting.h (renamed from jobs/generated/inviting.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/kicking.cpp (renamed from jobs/generated/kicking.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/kicking.h (renamed from jobs/generated/kicking.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/leaving.cpp (renamed from jobs/generated/leaving.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/leaving.h (renamed from jobs/generated/leaving.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/list_public_rooms.cpp (renamed from jobs/generated/list_public_rooms.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/list_public_rooms.h (renamed from jobs/generated/list_public_rooms.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/login.cpp (renamed from jobs/generated/login.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/login.h (renamed from jobs/generated/login.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/logout.cpp (renamed from jobs/generated/logout.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/logout.h (renamed from jobs/generated/logout.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/profile.cpp (renamed from jobs/generated/profile.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/profile.h (renamed from jobs/generated/profile.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/receipts.cpp (renamed from jobs/generated/receipts.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/receipts.h (renamed from jobs/generated/receipts.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/redaction.cpp (renamed from jobs/generated/redaction.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/redaction.h (renamed from jobs/generated/redaction.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/third_party_membership.cpp (renamed from jobs/generated/third_party_membership.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/third_party_membership.h (renamed from jobs/generated/third_party_membership.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/typing.cpp (renamed from jobs/generated/typing.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/typing.h (renamed from jobs/generated/typing.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/versions.cpp (renamed from jobs/generated/versions.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/versions.h (renamed from jobs/generated/versions.h) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/whoami.cpp (renamed from jobs/generated/whoami.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/generated/whoami.h (renamed from jobs/generated/whoami.h) | 0 | ||||
-rw-r--r-- | lib/jobs/joinroomjob.cpp (renamed from jobs/joinroomjob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/joinroomjob.h (renamed from jobs/joinroomjob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/mediathumbnailjob.cpp (renamed from jobs/mediathumbnailjob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/mediathumbnailjob.h (renamed from jobs/mediathumbnailjob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/passwordlogin.cpp (renamed from jobs/passwordlogin.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/passwordlogin.h (renamed from jobs/passwordlogin.h) | 0 | ||||
-rw-r--r-- | lib/jobs/postreadmarkersjob.h (renamed from jobs/postreadmarkersjob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/postreceiptjob.cpp (renamed from jobs/postreceiptjob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/postreceiptjob.h (renamed from jobs/postreceiptjob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/requestdata.cpp (renamed from jobs/requestdata.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/requestdata.h (renamed from jobs/requestdata.h) | 0 | ||||
-rw-r--r-- | lib/jobs/roommessagesjob.cpp (renamed from jobs/roommessagesjob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/roommessagesjob.h (renamed from jobs/roommessagesjob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/sendeventjob.cpp (renamed from jobs/sendeventjob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/sendeventjob.h (renamed from jobs/sendeventjob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/setroomstatejob.cpp (renamed from jobs/setroomstatejob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/setroomstatejob.h (renamed from jobs/setroomstatejob.h) | 0 | ||||
-rw-r--r-- | lib/jobs/syncjob.cpp (renamed from jobs/syncjob.cpp) | 0 | ||||
-rw-r--r-- | lib/jobs/syncjob.h (renamed from jobs/syncjob.h) | 0 | ||||
-rw-r--r-- | lib/joinstate.h (renamed from joinstate.h) | 0 | ||||
-rw-r--r-- | lib/logging.cpp (renamed from logging.cpp) | 0 | ||||
-rw-r--r-- | lib/logging.h (renamed from logging.h) | 0 | ||||
-rw-r--r-- | lib/networkaccessmanager.cpp (renamed from networkaccessmanager.cpp) | 0 | ||||
-rw-r--r-- | lib/networkaccessmanager.h (renamed from networkaccessmanager.h) | 0 | ||||
-rw-r--r-- | lib/networksettings.cpp (renamed from networksettings.cpp) | 0 | ||||
-rw-r--r-- | lib/networksettings.h (renamed from networksettings.h) | 0 | ||||
-rw-r--r-- | lib/room.cpp (renamed from room.cpp) | 0 | ||||
-rw-r--r-- | lib/room.h (renamed from room.h) | 0 | ||||
-rw-r--r-- | lib/settings.cpp (renamed from settings.cpp) | 246 | ||||
-rw-r--r-- | lib/settings.h (renamed from settings.h) | 0 | ||||
-rw-r--r-- | lib/user.cpp (renamed from user.cpp) | 0 | ||||
-rw-r--r-- | lib/user.h (renamed from user.h) | 0 | ||||
-rw-r--r-- | lib/util.h (renamed from util.h) | 0 | ||||
-rw-r--r-- | libqmatrixclient.pri | 133 | ||||
-rw-r--r-- | state.cpp | 69 | ||||
-rw-r--r-- | state.h | 47 |
111 files changed, 366 insertions, 345 deletions
diff --git a/.travis.yml b/.travis.yml index a5938670..45db175a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,12 +25,20 @@ before_install: - if [ "$TRAVIS_OS_NAME" = "linux" ]; then VALGRIND="valgrind $VALGRIND_OPTIONS"; . /opt/qt56/bin/qt56-env.sh; fi script: -- mkdir build && cd build -- cmake .. +# Build and install with CMake +- mkdir build && pushd build +- cmake -DCMAKE_INSTALL_PREFIX=../install .. - cmake --build . --target all -- cd .. +- cmake --build . --target install +# Build qmc-example with the installed library +- popd && mkdir build-example && pushd build-example +- cmake -DCMAKE_PREFIX_PATH=../install ../examples +- cmake --build . --target all +- popd +# Build and install with qmake - qmake qmc-example.pro "CONFIG += debug" "CONFIG -= app_bundle" "QMAKE_CC = $CC" "QMAKE_CXX = $CXX" - make all +# Run the qmake-compiled qmc-example under valgrind - if [ "$QMC_TEST_USER" != "" ]; then $VALGRIND ./qmc-example "$QMC_TEST_USER" "$QMC_TEST_PWD" qmc-example-travis '#qmc-test:matrix.org' "Travis CI job $TRAVIS_JOB_NUMBER"; fi notifications: diff --git a/CMakeLists.txt b/CMakeLists.txt index 82ab2b55..956c9a1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,10 @@ cmake_minimum_required(VERSION 3.1) project(qmatrixclient CXX) include(CheckCXXCompilerFlag) +if (NOT WIN32) + include(GNUInstallDirs) +endif(NOT WIN32) -# Find includes in corresponding build directories -set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) @@ -18,6 +19,18 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) "MinSizeRel" "RelWithDebInfo") endif() +if (NOT CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR ".") +endif() + +if (NOT CMAKE_INSTALL_BINDIR) + set(CMAKE_INSTALL_BINDIR ".") +endif() + +if (NOT CMAKE_INSTALL_INCLUDEDIR) + set(CMAKE_INSTALL_INCLUDEDIR "include") +endif() + set(CMAKE_CXX_STANDARD 14) foreach (FLAG all "" pedantic extra error=return-type no-unused-parameter no-gnu-zero-variadic-macro-arguments) @@ -44,49 +57,94 @@ message( STATUS ) # Set up source files set(libqmatrixclient_SRCS - networkaccessmanager.cpp - connectiondata.cpp - connection.cpp - logging.cpp - room.cpp - user.cpp - avatar.cpp - settings.cpp - networksettings.cpp - events/event.cpp - events/eventcontent.cpp - events/roommessageevent.cpp - events/roommemberevent.cpp - events/roomavatarevent.cpp - events/typingevent.cpp - events/receiptevent.cpp - events/directchatevent.cpp - jobs/requestdata.cpp - jobs/basejob.cpp - jobs/checkauthmethods.cpp - jobs/sendeventjob.cpp - jobs/setroomstatejob.cpp - jobs/joinroomjob.cpp - jobs/roommessagesjob.cpp - jobs/syncjob.cpp - jobs/mediathumbnailjob.cpp - jobs/downloadfilejob.cpp + lib/networkaccessmanager.cpp + lib/connectiondata.cpp + lib/connection.cpp + lib/logging.cpp + lib/room.cpp + lib/user.cpp + lib/avatar.cpp + lib/settings.cpp + lib/networksettings.cpp + lib/events/event.cpp + lib/events/eventcontent.cpp + lib/events/roommessageevent.cpp + lib/events/roommemberevent.cpp + lib/events/roomavatarevent.cpp + lib/events/typingevent.cpp + lib/events/receiptevent.cpp + lib/events/directchatevent.cpp + lib/jobs/requestdata.cpp + lib/jobs/basejob.cpp + lib/jobs/checkauthmethods.cpp + lib/jobs/sendeventjob.cpp + lib/jobs/setroomstatejob.cpp + lib/jobs/joinroomjob.cpp + lib/jobs/roommessagesjob.cpp + lib/jobs/syncjob.cpp + lib/jobs/mediathumbnailjob.cpp + lib/jobs/downloadfilejob.cpp ) -aux_source_directory(jobs/generated libqmatrixclient_job_SRCS) +aux_source_directory(lib/jobs/generated libqmatrixclient_job_SRCS) set(example_SRCS examples/qmc-example.cpp) -add_library(qmatrixclient ${libqmatrixclient_SRCS} ${libqmatrixclient_job_SRCS}) -set_property(TARGET qmatrixclient PROPERTY VERSION "0.2.0") -set_property(TARGET qmatrixclient PROPERTY SOVERSION 0 ) +add_library(QMatrixClient ${libqmatrixclient_SRCS} ${libqmatrixclient_job_SRCS}) +set(API_VERSION 2) +set_property(TARGET QMatrixClient PROPERTY VERSION "0.2.0") +set_property(TARGET QMatrixClient PROPERTY SOVERSION 0 ) +set_property(TARGET QMatrixClient PROPERTY + INTERFACE_QMatrixClient_MAJOR_VERSION ${API_VERSION}) +set_property(TARGET QMatrixClient APPEND PROPERTY + COMPATIBLE_INTERFACE_STRING QMatrixClient_MAJOR_VERSION) -target_link_libraries(qmatrixclient Qt5::Core Qt5::Network Qt5::Gui) +target_include_directories(QMatrixClient PUBLIC + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib> + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> +) +target_link_libraries(QMatrixClient Qt5::Core Qt5::Network Qt5::Gui) add_executable(qmc-example ${example_SRCS}) -target_link_libraries(qmc-example Qt5::Core qmatrixclient) +target_link_libraries(qmc-example Qt5::Core QMatrixClient) + +# Installation + +install(TARGETS QMatrixClient EXPORT QMatrixClientTargets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +install(DIRECTORY lib/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.h") + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/QMatrixClient/QMatrixClientConfigVersion.cmake" + VERSION ${API_VERSION} + COMPATIBILITY AnyNewerVersion +) + +export(PACKAGE QMatrixClient) +export(EXPORT QMatrixClientTargets + FILE "${CMAKE_CURRENT_BINARY_DIR}/QMatrixClient/QMatrixClientTargets.cmake") +configure_file(cmake/QMatrixClientConfig.cmake + "${CMAKE_CURRENT_BINARY_DIR}/QMatrixClient/QMatrixClientConfig.cmake" + COPYONLY +) + +set(ConfigFilesLocation "${CMAKE_INSTALL_LIBDIR}/cmake/QMatrixClient") +install(EXPORT QMatrixClientTargets + FILE QMatrixClientTargets.cmake DESTINATION ${ConfigFilesLocation}) + +install(FILES cmake/QMatrixClientConfig.cmake + "${CMAKE_CURRENT_BINARY_DIR}/QMatrixClient/QMatrixClientConfigVersion.cmake" + DESTINATION ${ConfigFilesLocation} +) +install(EXPORT_ANDROID_MK QMatrixClientTargets DESTINATION share/ndk-modules) if (WIN32) - install (FILES mime/packages/freedesktop.org.xml - DESTINATION mime/packages) + install(FILES mime/packages/freedesktop.org.xml DESTINATION mime/packages) endif (WIN32) + +install(TARGETS qmc-example RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/cmake/QMatrixClientConfig.cmake b/cmake/QMatrixClientConfig.cmake new file mode 100644 index 00000000..900038a5 --- /dev/null +++ b/cmake/QMatrixClientConfig.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/QMatrixClientTargets.cmake") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..49e0089a --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.1) + +# This CMakeLists file assumes that the library is installed to CMAKE_INSTALL_PREFIX +# and ignores the in-tree library code. You can use this to start work on your own client. + +project(qmc-example CXX) + +include(CheckCXXCompilerFlag) +if (NOT WIN32) + include(GNUInstallDirs) +endif(NOT WIN32) + +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +# Set a default build type if none was specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Debug' as none was specified") + set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build" FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() + +if (NOT CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR ".") +endif() + +if (NOT CMAKE_INSTALL_BINDIR) + set(CMAKE_INSTALL_BINDIR ".") +endif() + +if (NOT CMAKE_INSTALL_INCLUDEDIR) + set(CMAKE_INSTALL_INCLUDEDIR "include") +endif() + +set(CMAKE_CXX_STANDARD 14) + +foreach (FLAG all "" pedantic extra error=return-type no-unused-parameter no-gnu-zero-variadic-macro-arguments) + CHECK_CXX_COMPILER_FLAG("-W${FLAG}" WARN_${FLAG}_SUPPORTED) + if ( WARN_${FLAG}_SUPPORTED AND NOT CMAKE_CXX_FLAGS MATCHES "(^| )-W?${FLAG}($| )") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W${FLAG}") + endif () +endforeach () + +find_package(Qt5 5.6 REQUIRED Network Gui) +get_filename_component(Qt5_Prefix "${Qt5_DIR}/../../../.." ABSOLUTE) + +find_package(QMatrixClient REQUIRED) +get_filename_component(QMC_Prefix "${QMatrixClient_DIR}/../.." ABSOLUTE) + +message( STATUS "qmc-example configuration:" ) +if (CMAKE_BUILD_TYPE) + message( STATUS " Build type: ${CMAKE_BUILD_TYPE}") +endif(CMAKE_BUILD_TYPE) +message( STATUS " Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}" ) +message( STATUS " Qt: ${Qt5_VERSION} at ${Qt5_Prefix}" ) +message( STATUS " QMatrixClient: ${QMatrixClient_VERSION} at ${QMC_Prefix}" ) + +set(example_SRCS qmc-example.cpp) + +add_executable(qmc-example ${example_SRCS}) +target_link_libraries(qmc-example Qt5::Core QMatrixClient) + +# Installation + +install (TARGETS qmc-example RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/avatar.cpp b/lib/avatar.cpp index 1ff2aae1..1ff2aae1 100644 --- a/avatar.cpp +++ b/lib/avatar.cpp diff --git a/connection.cpp b/lib/connection.cpp index 2d7235b9..2d7235b9 100644 --- a/connection.cpp +++ b/lib/connection.cpp diff --git a/connection.h b/lib/connection.h index c6d543ec..c6d543ec 100644 --- a/connection.h +++ b/lib/connection.h diff --git a/connectiondata.cpp b/lib/connectiondata.cpp index 4e9bc77e..4e9bc77e 100644 --- a/connectiondata.cpp +++ b/lib/connectiondata.cpp diff --git a/connectiondata.h b/lib/connectiondata.h index 7a2f2e90..7a2f2e90 100644 --- a/connectiondata.h +++ b/lib/connectiondata.h diff --git a/converters.h b/lib/converters.h index bba298e0..bba298e0 100644 --- a/converters.h +++ b/lib/converters.h diff --git a/events/accountdataevents.h b/lib/events/accountdataevents.h index f3ba27bb..f3ba27bb 100644 --- a/events/accountdataevents.h +++ b/lib/events/accountdataevents.h diff --git a/events/directchatevent.cpp b/lib/events/directchatevent.cpp index 7049d967..7049d967 100644 --- a/events/directchatevent.cpp +++ b/lib/events/directchatevent.cpp diff --git a/events/directchatevent.h b/lib/events/directchatevent.h index 2b0ad0a0..2b0ad0a0 100644 --- a/events/directchatevent.h +++ b/lib/events/directchatevent.h diff --git a/events/event.cpp b/lib/events/event.cpp index 8ddf3945..8ddf3945 100644 --- a/events/event.cpp +++ b/lib/events/event.cpp diff --git a/events/event.h b/lib/events/event.h index eccfec41..eccfec41 100644 --- a/events/event.h +++ b/lib/events/event.h diff --git a/events/eventcontent.cpp b/lib/events/eventcontent.cpp index f5974b46..f5974b46 100644 --- a/events/eventcontent.cpp +++ b/lib/events/eventcontent.cpp diff --git a/events/eventcontent.h b/lib/events/eventcontent.h index 9d44aec0..9d44aec0 100644 --- a/events/eventcontent.h +++ b/lib/events/eventcontent.h diff --git a/events/receiptevent.cpp b/lib/events/receiptevent.cpp index 7555db82..7555db82 100644 --- a/events/receiptevent.cpp +++ b/lib/events/receiptevent.cpp diff --git a/events/receiptevent.h b/lib/events/receiptevent.h index 5b99ae3f..5b99ae3f 100644 --- a/events/receiptevent.h +++ b/lib/events/receiptevent.h diff --git a/events/redactionevent.cpp b/lib/events/redactionevent.cpp index bf467718..bf467718 100644 --- a/events/redactionevent.cpp +++ b/lib/events/redactionevent.cpp diff --git a/events/redactionevent.h b/lib/events/redactionevent.h index fa6902ab..fa6902ab 100644 --- a/events/redactionevent.h +++ b/lib/events/redactionevent.h diff --git a/events/roomavatarevent.cpp b/lib/events/roomavatarevent.cpp index 7a5f82a1..7a5f82a1 100644 --- a/events/roomavatarevent.cpp +++ b/lib/events/roomavatarevent.cpp diff --git a/events/roomavatarevent.h b/lib/events/roomavatarevent.h index ccfe8fbf..ccfe8fbf 100644 --- a/events/roomavatarevent.h +++ b/lib/events/roomavatarevent.h diff --git a/events/roommemberevent.cpp b/lib/events/roommemberevent.cpp index 76b003c2..76b003c2 100644 --- a/events/roommemberevent.cpp +++ b/lib/events/roommemberevent.cpp diff --git a/events/roommemberevent.h b/lib/events/roommemberevent.h index 89b970c9..89b970c9 100644 --- a/events/roommemberevent.h +++ b/lib/events/roommemberevent.h diff --git a/events/roommessageevent.cpp b/lib/events/roommessageevent.cpp index dec0ca50..dec0ca50 100644 --- a/events/roommessageevent.cpp +++ b/lib/events/roommessageevent.cpp diff --git a/events/roommessageevent.h b/lib/events/roommessageevent.h index a55564ed..a55564ed 100644 --- a/events/roommessageevent.h +++ b/lib/events/roommessageevent.h diff --git a/events/simplestateevents.h b/lib/events/simplestateevents.h index 6b0cd51a..6b0cd51a 100644 --- a/events/simplestateevents.h +++ b/lib/events/simplestateevents.h diff --git a/events/typingevent.cpp b/lib/events/typingevent.cpp index a4d3bae4..a4d3bae4 100644 --- a/events/typingevent.cpp +++ b/lib/events/typingevent.cpp diff --git a/events/typingevent.h b/lib/events/typingevent.h index 8c9551a4..8c9551a4 100644 --- a/events/typingevent.h +++ b/lib/events/typingevent.h diff --git a/jobs/basejob.cpp b/lib/jobs/basejob.cpp index a23f43b3..a23f43b3 100644 --- a/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp diff --git a/jobs/basejob.h b/lib/jobs/basejob.h index ed630a67..ed630a67 100644 --- a/jobs/basejob.h +++ b/lib/jobs/basejob.h diff --git a/jobs/checkauthmethods.cpp b/lib/jobs/checkauthmethods.cpp index 117def89..117def89 100644 --- a/jobs/checkauthmethods.cpp +++ b/lib/jobs/checkauthmethods.cpp diff --git a/jobs/checkauthmethods.h b/lib/jobs/checkauthmethods.h index 647f3db6..647f3db6 100644 --- a/jobs/checkauthmethods.h +++ b/lib/jobs/checkauthmethods.h diff --git a/jobs/downloadfilejob.cpp b/lib/jobs/downloadfilejob.cpp index 6a3d8483..6a3d8483 100644 --- a/jobs/downloadfilejob.cpp +++ b/lib/jobs/downloadfilejob.cpp diff --git a/jobs/downloadfilejob.h b/lib/jobs/downloadfilejob.h index 1815a7c8..1815a7c8 100644 --- a/jobs/downloadfilejob.h +++ b/lib/jobs/downloadfilejob.h diff --git a/jobs/generated/account-data.cpp b/lib/jobs/generated/account-data.cpp index 35ee94c0..35ee94c0 100644 --- a/jobs/generated/account-data.cpp +++ b/lib/jobs/generated/account-data.cpp diff --git a/jobs/generated/account-data.h b/lib/jobs/generated/account-data.h index 69ad9fb4..69ad9fb4 100644 --- a/jobs/generated/account-data.h +++ b/lib/jobs/generated/account-data.h diff --git a/jobs/generated/administrative_contact.cpp b/lib/jobs/generated/administrative_contact.cpp index 1af57941..1af57941 100644 --- a/jobs/generated/administrative_contact.cpp +++ b/lib/jobs/generated/administrative_contact.cpp diff --git a/jobs/generated/administrative_contact.h b/lib/jobs/generated/administrative_contact.h index c8429d39..c8429d39 100644 --- a/jobs/generated/administrative_contact.h +++ b/lib/jobs/generated/administrative_contact.h diff --git a/jobs/generated/banning.cpp b/lib/jobs/generated/banning.cpp index f66b27b6..f66b27b6 100644 --- a/jobs/generated/banning.cpp +++ b/lib/jobs/generated/banning.cpp diff --git a/jobs/generated/banning.h b/lib/jobs/generated/banning.h index 2d6fbd9b..2d6fbd9b 100644 --- a/jobs/generated/banning.h +++ b/lib/jobs/generated/banning.h diff --git a/jobs/generated/content-repo.cpp b/lib/jobs/generated/content-repo.cpp index 51011251..51011251 100644 --- a/jobs/generated/content-repo.cpp +++ b/lib/jobs/generated/content-repo.cpp diff --git a/jobs/generated/content-repo.h b/lib/jobs/generated/content-repo.h index b4ea562f..b4ea562f 100644 --- a/jobs/generated/content-repo.h +++ b/lib/jobs/generated/content-repo.h diff --git a/jobs/generated/create_room.cpp b/lib/jobs/generated/create_room.cpp index de7807b5..de7807b5 100644 --- a/jobs/generated/create_room.cpp +++ b/lib/jobs/generated/create_room.cpp diff --git a/jobs/generated/create_room.h b/lib/jobs/generated/create_room.h index b479615a..b479615a 100644 --- a/jobs/generated/create_room.h +++ b/lib/jobs/generated/create_room.h diff --git a/jobs/generated/directory.cpp b/lib/jobs/generated/directory.cpp index 9428dcee..9428dcee 100644 --- a/jobs/generated/directory.cpp +++ b/lib/jobs/generated/directory.cpp diff --git a/jobs/generated/directory.h b/lib/jobs/generated/directory.h index 87591240..87591240 100644 --- a/jobs/generated/directory.h +++ b/lib/jobs/generated/directory.h diff --git a/jobs/generated/inviting.cpp b/lib/jobs/generated/inviting.cpp index d2ee2107..d2ee2107 100644 --- a/jobs/generated/inviting.cpp +++ b/lib/jobs/generated/inviting.cpp diff --git a/jobs/generated/inviting.h b/lib/jobs/generated/inviting.h index eaa884df..eaa884df 100644 --- a/jobs/generated/inviting.h +++ b/lib/jobs/generated/inviting.h diff --git a/jobs/generated/kicking.cpp b/lib/jobs/generated/kicking.cpp index bf2490b7..bf2490b7 100644 --- a/jobs/generated/kicking.cpp +++ b/lib/jobs/generated/kicking.cpp diff --git a/jobs/generated/kicking.h b/lib/jobs/generated/kicking.h index 3814bef7..3814bef7 100644 --- a/jobs/generated/kicking.h +++ b/lib/jobs/generated/kicking.h diff --git a/jobs/generated/leaving.cpp b/lib/jobs/generated/leaving.cpp index fbc40d11..fbc40d11 100644 --- a/jobs/generated/leaving.cpp +++ b/lib/jobs/generated/leaving.cpp diff --git a/jobs/generated/leaving.h b/lib/jobs/generated/leaving.h index 9bae2363..9bae2363 100644 --- a/jobs/generated/leaving.h +++ b/lib/jobs/generated/leaving.h diff --git a/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp index 39653300..39653300 100644 --- a/jobs/generated/list_public_rooms.cpp +++ b/lib/jobs/generated/list_public_rooms.cpp diff --git a/jobs/generated/list_public_rooms.h b/lib/jobs/generated/list_public_rooms.h index 5c281de3..5c281de3 100644 --- a/jobs/generated/list_public_rooms.h +++ b/lib/jobs/generated/list_public_rooms.h diff --git a/jobs/generated/login.cpp b/lib/jobs/generated/login.cpp index a4dab428..a4dab428 100644 --- a/jobs/generated/login.cpp +++ b/lib/jobs/generated/login.cpp diff --git a/jobs/generated/login.h b/lib/jobs/generated/login.h index 3ac955d4..3ac955d4 100644 --- a/jobs/generated/login.h +++ b/lib/jobs/generated/login.h diff --git a/jobs/generated/logout.cpp b/lib/jobs/generated/logout.cpp index 83139842..83139842 100644 --- a/jobs/generated/logout.cpp +++ b/lib/jobs/generated/logout.cpp diff --git a/jobs/generated/logout.h b/lib/jobs/generated/logout.h index 7640ba55..7640ba55 100644 --- a/jobs/generated/logout.h +++ b/lib/jobs/generated/logout.h diff --git a/jobs/generated/profile.cpp b/lib/jobs/generated/profile.cpp index 1f7092d7..1f7092d7 100644 --- a/jobs/generated/profile.cpp +++ b/lib/jobs/generated/profile.cpp diff --git a/jobs/generated/profile.h b/lib/jobs/generated/profile.h index 024130f5..024130f5 100644 --- a/jobs/generated/profile.h +++ b/lib/jobs/generated/profile.h diff --git a/jobs/generated/receipts.cpp b/lib/jobs/generated/receipts.cpp index 83c38b6f..83c38b6f 100644 --- a/jobs/generated/receipts.cpp +++ b/lib/jobs/generated/receipts.cpp diff --git a/jobs/generated/receipts.h b/lib/jobs/generated/receipts.h index 9eb7a489..9eb7a489 100644 --- a/jobs/generated/receipts.h +++ b/lib/jobs/generated/receipts.h diff --git a/jobs/generated/redaction.cpp b/lib/jobs/generated/redaction.cpp index 0da35dfc..0da35dfc 100644 --- a/jobs/generated/redaction.cpp +++ b/lib/jobs/generated/redaction.cpp diff --git a/jobs/generated/redaction.h b/lib/jobs/generated/redaction.h index e3b3ff4f..e3b3ff4f 100644 --- a/jobs/generated/redaction.h +++ b/lib/jobs/generated/redaction.h diff --git a/jobs/generated/third_party_membership.cpp b/lib/jobs/generated/third_party_membership.cpp index b637d481..b637d481 100644 --- a/jobs/generated/third_party_membership.cpp +++ b/lib/jobs/generated/third_party_membership.cpp diff --git a/jobs/generated/third_party_membership.h b/lib/jobs/generated/third_party_membership.h index c7b5214e..c7b5214e 100644 --- a/jobs/generated/third_party_membership.h +++ b/lib/jobs/generated/third_party_membership.h diff --git a/jobs/generated/typing.cpp b/lib/jobs/generated/typing.cpp index fa700290..fa700290 100644 --- a/jobs/generated/typing.cpp +++ b/lib/jobs/generated/typing.cpp diff --git a/jobs/generated/typing.h b/lib/jobs/generated/typing.h index 0495ed0a..0495ed0a 100644 --- a/jobs/generated/typing.h +++ b/lib/jobs/generated/typing.h diff --git a/jobs/generated/versions.cpp b/lib/jobs/generated/versions.cpp index b12594ca..b12594ca 100644 --- a/jobs/generated/versions.cpp +++ b/lib/jobs/generated/versions.cpp diff --git a/jobs/generated/versions.h b/lib/jobs/generated/versions.h index 18f6bb44..18f6bb44 100644 --- a/jobs/generated/versions.h +++ b/lib/jobs/generated/versions.h diff --git a/jobs/generated/whoami.cpp b/lib/jobs/generated/whoami.cpp index cc38fa4d..cc38fa4d 100644 --- a/jobs/generated/whoami.cpp +++ b/lib/jobs/generated/whoami.cpp diff --git a/jobs/generated/whoami.h b/lib/jobs/generated/whoami.h index 835232ee..835232ee 100644 --- a/jobs/generated/whoami.h +++ b/lib/jobs/generated/whoami.h diff --git a/jobs/joinroomjob.cpp b/lib/jobs/joinroomjob.cpp index 66a75089..66a75089 100644 --- a/jobs/joinroomjob.cpp +++ b/lib/jobs/joinroomjob.cpp diff --git a/jobs/joinroomjob.h b/lib/jobs/joinroomjob.h index f3ba216f..f3ba216f 100644 --- a/jobs/joinroomjob.h +++ b/lib/jobs/joinroomjob.h diff --git a/jobs/mediathumbnailjob.cpp b/lib/jobs/mediathumbnailjob.cpp index dda1cdb4..dda1cdb4 100644 --- a/jobs/mediathumbnailjob.cpp +++ b/lib/jobs/mediathumbnailjob.cpp diff --git a/jobs/mediathumbnailjob.h b/lib/jobs/mediathumbnailjob.h index 6e0b94f3..6e0b94f3 100644 --- a/jobs/mediathumbnailjob.h +++ b/lib/jobs/mediathumbnailjob.h diff --git a/jobs/passwordlogin.cpp b/lib/jobs/passwordlogin.cpp index 8abfe66a..8abfe66a 100644 --- a/jobs/passwordlogin.cpp +++ b/lib/jobs/passwordlogin.cpp diff --git a/jobs/passwordlogin.h b/lib/jobs/passwordlogin.h index fb8777a3..fb8777a3 100644 --- a/jobs/passwordlogin.h +++ b/lib/jobs/passwordlogin.h diff --git a/jobs/postreadmarkersjob.h b/lib/jobs/postreadmarkersjob.h index d0198821..d0198821 100644 --- a/jobs/postreadmarkersjob.h +++ b/lib/jobs/postreadmarkersjob.h diff --git a/jobs/postreceiptjob.cpp b/lib/jobs/postreceiptjob.cpp index 4572d74c..4572d74c 100644 --- a/jobs/postreceiptjob.cpp +++ b/lib/jobs/postreceiptjob.cpp diff --git a/jobs/postreceiptjob.h b/lib/jobs/postreceiptjob.h index 23df7c05..23df7c05 100644 --- a/jobs/postreceiptjob.h +++ b/lib/jobs/postreceiptjob.h diff --git a/jobs/requestdata.cpp b/lib/jobs/requestdata.cpp index 5cb62221..5cb62221 100644 --- a/jobs/requestdata.cpp +++ b/lib/jobs/requestdata.cpp diff --git a/jobs/requestdata.h b/lib/jobs/requestdata.h index aa03b744..aa03b744 100644 --- a/jobs/requestdata.h +++ b/lib/jobs/requestdata.h diff --git a/jobs/roommessagesjob.cpp b/lib/jobs/roommessagesjob.cpp index e5568f17..e5568f17 100644 --- a/jobs/roommessagesjob.cpp +++ b/lib/jobs/roommessagesjob.cpp diff --git a/jobs/roommessagesjob.h b/lib/jobs/roommessagesjob.h index 7b3fd9c9..7b3fd9c9 100644 --- a/jobs/roommessagesjob.h +++ b/lib/jobs/roommessagesjob.h diff --git a/jobs/sendeventjob.cpp b/lib/jobs/sendeventjob.cpp index f5190d4b..f5190d4b 100644 --- a/jobs/sendeventjob.cpp +++ b/lib/jobs/sendeventjob.cpp diff --git a/jobs/sendeventjob.h b/lib/jobs/sendeventjob.h index 3a11eb6a..3a11eb6a 100644 --- a/jobs/sendeventjob.h +++ b/lib/jobs/sendeventjob.h diff --git a/jobs/setroomstatejob.cpp b/lib/jobs/setroomstatejob.cpp index c2beb87b..c2beb87b 100644 --- a/jobs/setroomstatejob.cpp +++ b/lib/jobs/setroomstatejob.cpp diff --git a/jobs/setroomstatejob.h b/lib/jobs/setroomstatejob.h index b7e6d4a1..b7e6d4a1 100644 --- a/jobs/setroomstatejob.h +++ b/lib/jobs/setroomstatejob.h diff --git a/jobs/syncjob.cpp b/lib/jobs/syncjob.cpp index 435dfd0e..435dfd0e 100644 --- a/jobs/syncjob.cpp +++ b/lib/jobs/syncjob.cpp diff --git a/jobs/syncjob.h b/lib/jobs/syncjob.h index 919060be..919060be 100644 --- a/jobs/syncjob.h +++ b/lib/jobs/syncjob.h diff --git a/joinstate.h b/lib/joinstate.h index 42613895..42613895 100644 --- a/joinstate.h +++ b/lib/joinstate.h diff --git a/logging.cpp b/lib/logging.cpp index 7476781f..7476781f 100644 --- a/logging.cpp +++ b/lib/logging.cpp diff --git a/logging.h b/lib/logging.h index 8dbfdf30..8dbfdf30 100644 --- a/logging.h +++ b/lib/logging.h diff --git a/networkaccessmanager.cpp b/lib/networkaccessmanager.cpp index 89967a8a..89967a8a 100644 --- a/networkaccessmanager.cpp +++ b/lib/networkaccessmanager.cpp diff --git a/networkaccessmanager.h b/lib/networkaccessmanager.h index ae847582..ae847582 100644 --- a/networkaccessmanager.h +++ b/lib/networkaccessmanager.h diff --git a/networksettings.cpp b/lib/networksettings.cpp index 48bd09f3..48bd09f3 100644 --- a/networksettings.cpp +++ b/lib/networksettings.cpp diff --git a/networksettings.h b/lib/networksettings.h index 83613060..83613060 100644 --- a/networksettings.h +++ b/lib/networksettings.h diff --git a/settings.cpp b/lib/settings.cpp index bf369c58..852e19cb 100644 --- a/settings.cpp +++ b/lib/settings.cpp @@ -1,123 +1,123 @@ -#include "settings.h"
-
-#include "logging.h"
-
-#include <QtCore/QUrl>
-
-using namespace QMatrixClient;
-
-QString Settings::legacyOrganizationName {};
-QString Settings::legacyApplicationName {};
-
-void Settings::setLegacyNames(const QString& organizationName,
- const QString& applicationName)
-{
- legacyOrganizationName = organizationName;
- legacyApplicationName = applicationName;
-}
-
-void Settings::setValue(const QString& key, const QVariant& value)
-{
-// qCDebug() << "Setting" << key << "to" << value;
- QSettings::setValue(key, value);
- if (legacySettings.contains(key))
- legacySettings.remove(key);
-}
-
-QVariant Settings::value(const QString& key, const QVariant& defaultValue) const
-{
- auto value = QSettings::value(key, legacySettings.value(key, defaultValue));
- // QML's Qt.labs.Settings stores boolean values as strings, which, if loaded
- // through the usual QSettings interface, confuses QML
- // (QVariant("false") == true in JavaScript). Since we have a mixed
- // environment where both QSettings and Qt.labs.Settings may potentially
- // work with same settings, better ensure compatibility.
- return value.toString() == QStringLiteral("false") ? QVariant(false) : value;
-}
-
-bool Settings::contains(const QString& key) const
-{
- return QSettings::contains(key) || legacySettings.contains(key);
-}
-
-QStringList Settings::childGroups() const
-{
- auto l = QSettings::childGroups();
- return !l.isEmpty() ? l : legacySettings.childGroups();
-}
-
-void SettingsGroup::setValue(const QString& key, const QVariant& value)
-{
- Settings::setValue(groupPath + '/' + key, value);
-}
-
-bool SettingsGroup::contains(const QString& key) const
-{
- return Settings::contains(groupPath + '/' + key);
-}
-
-QVariant SettingsGroup::value(const QString& key, const QVariant& defaultValue) const
-{
- return Settings::value(groupPath + '/' + key, defaultValue);
-}
-
-QString SettingsGroup::group() const
-{
- return groupPath;
-}
-
-QStringList SettingsGroup::childGroups() const
-{
- const_cast<SettingsGroup*>(this)->beginGroup(groupPath);
- const_cast<QSettings&>(legacySettings).beginGroup(groupPath);
- QStringList l = Settings::childGroups();
- const_cast<SettingsGroup*>(this)->endGroup();
- const_cast<QSettings&>(legacySettings).endGroup();
- return l;
-}
-
-void SettingsGroup::remove(const QString& key)
-{
- QString fullKey { groupPath };
- if (!key.isEmpty())
- fullKey += "/" + key;
- Settings::remove(fullKey);
-}
-
-QMC_DEFINE_SETTING(AccountSettings, QString, deviceId, "device_id", "", setDeviceId)
-QMC_DEFINE_SETTING(AccountSettings, QString, deviceName, "device_name", "", setDeviceName)
-QMC_DEFINE_SETTING(AccountSettings, bool, keepLoggedIn, "keep_logged_in", false, setKeepLoggedIn)
-
-QUrl AccountSettings::homeserver() const
-{
- return QUrl::fromUserInput(value("homeserver").toString());
-}
-
-void AccountSettings::setHomeserver(const QUrl& url)
-{
- setValue("homeserver", url.toString());
-}
-
-QString AccountSettings::userId() const
-{
- return group().section('/', -1);
-}
-
-QString AccountSettings::accessToken() const
-{
- return value("access_token").toString();
-}
-
-void AccountSettings::setAccessToken(const QString& accessToken)
-{
- qCWarning(MAIN) << "Saving access_token to QSettings is insecure."
- " Developers, please save access_token separately.";
- setValue("access_token", accessToken);
-}
-
-void AccountSettings::clearAccessToken()
-{
- legacySettings.remove("access_token");
- legacySettings.remove("device_id"); // Force the server to re-issue it
- remove("access_token");
-}
+#include "settings.h" + +#include "logging.h" + +#include <QtCore/QUrl> + +using namespace QMatrixClient; + +QString Settings::legacyOrganizationName {}; +QString Settings::legacyApplicationName {}; + +void Settings::setLegacyNames(const QString& organizationName, + const QString& applicationName) +{ + legacyOrganizationName = organizationName; + legacyApplicationName = applicationName; +} + +void Settings::setValue(const QString& key, const QVariant& value) +{ +// qCDebug() << "Setting" << key << "to" << value; + QSettings::setValue(key, value); + if (legacySettings.contains(key)) + legacySettings.remove(key); +} + +QVariant Settings::value(const QString& key, const QVariant& defaultValue) const +{ + auto value = QSettings::value(key, legacySettings.value(key, defaultValue)); + // QML's Qt.labs.Settings stores boolean values as strings, which, if loaded + // through the usual QSettings interface, confuses QML + // (QVariant("false") == true in JavaScript). Since we have a mixed + // environment where both QSettings and Qt.labs.Settings may potentially + // work with same settings, better ensure compatibility. + return value.toString() == QStringLiteral("false") ? QVariant(false) : value; +} + +bool Settings::contains(const QString& key) const +{ + return QSettings::contains(key) || legacySettings.contains(key); +} + +QStringList Settings::childGroups() const +{ + auto l = QSettings::childGroups(); + return !l.isEmpty() ? l : legacySettings.childGroups(); +} + +void SettingsGroup::setValue(const QString& key, const QVariant& value) +{ + Settings::setValue(groupPath + '/' + key, value); +} + +bool SettingsGroup::contains(const QString& key) const +{ + return Settings::contains(groupPath + '/' + key); +} + +QVariant SettingsGroup::value(const QString& key, const QVariant& defaultValue) const +{ + return Settings::value(groupPath + '/' + key, defaultValue); +} + +QString SettingsGroup::group() const +{ + return groupPath; +} + +QStringList SettingsGroup::childGroups() const +{ + const_cast<SettingsGroup*>(this)->beginGroup(groupPath); + const_cast<QSettings&>(legacySettings).beginGroup(groupPath); + QStringList l = Settings::childGroups(); + const_cast<SettingsGroup*>(this)->endGroup(); + const_cast<QSettings&>(legacySettings).endGroup(); + return l; +} + +void SettingsGroup::remove(const QString& key) +{ + QString fullKey { groupPath }; + if (!key.isEmpty()) + fullKey += "/" + key; + Settings::remove(fullKey); +} + +QMC_DEFINE_SETTING(AccountSettings, QString, deviceId, "device_id", "", setDeviceId) +QMC_DEFINE_SETTING(AccountSettings, QString, deviceName, "device_name", "", setDeviceName) +QMC_DEFINE_SETTING(AccountSettings, bool, keepLoggedIn, "keep_logged_in", false, setKeepLoggedIn) + +QUrl AccountSettings::homeserver() const +{ + return QUrl::fromUserInput(value("homeserver").toString()); +} + +void AccountSettings::setHomeserver(const QUrl& url) +{ + setValue("homeserver", url.toString()); +} + +QString AccountSettings::userId() const +{ + return group().section('/', -1); +} + +QString AccountSettings::accessToken() const +{ + return value("access_token").toString(); +} + +void AccountSettings::setAccessToken(const QString& accessToken) +{ + qCWarning(MAIN) << "Saving access_token to QSettings is insecure." + " Developers, please save access_token separately."; + setValue("access_token", accessToken); +} + +void AccountSettings::clearAccessToken() +{ + legacySettings.remove("access_token"); + legacySettings.remove("device_id"); // Force the server to re-issue it + remove("access_token"); +} diff --git a/settings.h b/lib/settings.h index 27ec9ba5..27ec9ba5 100644 --- a/settings.h +++ b/lib/settings.h diff --git a/libqmatrixclient.pri b/libqmatrixclient.pri index 144c9dbc..edba623e 100644 --- a/libqmatrixclient.pri +++ b/libqmatrixclient.pri @@ -1,5 +1,5 @@ QT += network -CONFIG += c++14 warn_on rtti_off +CONFIG += c++14 warn_on rtti_off create_prl win32-msvc* { QMAKE_CXXFLAGS_WARN_ON += -wd4100 @@ -7,72 +7,73 @@ win32-msvc* { QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter } -INCLUDEPATH += $$PWD +SRCPATH = $$PWD/lib +INCLUDEPATH += $$SRCPATH HEADERS += \ - $$PWD/connectiondata.h \ - $$PWD/connection.h \ - $$PWD/room.h \ - $$PWD/user.h \ - $$PWD/avatar.h \ - $$PWD/util.h \ - $$PWD/events/event.h \ - $$PWD/events/eventcontent.h \ - $$PWD/events/roommessageevent.h \ - $$PWD/events/simplestateevents.h \ - $$PWD/events/roommemberevent.h \ - $$PWD/events/roomavatarevent.h \ - $$PWD/events/typingevent.h \ - $$PWD/events/receiptevent.h \ - $$PWD/events/accountdataevents.h \ - $$PWD/events/directchatevent.h \ - $$PWD/events/redactionevent.h \ - $$PWD/jobs/requestdata.h \ - $$PWD/jobs/basejob.h \ - $$PWD/jobs/checkauthmethods.h \ - $$PWD/jobs/passwordlogin.h \ - $$PWD/jobs/sendeventjob.h \ - $$PWD/jobs/postreceiptjob.h \ - $$PWD/jobs/joinroomjob.h \ - $$PWD/jobs/roommessagesjob.h \ - $$PWD/jobs/syncjob.h \ - $$PWD/jobs/mediathumbnailjob.h \ - $$PWD/jobs/setroomstatejob.h \ - $$files($$PWD/jobs/generated/*.h, false) \ - $$PWD/logging.h \ - $$PWD/settings.h \ - $$PWD/networksettings.h \ - $$PWD/networkaccessmanager.h \ - $$PWD/jobs/downloadfilejob.h \ - $$PWD/jobs/postreadmarkersjob.h + $$SRCPATH/connectiondata.h \ + $$SRCPATH/connection.h \ + $$SRCPATH/room.h \ + $$SRCPATH/user.h \ + $$SRCPATH/avatar.h \ + $$SRCPATH/util.h \ + $$SRCPATH/events/event.h \ + $$SRCPATH/events/eventcontent.h \ + $$SRCPATH/events/roommessageevent.h \ + $$SRCPATH/events/simplestateevents.h \ + $$SRCPATH/events/roommemberevent.h \ + $$SRCPATH/events/roomavatarevent.h \ + $$SRCPATH/events/typingevent.h \ + $$SRCPATH/events/receiptevent.h \ + $$SRCPATH/events/accountdataevents.h \ + $$SRCPATH/events/directchatevent.h \ + $$SRCPATH/events/redactionevent.h \ + $$SRCPATH/jobs/requestdata.h \ + $$SRCPATH/jobs/basejob.h \ + $$SRCPATH/jobs/checkauthmethods.h \ + $$SRCPATH/jobs/passwordlogin.h \ + $$SRCPATH/jobs/sendeventjob.h \ + $$SRCPATH/jobs/postreceiptjob.h \ + $$SRCPATH/jobs/joinroomjob.h \ + $$SRCPATH/jobs/roommessagesjob.h \ + $$SRCPATH/jobs/syncjob.h \ + $$SRCPATH/jobs/mediathumbnailjob.h \ + $$SRCPATH/jobs/setroomstatejob.h \ + $$SRCPATH/jobs/downloadfilejob.h \ + $$SRCPATH/jobs/postreadmarkersjob.h \ + $$files($$SRCPATH/jobs/generated/*.h, false) \ + $$SRCPATH/logging.h \ + $$SRCPATH/settings.h \ + $$SRCPATH/networksettings.h \ + $$SRCPATH/networkaccessmanager.h SOURCES += \ - $$PWD/connectiondata.cpp \ - $$PWD/connection.cpp \ - $$PWD/room.cpp \ - $$PWD/user.cpp \ - $$PWD/avatar.cpp \ - $$PWD/events/event.cpp \ - $$PWD/events/eventcontent.cpp \ - $$PWD/events/roommessageevent.cpp \ - $$PWD/events/roommemberevent.cpp \ - $$PWD/events/typingevent.cpp \ - $$PWD/events/receiptevent.cpp \ - $$PWD/events/directchatevent.cpp \ - $$PWD/jobs/requestdata.cpp \ - $$PWD/jobs/basejob.cpp \ - $$PWD/jobs/checkauthmethods.cpp \ - $$PWD/jobs/passwordlogin.cpp \ - $$PWD/jobs/sendeventjob.cpp \ - $$PWD/jobs/postreceiptjob.cpp \ - $$PWD/jobs/joinroomjob.cpp \ - $$PWD/jobs/roommessagesjob.cpp \ - $$PWD/jobs/syncjob.cpp \ - $$PWD/jobs/mediathumbnailjob.cpp \ - $$PWD/jobs/setroomstatejob.cpp \ - $$files($$PWD/jobs/generated/*.cpp, false) \ - $$PWD/logging.cpp \ - $$PWD/settings.cpp \ - $$PWD/networksettings.cpp \ - $$PWD/networkaccessmanager.cpp \ - $$PWD/jobs/downloadfilejob.cpp + $$SRCPATH/connectiondata.cpp \ + $$SRCPATH/connection.cpp \ + $$SRCPATH/room.cpp \ + $$SRCPATH/user.cpp \ + $$SRCPATH/avatar.cpp \ + $$SRCPATH/events/event.cpp \ + $$SRCPATH/events/eventcontent.cpp \ + $$SRCPATH/events/roommessageevent.cpp \ + $$SRCPATH/events/roommemberevent.cpp \ + $$SRCPATH/events/typingevent.cpp \ + $$SRCPATH/events/receiptevent.cpp \ + $$SRCPATH/events/directchatevent.cpp \ + $$SRCPATH/jobs/requestdata.cpp \ + $$SRCPATH/jobs/basejob.cpp \ + $$SRCPATH/jobs/checkauthmethods.cpp \ + $$SRCPATH/jobs/passwordlogin.cpp \ + $$SRCPATH/jobs/sendeventjob.cpp \ + $$SRCPATH/jobs/postreceiptjob.cpp \ + $$SRCPATH/jobs/joinroomjob.cpp \ + $$SRCPATH/jobs/roommessagesjob.cpp \ + $$SRCPATH/jobs/syncjob.cpp \ + $$SRCPATH/jobs/mediathumbnailjob.cpp \ + $$SRCPATH/jobs/setroomstatejob.cpp \ + $$SRCPATH/jobs/downloadfilejob.cpp \ + $$files($$SRCPATH/jobs/generated/*.cpp, false) \ + $$SRCPATH/logging.cpp \ + $$SRCPATH/settings.cpp \ + $$SRCPATH/networksettings.cpp \ + $$SRCPATH/networkaccessmanager.cpp diff --git a/state.cpp b/state.cpp deleted file mode 100644 index 59a3b007..00000000 --- a/state.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "state.h" - -#include "events/event.h" - -using namespace QMatrixClient; - -class State::Private -{ - public: - Event* event; - QString stateKey; - QString replacesState; -}; - - -State::State(Event* event) - : d(new Private) -{ - d->event = event; -} - -State::~State() -{ - delete d; -} - -Event* State::event() const -{ - return d->event; -} - -QString State::stateKey() const -{ - return d->stateKey; -} - -QString State::replacesState() const -{ - return d->replacesState; -} - -State* State::fromJson(const QJsonObject& obj) -{ - Event* event = Event::fromJson(obj); - if( !event ) - return nullptr; - State* state = new State(event); - state->d->stateKey = obj.value("state_key").toString(); - state->d->replacesState = obj.value("replaces_state").toString(); - return state; -} diff --git a/state.h b/state.h deleted file mode 100644 index b059ea92..00000000 --- a/state.h +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include <QtCore/QString> -#include <QtCore/QJsonObject> - -namespace QMatrixClient -{ - class Event; - - /** - * Wraps an event that is a state - */ - class State - { - public: - State(Event* event); - virtual ~State(); - - Event* event() const; - QString stateKey() const; - QString replacesState() const; - - static State* fromJson(const QJsonObject& obj); - - private: - class Private; - Private* d; - }; -} |