Skip to content

Commit

Permalink
dbhub: Log in by only selecting an identity, no need to press a button
Browse files Browse the repository at this point in the history
This removes the login button from the dbhub dock. Instead of selecting
an identity and then clicking the login button, you are now logged in by
just selecting an identity.
  • Loading branch information
MKleusberg committed Jun 13, 2020
1 parent fa3a0f5 commit 5cdda28
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
19 changes: 13 additions & 6 deletions src/RemoteDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RemoteDock::RemoteDock(MainWindow* parent)
ui->treeStructure->setModel(remoteModel);

// Reload the directory tree when a database upload has finished
connect(&remoteDatabase, &RemoteDatabase::uploadFinished, this, &RemoteDock::setNewIdentity);
connect(&remoteDatabase, &RemoteDatabase::uploadFinished, remoteModel, &RemoteModel::refresh);

// Whenever a new directory listing has been parsed, check if it was a new root dir and, if so, open the user's directory
connect(remoteModel, &RemoteModel::directoryListingParsed, this, &RemoteDock::newDirectoryNode);
Expand Down Expand Up @@ -53,8 +53,12 @@ RemoteDock::~RemoteDock()

void RemoteDock::reloadSettings()
{
// Load list of client certs
// Clear list of client certificates and add a dummy entry which does nothing except serve as
// an explanation to the user.
ui->comboUser->clear();
ui->comboUser->addItem(tr("Select an identity to connect"), "dummy");

// Load list of client certs
QStringList client_certs = Settings::getValue("remote", "client_certificates").toStringList();
for(const QString& file : client_certs)
{
Expand All @@ -67,13 +71,16 @@ void RemoteDock::reloadSettings()
ui->comboUser->addItem(tr("Public"), ":/user_certs/public.cert.pem");
}

void RemoteDock::setNewIdentity()
void RemoteDock::setNewIdentity(const QString& identity)
{
// Get identity
QString identity = ui->comboUser->currentText();
if(identity.isEmpty())
// Do nothing if the dummy entry was selected
if(ui->comboUser->currentData() == "dummy")
return;

// Check if the dummy item is still there and remove it if it is
if(ui->comboUser->itemData(0) == "dummy")
ui->comboUser->removeItem(0);

// Get certificate file name
QString cert = ui->comboUser->itemData(ui->comboUser->findText(identity), Qt::UserRole).toString();
if(cert.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion src/RemoteDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public slots:
void reject() override;

private slots:
void setNewIdentity();
void setNewIdentity(const QString& identity);
void fetchDatabase(const QModelIndex& idx);
void pushDatabase();
void newDirectoryNode(const QModelIndex& parent);
Expand Down
22 changes: 4 additions & 18 deletions src/RemoteDock.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonLogin">
<property name="toolTip">
<string>Connect to the remote server using the currently selected identity. The correct server is taken from the identity as well.</string>
</property>
<property name="text">
<string>Go</string>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/cog_go.png</normaloff>:/icons/cog_go.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -179,10 +165,10 @@
</resources>
<connections>
<connection>
<sender>buttonLogin</sender>
<signal>clicked()</signal>
<sender>comboUser</sender>
<signal>currentTextChanged(QString)</signal>
<receiver>RemoteDock</receiver>
<slot>setNewIdentity()</slot>
<slot>setNewIdentity(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>551</x>
Expand Down Expand Up @@ -244,7 +230,7 @@
</connection>
</connections>
<slots>
<slot>setNewIdentity()</slot>
<slot>setNewIdentity(QString)</slot>
<slot>fetchDatabase(QModelIndex)</slot>
<slot>pushDatabase()</slot>
<slot>switchToMainView()</slot>
Expand Down
6 changes: 6 additions & 0 deletions src/RemoteModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ void RemoteModel::setNewRootDir(const QString& url, const QString& cert)
currentRootDirectory = url;
currentClientCert = cert;

// Fetch root directory
refresh();
}

void RemoteModel::refresh()
{
// Fetch root directory and put the reply data under the root item
remoteDatabase.fetch(currentRootDirectory, RemoteDatabase::RequestTypeDirectory, currentClientCert, QModelIndex());
}
Expand Down
1 change: 1 addition & 0 deletions src/RemoteModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class RemoteModel : public QAbstractItemModel
~RemoteModel() override;

void setNewRootDir(const QString& url, const QString& cert);
void refresh();

QModelIndex index(int row, int column,const QModelIndex& parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& index) const override;
Expand Down

0 comments on commit 5cdda28

Please sign in to comment.