Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 by Savoir-faire Linux |
| 3 | * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | */ |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 18 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 19 | import QtQuick 2.14 |
| 20 | import QtQuick.Controls 2.14 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 21 | import QtGraphicalEffects 1.12 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 22 | import net.jami.Models 1.0 |
| 23 | |
| 24 | import "../../commoncomponents" |
| 25 | |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 26 | import "../../commoncomponents/js/contextmenugenerator.js" as ContextMenuGenerator |
| 27 | |
| 28 | Item { |
| 29 | id: root |
| 30 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 31 | property string responsibleAccountId: "" |
| 32 | property string responsibleConvUid: "" |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 33 | property int contactType: Profile.Type.INVALID |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 34 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 35 | function openMenu(){ |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 36 | ContextMenuGenerator.addMenuItem(qsTr("Start video call"), |
| 37 | "qrc:/images/icons/ic_video_call_24px.svg", |
| 38 | function (){ |
| 39 | ConversationsAdapter.selectConversation( |
| 40 | responsibleAccountId, |
| 41 | responsibleConvUid, false) |
| 42 | CallAdapter.placeCall() |
| 43 | }) |
| 44 | ContextMenuGenerator.addMenuItem(qsTr("Start audio call"), |
| 45 | "qrc:/images/icons/ic_phone_24px.svg", |
| 46 | function (){ |
| 47 | ConversationsAdapter.selectConversation( |
| 48 | responsibleAccountId, |
| 49 | responsibleConvUid, false) |
| 50 | CallAdapter.placeAudioOnlyCall() |
| 51 | }) |
| 52 | ContextMenuGenerator.addMenuItem(qsTr("Clear conversation"), |
| 53 | "qrc:/images/icons/ic_clear_24px.svg", |
| 54 | function (){ |
| 55 | ClientWrapper.utilsAdaptor.clearConversationHistory( |
| 56 | responsibleAccountId, |
| 57 | responsibleConvUid) |
| 58 | }) |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 59 | |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 60 | if (contactType === Profile.Type.RING || contactType === Profile.Type.SIP) { |
| 61 | ContextMenuGenerator.addMenuItem(qsTr("Remove contact"), |
| 62 | "qrc:/images/icons/round-remove_circle-24px.svg", |
| 63 | function (){ |
| 64 | ClientWrapper.utilsAdaptor.removeConversation( |
| 65 | responsibleAccountId, |
| 66 | responsibleConvUid) |
| 67 | }) |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 68 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 69 | |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 70 | if (contactType === Profile.Type.RING || contactType === Profile.Type.PENDING) { |
| 71 | ContextMenuGenerator.addMenuSeparator() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 72 | |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 73 | if (contactType === Profile.Type.PENDING) { |
| 74 | ContextMenuGenerator.addMenuItem(qsTr("Accept request"), |
| 75 | "qrc:/images/icons/person_add-24px.svg", |
| 76 | function (){ |
| 77 | MessagesAdapter.acceptInvitation( |
| 78 | responsibleConvUid) |
| 79 | }) |
| 80 | ContextMenuGenerator.addMenuItem(qsTr("Decline request"), |
| 81 | "qrc:/images/icons/round-close-24px.svg", |
| 82 | function (){ |
| 83 | MessagesAdapter.refuseInvitation( |
| 84 | responsibleConvUid) |
| 85 | }) |
| 86 | } |
| 87 | ContextMenuGenerator.addMenuItem(qsTr("Block contact"), |
| 88 | "qrc:/images/icons/ic_block_24px.svg", |
| 89 | function (){ |
| 90 | MessagesAdapter.blockConversation( |
| 91 | responsibleConvUid) |
| 92 | }) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 93 | |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 94 | ContextMenuGenerator.addMenuSeparator() |
| 95 | ContextMenuGenerator.addMenuItem(qsTr("Profile"), |
| 96 | "qrc:/images/icons/person-24px.svg", |
| 97 | function (){ |
| 98 | userProfile.open() |
| 99 | }) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 100 | } |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 101 | |
| 102 | root.height = ContextMenuGenerator.getMenu().height |
| 103 | root.width = ContextMenuGenerator.getMenu().width |
| 104 | ContextMenuGenerator.getMenu().open() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Ming Rui Zhang | 9680887 | 2020-08-27 12:59:09 -0400 | [diff] [blame] | 107 | Component.onCompleted: { |
| 108 | ContextMenuGenerator.createBaseContextMenuObjects(root) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 109 | } |
| 110 | } |