#include "creds/abstractcredentials.h"
#include "networkjobs.h"
+#include "wizard/owncloudwizard.h"
namespace OCC {
-OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage()
+OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage(OwncloudWizard *wizard)
: QWizardPage()
, _progressIndi(new QProgressIndicator(this))
+ , _ocWizard(wizard)
{
_ui.setupUi(this);
-
- Theme *theme = Theme::instance();
- setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(theme->appNameGUI())));
- setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Setup local folder options")));
+ setupSyncModeLabel();
+ setupRKeepLocal();
+ setupCbSyncFromScratch();
registerField(QLatin1String("OCSyncFromScratch"), _ui.cbSyncFromScratch);
+ auto sizePolicy = _progressIndi->sizePolicy();
+ sizePolicy.setRetainSizeWhenHidden(true);
+ _progressIndi->setSizePolicy(sizePolicy);
+
_ui.resultLayout->addWidget(_progressIndi);
stopSpinner();
setupCustomization();
@@ -65,13 +71,11 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage()
});
connect(_ui.bSelectiveSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectiveSyncClicked);
- QIcon appIcon = theme->applicationIcon();
- _ui.lServerIcon->setText(QString());
- _ui.lServerIcon->setPixmap(appIcon.pixmap(48));
- _ui.lLocalIcon->setText(QString());
-
- // TO DO: File doesn't exist anymore - unneccessary or replacement needed?
- _ui.lLocalIcon->setPixmap(QPixmap(Theme::hidpiFileName(":/client/theme/folder-sync.png")));
+ const auto theme = Theme::instance();
+ const auto appIcon = theme->applicationIcon();
+ const auto appIconSize = Theme::isHidpi() ? 128 : 64;
+
+ _ui.lServerIcon->setPixmap(appIcon.pixmap(appIconSize));
if (theme->wizardHideExternalStorageConfirmationCheckbox()) {
_ui.confCheckBoxExternal->hide();
@@ -106,6 +110,16 @@ void OwncloudAdvancedSetupPage::setupCustomization()
variant = theme->customMedia(Theme::oCSetupBottom);
WizardCommon::setupCustomMedia(variant, _ui.bottomLabel);
+
+ WizardCommon::customizeSpinBoxStyle(_ui.confSpinBox);
+
+ WizardCommon::customizeSecondaryButtonStyle(_ui.bSelectiveSync);
+ WizardCommon::customizeSecondaryButtonStyle(_ui.pbSelectLocalFolder);
+
+ WizardCommon::customizeHintLabel(_ui.lFreeSpace);
+ WizardCommon::customizeHintLabel(_ui.lSyncEverythingSizeLabel);
+ WizardCommon::customizeHintLabel(_ui.lSelectiveSyncSizeLabel);
+ WizardCommon::customizeHintLabel(_ui.serverAddressLabel);
}
bool OwncloudAdvancedSetupPage::isComplete() const
@@ -158,6 +172,64 @@ void OwncloudAdvancedSetupPage::initializePage()
_ui.confCheckBoxSize->setChecked(newFolderLimit.first);
_ui.confSpinBox->setValue(newFolderLimit.second);
_ui.confCheckBoxExternal->setChecked(cfgFile.confirmExternalStorage());
+
+ fetchUserAvatar();
+ fetchUserData();
+
+ customizeStyle();
+}
+
+void OwncloudAdvancedSetupPage::fetchUserAvatar()
+{
+ // Reset user avatar
+ const auto appIcon = Theme::instance()->applicationIcon();
+ _ui.lServerIcon->setPixmap(appIcon.pixmap(48));
+ // Fetch user avatar
+ const auto account = _ocWizard->account();
+ auto avatarSize = 64;
+ if (Theme::isHidpi()) {
+ avatarSize *= 2;
+ }
+ const auto avatarJob = new AvatarJob(account, account->davUser(), avatarSize, this);
+ avatarJob->setTimeout(20 * 1000);
+ QObject::connect(avatarJob, &AvatarJob::avatarPixmap, this, [this](const QImage &avatarImage) {
+ if (avatarImage.isNull()) {
+ return;
+ }
+ const auto avatarPixmap = QPixmap::fromImage(AvatarJob::makeCircularAvatar(avatarImage));
+ _ui.lServerIcon->setPixmap(avatarPixmap);
+ });
+ avatarJob->start();
+}
+
+void OwncloudAdvancedSetupPage::fetchUserData()
+{
+ const auto account = _ocWizard->account();
+
+ // Fetch user data
+ const auto userJob = new JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/user"), this);
+ userJob->setTimeout(20 * 1000);
+ connect(userJob, &JsonApiJob::jsonReceived, this, [this](const QJsonDocument &json) {
+ const auto objData = json.object().value("ocs").toObject().value("data").toObject();
+ const auto displayName = objData.value("display-name").toString();
+ _ui.userNameLabel->setText(displayName);
+ });
+ userJob->start();
+
+ const auto serverUrl = account->url().toString();
+ setServerAddressLabelUrl(serverUrl);
+ const auto userName = account->davDisplayName();
+ _ui.userNameLabel->setText(userName);
+}
+
+void OwncloudAdvancedSetupPage::setServerAddressLabelUrl(const QUrl &url)
+{
+ if (!url.isValid()) {
+ return;
+ }
+
+ const auto prettyUrl = url.toString().mid(url.scheme().size() + 3); // + 3 because we need to remove ://
+ _ui.serverAddressLabel->setText(prettyUrl);
}
// Called if the user changes the user- or url field. Adjust the texts and
@@ -172,7 +244,8 @@ void OwncloudAdvancedSetupPage::updateStatus()
QString t;
- _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder));
+ setLocalFolderPushButtonPath(locFolder);
+
if (dataChanged()) {
if (_remoteFolder.isEmpty() || _remoteFolder == QLatin1String("/")) {
t = "";
@@ -185,20 +258,18 @@ void OwncloudAdvancedSetupPage::updateStatus()
const bool dirNotEmpty(QDir(locFolder).entryList(QDir::AllEntries | QDir::NoDotAndDotDot).count() > 0);
if (dirNotEmpty) {
- t += tr("Warning: The local folder is not empty. "
- "Pick a resolution!
");
+ t += tr("Warning: The local folder is not empty. Pick a resolution!");
}
- _ui.resolutionWidget->setVisible(dirNotEmpty);
+ setResolutionGuiVisible(dirNotEmpty);
} else {
- _ui.resolutionWidget->setVisible(false);
+ setResolutionGuiVisible(false);
}
QString lfreeSpaceStr = Utility::octetsToString(availableLocalSpace());
- _ui.lFreeSpace->setText(QString(tr("Free space: %1")).arg(lfreeSpaceStr));
+ _ui.lFreeSpace->setText(QString(tr("%1 free space")).arg(lfreeSpaceStr));
_ui.syncModeLabel->setText(t);
_ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height());
- wizard()->resize(wizard()->sizeHint());
qint64 rSpace = _ui.rSyncEverything->isChecked() ? _rSize : _rSelectedSize;
@@ -211,6 +282,13 @@ void OwncloudAdvancedSetupPage::updateStatus()
emit completeChanged();
}
+void OwncloudAdvancedSetupPage::setResolutionGuiVisible(bool value)
+{
+ _ui.syncModeLabel->setVisible(value);
+ _ui.rKeepLocal->setVisible(value);
+ _ui.cbSyncFromScratch->setVisible(value);
+}
+
/* obsolete */
bool OwncloudAdvancedSetupPage::dataChanged()
{
@@ -334,7 +412,7 @@ void OwncloudAdvancedSetupPage::slotSelectFolder()
{
QString dir = QFileDialog::getExistingDirectory(nullptr, tr("Local Sync Folder"), QDir::homePath());
if (!dir.isEmpty()) {
- _ui.pbSelectLocalFolder->setText(dir);
+ setLocalFolderPushButtonPath(dir);
wizard()->setProperty("localFolder", dir);
updateStatus();
}
@@ -344,6 +422,22 @@ void OwncloudAdvancedSetupPage::slotSelectFolder()
setErrorString(errorStr);
}
+
+void OwncloudAdvancedSetupPage::setLocalFolderPushButtonPath(const QString &path)
+{
+ const auto homeDir = QDir::homePath().endsWith('/') ? QDir::homePath() : QDir::homePath() + QLatin1Char('/');
+
+ if (!path.startsWith(homeDir)) {
+ _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(path));
+ return;
+ }
+
+ auto prettyPath = path;
+ prettyPath.remove(0, homeDir.size());
+
+ _ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(prettyPath));
+}
+
void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked()
{
AccountPtr acc = static_cast(wizard())->account();
@@ -439,8 +533,23 @@ void OwncloudAdvancedSetupPage::slotStyleChanged()
void OwncloudAdvancedSetupPage::customizeStyle()
{
- if(_progressIndi)
- _progressIndi->setColor(QGuiApplication::palette().color(QPalette::Text));
+ if (_progressIndi) {
+ const auto isDarkBackground = Theme::isDarkColor(palette().window().color());
+ if (isDarkBackground) {
+ _progressIndi->setColor(Qt::white);
+ } else {
+ _progressIndi->setColor(Qt::black);
+ }
+ }
+
+ styleSyncLogo();
+ styleLocalFolderLabel();
+}
+
+void OwncloudAdvancedSetupPage::styleLocalFolderLabel()
+{
+ const auto backgroundColor = palette().window().color();
+ _ui.lLocal->setPixmap(QPixmap(Theme::hidpiFileName("folder.png", backgroundColor)));
}
void OwncloudAdvancedSetupPage::setRadioChecked(QRadioButton *radio)
@@ -457,4 +566,31 @@ void OwncloudAdvancedSetupPage::setRadioChecked(QRadioButton *radio)
_ui.rVirtualFileSync->setCheckable(false);
}
+void OwncloudAdvancedSetupPage::styleSyncLogo()
+{
+ const auto backgroundColor = palette().window().color();
+ _ui.syncLogoLabel->setPixmap(Theme::hidpiFileName("sync-arrows.png", backgroundColor));
+}
+
+void OwncloudAdvancedSetupPage::setupSyncModeLabel()
+{
+ auto sizePolicy = _ui.syncModeLabel->sizePolicy();
+ sizePolicy.setRetainSizeWhenHidden(true);
+ _ui.syncModeLabel->setSizePolicy(sizePolicy);
+}
+
+void OwncloudAdvancedSetupPage::setupRKeepLocal()
+{
+ auto sizePolicy = _ui.rKeepLocal->sizePolicy();
+ sizePolicy.setRetainSizeWhenHidden(true);
+ _ui.rKeepLocal->setSizePolicy(sizePolicy);
+}
+
+void OwncloudAdvancedSetupPage::setupCbSyncFromScratch()
+{
+ auto sizePolicy = _ui.cbSyncFromScratch->sizePolicy();
+ sizePolicy.setRetainSizeWhenHidden(true);
+ _ui.cbSyncFromScratch->setSizePolicy(sizePolicy);
+}
+
} // namespace OCC
diff --git a/src/gui/wizard/owncloudadvancedsetuppage.h b/src/gui/wizard/owncloudadvancedsetuppage.h
index 7fcde225a716..069f385d9fa8 100644
--- a/src/gui/wizard/owncloudadvancedsetuppage.h
+++ b/src/gui/wizard/owncloudadvancedsetuppage.h
@@ -25,6 +25,8 @@ class QProgressIndicator;
namespace OCC {
+class OwncloudWizard;
+
/**
* @brief The OwncloudAdvancedSetupPage class
* @ingroup gui
@@ -33,7 +35,7 @@ class OwncloudAdvancedSetupPage : public QWizardPage
{
Q_OBJECT
public:
- OwncloudAdvancedSetupPage();
+ OwncloudAdvancedSetupPage(OwncloudWizard *wizard);
bool isComplete() const override;
void initializePage() override;
@@ -73,6 +75,16 @@ private slots:
qint64 availableLocalSpace() const;
QString checkLocalSpace(qint64 remoteSize) const;
void customizeStyle();
+ void setServerAddressLabelUrl(const QUrl &url);
+ void setLocalFolderPushButtonPath(const QString &path);
+ void styleSyncLogo();
+ void styleLocalFolderLabel();
+ void setResolutionGuiVisible(bool value);
+ void setupSyncModeLabel();
+ void setupRKeepLocal();
+ void setupCbSyncFromScratch();
+ void fetchUserAvatar();
+ void fetchUserData();
Ui_OwncloudAdvancedSetupPage _ui;
bool _checking = false;
@@ -83,6 +95,7 @@ private slots:
QStringList _selectiveSyncBlacklist;
qint64 _rSize = -1;
qint64 _rSelectedSize = -1;
+ OwncloudWizard *_ocWizard;
};
} // namespace OCC
diff --git a/src/gui/wizard/owncloudadvancedsetuppage.ui b/src/gui/wizard/owncloudadvancedsetuppage.ui
index 3b3b688dd80f..008d81742131 100644
--- a/src/gui/wizard/owncloudadvancedsetuppage.ui
+++ b/src/gui/wizard/owncloudadvancedsetuppage.ui
@@ -11,7 +11,7 @@
-
+
0
0
@@ -48,7 +48,7 @@
Qt::Vertical
- QSizePolicy::Fixed
+ QSizePolicy::Expanding
@@ -59,9 +59,291 @@