Small fixes.

- Align progress indicator to the center.
- Moves unused code.
- Removes unused labels.

Signed-off-by: Camila San <hello@camila.codes>
This commit is contained in:
Camila San 2018-05-14 13:40:42 +02:00 committed by Roeland Jago Douma
parent a9cd3b3a6d
commit 9de3985021
No known key found for this signature in database
GPG key ID: F941078878347C0C
3 changed files with 35 additions and 225 deletions

View file

@ -70,17 +70,12 @@ ActivityWidget::ActivityWidget(AccountState *accountState, QWidget *parent)
_ui->_activityList->setAlternatingRowColors(true); _ui->_activityList->setAlternatingRowColors(true);
_ui->_activityList->setModel(_model); _ui->_activityList->setModel(_model);
_ui->_notifyLabel->hide();
_ui->_notifyScroll->hide();
// Create a widget container for the notifications. The ui file defines // Create a widget container for the notifications. The ui file defines
// a scroll area that get a widget with a layout as children // a scroll area that get a widget with a layout as children
QWidget *w = new QWidget; QWidget *w = new QWidget;
_notificationsLayout = new QVBoxLayout; _notificationsLayout = new QVBoxLayout;
w->setLayout(_notificationsLayout); w->setLayout(_notificationsLayout);
_notificationsLayout->setAlignment(Qt::AlignTop); _notificationsLayout->setAlignment(Qt::AlignTop);
_ui->_notifyScroll->setAlignment(Qt::AlignTop);
_ui->_notifyScroll->setWidget(w);
showLabels(); showLabels();
@ -267,11 +262,6 @@ void ActivityWidget::slotRemoveAccount()
void ActivityWidget::showLabels() void ActivityWidget::showLabels()
{ {
QString t = tr("Server Activities"); QString t = tr("Server Activities");
_ui->_headerLabel->setTextFormat(Qt::RichText);
_ui->_headerLabel->setText(t);
_ui->_notifyLabel->setText(tr("Action Required: Notifications"));
t.clear(); t.clear();
QSetIterator<QString> i(_accountsWithoutActivities); QSetIterator<QString> i(_accountsWithoutActivities);
while (i.hasNext()) { while (i.hasNext()) {
@ -356,12 +346,8 @@ void ActivityWidget::checkActivityTabVisibility()
_accountsWithoutActivities.count() != accountCount; _accountsWithoutActivities.count() != accountCount;
bool hasNotifications = !_widgetForNotifId.isEmpty(); bool hasNotifications = !_widgetForNotifId.isEmpty();
_ui->_headerLabel->setVisible(hasAccountsWithActivity);
_ui->_activityList->setVisible(hasAccountsWithActivity); _ui->_activityList->setVisible(hasAccountsWithActivity);
_ui->_notifyLabel->setVisible(hasNotifications);
_ui->_notifyScroll->setVisible(hasNotifications);
emit hideActivityTab(!hasAccountsWithActivity && !hasNotifications); emit hideActivityTab(!hasAccountsWithActivity && !hasNotifications);
} }
@ -383,10 +369,9 @@ void ActivityWidget::slotOpenFile(QModelIndex indx)
// collected. // collected.
void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list) void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list)
{ {
QHash<QString, int> accNotified;
QString listAccountName; QString listAccountName;
// Whether a new notification widget was added to the notificationLayout. // Whether a new notification was added to the list
bool newNotificationShown = false; bool newNotificationShown = false;
foreach (auto activity, list) { foreach (auto activity, list) {
@ -395,26 +380,6 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list)
continue; continue;
} }
// NotificationWidget *widget = 0;
// if (_widgetForNotifId.contains(activity.ident())) {
// widget = _widgetForNotifId[activity.ident()];
// } else {
// widget = new NotificationWidget(this);
// connect(widget, &NotificationWidget::sendNotificationRequest,
// this, &ActivityWidget::slotSendNotificationRequest);
// connect(widget, &NotificationWidget::requestCleanupAndBlacklist,
// this, &ActivityWidget::slotRequestCleanupAndBlacklist);
// _notificationsLayout->addWidget(widget);
//// _ui->_notifyScroll->setMinimumHeight( widget->height());
// _ui->_notifyScroll->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
// _widgetForNotifId[activity.ident()] = widget;
// newNotificationShown = true;
// }
// widget->setActivity(activity);
// remember the list account name for the strayCat handling below. // remember the list account name for the strayCat handling below.
listAccountName = activity._accName; listAccountName = activity._accName;
@ -428,22 +393,9 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list)
if (_guiLogTimer.elapsed() > 60 * 60 * 1000) { if (_guiLogTimer.elapsed() > 60 * 60 * 1000) {
_guiLoggedNotifications.clear(); _guiLoggedNotifications.clear();
} }
if (!_guiLoggedNotifications.contains(activity._id)) { if (!_guiLoggedNotifications.contains(activity._id)) {
//QString host = activity._accName; newNotificationShown = true;
// store the name of the account that sends the notification to be
// able to add it to the tray notification
// remove the user name from the account as that is not accurate here.
// int indx = host.indexOf(QChar('@'));
// if (indx > -1) {
// host.remove(0, 1 + indx);
// }
// if (!host.isEmpty()) {
// if (accNotified.contains(host)) {
// accNotified[host] = accNotified[host] + 1;
// } else {
// accNotified[host] = 1;
// }
// }
_guiLoggedNotifications.insert(activity._id); _guiLoggedNotifications.insert(activity._id);
// Assemble a tray notification for the NEW notification // Assemble a tray notification for the NEW notification
@ -460,45 +412,9 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list)
} }
} }
// restart the gui log timer now that we show a new notification
// check if there are widgets that have no corresponding activity from if(newNotificationShown)
// the server any more. Collect them in a list
// QList<Activity::Identifier> strayCats;
// foreach (auto id, _widgetForNotifId.keys()) {
// NotificationWidget *widget = _widgetForNotifId[id];
// bool found = false;
// // do not mark widgets of other accounts to delete.
// if (widget->activity()._accName != listAccountName) {
// continue;
// }
// foreach (auto activity, list) {
// if (activity.ident() == id) {
// // found an activity
// found = true;
// break;
// }
// }
// if (!found) {
// // the activity does not exist any more.
// strayCats.append(id);
// }
// }
// .. and now delete all these stray cat widgets.
// foreach (auto strayCatId, strayCats) {
// NotificationWidget *widgetToGo = _widgetForNotifId[strayCatId];
// scheduleWidgetToRemove(widgetToGo, 0);
// }
checkActivityTabVisibility();
if (newNotificationShown) {
// restart the gui log timer now that we show a notification
_guiLogTimer.start(); _guiLogTimer.start();
emit newNotification();
}
} }
void ActivityWidget::slotSendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row) void ActivityWidget::slotSendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row)
@ -624,12 +540,6 @@ void ActivityWidget::slotCheckToCleanWidgets()
if (_widgetsToRemove.isEmpty()) { if (_widgetsToRemove.isEmpty()) {
_removeTimer.stop(); _removeTimer.stop();
} }
// check to see if the whole notification pane should be hidden
if (_widgetForNotifId.isEmpty()) {
_ui->_notifyLabel->setHidden(true);
_ui->_notifyScroll->setHidden(true);
}
} }
@ -639,19 +549,21 @@ ActivitySettings::ActivitySettings(AccountState *accountState, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, _accountState(accountState) , _accountState(accountState)
{ {
QHBoxLayout *hbox = new QHBoxLayout(this); _vbox = new QVBoxLayout(this);
setLayout(hbox); setLayout(_vbox);
// create a tab widget for the three activity views
// _widget = new QWidget(this);
// hbox->addWidget(_tab);
_activityWidget = new ActivityWidget(_accountState, this); _activityWidget = new ActivityWidget(_accountState, this);
//_activityTabId = _tab->addTab(_activityWidget, Theme::instance()->applicationIcon(), tr("Server Activity")); _vbox->insertWidget(1, _activityWidget);
hbox->addWidget(_activityWidget);
connect(_activityWidget, &ActivityWidget::copyToClipboard, this, &ActivitySettings::slotCopyToClipboard); connect(_activityWidget, &ActivityWidget::copyToClipboard, this, &ActivitySettings::slotCopyToClipboard);
connect(_activityWidget, &ActivityWidget::hideActivityTab, this, &ActivitySettings::setActivityTabHidden);
connect(_activityWidget, &ActivityWidget::guiLog, this, &ActivitySettings::guiLog); connect(_activityWidget, &ActivityWidget::guiLog, this, &ActivitySettings::guiLog);
connect(_activityWidget, &ActivityWidget::newNotification, this, &ActivitySettings::slotShowActivityTab); connect(&_notificationCheckTimer, &QTimer::timeout,
this, &ActivitySettings::slotRegularNotificationCheck);
// Add a progress indicator to spin if the acitivity list is updated.
_progressIndicator = new QProgressIndicator(this);
// connect a model signal to stop the animation
connect(_activityWidget, &ActivityWidget::rowsInserted, _progressIndicator, &QProgressIndicator::stopAnimation);
connect(_activityWidget, &ActivityWidget::rowsInserted, this, &ActivitySettings::slotDisplayActivities);
_protocolWidget = new ProtocolWidget(this); _protocolWidget = new ProtocolWidget(this);
_vbox->addWidget(_protocolWidget); _vbox->addWidget(_protocolWidget);
@ -666,19 +578,10 @@ ActivitySettings::ActivitySettings(AccountState *accountState, QWidget *parent)
// this, &ActivitySettings::slotShowIssueItemCount); // this, &ActivitySettings::slotShowIssueItemCount);
// connect(_issuesWidget, &IssuesWidget::copyToClipboard, // connect(_issuesWidget, &IssuesWidget::copyToClipboard,
// this, &ActivitySettings::slotCopyToClipboard); // this, &ActivitySettings::slotCopyToClipboard);
}
// Add a progress indicator to spin if the acitivity list is updated. void ActivitySettings::slotDisplayActivities(){
_progressIndicator = new QProgressIndicator(this); _vbox->removeWidget(_progressIndicator);
//_tab->setCornerWidget(_progressIndicator);
connect(&_notificationCheckTimer, &QTimer::timeout,
this, &ActivitySettings::slotRegularNotificationCheck);
// connect a model signal to stop the animation.
connect(_activityWidget, &ActivityWidget::rowsInserted, _progressIndicator, &QProgressIndicator::stopAnimation);
// We want the protocol be the default
//_tab->setCurrentIndex(1);
} }
void ActivitySettings::setNotificationRefreshInterval(std::chrono::milliseconds interval) void ActivitySettings::setNotificationRefreshInterval(std::chrono::milliseconds interval)
@ -687,22 +590,6 @@ void ActivitySettings::setNotificationRefreshInterval(std::chrono::milliseconds
_notificationCheckTimer.start(interval.count()); _notificationCheckTimer.start(interval.count());
} }
void ActivitySettings::setActivityTabHidden(bool hidden)
{
// if (hidden && _activityTabId > -1) {
// _tab->removeTab(_activityTabId);
// _activityTabId = -1;
// _protocolTabId -= 1;
// _syncIssueTabId -= 1;
// }
// if (!hidden && _activityTabId == -1) {
// _activityTabId = _tab->insertTab(0, _activityWidget, Theme::instance()->applicationIcon(), tr("Server Activity"));
// _protocolTabId += 1;
// _syncIssueTabId += 1;
// }
}
void ActivitySettings::slotShowIssueItemCount(int cnt) void ActivitySettings::slotShowIssueItemCount(int cnt)
{ {
QString cntText = tr("Not Synced"); QString cntText = tr("Not Synced");
@ -713,22 +600,6 @@ void ActivitySettings::slotShowIssueItemCount(int cnt)
//_tab->setTabText(_syncIssueTabId, cntText); //_tab->setTabText(_syncIssueTabId, cntText);
} }
void ActivitySettings::slotShowActivityTab()
{
// if (_activityTabId != -1) {
// _tab->setCurrentIndex(_activityTabId);
// }
}
//void ActivitySettings::slotShowIssuesTab(const QString &folderAlias)
//{
// if (_syncIssueTabId == -1)
// return;
// _tab->setCurrentIndex(_syncIssueTabId);
// _issuesWidget->showFolderErrors(folderAlias);
//}
void ActivitySettings::slotCopyToClipboard() void ActivitySettings::slotCopyToClipboard()
{ {
QString text; QString text;
@ -737,11 +608,7 @@ void ActivitySettings::slotCopyToClipboard()
//int idx = _tab->currentIndex(); //int idx = _tab->currentIndex();
QString message; QString message;
// if (idx == _activityTabId) { // if (idx == _protocolTabId) {
// // the activity widget
// _activityWidget->storeActivityList(ts);
// message = tr("The server activity list has been copied to the clipboard.");
// } else if (idx == _protocolTabId) {
// // the protocol widget // // the protocol widget
// //_protocolWidget->storeSyncActivity(ts); // //_protocolWidget->storeSyncActivity(ts);
// message = tr("The sync activity list has been copied to the clipboard."); // message = tr("The sync activity list has been copied to the clipboard.");
@ -776,6 +643,8 @@ void ActivitySettings::slotRefresh()
} }
if (_accountState && _accountState->isConnected()) { if (_accountState && _accountState->isConnected()) {
if (isVisible() || !timer.isValid()) { if (isVisible() || !timer.isValid()) {
_vbox->insertWidget(0, _progressIndicator);
_vbox->setAlignment(_progressIndicator, Qt::AlignHCenter);
_progressIndicator->startAnimation(); _progressIndicator->startAnimation();
_activityWidget->slotRefreshActivities(); _activityWidget->slotRefreshActivities();
} }

View file

@ -91,7 +91,6 @@ signals:
void copyToClipboard(); void copyToClipboard();
void rowsInserted(); void rowsInserted();
void hideActivityTab(bool); void hideActivityTab(bool);
void newNotification();
void sendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row); void sendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb, int row);
private slots: private slots:
@ -158,10 +157,9 @@ public slots:
private slots: private slots:
void slotCopyToClipboard(); void slotCopyToClipboard();
void setActivityTabHidden(bool hidden);
void slotRegularNotificationCheck(); void slotRegularNotificationCheck();
void slotShowIssueItemCount(int cnt); void slotShowIssueItemCount(int cnt);
void slotShowActivityTab(); void slotDisplayActivities();
signals: signals:
void guiLog(const QString &, const QString &); void guiLog(const QString &, const QString &);
@ -173,6 +171,7 @@ private:
ProtocolWidget *_protocolWidget; ProtocolWidget *_protocolWidget;
IssuesWidget *_issuesWidget; IssuesWidget *_issuesWidget;
QProgressIndicator *_progressIndicator; QProgressIndicator *_progressIndicator;
QVBoxLayout *_vbox;
QTimer _notificationCheckTimer; QTimer _notificationCheckTimer;
QHash<AccountState *, QElapsedTimer> _timeSinceLastCheck; QHash<AccountState *, QElapsedTimer> _timeSinceLastCheck;

View file

@ -14,75 +14,7 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="_notifyLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QScrollArea" name="_notifyScroll">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="_scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>677</width>
<height>70</height>
</rect>
</property>
</widget>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="_headerLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QListView" name="_activityList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="_bottomLabel"> <widget class="QLabel" name="_bottomLabel">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
@ -98,9 +30,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0"> <item row="2" column="0">
<widget class="QDialogButtonBox" name="_dialogButtonBox"/> <widget class="QDialogButtonBox" name="_dialogButtonBox"/>
</item> </item>
<item row="0" column="0">
<widget class="QListView" name="_activityList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>