Folder Wizard: Fix various issues

- Use data role for pathes
- call root dir "ownCloud"
- don't connect() multiple times
- ensure chars like # or ? in path are interpreted as part of the url path segment

Should fix #992
This commit is contained in:
Daniel Molkentin 2013-09-15 22:46:32 +02:00
parent 0be7c0273e
commit e420ae6942
2 changed files with 13 additions and 10 deletions

View File

@ -243,6 +243,7 @@ static void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QStr
item = new QTreeWidgetItem(parent);
item->setIcon(0, folderIcon);
item->setText(0, pathTrail.first());
item->setData(0, Qt::UserRole, pathTrail.first());
item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
}
@ -253,17 +254,13 @@ static void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QStr
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->setText(0, Theme::instance()->appNameGUI());
root->setIcon(0, Theme::instance()->applicationIcon());
root->setToolTip(0, tr("Choose this to sync the entire account"));
root->setData(0, Qt::UserRole, "/");
}
@ -284,7 +281,7 @@ void FolderWizardTargetPage::slotRefreshFolders()
void FolderWizardTargetPage::slotItemExpanded(QTreeWidgetItem *item)
{
ownCloudInfo::instance()->getDirectoryListing(item->text(0));
ownCloudInfo::instance()->getDirectoryListing(item->data(0, Qt::UserRole).toString());
}
FolderWizardTargetPage::~FolderWizardTargetPage()
@ -342,6 +339,8 @@ void FolderWizardTargetPage::initializePage()
SLOT(slotCreateRemoteFolderFinished( QNetworkReply::NetworkError )));
connect( ocInfo, SIGNAL(directoryListingUpdated(QStringList)),
SLOT(slotUpdateDirectories(QStringList)));
connect(_ui.folderTreeWidget, SIGNAL(itemExpanded(QTreeWidgetItem*)),
SLOT(slotItemExpanded(QTreeWidgetItem*)));
slotRefreshFolders();
}

View File

@ -138,7 +138,8 @@ QNetworkReply* ownCloudInfo::mkdirRequest( const QString& dir )
qDebug() << "OCInfo Making dir " << dir;
_authAttempts = 0;
QNetworkRequest req;
QUrl url = QUrl(webdavUrl(_connection));
QUrl url( webdavUrl(_connection) );
// ensure #, ? and co are interpreted as part of the path and nothing else
url.setEncodedPath(url.encodedPath()+QUrl::toPercentEncoding(dir, "/"));
req.setUrl( url );
@ -162,7 +163,7 @@ QNetworkReply* ownCloudInfo::mkdirRequest( const QString& dir )
QNetworkReply* ownCloudInfo::getQuotaRequest( const QString& dir )
{
QNetworkRequest req;
req.setUrl( QUrl( webdavUrl(_connection) + dir ) );
req.setUrl( QUrl( webdavUrl(_connection) + QUrl::toPercentEncoding(dir, "/") ) );
req.setRawHeader("Depth", "0");
QByteArray xml("<?xml version=\"1.0\" ?>\n"
"<d:propfind xmlns:d=\"DAV:\">\n"
@ -190,7 +191,10 @@ QNetworkReply* ownCloudInfo::getQuotaRequest( const QString& dir )
QNetworkReply* ownCloudInfo::getDirectoryListing( const QString& dir )
{
QNetworkRequest req;
req.setUrl( QUrl( webdavUrl(_connection) + dir ) );
QUrl url( webdavUrl(_connection) );
// ensure #, ? and co are interpreted as part of the path and nothing else
url.setPath(url.path() + dir );
req.setUrl( url );
req.setRawHeader("Depth", "1");
QByteArray xml("<?xml version=\"1.0\" ?>\n"
"<d:propfind xmlns:d=\"DAV:\">\n"