2023-05-01 13:51:46 -04:00
|
|
|
import QtCore
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Controls.Basic
|
|
|
|
import QtQuick.Layouts
|
2023-06-22 15:44:49 -04:00
|
|
|
import chatlistmodel
|
2023-05-01 13:51:46 -04:00
|
|
|
import llm
|
|
|
|
import download
|
|
|
|
import network
|
2023-06-28 16:05:35 -04:00
|
|
|
import mysettings
|
2023-05-01 13:51:46 -04:00
|
|
|
|
2024-03-13 08:53:53 -04:00
|
|
|
Rectangle {
|
2023-05-01 13:51:46 -04:00
|
|
|
id: chatDrawer
|
|
|
|
|
|
|
|
Theme {
|
|
|
|
id: theme
|
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
color: theme.viewBackground
|
2023-05-01 13:51:46 -04:00
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
Rectangle {
|
|
|
|
id: borderRight
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
2024-06-27 07:16:11 -04:00
|
|
|
width: 1
|
2024-06-24 18:49:23 -04:00
|
|
|
color: theme.dividerColor
|
|
|
|
}
|
2024-03-20 11:09:59 -04:00
|
|
|
|
2023-05-01 13:51:46 -04:00
|
|
|
Item {
|
2024-06-24 18:49:23 -04:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: borderRight.left
|
2023-05-01 13:51:46 -04:00
|
|
|
|
|
|
|
Accessible.role: Accessible.Pane
|
2023-10-21 10:38:46 -04:00
|
|
|
Accessible.name: qsTr("Drawer")
|
|
|
|
Accessible.description: qsTr("Main navigation drawer")
|
2023-05-01 13:51:46 -04:00
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
MySettingsButton {
|
2023-05-01 17:13:20 -04:00
|
|
|
id: newChat
|
2024-06-24 18:49:23 -04:00
|
|
|
anchors.top: parent.top
|
2023-05-01 17:13:20 -04:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2024-06-24 18:49:23 -04:00
|
|
|
anchors.margins: 20
|
2023-05-01 17:13:20 -04:00
|
|
|
font.pixelSize: theme.fontSizeLarger
|
2024-06-27 07:16:11 -04:00
|
|
|
topPadding: 24
|
|
|
|
bottomPadding: 24
|
2024-06-28 17:11:12 -04:00
|
|
|
text: qsTr("\uFF0B New Chat")
|
2023-10-21 10:38:46 -04:00
|
|
|
Accessible.description: qsTr("Create a new chat")
|
2023-05-01 17:13:20 -04:00
|
|
|
onClicked: {
|
2024-05-15 14:09:32 -04:00
|
|
|
ChatListModel.addChat()
|
|
|
|
conversationList.positionViewAtIndex(0, ListView.Beginning)
|
2024-04-25 13:16:52 -04:00
|
|
|
Network.trackEvent("new_chat", {"number_of_chats": ChatListModel.count})
|
2023-05-01 17:13:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
Rectangle {
|
|
|
|
id: divider
|
|
|
|
anchors.top: newChat.bottom
|
|
|
|
anchors.margins: 20
|
2024-06-27 07:16:11 -04:00
|
|
|
anchors.topMargin: 14
|
2024-06-24 18:49:23 -04:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
height: 1
|
|
|
|
color: theme.dividerColor
|
|
|
|
}
|
|
|
|
|
2023-05-01 20:27:07 -04:00
|
|
|
ScrollView {
|
2023-05-01 13:51:46 -04:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2024-06-24 18:49:23 -04:00
|
|
|
anchors.topMargin: 15
|
|
|
|
anchors.top: divider.bottom
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: 15
|
2023-07-31 12:18:38 -04:00
|
|
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
2023-05-13 19:33:19 -04:00
|
|
|
clip: true
|
2023-05-01 17:13:20 -04:00
|
|
|
|
2023-05-01 20:27:07 -04:00
|
|
|
ListView {
|
|
|
|
id: conversationList
|
|
|
|
anchors.fill: parent
|
2024-06-24 18:49:23 -04:00
|
|
|
anchors.leftMargin: 10
|
2023-05-01 20:27:07 -04:00
|
|
|
anchors.rightMargin: 10
|
2023-06-22 15:44:49 -04:00
|
|
|
model: ChatListModel
|
2024-05-15 14:09:32 -04:00
|
|
|
|
|
|
|
Component.onCompleted: ChatListModel.loadChats()
|
|
|
|
|
2024-01-22 14:41:47 -05:00
|
|
|
ScrollBar.vertical: ScrollBar {
|
|
|
|
parent: conversationList.parent
|
|
|
|
anchors.top: conversationList.top
|
|
|
|
anchors.left: conversationList.right
|
|
|
|
anchors.bottom: conversationList.bottom
|
|
|
|
}
|
2023-05-01 20:27:07 -04:00
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
Component {
|
|
|
|
id: sectionHeading
|
|
|
|
Rectangle {
|
|
|
|
width: ListView.view.width
|
|
|
|
height: childrenRect.height
|
|
|
|
color: "transparent"
|
|
|
|
property bool isServer: ChatListModel.get(parent.index) && ChatListModel.get(parent.index).isServer
|
|
|
|
visible: !isServer || MySettings.serverChat
|
|
|
|
|
|
|
|
required property string section
|
|
|
|
|
|
|
|
Text {
|
|
|
|
leftPadding: 10
|
|
|
|
rightPadding: 10
|
|
|
|
topPadding: 15
|
|
|
|
bottomPadding: 5
|
|
|
|
text: parent.section
|
2024-06-26 13:48:02 -04:00
|
|
|
color: theme.chatDrawerSectionHeader
|
2024-06-28 12:57:57 -04:00
|
|
|
font.pixelSize: theme.fontSizeSmallest
|
2024-06-24 18:49:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
section.property: "section"
|
|
|
|
section.criteria: ViewSection.FullString
|
|
|
|
section.delegate: sectionHeading
|
|
|
|
|
2023-05-01 20:27:07 -04:00
|
|
|
delegate: Rectangle {
|
|
|
|
id: chatRectangle
|
2023-05-01 20:56:53 -04:00
|
|
|
width: conversationList.width
|
2023-05-01 20:27:07 -04:00
|
|
|
height: chatName.height
|
2023-06-22 15:44:49 -04:00
|
|
|
property bool isCurrent: ChatListModel.currentChat === ChatListModel.get(index)
|
|
|
|
property bool isServer: ChatListModel.get(index) && ChatListModel.get(index).isServer
|
2023-05-02 12:36:21 -04:00
|
|
|
property bool trashQuestionDisplayed: false
|
2023-06-28 16:05:35 -04:00
|
|
|
visible: !isServer || MySettings.serverChat
|
2023-05-04 15:31:41 -04:00
|
|
|
z: isCurrent ? 199 : 1
|
2024-06-24 18:49:23 -04:00
|
|
|
color: isCurrent ? theme.selectedBackground : "transparent"
|
2023-05-01 20:27:07 -04:00
|
|
|
border.width: isCurrent
|
2024-06-24 18:49:23 -04:00
|
|
|
border.color: theme.dividerColor
|
|
|
|
radius: 10
|
|
|
|
|
2023-05-02 11:19:17 -04:00
|
|
|
TextField {
|
2023-05-01 20:27:07 -04:00
|
|
|
id: chatName
|
|
|
|
anchors.left: parent.left
|
2023-05-01 20:56:53 -04:00
|
|
|
anchors.right: buttons.left
|
2024-06-24 18:49:23 -04:00
|
|
|
color: theme.styledTextColor
|
|
|
|
topPadding: 15
|
|
|
|
bottomPadding: 15
|
2023-05-01 20:27:07 -04:00
|
|
|
focus: false
|
|
|
|
readOnly: true
|
|
|
|
wrapMode: Text.NoWrap
|
|
|
|
hoverEnabled: false // Disable hover events on the TextArea
|
|
|
|
selectByMouse: false // Disable text selection in the TextArea
|
2024-03-13 08:53:53 -04:00
|
|
|
font.pixelSize: theme.fontSizeLarge
|
2024-06-24 18:49:23 -04:00
|
|
|
font.bold: true
|
2023-05-02 11:19:17 -04:00
|
|
|
text: readOnly ? metrics.elidedText : name
|
2023-05-01 20:27:07 -04:00
|
|
|
horizontalAlignment: TextInput.AlignLeft
|
2023-05-02 12:36:21 -04:00
|
|
|
opacity: trashQuestionDisplayed ? 0.5 : 1.0
|
2023-05-02 11:19:17 -04:00
|
|
|
TextMetrics {
|
|
|
|
id: metrics
|
|
|
|
font: chatName.font
|
|
|
|
text: name
|
|
|
|
elide: Text.ElideRight
|
2024-06-24 18:49:23 -04:00
|
|
|
elideWidth: chatName.width - 15
|
2023-05-02 11:19:17 -04:00
|
|
|
}
|
2023-05-01 20:27:07 -04:00
|
|
|
background: Rectangle {
|
|
|
|
color: "transparent"
|
|
|
|
}
|
|
|
|
onEditingFinished: {
|
2023-05-04 15:31:41 -04:00
|
|
|
// Work around a bug in qml where we're losing focus when the whole window
|
|
|
|
// goes out of focus even though this textfield should be marked as not
|
|
|
|
// having focus
|
|
|
|
if (chatName.readOnly)
|
|
|
|
return;
|
2024-04-25 13:16:52 -04:00
|
|
|
Network.trackChatEvent("rename_chat")
|
2023-05-01 20:27:07 -04:00
|
|
|
changeName();
|
|
|
|
}
|
|
|
|
function changeName() {
|
2023-06-22 15:44:49 -04:00
|
|
|
ChatListModel.get(index).name = chatName.text
|
2023-05-01 20:27:07 -04:00
|
|
|
chatName.focus = false
|
|
|
|
chatName.readOnly = true
|
2023-05-02 11:19:17 -04:00
|
|
|
chatName.selectByMouse = false
|
2023-05-01 20:27:07 -04:00
|
|
|
}
|
|
|
|
TapHandler {
|
|
|
|
onTapped: {
|
|
|
|
if (isCurrent)
|
|
|
|
return;
|
2023-06-22 15:44:49 -04:00
|
|
|
ChatListModel.currentChat = ChatListModel.get(index);
|
2023-05-01 20:27:07 -04:00
|
|
|
}
|
|
|
|
}
|
2023-05-02 12:36:21 -04:00
|
|
|
Accessible.role: Accessible.Button
|
2024-02-07 10:37:15 -05:00
|
|
|
Accessible.name: text
|
2023-10-21 10:38:46 -04:00
|
|
|
Accessible.description: qsTr("Select the current chat or edit the chat when in edit mode")
|
2023-05-01 20:27:07 -04:00
|
|
|
}
|
2023-05-01 20:56:53 -04:00
|
|
|
Row {
|
|
|
|
id: buttons
|
2023-05-01 20:27:07 -04:00
|
|
|
anchors.verticalCenter: chatName.verticalCenter
|
|
|
|
anchors.right: chatRectangle.right
|
|
|
|
anchors.rightMargin: 10
|
2024-06-26 11:36:50 -04:00
|
|
|
spacing: 5
|
2023-05-31 21:07:14 -04:00
|
|
|
MyToolButton {
|
2023-05-01 20:56:53 -04:00
|
|
|
id: editButton
|
2024-06-26 11:36:50 -04:00
|
|
|
imageWidth: 24
|
|
|
|
imageHeight: 24
|
2023-05-11 16:46:25 -04:00
|
|
|
visible: isCurrent && !isServer
|
2023-05-02 12:36:21 -04:00
|
|
|
opacity: trashQuestionDisplayed ? 0.5 : 1.0
|
2023-05-31 21:07:14 -04:00
|
|
|
source: "qrc:/gpt4all/icons/edit.svg"
|
2023-05-01 20:56:53 -04:00
|
|
|
onClicked: {
|
|
|
|
chatName.focus = true
|
|
|
|
chatName.readOnly = false
|
2023-05-02 11:19:17 -04:00
|
|
|
chatName.selectByMouse = true
|
2023-05-01 20:56:53 -04:00
|
|
|
}
|
2023-10-21 10:38:46 -04:00
|
|
|
Accessible.name: qsTr("Edit chat name")
|
2023-05-01 20:27:07 -04:00
|
|
|
}
|
2023-05-31 21:07:14 -04:00
|
|
|
MyToolButton {
|
2023-05-11 16:46:25 -04:00
|
|
|
id: trashButton
|
2024-06-26 11:36:50 -04:00
|
|
|
imageWidth: 24
|
|
|
|
imageHeight: 24
|
2023-05-11 16:46:25 -04:00
|
|
|
visible: isCurrent && !isServer
|
2023-05-31 21:07:14 -04:00
|
|
|
source: "qrc:/gpt4all/icons/trash.svg"
|
2023-05-01 20:56:53 -04:00
|
|
|
onClicked: {
|
2023-05-02 12:36:21 -04:00
|
|
|
trashQuestionDisplayed = true
|
|
|
|
timer.start()
|
2023-05-01 20:56:53 -04:00
|
|
|
}
|
2023-10-21 10:38:46 -04:00
|
|
|
Accessible.name: qsTr("Delete chat")
|
2023-05-01 20:27:07 -04:00
|
|
|
}
|
|
|
|
}
|
2023-05-02 12:36:21 -04:00
|
|
|
Rectangle {
|
|
|
|
id: trashSureQuestion
|
|
|
|
anchors.top: buttons.bottom
|
|
|
|
anchors.topMargin: 10
|
|
|
|
anchors.right: buttons.right
|
|
|
|
width: childrenRect.width
|
|
|
|
height: childrenRect.height
|
|
|
|
color: chatRectangle.color
|
|
|
|
visible: isCurrent && trashQuestionDisplayed
|
|
|
|
opacity: 1.0
|
|
|
|
radius: 10
|
2023-05-04 15:31:41 -04:00
|
|
|
z: 200
|
2023-05-02 12:36:21 -04:00
|
|
|
Row {
|
|
|
|
spacing: 10
|
|
|
|
Button {
|
|
|
|
id: checkMark
|
|
|
|
width: 30
|
|
|
|
height: 30
|
|
|
|
contentItem: Text {
|
|
|
|
color: theme.textErrorColor
|
|
|
|
text: "\u2713"
|
|
|
|
font.pixelSize: theme.fontSizeLarger
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
background: Rectangle {
|
|
|
|
width: 30
|
|
|
|
height: 30
|
|
|
|
color: "transparent"
|
|
|
|
}
|
|
|
|
onClicked: {
|
2024-04-25 13:16:52 -04:00
|
|
|
Network.trackChatEvent("remove_chat")
|
2023-06-22 15:44:49 -04:00
|
|
|
ChatListModel.removeChat(ChatListModel.get(index))
|
2023-05-02 12:36:21 -04:00
|
|
|
}
|
|
|
|
Accessible.role: Accessible.Button
|
2023-10-21 10:38:46 -04:00
|
|
|
Accessible.name: qsTr("Confirm chat deletion")
|
2023-05-02 12:36:21 -04:00
|
|
|
}
|
|
|
|
Button {
|
|
|
|
id: cancel
|
|
|
|
width: 30
|
|
|
|
height: 30
|
|
|
|
contentItem: Text {
|
|
|
|
color: theme.textColor
|
|
|
|
text: "\u2715"
|
|
|
|
font.pixelSize: theme.fontSizeLarger
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
background: Rectangle {
|
|
|
|
width: 30
|
|
|
|
height: 30
|
|
|
|
color: "transparent"
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
trashQuestionDisplayed = false
|
|
|
|
}
|
|
|
|
Accessible.role: Accessible.Button
|
2023-10-21 10:38:46 -04:00
|
|
|
Accessible.name: qsTr("Cancel chat deletion")
|
2023-05-02 12:36:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
interval: 3000; running: false; repeat: false
|
|
|
|
onTriggered: trashQuestionDisplayed = false
|
|
|
|
}
|
2023-05-01 17:13:20 -04:00
|
|
|
}
|
2023-05-01 13:51:46 -04:00
|
|
|
|
2023-05-01 20:27:07 -04:00
|
|
|
Accessible.role: Accessible.List
|
|
|
|
Accessible.name: qsTr("List of chats")
|
|
|
|
Accessible.description: qsTr("List of chats in the drawer dialog")
|
|
|
|
}
|
2023-05-01 13:51:46 -04:00
|
|
|
}
|
|
|
|
}
|
2023-07-31 12:18:38 -04:00
|
|
|
}
|