dbhub: Open the user's directory by default

When 'logging in' or refreshing the view, look for the user's directory
and open it by default.
This commit is contained in:
Martin Kleusberg
2017-08-13 15:12:50 +02:00
parent 38caf867bc
commit bbbadba732
4 changed files with 30 additions and 0 deletions

View File

@@ -24,6 +24,9 @@ RemoteDock::RemoteDock(MainWindow* parent)
// Reload the directory tree when a database upload has finished
connect(&remoteDatabase, &RemoteDatabase::uploadFinished, this, &RemoteDock::setNewIdentity);
// 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);
// Initial setup
reloadSettings();
}
@@ -110,3 +113,22 @@ void RemoteDock::pushDatabase()
remoteDatabase.push(mainWindow->getDb().currentFile(), url, remoteModel->currentClientCertificate(),
pushDialog.commitMessage(), pushDialog.licence(), pushDialog.isPublic());
}
void RemoteDock::newDirectoryNode(const QModelIndex& parent)
{
// Was this a new root dir?
if(!parent.isValid())
{
// Then check if there is a directory with the current user name
// Get current user name
QString user = remoteDatabase.getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteDatabase::CertInfoUser);
for(int i=0;i<remoteModel->rowCount(parent);i++)
{
QModelIndex child = remoteModel->index(i, RemoteModelColumnName, parent);
if(child.data().toString() == user)
ui->treeStructure->expand(child);
}
}
}

View File

@@ -26,6 +26,7 @@ private slots:
void setNewIdentity();
void fetchDatabase(const QModelIndex& idx);
void pushDatabase();
void newDirectoryNode(const QModelIndex& parent);
private:
Ui::RemoteDock* ui;

View File

@@ -153,6 +153,9 @@ void RemoteModel::parseDirectoryListing(const QString& json, const QVariant& use
foreach(RemoteModelItem* item, items)
parentItem->appendChild(item);
endInsertRows();
// Emit directory listing parsed signal
emit directoryListingParsed(parent);
}
QModelIndex RemoteModel::index(int row, int column, const QModelIndex& parent) const

View File

@@ -86,6 +86,10 @@ public:
// Returns the current client certificate
const QString& currentClientCertificate() const;
signals:
// This signal is emitted whenever a directory listing has been received and parsed
void directoryListingParsed(QModelIndex parent);
private slots:
// This is called whenever a network reply containing a directory listing arrives. json contains the reply data, userdata
// contains some custom data passed to the request. In this case we expect this to be the model index of the parent tree item.