Skip to content

Commit 4b9dd9f

Browse files
Add the ability to change the directory via text field not just 'browse' button.
1 parent e223b47 commit 4b9dd9f

File tree

7 files changed

+67
-29
lines changed

7 files changed

+67
-29
lines changed

gpt4all-chat/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ qt_add_qml_module(chat
9494
qml/Theme.qml
9595
qml/MyButton.qml
9696
qml/MyComboBox.qml
97+
qml/MyDirectoryField.qml
9798
qml/MyTextField.qml
9899
qml/MyCheckBox.qml
99100
qml/MyBusyIndicator.qml

gpt4all-chat/llm.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ bool LLM::checkForUpdates() const
6363
return QProcess::startDetached(fileName);
6464
}
6565

66+
bool LLM::directoryExists(const QString &path) const
67+
{
68+
const QUrl url(path);
69+
const QString localFilePath = url.isLocalFile() ? url.toLocalFile() : path;
70+
const QFileInfo info(localFilePath);
71+
return info.exists() && info.isDir();
72+
}
73+
74+
bool LLM::fileExists(const QString &path) const
75+
{
76+
const QUrl url(path);
77+
const QString localFilePath = url.isLocalFile() ? url.toLocalFile() : path;
78+
const QFileInfo info(localFilePath);
79+
return info.exists() && info.isFile();
80+
}
81+
6682
int32_t LLM::threadCount() const
6783
{
6884
return m_threadCount;

gpt4all-chat/llm.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class LLM : public QObject
2525
bool compatHardware() const { return m_compatHardware; }
2626

2727
Q_INVOKABLE bool checkForUpdates() const;
28+
Q_INVOKABLE bool directoryExists(const QString &path) const;
29+
Q_INVOKABLE bool fileExists(const QString &path) const;
2830

2931
Q_SIGNALS:
3032
void chatListModelChanged();

gpt4all-chat/qml/LocalDocs.qml

+5-10
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import localdocs
99
Item {
1010
id: root
1111

12-
property string collection: ""
13-
property string folder_path: ""
12+
property alias collection: collection.text
13+
property alias folder_path: folderEdit.text
1414

1515
property int defaultChunkSize: 256
1616
property int defaultRetrievalSize: 3
@@ -60,24 +60,19 @@ Item {
6060
placeholderTextColor: theme.mutedTextColor
6161
ToolTip.text: qsTr("Name of the collection to add (Required)")
6262
ToolTip.visible: hovered
63-
onEditingFinished: {
64-
root.collection = text
65-
}
6663
Accessible.role: Accessible.EditableText
6764
Accessible.name: collection.text
6865
Accessible.description: ToolTip.text
6966
}
7067

71-
MyTextField {
72-
id: folderLabel
68+
MyDirectoryField {
69+
id: folderEdit
7370
anchors.left: collection.right
7471
anchors.leftMargin: 10
7572
anchors.right: browseButton.left
7673
anchors.rightMargin: 10
7774
anchors.verticalCenter: parent.verticalCenter
7875
text: root.folder_path
79-
readOnly: true
80-
color: theme.textColor
8176
placeholderText: qsTr("Folder path...")
8277
placeholderTextColor: theme.mutedTextColor
8378
ToolTip.text: qsTr("Folder path to documents (Required)")
@@ -100,7 +95,7 @@ Item {
10095
text: qsTr("Add")
10196
anchors.right: parent.right
10297
anchors.verticalCenter: parent.verticalCenter
103-
enabled: root.collection !== "" && root.folder_path != ""
98+
enabled: root.collection !== "" && root.folder_path !== "" && folderEdit.isValid
10499
Accessible.role: Accessible.Button
105100
Accessible.name: text
106101
Accessible.description: qsTr("Add button")

gpt4all-chat/qml/ModelDownloaderDialog.qml

+13-9
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ Dialog {
386386
title: "Please choose a directory"
387387
currentFolder: "file://" + Download.downloadLocalModelsPath
388388
onAccepted: {
389-
Download.downloadLocalModelsPath = selectedFolder
389+
modelPathDisplayField.text = selectedFolder
390+
Download.downloadLocalModelsPath = modelPathDisplayField.text
390391
settings.modelPath = Download.downloadLocalModelsPath
391392
settings.sync()
392393
}
@@ -398,20 +399,23 @@ Dialog {
398399
Layout.row: 1
399400
Layout.column: 0
400401
}
401-
TextField {
402-
id: modelPathDisplayLabel
402+
MyDirectoryField {
403+
id: modelPathDisplayField
403404
text: Download.downloadLocalModelsPath
404-
readOnly: true
405-
color: theme.textColor
406405
Layout.fillWidth: true
407406
ToolTip.text: qsTr("Path where model files will be downloaded to")
408407
ToolTip.visible: hovered
409408
Accessible.role: Accessible.ToolTip
410-
Accessible.name: modelPathDisplayLabel.text
409+
Accessible.name: modelPathDisplayField.text
411410
Accessible.description: ToolTip.text
412-
background: Rectangle {
413-
color: theme.backgroundLighter
414-
radius: 10
411+
onEditingFinished: {
412+
if (isValid) {
413+
Download.downloadLocalModelsPath = modelPathDisplayField.text
414+
settings.modelPath = Download.downloadLocalModelsPath
415+
settings.sync()
416+
} else {
417+
text = Download.downloadLocalModelsPath
418+
}
415419
}
416420
}
417421
MyButton {

gpt4all-chat/qml/MyDirectoryField.qml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import QtCore
2+
import QtQuick
3+
import QtQuick.Controls
4+
import QtQuick.Controls.Basic
5+
import llm
6+
7+
TextField {
8+
id: myDirectoryField
9+
padding: 10
10+
property bool isValid: LLM.directoryExists(text)
11+
color: text === "" || isValid ? theme.textColor : theme.textErrorColor
12+
background: Rectangle {
13+
implicitWidth: 150
14+
color: theme.backgroundLighter
15+
radius: 10
16+
}
17+
}

gpt4all-chat/qml/SettingsDialog.qml

+13-10
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,8 @@ Dialog {
651651
title: "Please choose a directory"
652652
currentFolder: "file://" + Download.downloadLocalModelsPath
653653
onAccepted: {
654-
Download.downloadLocalModelsPath = selectedFolder
654+
modelPathDisplayField.text = selectedFolder
655+
Download.downloadLocalModelsPath = modelPathDisplayField.text
655656
settings.modelPath = Download.downloadLocalModelsPath
656657
settings.sync()
657658
}
@@ -663,24 +664,26 @@ Dialog {
663664
Layout.row: 2
664665
Layout.column: 0
665666
}
666-
TextField {
667-
id: modelPathDisplayLabel
667+
MyDirectoryField {
668+
id: modelPathDisplayField
668669
text: Download.downloadLocalModelsPath
669-
readOnly: true
670-
color: theme.textColor
671670
implicitWidth: 300
672-
padding: 10
673671
Layout.row: 2
674672
Layout.column: 1
675673
Layout.fillWidth: true
676674
ToolTip.text: qsTr("Path where model files will be downloaded to")
677675
ToolTip.visible: hovered
678676
Accessible.role: Accessible.ToolTip
679-
Accessible.name: modelPathDisplayLabel.text
677+
Accessible.name: modelPathDisplayField.text
680678
Accessible.description: ToolTip.text
681-
background: Rectangle {
682-
color: theme.backgroundLighter
683-
radius: 10
679+
onEditingFinished: {
680+
if (isValid) {
681+
Download.downloadLocalModelsPath = modelPathDisplayField.text
682+
settings.modelPath = Download.downloadLocalModelsPath
683+
settings.sync()
684+
} else {
685+
text = Download.downloadLocalModelsPath
686+
}
684687
}
685688
}
686689
MyButton {

0 commit comments

Comments
 (0)