Activities: Hide if non of the accounts has the app enabled.

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
This commit is contained in:
Klaas Freitag 2016-03-08 18:01:42 +01:00
parent 25ce5f1c22
commit 9c5b9f932b
2 changed files with 52 additions and 29 deletions

View file

@ -120,6 +120,8 @@ 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;
@ -127,13 +129,12 @@ bool ActivityListModel::canFetchMore(const QModelIndex& ) const
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;
}
@ -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();
@ -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();
}
@ -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());
}
@ -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."));
@ -324,11 +322,19 @@ void ActivityWidget::showLabels()
_ui->_bottomLabel->setText(t);
}
void ActivityWidget::slotAccountWithoutActivityApp(AccountState *ast)
void ActivityWidget::slotAccountActivityStatus(AccountState *ast, int statusCode)
{
if( ast && ast->account() ) {
_accountsWithoutActivities.insert(ast->account()->displayName());
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();
}
@ -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
@ -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);
@ -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;

View file

@ -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);
@ -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();
@ -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&);
@ -192,6 +195,8 @@ private:
bool event(QEvent* e) Q_DECL_OVERRIDE;
QTabWidget *_tab;
int _activityTabId;
ActivityWidget *_activityWidget;
ProtocolWidget *_protocolWidget;
QProgressIndicator *_progressIndicator;