Skip to content

Commit

Permalink
Activities: Hide if non of the accounts has the app enabled.
Browse files Browse the repository at this point in the history
If the ownCloud server does not have the activity app enabled,
it returns 999 as status code. If all the configured accounts
do that, this code hides the entire tab with the server
activities.

This is supposed to fix #4533
  • Loading branch information
Klaas Freitag committed Mar 8, 2016
1 parent 25ce5f1 commit 9c5b9f9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 28 deletions.
70 changes: 44 additions & 26 deletions src/gui/activitywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,21 @@ int ActivityListModel::rowCount(const QModelIndex&) const
}

// current strategy: Fetch 100 items per Account
// ATTENTION: This method is const and thus it is not possible to modify
// the _activityLists hash or so. Doesn't make it easier...
bool ActivityListModel::canFetchMore(const QModelIndex& ) const
{
if( _activityLists.count() == 0 ) return true;

QMap<AccountState*, ActivityList>::const_iterator i = _activityLists.begin();
while (i != _activityLists.end()) {
AccountState *ast = i.key();
if( !ast->isConnected() ) {
return false;
}
ActivityList activities = i.value();
if( activities.count() == 0 &&
! _currentlyFetching.contains(ast) ) {
return true;
if( ast && ast->isConnected() ) {
ActivityList activities = i.value();
if( activities.count() == 0 &&
! _currentlyFetching.contains(ast) ) {
return true;
}
}
++i;
}
Expand Down Expand Up @@ -167,15 +168,15 @@ void ActivityListModel::slotActivitiesReceived(const QVariantMap& json, int stat
qDebug() << "*** activities" << activities;

ActivityList list;
AccountState* ai = qvariant_cast<AccountState*>(sender()->property("AccountStatePtr"));
_currentlyFetching.remove(ai);
list.setAccountName( ai->account()->displayName());
AccountState* ast = qvariant_cast<AccountState*>(sender()->property("AccountStatePtr"));
_currentlyFetching.remove(ast);
list.setAccountName( ast->account()->displayName());

foreach( auto activ, activities ) {
auto json = activ.toMap();

Activity a;
a._accName = ai->account()->displayName();
a._accName = ast->account()->displayName();
a._id = json.value("id").toLongLong();
a._subject = json.value("subject").toString();
a._message = json.value("message").toString();
Expand All @@ -186,11 +187,9 @@ void ActivityListModel::slotActivitiesReceived(const QVariantMap& json, int stat
list.append(a);
}

_activityLists[ai] = list;
_activityLists[ast] = list;

if( statusCode == 999 ) {
emit accountWithoutActivityApp(ai);
}
emit activityJobStatusCode(ast, statusCode);

combineActivityLists();
}
Expand All @@ -217,12 +216,11 @@ void ActivityListModel::fetchMore(const QModelIndex &)

foreach (AccountStatePtr asp, accounts) {
bool newItem = false;
// if the account is not yet managed, add an empty list.
if( !_activityLists.contains(asp.data()) ) {

if( !_activityLists.contains(asp.data()) && asp->isConnected() ) {
_activityLists[asp.data()] = ActivityList();
newItem = true;
}
ActivityList activities = _activityLists[asp.data()];
if( newItem ) {
startFetchJob(asp.data());
}
Expand Down Expand Up @@ -281,8 +279,8 @@ ActivityWidget::ActivityWidget(QWidget *parent) :

showLabels();

connect(_model, SIGNAL(accountWithoutActivityApp(AccountState*)),
this, SLOT(slotAccountWithoutActivityApp(AccountState*)));
connect(_model, SIGNAL(activityJobStatusCode(AccountState*,int)),
this, SLOT(slotAccountActivityStatus(AccountState*,int)));

_copyBtn = _ui->_dialogButtonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
_copyBtn->setToolTip( tr("Copy the activity list to the clipboard."));
Expand Down Expand Up @@ -324,12 +322,20 @@ void ActivityWidget::showLabels()
_ui->_bottomLabel->setText(t);
}

void ActivityWidget::slotAccountWithoutActivityApp(AccountState *ast)
void ActivityWidget::slotAccountActivityStatus(AccountState *ast, int statusCode)
{
if( ast && ast->account() ) {
if( !(ast && ast->account()) ) {
return;
}
if( statusCode == 999 ) {
_accountsWithoutActivities.insert(ast->account()->displayName());
} else {
_accountsWithoutActivities.remove(ast->account()->displayName());
}

int accountCount = AccountManager::instance()->accounts().count();
emit hideAcitivityTab(_accountsWithoutActivities.count() == accountCount);

showLabels();
}

Expand Down Expand Up @@ -406,12 +412,12 @@ ActivitySettings::ActivitySettings(QWidget *parent)
_tab = new QTabWidget(this);
hbox->addWidget(_tab);
_activityWidget = new ActivityWidget(this);
_tab->addTab(_activityWidget, Theme::instance()->applicationIcon(), tr("Server Activity"));
_activityTabId = _tab->insertTab(0, _activityWidget, Theme::instance()->applicationIcon(), tr("Server Activity"));
connect(_activityWidget, SIGNAL(copyToClipboard()), this, SLOT(slotCopyToClipboard()));

connect(_activityWidget, SIGNAL(hideAcitivityTab(bool)), this, SLOT(setActivityTabHidden(bool)));

_protocolWidget = new ProtocolWidget(this);
_tab->addTab(_protocolWidget, Theme::instance()->syncStateIcon(SyncResult::Success), tr("Sync Protocol"));
_tab->insertTab(1, _protocolWidget, Theme::instance()->syncStateIcon(SyncResult::Success), tr("Sync Protocol"));
connect(_protocolWidget, SIGNAL(copyToClipboard()), this, SLOT(slotCopyToClipboard()));

// Add the not-synced list into the tab
Expand All @@ -427,7 +433,7 @@ ActivitySettings::ActivitySettings(QWidget *parent)
connect(_copyBtn, SIGNAL(clicked()), this, SLOT(slotCopyToClipboard()));

w->setLayout(vbox2);
_tab->addTab(w, Theme::instance()->syncStateIcon(SyncResult::Problem), tr("Not Synced"));
_tab->insertTab(2, w, Theme::instance()->syncStateIcon(SyncResult::Problem), tr("Not Synced"));

// Add a progress indicator to spin if the acitivity list is updated.
_progressIndicator = new QProgressIndicator(this);
Expand All @@ -437,6 +443,18 @@ ActivitySettings::ActivitySettings(QWidget *parent)
connect(_activityWidget, SIGNAL(rowsInserted()), _progressIndicator, SLOT(stopAnimation()));
}

void ActivitySettings::setActivityTabHidden(bool hidden)
{
if( hidden && _activityTabId > -1 ) {
_tab->removeTab(_activityTabId);
_activityTabId = -1;
}

if( !hidden && _activityTabId == -1 ) {
_activityTabId = _tab->insertTab(0, _activityWidget, Theme::instance()->applicationIcon(), tr("Server Activity"));
}
}

void ActivitySettings::slotCopyToClipboard()
{
QString text;
Expand Down
9 changes: 7 additions & 2 deletions src/gui/activitywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private slots:
void slotActivitiesReceived(const QVariantMap& json, int statusCode);

signals:
void accountWithoutActivityApp(AccountState* ast);
void activityJobStatusCode(AccountState* ast, int statusCode);

private:
void startFetchJob(AccountState* s);
Expand Down Expand Up @@ -145,12 +145,13 @@ public slots:
void slotOpenFile(QModelIndex indx);
void slotRefresh(AccountState* ptr);
void slotRemoveAccount( AccountState *ptr );
void slotAccountWithoutActivityApp(AccountState *ast);
void slotAccountActivityStatus(AccountState *ast, int statusCode);

signals:
void guiLog(const QString&, const QString&);
void copyToClipboard();
void rowsInserted();
void hideAcitivityTab(bool);

private:
void showLabels();
Expand Down Expand Up @@ -183,7 +184,9 @@ public slots:
void slotRefresh( AccountState* ptr );
void slotRemoveAccount( AccountState *ptr );

private slots:
void slotCopyToClipboard();
void setActivityTabHidden(bool hidden);

signals:
void guiLog(const QString&, const QString&);
Expand All @@ -192,6 +195,8 @@ public slots:
bool event(QEvent* e) Q_DECL_OVERRIDE;

QTabWidget *_tab;
int _activityTabId;

ActivityWidget *_activityWidget;
ProtocolWidget *_protocolWidget;
QProgressIndicator *_progressIndicator;
Expand Down

0 comments on commit 9c5b9f9

Please sign in to comment.