#include "ui_sharedialog.h"
#include "account.h"
+#include "accountstate.h"
#include "configfile.h"
#include "theme.h"
#include "thumbnailjob.h"
#include <QFileInfo>
#include <QFileIconProvider>
#include <QDebug>
+#include <QPointer>
#include <QPushButton>
#include <QFrame>
namespace OCC {
-ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
+ShareDialog::ShareDialog(QPointer<AccountState> accountState, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
QDialog(parent),
_ui(new Ui::ShareDialog),
- _account(account),
+ _accountState(accountState),
_sharePath(sharePath),
_localPath(localPath),
_resharingAllowed(resharingAllowed),
QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close);
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+ // We want to act on account state changes
+ connect(_accountState, SIGNAL(stateChanged(int)), SLOT(slotAccountStateChanged(int)));
+
// Because people press enter in the dialog and we don't want to close for that
closeButton->setDefault(false);
closeButton->setAutoDefault(false);
this->setWindowTitle(tr("%1 Sharing").arg(Theme::instance()->appNameGUI()));
- if (!account->capabilities().shareAPI()) {
+ if (!accountState->account()->capabilities().shareAPI()) {
_ui->shareWidgetsLayout->addWidget(new QLabel(tr("The server does not allow sharing")));
return;
}
bool autoShare = true;
// We only do user/group sharing from 8.2.0
- if (theme->userGroupSharing() && account->serverVersionInt() >= ((8 << 16) + (2 << 8))) {
- _userGroupWidget = new ShareUserGroupWidget(account, sharePath, localPath, resharingAllowed, this);
+ if (theme->userGroupSharing() && accountState->account()->serverVersionInt() >= ((8 << 16) + (2 << 8))) {
+ _userGroupWidget = new ShareUserGroupWidget(accountState->account(), sharePath, localPath, resharingAllowed, this);
_ui->shareWidgetsLayout->addWidget(_userGroupWidget);
}
if (theme->linkSharing()) {
- _linkWidget = new ShareLinkWidget(account, sharePath, localPath, resharingAllowed, autoShare, this);
+ _linkWidget = new ShareLinkWidget(accountState->account(), sharePath, localPath, resharingAllowed, autoShare, this);
_linkWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
_ui->shareWidgetsLayout->addWidget(_linkWidget);
}
void ShareDialog::getShares()
{
if (QFileInfo(_localPath).isFile()) {
- ThumbnailJob *job = new ThumbnailJob(_sharePath, _account, this);
+ ThumbnailJob *job = new ThumbnailJob(_sharePath, _accountState->account(), this);
connect(job, SIGNAL(jobFinished(int, QByteArray)), SLOT(slotThumbnailFetched(int, QByteArray)));
job->start();
}
_ui->label_icon->setPixmap(p);
}
+void ShareDialog::slotAccountStateChanged(int state) {
+ bool enabled = (state == AccountState::State::Connected);
+ qDebug() << Q_FUNC_INFO << enabled;
+
+ if (_userGroupWidget != NULL) {
+ _userGroupWidget->setEnabled(enabled);
+ }
+
+ if (_linkWidget != NULL) {
+ _linkWidget->setEnabled(enabled);
+ }
+}
+
}