Skip to content

Commit bbbadba

Browse files
committed
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.
1 parent 38caf86 commit bbbadba

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/RemoteDock.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ RemoteDock::RemoteDock(MainWindow* parent)
2424
// Reload the directory tree when a database upload has finished
2525
connect(&remoteDatabase, &RemoteDatabase::uploadFinished, this, &RemoteDock::setNewIdentity);
2626

27+
// Whenever a new directory listing has been parsed, check if it was a new root dir and, if so, open the user's directory
28+
connect(remoteModel, &RemoteModel::directoryListingParsed, this, &RemoteDock::newDirectoryNode);
29+
2730
// Initial setup
2831
reloadSettings();
2932
}
@@ -110,3 +113,22 @@ void RemoteDock::pushDatabase()
110113
remoteDatabase.push(mainWindow->getDb().currentFile(), url, remoteModel->currentClientCertificate(),
111114
pushDialog.commitMessage(), pushDialog.licence(), pushDialog.isPublic());
112115
}
116+
117+
void RemoteDock::newDirectoryNode(const QModelIndex& parent)
118+
{
119+
// Was this a new root dir?
120+
if(!parent.isValid())
121+
{
122+
// Then check if there is a directory with the current user name
123+
124+
// Get current user name
125+
QString user = remoteDatabase.getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteDatabase::CertInfoUser);
126+
127+
for(int i=0;i<remoteModel->rowCount(parent);i++)
128+
{
129+
QModelIndex child = remoteModel->index(i, RemoteModelColumnName, parent);
130+
if(child.data().toString() == user)
131+
ui->treeStructure->expand(child);
132+
}
133+
}
134+
}

src/RemoteDock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private slots:
2626
void setNewIdentity();
2727
void fetchDatabase(const QModelIndex& idx);
2828
void pushDatabase();
29+
void newDirectoryNode(const QModelIndex& parent);
2930

3031
private:
3132
Ui::RemoteDock* ui;

src/RemoteModel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ void RemoteModel::parseDirectoryListing(const QString& json, const QVariant& use
153153
foreach(RemoteModelItem* item, items)
154154
parentItem->appendChild(item);
155155
endInsertRows();
156+
157+
// Emit directory listing parsed signal
158+
emit directoryListingParsed(parent);
156159
}
157160

158161
QModelIndex RemoteModel::index(int row, int column, const QModelIndex& parent) const

src/RemoteModel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class RemoteModel : public QAbstractItemModel
8686
// Returns the current client certificate
8787
const QString& currentClientCertificate() const;
8888

89+
signals:
90+
// This signal is emitted whenever a directory listing has been received and parsed
91+
void directoryListingParsed(QModelIndex parent);
92+
8993
private slots:
9094
// This is called whenever a network reply containing a directory listing arrives. json contains the reply data, userdata
9195
// contains some custom data passed to the request. In this case we expect this to be the model index of the parent tree item.

0 commit comments

Comments
 (0)