-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Read default folder configuration from a file on the server #6761
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,7 +353,35 @@ void OwncloudSetupWizard::testOwnCloudConnect() | |
// so don't automatically follow redirects. | ||
job->setFollowRedirects(false); | ||
job->setProperties(QList<QByteArray>() << "getlastmodified"); | ||
connect(job, &PropfindJob::result, _ocWizard, &OwncloudWizard::successfulStep); | ||
connect(job, &PropfindJob::result, this, [this, account] { | ||
auto *job2 = account->sendRequest("GET", Utility::concatUrlPath(account->davUrl(), ".desktopclientconfig")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer if this didn't store the configuration in a user-visible / editable file. I understand getting support on the server may be hard/limiting, and that this may be a reasonable tradeoff, but:
|
||
job2->setIgnoreCredentialFailure(true); | ||
QObject::connect(job2, &SimpleNetworkJob::finishedSignal, this, [this, account] (QNetworkReply *reply) { | ||
if (reply->error()) { | ||
if (reply->error() == QNetworkReply::ContentNotFoundError) { | ||
// Ignore a 404 error, the file can be missing (default case) | ||
_ocWizard->successfulStep(); | ||
} else { | ||
// Note: slotAuthError uses sender() which should be job2 | ||
slotAuthError(); | ||
} | ||
return; | ||
} | ||
auto jsonData = reply->readAll(); | ||
QJsonParseError jsonParseError; | ||
QJsonDocument json = QJsonDocument::fromJson(jsonData, &jsonParseError); | ||
if (jsonParseError.error != QJsonParseError::NoError) { | ||
// Invalid JSON | ||
qCWarning(lcWizard) << "Error while parsing .desktopclientconfig" << jsonParseError.errorString() << jsonData; | ||
// Silently ignore the error (consider the file was not there) | ||
} else { | ||
// TODO: make it a real parameter | ||
account->setProperty("oc_serverConfig", json); | ||
} | ||
_ocWizard->successfulStep(); | ||
}); | ||
}); | ||
|
||
connect(job, &PropfindJob::finishedWithError, this, &OwncloudSetupWizard::slotAuthError); | ||
job->start(); | ||
} | ||
|
@@ -362,7 +390,7 @@ void OwncloudSetupWizard::slotAuthError() | |
{ | ||
QString errorMsg; | ||
|
||
PropfindJob *job = qobject_cast<PropfindJob *>(sender()); | ||
AbstractNetworkJob *job = qobject_cast<AbstractNetworkJob *>(sender()); | ||
if (!job) { | ||
qCWarning(lcWizard) << "Can't check for authed redirects. This slot should be invoked from PropfindJob!"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also update this warning |
||
return; | ||
|
@@ -610,32 +638,62 @@ void OwncloudSetupWizard::slotAssistantFinished(int result) | |
FolderMan *folderMan = FolderMan::instance(); | ||
auto account = applyAccountChanges(); | ||
|
||
QJsonDocument configJson = account->account()->property("oc_serverConfig").toJsonDocument(); | ||
bool hasServerConfig = configJson.isObject() && !configJson.object()["default_folders"].toArray().isEmpty(); | ||
qWarning() << configJson << hasServerConfig; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. qCWarning() |
||
|
||
QString localFolder = FolderDefinition::prepareLocalPath(_ocWizard->localFolder()); | ||
|
||
bool startFromScratch = _ocWizard->field("OCSyncFromScratch").toBool(); | ||
if (!startFromScratch || ensureStartFromScratch(localFolder)) { | ||
qCInfo(lcWizard) << "Adding folder definition for" << localFolder << _remoteFolder; | ||
FolderDefinition folderDefinition; | ||
folderDefinition.localPath = localFolder; | ||
folderDefinition.targetPath = FolderDefinition::prepareTargetPath(_remoteFolder); | ||
folderDefinition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles(); | ||
if (_ocWizard->useVirtualFileSync()) { | ||
folderDefinition.virtualFilesMode = bestAvailableVfsMode(); | ||
} | ||
if (folderMan->navigationPaneHelper().showInExplorerNavigationPane()) | ||
folderDefinition.navigationPaneClsid = QUuid::createUuid(); | ||
|
||
auto f = folderMan->addFolder(account, folderDefinition); | ||
if (f) { | ||
if (folderDefinition.virtualFilesMode != Vfs::Off && _ocWizard->useVirtualFileSync()) | ||
f->setNewFilesAreVirtual(true); | ||
|
||
f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, | ||
_ocWizard->selectiveSyncBlacklist()); | ||
if (!_ocWizard->isConfirmBigFolderChecked()) { | ||
// The user already accepted the selective sync dialog. everything is in the white list | ||
f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, | ||
QStringList() << QLatin1String("/")); | ||
if (!hasServerConfig) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is getting very deeply nested. Split the two branches into functions? |
||
qCInfo(lcWizard) << "Adding folder definition for" << localFolder << _remoteFolder; | ||
FolderDefinition folderDefinition; | ||
folderDefinition.localPath = localFolder; | ||
folderDefinition.targetPath = FolderDefinition::prepareTargetPath(_remoteFolder); | ||
folderDefinition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles(); | ||
if (_ocWizard->useVirtualFileSync()) { | ||
folderDefinition.virtualFilesMode = bestAvailableVfsMode(); | ||
} | ||
if (folderMan->navigationPaneHelper().showInExplorerNavigationPane()) | ||
folderDefinition.navigationPaneClsid = QUuid::createUuid(); | ||
|
||
auto f = folderMan->addFolder(account, folderDefinition); | ||
if (f) { | ||
if (folderDefinition.virtualFilesMode != Vfs::Off && _ocWizard->useVirtualFileSync()) | ||
f->setNewFilesAreVirtual(true); | ||
|
||
f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, | ||
_ocWizard->selectiveSyncBlacklist()); | ||
if (!_ocWizard->isConfirmBigFolderChecked()) { | ||
// The user already accepted the selective sync dialog. everything is in the white list | ||
f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, | ||
QStringList() << QLatin1String("/")); | ||
} | ||
} | ||
} else { | ||
auto array = configJson.object()["default_folders"].toArray(); | ||
// FIXME! check consistency of the config and that the folder can be created | ||
for (const auto &x : array) { | ||
QString remoteFolder = x.toObject()["remote_folder"].toString(); | ||
QString name = QFileInfo(remoteFolder).fileName(); | ||
FolderDefinition folderDefinition; | ||
folderDefinition.localPath = (array.size() == 1) ? localFolder : QString(localFolder + name + '/'); | ||
QDir(localFolder).mkpath(folderDefinition.localPath); | ||
folderDefinition.targetPath = FolderDefinition::prepareTargetPath(remoteFolder); | ||
folderDefinition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles(); | ||
if (folderMan->navigationPaneHelper().showInExplorerNavigationPane()) | ||
folderDefinition.navigationPaneClsid = QUuid::createUuid(); | ||
|
||
auto f = folderMan->addFolder(account, folderDefinition); | ||
if (f) { | ||
if (folderDefinition.virtualFilesMode != Vfs::Off && _ocWizard->useVirtualFileSync()) | ||
f->setNewFilesAreVirtual(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be removed I think. folderDefinition.virtualFilesMode is never set and useVirtualFileSync() an't be true. |
||
|
||
QStringList list; | ||
foreach (const auto &l, x.toObject()["black_list"].toArray()) { list << l.toString(); } | ||
f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, list); | ||
} | ||
} | ||
} | ||
_ocWizard->appendToConfigurationLog(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(localFolder)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
#include <QUrl> | ||
#include <QTimer> | ||
#include <QMessageBox> | ||
#include <QJsonDocument> | ||
#include <QJsonObject> | ||
#include <QJsonArray> | ||
|
||
#include "QProgressIndicator.h" | ||
|
||
|
@@ -69,15 +72,6 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage() | |
_ui.lServerIcon->setPixmap(appIcon.pixmap(48)); | ||
_ui.lLocalIcon->setText(QString()); | ||
_ui.lLocalIcon->setPixmap(QPixmap(Theme::hidpiFileName(":/client/resources/folder-sync.png"))); | ||
|
||
if (theme->wizardHideExternalStorageConfirmationCheckbox()) { | ||
_ui.confCheckBoxExternal->hide(); | ||
} | ||
if (theme->wizardHideFolderSizeLimitCheckbox()) { | ||
_ui.confCheckBoxSize->hide(); | ||
_ui.confSpinBox->hide(); | ||
_ui.confTraillingSizeLabel->hide(); | ||
} | ||
} | ||
|
||
void OwncloudAdvancedSetupPage::setupCustomization() | ||
|
@@ -110,14 +104,6 @@ void OwncloudAdvancedSetupPage::initializePage() | |
labelSizeHint.width(), | ||
qMax<int>(1.3 * labelSizeHint.height(), _progressIndi->height())); | ||
|
||
if (!Theme::instance()->showVirtualFilesOption() || bestAvailableVfsMode() == Vfs::Off) { | ||
// If the layout were wrapped in a widget, the auto-grouping of the | ||
// radio buttons no longer works and there are surprising margins. | ||
// Just manually hide the button and remove the layout. | ||
_ui.rVirtualFileSync->hide(); | ||
_ui.wSyncStrategy->layout()->removeItem(_ui.lVirtualFileSync); | ||
} | ||
|
||
_checking = false; | ||
_ui.lSelectiveSyncSizeLabel->setText(QString()); | ||
_ui.lSyncEverythingSizeLabel->setText(QString()); | ||
|
@@ -139,11 +125,31 @@ void OwncloudAdvancedSetupPage::initializePage() | |
connect(quotaJob, &PropfindJob::result, this, &OwncloudAdvancedSetupPage::slotQuotaRetrieved); | ||
quotaJob->start(); | ||
|
||
QJsonDocument configJson = acc->property("oc_serverConfig").toJsonDocument(); | ||
bool hasServerConfig = configJson.isObject() && !configJson.object()["default_folders"].toArray().isEmpty(); | ||
Theme *theme = Theme::instance(); | ||
|
||
if (Theme::instance()->wizardSelectiveSyncDefaultNothing()) { | ||
_ui.rDefaultFolders->setVisible(hasServerConfig); | ||
_ui.rSyncEverything->setVisible(!hasServerConfig); | ||
_ui.lSyncEverythingSizeLabel->setVisible(!hasServerConfig); | ||
_ui.rSelectiveSync->setVisible(!hasServerConfig); | ||
_ui.bSelectiveSync->setVisible(!hasServerConfig); | ||
_ui.lSelectiveSyncSizeLabel->setVisible(!hasServerConfig); | ||
_ui.rVirtualFileSync->setVisible(!hasServerConfig && Theme::instance()->showVirtualFilesOption() && bestAvailableVfsMode() != Vfs::Off); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I remember removing the layout from the wSyncStrategy widget was required for making the layout not be broken on some platforms. May need testing. |
||
|
||
_ui.confCheckBoxExternal->setVisible(!hasServerConfig && !theme->wizardHideExternalStorageConfirmationCheckbox()); | ||
_ui.confCheckBoxSize->setVisible(!hasServerConfig && !theme->wizardHideFolderSizeLimitCheckbox()); | ||
_ui.confSpinBox->setVisible(!hasServerConfig && !theme->wizardHideFolderSizeLimitCheckbox()); | ||
_ui.confTraillingSizeLabel->setVisible(!hasServerConfig && !theme->wizardHideFolderSizeLimitCheckbox());; | ||
|
||
if (hasServerConfig) { | ||
setRadioChecked(_ui.rDefaultFolders); | ||
} else if (theme->wizardSelectiveSyncDefaultNothing()) { | ||
_selectiveSyncBlacklist = QStringList("/"); | ||
setRadioChecked(_ui.rSelectiveSync); | ||
QTimer::singleShot(0, this, &OwncloudAdvancedSetupPage::slotSelectiveSyncClicked); | ||
} else { | ||
setRadioChecked(_ui.rSyncEverything); | ||
} | ||
|
||
ConfigFile cfgFile; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if the code for triggering and handling the request checking the server here was a separate function. At least it must have a comment explaining what's going on.