Skip to content

Commit

Permalink
Activity tab visibility fixes #4651
Browse files Browse the repository at this point in the history
  • Loading branch information
ckamm committed Apr 14, 2016
1 parent 484a2c8 commit dfd7d4d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/gui/activitywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,7 @@ void ActivityWidget::slotAccountActivityStatus(AccountState *ast, int statusCode
_accountsWithoutActivities.remove(ast->account()->displayName());
}

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

// hide the activity pane in case there are no accounts enabled.
if( _accountsWithoutActivities.count() == accountCount ) {
_ui->_headerLabel->hide();
_ui->_activityList->hide();
}
emit hideActivityTab(_accountsWithoutActivities.count() == accountCount
&& _widgetForNotifId.count() == 0 ); // do not hide if there are notifications

checkActivityTabVisibility();
showLabels();
}

Expand Down Expand Up @@ -220,6 +211,22 @@ void ActivityWidget::storeActivityList( QTextStream& ts )
}
}

void ActivityWidget::checkActivityTabVisibility()
{
int accountCount = AccountManager::instance()->accounts().count();
bool hasAccountsWithActivity =
_accountsWithoutActivities.count() != accountCount;
bool hasNotifications = !_widgetForNotifId.isEmpty();

_ui->_headerLabel->setVisible( hasAccountsWithActivity );
_ui->_activityList->setVisible( hasAccountsWithActivity );

_ui->_notifyLabel->setVisible( hasNotifications );
_ui->_notifyScroll->setVisible( hasNotifications );

emit hideActivityTab(!hasAccountsWithActivity && !hasNotifications);
}

void ActivityWidget::slotOpenFile(QModelIndex indx)
{
qDebug() << Q_FUNC_INFO << indx.isValid() << indx.data(ActivityItemDelegate::PathRole).toString() << QFile::exists(indx.data(ActivityItemDelegate::PathRole).toString());
Expand Down Expand Up @@ -332,10 +339,7 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList& list)
scheduleWidgetToRemove(widgetToGo, 0);
}

emit hideActivityTab(false);

_ui->_notifyLabel->setHidden( _widgetForNotifId.isEmpty() );
_ui->_notifyScroll->setHidden( _widgetForNotifId.isEmpty() );
checkActivityTabVisibility();

int newGuiLogCount = accNotified.count();

Expand Down Expand Up @@ -611,24 +615,24 @@ void ActivitySettings::slotRemoveAccount( AccountState *ptr )

void ActivitySettings::slotRefresh( AccountState* ptr )
{
QElapsedTimer timer = _timeSinceLastCheck[ptr];
// QElapsedTimer isn't actually constructed as invalid.
if ( !_timeSinceLastCheck.contains(ptr) ) {
_timeSinceLastCheck[ptr].invalidate();
}
QElapsedTimer & timer = _timeSinceLastCheck[ptr];

// Fetch Activities only if visible and if last check is longer than 15 secs ago
if( timer.isValid() && timer.elapsed() < NOTIFICATION_REQUEST_FREE_PERIOD ) {
qDebug() << Q_FUNC_INFO << "do not check as last check is only secs ago: " << timer.elapsed() / 1000;
return;
}
if( ptr && ptr->isConnected() ) {
if( isVisible() ) {
if( isVisible() || !timer.isValid() ) {
_progressIndicator->startAnimation();
_activityWidget->slotRefreshActivities( ptr);
}
_activityWidget->slotRefreshNotifications(ptr);
if( !( _timeSinceLastCheck[ptr].isValid() ) ) {
_timeSinceLastCheck[ptr].start();
} else {
_timeSinceLastCheck[ptr].restart();
}
timer.start();
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/gui/activitywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class ActivityWidget : public QWidget
QSize sizeHint() const Q_DECL_OVERRIDE { return ownCloudGui::settingsDialogSize(); }
void storeActivityList(QTextStream &ts);

/**
* Adjusts the activity tab's and some widgets' visibility
*
* Based on whether activities are enabled and whether notifications are
* available.
*/
void checkActivityTabVisibility();

public slots:
void slotOpenFile(QModelIndex indx);
void slotRefreshActivities(AccountState* ptr);
Expand Down

0 comments on commit dfd7d4d

Please sign in to comment.