├── .gitignore ├── .gitmodules ├── .travis.yml ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── ChangeLog ├── LICENSE.md ├── README.md ├── appveyor.yml ├── cmake ├── CommonUtils.cmake ├── CompilerUtils.cmake └── QtBundleUtils.cmake ├── cmake_uninstall.cmake.in ├── examples ├── cpp │ └── phonefetcher │ │ ├── main.cpp │ │ ├── phonefetcher.cpp │ │ └── phonefetcher.h └── quick │ ├── audio │ └── qml │ │ ├── ScrollDecorator.qml │ │ ├── images │ │ └── media-optical-audio.png │ │ ├── main.qml │ │ └── simple.qmlproject │ ├── common │ ├── declarativeview.cpp │ ├── declarativeview.h │ └── main.cpp │ └── dialogs │ └── qml │ ├── ScrollDecorator.qml │ ├── main.qml │ └── simple.qmlproject ├── src ├── CMakeLists.txt ├── api │ ├── CMakeLists.txt │ ├── abstractlistmodel.cpp │ ├── abstractlistmodel.h │ ├── attachment.cpp │ ├── attachment.h │ ├── audio.cpp │ ├── audio.h │ ├── audioitem.cpp │ ├── audioitem.h │ ├── chatsession.cpp │ ├── chatsession.h │ ├── client.cpp │ ├── client.h │ ├── client_p.h │ ├── commentssession.cpp │ ├── commentssession.h │ ├── connection.cpp │ ├── connection.h │ ├── connection_p.h │ ├── contact.cpp │ ├── contact.h │ ├── contact_p.h │ ├── contentdownloader.cpp │ ├── contentdownloader.h │ ├── contentdownloader_p.h │ ├── dynamicpropertydata.cpp │ ├── dynamicpropertydata_p.h │ ├── friendrequest.cpp │ ├── friendrequest.h │ ├── groupchatsession.cpp │ ├── groupchatsession.h │ ├── groupmanager.cpp │ ├── groupmanager.h │ ├── groupmanager_p.h │ ├── json.cpp │ ├── json.h │ ├── localstorage.cpp │ ├── localstorage.h │ ├── longpoll.cpp │ ├── longpoll.h │ ├── longpoll_p.h │ ├── message.cpp │ ├── message.h │ ├── messagemodel.cpp │ ├── messagemodel.h │ ├── messagesession.cpp │ ├── messagesession.h │ ├── messagesession_p.h │ ├── newsfeed.cpp │ ├── newsfeed.h │ ├── newsitem.cpp │ ├── newsitem.h │ ├── pollitem.cpp │ ├── pollitem.h │ ├── pollprovider.cpp │ ├── pollprovider.h │ ├── reply.cpp │ ├── reply.h │ ├── reply_p.h │ ├── roster.cpp │ ├── roster.h │ ├── roster_p.h │ ├── utils.cpp │ ├── utils.h │ ├── utils_p.h │ ├── vk_global.h │ ├── vreen.pc.cmake │ ├── wallpost.cpp │ ├── wallpost.h │ ├── wallsession.cpp │ └── wallsession.h ├── auth │ ├── direct │ │ ├── CMakeLists.txt │ │ ├── directauth.qbs │ │ ├── directconnection.cpp │ │ └── directconnection_p.h │ └── widget │ │ ├── CMakeLists.txt │ │ ├── oauth.qbs │ │ ├── oauthconnection.cpp │ │ └── oauthconnection.h └── qml │ ├── CMakeLists.txt │ ├── qmldir │ ├── PhotoModel.qml │ └── qmldir │ └── src │ ├── audiomodel.cpp │ ├── audiomodel.h │ ├── buddymodel.cpp │ ├── buddymodel.h │ ├── chatmodel.cpp │ ├── chatmodel.h │ ├── clientimpl.cpp │ ├── clientimpl.h │ ├── commentsmodel.cpp │ ├── commentsmodel.h │ ├── dialogsmodel.cpp │ ├── dialogsmodel.h │ ├── newsfeedmodel.cpp │ ├── newsfeedmodel.h │ ├── vkitqmlplugin.h │ ├── vreenplugin.cpp │ ├── wallmodel.cpp │ └── wallmodel.h └── tests ├── auto ├── LongPoll │ └── tst_longpoll.cpp ├── Roster │ └── tst_roster.cpp └── connection │ └── tst_connection.cpp └── common └── utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated in the Qt build system 2 | # ---------------------------------------------------------------------------- 3 | 4 | qt-* 5 | build 6 | release* 7 | debug* 8 | callgrind.out.* 9 | pcviewer.cfg 10 | *~ 11 | *.a 12 | *.la 13 | *.core 14 | *.moc 15 | *.o 16 | *.obj 17 | *.orig 18 | *.swp 19 | *.rej 20 | *.so 21 | *.pbxuser 22 | *.mode1 23 | *.mode1v3 24 | *_pch.h.cpp 25 | *_resource.rc 26 | .#* 27 | *.*# 28 | .qmake.cache 29 | .qmake.vars 30 | *.prl 31 | tags 32 | .DS_Store 33 | *.debug 34 | Makefile* 35 | *.prl 36 | *.app 37 | *.pro.user 38 | *.qmlproject.user* 39 | moc_*.cpp 40 | ui_*.h 41 | qrc_*.cpp 42 | 43 | # xemacs temporary files 44 | *.flc 45 | 46 | # Vim temporary files 47 | .*.swp 48 | 49 | # Visual Studio generated files 50 | *.ib_pdb_index 51 | *.idb 52 | *.ilk 53 | *.pdb 54 | *.sln 55 | *.suo 56 | *.vcproj 57 | *.vcxproj 58 | *.vcxproj.filters 59 | *vcproj.*.*.user 60 | *.ncb 61 | *.*sdf 62 | Debug 63 | Release 64 | 65 | # MinGW generated files 66 | *.Debug 67 | *.Release 68 | 69 | .pch 70 | .rcc 71 | 72 | # Symbian build system generated files 73 | # --------------------- 74 | 75 | ABLD.BAT 76 | bld.inf 77 | *.mmp 78 | *.mk 79 | *.rss 80 | *.loc 81 | !s60main.rss 82 | *.pkg 83 | plugin_commonU.def 84 | *.qtplugin 85 | *.sis 86 | *.sisx 87 | 88 | # Generated by abldfast.bat from devtools. 89 | .abldsteps.* 90 | 91 | # Carbide project files 92 | # --------------------- 93 | .project 94 | .cproject 95 | .make.cache 96 | 97 | qtc-debugging-helper 98 | 99 | #svn file 100 | */.svn/* 101 | 102 | # linux shared libraries 103 | *.so* 104 | 105 | #mac shared libraries 106 | *.dylib* 107 | 108 | *.user 109 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alekseysidorov/vreen/0ab13c7d8960c3fb9ae06cb91e37ff6ac07a3da3/.gitmodules -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | sudo: required 3 | dist: trusty 4 | compiler: 5 | - clang 6 | os: 7 | - osx 8 | 9 | before_install: 10 | - brew update 11 | - brew install qt5 12 | 13 | before_script: 14 | - cmake . 15 | 16 | script: 17 | - cmake --build . 18 | - ctest --output-on-failure -C Debug 19 | 20 | branches: 21 | only: 22 | - master 23 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Vreen is primarily authored by: 2 | 3 | * Aleksey Sidorov 4 | 5 | Contributors include: 6 | 7 | * Alexey Shmalko 8 | * Ruslan Nigmatullin 9 | * Vlad Maltsev 10 | * Aleksey Ksenzov 11 | * Nicolay Izoderov 12 | * Hamper 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | project(vreen) 3 | 4 | cmake_minimum_required(VERSION 3.0 FATAL_ERROR) 5 | 6 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 7 | 8 | include(CommonUtils) 9 | 10 | option(VREEN_WITH_AUTH_WIDGET "Enable widget based oauth authorization" ON) 11 | option(VREEN_WITH_DIRECTAUTH "Enable direct authorization" OFF) 12 | option(VREEN_WITH_QMLAPI "Enable QtQuick bindings for vreen" ON) 13 | option(VREEN_WITH_EXAMPLES "Enable vreen tests" ON) 14 | option(VREEN_WITH_TESTS "Enable vreen examples" ON) 15 | option(VREEN_INSTALL_HEADERS "Install devel headers for vreen" ON) 16 | option(VREEN_DEVELOPER_BUILD "Install devel headers for vreen" OFF) 17 | 18 | #TODO check if vars is defined 19 | set(RLIBDIR bin) 20 | set(LIBDIR lib${LIB_SUFFIX}) 21 | set(LIB_DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIBDIR}) 22 | if(APPLE) 23 | set(CMAKE_INSTALL_NAME_DIR "${LIB_DESTINATION}") #hack for mac 24 | endif() 25 | 26 | set(CMAKE_VREEN_VERSION_MAJOR 2 CACHE INT "Major vk version number" FORCE) 27 | set(CMAKE_VREEN_VERSION_MINOR 0 CACHE INT "Minor vk version number" FORCE) 28 | set(CMAKE_VREEN_VERSION_PATCH 0 CACHE INT "Release vk version number" FORCE) 29 | set(CMAKE_VREEN_VERSION_STRING "${CMAKE_VREEN_VERSION_MAJOR}.${CMAKE_VREEN_VERSION_MINOR}.${CMAKE_VREEN_VERSION_PATCH}" CACHE STRING "vreen version string" FORCE) 30 | 31 | set(QT_IMPORTS_DIR "/usr/lib/x86_64-linux-gnu/qt5/qml/" CACHE PATH "Qt qml imports directory") 32 | set(VREEN_INCLUDE_DIR ${PROJECT_BINARY_DIR}/include) 33 | set(VREEN_PRIVATE_INCLUDE_DIR ${VREEN_INCLUDE_DIR}/vreen/${CMAKE_VREEN_VERSION_STRING}) 34 | 35 | find_package(Qt5Core REQUIRED) 36 | find_package(Qt5Widgets REQUIRED) 37 | 38 | add_subdirectory(src) 39 | 40 | # if(VREEN_WITH_EXAMPLES) 41 | # add_subdirectory(examples) 42 | # endif() 43 | # if(VREEN_WITH_TESTS) 44 | # enable_testing() 45 | # add_subdirectory(tests) 46 | # endif() 47 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alekseysidorov/vreen/0ab13c7d8960c3fb9ae06cb91e37ff6ac07a3da3/ChangeLog -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | clone_depth: 5 2 | 3 | environment: 4 | matrix: 5 | - GENERATOR : "Visual Studio 14 2015 Win64" 6 | QTDIR: C:\Qt\5.6.3\msvc2015_64 7 | PLATFORM: x64 8 | - GENERATOR : "Visual Studio 14 2015" 9 | QTDIR: C:\Qt\5.6.3\msvc2015 10 | PLATFORM: Win32 11 | 12 | image: Visual Studio 2015 13 | 14 | configuration: 15 | - Release 16 | 17 | install: 18 | - set PATH=%QTDIR%\bin;%PATH% 19 | - set Qt5_DIR=%QTDIR%\lib\cmake\Qt5 20 | - set PATH=C:\MinGW\bin;C:\MinGW\msys\1.0;%PATH% 21 | - set PATH=%PATH:C:\Program Files\Git\usr\bin=% # trick to remove sh.exe 22 | 23 | before_build: 24 | - mkdir build 25 | - cd build 26 | - mkdir bin 27 | - set OUTPUT_DIR=%cd%\bin 28 | - cmake "-G%GENERATOR%" 29 | -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG="%OUTPUT_DIR%" 30 | -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE="%OUTPUT_DIR%" 31 | -DCMAKE_CXX_FLAGS_INIT="%CMAKE_CXX_FLAGS_INIT%" 32 | .. 33 | 34 | 35 | build_script: 36 | - cmake --build . 37 | 38 | test_script: 39 | - ctest --output-on-failure -C Debug 40 | -------------------------------------------------------------------------------- /cmake/CompilerUtils.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCXXCompilerFlag) 2 | 3 | macro(UPDATE_CXX_COMPILER_FLAG target flag name) 4 | check_cxx_compiler_flag(${flag} COMPILER_SUPPORTS_${name}_FLAG) 5 | if(COMPILER_SUPPORTS_${name}_FLAG) 6 | add_definitions(${flag}) 7 | endif() 8 | set(${name} TRUE) 9 | endmacro() 10 | -------------------------------------------------------------------------------- /cmake/QtBundleUtils.cmake: -------------------------------------------------------------------------------- 1 | if(NOT CMAKE_DEBUG_POSTFIX) 2 | if(APPLE) 3 | set(CMAKE_DEBUG_POSTFIX _debug) 4 | elseif(WIN32) 5 | set(CMAKE_DEBUG_POSTFIX d) 6 | endif() 7 | endif() 8 | 9 | macro(DEPLOY_QT_PLUGIN _path) 10 | get_filename_component(_dir ${_path} PATH) 11 | get_filename_component(name ${_path} NAME_WE) 12 | string(TOUPPER ${CMAKE_BUILD_TYPE} _type) 13 | if(${_type} STREQUAL "DEBUG") 14 | set(name "${name}${CMAKE_DEBUG_POSTFIX}") 15 | endif() 16 | 17 | set(name "${CMAKE_SHARED_LIBRARY_PREFIX}${name}") 18 | set(PLUGIN "${QT_PLUGINS_DIR}/${_dir}/${name}${CMAKE_SHARED_LIBRARY_SUFFIX}") 19 | #trying to search lib with suffix 4 20 | if(NOT EXISTS ${PLUGIN}) 21 | set(name "${name}4") 22 | set(PLUGIN "${QT_PLUGINS_DIR}/${_dir}/${name}${CMAKE_SHARED_LIBRARY_SUFFIX}") 23 | endif() 24 | 25 | #message(${PLUGIN}) 26 | if(EXISTS ${PLUGIN}) 27 | message(STATUS "Deployng ${_path} plugin") 28 | install(FILES ${PLUGIN} DESTINATION "${PLUGINSDIR}/${_dir}" COMPONENT Runtime) 29 | else() 30 | message(STATUS "Could not deploy ${_path} plugin") 31 | endif() 32 | endmacro() 33 | 34 | macro(DEPLOY_QT_PLUGINS) 35 | foreach(plugin ${ARGN}) 36 | deploy_qt_plugin(${plugin}) 37 | endforeach() 38 | endmacro() 39 | 40 | macro(DEPLOY_QML_MODULE _path) 41 | string(TOUPPER ${CMAKE_BUILD_TYPE} _type) 42 | set(_importPath "${QT_IMPORTS_DIR}/${_path}") 43 | if(EXISTS ${_importPath}) 44 | if(WIN32 OR APPLE) 45 | if(${_type} STREQUAL "DEBUG") 46 | set(_libPattern "[^${CMAKE_DEBUG_POSTFIX}]${CMAKE_SHARED_LIBRARY_SUFFIX}$") 47 | else() 48 | set(_libPattern "${CMAKE_DEBUG_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}$") 49 | endif() 50 | else() 51 | set(_libPattern "^[*]") 52 | endif() 53 | 54 | #evil version 55 | message(STATUS "Deployng ${_path} QtQuick module") 56 | install(DIRECTORY ${_importPath} DESTINATION ${IMPORTSDIR} COMPONENT Runtime 57 | PATTERN "*.pdb" EXCLUDE 58 | REGEX "${_libPattern}" EXCLUDE 59 | ) 60 | else() 61 | message(STATUS "Could not deploy ${_path} QtQuick module") 62 | endif() 63 | endmacro() 64 | 65 | macro(DEPLOY_QML_MODULES) 66 | foreach(plugin ${ARGN}) 67 | deploy_qml_module(${plugin}) 68 | endforeach() 69 | endmacro() 70 | 71 | macro(DEFINE_BUNDLE_PATHS _name) 72 | if(WIN32) 73 | set(BUNDLE_NAME ${_name}.exe) 74 | set(BINDIR bin) 75 | set(BUNDLE_PATH "\${CMAKE_INSTALL_PREFIX}/${BINDIR}/${BUNDLE_NAME}") 76 | set(LIBDIR lib${LIB_SUFFIX}) 77 | set(SHAREDIR share) 78 | set(PLUGINSDIR bin) 79 | set(IMPORTSDIR ${BINDIR}) 80 | set(RLIBDIR ${BINDIR}) 81 | elseif(APPLE) 82 | set(BUNDLE_NAME ${_name}.app) 83 | set(BUNDLE_PATH "\${CMAKE_INSTALL_PREFIX}/${BUNDLE_NAME}") 84 | set(BINDIR ${BUNDLE_NAME}/Contents/MacOS) 85 | set(LIBDIR ${BINDIR}) 86 | set(RLIBDIR ${BUNDLE_NAME}/Contents/Frameworks) 87 | set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources) 88 | set(PLUGINSDIR ${BUNDLE_NAME}/Contents/PlugIns) 89 | set(IMPORTSDIR ${BINDIR}) 90 | else() 91 | set(BUNDLE_NAME ${_name}) 92 | set(BINDIR bin) 93 | set(BUNDLE_PATH "\${CMAKE_INSTALL_PREFIX}/${BINDIR}/${BUNDLE_NAME}") 94 | set(LIBDIR lib${LIB_SUFFIX}) 95 | set(RLIBDIR ${LIBDIR}) 96 | set(SHAREDIR share/apps/${_name}) 97 | set(PLUGINSDIR ${LIBDIR}/plugins/) 98 | set(IMPORTSDIR ${BINDIR}) #)${LIBDIR}/imports) 99 | endif() 100 | 101 | if(APPLE) 102 | set(DEPLOY_APP "${BUNDLE_NAME}") 103 | else() 104 | set(DEPLOY_APP "bin/${BUNDLE_NAME}") 105 | endif() 106 | endmacro() 107 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | MESSAGE(FATAL_ERROR "Cannot find install manifest: "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt"") 3 | ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | STRING(REGEX REPLACE "\n" ";" files "${files}") 7 | FOREACH(file ${files}) 8 | MESSAGE(STATUS "Uninstalling "$ENV{DESTDIR}${file}"") 9 | IF(EXISTS "$ENV{DESTDIR}${file}") 10 | EXEC_PROGRAM( 11 | "@CMAKE_COMMAND@" ARGS "-E remove "$ENV{DESTDIR}${file}"" 12 | OUTPUT_VARIABLE rm_out 13 | RETURN_VALUE rm_retval 14 | ) 15 | IF(NOT "${rm_retval}" STREQUAL 0) 16 | MESSAGE(FATAL_ERROR "Problem when removing "$ENV{DESTDIR}${file}"") 17 | ENDIF(NOT "${rm_retval}" STREQUAL 0) 18 | ELSE(EXISTS "$ENV{DESTDIR}${file}") 19 | MESSAGE(STATUS "File "$ENV{DESTDIR}${file}" does not exist.") 20 | ENDIF(EXISTS "$ENV{DESTDIR}${file}") 21 | ENDFOREACH(file) 22 | -------------------------------------------------------------------------------- /examples/cpp/phonefetcher/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include 26 | #include "phonefetcher.h" 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | QApplication a(argc, argv); 31 | a.setApplicationName("example"); 32 | a.setOrganizationName("vreen"); 33 | a.setOrganizationDomain("https://github.com/gorthauer/vreen"); 34 | a.setQuitOnLastWindowClosed(false); 35 | 36 | PhoneFetcher fetcher; 37 | fetcher.fetch(); 38 | return a.exec(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/cpp/phonefetcher/phonefetcher.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "phonefetcher.h" 26 | #include 27 | #include 28 | #include 29 | 30 | PhoneFetcher::PhoneFetcher(QObject *parent) : 31 | Vreen::Client(parent) 32 | { 33 | auto auth = new Vreen::OAuthConnection(3220807, this); 34 | auth->setConnectionOption(Vreen::Connection::ShowAuthDialog, true); 35 | auth->setConnectionOption(Vreen::Connection::KeepAuthData, true); 36 | setConnection(auth); 37 | 38 | connect(this, &PhoneFetcher::onlineStateChanged, this, &PhoneFetcher::onOnlineChanged); 39 | connect(roster(), &Vreen::Roster::syncFinished, this, &PhoneFetcher::onSynced); 40 | } 41 | 42 | void PhoneFetcher::fetch() 43 | { 44 | connectToHost(); 45 | } 46 | 47 | void PhoneFetcher::onOnlineChanged(bool online) 48 | { 49 | if (online) { 50 | auto fields = { 51 | QStringLiteral("first_name"), 52 | QStringLiteral("last_name"), 53 | QStringLiteral("contacts") 54 | }; 55 | roster()->sync(fields); 56 | } 57 | } 58 | 59 | void PhoneFetcher::onSynced(bool success) 60 | { 61 | if (success) { 62 | qDebug() << tr("-- %1 contacts recieved").arg(roster()->buddies().count()); 63 | for (const auto &buddy : roster()->buddies()) { 64 | qDebug() << tr("name: %1, home: %2, mobile: %3").arg(buddy->name()) 65 | .arg(buddy->homePhone().isEmpty() ? tr("unknown") : buddy->homePhone()) 66 | .arg(buddy->mobilePhone().isEmpty() ? tr("unknown") : buddy->mobilePhone()); 67 | } 68 | } 69 | qApp->quit(); 70 | } 71 | -------------------------------------------------------------------------------- /examples/cpp/phonefetcher/phonefetcher.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef PHONEFETCHER_H 26 | #define PHONEFETCHER_H 27 | 28 | #include 29 | #include 30 | 31 | class PhoneFetcher : public Vreen::Client 32 | { 33 | Q_OBJECT 34 | public: 35 | explicit PhoneFetcher(QObject *parent = 0); 36 | void fetch(); 37 | public slots: 38 | void onOnlineChanged(bool online); 39 | void onSynced(bool success); 40 | }; 41 | 42 | #endif // PHONEFETCHER_H 43 | -------------------------------------------------------------------------------- /examples/quick/audio/qml/ScrollDecorator.qml: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 | ** All rights reserved. 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) 6 | ** 7 | ** This file is part of the examples of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:BSD$ 10 | ** You may use this file under the terms of the BSD license as follows: 11 | ** 12 | ** "Redistribution and use in source and binary forms, with or without 13 | ** modification, are permitted provided that the following conditions are 14 | ** met: 15 | ** * Redistributions of source code must retain the above copyright 16 | ** notice, this list of conditions and the following disclaimer. 17 | ** * Redistributions in binary form must reproduce the above copyright 18 | ** notice, this list of conditions and the following disclaimer in 19 | ** the documentation and/or other materials provided with the 20 | ** distribution. 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 22 | ** the names of its contributors may be used to endorse or promote 23 | ** products derived from this software without specific prior written 24 | ** permission. 25 | ** 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | import QtQuick 2.0 42 | 43 | Item { 44 | id: scrollBar 45 | 46 | property real position: orientation == Qt.Vertical ? flickableItem.visibleArea.yPosition 47 | : flickableItem.visibleArea.xPosition 48 | property real pageSize: orientation == Qt.Vertical ? flickableItem.visibleArea.heightRatio 49 | : flickableItem.visibleArea.widthRatio 50 | property Flickable flickableItem 51 | property int orientation: Qt.Vertical 52 | 53 | property int __scrollSize: 6 54 | 55 | width: orientation == Qt.Vertical ? __scrollSize : flickableItem.width 56 | height: orientation == Qt.Vertical ? flickableItem.height : __scrollSize 57 | anchors.right: flickableItem.right 58 | 59 | // A light, semi-transparent background 60 | Rectangle { 61 | id: background 62 | anchors.fill: parent 63 | radius: orientation == Qt.Vertical ? (width/2 - 1) : (height/2 - 1) 64 | color: "black" 65 | opacity: area.containsMouse ? 0.1 : 0 66 | } 67 | 68 | // Size the bar to the required size, depending upon the orientation. 69 | Rectangle { 70 | id: handle 71 | x: orientation == Qt.Vertical ? 1 : (scrollBar.position * (scrollBar.width-2) + 1) 72 | y: orientation == Qt.Vertical ? (scrollBar.position * (scrollBar.height-2) + 1) : 1 73 | width: orientation == Qt.Vertical ? (parent.width-2) : (scrollBar.pageSize * (scrollBar.width-2)) 74 | height: orientation == Qt.Vertical ? (scrollBar.pageSize * (scrollBar.height-2)) : (parent.height-2) 75 | radius: orientation == Qt.Vertical ? (width/2 - 1) : (height/2 - 1) 76 | color: "black" 77 | opacity: 0 78 | } 79 | 80 | MouseArea { 81 | id: area 82 | hoverEnabled: true 83 | anchors.fill: parent 84 | } 85 | 86 | // Only show the scrollbars when the view is moving. 87 | states: [ 88 | State { 89 | name: "ShowBars" 90 | when: flickableItem.movingVertically || area.containsMouse 91 | PropertyChanges { target: handle; opacity: 0.3 } 92 | } 93 | ] 94 | } 95 | -------------------------------------------------------------------------------- /examples/quick/audio/qml/images/media-optical-audio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alekseysidorov/vreen/0ab13c7d8960c3fb9ae06cb91e37ff6ac07a3da3/examples/quick/audio/qml/images/media-optical-audio.png -------------------------------------------------------------------------------- /examples/quick/audio/qml/simple.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator, version 2.6.81 */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /examples/quick/common/declarativeview.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "declarativeview.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace { 32 | 33 | static QString testPath(const QString &source) 34 | { 35 | QString path = QCoreApplication::applicationDirPath() + source; 36 | if (QFileInfo(path).exists()) 37 | return path; 38 | else 39 | return QString(); 40 | } 41 | 42 | QString adjustPath(const QString &source) 43 | { 44 | QString path = testPath(QLatin1String("/../share/") + source); 45 | if (!path.isEmpty()) 46 | return path; 47 | path = testPath(QLatin1String("/../Resources/") + source); 48 | if (!path.isEmpty()) 49 | return path; 50 | path = testPath(QLatin1String("/../share/apps/") + qApp->applicationName() + QLatin1String("/") + source); 51 | if (!path.isEmpty()) 52 | return path; 53 | path = testPath("/" + source); 54 | return path; 55 | } 56 | 57 | } //namespace 58 | 59 | DeclarativeView::DeclarativeView(QWindow *parent) : 60 | QQuickView(parent) 61 | { 62 | QQmlEngine *e = engine(); 63 | e->addImportPath("../../bin"); 64 | 65 | setSource(QUrl(adjustPath("qml/main.qml"))); 66 | setResizeMode(SizeRootObjectToView); 67 | } 68 | -------------------------------------------------------------------------------- /examples/quick/common/declarativeview.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef DECLARATIVEVIEW_H 26 | #define DECLARATIVEVIEW_H 27 | 28 | #include 29 | 30 | class DeclarativeView : public QQuickView 31 | { 32 | Q_OBJECT 33 | public: 34 | explicit DeclarativeView(QWindow *parent = 0); 35 | 36 | signals: 37 | 38 | public slots: 39 | 40 | }; 41 | 42 | #endif // DECLARATIVEVIEW_H 43 | -------------------------------------------------------------------------------- /examples/quick/common/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include 26 | #include "declarativeview.h" 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | QApplication a(argc, argv); 35 | a.setApplicationName("example"); 36 | a.setOrganizationName("vreen"); 37 | a.setOrganizationDomain("https://github.com/gorthauer/vreen"); 38 | 39 | DeclarativeView view; 40 | if (!view.errors().empty()) { 41 | foreach (const QQmlError &e, view.errors()) 42 | std::cerr << e.toString().toUtf8().data() << std::endl; 43 | return -1; 44 | } 45 | 46 | 47 | view.showNormal(); 48 | return a.exec(); 49 | } 50 | -------------------------------------------------------------------------------- /examples/quick/dialogs/qml/ScrollDecorator.qml: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 | ** All rights reserved. 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) 6 | ** 7 | ** This file is part of the examples of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:BSD$ 10 | ** You may use this file under the terms of the BSD license as follows: 11 | ** 12 | ** "Redistribution and use in source and binary forms, with or without 13 | ** modification, are permitted provided that the following conditions are 14 | ** met: 15 | ** * Redistributions of source code must retain the above copyright 16 | ** notice, this list of conditions and the following disclaimer. 17 | ** * Redistributions in binary form must reproduce the above copyright 18 | ** notice, this list of conditions and the following disclaimer in 19 | ** the documentation and/or other materials provided with the 20 | ** distribution. 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 22 | ** the names of its contributors may be used to endorse or promote 23 | ** products derived from this software without specific prior written 24 | ** permission. 25 | ** 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | import QtQuick 2.0 42 | 43 | Item { 44 | id: scrollBar 45 | 46 | property real position: orientation == Qt.Vertical ? flickableItem.visibleArea.yPosition 47 | : flickableItem.visibleArea.xPosition 48 | property real pageSize: orientation == Qt.Vertical ? flickableItem.visibleArea.heightRatio 49 | : flickableItem.visibleArea.widthRatio 50 | property Flickable flickableItem 51 | property int orientation: Qt.Vertical 52 | 53 | property int __scrollSize: 6 54 | 55 | width: orientation == Qt.Vertical ? __scrollSize : flickableItem.width 56 | height: orientation == Qt.Vertical ? flickableItem.height : __scrollSize 57 | anchors.right: flickableItem.right 58 | 59 | // A light, semi-transparent background 60 | Rectangle { 61 | id: background 62 | anchors.fill: parent 63 | radius: orientation == Qt.Vertical ? (width/2 - 1) : (height/2 - 1) 64 | color: "black" 65 | opacity: area.containsMouse ? 0.1 : 0 66 | } 67 | 68 | // Size the bar to the required size, depending upon the orientation. 69 | Rectangle { 70 | id: handle 71 | x: orientation == Qt.Vertical ? 1 : (scrollBar.position * (scrollBar.width-2) + 1) 72 | y: orientation == Qt.Vertical ? (scrollBar.position * (scrollBar.height-2) + 1) : 1 73 | width: orientation == Qt.Vertical ? (parent.width-2) : (scrollBar.pageSize * (scrollBar.width-2)) 74 | height: orientation == Qt.Vertical ? (scrollBar.pageSize * (scrollBar.height-2)) : (parent.height-2) 75 | radius: orientation == Qt.Vertical ? (width/2 - 1) : (height/2 - 1) 76 | color: "black" 77 | opacity: 0 78 | } 79 | 80 | MouseArea { 81 | id: area 82 | hoverEnabled: true 83 | anchors.fill: parent 84 | } 85 | 86 | // Only show the scrollbars when the view is moving. 87 | states: [ 88 | State { 89 | name: "ShowBars" 90 | when: flickableItem.movingVertically || area.containsMouse 91 | PropertyChanges { target: handle; opacity: 0.3 } 92 | } 93 | ] 94 | } 95 | -------------------------------------------------------------------------------- /examples/quick/dialogs/qml/simple.qmlproject: -------------------------------------------------------------------------------- 1 | /* File generated by Qt Creator, version 2.6.81 */ 2 | 3 | import QmlProject 1.1 4 | 5 | Project { 6 | mainFile: "main.qml" 7 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ 9 | QmlFiles { 10 | directory: "." 11 | } 12 | JavaScriptFiles { 13 | directory: "." 14 | } 15 | ImageFiles { 16 | directory: "." 17 | } 18 | /* List of plugin directories passed to QML runtime */ 19 | // importPaths: [ "../exampleplugin" ] 20 | } 21 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT VREEN_INSTALL_HEADERS) 2 | set(INTERNAL_FLAG "INTERNAL") 3 | endif() 4 | if(VREEN_DEVELOPER_BUILD) 5 | set(DEVELOPER_FLAG "DEVELOPER") 6 | endif() 7 | 8 | add_subdirectory(api) 9 | if(VREEN_WITH_QMLAPI) 10 | add_subdirectory(qml) 11 | endif() 12 | if(VREEN_WITH_AUTH_WIDGET) 13 | add_subdirectory(auth/widget) 14 | endif() 15 | if(VREEN_WITH_DIRECTAUTH) 16 | add_subdirectory(auth/direct) 17 | endif() 18 | -------------------------------------------------------------------------------- /src/api/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_simple_library(vreen 2 | SHARED CXX14 3 | ${INTERNAL_FLAG} 4 | ${DEVELOPER_FLAG} 5 | DEFINE_SYMBOL VK_LIBRARY 6 | VERSION ${CMAKE_VREEN_VERSION_STRING} 7 | SOVERSION ${CMAKE_VREEN_VERSION_MAJOR} 8 | INCLUDE_DIR vreen 9 | QT Core Network Gui 10 | ) 11 | -------------------------------------------------------------------------------- /src/api/abstractlistmodel.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "abstractlistmodel.h" 26 | #include 27 | 28 | namespace Vreen { 29 | 30 | AbstractListModel::AbstractListModel(QObject *parent) : 31 | QAbstractListModel(parent) 32 | { 33 | } 34 | 35 | QVariantMap AbstractListModel::get(int row) 36 | { 37 | auto roles = roleNames(); 38 | QVariantMap map; 39 | auto index = createIndex(row, 0); 40 | for (auto it = roles.constBegin(); it != roles.constEnd(); it++) { 41 | auto value = data(index, it.key()); 42 | map.insert(it.value(), value); 43 | } 44 | return map; 45 | } 46 | 47 | QVariant AbstractListModel::get(int row, const QByteArray &field) 48 | { 49 | auto index = createIndex(row, 0); 50 | return data(index, roleNames().key(field)); 51 | } 52 | 53 | } //namespace Vreen 54 | 55 | -------------------------------------------------------------------------------- /src/api/abstractlistmodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef ABSTRACTLISTMODEL_H 26 | #define ABSTRACTLISTMODEL_H 27 | 28 | #include 29 | #include "vk_global.h" 30 | 31 | namespace Vreen { 32 | 33 | class VK_SHARED_EXPORT AbstractListModel : public QAbstractListModel 34 | { 35 | Q_OBJECT 36 | public: 37 | explicit AbstractListModel(QObject *parent = 0); 38 | Q_INVOKABLE QVariantMap get(int row); 39 | Q_INVOKABLE QVariant get(int row, const QByteArray &field); 40 | }; 41 | 42 | } //namespace Vreen 43 | 44 | #endif // ABSTRACTLISTMODEL_H 45 | 46 | -------------------------------------------------------------------------------- /src/api/attachment.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_ATTACHMENT_H 26 | #define VK_ATTACHMENT_H 27 | 28 | #include 29 | #include 30 | #include "vk_global.h" 31 | 32 | namespace Vreen { 33 | 34 | class AttachmentData; 35 | 36 | class VK_SHARED_EXPORT Attachment 37 | { 38 | Q_GADGET 39 | Q_ENUMS(Type) 40 | public: 41 | enum Type { 42 | Photo, 43 | PostedPhoto, 44 | Video, 45 | Audio, 46 | Document, 47 | Graffiti, 48 | Link, 49 | Note, 50 | ApplicationImage, 51 | Poll, 52 | Page, 53 | Other = -1 54 | }; 55 | typedef QList List; 56 | typedef QMultiHash Hash; 57 | 58 | Attachment(); 59 | Attachment(const Attachment &); 60 | Attachment &operator=(const Attachment &); 61 | ~Attachment(); 62 | 63 | void setData(const QVariantMap &data); 64 | QVariantMap data() const; 65 | Type type() const; 66 | void setType(Type); 67 | void setType(const QString &type); 68 | int ownerId() const; 69 | void setOwnerId(int ownerId); 70 | int mediaId() const; 71 | void setMediaId(int mediaId); 72 | bool isFetched() const; 73 | 74 | static Attachment fromData(const QVariant &data); 75 | static List fromVariantList(const QVariantList &list); 76 | static QVariantList toVariantList(const List &list); 77 | static Hash toHash(const List &list); 78 | static QVariantMap toVariantMap(const Hash &hash); 79 | 80 | QVariant property(const QString &name, const QVariant &def = QVariant()) const; 81 | template 82 | T property(const char *name, const T &def) const 83 | { return QVariant::fromValue(property(name, QVariant::fromValue(def))); } 84 | void setProperty(const QString &name, const QVariant &value); 85 | QStringList dynamicPropertyNames() const; 86 | template 87 | static T to(const Attachment &attachment); 88 | template 89 | static Attachment from(const T &item); 90 | 91 | friend QDataStream &operator <<(QDataStream &out, const Vreen::Attachment &item); 92 | friend QDataStream &operator >>(QDataStream &out, Vreen::Attachment &item); 93 | protected: 94 | Attachment(const QVariantMap &data); 95 | Attachment(const QString &string); 96 | private: 97 | QSharedDataPointer d; 98 | }; 99 | 100 | } // namespace Vreen 101 | 102 | Q_DECLARE_METATYPE(Vreen::Attachment) 103 | Q_DECLARE_METATYPE(Vreen::Attachment::List) 104 | Q_DECLARE_METATYPE(Vreen::Attachment::Hash) 105 | Q_DECLARE_METATYPE(Vreen::Attachment::Type) 106 | 107 | 108 | #endif // VK_ATTACHMENT_H 109 | 110 | -------------------------------------------------------------------------------- /src/api/audio.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_AUDIO_H 26 | #define VK_AUDIO_H 27 | 28 | #include 29 | #include "audioitem.h" 30 | #include "abstractlistmodel.h" 31 | #include "reply.h" 32 | 33 | namespace Vreen { 34 | 35 | class Client; 36 | typedef ReplyBase AudioItemListReply; 37 | typedef ReplyBase AudioAlbumItemListReply; 38 | 39 | class AudioProviderPrivate; 40 | class VK_SHARED_EXPORT AudioProvider : public QObject 41 | { 42 | Q_OBJECT 43 | Q_DECLARE_PRIVATE(AudioProvider) 44 | Q_ENUMS(SortOrder) 45 | public: 46 | 47 | enum SortOrder { 48 | SortByDate = 0, 49 | SortByDuration, 50 | SortByPopularity 51 | }; 52 | 53 | AudioProvider(Client *client); 54 | virtual ~AudioProvider(); 55 | AudioItemListReply *getContactAudio(int uid = 0, int count = 50, int offset = 0, int album_id = -1); 56 | AudioItemListReply *getAudiosByIds(const QString& ids); 57 | AudioItemListReply *getRecommendationsForUser(int uid = 0, int count = 50, int offset = 0); 58 | AudioItemListReply *searchAudio(const QString& query, int count = 50, int offset = 0, bool autoComplete = true, Vreen::AudioProvider::SortOrder sort = SortByPopularity, bool withLyrics = false); 59 | AudioAlbumItemListReply *getAlbums(int ownerId, int count = 50, int offset = 0); 60 | IntReply *getCount(int oid = 0); 61 | IntReply *addToLibrary(int aid, int oid, int gid = 0); 62 | IntReply *removeFromLibrary(int aid, int oid); 63 | protected: 64 | QScopedPointer d_ptr; 65 | }; 66 | 67 | class AudioModelPrivate; 68 | class VK_SHARED_EXPORT AudioModel : public AbstractListModel 69 | { 70 | Q_OBJECT 71 | Q_DECLARE_PRIVATE(AudioModel) 72 | 73 | Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged) 74 | public: 75 | 76 | enum Roles { 77 | IdRole = Qt::UserRole + 1, 78 | TitleRole, 79 | ArtistRole, 80 | UrlRole, 81 | DurationRole, 82 | AlbumIdRole, 83 | LyricsIdRole, 84 | OwnerIdRole 85 | }; 86 | 87 | AudioModel(QObject *parent); 88 | virtual ~AudioModel(); 89 | 90 | int count() const; 91 | int findAudio(int id) const; 92 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 93 | virtual int rowCount(const QModelIndex &parent) const; 94 | void setSortOrder(Qt::SortOrder order); 95 | Qt::SortOrder sortOrder() const; 96 | public slots: 97 | void clear(); 98 | void truncate(int count); 99 | void addAudio(const Vreen::AudioItem &item); 100 | void removeAudio(int aid); 101 | signals: 102 | void sortOrderChanged(Qt::SortOrder); 103 | protected: 104 | void insertAudio(int index, const AudioItem &item); 105 | void replaceAudio(int index, const AudioItem &item); 106 | void setAudio(const AudioItemList &items); 107 | virtual void sort(int column, Qt::SortOrder order); 108 | virtual QHash roleNames() const; 109 | private: 110 | QScopedPointer d_ptr; 111 | }; 112 | 113 | } // namespace Vreen 114 | 115 | #endif // VK_AUDIO_H 116 | 117 | -------------------------------------------------------------------------------- /src/api/audioitem.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_AUDIOITEM_H 26 | #define VK_AUDIOITEM_H 27 | 28 | #include 29 | #include "attachment.h" 30 | #include 31 | 32 | class QUrl; 33 | 34 | namespace Vreen { 35 | 36 | class Client; 37 | class AudioItemData; 38 | 39 | class VK_SHARED_EXPORT AudioItem 40 | { 41 | public: 42 | AudioItem(); 43 | AudioItem(const AudioItem &); 44 | AudioItem &operator=(const AudioItem &); 45 | ~AudioItem(); 46 | 47 | int id() const; 48 | void setId(int aid); 49 | int ownerId() const; 50 | void setOwnerId(int ownerId); 51 | QString artist() const; 52 | void setArtist(const QString &artist); 53 | QString title() const; 54 | void setTitle(const QString &title); 55 | qreal duration() const; 56 | void setDuration(qreal duration); 57 | QUrl url() const; 58 | void setUrl(const QUrl &url); 59 | int lyricsId() const; 60 | void setLyricsId(int lyricsId); 61 | int albumId() const; 62 | void setAlbumId(int albumId); 63 | private: 64 | QSharedDataPointer data; 65 | }; 66 | typedef QList AudioItemList; 67 | 68 | class AudioAlbumItemData; 69 | class VK_SHARED_EXPORT AudioAlbumItem 70 | { 71 | public: 72 | AudioAlbumItem(); 73 | AudioAlbumItem(const AudioAlbumItem &other); 74 | AudioAlbumItem &operator=(const AudioAlbumItem &other); 75 | ~AudioAlbumItem(); 76 | 77 | int id() const; 78 | void setId(int id); 79 | int ownerId() const; 80 | void setOwnerId(int ownerId); 81 | QString title() const; 82 | void setTitle(const QString &title); 83 | private: 84 | QSharedDataPointer data; 85 | }; 86 | typedef QList AudioAlbumItemList; 87 | 88 | template<> 89 | AudioItem Attachment::to(const Attachment &data); 90 | 91 | } // namespace Vreen 92 | 93 | Q_DECLARE_METATYPE(Vreen::AudioItem) 94 | Q_DECLARE_METATYPE(Vreen::AudioItemList) 95 | Q_DECLARE_METATYPE(Vreen::AudioAlbumItem) 96 | Q_DECLARE_METATYPE(Vreen::AudioAlbumItemList) 97 | 98 | #endif // VK_AUDIOITEM_H 99 | 100 | -------------------------------------------------------------------------------- /src/api/chatsession.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_CHATSESSION_H 26 | #define VK_CHATSESSION_H 27 | 28 | #include "message.h" 29 | #include "messagesession.h" 30 | 31 | namespace Vreen { 32 | 33 | class Reply; 34 | class ChatSessionPrivate; 35 | class VK_SHARED_EXPORT ChatSession : public MessageSession 36 | { 37 | Q_OBJECT 38 | Q_DECLARE_PRIVATE(ChatSession) 39 | 40 | Q_PROPERTY(Contact *contact READ contact CONSTANT) 41 | public: 42 | ChatSession(Contact *contact); 43 | virtual ~ChatSession(); 44 | 45 | Contact *contact() const; 46 | bool isActive() const; 47 | void setActive(bool set); 48 | protected: 49 | virtual ReplyBase *doGetHistory(int count = 16, int offset = 0); 50 | virtual SendMessageReply *doSendMessage(const Vreen::Message &message); 51 | private: 52 | 53 | Q_PRIVATE_SLOT(d_func(), void _q_message_added(const Vreen::Message &)) 54 | }; 55 | 56 | } // namespace Vreen 57 | 58 | #endif // VK_CHATSESSION_H 59 | 60 | -------------------------------------------------------------------------------- /src/api/client_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 * 60); 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef CLIENT_P_H 26 | #define CLIENT_P_H 27 | 28 | #include "client.h" 29 | #include "reply_p.h" 30 | #include "connection.h" 31 | #include "roster.h" 32 | #include "reply.h" 33 | #include "message.h" 34 | #include "longpoll.h" 35 | #include "utils.h" 36 | #include 37 | #include 38 | #include 39 | 40 | namespace Vreen { 41 | 42 | class ClientPrivate 43 | { 44 | Q_DECLARE_PUBLIC(Client) 45 | public: 46 | ClientPrivate(Client *q) : q_ptr(q), isInvisible(false), trackMessages(true) 47 | { 48 | onlineUpdater.setInterval(15000 * 60); 49 | onlineUpdater.setSingleShot(false); 50 | q->connect(&onlineUpdater, SIGNAL(timeout()), q, SLOT(_q_update_online())); 51 | } 52 | Client *q_ptr; 53 | QString login; 54 | QString password; 55 | QPointer connection; 56 | QPointer roster; 57 | QPointer longPoll; 58 | QPointer groupManager; 59 | QString activity; 60 | bool isInvisible; 61 | bool trackMessages; 62 | QTimer onlineUpdater; 63 | 64 | void setOnlineUpdaterRunning(bool set); 65 | 66 | void _q_connection_state_changed(Vreen::Client::State state); 67 | void _q_error_received(int error); 68 | void _q_reply_finished(const QVariant &); 69 | void _q_network_manager_error(int); 70 | void _q_activity_update_finished(const QVariant &); 71 | void _q_update_online(); 72 | 73 | void processReply(Reply *reply); 74 | 75 | //some orphaned methods 76 | static ReplyBase *getMessages(Client *client, const IdList &list, int previewLength = 0); 77 | }; 78 | 79 | } //namespace Vreen 80 | 81 | #endif // CLIENT_P_H 82 | 83 | -------------------------------------------------------------------------------- /src/api/commentssession.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "commentssession.h" 26 | #include "contact.h" 27 | #include "client.h" 28 | #include "reply.h" 29 | 30 | namespace Vreen { 31 | 32 | class CommentSession; 33 | class CommentSessionPrivate 34 | { 35 | Q_DECLARE_PUBLIC(CommentSession) 36 | public: 37 | CommentSessionPrivate(CommentSession *q, Contact *contact) : 38 | q_ptr(q), contact(contact), postId(0), 39 | sort(Qt::AscendingOrder), 40 | needLikes(true), 41 | previewLenght(0) 42 | 43 | {} 44 | CommentSession *q_ptr; 45 | Contact *contact; 46 | int postId; 47 | Qt::SortOrder sort; 48 | bool needLikes; 49 | int previewLenght; 50 | 51 | void _q_comments_received(const QVariant &response) 52 | { 53 | auto list = response.toList(); 54 | if (!list.isEmpty()) { 55 | list.takeFirst(); 56 | foreach (auto item, list) 57 | emit q_func()->commentAdded(item.toMap()); 58 | } 59 | } 60 | }; 61 | 62 | 63 | /*! 64 | * \brief CommentsSession::CommentsSession 65 | * \param client 66 | */ 67 | CommentSession::CommentSession(Contact *contact) : 68 | QObject(contact), 69 | d_ptr(new CommentSessionPrivate(this, contact)) 70 | { 71 | } 72 | 73 | void CommentSession::setPostId(int postId) 74 | { 75 | Q_D(CommentSession); 76 | d->postId = postId; 77 | } 78 | 79 | int CommentSession::postId() const 80 | { 81 | return d_func()->postId; 82 | } 83 | 84 | CommentSession::~CommentSession() 85 | { 86 | } 87 | 88 | Reply *CommentSession::getComments(int offset, int count) 89 | { 90 | Q_D(CommentSession); 91 | QVariantMap args; 92 | args.insert("owner_id", (d->contact->type() == Contact::GroupType ? -1 : 1) * d->contact->id()); 93 | args.insert("post_id", d->postId); 94 | args.insert("offset", offset); 95 | args.insert("count", count); 96 | args.insert("need_likes", d->needLikes); 97 | args.insert("preview_lenght", d->previewLenght); 98 | args.insert("sort", d->sort == Qt::AscendingOrder ? "asc" : "desc"); 99 | auto reply = d->contact->client()->request("wall.getComments", args); 100 | connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_comments_received(QVariant))); 101 | return reply; 102 | } 103 | 104 | } // namespace Vreen 105 | 106 | #include "moc_commentssession.cpp" 107 | 108 | -------------------------------------------------------------------------------- /src/api/commentssession.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_COMMENTSSESSION_H 26 | #define VK_COMMENTSSESSION_H 27 | 28 | #include 29 | #include 30 | #include "vk_global.h" 31 | 32 | namespace Vreen { 33 | 34 | class Reply; 35 | class Contact; 36 | class CommentSessionPrivate; 37 | 38 | class VK_SHARED_EXPORT CommentSession : public QObject 39 | { 40 | Q_OBJECT 41 | Q_DECLARE_PRIVATE(CommentSession) 42 | public: 43 | CommentSession(Vreen::Contact *contact); 44 | virtual ~CommentSession(); 45 | void setPostId(int id); 46 | int postId() const; 47 | public slots: 48 | Reply *getComments(int offset = 0, int count = 100); 49 | signals: 50 | void commentAdded(const QVariantMap &item); 51 | void commentDeleted(int commentId); 52 | private: 53 | QScopedPointer d_ptr; 54 | 55 | Q_PRIVATE_SLOT(d_func(), void _q_comments_received(QVariant)) 56 | }; 57 | 58 | typedef QList CommentList; 59 | 60 | } // namespace Vreen 61 | 62 | #endif // VK_COMMENTSSESSION_H 63 | 64 | -------------------------------------------------------------------------------- /src/api/connection.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "connection_p.h" 26 | 27 | #include 28 | 29 | namespace Vreen { 30 | 31 | const static QUrl apiUrl("https://api.vk.com/method/"); 32 | 33 | Connection::Connection(QObject *parent) : 34 | QNetworkAccessManager(parent), 35 | d_ptr(new ConnectionPrivate(this)) 36 | { 37 | } 38 | 39 | Connection::Connection(ConnectionPrivate *data, QObject *parent) : 40 | QNetworkAccessManager(parent), 41 | d_ptr(data) 42 | { 43 | } 44 | 45 | Connection::~Connection() 46 | { 47 | } 48 | 49 | QNetworkReply *Connection::get(QNetworkRequest request) 50 | { 51 | decorateRequest(request); 52 | return QNetworkAccessManager::get(request); 53 | } 54 | 55 | QNetworkReply *Connection::get(const QString &method, const QVariantMap &args) 56 | { 57 | return QNetworkAccessManager::get(makeRequest(method, args)); 58 | } 59 | 60 | QNetworkReply *Connection::put(const QString &method, QIODevice *data, const QVariantMap &args) 61 | { 62 | return QNetworkAccessManager::put(makeRequest(method, args), data); 63 | } 64 | 65 | QNetworkReply *Connection::put(const QString &method, const QByteArray &data, const QVariantMap &args) 66 | { 67 | return QNetworkAccessManager::put(makeRequest(method, args), data); 68 | } 69 | 70 | /*! 71 | * \brief Connection::clear auth data. Default implementation doesn't nothing. 72 | */ 73 | void Connection::clear() 74 | { 75 | } 76 | 77 | void Connection::setConnectionOption(Connection::ConnectionOption option, const QVariant &value) 78 | { 79 | Q_D(Connection); 80 | d->options[option] = value; 81 | } 82 | 83 | QVariant Connection::connectionOption(Connection::ConnectionOption option) const 84 | { 85 | return d_func()->options[option]; 86 | } 87 | 88 | QNetworkRequest Connection::makeRequest(const QString &method, const QVariantMap &args) 89 | { 90 | QUrl url = apiUrl; 91 | url.setPath(url.path() + QStringLiteral("/") + method); 92 | { 93 | QUrlQuery query; 94 | QVariantMap::const_iterator it = args.cbegin(); 95 | for (; it != args.cend(); it++) 96 | query.addQueryItem(QUrl::toPercentEncoding(it.key()), 97 | QUrl::toPercentEncoding(it.value().toString())); 98 | url.setQuery(query); 99 | } 100 | QNetworkRequest request(url); 101 | decorateRequest(request); 102 | return request; 103 | } 104 | 105 | void Connection::decorateRequest(QNetworkRequest &) 106 | { 107 | } 108 | 109 | } // namespace Vreen 110 | 111 | -------------------------------------------------------------------------------- /src/api/connection.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_CONNECTION_H 26 | #define VK_CONNECTION_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include "client.h" 32 | 33 | namespace Vreen { 34 | 35 | class Reply; 36 | class ConnectionPrivate; 37 | 38 | class VK_SHARED_EXPORT Connection : public QNetworkAccessManager 39 | { 40 | Q_OBJECT 41 | Q_DECLARE_PRIVATE(Connection) 42 | Q_ENUMS(ConnectionOption) 43 | public: 44 | Connection(QObject *parent = 0); 45 | Connection(ConnectionPrivate *data, QObject *parent = 0); 46 | ~Connection(); 47 | 48 | enum ConnectionOption { 49 | ShowAuthDialog, 50 | KeepAuthData 51 | }; 52 | 53 | virtual void connectToHost(const QString &login, const QString &password) = 0; 54 | virtual void disconnectFromHost() = 0; 55 | 56 | QNetworkReply *get(QNetworkRequest request); 57 | QNetworkReply *get(const QString &method, const QVariantMap &args = QVariantMap()); 58 | QNetworkReply *put(const QString &method, QIODevice *data, const QVariantMap &args = QVariantMap()); 59 | QNetworkReply *put(const QString &method, const QByteArray &data, const QVariantMap &args = QVariantMap()); 60 | 61 | virtual Client::State connectionState() const = 0; 62 | virtual int uid() const = 0; 63 | virtual void clear(); 64 | 65 | Q_INVOKABLE void setConnectionOption(ConnectionOption option, const QVariant &value); 66 | Q_INVOKABLE QVariant connectionOption(ConnectionOption option) const; 67 | signals: 68 | void connectionStateChanged(Vreen::Client::State connectionState); 69 | void error(Vreen::Client::Error); 70 | protected: 71 | virtual QNetworkRequest makeRequest(const QString &method, const QVariantMap &args = QVariantMap()); 72 | virtual void decorateRequest(QNetworkRequest &); 73 | QScopedPointer d_ptr; 74 | }; 75 | 76 | } //namespace Vreen 77 | 78 | Q_DECLARE_METATYPE(Vreen::Connection*) 79 | 80 | #endif // VK_CONNECTION_H 81 | 82 | -------------------------------------------------------------------------------- /src/api/connection_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef CONNECTION_P_H 26 | #define CONNECTION_P_H 27 | #include "connection.h" 28 | 29 | namespace Vreen { 30 | 31 | class Connection; 32 | class VK_SHARED_EXPORT ConnectionPrivate 33 | { 34 | Q_DECLARE_PUBLIC(Connection) 35 | public: 36 | ConnectionPrivate(Connection *q) : q_ptr(q) {} 37 | Connection *q_ptr; 38 | QMap options; 39 | }; 40 | 41 | } 42 | 43 | 44 | #endif // CONNECTION_P_H 45 | -------------------------------------------------------------------------------- /src/api/contentdownloader.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "contentdownloader_p.h" 26 | #include "utils.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace Vreen { 34 | 35 | static QPointer networkManager; 36 | 37 | ContentDownloader::ContentDownloader(QObject *parent) : 38 | QObject(parent) 39 | { 40 | if (!networkManager) { 41 | networkManager = new NetworkAccessManager; 42 | //use another thread for more smooth gui 43 | //auto thread = new QThread; 44 | //networkManager->moveToThread(thread); 45 | //connect(networkManager.data(), SIGNAL(destroyed()), thread, SLOT(quit())); 46 | //connect(thread, SIGNAL(finished()), SLOT(deleteLater())); 47 | //thread->start(QThread::LowPriority); 48 | } 49 | } 50 | 51 | QString ContentDownloader::download(const QUrl &link) 52 | { 53 | QString path = networkManager->cacheDir() 54 | + networkManager->fileHash(link) 55 | + QLatin1String(".") 56 | + QFileInfo(link.path()).completeSuffix(); 57 | 58 | if (QFileInfo(path).exists()) { 59 | //FIXME it maybe not work in some cases (use event instead emit) 60 | emit downloadFinished(path); 61 | } else { 62 | QNetworkRequest request(link); 63 | request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); 64 | auto reply = networkManager->get(request); 65 | reply->setProperty("path", path); 66 | connect(reply, SIGNAL(finished()), this, SLOT(replyDone())); 67 | } 68 | return path; 69 | } 70 | 71 | void ContentDownloader::replyDone() 72 | { 73 | auto reply = sender_cast(sender()); 74 | QString cacheDir = networkManager->cacheDir(); 75 | QDir dir(cacheDir); 76 | if (!dir.exists()) { 77 | if(!dir.mkpath(cacheDir)) { 78 | qWarning("Unable to create cache dir"); 79 | return; 80 | } 81 | } 82 | //TODO move method to manager in other thread 83 | QString path = reply->property("path").toString(); 84 | QFile file(path); 85 | if (!file.open(QIODevice::WriteOnly)) { 86 | qWarning("Unable to write file!"); 87 | return; 88 | } 89 | file.write(reply->readAll()); 90 | file.close(); 91 | 92 | emit downloadFinished(path); 93 | } 94 | 95 | } // namespace Vreen 96 | 97 | #include "moc_contentdownloader.cpp" 98 | 99 | -------------------------------------------------------------------------------- /src/api/contentdownloader.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_CONTENTDOWNLOADER_H 26 | #define VK_CONTENTDOWNLOADER_H 27 | 28 | #include 29 | #include "vk_global.h" 30 | 31 | class QUrl; 32 | 33 | namespace Vreen { 34 | 35 | class VK_SHARED_EXPORT ContentDownloader : public QObject 36 | { 37 | Q_OBJECT 38 | public: 39 | explicit ContentDownloader(QObject *parent = 0); 40 | Q_INVOKABLE QString download(const QUrl &link); 41 | signals: 42 | void downloadFinished(const QString &fileName); 43 | private slots: 44 | void replyDone(); 45 | }; 46 | 47 | } // namespace Vreen 48 | 49 | #endif // VK_CONTENTDOWNLOADER_H 50 | 51 | -------------------------------------------------------------------------------- /src/api/contentdownloader_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef CONTENTDOWNLOADER_P_H 26 | #define CONTENTDOWNLOADER_P_H 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "contentdownloader.h" 33 | 34 | namespace Vreen { 35 | 36 | class NetworkAccessManager : public QNetworkAccessManager 37 | { 38 | Q_OBJECT 39 | public: 40 | NetworkAccessManager(QObject *parent = 0) : QNetworkAccessManager(parent) 41 | { 42 | 43 | } 44 | 45 | QString fileHash(const QUrl &url) const 46 | { 47 | QCryptographicHash hash(QCryptographicHash::Md5); 48 | hash.addData(url.toString().toUtf8()); 49 | return hash.result().toHex(); 50 | } 51 | QString cacheDir() const 52 | { 53 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) 54 | auto dir = QStandardPaths::writableLocation(QStandardPaths::DataLocation); 55 | #else 56 | auto dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); 57 | #endif 58 | return dir + QLatin1String("/vk/"); 59 | } 60 | }; 61 | 62 | } //namespace Vreen 63 | 64 | #endif // CONTENTDOWNLOADER_P_H 65 | -------------------------------------------------------------------------------- /src/api/dynamicpropertydata.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "dynamicpropertydata_p.h" 26 | #include 27 | 28 | namespace Vreen { 29 | 30 | QVariant DynamicPropertyData::property(const char *name, const QVariant &def, 31 | const QList &gNames, 32 | const QList &gGetters) const 33 | { 34 | QByteArray prop = QByteArray::fromRawData(name, strlen(name)); 35 | int id = gNames.indexOf(prop); 36 | if (id < 0) { 37 | id = names.indexOf(prop); 38 | if(id < 0) 39 | return def; 40 | return values.at(id); 41 | } 42 | return (this->*gGetters.at(id))(); 43 | } 44 | 45 | void DynamicPropertyData::setProperty(const char *name, const QVariant &value, 46 | const QList &gNames, 47 | const QList &gSetters) 48 | { 49 | QByteArray prop = QByteArray::fromRawData(name, strlen(name)); 50 | int id = gNames.indexOf(prop); 51 | if (id < 0) { 52 | id = names.indexOf(prop); 53 | if (!value.isValid()) { 54 | if(id < 0) 55 | return; 56 | names.removeAt(id); 57 | values.removeAt(id); 58 | } else { 59 | if (id < 0) { 60 | prop.detach(); 61 | names.append(prop); 62 | values.append(value); 63 | } else { 64 | values[id] = value; 65 | } 66 | } 67 | } else { 68 | (this->*gSetters.at(id))(value); 69 | } 70 | } 71 | 72 | } // namespace Vreen 73 | 74 | -------------------------------------------------------------------------------- /src/api/dynamicpropertydata_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_DYNAMICPROPERTYDATA_P_H 26 | #define VK_DYNAMICPROPERTYDATA_P_H 27 | 28 | //from euroelessar code 29 | 30 | #include 31 | #include 32 | 33 | namespace Vreen { 34 | 35 | class DynamicPropertyData; 36 | 37 | namespace CompiledProperty 38 | { 39 | typedef QVariant (DynamicPropertyData::*Getter)() const; 40 | typedef void (DynamicPropertyData::*Setter)(const QVariant &variant); 41 | } 42 | 43 | class DynamicPropertyData : public QSharedData 44 | { 45 | public: 46 | typedef CompiledProperty::Getter Getter; 47 | typedef CompiledProperty::Setter Setter; 48 | DynamicPropertyData() {} 49 | DynamicPropertyData(const DynamicPropertyData &o) : 50 | QSharedData(o), names(o.names), values(o.values) {} 51 | QList names; 52 | QList values; 53 | 54 | QVariant property(const char *name, const QVariant &def, const QList &names, 55 | const QList &getters) const; 56 | void setProperty(const char *name, const QVariant &value, const QList &names, 57 | const QList &setters); 58 | }; 59 | 60 | } // namespace Vreen 61 | 62 | #endif // VK_DYNAMICPROPERTYDATA_P_H 63 | 64 | -------------------------------------------------------------------------------- /src/api/friendrequest.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "friendrequest.h" 26 | #include 27 | 28 | namespace Vreen { 29 | 30 | class FriendRequestData : public QSharedData { 31 | public: 32 | FriendRequestData(int uid) : QSharedData(), 33 | uid(uid) 34 | {} 35 | FriendRequestData(const FriendRequestData &o) : QSharedData(o), 36 | uid(o.uid), 37 | message(o.message), 38 | mutual(o.mutual) 39 | {} 40 | 41 | int uid; 42 | QString message; 43 | IdList mutual; 44 | }; 45 | 46 | FriendRequest::FriendRequest(int uid) : data(new FriendRequestData(uid)) 47 | { 48 | } 49 | 50 | FriendRequest::FriendRequest(const FriendRequest &rhs) : data(rhs.data) 51 | { 52 | } 53 | 54 | FriendRequest &FriendRequest::operator=(const FriendRequest &rhs) 55 | { 56 | if (this != &rhs) 57 | data.operator=(rhs.data); 58 | return *this; 59 | } 60 | 61 | FriendRequest::~FriendRequest() 62 | { 63 | } 64 | 65 | int FriendRequest::uid() const 66 | { 67 | return data->uid; 68 | } 69 | 70 | void FriendRequest::setUid(int uid) 71 | { 72 | data->uid = uid; 73 | } 74 | 75 | IdList FriendRequest::mutualFriends() const 76 | { 77 | return data->mutual; 78 | } 79 | 80 | void FriendRequest::setMutualFriends(const IdList &mutual) 81 | { 82 | data->mutual = mutual; 83 | } 84 | 85 | QString FriendRequest::message() const 86 | { 87 | return data->message; 88 | } 89 | 90 | void FriendRequest::setMessage(const QString &message) 91 | { 92 | data->message = message; 93 | } 94 | 95 | } // namespace Vreen 96 | -------------------------------------------------------------------------------- /src/api/friendrequest.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VREEN_FRIENDREQUEST_H 26 | #define VREEN_FRIENDREQUEST_H 27 | 28 | #include "vk_global.h" 29 | #include 30 | #include 31 | 32 | namespace Vreen { 33 | 34 | class FriendRequestData; 35 | 36 | class VK_SHARED_EXPORT FriendRequest 37 | { 38 | public: 39 | explicit FriendRequest(int uid = 0); 40 | FriendRequest(const FriendRequest &); 41 | FriendRequest &operator=(const FriendRequest &); 42 | ~FriendRequest(); 43 | int uid() const; 44 | void setUid(int uid); 45 | QString message() const; 46 | void setMessage(const QString &message); 47 | IdList mutualFriends() const; 48 | void setMutualFriends(const IdList &mutualFriends); 49 | private: 50 | QSharedDataPointer data; 51 | }; 52 | typedef QList FriendRequestList; 53 | 54 | } // namespace Vreen 55 | 56 | Q_DECLARE_METATYPE(Vreen::FriendRequest) 57 | Q_DECLARE_METATYPE(Vreen::FriendRequestList) 58 | 59 | #endif // VREEN_FRIENDREQUEST_H 60 | -------------------------------------------------------------------------------- /src/api/groupchatsession.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_GROUPCHATSESSION_H 26 | #define VK_GROUPCHATSESSION_H 27 | #include "messagesession.h" 28 | #include "contact.h" 29 | 30 | namespace Vreen { 31 | 32 | class GroupChatSessionPrivate; 33 | 34 | class VK_SHARED_EXPORT GroupChatSession : public Vreen::MessageSession 35 | { 36 | Q_OBJECT 37 | Q_DECLARE_PRIVATE(GroupChatSession) 38 | 39 | Q_PROPERTY(QString title READ title NOTIFY titleChanged) 40 | Q_PROPERTY(bool joined READ isJoined NOTIFY isJoinedChanged) 41 | public: 42 | explicit GroupChatSession(int chatId, Client *parent); 43 | 44 | BuddyList participants() const; 45 | Buddy *admin() const; 46 | QString title() const; 47 | Buddy *findParticipant(int uid) const; 48 | //Buddy *participant(int uid); 49 | bool isJoined() const; 50 | 51 | static Reply *create(Client *client, const IdList &uids, const QString &title = QString()); 52 | public slots: 53 | Reply *getInfo(); 54 | Reply *inviteParticipant(Contact *buddy); 55 | Reply *removeParticipant(Contact *buddy); 56 | Reply *updateTitle(const QString &title); 57 | void join(); 58 | void leave(); 59 | signals: 60 | void participantAdded(Vreen::Buddy*); 61 | void participantRemoved(Vreen::Buddy*); 62 | void titleChanged(QString); 63 | void isJoinedChanged(bool); 64 | protected: 65 | void setTitle(const QString &title); 66 | virtual SendMessageReply *doSendMessage(const Vreen::Message &message); 67 | virtual ReplyBase *doGetHistory(int count = 16, int offset = 0); 68 | private: 69 | Q_PRIVATE_SLOT(d_func(), void _q_info_received(const QVariant &response)) 70 | Q_PRIVATE_SLOT(d_func(), void _q_participant_added(const QVariant &response)) 71 | Q_PRIVATE_SLOT(d_func(), void _q_participant_removed(const QVariant &response)) 72 | Q_PRIVATE_SLOT(d_func(), void _q_title_updated(const QVariant &response)) 73 | Q_PRIVATE_SLOT(d_func(), void _q_online_changed(bool)) 74 | Q_PRIVATE_SLOT(d_func(), void _q_message_added(const Vreen::Message &)) 75 | Q_PRIVATE_SLOT(d_func(), void _q_group_chat_updated(int chatId, bool self)) 76 | }; 77 | 78 | } // namespace Vreen 79 | 80 | #endif // VK_GROUPCHATSESSION_H 81 | 82 | -------------------------------------------------------------------------------- /src/api/groupmanager.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "client.h" 26 | #include "contact.h" 27 | #include "utils_p.h" 28 | #include 29 | #include "groupmanager_p.h" 30 | 31 | namespace Vreen { 32 | 33 | GroupManager::GroupManager(Client *client) : 34 | QObject(client), 35 | d_ptr(new GroupManagerPrivate(this, client)) 36 | { 37 | } 38 | 39 | GroupManager::~GroupManager() 40 | { 41 | } 42 | 43 | Client *GroupManager::client() const 44 | { 45 | return d_func()->client; 46 | } 47 | 48 | Group *GroupManager::group(int gid) 49 | { 50 | Q_D(GroupManager); 51 | auto group = d->groupHash.value(gid); 52 | if (!group) { 53 | group = new Group(gid, client()); 54 | d->groupHash.insert(gid, group); 55 | } 56 | return group; 57 | } 58 | 59 | Group *GroupManager::group(int gid) const 60 | { 61 | return d_func()->groupHash.value(gid); 62 | } 63 | 64 | Reply *GroupManager::update(const IdList &ids, const QStringList &fields) 65 | { 66 | Q_D(GroupManager); 67 | QVariantMap args; 68 | args.insert("gids", join(ids)); 69 | args.insert("fields", fields.join(",")); 70 | auto reply = d->client->request("groups.getById", args); 71 | reply->connect(reply, SIGNAL(resultReady(const QVariant&)), 72 | this, SLOT(_q_update_finished(const QVariant&))); 73 | return reply; 74 | } 75 | 76 | Reply *GroupManager::update(const GroupList &groups, const QStringList &fields) 77 | { 78 | IdList ids; 79 | foreach (auto group, groups) 80 | ids.append(group->id()); 81 | return update(ids, fields); 82 | } 83 | 84 | void GroupManagerPrivate::_q_update_finished(const QVariant &response) 85 | { 86 | Q_Q(GroupManager); 87 | auto list = response.toList(); 88 | foreach (auto data, list) { 89 | auto map = data.toMap(); 90 | int id = -map.value("gid").toInt(); 91 | Contact::fill(q->group(id), map); 92 | } 93 | } 94 | 95 | void GroupManagerPrivate::_q_updater_handle() 96 | { 97 | Q_Q(GroupManager); 98 | q->update(updaterQueue); 99 | updaterQueue.clear(); 100 | } 101 | 102 | void GroupManagerPrivate::appendToUpdaterQueue(Group *contact) 103 | { 104 | if (!updaterQueue.contains(-contact->id())) 105 | updaterQueue.append(-contact->id()); 106 | if (!updaterTimer.isActive()) 107 | updaterTimer.start(); 108 | } 109 | 110 | } // namespace Vreen 111 | 112 | #include "moc_groupmanager.cpp" 113 | -------------------------------------------------------------------------------- /src/api/groupmanager.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_GROUPMANAGER_H 26 | #define VK_GROUPMANAGER_H 27 | 28 | #include "contact.h" 29 | #include 30 | 31 | namespace Vreen { 32 | 33 | class Client; 34 | class Group; 35 | class GroupManagerPrivate; 36 | 37 | class VK_SHARED_EXPORT GroupManager : public QObject 38 | { 39 | Q_OBJECT 40 | Q_DECLARE_PRIVATE(GroupManager) 41 | public: 42 | explicit GroupManager(Client *client); 43 | virtual ~GroupManager(); 44 | Client *client() const; 45 | Group *group(int gid) const; 46 | Group *group(int gid); 47 | public slots: 48 | Reply *update(const IdList &ids, const QStringList &fields = QStringList() << VK_GROUP_FIELDS); 49 | Reply *update(const GroupList &groups, const QStringList &fields = QStringList() << VK_GROUP_FIELDS); 50 | signals: 51 | void groupCreated(Group *group); 52 | protected: 53 | QScopedPointer d_ptr; 54 | private: 55 | 56 | Q_PRIVATE_SLOT(d_func(), void _q_update_finished(const QVariant &response)) 57 | Q_PRIVATE_SLOT(d_func(), void _q_updater_handle()) 58 | 59 | friend class Group; 60 | friend class GroupPrivate; 61 | }; 62 | 63 | } // namespace Vreen 64 | 65 | #endif // VK_GROUPMANAGER_H 66 | 67 | -------------------------------------------------------------------------------- /src/api/groupmanager_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef GROUPMANAGER_P_H 27 | #define GROUPMANAGER_P_H 28 | 29 | #include "groupmanager.h" 30 | #include "client.h" 31 | #include "contact.h" 32 | #include 33 | 34 | namespace Vreen { 35 | 36 | class GroupManager; 37 | class GroupManagerPrivate 38 | { 39 | Q_DECLARE_PUBLIC(GroupManager) 40 | public: 41 | GroupManagerPrivate(GroupManager *q, Client *client) : q_ptr(q), client(client) 42 | { 43 | updaterTimer.setInterval(5000); 44 | updaterTimer.setSingleShot(true); 45 | updaterTimer.connect(&updaterTimer, SIGNAL(timeout()), 46 | q, SLOT(_q_updater_handle())); 47 | } 48 | GroupManager *q_ptr; 49 | Client *client; 50 | QHash groupHash; 51 | 52 | //updater 53 | QTimer updaterTimer; 54 | IdList updaterQueue; 55 | 56 | void _q_update_finished(const QVariant &response); 57 | void _q_updater_handle(); 58 | void appendToUpdaterQueue(Group *contact); 59 | }; 60 | 61 | } //namespace Vreen 62 | 63 | #endif // GROUPMANAGER_P_H 64 | -------------------------------------------------------------------------------- /src/api/json.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012-2015 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "json.h" 26 | #include 27 | 28 | namespace Vreen { 29 | 30 | namespace JSON { 31 | 32 | /*! 33 | * \brief Parse JSON data to QVariant 34 | * \param String with JSON data 35 | * \return Result of parsing, QVariant::Null if there was an error 36 | */ 37 | QVariant parse(const QByteArray &data) 38 | { 39 | QJsonParseError error; 40 | 41 | auto document = QJsonDocument::fromJson(data, &error); 42 | return document.toVariant(); 43 | } 44 | 45 | /*! 46 | * \brief Generate JSON string from QVariant 47 | * \param data QVariant with data 48 | * \param indent Identation of new lines 49 | * \return JSON string with data 50 | */ 51 | QByteArray generate(const QVariant &data, int indent) 52 | { 53 | Q_UNUSED(indent); 54 | 55 | auto document = QJsonDocument::fromVariant(data); 56 | return document.toJson(QJsonDocument::Indented); 57 | } 58 | 59 | } //namespace JSON 60 | 61 | } // namespace Vreen 62 | 63 | -------------------------------------------------------------------------------- /src/api/json.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_JSON_H 26 | #define VK_JSON_H 27 | #include "vk_global.h" 28 | #include 29 | 30 | namespace Vreen { 31 | 32 | namespace JSON { 33 | VK_SHARED_EXPORT QVariant parse(const QByteArray &data); 34 | VK_SHARED_EXPORT QByteArray generate(const QVariant &data, int indent = 0); 35 | } //namespace JSON 36 | 37 | } // namespace Vreen 38 | 39 | #endif // VK_JSON_H 40 | 41 | -------------------------------------------------------------------------------- /src/api/localstorage.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licees/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "localstorage.h" 26 | 27 | namespace Vreen { 28 | 29 | AbstractLocalStorage::AbstractLocalStorage() 30 | { 31 | } 32 | 33 | } // namespace Vreen 34 | -------------------------------------------------------------------------------- /src/api/localstorage.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licees/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VREEN_LOCALSTORAGE_H 26 | #define VREEN_LOCALSTORAGE_H 27 | #include "contact.h" 28 | 29 | namespace Vreen { 30 | 31 | class AbstractLocalStorage 32 | { 33 | public: 34 | AbstractLocalStorage(); 35 | virtual ~AbstractLocalStorage() {} 36 | protected: 37 | virtual void loadBuddies(Roster *roster) = 0; 38 | virtual void storeBuddies(Roster *roster) = 0; 39 | //TODO group managers 40 | //key value storage 41 | virtual void store(const QString &key, const QVariant &value) = 0; 42 | virtual QVariant load(const QString &key) = 0; 43 | //TODO messages history async get and set 44 | }; 45 | 46 | } // namespace Vreen 47 | 48 | #endif // VREEN_LOCALSTORAGE_H 49 | -------------------------------------------------------------------------------- /src/api/longpoll.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_LONGPOLL_H 26 | #define VK_LONGPOLL_H 27 | 28 | #include 29 | #include "contact.h" 30 | 31 | namespace Vreen { 32 | 33 | class Message; 34 | class Client; 35 | class LongPollPrivate; 36 | class VK_SHARED_EXPORT LongPoll : public QObject 37 | { 38 | Q_OBJECT 39 | Q_DECLARE_PRIVATE(LongPoll) 40 | Q_PROPERTY(int pollInterval READ pollInterval WRITE setPollInterval NOTIFY pollIntervalChanged) 41 | public: 42 | 43 | enum ServerAnswer { 44 | MessageDeleted = 0, 45 | MessageFlagsReplaced= 1, 46 | MessageFlagsSet = 2, 47 | MessageFlagsReseted = 3, 48 | MessageAdded = 4, 49 | UserOnline = 8, 50 | UserOffline = 9, 51 | GroupChatUpdated = 51, 52 | ChatTyping = 61, 53 | GroupChatTyping = 62, 54 | UserCall = 70 55 | 56 | }; 57 | 58 | enum OfflineFlag { 59 | OfflineTimeout = 1 60 | }; 61 | Q_DECLARE_FLAGS(OfflineFlags, OfflineFlag) 62 | 63 | enum Mode { 64 | NoRecieveAttachments = 0, 65 | RecieveAttachments = 2 66 | }; 67 | 68 | LongPoll(Client *client); 69 | virtual ~LongPoll(); 70 | void setMode(Mode mode); 71 | Mode mode() const; 72 | int pollInterval() const; 73 | void setPollInterval(int interval); 74 | signals: 75 | void messageAdded(const Vreen::Message &msg); 76 | void messageDeleted(int mid); 77 | void messageFlagsReplaced(int mid, int mask, int userId = 0); 78 | void messageFlagsReseted(int mid, int mask, int userId = 0); 79 | void contactStatusChanged(int userId, Vreen::Contact::Status status); 80 | void contactTyping(int userId, int chatId = 0); 81 | void contactCall(int userId, int callId); 82 | void groupChatUpdated(int chatId, bool self); 83 | void pollIntervalChanged(int); 84 | public slots: 85 | void setRunning(bool set); 86 | protected slots: 87 | void requestServer(); 88 | void requestData(const QByteArray &timeStamp); 89 | protected: 90 | QScopedPointer d_ptr; 91 | 92 | Q_PRIVATE_SLOT(d_func(), void _q_request_server_finished(const QVariant &)) 93 | Q_PRIVATE_SLOT(d_func(), void _q_on_data_recieved(const QVariant &)) 94 | Q_PRIVATE_SLOT(d_func(), void _q_update_running()); 95 | }; 96 | 97 | } // namespace Vreen 98 | 99 | Q_DECLARE_METATYPE(Vreen::LongPoll*) 100 | 101 | #endif // VK_LONGPOLL_H 102 | 103 | -------------------------------------------------------------------------------- /src/api/longpoll_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef LONGPOLL_P_H 26 | #define LONGPOLL_P_H 27 | 28 | #include "longpoll.h" 29 | #include "client.h" 30 | #include "reply.h" 31 | #include "attachment.h" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | namespace Vreen { 42 | 43 | class LongPoll; 44 | class LongPollPrivate 45 | { 46 | Q_DECLARE_PUBLIC(LongPoll) 47 | public: 48 | LongPollPrivate(LongPoll *q) : q_ptr(q), client(0), 49 | mode(LongPoll::RecieveAttachments), pollInterval(1500), waitInterval(25), isRunning(false) {} 50 | LongPoll *q_ptr; 51 | Client *client; 52 | 53 | LongPoll::Mode mode; 54 | int pollInterval; 55 | int waitInterval; 56 | QUrl dataUrl; 57 | bool isRunning; 58 | QPointer dataRequestReply; 59 | 60 | void _q_request_server_finished(const QVariant &response); 61 | void _q_on_data_recieved(const QVariant &response); 62 | void _q_update_running(); 63 | Attachment::List getAttachments(const QVariantMap &map); 64 | }; 65 | 66 | 67 | } //namespace Vreen 68 | 69 | #endif // LONGPOLL_P_H 70 | 71 | -------------------------------------------------------------------------------- /src/api/message.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_MESSAGE_H 26 | #define VK_MESSAGE_H 27 | #include 28 | #include 29 | #include "attachment.h" 30 | 31 | namespace Vreen { 32 | 33 | class Contact; 34 | class Message; 35 | typedef QList MessageList; 36 | 37 | class Client; 38 | class MessageData; 39 | class VK_SHARED_EXPORT Message 40 | { 41 | Q_GADGET 42 | Q_ENUMS(ReadState) 43 | Q_ENUMS(Direction) 44 | Q_ENUMS(Flags) 45 | public: 46 | enum Flag { 47 | FlagUnread = 1, 48 | FlagOutbox = 2, 49 | FlagReplied = 4, 50 | FlagImportant= 8, 51 | FlagChat = 16, 52 | FlagFriends = 32, 53 | FlagSpam = 64, 54 | FlagDeleted = 128, 55 | FlagFixed = 256, 56 | FlagMedia = 512 57 | }; 58 | Q_DECLARE_FLAGS(Flags, Flag) 59 | enum Filter { 60 | FilterNone = 0, 61 | FilterUnread = 1, 62 | FilterNotFromChat = 2, 63 | FilterFromFriends = 4 64 | }; 65 | 66 | Message(int clientId); 67 | Message(const QVariantMap &data, int clientId); 68 | Message(Client *client = 0); 69 | Message(const QVariantMap &data, Client *client); 70 | Message(const Message &other); 71 | Message &operator =(const Message &other); 72 | bool operator ==(const Message &other); 73 | virtual ~Message(); 74 | 75 | int id() const; 76 | void setId(int id); 77 | QDateTime date() const; 78 | void setDate(const QDateTime &date); 79 | int fromId() const; 80 | void setFromId(int id); 81 | int toId() const; 82 | void setToId(int id); 83 | int chatId() const; 84 | void setChatId(int chatId); 85 | QString subject() const; 86 | void setSubject(const QString &subject); 87 | QString body() const; 88 | void setBody(const QString &body); 89 | bool isUnread() const; 90 | void setUnread(bool set); 91 | bool isIncoming() const; 92 | void setIncoming(bool set); 93 | void setFlags(Flags flags); 94 | Flags flags() const; 95 | void setFlag(Flag flag, bool set = true); 96 | bool testFlag(Flag flag) const; 97 | Attachment::Hash attachments() const; 98 | Attachment::List attachments(Attachment::Type type) const; 99 | void setAttachments(const Attachment::List &attachmentList); 100 | 101 | static MessageList fromVariantList(const QVariantList &list, Client *client); 102 | static MessageList fromVariantList(const QVariantList &list, int clientId); 103 | private: 104 | QSharedDataPointer d; 105 | }; 106 | 107 | typedef QList IdList; 108 | 109 | } // namespace Vreen 110 | 111 | Q_DECLARE_METATYPE(Vreen::Message) 112 | Q_DECLARE_METATYPE(Vreen::MessageList) 113 | Q_DECLARE_METATYPE(Vreen::IdList) 114 | Q_DECLARE_OPERATORS_FOR_FLAGS(Vreen::Message::Flags) 115 | 116 | #endif // VK_MESSAGE_H 117 | 118 | -------------------------------------------------------------------------------- /src/api/messagemodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef MESSAGEMODEL_H 26 | #define MESSAGEMODEL_H 27 | 28 | #include 29 | #include "message.h" 30 | 31 | namespace Vreen { 32 | 33 | class MessageListModelPrivate; 34 | class VK_SHARED_EXPORT MessageListModel : public QAbstractListModel 35 | { 36 | Q_OBJECT 37 | Q_DECLARE_PRIVATE(MessageListModel) 38 | Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged) 39 | Q_PROPERTY(Vreen::Client* client READ client WRITE setClient NOTIFY clientChanged) 40 | public: 41 | 42 | enum Roles { 43 | SubjectRole = Qt::UserRole + 1, 44 | BodyRole, 45 | FromRole, 46 | ToRole, 47 | ReadStateRole, 48 | DirectionRole, 49 | DateRole, 50 | IdRole, 51 | ChatIdRole, 52 | AttachmentRole 53 | }; 54 | 55 | MessageListModel(QObject *parent = 0); 56 | virtual ~MessageListModel(); 57 | int count() const; 58 | Message at(int index) const; 59 | int findMessage(int id); 60 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 61 | virtual int rowCount(const QModelIndex &parent) const; 62 | void setSortOrder(Qt::SortOrder order); 63 | Qt::SortOrder sortOrder() const; 64 | void setClient(Client *client); 65 | Client *client() const; 66 | signals: 67 | void sortOrderChanged(Qt::SortOrder order); 68 | void clientChanged(Vreen::Client*); 69 | public slots: 70 | void addMessage(const Vreen::Message &message); 71 | void removeMessage(const Vreen::Message &message); 72 | void removeMessage(int id); 73 | void setMessages(const Vreen::MessageList &messages); 74 | void clear(); 75 | protected: 76 | virtual void doReplaceMessage(int index, const::Vreen::Message &message); 77 | virtual void doInsertMessage(int index, const::Vreen::Message &message); 78 | virtual void doRemoveMessage(int index); 79 | void moveMessage(int sourceIndex, int destinationIndex); 80 | virtual void sort(int column, Qt::SortOrder order); 81 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) 82 | virtual QHash roleNames() const; 83 | #endif 84 | protected slots: 85 | void replaceMessageFlags(int id, int mask, int userId = 0); 86 | void resetMessageFlags(int id, int mask, int userId = 0); 87 | private: 88 | QScopedPointer d_ptr; 89 | }; 90 | 91 | } //namespace Vreen 92 | 93 | #endif // MESSAGEMODEL_H 94 | 95 | -------------------------------------------------------------------------------- /src/api/messagesession.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "messagesession_p.h" 26 | #include "client.h" 27 | #include "utils_p.h" 28 | 29 | namespace Vreen { 30 | 31 | MessageSession::MessageSession(MessageSessionPrivate *data) : 32 | QObject(data->client), 33 | d_ptr(data) 34 | { 35 | } 36 | MessageSession::~MessageSession() 37 | { 38 | } 39 | 40 | Client *MessageSession::client() const 41 | { 42 | return d_func()->client; 43 | } 44 | 45 | int MessageSession::uid() const 46 | { 47 | return d_func()->uid; 48 | } 49 | 50 | QString MessageSession::title() const 51 | { 52 | return d_func()->title; 53 | } 54 | 55 | void MessageSession::setTitle(const QString &title) 56 | { 57 | Q_D(MessageSession); 58 | if (d->title != title) { 59 | d->title = title; 60 | emit titleChanged(title); 61 | } 62 | } 63 | 64 | ReplyBase *MessageSession::getHistory(int count, int offset) 65 | { 66 | auto reply = doGetHistory(count, offset); 67 | connect(reply, SIGNAL(resultReady(QVariant)), SLOT(_q_history_received(QVariant))); 68 | return reply; 69 | } 70 | 71 | SendMessageReply *MessageSession::sendMessage(const QString &body, const QString &subject) 72 | { 73 | Q_D(MessageSession); 74 | Message msg(d->client); 75 | msg.setToId(d->uid); 76 | msg.setBody(body); 77 | msg.setSubject(subject); 78 | return sendMessage(msg); 79 | } 80 | 81 | SendMessageReply *MessageSession::sendMessage(const Message &message) 82 | { 83 | return doSendMessage(message); 84 | } 85 | 86 | Reply *MessageSession::markMessagesAsRead(IdList ids, bool set) 87 | { 88 | Q_D(MessageSession); 89 | QString request = set ? "messages.markAsRead" 90 | : "messages.markAsNew"; 91 | QVariantMap args; 92 | args.insert("mids", join(ids)); 93 | auto reply = d->client->request(request, args); 94 | reply->setProperty("mids", qVariantFromValue(ids)); 95 | reply->setProperty("set", set); 96 | return reply; 97 | } 98 | 99 | void MessageSessionPrivate::_q_history_received(const QVariant &) 100 | { 101 | Q_Q(MessageSession); 102 | auto reply = static_cast*>(q->sender()); 103 | foreach (auto message, reply->result()) 104 | emit q->messageAdded(message); 105 | } 106 | 107 | } // namespace Vreen 108 | 109 | #include "moc_messagesession.cpp" 110 | 111 | -------------------------------------------------------------------------------- /src/api/messagesession.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_MESSAGESESSION_H 26 | #define VK_MESSAGESESSION_H 27 | 28 | #include 29 | #include "message.h" 30 | #include "client.h" 31 | 32 | namespace Vreen { 33 | 34 | class Message; 35 | class Client; 36 | class MessageSessionPrivate; 37 | 38 | class VK_SHARED_EXPORT MessageSession : public QObject 39 | { 40 | Q_OBJECT 41 | Q_DECLARE_PRIVATE(MessageSession) 42 | 43 | Q_PROPERTY(int uid READ uid CONSTANT) 44 | Q_PROPERTY(Client* client READ client CONSTANT) 45 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 46 | public: 47 | explicit MessageSession(MessageSessionPrivate *data); 48 | virtual ~MessageSession(); 49 | Client *client() const; 50 | int uid() const; 51 | QString title() const; 52 | public slots: 53 | ReplyBase *getHistory(int count = 16, int offset = 0); 54 | SendMessageReply *sendMessage(const QString &body, const QString &subject = QString()); 55 | SendMessageReply *sendMessage(const Message &message); 56 | Reply *markMessagesAsRead(IdList ids, bool set = true); 57 | void setTitle(const QString &title); 58 | signals: 59 | void messageAdded(const Vreen::Message &message); 60 | void messageDeleted(int id); 61 | void messageReadStateChanged(int mid, bool isRead); 62 | void titleChanged(const QString &title); 63 | protected: 64 | virtual SendMessageReply *doSendMessage(const Vreen::Message &message) = 0; 65 | virtual ReplyBase *doGetHistory(int count, int offset) = 0; 66 | QScopedPointer d_ptr; 67 | private: 68 | Q_PRIVATE_SLOT(d_func(), void _q_history_received(const QVariant &)) 69 | }; 70 | 71 | } // namespace Vreen 72 | 73 | #endif // VK_MESSAGESESSION_H 74 | 75 | -------------------------------------------------------------------------------- /src/api/messagesession_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef MESSAGESESSION_P_H 26 | #define MESSAGESESSION_P_H 27 | #include "messagesession.h" 28 | #include "longpoll.h" 29 | 30 | namespace Vreen { 31 | 32 | class MessageSession; 33 | class MessageSessionPrivate 34 | { 35 | Q_DECLARE_PUBLIC(MessageSession) 36 | public: 37 | MessageSessionPrivate(MessageSession *q, Client *client, int uid) : 38 | q_ptr(q), client(client), uid(uid) {} 39 | MessageSession *q_ptr; 40 | Client *client; 41 | int uid; 42 | QString title; 43 | 44 | void _q_history_received(const QVariant &); 45 | }; 46 | 47 | } //namespace Vreen 48 | 49 | #endif // MESSAGESESSION_P_H 50 | 51 | -------------------------------------------------------------------------------- /src/api/newsfeed.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef NEWSFEED_H 26 | #define NEWSFEED_H 27 | #include 28 | #include "newsitem.h" 29 | #include 30 | 31 | namespace Vreen { 32 | 33 | class NewsFeedPrivate; 34 | class Client; 35 | class Reply; 36 | 37 | class VK_SHARED_EXPORT NewsFeed : public QObject 38 | { 39 | Q_OBJECT 40 | Q_DECLARE_PRIVATE(NewsFeed) 41 | Q_ENUMS(Filter) 42 | public: 43 | 44 | enum Filter { 45 | FilterNone = 0, 46 | FilterPost = 0x01, 47 | FilterPhoto = 0x02, 48 | FilterPhotoTag = 0x04, 49 | FilterFriend = 0x08, 50 | FilterNote = 0x10 51 | }; 52 | Q_DECLARE_FLAGS(Filters, Filter) 53 | 54 | NewsFeed(Client *client); 55 | virtual ~NewsFeed(); 56 | public slots: 57 | Reply *getNews(Filters filters = FilterNone, quint8 count = 25, int offset = 0); 58 | signals: 59 | void newsReceived(const Vreen::NewsItemList &list); 60 | private: 61 | QScopedPointer d_ptr; 62 | 63 | Q_PRIVATE_SLOT(d_func(), void _q_news_received(QVariant)) 64 | }; 65 | 66 | } //namespace Vreen 67 | 68 | Q_DECLARE_OPERATORS_FOR_FLAGS(Vreen::NewsFeed::Filters) 69 | 70 | #endif // NEWSFEED_H 71 | 72 | -------------------------------------------------------------------------------- /src/api/newsitem.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_NEWSITEM_H 26 | #define VK_NEWSITEM_H 27 | 28 | #include 29 | #include 30 | #include "attachment.h" 31 | 32 | namespace Vreen { 33 | 34 | class NewsItemData; 35 | 36 | class VK_SHARED_EXPORT NewsItem 37 | { 38 | Q_GADGET 39 | Q_ENUMS(Type) 40 | public: 41 | 42 | enum Type { 43 | Post, 44 | Photo, 45 | PhotoTag, 46 | Note, 47 | Invalid = -1 48 | }; 49 | 50 | NewsItem(); 51 | NewsItem(const NewsItem &); 52 | NewsItem &operator=(const NewsItem &); 53 | ~NewsItem(); 54 | 55 | static NewsItem fromData(const QVariant &data); 56 | 57 | Attachment::Hash attachments() const; 58 | Attachment::List attachments(Attachment::Type type) const; 59 | void setAttachments(const Attachment::List &attachmentList); 60 | Type type() const; 61 | void setType(Type type); 62 | int postId() const; 63 | void setPostId(int postId); 64 | int sourceId() const; 65 | void setSourceId(int sourceId); 66 | QString body() const; 67 | void setBody(const QString &body); 68 | QDateTime date() const; 69 | void setDate(const QDateTime &date); 70 | QVariantMap likes() const; 71 | void setLikes(const QVariantMap &likes); 72 | QVariantMap reposts() const; 73 | void setReposts(const QVariantMap &reposts); 74 | 75 | QVariant property(const QString &name, const QVariant &def = QVariant()) const; 76 | template 77 | T property(const char *name, const T &def) const 78 | { return QVariant::fromValue(property(name, QVariant::fromValue(def))); } 79 | void setProperty(const QString &name, const QVariant &value); 80 | QStringList dynamicPropertyNames() const; 81 | 82 | VK_SHARED_EXPORT friend QDataStream &operator <<(QDataStream &out, const Vreen::NewsItem &item); 83 | VK_SHARED_EXPORT friend QDataStream &operator >>(QDataStream &out, Vreen::NewsItem &item); 84 | protected: 85 | NewsItem(const QVariantMap &data); 86 | void setData(const QVariantMap &data); 87 | private: 88 | QSharedDataPointer d; 89 | }; 90 | typedef QList NewsItemList; 91 | 92 | } // namespace Vreen 93 | 94 | Q_DECLARE_METATYPE(Vreen::NewsItem) 95 | Q_DECLARE_METATYPE(Vreen::NewsItemList) 96 | 97 | #endif // VK_NEWSITEM_H 98 | 99 | -------------------------------------------------------------------------------- /src/api/pollitem.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licees/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "pollitem.h" 26 | #include 27 | #include 28 | 29 | namespace Vreen { 30 | 31 | template<> 32 | PollItem Attachment::to(const Attachment &data) 33 | { 34 | PollItem item; 35 | item.setPollId(data.property("poll_id").toInt()); 36 | item.setQuestion(data.property("question").toString()); 37 | return item; 38 | } 39 | 40 | class PollItemData : public QSharedData { 41 | public: 42 | PollItemData() : 43 | ownerId(0), pollId(0), votes(0), answerId(0) {} 44 | PollItemData(const PollItemData &o) : QSharedData(o), 45 | ownerId(o.ownerId), pollId(o.pollId), created(o.created), 46 | question(o.question), votes(o.votes), answerId(o.answerId), 47 | answers(o.answers) 48 | {} 49 | 50 | int ownerId; 51 | int pollId; 52 | QDateTime created; 53 | QString question; 54 | int votes; 55 | int answerId; 56 | PollItem::AnswerList answers; 57 | }; 58 | 59 | PollItem::PollItem(int pollId) : data(new PollItemData) 60 | { 61 | data->pollId = pollId; 62 | } 63 | 64 | PollItem::PollItem(const PollItem &rhs) : data(rhs.data) 65 | { 66 | } 67 | 68 | PollItem &PollItem::operator=(const PollItem &rhs) 69 | { 70 | if (this != &rhs) 71 | data.operator=(rhs.data); 72 | return *this; 73 | } 74 | 75 | PollItem::~PollItem() 76 | { 77 | } 78 | 79 | int PollItem::ownerId() const 80 | { 81 | return data->ownerId; 82 | } 83 | 84 | void PollItem::setOwnerId(int ownerId) 85 | { 86 | data->ownerId = ownerId; 87 | } 88 | 89 | int PollItem::pollId() const 90 | { 91 | return data->pollId; 92 | } 93 | 94 | void PollItem::setPollId(int pollId) 95 | { 96 | data->pollId = pollId; 97 | } 98 | 99 | QDateTime PollItem::created() const 100 | { 101 | return data->created; 102 | } 103 | 104 | void PollItem::setCreated(const QDateTime &created) 105 | { 106 | data->created = created; 107 | } 108 | 109 | QString PollItem::question() const 110 | { 111 | return data->question; 112 | } 113 | 114 | void PollItem::setQuestion(const QString &question) 115 | { 116 | data->question = question; 117 | } 118 | 119 | int PollItem::votes() const 120 | { 121 | return data->votes; 122 | } 123 | 124 | void PollItem::setVotes(int votes) 125 | { 126 | data->votes = votes; 127 | } 128 | 129 | int PollItem::answerId() const 130 | { 131 | return data->answerId; 132 | } 133 | 134 | void PollItem::setAnswerId(int answerId) 135 | { 136 | data->answerId = answerId; 137 | } 138 | 139 | PollItem::AnswerList PollItem::answers() const 140 | { 141 | return data->answers; 142 | } 143 | 144 | void PollItem::setAnswers(const PollItem::AnswerList &answers) 145 | { 146 | data->answers = answers; 147 | } 148 | 149 | } //namespace Vreen 150 | -------------------------------------------------------------------------------- /src/api/pollitem.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licees/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef POLLITEM_H 26 | #define POLLITEM_H 27 | 28 | #include 29 | #include 30 | #include "attachment.h" 31 | 32 | namespace Vreen { 33 | 34 | class PollItemData; 35 | 36 | class VK_SHARED_EXPORT PollItem 37 | { 38 | public: 39 | struct Answer { 40 | int id; 41 | QString text; 42 | int votes; 43 | qreal rate; 44 | }; 45 | typedef QList AnswerList; 46 | 47 | PollItem(int pollId = 0); 48 | PollItem(const PollItem &); 49 | PollItem &operator=(const PollItem &); 50 | ~PollItem(); 51 | 52 | int ownerId() const; 53 | void setOwnerId(int ownerId); 54 | int pollId() const; 55 | void setPollId(int pollId); 56 | QDateTime created() const; 57 | void setCreated(const QDateTime &created); 58 | QString question() const; 59 | void setQuestion(const QString &question); 60 | int votes() const; 61 | void setVotes(int votes); 62 | int answerId() const; 63 | void setAnswerId(int answerId); 64 | AnswerList answers() const; 65 | void setAnswers(const AnswerList &answers); 66 | private: 67 | QSharedDataPointer data; 68 | }; 69 | 70 | template<> 71 | PollItem Attachment::to(const Attachment &data); 72 | 73 | } //namespace Vreen 74 | 75 | Q_DECLARE_METATYPE(Vreen::PollItem) 76 | 77 | #endif // POLLITEM_H 78 | -------------------------------------------------------------------------------- /src/api/pollprovider.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licees/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include 26 | #include "client.h" 27 | #include "pollprovider.h" 28 | #include "pollitem.h" 29 | 30 | namespace Vreen { 31 | 32 | class PollProvider; 33 | class PollProviderPrivate 34 | { 35 | Q_DECLARE_PUBLIC(PollProvider) 36 | public: 37 | PollProviderPrivate(PollProvider *q, Client *client) : q_ptr(q), client(client) {} 38 | PollProvider *q_ptr; 39 | Client *client; 40 | 41 | static QVariant handlePoll(const QVariant& response) { 42 | auto map = response.toMap(); 43 | PollItem poll; 44 | poll.setOwnerId(map.value("owner_id").toInt()); 45 | poll.setPollId(map.value("poll_id").toInt()); 46 | poll.setCreated(map.value("created").toDateTime()); 47 | poll.setQuestion(map.value("question").toString()); 48 | poll.setVotes(map.value("votes").toInt()); 49 | poll.setAnswerId(map.value("answer_id").toInt()); 50 | 51 | PollItem::AnswerList answerList; 52 | auto answers = map.value("answers").toList(); 53 | foreach (auto item, answers) { 54 | auto map = item.toMap(); 55 | PollItem::Answer answer; 56 | answer.id = map.value("id").toInt(); 57 | answer.text = map.value("text").toString(); 58 | answer.votes = map.value("votes").toInt(); 59 | answer.rate = map.value("rate").toReal(); 60 | answerList.append(answer); 61 | } 62 | poll.setAnswers(answerList); 63 | 64 | return QVariant::fromValue(poll); 65 | } 66 | 67 | }; 68 | 69 | PollProvider::PollProvider(Client *client) : 70 | QObject(client), 71 | d_ptr(new PollProviderPrivate(this, client)) 72 | { 73 | } 74 | 75 | PollProvider::~PollProvider() 76 | { 77 | } 78 | 79 | PollItemReply *PollProvider::getPollById(int ownerId, int pollId) 80 | { 81 | Q_D(PollProvider); 82 | QVariantMap args; 83 | args.insert("owner_id", ownerId); 84 | args.insert("poll_id", pollId); 85 | 86 | auto reply = d->client->request("polls.getById", args, PollProviderPrivate::handlePoll); 87 | return reply; 88 | } 89 | 90 | Reply *PollProvider::addVote(int pollId, int answerId, int ownerId) 91 | { 92 | Q_D(PollProvider); 93 | QVariantMap args; 94 | args.insert("poll_id", pollId); 95 | args.insert("answer_id", answerId); 96 | if (ownerId) 97 | args.insert("owner_id", ownerId); 98 | 99 | auto reply = d->client->request("polls.addVote", args); 100 | return reply; 101 | } 102 | 103 | Reply *PollProvider::deleteVote(int pollId, int answerId, int ownerId) 104 | { 105 | Q_D(PollProvider); 106 | QVariantMap args; 107 | args.insert("poll_id", pollId); 108 | args.insert("answer_id", answerId); 109 | if (ownerId) 110 | args.insert("owner_id", ownerId); 111 | 112 | auto reply = d->client->request("polls.deleteVote", args); 113 | return reply; 114 | } 115 | 116 | } // namespace Vreen 117 | -------------------------------------------------------------------------------- /src/api/pollprovider.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licees/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VREEN_POLLPROVIDER_H 26 | #define VREEN_POLLPROVIDER_H 27 | 28 | #include "pollitem.h" 29 | #include "reply.h" 30 | 31 | namespace Vreen { 32 | 33 | class Client; 34 | typedef ReplyBase PollItemReply; 35 | 36 | class PollProviderPrivate; 37 | class VK_SHARED_EXPORT PollProvider : public QObject 38 | { 39 | Q_OBJECT 40 | Q_DECLARE_PRIVATE(PollProvider) 41 | public: 42 | explicit PollProvider(Client *client); 43 | ~PollProvider(); 44 | 45 | PollItemReply *getPollById(int ownerId, int pollId); 46 | Reply *addVote(int pollId, int answerId, int ownerId = 0); 47 | Reply *deleteVote(int pollId, int answerId, int ownerId = 0); 48 | protected: 49 | QScopedPointer d_ptr; 50 | }; 51 | 52 | } // namespace Vreen 53 | 54 | #endif // VREEN_POLLPROVIDER_H 55 | -------------------------------------------------------------------------------- /src/api/reply.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_REPLY_H 26 | #define VK_REPLY_H 27 | 28 | #include 29 | #include 30 | #include "vk_global.h" 31 | #include 32 | 33 | class QNetworkReply; 34 | namespace Vreen { 35 | 36 | class ReplyPrivate; 37 | class VK_SHARED_EXPORT Reply : public QObject 38 | { 39 | Q_OBJECT 40 | Q_DECLARE_PRIVATE(Reply) 41 | public: 42 | 43 | class ResultHandlerBase 44 | { 45 | public: 46 | virtual ~ResultHandlerBase() {} 47 | virtual QVariant handle(const QVariant &data) = 0; 48 | }; 49 | 50 | template 51 | class ResultHandlerImpl : public ResultHandlerBase 52 | { 53 | public: 54 | ResultHandlerImpl(Method method) : m_method(method) {} 55 | QVariant handle(const QVariant &data) 56 | { 57 | return m_method(data); 58 | } 59 | private: 60 | Method m_method; 61 | }; 62 | 63 | virtual ~Reply(); 64 | QNetworkReply *networkReply() const; 65 | QVariant response() const; 66 | Q_INVOKABLE QVariant error() const; 67 | QVariant result() const; 68 | 69 | template 70 | void setResultHandler(const Method &handler); 71 | signals: 72 | void resultReady(const QVariant &variables); 73 | void error(int code); 74 | protected: 75 | explicit Reply(QNetworkReply *networkReply = 0); 76 | void setReply(QNetworkReply *networkReply); 77 | 78 | QScopedPointer d_ptr; 79 | 80 | friend class Client; 81 | private: 82 | void setHandlerImpl(ResultHandlerBase *handler); 83 | 84 | Q_PRIVATE_SLOT(d_func(), void _q_reply_finished()) 85 | Q_PRIVATE_SLOT(d_func(), void _q_network_reply_error(QNetworkReply::NetworkError)) 86 | }; 87 | 88 | 89 | template 90 | void Reply::setResultHandler(const Method &handler) 91 | { 92 | setHandlerImpl(new ResultHandlerImpl(handler)); 93 | } 94 | 95 | template 96 | class ReplyBase : public Reply 97 | { 98 | public: 99 | T result() const { return qvariant_cast(Reply::result()); } 100 | protected: 101 | template 102 | explicit ReplyBase(Method handler, QNetworkReply *networkReply = 0) : 103 | Reply(networkReply) 104 | { 105 | setResultHandler(handler); 106 | } 107 | friend class Client; 108 | }; 109 | 110 | //some useful typedefs 111 | typedef ReplyBase IntReply; 112 | 113 | } // namespace Vreen 114 | 115 | Q_DECLARE_METATYPE(Vreen::Reply*) 116 | 117 | #endif // VK_REPLY_H 118 | 119 | -------------------------------------------------------------------------------- /src/api/reply_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef REPLY_P_H 26 | #define REPLY_P_H 27 | #include "reply.h" 28 | #include "json.h" 29 | #include "reply.h" 30 | #include "QNetworkReply" 31 | #include 32 | #include 33 | #include 34 | 35 | namespace Vreen { 36 | 37 | class ReplyPrivate 38 | { 39 | Q_DECLARE_PUBLIC(Reply) 40 | public: 41 | ReplyPrivate(Reply *q) : q_ptr(q), resultHandler(0) {} 42 | Reply *q_ptr; 43 | 44 | QPointer networkReply; 45 | QVariant response; 46 | QVariant error; 47 | QScopedPointer resultHandler; 48 | QVariant result; 49 | 50 | void _q_reply_finished(); 51 | void _q_network_reply_error(QNetworkReply::NetworkError); 52 | 53 | static QVariant handleInt(const QVariant &response) { return response.toInt(); } 54 | }; 55 | 56 | 57 | struct MessageListHandler { 58 | MessageListHandler(int clientId) : clientId(clientId) {} 59 | QVariant operator()(const QVariant &response); 60 | 61 | int clientId; 62 | }; 63 | 64 | } //namespace Vreen 65 | 66 | #endif // REPLY_P_H 67 | 68 | -------------------------------------------------------------------------------- /src/api/roster.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_ROSTER_H 26 | #define VK_ROSTER_H 27 | 28 | #include "contact.h" 29 | #include "message.h" 30 | #include "reply.h" 31 | #include "friendrequest.h" 32 | #include 33 | #include 34 | 35 | namespace Vreen { 36 | class Client; 37 | 38 | class RosterPrivate; 39 | class VK_SHARED_EXPORT Roster : public QObject 40 | { 41 | Q_OBJECT 42 | Q_DECLARE_PRIVATE(Roster) 43 | Q_FLAGS(FriendRequestFlags) 44 | public: 45 | 46 | enum NameCase { 47 | NomCase, 48 | GenCase, 49 | DatCase, 50 | AccCase, 51 | InsCase, 52 | AblCase 53 | }; 54 | 55 | enum FriendRequestFlag { 56 | NeedMutualFriends, 57 | NeedMessages, 58 | GetOutRequests 59 | }; 60 | Q_DECLARE_FLAGS(FriendRequestFlags, FriendRequestFlag) 61 | 62 | Roster(Client *client, int uid = 0); 63 | virtual ~Roster(); 64 | void setUid(int uid); 65 | int uid() const; 66 | 67 | Buddy *owner() const; 68 | Buddy *buddy(int id); 69 | Buddy *buddy(int id) const; 70 | BuddyList buddies() const; 71 | 72 | QMap tags() const; 73 | void setTags(const QMap &list); 74 | Reply *getDialogs(int offset = 0, int count = 16, int previewLength = -1); 75 | Reply *getMessages(int offset = 0, int count = 50, Message::Filter filter = Message::FilterNone); 76 | public slots: 77 | void sync(const QStringList &fields = QStringList() 78 | << VK_COMMON_FIELDS 79 | ); 80 | Reply *update(const IdList &ids, const QStringList &fields = QStringList() 81 | << VK_ALL_FIELDS 82 | ); 83 | Reply *update(const BuddyList &buddies, const QStringList &fields = QStringList() 84 | << VK_ALL_FIELDS 85 | ); 86 | ReplyBase *getFriendRequests(int count = 100, int offset = 0, FriendRequestFlags flags = NeedMessages); 87 | signals: 88 | void buddyAdded(Vreen::Buddy *buddy); 89 | void buddyUpdated(Vreen::Buddy *buddy); 90 | void buddyRemoved(int id); 91 | void tagsChanged(const QMap &); 92 | void syncFinished(bool success); 93 | void uidChanged(int uid); 94 | protected: 95 | QScopedPointer d_ptr; 96 | 97 | //friend class Contact; 98 | friend class Buddy; 99 | //friend class Group; 100 | 101 | Q_PRIVATE_SLOT(d_func(), void _q_tags_received(const QVariant &response)) 102 | Q_PRIVATE_SLOT(d_func(), void _q_friends_received(const QVariant &response)) 103 | Q_PRIVATE_SLOT(d_func(), void _q_status_changed(int userId, Vreen::Contact::Status status)) 104 | Q_PRIVATE_SLOT(d_func(), void _q_online_changed(bool)) 105 | Q_PRIVATE_SLOT(d_func(), void _q_updater_handle()) 106 | }; 107 | 108 | } // namespace Vreen 109 | 110 | Q_DECLARE_METATYPE(Vreen::Roster*) 111 | Q_DECLARE_OPERATORS_FOR_FLAGS(Vreen::Roster::FriendRequestFlags) 112 | 113 | #endif // VK_ROSTER_H 114 | 115 | -------------------------------------------------------------------------------- /src/api/roster_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef ROSTER_P_H 26 | #define ROSTER_P_H 27 | #include "roster.h" 28 | #include "client_p.h" 29 | #include "contact_p.h" 30 | 31 | namespace Vreen { 32 | 33 | typedef QHash BuddyHash; 34 | 35 | class Roster; 36 | class RosterPrivate 37 | { 38 | Q_DECLARE_PUBLIC(Roster) 39 | public: 40 | RosterPrivate(Roster *q, Client *client) : 41 | q_ptr(q), client(client), owner(0) 42 | { 43 | updaterTimer.setInterval(5000); 44 | updaterTimer.setSingleShot(true); 45 | updaterTimer.connect(&updaterTimer, SIGNAL(timeout()), 46 | q, SLOT(_q_updater_handle())); 47 | } 48 | 49 | Roster *q_ptr; 50 | Client *client; 51 | BuddyHash buddyHash; 52 | Buddy *owner; 53 | QMap tags; 54 | 55 | //TODO i want to use Qt5 slots 56 | //class Updater { 57 | //public: 58 | // typedef std::function Handler; 59 | 60 | // Updater(Client *client, const QVariantMap &query, const Handler &handler) : 61 | // client(client), 62 | // query(query), 63 | // handler(handler) 64 | // { 65 | // timer.setInterval(5000); 66 | // timer.setSingleShot(true); 67 | // QObject::connect(&timer, &timeout, this, &handle); 68 | // } 69 | // inline void handle() { 70 | // if (queue.count()) { 71 | // handler(client.data(), queue, query); 72 | // queue.clear(); 73 | // } 74 | // } 75 | // inline void append(const IdList &items) { 76 | // queue.append(items); 77 | // if (!timer.isActive()) { 78 | // timer.start(); 79 | // } 80 | // } 81 | //protected: 82 | // QPointer client; 83 | // QVariantMap query; 84 | // IdList queue; 85 | // QTimer timer; 86 | // Handler handler; 87 | //} updater; 88 | 89 | //updater 90 | QTimer updaterTimer; 91 | IdList updaterQueue; 92 | 93 | void getTags(); 94 | void getOnline(); 95 | void getFriends(const QVariantMap &args = QVariantMap()); 96 | void addBuddy(Buddy *contact); 97 | void appendToUpdaterQueue(Buddy *contact); 98 | 99 | static QVariant handleGetRequests(const QVariant &response); 100 | 101 | void _q_tags_received(const QVariant &response); 102 | void _q_friends_received(const QVariant &response); 103 | void _q_status_changed(int userId, Vreen::Contact::Status status); 104 | void _q_online_changed(bool); 105 | void _q_updater_handle(); 106 | }; 107 | 108 | } //namespace Vreen 109 | 110 | #endif // ROSTER_P_H 111 | 112 | -------------------------------------------------------------------------------- /src/api/utils.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "utils.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | //#define MAX_ENTITY 258 32 | //extern const struct QTextHtmlEntity { const char *name; quint16 code; } entities[MAX_ENTITY]; 33 | 34 | namespace Vreen { 35 | 36 | QString join(IdList ids) 37 | { 38 | QString result; 39 | if (ids.isEmpty()) 40 | return result; 41 | 42 | result = QString::number(ids.takeFirst()); 43 | foreach (auto id, ids) 44 | result += QLatin1Literal(",") % QString::number(id); 45 | return result; 46 | } 47 | 48 | QString toCamelCase(QString string) 49 | { 50 | int from = 0; 51 | while ((from = string.indexOf("_", from)) != -1) { 52 | auto index = from + 1; 53 | string.remove(from, 1); 54 | auto letter = string.at(index); 55 | string.replace(index, 1, letter.toUpper()); 56 | } 57 | return string; 58 | } 59 | 60 | QString fromHtmlEntities(const QString &source) 61 | { 62 | //Simple hack from slashdot 63 | QTextDocument text; 64 | text.setHtml(source); 65 | return text.toPlainText(); 66 | } 67 | 68 | QString toHtmlEntities(const QString &source) 69 | { 70 | #if QT_VERSION>=0x5 71 | return source.toHtmlEscaped(); 72 | #else 73 | return Qt::escape(source); 74 | #endif 75 | } 76 | 77 | } //namespace Vreen 78 | 79 | -------------------------------------------------------------------------------- /src/api/utils_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2013 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef UTILS_P_H 26 | #define UTILS_P_H 27 | #include "utils.h" 28 | 29 | namespace Vreen { 30 | 31 | QString VK_SHARED_EXPORT join(IdList ids); 32 | QString VK_SHARED_EXPORT toCamelCase(QString string); 33 | QString VK_SHARED_EXPORT fromHtmlEntities(const QString &source); 34 | 35 | } //namespace Vreen 36 | 37 | #endif // UTILS_P_H 38 | -------------------------------------------------------------------------------- /src/api/vk_global.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef API_GLOBAL_H 26 | #define API_GLOBAL_H 27 | 28 | #include 29 | 30 | #if defined(VK_LIBRARY) 31 | # define VK_SHARED_EXPORT Q_DECL_EXPORT 32 | #else 33 | # define VK_SHARED_EXPORT Q_DECL_IMPORT 34 | #endif 35 | 36 | typedef QList IdList; 37 | 38 | #endif // API_GLOBAL_H 39 | 40 | -------------------------------------------------------------------------------- /src/api/vreen.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=${CMAKE_INSTALL_PREFIX} 2 | exec_prefix=${CMAKE_INSTALL_PREFIX}/bin 3 | libdir=${LIB_DESTINATION} 4 | includedir=${VREEN_PKG_INCDIR} 5 | 6 | Name: vreen 7 | Description: Simple and fast Qt Binding for vk.com API 8 | Requires: QtCore QtNetwork 9 | Version: ${LIBRARY_VERSION} 10 | Libs: ${VREEN_PKG_LIBS} 11 | Cflags: -I${VREEN_PKG_INCDIR} 12 | 13 | -------------------------------------------------------------------------------- /src/api/wallpost.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef WALLPOST_H 26 | #define WALLPOST_H 27 | 28 | #include 29 | #include 30 | #include "vk_global.h" 31 | #include "attachment.h" 32 | 33 | namespace Vreen { 34 | 35 | class WallPostData; 36 | class Client; 37 | class Contact; 38 | 39 | class VK_SHARED_EXPORT WallPost 40 | { 41 | public: 42 | WallPost(); 43 | WallPost(const WallPost &); 44 | WallPost &operator=(const WallPost &); 45 | ~WallPost(); 46 | 47 | void setId(int id); 48 | int id() const; 49 | void setBody(const QString &body); 50 | QString body() const; 51 | void setFromId(int id); 52 | int fromId() const; 53 | void setToId(int id); 54 | int toId() const; 55 | int ownerId() const; 56 | void setOwnerId(int ownerId); 57 | void setDate(const QDateTime &date); 58 | QDateTime date() const; 59 | int signerId() const; 60 | void setSignerId(int signerId); 61 | QString copyText() const; 62 | void setCopyText(const QString ©Text); 63 | Attachment::Hash attachments() const; 64 | Attachment::List attachments(Attachment::Type type) const; 65 | void setAttachments(const Attachment::List &attachmentList); 66 | QVariantMap likes() const; 67 | void setLikes(const QVariantMap &likes); 68 | QVariantMap reposts() const; 69 | void setReposts(const QVariantMap &reposts); 70 | 71 | static WallPost fromData(const QVariant data); 72 | 73 | QVariant property(const QString &name, const QVariant &def = QVariant()) const; 74 | template 75 | T property(const char *name, const T &def) const 76 | { return QVariant::fromValue(property(name, QVariant::fromValue(def))); } 77 | 78 | void setProperty(const QString &name, const QVariant &value); 79 | QStringList dynamicPropertyNames() const; 80 | protected: 81 | WallPost(QVariantMap data); 82 | private: 83 | QSharedDataPointer d; 84 | }; 85 | typedef QList WallPostList; 86 | 87 | } //namespace Vreen 88 | 89 | #endif // WALLPOST_H 90 | 91 | -------------------------------------------------------------------------------- /src/api/wallsession.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_WALLSESSION_H 26 | #define VK_WALLSESSION_H 27 | 28 | #include "client.h" 29 | #include "wallpost.h" 30 | 31 | namespace Vreen { 32 | 33 | class Reply; 34 | class WallSessionPrivate; 35 | class VK_SHARED_EXPORT WallSession : public QObject 36 | { 37 | Q_OBJECT 38 | Q_DECLARE_PRIVATE(WallSession) 39 | Q_ENUMS(Filter) 40 | public: 41 | enum Filter { 42 | Owner = 0x1, 43 | Others = 0x2, 44 | All = Owner | Others 45 | }; 46 | 47 | explicit WallSession(Contact *contact); 48 | Contact *contact() const; 49 | virtual ~WallSession(); 50 | 51 | public slots: 52 | Reply *getPosts(Filter filter = All, quint8 count = 16, int offset = 0, bool extended = false); 53 | Reply *addLike(int postId, bool retweet = false, const QString &message = QString()); 54 | Reply *deleteLike(int postId); 55 | signals: 56 | void postAdded(const Vreen::WallPost &post); 57 | void postDeleted(int postId); 58 | void postLikeAdded(int postId, int likesCount, int repostsCount, bool isRetweeted); 59 | void postLikeDeleted(int postId, int likesCount); 60 | protected: 61 | QScopedPointer d_ptr; 62 | 63 | Q_PRIVATE_SLOT(d_func(), void _q_posts_received(QVariant)) 64 | Q_PRIVATE_SLOT(d_func(), void _q_like_added(QVariant)) 65 | Q_PRIVATE_SLOT(d_func(), void _q_like_deleted(QVariant)) 66 | }; 67 | 68 | } // namespace Vreen 69 | 70 | #endif // VK_WALLSESSION_H 71 | 72 | -------------------------------------------------------------------------------- /src/auth/direct/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_simple_library(vreendirectauth 2 | STATIC CXX11 3 | ${INTERNAL_FLAG} 4 | ${DEVELOPER_FLAG} 5 | DEFINE_SYMBOL VK_LIBRARY 6 | VERSION ${CMAKE_VREEN_VERSION_STRING} 7 | SOVERSION ${CMAKE_VREEN_VERSION_MAJOR} 8 | LIBRARIES vreen ${QT_QTWEBKIT_LIBRARY} 9 | INCLUDES ${VREEN_INCLUDE_DIR} ../api ${VREEN_PRIVATE_INCLUDE_DIR} 10 | INCLUDE_DIR vreen/auth 11 | QT Network 12 | ) 13 | -------------------------------------------------------------------------------- /src/auth/direct/directauth.qbs: -------------------------------------------------------------------------------- 1 | import qbs.base 1.0 2 | 3 | Product { 4 | condition: false 5 | 6 | property string clientId 7 | property string clientSecret 8 | property string clientName 9 | 10 | type: ["staticlibrary", "installed_content"] 11 | name: "vreendirectauth" 12 | destinationDirectory: vreen_lib_path 13 | 14 | cpp.defines: [ 15 | "VREEN_DIRECTAUTH_CLIENT_ID=\"" + clientId + "\"", 16 | "VREEN_DIRECTAUTH_CLIENT_SECRET=\"" + clientSecret + "\"", 17 | "VREEN_DIRECTAUTH_CLIENT_NAME=\"" + clientName + "\"" 18 | ] 19 | 20 | Depends { name: "cpp" } 21 | Depends { name: "Qt"; submodules: ['core', 'network'] } 22 | Depends { name: "vreen" } 23 | 24 | files: [ 25 | "*.cpp" 26 | ] 27 | 28 | Group { 29 | files: "*.h" 30 | fileTags: ["hpp", "devheader"] 31 | overrideTags: false 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/auth/direct/directconnection_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_DIRECTCONNECTION_H 26 | #define VK_DIRECTCONNECTION_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace Vreen { 33 | 34 | class DirectConnection : public Connection 35 | { 36 | Q_OBJECT 37 | public: 38 | explicit DirectConnection(QObject *parent = 0); 39 | 40 | void connectToHost(const QString &login, const QString &password); 41 | void disconnectFromHost(); 42 | Client::State connectionState() const; 43 | int uid() const; 44 | void clear(); 45 | protected: 46 | void setConnectionState(Client::State connectionState); 47 | void getToken(const QString &login, const QString &password); 48 | QNetworkRequest makeRequest(const QString &method, const QVariantMap &args); 49 | void decorateRequest(QNetworkRequest &request); 50 | protected slots: 51 | void getTokenFinished(); 52 | void onReplyFinished(); 53 | void onReplyError(QNetworkReply::NetworkError error); 54 | private: 55 | Client::State m_connectionState; 56 | struct AccessToken { 57 | AccessToken() {} 58 | QByteArray accessToken; 59 | int expireTime; 60 | int uid; 61 | }; 62 | AccessToken m_token; 63 | }; 64 | 65 | } // namespace Vreen 66 | 67 | #endif // VK_DIRECTCONNECTION_H 68 | 69 | -------------------------------------------------------------------------------- /src/auth/widget/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_simple_library(vreenoauth 2 | STATIC CXX14 3 | ${INTERNAL_FLAG} 4 | ${DEVELOPER_FLAG} 5 | DEFINE_SYMBOL VK_LIBRARY 6 | VERSION ${CMAKE_VREEN_VERSION_STRING} 7 | SOVERSION ${CMAKE_VREEN_VERSION_MAJOR} 8 | LIBRARIES vreen ${QT_QTWEBKIT_LIBRARY} 9 | INCLUDES ../../api ${VREEN_INCLUDE_DIR} ${VREEN_PRIVATE_INCLUDE_DIR} 10 | INCLUDE_DIR vreen/auth 11 | DEFINES VREEN_WITH_WEBENGINE 12 | QT WebEngine WebEngineWidgets 13 | ) 14 | -------------------------------------------------------------------------------- /src/auth/widget/oauth.qbs: -------------------------------------------------------------------------------- 1 | import qbs.base 1.0 2 | 3 | Product { 4 | property bool 5 | 6 | type: ["staticlibrary"] 7 | name: "vreenoauth" 8 | destinationDirectory: project.vreen_lib_path 9 | 10 | Depends { name: "cpp" } 11 | Depends { name: "Qt.core" } 12 | 13 | Properties { 14 | condition: !project.with_webkit 15 | cpp.defines: base.concat("VREEN_WITH_WEBENGINE") 16 | } 17 | 18 | Depends { name: "Qt.webengine"; condition: !project.with_webkit } 19 | Depends { name: "Qt.webenginewidgets"; condition: !project.with_webkit } 20 | Depends { name: "Qt.webkitwidgets"; condition: project.with_webkit } 21 | 22 | 23 | Depends { name: "vreencore" } 24 | Depends { name: "vreen" } 25 | 26 | files: [ 27 | "*.cpp" 28 | ] 29 | 30 | Export { 31 | Depends { name: "cpp" } 32 | Depends { name: "Qt.core" } 33 | 34 | Depends { name: "Qt.webengine"; condition: !project.with_webkit } 35 | Depends { name: "Qt.webenginewidgets"; condition: !project.with_webkit } 36 | Depends { name: "Qt.webkitwidgets"; condition: project.with_webkit } 37 | 38 | cpp.includePaths: [ 39 | product.buildDirectory + "/GeneratedFiles/include" 40 | ] 41 | cpp.defines: base.concat("VREEN_WITH_OAUTH") 42 | } 43 | 44 | Group { 45 | name: "Devel headers" 46 | files: "*.h" 47 | fileTags: ["hpp", "devheader"] 48 | overrideTags: false 49 | qbs.installDir: "include/vreen/auth" 50 | qbs.installSourceBase: "." 51 | qbs.install: true 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/auth/widget/oauthconnection.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VK_OAUTHCONNECTION_H 26 | #define VK_OAUTHCONNECTION_H 27 | 28 | #include 29 | #include 30 | 31 | class QWebPage; 32 | 33 | namespace Vreen { 34 | 35 | class OAuthConnectionPrivate; 36 | 37 | class OAuthConnection : public Connection 38 | { 39 | Q_OBJECT 40 | Q_DECLARE_PRIVATE(OAuthConnection) 41 | Q_ENUMS(DisplayType) 42 | Q_FLAGS(Scopes) 43 | Q_PROPERTY(int clientId READ clientId WRITE setClientId NOTIFY clientIdChanged) 44 | Q_PROPERTY(DisplayType displayType READ displayType WRITE setDisplayType) 45 | Q_PROPERTY(Scopes scopes READ scopes WRITE setScopes NOTIFY scopesChanged) 46 | public: 47 | enum DisplayType { 48 | Page, 49 | Popup, 50 | Touch, 51 | Wap 52 | }; 53 | enum Scope { 54 | Notify = 0x1, 55 | Friends = 0x2, 56 | Photos = 0x4, 57 | Audio = 0x8, 58 | Video = 0x10, 59 | Docs = 0x20, 60 | Notes = 0x40, 61 | Pages = 0x80, 62 | Status = 0x100, 63 | Offers = 0x200, 64 | Questions = 0x400, 65 | Wall = 0x800, 66 | Groups = 0x1000, 67 | Messages = 0x2000, 68 | Notifications = 0x4000, 69 | Stats = 0x8000, 70 | Ads = 0x10000, 71 | Offline = 0x20000 72 | }; 73 | Q_DECLARE_FLAGS(Scopes, Scope) 74 | 75 | explicit OAuthConnection(int clientId, QObject *parent = 0); 76 | explicit OAuthConnection(QObject *parent = 0); 77 | virtual ~OAuthConnection(); 78 | 79 | void connectToHost(const QString &login, const QString &password); 80 | void disconnectFromHost(); 81 | QNetworkReply *request(const QString &method, const QVariantMap &args = QVariantMap()); 82 | Client::State connectionState() const; 83 | int uid() const; 84 | void clear(); 85 | 86 | QString accessToken() const; 87 | time_t expiresIn() const; 88 | void setAccessToken(const QByteArray &token, time_t expiresIn = 0); 89 | void setUid(int uid); 90 | int clientId() const; 91 | void setClientId(int clientId); 92 | DisplayType displayType() const; 93 | void setDisplayType(DisplayType displayType); 94 | Scopes scopes() const; 95 | void setScopes(Scopes scopes); 96 | signals: 97 | void authConfirmRequested(QObject *page); 98 | void accessTokenChanged(const QString &token, time_t expiresIn); 99 | void clientIdChanged(int clientId); 100 | void scopesChanged(Vreen::OAuthConnection::Scopes scopes); 101 | protected: 102 | void decorateRequest(QNetworkRequest &); 103 | private: 104 | Q_PRIVATE_SLOT(d_func(), void _q_loadFinished(bool)) 105 | }; 106 | 107 | Q_DECLARE_OPERATORS_FOR_FLAGS(OAuthConnection::Scopes) 108 | 109 | } // namespace Vreen 110 | 111 | #endif // VK_OAUTHCONNECTION_H 112 | 113 | -------------------------------------------------------------------------------- /src/qml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QT_USE_QTDECLARATIVE true) 2 | set(VREEN_IMPORTS_DIR "${VREEN_IMPORTS_DIR}" CACHE INTERNAL "") 3 | 4 | if(VREEN_WITH_AUTH_WIDGET) 5 | list(APPEND VREEN_PLUGIN_DEFINES "VREEN_WITH_OAUTH") 6 | list(APPEND VREEN_PLUGIN_LIBS vreenoauth) 7 | list(APPEND _extra_qt WebEngineWidgets) 8 | endif() 9 | 10 | add_qml_module(vreenplugin 11 | CXX14 12 | ${DEVELOPER_FLAG} 13 | URI Vreen.Base 14 | QML_DIR qmldir 15 | SOURCE_DIR src 16 | SOURCE_FILES ${EXTRA_SRC} 17 | LIBRARIES vreen ${VREEN_PLUGIN_LIBS} 18 | DEFINES ${VREEN_PLUGIN_DEFINES} 19 | INCLUDES ../api ${VREEN_INCLUDE_DIR} ${VREEN_INCLUDE_DIR}/${CMAKE_VREEN_VERSION_STRING}/ 20 | IMPORTS_DIR ${VREEN_IMPORTS_DIR} 21 | QT Core Network Gui Widgets ${_extra_qt} 22 | ) 23 | -------------------------------------------------------------------------------- /src/qml/qmldir/PhotoModel.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 1.1 2 | 3 | ListModel { 4 | id: model 5 | 6 | function getAll(ownerId, count, offset) { 7 | if (!offset) 8 | offset = 0; 9 | if (!count) 10 | count = 200; 11 | 12 | var args = { 13 | "owner_id" : ownerId, 14 | "offset" : offset, 15 | "count" : count, 16 | "extended" : 0 17 | } 18 | var reply = client.request("photos.getAll", args) 19 | reply.resultReady.connect(function(response) { 20 | var count = response.shift() 21 | for (var index in response) { 22 | var photo = response[index] 23 | model.append(photo) 24 | } 25 | }) 26 | } 27 | 28 | function _find(photoId) { 29 | for (var index = 0; index != model.count; index++) 30 | if (get(index).pid === photoId) 31 | return photoId 32 | return -1 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/qml/qmldir/qmldir: -------------------------------------------------------------------------------- 1 | module Vreen.Base 2 | PhotoModel 2.0 PhotoModel.qml 3 | plugin vreenplugin 4 | -------------------------------------------------------------------------------- /src/qml/src/audiomodel.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "audiomodel.h" 26 | #include 27 | #include 28 | 29 | AudioModel::AudioModel(QObject *parent) : 30 | Vreen::AudioModel(parent) 31 | { 32 | } 33 | 34 | Vreen::Client* AudioModel::client() const 35 | { 36 | return m_client.data(); 37 | } 38 | 39 | void AudioModel::setClient(Vreen::Client* client) 40 | { 41 | if (m_client != client) { 42 | m_client = client; 43 | if (!client) 44 | m_provider.data()->deleteLater(); 45 | else 46 | m_provider = new Vreen::AudioProvider(client); 47 | emit clientChanged(client); 48 | } 49 | } 50 | 51 | Vreen::Reply *AudioModel::getAudio(Vreen::Contact* contact, int count, int offset) 52 | { 53 | return getAudio(contact->id(), count, offset); 54 | } 55 | 56 | Vreen::Reply *AudioModel::getAudio(int id, int count, int offset) 57 | { 58 | if (m_provider.data()) { 59 | auto reply = m_provider.data()->getContactAudio(id, count, offset); 60 | connect(reply, SIGNAL(resultReady(QVariant)), 61 | this, SLOT(onResultReady())); 62 | return reply; 63 | } 64 | return 0; 65 | } 66 | 67 | Vreen::Reply *AudioModel::searchAudio(const QString& query, int count, int offset, bool autoComplete, Vreen::AudioProvider::SortOrder sort, bool withLyrics) 68 | { 69 | if (m_provider.data()) { 70 | auto reply = m_provider.data()->searchAudio(query, count, offset, autoComplete, sort, withLyrics); 71 | connect(reply, SIGNAL(resultReady(QVariant)), 72 | this, SLOT(onResultReady())); 73 | return reply; 74 | } 75 | return 0; 76 | } 77 | 78 | void AudioModel::onResultReady() 79 | { 80 | auto reply = static_cast(sender()); 81 | foreach (auto item, reply->result()) 82 | addAudio(item); 83 | } 84 | -------------------------------------------------------------------------------- /src/qml/src/audiomodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef AUDIOMODEL_H 26 | #define AUDIOMODEL_H 27 | #include 28 | #include 29 | #include 30 | 31 | namespace Vreen { 32 | class Contact; 33 | } 34 | 35 | class AudioModel : public Vreen::AudioModel 36 | { 37 | Q_OBJECT 38 | 39 | Q_PROPERTY(Vreen::Client* client READ client WRITE setClient NOTIFY clientChanged) 40 | public: 41 | explicit AudioModel(QObject *parent = 0); 42 | Vreen::Client* client() const; 43 | void setClient(Vreen::Client *client); 44 | public slots: 45 | Vreen::Reply *getAudio(int id = 0, int count = 100, int offset = 0); 46 | Vreen::Reply *getAudio(Vreen::Contact *contact, int count = 100, int offset = 0); 47 | Vreen::Reply *searchAudio(const QString& query, int count = 50, int offset = 0, bool autoComplete = true, Vreen::AudioProvider::SortOrder sort = Vreen::AudioProvider::SortByPopularity, bool withLyrics = false); 48 | signals: 49 | void clientChanged(Vreen::Client *client); 50 | private slots: 51 | void onResultReady(); 52 | private: 53 | QPointer m_client; 54 | QPointer m_provider; 55 | }; 56 | 57 | #endif // AUDIOMODEL_H 58 | 59 | -------------------------------------------------------------------------------- /src/qml/src/buddymodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef CONTACTSMODEL_H 26 | #define CONTACTSMODEL_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class BuddyModel : public QAbstractListModel 34 | { 35 | Q_OBJECT 36 | 37 | Q_PROPERTY(Vreen::Roster *roster READ roster WRITE setRoster NOTIFY rosterChanged) 38 | Q_PROPERTY(QString filterByName READ filterByName WRITE setFilterByName NOTIFY filterByNameChanged) 39 | public: 40 | enum Roles { 41 | ContactRole = Qt::UserRole + 1 42 | }; 43 | 44 | struct CompareType 45 | { 46 | QString name; 47 | int status; 48 | inline friend bool operator <(const BuddyModel::CompareType &a, const BuddyModel::CompareType &b) 49 | { 50 | int less = a.name.compare(b.name); 51 | if (less) 52 | return less > 0; 53 | return a.status < b.status; 54 | } 55 | inline static CompareType comparator(Vreen::Buddy * const& buddy) 56 | { 57 | BuddyModel::CompareType type = { 58 | buddy->name(), 59 | buddy->status() 60 | }; 61 | return type; 62 | } 63 | }; 64 | 65 | explicit BuddyModel(QObject *parent = 0); 66 | 67 | void setRoster(Vreen::Roster *roster); 68 | Vreen::Roster *roster() const; 69 | int count() const; 70 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 71 | virtual int rowCount(const QModelIndex &parent) const; 72 | void setFilterByName(const QString &filter); 73 | QString filterByName(); 74 | void clear(); 75 | public slots: 76 | int findContact(int id) const; 77 | signals: 78 | void rosterChanged(Vreen::Roster*); 79 | void filterByNameChanged(const QString &filter); 80 | private slots: 81 | void addBuddy(Vreen::Buddy *); 82 | void removeFriend(int id); 83 | void onSyncFinished(); 84 | protected: 85 | bool checkContact(Vreen::Buddy *); 86 | void setBuddies(const Vreen::BuddyList &list); 87 | private: 88 | QPointer m_roster; 89 | Vreen::BuddyList m_buddyList; 90 | QString m_filterByName; 91 | bool m_friendsOnly; 92 | 93 | Vreen::Comparator m_buddyComparator; 94 | }; 95 | 96 | #endif // CONTACTSMODEL_H 97 | 98 | -------------------------------------------------------------------------------- /src/qml/src/chatmodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef CHATMODEL_H 26 | #define CHATMODEL_H 27 | #include "chatmodel.h" 28 | #include 29 | #include 30 | 31 | namespace Vreen { 32 | class MessageSession; 33 | class Reply; 34 | } //namespace Vreen 35 | 36 | class ChatModel : public Vreen::MessageListModel 37 | { 38 | Q_OBJECT 39 | Q_PROPERTY(QString title READ title NOTIFY titleChanged) 40 | Q_PROPERTY(Vreen::MessageSession* session READ messageSession NOTIFY messageSessionChanged) 41 | public: 42 | explicit ChatModel(QObject *parent = 0); 43 | QString title() const; 44 | void setMessageSession(Vreen::MessageSession *session); 45 | Vreen::MessageSession *messageSession() const; 46 | protected: 47 | void doInsertMessage(int index, const Vreen::Message &message); 48 | public slots: 49 | void setContact(Vreen::Contact *contact); 50 | void setChatId(int chatId); 51 | Vreen::Reply *getHistory(int count = 16, int offset = 0); 52 | Vreen::Reply *markAsRead(int mid, bool set = true); 53 | Vreen::Reply *sendMessage(const QString &message, const QString &subject = QString()); 54 | signals: 55 | void contactChanged(Vreen::Contact*); 56 | void titleChanged(const QString &title); 57 | void requestFinished(); 58 | void messageSessionChanged(const Vreen::MessageSession *); 59 | private slots: 60 | void messageReadStateChanged(int id, bool set); 61 | private: 62 | QPointer m_session; 63 | }; 64 | 65 | #endif // CHATMODEL_H 66 | 67 | -------------------------------------------------------------------------------- /src/qml/src/clientimpl.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "clientimpl.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | Client::Client(QObject *parent) : 37 | Vreen::Client(parent) 38 | { 39 | connect(this, SIGNAL(onlineStateChanged(bool)), this, 40 | SLOT(onOnlineStateChanged(bool))); 41 | 42 | QSettings settings; 43 | settings.beginGroup("connection"); 44 | setLogin(settings.value("login").toString()); 45 | setPassword(settings.value("password").toString()); 46 | settings.endGroup(); 47 | 48 | auto manager = new QNetworkConfigurationManager(this); 49 | connect(manager, SIGNAL(onlineStateChanged(bool)), this, SLOT(setOnline(bool))); 50 | 51 | connect(longPoll(), SIGNAL(messageAdded(Vreen::Message)), SLOT(onMessageAdded(Vreen::Message))); 52 | connect(this, SIGNAL(replyCreated(Vreen::Reply*)), SLOT(onReplyCreated(Vreen::Reply*))); 53 | connect(this, SIGNAL(error(Vreen::Client::Error)), SLOT(onReplyError(Vreen::Client::Error))); 54 | } 55 | 56 | QObject *Client::request(const QString &method, const QVariantMap &args) 57 | { 58 | return Vreen::Client::request(method, args); 59 | } 60 | 61 | Vreen::Contact *Client::contact(int id) 62 | { 63 | return roster()->buddy(id); 64 | } 65 | 66 | void Client::onOnlineStateChanged(bool isOnline) 67 | { 68 | if (isOnline) { 69 | //save settings (TODO use crypto backend as possible) 70 | QSettings settings; 71 | settings.beginGroup("connection"); 72 | settings.setValue("login", login()); 73 | settings.setValue("password", password()); 74 | settings.endGroup(); 75 | } 76 | } 77 | 78 | void Client::setOnline(bool set) 79 | { 80 | set ? connectToHost() 81 | : disconnectFromHost(); 82 | } 83 | 84 | void Client::onMessageAdded(const Vreen::Message &msg) 85 | { 86 | if (msg.isIncoming() && msg.isUnread()) 87 | emit messageReceived(contact(msg.fromId())); 88 | } 89 | 90 | void Client::onReplyCreated(Vreen::Reply *reply) 91 | { 92 | qDebug() << "--SendReply:" << reply->networkReply()->url(); 93 | connect(reply, SIGNAL(resultReady(QVariant)),SLOT(onReplyFinished(QVariant))); 94 | } 95 | 96 | void Client::onReplyFinished(const QVariant &) 97 | { 98 | Vreen::Reply *reply = Vreen::sender_cast(sender()); 99 | qDebug() << "--Reply finished" << reply->networkReply()->url().encodedPath(); 100 | //qDebug() << "--data" << reply->response(); 101 | } 102 | 103 | void Client::onReplyError(Error error) 104 | { 105 | qDebug() << "--Error" << error; 106 | } 107 | -------------------------------------------------------------------------------- /src/qml/src/clientimpl.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef CLIENT_H 26 | #define CLIENT_H 27 | #include 28 | #include 29 | 30 | class Client : public Vreen::Client 31 | { 32 | Q_OBJECT 33 | Q_CLASSINFO("DefaultProperty", "connection") 34 | public: 35 | Client(QObject *parent = 0); 36 | Q_INVOKABLE QObject *request(const QString &method, const QVariantMap &args = QVariantMap()); 37 | Q_INVOKABLE Vreen::Contact *contact(int id); 38 | signals: 39 | void messageReceived(Vreen::Contact *from); 40 | private slots: 41 | void onOnlineStateChanged(bool state); 42 | void setOnline(bool set); 43 | void onMessageAdded(const Vreen::Message &msg); 44 | void onReplyCreated(Vreen::Reply *reply); 45 | void onReplyFinished(const QVariant &); 46 | void onReplyError(Vreen::Client::Error); 47 | }; 48 | 49 | #endif // CLIENT_H 50 | 51 | -------------------------------------------------------------------------------- /src/qml/src/commentsmodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef COMMENTSMODEL_H 26 | #define COMMENTSMODEL_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | class CommentsModel : public QAbstractListModel 33 | { 34 | Q_OBJECT 35 | Q_PROPERTY(Vreen::Contact* contact READ contact WRITE setContact NOTIFY contactChanged) 36 | Q_PROPERTY(int postId READ postId WRITE setPostId NOTIFY postChangedId) 37 | public: 38 | explicit CommentsModel(QObject *parent = 0); 39 | 40 | enum Roles { 41 | IdRole = Qt::UserRole, 42 | FromRole, 43 | DateRole, 44 | BodyRole, 45 | LikesRole 46 | }; 47 | 48 | Vreen::Contact* contact() const; 49 | void setContact(Vreen::Contact* contact); 50 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 51 | virtual int rowCount(const QModelIndex &) const; 52 | int count() const; 53 | int findComment(int id) const; 54 | int postId() const; 55 | void setPostId(int arg); 56 | signals: 57 | void contactChanged(Vreen::Contact*); 58 | void requestFinished(); 59 | void postChangedId(int); 60 | 61 | public slots: 62 | void clear(); 63 | Vreen::Reply *getComments(int count = 100, int offset = 0); 64 | private slots: 65 | void addComment(const QVariantMap &data); 66 | void deleteComment(int id); 67 | private: 68 | QPointer m_contact; 69 | QPointer m_session; 70 | Vreen::CommentList m_comments; 71 | int m_postId; 72 | }; 73 | 74 | #endif // COMMENTSMODEL_H 75 | 76 | -------------------------------------------------------------------------------- /src/qml/src/dialogsmodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef DIALOGSMODEL_H 26 | #define DIALOGSMODEL_H 27 | #include 28 | #include 29 | #include 30 | 31 | class DialogsModel : public Vreen::MessageListModel 32 | { 33 | Q_OBJECT 34 | 35 | Q_PROPERTY(int unreadCount READ unreadCount NOTIFY unreadCountChanged) 36 | public: 37 | explicit DialogsModel(QObject *parent = 0); 38 | 39 | void setUnreadCount(int count); 40 | int unreadCount() const; 41 | public slots: 42 | Vreen::Reply *getDialogs(int count = 25, int offset = 0, int previewLength = -1); 43 | signals: 44 | void unreadCountChanged(int count); 45 | protected: 46 | virtual void doReplaceMessage(int index, const::Vreen::Message &message); 47 | virtual void doInsertMessage(int index, const::Vreen::Message &message); 48 | virtual void doRemoveMessage(int index); 49 | private slots: 50 | void onDialogsReceived(const QVariant &dialogs); 51 | void onClientChanged(Vreen::Client *client); 52 | private: 53 | int m_unreadCount; 54 | }; 55 | 56 | #endif // DIALOGSMODEL_H 57 | 58 | -------------------------------------------------------------------------------- /src/qml/src/newsfeedmodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef NEWSFEEDMODEL_H 26 | #define NEWSFEEDMODEL_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace Vreen { 34 | class Contact; 35 | } //namespace Vreen 36 | 37 | class NewsFeedModel : public QAbstractListModel 38 | { 39 | Q_OBJECT 40 | Q_PROPERTY(QObject* client READ client WRITE setClient NOTIFY clientChanged) 41 | Q_PROPERTY(int count READ count NOTIFY requestFinished) 42 | public: 43 | 44 | enum Roles { 45 | TypeRole = Qt::UserRole, 46 | PostIdRole, 47 | FromRole, 48 | DateRole, 49 | BodyRole, 50 | AttachmentsRole, 51 | LikesRole, 52 | RepostsRole, 53 | CommentsRole, 54 | OwnerRole 55 | }; 56 | 57 | explicit NewsFeedModel(QObject *parent = 0); 58 | QObject* client() const; 59 | void setClient(QObject* arg); 60 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 61 | virtual int rowCount(const QModelIndex &) const; 62 | int count() const; 63 | int findNews(int id); 64 | public slots: 65 | Vreen::Reply *getNews(int filters = Vreen::NewsFeed::FilterPost | Vreen::NewsFeed::FilterPhoto, 66 | quint8 count = 10, int offset = 0); 67 | void addLike(int postId, bool retweet = false, const QString &message = QString()); 68 | void deleteLike(int postId); 69 | void clear(); 70 | void truncate(int count); 71 | signals: 72 | void clientChanged(QObject* client); 73 | void requestFinished(); 74 | protected: 75 | void insertNews(int index, const Vreen::NewsItem &data); 76 | void replaceNews(int index, const Vreen::NewsItem &data); 77 | inline Vreen::Contact *findContact(int id) const; 78 | private slots: 79 | void onNewsReceived(const Vreen::NewsItemList &data); 80 | void onAddLike(const QVariant &response); 81 | void onDeleteLike(const QVariant &response); 82 | private: 83 | QPointer m_client; 84 | QPointer m_newsFeed; 85 | Vreen::NewsItemList m_newsList; 86 | Vreen::Comparator m_newsItemComparator; 87 | }; 88 | 89 | #endif // NEWSFEEDMODEL_H 90 | 91 | -------------------------------------------------------------------------------- /src/qml/src/vkitqmlplugin.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef VKITQMLPLUGIN_H 26 | #define VKITQMLPLUGIN_H 27 | 28 | #include "clientimpl.h" 29 | #include 30 | #include 31 | #include "buddymodel.h" 32 | #include "dialogsmodel.h" 33 | #include "chatmodel.h" 34 | #include "wallmodel.h" 35 | #include "commentsmodel.h" 36 | #include "newsfeedmodel.h" 37 | #include "audiomodel.h" 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 46 | #include 47 | #include 48 | #else 49 | #include 50 | #include 51 | #endif 52 | 53 | #ifdef VREEN_WITH_OAUTH 54 | #include 55 | #endif 56 | 57 | static inline void registerVreenTypes(const char *uri) 58 | { 59 | Q_ASSERT(uri == QLatin1String("Vreen.Base")); // @uri Vreen.Base 60 | 61 | qmlRegisterType(uri, 2, 0, "Client"); 62 | qmlRegisterType(uri, 2, 0, "BuddyModel"); 63 | qmlRegisterType(uri, 2, 0, "DialogsModel"); 64 | qmlRegisterType(uri, 2, 0, "ChatModel"); 65 | qmlRegisterType(uri, 2, 0, "WallModel"); 66 | qmlRegisterType(uri, 2, 0, "NewsFeedModel"); 67 | qmlRegisterType(uri, 2, 0, "CommentsModel"); 68 | qmlRegisterType(uri, 2, 0, "AudioModel"); 69 | #ifdef VREEN_WITH_OAUTH 70 | qmlRegisterType(uri, 2, 0, "OAuthConnection"); 71 | #endif 72 | 73 | qmlRegisterUncreatableType(uri, 2, 0, "Reply", QObject::tr("Don't use reply directly")); 74 | qmlRegisterUncreatableType(uri, 2, 0, "ClientBase", QObject::tr("Use SimpleClient instead")); 75 | qmlRegisterUncreatableType(uri, 2, 0, "Roster", QObject::tr("Use client.roster instead")); 76 | qmlRegisterUncreatableType(uri, 2, 0, "Connection", QObject::tr("Use client.connection instead")); 77 | qmlRegisterUncreatableType(uri, 2, 0, "Contact", QObject::tr("Use client.contact(id)")); 78 | qmlRegisterUncreatableType(uri, 2, 0, "Buddy", QObject::tr("User roster.buddy(id)")); 79 | qmlRegisterUncreatableType(uri, 2, 0, "Message", QObject::tr("Only flags")); 80 | qmlRegisterUncreatableType(uri, 2, 0, "LongPoll", QObject::tr("Use client.longPoll instead")); 81 | qmlRegisterUncreatableType(uri, 2, 0, "Attachment", QObject::tr("Attachment enums")); 82 | qmlRegisterUncreatableType(uri, 2, 0, "NewsItem", QObject::tr("NewsItem enums")); 83 | qmlRegisterUncreatableType(uri, 2, 0, "NewsFeed", QObject::tr("NewsFeed enums")); 84 | qmlRegisterUncreatableType(uri, 2, 0, "MessageListModel", QObject::tr("Cannot use this class directly")); 85 | qmlRegisterUncreatableType(uri, 2, 0, "MessageSession", QObject::tr("Cannot use this class directly")); 86 | } 87 | 88 | #endif // VKITQMLPLUGIN_H 89 | 90 | -------------------------------------------------------------------------------- /src/qml/src/vreenplugin.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include "vkitqmlplugin.h" 26 | 27 | class VKitQmlPlugin : public QQmlExtensionPlugin 28 | { 29 | Q_OBJECT 30 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") 31 | public: 32 | void registerTypes(const char *uri) 33 | { 34 | registerVreenTypes(uri); 35 | } 36 | }; 37 | 38 | #include "vreenplugin.moc" 39 | 40 | -------------------------------------------------------------------------------- /src/qml/src/wallmodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef WALLMODEL_H 26 | #define WALLMODEL_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class WallModel : public QAbstractListModel 34 | { 35 | Q_OBJECT 36 | Q_PROPERTY(Vreen::Contact* contact READ contact WRITE setContact NOTIFY contactChanged) 37 | public: 38 | enum Roles { 39 | IdRole = Qt::UserRole, 40 | FromRole, 41 | ToRole, 42 | OwnerRole, 43 | SignerRole, 44 | CopyTextRole, 45 | DateRole, 46 | BodyRole, 47 | CommentsRole, 48 | LikesRole, 49 | RepostsRole, 50 | AttachmentsRole 51 | }; 52 | 53 | explicit WallModel(QObject *parent = 0); 54 | Vreen::Contact* contact() const; 55 | void setContact(Vreen::Contact* arg); 56 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 57 | virtual int rowCount(const QModelIndex &) const; 58 | int count() const; 59 | public slots: 60 | Vreen::Reply *getPosts(int count = 25, int offset = 0, Vreen::WallSession::Filter filter = Vreen::WallSession::All); 61 | void addLike(int postId, bool retweet = false, const QString &message = QString()); 62 | void deleteLike(int postId); 63 | void clear(); 64 | int findPost(int id); 65 | signals: 66 | void contactChanged(Vreen::Contact* arg); 67 | private slots: 68 | void addPost(const Vreen::WallPost &post); 69 | void replacePost(int index, const Vreen::WallPost &post); 70 | void onPostLikeAdded(int id, int likes, int reposts, bool isRetweeted); 71 | void onPostLikeDeleted(int postId, int count); 72 | private: 73 | inline Vreen::Roster *roster() const { return client()->roster(); } 74 | inline Vreen::Client *client() const { return m_contact->client(); } 75 | QPointer m_contact; 76 | QPointer m_session; 77 | Vreen::WallPostList m_posts; 78 | }; 79 | 80 | #endif // WALLMODEL_H 81 | 82 | -------------------------------------------------------------------------------- /tests/auto/LongPoll/tst_longpoll.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "common/utils.h" 32 | 33 | class LongPollTest : public QObject 34 | { 35 | Q_OBJECT 36 | public: 37 | LongPollTest() 38 | { 39 | VREEN_TEST_PREPARE(); 40 | } 41 | private slots: 42 | void testUpdates_data() 43 | { 44 | VREEN_ADD_LOGIN_VARS(); 45 | } 46 | 47 | void testUpdates() 48 | { 49 | VREEN_CREATE_CLIENT(); 50 | 51 | client.longPoll()->setRunning(true); 52 | connect(client.longPoll(), SIGNAL(contactStatusChanged(int,Vreen::Contact::Status)), &loop, SLOT(quit())); 53 | loop.exec(); 54 | } 55 | }; 56 | 57 | QTEST_MAIN(LongPollTest) 58 | 59 | #include "tst_longpoll.moc" 60 | 61 | -------------------------------------------------------------------------------- /tests/auto/Roster/tst_roster.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include 26 | #include 27 | #include 28 | #include "common/utils.h" 29 | #include "roster.h" 30 | #include "contact.h" 31 | 32 | #include 33 | #include 34 | 35 | class RosterTest : public QObject 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | RosterTest() 41 | { 42 | VREEN_TEST_PREPARE(); 43 | } 44 | 45 | private Q_SLOTS: 46 | void testSync_data() 47 | { 48 | VREEN_ADD_LOGIN_VARS(); 49 | } 50 | 51 | void testSync() 52 | { 53 | VREEN_CREATE_CLIENT(); 54 | if (!client.isOnline()) 55 | QFAIL("Client is offline!"); 56 | 57 | Vreen::Roster *roster = client.roster(); 58 | connect(roster, SIGNAL(syncFinished(bool)), &loop, SLOT(quit())); 59 | roster->sync(); 60 | loop.exec(); 61 | 62 | QCOMPARE(roster->buddies().count() > 0, true); 63 | 64 | foreach (Vreen::Contact *contact, roster->buddies()) { 65 | qDebug() << contact->name() << ":" << "\n"; 66 | const QMetaObject *meta = contact->metaObject(); 67 | for (int index = 0; index != meta->propertyCount(); index++) { 68 | QMetaProperty property = meta->property(index); 69 | qDebug() << "Property name: " << property.name() << ". Value: " << property.read(contact); 70 | } 71 | } 72 | } 73 | }; 74 | 75 | QTEST_MAIN(RosterTest) 76 | 77 | #include "tst_roster.moc" 78 | 79 | -------------------------------------------------------------------------------- /tests/auto/connection/tst_connection.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "common/utils.h" 33 | 34 | class ConnectionTest: public QObject 35 | { 36 | Q_OBJECT 37 | public: 38 | ConnectionTest() 39 | { 40 | VREEN_TEST_PREPARE(); 41 | } 42 | private slots: 43 | void testRequest_data() 44 | { 45 | VREEN_ADD_LOGIN_VARS(); 46 | } 47 | 48 | void testRequest() 49 | { 50 | VREEN_CREATE_CLIENT(); 51 | 52 | if (!client.isOnline()) 53 | QFAIL("Client is offline!"); 54 | 55 | Vreen::Reply *reply = client.request("getUserSettings"); 56 | connect(reply, SIGNAL(resultReady(QVariant)), &loop, SLOT(quit())); 57 | loop.exec(); 58 | QCOMPARE(reply->response().toInt() > 6, true); 59 | } 60 | }; 61 | 62 | QTEST_MAIN(ConnectionTest) 63 | 64 | #include "tst_connection.moc" 65 | 66 | -------------------------------------------------------------------------------- /tests/common/utils.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Vreen - vk.com API Qt bindings 4 | ** 5 | ** Copyright © 2012 Aleksey Sidorov 6 | ** 7 | ***************************************************************************** 8 | ** 9 | ** $VREEN_BEGIN_LICENSE$ 10 | ** This program is free software: you can redistribute it and/or modify 11 | ** it under the terms of the GNU Lesser General Public License as published by 12 | ** the Free Software Foundation, either version 3 of the License, or 13 | ** (at your option) any later version. 14 | ** 15 | ** This program is distributed in the hope that it will be useful, 16 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | ** See the GNU Lesser General Public License for more details. 19 | ** 20 | ** You should have received a copy of the GNU General Public License 21 | ** along with this program. If not, see http://www.gnu.org/licenses/. 22 | ** $VREEN_END_LICENSE$ 23 | ** 24 | ****************************************************************************/ 25 | #ifndef UTILS_H 26 | #define UTILS_H 27 | #include "client.h" 28 | #include 29 | #include 30 | #include 31 | 32 | inline QString getVariable(const char *name) 33 | { 34 | return qgetenv(name); 35 | } 36 | 37 | #define VREEN_TEST_PREPARE() \ 38 | qApp->setApplicationName("test"); \ 39 | qApp->setOrganizationName("vreen"); \ 40 | 41 | #define VREEN_ADD_LOGIN_VARS() \ 42 | QTest::addColumn("login"); \ 43 | QTest::addColumn("password"); \ 44 | QTest::newRow("Env") \ 45 | << getVariable("VREEN_LOGIN") \ 46 | << getVariable("VREEN_PASSWORD"); 47 | 48 | //TODO add oauth connection support 49 | 50 | #define VREEN_CREATE_CLIENT() \ 51 | QFETCH(QString, login); \ 52 | QFETCH(QString, password); \ 53 | Vreen::Client client(login, password); \ 54 | auto connection = new Vreen::OAuthConnection(3220807, this); \ 55 | connection->setConnectionOption(Vreen::Connection::ShowAuthDialog, true); \ 56 | connection->setConnectionOption(Vreen::Connection::KeepAuthData, true); \ 57 | client.setConnection(connection); \ 58 | QEventLoop loop; \ 59 | connect(&client, SIGNAL(onlineStateChanged(bool)), &loop, SLOT(quit())); \ 60 | connect(&client, SIGNAL(error(Vreen::Client::Error)), &loop, SLOT(quit())); \ 61 | client.connectToHost(); \ 62 | if (!client.isOnline()) \ 63 | loop.exec(); 64 | 65 | #endif // UTILS_H 66 | 67 | --------------------------------------------------------------------------------