diff --git a/README.md b/README.md index 674f95c..b5eadd0 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ # Kat -The unofficial client for the most popular russian social network shared under the terms of the GNU GPL v3. + +This is an unofficial vk.com client for Jolla Sailfish OS. + +__You can:__ + + Viewing profiles + + Reading news + + Chatting + + Listening to audios __For developers:__ + _master_ branch is for releases - + _dev_ branch is for bug fixes - + _dev-new_ branch is for new features + + _dev_ branch is for development process diff --git a/harbour-kat.pro b/harbour-kat.pro index e0afb84..2ed3c28 100755 --- a/harbour-kat.pro +++ b/harbour-kat.pro @@ -26,13 +26,15 @@ include("vksdk/vksdk.pri") HEADERS += \ src/settingswrapper.h \ src/mediaplayerwrapper.h \ - src/playlistmodel.h + src/playlistmodel.h \ + src/filesaver.h SOURCES += \ src/harbour-kat.cpp \ src/settingswrapper.cpp \ src/mediaplayerwrapper.cpp \ - src/playlistmodel.cpp + src/playlistmodel.cpp \ + src/filesaver.cpp OTHER_FILES += \ qml/harbour-kat.qml \ @@ -42,6 +44,8 @@ OTHER_FILES += \ translations/*.ts \ rpm/harbour-kat.yaml \ rpm/harbour-kat.spec \ + harbour-kat.png\ + harbour-kat.desktop\ rpm/harbour-kat.changes.in \ LICENSE \ README.md @@ -49,7 +53,8 @@ OTHER_FILES += \ CONFIG += sailfishapp_i18n TRANSLATIONS += \ translations/harbour-kat-ru.ts \ - translations/harbour-kat-it.ts + translations/harbour-kat-it.ts \ + translations/harbour-kat-nl.ts DISTFILES += \ qml/pages/MainMenuPage.qml \ @@ -86,5 +91,8 @@ DISTFILES += \ qml/views/WallItem.qml \ qml/pages/RepostPage.qml \ qml/pages/StatisticsPage.qml \ - translations/harbour-kat-it.ts + qml/pages/SettingsPage.qml \ + qml/pages/PhotoAlbumPage.qml \ + qml/pages/TopicsPage.qml \ + qml/pages/TopicPage.qml diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml index cf15a04..600bf32 100755 --- a/qml/cover/CoverPage.qml +++ b/qml/cover/CoverPage.qml @@ -25,6 +25,20 @@ import Sailfish.Silica 1.0 CoverBackground { id: cover + BackgroundItem { + id: background + anchors.fill: parent + Image { + id: bg_image + anchors.fill: parent + width: parent.width + height: parent.height + fillMode: Image.PreserveAspectCrop + source: "/usr/share/icons/hicolor/86x86/apps/harbour-kat.png" + opacity: 0.2 + } + } + Column { anchors.centerIn: parent spacing: Theme.paddingMedium diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml index 7ae2095..538d297 100755 --- a/qml/pages/AboutPage.qml +++ b/qml/pages/AboutPage.qml @@ -47,19 +47,19 @@ Page { anchors.horizontalCenter: parent.horizontalCenter width: Theme.iconSizeExtraLarge height: Theme.iconSizeExtraLarge - source: "../harbour-kat.png" + source: "/usr/share/icons/hicolor/86x86/apps/harbour-kat.png" } Label { width: parent.width horizontalAlignment: Text.AlignHCenter - text: "v0.5.1" + text: "v0.5.3" } Label { width: parent.width horizontalAlignment: Text.AlignHCenter - text: "© 2015-2016 Petr Vytovtov" + text: "© 2015-2017 Petr Vytovtov" } Label { @@ -89,13 +89,23 @@ Page { onClicked: Qt.openUrlExternally("https://github.com/osanwe/Kat") } + Label { + width: parent.width + wrapMode: Text.WordWrap + linkColor: Theme.highlightColor + onLinkActivated: Qt.openUrlExternally(link) + text: qsTr("Thanks for features") + ":
" + + "Alexander Ryzhkov" + } + Label { width: parent.width wrapMode: Text.WordWrap linkColor: Theme.highlightColor onLinkActivated: Qt.openUrlExternally(link) text: qsTr("Localization") + ":
" + - qsTr("Italian") + ": Fra" + qsTr("Italian") + ": Fra
" + + qsTr("Dutch") + ": Richard
" } } diff --git a/qml/pages/DialogPage.qml b/qml/pages/DialogPage.qml index 6f23bc0..d6bf1d3 100755 --- a/qml/pages/DialogPage.qml +++ b/qml/pages/DialogPage.qml @@ -51,6 +51,7 @@ Page { anchors.left: parent.left anchors.right: parent.right + userId: fromId date: datetime isOut: out isRead: read diff --git a/qml/pages/GroupProfilePage.qml b/qml/pages/GroupProfilePage.qml index 5740141..3632505 100755 --- a/qml/pages/GroupProfilePage.qml +++ b/qml/pages/GroupProfilePage.qml @@ -111,23 +111,25 @@ Page { text: qsTr("Photos") counter: group.photosCount visible: group.photosCount !== 0 - } - MoreButton { - width: parent.width - height: Theme.itemSizeMedium - text: qsTr("Audios") - counter: group.audiosCount - visible: group.audiosCount !== 0 + onClicked: pageContainer.push(Qt.resolvedUrl("PhotoAlbumPage.qml"), { ownerId: groupId }) } - MoreButton { - width: parent.width - height: Theme.itemSizeMedium - text: qsTr("Videos") - counter: group.videosCount - visible: group.videosCount !== 0 - } +// MoreButton { +// width: parent.width +// height: Theme.itemSizeMedium +// text: qsTr("Audios") +// counter: group.audiosCount +// visible: group.audiosCount !== 0 +// } + +// MoreButton { +// width: parent.width +// height: Theme.itemSizeMedium +// text: qsTr("Videos") +// counter: group.videosCount +// visible: group.videosCount !== 0 +// } MoreButton { width: parent.width @@ -135,16 +137,18 @@ Page { text: qsTr("Topics") counter: group.topicsCount visible: group.topicsCount !== 0 - } - MoreButton { - width: parent.width - height: Theme.itemSizeMedium - text: qsTr("Documents") - counter: group.docsCount - visible: group.docsCount !== 0 + onClicked: pageContainer.push(Qt.resolvedUrl("TopicsPage.qml"), { ownerId: groupId }) } +// MoreButton { +// width: parent.width +// height: Theme.itemSizeMedium +// text: qsTr("Documents") +// counter: group.docsCount +// visible: group.docsCount !== 0 +// } + MoreButton { id: wallButton width: parent.width diff --git a/qml/pages/ImageViewPage.qml b/qml/pages/ImageViewPage.qml index 1f1f75e..54c485c 100755 --- a/qml/pages/ImageViewPage.qml +++ b/qml/pages/ImageViewPage.qml @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Petr Vytovtov + Copyright (C) 2016-2017 Petr Vytovtov Contact: Petr Vytovtov All rights reserved. @@ -25,55 +25,113 @@ import Sailfish.Silica 1.0 Page { id: imageViewPage + property var ownerIds + property var photoIds property var imagesModel property var current + property bool fromAlbum: false - SilicaListView { - id: flick + Drawer { + id: drawer anchors.fill: parent - anchors.bottomMargin: audioPlayer.open ? audioPlayer.height : 0 - clip: true - snapMode: ListView.SnapOneItem - orientation: ListView.HorizontalFlick - highlightRangeMode: ListView.StrictlyEnforceRange - cacheBuffer: width - - model: ListModel {} - - delegate: Item { - width: flick.width - height: flick.height - clip: true - - Image { - anchors.fill: parent - sourceSize.height: window.height * 2 - fillMode: Image.PreserveAspectFit - source: source_ - - PinchArea { - anchors.fill: parent - pinch.target: parent - pinch.minimumScale: 1 - pinch.maximumScale: 4 + + open: true + + background: SilicaListView { + anchors.fill: parent + + model: ListModel { + + ListElement { title: "Save" } + ListElement { title: "Like" } + ListElement { title: "Share" } + ListElement { title: "Copy link" } + } + + header: PageHeader { + title: (slideshowView.currentIndex + 1) + ' / ' + (fromAlbum ? vksdk.photosModel.count : imagesModel.length) + } + + delegate: ListItem { + + width: parent.width + height: Theme.itemSizeSmall + + Label { + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + width: parent.width - 2 * Theme.horizontalPageMargin + text: model.title } + + onClicked: switch (index) { + case 0: + fileSaver.save(fromAlbum ? vksdk.photosModel.getUrl(slideshowView.currentIndex) : imagesModel[slideshowView.currentIndex]) + break; + case 1: + if (fromAlbum) + vksdk.likes.addPhoto(vksdk.photosModel.getOwnerId(slideshowView.currentIndex), + vksdk.photosModel.getPhotoId(slideshowView.currentIndex)) + else + vksdk.likes.addPhoto(ownerIds[slideshowView.currentIndex], + photoIds[slideshowView.currentIndex]) + break; + case 2: + if (fromAlbum) + pageStack.push(Qt.resolvedUrl("RepostPage.qml"), + { sourceId: vksdk.photosModel.getOwnerId(slideshowView.currentIndex), + postId: vksdk.photosModel.getPhotoId(slideshowView.currentIndex), + type: "photo" }) + else + pageStack.push(Qt.resolvedUrl("RepostPage.qml"), { sourceId: ownerIds[slideshowView.currentIndex], + postId: photoIds[slideshowView.currentIndex], + type: "photo" }) + break; + case 3: + Clipboard.text = imagesModel[slideshowView.currentIndex] + break; + } } } - } - Label { - anchors.top: parent.top - anchors.right: parent.right - anchors.topMargin: Theme.paddingLarge - anchors.rightMargin: Theme.paddingLarge - text: (flick.currentIndex + 1) + ' / ' + imagesModel.length + SlideshowView { + id: slideshowView + width: imageViewPage.width + height: imageViewPage.height + model: fromAlbum ? vksdk.photosModel : imagesModel.length + + delegate: Image { + id: imageView + width: imageViewPage.width + height: width * (sourceSize.height / sourceSize.width) + fillMode: Image.PreserveAspectFit + source: fromAlbum ? photoUrl : imagesModel[index] + + PinchArea { + anchors.fill: parent + pinch.target: parent + pinch.minimumScale: 1 + pinch.maximumScale: 4 + + MouseArea { + anchors.fill: parent + drag.target: imageView + drag.axis: Drag.XAndYAxis + drag.minimumX: (slideshowView.width - imageView.width * imageView.scale) / 2 + drag.minimumY: (slideshowView.height - imageView.height * imageView.scale) / 2 + drag.maximumX: Math.abs(slideshowView.width - imageView.width * imageView.scale) / 2 + drag.maximumY: Math.abs(slideshowView.height - imageView.height * imageView.scale) / 2 + onClicked: drawer.open = !drawer.open + onPositionChanged: { // TODO + console.log(drag.minimumX + " <= " + imageView.x + " <= " + drag.maximumX) + console.log(drag.minimumY + " <= " + imageView.y + " <= " + drag.maximumY) + } + } + } + } + } } -// onStatusChanged: if (status === PageStatus.Active) pageStack.pushAttached(Qt.resolvedUrl("AudioPlayerPage.qml")) - - Component.onCompleted: { - for (var index in imagesModel) flick.model.append({ source_: imagesModel[index] }) - flick.currentIndex = current - } + Component.onCompleted: slideshowView.currentIndex = current } diff --git a/qml/pages/MainMenuPage.qml b/qml/pages/MainMenuPage.qml index ce439e7..08f5035 100755 --- a/qml/pages/MainMenuPage.qml +++ b/qml/pages/MainMenuPage.qml @@ -100,9 +100,10 @@ Page { onClicked: logout() } -// MenuItem { -// text: qsTr("Settings") -// } + MenuItem { + text: qsTr("Settings") + onClicked: pageContainer.push(Qt.resolvedUrl("SettingsPage.qml")) + } } header: PageHeader {} @@ -155,6 +156,18 @@ Page { } } + Timer { + id: onlineTimer + interval: 900000 + repeat: true + triggeredOnStart: false + + onTriggered: { + if (!settings.offlineStatus()) vksdk.account.setOnline() + else stop() + } + } + onStatusChanged: if (status === PageStatus.Active) { // pageStack.pushAttached(Qt.resolvedUrl("AudioPlayerPage.qml")) vksdk.dialogsListModel.clear() @@ -165,6 +178,12 @@ Page { vksdk.wallModel.clear() } - Component.onCompleted: init() + Component.onCompleted: { + if (!settings.offlineStatus()) { + vksdk.account.setOnline() + onlineTimer.start() + } + init() + } } diff --git a/qml/pages/PhotoAlbumPage.qml b/qml/pages/PhotoAlbumPage.qml new file mode 100644 index 0000000..aabcbe4 --- /dev/null +++ b/qml/pages/PhotoAlbumPage.qml @@ -0,0 +1,112 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +Page { + id: photoAlbumPage + + property var ownerId + property int album: 0 + + ComboBox { + id: albumChooser + anchors.top: parent.top + width: parent.width + label: qsTr("Album:") + + menu: ContextMenu { + + MenuItem { + text: qsTr("All photos") + onClicked: { + album = 0 + vksdk.photosModel.clear() + vksdk.photos.getAll(ownerId) + } + } + + Repeater { + id: albumsList + model: ListModel {} + delegate: MenuItem { + text: albumTitle + onClicked: { + album = albumId + vksdk.photosModel.clear() + vksdk.photos.get(ownerId, albumId) + } + } + } + } + + Rectangle { + anchors.fill: parent + z: -1 + gradient: Gradient { + + GradientStop { + position: 0.0 + color: Theme.rgba(Theme.highlightBackgroundColor, 0.15) + } + + GradientStop { + position: 1.0 + color: "transparent" + } + } + } + } + + SilicaGridView { + anchors.fill: parent + anchors.topMargin: albumChooser.height + clip: true + model: vksdk.photosModel + + cellWidth: width / 3 + cellHeight: cellWidth + + delegate: Image { + width: parent.width / 3 + height: width + fillMode: Image.PreserveAspectCrop + source: photoUrl + + MouseArea { + anchors.fill: parent + onClicked: { + pageStack.push(Qt.resolvedUrl("../pages/ImageViewPage.qml"), { current: index, + fromAlbum: true }) + } + } + } + + PushUpMenu { + visible: vksdk.photosModel.size !== vksdk.photosModel.count + + MenuItem { + text: qsTr("Load more") + onClicked: if (album === 0) vksdk.photos.getAll(ownerId, vksdk.photosModel.size) + else vksdk.photos.get(ownerId, album, vksdk.photosModel.size) + } + } + + VerticalScrollDecorator {} + } + + Connections { + target: vksdk + onGotPhotoAlbums: { + var id + for (var index in data) { + if (index % 2 === 0) id = data[index] + else albumsList.model.append({ albumId: id, albumTitle: data[index] }) + } + } + } + + Component.onCompleted: { + vksdk.photosModel.clear() + vksdk.photos.getAlbums(ownerId) + vksdk.photos.getAll(ownerId) + } +} diff --git a/qml/pages/ProfilePage.qml b/qml/pages/ProfilePage.qml index 8d66f28..65f102f 100755 --- a/qml/pages/ProfilePage.qml +++ b/qml/pages/ProfilePage.qml @@ -29,6 +29,7 @@ Page { property var profileId property var profile + property bool isBanned: false ViewPlaceholder { id: systemMessage @@ -48,10 +49,14 @@ Page { onClicked: Qt.openUrlExternally("https://m.vk.com/" + profile.domain) } -// MenuItem { -// text: profile.blacklisted ? qsTr("Remove from blacklist") : qsTr("Add to blacklist") -// onClicked: console.log("...banning...") -// } + MenuItem { + text: isBanned ? qsTr("Remove from blacklist") : qsTr("Add to blacklist") + visible: profileId !== settings.userId() + onClicked: { + if (isBanned) vksdk.account.unbanUser(profileId) + else vksdk.account.banUser(profileId) + } + } // MenuItem { // text: profile.isFavorite ? qsTr("Remove from favorites") : qsTr("Add to favorites") @@ -92,7 +97,7 @@ Page { if (!profile.online) { var date = new Date(profile.lastSeenTime * 1000) var day = "0" + date.getDate() - var month = "0" + date.getMonth() + var month = "0" + (date.getMonth() + 1) var year = date.getFullYear() var hours = "0" + date.getHours() var minutes = "0" + date.getMinutes() @@ -122,7 +127,13 @@ Page { platform = "Web" break; } - return qsTr("Last seen: ") + datetime + " (" + platform + ")" + switch(Qt.locale().name.substring(0,2)) { + case "ru": + return ((profile.sex === 1)? qsTr("Last seen female: "):qsTr("Last seen: ")) + datetime + " (" + platform + ")" + default: + return qsTr("Last seen: ") + datetime + " (" + platform + ")" + } + } else return "" } @@ -216,6 +227,8 @@ Page { text: qsTr("Photos") counter: profile.counterPhotos visible: profile.counterPhotos > 0 + + onClicked: pageContainer.push(Qt.resolvedUrl("PhotoAlbumPage.qml"), { ownerId: profile.id }) } MoreButton { @@ -303,6 +316,7 @@ Page { onGotProfile: { if (profileId === user.id) { profile = user + isBanned = user.blacklisted if (profile.deactivated.length > 0) { userDataView.visible = false systemMessage.enabled = true @@ -311,6 +325,7 @@ Page { } } } + onBanSettingChanged: isBanned = banned } onStatusChanged: { diff --git a/qml/pages/RepostPage.qml b/qml/pages/RepostPage.qml index 295853d..7f10c7f 100644 --- a/qml/pages/RepostPage.qml +++ b/qml/pages/RepostPage.qml @@ -3,6 +3,7 @@ import Sailfish.Silica 1.0 Dialog { + property string type: "wall" property int sourceId: 0 property int postId: 0 @@ -25,6 +26,6 @@ Dialog { } onAccepted: { - vksdk.wall.repost(sourceId, postId, repostComment.text) + vksdk.wall.repost(type, sourceId, postId, repostComment.text) } } diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml new file mode 100644 index 0000000..70db0f9 --- /dev/null +++ b/qml/pages/SettingsPage.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +Page { + + SilicaFlickable { + anchors.fill: parent + contentHeight: content.height + + Column { + id: content + width: parent.width + + PageHeader { + title: qsTr("Settings") + } + + TextSwitch { + id: isOffile + checked: settings.offlineStatus() + text: qsTr("Be offline if possible") + description: qsTr("Your status will be online only if you publish something on the wall or in the group.") + + onCheckedChanged: settings.setOfflineStatus(checked) + } + } + } +} diff --git a/qml/pages/TopicPage.qml b/qml/pages/TopicPage.qml new file mode 100644 index 0000000..2d98a71 --- /dev/null +++ b/qml/pages/TopicPage.qml @@ -0,0 +1,83 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +Page { + + property int ownerId + property int topicId + property bool isClosed + property string _title + + SilicaListView { + id: topicMessagesList + anchors.fill: parent + anchors.bottomMargin: newCommentField.height + clip: true + + header: PageHeader { title: _title } + + model: vksdk.commentsModel + + delegate: Item { + width: parent.width + height: childrenRect.height + Theme.paddingMedium + + Image { + id: commentAvatar + anchors.top: parent.top + anchors.left: parent.left + anchors.topMargin: Theme.paddingSmall + anchors.leftMargin: Theme.horizontalPageMargin + width: Theme.iconSizeMedium + height: Theme.iconSizeMedium + source: avatarSource + } + + Label { + anchors.top: parent.top + anchors.left: commentAvatar.right + anchors.right: parent.right + anchors.topMargin: Theme.paddingSmall + anchors.leftMargin: Theme.paddingMedium + anchors.rightMargin: Theme.horizontalPageMargin + wrapMode: Text.WordWrap + text: commentText + } + + Component.onCompleted: + if (index == vksdk.commentsModel.size-1) + vksdk.board.getComments(ownerId, topicId, vksdk.commentsModel.size) + } + + VerticalScrollDecorator {} + } + + TextField { + id: newCommentField + anchors.bottom: parent.bottom + width: parent.width + placeholderText: qsTr("Your comment") + label: qsTr("Your comment") + visible: !isClosed + + EnterKey.enabled: text.length > 0 + EnterKey.iconSource: "image://theme/icon-m-enter-accept" + EnterKey.onClicked: { + vksdk.board.createComment(ownerId, topicId, text) + text = "" + } + } + + Connections { + target: vksdk + onCommentCreated: { + vksdk.commentsModel.clear() + vksdk.board.getComments(ownerId, topicId) + } + } + + Component.onCompleted: { + vksdk.commentsModel.clear() + vksdk.board.getComments(ownerId, topicId) + } +} diff --git a/qml/pages/TopicsPage.qml b/qml/pages/TopicsPage.qml new file mode 100644 index 0000000..3c34775 --- /dev/null +++ b/qml/pages/TopicsPage.qml @@ -0,0 +1,50 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +Page { + + property int ownerId + + SilicaListView { + id: topicsList + anchors.fill: parent + + header: PageHeader { title: qsTr("Topics") } + + model: ListModel {} + + delegate: BackgroundItem { + width: parent.width + height: Theme.itemSizeSmall + + Label { + anchors.centerIn: parent + width: parent.width - 2 * Theme.horizontalPageMargin + height: Theme.itemSizeSmall + verticalAlignment: Text.AlignVCenter + text: title + color: highlighted ? Theme.highlightColor : Theme.primaryColor + truncationMode: TruncationMode.Fade + } + + onClicked: pageContainer.push(Qt.resolvedUrl("TopicPage.qml"), { ownerId: ownerId, + topicId: id_, + isClosed: isClosed, + _title: title }) + } + + VerticalScrollDecorator {} + } + + Connections { + target: vksdk + onGotTopics: { +// topicsList.model.clear() + for (var index in topics) { + topicsList.model.append({ id_: ids[index], title: topics[index], isClosed: closed[index] }) + } + } + } + + Component.onCompleted: vksdk.board.getTopics(ownerId) +} diff --git a/qml/pages/WallPostPage.qml b/qml/pages/WallPostPage.qml index 4fd8320..3bbfb4b 100755 --- a/qml/pages/WallPostPage.qml +++ b/qml/pages/WallPostPage.qml @@ -48,8 +48,8 @@ Page { MenuItem { text: qsTr("Like") onClicked: { - var sourceId = wallpost.sourceId === 0 ? wallpost.fromId : wallpost.sourceId - vksdk.likes.addPost(sourceId, wallpost.id) +// var sourceId = wallpost.sourceId === 0 ? wallpost.fromId : wallpost.sourceId + vksdk.likes.addPost(wallpost.toId, wallpost.id) } } } @@ -120,8 +120,8 @@ Page { EnterKey.enabled: text.length > 0 EnterKey.iconSource: "image://theme/icon-m-enter-accept" EnterKey.onClicked: { - var sourceId = wallpost.sourceId === 0 ? wallpost.fromId : wallpost.sourceId - vksdk.wall.createComment(sourceId, wallpost.id, text) +// var sourceId = wallpost.sourceId === 0 ? wallpost.fromId : wallpost.sourceId + vksdk.wall.createComment(wallpost.toId, wallpost.id, text) text = "" } } @@ -134,15 +134,15 @@ Page { target: vksdk onCommentCreated: { vksdk.commentsModel.clear() - var sourceId = wallpost.sourceId === 0 ? wallpost.fromId : wallpost.sourceId - vksdk.wall.getComments(sourceId, wallpost.id) +// var sourceId = wallpost.toId === 0 ? wallpost.fromId : wallpost.toId + vksdk.wall.getComments(wallpost.toId, wallpost.id) } } onStatusChanged: if (status === PageStatus.Active) { vksdk.commentsModel.clear() - var sourceId = wallpost.sourceId === 0 ? wallpost.fromId : wallpost.sourceId - vksdk.wall.getComments(sourceId, wallpost.id) +// var sourceId = wallpost.sourceId === 0 ? wallpost.fromId : wallpost.sourceId + vksdk.wall.getComments(wallpost.toId, wallpost.id) // pageStack.pushAttached(Qt.resolvedUrl("AudioPlayerPage.qml")) } } diff --git a/qml/views/MessageItem.qml b/qml/views/MessageItem.qml index b6ba185..87d7918 100755 --- a/qml/views/MessageItem.qml +++ b/qml/views/MessageItem.qml @@ -25,6 +25,7 @@ import Sailfish.Silica 1.0 Item { id: messageItem + property var userId property var date property var isOut property var isRead @@ -65,6 +66,11 @@ Item { width: Theme.iconSizeMedium height: Theme.iconSizeMedium LayoutMirroring.enabled: isOut + + MouseArea { + anchors.fill: parent + onClicked: pageContainer.push(Qt.resolvedUrl("../pages/ProfilePage.qml"), { profileId: userId }) + } } Column { diff --git a/qml/views/PhotosView.qml b/qml/views/PhotosView.qml index d98903e..bd74a87 100755 --- a/qml/views/PhotosView.qml +++ b/qml/views/PhotosView.qml @@ -33,19 +33,26 @@ Item { model: photos.length Image { - width: photos.length === 1 ? maximumWidth : maximumWidth / 2 - height: photos.length === 1 ? maximumWidth : maximumWidth / 2 - fillMode: Image.PreserveAspectCrop + width: calculateWidth(index, sourceSize.width, sourceSize.height) + height: width * (sourceSize.height / sourceSize.width) + fillMode: index === 0 ? Image.PreserveAspectFit : Image.PreserveAspectCrop source: photos[index].photoMaximum -// source: photos[index].photoMinimum MouseArea { anchors.fill: parent onClicked: { var sources = [] - for (var idx in photos) sources[idx] = photos[idx].photoMaximum + var owners = [] + var ids = [] + for (var idx in photos) { + sources[idx] = photos[idx].photoMaximum + owners[idx] = photos[idx].ownerId + ids[idx] = photos[idx].id + } pageStack.push(Qt.resolvedUrl("../pages/ImageViewPage.qml"), { current: index, - imagesModel: sources }) + imagesModel: sources, + ownerIds: owners, + photoIds: ids }) } } @@ -53,5 +60,25 @@ Item { } } } + + function calculateWidth(index, w, h) { + if (photos.length === 1) return maximumWidth + else { + if (photos.length === 2 || photos.length === 4) return maximumWidth / 2 + if (photos.length === 3 || photos.length === 6 || photos.length === 9) return maximumWidth / 3 + if (photos.length === 5) + if (index === 0 || index === 1) return maximumWidth / 2 + else return maximumWidth / 3 + if (photos.length === 7) + if (index === 0 || index === 1 || index === 2 || index === 3) return maximumWidth / 2 + else return maximumWidth / 3 + if (photos.length === 8) + if (index === 0 || index === 1) return maximumWidth / 2 + else return maximumWidth / 3 + if (photos.length === 10) + if (index === 0 || index === 1 || index === 2 || index === 3) return maximumWidth / 2 + else return maximumWidth / 3 + } + } } diff --git a/rpm/harbour-kat.spec b/rpm/harbour-kat.spec index e6330ad..ef3e802 100755 --- a/rpm/harbour-kat.spec +++ b/rpm/harbour-kat.spec @@ -13,8 +13,8 @@ Name: harbour-kat %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: The unofficial client for vk.com -Version: 0.5.1 -Release: 34 +Version: 0.5.3 +Release: 36 Group: Qt/Qt License: GNU GPLv3 URL: https://vk.com/kat_sailfishos @@ -52,6 +52,7 @@ The unofficial client for the most popular social network developed by Linux Use rm -rf %{buildroot} # >> install pre # << install pre + %qmake5_install # >> install post diff --git a/rpm/harbour-kat.yaml b/rpm/harbour-kat.yaml index d33aff1..530e331 100755 --- a/rpm/harbour-kat.yaml +++ b/rpm/harbour-kat.yaml @@ -1,7 +1,7 @@ Name: harbour-kat Summary: The unofficial client for vk.com -Version: 0.5.1 -Release: 34 +Version: 0.5.3 +Release: 36 # The contents of the Group field should be one of the groups listed here: # http://gitorious.org/meego-developer-tools/spectacle/blobs/master/data/GROUPS Group: Qt/Qt diff --git a/src/filesaver.cpp b/src/filesaver.cpp new file mode 100644 index 0000000..4e97b8b --- /dev/null +++ b/src/filesaver.cpp @@ -0,0 +1,24 @@ +#include "filesaver.h" + +FileSaver::FileSaver(QObject *parent) : QObject(parent) { + _manager = new QNetworkAccessManager(this); + connect(_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*))); +} + +FileSaver::~FileSaver() { + delete _manager; + _manager = NULL; +} + +void FileSaver::save(QString url) { + _manager->get(QNetworkRequest(QUrl(url))); +} + +void FileSaver::finished(QNetworkReply *reply) { + QFile *file = new QFile(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + reply->url().fileName()); + if (file->open(QIODevice::WriteOnly)) { + file->write(reply->readAll()); + file->close(); + } + reply->deleteLater(); +} diff --git a/src/filesaver.h b/src/filesaver.h new file mode 100644 index 0000000..aab16a2 --- /dev/null +++ b/src/filesaver.h @@ -0,0 +1,30 @@ +#ifndef FILESAVER_H +#define FILESAVER_H + +#include +#include +#include +#include +#include +#include + +#include + +class FileSaver : public QObject +{ + Q_OBJECT + +public: + explicit FileSaver(QObject *parent = 0); + ~FileSaver(); + + Q_INVOKABLE void save(QString url); + +public slots: + void finished(QNetworkReply *reply); + +private: + QNetworkAccessManager *_manager; +}; + +#endif // FILESAVER_H diff --git a/src/harbour-kat.cpp b/src/harbour-kat.cpp index 7768709..461f8b8 100755 --- a/src/harbour-kat.cpp +++ b/src/harbour-kat.cpp @@ -30,6 +30,7 @@ #include +#include "filesaver.h" #include "mediaplayerwrapper.h" #include "settingswrapper.h" #include "vksdk/src/vksdk.h" @@ -38,6 +39,9 @@ int main(int argc, char *argv[]) { QScopedPointer application(SailfishApp::application(argc, argv)); QScopedPointer view(SailfishApp::createView()); + QScopedPointer fileSaver(new FileSaver(view.data())); + view->rootContext()->setContextProperty("fileSaver", fileSaver.data()); + QScopedPointer player(new MediaPlayerWrapper(view.data())); view->rootContext()->setContextProperty("player", player.data()); diff --git a/src/settingswrapper.cpp b/src/settingswrapper.cpp index 5c196cb..0ec1529 100755 --- a/src/settingswrapper.cpp +++ b/src/settingswrapper.cpp @@ -69,3 +69,11 @@ void SettingsWrapper::removeAccessToken() { void SettingsWrapper::removeUserId() { _settings->remove(USER_ID_KEY); } + +void SettingsWrapper::setOfflineStatus(bool offline) { + _settings->setValue(OFFLINE_STATUS_KEY, offline); +} + +bool SettingsWrapper::offlineStatus() { + return _settings->value(OFFLINE_STATUS_KEY).toBool(); +} diff --git a/src/settingswrapper.h b/src/settingswrapper.h index 0ca9d08..8c12bb9 100755 --- a/src/settingswrapper.h +++ b/src/settingswrapper.h @@ -26,6 +26,8 @@ #include #include +#include + class SettingsWrapper : public QObject { Q_OBJECT @@ -47,6 +49,9 @@ class SettingsWrapper : public QObject Q_INVOKABLE void removeAccessToken(); Q_INVOKABLE void removeUserId(); + Q_INVOKABLE void setOfflineStatus(bool offline); + Q_INVOKABLE bool offlineStatus(); + private: QSettings *_settings; @@ -54,6 +59,8 @@ class SettingsWrapper : public QObject const QString USER_ID_KEY = "userId"; const QString DEFAULT_PAGE_KEY = "defaultPage"; const QString ATTACHMENTS_HINT = "attachmentsHint"; + + const QString OFFLINE_STATUS_KEY = "offlineStatus"; }; #endif // SETTINGSWRAPPER_H diff --git a/translations/harbour-kat-it.ts b/translations/harbour-kat-it.ts index b03dcaf..a6df53b 100644 --- a/translations/harbour-kat-it.ts +++ b/translations/harbour-kat-it.ts @@ -25,14 +25,24 @@ + Thanks for features + + + + Localization - + Italian + + + Dutch + + Donate @@ -143,18 +153,18 @@ DialogPage - + typing... - + Your message Messaggio - + Photo Foto @@ -210,32 +220,17 @@ Foto - - Audios - Audio - - - - Videos - Video - - - + Topics - - Documents - - - - + Wall - + Load more @@ -293,6 +288,11 @@ Logout Logout + + + Settings + + NewsView @@ -310,70 +310,104 @@ Bacheca + + PhotoAlbumPage + + + Load more + + + + + Album: + + + + + All photos + + + ProfilePage - + Open in browser - + + Remove from blacklist + + + + + Add to blacklist + + + + + Last seen female: + + + + + Last seen: - + Photos Foto - + Videos Video - + Audios Audio - + Groups Gruppi - + Wall - + Load more - + The user is deleted - + The user is baned - + Friends Amici - + Notes Note - + Go to dialog Vai alla conversazione @@ -381,16 +415,34 @@ RepostPage - + Share - + Cancel + + SettingsPage + + + Settings + + + + + Be offline if possible + + + + + Your status will be online only if you publish something on the wall or in the group. + + + StatisticsPage @@ -419,6 +471,23 @@ + + TopicPage + + + + Your comment + + + + + TopicsPage + + + Topics + + + VideoPlayerPage diff --git a/translations/harbour-kat-nl.ts b/translations/harbour-kat-nl.ts new file mode 100644 index 0000000..e33abf2 --- /dev/null +++ b/translations/harbour-kat-nl.ts @@ -0,0 +1,536 @@ + + + + + AboutPage + + + About + Over + + + + The unofficial client for vk.com, distributed under the terms of the GNU GPLv3. + De onofficiële client voor vk.com, gedistribueerd onder de GNU GPLv3 voorwaarden. + + + + Homepage + Startpagina + + + + Source code + Broncode + + + + Thanks for features + + + + + Localization + Lokalisatie + + + + Italian + Italiaans + + + + Dutch + + + + + Donate + Doneren + + + + AudioPlayerPage + + + Search audio... + Audio zoeken ... + + + + My audios + Mijn audio + + + + CollapsedView + + + Birthday: + Verjaardag: + + + + Single + Alleenstaand + + + + In a relationship + In een relatie + + + + Engaged + Verloofd + + + + Married + Getrouwd + + + + It's complicated + Het is gecompliceerd + + + + Actively searching + Actief zoekend + + + + In love + Verliefd + + + + City: + Stad: + + + + Country: + Land: + + + + Home town: + Geboortestad: + + + + Mobile phone: + Mobiele telefoon: + + + + Home phone: + Huis Telefoon + + + + Site: + Gebied: + + + + Gender: + Geslacht: + + + + Female + Vrouw + + + + Male + Man + + + + DialogPage + + + typing... + aan het typen... + + + + + Your message + Je bericht + + + + Photo + Foto + + + + DialogsListPage + + + Dialogs + Gesprekken + + + + FriendsListPage + + + Friends + Vrienden + + + + + Online friends + Vrienden online + + + + + Mutual friends + Gemeenschappelijke vrienden + + + + All friends + Alle vrienden + + + + GroupProfilePage + + + View stats + Statistieken bekijken + + + + Members + Leden + + + + Photos + Foto's + + + + Topics + Onderwerpen + + + + Wall + Prikbord + + + + Load more + Laad meer + + + + GroupsListPage + + + Groups + Groepen + + + + LoginPage + + + Logged to vk.com with Kat + Ingelogd op vk.com met Kat + + + + MainMenuPage + + + My profile + Mijn profiel + + + + News + Nieuws + + + + Messages + Berichten + + + + Friends + Vrienden + + + + Groups + Groepen + + + + About + Over + + + + Logout + Uitloggen + + + + Settings + + + + + NewsView + + + [Wall post] + [Prikbordbericht] + + + + NewsfeedPage + + + Newsfeed + Nieuwsfeed + + + + PhotoAlbumPage + + + Load more + Laad meer + + + + Album: + + + + + All photos + + + + + ProfilePage + + + Photos + Foto's + + + + Videos + Videos + + + + Notes + Aantekeningen + + + + Open in browser + Openen in browser + + + + The user is baned + De gebruiker is verbannen + + + + Go to dialog + Ga naar gesprekken + + + + Remove from blacklist + + + + + Add to blacklist + + + + + + Last seen: + Laatst gezien: + + + + Last seen female: + + + + + Friends + Vrienden + + + + Audios + Audio + + + + Groups + Groepen + + + + Wall + Prikbord + + + + The user is deleted + De gebruiker is verwijderd + + + + Load more + Laad meer + + + + RepostPage + + + Share + Delen + + + + Cancel + Annuleren + + + + SettingsPage + + + Settings + + + + + Be offline if possible + + + + + Your status will be online only if you publish something on the wall or in the group. + + + + + StatisticsPage + + + Statistics + Statistieken + + + + Date from: + Datum vanaf: + + + + Date to: + Datum tot: + + + + Total views + Totaal aantal keer bekeken + + + + Uniqual visitors + Unieke bezoekers + + + + TopicPage + + + + Your comment + Jouw commentaar + + + + TopicsPage + + + Topics + Onderwerpen + + + + VideoPlayerPage + + + The video is loading... + De video wordt geladen... + + + + The video is opened in a browser + De video wordt geopenend in een browser + + + + WallItem + + + Like + Like + + + + Share + Delen + + + + WallPostPage + + + Share + Delen + + + + Like + Like + + + + + Your comment + Jouw commentaar + + + diff --git a/translations/harbour-kat-ru.ts b/translations/harbour-kat-ru.ts index b580d23..7b68724 100755 --- a/translations/harbour-kat-ru.ts +++ b/translations/harbour-kat-ru.ts @@ -25,14 +25,24 @@ + Thanks for features + Спасибо за участие: + + + Localization Локализация - + Italian Итальянский + + + Dutch + Голландский + Donate @@ -143,18 +153,18 @@ DialogPage - + typing... набирает... - + Your message Ваше сообщение - + Photo Фотография @@ -210,32 +220,17 @@ Фотографии - - Audios - Аудиозаписи - - - - Videos - Видеозаписи - - - + Topics Обсуждения - - Documents - Документы - - - + Wall Стена - + Load more Загрузить больше @@ -293,6 +288,11 @@ Logout Выйти + + + Settings + Настройки + NewsView @@ -310,70 +310,104 @@ Новости + + PhotoAlbumPage + + + Load more + Загрузить больше + + + + Album: + Альбом: + + + + All photos + Все фотографии + + ProfilePage - + Photos Фотографии - + Videos Видеозаписи - + Notes Заметки - + Open in browser Открыть в браузере - + The user is baned Пользователь заблокирован - + Go to dialog Перейти к диалогу - + + Remove from blacklist + Убрать из чёрного списка + + + + Add to blacklist + Добавить в чёрный список + + + + Last seen female: + Была в сети: + + + + Last seen: - Был в сети: + Был в сети: - + Friends Друзья - + Audios Аудиозаписи - + Groups Сообщества - + Wall Стена - + The user is deleted Пользователь удалён - + Load more Загрузить больше @@ -381,16 +415,34 @@ RepostPage - + Share Поделиться - + Cancel Отменить + + SettingsPage + + + Settings + Настройки + + + + Be offline if possible + По возможности быть offline + + + + Your status will be online only if you publish something on the wall or in the group. + Вы будете offline пока не опубликуете что-нибудь на стене или в группе. + + StatisticsPage @@ -419,6 +471,23 @@ Уникальных посетителей + + TopicPage + + + + Your comment + Ваш комментарий + + + + TopicsPage + + + Topics + Обсуждения + + VideoPlayerPage diff --git a/translations/harbour-kat.ts b/translations/harbour-kat.ts index 82a8002..80eb06e 100755 --- a/translations/harbour-kat.ts +++ b/translations/harbour-kat.ts @@ -25,14 +25,24 @@ + Thanks for features + + + + Localization - + Italian + + + Dutch + + Donate @@ -143,18 +153,18 @@ DialogPage - + typing... - + Your message - + Photo @@ -210,32 +220,17 @@ - - Audios - - - - - Videos - - - - + Topics - - Documents - - - - + Wall - + Load more @@ -293,6 +288,11 @@ Logout + + + Settings + + NewsView @@ -310,70 +310,104 @@ + + PhotoAlbumPage + + + Load more + + + + + Album: + + + + + All photos + + + ProfilePage - + Photos - + Videos - + Notes - + Open in browser - + The user is baned - + Go to dialog - + + Remove from blacklist + + + + + Add to blacklist + + + + + Last seen female: + + + + + Last seen: - + Friends - + Audios - + Groups - + Wall - + The user is deleted - + Load more @@ -381,16 +415,34 @@ RepostPage - + Share - + Cancel + + SettingsPage + + + Settings + + + + + Be offline if possible + + + + + Your status will be online only if you publish something on the wall or in the group. + + + StatisticsPage @@ -419,6 +471,23 @@ + + TopicPage + + + + Your comment + + + + + TopicsPage + + + Topics + + + VideoPlayerPage diff --git a/vksdk/src/models/commentsmodel.cpp b/vksdk/src/models/commentsmodel.cpp index e857bd1..b6d2b3a 100644 --- a/vksdk/src/models/commentsmodel.cpp +++ b/vksdk/src/models/commentsmodel.cpp @@ -80,6 +80,10 @@ void CommentsModel::addUser(User *user) { emit dataChanged(startIndex, endIndex); } +int CommentsModel::size() const { + return _comments.size(); +} + QString CommentsModel::_getAvatarSource(const int id) const { if (id > 0) { if (_profiles.contains(id)) return _profiles[id]->getPhoto50(); diff --git a/vksdk/src/models/commentsmodel.h b/vksdk/src/models/commentsmodel.h index 61dce10..e238792 100644 --- a/vksdk/src/models/commentsmodel.h +++ b/vksdk/src/models/commentsmodel.h @@ -13,6 +13,8 @@ class CommentsModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(int size READ size CONSTANT) + public: enum Roles { AvatarRole = Qt::UserRole + 1, @@ -33,6 +35,8 @@ class CommentsModel : public QAbstractListModel Q_INVOKABLE void addGroup(Group *group); Q_INVOKABLE void addUser(User *user); + int size() const; + private: QList _comments; QHash _profiles; diff --git a/vksdk/src/models/messagesmodel.cpp b/vksdk/src/models/messagesmodel.cpp index 6cf9f67..e3f7cb6 100755 --- a/vksdk/src/models/messagesmodel.cpp +++ b/vksdk/src/models/messagesmodel.cpp @@ -42,6 +42,9 @@ QVariant MessagesModel::data(const QModelIndex &index, int role) const { case IdRole: return QVariant(message->id()); + case FromIdRole: + return QVariant(message->fromId()); + case DateRole: return QVariant(message->date()); @@ -90,6 +93,7 @@ QHash MessagesModel::roleNames() const { QHash roles = QAbstractListModel::roleNames(); roles[AvatarRole] = "avatar"; roles[IdRole] = "id"; + roles[FromIdRole] = "fromId"; roles[DateRole] = "datetime"; roles[IsOutRole] = "out"; roles[IsReadRole] = "read"; diff --git a/vksdk/src/models/messagesmodel.h b/vksdk/src/models/messagesmodel.h index 40be126..ae99c0d 100755 --- a/vksdk/src/models/messagesmodel.h +++ b/vksdk/src/models/messagesmodel.h @@ -38,6 +38,7 @@ class MessagesModel : public QAbstractListModel enum Roles { AvatarRole = Qt::UserRole + 1, IdRole, + FromIdRole, DateRole, IsOutRole, IsReadRole, diff --git a/vksdk/src/models/photosmodel.cpp b/vksdk/src/models/photosmodel.cpp new file mode 100644 index 0000000..c3cd74c --- /dev/null +++ b/vksdk/src/models/photosmodel.cpp @@ -0,0 +1,76 @@ +#include "photosmodel.h" + +PhotosModel::PhotosModel(QObject *parent) : QAbstractListModel(parent) +{} + +int PhotosModel::rowCount(const QModelIndex &parent) const { + if (parent.isValid()) return 0; + return _photos.size(); +} + +QVariant PhotosModel::data(const QModelIndex &index, int role) const { + if (!index.isValid()) return QVariant(); + + switch (role) { + case IdRole: + return QVariant(_photos.at(index.row())->id()); + case AlbumIdRole: + return QVariant(_photos.at(index.row())->albumId()); + case OwnerIdRole: + return QVariant(_photos.at(index.row())->ownerId()); + case UrlRole: + return QVariant(_photos.at(index.row())->photoMaximum()); + default: + return QVariant(); + } +} + +QHash PhotosModel::roleNames() const { + QHash roles = QAbstractListModel::roleNames(); + roles[IdRole] = "photoId"; + roles[AlbumIdRole] = "photoAlbumId"; + roles[OwnerIdRole] = "photoOwnerId"; + roles[UrlRole] = "photoUrl"; + return roles; +} + +void PhotosModel::clear() { + beginRemoveRows(QModelIndex(), 0, _photos.size()); + _photos.clear(); + endRemoveRows(); + QModelIndex index = createIndex(0, 0, static_cast(0)); + emit dataChanged(index, index); +} + +void PhotosModel::addPhoto(Photo *photo) { + beginInsertRows(QModelIndex(), _photos.size(), _photos.size()); + _photos.append(photo); + endInsertRows(); + + QModelIndex index = createIndex(0, 0, static_cast(0)); + emit dataChanged(index, index); +} + +int PhotosModel::getPhotoId(int index) { + return _photos.at(index)->id(); +} + +int PhotosModel::getOwnerId(int index) { + return _photos.at(index)->ownerId(); +} + +QString PhotosModel::getUrl(int index) { + return _photos.at(index)->photoMaximum(); +} + +int PhotosModel::size() const { + return _photos.size(); +} + +int PhotosModel::count() const { + return _count; +} + +void PhotosModel::setCount(int count) { + _count = count; +} diff --git a/vksdk/src/models/photosmodel.h b/vksdk/src/models/photosmodel.h new file mode 100644 index 0000000..21fd03f --- /dev/null +++ b/vksdk/src/models/photosmodel.h @@ -0,0 +1,46 @@ +#ifndef PHOTOSMODEL_H +#define PHOTOSMODEL_H + + +#include + +#include "../objects/photo.h" + + +class PhotosModel : public QAbstractListModel +{ + Q_OBJECT + + Q_PROPERTY(int count READ count CONSTANT) + Q_PROPERTY(int size READ size CONSTANT) + +public: + enum Roles { + IdRole = Qt::UserRole + 1, + AlbumIdRole, + OwnerIdRole, + UrlRole, + }; + + PhotosModel(QObject *parent = 0); + + virtual int rowCount(const QModelIndex &parent) const; + virtual QVariant data(const QModelIndex &index, int role) const; + virtual QHash roleNames() const; + + Q_INVOKABLE void clear(); + Q_INVOKABLE void addPhoto(Photo *photo); + Q_INVOKABLE int getPhotoId(int index); + Q_INVOKABLE int getOwnerId(int index); + Q_INVOKABLE QString getUrl(int index); + + int size() const; + int count() const; + void setCount(int count); + +private: + QList _photos; + int _count; +}; + +#endif // PHOTOSMODEL_H diff --git a/vksdk/src/objects/news.cpp b/vksdk/src/objects/news.cpp index 2a37395..757ac8b 100755 --- a/vksdk/src/objects/news.cpp +++ b/vksdk/src/objects/news.cpp @@ -43,7 +43,8 @@ News *News::fromJsonObject(QJsonObject object) { if (object.contains("post_id")) news->setId(object.value("post_id").toInt()); if (object.contains("id")) news->setId(object.value("id").toInt()); if (object.contains("source_id")) news->setSourceId(object.value("source_id").toInt()); - if (object.contains("to_id")) news->setSourceId(object.value("to_id").toInt()); +// if (object.contains("to_id")) news->setToId(object.value("to_id").toInt()); + if (object.contains("owner_id")) news->setToId(object.value("owner_id").toInt()); if (object.contains("from_id")) news->setFromId(object.value("from_id").toInt()); if (object.contains("date")) news->setDate(object.value("date").toInt()); if (object.contains("text")) news->setText(object.value("text").toString()); diff --git a/vksdk/src/objects/photo.h b/vksdk/src/objects/photo.h index 4e6412f..822417a 100755 --- a/vksdk/src/objects/photo.h +++ b/vksdk/src/objects/photo.h @@ -30,6 +30,8 @@ class Photo : public QObject { Q_OBJECT + Q_PROPERTY(int id READ id CONSTANT) + Q_PROPERTY(int ownerId READ ownerId CONSTANT) Q_PROPERTY(QString photoMinimum READ photoMinimum CONSTANT) Q_PROPERTY(QString photoMaximum READ photoMaximum CONSTANT) diff --git a/vksdk/src/requests/account.cpp b/vksdk/src/requests/account.cpp new file mode 100644 index 0000000..65f18cf --- /dev/null +++ b/vksdk/src/requests/account.cpp @@ -0,0 +1,22 @@ +#include "account.h" + +Account::Account(QObject *parent) : RequestBase(parent) +{} + +void Account::setOnline() { + QUrlQuery query; + query.addQueryItem("voip", "0"); + _api->makeApiGetRequest("account.setOnline", query, ApiRequest::ACCOUNT_SET_ONLINE); +} + +void Account::banUser(int id) { + QUrlQuery query; + query.addQueryItem("user_id", QString::number(id)); + _api->makeApiGetRequest("account.banUser", query, ApiRequest::ACCOUNT_BAN_USER); +} + +void Account::unbanUser(int id) { + QUrlQuery query; + query.addQueryItem("user_id", QString::number(id)); + _api->makeApiGetRequest("account.unbanUser", query, ApiRequest::ACCOUNT_UNBAN_USER); +} diff --git a/vksdk/src/requests/account.h b/vksdk/src/requests/account.h new file mode 100644 index 0000000..d2e6336 --- /dev/null +++ b/vksdk/src/requests/account.h @@ -0,0 +1,17 @@ +#ifndef ACCOUNT_H +#define ACCOUNT_H + +#include "requestbase.h" + +class Account : public RequestBase +{ + Q_OBJECT +public: + explicit Account(QObject *parent = 0); + + Q_INVOKABLE void setOnline(); + Q_INVOKABLE void banUser(int id); + Q_INVOKABLE void unbanUser(int id); +}; + +#endif // ACCOUNT_H diff --git a/vksdk/src/requests/apirequest.cpp b/vksdk/src/requests/apirequest.cpp index 2da0ff2..3d2b905 100755 --- a/vksdk/src/requests/apirequest.cpp +++ b/vksdk/src/requests/apirequest.cpp @@ -19,8 +19,15 @@ along with Kat. If not, see . */ +#include +#include +#include +#include +#include #include "apirequest.h" +const char TASK_TYPE_KEY[] = "taskType"; + ApiRequest::ApiRequest(QObject *parent) : QObject(parent) { _manager = new QNetworkAccessManager(this); connect(_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*))); @@ -30,41 +37,42 @@ ApiRequest::~ApiRequest() { delete _manager; } -void ApiRequest::makeApiGetRequest(QString method, QUrlQuery *query, TaskType type) { - query->addQueryItem("access_token", _accessToken); - query->addQueryItem("v", API_VERSION); +void ApiRequest::makeApiGetRequest(const QString &method, const QUrlQuery &q, TaskType type) { + QUrlQuery query = q; + query.addQueryItem("access_token", _accessToken); + query.addQueryItem("v", API_VERSION); QUrl url(API_URL + method); - url.setQuery(query->query()); - _history[url.toString()] = type; - qDebug() << url; - _manager->get(QNetworkRequest(url)); + url.setQuery(query.query()); + QNetworkReply *reply = _manager->get(QNetworkRequest(url)); + reply->setProperty(TASK_TYPE_KEY, type); } -void ApiRequest::makePostRequest(QUrl url, QUrlQuery *query, QHttpMultiPart *multipart, TaskType type) { - if (!query->isEmpty()) url.setQuery(query->query()); - _history[url.toString()] = type; - _manager->post(QNetworkRequest(url), multipart); +void ApiRequest::makePostRequest(const QUrl &u, const QUrlQuery &query, QHttpMultiPart *multipart, TaskType type) { + QUrl url = u; + if (!query.isEmpty()) url.setQuery(query.query()); + QNetworkReply *reply = _manager->post(QNetworkRequest(url), multipart); + reply->setProperty(TASK_TYPE_KEY, type); + multipart->setParent(reply); } -void ApiRequest::setAccessToken(QString token) { +void ApiRequest::setAccessToken(const QString &token) { _accessToken = token; } void ApiRequest::finished(QNetworkReply *reply) { - QString requestedUrl = reply->url().toString(); - if (_history.contains(requestedUrl)) { + const QVariant type = reply->property(TASK_TYPE_KEY); + if (type.isValid()) { + const TaskType taskType = type.value(); QJsonDocument jDoc = QJsonDocument::fromJson(reply->readAll()); - qDebug() << jDoc; QJsonObject jObj = jDoc.object(); - if (_history[requestedUrl] == PHOTOS_UPLOAD_TO_SERVER) { - emit gotResponse(jObj, _history[requestedUrl]); + if (taskType == PHOTOS_UPLOAD_TO_SERVER) { + emit gotResponse(jObj, taskType); } else if (jObj.contains("response")) { QJsonValue jVal = jObj.value("response"); - emit gotResponse(jVal, _history[requestedUrl]); + emit gotResponse(jVal, taskType); } else if (jObj.contains("error")) { qDebug() << "Error in API request!"; } - _history.remove(requestedUrl); } reply->deleteLater(); } diff --git a/vksdk/src/requests/apirequest.h b/vksdk/src/requests/apirequest.h index d221fef..afe62f4 100755 --- a/vksdk/src/requests/apirequest.h +++ b/vksdk/src/requests/apirequest.h @@ -22,48 +22,16 @@ #ifndef APIREQUEST_H #define APIREQUEST_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/* - Copyright (C) 2016 Petr Vytovtov - Contact: Petr Vytovtov - All rights reserved. - - This file is part of Kat. - - Kat is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Kat is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Kat. If not, see . -*/ - -#include #include #include #include -#include -//#include "objects/dialog.h" -//#include "objects/message.h" - -#include +QT_BEGIN_NAMESPACE +class QHttpMultiPart; +class QNetworkAccessManager; +class QNetworkReply; +class QJsonValue; +QT_END_NAMESPACE class ApiRequest : public QObject { @@ -74,9 +42,16 @@ class ApiRequest : public QObject ~ApiRequest(); enum TaskType { + ACCOUNT_BAN_USER, + ACCOUNT_GET_COUNTERS, + ACCOUNT_SET_ONLINE, + ACCOUNT_UNBAN_USER, AUDIO_ADD, AUDIO_GET, AUDIO_SEARCH, + BOARD_CREATE_COMMENT, + BOARD_GET_COMMENTS, + BOARD_GET_TOPICS, FRIENDS_GET, FRIENDS_GET_MUTUAL, FRIENDS_GET_ONLINE, @@ -91,6 +66,9 @@ class ApiRequest : public QObject MESSAGES_SEND, MESSAGES_SET_ACTIVITY, NEWSFEED_GET, + PHOTOS_GET, + PHOTOS_GET_ALBUMS, + PHOTOS_GET_ALL, PHOTOS_GET_MESSAGES_UPLOAD_SERVER, PHOTOS_GET_WALL_UPLOAD_SERVER, PHOTOS_SAVE_MESSAGES_PHOTO, @@ -108,25 +86,25 @@ class ApiRequest : public QObject WALL_REPOST, }; - void makeApiGetRequest(QString method, QUrlQuery *query, TaskType type); - void makePostRequest(QUrl url, QUrlQuery *query, QHttpMultiPart *multipart, TaskType type); + void makeApiGetRequest(const QString &method, const QUrlQuery &query, TaskType type); + void makePostRequest(const QUrl &url, const QUrlQuery &query, QHttpMultiPart *multipart, TaskType type); - void setAccessToken(QString token); + void setAccessToken(const QString &token); signals: - void gotResponse(QJsonValue value, ApiRequest::TaskType type); + void gotResponse(const QJsonValue &value, ApiRequest::TaskType type); public slots: void finished(QNetworkReply *reply); private: const QString API_URL = "https://api.vk.com/method/"; - const QString API_VERSION = "5.60"; + const QString API_VERSION = "5.63"; QString _accessToken; - QHash _history; - QNetworkAccessManager *_manager; }; +Q_DECLARE_METATYPE(ApiRequest::TaskType) + #endif // APIREQUEST_H diff --git a/vksdk/src/requests/audios.cpp b/vksdk/src/requests/audios.cpp index 971f9f0..c64dd6d 100755 --- a/vksdk/src/requests/audios.cpp +++ b/vksdk/src/requests/audios.cpp @@ -21,37 +21,30 @@ #include "audios.h" -Audios::Audios(QObject *parent) : QObject(parent) +Audios::Audios(QObject *parent) : RequestBase(parent) {} -Audios::~Audios() -{} - -void Audios::setApi(ApiRequest *api) { - _api = api; -} - void Audios::add(qint64 ownerId, qint64 audioId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("owner_id", QString::number(ownerId)); - query->addQueryItem("audio_id", QString::number(audioId)); + QUrlQuery query; + query.addQueryItem("owner_id", QString::number(ownerId)); + query.addQueryItem("audio_id", QString::number(audioId)); _api->makeApiGetRequest("audio.add", query, ApiRequest::AUDIO_ADD); } void Audios::get(qint64 ownerId, int count) { - QUrlQuery *query = new QUrlQuery(); - if (ownerId != 0) query->addQueryItem("owner_id", QString::number(ownerId)); - query->addQueryItem("count", QString::number(count)); + QUrlQuery query; + if (ownerId != 0) query.addQueryItem("owner_id", QString::number(ownerId)); + query.addQueryItem("count", QString::number(count)); _api->makeApiGetRequest("audio.get", query, ApiRequest::AUDIO_GET); } void Audios::search(QString _query) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("q", _query); - query->addQueryItem("auto_complete", "1"); - query->addQueryItem("lyrics", "0"); - query->addQueryItem("performer_only", "0"); - query->addQueryItem("sort", "2"); - query->addQueryItem("count", "300"); + QUrlQuery query; + query.addQueryItem("q", _query); + query.addQueryItem("auto_complete", "1"); + query.addQueryItem("lyrics", "0"); + query.addQueryItem("performer_only", "0"); + query.addQueryItem("sort", "2"); + query.addQueryItem("count", "300"); _api->makeApiGetRequest("audio.search", query, ApiRequest::AUDIO_SEARCH); } diff --git a/vksdk/src/requests/audios.h b/vksdk/src/requests/audios.h index bdb99b0..5933ed3 100755 --- a/vksdk/src/requests/audios.h +++ b/vksdk/src/requests/audios.h @@ -22,26 +22,17 @@ #ifndef AUDIOS_H #define AUDIOS_H -#include +#include "requestbase.h" -#include "apirequest.h" - -class Audios : public QObject +class Audios : public RequestBase { Q_OBJECT - public: explicit Audios(QObject *parent = 0); - ~Audios(); - - void setApi(ApiRequest *api); Q_INVOKABLE void add(qint64 ownerId, qint64 audioId); Q_INVOKABLE void get(qint64 ownerId = 0, int count = 6000); Q_INVOKABLE void search(QString query); - -private: - ApiRequest *_api; }; #endif // AUDIOS_H diff --git a/vksdk/src/requests/board.cpp b/vksdk/src/requests/board.cpp new file mode 100644 index 0000000..7c71ead --- /dev/null +++ b/vksdk/src/requests/board.cpp @@ -0,0 +1,30 @@ +#include "board.h" + +Board::Board(QObject *parent) : RequestBase(parent) +{} + +void Board::getTopics(int groupId, int offset) { + QUrlQuery query; + query.addQueryItem("group_id", QString::number(abs(groupId))); + query.addQueryItem("count", "100"); + if (offset != 0) query.addQueryItem("offset", QString::number(offset)); + _api->makeApiGetRequest("board.getTopics", query, ApiRequest::BOARD_GET_TOPICS); +} + +void Board::getComments(int groupId, int topicId, int offset) { + QUrlQuery query; + query.addQueryItem("group_id", QString::number(abs(groupId))); + query.addQueryItem("topic_id", QString::number(topicId)); + query.addQueryItem("count", "100"); + query.addQueryItem("extended", "1"); + if (offset != 0) query.addQueryItem("offset", QString::number(offset)); + _api->makeApiGetRequest("board.getComments", query, ApiRequest::BOARD_GET_COMMENTS); +} + +void Board::createComment(int groupId, int topicId, QString message) { + QUrlQuery query; + query.addQueryItem("group_id", QString::number(abs(groupId))); + query.addQueryItem("topic_id", QString::number(topicId)); + query.addQueryItem("message", message); + _api->makeApiGetRequest("board.createComment", query, ApiRequest::BOARD_CREATE_COMMENT); +} diff --git a/vksdk/src/requests/board.h b/vksdk/src/requests/board.h new file mode 100644 index 0000000..864149d --- /dev/null +++ b/vksdk/src/requests/board.h @@ -0,0 +1,18 @@ +#ifndef BOARD_H +#define BOARD_H + +#include "requestbase.h" + +class Board : public RequestBase +{ + Q_OBJECT +public: + explicit Board(QObject *parent = 0); + + Q_INVOKABLE void getTopics(int groupId, int offset = 0); + Q_INVOKABLE void getComments(int groupId, int topicId, int offset = 0); + Q_INVOKABLE void createComment(int groupId, int topicId, QString message); + +}; + +#endif // BOARD_H diff --git a/vksdk/src/requests/friends.cpp b/vksdk/src/requests/friends.cpp index 363c104..c86bd68 100755 --- a/vksdk/src/requests/friends.cpp +++ b/vksdk/src/requests/friends.cpp @@ -21,57 +21,25 @@ #include "friends.h" -Friends::Friends(QObject *parent) : QObject(parent) +Friends::Friends(QObject *parent) : RequestBase(parent) {} -Friends::~Friends() -{} - -void Friends::setApi(ApiRequest *api) { - _api = api; -} - void Friends::get(int userId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("user_id", QString("%1").arg(userId)); - query->addQueryItem("order", "hints"); - query->addQueryItem("fields", "photo_50,online,status"); + QUrlQuery query; + query.addQueryItem("user_id", QString::number(userId)); + query.addQueryItem("order", "hints"); + query.addQueryItem("fields", "photo_50,online,status"); _api->makeApiGetRequest("friends.get", query, ApiRequest::FRIENDS_GET); } void Friends::getOnline(int userId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("user_id", QString("%1").arg(userId)); + QUrlQuery query; + query.addQueryItem("user_id", QString::number(userId)); _api->makeApiGetRequest("friends.getOnline", query, ApiRequest::FRIENDS_GET_ONLINE); } void Friends::getMutual(int userId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("target_uid", QString("%1").arg(userId)); + QUrlQuery query; + query.addQueryItem("target_uid", QString::number(userId)); _api->makeApiGetRequest("friends.getMutual", query, ApiRequest::FRIENDS_GET_MUTUAL); } - -//void Friends::gotResponse(QJsonValue value, ApiRequest::TaskType type) { -// switch (type) { -// case ApiRequest::FRIENDS_GET: { -// QList friendsList; -// QJsonArray friends = value.toObject().value("items").toArray(); -// for (int index = 0; index < friends.size(); ++index) { -// QJsonObject friendItem = friends.at(index).toObject(); -// friendsList.append(Friend::fromJsonObject(friendItem)); -// } -// emit gotFriendsList(friendsList); -// break; -// } - -// case ApiRequest::FRIENDS_GET_ONLINE: -// case ApiRequest::FRIENDS_GET_MUTUAL: { -// emit gotMutualFriendsIds(value.toArray().toVariantList()); -// break; -// } - -// default: -// break; -// } -//} - diff --git a/vksdk/src/requests/friends.h b/vksdk/src/requests/friends.h index 0711170..b8ed6cf 100755 --- a/vksdk/src/requests/friends.h +++ b/vksdk/src/requests/friends.h @@ -22,43 +22,17 @@ #ifndef FRIENDS_H #define FRIENDS_H -//#include -//#include -//#include -//#include -#include -//#include -//#include -//#include +#include "requestbase.h" -#include "apirequest.h" -//#include "objects/friend.h" - -//#include - -class Friends : public QObject +class Friends : public RequestBase { Q_OBJECT - public: explicit Friends(QObject *parent = 0); - ~Friends(); - - void setApi(ApiRequest *api); Q_INVOKABLE void get(int userId); Q_INVOKABLE void getOnline(int userId); Q_INVOKABLE void getMutual(int userId); - -//signals: -// void gotFriendsList(QList friendsList); -// void gotMutualFriendsIds(QVariantList ids); - -//public slots: -// void gotResponse(QJsonValue value, ApiRequest::TaskType type); - -private: - ApiRequest *_api; }; #endif // FRIENDS_H diff --git a/vksdk/src/requests/groups.cpp b/vksdk/src/requests/groups.cpp index bfcd83f..06ce76d 100755 --- a/vksdk/src/requests/groups.cpp +++ b/vksdk/src/requests/groups.cpp @@ -1,28 +1,21 @@ #include "groups.h" -Groups::Groups(QObject *parent) : QObject(parent) +Groups::Groups(QObject *parent) : RequestBase(parent) {} -Groups::~Groups() -{} - -void Groups::setApi(ApiRequest *api) { - _api = api; -} - void Groups::get(int userId, int offset) { - QUrlQuery *query = new QUrlQuery(); - if (userId != 0) query->addQueryItem("user_id", QString::number(userId)); - if (offset != 0) query->addQueryItem("offset", QString::number(offset)); - query->addQueryItem("extended", "1"); - query->addQueryItem("fields", "status"); + QUrlQuery query; + if (userId != 0) query.addQueryItem("user_id", QString::number(userId)); + if (offset != 0) query.addQueryItem("offset", QString::number(offset)); + query.addQueryItem("extended", "1"); + query.addQueryItem("fields", "status"); _api->makeApiGetRequest("groups.get", query, ApiRequest::GROUPS_GET); } void Groups::getById(int groupId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("group_id", QString::number(abs(groupId))); - query->addQueryItem("fields", "description,members_count,counters,status"); + QUrlQuery query; + query.addQueryItem("group_id", QString::number(abs(groupId))); + query.addQueryItem("fields", "description,members_count,counters,status"); _api->makeApiGetRequest("groups.getById", query, ApiRequest::GROUPS_GET_BY_ID); } diff --git a/vksdk/src/requests/groups.h b/vksdk/src/requests/groups.h index e080db8..cddd8cb 100755 --- a/vksdk/src/requests/groups.h +++ b/vksdk/src/requests/groups.h @@ -1,25 +1,16 @@ #ifndef GROUPS_H #define GROUPS_H -#include +#include "requestbase.h" -#include "apirequest.h" - -class Groups : public QObject +class Groups : public RequestBase { Q_OBJECT - public: explicit Groups(QObject *parent = 0); - ~Groups(); - - void setApi(ApiRequest *api); Q_INVOKABLE void get(int userId = 0, int offset = 0); Q_INVOKABLE void getById(int groupId); - -private: - ApiRequest *_api; }; #endif // GROUPS_H diff --git a/vksdk/src/requests/likes.cpp b/vksdk/src/requests/likes.cpp index 92592cc..78148f0 100755 --- a/vksdk/src/requests/likes.cpp +++ b/vksdk/src/requests/likes.cpp @@ -21,32 +21,21 @@ #include "likes.h" -Likes::Likes(QObject *parent) : QObject(parent) +Likes::Likes(QObject *parent) : RequestBase(parent) {} -Likes::~Likes() -{} - -void Likes::setApi(ApiRequest *api) { - _api = api; -} - void Likes::addPost(int ownerId, int itemId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("type", "post"); - query->addQueryItem("owner_id", QString("%1").arg(ownerId)); - query->addQueryItem("item_id", QString("%1").arg(itemId)); + QUrlQuery query; + query.addQueryItem("type", "post"); + query.addQueryItem("owner_id", QString::number(ownerId)); + query.addQueryItem("item_id", QString::number(itemId)); _api->makeApiGetRequest("likes.add", query, ApiRequest::LIKES_ADD); } -//void Likes::gotResponse(QJsonValue value, ApiRequest::TaskType type) { -// switch (type) { -// case ApiRequest::LIKES_ADD: -// emit addedLike(value.toObject().value("likes").toInt()); -// break; - -// default: -// break; -// } -//} - +void Likes::addPhoto(int ownerId, int itemId) { + QUrlQuery query; + query.addQueryItem("type", "photo"); + query.addQueryItem("owner_id", QString("%1").arg(ownerId)); + query.addQueryItem("item_id", QString("%1").arg(itemId)); + _api->makeApiGetRequest("likes.add", query, ApiRequest::LIKES_ADD); +} diff --git a/vksdk/src/requests/likes.h b/vksdk/src/requests/likes.h index 58eee49..76cb57e 100755 --- a/vksdk/src/requests/likes.h +++ b/vksdk/src/requests/likes.h @@ -22,27 +22,17 @@ #ifndef LIKES_H #define LIKES_H -//#include -//#include -#include -//#include -//#include +#include "requestbase.h" -#include "apirequest.h" - -class Likes : public QObject +class Likes : public RequestBase { Q_OBJECT public: explicit Likes(QObject *parent = 0); - ~Likes(); Q_INVOKABLE void addPost(int ownerId, int itemId); + Q_INVOKABLE void addPhoto(int ownerId, int itemId); - void setApi(ApiRequest *api); - -private: - ApiRequest *_api; }; #endif // LIKES_H diff --git a/vksdk/src/requests/messages.cpp b/vksdk/src/requests/messages.cpp index 85cb439..0a8ee72 100755 --- a/vksdk/src/requests/messages.cpp +++ b/vksdk/src/requests/messages.cpp @@ -21,60 +21,53 @@ #include "messages.h" -Messages::Messages(QObject *parent) : QObject(parent) +Messages::Messages(QObject *parent) : RequestBase(parent) {} -Messages::~Messages() -{} - -void Messages::setApi(ApiRequest *api) { - _api = api; -} - void Messages::getById(int id) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("message_ids", QString::number(id)); + QUrlQuery query; + query.addQueryItem("message_ids", QString::number(id)); _api->makeApiGetRequest("messages.getById", query, ApiRequest::MESSAGES_GET_BY_ID); } -void Messages::getChat(QStringList ids) { - QUrlQuery *query = new QUrlQuery(); - if (ids.size() == 1) query->addQueryItem("chat_id", ids.at(0)); - else if (ids.size() > 1) query->addQueryItem("chat_ids", ids.join(",")); +void Messages::getChat(const QStringList &ids) { + QUrlQuery query; + if (ids.size() == 1) query.addQueryItem("chat_id", ids.at(0)); + else if (ids.size() > 1) query.addQueryItem("chat_ids", ids.join(",")); _api->makeApiGetRequest("messages.getChat", query, ApiRequest::MESSAGES_GET_CHAT); } void Messages::getDialogs(int offset) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("offset", QString("%1").arg(offset)); + QUrlQuery query; + query.addQueryItem("offset", QString::number(offset)); _api->makeApiGetRequest("messages.getDialogs", query, ApiRequest::MESSAGES_GET_DIALOGS); } void Messages::getHistory(int peerId, int offset) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("peer_id", QString("%1").arg(peerId)); - query->addQueryItem("offset", QString("%1").arg(offset)); + QUrlQuery query; + query.addQueryItem("peer_id", QString::number(peerId)); + query.addQueryItem("offset", QString::number(offset)); _api->makeApiGetRequest("messages.getHistory", query, ApiRequest::MESSAGES_GET_HISTORY); } void Messages::markAsRead(int peerId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("peer_id", QString::number(peerId)); + QUrlQuery query; + query.addQueryItem("peer_id", QString::number(peerId)); _api->makeApiGetRequest("messages.markAsRead", query, ApiRequest::MESSAGES_MARK_AS_READ); } -void Messages::send(int peerId, QString text, QString attachmentsList) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("peer_id", QString("%1").arg(peerId)); - if (!text.isEmpty()) query->addQueryItem("message", QString("%1").arg(text)); - if (!attachmentsList.isEmpty()) query->addQueryItem("attachment", attachmentsList); +void Messages::send(int peerId, const QString &text, const QString &attachmentsList) { + QUrlQuery query; + query.addQueryItem("peer_id", QString::number(peerId)); + if (!text.isEmpty()) query.addQueryItem("message", text); + if (!attachmentsList.isEmpty()) query.addQueryItem("attachment", attachmentsList); _api->makeApiGetRequest("messages.send", query, ApiRequest::MESSAGES_SEND); } void Messages::setActivity(int peerId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("peer_id", QString::number(peerId)); - query->addQueryItem("type", "typing"); + QUrlQuery query; + query.addQueryItem("peer_id", QString::number(peerId)); + query.addQueryItem("type", "typing"); _api->makeApiGetRequest("messages.setActivity", query, ApiRequest::MESSAGES_SET_ACTIVITY); } diff --git a/vksdk/src/requests/messages.h b/vksdk/src/requests/messages.h index 7d8ab0d..6bb2e0a 100755 --- a/vksdk/src/requests/messages.h +++ b/vksdk/src/requests/messages.h @@ -22,55 +22,22 @@ #ifndef MESSAGES_H #define MESSAGES_H -//#include -//#include -//#include -//#include -//#include -//#include -#include -//#include -//#include -//#include -//#include +#include "requestbase.h" -#include "apirequest.h" -//#include "../objects/chat.h" -//#include "../objects/dialog.h" - -//#include - -class Messages : public QObject +class Messages : public RequestBase { Q_OBJECT public: explicit Messages(QObject *parent = 0); - ~Messages(); - -// void setAccessToken(QString value); - void setApi(ApiRequest *api); Q_INVOKABLE void getById(int id); - Q_INVOKABLE void getChat(QStringList ids); + Q_INVOKABLE void getChat(const QStringList &ids); Q_INVOKABLE void getDialogs(int offset = 0); Q_INVOKABLE void getHistory(int peerId, int offset = 0); Q_INVOKABLE void markAsRead(int peerId); - Q_INVOKABLE void send(int peerId, QString text, QString attachmentsList); + Q_INVOKABLE void send(int peerId, const QString &text, const QString &attachmentsList); Q_INVOKABLE void setActivity(int peerId); - -//signals: -// void gotChatsList(QList chatsList); -// void gotDialogsList(QList dialogsList); -// void gotMessagesList(QList messagesList); -// void gotUnreadDialogsCounter(int value); - -//public slots: -// void gotResponse(QJsonValue value, ApiRequest::TaskType type); - -private: - ApiRequest *_api; - // QString _accessToken; }; #endif // MESSAGES_H diff --git a/vksdk/src/requests/newsfeed.cpp b/vksdk/src/requests/newsfeed.cpp index 0fa272d..4b7e344 100755 --- a/vksdk/src/requests/newsfeed.cpp +++ b/vksdk/src/requests/newsfeed.cpp @@ -21,22 +21,15 @@ #include "newsfeed.h" -Newsfeed::Newsfeed(QObject *parent) : QObject(parent) +Newsfeed::Newsfeed(QObject *parent) : RequestBase(parent) {} -Newsfeed::~Newsfeed() -{} - -void Newsfeed::setApi(ApiRequest *api) { - _api = api; -} - -void Newsfeed::get(QString startFrom) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("filters", "post"); - query->addQueryItem("return_banned", "0"); - query->addQueryItem("fields", "photo_50"); - if (!startFrom.isEmpty()) query->addQueryItem("start_from", startFrom); +void Newsfeed::get(const QString &startFrom) { + QUrlQuery query; + query.addQueryItem("filters", "post"); + query.addQueryItem("return_banned", "0"); + query.addQueryItem("fields", "photo_50"); + if (!startFrom.isEmpty()) query.addQueryItem("start_from", startFrom); _api->makeApiGetRequest("newsfeed.get", query, ApiRequest::NEWSFEED_GET); // ApiRequest *request = new ApiRequest(); // connect(request, SIGNAL(gotResponse(QJsonValue,ApiRequest::TaskType)), diff --git a/vksdk/src/requests/newsfeed.h b/vksdk/src/requests/newsfeed.h index 6545f41..5d505eb 100755 --- a/vksdk/src/requests/newsfeed.h +++ b/vksdk/src/requests/newsfeed.h @@ -22,24 +22,15 @@ #ifndef NEWSFEED_H #define NEWSFEED_H -#include +#include "requestbase.h" -#include "apirequest.h" - -class Newsfeed : public QObject +class Newsfeed : public RequestBase { Q_OBJECT - public: explicit Newsfeed(QObject *parent = 0); - ~Newsfeed(); - - void setApi(ApiRequest *api); - - Q_INVOKABLE void get(QString startFrom = ""); -private: - ApiRequest *_api; + Q_INVOKABLE void get(const QString &startFrom = QString()); }; #endif // NEWSFEED_H diff --git a/vksdk/src/requests/photos.cpp b/vksdk/src/requests/photos.cpp index cfdf720..57e6d5a 100755 --- a/vksdk/src/requests/photos.cpp +++ b/vksdk/src/requests/photos.cpp @@ -19,49 +19,75 @@ along with Kat. If not, see . */ -#include "photos.h" +#include +#include +#include -Photos::Photos(QObject *parent) : QObject(parent) -{} -Photos::~Photos() -{} +#include "photos.h" -void Photos::setApi(ApiRequest *api) { - _api = api; -} +Photos::Photos(QObject *parent) : RequestBase(parent) +{} void Photos::getMessagesUploadServer() { - _api->makeApiGetRequest("photos.getMessagesUploadServer", new QUrlQuery(), ApiRequest::PHOTOS_GET_MESSAGES_UPLOAD_SERVER); + _api->makeApiGetRequest("photos.getMessagesUploadServer", QUrlQuery(), ApiRequest::PHOTOS_GET_MESSAGES_UPLOAD_SERVER); } -void Photos::uploadPhotoToServer(QString server, QString album, QString user, QString path) { - path = path.replace("file://", ""); +void Photos::uploadPhotoToServer(const QString &server, const QString &album, const QString &user, const QString &p) { + Q_UNUSED(album) + Q_UNUSED(user) + + QString path = p; + path = path.remove("file://"); QString fileType = path.split(".").last(); QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8")); - QFile *file = new QFile(tr(path.toUtf8())); - if (file->open(QIODevice::ReadOnly)) { + QFile file(tr(path.toUtf8())); + if (file.open(QIODevice::ReadOnly)) { QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QString("image/%1").arg(fileType == "jpg" ? "jpeg" : fileType))); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"photo\"; filename=\"%1.%2\"").arg(qrand()).arg(fileType))); - imagePart.setBody(file->readAll()); + imagePart.setBody(file.readAll()); multipart->append(imagePart); - _api->makePostRequest(QUrl(server), new QUrlQuery(), multipart, ApiRequest::PHOTOS_UPLOAD_TO_SERVER); - file->close(); + _api->makePostRequest(QUrl(server), QUrlQuery(), multipart, ApiRequest::PHOTOS_UPLOAD_TO_SERVER); + file.close(); } } -void Photos::saveMessagesPhoto(QString photo, QString server, QString hash) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("photo", photo); - query->addQueryItem("server", server); - query->addQueryItem("hash", hash); +void Photos::saveMessagesPhoto(const QString &photo, const QString &server, const QString &hash) { + QUrlQuery query; + query.addQueryItem("photo", photo); + query.addQueryItem("server", server); + query.addQueryItem("hash", hash); _api->makeApiGetRequest("photos.saveMessagesPhoto", query, ApiRequest::PHOTOS_SAVE_MESSAGES_PHOTO); } +void Photos::get(QString ownerId, QString albumId, int offset) { + QUrlQuery query; + query.addQueryItem("owner_id", ownerId); + query.addQueryItem("album_id", albumId); + query.addQueryItem("count", "21"); + if (offset != 0) query.addQueryItem("offset", QString::number(offset)); + _api->makeApiGetRequest("photos.get", query, ApiRequest::PHOTOS_GET ); +} + +void Photos::getAlbums(QString ownerId) { + QUrlQuery query; + query.addQueryItem("owner_id", ownerId); + query.addQueryItem("need_system", "1"); + _api->makeApiGetRequest("photos.getAlbums", query, ApiRequest::PHOTOS_GET_ALBUMS); +} + +void Photos::getAll(QString ownerId, int offset) { + QUrlQuery query; + query.addQueryItem("owner_id", ownerId); + query.addQueryItem("count", "21"); + if (offset != 0) query.addQueryItem("offset", QString::number(offset)); + _api->makeApiGetRequest("photos.getAll", query, ApiRequest::PHOTOS_GET_ALL); +} + //void Photos::attachImage(QString image, QString mode, int groupId) { // pathToImage = image.replace("file://", ""); //// pathToImage = image; diff --git a/vksdk/src/requests/photos.h b/vksdk/src/requests/photos.h index b758e7b..9d77232 100755 --- a/vksdk/src/requests/photos.h +++ b/vksdk/src/requests/photos.h @@ -22,43 +22,21 @@ #ifndef PHOTOS_H #define PHOTOS_H -#include +#include "requestbase.h" -//#include -//#include -//#include -//#include -#include -//#include -//#include - -//#include -#include -#include -//#include -//#include -//#include -//#include - -#include -#include - -//#include - -#include "apirequest.h" - -class Photos : public QObject +class Photos : public RequestBase { Q_OBJECT public: explicit Photos(QObject *parent = 0); - ~Photos(); - - void setApi(ApiRequest *api); void getMessagesUploadServer(); - void uploadPhotoToServer(QString server, QString album, QString user, QString path); - void saveMessagesPhoto(QString photo, QString server, QString hash); + void uploadPhotoToServer(const QString &server, const QString &album, const QString &user, const QString &path); + void saveMessagesPhoto(const QString &photo, const QString &server, const QString &hash); + + Q_INVOKABLE void get(QString ownerId, QString albumId, int offset = 0); + Q_INVOKABLE void getAlbums(QString ownerId); + Q_INVOKABLE void getAll(QString ownerId, int offset = 0); // void setAccessToken(const QString &accessToken); @@ -74,7 +52,6 @@ class Photos : public QObject // void uploadedImage(QNetworkReply *reply); private: - ApiRequest *_api; // QString pathToImage; // QString mMode; // int mGroupId; diff --git a/vksdk/src/requests/requestbase.cpp b/vksdk/src/requests/requestbase.cpp new file mode 100644 index 0000000..2625aae --- /dev/null +++ b/vksdk/src/requests/requestbase.cpp @@ -0,0 +1,12 @@ +#include "requestbase.h" + +RequestBase::RequestBase(QObject *parent) : + QObject(parent), + _api(nullptr) +{ +} + +void RequestBase::setApi(ApiRequest *api) +{ + _api = api; +} diff --git a/vksdk/src/requests/requestbase.h b/vksdk/src/requests/requestbase.h new file mode 100644 index 0000000..6176cff --- /dev/null +++ b/vksdk/src/requests/requestbase.h @@ -0,0 +1,15 @@ +#ifndef REQUESTBASE_H +#define REQUESTBASE_H + +#include "apirequest.h" +class RequestBase : public QObject +{ +public: + RequestBase(QObject *parent = nullptr); + void setApi(ApiRequest *api); + +protected: + ApiRequest *_api; +}; + +#endif // REQUESTBASE diff --git a/vksdk/src/requests/stats.cpp b/vksdk/src/requests/stats.cpp index ae42d90..170d027 100644 --- a/vksdk/src/requests/stats.cpp +++ b/vksdk/src/requests/stats.cpp @@ -1,24 +1,17 @@ #include "stats.h" -Stats::Stats(QObject *parent) : QObject(parent) +Stats::Stats(QObject *parent) : RequestBase(parent) {} -Stats::~Stats() -{} - -void Stats::setApi(ApiRequest *api) { - _api = api; -} - -void Stats::get(int id, QString from, QString to, bool isGroup) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem(isGroup ? "group_id" : "app_id", QString::number(abs(id))); - query->addQueryItem("date_from", from); - query->addQueryItem("date_to", to); +void Stats::get(int id, const QString &from, const QString &to, bool isGroup) { + QUrlQuery query; + query.addQueryItem(isGroup ? "group_id" : "app_id", QString::number(abs(id))); + query.addQueryItem("date_from", from); + query.addQueryItem("date_to", to); _api->makeApiGetRequest("stats.get", query, ApiRequest::STATS_GET); } void Stats::trackVisitor() { - _api->makeApiGetRequest("stats.trackVisitor", new QUrlQuery(), ApiRequest::STATS_TRACK_VISITOR); + _api->makeApiGetRequest("stats.trackVisitor", QUrlQuery(), ApiRequest::STATS_TRACK_VISITOR); } diff --git a/vksdk/src/requests/stats.h b/vksdk/src/requests/stats.h index 368133a..f751469 100644 --- a/vksdk/src/requests/stats.h +++ b/vksdk/src/requests/stats.h @@ -1,25 +1,16 @@ #ifndef STATS_H #define STATS_H -#include +#include "requestbase.h" -#include "apirequest.h" - -class Stats : public QObject +class Stats : public RequestBase { Q_OBJECT - public: explicit Stats(QObject *parent = 0); - ~Stats(); - void setApi(ApiRequest *api); - - Q_INVOKABLE void get(int id, QString from, QString to, bool isGroup = true); + Q_INVOKABLE void get(int id, const QString &from, const QString &to, bool isGroup = true); Q_INVOKABLE void trackVisitor(); - -private: - ApiRequest *_api; }; #endif // STATS_H diff --git a/vksdk/src/requests/users.cpp b/vksdk/src/requests/users.cpp index 60a7942..b20793a 100755 --- a/vksdk/src/requests/users.cpp +++ b/vksdk/src/requests/users.cpp @@ -21,24 +21,17 @@ #include "users.h" -Users::Users(QObject *parent) : QObject(parent) +Users::Users(QObject *parent) : RequestBase(parent) {} -Users::~Users() -{} - -void Users::setApi(ApiRequest *api) { - _api = api; -} - void Users::getSelfProfile() { getUserProfile(0); } void Users::getUserProfile(int id) { - QUrlQuery *query = new QUrlQuery(); - if (id != 0) query->addQueryItem("user_ids", QString("%1").arg(id)); - query->addQueryItem("fields", "blacklisted,blacklisted_by_me,can_post,can_see_all_posts," + QUrlQuery query; + if (id != 0) query.addQueryItem("user_ids", QString::number(id)); + query.addQueryItem("fields", "blacklisted,blacklisted_by_me,can_post,can_see_all_posts," "can_see_audio,can_send_friend_request,can_write_private_message," "domain,exports,friend_status,is_favorite,is_hidden_from_feed," "photo_max_orig,verified,nickname,maiden_name,online,photo_50," @@ -47,10 +40,10 @@ void Users::getUserProfile(int id) { _api->makeApiGetRequest("users.get", query, ApiRequest::USERS_GET); } -void Users::getUsersByIds(QStringList ids) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("user_ids", ids.join(",")); - query->addQueryItem("fields", "photo_50,online,status"); +void Users::getUsersByIds(const QStringList &ids) { + QUrlQuery query; + query.addQueryItem("user_ids", ids.join(",")); + query.addQueryItem("fields", "photo_50,online,status"); _api->makeApiGetRequest("users.get", query, ApiRequest::USERS_GET_FRIENDS); } diff --git a/vksdk/src/requests/users.h b/vksdk/src/requests/users.h index ee5e3b8..471e611 100755 --- a/vksdk/src/requests/users.h +++ b/vksdk/src/requests/users.h @@ -22,32 +22,18 @@ #ifndef USERS_H #define USERS_H -//#include -//#include -//#include -#include -//#include -//#include -#include "apirequest.h" -//#include "objects/friend.h" -//#include "objects/user.h" +#include "requestbase.h" -//#include - -class Users : public QObject +class Users : public RequestBase { Q_OBJECT - public: explicit Users(QObject *parent = 0); - ~Users(); - - void setApi(ApiRequest *api); Q_INVOKABLE void getSelfProfile(); Q_INVOKABLE void getUserProfile(int id); - Q_INVOKABLE void getUsersByIds(QStringList ids); + Q_INVOKABLE void getUsersByIds(const QStringList &ids); //signals: // void gotUserProfile(User *user); @@ -56,8 +42,6 @@ class Users : public QObject //public slots: // void gotResponse(QJsonValue value, ApiRequest::TaskType type); -private: - ApiRequest *_api; }; #endif // USERS_H diff --git a/vksdk/src/requests/videos.cpp b/vksdk/src/requests/videos.cpp index 9690310..b2b5458 100755 --- a/vksdk/src/requests/videos.cpp +++ b/vksdk/src/requests/videos.cpp @@ -21,20 +21,13 @@ #include "videos.h" -Videos::Videos(QObject *parent) : QObject(parent) +Videos::Videos(QObject *parent) : RequestBase(parent) {} -Videos::~Videos() -{} - -void Videos::setApi(ApiRequest *api) { - _api = api; -} - void Videos::get(int ownerId, int videoId) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("owner_id", QString("%1").arg(ownerId)); - query->addQueryItem("videos", QString("%1_%2").arg(ownerId).arg(videoId)); + QUrlQuery query; + query.addQueryItem("owner_id", QString::number(ownerId)); + query.addQueryItem("videos", QString("%1_%2").arg(ownerId).arg(videoId)); _api->makeApiGetRequest("video.get", query, ApiRequest::VIDEO_GET); } diff --git a/vksdk/src/requests/videos.h b/vksdk/src/requests/videos.h index adae6e1..bd5211a 100755 --- a/vksdk/src/requests/videos.h +++ b/vksdk/src/requests/videos.h @@ -22,29 +22,15 @@ #ifndef VIDEOS_H #define VIDEOS_H -//#include -//#include -//#include -#include -//#include +#include "requestbase.h" -#include "apirequest.h" -//#include "objects/video.h" - -class Videos : public QObject +class Videos : public RequestBase { Q_OBJECT - public: explicit Videos(QObject *parent = 0); - ~Videos(); Q_INVOKABLE void get(int ownerId, int videoId); - - void setApi(ApiRequest *api); - -private: - ApiRequest *_api; }; #endif // VIDEOS_H diff --git a/vksdk/src/requests/wall.cpp b/vksdk/src/requests/wall.cpp index 05653ca..d116ce6 100755 --- a/vksdk/src/requests/wall.cpp +++ b/vksdk/src/requests/wall.cpp @@ -21,54 +21,47 @@ #include "wall.h" -Wall::Wall(QObject *parent) : QObject(parent) +Wall::Wall(QObject *parent) : RequestBase(parent) {} -Wall::~Wall() -{} - -void Wall::setApi(ApiRequest *api) { - _api = api; -} - void Wall::get(int ownerId, int offset) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("owner_id", QString::number(ownerId)); - query->addQueryItem("count", "20"); - query->addQueryItem("extended", "1"); - query->addQueryItem("fields", "photo_50"); - if (offset != 0) query->addQueryItem("offset", QString::number(offset)); + QUrlQuery query; + query.addQueryItem("owner_id", QString::number(ownerId)); + query.addQueryItem("count", "20"); + query.addQueryItem("extended", "1"); + query.addQueryItem("fields", "photo_50"); + if (offset != 0) query.addQueryItem("offset", QString::number(offset)); _api->makeApiGetRequest("wall.get", query, ApiRequest::WALL_GET); } void Wall::getById(int ownerId, int id) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("posts", QString("%1_%2").arg(ownerId).arg(id)); + QUrlQuery query; + query.addQueryItem("posts", QString("%1_%2").arg(ownerId).arg(id)); _api->makeApiGetRequest("wall.getById", query, ApiRequest::WALL_GET_BY_ID); } void Wall::getComments(int ownerId, int postId, int offset) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("owner_id", QString::number(ownerId)); - query->addQueryItem("post_id", QString::number(postId)); - query->addQueryItem("count", "100"); - query->addQueryItem("sort", "asc"); - query->addQueryItem("extended", "1"); - if (offset != 0) query->addQueryItem("offset", QString::number(offset)); + QUrlQuery query; + query.addQueryItem("owner_id", QString::number(ownerId)); + query.addQueryItem("post_id", QString::number(postId)); + query.addQueryItem("count", "100"); + query.addQueryItem("sort", "asc"); + query.addQueryItem("extended", "1"); + if (offset != 0) query.addQueryItem("offset", QString::number(offset)); _api->makeApiGetRequest("wall.getComments", query, ApiRequest::WALL_GET_COMMENTS); } -void Wall::createComment(int ownerId, int postId, QString message) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("owner_id", QString::number(ownerId)); - query->addQueryItem("post_id", QString::number(postId)); - query->addQueryItem("message", message); +void Wall::createComment(int ownerId, int postId, const QString &message) { + QUrlQuery query; + query.addQueryItem("owner_id", QString::number(ownerId)); + query.addQueryItem("post_id", QString::number(postId)); + query.addQueryItem("message", message); _api->makeApiGetRequest("wall.createComment", query, ApiRequest::WALL_CREATE_COMMENT); } -void Wall::repost(int ownerId, int postId, QString message) { - QUrlQuery *query = new QUrlQuery(); - query->addQueryItem("object", QString("wall%1_%2").arg(ownerId).arg(postId)); - query->addQueryItem("message", message); +void Wall::repost(const QString &type, int ownerId, int postId, const QString &message) { + QUrlQuery query; + query.addQueryItem("object", QString("%1%2_%3").arg(type).arg(ownerId).arg(postId)); + query.addQueryItem("message", message); _api->makeApiGetRequest("wall.repost", query, ApiRequest::WALL_REPOST); } diff --git a/vksdk/src/requests/wall.h b/vksdk/src/requests/wall.h index e743152..8d9cfb4 100755 --- a/vksdk/src/requests/wall.h +++ b/vksdk/src/requests/wall.h @@ -22,28 +22,19 @@ #ifndef WALL_H #define WALL_H -#include +#include "requestbase.h" -#include "apirequest.h" - -class Wall : public QObject +class Wall : public RequestBase { Q_OBJECT - public: explicit Wall(QObject *parent = 0); - ~Wall(); - - void setApi(ApiRequest *api); Q_INVOKABLE void get(int ownerId, int offset = 0); Q_INVOKABLE void getById(int ownerId, int id); Q_INVOKABLE void getComments(int ownerId, int postId, int offset = 0); - Q_INVOKABLE void createComment(int ownerId, int postId, QString message); - Q_INVOKABLE void repost(int ownerId, int postId, QString message); - -private: - ApiRequest *_api; + Q_INVOKABLE void createComment(int ownerId, int postId, const QString &message); + Q_INVOKABLE void repost(const QString &type, int ownerId, int postId, const QString &message); }; #endif // WALL_H diff --git a/vksdk/src/vksdk.cpp b/vksdk/src/vksdk.cpp index 70b5abc..70fb023 100755 --- a/vksdk/src/vksdk.cpp +++ b/vksdk/src/vksdk.cpp @@ -26,8 +26,7 @@ VkSDK::VkSDK(QObject *parent) : QObject(parent) { _api = new ApiRequest(this); _auth = new Authorization(this); qRegisterMetaType("Authorization*"); - connect(_api, SIGNAL(gotResponse(QJsonValue,ApiRequest::TaskType)), - this, SLOT(gotResponse(QJsonValue,ApiRequest::TaskType))); + connect(_api, &ApiRequest::gotResponse, this, &VkSDK::gotResponse); // connect(_api, &ApiRequest::gotResponse, // [this] (QJsonValue value, ApiRequest::TaskType type) { QtConcurrent::run(this, &VkSDK::gotResponse, value, type); }); // [this] (QJsonValue value, ApiRequest::TaskType type) { gotResponse(value, type); }); @@ -38,7 +37,9 @@ VkSDK::VkSDK(QObject *parent) : QObject(parent) { connect(_longPoll, SIGNAL(userTyping(qint64,qint64)), this, SLOT(_userTyping(qint64,qint64))); // requests: + _account = new Account(this); _audios = new Audios(this); + _board = new Board(this); _friends = new Friends(this); _groups = new Groups(this); _likes = new Likes(this); @@ -50,7 +51,9 @@ VkSDK::VkSDK(QObject *parent) : QObject(parent) { _videos = new Videos(this); _wall = new Wall(this); // _longPoll->setApi(_api); + _account->setApi(_api); _audios->setApi(_api); + _board->setApi(_api); _friends->setApi(_api); _groups->setApi(_api); _likes->setApi(_api); @@ -62,7 +65,9 @@ VkSDK::VkSDK(QObject *parent) : QObject(parent) { _videos->setApi(_api); _wall->setApi(_api); qRegisterMetaType("LongPoll*"); + qRegisterMetaType("Account*"); qRegisterMetaType("Audios*"); + qRegisterMetaType("Board*"); qRegisterMetaType("Friends*"); qRegisterMetaType("Groups*"); qRegisterMetaType("Likes*"); @@ -87,12 +92,14 @@ VkSDK::VkSDK(QObject *parent) : QObject(parent) { _messagesModel = new MessagesModel(this); _newsfeedModel = new NewsfeedModel(this); _wallModel = new NewsfeedModel(this); + _photosModel = new PhotosModel(this); qRegisterMetaType("CommentsModel*"); qRegisterMetaType("DialogsListModel*"); qRegisterMetaType("FriendsListModel*"); qRegisterMetaType("GroupsListModel*"); qRegisterMetaType("MessagesModel*"); qRegisterMetaType("NewsfeedModel*"); + qRegisterMetaType("PhotosModel*"); // qRegisterMetaType("Audio*"); @@ -107,7 +114,9 @@ VkSDK::~VkSDK() { delete _auth; delete _longPoll; + delete _account; delete _audios; + delete _board; delete _friends; delete _groups; delete _likes; @@ -126,6 +135,7 @@ VkSDK::~VkSDK() { delete _messagesModel; delete _newsfeedModel; delete _wallModel; + delete _photosModel; // delete _selfProfile; } @@ -147,10 +157,18 @@ LongPoll *VkSDK::longPoll() const { return _longPoll; } +Account *VkSDK::account() const { + return _account; +} + Audios *VkSDK::audios() const { return _audios; } +Board *VkSDK::board() const { + return _board; +} + Friends *VkSDK::friends() const { return _friends; } @@ -219,17 +237,30 @@ NewsfeedModel *VkSDK::wallModel() const { return _wallModel; } +PhotosModel *VkSDK::photosModel() const { + return _photosModel; +} + void VkSDK::attachPhotoToMessage(QString path) { _pathToPhoto = path; _photos->getMessagesUploadServer(); } -void VkSDK::gotResponse(QJsonValue value, ApiRequest::TaskType type) { +void VkSDK::gotResponse(const QJsonValue &value, ApiRequest::TaskType type) { switch (type) { + case ApiRequest::ACCOUNT_BAN_USER: + emit banSettingChanged(true); + break; + case ApiRequest::ACCOUNT_UNBAN_USER: + emit banSettingChanged(false); + break; case ApiRequest::AUDIO_GET: case ApiRequest::AUDIO_SEARCH: parseAudiosList(value.toObject().value("items").toArray()); break; + case ApiRequest::BOARD_GET_TOPICS: + parseTopicsList(value.toObject().value("items").toArray()); + break; case ApiRequest::FRIENDS_GET: parseEntireFriendsList(value.toObject().value("items").toArray()); break; @@ -255,6 +286,13 @@ void VkSDK::gotResponse(QJsonValue value, ApiRequest::TaskType type) { case ApiRequest::MESSAGES_GET_HISTORY: parseMessages(value.toObject().value("items").toArray()); break; + case ApiRequest::PHOTOS_GET_ALBUMS: + parsePhotoAlbums(value.toObject().value("items").toArray()); + break; + case ApiRequest::PHOTOS_GET: + case ApiRequest::PHOTOS_GET_ALL: + parsePhotosList(value.toObject()); + break; case ApiRequest::PHOTOS_GET_MESSAGES_UPLOAD_SERVER: parseUploadServerData(value.toObject()); break; @@ -285,6 +323,7 @@ void VkSDK::gotResponse(QJsonValue value, ApiRequest::TaskType type) { case ApiRequest::VIDEO_GET: emit gotVideo(parseVideoInfo(value.toObject().value("items").toArray())); break; + case ApiRequest::BOARD_CREATE_COMMENT: case ApiRequest::WALL_CREATE_COMMENT: emit commentCreated(); break; @@ -294,6 +333,7 @@ void VkSDK::gotResponse(QJsonValue value, ApiRequest::TaskType type) { case ApiRequest::WALL_GET_BY_ID: emit gotWallpost(parseWallpost(value.toObject().value("items").toArray())); break; + case ApiRequest::BOARD_GET_COMMENTS: case ApiRequest::WALL_GET_COMMENTS: parseComments(value.toObject()); break; @@ -465,6 +505,25 @@ void VkSDK::parseNewsfeed(QJsonObject object, bool isWall) { else _newsfeedModel->setNextFrom(nextFrom); } +void VkSDK::parsePhotoAlbums(QJsonArray array) { + QList data; + foreach (QJsonValue val, array) { + data.append(QString::number(val.toObject().value("id").toInt())); + data.append(val.toObject().value("title").toString()); + } + emit gotPhotoAlbums(data); +} + +void VkSDK::parsePhotosList(QJsonObject object) { + int count = object.value("count").toInt(); + QJsonArray items = object.value("items").toArray(); + for (int index = 0; index < items.size(); ++index) { + Photo *photo = Photo::fromJsonObject(items.at(index).toObject()); + _photosModel->addPhoto(photo); + } + _photosModel->setCount(count); +} + void VkSDK::parseSavedPhotoData(QJsonArray array) { QJsonObject photo = array.at(0).toObject(); emit savedPhoto(QString("photo%1_%2").arg(QString::number(photo.value("owner_id").toInt())) @@ -481,6 +540,18 @@ void VkSDK::parseStatistics(QJsonArray array) { emit gotStats(data); } +void VkSDK::parseTopicsList(QJsonArray array) { + QList ids; + QStringList titles; + QList closed; + foreach (QJsonValue val, array) { + ids << val.toObject().value("id").toInt(); + titles << val.toObject().value("title").toString(); + closed << (val.toObject().value("is_closed").toInt() == 1); + } + emit gotTopics(ids, titles, closed); +} + void VkSDK::parseUploadedPhotoData(QJsonObject object) { QString server = QString::number(object.value("server").toInt()); QString photo = object.value("photo").toString(); diff --git a/vksdk/src/vksdk.h b/vksdk/src/vksdk.h index 3925e44..66826a5 100755 --- a/vksdk/src/vksdk.h +++ b/vksdk/src/vksdk.h @@ -37,8 +37,11 @@ #include "models/groupslistmodel.h" #include "models/messagesmodel.h" #include "models/newsfeedmodel.h" +#include "models/photosmodel.h" +#include "requests/account.h" #include "requests/apirequest.h" #include "requests/audios.h" +#include "requests/board.h" #include "requests/friends.h" #include "requests/groups.h" #include "requests/likes.h" @@ -65,7 +68,9 @@ class VkSDK : public QObject Q_PROPERTY(Authorization* auth READ auth CONSTANT) Q_PROPERTY(LongPoll* longPoll READ longPoll CONSTANT) + Q_PROPERTY(Account* account READ account CONSTANT) Q_PROPERTY(Audios* audios READ audios CONSTANT) + Q_PROPERTY(Board* board READ board CONSTANT) Q_PROPERTY(Friends* friends READ friends CONSTANT) Q_PROPERTY(Groups* groups READ groups CONSTANT) Q_PROPERTY(Likes* likes READ likes CONSTANT) @@ -84,6 +89,7 @@ class VkSDK : public QObject Q_PROPERTY(MessagesModel* messagesModel READ messagesModel CONSTANT) Q_PROPERTY(NewsfeedModel* newsfeedModel READ newsfeedModel CONSTANT) Q_PROPERTY(NewsfeedModel* wallModel READ wallModel CONSTANT) + Q_PROPERTY(PhotosModel* photosModel READ photosModel CONSTANT) // Q_PROPERTY(User* selfProfile READ selfProfile CONSTANT) @@ -98,7 +104,9 @@ class VkSDK : public QObject Authorization *auth() const; LongPoll* longPoll() const; + Account* account() const; Audios* audios() const; + Board* board() const; Friends* friends() const; Groups* groups() const; Likes *likes() const; @@ -117,16 +125,20 @@ class VkSDK : public QObject MessagesModel* messagesModel() const; NewsfeedModel* newsfeedModel() const; NewsfeedModel* wallModel() const; + PhotosModel* photosModel() const; Q_INVOKABLE void attachPhotoToMessage(QString path); // User* selfProfile() const; signals: + void banSettingChanged(bool banned); void commentCreated(); void gotGroup(Group *grp); void gotNewMessage(QString name, QString preview); + void gotPhotoAlbums(QList data); void gotProfile(User *user); + void gotTopics(QList ids, QStringList topics, QList closed); void gotUnreadCounter(int value); void gotVideo(Video *video); void gotUserAudios(QVariantList audios); @@ -140,7 +152,7 @@ class VkSDK : public QObject // void newsfeedModelChanged(); public slots: - void gotResponse(QJsonValue value, ApiRequest::TaskType type); + void gotResponse(const QJsonValue &value, ApiRequest::TaskType type); void _gotNewMessage(int id); void _readMessages(qint64 peerId, qint64 localId, bool out); void _userTyping(qint64 userId, qint64 chatId); @@ -166,7 +178,9 @@ public slots: Authorization *_auth; LongPoll *_longPoll; + Account *_account; Audios *_audios; + Board *_board; Friends *_friends; Groups *_groups; Likes *_likes; @@ -185,6 +199,7 @@ public slots: MessagesModel *_messagesModel; NewsfeedModel *_newsfeedModel; NewsfeedModel *_wallModel; + PhotosModel *_photosModel; QString _messagePreview; QString _pathToPhoto; @@ -203,8 +218,11 @@ public slots: void parseMessages(QJsonArray array); void parseNewMessage(QJsonObject object); void parseNewsfeed(QJsonObject object, bool isWall); + void parsePhotoAlbums(QJsonArray array); + void parsePhotosList(QJsonObject object); void parseSavedPhotoData(QJsonArray array); void parseStatistics(QJsonArray array); + void parseTopicsList(QJsonArray array); void parseUploadedPhotoData(QJsonObject object); void parseUploadServerData(QJsonObject object); User* parseUserProfile(QJsonArray array); diff --git a/vksdk/vksdk.pri b/vksdk/vksdk.pri index d486827..3c3ac7c 100755 --- a/vksdk/vksdk.pri +++ b/vksdk/vksdk.pri @@ -32,7 +32,11 @@ HEADERS += \ $$PWD/src/models/groupslistmodel.h \ $$PWD/src/objects/comment.h \ $$PWD/src/models/commentsmodel.h \ - $$PWD/src/requests/stats.h + $$PWD/src/requests/stats.h \ + $$PWD/src/requests/account.h \ + $$PWD/src/requests/requestbase.h \ + $$PWD/src/models/photosmodel.h \ + $$PWD/src/requests/board.h SOURCES += \ $$PWD/src/authorization.cpp \ @@ -68,4 +72,8 @@ SOURCES += \ $$PWD/src/models/groupslistmodel.cpp \ $$PWD/src/objects/comment.cpp \ $$PWD/src/models/commentsmodel.cpp \ - $$PWD/src/requests/stats.cpp + $$PWD/src/requests/stats.cpp \ + $$PWD/src/requests/account.cpp \ + $$PWD/src/requests/requestbase.cpp \ + $$PWD/src/models/photosmodel.cpp \ + $$PWD/src/requests/board.cpp