Skip to content

Commit

Permalink
Extend settings with selective delete for recent servers
Browse files Browse the repository at this point in the history
  • Loading branch information
basyskom-jvoe authored and khaexy committed Mar 13, 2024
1 parent a13067f commit 79d26be
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,25 @@ void BackEnd::trustCertificate()
connectToEndpoint();
}

void BackEnd::removeRecentConnection(const QString &name)
{
if (mLastServerHosts.contains(name)) {
mLastServerHosts.removeAll(name);

QSettings settings;
settings.remove(Constants::SettingsKey::RecentConnections);

settings.beginWriteArray(Constants::SettingsKey::RecentConnections);
for (qsizetype i = 0; i < qMin(10, mLastServerHosts.count()); ++i) {
settings.setArrayIndex(i);
settings.setValue(Constants::SettingsKey::Url, mLastServerHosts.at(i));
}
settings.endArray();

emit recentConnectionsChanged();
}
}

void BackEnd::saveLastDashboards()
{
Q_ASSERT(mDashboardItemModel);
Expand Down
2 changes: 2 additions & 0 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class BackEnd : public QObject
Q_INVOKABLE void useHostUrlForEndpointConnection();
Q_INVOKABLE void trustCertificate();

Q_INVOKABLE void removeRecentConnection(const QString &name);

signals:
void recentConnectionsChanged();
void serverListChanged();
Expand Down
89 changes: 89 additions & 0 deletions src/qml/SettingsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,95 @@ Rectangle {
}
}

// Recent connections list view
Column {
width: parent.width - content.leftPadding - content.rightPadding
spacing: 5

Text {
color: view.theme.textColor
font {
pointSize: 14
bold: true
}
text: qsTranslate("Connection", "Recent connections")
}

Rectangle {
color: view.theme.backgroundListView
radius: 5

width: parent.width
height: childrenRect.height

ListView {
id: recentConnectionsListView

width: parent.width
height: Math.min(200, contentHeight)

clip: true

model: BackEnd.recentConnections

boundsBehavior: Flickable.StopAtBounds
boundsMovement: Flickable.StopAtBounds

ScrollBar.vertical: StyledScrollBar {
policy: ScrollBar.AsNeeded
}

delegate: Rectangle {
id: recentConnectionsListViewDelegate

required property int index
required property string modelData

radius: 5
width: recentConnectionsListView.width
implicitHeight: childrenRect.height
color: "transparent"
clip: true

RowLayout {
width: parent.width
height: 30
spacing: 10

Text {
Layout.fillWidth: true
Layout.rightMargin: 5
Layout.leftMargin: 5
font {
pointSize: 11
}
text: modelData
color: view.theme.textColor
elide: Text.ElideRight
}

IconImage {
Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: 10
sourceSize.width: 24
sourceSize.height: 24
source: "qrc:/icons/delete.svg"
color: view.theme.textColor

MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: function() {
BackEnd.removeRecentConnection(modelData)
}
}
}
}
}
}
}
}

// Certificate list view
Column {
width: parent.width - content.leftPadding - content.rightPadding
Expand Down

0 comments on commit 79d26be

Please sign in to comment.