Add Vk.com plugin.
27
3rdparty/vreen/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
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(VREEN_WITH_QMLAPI OFF CACHE INTERNAL "")
|
||||
set(VREEN_WITH_OAUTH ON CACHE INTERNAL "")
|
||||
set(VREEN_INSTALL_HEADERS OFF CACHE INTERNAL "")
|
||||
set(VREEN_DEVELOPER_BUILD ON 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()
|
44
3rdparty/vreen/vreen/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
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()
|
633
3rdparty/vreen/vreen/cmake/CommonUtils.cmake
vendored
Normal file
@ -0,0 +1,633 @@
|
||||
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()
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
update_cxx_compiler_flag(${target} "-flto" LTO)
|
||||
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()
|
9
3rdparty/vreen/vreen/cmake/CompilerUtils.cmake
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
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()
|
113
3rdparty/vreen/vreen/cmake/FindLibraryWithDebug.cmake
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
#
|
||||
# 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, <ch.ehrlicher@gmx.de>
|
||||
# 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)
|
8
3rdparty/vreen/vreen/cmake/FindQCA2.cmake
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
#find qca2
|
||||
include(CommonUtils)
|
||||
find_module(qca2
|
||||
GLOBAL_HEADER qca.h
|
||||
HEADERS_DIR QtCrypto
|
||||
LIBRARY_HINTS ${QT_LIBRARY_DIR}
|
||||
INCLUDE_HINTS ${QT_INCLUDE_DIR}
|
||||
)
|
42
3rdparty/vreen/vreen/cmake/FindQOAuth.cmake
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
# 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 <apachelogger@ubuntu.com>
|
||||
#
|
||||
# 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)
|
6
3rdparty/vreen/vreen/cmake/FindQt3D.cmake
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#find Qt3D
|
||||
include(CommonUtils)
|
||||
find_qt_module(Qt3D
|
||||
GLOBAL_HEADER qt3dglobal.h
|
||||
HEADERS_DIR Qt3D qt4/Qt3D
|
||||
)
|
5
3rdparty/vreen/vreen/cmake/FindQt3DQuick.cmake
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
#find Qt3D
|
||||
find_qt_module(Qt3DQuick
|
||||
GLOBAL_HEADER qt3dquickglobal.h
|
||||
HEADERS_DIR Qt3DQuick qt4/Qt3DQuick
|
||||
)
|
50
3rdparty/vreen/vreen/cmake/MocUtils.cmake
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
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)
|
106
3rdparty/vreen/vreen/cmake/QtBundleUtils.cmake
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
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()
|
0
3rdparty/vreen/vreen/cmake/README
vendored
Normal file
21
3rdparty/vreen/vreen/cmake_uninstall.cmake.in
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
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)
|
17
3rdparty/vreen/vreen/src/3rdparty/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
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()
|
59
3rdparty/vreen/vreen/src/3rdparty/k8json/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
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)
|
||||
|
894
3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.cpp
vendored
Normal file
@ -0,0 +1,894 @@
|
||||
/* 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 <QtDebug>
|
||||
|
||||
#if defined(K8JSON_INCLUDE_COMPLEX_GENERATOR) || defined(K8JSON_INCLUDE_GENERATOR)
|
||||
# include <QStringList>
|
||||
#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
|
||||
|
||||
|
||||
}
|
130
3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.h
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/* 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 <QHash>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
#if defined(K8JSON_INCLUDE_COMPLEX_GENERATOR) || defined(K8JSON_INCLUDE_GENERATOR)
|
||||
# include <QByteArray>
|
||||
#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
|
12
3rdparty/vreen/vreen/src/3rdparty/k8json/k8json.pc.cmake
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
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
|
||||
|
9
3rdparty/vreen/vreen/src/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
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)
|
14
3rdparty/vreen/vreen/src/api/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
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
|
||||
)
|
54
3rdparty/vreen/vreen/src/api/abstractlistmodel.cpp
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QDebug>
|
||||
|
||||
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
|
||||
|
45
3rdparty/vreen/vreen/src/api/abstractlistmodel.h
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QAbstractListModel>
|
||||
#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
|
||||
|
234
3rdparty/vreen/vreen/src/api/attachment.cpp
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedData>
|
||||
#include <QStringList>
|
||||
|
||||
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<Attachment::Type>(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"
|
109
3rdparty/vreen/vreen/src/api/attachment.h
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedDataPointer>
|
||||
#include <QVariantMap>
|
||||
#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<Attachment> List;
|
||||
typedef QMultiHash<Attachment::Type, Attachment> 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<typename T>
|
||||
T property(const char *name, const T &def) const
|
||||
{ return QVariant::fromValue<T>(property(name, QVariant::fromValue(def))); }
|
||||
void setProperty(const QString &name, const QVariant &value);
|
||||
QStringList dynamicPropertyNames() const;
|
||||
template <typename T>
|
||||
static T to(const Attachment &attachment);
|
||||
template <typename T>
|
||||
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<AttachmentData> 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
|
||||
|
405
3rdparty/vreen/vreen/src/api/audio.cpp
vendored
Normal file
@ -0,0 +1,405 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QUrl>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QtCore/qalgorithms.h>
|
||||
|
||||
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<int>())
|
||||
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<int>())
|
||||
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<AudioItemListReply>("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<int>(sort));
|
||||
args.insert("lyrics", withLyrics);
|
||||
args.insert("count", count);
|
||||
args.insert("offset", offset);
|
||||
|
||||
auto reply = d->client->request<AudioItemListReply>("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<AudioAlbumItemListReply>("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<AudioItemListReply>("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<IntReply>("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<IntReply>("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<IntReply>("audio.delete", args, ReplyPrivate::handleInt);
|
||||
return reply;
|
||||
}
|
||||
|
||||
AudioItemListReply *AudioProvider::getAudiosByIds(const QString &ids)
|
||||
{
|
||||
Q_D(AudioProvider);
|
||||
|
||||
QVariantMap args;
|
||||
args.insert("audios", ids);
|
||||
|
||||
auto reply = d->client->request<AudioItemListReply>("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<AudioItem> 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"
|
||||
|
115
3rdparty/vreen/vreen/src/api/audio.h
vendored
Normal file
@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QAbstractListModel>
|
||||
#include "audioitem.h"
|
||||
#include "abstractlistmodel.h"
|
||||
#include "reply.h"
|
||||
|
||||
namespace Vreen {
|
||||
|
||||
class Client;
|
||||
typedef ReplyBase<AudioItemList> AudioItemListReply;
|
||||
typedef ReplyBase<AudioAlbumItemList> AudioAlbumItemListReply;
|
||||
|
||||
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);
|
||||
protected:
|
||||
QScopedPointer<AudioProviderPrivate> 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<AudioModelPrivate> d_ptr;
|
||||
};
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
#endif // VK_AUDIO_H
|
||||
|
238
3rdparty/vreen/vreen/src/api/audioitem.cpp
vendored
Normal file
@ -0,0 +1,238 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedData>
|
||||
#include <QUrl>
|
||||
#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
|
||||
|
99
3rdparty/vreen/vreen/src/api/audioitem.h
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedDataPointer>
|
||||
#include "attachment.h"
|
||||
#include <QVariant>
|
||||
|
||||
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<AudioItemData> data;
|
||||
};
|
||||
typedef QList<AudioItem> 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<AudioAlbumItemData> data;
|
||||
};
|
||||
typedef QList<AudioAlbumItem> 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
|
||||
|
138
3rdparty/vreen/vreen/src/api/chatsession.cpp
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QStringBuilder>
|
||||
|
||||
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<MessageList> *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<ReplyBase<MessageList>>("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<Reply*>(q->sender());
|
||||
if (response.toInt() == 1) {
|
||||
auto set = reply->property("set").toBool();
|
||||
auto ids = reply->property("mids").value<IdList>();
|
||||
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"
|
||||
|
59
3rdparty/vreen/vreen/src/api/chatsession.h
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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<MessageList> *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
|
||||
|
440
3rdparty/vreen/vreen/src/api/client.cpp
vendored
Normal file
@ -0,0 +1,440 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
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<SendMessageReply>("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<Reply*>(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<MessageList> *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<ReplyBase<MessageList>>("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<Reply*>(q->sender());
|
||||
qDebug() << "Error received :" << code << reply->networkReply()->url();
|
||||
reply->deleteLater();
|
||||
auto error = static_cast<Client::Error>(code);
|
||||
emit q->error(error);
|
||||
if (error == Client::ErrorAuthorizationFailed) {
|
||||
connection->disconnectFromHost();
|
||||
connection->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ClientPrivate::_q_reply_finished(const QVariant &)
|
||||
{
|
||||
auto reply = sender_cast<Reply*>(q_func()->sender());
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
void ClientPrivate::_q_network_manager_error(int)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
#include "moc_client.cpp"
|
||||
|
174
3rdparty/vreen/vreen/src/api/client.h
vendored
Normal file
@ -0,0 +1,174 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QScopedPointer>
|
||||
#include <QObject>
|
||||
#include <QVariantMap>
|
||||
|
||||
class QUrl;
|
||||
namespace Vreen {
|
||||
|
||||
class Message;
|
||||
class Connection;
|
||||
class ClientPrivate;
|
||||
class Roster;
|
||||
class GroupManager;
|
||||
class LongPoll;
|
||||
class Contact;
|
||||
class Buddy;
|
||||
|
||||
typedef ReplyBase<int> 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 <typename ReplyImpl, typename Handler>
|
||||
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<ClientPrivate> 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<typename ReplyImpl, typename Handler>
|
||||
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
|
||||
|
82
3rdparty/vreen/vreen/src/api/client_p.h
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QPointer>
|
||||
|
||||
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> connection;
|
||||
QPointer<Roster> roster;
|
||||
QPointer<LongPoll> longPoll;
|
||||
QPointer<GroupManager> 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<MessageList> *getMessages(Client *client, const IdList &list, int previewLength = 0);
|
||||
};
|
||||
|
||||
} //namespace Vreen
|
||||
|
||||
#endif // CLIENT_P_H
|
||||
|
107
3rdparty/vreen/vreen/src/api/commentssession.cpp
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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"
|
||||
|
63
3rdparty/vreen/vreen/src/api/commentssession.h
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QObject>
|
||||
#include <QVariantMap>
|
||||
#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<CommentSessionPrivate> d_ptr;
|
||||
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_comments_received(QVariant))
|
||||
};
|
||||
|
||||
typedef QList<QVariantMap> CommentList;
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
#endif // VK_COMMENTSSESSION_H
|
||||
|
89
3rdparty/vreen/vreen/src/api/connection.cpp
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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
|
||||
|
81
3rdparty/vreen/vreen/src/api/connection.h
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QVariantMap>
|
||||
#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<ConnectionPrivate> d_ptr;
|
||||
};
|
||||
|
||||
} //namespace Vreen
|
||||
|
||||
Q_DECLARE_METATYPE(Vreen::Connection*)
|
||||
|
||||
#endif // VK_CONNECTION_H
|
||||
|
44
3rdparty/vreen/vreen/src/api/connection_p.h
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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<Connection::ConnectionOption, QVariant> options;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // CONNECTION_P_H
|
317
3rdparty/vreen/vreen/src/api/contact.cpp
vendored
Normal file
@ -0,0 +1,317 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QDebug>
|
||||
#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"
|
||||
|
243
3rdparty/vreen/vreen/src/api/contact.h
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
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<ContactPrivate> 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<Contact*> ContactList;
|
||||
typedef QList<Buddy*> BuddyList;
|
||||
typedef QList<Group*> GroupList;
|
||||
|
||||
//contact's casts
|
||||
template <typename T>
|
||||
Q_INLINE_TEMPLATE T contact_cast(Contact *contact)
|
||||
{
|
||||
//T t = reinterpret_cast<T>(0);
|
||||
//if (t->staticType() == contact->type())
|
||||
// return static_cast<T>(contact);
|
||||
return qobject_cast<T>(contact);
|
||||
}
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
Q_DECLARE_METATYPE(Vreen::Contact*)
|
||||
Q_DECLARE_METATYPE(Vreen::Buddy*)
|
||||
Q_DECLARE_METATYPE(Vreen::Group*)
|
||||
|
||||
#endif // VK_USER_H
|
||||
|
141
3rdparty/vreen/vreen/src/api/contact_p.h
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QStringList>
|
||||
#include <QVector>
|
||||
|
||||
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<QString> 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
|
||||
|
98
3rdparty/vreen/vreen/src/api/contentdownloader.cpp
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QPointer>
|
||||
#include <QThread>
|
||||
#include <QFileInfo>
|
||||
#include <QNetworkReply>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Vreen {
|
||||
|
||||
static QPointer<NetworkAccessManager> 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<QNetworkReply*>(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"
|
||||
|
50
3rdparty/vreen/vreen/src/api/contentdownloader.h
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QObject>
|
||||
#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
|
||||
|
60
3rdparty/vreen/vreen/src/api/contentdownloader_p.h
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QNetworkAccessManager>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QDesktopServices>
|
||||
#include <QCryptographicHash>
|
||||
#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
|
73
3rdparty/vreen/vreen/src/api/dynamicpropertydata.cpp
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedData>
|
||||
|
||||
namespace Vreen {
|
||||
|
||||
QVariant DynamicPropertyData::property(const char *name, const QVariant &def,
|
||||
const QList<QByteArray> &gNames,
|
||||
const QList<Getter> &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<QByteArray> &gNames,
|
||||
const QList<Setter> &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
|
||||
|
63
3rdparty/vreen/vreen/src/api/dynamicpropertydata_p.h
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedData>
|
||||
#include <QVariant>
|
||||
|
||||
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<QByteArray> names;
|
||||
QList<QVariant> values;
|
||||
|
||||
QVariant property(const char *name, const QVariant &def, const QList<QByteArray> &names,
|
||||
const QList<Getter> &getters) const;
|
||||
void setProperty(const char *name, const QVariant &value, const QList<QByteArray> &names,
|
||||
const QList<Setter> &setters);
|
||||
};
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
#endif // VK_DYNAMICPROPERTYDATA_P_H
|
||||
|
95
3rdparty/vreen/vreen/src/api/friendrequest.cpp
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedData>
|
||||
|
||||
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
|
59
3rdparty/vreen/vreen/src/api/friendrequest.h
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QVariant>
|
||||
#include <QSharedDataPointer>
|
||||
|
||||
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<FriendRequestData> data;
|
||||
};
|
||||
typedef QList<FriendRequest> FriendRequestList;
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
Q_DECLARE_METATYPE(Vreen::FriendRequest)
|
||||
Q_DECLARE_METATYPE(Vreen::FriendRequestList)
|
||||
|
||||
#endif // VREEN_FRIENDREQUEST_H
|
336
3rdparty/vreen/vreen/src/api/groupchatsession.cpp
vendored
Normal file
@ -0,0 +1,336 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSet>
|
||||
|
||||
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<int, Buddy*> 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<Buddy*>(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<MessageList> *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<ReplyBase<MessageList>>("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<SendMessageReply>("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<int> uidsToAdd;
|
||||
foreach (auto item, map.value("users").toList())
|
||||
uidsToAdd.insert(item.toInt());
|
||||
|
||||
QSet<int> uids = buddies.keys().toSet();
|
||||
QSet<int> 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<Buddy*>(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"
|
||||
|
81
3rdparty/vreen/vreen/src/api/groupchatsession.h
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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<MessageList> *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
|
||||
|
112
3rdparty/vreen/vreen/src/api/groupmanager.cpp
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QTimer>
|
||||
#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"
|
66
3rdparty/vreen/vreen/src/api/groupmanager.h
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QObject>
|
||||
|
||||
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<GroupManagerPrivate> 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
|
||||
|
63
3rdparty/vreen/vreen/src/api/groupmanager_p.h
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QTimer>
|
||||
|
||||
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<int, Group*> 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
|
61
3rdparty/vreen/vreen/src/api/json.cpp
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <k8json/k8json.h>
|
||||
|
||||
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<const uchar *>(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
|
||||
|
40
3rdparty/vreen/vreen/src/api/json.h
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QVariantMap>
|
||||
|
||||
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
|
||||
|
33
3rdparty/vreen/vreen/src/api/localstorage.cpp
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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
|
48
3rdparty/vreen/vreen/src/api/localstorage.h
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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
|
279
3rdparty/vreen/vreen/src/api/longpoll.cpp
vendored
Normal file
@ -0,0 +1,279 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QDateTime>
|
||||
#include <QDebug>
|
||||
|
||||
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<int, Attachment> 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"
|
||||
|
102
3rdparty/vreen/vreen/src/api/longpoll.h
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QObject>
|
||||
#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<LongPollPrivate> 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
|
||||
|
70
3rdparty/vreen/vreen/src/api/longpoll_p.h
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QVariant>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
#include <QPointer>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
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<Reply> 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
|
||||
|
327
3rdparty/vreen/vreen/src/api/message.cpp
vendored
Normal file
@ -0,0 +1,327 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QDateTime>
|
||||
#include "dynamicpropertydata_p.h"
|
||||
#include "utils_p.h"
|
||||
#include <QDebug>
|
||||
|
||||
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<int> forwardMsgIds;
|
||||
int chatId;
|
||||
QList<int> 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"
|
117
3rdparty/vreen/vreen/src/api/message.h
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QVariant>
|
||||
#include <QSharedData>
|
||||
#include "attachment.h"
|
||||
|
||||
namespace Vreen {
|
||||
|
||||
class Contact;
|
||||
class Message;
|
||||
typedef QList<Message> 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<MessageData> d;
|
||||
};
|
||||
|
||||
typedef QList<int> 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
|
||||
|
286
3rdparty/vreen/vreen/src/api/messagemodel.cpp
vendored
Normal file
@ -0,0 +1,286 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QPointer>
|
||||
|
||||
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> client;
|
||||
|
||||
MessageList messageList;
|
||||
IdComparator<Message> 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<Message::Flags>(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"
|
||||
|
91
3rdparty/vreen/vreen/src/api/messagemodel.h
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QAbstractListModel>
|
||||
#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<MessageListModelPrivate> d_ptr;
|
||||
};
|
||||
|
||||
} //namespace Vreen
|
||||
|
||||
#endif // MESSAGEMODEL_H
|
||||
|
110
3rdparty/vreen/vreen/src/api/messagesession.cpp
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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<MessageList> *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<ReplyBase<MessageList>*>(q->sender());
|
||||
foreach (auto message, reply->result())
|
||||
emit q->messageAdded(message);
|
||||
}
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
#include "moc_messagesession.cpp"
|
||||
|
74
3rdparty/vreen/vreen/src/api/messagesession.h
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QObject>
|
||||
#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<MessageList> *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<MessageList> *doGetHistory(int count, int offset) = 0;
|
||||
QScopedPointer<MessageSessionPrivate> d_ptr;
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_history_received(const QVariant &))
|
||||
};
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
#endif // VK_MESSAGESESSION_H
|
||||
|
50
3rdparty/vreen/vreen/src/api/messagesession_p.h
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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
|
||||
|
148
3rdparty/vreen/vreen/src/api/newsfeed.cpp
vendored
Normal file
@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QVariantList>
|
||||
|
||||
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"
|
||||
|
71
3rdparty/vreen/vreen/src/api/newsfeed.h
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QObject>
|
||||
#include "newsitem.h"
|
||||
#include <QVariantMap>
|
||||
|
||||
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<NewsFeedPrivate> 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
|
||||
|
234
3rdparty/vreen/vreen/src/api/newsitem.cpp
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedData>
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
|
||||
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<Type>(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"
|
98
3rdparty/vreen/vreen/src/api/newsitem.h
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedDataPointer>
|
||||
#include <QVariant>
|
||||
#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<typename T>
|
||||
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<NewsItemData> d;
|
||||
};
|
||||
typedef QList<NewsItem> NewsItemList;
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
Q_DECLARE_METATYPE(Vreen::NewsItem)
|
||||
Q_DECLARE_METATYPE(Vreen::NewsItemList)
|
||||
|
||||
#endif // VK_NEWSITEM_H
|
||||
|
149
3rdparty/vreen/vreen/src/api/pollitem.cpp
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedData>
|
||||
#include <QDateTime>
|
||||
|
||||
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
|
77
3rdparty/vreen/vreen/src/api/pollitem.h
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedDataPointer>
|
||||
#include <QVariant>
|
||||
#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<Answer> 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<PollItemData> data;
|
||||
};
|
||||
|
||||
template<>
|
||||
PollItem Attachment::to(const Attachment &data);
|
||||
|
||||
} //namespace Vreen
|
||||
|
||||
Q_DECLARE_METATYPE(Vreen::PollItem)
|
||||
|
||||
#endif // POLLITEM_H
|
116
3rdparty/vreen/vreen/src/api/pollprovider.cpp
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QDateTime>
|
||||
#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<PollItemReply>("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
|
54
3rdparty/vreen/vreen/src/api/pollprovider.h
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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<Vreen::PollItem> 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<PollProviderPrivate> d_ptr;
|
||||
};
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
#endif // VREEN_POLLPROVIDER_H
|
140
3rdparty/vreen/vreen/src/api/reply.cpp
vendored
Normal file
@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QNetworkReply>
|
||||
#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<QNetworkReply*>(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 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"
|
||||
|
118
3rdparty/vreen/vreen/src/api/reply.h
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QObject>
|
||||
#include <QVariant>
|
||||
#include "vk_global.h"
|
||||
#include <functional>
|
||||
|
||||
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 <typename Method>
|
||||
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 <typename Method>
|
||||
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<ReplyPrivate> 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 <typename Method>
|
||||
void Reply::setResultHandler(const Method &handler)
|
||||
{
|
||||
setHandlerImpl(new ResultHandlerImpl<Method>(handler));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class ReplyBase : public Reply
|
||||
{
|
||||
public:
|
||||
T result() const { return qvariant_cast<T>(Reply::result()); }
|
||||
protected:
|
||||
template<typename Method>
|
||||
explicit ReplyBase(Method handler, QNetworkReply *networkReply = 0) :
|
||||
Reply(networkReply)
|
||||
{
|
||||
setResultHandler(handler);
|
||||
}
|
||||
friend class Client;
|
||||
};
|
||||
|
||||
//some useful typedefs
|
||||
typedef ReplyBase<int> IntReply;
|
||||
|
||||
} // namespace Vreen
|
||||
|
||||
Q_DECLARE_METATYPE(Vreen::Reply*)
|
||||
|
||||
#endif // VK_REPLY_H
|
||||
|
67
3rdparty/vreen/vreen/src/api/reply_p.h
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QDebug>
|
||||
#include <QPointer>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace Vreen {
|
||||
|
||||
class ReplyPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(Reply)
|
||||
public:
|
||||
ReplyPrivate(Reply *q) : q_ptr(q), resultHandler(0) {}
|
||||
Reply *q_ptr;
|
||||
|
||||
QPointer<QNetworkReply> networkReply;
|
||||
QVariant response;
|
||||
QVariant error;
|
||||
QScopedPointer<Reply::ResultHandlerBase> resultHandler;
|
||||
QVariant result;
|
||||
|
||||
void _q_reply_finished();
|
||||
void _q_network_reply_error(QNetworkReply::NetworkError);
|
||||
|
||||
static QVariant handleInt(const QVariant &response) { return response.toInt(); }
|
||||
};
|
||||
|
||||
|
||||
struct MessageListHandler {
|
||||
MessageListHandler(int clientId) : clientId(clientId) {}
|
||||
QVariant operator()(const QVariant &response);
|
||||
|
||||
int clientId;
|
||||
};
|
||||
|
||||
} //namespace Vreen
|
||||
|
||||
#endif // REPLY_P_H
|
||||
|
346
3rdparty/vreen/vreen/src/api/roster.cpp
vendored
Normal file
@ -0,0 +1,346 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
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<int, QString> Roster::tags() const
|
||||
{
|
||||
return d_func()->tags;
|
||||
}
|
||||
|
||||
void Roster::setTags(const QMap<int, QString> &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<FriendRequestList> *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<ReplyBase<FriendRequestList>>("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<int, QString> 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"
|
||||
|
114
3rdparty/vreen/vreen/src/api/roster.h
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QVariant>
|
||||
#include <QStringList>
|
||||
|
||||
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<int, QString> tags() const;
|
||||
void setTags(const QMap<int, QString> &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<FriendRequestList> *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<int, QString> &);
|
||||
void syncFinished(bool success);
|
||||
void uidChanged(int uid);
|
||||
protected:
|
||||
QScopedPointer<RosterPrivate> 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
|
||||
|
111
3rdparty/vreen/vreen/src/api/roster_p.h
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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<int, Buddy*> 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<int, QString> tags;
|
||||
|
||||
//TODO i want to use Qt5 slots
|
||||
//class Updater {
|
||||
//public:
|
||||
// typedef std::function<void (Client *client, const IdList &idList, const QVariant &query)> 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> 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
|
||||
|
73
3rdparty/vreen/vreen/src/api/utils.cpp
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QStringBuilder>
|
||||
#include <QTextDocument>
|
||||
#include <QUrl>
|
||||
|
||||
//#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
|
||||
|
151
3rdparty/vreen/vreen/src/api/utils.h
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QStringList>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
namespace Vreen {
|
||||
|
||||
typedef QList<int> IdList;
|
||||
|
||||
template <typename T>
|
||||
Q_INLINE_TEMPLATE T sender_cast(QObject *sender)
|
||||
{
|
||||
#ifndef QT_NO_DEBUG
|
||||
Q_ASSERT(qobject_cast<T>(sender));
|
||||
#endif
|
||||
return static_cast<T>(sender);
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
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<typename X,typename T, int N>
|
||||
Q_INLINE_TEMPLATE X strToEnum(const T &str, const char *(&strings)[N])
|
||||
{
|
||||
return static_cast<X>(strToEnum(str,strings));
|
||||
}
|
||||
|
||||
template<int N>
|
||||
Q_INLINE_TEMPLATE QLatin1String enumToStr(int i, const char *(&strings)[N])
|
||||
{
|
||||
return QLatin1String((i < 0 || i >= N) ? 0 : strings[i]);
|
||||
}
|
||||
|
||||
template<int N>
|
||||
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<typename Container, typename T, typename LessThan>
|
||||
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<int N>
|
||||
Q_INLINE_TEMPLATE size_t strCount(const char *(&)[N])
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
template <typename Item, typename Value, typename Method>
|
||||
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 <typename Item, typename Value>
|
||||
struct Comparator : public ComparatorBase<Item, Value, Value (*)(const Item &)>
|
||||
{
|
||||
typedef Value (*Method)(const Item &);
|
||||
Comparator(Method method, Qt::SortOrder order = Qt::AscendingOrder) :
|
||||
ComparatorBase<Item, Value, Value (*)(const Item &)>(method, order)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Container>
|
||||
struct IdComparator : public Comparator<Container, int>
|
||||
{
|
||||
IdComparator(Qt::SortOrder order = Qt::AscendingOrder) :
|
||||
Comparator<Container, int>(id_, order)
|
||||
{
|
||||
|
||||
}
|
||||
private:
|
||||
inline static int id_(const Container &a) { return a.id(); }
|
||||
};
|
||||
|
||||
|
||||
} //namespace Vreen
|
||||
|
||||
#endif // UTILS_H
|
||||
|
37
3rdparty/vreen/vreen/src/api/utils_p.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2013 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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
|
34
3rdparty/vreen/vreen/src/api/vk_global.h
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QObject>
|
||||
|
||||
#define VK_SHARED_EXPORT
|
||||
typedef QList<int> IdList;
|
||||
|
||||
#endif // API_GLOBAL_H
|
||||
|
12
3rdparty/vreen/vreen/src/api/vreen.pc.cmake
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
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}
|
||||
|
247
3rdparty/vreen/vreen/src/api/wallpost.cpp
vendored
Normal file
@ -0,0 +1,247 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QDateTime>
|
||||
#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
|
||||
|
90
3rdparty/vreen/vreen/src/api/wallpost.h
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QSharedDataPointer>
|
||||
#include <QVariant>
|
||||
#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<typename T>
|
||||
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<WallPostData> d;
|
||||
};
|
||||
typedef QList<WallPost> WallPostList;
|
||||
|
||||
} //namespace Vreen
|
||||
|
||||
#endif // WALLPOST_H
|
||||
|
163
3rdparty/vreen/vreen/src/api/wallsession.cpp
vendored
Normal file
@ -0,0 +1,163 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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 <QNetworkReply>
|
||||
|
||||
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<Reply*>(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<Reply*>(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"
|
||||
|
71
3rdparty/vreen/vreen/src/api/wallsession.h
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Vreen - vk.com API Qt bindings
|
||||
**
|
||||
** Copyright © 2012 Aleksey Sidorov <gorthauer87@ya.ru>
|
||||
**
|
||||
*****************************************************************************
|
||||
**
|
||||
** $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<WallSessionPrivate> 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
|
||||
|
@ -206,6 +206,8 @@ 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(AUDIOCD ON "Devices: Audio CD support"
|
||||
DEPENDS "libcdio" CDIO_FOUND
|
||||
)
|
||||
@ -271,6 +273,12 @@ 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})
|
||||
|
||||
|
@ -401,5 +401,23 @@
|
||||
<file>volumeslider-handle_glow.png</file>
|
||||
<file>volumeslider-handle.png</file>
|
||||
<file>volumeslider-inset.png</file>
|
||||
<file>vk/add.png</file>
|
||||
<file>vk/bookmarks.png</file>
|
||||
<file>vk/delete.png</file>
|
||||
<file>vk/discography.png</file>
|
||||
<file>vk/download.png</file>
|
||||
<file>vk/edit.png</file>
|
||||
<file>vk/find.png</file>
|
||||
<file>vk/group.png</file>
|
||||
<file>vk/my_music.png</file>
|
||||
<file>vk/play_alt.png</file>
|
||||
<file>vk/playlist.png</file>
|
||||
<file>vk/recommends.png</file>
|
||||
<file>vk/remove.png</file>
|
||||
<file>vk/upload.png</file>
|
||||
<file>vk/user.png</file>
|
||||
<file>vk/deactivated.gif</file>
|
||||
<file>providers/vk.png</file>
|
||||
<file>vk/link.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
data/providers/vk.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
data/vk/add.png
Normal file
After Width: | Height: | Size: 185 B |
BIN
data/vk/bookmarks.png
Normal file
After Width: | Height: | Size: 655 B |
BIN
data/vk/deactivated.gif
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
data/vk/delete.png
Normal file
After Width: | Height: | Size: 351 B |
BIN
data/vk/discography.png
Normal file
After Width: | Height: | Size: 486 B |
BIN
data/vk/download.png
Normal file
After Width: | Height: | Size: 323 B |
BIN
data/vk/edit.png
Normal file
After Width: | Height: | Size: 412 B |