forked from owncloud/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotificationwidget.cpp
More file actions
145 lines (124 loc) · 4.84 KB
/
Copy pathnotificationwidget.cpp
File metadata and controls
145 lines (124 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "notificationwidget.h"
#include "QProgressIndicator.h"
#include "common/utility.h"
#include "common/asserts.h"
#include "guiutility.h"
#include <QPushButton>
#include "ocsjob.h"
namespace OCC {
Q_LOGGING_CATEGORY(lcNotifications, "gui.notifications", QtInfoMsg)
NotificationWidget::NotificationWidget(QWidget *parent)
: QWidget(parent)
{
_ui.setupUi(this);
_progressIndi = new QProgressIndicator(this);
_ui.horizontalLayout->addWidget(_progressIndi);
}
void NotificationWidget::setActivity(const Activity &activity)
{
_myActivity = activity;
_accountName = activity.accName();
OC_ASSERT(!_accountName.isEmpty());
// _ui._headerLabel->setText( );
_ui._subjectLabel->setVisible(!activity.subject().isEmpty());
_ui._messageLabel->setVisible(!activity.message().isEmpty());
if (activity.link().isEmpty()) {
_ui._subjectLabel->setText(activity.subject());
} else {
_ui._subjectLabel->setText(QString("<a href=\"%1\">%2</a>")
.arg(activity.link().toString(QUrl::FullyEncoded),
activity.subject().toHtmlEscaped()));
_ui._subjectLabel->setTextFormat(Qt::RichText);
_ui._subjectLabel->setOpenExternalLinks(true);
}
_ui._messageLabel->setText(activity.message());
QString tText = tr("Created at %1").arg(Utility::timeAgoInWords(activity.dateTime()));
_ui._timeLabel->setText(tText);
// always remove the buttons
qDeleteAll(_buttons);
_buttons.clear();
// display buttons for the links
if (activity.links().isEmpty()) {
// in case there is no action defined, do a close button.
QPushButton *b = _ui._buttonBox->addButton(QDialogButtonBox::Close);
b->setDefault(true);
connect(b, &QAbstractButton::clicked, this, [this]{
QString doneText = tr("Closing in a few seconds...");
_ui._timeLabel->setText(doneText);
emit requestCleanupAndBlacklist(_myActivity);
return;
});
} else {
for (const auto &link : activity.links()) {
QPushButton *b = _ui._buttonBox->addButton(link._label, QDialogButtonBox::AcceptRole);
b->setDefault(link._isPrimary);
connect(b, &QAbstractButton::clicked, this, [this, b, link] {
slotButtonClicked(b, link);
});
_buttons.append(b);
}
}
}
Activity NotificationWidget::activity() const
{
return _myActivity;
}
void NotificationWidget::slotButtonClicked(QPushButton *buttonWidget, const ActivityLink &triggeredLink)
{
buttonWidget->setEnabled(false);
_actionLabel = triggeredLink._label;
if (!triggeredLink._link.isEmpty()) {
qCInfo(lcNotifications) << "Notification Link: " << triggeredLink._verb << triggeredLink._link;
_progressIndi->startAnimation();
emit sendNotificationRequest(_accountName, triggeredLink._link, triggeredLink._verb);
}
}
void NotificationWidget::slotNotificationRequestFinished(int statusCode)
{
QString doneText;
QLocale locale;
QString timeStr = locale.toString(QTime::currentTime());
// the ocs API returns stat code 100 or 200 inside the xml if it succeeded.
if (statusCode != OCS_SUCCESS_STATUS_CODE && statusCode != OCS_SUCCESS_STATUS_CODE_V2) {
qCWarning(lcNotifications) << "Notification Request to Server failed, leave button visible.";
for (auto *button : qAsConst(_buttons)) {
button->setEnabled(true);
}
//: The second parameter is a time, such as 'failed at 09:58pm'
doneText = tr("%1 request failed at %2").arg(_actionLabel, timeStr);
} else {
// the call to the ocs API succeeded.
_ui._buttonBox->hide();
//: The second parameter is a time, such as 'selected at 09:58pm'
doneText = tr("'%1' selected at %2").arg(_actionLabel, timeStr);
}
_ui._timeLabel->setText(doneText);
_progressIndi->stopAnimation();
}
void NotificationWidget::changeEvent(QEvent *e)
{
switch (e->type()) {
case QEvent::StyleChange:
case QEvent::PaletteChange:
case QEvent::ThemeChange:
_ui._notifIcon->setPixmap(Utility::getCoreIcon(QStringLiteral("bell")).pixmap(_ui._notifIcon->size()));
break;
default:
break;
}
QWidget::changeEvent(e);
}
}