-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It displays a server notification that can come with a dynamic set of buttons next to a message and a subject (=header)
- Loading branch information
Showing
3 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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; version 2 of the License. | ||
* | ||
* 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 <QPushButton> | ||
|
||
namespace OCC { | ||
|
||
NotificationWidget::NotificationWidget(QWidget *parent) : QWidget(parent) | ||
{ | ||
_ui.setupUi(this); | ||
} | ||
|
||
void NotificationWidget::setAccountName( const QString& name ) | ||
{ | ||
_accountName = name; | ||
} | ||
|
||
void NotificationWidget::setActivity(const Activity& activity) | ||
{ | ||
_myActivity = activity; | ||
|
||
Q_ASSERT( !activity._accName.isEmpty() ); | ||
_accountName = activity._accName; | ||
|
||
// _ui._headerLabel->setText( ); | ||
_ui._subjectLabel->setText(activity._subject); | ||
if( activity._message.isEmpty()) { | ||
_ui._messageLabel->hide(); | ||
} else { | ||
_ui._messageLabel->setText(activity._message); | ||
} | ||
_ui._notifIcon->setPixmap(QPixmap(":/client/resources/bell.png")); | ||
_ui._notifIcon->setMinimumWidth(64); | ||
_ui._notifIcon->setMinimumHeight(64); | ||
_ui._notifIcon->show(); | ||
|
||
// always remove the buttons | ||
foreach( auto button, _ui._buttonBox->buttons() ) { | ||
_ui._buttonBox->removeButton(button); | ||
} | ||
|
||
// display buttons for the links | ||
foreach( auto link, activity._links ) { | ||
QPushButton *b = _ui._buttonBox->addButton( link._label, QDialogButtonBox::AcceptRole); | ||
b->setDefault(link._isPrimary); | ||
connect(b, SIGNAL(clicked()), this, SLOT(slotButtonClicked())); | ||
_buttons.append(b); | ||
} | ||
} | ||
|
||
void NotificationWidget::slotButtonClicked() | ||
{ | ||
QObject *buttonWidget = QObject::sender(); | ||
int index = -1; | ||
if( buttonWidget ) { | ||
for( int i = 0; i < _buttons.count(); i++ ) { | ||
if( _buttons.at(i) == buttonWidget ) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
if( index > -1 && index < _myActivity._links.count() ) { | ||
ActivityLink triggeredLink = _myActivity._links.at(index); | ||
qDebug() << "Notification Link: "<< triggeredLink._verb << triggeredLink._link; | ||
|
||
emit sendNotificationRequest( _accountName, triggeredLink._link, triggeredLink._verb ); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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; version 2 of the License. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#ifndef NOTIFICATIONWIDGET_H | ||
#define NOTIFICATIONWIDGET_H | ||
|
||
#include <QWidget> | ||
|
||
#include "activitywidget.h" | ||
|
||
#include "ui_notificationwidget.h" | ||
|
||
namespace OCC { | ||
|
||
class NotificationWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit NotificationWidget(QWidget *parent = 0); | ||
|
||
void setAccountName( const QString& name ); | ||
|
||
signals: | ||
void sendNotificationRequest( const QString&, const QString& link, const QString& verb); | ||
|
||
public slots: | ||
void setActivity(const Activity& activity); | ||
|
||
private slots: | ||
void slotButtonClicked(); | ||
|
||
private: | ||
Ui_NotificationWidget _ui; | ||
Activity _myActivity; | ||
QList<QPushButton*> _buttons; | ||
QString _accountName; | ||
}; | ||
|
||
} | ||
|
||
#endif // NOTIFICATIONWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>NotificationWidget</class> | ||
<widget class="QWidget" name="NotificationWidget"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>725</width> | ||
<height>159</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="0" column="0"> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<widget class="QLabel" name="_notifIcon"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
<property name="pixmap"> | ||
<pixmap>../../resources/bell.png</pixmap> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QLabel" name="_subjectLabel"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="text"> | ||
<string>Lorem ipsum dolor sit amet</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QLabel" name="_messageLabel"> | ||
<property name="text"> | ||
<string>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam </string> | ||
</property> | ||
<property name="wordWrap"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="_buttonBox"> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QFrame" name="frame"> | ||
<property name="frameShape"> | ||
<enum>QFrame::HLine</enum> | ||
</property> | ||
<property name="frameShadow"> | ||
<enum>QFrame::Raised</enum> | ||
</property> | ||
<property name="lineWidth"> | ||
<number>4</number> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="0"> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>25</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |