2023-05-01 17:51:46 +00:00
|
|
|
import QtCore
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Controls.Basic
|
|
|
|
import QtQuick.Layouts
|
2023-06-22 19:44:49 +00:00
|
|
|
import chatlistmodel
|
2023-05-01 17:51:46 +00:00
|
|
|
import llm
|
|
|
|
import download
|
|
|
|
import network
|
2023-06-28 20:05:35 +00:00
|
|
|
import mysettings
|
2023-05-01 17:51:46 +00:00
|
|
|
|
|
|
|
Drawer {
|
|
|
|
id: chatDrawer
|
|
|
|
modal: false
|
|
|
|
|
|
|
|
Theme {
|
|
|
|
id: theme
|
|
|
|
}
|
|
|
|
|
|
|
|
signal downloadClicked
|
2023-05-05 14:47:05 +00:00
|
|
|
signal aboutClicked
|
2023-05-01 17:51:46 +00:00
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
height: parent.height
|
2024-01-22 19:41:47 +00:00
|
|
|
color: theme.containerBackground
|
2023-05-01 17:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
anchors.fill: parent
|
2023-05-01 21:13:20 +00:00
|
|
|
anchors.margins: 10
|
2023-05-01 17:51:46 +00:00
|
|
|
|
|
|
|
Accessible.role: Accessible.Pane
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.name: qsTr("Drawer")
|
|
|
|
Accessible.description: qsTr("Main navigation drawer")
|
2023-05-01 17:51:46 +00:00
|
|
|
|
2023-05-22 18:17:45 +00:00
|
|
|
MyButton {
|
2023-05-01 21:13:20 +00:00
|
|
|
id: newChat
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
font.pixelSize: theme.fontSizeLarger
|
2023-06-01 00:42:00 +00:00
|
|
|
topPadding: 20
|
|
|
|
bottomPadding: 20
|
|
|
|
text: qsTr("\uFF0B New chat")
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.description: qsTr("Create a new chat")
|
2023-05-01 21:13:20 +00:00
|
|
|
onClicked: {
|
2023-06-22 19:44:49 +00:00
|
|
|
ChatListModel.addChat();
|
|
|
|
Network.sendNewChat(ChatListModel.count)
|
2023-05-01 21:13:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-02 00:27:07 +00:00
|
|
|
ScrollView {
|
2023-05-01 17:51:46 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2023-05-02 00:27:07 +00:00
|
|
|
anchors.rightMargin: -10
|
2023-05-01 21:13:20 +00:00
|
|
|
anchors.topMargin: 10
|
|
|
|
anchors.top: newChat.bottom
|
|
|
|
anchors.bottom: checkForUpdatesButton.top
|
2023-05-02 00:27:07 +00:00
|
|
|
anchors.bottomMargin: 10
|
2023-07-31 16:18:38 +00:00
|
|
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
2023-05-13 23:33:19 +00:00
|
|
|
clip: true
|
2023-05-01 21:13:20 +00:00
|
|
|
|
2023-05-02 00:27:07 +00:00
|
|
|
ListView {
|
|
|
|
id: conversationList
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.rightMargin: 10
|
2023-06-22 19:44:49 +00:00
|
|
|
model: ChatListModel
|
2024-01-22 19:41:47 +00:00
|
|
|
ScrollBar.vertical: ScrollBar {
|
|
|
|
parent: conversationList.parent
|
|
|
|
anchors.top: conversationList.top
|
|
|
|
anchors.left: conversationList.right
|
|
|
|
anchors.bottom: conversationList.bottom
|
|
|
|
}
|
2023-05-02 00:27:07 +00:00
|
|
|
|
|
|
|
delegate: Rectangle {
|
|
|
|
id: chatRectangle
|
2023-05-02 00:56:53 +00:00
|
|
|
width: conversationList.width
|
2023-05-02 00:27:07 +00:00
|
|
|
height: chatName.height
|
2023-06-22 19:44:49 +00:00
|
|
|
property bool isCurrent: ChatListModel.currentChat === ChatListModel.get(index)
|
|
|
|
property bool isServer: ChatListModel.get(index) && ChatListModel.get(index).isServer
|
2023-05-02 16:36:21 +00:00
|
|
|
property bool trashQuestionDisplayed: false
|
2023-06-28 20:05:35 +00:00
|
|
|
visible: !isServer || MySettings.serverChat
|
2023-05-04 19:31:41 +00:00
|
|
|
z: isCurrent ? 199 : 1
|
2024-01-22 19:41:47 +00:00
|
|
|
color: index % 2 === 0 ? theme.darkContrast : theme.lightContrast
|
2023-05-02 00:27:07 +00:00
|
|
|
border.width: isCurrent
|
2023-05-02 15:34:39 +00:00
|
|
|
border.color: chatName.readOnly ? theme.assistantColor : theme.userColor
|
2023-05-02 15:19:17 +00:00
|
|
|
TextField {
|
2023-05-02 00:27:07 +00:00
|
|
|
id: chatName
|
|
|
|
anchors.left: parent.left
|
2023-05-02 00:56:53 +00:00
|
|
|
anchors.right: buttons.left
|
2023-05-02 00:27:07 +00:00
|
|
|
color: theme.textColor
|
|
|
|
padding: 15
|
|
|
|
focus: false
|
|
|
|
readOnly: true
|
|
|
|
wrapMode: Text.NoWrap
|
|
|
|
hoverEnabled: false // Disable hover events on the TextArea
|
|
|
|
selectByMouse: false // Disable text selection in the TextArea
|
|
|
|
font.pixelSize: theme.fontSizeLarger
|
2023-05-02 15:19:17 +00:00
|
|
|
text: readOnly ? metrics.elidedText : name
|
2023-05-02 00:27:07 +00:00
|
|
|
horizontalAlignment: TextInput.AlignLeft
|
2023-05-02 16:36:21 +00:00
|
|
|
opacity: trashQuestionDisplayed ? 0.5 : 1.0
|
2023-05-02 15:19:17 +00:00
|
|
|
TextMetrics {
|
|
|
|
id: metrics
|
|
|
|
font: chatName.font
|
|
|
|
text: name
|
|
|
|
elide: Text.ElideRight
|
2024-01-22 19:41:47 +00:00
|
|
|
elideWidth: chatName.width - 40
|
2023-05-02 15:19:17 +00:00
|
|
|
}
|
2023-05-02 00:27:07 +00:00
|
|
|
background: Rectangle {
|
|
|
|
color: "transparent"
|
|
|
|
}
|
|
|
|
onEditingFinished: {
|
2023-05-04 19:31:41 +00: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;
|
2023-05-02 00:27:07 +00:00
|
|
|
changeName();
|
2023-05-03 00:31:17 +00:00
|
|
|
Network.sendRenameChat()
|
2023-05-02 00:27:07 +00:00
|
|
|
}
|
|
|
|
function changeName() {
|
2023-06-22 19:44:49 +00:00
|
|
|
ChatListModel.get(index).name = chatName.text
|
2023-05-02 00:27:07 +00:00
|
|
|
chatName.focus = false
|
|
|
|
chatName.readOnly = true
|
2023-05-02 15:19:17 +00:00
|
|
|
chatName.selectByMouse = false
|
2023-05-02 00:27:07 +00:00
|
|
|
}
|
|
|
|
TapHandler {
|
|
|
|
onTapped: {
|
|
|
|
if (isCurrent)
|
|
|
|
return;
|
2023-06-22 19:44:49 +00:00
|
|
|
ChatListModel.currentChat = ChatListModel.get(index);
|
2023-05-02 00:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-02 16:36:21 +00:00
|
|
|
Accessible.role: Accessible.Button
|
2024-02-07 15:37:15 +00:00
|
|
|
Accessible.name: text
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.description: qsTr("Select the current chat or edit the chat when in edit mode")
|
2023-05-02 00:27:07 +00:00
|
|
|
}
|
2023-05-02 00:56:53 +00:00
|
|
|
Row {
|
|
|
|
id: buttons
|
2023-05-02 00:27:07 +00:00
|
|
|
anchors.verticalCenter: chatName.verticalCenter
|
|
|
|
anchors.right: chatRectangle.right
|
|
|
|
anchors.rightMargin: 10
|
2023-05-02 00:56:53 +00:00
|
|
|
spacing: 10
|
2023-06-01 01:07:14 +00:00
|
|
|
MyToolButton {
|
2023-05-02 00:56:53 +00:00
|
|
|
id: editButton
|
2023-05-02 00:27:07 +00:00
|
|
|
width: 30
|
|
|
|
height: 30
|
2023-05-11 20:46:25 +00:00
|
|
|
visible: isCurrent && !isServer
|
2023-05-02 16:36:21 +00:00
|
|
|
opacity: trashQuestionDisplayed ? 0.5 : 1.0
|
2023-06-01 01:07:14 +00:00
|
|
|
source: "qrc:/gpt4all/icons/edit.svg"
|
2023-05-02 00:56:53 +00:00
|
|
|
onClicked: {
|
|
|
|
chatName.focus = true
|
|
|
|
chatName.readOnly = false
|
2023-05-02 15:19:17 +00:00
|
|
|
chatName.selectByMouse = true
|
2023-05-02 00:56:53 +00:00
|
|
|
}
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.name: qsTr("Edit chat name")
|
2023-05-02 00:27:07 +00:00
|
|
|
}
|
2023-06-01 01:07:14 +00:00
|
|
|
MyToolButton {
|
2023-05-11 20:46:25 +00:00
|
|
|
id: trashButton
|
2023-05-02 00:56:53 +00:00
|
|
|
width: 30
|
|
|
|
height: 30
|
2023-05-11 20:46:25 +00:00
|
|
|
visible: isCurrent && !isServer
|
2023-06-01 01:07:14 +00:00
|
|
|
source: "qrc:/gpt4all/icons/trash.svg"
|
2023-05-02 00:56:53 +00:00
|
|
|
onClicked: {
|
2023-05-02 16:36:21 +00:00
|
|
|
trashQuestionDisplayed = true
|
|
|
|
timer.start()
|
2023-05-02 00:56:53 +00:00
|
|
|
}
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.name: qsTr("Delete chat")
|
2023-05-02 00:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-02 16:36:21 +00: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 19:31:41 +00:00
|
|
|
z: 200
|
2023-05-02 16:36:21 +00: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: {
|
2023-06-22 19:44:49 +00:00
|
|
|
ChatListModel.removeChat(ChatListModel.get(index))
|
2023-05-03 00:31:17 +00:00
|
|
|
Network.sendRemoveChat()
|
2023-05-02 16:36:21 +00:00
|
|
|
}
|
|
|
|
Accessible.role: Accessible.Button
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.name: qsTr("Confirm chat deletion")
|
2023-05-02 16:36:21 +00: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 14:38:46 +00:00
|
|
|
Accessible.name: qsTr("Cancel chat deletion")
|
2023-05-02 16:36:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
interval: 3000; running: false; repeat: false
|
|
|
|
onTriggered: trashQuestionDisplayed = false
|
|
|
|
}
|
2023-05-01 21:13:20 +00:00
|
|
|
}
|
2023-05-01 17:51:46 +00:00
|
|
|
|
2023-05-02 00:27:07 +00:00
|
|
|
Accessible.role: Accessible.List
|
|
|
|
Accessible.name: qsTr("List of chats")
|
|
|
|
Accessible.description: qsTr("List of chats in the drawer dialog")
|
|
|
|
}
|
2023-05-01 17:51:46 +00:00
|
|
|
}
|
|
|
|
|
2023-05-22 18:17:45 +00:00
|
|
|
MyButton {
|
2023-05-01 21:13:20 +00:00
|
|
|
id: checkForUpdatesButton
|
2023-05-01 17:51:46 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: downloadButton.top
|
2023-05-01 21:13:20 +00:00
|
|
|
anchors.bottomMargin: 10
|
2023-05-22 18:17:45 +00:00
|
|
|
text: qsTr("Updates")
|
2023-08-07 17:54:13 +00:00
|
|
|
font.pixelSize: theme.fontSizeLarge
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.description: qsTr("Launch an external application that will check for updates to the installer")
|
2023-05-01 17:51:46 +00:00
|
|
|
onClicked: {
|
|
|
|
if (!LLM.checkForUpdates())
|
|
|
|
checkForUpdatesError.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 18:17:45 +00:00
|
|
|
MyButton {
|
2023-05-01 17:51:46 +00:00
|
|
|
id: downloadButton
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2023-05-05 14:47:05 +00:00
|
|
|
anchors.bottom: aboutButton.top
|
|
|
|
anchors.bottomMargin: 10
|
2023-05-22 18:17:45 +00:00
|
|
|
text: qsTr("Downloads")
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.description: qsTr("Launch a dialog to download new models")
|
2023-05-01 17:51:46 +00:00
|
|
|
onClicked: {
|
2023-05-02 19:02:25 +00:00
|
|
|
downloadClicked()
|
|
|
|
}
|
2023-05-01 17:51:46 +00:00
|
|
|
}
|
2023-05-05 14:47:05 +00:00
|
|
|
|
2023-05-22 18:17:45 +00:00
|
|
|
MyButton {
|
2023-05-05 14:47:05 +00:00
|
|
|
id: aboutButton
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
2023-05-22 18:17:45 +00:00
|
|
|
text: qsTr("About")
|
2023-10-21 14:38:46 +00:00
|
|
|
Accessible.description: qsTr("Launch a dialog to show the about page")
|
2023-05-05 14:47:05 +00:00
|
|
|
onClicked: {
|
|
|
|
aboutClicked()
|
|
|
|
}
|
|
|
|
}
|
2023-05-01 17:51:46 +00:00
|
|
|
}
|
2023-07-31 16:18:38 +00:00
|
|
|
}
|