mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Fix regression in FolderWizard over 1.3
Now it's possible to also pick subdirectory of in arbitrary depths again
This commit is contained in:
parent
7e794cd94f
commit
c49edeb09d
3 changed files with 87 additions and 13 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <QUrl>
|
||||
#include <QValidator>
|
||||
#include <QWizardPage>
|
||||
#include <QTreeWidget>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -171,16 +172,25 @@ FolderWizardTargetPage::FolderWizardTargetPage()
|
|||
_ui.warnFrame->hide();
|
||||
|
||||
connect(_ui.addFolderButton, SIGNAL(clicked()), SLOT(slotAddRemoteFolder()));
|
||||
connect(_ui.refreshButton, SIGNAL(clicked()), SLOT(slotRefreshFolders())),
|
||||
connect(_ui.folderListWidget, SIGNAL(currentTextChanged(QString)),
|
||||
SIGNAL(completeChanged()));
|
||||
connect(_ui.refreshButton, SIGNAL(clicked()), SLOT(slotRefreshFolders()));
|
||||
connect(_ui.folderTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), SIGNAL(completeChanged()));
|
||||
connect(_ui.folderTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), SIGNAL(completeChanged()));
|
||||
}
|
||||
|
||||
void FolderWizardTargetPage::slotAddRemoteFolder()
|
||||
{
|
||||
QTreeWidgetItem *current = _ui.folderTreeWidget->currentItem();
|
||||
|
||||
QString parent('/');
|
||||
if (current) {
|
||||
parent = current->data(0, Qt::UserRole).toString();
|
||||
}
|
||||
|
||||
QInputDialog *dlg = new QInputDialog(this);
|
||||
|
||||
dlg->setWindowTitle(tr("Add Remote Folder"));
|
||||
dlg->setLabelText(tr("Enter the name of the new folder:"));
|
||||
dlg->setTextValue(parent);
|
||||
dlg->open(this, SLOT(slotCreateRemoteFolder(QString)));
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
}
|
||||
|
@ -205,22 +215,74 @@ void FolderWizardTargetPage::slotCreateRemoteFolderFinished( QNetworkReply::Netw
|
|||
}
|
||||
}
|
||||
|
||||
void FolderWizardTargetPage::slotUpdateDirectories(QStringList list)
|
||||
static QTreeWidgetItem* findFirstChild(QTreeWidgetItem *parent, const QString& text)
|
||||
{
|
||||
for (int i = 0; i < parent->childCount(); ++i) {
|
||||
QTreeWidgetItem *child = parent->child(i);
|
||||
if (child->text(0) == text) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path)
|
||||
{
|
||||
_ui.folderListWidget->clear();
|
||||
QFileIconProvider prov;
|
||||
QIcon folderIcon = prov.icon(QFileIconProvider::Folder);
|
||||
if (pathTrail.size() == 0) {
|
||||
if (path.endsWith('/')) {
|
||||
path.chop(1);
|
||||
}
|
||||
parent->setToolTip(0, path);
|
||||
parent->setData(0, Qt::UserRole, path);
|
||||
} else {
|
||||
QTreeWidgetItem *item = findFirstChild(parent, pathTrail.first());
|
||||
if (!item) {
|
||||
item = new QTreeWidgetItem(parent);
|
||||
item->setIcon(0, folderIcon);
|
||||
item->setText(0, pathTrail.first());
|
||||
item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
|
||||
}
|
||||
|
||||
pathTrail.removeFirst();
|
||||
recursiveInsert(item, pathTrail, path);
|
||||
}
|
||||
}
|
||||
|
||||
void FolderWizardTargetPage::slotUpdateDirectories(QStringList list)
|
||||
{
|
||||
QFileIconProvider prov;
|
||||
QIcon folderIcon = prov.icon(QFileIconProvider::Folder);
|
||||
|
||||
QString webdavFolder = QUrl(ownCloudInfo::instance()->webdavUrl()).path();
|
||||
connect(_ui.folderTreeWidget, SIGNAL(itemExpanded(QTreeWidgetItem*)), SLOT(slotItemExpanded(QTreeWidgetItem*)));
|
||||
|
||||
QTreeWidgetItem *root = _ui.folderTreeWidget->topLevelItem(0);
|
||||
if (!root) {
|
||||
root = new QTreeWidgetItem(_ui.folderTreeWidget);
|
||||
root->setText(0, tr("Root (\"/\")", "root folder"));
|
||||
root->setIcon(0, folderIcon);
|
||||
root->setToolTip(0, tr("Choose this to sync the entire account"));
|
||||
root->setData(0, Qt::UserRole, "/");
|
||||
}
|
||||
foreach (QString path, list) {
|
||||
path.remove(webdavFolder);
|
||||
if (!path.startsWith("/")) path.prepend('/');
|
||||
new QListWidgetItem(folderIcon, path, _ui.folderListWidget);
|
||||
QStringList paths = path.split('/');
|
||||
if (paths.last().isEmpty()) paths.removeLast();
|
||||
recursiveInsert(root, paths, path);
|
||||
}
|
||||
root->setExpanded(true);
|
||||
}
|
||||
|
||||
void FolderWizardTargetPage::slotRefreshFolders()
|
||||
{
|
||||
ownCloudInfo::instance()->getDirectoryListing("/");
|
||||
_ui.folderTreeWidget->clear();
|
||||
}
|
||||
|
||||
void FolderWizardTargetPage::slotItemExpanded(QTreeWidgetItem *item)
|
||||
{
|
||||
ownCloudInfo::instance()->getDirectoryListing(item->text(0));
|
||||
}
|
||||
|
||||
FolderWizardTargetPage::~FolderWizardTargetPage()
|
||||
|
@ -229,10 +291,10 @@ FolderWizardTargetPage::~FolderWizardTargetPage()
|
|||
|
||||
bool FolderWizardTargetPage::isComplete() const
|
||||
{
|
||||
if (!_ui.folderListWidget->currentItem())
|
||||
if (!_ui.folderTreeWidget->currentItem())
|
||||
return false;
|
||||
|
||||
QString dir = _ui.folderListWidget->currentItem()->text();
|
||||
QString dir = _ui.folderTreeWidget->currentItem()->data(0, Qt::UserRole).toString();
|
||||
wizard()->setProperty("targetPath", dir);
|
||||
|
||||
if( dir == QLatin1String("/") ) {
|
||||
|
|
|
@ -77,7 +77,7 @@ protected slots:
|
|||
void slotCreateRemoteFolderFinished( QNetworkReply::NetworkError error );
|
||||
void slotUpdateDirectories(QStringList);
|
||||
void slotRefreshFolders();
|
||||
|
||||
void slotItemExpanded(QTreeWidgetItem*);
|
||||
private:
|
||||
Ui_FolderWizardTargetPage _ui;
|
||||
ownCloudInfo *_ownCloudDirCheck;
|
||||
|
|
|
@ -64,9 +64,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="4">
|
||||
<widget class="QListWidget" name="folderListWidget"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
|
@ -87,6 +84,21 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="4">
|
||||
<widget class="QTreeWidget" name="folderTreeWidget">
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="headerHidden">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Folders</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in a new issue