From 16d6418d10f7b1abcc91fb2238fc29e651efbe29 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Wed, 18 Feb 2015 17:49:07 +0100 Subject: [PATCH 1/5] Use a themable WebDAV path all over. This is needed for enterprise#481 --- src/cmd/cmd.cpp | 6 +++--- src/gui/socketapi.cpp | 2 +- src/gui/wizard/owncloudsetuppage.cpp | 12 ++++++++---- src/libsync/account.cpp | 3 ++- src/libsync/account.h | 2 +- src/libsync/discoveryphase.cpp | 2 +- src/libsync/owncloudpropagator.cpp | 2 +- src/libsync/owncloudpropagator.h | 4 ++-- src/libsync/theme.cpp | 4 ++++ src/libsync/theme.h | 8 ++++++++ 10 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 73b93c807..d1683d55f 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -185,12 +185,12 @@ void parseOptions( const QStringList& app_args, CmdOptions *options ) } options->target_url = args.takeLast(); - // check if the remote.php/webdav tail was added and append if not. + // check if the webDAV path was added to the url and append if not. if(!options->target_url.endsWith("/")) { options->target_url.append("/"); } - if( !options->target_url.contains("remote.php/webdav/")) { - options->target_url.append("remote.php/webdav/"); + if( !options->target_url.contains( Theme::instance()->webDavPath() )) { + options->target_url.append(Theme::instance()->webDavPath()); } if (options->target_url.startsWith("http")) options->target_url.replace(0, 4, "owncloud"); diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index b2387640b..ba18f2cbf 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -655,7 +655,7 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa if (rec._remotePerm.isNull()) { // probably owncloud 6, that does not have permissions flag yet. QString url = folder->remoteUrl().toString() + fileName; - if (url.contains(QLatin1String("/remote.php/webdav/Shared/"))) { + if (url.contains( Theme::instance()->webDavPath() + QLatin1String("Shared/") )) { status.setSharedWithMe(true); } } else if (rec._remotePerm.contains("S")) { diff --git a/src/gui/wizard/owncloudsetuppage.cpp b/src/gui/wizard/owncloudsetuppage.cpp index 838ab4bc8..18e9d78a3 100644 --- a/src/gui/wizard/owncloudsetuppage.cpp +++ b/src/gui/wizard/owncloudsetuppage.cpp @@ -106,11 +106,15 @@ void OwncloudSetupPage::slotUrlChanged(const QString& url) if (url.endsWith("index.php")) { newUrl.chop(9); } - if (url.endsWith("remote.php/webdav")) { - newUrl.chop(17); + QString webDavPath = Theme::instance()->webDavPath(); + if (url.endsWith(webDavPath)) { + newUrl.chop( webDavPath.length() ); } - if (url.endsWith("remote.php/webdav/")) { - newUrl.chop(18); + if( webDavPath.endsWith(QLatin1Char('/')) ) { + webDavPath.chop(1); // cut off the slash + if( url.endsWith(webDavPath)) { + newUrl.chop(webDavPath.length()); + } } if (newUrl != url) { _ui.leUrl->setText(newUrl); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 1c75a08ab..03089800b 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -19,6 +19,7 @@ #include "creds/abstractcredentials.h" #include "../3rdparty/certificates/p12topem.h" #include "capabilities.h" +#include "theme.h" #include #include @@ -40,7 +41,7 @@ Account::Account(QObject *parent) , _am(0) , _credentials(0) , _treatSslErrorsAsFailure(false) - , _davPath("remote.php/webdav/") + , _davPath( Theme::instance()->webDavPath() ) , _wasMigrated(false) { qRegisterMetaType("AccountPtr"); diff --git a/src/libsync/account.h b/src/libsync/account.h index 4f98aa839..986bf85f5 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -193,7 +193,7 @@ private: static QString _configFileName; QByteArray _pemCertificate; QString _pemPrivateKey; - QString _davPath; // default "remote.php/webdav/"; + QString _davPath; // defaults to value from theme, might be overwritten in brandings bool _wasMigrated; friend class AccountManager; }; diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index dd7b45c64..dcf2500ae 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -300,7 +300,7 @@ void DiscoverySingleDirectoryJob::directoryListingIteratedSlot(QString file,QMap } } else { - // Remove /remote.php/webdav/folder/ from /remote.php/webdav/folder/subfile.txt + // Remove /folder/ from /folder/subfile.txt file.remove(0, _lsColJob->reply()->request().url().path().length()); // remove trailing slash while (file.endsWith('/')) { diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index c89cdb5c5..0ba8f4b7c 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -368,7 +368,7 @@ void OwncloudPropagator::start(const SyncFileItemVector& items) bool OwncloudPropagator::isInSharedDirectory(const QString& file) { bool re = false; - if( _remoteDir.contains("remote.php/webdav/Shared") ) { + if( _remoteDir.contains( _account->davPath() + QLatin1String("Shared") ) ) { // The Shared directory is synced as its own sync connection re = true; } else { diff --git a/src/libsync/owncloudpropagator.h b/src/libsync/owncloudpropagator.h index ca22aab7a..564e7a553 100644 --- a/src/libsync/owncloudpropagator.h +++ b/src/libsync/owncloudpropagator.h @@ -249,8 +249,8 @@ public: ne_session_s * const _session; const QString _localDir; // absolute path to the local directory. ends with '/' - const QString _remoteDir; // path to the root of the remote. ends with '/' (include remote.php/webdav) - const QString _remoteFolder; // folder. (same as remoteDir but without remote.php/webdav) + const QString _remoteDir; // path to the root of the remote. ends with '/' (include WebDAV path) + const QString _remoteFolder; // folder. (same as remoteDir but without the WebDAV path) SyncJournalDb * const _journal; bool _finishedEmited; // used to ensure that finished is only emit once diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 737b304c0..257c05ba1 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -407,6 +407,10 @@ bool Theme::wizardSelectiveSyncDefaultNothing() const return false; } +QString Theme::webDavPath() const +{ + return QLatin1String("remote.php/webdav/"); +} } // end namespace client diff --git a/src/libsync/theme.h b/src/libsync/theme.h index 3836c73c5..05acf80cc 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -219,6 +219,14 @@ public: **/ virtual qint64 newBigFolderSizeLimit() const; + /** + * Alternative path on the server that provides access to the webdav capabilities + * + * Attention: Make sure that this string does NOT have a leading slash and that + * it has a trailing slash, for example "remote.php/webdav/". + */ + virtual QString webDavPath() const; + protected: #ifndef TOKEN_AUTH_ONLY QIcon themeIcon(const QString& name, bool sysTray = false) const; From 93e1ad088c2623240bf30ed37cf079a499f45b50 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Thu, 10 Sep 2015 15:38:40 +0200 Subject: [PATCH 2/5] Account: Make sure that davPath() always comes with trailing slash. --- src/libsync/account.cpp | 11 +++++++++++ src/libsync/account.h | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 03089800b..86c808c74 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -61,6 +61,17 @@ Account::~Account() delete _am; } +QString Account::davPath() const +{ + // make sure to have a trailing slash + if( !_davPath.endsWith('/') ) { + QString dp(_davPath); + dp.append('/'); + return dp; + } + return _davPath; +} + void Account::setSharedThis(AccountPtr sharedThis) { _sharedThis = sharedThis.toWeakRef(); diff --git a/src/libsync/account.h b/src/libsync/account.h index 986bf85f5..a1b734c03 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -60,7 +60,12 @@ public: class OWNCLOUDSYNC_EXPORT Account : public QObject { Q_OBJECT public: - QString davPath() const { return _davPath; } + /** + * @brief The possibly themed dav path for the account. Is has + * a trailing slash. + * @returns the (themeable) dav path for the account. + */ + QString davPath() const; void setDavPath(const QString&s) { _davPath = s; } static AccountPtr create(); From cf7726353a98fc2a9751ed8c0e231e3aec142897 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Thu, 10 Sep 2015 15:39:37 +0200 Subject: [PATCH 3/5] Always use the webdav path from the Account object. The Account object has the themed webdav path if it is branded. --- src/cmd/cmd.cpp | 27 ++++++++++++++++----------- src/gui/socketapi.cpp | 3 ++- src/gui/wizard/owncloudsetuppage.cpp | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index d1683d55f..37fbcabde 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -185,15 +185,7 @@ void parseOptions( const QStringList& app_args, CmdOptions *options ) } options->target_url = args.takeLast(); - // check if the webDAV path was added to the url and append if not. - if(!options->target_url.endsWith("/")) { - options->target_url.append("/"); - } - if( !options->target_url.contains( Theme::instance()->webDavPath() )) { - options->target_url.append(Theme::instance()->webDavPath()); - } - if (options->target_url.startsWith("http")) - options->target_url.replace(0, 4, "owncloud"); + options->source_dir = args.takeLast(); if (!options->source_dir.endsWith('/')) { options->source_dir.append('/'); @@ -280,6 +272,21 @@ int main(int argc, char **argv) { parseOptions( app.arguments(), &options ); + AccountPtr account = Account::create(); + + if( !account ) { + qFatal("Could not initialize account!"); + return EXIT_FAILURE; + } + // check if the webDAV path was added to the url and append if not. + if(!options.target_url.endsWith("/")) { + options.target_url.append("/"); + } + if( !options.target_url.contains( account->davPath() )) { + options.target_url.append(account->davPath()); + } + if (options.target_url.startsWith("http")) + options.target_url.replace(0, 4, "owncloud"); QUrl url = QUrl::fromUserInput(options.target_url); // Order of retrieval attempt (later attempts override earlier ones): @@ -331,8 +338,6 @@ int main(int argc, char **argv) { // take the unmodified url to pass to csync_create() QByteArray remUrl = options.target_url.toUtf8(); - AccountPtr account = Account::create(); - // Find the folder and the original owncloud url QStringList splitted = url.path().split(account->davPath()); url.setPath(splitted.value(0)); diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index ba18f2cbf..1db9696c8 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -26,6 +26,7 @@ #include "syncfileitem.h" #include "filesystem.h" #include "version.h" +#include "account.h" #include "accountstate.h" #include @@ -655,7 +656,7 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa if (rec._remotePerm.isNull()) { // probably owncloud 6, that does not have permissions flag yet. QString url = folder->remoteUrl().toString() + fileName; - if (url.contains( Theme::instance()->webDavPath() + QLatin1String("Shared/") )) { + if (url.contains( folder->accountState()->account()->davPath() + QLatin1String("Shared/") )) { status.setSharedWithMe(true); } } else if (rec._remotePerm.contains("S")) { diff --git a/src/gui/wizard/owncloudsetuppage.cpp b/src/gui/wizard/owncloudsetuppage.cpp index 18e9d78a3..616caa007 100644 --- a/src/gui/wizard/owncloudsetuppage.cpp +++ b/src/gui/wizard/owncloudsetuppage.cpp @@ -106,7 +106,7 @@ void OwncloudSetupPage::slotUrlChanged(const QString& url) if (url.endsWith("index.php")) { newUrl.chop(9); } - QString webDavPath = Theme::instance()->webDavPath(); + QString webDavPath = _ocWizard->account()->davPath(); if (url.endsWith(webDavPath)) { newUrl.chop( webDavPath.length() ); } From 9eec45f9c4fc04b56f712364c75332a451906b16 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Thu, 10 Sep 2015 16:03:22 +0200 Subject: [PATCH 4/5] SetupPage: Fix crash caused by uninitialized Account object. Since the webdav path is read from account now, it needs to be initialized first thing. --- src/gui/wizard/owncloudsetuppage.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/gui/wizard/owncloudsetuppage.cpp b/src/gui/wizard/owncloudsetuppage.cpp index 616caa007..d3ea76b32 100644 --- a/src/gui/wizard/owncloudsetuppage.cpp +++ b/src/gui/wizard/owncloudsetuppage.cpp @@ -45,6 +45,7 @@ OwncloudSetupPage::OwncloudSetupPage(QWidget *parent) _progressIndi(new QProgressIndicator (this)) { _ui.setupUi(this); + _ocWizard = qobject_cast(parent); Theme *theme = Theme::instance(); setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(theme->appNameGUI()))); @@ -66,7 +67,6 @@ OwncloudSetupPage::OwncloudSetupPage(QWidget *parent) connect(_ui.leUrl, SIGNAL(editingFinished()), SLOT(slotUrlEditFinished())); addCertDial = new AddCertificateDialog(this); - _ocWizard = qobject_cast(parent); connect(_ocWizard,SIGNAL(needCertificate()),this,SLOT(slotAskSSLClientCertificate())); } @@ -106,14 +106,16 @@ void OwncloudSetupPage::slotUrlChanged(const QString& url) if (url.endsWith("index.php")) { newUrl.chop(9); } - QString webDavPath = _ocWizard->account()->davPath(); - if (url.endsWith(webDavPath)) { - newUrl.chop( webDavPath.length() ); - } - if( webDavPath.endsWith(QLatin1Char('/')) ) { - webDavPath.chop(1); // cut off the slash - if( url.endsWith(webDavPath)) { - newUrl.chop(webDavPath.length()); + if( _ocWizard && _ocWizard->account() ) { + QString webDavPath = _ocWizard->account()->davPath(); + if (url.endsWith(webDavPath)) { + newUrl.chop( webDavPath.length() ); + } + if( webDavPath.endsWith(QLatin1Char('/')) ) { + webDavPath.chop(1); // cut off the slash + if( url.endsWith(webDavPath)) { + newUrl.chop(webDavPath.length()); + } } } if (newUrl != url) { From 8c2b5af7f0bce8f29e93eb0d8f9a3c5185d7d31c Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Thu, 10 Sep 2015 17:44:20 +0200 Subject: [PATCH 5/5] Account: Fixed typo in comment. --- src/libsync/account.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/account.h b/src/libsync/account.h index a1b734c03..3ec92e565 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -61,7 +61,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject { Q_OBJECT public: /** - * @brief The possibly themed dav path for the account. Is has + * @brief The possibly themed dav path for the account. It has * a trailing slash. * @returns the (themeable) dav path for the account. */