diff --git a/3rdparty/vreen/CMakeLists.txt b/3rdparty/vreen/CMakeLists.txt deleted file mode 100644 index cb5efef8e..000000000 --- a/3rdparty/vreen/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -set(QT_USE_QTNETWORK true) - -option(USE_SYSTEM_VREEN "Force use system vreen instead build-in copy" OFF) - -if(USE_SYSTEM_VREEN) - find_package(PkgConfig) - if(PKG_CONFIG_FOUND) - pkg_check_modules(VREEN REQUIRED vreen) - #another spike. In pkgconfig LIBRARIES macro list only lib names - set(VREEN_LIBRARIES ${VREEN_LDFLAGS}) - endif() -endif() -if(NOT VREEN_FOUND) - if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr") - set(VREEN_IMPORTS_DIR bin) - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++0x") - set(VREEN_WITH_QMLAPI OFF CACHE INTERNAL "") - set(VREEN_WITH_OAUTH ON CACHE INTERNAL "") - set(VREEN_INSTALL_HEADERS OFF CACHE INTERNAL "") - set(VREEN_DEVELOPER_BUILD OFF CACHE INTERNAL "") - set(VREEN_WITH_EXAMPLES OFF CACHE INTERNAL "") - set(VREEN_WITH_TESTS OFF CACHE INTERNAL "") - add_subdirectory(vreen) - message(STATUS "Using internal copy of vreen") - set(VREEN_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/vreen/include CACHE INTERNAL "") - set(VREEN_LIBRARIES vreen CACHE INTERNAL "") -endif() diff --git a/3rdparty/vreen/vreen/CMakeLists.txt b/3rdparty/vreen/vreen/CMakeLists.txt deleted file mode 100644 index 80ddde319..000000000 --- a/3rdparty/vreen/vreen/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -project(vreen) -cmake_minimum_required(VERSION 2.8 FATAL_ERROR) - -if(COMMAND cmake_policy) - cmake_policy (SET CMP0003 NEW) -endif(COMMAND cmake_policy) - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") - -include(CommonUtils) - -option(VREEN_WITH_OAUTH "Enable webkit based oauth authorization" ON) -option(VREEN_WITH_DIRECTAUTH "Enable direct authorization" OFF) -option(VREEN_WITH_QMLAPI "Enable QtQuick bindings for vreen" ON) -option(VREEN_WITH_EXAMPLES "Enable vreen tests" ON) -option(VREEN_WITH_TESTS "Enable vreen examples" ON) -option(VREEN_INSTALL_HEADERS "Install devel headers for vreen" ON) -option(VREEN_DEVELOPER_BUILD "Install devel headers for vreen" OFF) -option(USE_QT5 "Build with Qt 5" OFF) - -#TODO check if vars is defined -set(RLIBDIR bin) -set(LIBDIR lib${LIB_SUFFIX}) -set(LIB_DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIBDIR}) -if(APPLE) - set(CMAKE_INSTALL_NAME_DIR "${LIB_DESTINATION}") #hack for mac -endif() - -set(CMAKE_VREEN_VERSION_MAJOR 0 CACHE INT "Major vk version number" FORCE) -set(CMAKE_VREEN_VERSION_MINOR 9 CACHE INT "Minor vk version number" FORCE) -set(CMAKE_VREEN_VERSION_PATCH 5 CACHE INT "Release vk version number" FORCE) -set(CMAKE_VREEN_VERSION_STRING "${CMAKE_VREEN_VERSION_MAJOR}.${CMAKE_VREEN_VERSION_MINOR}.${CMAKE_VREEN_VERSION_PATCH}" CACHE STRING "vreen version string" FORCE) - -set(VREEN_INCLUDE_DIR ${PROJECT_BINARY_DIR}/include) -set(VREEN_PRIVATE_INCLUDE_DIR ${VREEN_INCLUDE_DIR}/vreen/${CMAKE_VREEN_VERSION_STRING}) - -add_subdirectory(src) -if(VREEN_WITH_EXAMPLES) - add_subdirectory(examples) -endif() -if(VREEN_WITH_TESTS) - enable_testing() - add_subdirectory(tests) -endif() diff --git a/3rdparty/vreen/vreen/cmake/CommonUtils.cmake b/3rdparty/vreen/vreen/cmake/CommonUtils.cmake deleted file mode 100644 index 81c809131..000000000 --- a/3rdparty/vreen/vreen/cmake/CommonUtils.cmake +++ /dev/null @@ -1,630 +0,0 @@ -include(CompilerUtils) -include(QtBundleUtils) -include(MocUtils) - -set(CMAKE_AUTOMOC true) - -macro(LIST_CONTAINS var value) -set(${var}) -foreach(value2 ${ARGN}) - if(${value} STREQUAL ${value2}) - set(${var} TRUE) - endif(${value} STREQUAL ${value2}) -endforeach(value2) -endmacro(LIST_CONTAINS) - -macro(LIST_FILTER list regex output) - unset(${output}) - foreach(item ${list}) - string(REGEX MATCH ${regex} item2 ${item}) - if(item MATCHES ${regex}) - list(APPEND ${output} ${item}) - endif() - endforeach() -endmacro() - -macro(PARSE_ARGUMENTS prefix arg_names option_names) - set(DEFAULT_ARGS) - foreach(arg_name ${arg_names}) - set(${prefix}_${arg_name}) - endforeach(arg_name) - foreach(option ${option_names}) - set(${prefix}_${option} FALSE) - endforeach(option) - - set(current_arg_name DEFAULT_ARGS) - set(current_arg_list) - foreach(arg ${ARGN}) - list_contains(is_arg_name ${arg} ${arg_names}) - if(is_arg_name) - set(${prefix}_${current_arg_name} ${current_arg_list}) - set(current_arg_name ${arg}) - set(current_arg_list) - else(is_arg_name) - list_contains(is_option ${arg} ${option_names}) - if(is_option) - set(${prefix}_${arg} TRUE) - else(is_option) - set(current_arg_list ${current_arg_list} ${arg}) - endif(is_option) - endif(is_arg_name) - endforeach(arg) - SET(${prefix}_${current_arg_name} ${current_arg_list}) -endmacro(PARSE_ARGUMENTS) - -macro(qt_use_modules target) - if(USE_QT5) - find_package(Qt5Core QUIET) - endif() - if(Qt5Core_DIR) - add_definitions("-DQT_DISABLE_DEPRECATED_BEFORE=0") - qt5_use_modules(${target} ${ARGN}) - else() - foreach(_module ${ARGN}) - list(APPEND _modules Qt${_module}) - endforeach() - find_package(Qt4 COMPONENTS ${_modules} QUIET) - include(UseQt4) - target_link_libraries(${target} ${QT_LIBRARIES}) - set(${target}_libraries ${QT_LIBRARIES}) - endif() -endmacro() - -macro(UPDATE_COMPILER_FLAGS target) - parse_arguments(FLAGS - "" - "DEVELOPER;CXX11" - ${ARGN} - ) - - if(FLAGS_DEVELOPER) - if(MSVC) - update_cxx_compiler_flag(${target} "/W3" W3) - update_cxx_compiler_flag(${target} "/WX" WX) - else() - update_cxx_compiler_flag(${target} "-Wall" WALL) - update_cxx_compiler_flag(${target} "-Wextra" WEXTRA) - update_cxx_compiler_flag(${target} "-Wnon-virtual-dtor" WDTOR) - update_cxx_compiler_flag(${target} "-Werror" WERROR) - #update_cxx_compiler_flag(${target} "-Wdocumentation" WERROR) - endif() - endif() - - if(FLAGS_CXX11) - update_cxx_compiler_flag(${target} "-std=c++0x" CXX_11) - update_cxx_compiler_flag(${target} "-stdlib=libc++" STD_LIBCXX) - #add check for c++11 support - endif() - - get_target_property(${target}_TYPE ${target} TYPE) - if(${target}_TYPE STREQUAL "STATIC_LIBRARY" AND NOT WIN32) - update_cxx_compiler_flag(${target} "-fpic" PIC) - elseif(${target}_TYPE STREQUAL "SHARED_LIBRARY") - update_cxx_compiler_flag(${target} "-fvisibility=hidden" HIDDEN_VISIBILITY) - endif() - set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${COMPILER_FLAGS}") -endmacro() - -function(__GET_SOURCES name) - list(LENGTH ARGV _len) - if(_len GREATER 1) - list(GET ARGV 1 sourceDir) - endif() - if(NOT DEFINED sourceDir) - set(sourceDir ${CMAKE_CURRENT_SOURCE_DIR}) - endif() - #Search for source and headers in source directory - file(GLOB_RECURSE HDR "${sourceDir}/*.h") - file(GLOB_RECURSE CXX "${sourceDir}/*.cpp") - file(GLOB_RECURSE CC "${sourceDir}/*.c") - file(GLOB_RECURSE FORMS "${sourceDir}/*.ui") - file(GLOB_RECURSE QRC "${sourceDir}/*.qrc") - if(APPLE) - file(GLOB_RECURSE MM "${sourceDir}/*.mm") - endif() - - list(APPEND sources - ${CXX} - ${CC} - ${MM} - ${HDR} - ${FORMS} - ${QRC} - ) - set(${name} ${sources} PARENT_SCOPE) -endfunction() - -function(__CHECK_SOURCE_FILES name) - list_filter("${ARGV}" ".*\\\\.h" HDR) - list_filter("${ARGV}" ".*\\\\.cpp" CXX) - list_filter("${ARGV}" ".*\\\\.cc" CC) - list_filter("${ARGV}" ".*\\\\.mm" MM) - list_filter("${ARGV}" ".*\\\\.ui" FORMS) - list_filter("${ARGV}" ".*\\\\.qrc" QRC) - - if(USE_QT5) - find_package(Qt5Core QUIET) - find_package(Qt5Widgets QUIET) - else() - find_package(Qt4 COMPONENTS QtCore QUIET REQUIRED) - endif() - - if(Qt5Core_DIR) - qt5_add_resources(${name}_QRC ${QRC}) - qt5_wrap_ui(${name}_HDR ${FORMS}) - else() - qt4_add_resources(${name}_QRC ${QRC}) - qt4_wrap_ui(${name}_HDR ${FORMS}) - endif() - - set(__sources "") - list(APPEND _extra_sources - ${CXX} - ${CC} - ${MM} - ${HDR} - ${FORMS} - ${${name}_QRC} - ${${name}_HDR} - ) - set(${name} ${_extra_sources} PARENT_SCOPE) -endfunction() - -macro(ADD_SIMPLE_LIBRARY target) - parse_arguments(LIBRARY - "LIBRARIES;INCLUDES;DEFINES;VERSION;SOVERSION;DEFINE_SYMBOL;SOURCE_DIR;SOURCE_FILES;INCLUDE_DIR;PKGCONFIG_TEMPLATE;QT" - "STATIC;INTERNAL;DEVELOPER;CXX11;NO_FRAMEWORK" - ${ARGN} - ) - - set(FRAMEWORK FALSE) - if(APPLE AND NOT LIBRARY_NO_FRAMEWORK) - set(FRAMEWORK TRUE) - endif() - - if(LIBRARY_STATIC) - set(type STATIC) - set(FRAMEWORK FALSE) - else() - set(type SHARED) - endif() - - if(LIBRARY_DEVELOPER) - list(APPEND opts DEVELOPER) - endif() - if(LIBRARY_CXX11) - list(APPEND opts CXX11) - endif() - - if(NOT LIBRARY_SOURCE_DIR) - set(LIBRARY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - endif() - - if(NOT LIBRARY_SOURCE_DIR STREQUAL "NONE") - __get_sources(LIBRARY_SOURCES ${LIBRARY_SOURCE_DIR}) - endif() - - set(LIBRARY_EXTRA_SOURCES "") - __check_source_files(LIBRARY_EXTRA_SOURCES ${LIBRARY_SOURCE_FILES}) - - # This project will generate library - add_library(${target} ${type} ${LIBRARY_SOURCES} ${LIBRARY_EXTRA_SOURCES}) - foreach(_define ${LIBRARY_DEFINES}) - add_definitions(-D${_define}) - endforeach() - - include_directories(${CMAKE_CURRENT_BINARY_DIR} - ${LIBRARY_SOURCE_DIR} - ${LIBRARY_INCLUDES} - ) - update_compiler_flags(${target} ${opts}) - qt_use_modules(${target} ${LIBRARY_QT}) - set_target_properties(${target} PROPERTIES - VERSION ${LIBRARY_VERSION} - SOVERSION ${LIBRARY_SOVERSION} - DEFINE_SYMBOL ${LIBRARY_DEFINE_SYMBOL} - FRAMEWORK ${FRAMEWORK} - ) - - target_link_libraries(${target} - ${QT_LIBRARIES} - ${LIBRARY_LIBRARIES} - ) - - #TODO add framework creation ability - if(LIBRARY_INCLUDE_DIR) - set(INCNAME ${LIBRARY_INCLUDE_DIR}) - else() - set(INCNAME ${target}) - endif() - - file(GLOB_RECURSE PUBLIC_HEADERS "${LIBRARY_SOURCE_DIR}/*[^p].h") - file(GLOB_RECURSE PRIVATE_HEADERS "${LIBRARY_SOURCE_DIR}/*_p.h") - - generate_include_headers("include/${INCNAME}" ${PUBLIC_HEADERS}) - generate_include_headers("include/${INCNAME}/${LIBRARY_VERSION}/${INCNAME}/private/" ${PRIVATE_HEADERS}) - if(FRAMEWORK) - set_source_files_properties(${PUBLIC_HEADERS} - PROPERTIES MACOSX_PACKAGE_LOCATION Headers) - set_source_files_properties(${PRIVATE_HEADERS} - PROPERTIES MACOSX_PACKAGE_LOCATION Headers/${LIBRARY_VERSION}/${INCNAME}/private/) - endif() - - if(NOT LIBRARY_INTERNAL) - if(NOT FRAMEWORK) - install(FILES ${PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/${INCNAME}") - install(FILES ${PRIVATE_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/${INCNAME}/${LIBRARY_VERSION}/${INCNAME}/private/") - endif() - if(LIBRARY_PKGCONFIG_TEMPLATE) - string(TOUPPER ${target} _target) - if(FRAMEWORK) - set(${_target}_PKG_LIBS "-L${LIB_DESTINATION} -f${target}") - set(${_target}_PKG_INCDIR "${LIB_DESTINATION}/${target}.framework/Contents/Headers") - else() - set(${_target}_PKG_LIBS "-L${LIB_DESTINATION} -l${target}") - set(${_target}_PKG_INCDIR "${CMAKE_INSTALL_PREFIX}/include/${INCNAME}") - endif() - add_pkgconfig_file(${LIBRARY_PKGCONFIG_TEMPLATE}) - endif() - endif() - if(type STREQUAL "SHARED" OR NOT LIBRARY_INTERNAL) - install(TARGETS ${target} - RUNTIME DESTINATION ${RLIBDIR} - LIBRARY DESTINATION ${LIBDIR} - ARCHIVE DESTINATION ${LIBDIR} - FRAMEWORK DESTINATION ${LIBDIR} - ) - endif() - string(TOLOWER ${type} _type) - message(STATUS "Added ${_type} library ${target}") -endmacro() - -macro(ADD_SIMPLE_EXECUTABLE target) - parse_arguments(EXECUTABLE - "LIBRARIES;INCLUDES;DEFINES;SOURCE_DIR;SOURCE_FILES;QT" - "INTERNAL;GUI;CXX11" - ${ARGN} - ) - - if(EXECUTABLE_GUI) - if(APPLE) - set(type MACOSX_BUNDLE) - else() - set(type WIN32) - endif() - else() - set(type "") - endif() - - if(NOT EXECUTABLE_SOURCE_DIR) - set(EXECUTABLE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - endif() - - set(EXECUTABLE_EXTRA_SOURCES "") - __get_sources(EXECUTABLE_EXTRA_SOURCES ${EXECUTABLE_SOURCE_DIR}) - __check_source_files(SOURCES "${EXECUTABLE_EXTRA_SOURCES};${EXECUTABLE_SOURCE_FILES}") - - # This project will generate library - add_executable(${target} ${type} ${SOURCES}) - foreach(_define ${EXECUTABLE_DEFINES}) - add_definitions(-D${_define}) - endforeach() - - include_directories(${CMAKE_CURRENT_BINARY_DIR} - . - ${EXECUTABLE_INCLUDES} - ) - - if(EXECUTABLE_CXX11) - list(APPEND opts CXX11) - endif() - - update_compiler_flags(${target} ${opts}) - qt_use_modules(${target} ${EXECUTABLE_QT}) - - target_link_libraries(${target} - ${EXECUTABLE_LIBRARIES} - ${QT_LIBRARIES} - ) - - if(NOT EXECUTABLE_INTERNAL) - install(TARGETS ${target} - RUNTIME DESTINATION ${BINDIR} - BUNDLE DESTINATION . - ) - endif() - message(STATUS "Added executable: ${target}") -endmacro() - -macro(ADD_QML_DIR _qmldir) - parse_arguments(QMLDIR - "URI;VERSION;IMPORTS_DIR" - "" - ${ARGN} - ) - if(NOT QMLDIR_IMPORTS_DIR) - set(QMLDIR_IMPORTS_DIR "${QT_IMPORTS_DIR}") - endif() - - string(REPLACE "." "/" _URI ${QMLDIR_URI}) - message(STATUS "Added qmldir: ${_qmldir} with uri ${QMLDIR_URI}") - set(QML_DIR_DESTINATION "${QMLDIR_IMPORTS_DIR}/${_URI}") - deploy_folder("${_qmldir}" - DESTINATION "${QML_DIR_DESTINATION}" - DESCRIPTION "qmldir with uri ${QMLDIR_URI}") -endmacro() - -macro(ADD_QML_MODULE target) - parse_arguments(MODULE - "LIBRARIES;INCLUDES;DEFINES;URI;QML_DIR;VERSION;SOURCE_DIR;SOURCE_FILES;IMPORTS_DIR;PLUGIN_DIR;QT" - "CXX11" - ${ARGN} - ) - - if(NOT MODULE_IMPORTS_DIR) - set(MODULE_IMPORTS_DIR "${QT_IMPORTS_DIR}") - endif() - if(MODULE_QML_DIR) - add_qml_dir("${MODULE_QML_DIR}" - URI "${MODULE_URI}" - VERSION "${MODULE_VERSION}" - IMPORTS_DIR "${MODULE_IMPORTS_DIR}" - ) - endif() - - __get_sources(SOURCES ${MODULE_SOURCE_DIR}) - set(MODULE_EXTRA_SOURCES "") - - __check_source_files(MODULE_EXTRA_SOURCES ${MODULE_SOURCE_FILES}) - list(APPEND SOURCES ${MODULE_EXTRA_SOURCES}) - # This project will generate library - add_library(${target} SHARED ${SOURCES}) - foreach(_define ${MODULE_DEFINES}) - add_definitions(-D${_define}) - endforeach() - - include_directories(${CMAKE_CURRENT_BINARY_DIR} - ${MODULE_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} - ${MODULE_INCLUDES} - ) - - qt_use_modules(${target} ${MODULE_QT}) - target_link_libraries(${target} - ${${target}_libraries} - ${MODULE_LIBRARIES} - ) - - if(MODULE_CXX11) - list(APPEND opts CXX11) - endif() - update_compiler_flags(${target} ${opts}) - message(STATUS "Added qml module: ${target} with uri ${MODULE_URI}") - string(REPLACE "." "/" _URI ${MODULE_URI}) - install(TARGETS ${target} DESTINATION "${MODULE_IMPORTS_DIR}/${_URI}/${MODULE_PLUGIN_DIR}") -endmacro() - -macro(ADD_SIMPLE_QT_TEST target) - parse_arguments(TEST - "LIBRARIES;RESOURCES;SOURCES;QT" - "CXX11" - ${ARGN} - ) - - if(TEST_SOURCES) - set(${target}_SRC ${TEST_SOURCES}) - else() - set(${target}_SRC ${target}.cpp) - endif() - list(APPEND TEST_QT Test) - - list(APPEND ${target}_SRC ${TEST_RESOURCES}) - __check_source_files(${target}_SRC ${${target}_SRC}) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - add_executable(${target} ${${target}_SRC}) - qt_use_modules(${target} ${TEST_QT}) - target_link_libraries(${target} ${TEST_LIBRARIES} ${QT_LIBRARIES}) - if(TEST_CXX11) - list(APPEND opts CXX11) - endif() - update_compiler_flags(${target} ${opts}) - add_test(NAME ${target} COMMAND ${target}) - message(STATUS "Added simple test: ${target}") -endmacro() - -macro(APPEND_TARGET_LOCATION target list) - get_target_property(${target}_LOCATION ${target} LOCATION) - list(APPEND ${list} ${${target}_LOCATION}) -endmacro() - -macro(CHECK_DIRECTORY_EXIST directory exists) - if(EXISTS ${directory}) - set(_exists FOUND) - else() - set(_exists NOT_FOUND) - endif() - set(exists ${_exists}) -endmacro() - -macro(CHECK_QML_MODULE name exists) - check_directory_exist("${QT_IMPORTS_DIR}/${name}" _exists) - message(STATUS "Checking qml module ${name} - ${_exists}") - set(${exists} ${_exists}) -endmacro() - -macro(ADD_PUBLIC_HEADER header dir) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${header} - ${CMAKE_CURRENT_BINARY_DIR}/include/${dir}/${header} COPYONLY) - list(APPEND PUBLIC_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/include/${dir}/${header}) -endmacro() - -macro(GENERATE_PUBLIC_HEADER header dir name) - add_public_header(${header}) - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/include/${dir}/${name} - "#include \"${name}\"\n" - ) - list(APPEND PUBLIC_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/include/${name}) -endmacro() - -macro(GENERATE_INCLUDE_HEADERS _dir) - include_directories(${PROJECT_BINARY_DIR}) - foreach(header ${ARGN}) - get_filename_component(_basename ${header} NAME_WE) - get_filename_component(_abs_FILE ${header} ABSOLUTE) - #message(STATUS "${PROJECT_BINARY_DIR}/${_dir}/${_basename}.h") - - if(NOT EXISTS "${PROJECT_BINARY_DIR}/${_dir}/${_basename}.h" ) - file(WRITE "${PROJECT_BINARY_DIR}/${_dir}/${_basename}.h" - "#include \"${_abs_FILE}\"\n" - ) - endif() - endforeach() -endmacro() - -macro(ADD_CUSTOM_DIRECTORY sourceDir) - parse_arguments(DIR - "DESCRIPTION" - "" - ${ARGN} - ) - - string(RANDOM tail) - get_filename_component(_basename ${sourceDir} NAME_WE) - file(GLOB_RECURSE _files "${sourceDir}/*") - add_custom_target(dir_${_basename}_${tail} ALL - SOURCES ${_files} - ) - if(DIR_DESCRIPTION) - source_group(${DIR_DESCRIPTION} FILES ${_files}) - endif() -endmacro() - -macro(DEPLOY_FOLDER sourceDir) - parse_arguments(FOLDER - "DESCRIPTION;DESTINATION" - "" - ${ARGN} - ) - - get_filename_component(_basename ${sourceDir} NAME_WE) - get_filename_component(_destname ${FOLDER_DESTINATION} NAME_WE) - file(GLOB_RECURSE _files "${sourceDir}/*") - message(STATUS "deploy folder: ${sourceDir}") - add_custom_target(qml_${_destname} ALL - SOURCES ${_files} - ) - file(GLOB _files "${sourceDir}/*") - foreach(_file ${_files}) - if(IS_DIRECTORY ${_file}) - install(DIRECTORY ${_file} DESTINATION ${FOLDER_DESTINATION}) - get_filename_component(_name ${_file} NAME_WE) - else() - install(FILES ${_file} DESTINATION ${FOLDER_DESTINATION}) - endif() - endforeach() - if(FOLDER_DESCRIPTION) - source_group(${FOLDER_DESCRIPTION} FILES ${_files}) - endif() -endmacro() - -macro(ENABLE_QML_DEBUG_SUPPORT target) - -endmacro() - -macro(ADD_PKGCONFIG_FILE file) - #add pkgconfig file - get_filename_component(_name ${file} NAME_WE) - set(PKGCONFIG_DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIBDIR}/pkgconfig) - configure_file(${file} - ${CMAKE_CURRENT_BINARY_DIR}/${_name}.pc - ) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_name}.pc - DESTINATION ${PKGCONFIG_DESTINATION} - ) -endmacro() - -macro(FIND_MODULE module) - parse_arguments(MODULE - "PREFIX;LIBRARY_HINTS;HEADERS_DIR;INCLUDE_HINTS;GLOBAL_HEADER" - "NO_PKGCONFIG;NO_MACOSX_FRAMEWORK" - ${ARGN} - ) - string(TOUPPER ${module} _name) - if(MODULE_PREFIX) - set(_name "${MODULE_PREFIX}_${_name}") - endif() - - #try to use pkgconfig - if(NOT MODULE_NO_PKGCONFIG) - find_package(PkgConfig) - pkg_check_modules(${_name} ${module}) - if(${_name}_FOUND) - list(GET ${_name}_INCLUDE_DIRS 0 ${_name}_INCLUDE_DIR) - list(GET ${_name}_LIBRARIES 0 ${_name}_LIBRARIES) - endif() - #message("${_name} + ${${_name}_LIBRARIES} AND ${${_name}_INCLUDE_DIR}") - endif() - #try to find macosx framework - if(APPLE AND NOT MODULE_NO_MACOSX_FRAMEWORK AND NOT ${_name}_FOUND) - message(STATUS "Try to find MacosX framework ${module}.framework") - find_library(${_name}_LIBRARIES - NAMES ${module} - HINTS ${MODULE_LIBRARY_HINTS} - ) - if(${_name}_LIBRARIES) - set(${_name}_FOUND true) - list(APPEND ${MODULE_PREFIX}_LIBRARIES ${${_name}_LIBRARIES}) - set(${_name}_INCLUDE_DIR "${${MODULE_PREFIX}_LIBRARIES}/Headers/") - list(APPEND ${MODULE_PREFIX}_INCLUDES - ${${_name}_INCLUDE_DIR} - ) - endif() - endif() - #try to use simple find - if(NOT ${_name}_FOUND) - message(STATUS "Try to find ${module}") - include(FindLibraryWithDebug) - find_path(${_name}_INCLUDE_DIR ${MODULE_GLOBAL_HEADER} - HINTS ${MODULE_INCLUDE_HINTS} - PATH_SUFFIXES ${MODULE_HEADERS_DIR} - ) - find_library_with_debug(${_name}_LIBRARIES - WIN32_DEBUG_POSTFIX d - NAMES ${module} - HINTS ${MODULE_LIBRARY_HINTS} - ) - #message("${MODULE_HEADERS_DIR} ${MODULE_INCLUDE_HINTS} ${QT_INCLUDE_DIR}") - endif() - - #include(FindPackageHandleStandardArgs) - #find_package_handle_standard_args(${_name} DEFAULT_MSG ${${_name}_LIBRARIES} ${${_name}_INCLUDE_DIR}) - - if(${_name}_LIBRARIES AND ${_name}_INCLUDE_DIR) - message(STATUS "Found ${module}: ${${_name}_LIBRARIES}") - set(${_name}_FOUND true) - list(APPEND ${MODULE_PREFIX}_LIBRARIES - ${${_name}_LIBRARIES} - ) - list(APPEND ${MODULE_PREFIX}_INCLUDES - ${${_name}_INCLUDE_DIR} - ) - #message("${${_name}_LIBRARIES} \n ${${_name}_INCLUDE_DIR}") - else(${_name}_LIBRARIES AND ${_name}_INCLUDE_DIR) - message(STATUS "Could NOT find ${module}") - endif() - mark_as_advanced(${${_name}_INCLUDE_DIR} ${${_name}_LIBRARIES}) -endmacro() - -macro(FIND_QT_MODULE module) - parse_arguments(MODULE - "HEADERS_DIR;GLOBAL_HEADER" - "" - ${ARGN} - ) - find_module(${module} - PREFIX QT - HEADERS_DIR ${MODULE_HEADERS_DIR} - GLOBAL_HEADER ${MODULE_GLOBAL_HEADER} - LIBRARY_HINTS ${QT_LIBRARY_DIR} - ) -endmacro() diff --git a/3rdparty/vreen/vreen/cmake/CompilerUtils.cmake b/3rdparty/vreen/vreen/cmake/CompilerUtils.cmake deleted file mode 100644 index c251fa3f7..000000000 --- a/3rdparty/vreen/vreen/cmake/CompilerUtils.cmake +++ /dev/null @@ -1,9 +0,0 @@ -include(CheckCXXCompilerFlag) - -macro(UPDATE_CXX_COMPILER_FLAG target flag name) - check_cxx_compiler_flag(${flag} COMPILER_SUPPORTS_${name}_FLAG) - if(COMPILER_SUPPORTS_${name}_FLAG) - add_definitions(${flag}) - endif() - set(${name} TRUE) -endmacro() diff --git a/3rdparty/vreen/vreen/cmake/FindLibraryWithDebug.cmake b/3rdparty/vreen/vreen/cmake/FindLibraryWithDebug.cmake deleted file mode 100644 index 58cd73086..000000000 --- a/3rdparty/vreen/vreen/cmake/FindLibraryWithDebug.cmake +++ /dev/null @@ -1,113 +0,0 @@ -# -# FIND_LIBRARY_WITH_DEBUG -# -> enhanced FIND_LIBRARY to allow the search for an -# optional debug library with a WIN32_DEBUG_POSTFIX similar -# to CMAKE_DEBUG_POSTFIX when creating a shared lib -# it has to be the second and third argument - -# Copyright (c) 2007, Christian Ehrlicher, -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -MACRO(FIND_LIBRARY_WITH_DEBUG var_name win32_dbg_postfix_name dgb_postfix libname) - - IF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") - - # no WIN32_DEBUG_POSTFIX -> simply pass all arguments to FIND_LIBRARY - FIND_LIBRARY(${var_name} - ${win32_dbg_postfix_name} - ${dgb_postfix} - ${libname} - ${ARGN} - ) - - ELSE(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") - - IF(NOT WIN32) - # on non-win32 we don't need to take care about WIN32_DEBUG_POSTFIX - - FIND_LIBRARY(${var_name} ${libname} ${ARGN}) - - ELSE(NOT WIN32) - - # 1. get all possible libnames - SET(args ${ARGN}) - SET(newargs "") - SET(libnames_release "") - SET(libnames_debug "") - - LIST(LENGTH args listCount) - - IF("${libname}" STREQUAL "NAMES") - SET(append_rest 0) - LIST(APPEND args " ") - - FOREACH(i RANGE ${listCount}) - LIST(GET args ${i} val) - - IF(append_rest) - LIST(APPEND newargs ${val}) - ELSE(append_rest) - IF("${val}" STREQUAL "PATHS") - LIST(APPEND newargs ${val}) - SET(append_rest 1) - ELSE("${val}" STREQUAL "PATHS") - LIST(APPEND libnames_release "${val}") - LIST(APPEND libnames_debug "${val}${dgb_postfix}") - ENDIF("${val}" STREQUAL "PATHS") - ENDIF(append_rest) - - ENDFOREACH(i) - - ELSE("${libname}" STREQUAL "NAMES") - - # just one name - LIST(APPEND libnames_release "${libname}") - LIST(APPEND libnames_debug "${libname}${dgb_postfix}") - - SET(newargs ${args}) - - ENDIF("${libname}" STREQUAL "NAMES") - - # search the release lib - FIND_LIBRARY(${var_name}_RELEASE - NAMES ${libnames_release} - ${newargs} - ) - - # search the debug lib - FIND_LIBRARY(${var_name}_DEBUG - NAMES ${libnames_debug} - ${newargs} - ) - - IF(${var_name}_RELEASE AND ${var_name}_DEBUG) - - # both libs found - SET(${var_name} optimized ${${var_name}_RELEASE} - debug ${${var_name}_DEBUG}) - - ELSE(${var_name}_RELEASE AND ${var_name}_DEBUG) - - IF(${var_name}_RELEASE) - - # only release found - SET(${var_name} ${${var_name}_RELEASE}) - - ELSE(${var_name}_RELEASE) - - # only debug (or nothing) found - SET(${var_name} ${${var_name}_DEBUG}) - - ENDIF(${var_name}_RELEASE) - - ENDIF(${var_name}_RELEASE AND ${var_name}_DEBUG) - - MARK_AS_ADVANCED(${var_name}_RELEASE) - MARK_AS_ADVANCED(${var_name}_DEBUG) - - ENDIF(NOT WIN32) - - ENDIF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") - -ENDMACRO(FIND_LIBRARY_WITH_DEBUG) diff --git a/3rdparty/vreen/vreen/cmake/FindQCA2.cmake b/3rdparty/vreen/vreen/cmake/FindQCA2.cmake deleted file mode 100644 index 6bfb5fbad..000000000 --- a/3rdparty/vreen/vreen/cmake/FindQCA2.cmake +++ /dev/null @@ -1,8 +0,0 @@ -#find qca2 -include(CommonUtils) -find_module(qca2 - GLOBAL_HEADER qca.h - HEADERS_DIR QtCrypto - LIBRARY_HINTS ${QT_LIBRARY_DIR} - INCLUDE_HINTS ${QT_INCLUDE_DIR} -) diff --git a/3rdparty/vreen/vreen/cmake/FindQOAuth.cmake b/3rdparty/vreen/vreen/cmake/FindQOAuth.cmake deleted file mode 100644 index 2db3d28cb..000000000 --- a/3rdparty/vreen/vreen/cmake/FindQOAuth.cmake +++ /dev/null @@ -1,42 +0,0 @@ -# Find QOAuth -# -# QOAuth_FOUND - system has QOAuth -# QOAuth_INCLUDE_DIR - the QOAuth include directory -# QOAuth_LIBRARIES - the libraries needed to use QOAuth -# QOAuth_DEFINITIONS - Compiler switches required for using QOAuth -# -# Copyright © 2010 Harald Sitter -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -include(FindLibraryWithDebug) - -if (QOAuth_INCLUDE_DIR AND QOAuth_LIBRARIES) - set(QOAuth_FOUND TRUE) -else (QOAuth_INCLUDE_DIR AND QOAuth_LIBRARIES) - if (NOT WIN32) - find_package(PkgConfig) - pkg_check_modules(PC_QOAuth QUIET qoauth) - set(QOAuth_DEFINITIONS ${PC_QOAuth_CFLAGS_OTHER}) - endif (NOT WIN32) - - find_library_with_debug(QOAuth_LIBRARIES - WIN32_DEBUG_POSTFIX d - NAMES qoauth - HINTS ${PC_QOAuth_LIBDIR} ${PC_QOAuth_LIBRARY_DIRS} - ) - - find_path(QOAuth_INCLUDE_DIR QtOAuth - HINTS ${PC_QOAuth_INCLUDEDIR} ${PC_QOAuth_INCLUDE_DIRS} - PATH_SUFFIXES QtOAuth) - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(QOAuth - DEFAULT_MSG - QOAuth_LIBRARIES - QOAuth_INCLUDE_DIR - ) - - mark_as_advanced(QOAuth_INCLUDE_DIR QOAuth_LIBRARIES) -endif (QOAuth_INCLUDE_DIR AND QOAuth_LIBRARIES) diff --git a/3rdparty/vreen/vreen/cmake/FindQt3D.cmake b/3rdparty/vreen/vreen/cmake/FindQt3D.cmake deleted file mode 100644 index 5e1f2a81c..000000000 --- a/3rdparty/vreen/vreen/cmake/FindQt3D.cmake +++ /dev/null @@ -1,6 +0,0 @@ -#find Qt3D -include(CommonUtils) -find_qt_module(Qt3D - GLOBAL_HEADER qt3dglobal.h - HEADERS_DIR Qt3D qt4/Qt3D -) diff --git a/3rdparty/vreen/vreen/cmake/FindQt3DQuick.cmake b/3rdparty/vreen/vreen/cmake/FindQt3DQuick.cmake deleted file mode 100644 index 3734a8582..000000000 --- a/3rdparty/vreen/vreen/cmake/FindQt3DQuick.cmake +++ /dev/null @@ -1,5 +0,0 @@ -#find Qt3D -find_qt_module(Qt3DQuick - GLOBAL_HEADER qt3dquickglobal.h - HEADERS_DIR Qt3DQuick qt4/Qt3DQuick -) diff --git a/3rdparty/vreen/vreen/cmake/MocUtils.cmake b/3rdparty/vreen/vreen/cmake/MocUtils.cmake deleted file mode 100644 index aa9bef8a5..000000000 --- a/3rdparty/vreen/vreen/cmake/MocUtils.cmake +++ /dev/null @@ -1,50 +0,0 @@ -macro(MOC_WRAP_CPP outfiles) - if(NOT CMAKE_AUTOMOC) - # get include dirs - qt4_get_moc_flags(moc_flags) - qt4_extract_options(moc_files moc_options ${ARGN}) - - foreach(it ${moc_files}) - get_filename_component(_abs_file ${it} ABSOLUTE) - get_filename_component(_abs_PATH ${_abs_file} PATH) - get_filename_component(_basename ${it} NAME_WE) - - set(_HAS_MOC false) - - if(EXISTS ${_abs_PATH}/${_basename}.cpp) - set(_header ${_abs_PATH}/${_basename}.cpp) - file(READ ${_header} _contents) - string(REGEX MATCHALL "# *include +[\">]moc_[^ ]+\\.cpp[\">]" _match "${_contents}") - string(REGEX MATCHALL "# *include +[^ ]+\\.moc[\">]" _match2 "${_contents}") - string(REGEX MATCHALL "Q_OBJECT" _match3 "${_contents}") - if(_match) - set(_HAS_MOC true) - foreach(_current_MOC_INC ${_match}) - string(REGEX MATCH "moc_[^ <\"]+\\.cpp" _current_MOC "${_current_MOC_INC}") - set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) - qt4_create_moc_command(${_abs_file} ${_moc} "${_moc_INCS}" "") - macro_add_file_dependencies(${_abs_file} ${_moc}) - endforeach(_current_MOC_INC) - endif() - if(_match2) - set(_HAS_MOC true) - foreach(_current_MOC_INC ${_match2}) - string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") - set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) - qt4_create_moc_command(${_header} ${_moc} "${_moc_INCS}" "") - macro_add_file_dependencies(${_header} ${_moc}) - endforeach (_current_MOC_INC) - endif() - endif() - if(NOT _HAS_MOC) - file(READ ${_abs_file} _contents) - string(REGEX MATCHALL "Q_OBJECT|Q_GADGET" _match2 "${_contents}") - if(_match2) - qt4_make_output_file(${_abs_file} moc_ cpp outfile) - qt4_create_moc_command(${_abs_file} ${outfile} "${moc_flags}" "${moc_options}") - set(${outfiles} ${${outfiles}} ${outfile}) - endif() - endif() - endforeach(it) - endif() -endmacro(MOC_WRAP_CPP) diff --git a/3rdparty/vreen/vreen/cmake/QtBundleUtils.cmake b/3rdparty/vreen/vreen/cmake/QtBundleUtils.cmake deleted file mode 100644 index a5ccc92ff..000000000 --- a/3rdparty/vreen/vreen/cmake/QtBundleUtils.cmake +++ /dev/null @@ -1,106 +0,0 @@ -if(NOT CMAKE_DEBUG_POSTFIX) - if(APPLE) - set(CMAKE_DEBUG_POSTFIX _debug) - elseif(WIN32) - set(CMAKE_DEBUG_POSTFIX d) - endif() -endif() - -macro(DEPLOY_QT_PLUGIN _path) - get_filename_component(_dir ${_path} PATH) - get_filename_component(name ${_path} NAME_WE) - string(TOUPPER ${CMAKE_BUILD_TYPE} _type) - if(${_type} STREQUAL "DEBUG") - set(name "${name}${CMAKE_DEBUG_POSTFIX}") - endif() - - set(name "${CMAKE_SHARED_LIBRARY_PREFIX}${name}") - set(PLUGIN "${QT_PLUGINS_DIR}/${_dir}/${name}${CMAKE_SHARED_LIBRARY_SUFFIX}") - #trying to search lib with suffix 4 - if(NOT EXISTS ${PLUGIN}) - set(name "${name}4") - set(PLUGIN "${QT_PLUGINS_DIR}/${_dir}/${name}${CMAKE_SHARED_LIBRARY_SUFFIX}") - endif() - - #message(${PLUGIN}) - if(EXISTS ${PLUGIN}) - message(STATUS "Deployng ${_path} plugin") - install(FILES ${PLUGIN} DESTINATION "${PLUGINSDIR}/${_dir}" COMPONENT Runtime) - else() - message(STATUS "Could not deploy ${_path} plugin") - endif() -endmacro() - -macro(DEPLOY_QT_PLUGINS) - foreach(plugin ${ARGN}) - deploy_qt_plugin(${plugin}) - endforeach() -endmacro() - -macro(DEPLOY_QML_MODULE _path) - string(TOUPPER ${CMAKE_BUILD_TYPE} _type) - set(_importPath "${QT_IMPORTS_DIR}/${_path}") - if(EXISTS ${_importPath}) - if(WIN32 OR APPLE) - if(${_type} STREQUAL "DEBUG") - set(_libPattern "[^${CMAKE_DEBUG_POSTFIX}]${CMAKE_SHARED_LIBRARY_SUFFIX}$") - else() - set(_libPattern "${CMAKE_DEBUG_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}$") - endif() - else() - set(_libPattern "^[*]") - endif() - - #evil version - message(STATUS "Deployng ${_path} QtQuick module") - install(DIRECTORY ${_importPath} DESTINATION ${IMPORTSDIR} COMPONENT Runtime - PATTERN "*.pdb" EXCLUDE - REGEX "${_libPattern}" EXCLUDE - ) - else() - message(STATUS "Could not deploy ${_path} QtQuick module") - endif() -endmacro() - -macro(DEPLOY_QML_MODULES) - foreach(plugin ${ARGN}) - deploy_qml_module(${plugin}) - endforeach() -endmacro() - -macro(DEFINE_BUNDLE_PATHS _name) - if(WIN32) - set(BUNDLE_NAME ${_name}.exe) - set(BINDIR bin) - set(BUNDLE_PATH "\${CMAKE_INSTALL_PREFIX}/${BINDIR}/${BUNDLE_NAME}") - set(LIBDIR lib${LIB_SUFFIX}) - set(SHAREDIR share) - set(PLUGINSDIR bin) - set(IMPORTSDIR ${BINDIR}) - set(RLIBDIR ${BINDIR}) - elseif(APPLE) - set(BUNDLE_NAME ${_name}.app) - set(BUNDLE_PATH "\${CMAKE_INSTALL_PREFIX}/${BUNDLE_NAME}") - set(BINDIR ${BUNDLE_NAME}/Contents/MacOS) - set(LIBDIR ${BINDIR}) - set(RLIBDIR ${BUNDLE_NAME}/Contents/Frameworks) - set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources) - set(PLUGINSDIR ${BUNDLE_NAME}/Contents/PlugIns) - set(IMPORTSDIR ${BINDIR}) - else() - set(BUNDLE_NAME ${_name}) - set(BINDIR bin) - set(BUNDLE_PATH "\${CMAKE_INSTALL_PREFIX}/${BINDIR}/${BUNDLE_NAME}") - set(LIBDIR lib${LIB_SUFFIX}) - set(RLIBDIR ${LIBDIR}) - set(SHAREDIR share/apps/${_name}) - set(PLUGINSDIR ${LIBDIR}/plugins/) - set(IMPORTSDIR ${BINDIR}) #)${LIBDIR}/imports) - endif() - - if(APPLE) - set(DEPLOY_APP "${BUNDLE_NAME}") - else() - set(DEPLOY_APP "bin/${BUNDLE_NAME}") - endif() -endmacro() diff --git a/3rdparty/vreen/vreen/cmake/README b/3rdparty/vreen/vreen/cmake/README deleted file mode 100644 index e69de29bb..000000000 diff --git a/3rdparty/vreen/vreen/cmake_uninstall.cmake.in b/3rdparty/vreen/vreen/cmake_uninstall.cmake.in deleted file mode 100644 index 31a573cc2..000000000 --- a/3rdparty/vreen/vreen/cmake_uninstall.cmake.in +++ /dev/null @@ -1,21 +0,0 @@ -IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") - MESSAGE(FATAL_ERROR "Cannot find install manifest: "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt"") -ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") - -FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) -STRING(REGEX REPLACE "\n" ";" files "${files}") -FOREACH(file ${files}) - MESSAGE(STATUS "Uninstalling "$ENV{DESTDIR}${file}"") - IF(EXISTS "$ENV{DESTDIR}${file}") - EXEC_PROGRAM( - "@CMAKE_COMMAND@" ARGS "-E remove "$ENV{DESTDIR}${file}"" - OUTPUT_VARIABLE rm_out - RETURN_VALUE rm_retval - ) - IF(NOT "${rm_retval}" STREQUAL 0) - MESSAGE(FATAL_ERROR "Problem when removing "$ENV{DESTDIR}${file}"") - ENDIF(NOT "${rm_retval}" STREQUAL 0) - ELSE(EXISTS "$ENV{DESTDIR}${file}") - MESSAGE(STATUS "File "$ENV{DESTDIR}${file}" does not exist.") - ENDIF(EXISTS "$ENV{DESTDIR}${file}") -ENDFOREACH(file) diff --git a/3rdparty/vreen/vreen/src/3rdparty/CMakeLists.txt b/3rdparty/vreen/vreen/src/3rdparty/CMakeLists.txt deleted file mode 100644 index 2bda20263..000000000 --- a/3rdparty/vreen/vreen/src/3rdparty/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -find_package(PkgConfig) -if(PKG_CONFIG_FOUND) - pkg_check_modules(K8JSON k8json) - set(K8JSON_LIBRARIES ${K8JSON_LDFLAGS}) -endif() -if(NOT K8JSON_FOUND) - message(STATUS "Using internal copy of k8json") - set(K8JSON_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") - - list(APPEND SRC "k8json/k8json.cpp") - add_library(k8json STATIC ${SRC}) - target_link_libraries(k8json) - qt_use_modules(k8json Core) - update_compiler_flags(k8json) - add_definitions(-DK8JSON_LIB_MAKEDLL -DK8JSON_INCLUDE_GENERATOR -DK8JSON_INCLUDE_COMPLEX_GENERATOR) - set(K8JSON_LIBRARIES k8json CACHE INTERNAL "") -endif() diff --git a/3rdparty/vreen/vreen/src/3rdparty/k8json/CMakeLists.txt b/3rdparty/vreen/vreen/src/3rdparty/k8json/CMakeLists.txt deleted file mode 100644 index 155448f35..000000000 --- a/3rdparty/vreen/vreen/src/3rdparty/k8json/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -project(k8json) -cmake_minimum_required(VERSION 2.6) - -set(CMAKE_LIBK8JSON_VERSION_MAJOR 1 CACHE INT "Major k8json version number" FORCE) -set(CMAKE_LIBK8JSON_VERSION_MINOR 0 CACHE INT "Minor k8json version number" FORCE) -set(CMAKE_LIBK8JSON_VERSION_PATCH 0 CACHE INT "Release k8json version number" FORCE) -set(CMAKE_LIBK8JSON_VERSION_STRING "${CMAKE_LIBK8JSON_VERSION_MAJOR}.${CMAKE_LIBK8JSON_VERSION_MINOR}.${CMAKE_LIBK8JSON_VERSION_PATCH}" CACHE STRING "k8json version string" FORCE) - -add_definitions(-DK8JSON_LIB_MAKEDLL -DK8JSON_INCLUDE_GENERATOR -DK8JSON_INCLUDE_COMPLEX_GENERATOR) - -set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR}) -set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) -set(LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE STRING "Library directory name" FORCE) - -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - -find_package(Qt4 REQUIRED) -include_directories(${QT_INCLUDES}) - -# mingw can't handle exported explicit template instantiations in a DLL -if (MINGW) - set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols ${CMAKE_SHARED_LINKER_FLAGS}") -endif (MINGW) - -set(k8json_SRCS - k8json.cpp -) - -add_library(k8json SHARED ${k8json_SRCS}) - -set_target_properties(k8json PROPERTIES - VERSION ${CMAKE_LIBK8JSON_VERSION_STRING} - SOVERSION ${CMAKE_LIBK8JSON_VERSION_MAJOR} - LINK_INTERFACE_LIBRARIES "" - DEFINE_SYMBOL K8JSON_LIB_MAKEDLL -) - -target_link_libraries(k8json ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY}) - - -install(TARGETS k8json ARCHIVE DESTINATION ${LIB_DESTINATION} - LIBRARY DESTINATION ${LIB_DESTINATION} - RUNTIME DESTINATION bin) - -install(FILES - k8json.h - DESTINATION include/k8json COMPONENT Devel -) - -# Install package config file -if(NOT WIN32) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/k8json.pc.cmake - ${CMAKE_CURRENT_BINARY_DIR}/k8json.pc - ) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/k8json.pc - DESTINATION ${LIB_DESTINATION}/pkgconfig - ) -endif(NOT WIN32) - diff --git a/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.cpp b/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.cpp deleted file mode 100644 index af0863c19..000000000 --- a/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.cpp +++ /dev/null @@ -1,894 +0,0 @@ -/* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar) - * Understanding is not required. Only obedience. - * - * This program is free software. It comes without any warranty, to - * the extent permitted by applicable law. You can redistribute it - * and/or modify it under the terms of the Do What The Fuck You Want - * To Public License, Version 2, as published by Sam Hocevar. See - * http://sam.zoy.org/wtfpl/COPYING for more details. - */ -//#include - -#if defined(K8JSON_INCLUDE_COMPLEX_GENERATOR) || defined(K8JSON_INCLUDE_GENERATOR) -# include -#endif - -#include "k8json.h" - - -namespace K8JSON { - -static const quint8 utf8Length[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x00-0x0f - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x10-0x1f - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x20-0x2f - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x30-0x3f - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x40-0x4f - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x50-0x5f - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x60-0x6f - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x70-0x7f - 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, //0x80-0x8f - 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, //0x90-0x9f - 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, //0xa0-0xaf - 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, //0xb0-0xbf - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, //0xc0-0xcf c0-c1: overlong encoding: start of a 2-byte sequence, but code point <= 127 - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, //0xd0-0xdf - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, //0xe0-0xef - 4,4,4,4,4,8,8,8,8,8,8,8,8,8,8,8 //0xf0-0xff -}; - - -/* - * check if given (const uchar *) represents valid UTF-8 sequence - * NULL (or empty) s is not valid - */ -bool isValidUtf8 (const uchar *s, int maxLen, bool zeroInvalid) { - if (!s) return false; - if (maxLen < 1) return false; - uchar ch = 0; - const uchar *tmpS = s; - while (maxLen > 0) { - ch = *tmpS++; maxLen--; - if (!ch) { - if (maxLen != 0 && zeroInvalid) return false; - break; - } - // ascii or utf-8 - quint8 t = utf8Length[ch]; - if (t&0x08) return false; // invalid utf-8 sequence - if (t) { - // utf-8 - if (maxLen < --t) return false; // invalid utf-8 sequence - while (t--) { - quint8 b = *tmpS++; maxLen--; - if (utf8Length[b] != 9) return false; // invalid utf-8 sequence - } - } - } - return true; -} - - -QString quote (const QString &str) { - int len = str.length(), c; - QString res('"'); res.reserve(len+128); - for (int f = 0; f < len; f++) { - QChar ch(str[f]); - ushort uc = ch.unicode(); - if (uc < 32) { - // control char - switch (uc) { - case '\b': res += "\\b"; break; - case '\f': res += "\\f"; break; - case '\n': res += "\\n"; break; - case '\r': res += "\\r"; break; - case '\t': res += "\\t"; break; - default: - res += "\\u"; - for (c = 4; c > 0; c--) { - ushort n = (uc>>12)&0x0f; - n += '0'+(n>9?7:0); - res += (uchar)n; - } - break; - } - } else { - // normal char - switch (uc) { - case '"': res += "\\\""; break; - case '\\': res += "\\\\"; break; - default: res += ch; break; - } - } - } - res += '"'; - return res; -} - - -/* - * skip blanks and comments - * return ptr to first non-blank char or 0 on error - * 'maxLen' will be changed - */ -const uchar *skipBlanks (const uchar *s, int *maxLength) { - if (!s) return 0; - int maxLen = *maxLength; - if (maxLen < 0) return 0; - while (maxLen > 0) { - // skip blanks - uchar ch = *s++; maxLen--; - if (ch <= ' ') continue; - // skip comments - if (ch == '/') { - if (maxLen < 2) return 0; - switch (*s) { - case '/': - while (maxLen > 0) { - s++; maxLen--; - if (s[-1] == '\n') break; - if (maxLen < 1) return 0; - } - break; - case '*': - s++; maxLen--; // skip '*' - while (maxLen > 0) { - s++; maxLen--; - if (s[-1] == '*' && s[0] == '/') { - s++; maxLen--; // skip '/' - break; - } - if (maxLen < 2) return 0; - } - break; - default: return 0; // error - } - continue; - } - // it must be a token - s--; maxLen++; - break; - } - // done - *maxLength = maxLen; - return s; -} - - -//FIXME: table? -static inline bool isValidIdChar (const uchar ch) { - return ( - ch == '$' || ch == '_' || ch >= 128 || - (ch >= '0' && ch <= '9') || - (ch >= 'A' && ch <= 'Z') || - (ch >= 'a' && ch <= 'z') - ); -} - -/* - * skip one record - * the 'record' is either one full field ( field: val) - * or one list/object. - * return ptr to the first non-blank char after the record (or 0) - * 'maxLen' will be changed - */ -const uchar *skipRec (const uchar *s, int *maxLength) { - if (!s) return 0; - int maxLen = *maxLength; - if (maxLen < 0) return 0; - int fieldNameSeen = 0; - bool again = true; - while (again && maxLen > 0) { - // skip blanks - if (!(s = skipBlanks(s, &maxLen))) return 0; - if (!maxLen) break; - uchar qch, ch = *s++; maxLen--; - // fieldNameSeen<1: no field name was seen - // fieldNameSeen=1: waiting for ':' - // fieldNameSeen=2: field name was seen, ':' was seen too, waiting for value - // fieldNameSeen=3: everything was seen, waiting for terminator - //fprintf(stderr, " ch=[%c]; fns=%i\n", ch, fieldNameSeen); - if (ch == ':') { - if (fieldNameSeen != 1) return 0; // wtf? - fieldNameSeen++; - continue; - } - // it must be a token, skip it - again = false; - //fprintf(stderr, " s=%s\n==========\n", s); - switch (ch) { - case '{': case '[': - if (fieldNameSeen == 1) return 0; // waiting for delimiter; error - fieldNameSeen = 3; - // recursive skip - qch = (ch=='{' ? '}' : ']'); // end char - if (!(s = skipBlanks(s, &maxLen))) return 0; - if (maxLen < 1 || *s != qch) { - //fprintf(stderr, " [%c]\n", *s); - for (;;) { - if (!(s = skipRec(s, &maxLen))) return 0; - if (maxLen < 1) return 0; // no closing char - ch = *s++; maxLen--; - if (ch == ',') continue; // skip next field/value pair - if (ch == qch) break; // end of the list or object - return 0; // error! - } - } else { - //fprintf(stderr, "empty!\n"); - s++; maxLen--; // skip terminator - } - //fprintf(stderr, "[%s]\n", s); - break; - case ']': case '}': case ',': // terminator - //fprintf(stderr, " term [%c] (%i)\n", ch, fieldNameSeen); - if (fieldNameSeen != 3) return 0; // incomplete field - s--; maxLen++; // back to this char - break; - case '"': case '\x27': // string - if (fieldNameSeen == 1 || fieldNameSeen > 2) return 0; // no delimiter - //fprintf(stderr, "000\n"); - fieldNameSeen++; - qch = ch; - while (*s && maxLen > 0) { - ch = *s++; maxLen--; - if (ch == qch) { s--; maxLen++; break; } - if (ch != '\\') continue; - if (maxLen < 2) return 0; // char and quote - ch = *s++; maxLen--; - switch (ch) { - case 'u': - if (maxLen < 5) return 0; - if (s[0] == qch || s[0] == '\\' || s[1] == qch || s[1] == '\\') return 0; - s += 2; maxLen -= 2; - // fallthru - case 'x': - if (maxLen < 3) return 0; - if (s[0] == qch || s[0] == '\\' || s[1] == qch || s[1] == '\\') return 0; - s += 2; maxLen -= 2; - break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': - if (maxLen < 4) return 0; - if (s[0] == qch || s[0] == '\\' || s[1] == qch || s[1] == '\\' || s[2] == qch || s[2] == '\\') return 0; - s += 3; maxLen -= 3; - break; - default: ; // escaped char already skiped - } - } - //fprintf(stderr, " str [%c]; ml=%i\n", *s, maxLen); - if (maxLen < 1 || *s != qch) return 0; // error - s++; maxLen--; // skip quote - //fprintf(stderr, " 001\n"); - again = true; - break; - default: // we can check for punctuation here, but i'm too lazy to do it - if (fieldNameSeen == 1 || fieldNameSeen > 2) return 0; // no delimiter - fieldNameSeen++; - if (isValidIdChar(ch) || ch == '-' || ch == '.' || ch == '+') { - // good token, skip it - again = true; // just a token, skip it and go on - // check for valid utf8? - while (*s && maxLen > 0) { - ch = *s++; maxLen--; - if (ch != '.' && ch != '-' && ch != '+' && !isValidIdChar(ch)) { - s--; maxLen++; - break; - } - } - } else return 0; // error - } - } - if (fieldNameSeen != 3) return 0; - // skip blanks - if (!(s = skipBlanks(s, &maxLen))) return 0; - // done - *maxLength = maxLen; - return s; -} - - -/* - * parse json-quoted string. a relaxed parser, it allows "'"-quoted strings, - * whereas json standard does not. also \x and \nnn are allowed. - * return position after the string or 0 - * 's' should point to the quote char on entry - */ -static const uchar *parseString (QString &str, const uchar *s, int *maxLength) { - if (!s) return 0; - int maxLen = *maxLength; - if (maxLen < 2) return 0; - uchar ch = 0, qch = *s++; maxLen--; - if (qch != '"' && qch != '\x27') return 0; - // calc string length and check string for correctness - int strLen = 0, tmpLen = maxLen; - const uchar *tmpS = s; - while (tmpLen > 0) { - ch = *tmpS++; tmpLen--; strLen++; - if (ch == qch) break; - if (ch != '\\') { - // ascii or utf-8 - quint8 t = utf8Length[ch]; - if (t&0x08) return 0; // invalid utf-8 sequence - if (t) { - // utf-8 - if (tmpLen < t) return 0; // invalid utf-8 sequence - while (--t) { - quint8 b = *tmpS++; tmpLen--; - if (utf8Length[b] != 9) return 0; // invalid utf-8 sequence - } - } - continue; - } - // escape sequence - ch = *tmpS++; tmpLen--; //!strLen++; - if (tmpLen < 2) return 0; - int hlen = 0; - switch (ch) { - case 'u': hlen = 4; - case 'x': - if (!hlen) hlen = 2; - if (tmpLen < hlen+1) return 0; - while (hlen-- > 0) { - ch = *tmpS++; tmpLen--; - if (ch >= 'a') ch -= 32; - if (!(ch >= '0' && ch <= '9') && !(ch >= 'A' && ch <= 'F')) return 0; - } - hlen = 0; - break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': // octal char - if (tmpLen < 3) return 0; - for (hlen = 2; hlen > 0; hlen--) { - ch = *tmpS++; tmpLen--; - if (ch < '0' || ch > '7') return 0; - } - break; - case '"': case '\x27': ch = 0; break; - default: ; // one escaped char; will be checked later - } - } - if (ch != qch) return 0; // no terminating quote - // - str.reserve(str.length()+strLen+1); - ch = 0; - while (maxLen > 0) { - ch = *s++; maxLen--; - if (ch == qch) break; - if (ch != '\\') { - // ascii or utf-8 - quint8 t = utf8Length[ch]; - if (!t) str.append(ch); // ascii - else { - // utf-8 - int u = 0; s--; maxLen++; - while (t--) { - quint8 b = *s++; maxLen--; - u = (u<<6)+(b&0x3f); - } - if (u > 0x10ffff) u &= 0xffff; - if ((u >= 0xd800 && u <= 0xdfff) || // utf16/utf32 surrogates - (u >= 0xfdd0 && u <= 0xfdef) || // just for fun - (u >= 0xfffe && u <= 0xffff)) continue; // bad unicode, skip it - QChar zch(u); - str.append(zch); - } - continue; - } - ch = *s++; maxLen--; // at least one char left here - int uu = 0; int escCLen = 0; - switch (ch) { - case 'u': // unicode char, 4 hex digits - escCLen = 4; - // fallthru - case 'x': { // ascii char, 2 hex digits - if (!escCLen) escCLen = 2; - while (escCLen-- > 0) { - ch = *s++; maxLen--; - if (ch >= 'a') ch -= 32; - uu = uu*16+ch-'0'; - if (ch >= 'A'/* && ch <= 'F'*/) uu -= 7; - } - if (uu > 0x10ffff) uu &= 0xffff; - if ((uu >= 0xd800 && uu <= 0xdfff) || // utf16/utf32 surrogates - (uu >= 0xfdd0 && uu <= 0xfdef) || // just for fun - (uu >= 0xfffe && uu <= 0xffff)) uu = -1; // bad unicode, skip it - if (uu >= 0) { - QChar zch(uu); - str.append(zch); - } - } break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { // octal char - s--; maxLen++; - uu = 0; - for (int f = 3; f > 0; f--) { - ch = *s++; maxLen--; - uu = uu*8+ch-'0'; - } - QChar zch(uu); - str.append(zch); - } break; - case '\\': str.append('\\'); break; - case '/': str.append('/'); break; - case 'b': str.append('\b'); break; - case 'f': str.append('\f'); break; - case 'n': str.append('\n'); break; - case 'r': str.append('\r'); break; - case 't': str.append('\t'); break; - case '"': case '\x27': str.append(ch); break; - default: - // non-standard! - if (ch != '\t' && ch != '\r' && ch != '\n') return 0; // all other chars are BAD - str.append(ch); - } - } - if (ch != qch) return 0; - *maxLength = maxLen; - return s; -} - - -/* - * parse identifier - */ -static const uchar *parseId (QString &str, const uchar *s, int *maxLength) { - if (!s) return 0; - int maxLen = *maxLength; - if (maxLen < 1) return 0; - uchar ch = 0; - // calc string length and check string for correctness - int strLen = 0, tmpLen = maxLen; - const uchar *tmpS = s; - while (tmpLen > 0) { - ch = *tmpS++; - if (!isValidIdChar(ch)) { - if (!strLen) return 0; - break; - } - tmpLen--; strLen++; - // ascii or utf-8 - quint8 t = utf8Length[ch]; - if (t&0x08) return 0; // invalid utf-8 sequence - if (t) { - // utf-8 - if (tmpLen < t) return 0; // invalid utf-8 sequence - while (--t) { - quint8 b = *tmpS++; tmpLen--; - if (utf8Length[b] != 9) return 0; // invalid utf-8 sequence - } - } - continue; - } -/* - str = "true"; - while (isValidIdChar(*s)) { s++; (*maxLength)--; } - return s; -*/ - // - str.reserve(str.length()+strLen+1); - ch = 0; - while (maxLen > 0) { - ch = *s++; maxLen--; - if (!isValidIdChar(ch)) { s--; maxLen++; break; } - // ascii or utf-8 - quint8 t = utf8Length[ch]; - if (!t) str.append(ch); // ascii - else { - // utf-8 - int u = 0; s--; maxLen++; - while (t--) { - quint8 ch = *s++; maxLen--; - u = (u<<6)+(ch&0x3f); - } - if (u > 0x10ffff) u &= 0xffff; - if ((u >= 0xd800 && u <= 0xdfff) || // utf16/utf32 surrogates - (u >= 0xfdd0 && u <= 0xfdef) || // just for fun - (u >= 0xfffe && u <= 0xffff)) continue; // bad unicode, skip it - QChar zch(u); - str.append(zch); - } - continue; - } - *maxLength = maxLen; - return s; -} - - -/* - * parse number - */ -//TODO: parse 0x... -static const uchar *parseNumber (QVariant &num, const uchar *s, int *maxLength) { - if (!s) return 0; - int maxLen = *maxLength; - if (maxLen < 1) return 0; - uchar ch = *s++; maxLen--; - // check for negative number - bool negative = false, fr = false; - double fnum = 0.0; - switch (ch) { - case '-': - if (maxLen < 1) return 0; - ch = *s++; maxLen--; - negative = true; - break; - case '+': - if (maxLen < 1) return 0; - ch = *s++; maxLen--; - break; - default: ; - } - if (ch != '.' && (ch < '0' || ch > '9')) return 0; // invalid integer part, no fraction part - if (ch == '0' && *maxLength > 0 && *s == 'x') { - // hex number - s++; (*maxLength)--; // skip 'x' - bool wasDigit = false; - for (;;) { - if (*maxLength < 1) break; - uchar ch = *s++; (*maxLength)--; - //if (ch >= 'a' && ch <= 'f') ch -= 32; - if (ch >= '0' && ch <= '9') { - fnum *= 16; fnum += ch-'0'; - } else if (ch >= 'A' && ch <= 'F') { - fnum *= 16; fnum += ch-'A'+10; - } else if (ch >= 'a' && ch <= 'f') { - fnum *= 16; fnum += ch-'a'+10; - } else break; - wasDigit = true; - } - if (!wasDigit) return 0; - goto backanddone; - } - // parse integer part - while (ch >= '0' && ch <= '9') { - ch -= '0'; - fnum = fnum*10+ch; - if (!maxLen) goto done; - ch = *s++; maxLen--; - } - // check for fractional part - if (ch == '.') { - // parse fractional part - if (maxLen < 1) return 0; - ch = *s++; maxLen--; - double frac = 0.1; fr = true; - if (ch < '0' || ch > '9') return 0; // invalid fractional part - while (ch >= '0' && ch <= '9') { - ch -= '0'; - fnum += frac*ch; - if (!maxLen) goto done; - frac /= 10; - ch = *s++; maxLen--; - } - } - // check for exp part - if (ch == 'e' || ch == 'E') { - if (maxLen < 1) return 0; - // check for exp sign - bool expNeg = false; - ch = *s++; maxLen--; - if (ch == '+' || ch == '-') { - if (maxLen < 1) return 0; - expNeg = (ch == '-'); - ch = *s++; maxLen--; - } - // check for exp digits - if (ch < '0' || ch > '9') return 0; // invalid exp - quint32 exp = 0; // 64? %-) - while (ch >= '0' && ch <= '9') { - exp = exp*10+ch-'0'; - if (!maxLen) { s++; maxLen--; break; } - ch = *s++; maxLen--; - } - while (exp--) { - if (expNeg) fnum /= 10; else fnum *= 10; - } - if (expNeg && !fr) { - if (fnum > 2147483647.0 || ((qint64)fnum)*1.0 != fnum) fr = true; - } - } -backanddone: - s--; maxLen++; -done: - if (!fr && fnum > 2147483647.0) fr = true; - if (negative) fnum = -fnum; - if (fr) num = fnum; else num = (qint32)fnum; - *maxLength = maxLen; - return s; -} - - -static const QString sTrue("true"); -static const QString sFalse("false"); -static const QString sNull("null"); - - -/* - * parse field value - * return ptr to the first non-blank char after the value (or 0) - * 'maxLen' will be changed - */ -const uchar *parseValue (QVariant &fvalue, const uchar *s, int *maxLength) { - fvalue.clear(); - if (!(s = skipBlanks(s, maxLength))) return 0; - if (*maxLength < 1) return 0; - switch (*s) { - case '-': case '+': case '.': // '+' and '.' are not in specs! - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - // number - if (!(s = parseNumber(fvalue, s, maxLength))) return 0; - break; - case 't': // true? - if (*maxLength < 4) return 0; - if (s[1] != 'r' || s[2] != 'u' || s[3] != 'e') return 0; - if (*maxLength > 4 && isValidIdChar(s[4])) return 0; - s += 4; (*maxLength) -= 4; - fvalue = true; - break; - case 'f': // false? - if (*maxLength < 5) return 0; - if (s[1] != 'a' || s[2] != 'l' || s[3] != 's' || s[4] != 'e') return 0; - if (*maxLength > 5 && isValidIdChar(s[5])) return 0; - s += 5; (*maxLength) -= 5; - fvalue = false; - break; - case 'n': // null? - if (*maxLength < 4) return 0; - if (s[1] != 'u' || s[2] != 'l' || s[3] != 'l') return 0; - if (*maxLength > 4 && isValidIdChar(s[4])) return 0; - s += 4; (*maxLength) -= 4; - // fvalue is null already - break; - case '"': case '\x27': { - // string - QString tmp; - if (!(s = parseString(tmp, s, maxLength))) return 0; - fvalue = tmp; - } - break; - case '{': case '[': - // object or list - if (!(s = parseRecord(fvalue, s, maxLength))) return 0; - break; - default: // unknown - return 0; - } - if (!(s = skipBlanks(s, maxLength))) return 0; - return s; -} - - -/* - * parse one field (f-v pair) - * return ptr to the first non-blank char after the record (or 0) - * 'maxLen' will be changed - */ -const uchar *parseField (QString &fname, QVariant &fvalue, const uchar *s, int *maxLength) { - if (!s) return 0; - //int maxLen = *maxLength; - fname.clear(); - fvalue.clear(); - if (!(s = skipBlanks(s, maxLength))) return 0; - if (*maxLength < 1) return 0; - uchar ch = *s; - // field name - if (isValidIdChar(ch)) { - // id - if (!(s = parseId(fname, s, maxLength))) return 0; - } else if (ch == '"' || ch == '\x27') { - // string - if (!(s = parseString(fname, s, maxLength))) return 0; - } - // ':' - if (!(s = skipBlanks(s, maxLength))) return 0; - if (*maxLength < 2 || *s != ':') return 0; - s++; (*maxLength)--; - // field value - return parseValue(fvalue, s, maxLength); -} - - -/* - * parse one record (list or object) - * return ptr to the first non-blank char after the record (or 0) - * 'maxLen' will be changed - */ -const uchar *parseRecord (QVariant &res, const uchar *s, int *maxLength) { - if (!s) return 0; - //int maxLen = *maxLength; - res.clear(); - if (!(s = skipBlanks(s, maxLength))) return 0; - if (*maxLength < 1) return 0; - // field name or list/object start - QString str; QVariant val; - uchar ch = *s; - bool isList = false; - switch (ch) { - case '[': isList = true; // list, fallthru - case '{': { // object - if (*maxLength < 2) return 0; - uchar ech = isList ? ']' : '}'; - s++; (*maxLength)--; - if (!(s = skipBlanks(s, maxLength))) return 0; - QVariantMap obj; QVariantList lst; - if (*maxLength < 1 || *s != ech) { - for (;;) { - if (isList) { - // list, only values - if (!(s = parseValue(val, s, maxLength))) return 0; - lst << val; - } else { - // object, full fields - if (!(s = parseField(str, val, s, maxLength))) return 0; - obj[str] = val; - } - if (*maxLength > 0) { - bool wasComma = false; - // skip commas - while (true) { - if (!(s = skipBlanks(s, maxLength))) return 0; - if (*maxLength < 1) { ch = '\0'; wasComma = false; break; } - ch = *s; - if (ch == ech) { s++; (*maxLength)--; break; } - if (ch != ',') break; - s++; (*maxLength)--; - wasComma = true; - } - if (ch == ech) break; // end of the object/list - if (wasComma) continue; - // else error - } - // error - s = 0; - break; - } - } else { - s++; (*maxLength)--; - } - if (isList) res = lst; else res = obj; - return s; - } // it will never comes here - default: ; - } - if (!(s = parseField(str, val, s, maxLength))) return 0; - QVariantMap obj; - obj[str] = val; - res = obj; - return s; -} - - -#ifdef K8JSON_INCLUDE_GENERATOR -# ifndef K8JSON_INCLUDE_COMPLEX_GENERATOR -# define _K8_JSON_COMPLEX_WORD static -# else -# define _K8_JSON_COMPLEX_WORD -# endif -#else -# ifdef K8JSON_INCLUDE_COMPLEX_GENERATOR -# define _K8_JSON_COMPLEX_WORD -# endif -#endif - -#if defined(K8JSON_INCLUDE_COMPLEX_GENERATOR) || defined(K8JSON_INCLUDE_GENERATOR) -# ifndef K8JSON_INCLUDE_COMPLEX_GENERATOR -typedef bool (*generatorCB) (void *udata, QString &err, QByteArray &res, const QVariant &val, int indent); -# endif - -_K8_JSON_COMPLEX_WORD bool generateExCB (void *udata, generatorCB cb, QString &err, QByteArray &res, const QVariant &val, int indent) { - switch (val.type()) { - case QVariant::Invalid: res += "null"; break; - case QVariant::Bool: res += (val.toBool() ? "true" : "false"); break; - case QVariant::Char: res += quote(QString(val.toChar())).toUtf8(); break; - case QVariant::Double: res += QString::number(val.toDouble()).toLatin1(); break; //CHECKME: is '.' always '.'? - case QVariant::Int: res += QString::number(val.toInt()).toLatin1(); break; - case QVariant::LongLong: res += QString::number(val.toLongLong()).toLatin1(); break; - case QVariant::UInt: res += QString::number(val.toUInt()).toLatin1(); break; - case QVariant::ULongLong: res += QString::number(val.toULongLong()).toLatin1(); break; - case QVariant::String: res += quote(val.toString()).toUtf8(); break; - case QVariant::Map: { - //for (int c = indent; c > 0; c--) res += ' '; - res += "{"; - indent++; bool comma = false; - QVariantMap m(val.toMap()); - QVariantMap::const_iterator i; - for (i = m.constBegin(); i != m.constEnd(); ++i) { - if (comma) res += ",\n"; else { res += '\n'; comma = true; } - for (int c = indent; c > 0; c--) res += ' '; - res += quote(i.key()).toUtf8(); - res += ": "; - if (!generateExCB(udata, cb, err, res, i.value(), indent)) return false; - } - indent--; - if (comma) { - res += '\n'; - for (int c = indent; c > 0; c--) res += ' '; - } - res += '}'; - indent--; - } break; - case QVariant::Hash: { - //for (int c = indent; c > 0; c--) res += ' '; - res += "{"; - indent++; bool comma = false; - QVariantHash m(val.toHash()); - QVariantHash::const_iterator i; - for (i = m.constBegin(); i != m.constEnd(); ++i) { - if (comma) res += ",\n"; else { res += '\n'; comma = true; } - for (int c = indent; c > 0; c--) res += ' '; - res += quote(i.key()).toUtf8(); - res += ": "; - if (!generateExCB(udata, cb, err, res, i.value(), indent)) return false; - } - indent--; - if (comma) { - res += '\n'; - for (int c = indent; c > 0; c--) res += ' '; - } - res += '}'; - indent--; - } break; - case QVariant::List: { - //for (int c = indent; c > 0; c--) res += ' '; - res += "["; - indent++; bool comma = false; - QVariantList m(val.toList()); - foreach (const QVariant &v, m) { - if (comma) res += ",\n"; else { res += '\n'; comma = true; } - for (int c = indent; c > 0; c--) res += ' '; - if (!generateExCB(udata, cb, err, res, v, indent)) return false; - } - indent--; - if (comma) { - res += '\n'; - for (int c = indent; c > 0; c--) res += ' '; - } - res += ']'; - indent--; - } break; - case QVariant::StringList: { - //for (int c = indent; c > 0; c--) res += ' '; - res += "["; - indent++; bool comma = false; - QStringList m(val.toStringList()); - foreach (const QString &v, m) { - if (comma) res += ",\n"; else { res += '\n'; comma = true; } - for (int c = indent; c > 0; c--) res += ' '; - res += quote(v).toUtf8(); - } - indent--; - if (comma) { - res += '\n'; - for (int c = indent; c > 0; c--) res += ' '; - } - res += ']'; - indent--; - } break; - default: - if (cb) return cb(udata, err, res, val, indent); - err = QString("invalid variant type: %1").arg(val.typeName()); - return false; - } - return true; -} - - -_K8_JSON_COMPLEX_WORD bool generateCB (void *udata, generatorCB cb, QByteArray &res, const QVariant &val, int indent) { - QString err; - return generateExCB(udata, cb, err, res, val, indent); -} -#endif - - -#ifdef K8JSON_INCLUDE_GENERATOR -bool generateEx (QString &err, QByteArray &res, const QVariant &val, int indent) { - return generateExCB(0, 0, err, res, val, indent); -} - - -bool generate (QByteArray &res, const QVariant &val, int indent) { - QString err; - return generateExCB(0, 0, err, res, val, indent); -} -#endif - - -} diff --git a/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.h b/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.h deleted file mode 100644 index 2b8a724e4..000000000 --- a/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.h +++ /dev/null @@ -1,130 +0,0 @@ -/* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar) - * Understanding is not required. Only obedience. - * - * This program is free software. It comes without any warranty, to - * the extent permitted by applicable law. You can redistribute it - * and/or modify it under the terms of the Do What The Fuck You Want - * To Public License, Version 2, as published by Sam Hocevar. See - * http://sam.zoy.org/wtfpl/COPYING for more details. - */ -#ifndef K8JSON_H -#define K8JSON_H - -//#define K8JSON_INCLUDE_GENERATOR -//#define K8JSON_INCLUDE_COMPLEX_GENERATOR - - -#include -#include -#include -#include -#include - -#if defined(K8JSON_INCLUDE_COMPLEX_GENERATOR) || defined(K8JSON_INCLUDE_GENERATOR) -# include -#endif - -#if defined(K8JSON_LIB_MAKEDLL) -# define K8JSON_EXPORT Q_DECL_EXPORT -#elif defined(K8JSON_LIB_DLL) -# define K8JSON_EXPORT Q_DECL_IMPORT -#else -# define K8JSON_EXPORT -#endif - - -namespace K8JSON { - -/* - * quote string to JSON-friendly format, add '"' - */ -K8JSON_EXPORT QString quote (const QString &str); - -/* - * check if given (const uchar *) represents valid UTF-8 sequence - * NULL (or empty) s is not valid - * sequence ends on '\0' if zeroInvalid==false - */ -K8JSON_EXPORT bool isValidUtf8 (const uchar *s, int maxLen, bool zeroInvalid=false); - - -/* - * skip blanks and comments - * return ptr to first non-blank char or 0 on error - * 'maxLen' will be changed - */ -K8JSON_EXPORT const uchar *skipBlanks (const uchar *s, int *maxLength); - -/* - * skip one record - * the 'record' is either one full field ( field: val) - * or one list/object. - * return ptr to the first non-blank char after the record (or 0) - * 'maxLen' will be changed - */ -K8JSON_EXPORT const uchar *skipRec (const uchar *s, int *maxLength); - -/* - * parse field value - * return ptr to the first non-blank char after the value (or 0) - * 'maxLen' will be changed - */ -K8JSON_EXPORT const uchar *parseValue (QVariant &fvalue, const uchar *s, int *maxLength); - - -/* - * parse one field (f-v pair) - * return ptr to the first non-blank char after the record (or 0) - * 'maxLen' will be changed - */ -K8JSON_EXPORT const uchar *parseField (QString &fname, QVariant &fvalue, const uchar *s, int *maxLength); - -/* - * parse one record (list or object) - * return ptr to the first non-blank char after the record (or 0) - * 'maxLen' will be changed - */ -K8JSON_EXPORT const uchar *parseRecord (QVariant &res, const uchar *s, int *maxLength); - - -#ifdef K8JSON_INCLUDE_GENERATOR -/* - * generate JSON text from variant - * 'err' must be empty (generateEx() will not clear it) - * return false on error - */ -K8JSON_EXPORT bool generateEx (QString &err, QByteArray &res, const QVariant &val, int indent=0); - -/* - * same as above, but without error message - */ -K8JSON_EXPORT bool generate (QByteArray &res, const QVariant &val, int indent=0); -#endif - - -#ifdef K8JSON_INCLUDE_COMPLEX_GENERATOR -/* - * callback for unknown variant type - * return false and set 'err' on error - * or return true and *add* converted value (valid sequence of utf-8 bytes) to res - */ -typedef bool (*generatorCB) (void *udata, QString &err, QByteArray &res, const QVariant &val, int indent); - -/* - * generate JSON text from variant - * 'err' must be empty (generateEx() will not clear it) - * return false on error - */ -K8JSON_EXPORT bool generateExCB (void *udata, generatorCB cb, QString &err, QByteArray &res, const QVariant &val, int indent=0); - -/* - * same as above, but without error message - */ -K8JSON_EXPORT bool generateCB (void *udata, generatorCB cb, QByteArray &res, const QVariant &val, int indent=0); -#endif - - -} - - -#endif diff --git a/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.pc.cmake b/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.pc.cmake deleted file mode 100644 index 6c51050c7..000000000 --- a/3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.pc.cmake +++ /dev/null @@ -1,12 +0,0 @@ -prefix=${CMAKE_INSTALL_PREFIX} -exec_prefix=${CMAKE_INSTALL_PREFIX}/bin -libdir=${LIB_DESTINATION} -includedir=${CMAKE_INSTALL_PREFIX}/include - -Name: k8json -Description: Small and fast Qt JSON parser -Requires: QtCore -Version: ${CMAKE_LIBK8JSON_VERSION_MAJOR}.${CMAKE_LIBK8JSON_VERSION_MINOR}.${CMAKE_LIBK8JSON_VERSION_PATCH} -Libs: -L${LIB_DESTINATION} -lk8json -Cflags: -I${CMAKE_INSTALL_PREFIX}/include - diff --git a/3rdparty/vreen/vreen/src/CMakeLists.txt b/3rdparty/vreen/vreen/src/CMakeLists.txt deleted file mode 100644 index d7845a034..000000000 --- a/3rdparty/vreen/vreen/src/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -if(NOT VREEN_INSTALL_HEADERS) - set(INTERNAL_FLAG "INTERNAL") -endif() -if(VREEN_DEVELOPER_BUILD) - set(DEVELOPER_FLAG "DEVELOPER") -endif() - -add_subdirectory(3rdparty) -add_subdirectory(api) diff --git a/3rdparty/vreen/vreen/src/api/CMakeLists.txt b/3rdparty/vreen/vreen/src/api/CMakeLists.txt deleted file mode 100644 index d9a7b1de2..000000000 --- a/3rdparty/vreen/vreen/src/api/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_simple_library(vreen - STATIC CXX11 - ${INTERNAL_FLAG} - ${DEVELOPER_FLAG} - DEFINE_SYMBOL VK_LIBRARY - DEFINES "K8JSON_INCLUDE_GENERATOR;K8JSON_INCLUDE_COMPLEX_GENERATOR" - VERSION ${CMAKE_VREEN_VERSION_STRING} - SOVERSION ${CMAKE_VREEN_VERSION_MAJOR} - LIBRARIES ${K8JSON_LIBRARIES} - INCLUDES ${K8JSON_INCLUDE_DIRS} - INCLUDE_DIR vreen - PKGCONFIG_TEMPLATE vreen.pc.cmake - QT Core Network Gui -) diff --git a/3rdparty/vreen/vreen/src/api/abstractlistmodel.cpp b/3rdparty/vreen/vreen/src/api/abstractlistmodel.cpp deleted file mode 100644 index f6890a3af..000000000 --- a/3rdparty/vreen/vreen/src/api/abstractlistmodel.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "abstractlistmodel.h" -#include - -namespace Vreen { - -AbstractListModel::AbstractListModel(QObject *parent) : - QAbstractListModel(parent) -{ -} - -QVariantMap AbstractListModel::get(int row) -{ - auto roles = roleNames(); - QVariantMap map; - auto index = createIndex(row, 0); - for (auto it = roles.constBegin(); it != roles.constEnd(); it++) { - auto value = data(index, it.key()); - map.insert(it.value(), value); - } - return map; -} - -QVariant AbstractListModel::get(int row, const QByteArray &field) -{ - auto index = createIndex(row, 0); - return data(index, roleNames().key(field)); -} - -} //namespace Vreen - diff --git a/3rdparty/vreen/vreen/src/api/abstractlistmodel.h b/3rdparty/vreen/vreen/src/api/abstractlistmodel.h deleted file mode 100644 index 90d8ce3c6..000000000 --- a/3rdparty/vreen/vreen/src/api/abstractlistmodel.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef ABSTRACTLISTMODEL_H -#define ABSTRACTLISTMODEL_H - -#include -#include "vk_global.h" - -namespace Vreen { - -class VK_SHARED_EXPORT AbstractListModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit AbstractListModel(QObject *parent = 0); - Q_INVOKABLE QVariantMap get(int row); - Q_INVOKABLE QVariant get(int row, const QByteArray &field); -}; - -} //namespace Vreen - -#endif // ABSTRACTLISTMODEL_H - diff --git a/3rdparty/vreen/vreen/src/api/attachment.cpp b/3rdparty/vreen/vreen/src/api/attachment.cpp deleted file mode 100644 index 06c2e793d..000000000 --- a/3rdparty/vreen/vreen/src/api/attachment.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "attachment.h" -#include -#include - -namespace Vreen { - -QDataStream &operator <<(QDataStream &out, const Vreen::Attachment &item) -{ - return out << item.data(); -} - -QDataStream &operator >>(QDataStream &out, Vreen::Attachment &item) -{ - QVariantMap data; - out >> data; - item.setData(data); - return out; -} - -const static QStringList types = QStringList() - << "photo" - << "posted_photo" - << "video" - << "audio" - << "doc" - << "graffiti" - << "link" - << "note" - << "app" - << "poll" - << "page"; - -class AttachmentData : public QSharedData { -public: - AttachmentData() : QSharedData(), - type(Attachment::Other), - ownerId(0), - mediaId(0) {} - AttachmentData(const AttachmentData &o) : QSharedData(o), - type(o.type), - ownerId(o.ownerId), - mediaId(o.mediaId), - data(o.data) {} - Attachment::Type type; - int ownerId; - int mediaId; - QVariantMap data; - - static Attachment::Type getType(const QString &type) - { - return static_cast(types.indexOf(type)); - } -}; - -/*! - * \brief The Attachment class - * Api reference: \link http://vk.com/developers.php?oid=-1&p=Описание_поля_attachments - */ - -/*! - * \brief Attachment::Attachment - */ -Attachment::Attachment() : d(new AttachmentData) -{ -} - -Attachment::Attachment(const QVariantMap &data) : d(new AttachmentData) -{ - setData(data); -} - -Attachment::Attachment(const QString &string) : d(new AttachmentData) -{ - QRegExp regex("(\\w+)(\\d+)_(\\d+)"); - regex.indexIn(string); - //convert type to enum - d->data.insert("type", d->type = AttachmentData::getType(regex.cap(1))); - d->ownerId = regex.cap(2).toInt(); - d->mediaId = regex.cap(3).toInt(); -} - -Attachment::Attachment(const Attachment &rhs) : d(rhs.d) -{ -} - -Attachment &Attachment::operator=(const Attachment &rhs) -{ - if (this != &rhs) - d.operator=(rhs.d); - return *this; -} - -Attachment::~Attachment() -{ -} - -void Attachment::setData(const QVariantMap &data) -{ - d->data.clear(); - QString type = data.value("type").toString(); - - //move properties to top level - auto map = data.value(type).toMap(); - for (auto it = map.constBegin(); it != map.constEnd(); it++) - d->data.insert(it.key(), it.value()); - //convert type to enum - d->data.insert("type", d->type = AttachmentData::getType(type)); -} - -QVariantMap Attachment::data() const -{ - return d->data; -} - -Attachment::Type Attachment::type() const -{ - return d->type; -} - -void Attachment::setType(Attachment::Type type) -{ - d->type = type; -} - -void Attachment::setType(const QString &type) -{ - d->type = d->getType(type); -} - -int Attachment::ownerId() const -{ - return d->ownerId; -} - -void Attachment::setOwnerId(int ownerId) -{ - d->ownerId = ownerId; -} - -int Attachment::mediaId() const -{ - return d->mediaId; -} - -void Attachment::setMediaId(int id) -{ - d->mediaId = id; -} - -Attachment Attachment::fromData(const QVariant &data) -{ - return Attachment(data.toMap()); -} - -Attachment::List Attachment::fromVariantList(const QVariantList &list) -{ - Attachment::List attachments; - foreach (auto item, list) - attachments.append(Attachment::fromData(item.toMap())); - return attachments; -} - -QVariantList Attachment::toVariantList(const Attachment::List &list) -{ - QVariantList variantList; - foreach (auto item, list) - variantList.append(item.data()); - return variantList; -} - -Attachment::Hash Attachment::toHash(const Attachment::List &list) -{ - Hash hash; - foreach (auto attachment, list) - hash.insert(attachment.type(), attachment); - return hash; -} - -QVariantMap Attachment::toVariantMap(const Attachment::Hash &hash) -{ - //FIXME i want to Qt5 - QVariantMap map; - foreach (auto key, hash.keys()) - map.insert(QString::number(key), toVariantList(hash.values(key))); - return map; -} - -QVariant Attachment::property(const QString &name, const QVariant &def) const -{ - return d->data.value(name, def); -} - -QStringList Attachment::dynamicPropertyNames() const -{ - return d->data.keys(); -} - -void Attachment::setProperty(const QString &name, const QVariant &value) -{ - d->data.insert(name, value); -} - -bool Attachment::isFetched() const -{ - return !d->data.isEmpty(); -} - -} // namespace Vreen - -#include "moc_attachment.cpp" diff --git a/3rdparty/vreen/vreen/src/api/attachment.h b/3rdparty/vreen/vreen/src/api/attachment.h deleted file mode 100644 index 7e84927dd..000000000 --- a/3rdparty/vreen/vreen/src/api/attachment.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_ATTACHMENT_H -#define VK_ATTACHMENT_H - -#include -#include -#include "vk_global.h" - -namespace Vreen { - -class AttachmentData; - -class VK_SHARED_EXPORT Attachment -{ - Q_GADGET - Q_ENUMS(Type) -public: - enum Type { - Photo, - PostedPhoto, - Video, - Audio, - Document, - Graffiti, - Link, - Note, - ApplicationImage, - Poll, - Page, - Other = -1 - }; - typedef QList List; - typedef QMultiHash Hash; - - Attachment(); - Attachment(const Attachment &); - Attachment &operator=(const Attachment &); - ~Attachment(); - - void setData(const QVariantMap &data); - QVariantMap data() const; - Type type() const; - void setType(Type); - void setType(const QString &type); - int ownerId() const; - void setOwnerId(int ownerId); - int mediaId() const; - void setMediaId(int mediaId); - bool isFetched() const; - - static Attachment fromData(const QVariant &data); - static List fromVariantList(const QVariantList &list); - static QVariantList toVariantList(const List &list); - static Hash toHash(const List &list); - static QVariantMap toVariantMap(const Hash &hash); - - QVariant property(const QString &name, const QVariant &def = QVariant()) const; - template - T property(const char *name, const T &def) const - { return QVariant::fromValue(property(name, QVariant::fromValue(def))); } - void setProperty(const QString &name, const QVariant &value); - QStringList dynamicPropertyNames() const; - template - static T to(const Attachment &attachment); - template - static Attachment from(const T &item); - - friend QDataStream &operator <<(QDataStream &out, const Vreen::Attachment &item); - friend QDataStream &operator >>(QDataStream &out, Vreen::Attachment &item); -protected: - Attachment(const QVariantMap &data); - Attachment(const QString &string); -private: - QSharedDataPointer d; -}; - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::Attachment) -Q_DECLARE_METATYPE(Vreen::Attachment::List) -Q_DECLARE_METATYPE(Vreen::Attachment::Hash) -Q_DECLARE_METATYPE(Vreen::Attachment::Type) - - -#endif // VK_ATTACHMENT_H - diff --git a/3rdparty/vreen/vreen/src/api/audio.cpp b/3rdparty/vreen/vreen/src/api/audio.cpp deleted file mode 100644 index 07245f0d3..000000000 --- a/3rdparty/vreen/vreen/src/api/audio.cpp +++ /dev/null @@ -1,428 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "audio.h" -#include "client.h" -#include "reply_p.h" -#include "utils_p.h" -#include -#include -#include -#include - -namespace Vreen { - -class AudioProvider; -class AudioProviderPrivate -{ - Q_DECLARE_PUBLIC(AudioProvider) -public: - AudioProviderPrivate(AudioProvider *q, Client *client) : q_ptr(q), client(client) {} - AudioProvider *q_ptr; - Client *client; - - static QVariant handleAudio(const QVariant &response) { - AudioItemList items; - auto list = response.toList(); - if (list.count() && list.first().canConvert()) - list.removeFirst(); //HACK For stupid API((( - - foreach (auto item, list) { - auto map = item.toMap(); - AudioItem audio; - audio.setId(map.value("aid").toInt()); - audio.setOwnerId(map.value("owner_id").toInt()); - audio.setArtist(fromHtmlEntities(map.value("artist").toString())); - audio.setTitle(fromHtmlEntities(map.value("title").toString())); - audio.setDuration(map.value("duration").toReal()); - audio.setAlbumId(map.value("album").toInt()); - audio.setLyricsId(map.value("lyrics_id").toInt()); - audio.setUrl(map.value("url").toUrl()); - items.append(audio); - } - return QVariant::fromValue(items); - } - - static QVariant handleAudioAlbum(const QVariant &response) { - AudioAlbumItemList items; - auto list = response.toList(); - - if (list.count() && list.first().canConvert()) - list.removeFirst(); - - foreach (auto item, list) { - auto map = item.toMap(); - AudioAlbumItem audio; - audio.setId(map.value("album_id").toInt()); - audio.setOwnerId(map.value("owner_id").toInt()); - audio.setTitle(fromHtmlEntities(map.value("title").toString())); - items.append(audio); - } - return QVariant::fromValue(items); - } -}; - -AudioProvider::AudioProvider(Client *client) : - d_ptr(new AudioProviderPrivate(this, client)) -{ - -} - -AudioProvider::~AudioProvider() -{ - -} - -/*! - * \brief AudioProvider::get \link http://vk.com/developers.php?oid=-1&p=audio.get - * \param uid - * \param count - * \param offset - * \return reply - */ -AudioItemListReply *AudioProvider::getContactAudio(int uid, int count, int offset, int album_id) -{ - Q_D(AudioProvider); - QVariantMap args; - if (uid) - args.insert(uid > 0 ? "uid" : "gid", qAbs(uid)); - if (album_id > 0) - args.insert("album_id", album_id); - args.insert("count", count); - args.insert("offset", offset); - - auto reply = d->client->request("audio.get", args, AudioProviderPrivate::handleAudio); - return reply; -} - -/*! - * \brief AudioProvider::searchAudio \link http://vk.com/developers.php?oid=-1&p=audio.search - * - * \param query - * \param autocomplete - * \param lyrics - * \param count - * \param offset - * \return reply - **/ -AudioItemListReply *AudioProvider::searchAudio(const QString& query, int count, int offset, bool autoComplete, Vreen::AudioProvider::SortOrder sort, bool withLyrics) -{ - Q_D(AudioProvider); - QVariantMap args; - args.insert("q", query); - args.insert("auto_complete", autoComplete); - args.insert("sort", static_cast(sort)); - args.insert("lyrics", withLyrics); - args.insert("count", count); - args.insert("offset", offset); - - auto reply = d->client->request("audio.search", args, AudioProviderPrivate::handleAudio); - return reply; -} - -AudioAlbumItemListReply *AudioProvider::getAlbums(int ownerId, int count, int offset) -{ - Q_D(AudioProvider); - QVariantMap args; - args.insert("owner_id", ownerId); - args.insert("count", count); - args.insert("offset", offset); - - auto reply = d->client->request("audio.getAlbums", args, AudioProviderPrivate::handleAudioAlbum); - return reply; -} - -AudioItemListReply *AudioProvider::getRecommendationsForUser(int uid, int count, int offset) -{ - Q_D(AudioProvider); - QVariantMap args; - if (uid < 0) { - qDebug("Vreen::AudioProvider::getRecomendationForUser may not work with groups (uid < 0)"); - - } - args.insert("uid",uid); - args.insert("count", count); - args.insert("offset", offset); - - auto reply = d->client->request("audio.getRecommendations", args, AudioProviderPrivate::handleAudio); - return reply; -} - -IntReply *AudioProvider::getCount(int oid) -{ - Q_D(AudioProvider); - - oid = oid?oid:d->client->id(); - - QVariantMap args; - args.insert("oid", oid); - - auto reply = d->client->request("audio.getCount", args, ReplyPrivate::handleInt); - return reply; -} - -IntReply *AudioProvider::addToLibrary(int aid, int oid, int gid) -{ - Q_D(AudioProvider); - - QVariantMap args; - args.insert("aid", aid); - args.insert("oid", oid); - - if (gid) { - args.insert("gid",gid); - } - - auto reply = d->client->request("audio.add", args, ReplyPrivate::handleInt); - return reply; -} - -IntReply *AudioProvider::removeFromLibrary(int aid, int oid) -{ - Q_D(AudioProvider); - - QVariantMap args; - args.insert("aid", aid); - args.insert("oid", oid); - - auto reply = d->client->request("audio.delete", args, ReplyPrivate::handleInt); - return reply; -} - -IdListReply *AudioProvider::setBroadcast(int aid, int oid, const IdList &targetIds) -{ - Q_D(AudioProvider); - - QVariantMap args; - args.insert("audio", QString("%1_%2").arg(oid).arg(aid)); - args.insert("target_ids", join(targetIds)); - - auto reply = d->client->request("audio.setBroadcast", args, ReplyPrivate::handleIdList); - return reply; -} - -IdListReply *AudioProvider::resetBroadcast(const IdList &targetIds) -{ - Q_D(AudioProvider); - - QVariantMap args; - args.insert("audio",""); - args.insert("target_ids", join(targetIds)); - auto reply = d->client->request("audio.setBroadcast", args, ReplyPrivate::handleIdList); - return reply; -} - -AudioItemListReply *AudioProvider::getAudiosByIds(const QString &ids) -{ - Q_D(AudioProvider); - - QVariantMap args; - args.insert("audios", ids); - - auto reply = d->client->request("audio.getById", args, AudioProviderPrivate::handleAudio); - return reply; -} - -class AudioModel; -class AudioModelPrivate -{ - Q_DECLARE_PUBLIC(AudioModel) -public: - AudioModelPrivate(AudioModel *q) : q_ptr(q) {} - AudioModel *q_ptr; - AudioItemList itemList; - - IdComparator audioItemComparator; -}; - -AudioModel::AudioModel(QObject *parent) : AbstractListModel(parent), - d_ptr(new AudioModelPrivate(this)) -{ - auto roles = roleNames(); - roles[IdRole] = "aid"; - roles[TitleRole] = "title"; - roles[ArtistRole] = "artist"; - roles[UrlRole] = "url"; - roles[DurationRole] = "duration"; - roles[AlbumIdRole] = "albumId"; - roles[LyricsIdRole] = "lyricsId"; - roles[OwnerIdRole] = "ownerId"; - setRoleNames(roles); -} - -AudioModel::~AudioModel() -{ -} - -int AudioModel::count() const -{ - return d_func()->itemList.count(); -} - -void AudioModel::insertAudio(int index, const AudioItem &item) -{ - beginInsertRows(QModelIndex(), index, index); - d_func()->itemList.insert(index, item); - endInsertRows(); -} - -void AudioModel::replaceAudio(int i, const AudioItem &item) -{ - auto index = createIndex(i, 0); - d_func()->itemList[i] = item; - emit dataChanged(index, index); -} - -void AudioModel::setAudio(const AudioItemList &items) -{ - Q_D(AudioModel); - clear(); - beginInsertRows(QModelIndex(), 0, items.count()); - d->itemList = items; - qSort(d->itemList.begin(), d->itemList.end(), d->audioItemComparator); - endInsertRows(); -} - -void AudioModel::sort(int, Qt::SortOrder order) -{ - Q_D(AudioModel); - d->audioItemComparator.sortOrder = order; - setAudio(d->itemList); -} - -void AudioModel::removeAudio(int aid) -{ - Q_D(AudioModel); - int index = findAudio(aid); - if (index == -1) - return; - beginRemoveRows(QModelIndex(), index, index); - d->itemList.removeAt(index); - endRemoveRows(); -} - -void AudioModel::addAudio(const AudioItem &item) -{ - Q_D(AudioModel); - if (findAudio(item.id()) != -1) - return; - - int index = d->itemList.count(); - beginInsertRows(QModelIndex(), index, index); - d->itemList.append(item); - endInsertRows(); - - //int index = 0; - //if (d->sortOrder == Qt::AscendingOrder) - // index = d->itemList.count(); - //insertAudio(index, item); -} - -void AudioModel::clear() -{ - Q_D(AudioModel); - beginRemoveRows(QModelIndex(), 0, d->itemList.count()); - d->itemList.clear(); - endRemoveRows(); -} - -void AudioModel::truncate(int count) -{ - Q_D(AudioModel); - if (count > 0 && count > d->itemList.count()) { - qWarning("Unable to truncate"); - return; - } - beginRemoveRows(QModelIndex(), 0, count); - d->itemList.erase(d->itemList.begin() + count, d->itemList.end()); - endRemoveRows(); -} - -int AudioModel::rowCount(const QModelIndex &) const -{ - return count(); -} - -void AudioModel::setSortOrder(Qt::SortOrder order) -{ - Q_D(AudioModel); - if (order != d->audioItemComparator.sortOrder) { - d->audioItemComparator.sortOrder = order; - emit sortOrderChanged(order); - sort(0, order); - } -} - -Qt::SortOrder AudioModel::sortOrder() const -{ - Q_D(const AudioModel); - return d->audioItemComparator.sortOrder; -} - -QVariant AudioModel::data(const QModelIndex &index, int role) const -{ - Q_D(const AudioModel); - int row = index.row(); - auto item = d->itemList.at(row); - switch (role) { - case IdRole: - return item.id(); - break; - case TitleRole: - return item.title(); - case ArtistRole: - return item.artist(); - case UrlRole: - return item.url(); - case DurationRole: - return item.duration(); - case AlbumIdRole: - return item.albumId(); - case LyricsIdRole: - return item.lyricsId(); - case OwnerIdRole: - return item.ownerId(); - default: - break; - } - return QVariant::Invalid; -} - -int AudioModel::findAudio(int id) const -{ - Q_D(const AudioModel); - //auto it = qBinaryFind(d->itemList.begin(), d->itemList.end(), id, d->audioItemComparator); - //auto index = it - d->itemList.begin(); - //return index; - - for (int i = 0; i != d->itemList.count(); i++) - if (d->itemList.at(i).id() == id) - return id; - return -1; -} - -} // namespace Vreen - -#include "moc_audio.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/audio.h b/3rdparty/vreen/vreen/src/api/audio.h deleted file mode 100644 index 37f42c520..000000000 --- a/3rdparty/vreen/vreen/src/api/audio.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_AUDIO_H -#define VK_AUDIO_H - -#include -#include "vk_global.h" -#include "audioitem.h" -#include "abstractlistmodel.h" -#include "reply.h" - -namespace Vreen { - -class Client; -typedef ReplyBase AudioItemListReply; -typedef ReplyBase AudioAlbumItemListReply; -typedef ReplyBase> IdListReply; - -class AudioProviderPrivate; -class VK_SHARED_EXPORT AudioProvider : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(AudioProvider) - Q_ENUMS(SortOrder) -public: - - enum SortOrder { - SortByDate = 0, - SortByDuration, - SortByPopularity - }; - - AudioProvider(Client *client); - virtual ~AudioProvider(); - AudioItemListReply *getContactAudio(int uid = 0, int count = 50, int offset = 0, int album_id = -1); - AudioItemListReply *getAudiosByIds(const QString& ids); - AudioItemListReply *getRecommendationsForUser(int uid = 0, int count = 50, int offset = 0); - AudioItemListReply *searchAudio(const QString& query, int count = 50, int offset = 0, bool autoComplete = true, Vreen::AudioProvider::SortOrder sort = SortByPopularity, bool withLyrics = false); - AudioAlbumItemListReply *getAlbums(int ownerId, int count = 50, int offset = 0); - IntReply *getCount(int oid = 0); - IntReply *addToLibrary(int aid, int oid, int gid = 0); - IntReply *removeFromLibrary(int aid, int oid); - IdListReply *setBroadcast(int aid, int oid, const IdList& targetIds); - IdListReply *resetBroadcast(const IdList& targetIds); -protected: - QScopedPointer d_ptr; -}; - -class AudioModelPrivate; -class VK_SHARED_EXPORT AudioModel : public AbstractListModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(AudioModel) - - Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged) -public: - - enum Roles { - IdRole = Qt::UserRole + 1, - TitleRole, - ArtistRole, - UrlRole, - DurationRole, - AlbumIdRole, - LyricsIdRole, - OwnerIdRole - }; - - AudioModel(QObject *parent); - virtual ~AudioModel(); - - int count() const; - int findAudio(int id) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual int rowCount(const QModelIndex &parent) const; - void setSortOrder(Qt::SortOrder order); - Qt::SortOrder sortOrder() const; -public slots: - void clear(); - void truncate(int count); - void addAudio(const Vreen::AudioItem &item); - void removeAudio(int aid); -signals: - void sortOrderChanged(Qt::SortOrder); -protected: - void insertAudio(int index, const AudioItem &item); - void replaceAudio(int index, const AudioItem &item); - void setAudio(const AudioItemList &items); - virtual void sort(int column, Qt::SortOrder order); -private: - QScopedPointer d_ptr; -}; - -} // namespace Vreen - -#endif // VK_AUDIO_H - diff --git a/3rdparty/vreen/vreen/src/api/audioitem.cpp b/3rdparty/vreen/vreen/src/api/audioitem.cpp deleted file mode 100644 index aa07fb3e9..000000000 --- a/3rdparty/vreen/vreen/src/api/audioitem.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "audioitem.h" -#include -#include -#include "client.h" - -namespace Vreen { - -template<> -AudioItem Attachment::to(const Attachment &data) -{ - AudioItem item; - item.setId(data.property("aid").toInt()); - item.setOwnerId(data.property("owner_id").toInt()); - item.setArtist(data.property("performer").toString()); - item.setTitle(data.property("title").toString()); - item.setUrl(data.property("url").toUrl()); - item.setDuration(data.property("duration").toDouble()); - return item; -} - -class AudioItemData : public QSharedData { -public: - AudioItemData() : - id(0), ownerId(0), - duration(0), - lyricsId(0), - albumId(0) - {} - AudioItemData(AudioItemData &o) : QSharedData(), - id(o.id), ownerId(o.ownerId), - artist(o.artist), - title(o.title), - duration(o.duration), - url(o.url), - lyricsId(o.lyricsId), - albumId(o.albumId) - {} - int id; - int ownerId; - QString artist; - QString title; - qreal duration; - QUrl url; - int lyricsId; - int albumId; -}; - -AudioItem::AudioItem() : data(new AudioItemData) -{ -} - -AudioItem::AudioItem(const AudioItem &rhs) : data(rhs.data) -{ -} - -AudioItem &AudioItem::operator=(const AudioItem &rhs) -{ - if (this != &rhs) - data.operator=(rhs.data); - return *this; -} - -AudioItem::~AudioItem() -{ -} - -int AudioItem::id() const -{ - return data->id; -} - -void AudioItem::setId(int id) -{ - data->id = id; -} - -int AudioItem::ownerId() const -{ - return data->ownerId; -} - -void AudioItem::setOwnerId(int ownerId) -{ - data->ownerId = ownerId; -} - -QString AudioItem::artist() const -{ - return data->artist; -} - -void AudioItem::setArtist(const QString &artist) -{ - data->artist = artist; -} - -QString AudioItem::title() const -{ - return data->title; -} - -void AudioItem::setTitle(const QString &title) -{ - data->title = title; -} - -qreal AudioItem::duration() const -{ - return data->duration; -} - -void AudioItem::setDuration(qreal duration) -{ - data->duration = duration; -} - -QUrl AudioItem::url() const -{ - return data->url; -} - -void AudioItem::setUrl(const QUrl &url) -{ - data->url = url; -} - -int AudioItem::lyricsId() const -{ - return data->lyricsId; -} - -void AudioItem::setLyricsId(int lyricsId) -{ - data->lyricsId = lyricsId; -} - -int AudioItem::albumId() const -{ - return data->albumId; -} - -void AudioItem::setAlbumId(int albumId) -{ - data->albumId = albumId; -} - -class AudioAlbumItemData : public QSharedData { -public: - AudioAlbumItemData() : - id(0), - ownerId(0) - {} - AudioAlbumItemData(AudioAlbumItemData &o) : QSharedData(), - id(o.id), - ownerId(o.ownerId), - title(o.title) - {} - int id; - int ownerId; - QString title; -}; - -AudioAlbumItem::AudioAlbumItem() : data(new AudioAlbumItemData) -{ -} - -AudioAlbumItem::AudioAlbumItem(const AudioAlbumItem &rhs) : data(rhs.data) -{ -} - -AudioAlbumItem &AudioAlbumItem::operator=(const AudioAlbumItem &rhs) -{ - if (this != &rhs) - data.operator=(rhs.data); - return *this; -} - -AudioAlbumItem::~AudioAlbumItem() -{ - -} - -int AudioAlbumItem::ownerId() const -{ - return data->ownerId; -} - -void AudioAlbumItem::setOwnerId(int ownerId) -{ - data->ownerId = ownerId; -} - -int AudioAlbumItem::id() const -{ - return data->id; -} - -void AudioAlbumItem::setId(int id) -{ - data->id = id; -} - -QString AudioAlbumItem::title() const -{ - return data->title; -} - -void AudioAlbumItem::setTitle(const QString &title) -{ - data->title = title; -} - -} // namespace Vreen - diff --git a/3rdparty/vreen/vreen/src/api/audioitem.h b/3rdparty/vreen/vreen/src/api/audioitem.h deleted file mode 100644 index 55b4a647c..000000000 --- a/3rdparty/vreen/vreen/src/api/audioitem.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_AUDIOITEM_H -#define VK_AUDIOITEM_H - -#include -#include "attachment.h" -#include - -class QUrl; - -namespace Vreen { - -class Client; -class AudioItemData; - -class VK_SHARED_EXPORT AudioItem -{ -public: - AudioItem(); - AudioItem(const AudioItem &); - AudioItem &operator=(const AudioItem &); - ~AudioItem(); - - int id() const; - void setId(int aid); - int ownerId() const; - void setOwnerId(int ownerId); - QString artist() const; - void setArtist(const QString &artist); - QString title() const; - void setTitle(const QString &title); - qreal duration() const; - void setDuration(qreal duration); - QUrl url() const; - void setUrl(const QUrl &url); - int lyricsId() const; - void setLyricsId(int lyricsId); - int albumId() const; - void setAlbumId(int albumId); -private: - QSharedDataPointer data; -}; -typedef QList AudioItemList; - -class AudioAlbumItemData; -class VK_SHARED_EXPORT AudioAlbumItem -{ -public: - AudioAlbumItem(); - AudioAlbumItem(const AudioAlbumItem &other); - AudioAlbumItem &operator=(const AudioAlbumItem &other); - ~AudioAlbumItem(); - - int id() const; - void setId(int id); - int ownerId() const; - void setOwnerId(int ownerId); - QString title() const; - void setTitle(const QString &title); -private: - QSharedDataPointer data; -}; -typedef QList AudioAlbumItemList; - -template<> -AudioItem Attachment::to(const Attachment &data); - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::AudioItem) -Q_DECLARE_METATYPE(Vreen::AudioItemList) -Q_DECLARE_METATYPE(Vreen::AudioAlbumItem) -Q_DECLARE_METATYPE(Vreen::AudioAlbumItemList) - -#endif // VK_AUDIOITEM_H - diff --git a/3rdparty/vreen/vreen/src/api/chatsession.cpp b/3rdparty/vreen/vreen/src/api/chatsession.cpp deleted file mode 100644 index 4d8ef7383..000000000 --- a/3rdparty/vreen/vreen/src/api/chatsession.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "chatsession.h" -#include "messagesession_p.h" -#include "contact.h" -#include "client_p.h" -#include "longpoll.h" -#include - -namespace Vreen { - -class ChatSessionPrivate : public MessageSessionPrivate -{ - Q_DECLARE_PUBLIC(ChatSession) -public: - ChatSessionPrivate(ChatSession *q, Contact *contact) : - MessageSessionPrivate(q, contact->client(), contact->id()), - contact(contact), isActive(false) {} - - Contact *contact; - bool isActive; - - void _q_message_read_state_updated(const QVariant &); - void _q_message_added(const Message &message); -}; - - -/*! - * \brief The ChatSession class - * Api reference: \link http://vk.com/developers.php?oid=-1&p=Расширенные_методы_API - */ - -/*! - * \brief ChatSession::ChatSession - * \param contact - */ -ChatSession::ChatSession(Contact *contact) : - MessageSession(new ChatSessionPrivate(this, contact)) -{ - Q_D(ChatSession); - auto longPoll = d->contact->client()->longPoll(); - connect(longPoll, SIGNAL(messageAdded(Vreen::Message)), - this, SLOT(_q_message_added(Vreen::Message))); - connect(longPoll, SIGNAL(messageDeleted(int)), - this, SIGNAL(messageDeleted(int))); - connect(d->contact, SIGNAL(nameChanged(QString)), SLOT(setTitle(QString))); - setTitle(d->contact->name()); -} - -ChatSession::~ChatSession() -{ - -} - -Contact *ChatSession::contact() const -{ - return d_func()->contact; -} - -bool ChatSession::isActive() const -{ - return d_func()->isActive; -} - -void ChatSession::setActive(bool set) -{ - Q_D(ChatSession); - d->isActive = set; -} - -ReplyBase *ChatSession::doGetHistory(int count, int offset) -{ - Q_D(ChatSession); - QVariantMap args; - args.insert("count", count); - args.insert("offset", offset); - args.insert("uid", d->contact->id()); - - auto reply = d->client->request>("messages.getHistory", - args, - MessageListHandler(d->client->id())); - return reply; -} - -SendMessageReply *ChatSession::doSendMessage(const Message &message) -{ - Q_D(ChatSession); - return d->contact->client()->sendMessage(message); -} - -void ChatSessionPrivate::_q_message_read_state_updated(const QVariant &response) -{ - Q_Q(ChatSession); - auto reply = qobject_cast(q->sender()); - if (response.toInt() == 1) { - auto set = reply->property("set").toBool(); - auto ids = reply->property("mids").value(); - foreach(int id, ids) - emit q->messageReadStateChanged(id, set); - } -} - -void ChatSessionPrivate::_q_message_added(const Message &message) -{ - //auto sender = client->contact(); - //if (sender == contact || !sender) //HACK some workaround - int id = message.isIncoming() ? message.fromId() : message.toId(); - if (!message.chatId() && id == contact->id()) { - emit q_func()->messageAdded(message); - } -} - -} // namespace Vreen - -#include "moc_chatsession.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/chatsession.h b/3rdparty/vreen/vreen/src/api/chatsession.h deleted file mode 100644 index cd45e02f6..000000000 --- a/3rdparty/vreen/vreen/src/api/chatsession.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_CHATSESSION_H -#define VK_CHATSESSION_H - -#include "message.h" -#include "messagesession.h" - -namespace Vreen { - -class Reply; -class ChatSessionPrivate; -class VK_SHARED_EXPORT ChatSession : public MessageSession -{ - Q_OBJECT - Q_DECLARE_PRIVATE(ChatSession) - - Q_PROPERTY(Contact *contact READ contact CONSTANT) -public: - ChatSession(Contact *contact); - virtual ~ChatSession(); - - Contact *contact() const; - bool isActive() const; - void setActive(bool set); -protected: - virtual ReplyBase *doGetHistory(int count = 16, int offset = 0); - virtual SendMessageReply *doSendMessage(const Vreen::Message &message); -private: - - Q_PRIVATE_SLOT(d_func(), void _q_message_added(const Vreen::Message &)) -}; - -} // namespace Vreen - -#endif // VK_CHATSESSION_H - diff --git a/3rdparty/vreen/vreen/src/api/client.cpp b/3rdparty/vreen/vreen/src/api/client.cpp deleted file mode 100644 index 770412dd9..000000000 --- a/3rdparty/vreen/vreen/src/api/client.cpp +++ /dev/null @@ -1,440 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "client_p.h" -#include "message.h" -#include "contact.h" -#include "groupmanager.h" -#include "reply_p.h" -#include "utils_p.h" -#include -#include - -namespace Vreen { - -Client::Client(QObject *parent) : - QObject(parent), - d_ptr(new ClientPrivate(this)) -{ -} - -Client::Client(const QString &login, const QString &password, QObject *parent) : - QObject(parent), - d_ptr(new ClientPrivate(this)) -{ - Q_D(Client); - d->login = login; - d->password = password; -} - -Client::~Client() -{ -} - -QString Client::password() const -{ - return d_func()->password; -} - -void Client::setPassword(const QString &password) -{ - d_func()->password = password; - emit passwordChanged(password); -} - -QString Client::login() const -{ - return d_func()->login; -} - -void Client::setLogin(const QString &login) -{ - d_func()->login = login; - emit loginChanged(login); -} - -Client::State Client::connectionState() const -{ - Q_D(const Client); - if (d->connection.isNull()) - return StateInvalid; - return d->connection.data()->connectionState(); -} - -bool Client::isOnline() const -{ - if (auto c = connection()) - return c->connectionState() == Client::StateOnline; - else - return false; -} - -QString Client::activity() const -{ - return d_func()->activity; -} - -Connection *Client::connection() const -{ - return d_func()->connection.data(); -} - -Connection *Client::connection() -{ - Q_D(Client); - if (d->connection.isNull()) - qWarning("Unknown method of connection. Use oauth webkit connection"); - // setConnection(new DirectConnection(this)); - return d_func()->connection.data(); -} - -void Client::setConnection(Connection *connection) -{ - Q_D(Client); - if (d->connection != connection) { - if (d->connection) { - d->connection.data()->deleteLater(); - } - - d->connection = connection; - connect(connection, SIGNAL(connectionStateChanged(Vreen::Client::State)), - this, SLOT(_q_connection_state_changed(Vreen::Client::State))); - connect(connection, SIGNAL(error(Vreen::Client::Error)), this, SIGNAL(error(Vreen::Client::Error))); - - emit connectionChanged(d->connection); - } -} - -Roster *Client::roster() const -{ - return d_func()->roster.data(); -} - -Roster *Client::roster() -{ - Q_D(Client); - if (d->roster.isNull()) { - d->roster = new Roster(this, d->connection.isNull() ? 0 : d->connection->uid()); - } - return d->roster.data(); -} - -LongPoll *Client::longPoll() const -{ - return d_func()->longPoll.data(); -} - -LongPoll *Client::longPoll() -{ - Q_D(Client); - if (d->longPoll.isNull()) { - d->longPoll = new LongPoll(this); - - emit longPollChanged(d->longPoll.data()); - } - return d->longPoll.data(); -} - -GroupManager *Client::groupManager() const -{ - return d_func()->groupManager.data(); -} - -GroupManager *Client::groupManager() -{ - Q_D(Client); - if (!d->groupManager) - d->groupManager = new GroupManager(this); - return d->groupManager.data(); -} - -Reply *Client::request(const QUrl &url) -{ - QNetworkRequest request(url); - auto networkReply = connection()->get(request); - auto reply = new Reply(networkReply); - d_func()->processReply(reply); - return reply; -} - -Reply *Client::request(const QString &method, const QVariantMap &args) -{ - auto reply = new Reply(connection()->get(method, args)); - d_func()->processReply(reply); - return reply; -} - -Buddy *Client::me() const -{ - if (auto r = roster()) - return r->owner(); - return 0; -} - -Buddy *Client::me() -{ - return roster()->owner(); -} - -Contact *Client::contact(int id) const -{ - Contact *contact = 0; - if (id > 0) { - if (roster()) - contact = roster()->buddy(id); - if (!contact && groupManager()) - contact = groupManager()->group(id); - } else if (id < 0 && groupManager()) - contact = groupManager()->group(id); - return contact; -} - -int Client::id() const -{ - return me() ? me()->id() : 0; -} - -SendMessageReply *Client::sendMessage(const Message &message) -{ - //TODO add delayed send - if (!isOnline()) - return 0; - - //checks - Q_ASSERT(message.toId()); - - QVariantMap args; - //TODO add chat messages support and contact check - args.insert("uid", message.toId()); - args.insert("message", message.body()); - args.insert("title", message.subject()); - return request("messages.send", args, ReplyPrivate::handleInt); -} - -/*! - * \brief Client::getMessage see \link http://vk.com/developers.php?p=messages.getById - */ -Reply *Client::getMessage(int mid, int previewLength) -{ - QVariantMap args; - args.insert("mid", mid); - args.insert("preview_length", previewLength); - return request("messages.getById", args); -} - -Reply *Client::addLike(int ownerId, int postId, bool retweet, const QString &message) -{ - QVariantMap args; - args.insert("owner_id", ownerId); - args.insert("post_id", postId); - args.insert("repost", (int)retweet); - args.insert("message", message); - return request("wall.addLike", args); -} - -Reply *Client::deleteLike(int ownerId, int postId) -{ - QVariantMap args; - args.insert("owner_id", ownerId); - args.insert("post_id", postId); - auto reply = request("wall.deleteLike", args); - return reply; -} - -void Client::connectToHost() -{ - Q_D(Client); - //TODO add warnings - connection()->connectToHost(d->login, d->password); -} - -void Client::connectToHost(const QString &login, const QString &password) -{ - setLogin(login); - setPassword(password); - connectToHost(); -} - -void Client::disconnectFromHost() -{ - connection()->disconnectFromHost(); -} - - -void Client::setActivity(const QString &activity) -{ - Q_D(Client); - if (d->activity != activity) { - auto reply = setStatus(activity); - connect(reply, SIGNAL(resultReady(const QVariant &)), SLOT(_q_activity_update_finished(const QVariant &))); - } -} - -bool Client::isInvisible() const -{ - return d_func()->isInvisible; -} - -void Client::setInvisible(bool set) -{ - Q_D(Client); - if (d->isInvisible != set) { - d->isInvisible = set; - if (isOnline()) - d->setOnlineUpdaterRunning(!set); - emit invisibleChanged(set); - } -} - -bool Client::trackMessages() const -{ - return d_func()->trackMessages; -} - -void Client::setTrackMessages(bool set) -{ - Q_D(Client); - if( d->trackMessages != set ) { - d->trackMessages = set; - emit trackMessagesChanged(set); - } -} - -Reply *Client::setStatus(const QString &text, int aid) -{ - QVariantMap args; - args.insert("text", text); - if (aid) - args.insert("audio", QString("%1_%2").arg(me()->id()).arg(aid)); - return request("status.set", args); -} - -void Client::processReply(Reply *reply) -{ - d_func()->processReply(reply); -} - -QNetworkReply *Client::requestHelper(const QString &method, const QVariantMap &args) -{ - return connection()->get(method, args); -} - -void ClientPrivate::_q_activity_update_finished(const QVariant &response) -{ - Q_Q(Client); - auto reply = sender_cast(q->sender()); - if (response.toInt() == 1) { - activity = reply->networkReply()->url().queryItemValue("text"); - emit q->activityChanged(activity); - } -} - -void ClientPrivate::_q_update_online() -{ - Q_Q(Client); - q->request("account.setOnline"); -} - -void ClientPrivate::processReply(Reply *reply) -{ - Q_Q(Client); - q->connect(reply, SIGNAL(resultReady(const QVariant &)), q, SLOT(_q_reply_finished(const QVariant &))); - q->connect(reply, SIGNAL(error(int)), q, SLOT(_q_error_received(int))); - emit q->replyCreated(reply); -} - -ReplyBase *ClientPrivate::getMessages(Client *client, const IdList &list, int previewLength) -{ - QVariantMap map; - if (list.count() == 1) - map.insert("mid", list.first()); - else - map.insert("mids", join(list)); - map.insert("preview_length", previewLength); - return client->request>("messages.getById", - map, - MessageListHandler(client->id())); -} - -void ClientPrivate::setOnlineUpdaterRunning(bool set) -{ - if (set) { - onlineUpdater.start(); - _q_update_online(); - } else - onlineUpdater.stop(); -} - -void ClientPrivate::_q_connection_state_changed(Client::State state) -{ - Q_Q(Client); - switch (state) { - case Client::StateOffline: - emit q->onlineStateChanged(false); - setOnlineUpdaterRunning(false); - break; - case Client::StateOnline: - emit q->onlineStateChanged(true); - if (!roster.isNull()) { - roster->setUid(connection->uid()); - emit q->meChanged(roster->owner()); - } - if (!isInvisible) - setOnlineUpdaterRunning(true); - break; - default: - break; - } - emit q->connectionStateChanged(state); -} - -void ClientPrivate::_q_error_received(int code) -{ - Q_Q(Client); - auto reply = sender_cast(q->sender()); - qDebug() << "Error received :" << code << reply->networkReply()->url(); - reply->deleteLater(); - auto error = static_cast(code); - emit q->error(error); - if (error == Client::ErrorAuthorizationFailed) { - connection->disconnectFromHost(); - connection->clear(); - } -} - -void ClientPrivate::_q_reply_finished(const QVariant &) -{ - auto reply = sender_cast(q_func()->sender()); - reply->deleteLater(); -} - -void ClientPrivate::_q_network_manager_error(int) -{ - -} - -} // namespace Vreen - -#include "moc_client.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/client.h b/3rdparty/vreen/vreen/src/api/client.h deleted file mode 100644 index 13244eba2..000000000 --- a/3rdparty/vreen/vreen/src/api/client.h +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_CLIENT_H -#define VK_CLIENT_H - -#include "vk_global.h" -#include "reply.h" -#include -#include -#include - -class QUrl; -namespace Vreen { - -class Message; -class Connection; -class ClientPrivate; -class Roster; -class GroupManager; -class LongPoll; -class Contact; -class Buddy; - -typedef ReplyBase SendMessageReply; - -class VK_SHARED_EXPORT Client : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(Client) - - Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged DESIGNABLE true) - Q_PROPERTY(QString login READ login WRITE setLogin NOTIFY loginChanged DESIGNABLE true) - Q_PROPERTY(bool online READ isOnline NOTIFY onlineStateChanged DESIGNABLE true) - Q_PROPERTY(State connectionState READ connectionState NOTIFY connectionStateChanged DESIGNABLE true) - Q_PROPERTY(Vreen::Roster* roster READ roster NOTIFY rosterChanged DESIGNABLE true) - Q_PROPERTY(Vreen::GroupManager* groupManager READ groupManager NOTIFY groupManagerChanged DESIGNABLE true) - Q_PROPERTY(Vreen::LongPoll* longPoll READ longPoll NOTIFY longPollChanged DESIGNABLE true) - Q_PROPERTY(Vreen::Buddy* me READ me NOTIFY meChanged DESIGNABLE true) - Q_PROPERTY(Vreen::Connection* connection READ connection WRITE setConnection NOTIFY connectionChanged DESIGNABLE true) - Q_PROPERTY(QString activity READ activity WRITE setActivity NOTIFY activityChanged DESIGNABLE true) - Q_PROPERTY(bool invisible READ isInvisible WRITE setInvisible NOTIFY invisibleChanged) - Q_PROPERTY(bool trackMessages READ trackMessages WRITE setTrackMessages NOTIFY trackMessagesChanged) - - Q_ENUMS(State) - Q_ENUMS(Error) -public: - - enum State { - StateOffline, - StateConnecting, - StateOnline, - StateInvalid - }; - enum Error { - ErrorUnknown = 1, - ErrorApplicationDisabled = 2, - ErrorIncorrectSignature = 4, - ErrorAuthorizationFailed = 5, - ErrorToManyRequests = 6, - ErrorPermissionDenied = 7, - ErrorCaptchaNeeded = 14, - ErrorMissingOrInvalidParameter = 100, - ErrorNetworkReply = 4096 - }; - - explicit Client(QObject *parent = 0); - explicit Client(const QString &login, const QString &password, QObject *parent = 0); - virtual ~Client(); - QString password() const; - void setPassword(const QString &password); - QString login() const; - void setLogin(const QString &login); - State connectionState() const; - bool isOnline() const; - QString activity() const; - void setActivity(const QString &activity); - bool isInvisible() const; - void setInvisible(bool set); - bool trackMessages() const; - void setTrackMessages(bool set); - - Connection *connection() const; - Connection *connection(); - void setConnection(Connection *connection); - Roster *roster(); - Roster *roster() const; - LongPoll *longPoll(); - LongPoll *longPoll() const; - GroupManager *groupManager(); - GroupManager *groupManager() const; - - Reply *request(const QUrl &); - Reply *request(const QString &method, const QVariantMap &args = QVariantMap()); - template - ReplyImpl *request(const QString &method, const QVariantMap &args, const Handler &handler); - SendMessageReply *sendMessage(const Message &message); - Reply *getMessage(int mid, int previewLength = 0); - Reply *addLike(int ownerId, int postId, bool retweet = false, const QString &message = QString()); //TODO move method - Reply *deleteLike(int ownerId, int postId); //TODO move method - - Q_INVOKABLE Buddy *me(); - Buddy *me() const; - Q_INVOKABLE Contact *contact(int id) const; - int id() const; -public slots: - void connectToHost(); - void connectToHost(const QString &login, const QString &password); - void disconnectFromHost(); -signals: - void loginChanged(const QString &login); - void passwordChanged(const QString &password); - void connectionChanged(Vreen::Connection *connection); - void connectionStateChanged(Vreen::Client::State state); - void replyCreated(Vreen::Reply*); - void error(Vreen::Client::Error error); - void onlineStateChanged(bool online); - void rosterChanged(Vreen::Roster*); - void groupManagerChanged(Vreen::GroupManager*); - void longPollChanged(Vreen::LongPoll*); - void meChanged(Vreen::Buddy *me); - void activityChanged(const QString &activity); - void invisibleChanged(bool set); - void trackMessagesChanged(bool set); -protected: - Reply *setStatus(const QString &text, int aid = 0); - QScopedPointer d_ptr; -private: - void processReply(Reply *reply); - QNetworkReply *requestHelper(const QString &method, const QVariantMap &args); - - Q_PRIVATE_SLOT(d_func(), void _q_connection_state_changed(Vreen::Client::State)) - Q_PRIVATE_SLOT(d_func(), void _q_error_received(int)) - Q_PRIVATE_SLOT(d_func(), void _q_reply_finished(const QVariant &)) - Q_PRIVATE_SLOT(d_func(), void _q_activity_update_finished(const QVariant &)) - Q_PRIVATE_SLOT(d_func(), void _q_update_online()) - Q_PRIVATE_SLOT(d_func(), void _q_network_manager_error(int)) -}; - -template -ReplyImpl *Client::request(const QString &method, const QVariantMap &args, const Handler &handler) -{ - ReplyImpl *reply = new ReplyImpl(handler, requestHelper(method, args)); - processReply(reply); - return reply; -} - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::Client*) - -#endif // VK_CLIENT_H - diff --git a/3rdparty/vreen/vreen/src/api/client_p.h b/3rdparty/vreen/vreen/src/api/client_p.h deleted file mode 100644 index edf0793a3..000000000 --- a/3rdparty/vreen/vreen/src/api/client_p.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 * 60); -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef CLIENT_P_H -#define CLIENT_P_H - -#include "client.h" -#include "reply_p.h" -#include "connection.h" -#include "roster.h" -#include "reply.h" -#include "message.h" -#include "longpoll.h" -#include "utils.h" -#include -#include -#include - -namespace Vreen { - -class ClientPrivate -{ - Q_DECLARE_PUBLIC(Client) -public: - ClientPrivate(Client *q) : q_ptr(q), isInvisible(false), trackMessages(true) - { - onlineUpdater.setInterval(15000 * 60); - onlineUpdater.setSingleShot(false); - q->connect(&onlineUpdater, SIGNAL(timeout()), q, SLOT(_q_update_online())); - } - Client *q_ptr; - QString login; - QString password; - QPointer connection; - QPointer roster; - QPointer longPoll; - QPointer groupManager; - QString activity; - bool isInvisible; - bool trackMessages; - QTimer onlineUpdater; - - void setOnlineUpdaterRunning(bool set); - - void _q_connection_state_changed(Vreen::Client::State state); - void _q_error_received(int error); - void _q_reply_finished(const QVariant &); - void _q_network_manager_error(int); - void _q_activity_update_finished(const QVariant &); - void _q_update_online(); - - void processReply(Reply *reply); - - //some orphaned methods - static ReplyBase *getMessages(Client *client, const IdList &list, int previewLength = 0); -}; - -} //namespace Vreen - -#endif // CLIENT_P_H - diff --git a/3rdparty/vreen/vreen/src/api/commentssession.cpp b/3rdparty/vreen/vreen/src/api/commentssession.cpp deleted file mode 100644 index af9342e1b..000000000 --- a/3rdparty/vreen/vreen/src/api/commentssession.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "commentssession.h" -#include "contact.h" -#include "client.h" -#include "reply.h" - -namespace Vreen { - -class CommentSession; -class CommentSessionPrivate -{ - Q_DECLARE_PUBLIC(CommentSession) -public: - CommentSessionPrivate(CommentSession *q, Contact *contact) : - q_ptr(q), contact(contact), postId(0), - sort(Qt::AscendingOrder), - needLikes(true), - previewLenght(0) - - {} - CommentSession *q_ptr; - Contact *contact; - int postId; - Qt::SortOrder sort; - bool needLikes; - int previewLenght; - - void _q_comments_received(const QVariant &response) - { - auto list = response.toList(); - if (!list.isEmpty()) { - list.takeFirst(); - foreach (auto item, list) - emit q_func()->commentAdded(item.toMap()); - } - } -}; - - -/*! - * \brief CommentsSession::CommentsSession - * \param client - */ -CommentSession::CommentSession(Contact *contact) : - QObject(contact), - d_ptr(new CommentSessionPrivate(this, contact)) -{ -} - -void CommentSession::setPostId(int postId) -{ - Q_D(CommentSession); - d->postId = postId; -} - -int CommentSession::postId() const -{ - return d_func()->postId; -} - -CommentSession::~CommentSession() -{ -} - -Reply *CommentSession::getComments(int offset, int count) -{ - Q_D(CommentSession); - QVariantMap args; - args.insert("owner_id", (d->contact->type() == Contact::GroupType ? -1 : 1) * d->contact->id()); - args.insert("post_id", d->postId); - args.insert("offset", offset); - args.insert("count", count); - args.insert("need_likes", d->needLikes); - args.insert("preview_lenght", d->previewLenght); - args.insert("sort", d->sort == Qt::AscendingOrder ? "asc" : "desc"); - auto reply = d->contact->client()->request("wall.getComments", args); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_comments_received(QVariant))); - return reply; -} - -} // namespace Vreen - -#include "moc_commentssession.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/commentssession.h b/3rdparty/vreen/vreen/src/api/commentssession.h deleted file mode 100644 index e97c70772..000000000 --- a/3rdparty/vreen/vreen/src/api/commentssession.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_COMMENTSSESSION_H -#define VK_COMMENTSSESSION_H - -#include -#include -#include "vk_global.h" - -namespace Vreen { - -class Reply; -class Contact; -class CommentSessionPrivate; - -class VK_SHARED_EXPORT CommentSession : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(CommentSession) -public: - CommentSession(Vreen::Contact *contact); - virtual ~CommentSession(); - void setPostId(int id); - int postId() const; -public slots: - Reply *getComments(int offset = 0, int count = 100); -signals: - void commentAdded(const QVariantMap &item); - void commentDeleted(int commentId); -private: - QScopedPointer d_ptr; - - Q_PRIVATE_SLOT(d_func(), void _q_comments_received(QVariant)) -}; - -typedef QList CommentList; - -} // namespace Vreen - -#endif // VK_COMMENTSSESSION_H - diff --git a/3rdparty/vreen/vreen/src/api/connection.cpp b/3rdparty/vreen/vreen/src/api/connection.cpp deleted file mode 100644 index 7bdba931d..000000000 --- a/3rdparty/vreen/vreen/src/api/connection.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "connection_p.h" - -namespace Vreen { - -Connection::Connection(QObject *parent) : - QNetworkAccessManager(parent), - d_ptr(new ConnectionPrivate(this)) -{ -} - -Connection::Connection(ConnectionPrivate *data, QObject *parent) : - QNetworkAccessManager(parent), - d_ptr(data) -{ -} - -Connection::~Connection() -{ -} - -QNetworkReply *Connection::get(QNetworkRequest request) -{ - decorateRequest(request); - return QNetworkAccessManager::get(request); -} - -QNetworkReply *Connection::get(const QString &method, const QVariantMap &args) -{ - return QNetworkAccessManager::get(makeRequest(method, args)); -} - -QNetworkReply *Connection::put(const QString &method, QIODevice *data, const QVariantMap &args) -{ - return QNetworkAccessManager::put(makeRequest(method, args), data); -} - -QNetworkReply *Connection::put(const QString &method, const QByteArray &data, const QVariantMap &args) -{ - return QNetworkAccessManager::put(makeRequest(method, args), data); -} - -/*! - * \brief Connection::clear auth data. Default implementation doesn't nothing. - */ -void Connection::clear() -{ -} - -void Connection::setConnectionOption(Connection::ConnectionOption option, const QVariant &value) -{ - Q_D(Connection); - d->options[option] = value; -} - -QVariant Connection::connectionOption(Connection::ConnectionOption option) const -{ - return d_func()->options[option]; -} - -void Connection::decorateRequest(QNetworkRequest &) -{ -} - -} // namespace Vreen - diff --git a/3rdparty/vreen/vreen/src/api/connection.h b/3rdparty/vreen/vreen/src/api/connection.h deleted file mode 100644 index 7548fc072..000000000 --- a/3rdparty/vreen/vreen/src/api/connection.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_CONNECTION_H -#define VK_CONNECTION_H - -#include -#include -#include -#include "client.h" - -namespace Vreen { - -class Reply; -class ConnectionPrivate; - -class VK_SHARED_EXPORT Connection : public QNetworkAccessManager -{ - Q_OBJECT - Q_DECLARE_PRIVATE(Connection) - Q_ENUMS(ConnectionOption) -public: - Connection(QObject *parent = 0); - Connection(ConnectionPrivate *data, QObject *parent = 0); - ~Connection(); - - enum ConnectionOption { - ShowAuthDialog, - KeepAuthData - }; - - virtual void connectToHost(const QString &login, const QString &password) = 0; - virtual void disconnectFromHost() = 0; - - QNetworkReply *get(QNetworkRequest request); - QNetworkReply *get(const QString &method, const QVariantMap &args = QVariantMap()); - QNetworkReply *put(const QString &method, QIODevice *data, const QVariantMap &args = QVariantMap()); - QNetworkReply *put(const QString &method, const QByteArray &data, const QVariantMap &args = QVariantMap()); - - virtual Client::State connectionState() const = 0; - virtual int uid() const = 0; - virtual void clear(); - - Q_INVOKABLE void setConnectionOption(ConnectionOption option, const QVariant &value); - Q_INVOKABLE QVariant connectionOption(ConnectionOption option) const; -signals: - void connectionStateChanged(Vreen::Client::State connectionState); - void error(Vreen::Client::Error); -protected: - virtual QNetworkRequest makeRequest(const QString &method, const QVariantMap &args = QVariantMap()) = 0; - virtual void decorateRequest(QNetworkRequest &); - QScopedPointer d_ptr; -}; - -} //namespace Vreen - -Q_DECLARE_METATYPE(Vreen::Connection*) - -#endif // VK_CONNECTION_H - diff --git a/3rdparty/vreen/vreen/src/api/connection_p.h b/3rdparty/vreen/vreen/src/api/connection_p.h deleted file mode 100644 index ff79c28d9..000000000 --- a/3rdparty/vreen/vreen/src/api/connection_p.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef CONNECTION_P_H -#define CONNECTION_P_H -#include "connection.h" - -namespace Vreen { - -class Connection; -class VK_SHARED_EXPORT ConnectionPrivate -{ - Q_DECLARE_PUBLIC(Connection) -public: - ConnectionPrivate(Connection *q) : q_ptr(q) {} - Connection *q_ptr; - QMap options; -}; - -} - - -#endif // CONNECTION_P_H diff --git a/3rdparty/vreen/vreen/src/api/contact.cpp b/3rdparty/vreen/vreen/src/api/contact.cpp deleted file mode 100644 index ecb1f358b..000000000 --- a/3rdparty/vreen/vreen/src/api/contact.cpp +++ /dev/null @@ -1,317 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include -#include "contact_p.h" -#include "message.h" -#include "roster_p.h" -#include "groupmanager_p.h" - -namespace Vreen { - -Contact::Contact(int id, Client *client) : - QObject(client), - d_ptr(new ContactPrivate(this, id, client)) -{ -} - -Contact::Contact(ContactPrivate *data) : - QObject(data->client), - d_ptr(data) -{ -} - -Contact::~Contact() -{ -} - -Contact::Type Contact::type() -{ - return d_func()->type; -} - -int Contact::id() const -{ - return d_func()->id; -} - -Client *Contact::client() const -{ - return d_func()->client; -} - -QString Contact::photoSource(Contact::PhotoSize size) const -{ - Q_D(const Contact); - return d->sources.value(size); -} - -void Contact::setPhotoSource(const QString &source, Contact::PhotoSize size) -{ - d_func()->sources[size] = source; - emit photoSourceChanged(source, size); -} - -void Contact::fill(Contact *contact, const QVariantMap &data) -{ - auto it = data.constBegin(); - for (; it != data.constEnd(); it++) { - QByteArray property = "_q_" + it.key().toLatin1(); - contact->setProperty(property.data(), it.value()); - } -} - -Buddy::Buddy(int id, Client *client) : - Contact(new BuddyPrivate(this, id, client)) -{ - if (id < 0) - qWarning() << "Buddy's id must be positive"; -} - -QString Buddy::firstName() const -{ - return d_func()->firstName; -} - -void Buddy::setFirstName(const QString &firstName) -{ - Q_D(Buddy); - if (d->firstName != firstName) { - d->firstName = firstName; - emit firstNameChanged(firstName); - emit nameChanged(name()); - } -} - -QString Buddy::lastName() const -{ - return d_func()->lastName; -} - -void Buddy::setLastName(const QString &lastName) -{ - Q_D(Buddy); - if (d->lastName != lastName) { - d->lastName = lastName; - emit lastNameChanged(lastName); - emit nameChanged(name()); - } -} - -bool Buddy::isOnline() const -{ - return d_func()->status != Offline; -} - -void Buddy::setOnline(bool set) -{ - setStatus(set ? Online : Offline); - emit onlineChanged(set); -} - -QString Buddy::name() const -{ - Q_D(const Buddy); - if (d->firstName.isEmpty() && d->lastName.isEmpty()) - return tr("id%1").arg(id()); - else if (d->lastName.isEmpty()) - return d->firstName; - else if (d->firstName.isEmpty()) - return d->lastName; - else - return d->firstName + ' ' + d->lastName; - -} - -QStringList Buddy::tags() const -{ - Q_D(const Buddy); - QStringList tags; - foreach (auto data, d->tagIdList) { - int id = data.toInt(); - tags.append(d->client->roster()->tags().value(id, tr("Unknown tag id %1").arg(id))); - } - return tags; -} - -QString Buddy::activity() const -{ - return d_func()->activity; -} - -Buddy::Status Buddy::status() const -{ - return d_func()->status; -} - -void Buddy::setStatus(Buddy::Status status) -{ - Q_D(Buddy); - //hack for delayed replies recieve - if (!d->client->isOnline()) - status = Offline; - - if (d->status != status) { - d_func()->status = status; - emit statusChanged(status); - } -} - -bool Buddy::isFriend() const -{ - return d_func()->isFriend; -} - -void Buddy::setIsFriend(bool set) -{ - Q_D(Buddy); - if (d->isFriend != set) { - d->isFriend = set; - emit isFriendChanged(set); - } -} - -/*! - * \brief Buddy::update - * \param fields - some fields need to update. - * \note This request will be called immediately. - * \sa update - * api reference \link http://vk.com/developers.php?oid=-1&p=users.get - */ -void Buddy::update(const QStringList &fields) -{ - IdList ids; - ids.append(id()); - d_func()->client->roster()->update(ids, fields); -} - -/*! - * \brief Buddy::update - * Add contact to update queue and it will be updated as soon as posible in near future. - * Use this method if you know that it takes more than one update - * \sa update(fields) - */ -void Buddy::update() -{ - Q_D(Buddy); - d->client->roster()->d_func()->appendToUpdaterQueue(this); -} - -SendMessageReply *Buddy::sendMessage(const QString &body, const QString &subject) -{ - Q_D(Buddy); - Message message(d->client); - message.setBody(body); - message.setSubject(subject); - message.setToId(id()); - return d->client->sendMessage(message); -} - -Reply *Buddy::addToFriends(const QString &reason) -{ - Q_D(Buddy); - QVariantMap args; - args.insert("uid", d->id); - args.insert("text", reason); - auto reply = d->client->request("friends.add", args); - connect(reply, SIGNAL(resultReady(QVariant)), this, SLOT(_q_friends_add_finished(QVariant))); - return reply; -} - -Reply *Buddy::removeFromFriends() -{ - Q_D(Buddy); - QVariantMap args; - args.insert("uid", d->id); - auto reply = d->client->request("friends.delete", args); - connect(reply, SIGNAL(resultReady(QVariant)), this, SLOT(_q_friends_delete_finished(QVariant))); - return reply; -} - -Group::Group(int id, Client *client) : - Contact(new GroupPrivate(this, id, client)) -{ - Q_D(Group); - if (id > 0) - qWarning() << "Group's id must be negative"; - d->type = GroupType; -} - -QString Group::name() const -{ - Q_D(const Group); - if (!d->name.isEmpty()) - return d->name; - return tr("group-%1").arg(id()); -} - -void Group::setName(const QString &name) -{ - d_func()->name = name; - emit nameChanged(name); -} - -void Group::update() -{ - Q_D(Group); - d->client->groupManager()->d_func()->appendToUpdaterQueue(this); -} - -void BuddyPrivate::_q_friends_add_finished(const QVariant &response) -{ - Q_Q(Buddy); - int answer = response.toInt(); - switch (answer) { - case 1: - //TODO - break; - case 2: - q->setIsFriend(true); - case 4: - //TODO - break; - default: - break; - } -} - -void BuddyPrivate::_q_friends_delete_finished(const QVariant &response) -{ - Q_Q(Buddy); - int answer = response.toInt(); - switch (answer) { - case 1: - q->setIsFriend(false); - break; - case 2: - //TODO - default: - break; - } -} - -} // namespace Vreen - -#include "moc_contact.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/contact.h b/3rdparty/vreen/vreen/src/api/contact.h deleted file mode 100644 index 4fa67c766..000000000 --- a/3rdparty/vreen/vreen/src/api/contact.h +++ /dev/null @@ -1,243 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_USER_H -#define VK_USER_H - -#include "client.h" -#include -#include - -namespace Vreen { - -#define VK_COMMON_FIELDS QLatin1String("first_name") \ - << QLatin1String("last_name") \ - << QLatin1String("online") \ - << QLatin1String("photo") \ - << QLatin1String("photo_medium") \ - << QLatin1String("photo_medium_rec") \ - << QLatin1String("photo_big") \ - << QLatin1String("photo_big_rec") \ - << QLatin1String("lists") \ - << QLatin1String("activity") - -#define VK_EXTENDED_FIELDS QLatin1String("sex") \ - << QLatin1String("bdate") \ - << QLatin1String("city") \ - << QLatin1String("country") \ - << QLatin1String("education") \ - << QLatin1String("can_post") \ - << QLatin1String("contacts") \ - << QLatin1String("can_see_all_posts") \ - << QLatin1String("can_write_private_message") \ - << QLatin1String("last_seen") \ - << QLatin1String("relation") \ - << QLatin1String("nickname") \ - << QLatin1String("wall_comments") \ - -#define VK_GROUP_FIELDS QLatin1String("city") \ - << "country" \ - << "place" \ - << "description" \ - << "wiki_page" \ - << "members_count" \ - << "counters" \ - << "start_date" \ - << "end_date" \ - << "can_post" \ - << "activity" - -#define VK_ALL_FIELDS VK_COMMON_FIELDS \ - << VK_EXTENDED_FIELDS - -class Client; -class ContactPrivate; -class VK_SHARED_EXPORT Contact : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(Contact) - Q_ENUMS(Type) - Q_ENUMS(Status) - - Q_PROPERTY(int id READ id CONSTANT) - Q_PROPERTY(QString name READ name NOTIFY nameChanged) - Q_PROPERTY(Type type READ type CONSTANT) - Q_PRIVATE_PROPERTY(Contact::d_func(), QString photoSource READ defaultSource NOTIFY photoSourceChanged) - Q_PRIVATE_PROPERTY(Contact::d_func(), QString photoSourceBig READ bigSource NOTIFY photoSourceChanged) - - Q_PRIVATE_PROPERTY(Contact::d_func(), QString _q_photo READ smallSource WRITE setSmallSource DESIGNABLE false) - Q_PRIVATE_PROPERTY(Contact::d_func(), QString _q_photo_medium READ mediumSource WRITE setMediumSource DESIGNABLE false) - Q_PRIVATE_PROPERTY(Contact::d_func(), QString _q_photo_medium_rec READ mediumSourceRec WRITE setMediumSourceRec DESIGNABLE false) - Q_PRIVATE_PROPERTY(Contact::d_func(), QString _q_photo_big READ bigSource WRITE setBigSource DESIGNABLE false) - Q_PRIVATE_PROPERTY(Contact::d_func(), QString _q_photo_big_rec READ bigSourceRec WRITE setBigSourceRec DESIGNABLE false) -public: - - enum PhotoSize { - PhotoSizeSmall, - PhotoSizeMedium, - PhotoSizeBig, - PhotoSizeMediumRec, - PhotoSizeBigRec - }; - - enum Type { - BuddyType, - GroupType, - ChatType - }; - - enum Status { - Online, - Away, - Offline, - Unknown - }; - - Contact(int id, Client *client); - Contact(ContactPrivate *data); - virtual ~Contact(); - virtual QString name() const = 0; - Type type(); - int id() const; - Client *client() const; - Q_INVOKABLE QString photoSource(PhotoSize size = PhotoSizeSmall) const; - void setPhotoSource(const QString &source, PhotoSize size = PhotoSizeSmall); - static void fill(Contact *contact, const QVariantMap &data); -signals: - void nameChanged(const QString &name); - void photoSourceChanged(const QString &source, Vreen::Contact::PhotoSize); -protected: - QScopedPointer d_ptr; -}; - -#define VK_CONTACT_TYPE(ContactType) \ - public: \ - static Contact::Type staticType() { return ContactType; } \ - virtual Contact::Type type() const { return staticType(); } \ - private: - -class BuddyPrivate; -class VK_SHARED_EXPORT Buddy : public Contact -{ - Q_OBJECT - Q_DECLARE_PRIVATE(Buddy) - VK_CONTACT_TYPE(BuddyType) - - Q_PROPERTY(QString fistName READ firstName NOTIFY firstNameChanged) - Q_PROPERTY(QString lastName READ lastName NOTIFY lastNameChanged) - Q_PROPERTY(bool online READ isOnline NOTIFY onlineChanged) - Q_PROPERTY(QStringList tags READ tags NOTIFY tagsChanged) - Q_PROPERTY(QString activity READ activity NOTIFY activityChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(bool isFriend READ isFriend NOTIFY isFriendChanged) - - //private properties - Q_PROPERTY(QString _q_first_name READ firstName WRITE setFirstName DESIGNABLE false) - Q_PROPERTY(QString _q_last_name READ lastName WRITE setLastName DESIGNABLE false) - Q_PROPERTY(bool _q_online READ isOnline WRITE setOnline DESIGNABLE false STORED false) - Q_PRIVATE_PROPERTY(d_func(), QVariantList _q_lists READ lists WRITE setLists DESIGNABLE false) - Q_PRIVATE_PROPERTY(d_func(), QString _q_activity READ getActivity WRITE setActivity DESIGNABLE false) -public: - //TODO name case support maybe needed - QString firstName() const; - void setFirstName(const QString &firstName); - QString lastName() const; - void setLastName(const QString &lastName); - bool isOnline() const; - void setOnline(bool set); - virtual QString name() const; - QStringList tags() const; - QString activity() const; - Status status() const; - void setStatus(Status status); - bool isFriend() const; - void setIsFriend(bool set); -public slots: - void update(const QStringList &fields); - void update(); - SendMessageReply *sendMessage(const QString &body, const QString &subject = QString()); - Reply *addToFriends(const QString &reason = QString()); - Reply *removeFromFriends(); -signals: - void firstNameChanged(const QString &name); - void lastNameChanged(const QString &name); - void onlineChanged(bool isOnline); - void tagsChanged(const QStringList &tags); - void activityChanged(const QString &activity); - void statusChanged(Vreen::Contact::Status); - void isFriendChanged(bool isFriend); -protected: - Buddy(int id, Client *client); - - friend class Roster; - friend class RosterPrivate; - - Q_PRIVATE_SLOT(d_func(), void _q_friends_add_finished(const QVariant &response)) - Q_PRIVATE_SLOT(d_func(), void _q_friends_delete_finished(const QVariant &response)) -}; - -class GroupPrivate; -class VK_SHARED_EXPORT Group : public Contact -{ - Q_OBJECT - Q_DECLARE_PRIVATE(Group) - VK_CONTACT_TYPE(GroupType) - - Q_PROPERTY(QString _q_name READ name WRITE setName DESIGNABLE false) -public: - virtual QString name() const; - void setName(const QString &name); -public slots: - void update(); -protected: - Group(int id, Client *client); - - friend class GroupManager; -}; - -//TODO group chats -class GroupChat; - -typedef QList ContactList; -typedef QList BuddyList; -typedef QList GroupList; - -//contact's casts -template -Q_INLINE_TEMPLATE T contact_cast(Contact *contact) -{ - //T t = reinterpret_cast(0); - //if (t->staticType() == contact->type()) - // return static_cast(contact); - return qobject_cast(contact); -} - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::Contact*) -Q_DECLARE_METATYPE(Vreen::Buddy*) -Q_DECLARE_METATYPE(Vreen::Group*) - -#endif // VK_USER_H - diff --git a/3rdparty/vreen/vreen/src/api/contact_p.h b/3rdparty/vreen/vreen/src/api/contact_p.h deleted file mode 100644 index 9487e3632..000000000 --- a/3rdparty/vreen/vreen/src/api/contact_p.h +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef USER_P_H -#define USER_P_H -#include "contact.h" -#include "client.h" -#include -#include - -namespace Vreen { - -class Contact; -class ContactPrivate -{ - Q_DECLARE_PUBLIC(Contact) -public: - ContactPrivate(Contact *q, int id, Client *client) : q_ptr(q), - client(client), id(id), type(Contact::BuddyType), - sources(Contact::PhotoSizeBigRec + 1), - preferedSize(Contact::PhotoSizeMediumRec) - { - - } - Contact *q_ptr; - Client *client; - int id; - Contact::Type type; - QVector sources; - Contact::PhotoSize preferedSize; - - QString defaultSource() const - { - //return sources[preferedSize]; - for (int index = preferedSize; index != -1; index--) { - auto photo = sources.value(index); - if (!photo.isNull()) - return photo; - } - return QString(); - } - QString smallSource() { return sources[Contact::PhotoSizeSmall]; } - void setSmallSource(const QString &source) - { - q_func()->setPhotoSource(source, Contact::PhotoSizeSmall); - } - QString mediumSource() { return sources[Contact::PhotoSizeMedium]; } - void setMediumSource(const QString &source) - { - q_func()->setPhotoSource(source, Contact::PhotoSizeMedium); - } - QString mediumSourceRec() { return sources[Contact::PhotoSizeMediumRec]; } - void setMediumSourceRec(const QString &source) - { - q_func()->setPhotoSource(source, Contact::PhotoSizeMediumRec); - } - QString bigSource() { return sources[Contact::PhotoSizeBig]; } - void setBigSource(const QString &source) - { - q_func()->setPhotoSource(source, Contact::PhotoSizeBig); - } - QString bigSourceRec() { return sources[Contact::PhotoSizeBigRec]; } - void setBigSourceRec(const QString &source) - { - q_func()->setPhotoSource(source, Contact::PhotoSizeBigRec); - } -}; - -class BuddyPrivate : public ContactPrivate -{ - Q_DECLARE_PUBLIC(Buddy) -public: - BuddyPrivate(Contact *q, int id, Client *client) : - ContactPrivate(q, id, client), - status(Buddy::Offline), - isFriend(false) - { - type = Contact::BuddyType; - } - QString firstName; - QString lastName; - Buddy::Status status; - QVariantList tagIdList; - QString activity; - bool isFriend; - - QVariantList lists() const { return QVariantList(); } - void setLists(const QVariantList &list) - { - Q_Q(Buddy); - tagIdList.clear(); - foreach (auto value, list) - tagIdList.append(value); - emit q->tagsChanged(q->tags()); - } - QString getActivity() const { return activity; } - void setActivity(const QString &now) - { - if (activity != now) { - activity = now; - emit q_func()->activityChanged(now); - } - } - - void _q_friends_add_finished(const QVariant &response); - void _q_friends_delete_finished(const QVariant &response); -}; - -class GroupPrivate : public ContactPrivate -{ - Q_DECLARE_PUBLIC(Group) -public: - GroupPrivate(Contact *q, int id, Client *client) : ContactPrivate(q, id, client) {} - QString name; -}; - -} //namespace Vreen - -#endif // USER_P_H - diff --git a/3rdparty/vreen/vreen/src/api/contentdownloader.cpp b/3rdparty/vreen/vreen/src/api/contentdownloader.cpp deleted file mode 100644 index c51d24c1a..000000000 --- a/3rdparty/vreen/vreen/src/api/contentdownloader.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "contentdownloader_p.h" -#include "utils.h" -#include -#include -#include -#include -#include - -namespace Vreen { - -static QPointer networkManager; - -ContentDownloader::ContentDownloader(QObject *parent) : - QObject(parent) -{ - if (!networkManager) { - networkManager = new NetworkAccessManager; - //use another thread for more smooth gui - //auto thread = new QThread; - //networkManager->moveToThread(thread); - //connect(networkManager.data(), SIGNAL(destroyed()), thread, SLOT(quit())); - //connect(thread, SIGNAL(finished()), SLOT(deleteLater())); - //thread->start(QThread::LowPriority); - } -} - -QString ContentDownloader::download(const QUrl &link) -{ - QString path = networkManager->cacheDir() - + networkManager->fileHash(link) - + QLatin1String(".") - + QFileInfo(link.path()).completeSuffix(); - - if (QFileInfo(path).exists()) { - //FIXME it maybe not work in some cases (use event instead emit) - emit downloadFinished(path); - } else { - QNetworkRequest request(link); - request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - auto reply = networkManager->get(request); - reply->setProperty("path", path); - connect(reply, SIGNAL(finished()), this, SLOT(replyDone())); - } - return path; -} - -void ContentDownloader::replyDone() -{ - auto reply = sender_cast(sender()); - QString cacheDir = networkManager->cacheDir(); - QDir dir(cacheDir); - if (!dir.exists()) { - if(!dir.mkpath(cacheDir)) { - qWarning("Unable to create cache dir"); - return; - } - } - //TODO move method to manager in other thread - QString path = reply->property("path").toString(); - QFile file(path); - if (!file.open(QIODevice::WriteOnly)) { - qWarning("Unable to write file!"); - return; - } - file.write(reply->readAll()); - file.close(); - - emit downloadFinished(path); -} - -} // namespace Vreen - -#include "moc_contentdownloader.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/contentdownloader.h b/3rdparty/vreen/vreen/src/api/contentdownloader.h deleted file mode 100644 index 480de3899..000000000 --- a/3rdparty/vreen/vreen/src/api/contentdownloader.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_CONTENTDOWNLOADER_H -#define VK_CONTENTDOWNLOADER_H - -#include -#include "vk_global.h" - -class QUrl; - -namespace Vreen { - -class VK_SHARED_EXPORT ContentDownloader : public QObject -{ - Q_OBJECT -public: - explicit ContentDownloader(QObject *parent = 0); - Q_INVOKABLE QString download(const QUrl &link); -signals: - void downloadFinished(const QString &fileName); -private slots: - void replyDone(); -}; - -} // namespace Vreen - -#endif // VK_CONTENTDOWNLOADER_H - diff --git a/3rdparty/vreen/vreen/src/api/contentdownloader_p.h b/3rdparty/vreen/vreen/src/api/contentdownloader_p.h deleted file mode 100644 index 797bbbf69..000000000 --- a/3rdparty/vreen/vreen/src/api/contentdownloader_p.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef CONTENTDOWNLOADER_P_H -#define CONTENTDOWNLOADER_P_H -#include -#include -#include -#include -#include -#include "contentdownloader.h" - -namespace Vreen { - -class NetworkAccessManager : public QNetworkAccessManager -{ - Q_OBJECT -public: - NetworkAccessManager(QObject *parent = 0) : QNetworkAccessManager(parent) - { - - } - - QString fileHash(const QUrl &url) const - { - QCryptographicHash hash(QCryptographicHash::Md5); - hash.addData(url.toString().toUtf8()); - return hash.result().toHex(); - } - QString cacheDir() const - { - auto dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); - return dir + QLatin1String("/vk/"); - } -}; - -} //namespace Vreen - -#endif // CONTENTDOWNLOADER_P_H diff --git a/3rdparty/vreen/vreen/src/api/dynamicpropertydata.cpp b/3rdparty/vreen/vreen/src/api/dynamicpropertydata.cpp deleted file mode 100644 index 0a28fff7c..000000000 --- a/3rdparty/vreen/vreen/src/api/dynamicpropertydata.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "dynamicpropertydata_p.h" -#include - -namespace Vreen { - -QVariant DynamicPropertyData::property(const char *name, const QVariant &def, - const QList &gNames, - const QList &gGetters) const -{ - QByteArray prop = QByteArray::fromRawData(name, strlen(name)); - int id = gNames.indexOf(prop); - if (id < 0) { - id = names.indexOf(prop); - if(id < 0) - return def; - return values.at(id); - } - return (this->*gGetters.at(id))(); -} - -void DynamicPropertyData::setProperty(const char *name, const QVariant &value, - const QList &gNames, - const QList &gSetters) -{ - QByteArray prop = QByteArray::fromRawData(name, strlen(name)); - int id = gNames.indexOf(prop); - if (id < 0) { - id = names.indexOf(prop); - if (!value.isValid()) { - if(id < 0) - return; - names.removeAt(id); - values.removeAt(id); - } else { - if (id < 0) { - prop.detach(); - names.append(prop); - values.append(value); - } else { - values[id] = value; - } - } - } else { - (this->*gSetters.at(id))(value); - } -} - -} // namespace Vreen - diff --git a/3rdparty/vreen/vreen/src/api/dynamicpropertydata_p.h b/3rdparty/vreen/vreen/src/api/dynamicpropertydata_p.h deleted file mode 100644 index eb451e03c..000000000 --- a/3rdparty/vreen/vreen/src/api/dynamicpropertydata_p.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_DYNAMICPROPERTYDATA_P_H -#define VK_DYNAMICPROPERTYDATA_P_H - -//from euroelessar code - -#include -#include - -namespace Vreen { - -class DynamicPropertyData; - -namespace CompiledProperty -{ - typedef QVariant (DynamicPropertyData::*Getter)() const; - typedef void (DynamicPropertyData::*Setter)(const QVariant &variant); -} - -class DynamicPropertyData : public QSharedData -{ -public: - typedef CompiledProperty::Getter Getter; - typedef CompiledProperty::Setter Setter; - DynamicPropertyData() {} - DynamicPropertyData(const DynamicPropertyData &o) : - QSharedData(o), names(o.names), values(o.values) {} - QList names; - QList values; - - QVariant property(const char *name, const QVariant &def, const QList &names, - const QList &getters) const; - void setProperty(const char *name, const QVariant &value, const QList &names, - const QList &setters); -}; - -} // namespace Vreen - -#endif // VK_DYNAMICPROPERTYDATA_P_H - diff --git a/3rdparty/vreen/vreen/src/api/friendrequest.cpp b/3rdparty/vreen/vreen/src/api/friendrequest.cpp deleted file mode 100644 index 1e46b509d..000000000 --- a/3rdparty/vreen/vreen/src/api/friendrequest.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "friendrequest.h" -#include - -namespace Vreen { - -class FriendRequestData : public QSharedData { -public: - FriendRequestData(int uid) : QSharedData(), - uid(uid) - {} - FriendRequestData(const FriendRequestData &o) : QSharedData(o), - uid(o.uid), - message(o.message), - mutual(o.mutual) - {} - - int uid; - QString message; - IdList mutual; -}; - -FriendRequest::FriendRequest(int uid) : data(new FriendRequestData(uid)) -{ -} - -FriendRequest::FriendRequest(const FriendRequest &rhs) : data(rhs.data) -{ -} - -FriendRequest &FriendRequest::operator=(const FriendRequest &rhs) -{ - if (this != &rhs) - data.operator=(rhs.data); - return *this; -} - -FriendRequest::~FriendRequest() -{ -} - -int FriendRequest::uid() const -{ - return data->uid; -} - -void FriendRequest::setUid(int uid) -{ - data->uid = uid; -} - -IdList FriendRequest::mutualFriends() const -{ - return data->mutual; -} - -void FriendRequest::setMutualFriends(const IdList &mutual) -{ - data->mutual = mutual; -} - -QString FriendRequest::message() const -{ - return data->message; -} - -void FriendRequest::setMessage(const QString &message) -{ - data->message = message; -} - -} // namespace Vreen diff --git a/3rdparty/vreen/vreen/src/api/friendrequest.h b/3rdparty/vreen/vreen/src/api/friendrequest.h deleted file mode 100644 index c017e23fe..000000000 --- a/3rdparty/vreen/vreen/src/api/friendrequest.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VREEN_FRIENDREQUEST_H -#define VREEN_FRIENDREQUEST_H - -#include "vk_global.h" -#include -#include - -namespace Vreen { - -class FriendRequestData; - -class VK_SHARED_EXPORT FriendRequest -{ -public: - explicit FriendRequest(int uid = 0); - FriendRequest(const FriendRequest &); - FriendRequest &operator=(const FriendRequest &); - ~FriendRequest(); - int uid() const; - void setUid(int uid); - QString message() const; - void setMessage(const QString &message); - IdList mutualFriends() const; - void setMutualFriends(const IdList &mutualFriends); -private: - QSharedDataPointer data; -}; -typedef QList FriendRequestList; - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::FriendRequest) -Q_DECLARE_METATYPE(Vreen::FriendRequestList) - -#endif // VREEN_FRIENDREQUEST_H diff --git a/3rdparty/vreen/vreen/src/api/groupchatsession.cpp b/3rdparty/vreen/vreen/src/api/groupchatsession.cpp deleted file mode 100644 index 313b6d998..000000000 --- a/3rdparty/vreen/vreen/src/api/groupchatsession.cpp +++ /dev/null @@ -1,336 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "groupchatsession.h" -#include "messagesession_p.h" -#include "client_p.h" -#include "reply_p.h" -#include "roster.h" -#include - -namespace Vreen { - -class GroupChatSession; -class GroupChatSessionPrivate : public MessageSessionPrivate -{ - Q_DECLARE_PUBLIC(GroupChatSession) -public: - GroupChatSessionPrivate(MessageSession *q, Client *client, int uid) : - MessageSessionPrivate(q, client, uid), - adminId(0) - {} - QString title; - QHash buddies; - int adminId; - - Buddy *addContact(int id); - void removeContact(int id); - - void _q_message_sent(const QVariant &response); - void _q_info_received(const QVariant &response); - void _q_participant_added(const QVariant &response); - void _q_participant_removed(const QVariant &response); - void _q_title_updated(const QVariant &response); - void _q_online_changed(bool set); - void _q_message_added(const Vreen::Message &); - void _q_group_chat_updated(int chatId, bool self); -}; - -/*! - * \brief The GroupChatSession class, based on - * \link http://vk.com/developers.php?oid=-1&p=messages.getChat - * \link http://vk.com/developers.php?o=-1&p=messages.createChat - * etc - */ - -/*! - * \brief GroupChatSession::GroupChatSession - * \param chatId - * \param client - */ - -GroupChatSession::GroupChatSession(int chatId, Client *client) : - MessageSession(new GroupChatSessionPrivate(this, client, chatId)) -{ - connect(client, SIGNAL(onlineStateChanged(bool)), SLOT(_q_online_changed(bool))); - connect(client->longPoll(), SIGNAL(groupChatUpdated(int,bool)), SLOT(_q_group_chat_updated(int,bool))); -} - -BuddyList GroupChatSession::participants() const -{ - return d_func()->buddies.values(); -} - -Buddy *GroupChatSession::admin() const -{ - return static_cast(findParticipant(d_func()->adminId)); -} - -QString GroupChatSession::title() const -{ - return d_func()->title; -} - -Buddy *GroupChatSession::findParticipant(int uid) const -{ - foreach (auto buddy, d_func()->buddies) - if (buddy->id() == uid) - return buddy; - return 0; -} - -bool GroupChatSession::isJoined() const -{ - Q_D(const GroupChatSession); - return d->buddies.contains(d->client->me()->id()) - && d->client->isOnline(); -} - -//Buddy *GroupChatSession::participant(int uid) -//{ -// auto p = findParticipant(uid); -// if (!p) -// p = d_func()->addContact(uid); -// return p; -//} - -Reply *GroupChatSession::create(Client *client, const IdList &uids, const QString &title) -{ - QStringList list; - foreach (auto &uid, uids) - list.append(QString::number(uid)); - QVariantMap args; - args.insert("uids", list.join(",")); - args.insert("title", title); - return client->request("messages.createChat", args); -} - -void GroupChatSession::setTitle(const QString &title) -{ - Q_D(GroupChatSession); - if (d->title != title) { - d->title = title; - emit titleChanged(title); - } -} - -ReplyBase *GroupChatSession::doGetHistory(int count, int offset) -{ - Q_D(GroupChatSession); - QVariantMap args; - args.insert("count", count); - args.insert("offset", offset); - args.insert("chat_id", d->uid); - - auto reply = d->client->request>("messages.getHistory", - args, - MessageListHandler(d->client->id())); - return reply; -} - -SendMessageReply *GroupChatSession::doSendMessage(const Message &message) -{ - Q_D(GroupChatSession); - QVariantMap args; - //TODO move to client - args.insert("chat_id", d->uid); - args.insert("message", message.body()); - args.insert("title", message.subject()); - - return d->client->request("messages.send", args, ReplyPrivate::handleInt); -} - -Reply *GroupChatSession::getInfo() -{ - Q_D(GroupChatSession); - QVariantMap args; - args.insert("chat_id", d->uid); - - auto reply = d->client->request("messages.getChat", args); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_info_received(QVariant))); - return reply; -} - -/*! - * \brief GroupChatSession::inviteParticipant \link http://vk.com/developers.php?oid=-1&p=messages.addChatUser - * \param buddy - * \return - */ -Reply *GroupChatSession::inviteParticipant(Contact *buddy) -{ - Q_D(GroupChatSession); - QVariantMap args; - args.insert("chat_id", d->uid); - args.insert("uid", buddy->id()); - - auto reply = d->client->request("messages.addChatUser", args); - reply->setProperty("uid", buddy->id()); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_participant_added(QVariant))); - return reply; -} - -Reply *GroupChatSession::removeParticipant(Contact *buddy) -{ - Q_D(GroupChatSession); - QVariantMap args; - args.insert("chat_id", d->uid); - args.insert("uid", buddy->id()); - - auto reply = d->client->request("messages.removeChatUser", args); - reply->setProperty("uid", buddy->id()); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_participant_removed(QVariant))); - return reply; -} - -Reply *GroupChatSession::updateTitle(const QString &title) -{ - Q_D(GroupChatSession); - QVariantMap args; - args.insert("chat_id", d->uid); - args.insert("title", title); - - auto reply = d->client->request("messages.editChat", args); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_title_updated(QVariant))); - return reply; -} - -void GroupChatSession::join() -{ - Q_D(GroupChatSession); - if (!isJoined() && d->client->isOnline()) - inviteParticipant(d_func()->client->me()); -} - -void GroupChatSession::leave() -{ - if (isJoined()) - removeParticipant(d_func()->client->me()); -} - -void GroupChatSessionPrivate::_q_info_received(const QVariant &response) -{ - Q_Q(GroupChatSession); - auto map = response.toMap(); - adminId = map.value("admin_id").toInt(); - q->setTitle(map.value("title").toString()); - - QSet uidsToAdd; - foreach (auto item, map.value("users").toList()) - uidsToAdd.insert(item.toInt()); - - QSet uids = buddies.keys().toSet(); - QSet uidsToRemove = uids - uidsToAdd; - uidsToAdd -= uids; - foreach (auto uid, uidsToRemove) - removeContact(uid); - foreach (auto uid, uidsToAdd) - addContact(uid); -} - -void GroupChatSessionPrivate::_q_participant_added(const QVariant &response) -{ - if (response.toInt() == 1) { - int id = q_func()->sender()->property("uid").toInt(); - addContact(id); - } -} - -void GroupChatSessionPrivate::_q_participant_removed(const QVariant &response) -{ - if (response.toInt() == 1) { - int id = q_func()->sender()->property("uid").toInt(); - removeContact(id); - } -} - -void GroupChatSessionPrivate::_q_title_updated(const QVariant &response) -{ - Q_Q(GroupChatSession); - auto map = response.toMap(); - q->setTitle(map.value("title").toString()); -} - -void GroupChatSessionPrivate::_q_online_changed(bool set) -{ - foreach (auto contact, buddies) { - if (auto buddy = qobject_cast(contact)) { - if (set) - buddy->update(); - else - buddy->setOnline(false); - } - } - if (!set) - emit q_func()->isJoinedChanged(false); -} - -void GroupChatSessionPrivate::_q_message_added(const Message &msg) -{ - if (msg.chatId() == uid) { - emit q_func()->messageAdded(msg); - } -} - -void GroupChatSessionPrivate::_q_group_chat_updated(int chatId, bool) -{ - Q_Q(GroupChatSession); - if (chatId == uid) - q->getInfo(); -} - -Buddy *GroupChatSessionPrivate::addContact(int id) -{ - Q_Q(GroupChatSession); - if (id) { - if (!buddies.contains(id)) { - auto contact = client->roster()->buddy(id); - buddies.insert(id, contact); - emit q->participantAdded(contact); - if (contact == client->me()) { - emit q->isJoinedChanged(true); - } - return contact; - } - } - return 0; -} - -void GroupChatSessionPrivate::removeContact(int id) -{ - Q_Q(GroupChatSession); - if (id) { - if (buddies.contains(id)) { - buddies.remove(id); - auto contact = client->roster()->buddy(id); - emit q->participantRemoved(contact); - if (contact == client->me()) - emit q->isJoinedChanged(false); - } - } -} - -} // namespace Vreen - -#include "moc_groupchatsession.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/groupchatsession.h b/3rdparty/vreen/vreen/src/api/groupchatsession.h deleted file mode 100644 index 2f6a5f9a3..000000000 --- a/3rdparty/vreen/vreen/src/api/groupchatsession.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_GROUPCHATSESSION_H -#define VK_GROUPCHATSESSION_H -#include "messagesession.h" -#include "contact.h" - -namespace Vreen { - -class GroupChatSessionPrivate; - -class VK_SHARED_EXPORT GroupChatSession : public Vreen::MessageSession -{ - Q_OBJECT - Q_DECLARE_PRIVATE(GroupChatSession) - - Q_PROPERTY(QString title READ title NOTIFY titleChanged) - Q_PROPERTY(bool joined READ isJoined NOTIFY isJoinedChanged) -public: - explicit GroupChatSession(int chatId, Client *parent); - - BuddyList participants() const; - Buddy *admin() const; - QString title() const; - Buddy *findParticipant(int uid) const; - //Buddy *participant(int uid); - bool isJoined() const; - - static Reply *create(Client *client, const IdList &uids, const QString &title = QString()); -public slots: - Reply *getInfo(); - Reply *inviteParticipant(Contact *buddy); - Reply *removeParticipant(Contact *buddy); - Reply *updateTitle(const QString &title); - void join(); - void leave(); -signals: - void participantAdded(Vreen::Buddy*); - void participantRemoved(Vreen::Buddy*); - void titleChanged(QString); - void isJoinedChanged(bool); -protected: - void setTitle(const QString &title); - virtual SendMessageReply *doSendMessage(const Vreen::Message &message); - virtual ReplyBase *doGetHistory(int count = 16, int offset = 0); -private: - Q_PRIVATE_SLOT(d_func(), void _q_info_received(const QVariant &response)) - Q_PRIVATE_SLOT(d_func(), void _q_participant_added(const QVariant &response)) - Q_PRIVATE_SLOT(d_func(), void _q_participant_removed(const QVariant &response)) - Q_PRIVATE_SLOT(d_func(), void _q_title_updated(const QVariant &response)) - Q_PRIVATE_SLOT(d_func(), void _q_online_changed(bool)) - Q_PRIVATE_SLOT(d_func(), void _q_message_added(const Vreen::Message &)) - Q_PRIVATE_SLOT(d_func(), void _q_group_chat_updated(int chatId, bool self)) -}; - -} // namespace Vreen - -#endif // VK_GROUPCHATSESSION_H - diff --git a/3rdparty/vreen/vreen/src/api/groupmanager.cpp b/3rdparty/vreen/vreen/src/api/groupmanager.cpp deleted file mode 100644 index e496b1380..000000000 --- a/3rdparty/vreen/vreen/src/api/groupmanager.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "client.h" -#include "contact.h" -#include "utils_p.h" -#include -#include "groupmanager_p.h" - -namespace Vreen { - -GroupManager::GroupManager(Client *client) : - QObject(client), - d_ptr(new GroupManagerPrivate(this, client)) -{ -} - -GroupManager::~GroupManager() -{ -} - -Client *GroupManager::client() const -{ - return d_func()->client; -} - -Group *GroupManager::group(int gid) -{ - Q_D(GroupManager); - auto group = d->groupHash.value(gid); - if (!group) { - group = new Group(gid, client()); - d->groupHash.insert(gid, group); - } - return group; -} - -Group *GroupManager::group(int gid) const -{ - return d_func()->groupHash.value(gid); -} - -Reply *GroupManager::update(const IdList &ids, const QStringList &fields) -{ - Q_D(GroupManager); - QVariantMap args; - args.insert("gids", join(ids)); - args.insert("fields", fields.join(",")); - auto reply = d->client->request("groups.getById", args); - reply->connect(reply, SIGNAL(resultReady(const QVariant&)), - this, SLOT(_q_update_finished(const QVariant&))); - return reply; -} - -Reply *GroupManager::update(const GroupList &groups, const QStringList &fields) -{ - IdList ids; - foreach (auto group, groups) - ids.append(group->id()); - return update(ids, fields); -} - -void GroupManagerPrivate::_q_update_finished(const QVariant &response) -{ - Q_Q(GroupManager); - auto list = response.toList(); - foreach (auto data, list) { - auto map = data.toMap(); - int id = -map.value("gid").toInt(); - Contact::fill(q->group(id), map); - } -} - -void GroupManagerPrivate::_q_updater_handle() -{ - Q_Q(GroupManager); - q->update(updaterQueue); - updaterQueue.clear(); -} - -void GroupManagerPrivate::appendToUpdaterQueue(Group *contact) -{ - if (!updaterQueue.contains(-contact->id())) - updaterQueue.append(-contact->id()); - if (!updaterTimer.isActive()) - updaterTimer.start(); -} - -} // namespace Vreen - -#include "moc_groupmanager.cpp" diff --git a/3rdparty/vreen/vreen/src/api/groupmanager.h b/3rdparty/vreen/vreen/src/api/groupmanager.h deleted file mode 100644 index 4b855fc29..000000000 --- a/3rdparty/vreen/vreen/src/api/groupmanager.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_GROUPMANAGER_H -#define VK_GROUPMANAGER_H - -#include "contact.h" -#include - -namespace Vreen { - -class Client; -class Group; -class GroupManagerPrivate; - -class VK_SHARED_EXPORT GroupManager : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(GroupManager) -public: - explicit GroupManager(Client *client); - virtual ~GroupManager(); - Client *client() const; - Group *group(int gid) const; - Group *group(int gid); -public slots: - Reply *update(const IdList &ids, const QStringList &fields = QStringList() << VK_GROUP_FIELDS); - Reply *update(const GroupList &groups, const QStringList &fields = QStringList() << VK_GROUP_FIELDS); -signals: - void groupCreated(Group *group); -protected: - QScopedPointer d_ptr; -private: - - Q_PRIVATE_SLOT(d_func(), void _q_update_finished(const QVariant &response)) - Q_PRIVATE_SLOT(d_func(), void _q_updater_handle()) - - friend class Group; - friend class GroupPrivate; -}; - -} // namespace Vreen - -#endif // VK_GROUPMANAGER_H - diff --git a/3rdparty/vreen/vreen/src/api/groupmanager_p.h b/3rdparty/vreen/vreen/src/api/groupmanager_p.h deleted file mode 100644 index 58249f6b0..000000000 --- a/3rdparty/vreen/vreen/src/api/groupmanager_p.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GROUPMANAGER_P_H -#define GROUPMANAGER_P_H - -#include "groupmanager.h" -#include "client.h" -#include "contact.h" -#include - -namespace Vreen { - -class GroupManager; -class GroupManagerPrivate -{ - Q_DECLARE_PUBLIC(GroupManager) -public: - GroupManagerPrivate(GroupManager *q, Client *client) : q_ptr(q), client(client) - { - updaterTimer.setInterval(5000); - updaterTimer.setSingleShot(true); - updaterTimer.connect(&updaterTimer, SIGNAL(timeout()), - q, SLOT(_q_updater_handle())); - } - GroupManager *q_ptr; - Client *client; - QHash groupHash; - - //updater - QTimer updaterTimer; - IdList updaterQueue; - - void _q_update_finished(const QVariant &response); - void _q_updater_handle(); - void appendToUpdaterQueue(Group *contact); -}; - -} //namespace Vreen - -#endif // GROUPMANAGER_P_H diff --git a/3rdparty/vreen/vreen/src/api/json.cpp b/3rdparty/vreen/vreen/src/api/json.cpp deleted file mode 100644 index 0acfe755b..000000000 --- a/3rdparty/vreen/vreen/src/api/json.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "json.h" -#include - -namespace Vreen { - -namespace JSON { - -/*! - * \brief Parse JSON data to QVariant - * \param String with JSON data - * \return Result of parsing, QVariant::Null if there was an error - */ -QVariant parse(const QByteArray &data) -{ - QVariant res; - int len = data.size(); - K8JSON::parseRecord(res, reinterpret_cast(data.constData()), &len); - return res; -} - -/*! - * \brief Generate JSON string from QVariant - * \param data QVariant with data - * \param indent Identation of new lines - * \return JSON string with data -*/ -QByteArray generate(const QVariant &data, int indent) -{ - QByteArray res; - K8JSON::generate(res, data, indent); - return res; -} - -} //namespace JSON - -} // namespace Vreen - diff --git a/3rdparty/vreen/vreen/src/api/json.h b/3rdparty/vreen/vreen/src/api/json.h deleted file mode 100644 index 6c76cccb2..000000000 --- a/3rdparty/vreen/vreen/src/api/json.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_JSON_H -#define VK_JSON_H -#include "vk_global.h" -#include - -namespace Vreen { - -namespace JSON { - VK_SHARED_EXPORT QVariant parse(const QByteArray &data); - VK_SHARED_EXPORT QByteArray generate(const QVariant &data, int indent = 0); -} //namespace JSON - -} // namespace Vreen - -#endif // VK_JSON_H - diff --git a/3rdparty/vreen/vreen/src/api/localstorage.cpp b/3rdparty/vreen/vreen/src/api/localstorage.cpp deleted file mode 100644 index fd7161e62..000000000 --- a/3rdparty/vreen/vreen/src/api/localstorage.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licees/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "localstorage.h" - -namespace Vreen { - -AbstractLocalStorage::AbstractLocalStorage() -{ -} - -} // namespace Vreen diff --git a/3rdparty/vreen/vreen/src/api/localstorage.h b/3rdparty/vreen/vreen/src/api/localstorage.h deleted file mode 100644 index 910e75dba..000000000 --- a/3rdparty/vreen/vreen/src/api/localstorage.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licees/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VREEN_LOCALSTORAGE_H -#define VREEN_LOCALSTORAGE_H -#include "contact.h" - -namespace Vreen { - -class AbstractLocalStorage -{ -public: - AbstractLocalStorage(); - virtual ~AbstractLocalStorage() {} -protected: - virtual void loadBuddies(Roster *roster) = 0; - virtual void storeBuddies(Roster *roster) = 0; - //TODO group managers - //key value storage - virtual void store(const QString &key, const QVariant &value) = 0; - virtual QVariant load(const QString &key) = 0; - //TODO messages history async get and set -}; - -} // namespace Vreen - -#endif // VREEN_LOCALSTORAGE_H diff --git a/3rdparty/vreen/vreen/src/api/longpoll.cpp b/3rdparty/vreen/vreen/src/api/longpoll.cpp deleted file mode 100644 index b83a6bd81..000000000 --- a/3rdparty/vreen/vreen/src/api/longpoll.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "longpoll_p.h" -#include "connection.h" -#include "message.h" -#include "roster.h" -#include "contact.h" -#include -#include - -namespace Vreen { - -static const int chatMessageOffset = 2000000000; - -/*! - * \brief The LongPoll class - * Api reference: \link http://vk.com/developers.php?oid=-1&p=messages.getLongPollServer - */ - -/*! - * \brief LongPoll::LongPoll - * \param client - */ -LongPoll::LongPoll(Client *client) : - QObject(client), - d_ptr(new LongPollPrivate(this)) -{ - Q_D(LongPoll); - d->client = client; - setRunning(client->isOnline() && client->trackMessages()); - - connect(client, SIGNAL(onlineStateChanged(bool)), SLOT(_q_update_running())); - connect(client, SIGNAL(trackMessagesChanged(bool)), SLOT(_q_update_running())); -} - -LongPoll::~LongPoll() -{ - -} - -void LongPoll::setMode(LongPoll::Mode mode) -{ - d_func()->mode = mode; -} - -LongPoll::Mode LongPoll::mode() const -{ - return d_func()->mode; -} - -int LongPoll::pollInterval() const -{ - return d_func()->pollInterval; -} - -void LongPoll::setRunning(bool set) -{ - Q_D(LongPoll); - if (set != d->isRunning) { - d->isRunning = set; - if (set) - requestServer(); - } -} - -void LongPoll::requestServer() -{ - Q_D(LongPoll); - if (d->isRunning) { - auto reply = d->client->request("messages.getLongPollServer"); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_request_server_finished(QVariant))); - } -} - -void LongPoll::requestData(const QByteArray &timeStamp) -{ - Q_D(LongPoll); - if (d->dataRequestReply) { - d->dataRequestReply->disconnect(this, SLOT(_q_on_data_recieved(QVariant))); - d->dataRequestReply->deleteLater(); - } - if (d->isRunning) { - QUrl url = d->dataUrl; - url.addQueryItem("ts", timeStamp); - auto reply = d->client->request(url); - connect(reply, SIGNAL(resultReady(QVariant)), this, SLOT(_q_on_data_recieved(QVariant))); - d->dataRequestReply = reply; - } -} - -void LongPollPrivate::_q_request_server_finished(const QVariant &response) -{ - Q_Q(LongPoll); - - QVariantMap data = response.toMap(); - if (data.isEmpty()) { - QTimer::singleShot(pollInterval, q, SLOT(requestServer())); - return; - } - - QString url("http://%1?act=a_check&key=%2&wait=%3&mode=%4"); - dataUrl = url.arg(data.value("server").toString(), - data.value("key").toString(), - QString::number(waitInterval), - QString::number(mode)); - q->requestData(data.value("ts").toByteArray()); -} - -void LongPollPrivate::_q_on_data_recieved(const QVariant &response) -{ - Q_Q(LongPoll); - auto data = response.toMap(); - - if (data.contains("failed")) { - q->requestServer(); - return; - } - - QVariantList updates = data.value("updates").toList(); - for (int i = 0; i < updates.size(); i++) { - QVariantList update = updates.at(i).toList(); - int updateType = update.value(0, -1).toInt(); - switch (updateType) { - case LongPoll::MessageDeleted: { - emit q->messageDeleted(update.value(1).toInt()); - break; - } - case LongPoll::MessageAdded: { - QVariantMap additional = update.value(7).toMap(); - - int rid = additional.value("from").toInt(); - auto attachmets = getAttachments(additional); - - Message::Flags flags(update.value(2).toInt()); - Message message(client); - message.setAttachments(attachmets); - int cid = update.value(3).toInt(); - - if ((cid - chatMessageOffset) >= 0) { - //WTF chat flag? - message.setChatId(cid - chatMessageOffset); - } - message.setId(update.value(1).toInt()); - message.setFlags(flags); - if (flags & Message::FlagOutbox) { - message.setToId(message.chatId() ? rid : cid); - message.setFromId(client->me()->id()); - } else { - message.setFromId(message.chatId() ? rid : cid); - message.setToId(client->me()->id()); - } - message.setSubject(update.value(5).toString()); - message.setBody(update.value(6).toString()); - message.setDate(QDateTime::currentDateTime()); - emit q->messageAdded(message); - break; - } - case LongPoll::MessageFlagsReplaced: { - int id = update.value(1).toInt(); - int flags = update.value(2).toInt(); - int userId = update.value(3).toInt(); - emit q->messageFlagsReplaced(id, flags, userId); - break; - } - case LongPoll::MessageFlagsReseted: { //TODO remove copy/paste - int id = update.value(1).toInt(); - int flags = update.value(2).toInt(); - int userId = update.value(3).toInt(); - emit q->messageFlagsReseted(id, flags, userId); - break; - } - case LongPoll::UserOnline: - case LongPoll::UserOffline: { - // WTF? Why VKontakte sends minus as first char of id? - auto id = qAbs(update.value(1).toInt()); - Buddy::Status status; - if (updateType == LongPoll::UserOnline) - status = Buddy::Online; - else - status = update.value(2).toInt() == 1 ? Buddy::Away - : Buddy::Offline; - emit q->contactStatusChanged(id, status); - break; - } - case LongPoll::GroupChatUpdated: { - int chat_id = update.value(1).toInt(); - bool self = update.value(1).toInt(); - emit q->groupChatUpdated(chat_id, self); - break; - } - case LongPoll::ChatTyping: { - int user_id = qAbs(update.value(1).toInt()); - //int flags = update.at(2).toInt(); - emit q->contactTyping(user_id); - break; - } - case LongPoll::GroupChatTyping: { - int user_id = qAbs(update.value(1).toInt()); - int chat_id = update.at(2).toInt(); - emit q->contactTyping(user_id, chat_id); - break; - } - case LongPoll::UserCall: { - int user_id = qAbs(update.value(1).toInt()); - int call_id = update.at(2).toInt(); - emit q->contactCall(user_id, call_id); - break; - } - } - } - - q->requestData(data.value("ts").toByteArray()); -} - -void LongPollPrivate::_q_update_running() -{ - Q_Q(LongPoll); - q->setRunning(client->isOnline() && client->trackMessages()); -} - -Attachment::List LongPollPrivate::getAttachments(const QVariantMap &map) -{ - QHash hash; - hash.reserve(map.keys().size() / 2); - auto it = map.constBegin(); - for (; it != map.constEnd(); it++) { - QString key = it.key(); - if (key.startsWith("attach")) { - key = key.remove(0, 6); - if (key.endsWith("type")) { - key.chop(5); - int i = key.toInt(); - hash[i].setType(it.value().toString()); - } else { - QStringList values = it.value().toString().split('_'); - int i = key.toInt(); - hash[i].setOwnerId(values[0].toInt()); - hash[i].setMediaId(values[1].toInt()); - } - } - } - return hash.values(); -} - -void LongPoll::setPollInterval(int interval) -{ - Q_D(LongPoll); - if (d->pollInterval != interval) { - d->pollInterval = interval; - emit pollIntervalChanged(interval); - } -} - -} // namespace Vreen - -#include "moc_longpoll.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/longpoll.h b/3rdparty/vreen/vreen/src/api/longpoll.h deleted file mode 100644 index bcd5daf80..000000000 --- a/3rdparty/vreen/vreen/src/api/longpoll.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_LONGPOLL_H -#define VK_LONGPOLL_H - -#include -#include "contact.h" - -namespace Vreen { - -class Message; -class Client; -class LongPollPrivate; -class VK_SHARED_EXPORT LongPoll : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(LongPoll) - Q_PROPERTY(int pollInterval READ pollInterval WRITE setPollInterval NOTIFY pollIntervalChanged) -public: - - enum ServerAnswer { - MessageDeleted = 0, - MessageFlagsReplaced= 1, - MessageFlagsSet = 2, - MessageFlagsReseted = 3, - MessageAdded = 4, - UserOnline = 8, - UserOffline = 9, - GroupChatUpdated = 51, - ChatTyping = 61, - GroupChatTyping = 62, - UserCall = 70 - - }; - - enum OfflineFlag { - OfflineTimeout = 1 - }; - Q_DECLARE_FLAGS(OfflineFlags, OfflineFlag) - - enum Mode { - NoRecieveAttachments = 0, - RecieveAttachments = 2 - }; - - LongPoll(Client *client); - virtual ~LongPoll(); - void setMode(Mode mode); - Mode mode() const; - int pollInterval() const; - void setPollInterval(int interval); -signals: - void messageAdded(const Vreen::Message &msg); - void messageDeleted(int mid); - void messageFlagsReplaced(int mid, int mask, int userId = 0); - void messageFlagsReseted(int mid, int mask, int userId = 0); - void contactStatusChanged(int userId, Vreen::Contact::Status status); - void contactTyping(int userId, int chatId = 0); - void contactCall(int userId, int callId); - void groupChatUpdated(int chatId, bool self); - void pollIntervalChanged(int); -public slots: - void setRunning(bool set); -protected slots: - void requestServer(); - void requestData(const QByteArray &timeStamp); -protected: - QScopedPointer d_ptr; - - Q_PRIVATE_SLOT(d_func(), void _q_request_server_finished(const QVariant &)) - Q_PRIVATE_SLOT(d_func(), void _q_on_data_recieved(const QVariant &)) - Q_PRIVATE_SLOT(d_func(), void _q_update_running()); -}; - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::LongPoll*) - -#endif // VK_LONGPOLL_H - diff --git a/3rdparty/vreen/vreen/src/api/longpoll_p.h b/3rdparty/vreen/vreen/src/api/longpoll_p.h deleted file mode 100644 index 0c1ce7b0c..000000000 --- a/3rdparty/vreen/vreen/src/api/longpoll_p.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef LONGPOLL_P_H -#define LONGPOLL_P_H - -#include "longpoll.h" -#include "client.h" -#include "reply.h" -#include "attachment.h" - -#include -#include -#include -#include -#include - -#include - -namespace Vreen { - -class LongPoll; -class LongPollPrivate -{ - Q_DECLARE_PUBLIC(LongPoll) -public: - LongPollPrivate(LongPoll *q) : q_ptr(q), client(0), - mode(LongPoll::RecieveAttachments), pollInterval(1500), waitInterval(25), isRunning(false) {} - LongPoll *q_ptr; - Client *client; - - LongPoll::Mode mode; - int pollInterval; - int waitInterval; - QUrl dataUrl; - bool isRunning; - QPointer dataRequestReply; - - void _q_request_server_finished(const QVariant &response); - void _q_on_data_recieved(const QVariant &response); - void _q_update_running(); - Attachment::List getAttachments(const QVariantMap &map); -}; - - -} //namespace Vreen - -#endif // LONGPOLL_P_H - diff --git a/3rdparty/vreen/vreen/src/api/message.cpp b/3rdparty/vreen/vreen/src/api/message.cpp deleted file mode 100644 index 9bc067c43..000000000 --- a/3rdparty/vreen/vreen/src/api/message.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "message.h" -#include "contact.h" -#include "client.h" -#include "roster.h" -#include -#include "dynamicpropertydata_p.h" -#include "utils_p.h" -#include - -namespace Vreen { - -class MessageData : public DynamicPropertyData -{ -public: - MessageData(int clientId) : - clientId(clientId), - messageId(0), - fromId(0), - toId(0), - chatId(0), - userCount(0), - adminId(0), - latitude(-1), - longitude(-1) - {} - MessageData(const MessageData &o) : - DynamicPropertyData(o), - clientId(o.clientId), - messageId(o.messageId), - fromId(o.fromId), - toId(o.toId), - date(o.date), - flags(o.flags), - subject(o.subject), - body(o.body), - forwardMsgIds(o.forwardMsgIds), - chatId(o.chatId), - chatActive(o.chatActive), - userCount(o.userCount), - adminId(o.adminId), - latitude(o.latitude), - longitude(o.longitude), - attachmentHash(o.attachmentHash) - {} - ~MessageData() {} - - int clientId; - int messageId; - int fromId; - int toId; - QDateTime date; - Message::Flags flags; - QString subject; - QString body; - QList forwardMsgIds; - int chatId; - QList chatActive; - int userCount; - int adminId; - qreal latitude; - qreal longitude; - Attachment::Hash attachmentHash; - - void fill(const QVariantMap &data) - { - messageId = data.value("mid").toInt(); - - int contactId = data.value("from_id").toInt(); - if (contactId) { - bool isIncoming = (contactId == clientId); - setFlag(Message::FlagOutbox, !isIncoming); - if (isIncoming) { - fromId = clientId; - toId = 0; - } else { - fromId = contactId; - toId = clientId; - } - } else { - setFlag(Message::FlagOutbox, data.value("out").toBool()); - contactId = data.value("uid").toInt(); - if (!flags.testFlag(Message::FlagOutbox)) { - fromId = contactId; - toId = clientId; - } else { - toId = contactId; - fromId = clientId; - } - } - - date = QDateTime::fromTime_t(data.value("date").toInt()); - setFlag(Message::FlagUnread, !data.value("read_state").toBool()); - subject = fromHtmlEntities(data.value("title").toString()); - body = fromHtmlEntities(data.value("body").toString()); - attachmentHash = Attachment::toHash(Attachment::fromVariantList(data.value("attachments").toList())); - //TODO forward messages - chatId = data.value("chat_id").toInt(); - } - - void setFlag(Message::Flag flag, bool set = true) - { - if (set) - flags |= flag; - else - flags &= ~flag; - } - - int getId(Contact *contact) const - { - return contact ? contact->id() : 0; - } -}; - - -/*! - * \brief The Message class - * Api reference: \link http://vk.com/developers.php?oid=-1&p=Формат_описания_личных_сообщений */ - -Message::Message(Client *client) : - d(new MessageData(client->id())) -{ -} - -Message::Message(int clientId) : - d(new MessageData(clientId)) -{ -} - -Message::Message(const QVariantMap &data, int clientId) : - d(new MessageData(clientId)) -{ - d->fill(data); -} - -Message::Message(const QVariantMap &data, Client *client) : - d(new MessageData(client->id())) -{ - d->fill(data); -} - -Message::Message(const Message &other) : d(other.d) -{ -} - -Message &Message::operator =(const Message &other) -{ - if (this != &other) - d.operator=(other.d); - return *this; -} - -bool Message::operator ==(const Message &other) -{ - return id() == other.id(); -} - -Message::~Message() -{ -} - -int Message::id() const -{ - return d->messageId; -} - -void Message::setId(int id) -{ - d->messageId = id; -} - -QDateTime Message::date() const -{ - return d->date; -} - -void Message::setDate(const QDateTime &date) -{ - d->date = date; -} - -int Message::fromId() const -{ - return d->fromId; -} - -void Message::setFromId(int id) -{ - d->fromId = id; -} - -int Message::toId() const -{ - return d->toId; -} - -void Message::setToId(int id) -{ - d->toId = id; -} - -int Message::chatId() const -{ - return d->chatId; -} - -void Message::setChatId(int chatId) -{ - d->chatId = chatId; -} - -QString Message::subject() const -{ - return d->subject; -} - -void Message::setSubject(const QString &title) -{ - d->subject = title; -} - -QString Message::body() const -{ - return d->body; -} - -void Message::setBody(const QString &body) -{ - d->body = body; -} - -bool Message::isUnread() const -{ - return testFlag(FlagUnread); -} - -void Message::setUnread(bool set) -{ - setFlag(FlagUnread, set); -} - -bool Message::isIncoming() const -{ - return !testFlag(FlagOutbox); -} - -void Message::setIncoming(bool set) -{ - setFlag(FlagOutbox, !set); -} - -void Message::setFlags(Message::Flags flags) -{ - d->flags = flags; -} - -Message::Flags Message::flags() const -{ - return d->flags; -} - -void Message::setFlag(Flag flag, bool set) -{ - d->setFlag(flag, set); -} - -bool Message::testFlag(Flag flag) const -{ - return d->flags.testFlag(flag); -} - -Attachment::Hash Message::attachments() const -{ - return d->attachmentHash; -} - -Attachment::List Message::attachments(Attachment::Type type) const -{ - return d->attachmentHash.values(type); -} - -void Message::setAttachments(const Attachment::List &attachmentList) -{ - d->attachmentHash = Attachment::toHash(attachmentList); -} - -MessageList Message::fromVariantList(const QVariantList &list, Vreen::Client *client) -{ - return fromVariantList(list, client->id()); -} - -MessageList Message::fromVariantList(const QVariantList &list, int clientId) -{ - MessageList messageList; - foreach (auto item, list) { - Vreen::Message message(item.toMap(), clientId); - messageList.append(message); - } - return messageList; -} - -} // namespace Vreen - -#include "moc_message.cpp" diff --git a/3rdparty/vreen/vreen/src/api/message.h b/3rdparty/vreen/vreen/src/api/message.h deleted file mode 100644 index 8b4f4662d..000000000 --- a/3rdparty/vreen/vreen/src/api/message.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_MESSAGE_H -#define VK_MESSAGE_H -#include -#include -#include "attachment.h" - -namespace Vreen { - -class Contact; -class Message; -typedef QList MessageList; - -class Client; -class MessageData; -class VK_SHARED_EXPORT Message -{ - Q_GADGET - Q_ENUMS(ReadState) - Q_ENUMS(Direction) - Q_ENUMS(Flags) -public: - enum Flag { - FlagUnread = 1, - FlagOutbox = 2, - FlagReplied = 4, - FlagImportant= 8, - FlagChat = 16, - FlagFriends = 32, - FlagSpam = 64, - FlagDeleted = 128, - FlagFixed = 256, - FlagMedia = 512 - }; - Q_DECLARE_FLAGS(Flags, Flag) - enum Filter { - FilterNone = 0, - FilterUnread = 1, - FilterNotFromChat = 2, - FilterFromFriends = 4 - }; - - Message(int clientId); - Message(const QVariantMap &data, int clientId); - Message(Client *client = 0); - Message(const QVariantMap &data, Client *client); - Message(const Message &other); - Message &operator =(const Message &other); - bool operator ==(const Message &other); - virtual ~Message(); - - int id() const; - void setId(int id); - QDateTime date() const; - void setDate(const QDateTime &date); - int fromId() const; - void setFromId(int id); - int toId() const; - void setToId(int id); - int chatId() const; - void setChatId(int chatId); - QString subject() const; - void setSubject(const QString &subject); - QString body() const; - void setBody(const QString &body); - bool isUnread() const; - void setUnread(bool set); - bool isIncoming() const; - void setIncoming(bool set); - void setFlags(Flags flags); - Flags flags() const; - void setFlag(Flag flag, bool set = true); - bool testFlag(Flag flag) const; - Attachment::Hash attachments() const; - Attachment::List attachments(Attachment::Type type) const; - void setAttachments(const Attachment::List &attachmentList); - - static MessageList fromVariantList(const QVariantList &list, Client *client); - static MessageList fromVariantList(const QVariantList &list, int clientId); -private: - QSharedDataPointer d; -}; - -typedef QList IdList; - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::Message) -Q_DECLARE_METATYPE(Vreen::MessageList) -Q_DECLARE_METATYPE(Vreen::IdList) -Q_DECLARE_OPERATORS_FOR_FLAGS(Vreen::Message::Flags) - -#endif // VK_MESSAGE_H - diff --git a/3rdparty/vreen/vreen/src/api/messagemodel.cpp b/3rdparty/vreen/vreen/src/api/messagemodel.cpp deleted file mode 100644 index a87c2d418..000000000 --- a/3rdparty/vreen/vreen/src/api/messagemodel.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "messagemodel.h" -#include "contact.h" -#include "longpoll.h" -#include "utils.h" -#include "utils_p.h" -#include "client.h" -#include -#include -#include - -namespace Vreen { - -class MessageListModel; -class MessageListModelPrivate -{ - Q_DECLARE_PUBLIC(MessageListModel) -public: - MessageListModelPrivate(MessageListModel *q) : q_ptr(q), - messageComparator(Qt::DescendingOrder) {} - MessageListModel *q_ptr; - QPointer client; - - MessageList messageList; - IdComparator messageComparator; -}; - - -MessageListModel::MessageListModel(QObject *parent) : - QAbstractListModel(parent), - d_ptr(new MessageListModelPrivate(this)) -{ - auto roles = roleNames(); - roles[SubjectRole] = "subject"; - roles[BodyRole] = "body"; - roles[FromRole] = "from"; - roles[ToRole] = "to"; - roles[ReadStateRole] = "unread"; - roles[DirectionRole] = "incoming"; - roles[DateRole] = "date"; - roles[IdRole] = "mid"; - roles[AttachmentRole] = "attachments"; - roles[ChatIdRole] = "chatId"; - setRoleNames(roles); -} - -MessageListModel::~MessageListModel() -{ - -} - -int MessageListModel::count() const -{ - return d_func()->messageList.count(); -} - -Message MessageListModel::at(int index) const -{ - return d_func()->messageList.at(index); -} - -int MessageListModel::findMessage(int id) -{ - Q_D(MessageListModel); - for (int index = 0; index != d->messageList.count(); index++) - if (d->messageList.at(index).id() == id) - return index; - return -1; -} - - -QVariant MessageListModel::data(const QModelIndex &index, int role) const -{ - Q_D(const MessageListModel); - - int row = index.row(); - auto message = d->messageList.at(row); - switch (role) { - case SubjectRole: - return message.subject(); - break; - case BodyRole: - return fromHtmlEntities(message.body()); - case FromRole: - return QVariant::fromValue(d->client->contact(message.fromId())); - case ToRole: - return QVariant::fromValue(d->client->contact(message.toId())); - case ReadStateRole: - return message.isUnread(); - case DirectionRole: - return message.isIncoming(); - case DateRole: - return message.date(); - case IdRole: - return message.id(); - case AttachmentRole: - return Attachment::toVariantMap(message.attachments()); - case ChatIdRole: - return message.chatId(); - default: - break; - } - return QVariant::Invalid; -} - -int MessageListModel::rowCount(const QModelIndex &) const -{ - return count(); -} - -void MessageListModel::setSortOrder(Qt::SortOrder order) -{ - Q_D(MessageListModel); - if (d->messageComparator.sortOrder != order) { - sort(0, order); - emit sortOrderChanged(order); - } -} - -Qt::SortOrder MessageListModel::sortOrder() const -{ - return d_func()->messageComparator.sortOrder; -} - -void MessageListModel::setClient(Client *client) -{ - Q_D(MessageListModel); - if (d->client != client) { - d->client = client; - emit clientChanged(client); - - if (d->client) { - auto longPoll = d->client.data()->longPoll(); - connect(longPoll, SIGNAL(messageFlagsReplaced(int, int, int)), SLOT(replaceMessageFlags(int, int, int))); - connect(longPoll, SIGNAL(messageFlagsReseted(int,int,int)), SLOT(resetMessageFlags(int,int))); - } - if (client) - client->disconnect(this); - } -} - -Client *MessageListModel::client() const -{ - return d_func()->client.data(); -} - -void MessageListModel::addMessage(const Message &message) -{ - Q_D(MessageListModel); - int index = findMessage(message.id()); - if (index != -1) - return; - - index = lowerBound(d->messageList, message, d->messageComparator); - doInsertMessage(index, message); -} - -void MessageListModel::removeMessage(const Message &message) -{ - Q_D(MessageListModel); - int index = d->messageList.indexOf(message); - if (index == -1) - return; - doRemoveMessage(index); -} - -void MessageListModel::removeMessage(int id) -{ - int index = findMessage(id); - if (index != -1) - doRemoveMessage(index); -} - -void MessageListModel::setMessages(const MessageList &messages) -{ - clear(); - foreach (auto message, messages) { - addMessage(message); - qApp->processEvents(QEventLoop::ExcludeUserInputEvents); - } -} - -void MessageListModel::clear() -{ - Q_D(MessageListModel); - beginRemoveRows(QModelIndex(), 0, d->messageList.count()); - d->messageList.clear(); - endRemoveRows(); -} - -void MessageListModel::doReplaceMessage(int i, const Message &message) -{ - auto index = createIndex(i, 0); - d_func()->messageList[i] = message; - emit dataChanged(index, index); -} - -void MessageListModel::doInsertMessage(int index, const Message &message) -{ - Q_D(MessageListModel); - beginInsertRows(QModelIndex(), index, index); - d->messageList.insert(index, message); - endInsertRows(); -} - -void MessageListModel::doRemoveMessage(int index) -{ - Q_D(MessageListModel); - beginRemoveRows(QModelIndex(), index, index); - d->messageList.removeAt(index); - endRemoveRows(); -} - -void MessageListModel::moveMessage(int sourceIndex, int destinationIndex) -{ - Q_D(MessageListModel); - beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, - QModelIndex(), destinationIndex); - d->messageList.move(sourceIndex, destinationIndex); - endMoveRows(); -} - -void MessageListModel::sort(int column, Qt::SortOrder order) -{ - Q_D(MessageListModel); - Q_UNUSED(column); - d->messageComparator.sortOrder = order; - qStableSort(d->messageList.begin(), d->messageList.end(), d->messageComparator); - emit dataChanged(createIndex(0, 0), createIndex(d->messageList.count(), 0)); -} - -void MessageListModel::replaceMessageFlags(int id, int mask, int userId) -{ - Q_UNUSED(userId); - int index = findMessage(id); - if (index == -1) - return; - - auto message = at(index); - Message::Flags flags = message.flags(); - flags |= static_cast(mask); - message.setFlags(flags); - doReplaceMessage(index, message); -} - -void MessageListModel::resetMessageFlags(int id, int mask, int userId) -{ - Q_UNUSED(userId); - int index = findMessage(id); - if (index == -1) - return; - - auto message = at(index); - auto flags = message.flags(); - flags &= ~mask; - message.setFlags(flags); - doReplaceMessage(index, message); -} - -} //namespace Vreen - -#include "moc_messagemodel.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/messagemodel.h b/3rdparty/vreen/vreen/src/api/messagemodel.h deleted file mode 100644 index 21e61a558..000000000 --- a/3rdparty/vreen/vreen/src/api/messagemodel.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef MESSAGEMODEL_H -#define MESSAGEMODEL_H - -#include -#include "message.h" - -namespace Vreen { - -class MessageListModelPrivate; -class VK_SHARED_EXPORT MessageListModel : public QAbstractListModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(MessageListModel) - Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged) - Q_PROPERTY(Vreen::Client* client READ client WRITE setClient NOTIFY clientChanged) -public: - - enum Roles { - SubjectRole = Qt::UserRole + 1, - BodyRole, - FromRole, - ToRole, - ReadStateRole, - DirectionRole, - DateRole, - IdRole, - ChatIdRole, - AttachmentRole - }; - - MessageListModel(QObject *parent = 0); - virtual ~MessageListModel(); - int count() const; - Message at(int index) const; - int findMessage(int id); - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual int rowCount(const QModelIndex &parent) const; - void setSortOrder(Qt::SortOrder order); - Qt::SortOrder sortOrder() const; - void setClient(Client *client); - Client *client() const; -signals: - void sortOrderChanged(Qt::SortOrder order); - void clientChanged(Vreen::Client*); -public slots: - void addMessage(const Vreen::Message &message); - void removeMessage(const Vreen::Message &message); - void removeMessage(int id); - void setMessages(const Vreen::MessageList &messages); - void clear(); -protected: - virtual void doReplaceMessage(int index, const::Vreen::Message &message); - virtual void doInsertMessage(int index, const::Vreen::Message &message); - virtual void doRemoveMessage(int index); - void moveMessage(int sourceIndex, int destinationIndex); - virtual void sort(int column, Qt::SortOrder order); -protected slots: - void replaceMessageFlags(int id, int mask, int userId = 0); - void resetMessageFlags(int id, int mask, int userId = 0); -private: - QScopedPointer d_ptr; -}; - -} //namespace Vreen - -#endif // MESSAGEMODEL_H - diff --git a/3rdparty/vreen/vreen/src/api/messagesession.cpp b/3rdparty/vreen/vreen/src/api/messagesession.cpp deleted file mode 100644 index 44bb5a2ef..000000000 --- a/3rdparty/vreen/vreen/src/api/messagesession.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "messagesession_p.h" -#include "client.h" -#include "utils_p.h" - -namespace Vreen { - -MessageSession::MessageSession(MessageSessionPrivate *data) : - QObject(data->client), - d_ptr(data) -{ -} -MessageSession::~MessageSession() -{ -} - -Client *MessageSession::client() const -{ - return d_func()->client; -} - -int MessageSession::uid() const -{ - return d_func()->uid; -} - -QString MessageSession::title() const -{ - return d_func()->title; -} - -void MessageSession::setTitle(const QString &title) -{ - Q_D(MessageSession); - if (d->title != title) { - d->title = title; - emit titleChanged(title); - } -} - -ReplyBase *MessageSession::getHistory(int count, int offset) -{ - auto reply = doGetHistory(count, offset); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_history_received(QVariant))); - return reply; -} - -SendMessageReply *MessageSession::sendMessage(const QString &body, const QString &subject) -{ - Q_D(MessageSession); - Message msg(d->client); - msg.setToId(d->uid); - msg.setBody(body); - msg.setSubject(subject); - return sendMessage(msg); -} - -SendMessageReply *MessageSession::sendMessage(const Message &message) -{ - return doSendMessage(message); -} - -Reply *MessageSession::markMessagesAsRead(IdList ids, bool set) -{ - Q_D(MessageSession); - QString request = set ? "messages.markAsRead" - : "messages.markAsNew"; - QVariantMap args; - args.insert("mids", join(ids)); - auto reply = d->client->request(request, args); - reply->setProperty("mids", qVariantFromValue(ids)); - reply->setProperty("set", set); - return reply; -} - -void MessageSessionPrivate::_q_history_received(const QVariant &) -{ - Q_Q(MessageSession); - auto reply = static_cast*>(q->sender()); - foreach (auto message, reply->result()) - emit q->messageAdded(message); -} - -} // namespace Vreen - -#include "moc_messagesession.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/messagesession.h b/3rdparty/vreen/vreen/src/api/messagesession.h deleted file mode 100644 index 81428f8da..000000000 --- a/3rdparty/vreen/vreen/src/api/messagesession.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_MESSAGESESSION_H -#define VK_MESSAGESESSION_H - -#include -#include "message.h" -#include "client.h" - -namespace Vreen { - -class Message; -class Client; -class MessageSessionPrivate; - -class VK_SHARED_EXPORT MessageSession : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(MessageSession) - - Q_PROPERTY(int uid READ uid CONSTANT) - Q_PROPERTY(Client* client READ client CONSTANT) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) -public: - explicit MessageSession(MessageSessionPrivate *data); - virtual ~MessageSession(); - Client *client() const; - int uid() const; - QString title() const; -public slots: - ReplyBase *getHistory(int count = 16, int offset = 0); - SendMessageReply *sendMessage(const QString &body, const QString &subject = QString()); - SendMessageReply *sendMessage(const Message &message); - Reply *markMessagesAsRead(IdList ids, bool set = true); - void setTitle(const QString &title); -signals: - void messageAdded(const Vreen::Message &message); - void messageDeleted(int id); - void messageReadStateChanged(int mid, bool isRead); - void titleChanged(const QString &title); -protected: - virtual SendMessageReply *doSendMessage(const Vreen::Message &message) = 0; - virtual ReplyBase *doGetHistory(int count, int offset) = 0; - QScopedPointer d_ptr; -private: - Q_PRIVATE_SLOT(d_func(), void _q_history_received(const QVariant &)) -}; - -} // namespace Vreen - -#endif // VK_MESSAGESESSION_H - diff --git a/3rdparty/vreen/vreen/src/api/messagesession_p.h b/3rdparty/vreen/vreen/src/api/messagesession_p.h deleted file mode 100644 index f48d57565..000000000 --- a/3rdparty/vreen/vreen/src/api/messagesession_p.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef MESSAGESESSION_P_H -#define MESSAGESESSION_P_H -#include "messagesession.h" -#include "longpoll.h" - -namespace Vreen { - -class MessageSession; -class MessageSessionPrivate -{ - Q_DECLARE_PUBLIC(MessageSession) -public: - MessageSessionPrivate(MessageSession *q, Client *client, int uid) : - q_ptr(q), client(client), uid(uid) {} - MessageSession *q_ptr; - Client *client; - int uid; - QString title; - - void _q_history_received(const QVariant &); -}; - -} //namespace Vreen - -#endif // MESSAGESESSION_P_H - diff --git a/3rdparty/vreen/vreen/src/api/newsfeed.cpp b/3rdparty/vreen/vreen/src/api/newsfeed.cpp deleted file mode 100644 index 6b893d774..000000000 --- a/3rdparty/vreen/vreen/src/api/newsfeed.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "newsfeed.h" -#include "utils.h" -#include "client.h" -#include "roster.h" -#include "groupmanager.h" -#include - -namespace Vreen { - -static const char *filters_str[] = { - "post", - "photo", - "photo_tag", - "friend", - "note" -}; - -class NewsFeed; -class NewsFeedPrivate -{ - Q_DECLARE_PUBLIC(NewsFeed) -public: - NewsFeedPrivate(NewsFeed *q, Client *client) : q_ptr(q), client(client) {} - NewsFeed *q_ptr; - Client *client; - - void updateProfiles(const QVariantList &profiles) - { - foreach (auto item, profiles) { - auto map = item.toMap(); - int uid = map.value("uid").toInt(); - - if (uid > 0) { - auto roster = client->roster(); - auto buddy = roster->buddy(uid); - Contact::fill(buddy, map); - } else { - auto manager = client->groupManager(); - auto group = manager->group(-uid); - Contact::fill(group, map); - } - } - } - - void updateGroups(const QVariantList &groups) - { - foreach (auto item, groups) { - auto map = item.toMap(); - auto manager = client->groupManager(); - int gid = -map.value("gid").toInt(); - auto contact = manager->group(gid); - Contact::fill(contact, map); - } - } - - void _q_news_received(const QVariant &response) - { - Q_Q(NewsFeed); - auto map = response.toMap(); - updateProfiles(map.value("profiles").toList()); - updateGroups(map.value("groups").toList()); - - auto items = map.value("items").toList(); - NewsItemList news; - foreach (auto item, items) { - auto newsItem = NewsItem::fromData(item); - auto map = item.toMap(); - auto itemCount = strCount(filters_str); - for (size_t i = 0; i != itemCount; i++) { - auto list = map.value(filters_str[i]).toList(); - if (list.count()) { - auto count = list.takeFirst().toInt(); - Q_UNUSED(count); - newsItem.setAttachments(Attachment::fromVariantList(list)); - break; - } - } - news.append(newsItem); - } - emit q->newsReceived(news); - } -}; - -/*! - * \brief The NewsFeed class - * Api reference: \link http://vk.com/developers.php?oid=-1&p=Расширенные_методы_API - */ - -/*! - * \brief NewsFeed::NewsFeed - * \param client - */ -NewsFeed::NewsFeed(Client *client) : - QObject(client), - d_ptr(new NewsFeedPrivate(this, client)) -{ - -} - -NewsFeed::~NewsFeed() -{ - -} - -/*! - * \brief NewsFeed::getNews API reference is \link http://vk.com/developers.php?oid=-1&p=newsfeed.get - * \return - */ -Reply *NewsFeed::getNews(Filters filters, quint8 count, int offset) -{ - QVariantMap args; - args.insert("count", count); - args.insert("filters", flagsToStrList(filters, filters_str).join(",")); - args.insert("offset", offset); - - auto reply = d_func()->client->request("newsfeed.get", args); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_news_received(QVariant))); - return reply; -} - -} //namespace Vreen - -#include "moc_newsfeed.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/newsfeed.h b/3rdparty/vreen/vreen/src/api/newsfeed.h deleted file mode 100644 index 008b0e4ab..000000000 --- a/3rdparty/vreen/vreen/src/api/newsfeed.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef NEWSFEED_H -#define NEWSFEED_H -#include -#include "newsitem.h" -#include - -namespace Vreen { - -class NewsFeedPrivate; -class Client; -class Reply; - -class VK_SHARED_EXPORT NewsFeed : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(NewsFeed) - Q_ENUMS(Filter) -public: - - enum Filter { - FilterNone = 0, - FilterPost = 0x01, - FilterPhoto = 0x02, - FilterPhotoTag = 0x04, - FilterFriend = 0x08, - FilterNote = 0x10 - }; - Q_DECLARE_FLAGS(Filters, Filter) - - NewsFeed(Client *client); - virtual ~NewsFeed(); -public slots: - Reply *getNews(Filters filters = FilterNone, quint8 count = 25, int offset = 0); -signals: - void newsReceived(const Vreen::NewsItemList &list); -private: - QScopedPointer d_ptr; - - Q_PRIVATE_SLOT(d_func(), void _q_news_received(QVariant)) -}; - -} //namespace Vreen - -Q_DECLARE_OPERATORS_FOR_FLAGS(Vreen::NewsFeed::Filters) - -#endif // NEWSFEED_H - diff --git a/3rdparty/vreen/vreen/src/api/newsitem.cpp b/3rdparty/vreen/vreen/src/api/newsitem.cpp deleted file mode 100644 index cca110233..000000000 --- a/3rdparty/vreen/vreen/src/api/newsitem.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licees/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "newsitem.h" -#include "utils.h" -#include "utils_p.h" -#include -#include -#include - -namespace Vreen { - -class NewsItemData : public QSharedData { -public: - NewsItemData() : QSharedData() {} - NewsItemData(const NewsItemData &o) : QSharedData(o), - body(o.body), - data(o.data), - likes(o.likes), - reposts(o.reposts), - attachmentHash(o.attachmentHash) - {} - - QString body; - - QVariantMap data; - QVariantMap likes; - QVariantMap reposts; - Attachment::Hash attachmentHash; -}; - -QDataStream &operator <<(QDataStream &out, const NewsItem &item) -{ - auto &d = item.d; - return out << d->body - << d->data - << d->likes - << d->reposts - << d->attachmentHash.values(); -} - -QDataStream &operator >>(QDataStream &out, NewsItem &item) -{ - auto &d = item.d; - Attachment::List list; - out >> d->body - >> d->data - >> d->likes - >> d->reposts - >> list; - d->attachmentHash = Attachment::toHash(list); - return out; -} - -const static QStringList types = QStringList() - << "post" - << "photo" - << "photo_tag" - << "friend" - << "note"; - -/*! - * \brief The NewsItem class - * Api reference: \link http://vk.com/developers.php?oid=-1&p=newsfeed.get - */ - -/*! - * \brief NewsItem::NewsItem - */ - -NewsItem::NewsItem() : d(new NewsItemData) -{ -} - -NewsItem::NewsItem(const QVariantMap &data) : d(new NewsItemData) -{ - setData(data); -} - -NewsItem::NewsItem(const NewsItem &rhs) : d(rhs.d) -{ -} - -NewsItem &NewsItem::operator=(const NewsItem &rhs) -{ - if (this != &rhs) - d.operator=(rhs.d); - return *this; -} - -NewsItem::~NewsItem() -{ -} - -NewsItem NewsItem::fromData(const QVariant &data) -{ - return NewsItem(data.toMap()); -} - -void NewsItem::setData(const QVariantMap &data) -{ - d->data = data; - d->body = fromHtmlEntities(d->data.take("text").toString()); - d->likes = d->data.take("likes").toMap(); - d->reposts = d->data.take("reposts").toMap(); - auto attachmentList = Attachment::fromVariantList(d->data.take("attachments").toList()); - setAttachments(attachmentList); - -} - -Attachment::Hash NewsItem::attachments() const -{ - return d->attachmentHash; -} - -Attachment::List NewsItem::attachments(Attachment::Type type) const -{ - return d->attachmentHash.values(type); -} - -void NewsItem::setAttachments(const Attachment::List &attachmentList) -{ - d->attachmentHash = Attachment::toHash(attachmentList); -} - -NewsItem::Type NewsItem::type() const -{ - return static_cast(types.indexOf(d->data.value("type").toString())); -} - -void NewsItem::setType(NewsItem::Type type) -{ - d->data.insert("type", types.value(type)); -} - -int NewsItem::postId() const -{ - return d->data.value("post_id").toInt(); -} - -void NewsItem::setPostId(int postId) -{ - d->data.insert("post_id", postId); -} - -int NewsItem::sourceId() const -{ - return d->data.value("source_id").toInt(); -} - -void NewsItem::setSourceId(int sourceId) -{ - d->data.insert("source_id", sourceId); -} - -QString NewsItem::body() const -{ - return d->body; -} - -void NewsItem::setBody(const QString &body) -{ - d->body = body; -} - -QDateTime NewsItem::date() const -{ - return QDateTime::fromTime_t(d->data.value("date").toInt()); -} - -void NewsItem::setDate(const QDateTime &date) -{ - d->data.insert("date", date.toTime_t()); -} - -QVariant NewsItem::property(const QString &name, const QVariant &def) const -{ - return d->data.value(name, def); -} - -QStringList NewsItem::dynamicPropertyNames() const -{ - return d->data.keys(); -} - -void NewsItem::setProperty(const QString &name, const QVariant &value) -{ - d->data.insert(name, value); -} - -QVariantMap NewsItem::likes() const -{ - return d->likes; -} - -void NewsItem::setLikes(const QVariantMap &likes) -{ - d->likes = likes; -} - -QVariantMap NewsItem::reposts() const -{ - return d->reposts; -} - -void NewsItem::setReposts(const QVariantMap &reposts) -{ - d->reposts = reposts; -} - -} // namespace Vreen - -#include "moc_newsitem.cpp" diff --git a/3rdparty/vreen/vreen/src/api/newsitem.h b/3rdparty/vreen/vreen/src/api/newsitem.h deleted file mode 100644 index ac027774f..000000000 --- a/3rdparty/vreen/vreen/src/api/newsitem.h +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_NEWSITEM_H -#define VK_NEWSITEM_H - -#include -#include -#include "attachment.h" - -namespace Vreen { - -class NewsItemData; - -class VK_SHARED_EXPORT NewsItem -{ - Q_GADGET - Q_ENUMS(Type) -public: - - enum Type { - Post, - Photo, - PhotoTag, - Note, - Invalid = -1 - }; - - NewsItem(); - NewsItem(const NewsItem &); - NewsItem &operator=(const NewsItem &); - ~NewsItem(); - - static NewsItem fromData(const QVariant &data); - - Attachment::Hash attachments() const; - Attachment::List attachments(Attachment::Type type) const; - void setAttachments(const Attachment::List &attachmentList); - Type type() const; - void setType(Type type); - int postId() const; - void setPostId(int postId); - int sourceId() const; - void setSourceId(int sourceId); - QString body() const; - void setBody(const QString &body); - QDateTime date() const; - void setDate(const QDateTime &date); - QVariantMap likes() const; - void setLikes(const QVariantMap &likes); - QVariantMap reposts() const; - void setReposts(const QVariantMap &reposts); - - QVariant property(const QString &name, const QVariant &def = QVariant()) const; - template - T property(const char *name, const T &def) const - { return QVariant::fromValue(property(name, QVariant::fromValue(def))); } - void setProperty(const QString &name, const QVariant &value); - QStringList dynamicPropertyNames() const; - - VK_SHARED_EXPORT friend QDataStream &operator <<(QDataStream &out, const Vreen::NewsItem &item); - VK_SHARED_EXPORT friend QDataStream &operator >>(QDataStream &out, Vreen::NewsItem &item); -protected: - NewsItem(const QVariantMap &data); - void setData(const QVariantMap &data); -private: - QSharedDataPointer d; -}; -typedef QList NewsItemList; - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::NewsItem) -Q_DECLARE_METATYPE(Vreen::NewsItemList) - -#endif // VK_NEWSITEM_H - diff --git a/3rdparty/vreen/vreen/src/api/pollitem.cpp b/3rdparty/vreen/vreen/src/api/pollitem.cpp deleted file mode 100644 index 4fc0d8bf9..000000000 --- a/3rdparty/vreen/vreen/src/api/pollitem.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licees/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "pollitem.h" -#include -#include - -namespace Vreen { - -template<> -PollItem Attachment::to(const Attachment &data) -{ - PollItem item; - item.setPollId(data.property("poll_id").toInt()); - item.setQuestion(data.property("question").toString()); - return item; -} - -class PollItemData : public QSharedData { -public: - PollItemData() : - ownerId(0), pollId(0), votes(0), answerId(0) {} - PollItemData(const PollItemData &o) : QSharedData(o), - ownerId(o.ownerId), pollId(o.pollId), created(o.created), - question(o.question), votes(o.votes), answerId(o.answerId), - answers(o.answers) - {} - - int ownerId; - int pollId; - QDateTime created; - QString question; - int votes; - int answerId; - PollItem::AnswerList answers; -}; - -PollItem::PollItem(int pollId) : data(new PollItemData) -{ - data->pollId = pollId; -} - -PollItem::PollItem(const PollItem &rhs) : data(rhs.data) -{ -} - -PollItem &PollItem::operator=(const PollItem &rhs) -{ - if (this != &rhs) - data.operator=(rhs.data); - return *this; -} - -PollItem::~PollItem() -{ -} - -int PollItem::ownerId() const -{ - return data->ownerId; -} - -void PollItem::setOwnerId(int ownerId) -{ - data->ownerId = ownerId; -} - -int PollItem::pollId() const -{ - return data->pollId; -} - -void PollItem::setPollId(int pollId) -{ - data->pollId = pollId; -} - -QDateTime PollItem::created() const -{ - return data->created; -} - -void PollItem::setCreated(const QDateTime &created) -{ - data->created = created; -} - -QString PollItem::question() const -{ - return data->question; -} - -void PollItem::setQuestion(const QString &question) -{ - data->question = question; -} - -int PollItem::votes() const -{ - return data->votes; -} - -void PollItem::setVotes(int votes) -{ - data->votes = votes; -} - -int PollItem::answerId() const -{ - return data->answerId; -} - -void PollItem::setAnswerId(int answerId) -{ - data->answerId = answerId; -} - -PollItem::AnswerList PollItem::answers() const -{ - return data->answers; -} - -void PollItem::setAnswers(const PollItem::AnswerList &answers) -{ - data->answers = answers; -} - -} //namespace Vreen diff --git a/3rdparty/vreen/vreen/src/api/pollitem.h b/3rdparty/vreen/vreen/src/api/pollitem.h deleted file mode 100644 index 0317ad065..000000000 --- a/3rdparty/vreen/vreen/src/api/pollitem.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licees/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef POLLITEM_H -#define POLLITEM_H - -#include -#include -#include "attachment.h" - -namespace Vreen { - -class PollItemData; - -class VK_SHARED_EXPORT PollItem -{ -public: - struct Answer { - int id; - QString text; - int votes; - qreal rate; - }; - typedef QList AnswerList; - - PollItem(int pollId = 0); - PollItem(const PollItem &); - PollItem &operator=(const PollItem &); - ~PollItem(); - - int ownerId() const; - void setOwnerId(int ownerId); - int pollId() const; - void setPollId(int pollId); - QDateTime created() const; - void setCreated(const QDateTime &created); - QString question() const; - void setQuestion(const QString &question); - int votes() const; - void setVotes(int votes); - int answerId() const; - void setAnswerId(int answerId); - AnswerList answers() const; - void setAnswers(const AnswerList &answers); -private: - QSharedDataPointer data; -}; - -template<> -PollItem Attachment::to(const Attachment &data); - -} //namespace Vreen - -Q_DECLARE_METATYPE(Vreen::PollItem) - -#endif // POLLITEM_H diff --git a/3rdparty/vreen/vreen/src/api/pollprovider.cpp b/3rdparty/vreen/vreen/src/api/pollprovider.cpp deleted file mode 100644 index c0f7ccf32..000000000 --- a/3rdparty/vreen/vreen/src/api/pollprovider.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licees/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include -#include "client.h" -#include "pollprovider.h" -#include "pollitem.h" - -namespace Vreen { - -class PollProvider; -class PollProviderPrivate -{ - Q_DECLARE_PUBLIC(PollProvider) -public: - PollProviderPrivate(PollProvider *q, Client *client) : q_ptr(q), client(client) {} - PollProvider *q_ptr; - Client *client; - - static QVariant handlePoll(const QVariant& response) { - auto map = response.toMap(); - PollItem poll; - poll.setOwnerId(map.value("owner_id").toInt()); - poll.setPollId(map.value("poll_id").toInt()); - poll.setCreated(map.value("created").toDateTime()); - poll.setQuestion(map.value("question").toString()); - poll.setVotes(map.value("votes").toInt()); - poll.setAnswerId(map.value("answer_id").toInt()); - - PollItem::AnswerList answerList; - auto answers = map.value("answers").toList(); - foreach (auto item, answers) { - auto map = item.toMap(); - PollItem::Answer answer; - answer.id = map.value("id").toInt(); - answer.text = map.value("text").toString(); - answer.votes = map.value("votes").toInt(); - answer.rate = map.value("rate").toReal(); - answerList.append(answer); - } - poll.setAnswers(answerList); - - return QVariant::fromValue(poll); - } - -}; - -PollProvider::PollProvider(Client *client) : - QObject(client), - d_ptr(new PollProviderPrivate(this, client)) -{ -} - -PollProvider::~PollProvider() -{ -} - -PollItemReply *PollProvider::getPollById(int ownerId, int pollId) -{ - Q_D(PollProvider); - QVariantMap args; - args.insert("owner_id", ownerId); - args.insert("poll_id", pollId); - - auto reply = d->client->request("polls.getById", args, PollProviderPrivate::handlePoll); - return reply; -} - -Reply *PollProvider::addVote(int pollId, int answerId, int ownerId) -{ - Q_D(PollProvider); - QVariantMap args; - args.insert("poll_id", pollId); - args.insert("answer_id", answerId); - if (ownerId) - args.insert("owner_id", ownerId); - - auto reply = d->client->request("polls.addVote", args); - return reply; -} - -Reply *PollProvider::deleteVote(int pollId, int answerId, int ownerId) -{ - Q_D(PollProvider); - QVariantMap args; - args.insert("poll_id", pollId); - args.insert("answer_id", answerId); - if (ownerId) - args.insert("owner_id", ownerId); - - auto reply = d->client->request("polls.deleteVote", args); - return reply; -} - -} // namespace Vreen diff --git a/3rdparty/vreen/vreen/src/api/pollprovider.h b/3rdparty/vreen/vreen/src/api/pollprovider.h deleted file mode 100644 index 8296ac62f..000000000 --- a/3rdparty/vreen/vreen/src/api/pollprovider.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licees/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VREEN_POLLPROVIDER_H -#define VREEN_POLLPROVIDER_H - -#include "pollitem.h" -#include "reply.h" - -namespace Vreen { - -class Client; -typedef ReplyBase PollItemReply; - -class PollProviderPrivate; -class VK_SHARED_EXPORT PollProvider : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(PollProvider) -public: - explicit PollProvider(Client *client); - ~PollProvider(); - - PollItemReply *getPollById(int ownerId, int pollId); - Reply *addVote(int pollId, int answerId, int ownerId = 0); - Reply *deleteVote(int pollId, int answerId, int ownerId = 0); -protected: - QScopedPointer d_ptr; -}; - -} // namespace Vreen - -#endif // VREEN_POLLPROVIDER_H diff --git a/3rdparty/vreen/vreen/src/api/reply.cpp b/3rdparty/vreen/vreen/src/api/reply.cpp deleted file mode 100644 index b3683df73..000000000 --- a/3rdparty/vreen/vreen/src/api/reply.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "reply_p.h" -#include -#include "client.h" -#include "message.h" - -namespace Vreen { - -Reply::Reply(QNetworkReply *reply) : - QObject(reply), - d_ptr(new ReplyPrivate(this)) -{ - setReply(reply); - - //qDebug() << "--Send reply:" << reply->url(); -} - -Reply::~Reply() -{ - //FIXME maybee it's never been used - if (auto networkReply = d_func()->networkReply.data()) - networkReply->deleteLater(); -} - -QNetworkReply *Reply::networkReply() const -{ - return d_func()->networkReply.data(); -} - -QVariant Reply::response() const -{ - return d_func()->response; -} - -QVariant Reply::error() const -{ - return d_func()->error; -} - -QVariant Reply::result() const -{ - Q_D(const Reply); - return d->result; -} - -void Reply::setReply(QNetworkReply *reply) -{ - Q_D(Reply); - if (!d->networkReply.isNull()) - d->networkReply.data()->deleteLater(); - d->networkReply = reply; - setParent(reply); - - connect(reply, SIGNAL(finished()), SLOT(_q_reply_finished())); - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(_q_network_reply_error(QNetworkReply::NetworkError))); -} - -void Reply::setHandlerImpl(Reply::ResultHandlerBase *handler) -{ - Q_D(Reply); - d->resultHandler.reset(handler); -} - -void ReplyPrivate::_q_reply_finished() -{ - Q_Q(Reply); - auto reply = static_cast(q->sender()); - QVariantMap map = JSON::parse(reply->readAll()).toMap(); - //TODO error and captcha handler - - //qDebug() << "--Reply finished: " << reply->url().encodedPath(); - - response = map.value("response"); - if (!response.isNull()) { - if (resultHandler) - result = resultHandler->handle(response); - emit q->resultReady(response); - return; - } else { - error = map.value("error"); - int errorCode = error.toMap().value("error_code").toInt(); - if (errorCode) { - emit q->error(errorCode); - emit q->resultReady(response); //emit blank response to mark reply as finished - return; - } - } - if (!map.isEmpty()) { - response = map; - emit q->resultReady(response); - } -} - -void ReplyPrivate::_q_network_reply_error(QNetworkReply::NetworkError code) -{ - Q_Q(Reply); - error = code; - emit q->error(Client::ErrorNetworkReply); - emit q->resultReady(response); -} - -QVariant ReplyPrivate::handleIdList(const QVariant &response) -{ - IdList ids; - auto list = response.toList(); - foreach (auto item, list) { - ids.append(item.toInt()); - } - return QVariant::fromValue(ids); -} - - -QVariant MessageListHandler::operator()(const QVariant &response) -{ - MessageList msgList; - auto list = response.toList(); - if (list.count()) { - list.removeFirst(); //remove count - msgList = Message::fromVariantList(list, clientId); - } - return QVariant::fromValue(msgList); -} - -} // namespace Vreen - -#include "moc_reply.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/reply.h b/3rdparty/vreen/vreen/src/api/reply.h deleted file mode 100644 index 09b75c8dd..000000000 --- a/3rdparty/vreen/vreen/src/api/reply.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_REPLY_H -#define VK_REPLY_H - -#include -#include -#include "vk_global.h" -#include - -class QNetworkReply; -namespace Vreen { - -class ReplyPrivate; -class VK_SHARED_EXPORT Reply : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(Reply) -public: - - class ResultHandlerBase - { - public: - virtual ~ResultHandlerBase() {} - virtual QVariant handle(const QVariant &data) = 0; - }; - - template - class ResultHandlerImpl : public ResultHandlerBase - { - public: - ResultHandlerImpl(Method method) : m_method(method) {} - QVariant handle(const QVariant &data) - { - return m_method(data); - } - private: - Method m_method; - }; - - virtual ~Reply(); - QNetworkReply *networkReply() const; - QVariant response() const; - Q_INVOKABLE QVariant error() const; - QVariant result() const; - - template - void setResultHandler(const Method &handler); -signals: - void resultReady(const QVariant &variables); - void error(int code); -protected: - explicit Reply(QNetworkReply *networkReply = 0); - void setReply(QNetworkReply *networkReply); - - QScopedPointer d_ptr; - - friend class Client; -private: - void setHandlerImpl(ResultHandlerBase *handler); - - Q_PRIVATE_SLOT(d_func(), void _q_reply_finished()) - Q_PRIVATE_SLOT(d_func(), void _q_network_reply_error(QNetworkReply::NetworkError)) -}; - - -template -void Reply::setResultHandler(const Method &handler) -{ - setHandlerImpl(new ResultHandlerImpl(handler)); -} - -template -class ReplyBase : public Reply -{ -public: - T result() const { return qvariant_cast(Reply::result()); } -protected: - template - explicit ReplyBase(Method handler, QNetworkReply *networkReply = 0) : - Reply(networkReply) - { - setResultHandler(handler); - } - friend class Client; -}; - -//some useful typedefs -typedef ReplyBase IntReply; - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::Reply*) - -#endif // VK_REPLY_H - diff --git a/3rdparty/vreen/vreen/src/api/reply_p.h b/3rdparty/vreen/vreen/src/api/reply_p.h deleted file mode 100644 index 8b3949d6f..000000000 --- a/3rdparty/vreen/vreen/src/api/reply_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef REPLY_P_H -#define REPLY_P_H -#include "reply.h" -#include "json.h" -#include "reply.h" -#include "QNetworkReply" -#include -#include -#include - -namespace Vreen { - -class ReplyPrivate -{ - Q_DECLARE_PUBLIC(Reply) -public: - ReplyPrivate(Reply *q) : q_ptr(q), resultHandler(0) {} - Reply *q_ptr; - - QPointer networkReply; - QVariant response; - QVariant error; - QScopedPointer resultHandler; - QVariant result; - - void _q_reply_finished(); - void _q_network_reply_error(QNetworkReply::NetworkError); - - static QVariant handleInt(const QVariant &response) { return response.toInt(); } - static QVariant handleIdList(const QVariant& response); -}; - - -struct MessageListHandler { - MessageListHandler(int clientId) : clientId(clientId) {} - QVariant operator()(const QVariant &response); - - int clientId; -}; - -} //namespace Vreen - -#endif // REPLY_P_H - diff --git a/3rdparty/vreen/vreen/src/api/roster.cpp b/3rdparty/vreen/vreen/src/api/roster.cpp deleted file mode 100644 index c355d95b1..000000000 --- a/3rdparty/vreen/vreen/src/api/roster.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "roster_p.h" -#include "longpoll.h" -#include "utils_p.h" - -#include -#include - -namespace Vreen { - -/*! - * \brief The Roster class - * Api reference: \link http://vk.com/developers.php?oid=-1&p=friends.get - */ - -/*! - * \brief Roster::Roster - * \param client - */ -Roster::Roster(Client *client, int uid) : - QObject(client), - d_ptr(new RosterPrivate(this, client)) -{ - Q_D(Roster); - connect(d->client->longPoll(), SIGNAL(contactStatusChanged(int, Vreen::Contact::Status)), - this, SLOT(_q_status_changed(int, Vreen::Contact::Status))); - connect(d->client, SIGNAL(onlineStateChanged(bool)), SLOT(_q_online_changed(bool))); - if (uid) - setUid(uid); -} - -Roster::~Roster() -{ - -} - -void Roster::setUid(int uid) -{ - Q_D(Roster); - if (uid) { - if (d->owner) { - if (uid == d->owner->id()) - return; - else - qDeleteAll(d->buddyHash); - } - d->owner = buddy(uid); - emit uidChanged(uid); - } else { - qDeleteAll(d->buddyHash); - emit uidChanged(uid); - } -} - -int Roster::uid() const -{ - Q_D(const Roster); - if (d->owner) - return d->owner->id(); - return 0; -} - -Buddy *Roster::owner() const -{ - return d_func()->owner; -} - -Buddy *Roster::buddy(int id) -{ - Q_D(Roster); - if (!id) { - qWarning("Contact id cannot be null!"); - return 0; - } - if (id < 0) { - id = qAbs(id); - qWarning("For groups use class GroupManager"); - } - - - auto buddy = d->buddyHash.value(id); - if (!buddy) { - if (d->owner && d->owner->id() == id) - return d->owner; - buddy = new Buddy(id, d->client); - d->addBuddy(buddy); - } - return buddy; -} - -Buddy *Roster::buddy(int id) const -{ - return d_func()->buddyHash.value(id); -} - -BuddyList Roster::buddies() const -{ - return d_func()->buddyHash.values(); -} - -QMap Roster::tags() const -{ - return d_func()->tags; -} - -void Roster::setTags(const QMap &tags) -{ - d_func()->tags = tags; - emit tagsChanged(tags); -} - -/*! - * \brief Roster::getDialogs - * \param offset - * \param count - * \param previewLength - * \return - */ -Reply *Roster::getDialogs(int offset, int count, int previewLength) -{ - QVariantMap args; - args.insert("count", count); - args.insert("offset", offset); - if (previewLength != -1) - args.insert("preview_length", previewLength); - return d_func()->client->request("messages.getDialogs", args); -} - -/*! - * \brief Roster::getMessages - * \param offset - * \param count - * \param filter - * \return - */ -Reply *Roster::getMessages(int offset, int count, Message::Filter filter) -{ - QVariantMap args; - args.insert("count", count); - args.insert("offset", offset); - args.insert("filter", filter); - return d_func()->client->request("messages.get", args); -} - -void Roster::sync(const QStringList &fields) -{ - Q_D(Roster); - //TODO rewrite with method chains with lambdas in Qt5 - QVariantMap args; - args.insert("fields", fields.join(",")); - args.insert("order", "hints"); - - d->getTags(); - d->getFriends(args); -} - -/*! - * \brief Roster::update - * \param ids - * \param fields from \link http://vk.com/developers.php?oid=-1&p=Описание_полей_параметра_fields - */ -Reply *Roster::update(const IdList &ids, const QStringList &fields) -{ - Q_D(Roster); - QVariantMap args; - args.insert("uids", join(ids)); - args.insert("fields", fields.join(",")); - auto reply = d->client->request("users.get", args); - reply->connect(reply, SIGNAL(resultReady(const QVariant&)), - this, SLOT(_q_friends_received(const QVariant&))); - return reply; -} - -Reply *Roster::update(const BuddyList &buddies, const QStringList &fields) -{ - IdList ids; - foreach (auto buddy, buddies) - ids.append(buddy->id()); - return update(ids, fields); -} - -ReplyBase *Roster::getFriendRequests(int count, int offset, FriendRequestFlags flags) -{ - Q_D(Roster); - QVariantMap args; - args.insert("count", count); - args.insert("offset", offset); - if (flags & NeedMutualFriends) - args.insert("need_mutual", true); - if (flags & NeedMessages) - args.insert("need_messages", true); - if (flags & GetOutRequests) - args.insert("out", 1); - auto reply = d->client->request>("friends.getRequests", - args, - RosterPrivate::handleGetRequests); - return reply; -} - -void RosterPrivate::getTags() -{ - Q_Q(Roster); - auto reply = client->request("friends.getLists"); - reply->connect(reply, SIGNAL(resultReady(const QVariant&)), - q, SLOT(_q_tags_received(const QVariant&))); -} - -void RosterPrivate::getOnline() -{ -} - -void RosterPrivate::getFriends(const QVariantMap &args) -{ - Q_Q(Roster); - auto reply = client->request("friends.get", args); - reply->setProperty("friend", true); - reply->setProperty("sync", true); - reply->connect(reply, SIGNAL(resultReady(const QVariant&)), - q, SLOT(_q_friends_received(const QVariant&))); -} - -void RosterPrivate::addBuddy(Buddy *buddy) -{ - Q_Q(Roster); - if (!buddy->isFriend()) { - IdList ids; - ids.append(buddy->id()); - //q->update(ids, QStringList() << VK_COMMON_FIELDS); //TODO move! - } - buddyHash.insert(buddy->id(), buddy); - emit q->buddyAdded(buddy); -} - -void RosterPrivate::appendToUpdaterQueue(Buddy *contact) -{ - if (!updaterQueue.contains(contact->id())) - updaterQueue.append(contact->id()); - if (!updaterTimer.isActive()) - updaterTimer.start(); -} - -QVariant RosterPrivate::handleGetRequests(const QVariant &response) -{ - FriendRequestList list; - foreach (auto item, response.toList()) { - QVariantMap map = item.toMap(); - FriendRequest request(map.value("uid").toInt()); - - request.setMessage(map.value("message").toString()); - IdList ids; - QVariantMap mutuals = map.value("mutual").toMap(); - foreach (auto user, mutuals.value("users").toList()) - ids.append(user.toInt()); - request.setMutualFriends(ids); - list.append(request); - } - return QVariant::fromValue(list); -} - -void RosterPrivate::_q_tags_received(const QVariant &response) -{ - Q_Q(Roster); - auto list = response.toList(); - QMap tags; - foreach (auto item, list) { - tags.insert(item.toMap().value("lid").toInt(),item.toMap().value("name").toString()); - } - q->setTags(tags); -} - -void RosterPrivate::_q_friends_received(const QVariant &response) -{ - Q_Q(Roster); - bool isFriend = q->sender()->property("friend").toBool(); - bool isSync = q->sender()->property("sync").toBool(); - auto list = response.toList(); - foreach (auto data, list) { - auto map = data.toMap(); - int id = map.value("uid").toInt(); - auto buddy = buddyHash.value(id); - if (!buddy) { - buddy = new Buddy(id, client); - Contact::fill(buddy, map); - buddy->setIsFriend(isFriend); - buddyHash[id] = buddy; - if (!isSync) - emit q->buddyAdded(buddy); - } else { - buddy->setIsFriend(isFriend); - Contact::fill(buddy, map); - if (!isSync) - emit q->buddyUpdated(buddy); - } - } - emit q->syncFinished(true); -} - -void RosterPrivate::_q_status_changed(int userId, Buddy::Status status) -{ - Q_Q(Roster); - auto buddy = q->buddy(userId); - buddy->setStatus(status); -} - -void RosterPrivate::_q_online_changed(bool set) -{ - if (!set) - foreach(auto buddy, buddyHash) - buddy->setOnline(false); -} - -void RosterPrivate::_q_updater_handle() -{ - Q_Q(Roster); - q->update(updaterQueue); - updaterQueue.clear(); -} - - -} // namespace Vreen - -#include "moc_roster.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/roster.h b/3rdparty/vreen/vreen/src/api/roster.h deleted file mode 100644 index b7bf886cb..000000000 --- a/3rdparty/vreen/vreen/src/api/roster.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_ROSTER_H -#define VK_ROSTER_H - -#include "contact.h" -#include "message.h" -#include "reply.h" -#include "friendrequest.h" -#include -#include - -namespace Vreen { -class Client; - -class RosterPrivate; -class VK_SHARED_EXPORT Roster : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(Roster) - Q_FLAGS(FriendRequestFlags) -public: - - enum NameCase { - NomCase, - GenCase, - DatCase, - AccCase, - InsCase, - AblCase - }; - - enum FriendRequestFlag { - NeedMutualFriends, - NeedMessages, - GetOutRequests - }; - Q_DECLARE_FLAGS(FriendRequestFlags, FriendRequestFlag) - - Roster(Client *client, int uid = 0); - virtual ~Roster(); - void setUid(int uid); - int uid() const; - - Buddy *owner() const; - Buddy *buddy(int id); - Buddy *buddy(int id) const; - BuddyList buddies() const; - - QMap tags() const; - void setTags(const QMap &list); - Reply *getDialogs(int offset = 0, int count = 16, int previewLength = -1); - Reply *getMessages(int offset = 0, int count = 50, Message::Filter filter = Message::FilterNone); -public slots: - void sync(const QStringList &fields = QStringList() - << VK_COMMON_FIELDS - ); - Reply *update(const IdList &ids, const QStringList &fields = QStringList() - << VK_ALL_FIELDS - ); - Reply *update(const BuddyList &buddies, const QStringList &fields = QStringList() - << VK_ALL_FIELDS - ); - ReplyBase *getFriendRequests(int count = 100, int offset = 0, FriendRequestFlags flags = NeedMessages); -signals: - void buddyAdded(Vreen::Buddy *buddy); - void buddyUpdated(Vreen::Buddy *buddy); - void buddyRemoved(int id); - void tagsChanged(const QMap &); - void syncFinished(bool success); - void uidChanged(int uid); -protected: - QScopedPointer d_ptr; - - //friend class Contact; - friend class Buddy; - //friend class Group; - - Q_PRIVATE_SLOT(d_func(), void _q_tags_received(const QVariant &response)) - Q_PRIVATE_SLOT(d_func(), void _q_friends_received(const QVariant &response)) - Q_PRIVATE_SLOT(d_func(), void _q_status_changed(int userId, Vreen::Contact::Status status)) - Q_PRIVATE_SLOT(d_func(), void _q_online_changed(bool)) - Q_PRIVATE_SLOT(d_func(), void _q_updater_handle()) -}; - -} // namespace Vreen - -Q_DECLARE_METATYPE(Vreen::Roster*) -Q_DECLARE_OPERATORS_FOR_FLAGS(Vreen::Roster::FriendRequestFlags) - -#endif // VK_ROSTER_H - diff --git a/3rdparty/vreen/vreen/src/api/roster_p.h b/3rdparty/vreen/vreen/src/api/roster_p.h deleted file mode 100644 index 8237269d9..000000000 --- a/3rdparty/vreen/vreen/src/api/roster_p.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef ROSTER_P_H -#define ROSTER_P_H -#include "roster.h" -#include "client_p.h" -#include "contact_p.h" - -namespace Vreen { - -typedef QHash BuddyHash; - -class Roster; -class RosterPrivate -{ - Q_DECLARE_PUBLIC(Roster) -public: - RosterPrivate(Roster *q, Client *client) : - q_ptr(q), client(client), owner(0) - { - updaterTimer.setInterval(5000); - updaterTimer.setSingleShot(true); - updaterTimer.connect(&updaterTimer, SIGNAL(timeout()), - q, SLOT(_q_updater_handle())); - } - - Roster *q_ptr; - Client *client; - BuddyHash buddyHash; - Buddy *owner; - QMap tags; - - //TODO i want to use Qt5 slots - //class Updater { - //public: - // typedef std::function Handler; - - // Updater(Client *client, const QVariantMap &query, const Handler &handler) : - // client(client), - // query(query), - // handler(handler) - // { - // timer.setInterval(5000); - // timer.setSingleShot(true); - // QObject::connect(&timer, &timeout, this, &handle); - // } - // inline void handle() { - // if (queue.count()) { - // handler(client.data(), queue, query); - // queue.clear(); - // } - // } - // inline void append(const IdList &items) { - // queue.append(items); - // if (!timer.isActive()) { - // timer.start(); - // } - // } - //protected: - // QPointer client; - // QVariantMap query; - // IdList queue; - // QTimer timer; - // Handler handler; - //} updater; - - //updater - QTimer updaterTimer; - IdList updaterQueue; - - void getTags(); - void getOnline(); - void getFriends(const QVariantMap &args = QVariantMap()); - void addBuddy(Buddy *contact); - void appendToUpdaterQueue(Buddy *contact); - - static QVariant handleGetRequests(const QVariant &response); - - void _q_tags_received(const QVariant &response); - void _q_friends_received(const QVariant &response); - void _q_status_changed(int userId, Vreen::Contact::Status status); - void _q_online_changed(bool); - void _q_updater_handle(); -}; - -} //namespace Vreen - -#endif // ROSTER_P_H - diff --git a/3rdparty/vreen/vreen/src/api/utils.cpp b/3rdparty/vreen/vreen/src/api/utils.cpp deleted file mode 100644 index 2000cc8c8..000000000 --- a/3rdparty/vreen/vreen/src/api/utils.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "utils.h" -#include -#include -#include - -//#define MAX_ENTITY 258 -//extern const struct QTextHtmlEntity { const char *name; quint16 code; } entities[MAX_ENTITY]; - -namespace Vreen { - -QString join(IdList ids) -{ - QString result; - if (ids.isEmpty()) - return result; - - result = QString::number(ids.takeFirst()); - foreach (auto id, ids) - result += QLatin1Literal(",") % QString::number(id); - return result; -} - -QString toCamelCase(QString string) -{ - int from = 0; - while ((from = string.indexOf("_", from)) != -1) { - auto index = from + 1; - string.remove(from, 1); - auto letter = string.at(index); - string.replace(index, 1, letter.toUpper()); - } - return string; -} - -QString fromHtmlEntities(const QString &source) -{ - //Simple hack from slashdot - QTextDocument text; - text.setHtml(source); - return text.toPlainText(); -} - -QString toHtmlEntities(const QString &source) -{ - return Qt::escape(source); -} - -} //namespace Vreen - diff --git a/3rdparty/vreen/vreen/src/api/utils.h b/3rdparty/vreen/vreen/src/api/utils.h deleted file mode 100644 index bb6afdf45..000000000 --- a/3rdparty/vreen/vreen/src/api/utils.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef UTILS_H -#define UTILS_H -#include "vk_global.h" -#include - -#include - -namespace Vreen { - -typedef QList IdList; - -template -Q_INLINE_TEMPLATE T sender_cast(QObject *sender) -{ -#ifndef QT_NO_DEBUG - Q_ASSERT(qobject_cast(sender)); -#endif - return static_cast(sender); -} - -template -Q_INLINE_TEMPLATE int strToEnum(const T &str, const char *(&strings)[N]) -{ - for(int i=0; i < N; i++) { - if(QLatin1String(strings[i]) == str) - return i; - } - return -1; -} - -template -Q_INLINE_TEMPLATE X strToEnum(const T &str, const char *(&strings)[N]) -{ - return static_cast(strToEnum(str,strings)); -} - -template -Q_INLINE_TEMPLATE QLatin1String enumToStr(int i, const char *(&strings)[N]) -{ - return QLatin1String((i < 0 || i >= N) ? 0 : strings[i]); -} - -template -Q_INLINE_TEMPLATE QStringList flagsToStrList(int i, const char *(&strings)[N]) -{ - QStringList list; - for (int pos = 0; pos < N; pos++) { - int flag = 1 << pos; - if ((flag) & i) - list.append(strings[pos]); - } - return list; -} - -template -int lowerBound(Container container, const T &value, LessThan lessThan) -{ - auto it = qLowerBound(container.constBegin(), container.constEnd(), value, lessThan); - int index = it - container.constBegin(); - return index; -} - -template -Q_INLINE_TEMPLATE size_t strCount(const char *(&)[N]) -{ - return N; -} - -template -struct ComparatorBase -{ - ComparatorBase(Method method, Qt::SortOrder order = Qt::AscendingOrder) : - method(method), - sortOrder(order) - { - - } - inline bool operator()(const Item &a, const Item &b) const - { - return operator()(method(a), method(b)); - } - inline bool operator()(const Item &a, int id) const - { - return operator()(method(a), id); - } - inline bool operator()(Value id, const Item &b) const - { - return operator()(id, method(b)); - } - inline bool operator()(Value a, Value b) const - { - return sortOrder == Qt::AscendingOrder ? a < b - : b < a; - } - - const Method method; - Qt::SortOrder sortOrder; -}; - -template -struct Comparator : public ComparatorBase -{ - typedef Value (*Method)(const Item &); - Comparator(Method method, Qt::SortOrder order = Qt::AscendingOrder) : - ComparatorBase(method, order) - { - - } -}; - -template -struct IdComparator : public Comparator -{ - IdComparator(Qt::SortOrder order = Qt::AscendingOrder) : - Comparator(id_, order) - { - - } -private: - inline static int id_(const Container &a) { return a.id(); } -}; - - -} //namespace Vreen - -#endif // UTILS_H - diff --git a/3rdparty/vreen/vreen/src/api/utils_p.h b/3rdparty/vreen/vreen/src/api/utils_p.h deleted file mode 100644 index f868e001f..000000000 --- a/3rdparty/vreen/vreen/src/api/utils_p.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2013 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef UTILS_P_H -#define UTILS_P_H -#include "utils.h" - -namespace Vreen { - -QString VK_SHARED_EXPORT join(IdList ids); -QString VK_SHARED_EXPORT toCamelCase(QString string); -QString VK_SHARED_EXPORT fromHtmlEntities(const QString &source); - -} //namespace Vreen - -#endif // UTILS_P_H diff --git a/3rdparty/vreen/vreen/src/api/vk_global.h b/3rdparty/vreen/vreen/src/api/vk_global.h deleted file mode 100644 index fa1f5e91d..000000000 --- a/3rdparty/vreen/vreen/src/api/vk_global.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef API_GLOBAL_H -#define API_GLOBAL_H - -#include - -#define VK_SHARED_EXPORT -typedef QList IdList; - -#endif // API_GLOBAL_H - diff --git a/3rdparty/vreen/vreen/src/api/vreen.pc.cmake b/3rdparty/vreen/vreen/src/api/vreen.pc.cmake deleted file mode 100644 index 595bba66b..000000000 --- a/3rdparty/vreen/vreen/src/api/vreen.pc.cmake +++ /dev/null @@ -1,12 +0,0 @@ -prefix=${CMAKE_INSTALL_PREFIX} -exec_prefix=${CMAKE_INSTALL_PREFIX}/bin -libdir=${LIB_DESTINATION} -includedir=${VREEN_PKG_INCDIR} - -Name: vreen -Description: Simple and fast Qt Binding for vk.com API -Requires: QtCore QtNetwork -Version: ${LIBRARY_VERSION} -Libs: ${VREEN_PKG_LIBS} -Cflags: -I${VREEN_PKG_INCDIR} - diff --git a/3rdparty/vreen/vreen/src/api/wallpost.cpp b/3rdparty/vreen/vreen/src/api/wallpost.cpp deleted file mode 100644 index ccfd280c4..000000000 --- a/3rdparty/vreen/vreen/src/api/wallpost.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "wallpost.h" -#include "dynamicpropertydata_p.h" -#include -#include "roster.h" -#include "client.h" -#include "utils_p.h" - -namespace Vreen { - -class WallPostData : public QSharedData -{ -public: - WallPostData() : QSharedData(), - id(0), - fromId(0), - toId(0), - ownerId(0), - signerId(0) - {} - WallPostData(const WallPostData &o) : QSharedData(o), - id(o.id), - body(o.body), - date(o.date), - fromId(o.fromId), - toId(o.toId), - ownerId(o.ownerId), - signerId(o.signerId), - copyText(o.copyText), - likes(o.likes), - reposts(o.reposts), - attachmentHash(o.attachmentHash), - data(o.data) - {} - - int id; - QString body; - QDateTime date; - int fromId; - int toId; - int ownerId; - int signerId; - QString copyText; - QVariantMap likes; - QVariantMap reposts; - Attachment::Hash attachmentHash; - QVariantMap data; -}; - -WallPost::WallPost() : - d(new WallPostData()) -{ -} - -WallPost::WallPost(QVariantMap data) : - d(new WallPostData()) -{ - d->id = data.take("id").toInt(); - d->body = fromHtmlEntities(data.take("text").toString()); - d->fromId = data.take("from_id").toInt(); - d->toId = data.take("to_id").toInt(); - d->ownerId = data.take("copy_owner_id").toInt(); - d->signerId = data.take("signer_id").toInt(); - d->copyText = fromHtmlEntities(data.take("copy_text").toString()); - d->date = QDateTime::fromTime_t(data.take("date").toUInt()); - d->likes = data.take("likes").toMap(); - d->reposts = data.take("reposts").toMap(); - setAttachments(Attachment::fromVariantList(data.take("attachments").toList())); - d->data = data; -} - -WallPost::WallPost(const WallPost &other) : d(other.d) -{ -} - -WallPost &WallPost::operator=(const WallPost &other) -{ - if (this != &other) - d.operator=(other.d); - return *this; -} - -WallPost::~WallPost() -{ -} - -void WallPost::setId(int id) -{ - d->id = id; -} - -int WallPost::id() const -{ - return d->id; -} - -void WallPost::setBody(const QString &body) -{ - d->body = body; -} - -QString WallPost::body() const -{ - return d->body; -} - -void WallPost::setFromId(int id) -{ - d->fromId = id; -} - -int WallPost::fromId() const -{ - return d->fromId; -} - -void WallPost::setToId(int id) -{ - d->toId = id; -} - -int WallPost::toId() const -{ - return d->toId; -} - -int WallPost::ownerId() const -{ - return d->ownerId; -} - -void WallPost::setOwnerId(int ownerId) -{ - d->ownerId = ownerId; -} - -void WallPost::setDate(const QDateTime &date) -{ - d->date = date; -} - -QDateTime WallPost::date() const -{ - return d->date; -} - -int WallPost::signerId() const -{ - return d->signerId; -} - -void WallPost::setSignerId(int signerId) -{ - d->signerId = signerId; -} - -QString WallPost::copyText() const -{ - return d->copyText; -} - -void WallPost::setCopyText(const QString ©Text) -{ - d->copyText = copyText; -} - -Attachment::Hash WallPost::attachments() const -{ - return d->attachmentHash; -} - -Attachment::List WallPost::attachments(Attachment::Type type) const -{ - return d->attachmentHash.values(type); -} - -void WallPost::setAttachments(const Attachment::List &list) -{ - d->attachmentHash = Attachment::toHash(list); -} - -QVariantMap WallPost::likes() const -{ - return d->likes; -} - -void WallPost::setLikes(const QVariantMap &likes) -{ - d->likes = likes; -} - -WallPost WallPost::fromData(const QVariant data) -{ - return WallPost(data.toMap()); -} - -QVariant WallPost::property(const QString &name, const QVariant &def) const -{ - return d->data.value(name, def); -} - -void WallPost::setProperty(const QString &name, const QVariant &value) -{ - d->data.insert(name, value); -} - -QStringList WallPost::dynamicPropertyNames() const -{ - return d->data.keys(); -} - -QVariantMap WallPost::reposts() const -{ - return d->reposts; -} - -void WallPost::setReposts(const QVariantMap &reposts) -{ - d->reposts = reposts; -} - - -} //namespace Vreen - diff --git a/3rdparty/vreen/vreen/src/api/wallpost.h b/3rdparty/vreen/vreen/src/api/wallpost.h deleted file mode 100644 index 6643aeac6..000000000 --- a/3rdparty/vreen/vreen/src/api/wallpost.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef WALLPOST_H -#define WALLPOST_H - -#include -#include -#include "vk_global.h" -#include "attachment.h" - -namespace Vreen { - -class WallPostData; -class Client; -class Contact; - -class VK_SHARED_EXPORT WallPost -{ -public: - WallPost(); - WallPost(const WallPost &); - WallPost &operator=(const WallPost &); - ~WallPost(); - - void setId(int id); - int id() const; - void setBody(const QString &body); - QString body() const; - void setFromId(int id); - int fromId() const; - void setToId(int id); - int toId() const; - int ownerId() const; - void setOwnerId(int ownerId); - void setDate(const QDateTime &date); - QDateTime date() const; - int signerId() const; - void setSignerId(int signerId); - QString copyText() const; - void setCopyText(const QString ©Text); - Attachment::Hash attachments() const; - Attachment::List attachments(Attachment::Type type) const; - void setAttachments(const Attachment::List &attachmentList); - QVariantMap likes() const; - void setLikes(const QVariantMap &likes); - QVariantMap reposts() const; - void setReposts(const QVariantMap &reposts); - - static WallPost fromData(const QVariant data); - - QVariant property(const QString &name, const QVariant &def = QVariant()) const; - template - T property(const char *name, const T &def) const - { return QVariant::fromValue(property(name, QVariant::fromValue(def))); } - - void setProperty(const QString &name, const QVariant &value); - QStringList dynamicPropertyNames() const; -protected: - WallPost(QVariantMap data); -private: - QSharedDataPointer d; -}; -typedef QList WallPostList; - -} //namespace Vreen - -#endif // WALLPOST_H - diff --git a/3rdparty/vreen/vreen/src/api/wallsession.cpp b/3rdparty/vreen/vreen/src/api/wallsession.cpp deleted file mode 100644 index 0388cb722..000000000 --- a/3rdparty/vreen/vreen/src/api/wallsession.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#include "wallsession.h" -#include "contact.h" -#include "wallpost.h" -#include "utils.h" -#include "client_p.h" -#include - -namespace Vreen { - -static const char *filters[] = { - "owner", - "others", - "all" -}; - -class WallSession; -class WallSessionPrivate -{ - Q_DECLARE_PUBLIC(WallSession) -public: - WallSessionPrivate(WallSession *q, Contact *contact) : q_ptr(q), contact(contact) {} - WallSession *q_ptr; - Contact *contact; - - void _q_posts_received(const QVariant &response) - { - auto list = response.toMap().value("wall").toList(); - if (!list.isEmpty()) { - list.takeFirst(); - foreach (auto item, list) { - auto post = WallPost::fromData(item); - emit q_func()->postAdded(post); - } - } - } - - void _q_like_added(const QVariant &response) - { - //FIXME error handler - auto reply = sender_cast(q_func()->sender()); - auto url = reply->networkReply()->url(); - int id = url.queryItemValue("post_id").toInt(); - int retweet = url.queryItemValue("repost").toInt(); - auto map = response.toMap(); - - emit q_func()->postLikeAdded(id, - map.value("likes").toInt(), - map.value("reposts").toInt(), - retweet); - } - - void _q_like_deleted(const QVariant &response) - { - auto reply = sender_cast(q_func()->sender()); - auto url = reply->networkReply()->url(); - int id = url.queryItemValue("post_id").toInt(); - int likesCount = response.toMap().value("likes").toInt(); - - emit q_func()->postLikeDeleted(id, likesCount); - } -}; - -WallSession::WallSession(Contact *contact) : - QObject(contact), - d_ptr(new WallSessionPrivate(this, contact)) -{ - -} - -WallSession::~WallSession() -{ - -} - -/*! - * \brief WallSession::getPosts. A wrapper on API method wall.get, \link http://vk.com/developers.php?oid=-1&p=wall.get - * \param filter determine what types of messages on the wall to get. The following parameter values​​: - * Owner - messages on the wall by its owner - * Others - posts on the wall, not on its owner - * All - all the messages on the wall - * \param count - * \param offset - * \param extended flag: true - three arrays will be returned to wall, profiles, and groups. By default, additional fields will not be returned. - * \return - */ -Reply *WallSession::getPosts(WallSession::Filter filter, quint8 count, int offset, bool extended) -{ - Q_D(WallSession); - QVariantMap args; - args.insert("owner_id", QString::number(d->contact->id())); - args.insert("offset", offset); - args.insert("count", count); - args.insert("filter", filters[filter-1]); - args.insert("extended", extended); - auto reply = d->contact->client()->request("wall.get", args); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_posts_received(QVariant))); - - return reply; -} - -Contact *WallSession::contact() const -{ - return d_func()->contact; -} - -/*! - * \brief Vreen::WallSession::like A wrapper on API method wall.addLike \link http://vk.com/developers.php?oid=-1&p=wall.addLike - * \param postId - * \param retweet - * \return - */ -Vreen::Reply *Vreen::WallSession::addLike(int postId, bool retweet, const QString &message) -{ - Q_D(WallSession); - auto reply = d->contact->client()->addLike(d->contact->id(), - postId, - retweet, - message); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_like_added(QVariant))); - return reply; -} - -/*! - * \brief WallSession::deleteLike a wrapper on API method wall.deleteLike \link http://vk.com/developers.php?oid=-1&p=wall.deleteLike - * \param postId - * \return - */ -Reply *WallSession::deleteLike(int postId) -{ - Q_D(WallSession); - auto reply = d->contact->client()->deleteLike(d->contact->id(), postId); - connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_like_deleted(QVariant))); - return reply; -} - -} // namespace Vreen - -#include "moc_wallsession.cpp" - diff --git a/3rdparty/vreen/vreen/src/api/wallsession.h b/3rdparty/vreen/vreen/src/api/wallsession.h deleted file mode 100644 index 0c99a1d30..000000000 --- a/3rdparty/vreen/vreen/src/api/wallsession.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Vreen - vk.com API Qt bindings -** -** Copyright © 2012 Aleksey Sidorov -** -***************************************************************************** -** -** $VREEN_BEGIN_LICENSE$ -** This program 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 3 of the License, or -** (at your option) any later version. -** -** This program 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 General Public License -** along with this program. If not, see http://www.gnu.org/licenses/. -** $VREEN_END_LICENSE$ -** -****************************************************************************/ -#ifndef VK_WALLSESSION_H -#define VK_WALLSESSION_H - -#include "client.h" -#include "wallpost.h" - -namespace Vreen { - -class Reply; -class WallSessionPrivate; -class VK_SHARED_EXPORT WallSession : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(WallSession) - Q_ENUMS(Filter) -public: - enum Filter { - Owner = 0x1, - Others = 0x2, - All = Owner | Others - }; - - explicit WallSession(Contact *contact); - Contact *contact() const; - virtual ~WallSession(); - -public slots: - Reply *getPosts(Filter filter = All, quint8 count = 16, int offset = 0, bool extended = false); - Reply *addLike(int postId, bool retweet = false, const QString &message = QString()); - Reply *deleteLike(int postId); -signals: - void postAdded(const Vreen::WallPost &post); - void postDeleted(int postId); - void postLikeAdded(int postId, int likesCount, int repostsCount, bool isRetweeted); - void postLikeDeleted(int postId, int likesCount); -protected: - QScopedPointer d_ptr; - - Q_PRIVATE_SLOT(d_func(), void _q_posts_received(QVariant)) - Q_PRIVATE_SLOT(d_func(), void _q_like_added(QVariant)) - Q_PRIVATE_SLOT(d_func(), void _q_like_deleted(QVariant)) -}; - -} // namespace Vreen - -#endif // VK_WALLSESSION_H - diff --git a/CMakeLists.txt b/CMakeLists.txt index c8b048f4d..bdbaab9a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,8 +211,6 @@ optional_component(BOX ON "Box support" DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" ) -optional_component(VK ON "Vk.com support") - optional_component(SEAFILE ON "Seafile support" DEPENDS "Google sparsehash" SPARSEHASH_INCLUDE_DIRS DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" @@ -288,12 +286,6 @@ if (HAVE_DBUS) find_package(Qt4 REQUIRED QtDbus) endif () -if (HAVE_VK) - add_subdirectory(3rdparty/vreen) - include_directories(${VREEN_INCLUDE_DIRS}) - include_directories(${VREENOAUTH_INCLUDE_DIRS}) -endif(HAVE_VK) - # We can include the Qt definitions now include(${QT_USE_FILE}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 76958329b..2243d4481 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1163,31 +1163,6 @@ optional_source(HAVE_BOX internet/box/boxsettingspage.ui ) -# Vk.com support -optional_source(HAVE_VK - INCLUDE_DIRECTORIES - ${VREEN_INCLUDE_DIRS} - SOURCES - globalsearch/vksearchprovider.cpp - internet/vk/vkconnection.cpp - internet/vk/vkmusiccache.cpp - internet/vk/vksearchdialog.cpp - internet/vk/vkservice.cpp - internet/vk/vksettingspage.cpp - internet/vk/vkurlhandler.cpp - HEADERS - globalsearch/vksearchprovider.h - internet/vk/vkconnection.h - internet/vk/vkmusiccache.h - internet/vk/vksearchdialog.h - internet/vk/vkservice.h - internet/vk/vksettingspage.h - internet/vk/vkurlhandler.h - UI - internet/vk/vksearchdialog.ui - internet/vk/vksettingspage.ui -) - # Seafile support optional_source(HAVE_SEAFILE SOURCES @@ -1280,10 +1255,6 @@ target_link_libraries(clementine_lib Qocoa ) -if(HAVE_VK) - target_link_libraries(clementine_lib ${VREEN_LIBRARIES}) -endif(HAVE_VK) - if(ENABLE_VISUALISATIONS) target_link_libraries(clementine_lib ${LIBPROJECTM_LIBRARIES}) endif(ENABLE_VISUALISATIONS) diff --git a/src/config.h.in b/src/config.h.in index 2bd31b705..831d74a28 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -42,11 +42,10 @@ #cmakedefine HAVE_SPARKLE #cmakedefine HAVE_SPOTIFY_DOWNLOADER #cmakedefine HAVE_UDISKS2 -#cmakedefine HAVE_VK #cmakedefine HAVE_WIIMOTEDEV #cmakedefine TAGLIB_HAS_OPUS #cmakedefine USE_INSTALL_PREFIX #cmakedefine USE_SYSTEM_PROJECTM #cmakedefine USE_SYSTEM_SHA2 -#endif // CONFIG_H_IN +#endif // CONFIG_H_IN diff --git a/src/core/metatypes.cpp b/src/core/metatypes.cpp index 00b3553d9..0894279e2 100644 --- a/src/core/metatypes.cpp +++ b/src/core/metatypes.cpp @@ -30,21 +30,17 @@ #include "engines/enginebase.h" #include "engines/gstengine.h" #include "globalsearch/searchprovider.h" -#include "internet/digitally/digitallyimportedclient.h" #include "internet/core/geolocator.h" -#include "internet/podcasts/podcastepisode.h" -#include "internet/podcasts/podcast.h" -#include "internet/somafm/somafmservice.h" +#include "internet/digitally/digitallyimportedclient.h" #include "internet/intergalacticfm/intergalacticfmservice.h" +#include "internet/podcasts/podcast.h" +#include "internet/podcasts/podcastepisode.h" +#include "internet/somafm/somafmservice.h" #include "library/directory.h" #include "playlist/playlist.h" #include "songinfo/collapsibleinfopane.h" #include "ui/equalizer.h" -#ifdef HAVE_VK -#include "internet/vk/vkservice.h" -#endif - #ifdef HAVE_DBUS #include #include "core/mpris2.h" @@ -112,11 +108,6 @@ void RegisterMetaTypes() { qRegisterMetaType("Subdirectory"); qRegisterMetaType>("QList"); -#ifdef HAVE_VK - qRegisterMetaType("MusicOwner"); - qRegisterMetaTypeStreamOperators("MusicOwner"); -#endif - #ifdef HAVE_DBUS qDBusRegisterMetaType(); qDBusRegisterMetaType(); diff --git a/src/internet/core/internetmodel.cpp b/src/internet/core/internetmodel.cpp index 65c4f88f4..fced864bd 100644 --- a/src/internet/core/internetmodel.cpp +++ b/src/internet/core/internetmodel.cpp @@ -58,9 +58,6 @@ #ifdef HAVE_BOX #include "internet/box/boxservice.h" #endif -#ifdef HAVE_VK -#include "internet/vk/vkservice.h" -#endif #ifdef HAVE_SEAFILE #include "internet/seafile/seafileservice.h" #endif @@ -114,9 +111,6 @@ InternetModel::InternetModel(Application* app, QObject* parent) #ifdef HAVE_SKYDRIVE AddService(new SkydriveService(app, this)); #endif -#ifdef HAVE_VK - AddService(new VkService(app, this)); -#endif invisibleRootItem()->sortChildren(0, Qt::AscendingOrder); UpdateServices(); diff --git a/src/internet/vk/vkconnection.cpp b/src/internet/vk/vkconnection.cpp deleted file mode 100644 index d44a65e65..000000000 --- a/src/internet/vk/vkconnection.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Vlad Maltsev - Copyright 2014, Krzysztof Sobiecki - Copyright 2014, Ivan Leontiev - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#include "vkconnection.h" - -#include -#include - -#include - -#include "core/closure.h" -#include "core/logging.h" -#include "internet/core/localredirectserver.h" -#include "vreen/utils.h" - -#include "vkservice.h" - -static const QUrl kVkOAuthEndpoint("https://oauth.vk.com/authorize"); -static const QUrl kVkOAuthTokenEndpoint("https://oauth.vk.com/access_token"); -static const QUrl kApiUrl("https://api.vk.com/method/"); -static const char* kScopeNames[] = { - "notify", "friends", "photos", "audio", "video", "docs", - "notes", "pages", "status", "offers", "questions", "wall", - "groups", "messages", "notifications", "stats", "ads", "offline"}; - -static const QString kAppID = "3421812"; -static const QString kAppSecret = "cY7KMyX46Fq3nscZlbdo"; -static const VkConnection::Scopes kScopes = - VkConnection::Offline | VkConnection::Audio | VkConnection::Friends | - VkConnection::Groups | VkConnection::Status; - -static const char* kSettingsGroup = "Vk.com/oauth"; - -VkConnection::VkConnection(QObject* parent) - : Connection(parent), - state_(Vreen::Client::StateOffline), - expires_in_(0), - uid_(0) { - loadToken(); -} - -VkConnection::~VkConnection() {} - -void VkConnection::connectToHost(const QString& login, - const QString& password) { - Q_UNUSED(login) - Q_UNUSED(password) - if (hasAccount()) { - setConnectionState(Vreen::Client::StateOnline); - } else { - setConnectionState(Vreen::Client::StateConnecting); - requestAccessToken(); - } -} - -void VkConnection::disconnectFromHost() { - clear(); - setConnectionState(Vreen::Client::StateOffline); -} - -void VkConnection::clear() { - access_token_.clear(); - expires_in_ = 0; - uid_ = 0; - - QSettings s; - s.beginGroup(kSettingsGroup); - s.remove("access_token"); - s.remove("expires_in"); - s.remove("uid"); -} - -bool VkConnection::hasAccount() { - return !access_token_.isNull() && - (expires_in_ > - static_cast(QDateTime::currentDateTime().toTime_t())); -} - -QNetworkRequest VkConnection::makeRequest(const QString& method, - const QVariantMap& args) { - QUrl url = kApiUrl; - url.setPath(url.path() % QLatin1Literal("/") % method); - for (auto it = args.constBegin(); it != args.constEnd(); ++it) { - url.addEncodedQueryItem(QUrl::toPercentEncoding(it.key()), - QUrl::toPercentEncoding(it.value().toString())); - } - url.addEncodedQueryItem("access_token", access_token_); - return QNetworkRequest(url); -} - -void VkConnection::decorateRequest(QNetworkRequest& request) { - QUrl url = request.url(); - url.addEncodedQueryItem("access_token", access_token_); - request.setUrl(url); -} - -void VkConnection::requestAccessToken() { - LocalRedirectServer* server = new LocalRedirectServer(this); - server->Listen(); - - QUrl url = kVkOAuthEndpoint; - url.addQueryItem("client_id", kAppID); - url.addQueryItem("scope", - Vreen::flagsToStrList(kScopes, kScopeNames).join(",")); - url.addQueryItem("redirect_uri", server->url().toString()); - url.addQueryItem("response_type", "code"); - - qLog(Debug) << "Try to login to Vk.com" << url; - - NewClosure(server, SIGNAL(Finished()), this, - SLOT(codeRecived(LocalRedirectServer*, QUrl)), server, - server->url()); - QDesktopServices::openUrl(url); -} - -void VkConnection::codeRecived(LocalRedirectServer* server, QUrl redirect_uri) { - if (server->request_url().hasQueryItem("code")) { - code_ = server->request_url().queryItemValue("code").toUtf8(); - QUrl url = kVkOAuthTokenEndpoint; - url.addQueryItem("client_id", kAppID); - url.addQueryItem("client_secret", kAppSecret); - url.addQueryItem("code", QString::fromUtf8(code_)); - url.addQueryItem("redirect_uri", redirect_uri.toString()); - qLog(Debug) << "Getting access token" << url; - - QNetworkRequest request(url); - QNetworkReply* reply = network_.get(request); - - NewClosure(reply, SIGNAL(finished()), this, - SLOT(accessTokenRecived(QNetworkReply*)), reply); - } else { - qLog(Error) << "Login failed" << server->request_url(); - clear(); - emit connectionStateChanged(Vreen::Client::StateOffline); - } -} - -void VkConnection::accessTokenRecived(QNetworkReply* reply) { - if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 200) { - qLog(Error) << "Failed to get access token" << reply->readAll(); - emit setConnectionState(Vreen::Client::StateOffline); - clear(); - return; - } - - QJson::Parser parser; - bool ok = false; - QByteArray reply_data = reply->readAll(); - QVariantMap result = parser.parse(reply_data, &ok).toMap(); - if (!ok) { - qLog(Error) << "Failed to parse oauth reply" << reply_data; - emit setConnectionState(Vreen::Client::StateOffline); - clear(); - return; - } - qLog(Debug) << result; - - access_token_ = result["access_token"].toByteArray(); - expires_in_ = result["expires_in"].toUInt(); - uid_ = result["user_id"].toInt(); - - if (expires_in_) { - expires_in_ += QDateTime::currentDateTime().toTime_t(); - } else { - expires_in_ += QDateTime::currentDateTime().addMonths(1).toTime_t(); - } - qLog(Debug) << "Access token expires in" << expires_in_; - - saveToken(); - setConnectionState(Vreen::Client::StateOnline); - - reply->deleteLater(); -} - -void VkConnection::setConnectionState(Vreen::Client::State state) { - if (state != state_) { - state_ = state; - emit connectionStateChanged(state); - } -} - -void VkConnection::saveToken() { - QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("access_token", access_token_); - s.setValue("expires_in", QVariant::fromValue(expires_in_)); - s.setValue("uid", uid_); -} - -void VkConnection::loadToken() { - QSettings s; - s.beginGroup(kSettingsGroup); - access_token_ = s.value("access_token").toByteArray(); - expires_in_ = s.value("expires_in").toUInt(); - uid_ = s.value("uid").toInt(); -} diff --git a/src/internet/vk/vkconnection.h b/src/internet/vk/vkconnection.h deleted file mode 100644 index 557f6aedc..000000000 --- a/src/internet/vk/vkconnection.h +++ /dev/null @@ -1,90 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Krzysztof Sobiecki - Copyright 2014, Maltsev Vlad - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef INTERNET_VK_VKCONNECTION_H_ -#define INTERNET_VK_VKCONNECTION_H_ - -#include "vreen/client.h" -#include "vreen/connection.h" - -class LocalRedirectServer; - -class VkConnection : public Vreen::Connection { - Q_OBJECT - Q_ENUMS(DisplayType) - Q_FLAGS(Scopes) - - public: - enum DisplayType { Page, Popup, Touch, Wap }; - enum Scope { - Notify = 0x1, - Friends = 0x2, - Photos = 0x4, - Audio = 0x8, - Video = 0x10, - Docs = 0x20, - Notes = 0x40, - Pages = 0x80, - Status = 0x100, - Offers = 0x200, - Questions = 0x400, - Wall = 0x800, - Groups = 0x1000, - Messages = 0x2000, - Notifications = 0x4000, - Stats = 0x8000, - Ads = 0x10000, - Offline = 0x20000 - }; - Q_DECLARE_FLAGS(Scopes, Scope) - - explicit VkConnection(QObject* parent = 0); - ~VkConnection(); - - void connectToHost(const QString& login, const QString& password); - void disconnectFromHost(); - Vreen::Client::State connectionState() const { return state_; } - int uid() const { return uid_; } - void clear(); - bool hasAccount(); - - protected: - QNetworkRequest makeRequest(const QString& method, - const QVariantMap& args = QVariantMap()); - void decorateRequest(QNetworkRequest& request); - - private slots: - void codeRecived(LocalRedirectServer* server, QUrl redirect_uri); - void accessTokenRecived(QNetworkReply* reply); - - private: - void requestAccessToken(); - void setConnectionState(Vreen::Client::State state); - void saveToken(); - void loadToken(); - QNetworkAccessManager network_; - Vreen::Client::State state_; - QByteArray code_; - QByteArray access_token_; - time_t expires_in_; - int uid_; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(VkConnection::Scopes) - -#endif // INTERNET_VK_VKCONNECTION_H_ diff --git a/src/internet/vk/vkmusiccache.cpp b/src/internet/vk/vkmusiccache.cpp deleted file mode 100644 index 62033948c..000000000 --- a/src/internet/vk/vkmusiccache.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Maltsev Vlad - Copyright 2014, Krzysztof Sobiecki - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ -#include "vkmusiccache.h" - -#include -#include - -#include "core/application.h" -#include "core/logging.h" -#include "core/taskmanager.h" -#include "vkservice.h" - -VkMusicCache::VkMusicCache(Application* app, VkService* service) - : QObject(service), - app_(app), - service_(service), - current_song_index(0), - is_downloading(false), - is_aborted(false), - task_id(0), - file_(NULL), - network_manager_(new QNetworkAccessManager), - reply_(NULL) {} - -QUrl VkMusicCache::Get(const QUrl& url) { - QUrl result; - if (InCache(url)) { - QString cached_filename = CachedFilename(url); - qLog(Info) << "Use cashed file" << cached_filename; - result = QUrl::fromLocalFile(cached_filename); - } - return result; -} - -void VkMusicCache::AddToCache(const QUrl& url, const QUrl& media_url, - bool force) { - AddToQueue(CachedFilename(url), media_url); - if (!force) { - current_song_index = queue_.size(); - } -} - -void VkMusicCache::BreakCurrentCaching() { - if (current_song_index > 0) { - // Current song in queue - queue_.removeAt(current_song_index - 1); - } else if (current_song_index == 0) { - // Current song is downloading - if (reply_) { - reply_->abort(); - is_aborted = true; - } - } -} - -/*** -* Queue operations -*/ - -void VkMusicCache::AddToQueue(const QString& filename, - const QUrl& download_url) { - DownloadItem item; - item.filename = filename; - item.url = download_url; - queue_.push_back(item); - DownloadNext(); -} - -/*** -* Downloading -*/ - -void VkMusicCache::DownloadNext() { - if (is_downloading || queue_.isEmpty()) { - return; - } else { - current_download = queue_.first(); - queue_.pop_front(); - current_song_index--; - - // Check file path and file existance first - if (QFile::exists(current_download.filename)) { - qLog(Warning) << "Tried to overwrite already cached file" - << current_download.filename; - return; - } - - // Create temporarry file we download to. - if (file_) { - qLog(Warning) << "QFile" << file_->fileName() << "is not null"; - delete file_; - file_ = NULL; - } - - file_ = new QTemporaryFile; - if (!file_->open(QFile::WriteOnly)) { - qLog(Warning) << "Can not create temporary file" << file_->fileName() - << "Download right away to" << current_download.filename; - } - - // Start downloading - is_aborted = false; - is_downloading = true; - task_id = app_->task_manager()->StartTask( - tr("Caching %1").arg(QFileInfo(current_download.filename).baseName())); - reply_ = network_manager_->get(QNetworkRequest(current_download.url)); - connect(reply_, SIGNAL(finished()), SLOT(Downloaded())); - connect(reply_, SIGNAL(readyRead()), SLOT(DownloadReadyToRead())); - connect(reply_, SIGNAL(downloadProgress(qint64, qint64)), - SLOT(DownloadProgress(qint64, qint64))); - qLog(Info) << "Start cashing" << current_download.filename << "from" - << current_download.url; - } -} - -void VkMusicCache::DownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { - if (bytesTotal) { - int progress = qRound(100 * bytesReceived / bytesTotal); - app_->task_manager()->SetTaskProgress(task_id, progress, 100); - } -} - -void VkMusicCache::DownloadReadyToRead() { - if (file_) { - file_->write(reply_->readAll()); - } else { - qLog(Warning) << "Tried to write recived song to not created file"; - } -} - -void VkMusicCache::Downloaded() { - app_->task_manager()->SetTaskFinished(task_id); - if (is_aborted || reply_->error()) { - if (reply_->error()) { - qLog(Info) << "Downloading failed" << reply_->errorString(); - } - } else { - DownloadReadyToRead(); // Save all recent recived data. - - QString path = service_->cacheDir(); - - if (file_->size() > 0) { - QDir(path).mkpath(QFileInfo(current_download.filename).path()); - if (file_->copy(current_download.filename)) { - qLog(Info) << "Cached" << current_download.filename; - } else { - qLog(Error) << "Unable to save" << current_download.filename << ":" - << file_->errorString(); - } - } else { - qLog(Error) << "File" << current_download.filename << "is empty"; - } - } - - delete file_; - file_ = NULL; - - reply_->deleteLater(); - reply_ = NULL; - - is_downloading = false; - DownloadNext(); -} - -/*** -* Utils -*/ - -bool VkMusicCache::InCache(const QUrl& url) { - return QFile::exists(CachedFilename(url)); -} - -QString VkMusicCache::CachedFilename(const QUrl& url) { - QStringList args = url.path().split('/'); - - QString cache_filename; - if (args.size() == 4) { - cache_filename = service_->cacheFilename(); - cache_filename.replace("%artist", args[2]); - cache_filename.replace("%title", args[3]); - } else { - qLog(Warning) << "Song url with args" << args - << "does not contain artist and title" - << "use id as file name for cache."; - cache_filename = args[1]; - } - - QString cache_dir = service_->cacheDir(); - if (cache_dir.isEmpty()) { - qLog(Warning) << "Cache dir not defined"; - return ""; - } - // TODO(Vk): Maybe use extenstion from link? Seems it's always mp3. - return cache_dir + QDir::separator() + cache_filename + ".mp3"; -} diff --git a/src/internet/vk/vkmusiccache.h b/src/internet/vk/vkmusiccache.h deleted file mode 100644 index 7c72d6db2..000000000 --- a/src/internet/vk/vkmusiccache.h +++ /dev/null @@ -1,79 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Maltsev Vlad - Copyright 2014, Krzysztof Sobiecki - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef INTERNET_VK_VKMUSICCACHE_H_ -#define INTERNET_VK_VKMUSICCACHE_H_ - -#include -#include -#include -#include -#include - -class VkService; -class Application; - -class VkMusicCache : public QObject { - Q_OBJECT - - public: - explicit VkMusicCache(Application* app, VkService* service); - ~VkMusicCache() {} - // Return file path if file in cache otherwise - // return internet url and add song to caching queue - QUrl Get(const QUrl& url); - void AddToCache(const QUrl& url, const QUrl& media_url, bool force = false); - void BreakCurrentCaching(); - bool InCache(const QUrl& url); - - private slots: - void AddToQueue(const QString& filename, const QUrl& download_url); - void DownloadNext(); - void DownloadProgress(qint64 bytesReceived, qint64 bytesTotal); - void DownloadReadyToRead(); - void Downloaded(); - - private: - struct DownloadItem { - QString filename; - QUrl url; - - bool operator==(const DownloadItem& rhv) { - return filename == rhv.filename; - } - }; - - QString CachedFilename(const QUrl& url); - - Application* app_; - VkService* service_; - QList queue_; - // Contain index of current song in queue, need for removing if song was - // skipped. It's zero if song downloading now, and less that zero - // if current song not caching or cached. - int current_song_index; - DownloadItem current_download; - bool is_downloading; - bool is_aborted; - int task_id; - QFile* file_; - QNetworkAccessManager* network_manager_; - QNetworkReply* reply_; -}; - -#endif // INTERNET_VK_VKMUSICCACHE_H_ diff --git a/src/internet/vk/vksearchdialog.cpp b/src/internet/vk/vksearchdialog.cpp deleted file mode 100644 index e6eb65737..000000000 --- a/src/internet/vk/vksearchdialog.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Krzysztof Sobiecki - Copyright 2014, Maltsev Vlad - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#include "vksearchdialog.h" -#include "ui_vksearchdialog.h" - -#include -#include - -#include "vkservice.h" -#include "ui/iconloader.h" - -VkSearchDialog::VkSearchDialog(VkService* service, QWidget* parent) - : QDialog(parent), - ui(new Ui::VkSearchDialog), - service_(service), - last_search_(SearchID(SearchID::UserOrGroup)) { - ui->setupUi(this); - - timer = new QTimer(this); - timer->setSingleShot(true); - timer->setInterval(100); - connect(timer, SIGNAL(timeout()), SLOT(suggest())); - connect(ui->searchLine, SIGNAL(textChanged(QString)), timer, SLOT(start())); - - popup = new QTreeWidget(this); - popup->setColumnCount(2); - popup->setUniformRowHeights(true); - popup->setRootIsDecorated(false); - popup->setEditTriggers(QTreeWidget::NoEditTriggers); - popup->setSelectionBehavior(QTreeWidget::SelectRows); - popup->setFrameStyle(QFrame::Box | QFrame::Plain); - popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - popup->header()->hide(); - popup->installEventFilter(this); - popup->setMouseTracking(true); - - popup->setWindowFlags(Qt::Popup); - popup->setFocusPolicy(Qt::NoFocus); - popup->setFocusProxy(parent); - - connect(popup, SIGNAL(itemSelectionChanged()), SLOT(selectionChanged())); - connect(popup, SIGNAL(clicked(QModelIndex)), SLOT(selected())); - - connect(this, SIGNAL(Find(QString)), service_, - SLOT(FindUserOrGroup(QString))); - connect(service_, SIGNAL(UserOrGroupSearchResult(SearchID, MusicOwnerList)), - this, SLOT(ReceiveResults(SearchID, MusicOwnerList))); - - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); -} - -VkSearchDialog::~VkSearchDialog() { - delete ui; - delete popup; -} - -void VkSearchDialog::suggest() { emit Find(ui->searchLine->text()); } - -void VkSearchDialog::selected() { - selectionChanged(); - ui->searchLine->setText(selected_.name()); - timer->stop(); - popup->hide(); -} - -void VkSearchDialog::ReceiveResults(const SearchID& id, - const MusicOwnerList& owners) { - if (id.id() > last_search_.id()) { - popup->setUpdatesEnabled(false); - popup->clear(); - - if (owners.count() > 0) { - for (const MusicOwner& own : owners) { - popup->addTopLevelItem(createItem(own)); - } - } else { - popup->addTopLevelItem(new QTreeWidgetItem(QStringList(tr("Nothing found")))); - } - - popup->setCurrentItem(popup->topLevelItem(0)); - - popup->resizeColumnToContents(0); - int ch = popup->columnWidth(0); - if (ch > 0.8 * ui->searchLine->width()) { - popup->setColumnWidth(0, qRound(0.8 * ui->searchLine->width())); - } - popup->resizeColumnToContents(1); - popup->adjustSize(); - popup->setUpdatesEnabled(true); - - int elems = (owners.count() > 0) ? owners.count() : 1; - int h = popup->sizeHintForRow(0) * qMin(10, elems) + 3; - - popup->resize(ui->searchLine->width(), h); - - QPoint relpos = ui->searchLine->pos() + QPoint(0, ui->searchLine->height()); - popup->move(mapToGlobal(relpos)); - popup->setFocus(); - popup->show(); - } -} - -void VkSearchDialog::showEvent(QShowEvent*) { - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - selected_ = MusicOwner(); - ui->searchLine->clear(); -} - -void VkSearchDialog::selectionChanged() { - if (popup->selectedItems().size() > 0) { - QTreeWidgetItem* sel = popup->selectedItems()[0]; - selected_ = sel->data(0, Qt::UserRole).value(); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(selected_.id() != 0); - ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); - } -} - -MusicOwner VkSearchDialog::found() const { - return selected_; -} - -bool VkSearchDialog::eventFilter(QObject* obj, QEvent* ev) { - if (obj != popup) - return false; - - if (ev->type() == QEvent::MouseButtonPress) { - popup->hide(); - ui->searchLine->setFocus(); - return true; - } - - if (ev->type() == QEvent::KeyPress) { - bool consumed = false; - int key = static_cast(ev)->key(); - - switch (key) { - case Qt::Key_Enter: - case Qt::Key_Return: - selected(); - break; - - case Qt::Key_Escape: - ui->searchLine->setFocus(); - popup->hide(); - consumed = true; - break; - - case Qt::Key_Up: - case Qt::Key_Down: - case Qt::Key_Home: - case Qt::Key_End: - case Qt::Key_PageUp: - case Qt::Key_PageDown: - break; - - default: - ui->searchLine->setFocus(); - ui->searchLine->event(ev); - break; - } - - return consumed; - } - - return false; -} - -QTreeWidgetItem* VkSearchDialog::createItem(const MusicOwner& own) { - QTreeWidgetItem* item = new QTreeWidgetItem(popup); - item->setText(0, own.name()); - if (own.id() > 0) { - item->setIcon(0, IconLoader::Load("x-clementine-artist", IconLoader::Base)); - } else { - item->setIcon(0, IconLoader::Load("group", IconLoader::Base)); - } - item->setData(0, Qt::UserRole, QVariant::fromValue(own)); - item->setText(1, QString::number(own.song_count())); - item->setTextAlignment(1, Qt::AlignRight); - item->setTextColor(1, palette().color(QPalette::WindowText)); - return item; -} diff --git a/src/internet/vk/vksearchdialog.h b/src/internet/vk/vksearchdialog.h deleted file mode 100644 index 620d79095..000000000 --- a/src/internet/vk/vksearchdialog.h +++ /dev/null @@ -1,66 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Krzysztof Sobiecki - Copyright 2014, Maltsev Vlad - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef INTERNET_VK_VKSEARCHDIALOG_H_ -#define INTERNET_VK_VKSEARCHDIALOG_H_ - -#include -#include -#include - -#include "vkservice.h" - -namespace Ui { -class VkSearchDialog; -} - -class VkSearchDialog : public QDialog { - Q_OBJECT - - public: - explicit VkSearchDialog(VkService* service, QWidget* parent = 0); - ~VkSearchDialog(); - MusicOwner found() const; - - signals: - void Find(const QString& query); - - public slots: - void ReceiveResults(const SearchID& id, const MusicOwnerList& owners); - - protected: - void showEvent(QShowEvent*); - - private slots: - void selectionChanged(); - void suggest(); - void selected(); - - private: - bool eventFilter(QObject* obj, QEvent* ev); - QTreeWidgetItem* createItem(const MusicOwner& own); - - Ui::VkSearchDialog* ui; - MusicOwner selected_; - VkService* service_; - SearchID last_search_; - QTreeWidget* popup; - QTimer* timer; -}; - -#endif // INTERNET_VK_VKSEARCHDIALOG_H_ diff --git a/src/internet/vk/vksearchdialog.ui b/src/internet/vk/vksearchdialog.ui deleted file mode 100644 index cf7ae1773..000000000 --- a/src/internet/vk/vksearchdialog.ui +++ /dev/null @@ -1,67 +0,0 @@ - - - VkSearchDialog - - - - 0 - 0 - 418 - 78 - - - - Dialog - - - - - - - - - Qt::Vertical - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - VkSearchDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - VkSearchDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/internet/vk/vkservice.cpp b/src/internet/vk/vkservice.cpp deleted file mode 100644 index 0436283d7..000000000 --- a/src/internet/vk/vkservice.cpp +++ /dev/null @@ -1,1545 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Vlad Maltsev - Copyright 2014, Krzysztof Sobiecki - Copyright 2014, Ivan Leontiev - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#include "vkservice.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "core/application.h" -#include "core/closure.h" -#include "core/logging.h" -#include "core/mergedproxymodel.h" -#include "core/player.h" -#include "core/timeconstants.h" -#include "core/utilities.h" -#include "ui/iconloader.h" -#include "widgets/didyoumean.h" - -#include "globalsearch/globalsearch.h" -#include "internet/core/internetmodel.h" -#include "internet/core/internetplaylistitem.h" -#include "internet/core/searchboxwidget.h" - -#include "vreen/audio.h" -#include "vreen/contact.h" -#include "vreen/roster.h" - -#include "globalsearch/vksearchprovider.h" -#include "vkmusiccache.h" -#include "vksearchdialog.h" - -const char* VkService::kServiceName = "Vk.com"; -const char* VkService::kSettingGroup = "Vk.com"; -const char* VkService::kUrlScheme = "vk"; - -const char* VkService::kDefCacheFilename = "%artist - %title"; -const int VkService::kMaxVkSongList = 6000; -const int VkService::kMaxVkWallPostList = 100; -const int VkService::kMaxVkSongCount = 300; -const int VkService::kSearchDelayMsec = 400; - -QString VkService::DefaultCacheDir() { - return QDir::toNativeSeparators( - Utilities::GetConfigPath(Utilities::Path_CacheRoot) + "/vkcache"); -} - -uint SearchID::last_id_ = 0; - -/*** - * Little functions - */ - -inline static void RemoveLastRow(QStandardItem* item, - VkService::ItemType type) { - QStandardItem* last_item = item->child(item->rowCount() - 1); - if (last_item->data(InternetModel::Role_Type).toInt() == type) { - item->removeRow(item->rowCount() - 1); - } else { - qLog(Error) << "Tryed to remove row" << last_item->text() << "of type" - << last_item->data(InternetModel::Role_Type).toInt() - << "instead of" << type << "from" << item->text(); - } -} - -struct SongId { - SongId() : audio_id(0), owner_id(0) {} - - int audio_id; - int owner_id; -}; - -static SongId ExtractIds(const QUrl& url) { - SongId res; - QString song_ids = url.path().section('/', 1, 1); - res.owner_id = song_ids.section('_', 0, 0).toInt(); - res.audio_id = song_ids.section('_', 1, 1).toInt(); - - if (res.owner_id && res.audio_id && url.scheme() == "vk" && - url.host() == "song") { - return res; - } else { - qLog(Error) << "Wromg song url" << url; - return SongId(); - } -} - -static Song SongFromUrl(const QUrl& url) { - Song result; - if (url.scheme() == "vk" && url.host() == "song") { - QStringList ids = url.path().split('/'); - if (ids.size() == 4) { - result.set_artist(ids[2]); - result.set_title(ids[3]); - result.set_valid(true); - } else { - qLog(Error) << "Wrong song url" << url; - result.set_valid(false); - } - result.set_url(url); - } else { - qLog(Error) << "Wrong song url" << url; - result.set_valid(false); - } - return result; -} - -MusicOwner::MusicOwner(const QUrl& group_url) { - QStringList tokens = group_url.path().split('/'); - if (group_url.scheme() == "vk" && group_url.host() == "group" && - tokens.size() == 5) { - id_ = -tokens[1].toInt(); - songs_count_ = tokens[2].toInt(); - screen_name_ = tokens[3]; - name_ = tokens[4].replace('_', '/'); - } else { - qLog(Error) << "Wrong group url" << group_url; - } -} - -Song MusicOwner::toOwnerRadio() const { - Song song; - song.set_title(QObject::tr("%1 (%2 songs)").arg(name_).arg(songs_count_)); - song.set_url(QUrl(QString("vk://group/%1/%2/%3/%4") - .arg(-id_) - .arg(songs_count_) - .arg(screen_name_) - .arg(QString(name_).replace('/', '_')))); - song.set_artist(" " + QObject::tr("Community Radio")); - song.set_valid(true); - return song; -} - -QDataStream& operator<<(QDataStream& stream, const MusicOwner& val) { - stream << val.id_; - stream << val.name_; - stream << val.songs_count_; - stream << val.screen_name_; - return stream; -} - -QDataStream& operator>>(QDataStream& stream, MusicOwner& var) { - stream >> var.id_; - stream >> var.name_; - stream >> var.songs_count_; - stream >> var.screen_name_; - return stream; -} - -QDebug operator<<(QDebug d, const MusicOwner& owner) { - d << "MusicOwner(" << owner.id_ << "," << owner.name_ << "," - << owner.songs_count_ << "," << owner.screen_name_ << ")"; - return d; -} - -MusicOwnerList MusicOwner::parseMusicOwnerList(const QVariant& request_result) { - auto list = request_result.toList(); - MusicOwnerList result; - for (const auto& item : list) { - auto map = item.toMap(); - MusicOwner owner; - owner.songs_count_ = map.value("songs_count").toInt(); - owner.id_ = map.value("id").toInt(); - owner.name_ = map.value("name").toString(); - owner.screen_name_ = map.value("screen_name").toString(); - owner.photo_ = map.value("photo").toUrl(); - - result.append(owner); - } - - return result; -} - -VkService::VkService(Application* app, InternetModel* parent) - : InternetService(kServiceName, app, parent, parent), - root_item_(NULL), - recommendations_item_(NULL), - my_music_item_(NULL), - my_albums_item_(NULL), - search_result_item_(NULL), - context_menu_(NULL), - update_item_(NULL), - find_this_artist_(NULL), - add_to_my_music_(NULL), - remove_from_my_music_(NULL), - add_song_to_cache_(NULL), - copy_share_url_(NULL), - add_to_bookmarks_(NULL), - remove_from_bookmarks_(NULL), - find_owner_(NULL), - search_box_(new SearchBoxWidget(this)), - vk_search_dialog_(new VkSearchDialog(this)), - client_(new Vreen::Client), - connection_(new VkConnection(this)), - url_handler_(new VkUrlHandler(this, this)), - audio_provider_(new Vreen::AudioProvider(client_.get())), - cache_(new VkMusicCache(app_, this)), - last_search_id_(0), - search_delay_(new QTimer(this)) { - QSettings s; - s.beginGroup(kSettingGroup); - - /* Init connection */ - client_->setTrackMessages(false); - client_->setInvisible(true); - client_->setConnection(connection_.get()); - - ReloadSettings(); - - if (HasAccount()) { - Login(); - } - - connect(client_.get(), SIGNAL(connectionStateChanged(Vreen::Client::State)), - SLOT(ChangeConnectionState(Vreen::Client::State))); - connect(client_.get(), SIGNAL(error(Vreen::Client::Error)), - SLOT(Error(Vreen::Client::Error))); - - /* Init interface */ - - VkSearchProvider* search_provider = new VkSearchProvider(app_, this); - search_provider->Init(this); - app_->global_search()->AddProvider(search_provider); - - search_delay_->setInterval(kSearchDelayMsec); - search_delay_->setSingleShot(true); - connect(search_delay_, SIGNAL(timeout()), SLOT(DoLocalSearch())); - - connect(search_box_, SIGNAL(TextChanged(QString)), SLOT(FindSongs(QString))); - connect(this, SIGNAL(SongSearchResult(SearchID, SongList)), - SLOT(SearchResultLoaded(SearchID, SongList))); - - app_->player()->RegisterUrlHandler(url_handler_); -} - -VkService::~VkService() {} - -/*** - * Interface - */ - -QStandardItem* VkService::CreateRootItem() { - root_item_ = new QStandardItem(IconLoader::Load("vk", IconLoader::Provider), - kServiceName); - root_item_->setData(true, InternetModel::Role_CanLazyLoad); - return root_item_; -} - -void VkService::LazyPopulate(QStandardItem* parent) { - switch (parent->data(InternetModel::Role_Type).toInt()) { - case InternetModel::Type_Service: - UpdateRoot(); - break; - case Type_Recommendations: - UpdateRecommendations(); - break; - case Type_AlbumList: - UpdateAlbumList(parent); - break; - case Type_Music: - UpdateMusic(parent); - break; - case Type_Album: - UpdateAlbumSongs(parent); - break; - case Type_Wall: - UpdateWallSongs(parent); - break; - default: - break; - } -} - -void VkService::EnsureMenuCreated() { - if (!context_menu_) { - context_menu_ = new QMenu; - - context_menu_->addActions(GetPlaylistActions()); - context_menu_->addSeparator(); - - add_to_bookmarks_ = - context_menu_->addAction(IconLoader::Load("list-add", IconLoader::Base), - tr("Add to bookmarks"), this, - SLOT(AddSelectedToBookmarks())); - - remove_from_bookmarks_ = context_menu_->addAction( - IconLoader::Load("list-remove", IconLoader::Base), tr("Remove from bookmarks"), - this, SLOT(RemoveFromBookmark())); - - context_menu_->addSeparator(); - - find_this_artist_ = - context_menu_->addAction(IconLoader::Load("edit-find", IconLoader::Base), - tr("Find this artist"), this, - SLOT(FindThisArtist())); - - add_to_my_music_ = - context_menu_->addAction(IconLoader::Load("list-add", IconLoader::Base), - tr("Add to My Music"), this, SLOT(AddToMyMusic())); - - remove_from_my_music_ = context_menu_->addAction( - IconLoader::Load("list-remove", IconLoader::Base), tr("Remove from My Music"), - this, SLOT(RemoveFromMyMusic())); - - add_song_to_cache_ = context_menu_->addAction(IconLoader::Load("download", - IconLoader::Base), - tr("Add song to cache"), this, - SLOT(AddSelectedToCache())); - - copy_share_url_ = context_menu_->addAction( - IconLoader::Load("link", IconLoader::Base), tr("Copy share url to clipboard"), - this, SLOT(CopyShareUrl())); - - find_owner_ = context_menu_->addAction(IconLoader::Load("edit-find", - IconLoader::Base), - tr("Add user/group to bookmarks"), - this, SLOT(ShowSearchDialog())); - - update_item_ = - context_menu_->addAction(IconLoader::Load("view-refresh", IconLoader::Base), - tr("Update"), this, SLOT(UpdateItem())); - - context_menu_->addSeparator(); - context_menu_->addAction(IconLoader::Load("configure", IconLoader::Base), - tr("Configure Vk.com..."), this, - SLOT(ShowConfig())); - } -} - -void VkService::ShowContextMenu(const QPoint& global_pos) { - EnsureMenuCreated(); - - QModelIndex current(model()->current_index()); - QStandardItem* current_item = model()->itemFromIndex(current); - - const int item_type = current.data(InternetModel::Role_Type).toInt(); - const int parent_type = - current.parent().data(InternetModel::Role_Type).toInt(); - - const bool is_playable = model()->IsPlayable(current); - const bool is_my_music_item = current_item == my_music_item_ || - current_item->parent() == my_music_item_; - const bool is_track = item_type == InternetModel::Type_Track; - - const bool is_bookmark = item_type == Type_Bookmark; - - const bool is_updatable = - item_type != Type_Bookmark && item_type != Type_Loading && - item_type != Type_More && item_type != Type_Search && - parent_type != Type_Search; - - const bool is_update_enable = - // To prevent call LazyPopulate twice when we try to Update not populated - // item - !current.data(InternetModel::Role_CanLazyLoad).toBool() && - !current.parent().data(InternetModel::Role_CanLazyLoad).toBool() && - // disable update action until all of item's children have finished - // updating - !isItemBusy(model()->itemFromIndex(current)); - - bool is_in_mymusic = false; - bool is_cached = false; - - if (is_track) { - selected_song_ = - current.data(InternetModel::Role_SongMetadata).value(); - is_in_mymusic = is_my_music_item || - ExtractIds(selected_song_.url()).owner_id == UserID(); - is_cached = cache_->InCache(selected_song_.url()); - } - - update_item_->setVisible(is_updatable); - update_item_->setEnabled(is_update_enable); - find_this_artist_->setVisible(is_track); - add_song_to_cache_->setVisible(is_track && !is_cached); - add_to_my_music_->setVisible(is_track && !is_in_mymusic); - remove_from_my_music_->setVisible(is_track && is_in_mymusic); - copy_share_url_->setVisible(is_track); - remove_from_bookmarks_->setVisible(is_bookmark); - add_to_bookmarks_->setVisible(false); - - GetAppendToPlaylistAction()->setEnabled(is_playable); - GetReplacePlaylistAction()->setEnabled(is_playable); - GetOpenInNewPlaylistAction()->setEnabled(is_playable); - - context_menu_->popup(global_pos); -} - -void VkService::ItemDoubleClicked(QStandardItem* item) { - switch (item->data(InternetModel::Role_Type).toInt()) { - case Type_More: - switch (item->parent()->data(InternetModel::Role_Type).toInt()) { - case Type_Recommendations: - MoreRecommendations(); - break; - case Type_Search: - FindMore(); - break; - case Type_Wall: - MoreWallSongs(item); - break; - default: - qLog(Warning) << "Wrong parent for More item:" - << item->parent()->text(); - } - break; - default: - qLog(Warning) << "Wrong item for double click with type:" - << item->data(InternetModel::Role_Type); - } -} - -QList VkService::playlistitem_actions(const Song& song) { - EnsureMenuCreated(); - - QList actions; - - if (song.url().host() == "song") { - selected_song_ = song; - } else if (song.url().host() == "group") { - add_to_bookmarks_->setVisible(true); - actions << add_to_bookmarks_; - if (song.url() == current_group_url_) { - // Selected now playing group. - selected_song_ = current_song_; - } else { - // If selected not playing group, return only "Add to bookmarks" action. - selected_song_ = song; - return actions; - } - } - - // Adding songs actions. - find_this_artist_->setVisible(true); - actions << find_this_artist_; - - if (ExtractIds(selected_song_.url()).owner_id != UserID()) { - add_to_my_music_->setVisible(true); - actions << add_to_my_music_; - } else { - remove_from_my_music_->setVisible(true); - actions << remove_from_my_music_; - } - - copy_share_url_->setVisible(true); - actions << copy_share_url_; - - if (!cache_->InCache(selected_song_.url())) { - add_song_to_cache_->setVisible(true); - actions << add_song_to_cache_; - } - - return actions; -} - -void VkService::ShowConfig() { - app_->OpenSettingsDialogAtPage(SettingsDialog::Page_Vk); -} - -void VkService::UpdateRoot() { - ClearStandardItem(root_item_); - - if (HasAccount()) { - CreateAndAppendRow(root_item_, Type_Recommendations); - AppendMusic(root_item_, true); - AppendAlbumList(root_item_, true); - LoadBookmarks(); - } else { - ShowConfig(); - } -} - -QWidget* VkService::HeaderWidget() const { - if (HasAccount()) { - return search_box_; - } else { - return NULL; - } -} - -QStandardItem* VkService::CreateAndAppendRow(QStandardItem* parent, - VkService::ItemType type) { - QStandardItem* item = NULL; - - switch (type) { - case Type_Loading: - item = new QStandardItem(tr("Loading...")); - break; - - case Type_More: - item = new QStandardItem(tr("More")); - item->setData(InternetModel::PlayBehaviour_DoubleClickAction, - InternetModel::Role_PlayBehaviour); - break; - - case Type_Recommendations: - item = new QStandardItem(IconLoader::Load("audio-headset", - IconLoader::Base), - tr("My Recommendations")); - item->setData(true, InternetModel::Role_CanLazyLoad); - item->setData(InternetModel::PlayBehaviour_MultipleItems, - InternetModel::Role_PlayBehaviour); - recommendations_item_ = item; - break; - - case Type_Search: - item = new QStandardItem(IconLoader::Load("edit-find", - IconLoader::Base), tr("Search")); - item->setData(InternetModel::PlayBehaviour_MultipleItems, - InternetModel::Role_PlayBehaviour); - search_result_item_ = item; - break; - - case Type_Bookmark: - qLog(Error) << "Use AppendBookmark(const MusicOwner &owner)" - << "for creating Bookmark item instead."; - break; - - case Type_Album: - qLog(Error) << "Use AppendAlbum(const Vreen::AudioAlbumItem &album)" - << "for creating Album item instead."; - break; - - default: - qLog(Error) << "Invalid type for creating row: " << type; - break; - } - - item->setData(type, InternetModel::Role_Type); - parent->appendRow(item); - return item; -} - -/*** - * Connection - */ - -void VkService::Login() { client_->connectToHost(); } - -void VkService::Logout() { - if (connection_) { - client_->disconnectFromHost(); - connection_->clear(); - } -} - -bool VkService::HasAccount() const { return connection_->hasAccount(); } - -int VkService::UserID() const { return connection_->uid(); } - -void VkService::ChangeConnectionState(Vreen::Client::State state) { - qLog(Debug) << "Connection state changed to" << state; - switch (state) { - case Vreen::Client::StateOnline: - emit LoginSuccess(true); - break; - - case Vreen::Client::StateInvalid: - case Vreen::Client::StateOffline: - emit LoginSuccess(false); - break; - case Vreen::Client::StateConnecting: - return; - default: - qLog(Error) << "Wrong connection state " << state; - return; - } - - if (!root_item_->data(InternetModel::Role_CanLazyLoad).toBool()) { - UpdateRoot(); - } -} - -void VkService::RequestUserProfile() { - QVariantMap args; - args.insert("users_ids", "0"); - Vreen::Reply* reply = client_->request("users.get", args); - - connect(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(UserProfileRecived(QVariant)), Qt::UniqueConnection); -} - -void VkService::UserProfileRecived(const QVariant& result) { - auto list = result.toList(); - if (!list.isEmpty()) { - auto profile = list[0].toMap(); - QString name = profile.value("first_name").toString() + " " + - profile.value("last_name").toString(); - emit NameUpdated(name); - } else { - qLog(Debug) << "Fetching user profile failed" << result; - } -} - -void VkService::Error(Vreen::Client::Error error) { - QString msg; - - switch (error) { - case Vreen::Client::ErrorApplicationDisabled: - msg = "Application disabled"; - break; - case Vreen::Client::ErrorIncorrectSignature: - msg = "Incorrect signature"; - break; - case Vreen::Client::ErrorAuthorizationFailed: - msg = "Authorization failed"; - emit LoginSuccess(false); - break; - case Vreen::Client::ErrorToManyRequests: - msg = "Too many requests"; - break; - case Vreen::Client::ErrorPermissionDenied: - msg = "Permission denied"; - break; - case Vreen::Client::ErrorCaptchaNeeded: - msg = "Captcha needed"; - QMessageBox::critical(NULL, tr("Error"), - tr("Captcha is needed.\n" - "Try to login into Vk.com with your browser," - "to fix this problem."), - QMessageBox::Close); - break; - case Vreen::Client::ErrorMissingOrInvalidParameter: - msg = "Missing or invalid parameter"; - break; - case Vreen::Client::ErrorNetworkReply: - msg = "Network reply"; - break; - default: - msg = "Unknown error"; - break; - } - - qLog(Error) << "Client error: " << error << msg; -} - -/*** - * My Music - */ - -void VkService::UpdateMusic(QStandardItem* item) { - if (item) { - MusicOwner owner = item->data(Role_MusicOwnerMetadata).value(); - LoadAndAppendSongList(item, owner.id()); - } -} - -/*** - * Recommendation - */ - -void VkService::UpdateRecommendations() { - ClearStandardItem(recommendations_item_); - CreateAndAppendRow(recommendations_item_, Type_Loading); - - auto my_audio = - audio_provider_->getRecommendationsForUser(0, kMaxVkSongCount, 0); - - NewClosure(my_audio, SIGNAL(resultReady(QVariant)), this, - SLOT(RecommendationsLoaded(Vreen::AudioItemListReply*)), my_audio); -} - -void VkService::MoreRecommendations() { - RemoveLastRow(recommendations_item_, Type_More); - CreateAndAppendRow(recommendations_item_, Type_Loading); - - auto my_audio = audio_provider_->getRecommendationsForUser( - 0, kMaxVkSongCount, recommendations_item_->rowCount() - 1); - - NewClosure(my_audio, SIGNAL(resultReady(QVariant)), this, - SLOT(RecommendationsLoaded(Vreen::AudioItemListReply*)), my_audio); -} - -void VkService::RecommendationsLoaded(Vreen::AudioItemListReply* reply) { - SongList songs = FromAudioList(reply->result()); - RemoveLastRow(recommendations_item_, Type_Loading); - AppendSongs(recommendations_item_, songs); - if (songs.count() > 0) { - CreateAndAppendRow(recommendations_item_, Type_More); - } -} - -/*** - * Bookmarks - */ - -void VkService::AddSelectedToBookmarks() { - QUrl group_url; - if (selected_song_.url().scheme() == "vk" && - selected_song_.url().host() == "song") { - // Selected song is song of now playing group, so group url in - // current_group_url_ - group_url = current_group_url_; - } else { - // Otherwise selectet group radio in playlist - group_url = selected_song_.url(); - } - - AppendBookmark(MusicOwner(group_url)); - SaveBookmarks(); -} - -void VkService::RemoveFromBookmark() { - QModelIndex current(model()->current_index()); - root_item_->removeRow(current.row()); - SaveBookmarks(); -} - -void VkService::SaveBookmarks() { - QSettings s; - s.beginGroup(kSettingGroup); - - s.beginWriteArray("bookmarks"); - int index = 0; - for (int i = 0; i < root_item_->rowCount(); ++i) { - auto item = root_item_->child(i); - if (item->data(InternetModel::Role_Type).toInt() == Type_Bookmark) { - MusicOwner owner = - item->data(Role_MusicOwnerMetadata).value(); - s.setArrayIndex(index); - qLog(Info) << "Save" << index << ":" << owner; - s.setValue("owner", QVariant::fromValue(owner)); - ++index; - } - } - s.endArray(); -} - -void VkService::LoadBookmarks() { - QSettings s; - s.beginGroup(kSettingGroup); - - int max = s.beginReadArray("bookmarks"); - for (int i = 0; i < max; ++i) { - s.setArrayIndex(i); - MusicOwner owner = s.value("owner").value(); - qLog(Info) << "Load" << i << ":" << owner; - AppendBookmark(owner); - } - s.endArray(); -} - -QStandardItem* VkService::AppendBookmark(const MusicOwner& owner) { - QIcon icon; - if (owner.id() > 0) { - icon = IconLoader::Load("x-clementine-artist", IconLoader::Base); - } else { - icon = IconLoader::Load("group", IconLoader::Base); - } - QStandardItem* item = new QStandardItem(icon, owner.name()); - - item->setData(QVariant::fromValue(owner), Role_MusicOwnerMetadata); - item->setData(Type_Bookmark, InternetModel::Role_Type); - - AppendWall(item); - AppendMusic(item); - AppendAlbumList(item); - - root_item_->appendRow(item); - return item; -} - -void VkService::UpdateItem() { - QModelIndex current(model()->current_index()); - QStandardItem* item = current.data(InternetModel::Role_Type).toInt() == - InternetModel::Type_Track - ? model()->itemFromIndex(current.parent()) - : model()->itemFromIndex(current); - - LazyPopulate(item); -} - -void VkService::UpdateAlbumList(QStandardItem* item) { - MusicOwner owner = item->data(Role_MusicOwnerMetadata).value(); - ClearStandardItem(item); - CreateAndAppendRow(item, Type_Loading); - LoadAlbums(item, owner); -} - -/*** - * Albums - */ - -void VkService::LoadAlbums(QStandardItem* parent, const MusicOwner& owner) { - auto albums_request = audio_provider_->getAlbums(owner.id()); - NewClosure( - albums_request, SIGNAL(resultReady(QVariant)), this, - SLOT(AlbumListReceived(QStandardItem*, Vreen::AudioAlbumItemListReply*)), - parent, albums_request); -} - -QStandardItem* VkService::AppendAlbum(QStandardItem* parent, - const Vreen::AudioAlbumItem& album) { - QStandardItem* item = - new QStandardItem(IconLoader::Load("view-media-playlist", IconLoader::Base), - album.title()); - - item->setData(QVariant::fromValue(album), Role_AlbumMetadata); - item->setData(Type_Album, InternetModel::Role_Type); - item->setData(true, InternetModel::Role_CanLazyLoad); - item->setData(InternetModel::PlayBehaviour_MultipleItems, - InternetModel::Role_PlayBehaviour); - - parent->appendRow(item); - return item; -} - -QStandardItem* VkService::AppendAlbumList(QStandardItem* parent, bool myself) { - MusicOwner owner; - QStandardItem* item; - - if (myself) { - item = new QStandardItem(IconLoader::Load("x-clementine-album", - IconLoader::Base), tr("My Albums")); - // TODO(Ivan Leontiev): Do this better. We have incomplete MusicOwner - // instance for logged in user. - owner.setId(UserID()); - my_albums_item_ = item; - } else { - owner = parent->data(Role_MusicOwnerMetadata).value(); - item = new QStandardItem(IconLoader::Load("x-clementine-album", - IconLoader::Base), tr("Albums")); - } - - item->setData(QVariant::fromValue(owner), Role_MusicOwnerMetadata); - item->setData(Type_AlbumList, InternetModel::Role_Type); - item->setData(true, InternetModel::Role_CanLazyLoad); - - parent->appendRow(item); - return item; -} - -void VkService::AlbumListReceived(QStandardItem* parent, - Vreen::AudioAlbumItemListReply* reply) { - Vreen::AudioAlbumItemList albums = reply->result(); - RemoveLastRow(parent, Type_Loading); - for (const auto& album : albums) { - AppendAlbum(parent, album); - } -} - -void VkService::UpdateAlbumSongs(QStandardItem* item) { - Vreen::AudioAlbumItem album = - item->data(Role_AlbumMetadata).value(); - - LoadAndAppendSongList(item, album.ownerId(), album.id()); -} - -/*** - * Wall - */ - -QStandardItem* VkService::AppendWall(QStandardItem* parent) { - QStandardItem* item = - new QStandardItem(IconLoader::Load("view-media-playlist", - IconLoader::Base), tr("Wall")); - MusicOwner owner = parent->data(Role_MusicOwnerMetadata).value(); - - item->setData(QVariant::fromValue(owner), Role_MusicOwnerMetadata); - item->setData(Type_Wall, InternetModel::Role_Type); - item->setData(true, InternetModel::Role_CanLazyLoad); - item->setData(InternetModel::PlayBehaviour_MultipleItems, - InternetModel::Role_PlayBehaviour); - - parent->appendRow(item); - return item; -} - -QStandardItem* VkService::AppendMusic(QStandardItem* parent, bool myself) { - MusicOwner owner; - QStandardItem* item; - - if (myself) { - item = new QStandardItem(IconLoader::Load("love", IconLoader::Lastfm), - tr("My Music")); - // TODO(Ivan Leontiev): Do this better. We have incomplete MusicOwner - // instance for logged in user. - owner.setId(UserID()); - my_music_item_ = item; - } else { - item = new QStandardItem(IconLoader::Load("view-media-playlist", - IconLoader::Base), tr("Music")); - owner = parent->data(Role_MusicOwnerMetadata).value(); - } - - item->setData(QVariant::fromValue(owner), Role_MusicOwnerMetadata); - item->setData(Type_Music, InternetModel::Role_Type); - item->setData(true, InternetModel::Role_CanLazyLoad); - item->setData(InternetModel::PlayBehaviour_MultipleItems, - InternetModel::Role_PlayBehaviour); - - parent->appendRow(item); - return item; -} - -void VkService::UpdateWallSongs(QStandardItem* item) { - MusicOwner owner = item->data(Role_MusicOwnerMetadata).value(); - ClearStandardItem(item); - LoadAndAppendWallSongList(item, owner); -} - -void VkService::MoreWallSongs(QStandardItem* item) { - QStandardItem* parent = item->parent(); - MusicOwner owner = parent->data(Role_MusicOwnerMetadata).value(); - int offset = item->data(Role_MoreMetadata).value(); - - RemoveLastRow(parent, Type_More); - LoadAndAppendWallSongList(parent, owner, offset); -} - -void VkService::WallPostsLoaded(QStandardItem* item, Vreen::Reply* reply, - int offset) { - auto response = reply->response().toMap(); - int count = response.value("count").toInt(); - - SongList songs = FromAudioList(handleWallPosts(response.value("items"))); - - RemoveLastRow(item, Type_Loading); - AppendSongs(item, songs); - if (count > offset) { - auto m = CreateAndAppendRow(item, Type_More); - m->setData(offset, Role_MoreMetadata); - } -} - -void VkService::LoadAndAppendWallSongList(QStandardItem* item, - const MusicOwner& owner, int offset) { - if (item) { - CreateAndAppendRow(item, Type_Loading); - QVariantMap args; - QString vk_script = - "var a = API.wall.get({" - " \"owner_id\": Args.q," - " \"count\": Args.count," - " \"offset\": Args.offset" - "});" - "return {\"count\": a.count, \"items\": a.items@.attachments};"; - - args.insert("v", "5.25"); - args.insert("q", owner.id()); - args.insert("offset", offset); - args.insert("count", kMaxVkWallPostList); - args.insert("code", vk_script); - - auto reply = client_->request("execute", args); - NewClosure(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(WallPostsLoaded(QStandardItem*, Vreen::Reply*, int)), item, - reply, offset + kMaxVkWallPostList); - } -} - -/*** - * Features - */ - -void VkService::FindThisArtist() { - search_box_->SetText(selected_song_.artist()); -} - -void VkService::AddToMyMusic() { - SongId id = ExtractIds(selected_song_.url()); - auto reply = audio_provider_->addToLibrary(id.audio_id, id.owner_id); - NewClosure(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(UpdateMusic(QStandardItem*)), my_music_item_); -} - -void VkService::AddToMyMusicCurrent() { - if (isLoveAddToMyMusic() && current_song_.is_valid()) { - selected_song_ = current_song_; - AddToMyMusic(); - } -} - -void VkService::RemoveFromMyMusic() { - SongId id = ExtractIds(selected_song_.url()); - if (id.owner_id == UserID()) { - auto reply = audio_provider_->removeFromLibrary(id.audio_id, id.owner_id); - NewClosure(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(UpdateMusic(QStandardItem*)), my_music_item_); - } else { - qLog(Error) << "Tried to delete song that not owned by user (" << UserID() - << selected_song_.url(); - } -} - -void VkService::AddSelectedToCache() { - QUrl selected_song_media_url = - GetAudioItemFromUrl(selected_song_.url()).url(); - cache_->AddToCache(selected_song_.url(), selected_song_media_url, true); -} - -void VkService::CopyShareUrl() { - QByteArray share_url("http://vk.com/audio?q="); - share_url += QUrl::toPercentEncoding( - QString(selected_song_.artist() + " " + selected_song_.title())); - - QApplication::clipboard()->setText(share_url); -} - -/*** - * Search - */ - -void VkService::DoLocalSearch() { - ClearStandardItem(search_result_item_); - CreateAndAppendRow(search_result_item_, Type_Loading); - SearchID id(SearchID::LocalSearch); - - last_search_id_ = id.id(); - SongSearch(id, last_query_); -} - -void VkService::FindSongs(const QString& query) { - last_query_ = query; - - if (query.isEmpty()) { - search_delay_->stop(); - root_item_->removeRow(search_result_item_->row()); - search_result_item_ = NULL; - last_search_id_ = 0; - return; - } - - search_delay_->start(); - - if (!search_result_item_) { - CreateAndAppendRow(root_item_, Type_Search); - } -} - -void VkService::FindMore() { - RemoveLastRow(search_result_item_, Type_More); - CreateAndAppendRow(search_result_item_, Type_Loading); - SearchID id(SearchID::MoreLocalSearch); - - last_search_id_ = id.id(); - SongSearch(id, last_query_, kMaxVkSongCount, - search_result_item_->rowCount() - 1); -} - -void VkService::SearchResultLoaded(const SearchID& id, const SongList& songs) { - if (!search_result_item_) { - return; // Result received when search is already over. - } - - if (id.id() == last_search_id_) { - if (id.type() == SearchID::LocalSearch) { - ClearStandardItem(search_result_item_); - } else if (id.type() == SearchID::MoreLocalSearch) { - RemoveLastRow(search_result_item_, Type_Loading); - } else { - return; // Others request types ignored. - } - - if (!songs.isEmpty()) { - AppendSongs(search_result_item_, songs); - CreateAndAppendRow(search_result_item_, Type_More); - } - - // If new search, scroll to search results. - if (id.type() == SearchID::LocalSearch) { - QModelIndex index = - model()->merged_model()->mapFromSource(search_result_item_->index()); - ScrollToIndex(index); - } - } -} - -/*** - * Load song list methods - */ - -void VkService::LoadAndAppendSongList(QStandardItem* item, int uid, - int album_id) { - if (item) { - ClearStandardItem(item); - CreateAndAppendRow(item, Type_Loading); - auto audioreq = - audio_provider_->getContactAudio(uid, kMaxVkSongList, 0, album_id); - NewClosure( - audioreq, SIGNAL(resultReady(QVariant)), this, - SLOT(AppendLoadedSongs(QStandardItem*, Vreen::AudioItemListReply*)), - item, audioreq); - } -} - -void VkService::AppendLoadedSongs(QStandardItem* item, - Vreen::AudioItemListReply* reply) { - SongList songs = FromAudioList(reply->result()); - - if (item) { - ClearStandardItem(item); - if (songs.count() > 0) { - AppendSongs(item, songs); - return; - } - } else { - qLog(Warning) << "Item for request not exist"; - } - - item->appendRow(new QStandardItem( - tr("Connection trouble " - "or audio is disabled by owner"))); -} - -static QString SanitiseCharacters(QString str) { - // Remove all leading and trailing unicode symbols - // that some users love to add to title and artist. - str = str.remove(QRegExp("^[^\\w]*")); - str = str.remove(QRegExp("[^])\\w]*$")); - return str; -} - -Song VkService::FromAudioItem(const Vreen::AudioItem& item) { - Song song; - song.set_title(SanitiseCharacters(item.title())); - song.set_artist(SanitiseCharacters(item.artist())); - song.set_length_nanosec(qFloor(item.duration()) * kNsecPerSec); - - QString url = QString("vk://song/%1_%2/%3/%4") - .arg(item.ownerId()) - .arg(item.id()) - .arg(item.artist().replace('/', '_')) - .arg(item.title().replace('/', '_')); - - song.set_url(QUrl(url)); - song.set_valid(true); - return song; -} - -SongList VkService::FromAudioList(const Vreen::AudioItemList& list) { - SongList song_list; - for (const Vreen::AudioItem& item : list) { - song_list.append(FromAudioItem(item)); - } - return song_list; -} - -/*** - * Url handling - */ - -Vreen::AudioItem VkService::GetAudioItemFromUrl(const QUrl& url) { - QStringList tokens = url.path().split('/'); - - if (tokens.count() < 2) { - qLog(Error) << "Wrong song url" << url; - return Vreen::AudioItem(); - } - - QString song_id = tokens[1]; - - if (HasAccount()) { - Vreen::AudioItemListReply* song_request = - audio_provider_->getAudiosByIds(song_id); - emit StopWaiting(); // Stop all previous requests. - bool success = WaitForReply(song_request); - - if (success && !song_request->result().isEmpty()) { - return song_request->result()[0]; - } - } - - qLog(Info) << "Unresolved url by id" << song_id; - return Vreen::AudioItem(); -} - -UrlHandler::LoadResult VkService::GetSongResult(const QUrl& url) { - // Try get from cache - QUrl media_url = cache_->Get(url); - if (media_url.isValid()) { - SongStarting(url); - return UrlHandler::LoadResult(url, UrlHandler::LoadResult::TrackAvailable, - media_url); - } - - // Otherwise get fresh link - auto audio_item = GetAudioItemFromUrl(url); - media_url = audio_item.url(); - if (media_url.isValid()) { - Song song = FromAudioItem(audio_item); - SongStarting(song); - - if (cachingEnabled_) { - cache_->AddToCache(url, media_url); - } - - return UrlHandler::LoadResult(url, UrlHandler::LoadResult::TrackAvailable, - media_url, song.length_nanosec()); - } - - return UrlHandler::LoadResult(url); -} - -UrlHandler::LoadResult VkService::GetGroupNextSongUrl(const QUrl& url) { - QStringList tokens = url.path().split('/'); - if (tokens.count() < 3) { - qLog(Error) << "Wrong url" << url; - return UrlHandler::LoadResult(url); - } - - int gid = tokens[1].toInt(); - int songs_count = tokens[2].toInt(); - - if (songs_count > kMaxVkSongList) { - songs_count = kMaxVkSongList; - } - - if (HasAccount()) { - // Getting one random song from groups playlist. - Vreen::AudioItemListReply* song_request = - audio_provider_->getContactAudio(-gid, 1, qrand() % songs_count); - - emit StopWaiting(); // Stop all previous requests. - bool success = WaitForReply(song_request); - - if (success && !song_request->result().isEmpty()) { - Vreen::AudioItem song = song_request->result()[0]; - current_group_url_ = url; - SongStarting(FromAudioItem(song)); - emit StreamMetadataFound(url, current_song_); - return UrlHandler::LoadResult(url, UrlHandler::LoadResult::TrackAvailable, - song.url(), current_song_.length_nanosec()); - } - } - - qLog(Info) << "Unresolved group url" << url; - return UrlHandler::LoadResult(url); -} - -/*** - * Song playing - */ - -void VkService::SongStarting(const QUrl& url) { - SongStarting(SongFromUrl(url)); -} - -void VkService::SongStarting(const Song& song) { - current_song_ = song; - - if (isBroadcasting() && HasAccount()) { - auto id = ExtractIds(song.url()); - auto reply = - audio_provider_->setBroadcast(id.audio_id, id.owner_id, IdList()); - NewClosure(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(BroadcastChangeReceived(Vreen::IntReply*)), reply); - connect(app_->player(), SIGNAL(Stopped()), this, SLOT(SongStopped()), - Qt::UniqueConnection); - qLog(Debug) << "Broadcasting" << song.artist() << "-" << song.title(); - } -} - -void VkService::SongSkipped() { - current_song_.set_valid(false); - cache_->BreakCurrentCaching(); -} - -void VkService::SongStopped() { - current_song_.set_valid(false); - - if (isBroadcasting() && HasAccount()) { - auto reply = audio_provider_->resetBroadcast(IdList()); - NewClosure(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(BroadcastChangeReceived(Vreen::IntReply*)), reply); - disconnect(app_->player(), SIGNAL(Stopped()), this, SLOT(SongStopped())); - qLog(Debug) << "End of broadcasting"; - } -} - -void VkService::BroadcastChangeReceived(Vreen::IntReply* reply) { - qLog(Debug) << "Broadcast changed for " << reply->result(); -} - -/*** - * Search - */ - -void VkService::SongSearch(SearchID id, const QString& query, int count, - int offset) { - auto reply = audio_provider_->searchAudio( - query, count, offset, false, Vreen::AudioProvider::SortByPopularity); - NewClosure(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(SongSearchReceived(SearchID, Vreen::AudioItemListReply*)), id, - reply); -} - -void VkService::SongSearchReceived(const SearchID& id, - Vreen::AudioItemListReply* reply) { - SongList songs = FromAudioList(reply->result()); - emit SongSearchResult(id, songs); -} - -void VkService::GroupSearch(SearchID id, const QString& query) { - QVariantMap args; - args.insert("q", query); - - // This is using of 'execute' method that execute - // this VKScript method on vk server: - /* - var groups = API.groups.search({"q": Args.q}); - if (groups.length == 0) { - return []; - } - - var i = 1; - var res = []; - while (i < groups.length - 1) { - i = i + 1; - var grp = groups[i]; - var songs = API.audio.getCount({oid: -grp.gid}); - if ( songs > 1 && - (grp.is_closed == 0 || grp.is_member == 1)) - { - res = res + [{"songs_count" : songs, - "id" : -grp.gid, - "name" : grp.name, - "screen_name" : grp.screen_name, - "photo": grp.photo}]; - } - } - return res; - */ - // - // I leave it here in case if my vk app disappear or smth. - - auto reply = client_->request("execute.searchMusicGroup", args); - - NewClosure(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(GroupSearchReceived(SearchID, Vreen::Reply*)), id, reply); -} - -void VkService::GroupSearchReceived(const SearchID& id, Vreen::Reply* reply) { - QVariant groups = reply->response(); - emit GroupSearchResult(id, MusicOwner::parseMusicOwnerList(groups)); -} - -/*** - * Vk search user or group. - */ - -void VkService::ShowSearchDialog() { - if (vk_search_dialog_->exec() == QDialog::Accepted) { - AppendBookmark(vk_search_dialog_->found()); - SaveBookmarks(); - } -} - -void VkService::FindUserOrGroup(const QString& q) { - QVariantMap args; - args.insert("q", q); - - // This is using of 'execute' method that execute - // this VKScript method on vk server: - /* - var q = Args.q; - if (q + "" == ""){ - return []; - } - - var results_count = 0; - var res = []; - - // Search groups - var groups = API.groups.search({"q": q}); - - var i = 0; - while (i < groups.length - 1 && results_count <= 5) { - i = i + 1; - var grp = groups[i]; - var songs = API.audio.getCount({oid: -grp.gid}); - // Add only accessible groups with songs - if ( songs > 1 && - (grp.is_closed == 0 || grp.is_member == 1)) - { - results_count = results_count + 1; - res = res + [{"songs_count" : songs, - "id" : -grp.gid, - "name" : grp.name, - "screen_name" : grp.screen_name, - "photo": grp.photo}]; - } - } - - // Search peoples - var peoples = API.users.search({"q": q, - "count":10, - "fields":"screen_name,photo"}); - var i = 0; - while (i < peoples.length - 1 && results_count <= 7) { - i = i + 1; - var user = peoples[i]; - var songs = API.audio.getCount({"oid": user.uid}); - // Add groups only with songs - if (songs > 1) { - results_count = results_count + 1; - res = res + [{"songs_count" : songs, - "id" : user.uid, - "name" : user.first_name + " " + user.last_name, - "screen_name" : user.screen_name, - "phone" : user.photo}]; - } - } - - return res; - */ - // I leave it here just in case if my vk app will disappear or smth. - - auto reply = client_->request("execute.searchMusicOwner", args); - - NewClosure(reply, SIGNAL(resultReady(QVariant)), this, - SLOT(UserOrGroupReceived(SearchID, Vreen::Reply*)), - SearchID(SearchID::UserOrGroup), reply); -} - -void VkService::UserOrGroupReceived(const SearchID& id, Vreen::Reply* reply) { - QVariant owners = reply->response(); - emit UserOrGroupSearchResult(id, MusicOwner::parseMusicOwnerList(owners)); -} - -/*** - * Utils - */ - -int VkService::TypeOfItem(const QStandardItem* item) { - return item->data(InternetModel::Role_Type).toInt(); -} - -bool VkService::isItemBusy(const QStandardItem* item) { - const QStandardItem* cur_item = - TypeOfItem(item) == InternetModel::Type_Track ? item->parent() : item; - - int r_count = cur_item->rowCount(); - bool flag = false; - - if (r_count) { - if (TypeOfItem(cur_item->child(r_count - 1)) == Type_Loading) return true; - - int t = TypeOfItem(cur_item); - if (cur_item == root_item_ || t == Type_Bookmark || t == Type_AlbumList) { - for (int i = 0; i < r_count; i++) { - flag |= isItemBusy(cur_item->child(i)); - } - } - } - return flag; -} - -void VkService::AppendSongs(QStandardItem* parent, const SongList& songs) { - for (const auto& song : songs) { - parent->appendRow(CreateSongItem(song)); - } -} - -void VkService::ReloadSettings() { - QSettings s; - s.beginGroup(kSettingGroup); - maxGlobalSearch_ = s.value("max_global_search", kMaxVkSongCount).toInt(); - cachingEnabled_ = s.value("cache_enabled", false).toBool(); - cacheDir_ = s.value("cache_dir", DefaultCacheDir()).toString(); - cacheFilename_ = s.value("cache_filename", kDefCacheFilename).toString(); - love_is_add_to_mymusic_ = s.value("love_is_add_to_my_music", false).toBool(); - groups_in_global_search_ = s.value("groups_in_global_search", false).toBool(); - - if (!s.contains("enable_broadcast")) { - // Need to update premissions - Logout(); - } - enable_broadcast_ = s.value("enable_broadcast", false).toBool(); -} - -void VkService::ClearStandardItem(QStandardItem* item) { - if (item && item->hasChildren()) { - item->removeRows(0, item->rowCount()); - } -} - -bool VkService::WaitForReply(Vreen::Reply* reply) { - QEventLoop event_loop; - QTimer timeout_timer; - connect(this, SIGNAL(StopWaiting()), &timeout_timer, SLOT(stop())); - connect(&timeout_timer, SIGNAL(timeout()), &event_loop, SLOT(quit())); - connect(reply, SIGNAL(resultReady(QVariant)), &event_loop, SLOT(quit())); - timeout_timer.start(10000); - event_loop.exec(); - if (!timeout_timer.isActive()) { - qLog(Error) << "Vk.com request timeout"; - return false; - } - timeout_timer.stop(); - return true; -} - -Vreen::AudioItemList VkService::handleWallPosts(const QVariant& response) { - Vreen::AudioItemList items; - auto list = response.toList(); - for (const auto& i : list) { - auto attachments = i.toList(); - for (const auto& j : attachments) { - auto item = j.toMap(); - if (item.value("type") == "audio") { - auto map = item.value("audio").toMap(); - Vreen::AudioItem audio; - - audio.setId(map.value("id").toInt()); - audio.setOwnerId(map.value("owner_id").toInt()); - audio.setArtist(map.value("artist").toString()); - audio.setTitle(map.value("title").toString()); - audio.setDuration(map.value("duration").toReal()); - audio.setAlbumId(map.value("album").toInt()); - audio.setLyricsId(map.value("lyrics_id").toInt()); - audio.setUrl(map.value("url").toUrl()); - - items.append(audio); - } - } - } - return items; -} diff --git a/src/internet/vk/vkservice.h b/src/internet/vk/vkservice.h deleted file mode 100644 index 5d629792b..000000000 --- a/src/internet/vk/vkservice.h +++ /dev/null @@ -1,326 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Vlad Maltsev - Copyright 2014, Krzysztof Sobiecki - Copyright 2014, Ivan Leontiev - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef INTERNET_VK_VKSERVICE_H_ -#define INTERNET_VK_VKSERVICE_H_ - -#include - -#include "internet/core/internetservice.h" -#include "internet/core/internetmodel.h" -#include "core/song.h" - -#include "vreen/audio.h" -#include "vreen/contact.h" - -#include "vkconnection.h" -#include "vkurlhandler.h" - -namespace Vreen { -class Client; -class Buddy; -} - -class SearchBoxWidget; -class VkMusicCache; -class VkSearchDialog; - -/*** - * Store information about user or group - * using in bookmarks. - */ -class MusicOwner { - public: - MusicOwner() : songs_count_(0), id_(0) {} - - explicit MusicOwner(const QUrl& group_url); - Song toOwnerRadio() const; - - QString name() const { return name_; } - int id() const { return id_; } - int song_count() const { return songs_count_; } - static QList parseMusicOwnerList(const QVariant& request_result); - // quick and dirty solution for creating MusicOwner instance for - // logged in user - void setId(int id) { id_ = id; } - - private: - friend QDataStream& operator<<(QDataStream& stream, const MusicOwner& val); - friend QDataStream& operator>>(QDataStream& stream, MusicOwner& val); - friend QDebug operator<<(QDebug d, const MusicOwner& owner); - - int songs_count_; - int id_; // if id > 0 is user otherwise id group - QString name_; - // name used in url http://vk.com/ for example: - // http://vk.com/shedward - QString screen_name_; - QUrl photo_; -}; - -typedef QList MusicOwnerList; - -Q_DECLARE_METATYPE(MusicOwner) - -QDataStream& operator<<(QDataStream& stream, const MusicOwner& val); -QDataStream& operator>>(QDataStream& stream, MusicOwner& var); -QDebug operator<<(QDebug d, const MusicOwner& owner); - -/*** - * The simple structure allows the handler to determine - * how to react to the received request or quickly skip unwanted. - */ -struct SearchID { - enum Type { GlobalSearch, LocalSearch, MoreLocalSearch, UserOrGroup }; - - explicit SearchID(Type type) : type_(type) { id_ = last_id_++; } - int id() const { return id_; } - Type type() const { return type_; } - - private: - static uint last_id_; - int id_; - Type type_; -}; - -/*** - * VkService - */ -class VkService : public InternetService { - Q_OBJECT - - public: - explicit VkService(Application* app, InternetModel* parent); - ~VkService(); - - static const char* kServiceName; - static const char* kSettingGroup; - static const char* kUrlScheme; - static const char* kDefCacheFilename; - static QString DefaultCacheDir(); - static const int kMaxVkSongList; - static const int kMaxVkWallPostList; - static const int kMaxVkSongCount; - static const int kSearchDelayMsec; - - enum ItemType { - Type_Loading = InternetModel::TypeCount, - Type_More, - - Type_Recommendations, - Type_Music, - Type_Bookmark, - Type_Album, - Type_Wall, - Type_AlbumList, - - Type_Search - }; - - enum Role { - Role_MusicOwnerMetadata = InternetModel::RoleCount, - Role_AlbumMetadata, - Role_MoreMetadata - }; - - Application* app() const { return app_; } - - /* InternetService interface */ - QStandardItem* CreateRootItem(); - void LazyPopulate(QStandardItem* parent); - void ShowContextMenu(const QPoint& global_pos); - void ItemDoubleClicked(QStandardItem* item); - QList playlistitem_actions(const Song& song); - - /* Interface*/ - QWidget* HeaderWidget() const; - - /* Connection */ - void Login(); - void Logout(); - bool HasAccount() const; - int UserID() const; - void RequestUserProfile(); - bool WaitForReply(Vreen::Reply* reply); - - /* Music */ - void SongStarting(const Song& song); - void SongStarting(const QUrl& url); // Used if song taked from cache. - void SongSkipped(); - UrlHandler::LoadResult GetSongResult(const QUrl& url); - Vreen::AudioItem GetAudioItemFromUrl(const QUrl& url); - // Return random song result from group playlist. - UrlHandler::LoadResult GetGroupNextSongUrl(const QUrl& url); - - void SongSearch(SearchID id, const QString& query, - int count = kMaxVkSongCount, int offset = 0); - void GroupSearch(SearchID id, const QString& query); - - /* Settings */ - void ReloadSettings(); - int maxGlobalSearch() const { return maxGlobalSearch_; } - bool isCachingEnabled() const { return cachingEnabled_; } - bool isGroupsInGlobalSearch() const { return groups_in_global_search_; } - bool isBroadcasting() const { return enable_broadcast_; } - QString cacheDir() const { return cacheDir_; } - QString cacheFilename() const { return cacheFilename_; } - bool isLoveAddToMyMusic() const { return love_is_add_to_mymusic_; } - -signals: - void NameUpdated(const QString& name); - void ConnectionStateChanged(Vreen::Client::State state); - void LoginSuccess(bool success); - void SongSearchResult(const SearchID& id, const SongList& songs); - void GroupSearchResult(const SearchID& id, const MusicOwnerList& groups); - void UserOrGroupSearchResult(const SearchID& id, - const MusicOwnerList& owners); - void StopWaiting(); - - public slots: - void UpdateRoot(); - void ShowConfig(); - void FindUserOrGroup(const QString& q); - void DoLocalSearch(); - - private slots: - /* Interface */ - void UpdateItem(); - - /* Connection */ - void ChangeConnectionState(Vreen::Client::State state); - void UserProfileRecived(const QVariant& result); - void Error(Vreen::Client::Error error); - - /* Music */ - void SongStopped(); - void UpdateMusic(QStandardItem* item); - void UpdateAlbumList(QStandardItem* item); - void UpdateAlbumSongs(QStandardItem* item); - void UpdateWallSongs(QStandardItem* item); - void MoreWallSongs(QStandardItem* item); - void FindSongs(const QString& query); - void FindMore(); - void UpdateRecommendations(); - void MoreRecommendations(); - void FindThisArtist(); - void AddToMyMusic(); - void AddToMyMusicCurrent(); - void RemoveFromMyMusic(); - void AddSelectedToCache(); - void CopyShareUrl(); - void ShowSearchDialog(); - - void AddSelectedToBookmarks(); - void RemoveFromBookmark(); - - void SongSearchReceived(const SearchID& id, Vreen::AudioItemListReply* reply); - void GroupSearchReceived(const SearchID& id, Vreen::Reply* reply); - void UserOrGroupReceived(const SearchID& id, Vreen::Reply* reply); - void AlbumListReceived(QStandardItem* parent, - Vreen::AudioAlbumItemListReply* reply); - void BroadcastChangeReceived(Vreen::IntReply* reply); - - void AppendLoadedSongs(QStandardItem* item, Vreen::AudioItemListReply* reply); - void RecommendationsLoaded(Vreen::AudioItemListReply* reply); - void SearchResultLoaded(const SearchID& id, const SongList& songs); - void WallPostsLoaded(QStandardItem* item, Vreen::Reply* reply, int offset); - - private: - bool isItemBusy(const QStandardItem* item); - int TypeOfItem(const QStandardItem* item); - Vreen::AudioItemList handleWallPosts(const QVariant& response); - - /* Interface */ - QStandardItem* CreateAndAppendRow(QStandardItem* parent, - VkService::ItemType type); - void ClearStandardItem(QStandardItem* item); - QStandardItem* GetBookmarkItemById(int id); - void EnsureMenuCreated(); - - /* Music */ - void LoadAndAppendSongList(QStandardItem* item, int uid, int album_id = -1); - void LoadAndAppendWallSongList(QStandardItem* item, const MusicOwner& owner, - int offset = 0); - Song FromAudioItem(const Vreen::AudioItem& item); - SongList FromAudioList(const Vreen::AudioItemList& list); - void AppendSongs(QStandardItem* parent, const SongList& songs); - - QStandardItem* AppendBookmark(const MusicOwner& owner); - void SaveBookmarks(); - void LoadBookmarks(); - - void LoadAlbums(QStandardItem* parent, const MusicOwner& owner); - QStandardItem* AppendAlbum(QStandardItem* parent, - const Vreen::AudioAlbumItem& album); - QStandardItem* AppendAlbumList(QStandardItem* parent, bool myself = false); - - QStandardItem* AppendWall(QStandardItem* parent); - QStandardItem* AppendMusic(QStandardItem* parent, bool myself = false); - - /* Interface */ - QStandardItem* root_item_; - QStandardItem* recommendations_item_; - QStandardItem* my_music_item_; - QStandardItem* my_albums_item_; - QStandardItem* search_result_item_; - - QMenu* context_menu_; - - QAction* update_item_; - QAction* find_this_artist_; - QAction* add_to_my_music_; - QAction* remove_from_my_music_; - QAction* add_song_to_cache_; - QAction* copy_share_url_; - QAction* add_to_bookmarks_; - QAction* remove_from_bookmarks_; - QAction* find_owner_; - - SearchBoxWidget* search_box_; - VkSearchDialog* vk_search_dialog_; - - /* Connection */ - std::unique_ptr client_; - std::unique_ptr connection_; - VkUrlHandler* url_handler_; - - /* Music */ - std::unique_ptr audio_provider_; - VkMusicCache* cache_; - // Keeping when more recent results recived. - // Using for prevent loading tardy result instead. - uint last_search_id_; - QTimer* search_delay_; - QString last_query_; - Song selected_song_; // Store for context menu actions. - Song current_song_; // Store for actions with now playing song. - // Store current group url for actions with it. - QUrl current_group_url_; - - /* Settings */ - int maxGlobalSearch_; - bool cachingEnabled_; - bool love_is_add_to_mymusic_; - bool groups_in_global_search_; - bool enable_broadcast_; - QString cacheDir_; - QString cacheFilename_; -}; - -#endif // INTERNET_VK_VKSERVICE_H_ diff --git a/src/internet/vk/vksettingspage.cpp b/src/internet/vk/vksettingspage.cpp deleted file mode 100644 index fd4584176..000000000 --- a/src/internet/vk/vksettingspage.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Maltsev Vlad - Copyright 2014, Krzysztof Sobiecki - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#include "vksettingspage.h" - -#include -#include - -#include "ui_vksettingspage.h" -#include "core/application.h" -#include "core/logging.h" -#include "internet/vk/vkservice.h" -#include "ui/iconloader.h" - -VkSettingsPage::VkSettingsPage(SettingsDialog* parent) - : SettingsPage(parent), - ui_(new Ui::VkSettingsPage), - service_(dialog()->app()->internet_model()->Service()) { - ui_->setupUi(this); - setWindowIcon(IconLoader::Load("vk", IconLoader::Provider)); - - connect(service_, SIGNAL(LoginSuccess(bool)), SLOT(LoginSuccess(bool))); - connect(ui_->choose_path, SIGNAL(clicked()), SLOT(CacheDirBrowse())); - connect(ui_->reset, SIGNAL(clicked()), SLOT(ResetCasheFilenames())); -} - -VkSettingsPage::~VkSettingsPage() { delete ui_; } - -void VkSettingsPage::Load() { - service_->ReloadSettings(); - - ui_->max_global_search->setValue(service_->maxGlobalSearch()); - ui_->enable_caching->setChecked(service_->isCachingEnabled()); - ui_->cache_dir->setText(service_->cacheDir()); - ui_->cache_filename->setText(service_->cacheFilename()); - ui_->love_button_is_add_to_mymusic->setChecked( - service_->isLoveAddToMyMusic()); - ui_->groups_in_global_search->setChecked(service_->isGroupsInGlobalSearch()); - ui_->enable_broadcast->setChecked(service_->isBroadcasting()); - - if (service_->HasAccount()) { - LogoutWidgets(); - } else { - LoginWidgets(); - } -} - -void VkSettingsPage::Save() { - QSettings s; - s.beginGroup(VkService::kSettingGroup); - - s.setValue("max_global_search", ui_->max_global_search->value()); - s.setValue("cache_enabled", ui_->enable_caching->isChecked()); - s.setValue("cache_dir", ui_->cache_dir->text()); - s.setValue("cache_filename", ui_->cache_filename->text()); - s.setValue("love_is_add_to_my_music", - ui_->love_button_is_add_to_mymusic->isChecked()); - s.setValue("groups_in_global_search", - ui_->groups_in_global_search->isChecked()); - s.setValue("enable_broadcast", ui_->enable_broadcast->isChecked()); - - service_->ReloadSettings(); -} - -void VkSettingsPage::Login() { - ui_->login_button->setEnabled(false); - service_->Login(); -} - -void VkSettingsPage::LoginSuccess(bool success) { - if (success) { - LogoutWidgets(); - } else { - LoginWidgets(); - } -} - -void VkSettingsPage::Logout() { - ui_->login_button->setEnabled(false); - service_->Logout(); - LoginWidgets(); -} - -void VkSettingsPage::CacheDirBrowse() { - QString directory = QFileDialog::getExistingDirectory( - this, tr("Choose Vk.com cache directory"), ui_->cache_dir->text()); - if (directory.isEmpty()) { - return; - } - - ui_->cache_dir->setText(QDir::toNativeSeparators(directory)); -} - -void VkSettingsPage::ResetCasheFilenames() { - ui_->cache_filename->setText(VkService::kDefCacheFilename); -} - -void VkSettingsPage::LoginWidgets() { - ui_->login_button->setText(tr("Login")); - ui_->name->setText(""); - ui_->login_button->setEnabled(true); - - connect(ui_->login_button, SIGNAL(clicked()), SLOT(Login()), - Qt::UniqueConnection); - disconnect(ui_->login_button, SIGNAL(clicked()), this, SLOT(Logout())); -} - -void VkSettingsPage::LogoutWidgets() { - ui_->login_button->setText(tr("Logout")); - ui_->name->setText(tr("Loading...")); - ui_->login_button->setEnabled(true); - - connect(service_, SIGNAL(NameUpdated(QString)), ui_->name, - SLOT(setText(QString)), Qt::UniqueConnection); - service_->RequestUserProfile(); - - connect(ui_->login_button, SIGNAL(clicked()), SLOT(Logout()), - Qt::UniqueConnection); - disconnect(ui_->login_button, SIGNAL(clicked()), this, SLOT(Login())); -} diff --git a/src/internet/vk/vksettingspage.h b/src/internet/vk/vksettingspage.h deleted file mode 100644 index 826d4ba66..000000000 --- a/src/internet/vk/vksettingspage.h +++ /dev/null @@ -1,56 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Krzysztof Sobiecki - Copyright 2014, Maltsev Vlad - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef INTERNET_VK_VKSETTINGSPAGE_H_ -#define INTERNET_VK_VKSETTINGSPAGE_H_ - -#include "ui/settingspage.h" - -#include -#include - -class VkService; -class Ui_VkSettingsPage; - -class VkSettingsPage : public SettingsPage { - Q_OBJECT - - public: - explicit VkSettingsPage(SettingsDialog* parent); - ~VkSettingsPage(); - - void Load(); - void Save(); - - private slots: - void LoginSuccess(bool success); - - void Login(); - void Logout(); - - void CacheDirBrowse(); - void ResetCasheFilenames(); - - private: - void LoginWidgets(); - void LogoutWidgets(); - Ui_VkSettingsPage* ui_; - VkService* service_; -}; - -#endif // INTERNET_VK_VKSETTINGSPAGE_H_ diff --git a/src/internet/vk/vksettingspage.ui b/src/internet/vk/vksettingspage.ui deleted file mode 100644 index 4120c14dc..000000000 --- a/src/internet/vk/vksettingspage.ui +++ /dev/null @@ -1,215 +0,0 @@ - - - VkSettingsPage - - - - 0 - 0 - 569 - 491 - - - - Vk.com - - - - - - Account details - - - - - - - - - true - - - - - - - - 120 - 16777215 - - - - Login - - - - - - - - - - Preferences - - - - - - - - Max global search results - - - max_global_search - - - - - - - 50 - - - 3000 - - - 50 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Add songs to "My Music" when the "Love" button is clicked - - - - - - - Show groups in global search result - - - - - - - Show playing song on your page - - - - - - - - - - Caching - - - - - - Enable automatic caching - - - - - - - true - - - - - - - - Cache path: - - - cache_dir - - - - - - - - - - ... - - - - - - - - - - - File name pattern: - - - cache_filename - - - - - - - %artist - %title - - - - - - - Reset - - - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 40 - - - - - - - - diff --git a/src/internet/vk/vkurlhandler.cpp b/src/internet/vk/vkurlhandler.cpp deleted file mode 100644 index adc208502..000000000 --- a/src/internet/vk/vkurlhandler.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Maltsev Vlad - Copyright 2014, Krzysztof Sobiecki - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#include "vkurlhandler.h" - -#include "core/application.h" -#include "core/logging.h" -#include "core/player.h" - -#include "vkservice.h" -#include "vkmusiccache.h" - -VkUrlHandler::VkUrlHandler(VkService* service, QObject* parent) - : UrlHandler(parent), service_(service) {} - -UrlHandler::LoadResult VkUrlHandler::StartLoading(const QUrl& url) { - QStringList args = url.path().split("/"); - LoadResult result(url); - - if (args.size() < 2) { - qLog(Error) - << "Invalid Vk.com URL: " << url - << "Url format should be vk:///." - << "For example vk://song/61145020_166946521/Daughtry/Gone Too Soon"; - } else { - QString action = url.host(); - - if (action == "song") { - result = service_->GetSongResult(url); - } else if (action == "group") { - result = service_->GetGroupNextSongUrl(url); - } else { - qLog(Error) << "Invalid vk.com url action:" << action; - } - } - - return result; -} - -void VkUrlHandler::TrackSkipped() { service_->SongSkipped(); } - -UrlHandler::LoadResult VkUrlHandler::LoadNext(const QUrl& url) { - if (url.host() == "group") { - return StartLoading(url); - } else { - return LoadResult(url); - } -} diff --git a/src/internet/vk/vkurlhandler.h b/src/internet/vk/vkurlhandler.h deleted file mode 100644 index cf5b92512..000000000 --- a/src/internet/vk/vkurlhandler.h +++ /dev/null @@ -1,46 +0,0 @@ -/* This file is part of Clementine. - Copyright 2014, Maltsev Vlad - Copyright 2014, Krzysztof Sobiecki - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef INTERNET_VK_VKURLHANDLER_H_ -#define INTERNET_VK_VKURLHANDLER_H_ - -#include "core/urlhandler.h" -#include "ui/iconloader.h" - -#include -#include -#include - -class VkService; -class VkMusicCache; - -class VkUrlHandler : public UrlHandler { - Q_OBJECT - public: - VkUrlHandler(VkService* service, QObject* parent); - QString scheme() const { return "vk"; } - QIcon icon() const { return IconLoader::Load("vk", IconLoader::Provider); } - LoadResult StartLoading(const QUrl& url); - void TrackSkipped(); - LoadResult LoadNext(const QUrl& url); - - private: - VkService* service_; -}; - -#endif // INTERNET_VK_VKURLHANDLER_H_ diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 88843bf1c..4f3b267a9 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -33,9 +33,9 @@ #include #include #include -#include #include #include +#include #ifdef Q_OS_WIN32 #include @@ -70,11 +70,12 @@ #include "globalsearch/globalsearch.h" #include "globalsearch/globalsearchview.h" #include "globalsearch/librarysearchprovider.h" -#include "internet/magnatune/magnatuneservice.h" #include "internet/core/internetmodel.h" #include "internet/core/internetview.h" #include "internet/core/internetviewcontainer.h" #include "internet/internetradio/savedradio.h" +#include "internet/magnatune/magnatuneservice.h" +#include "internet/podcasts/podcastservice.h" #include "library/groupbydialog.h" #include "library/library.h" #include "library/librarybackend.h" @@ -83,8 +84,8 @@ #include "library/libraryviewcontainer.h" #include "musicbrainz/tagfetcher.h" #include "networkremote/networkremote.h" -#include "playlist/playlistbackend.h" #include "playlist/playlist.h" +#include "playlist/playlistbackend.h" #include "playlist/playlistlistcontainer.h" #include "playlist/playlistmanager.h" #include "playlist/playlistsequence.h" @@ -93,7 +94,6 @@ #include "playlist/queuemanager.h" #include "playlist/songplaylistitem.h" #include "playlistparsers/playlistparser.h" -#include "internet/podcasts/podcastservice.h" #ifdef HAVE_AUDIOCD #include "ripper/ripcddialog.h" #endif @@ -147,10 +147,6 @@ #include "moodbar/moodbarproxystyle.h" #endif -#ifdef HAVE_VK -#include "internet/vk/vkservice.h" -#endif - #include #ifdef Q_OS_DARWIN @@ -423,11 +419,6 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd, SLOT(ToggleScrobbling())); #endif -#ifdef HAVE_VK - connect(ui_->action_love, SIGNAL(triggered()), - InternetModel::Service(), SLOT(AddToMyMusicCurrent())); -#endif - connect(ui_->action_clear_playlist, SIGNAL(triggered()), app_->playlist_manager(), SLOT(ClearCurrent())); connect(ui_->action_remove_duplicates, SIGNAL(triggered()), @@ -1073,9 +1064,9 @@ void MainWindow::ReloadSettings() { AddBehaviour(s.value("doubleclick_addmode", AddBehaviour_Append).toInt()); doubleclick_playmode_ = PlayBehaviour( s.value("doubleclick_playmode", PlayBehaviour_IfStopped).toInt()); - doubleclick_playlist_addmode_ = - PlaylistAddBehaviour(s.value("doubleclick_playlist_addmode", - PlaylistAddBehaviour_Play).toInt()); + doubleclick_playlist_addmode_ = PlaylistAddBehaviour( + s.value("doubleclick_playlist_addmode", PlaylistAddBehaviour_Play) + .toInt()); menu_playmode_ = PlayBehaviour(s.value("menu_playmode", PlayBehaviour_IfStopped).toInt()); @@ -2021,9 +2012,9 @@ void MainWindow::AddFile() { // Show dialog QStringList file_names = QFileDialog::getOpenFileNames( this, tr("Add file"), directory, - QString("%1 (%2);;%3;;%4").arg(tr("Music"), FileView::kFileFilter, - parser.filters(), - tr(kAllFilesFilterSpec))); + QString("%1 (%2);;%3;;%4") + .arg(tr("Music"), FileView::kFileFilter, parser.filters(), + tr(kAllFilesFilterSpec))); if (file_names.isEmpty()) return; // Save last used directory diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index dac9b64af..6165c8a33 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -15,18 +15,11 @@ along with Clementine. If not, see . */ +#include "settingsdialog.h" #include "appearancesettingspage.h" #include "backgroundstreamssettingspage.h" #include "behavioursettingspage.h" #include "config.h" -#include "globalshortcutssettingspage.h" -#include "iconloader.h" -#include "playbacksettingspage.h" -#include "networkproxysettingspage.h" -#include "networkremotesettingspage.h" -#include "notificationssettingspage.h" -#include "mainwindow.h" -#include "settingsdialog.h" #include "core/application.h" #include "core/backgroundstreams.h" #include "core/logging.h" @@ -35,15 +28,22 @@ #include "engines/enginebase.h" #include "engines/gstengine.h" #include "globalsearch/globalsearchsettingspage.h" -#include "internet/digitally/digitallyimportedsettingspage.h" +#include "globalshortcutssettingspage.h" +#include "iconloader.h" #include "internet/core/internetshowsettingspage.h" +#include "internet/digitally/digitallyimportedsettingspage.h" #include "internet/magnatune/magnatunesettingspage.h" +#include "internet/podcasts/podcastsettingspage.h" #include "internet/soundcloud/soundcloudsettingspage.h" #include "internet/spotify/spotifysettingspage.h" #include "internet/subsonic/subsonicsettingspage.h" #include "library/librarysettingspage.h" +#include "mainwindow.h" +#include "networkproxysettingspage.h" +#include "networkremotesettingspage.h" +#include "notificationssettingspage.h" +#include "playbacksettingspage.h" #include "playlist/playlistview.h" -#include "internet/podcasts/podcastsettingspage.h" #include "songinfo/songinfosettingspage.h" #include "transcoder/transcodersettingspage.h" #include "widgets/groupediconview.h" @@ -71,10 +71,6 @@ #include "internet/box/boxsettingspage.h" #endif -#ifdef HAVE_VK -#include "internet/vk/vksettingspage.h" -#endif - #ifdef HAVE_SKYDRIVE #include "internet/skydrive/skydrivesettingspage.h" #endif @@ -182,10 +178,6 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams, AddPage(Page_SoundCloud, new SoundCloudSettingsPage(this), providers); AddPage(Page_Spotify, new SpotifySettingsPage(this), providers); -#ifdef HAVE_VK - AddPage(Page_Vk, new VkSettingsPage(this), providers); -#endif - #ifdef HAVE_SEAFILE AddPage(Page_Seafile, new SeafileSettingsPage(this), providers); #endif