diff --git a/CMakeLists.txt b/CMakeLists.txt index 61e2c19..d7f72d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,84 +1,101 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) -if(POLICY CMP0048) # in CMake >= 3.0.0 - cmake_policy(SET CMP0048 OLD) # keep project() from clearing VERSION variables -endif(POLICY CMP0048) - -set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") set(VER_MAJOR "1") set(VER_MINOR "0") -set(VER_PATCH "1") +set(VER_PATCH "2") set(API_VER_PATCH "0") set(CPACK_PACKAGE_VERSION_MAJOR ${VER_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${VER_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${VER_PATCH}) + set(PROJECT_VERSION ${VER_MAJOR}.${VER_MINOR}.${VER_PATCH}) set(API_VERSION ${VER_MAJOR}.${VER_MINOR}.${API_VER_PATCH}) -project(o2) +project(o2 + LANGUAGES CXX + VERSION ${PROJECT_VERSION} +) -option(o2_WITH_QT5 "Use Qt5" ON) +option(BUILD_SHARED_LIBS "Build shared library" OFF) set(o2_LIB_SUFFIX "" CACHE STRING "Suffix for install 'lib' directory, e.g. 64 for lib64") -option(o2_SHOW_TRACE "Show debugging messages" OFF) -if(NOT o2_SHOW_TRACE) - add_definitions(-DQT_NO_DEBUG_OUTPUT=1) +option(o2_BUILD_EXAMPLES "Build examples" OFF) +option(o2_SHOW_TRACE "Show debugging messages" ON) + +option(o2_WITH_DROPBOX "Authenticate with Dropbox" OFF) +option(o2_WITH_FACEBOOK "Authenticate with Facebook" OFF) +option(o2_WITH_FLICKR "Authenticate with Flickr" OFF) +option(o2_WITH_GOOGLE "Authenticate with Google" OFF) +option(o2_WITH_HUBIC "Authenticate with Hubic" OFF) +option(o2_WITH_MSGRAPH "Authenticate with MSGraph" OFF) +option(o2_WITH_SKYDRIVE "Authenticate with SkyDrive" OFF) +option(o2_WITH_SMUGMUG "Authenticate with SmugMug" OFF) +option(o2_WITH_SPOTIFY "Authenticate with Spotify" OFF) +option(o2_WITH_SURVEYMONKEY "Authenticate with SurveyMonkey" OFF) +option(o2_WITH_TWITTER "Authenticate with Twitter" OFF) +option(o2_WITH_UBER "Authenticate with Uber" OFF) +option(o2_WITH_VIMEO "Authenticate with Vimeo" OFF) + +option(o2_WITH_KEYCHAIN "keychain store" OFF) +option(o2_WITH_OAUTH1 "Include OAuth1 authentication" OFF) + +if(o2_WITH_TWITTER OR o2_WITH_DROPBOX OR o2_WITH_FLICKR OR o2_WITH_SMUGMUG) + set(o2_WITH_OAUTH1 ON) endif() -option(o2_WITH_TWITTER "Authenticate with Twitter" OFF) -option(o2_WITH_DROPBOX "Authenticate with Dropbox" OFF) -option(o2_WITH_GOOGLE "Authenticate with Google" OFF) -option(o2_WITH_VIMEO "Authenticate with Vimeo" OFF) -option(o2_WITH_FACEBOOK "Authenticate with Facebook" OFF) -option(o2_WITH_UBER "Authenticate with Uber" OFF) -option(o2_WITH_SKYDRIVE "Authenticate with SkyDrive" OFF) -option(o2_WITH_FLICKR "Authenticate with Flickr" OFF) -option(o2_WITH_HUBIC "Authenticate with Hubic" OFF) -option(o2_WITH_SPOTIFY "Authenticate with Spotify" OFF) -option(o2_WITH_SURVEYMONKEY "Authenticate with SurveyMonkey" OFF) -option(o2_WITH_SMUGMUG "Authenticate with SmugMug" OFF) -option(o2_WITH_MSGRAPH "Authenticate with MSGraph" OFF) -option(o2_WITH_KEYCHAIN "keychain store" ON) +if(NOT o2_SHOW_TRACE) + add_compile_definitions(QT_NO_DEBUG_OUTPUT=1) +endif() -option(o2_WITH_OAUTH1 "Include OAuth1 authentication" OFF) +add_subdirectory(src) -if (o2_WITH_TWITTER) - set(HAVE_TWITTER_SUPPORT 1) +if(o2_BUILD_EXAMPLES) + add_subdirectory(examples) endif() + +# prepare variables for config header + if (o2_WITH_DROPBOX) set(HAVE_DROPBOX_SUPPORT 1) endif() -if (o2_WITH_GOOGLE) - set(HAVE_GOOGLE_SUPPORT 1) -endif() if (o2_WITH_FACEBOOK) set(HAVE_FACEBOOK_SUPPORT 1) endif() -if (o2_WITH_UBER) - set(HAVE_UBER_SUPPORT 1) -endif() -if (o2_WITH_SKYDRIVE) - set(HAVE_SKYDRIVE_SUPPORT 1) -endif() if (o2_WITH_FLICKR) set(HAVE_FLICKR_SUPPORT 1) endif() +if (o2_WITH_GOOGLE) + set(HAVE_GOOGLE_SUPPORT 1) +endif() if (o2_WITH_HUBIC) set(HAVE_HUBIC_SUPPORT 1) endif() +if (o2_WITH_MSGRAPH) + set(HAVE_MSGRAPH_SUPPORT 1) +endif() +if (o2_WITH_SKYDRIVE) + set(HAVE_SKYDRIVE_SUPPORT 1) +endif() +if (o2_WITH_SMUGMUG) + set(HAVE_SMUGMUG_SUPPORT 1) +endif() if (o2_WITH_SPOTIFY) set(HAVE_SPOTIFY_SUPPORT 1) endif() if (o2_WITH_SURVEYMONKEY) set(HAVE_SURVEYMONKEY_SUPPORT 1) endif() -if (o2_WITH_SMUGMUG) - set(HAVE_SMUGMUG_SUPPORT 1) +if (o2_WITH_TWITTER) + set(HAVE_TWITTER_SUPPORT 1) endif() -if (o2_WITH_MSGRAPH) - set(HAVE_MSGRAPH_SUPPORT 1) +if (o2_WITH_UBER) + set(HAVE_UBER_SUPPORT 1) +endif() +if (o2_WITH_VIMEO) + set(HAVE_VIMEO_SUPPORT 1) endif() if (o2_WITH_KEYCHAIN) set(HAVE_KEYCHAIN_SUPPORT 1) @@ -86,21 +103,3 @@ endif() if (o2_WITH_OAUTH1) set(HAVE_OAUTH1_SUPPORT 1) endif() - - - -if(o2_WITH_TWITTER OR o2_WITH_DROPBOX OR o2_WITH_FLICKR OR o2_WITH_SMUGMUG) - set(o2_WITH_OAUTH1 ON) -endif() - -option(o2_BUILD_EXAMPLES "Build examples" OFF) - -if(WIN32) - add_definitions(-DO2_DLL_EXPORT) -endif() - -add_subdirectory(src) - -if(o2_BUILD_EXAMPLES) - add_subdirectory(examples) -endif(o2_BUILD_EXAMPLES) diff --git a/cmake/modules/FindQt5Keychain.cmake b/cmake/modules/FindQt5Keychain.cmake deleted file mode 100644 index e28ac56..0000000 --- a/cmake/modules/FindQt5Keychain.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# (c) 2014 Copyright ownCloud GmbH -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING* file. - -# - Try to find QtKeychain -# Once done this will define -# QTKEYCHAIN_FOUND - System has QtKeychain -# QTKEYCHAIN_INCLUDE_DIRS - The QtKeychain include directories -# QTKEYCHAIN_LIBRARIES - The libraries needed to use QtKeychain -# QTKEYCHAIN_DEFINITIONS - Compiler switches required for using LibXml2 - -find_path(QTKEYCHAIN_INCLUDE_DIR - NAMES - keychain.h - PATH_SUFFIXES - qt5keychain - ) - -find_library(QTKEYCHAIN_LIBRARY - NAMES - qt5keychain - lib5qtkeychain - PATHS - /usr/lib - /usr/lib/${CMAKE_ARCH_TRIPLET} - /usr/local/lib - /opt/local/lib - ${CMAKE_LIBRARY_PATH} - ${CMAKE_INSTALL_PREFIX}/lib - ) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set QTKEYCHAIN_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(Qt5Keychain DEFAULT_MSG - QTKEYCHAIN_LIBRARY QTKEYCHAIN_INCLUDE_DIR) - -mark_as_advanced(QTKEYCHAIN_INCLUDE_DIR QTKEYCHAIN_LIBRARY) diff --git a/cmake/modules/FindQtKeychain.cmake b/cmake/modules/FindQtKeychain.cmake deleted file mode 100644 index 30d615d..0000000 --- a/cmake/modules/FindQtKeychain.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# (c) 2014 Copyright ownCloud GmbH -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING* file. - -# - Try to find QtKeychain -# Once done this will define -# QTKEYCHAIN_FOUND - System has QtKeychain -# QTKEYCHAIN_INCLUDE_DIRS - The QtKeychain include directories -# QTKEYCHAIN_LIBRARIES - The libraries needed to use QtKeychain -# QTKEYCHAIN_DEFINITIONS - Compiler switches required for using LibXml2 - -find_path(QTKEYCHAIN_INCLUDE_DIR - NAMES - keychain.h - PATH_SUFFIXES - qtkeychain - ) - - -find_library(QTKEYCHAIN_LIBRARY - NAMES - qtkeychain - libqtkeychain - PATHS - /usr/lib - /usr/lib/${CMAKE_ARCH_TRIPLET} - /usr/local/lib - /opt/local/lib - ${CMAKE_LIBRARY_PATH} - ${CMAKE_INSTALL_PREFIX}/lib - ) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set QTKEYCHAIN_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(QtKeychain DEFAULT_MSG - QTKEYCHAIN_LIBRARY QTKEYCHAIN_INCLUDE_DIR) - -mark_as_advanced(QTKEYCHAIN_INCLUDE_DIR QTKEYCHAIN_LIBRARY) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8582ef8..0c939e0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,8 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) if(o2_WITH_FACEBOOK) add_subdirectory(facebookdemo) + add_subdirectory(facebookexternalinterceptordemo) endif(o2_WITH_FACEBOOK) if(o2_WITH_GOOGLE) @@ -12,14 +13,14 @@ if(o2_WITH_TWITTER) add_subdirectory(twitterdemo) endif(o2_WITH_TWITTER) -#if(o2_WITH_SPOTIFY) -# add_subdirectory(spotifydemo) -#endif(o2_WITH_SPOTIFY) - if (o2_WITH_VIMEO) add_subdirectory(vimeodemo) endif(o2_WITH_VIMEO) +if (o2_WITH_YOUTUBE) + add_subdirectory(youtubedemo) +endif(o2_WITH_YOUTUBE) + if (o2_WITH_MSGRAPH) add_subdirectory(msgraphdemo) add_subdirectory(msgraphexternalinterceptordemo) diff --git a/examples/facebookdemo/CMakeLists.txt b/examples/facebookdemo/CMakeLists.txt index 3326740..895f4ea 100644 --- a/examples/facebookdemo/CMakeLists.txt +++ b/examples/facebookdemo/CMakeLists.txt @@ -1,44 +1,30 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) -project( fbexample ) +project(facebookexample) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) - # Qt5 packages find their own dependencies. - find_package(Qt5Core REQUIRED) - find_package(Qt5Widgets REQUIRED) - find_package(Qt5Script REQUIRED) - find_package(Qt5Network REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Widgets) -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) - -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "../../src" ) - -set(fb_SRCS +add_executable(${PROJECT_NAME} WIN32 main.cpp fbdemo.cpp fbdemo.h ) -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) +target_link_libraries(${PROJECT_NAME} + PRIVATE + o2 -add_executable( fbexample ${fb_SRCS} ) + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Network + Qt${QT_MAJOR_VERSION}::Widgets +) -if(o2_WITH_QT5) - qt5_use_modules( fbexample Core Widgets Network ) - target_link_libraries( fbexample o2 ) -else(o2_WITH_QT5) - target_link_libraries( fbexample ${QT_LIBRARIES} o2 ) -endif(o2_WITH_QT5) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W3) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +endif() diff --git a/examples/facebookdemo/main.cpp b/examples/facebookdemo/main.cpp index ca83551..2cc9f98 100644 --- a/examples/facebookdemo/main.cpp +++ b/examples/facebookdemo/main.cpp @@ -25,9 +25,6 @@ class Helper : public QObject { public slots: void processArgs() { QStringList argList = qApp->arguments(); - QByteArray help = QString(USAGE).arg(OPT_OAUTH_CODE, - OPT_VALIDATE_TOKEN).toLatin1(); - const char* helpText = help.constData(); connect(&fbdemo_, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed())); connect(&fbdemo_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded())); if (argList.contains(OPT_OAUTH_CODE)) { @@ -36,7 +33,7 @@ public slots: } else if (argList.contains(OPT_VALIDATE_TOKEN)) { fbdemo_.validateToken(); } else { - qDebug() << helpText; + qDebug() << QString(USAGE).arg(OPT_OAUTH_CODE, OPT_VALIDATE_TOKEN); qApp->exit(1); } } diff --git a/examples/facebookexternalinterceptordemo/CMakeLists.txt b/examples/facebookexternalinterceptordemo/CMakeLists.txt index afc3d27..a2eff9c 100644 --- a/examples/facebookexternalinterceptordemo/CMakeLists.txt +++ b/examples/facebookexternalinterceptordemo/CMakeLists.txt @@ -1,43 +1,38 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) -project( fbexample ) +project(facebookexampleexternalinterceptorexample) set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) - # Qt5 packages find their own dependencies. - find_package(Qt5Core REQUIRED) - find_package(Qt5Widgets REQUIRED) - find_package(Qt5Script REQUIRED) - find_package(Qt5Network REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Widgets WebEngineCore WebEngineWidgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network WebEngineCore WebEngineWidgets) -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) - -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "../../src" ) - -set(fb_SRCS +add_executable(${PROJECT_NAME} WIN32 main.cpp fbdemo.cpp + fbdemo.h + webenginepage.cpp + webenginepage.h + webwindow.cpp + webwindow.h + webwindow.ui ) -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) +target_link_libraries(${PROJECT_NAME} + PRIVATE + o2 -add_executable( fbexample ${fb_SRCS} ) + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Network + Qt${QT_MAJOR_VERSION}::Widgets + Qt${QT_MAJOR_VERSION}::WebEngineCore + Qt${QT_MAJOR_VERSION}::WebEngineWidgets +) -if(o2_WITH_QT5) - qt5_use_modules( fbexample Core Widgets Network ) - target_link_libraries( fbexample o2 ) -else(o2_WITH_QT5) - target_link_libraries( fbexample ${QT_LIBRARIES} o2 ) -endif(o2_WITH_QT5) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W3) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +endif() diff --git a/examples/facebookexternalinterceptordemo/fbdemo.cpp b/examples/facebookexternalinterceptordemo/fbdemo.cpp index 172f2b3..78c60f1 100644 --- a/examples/facebookexternalinterceptordemo/fbdemo.cpp +++ b/examples/facebookexternalinterceptordemo/fbdemo.cpp @@ -66,7 +66,7 @@ void FBDemo::onAuthWindowCallbackCalled(const QString &inURLString) QUrlQuery query(getTokenUrl); QList< QPair > tokens = query.queryItems(); - QMultiMap queryParams; + QMap queryParams; QPair tokenPair; foreach (tokenPair, tokens) { // FIXME: We are decoding key and value again. This helps with Google OAuth, but is it mandated by the standard? diff --git a/examples/msgraphdemo/CMakeLists.txt b/examples/msgraphdemo/CMakeLists.txt index 449a136..8b1e848 100644 --- a/examples/msgraphdemo/CMakeLists.txt +++ b/examples/msgraphdemo/CMakeLists.txt @@ -1,44 +1,30 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) -project( msgraphexample ) +project(msgraphexample) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) - # Qt5 packages find their own dependencies. - find_package(Qt5Core REQUIRED) - find_package(Qt5Gui REQUIRED) - find_package(Qt5Network REQUIRED) - find_package(Qt5Widgets REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Widgets) -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) - -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "../../src" ) - -set(msgraph_SRCS +add_executable(${PROJECT_NAME} WIN32 main.cpp msgraphdemo.cpp msgraphdemo.h ) -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) +target_link_libraries(${PROJECT_NAME} + PRIVATE + o2 -add_executable( msgraphexample ${msgraph_SRCS} ) + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Network + Qt${QT_MAJOR_VERSION}::Widgets +) -if(o2_WITH_QT5) - qt5_use_modules( msgraphexample Core Gui Network Widgets ) - target_link_libraries( msgraphexample o2 ) -else(o2_WITH_QT5) - target_link_libraries( msgraphexample ${QT_LIBRARIES} o2 ) -endif(o2_WITH_QT5) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W3) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +endif() diff --git a/examples/msgraphdemo/msgraphdemo.cpp b/examples/msgraphdemo/msgraphdemo.cpp index 907f394..8a2c37e 100644 --- a/examples/msgraphdemo/msgraphdemo.cpp +++ b/examples/msgraphdemo/msgraphdemo.cpp @@ -4,7 +4,11 @@ #include #include #include +#if QT_VERSION >= 0x060000 +#include +#else #include +#endif #include "msgraphdemo.h" #include "o0globals.h" @@ -114,13 +118,25 @@ void MsgraphDemo::onFinished(int requestId, QNetworkReply::NetworkError error, Q return; } - QRegExp userPrincipalNameRE("\"userPrincipalName\":\"([^\"]+)\""); - if (userPrincipalNameRE.indexIn(reply) == -1) { +#if QT_VERSION >= 0x060000 + QRegularExpression nameRE("\"userPrincipalName\":\"([^\"]+)\""); + QRegularExpressionMatch match = nameRE.match(reply); + + bool hasMatch = match.hasMatch(); + QString name = match.captured(); +#else + QRegExp nameRE("\"userPrincipalName\":\"([^\"]+)\""); + + bool hasMatch = (nameRE.indexIn(reply) != -1); + QString name = nameRE.cap(1); +#endif + + if (!hasMatch) { qDebug() << "Can not parse reply:" << reply; emit userPrincipalNameFailed(); return; } - qInfo() << "userPrincipalName: " << userPrincipalNameRE.cap(1); + qInfo() << "userPrincipalName: " << name; emit userPrincipalNameReceived(); } diff --git a/examples/msgraphexternalinterceptordemo/CMakeLists.txt b/examples/msgraphexternalinterceptordemo/CMakeLists.txt index b2944ef..0b33699 100644 --- a/examples/msgraphexternalinterceptordemo/CMakeLists.txt +++ b/examples/msgraphexternalinterceptordemo/CMakeLists.txt @@ -1,47 +1,38 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) -project( msgraphexternalinterceptorexample ) +project(msgraphexternalinterceptorexample) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) - # Qt5 packages find their own dependencies. - find_package(Qt5Core REQUIRED) - find_package(Qt5Widgets REQUIRED) - find_package(Qt5Script REQUIRED) - find_package(Qt5Network REQUIRED) - find_package(Qt5WebEngine REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Widgets WebEngineCore WebEngineWidgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Widgets WebEngineCore WebEngineWidgets) -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) - -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "../../src" ) - -set(msgraph_SRCS +add_executable(${PROJECT_NAME} WIN32 main.cpp msgraphdemo.cpp - webwindow.cpp + msgraphdemo.h webenginepage.cpp + webenginepage.h + webwindow.cpp + webwindow.h + webwindow.ui ) -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) +target_link_libraries(${PROJECT_NAME} + PRIVATE + o2 -add_executable( msgraphexternalinterceptorexample ${msgraph_SRCS} ) + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Network + Qt${QT_MAJOR_VERSION}::Widgets + Qt${QT_MAJOR_VERSION}::WebEngineCore + Qt${QT_MAJOR_VERSION}::WebEngineWidgets +) -if(o2_WITH_QT5) - qt5_use_modules( msgraphexternalinterceptorexample Core Widgets Network WebEngineWidgets ) - target_link_libraries( msgraphexternalinterceptorexample o2 ) -else(o2_WITH_QT5) - target_link_libraries( msgraphexternalinterceptorexample ${QT_LIBRARIES} o2 ) -endif(o2_WITH_QT5) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W3) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +endif() diff --git a/examples/msgraphexternalinterceptordemo/msgraphdemo.cpp b/examples/msgraphexternalinterceptordemo/msgraphdemo.cpp index 04017f9..16d00ce 100644 --- a/examples/msgraphexternalinterceptordemo/msgraphdemo.cpp +++ b/examples/msgraphexternalinterceptordemo/msgraphdemo.cpp @@ -5,6 +5,12 @@ #include #include #include +#if QT_VERSION >= 0x060000 +#include +#else +#include +#endif + #include "msgraphdemo.h" #include "o0globals.h" @@ -85,7 +91,7 @@ void MsgraphDemo::onAuthWindowCallbackCalled(const QString &inURLString) QUrlQuery query(getTokenUrl); QList< QPair > tokens = query.queryItems(); - QMultiMap queryParams; + QMap queryParams; QPair tokenPair; foreach (tokenPair, tokens) { // FIXME: We are decoding key and value again. This helps with Google OAuth, but is it mandated by the standard? @@ -148,13 +154,25 @@ void MsgraphDemo::onFinished(int requestId, QNetworkReply::NetworkError error, Q return; } - QRegExp userPrincipalNameRE("\"userPrincipalName\":\"([^\"]+)\""); - if (userPrincipalNameRE.indexIn(reply) == -1) { +#if QT_VERSION >= 0x060000 + QRegularExpression nameRE("\"userPrincipalName\":\"([^\"]+)\""); + QRegularExpressionMatch match = nameRE.match(reply); + + bool hasMatch = match.hasMatch(); + QString name = match.captured(); +#else + QRegExp nameRE("\"userPrincipalName\":\"([^\"]+)\""); + + bool hasMatch = (nameRE.indexIn(reply) != -1); + QString name = nameRE.cap(1); +#endif + + if (!hasMatch) { qDebug() << "Can not parse reply:" << reply; emit userPrincipalNameFailed(); return; } - qInfo() << "userPrincipalName: " << userPrincipalNameRE.cap(1); + qInfo() << "userPrincipalName: " << name; emit userPrincipalNameReceived(); } diff --git a/examples/twitterdemo/CMakeLists.txt b/examples/twitterdemo/CMakeLists.txt index 245026e..d7c071e 100644 --- a/examples/twitterdemo/CMakeLists.txt +++ b/examples/twitterdemo/CMakeLists.txt @@ -1,43 +1,30 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) -project( twitterexample ) +project(twitterexample) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) - # Qt5 packages find their own dependencies. - find_package(Qt5Core REQUIRED) - find_package(Qt5Widgets REQUIRED) - find_package(Qt5Script REQUIRED) - find_package(Qt5Network REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Widgets) -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) - -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "../../src" ) - -set(fb_SRCS +add_executable(${PROJECT_NAME} WIN32 main.cpp tweeter.cpp + tweeter.h ) -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) +target_link_libraries(${PROJECT_NAME} + PRIVATE + o2 -add_executable( twitterexample ${fb_SRCS} ) + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Network + Qt${QT_MAJOR_VERSION}::Widgets +) -if(o2_WITH_QT5) - qt5_use_modules( twitterexample Core Widgets Network ) - target_link_libraries( twitterexample o2 ) -else(o2_WITH_QT5) - target_link_libraries( twitterexample ${QT_LIBRARIES} o2 ) -endif(o2_WITH_QT5) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W3) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +endif() diff --git a/examples/vimeodemo/CMakeLists.txt b/examples/vimeodemo/CMakeLists.txt index e319fec..46db78d 100644 --- a/examples/vimeodemo/CMakeLists.txt +++ b/examples/vimeodemo/CMakeLists.txt @@ -1,44 +1,30 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) -project( vimeoexample ) +project(vimeoexample) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) - # Qt5 packages find their own dependencies. - find_package(Qt5Core REQUIRED) - find_package(Qt5Gui REQUIRED) - find_package(Qt5Network REQUIRED) - find_package(Qt5Widgets REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Widgets) -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) - -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "../../src" ) - -set(vimeo_SRCS +add_executable(${PROJECT_NAME} WIN32 main.cpp vimeodemo.cpp vimeodemo.h ) -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) +target_link_libraries(${PROJECT_NAME} + PRIVATE + o2 -add_executable( vimeoexample ${vimeo_SRCS} ) + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Network + Qt${QT_MAJOR_VERSION}::Widgets +) -if(o2_WITH_QT5) - qt5_use_modules( vimeoexample Core Gui Network Widgets ) - target_link_libraries( vimeoexample o2 ) -else(o2_WITH_QT5) - target_link_libraries( vimeoexample ${QT_LIBRARIES} o2 ) -endif(o2_WITH_QT5) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W3) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +endif() diff --git a/examples/vimeodemo/vimeodemo.cpp b/examples/vimeodemo/vimeodemo.cpp index adfb373..ba4545e 100644 --- a/examples/vimeodemo/vimeodemo.cpp +++ b/examples/vimeodemo/vimeodemo.cpp @@ -4,8 +4,11 @@ #include #include #include +#if QT_VERSION >= 0x060000 +#include +#else #include - +#endif #include "vimeodemo.h" #include "o0globals.h" #include "o0settingsstore.h" @@ -111,13 +114,25 @@ void VimeoDemo::onFinished(int requestId, QNetworkReply::NetworkError error, QBy return; } +#if QT_VERSION >= 0x060000 + QRegularExpression nameRE("\"name\":\"([^\"]+)\""); + QRegularExpressionMatch match = nameRE.match(reply); + + bool hasMatch = match.hasMatch(); + QString name = match.captured(); +#else QRegExp nameRE("\"name\":\"([^\"]+)\""); - if (nameRE.indexIn(reply) == -1) { + + bool hasMatch = (nameRE.indexIn(reply) != -1); + QString name = nameRE.cap(1); +#endif + + if (!hasMatch){ qDebug() << "Can not parse reply:" << reply; emit userNameFailed(); return; } - qInfo() << "User name: " << nameRE.cap(1); + qInfo() << "User name: " << name; emit userNameReceived(); } diff --git a/examples/youtubedemo/CMakeLists.txt b/examples/youtubedemo/CMakeLists.txt index 974aa9c..ed623ad 100644 --- a/examples/youtubedemo/CMakeLists.txt +++ b/examples/youtubedemo/CMakeLists.txt @@ -1,44 +1,30 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) -project( ytexample ) +project(youtubetexample) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) - # Qt5 packages find their own dependencies. - find_package(Qt5Core REQUIRED) - find_package(Qt5Gui REQUIRED) - find_package(Qt5Network REQUIRED) - find_package(Qt5Widgets REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Widgets) -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) - -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} "../../src" ) - -set(yt_SRCS +add_executable(${PROJECT_NAME} WIN32 main.cpp ytdemo.cpp ytdemo.h ) -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) +target_link_libraries(${PROJECT_NAME} + PRIVATE + o2 -add_executable( ytexample ${yt_SRCS} ) + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Network + Qt${QT_MAJOR_VERSION}::Widgets +) -if(o2_WITH_QT5) - qt5_use_modules( ytexample Core Gui Network Widgets ) - target_link_libraries( ytexample o2 ) -else(o2_WITH_QT5) - target_link_libraries( ytexample ${QT_LIBRARIES} o2 ) -endif(o2_WITH_QT5) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W3) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +endif() diff --git a/examples/youtubedemo/main.cpp b/examples/youtubedemo/main.cpp index 5c91f8e..319e656 100644 --- a/examples/youtubedemo/main.cpp +++ b/examples/youtubedemo/main.cpp @@ -5,8 +5,6 @@ #include "ytdemo.h" -const char OPT_OAUTH_CODE[] = "-o"; - class Helper : public QObject { Q_OBJECT diff --git a/o2-config.h.cmake b/o2-config.h.cmake index d073348..2ad9b5a 100644 --- a/o2-config.h.cmake +++ b/o2-config.h.cmake @@ -1,17 +1,19 @@ #ifndef O2_CONFIG_SUPPORT_FEATURE_H #define O2_CONFIG_SUPPORT_FEATURE_H - -#cmakedefine01 HAVE_TWITTER_SUPPORT #cmakedefine01 HAVE_DROPBOX_SUPPORT +#cmakedefine01 HAVE_FACEBOOK_SUPPORT +#cmakedefine01 HAVE_FLICKR_SUPPORT #cmakedefine01 HAVE_GOOGLE_SUPPORT -#cmakedefine01 HAVE_UBER_SUPPORT -#cmakedefine01 HAVE_SKYDRIVE_SUPPORT #cmakedefine01 HAVE_HUBIC_SUPPORT +#cmakedefine01 HAVE_MSGRAPH_SUPPORT +#cmakedefine01 HAVE_SKYDRIVE_SUPPORT +#cmakedefine01 HAVE_SMUGMUG_SUPPORT #cmakedefine01 HAVE_SPOTIFY_SUPPORT #cmakedefine01 HAVE_SURVEYMONKEY_SUPPORT -#cmakedefine01 HAVE_SMUGMUG_SUPPORT -#cmakedefine01 HAVE_MSGRAPH_SUPPORT +#cmakedefine01 HAVE_TWITTER_SUPPORT +#cmakedefine01 HAVE_UBER_SUPPORT +#cmakedefine01 HAVE_VIMEO_SUPPORT #cmakedefine01 HAVE_KEYCHAIN_SUPPORT #cmakedefine01 HAVE_0AUTH1_SUPPORT diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 39536cb..d086880 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,22 +1,12 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -if(o2_WITH_QT5) - find_package(Qt5 COMPONENTS Core Network REQUIRED) -else(o2_WITH_QT5) - set(QT_USE_QTNETWORK true) - set(QT_USE_QTSCRIPT true) - find_package(Qt4 REQUIRED) -endif(o2_WITH_QT5) -#find_package(QJson REQUIRED) - -if (NOT o2_WITH_QT5) - include( ${QT_USE_FILE} ) -endif(NOT o2_WITH_QT5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network) +# collect all sources set( o2_SRCS o2.cpp @@ -192,69 +182,82 @@ if(o2_WITH_MSGRAPH) endif(o2_WITH_MSGRAPH) if(o2_WITH_KEYCHAIN) - if (Qt5Core_DIR) - find_package(Qt5Keychain REQUIRED) - else() - find_package(QtKeychain REQUIRED) - endif() - if(QTKEYCHAIN_FOUND OR QT5KEYCHAIN_FOUND) - MESSAGE("Found QTKeychain") - list(APPEND LINK_TARGETS ${QTKEYCHAIN_LIBRARY}) - include_directories(${QTKEYCHAIN_INCLUDE_DIR}) - set( o2_SRCS - ${o2_SRCS} - o0keychainstore.cpp - ) - set( o2_HDRS - ${o2_HDRS} - o0keychainstore.h - ) - else() - MESSAGE("Qt5Keychain or QtKeychain is required") + + include(FetchContent) + FetchContent_Declare( + QtKeychain + GIT_REPOSITORY https://github.com/frankosterfeld/qtkeychain.git + GIT_TAG 841f31c7ca177e45647fd705200d7fcbeee056e5 # master Jan 30, 2023 (Qt 6.4 compatible) + ) + + if (Qt6Core_FOUND) + set(BUILD_WITH_QT6 ON) endif() + FetchContent_MakeAvailable(QtKeychain) -endif(o2_WITH_KEYCHAIN) + # patch include path to find QtKeychain headers without installing it + include_directories(${qtkeychain_SOURCE_DIR}) + list(APPEND LINK_TARGETS qt${Qt_MAJOR_VERSION}keychain) + set( o2_SRCS + ${o2_SRCS} + o0keychainstore.cpp + ) + set( o2_HDRS + ${o2_HDRS} + o0keychainstore.h + ) +endif(o2_WITH_KEYCHAIN) +# compose the library -if(NOT o2_WITH_QT5) - add_definitions(${QT4_DEFINITIONS}) -endif(NOT o2_WITH_QT5) +add_library(o2 ${o2_SRCS} ${o2_HDRS}) -if(BUILD_SHARED_LIBS AND APPLE AND POLICY CMP0042) # in CMake >= 2.8.12 - cmake_policy(SET CMP0042 OLD) - set(CMAKE_MACOSX_RPATH OFF) # don't embed @rpath in install name -endif(BUILD_SHARED_LIBS AND APPLE AND POLICY CMP0042) +target_include_directories(o2 PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) -add_library( o2 ${o2_SRCS} ${o2_HDRS} ) +target_link_libraries(o2 + PUBLIC + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Network -if(BUILD_SHARED_LIBS) - add_definitions( -DO2_SHARED_LIB ) -endif(BUILD_SHARED_LIBS) + PRIVATE + ${LINK_TARGETS} +) -if(o2_WITH_QT5) - target_link_libraries( o2 Qt5::Core Qt5::Network ${LINK_TARGETS}) -else(o2_WITH_QT5) - target_link_libraries( o2 ${QT_LIBRARIES} ${LINK_TARGETS}) -endif(o2_WITH_QT5) +if (MSVC) + target_compile_options(o2 PRIVATE /W3) +else() + target_compile_options(o2 PRIVATE -Wall) +endif() if(BUILD_SHARED_LIBS) if(APPLE) - set_target_properties(o2 - PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib - ) - endif(APPLE) + set_target_properties(o2 PROPERTIES + BUILD_WITH_INSTALL_NAME_DIR ON + INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib + ) + elseif(WIN32) + target_compile_definitions(o2 + PRIVATE O2_DLL_EXPORT + PUBLIC O2_SHARED_LIB + ) + endif() + set_target_properties(o2 PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${API_VERSION} ) -else(BUILD_SHARED_LIBS) +else() # needed for statically linked o2 in shared libs on x86_64 set_target_properties(o2 PROPERTIES POSITION_INDEPENDENT_CODE TRUE ) -endif(BUILD_SHARED_LIBS) +endif() + +# install target install(TARGETS o2 RUNTIME DESTINATION bin @@ -272,4 +275,3 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/o2.pc DESTINATION "${CMAKE_INSTALL_PRE configure_file(${CMAKE_CURRENT_LIST_DIR}/../o2-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/o2-config.h @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/o2-config.h DESTINATION "${CMAKE_INSTALL_PREFIX}/include/o2") -