2023-05-01 17:51:46 +00:00
|
|
|
import QtCore
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Controls.Basic
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import llm
|
|
|
|
import download
|
|
|
|
import network
|
|
|
|
|
|
|
|
Drawer {
|
|
|
|
id: chatDrawer
|
|
|
|
modal: false
|
|
|
|
opacity: 0.9
|
|
|
|
|
|
|
|
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
|
|
|
|
color: theme.backgroundDarkest
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
Accessible.name: qsTr("Drawer on the left of the application")
|
|
|
|
Accessible.description: qsTr("Drawer that is revealed by pressing the hamburger button")
|
|
|
|
|
2023-05-01 21:13:20 +00:00
|
|
|
Button {
|
|
|
|
id: newChat
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
padding: 15
|
|
|
|
font.pixelSize: theme.fontSizeLarger
|
|
|
|
background: Rectangle {
|
|
|
|
color: theme.backgroundDarkest
|
|
|
|
opacity: .5
|
|
|
|
border.color: theme.backgroundLightest
|
|
|
|
border.width: 1
|
|
|
|
radius: 10
|
|
|
|
}
|
|
|
|
contentItem: Text {
|
|
|
|
text: qsTr("New chat")
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: theme.textColor
|
|
|
|
|
|
|
|
Accessible.role: Accessible.Button
|
|
|
|
Accessible.name: text
|
|
|
|
Accessible.description: qsTr("Use this to launch an external application that will check for updates to the installer")
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
LLM.chatListModel.addChat();
|
2023-05-03 00:31:17 +00:00
|
|
|
Network.sendNewChat(LLM.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
|
|
|
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
|
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
|
|
|
|
|
|
|
|
model: LLM.chatListModel
|
|
|
|
|
|
|
|
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
|
|
|
|
opacity: 0.9
|
|
|
|
property bool isCurrent: LLM.chatListModel.currentChat === LLM.chatListModel.get(index)
|
2023-05-11 20:46:25 +00:00
|
|
|
property bool isServer: LLM.chatListModel.get(index) && LLM.chatListModel.get(index).isServer
|
2023-05-02 16:36:21 +00:00
|
|
|
property bool trashQuestionDisplayed: false
|
2023-05-11 20:46:25 +00:00
|
|
|
visible: !isServer || LLM.serverEnabled
|
2023-05-04 19:31:41 +00:00
|
|
|
z: isCurrent ? 199 : 1
|
2023-05-11 20:46:25 +00:00
|
|
|
color: isServer ? theme.backgroundDarkest : (index % 2 === 0 ? theme.backgroundLight : theme.backgroundLighter)
|
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
|
|
|
|
elideWidth: chatName.width - 25
|
|
|
|
}
|
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() {
|
|
|
|
LLM.chatListModel.get(index).name = chatName.text
|
|
|
|
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;
|
|
|
|
LLM.chatListModel.currentChat = LLM.chatListModel.get(index);
|
|
|
|
}
|
|
|
|
}
|
2023-05-02 16:36:21 +00:00
|
|
|
Accessible.role: Accessible.Button
|
|
|
|
Accessible.name: qsTr("Select the current chat")
|
|
|
|
Accessible.description: qsTr("Provides a button to 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
|
|
|
|
Button {
|
|
|
|
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-05-02 00:56:53 +00:00
|
|
|
background: Image {
|
|
|
|
width: 30
|
|
|
|
height: 30
|
|
|
|
source: "qrc:/gpt4all/icons/edit.svg"
|
|
|
|
}
|
|
|
|
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-05-02 16:36:21 +00:00
|
|
|
Accessible.role: Accessible.Button
|
|
|
|
Accessible.name: qsTr("Edit the chat name")
|
|
|
|
Accessible.description: qsTr("Provides a button to edit the chat name")
|
2023-05-02 00:27:07 +00:00
|
|
|
}
|
2023-05-02 00:56:53 +00:00
|
|
|
Button {
|
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-05-02 00:56:53 +00:00
|
|
|
background: Image {
|
|
|
|
width: 30
|
|
|
|
height: 30
|
|
|
|
source: "qrc:/gpt4all/icons/trash.svg"
|
|
|
|
}
|
|
|
|
onClicked: {
|
2023-05-02 16:36:21 +00:00
|
|
|
trashQuestionDisplayed = true
|
|
|
|
timer.start()
|
2023-05-02 00:56:53 +00:00
|
|
|
}
|
2023-05-02 16:36:21 +00:00
|
|
|
Accessible.role: Accessible.Button
|
|
|
|
Accessible.name: qsTr("Delete of the chat")
|
|
|
|
Accessible.description: qsTr("Provides a button to delete the 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: {
|
|
|
|
LLM.chatListModel.removeChat(LLM.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
|
|
|
|
Accessible.name: qsTr("Confirm delete of the chat")
|
|
|
|
Accessible.description: qsTr("Provides a button to confirm delete of the chat")
|
|
|
|
}
|
|
|
|
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
|
|
|
|
Accessible.name: qsTr("Cancel the delete of the chat")
|
|
|
|
Accessible.description: qsTr("Provides a button to cancel delete of the chat")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
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-01 17:51:46 +00:00
|
|
|
padding: 15
|
|
|
|
contentItem: Text {
|
2023-05-10 00:54:16 +00:00
|
|
|
text: qsTr("Updates")
|
2023-05-01 17:51:46 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: theme.textColor
|
|
|
|
|
|
|
|
Accessible.role: Accessible.Button
|
|
|
|
Accessible.name: text
|
|
|
|
Accessible.description: qsTr("Use this to launch an external application that will check for updates to the installer")
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
opacity: .5
|
|
|
|
border.color: theme.backgroundLightest
|
|
|
|
border.width: 1
|
|
|
|
radius: 10
|
|
|
|
color: theme.backgroundLight
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (!LLM.checkForUpdates())
|
|
|
|
checkForUpdatesError.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
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-01 17:51:46 +00:00
|
|
|
padding: 15
|
|
|
|
contentItem: Text {
|
2023-05-10 00:54:16 +00:00
|
|
|
text: qsTr("Downloads")
|
2023-05-01 17:51:46 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: theme.textColor
|
|
|
|
|
|
|
|
Accessible.role: Accessible.Button
|
|
|
|
Accessible.name: text
|
|
|
|
Accessible.description: qsTr("Use this to launch a dialog to download new models")
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
opacity: .5
|
|
|
|
border.color: theme.backgroundLightest
|
|
|
|
border.width: 1
|
|
|
|
radius: 10
|
|
|
|
color: theme.backgroundLight
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Button {
|
|
|
|
id: aboutButton
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
padding: 15
|
|
|
|
contentItem: Text {
|
|
|
|
text: qsTr("About")
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: theme.textColor
|
|
|
|
|
|
|
|
Accessible.role: Accessible.Button
|
|
|
|
Accessible.name: text
|
|
|
|
Accessible.description: qsTr("Use this to launch a dialog to show the about page")
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
opacity: .5
|
|
|
|
border.color: theme.backgroundLightest
|
|
|
|
border.width: 1
|
|
|
|
radius: 10
|
|
|
|
color: theme.backgroundLight
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
aboutClicked()
|
|
|
|
}
|
|
|
|
}
|
2023-05-01 17:51:46 +00:00
|
|
|
}
|
|
|
|
}
|