added a new backend, to internaly display notifications
This commit is contained in:
parent
286ac4dd98
commit
49b79615ec
|
@ -87,6 +87,10 @@ void SnoreBackend::closeNotification(Notification n, Notification::CloseReasons
|
|||
{
|
||||
m_activeNotifications.remove(n.id());
|
||||
}
|
||||
if(n.isUpdate() && m_activeNotifications.contains(n.old().id()))
|
||||
{
|
||||
m_activeNotifications.remove(n.old().id());
|
||||
}
|
||||
n.data()->setCloseReason(reason);
|
||||
snoreDebug( SNORE_DEBUG ) << n;
|
||||
emit notificationClosed(n);
|
||||
|
|
|
@ -3,3 +3,4 @@ add_subdirectory(snarl)
|
|||
add_subdirectory(growl)
|
||||
add_subdirectory(trayicon)
|
||||
add_subdirectory(snoretoast)
|
||||
add_subdirectory(snore)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
set( SNORE_SRC
|
||||
snorenotifier.cpp
|
||||
notifywidget.cpp
|
||||
DPIScaler.cpp
|
||||
)
|
||||
|
||||
set( SNORE_FORMS
|
||||
notifywidget.ui)
|
||||
|
||||
qt4_wrap_ui(SNORE_UI ${SNORE_FORMS})
|
||||
|
||||
add_library(libsnore_backend_snore MODULE ${SNORE_SRC} ${SNORE_UI} )
|
||||
target_link_libraries(libsnore_backend_snore snorecore ${QT_QTCORE_LIBRARY} )
|
||||
|
||||
install(TARGETS libsnore_backend_snore ${SNORE_PLUGIN_INSTALL_PATH})
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Tomahawk 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "DpiScaler.h"
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
|
||||
|
||||
namespace TomahawkUtils
|
||||
{
|
||||
int DpiScaler::s_fontSize = 0;
|
||||
#ifdef Q_OS_MAC
|
||||
const qreal DpiScaler::s_baseDpi = 72.;
|
||||
#else
|
||||
const qreal DpiScaler::s_baseDpi = 96.;
|
||||
#endif
|
||||
|
||||
DpiScaler::DpiScaler( const QPaintDevice* that )
|
||||
: that( that )
|
||||
{
|
||||
m_ratioX = ratioX( that );
|
||||
m_ratioY = ratioY( that );
|
||||
}
|
||||
|
||||
|
||||
QSize
|
||||
DpiScaler::scaled( int w, int h ) const
|
||||
{
|
||||
return QSize( scaledX( w ), scaledY( h ) );
|
||||
}
|
||||
|
||||
|
||||
QSize
|
||||
DpiScaler::scaled( const QSize& size ) const
|
||||
{
|
||||
return scaled( size.width(), size.height() );
|
||||
}
|
||||
|
||||
|
||||
QMargins
|
||||
DpiScaler::scaled( int left, int top, int right, int bottom ) const
|
||||
{
|
||||
return QMargins( scaledX( left ),
|
||||
scaledY( top ),
|
||||
scaledX( right ),
|
||||
scaledY( bottom ) );
|
||||
}
|
||||
|
||||
|
||||
QMargins
|
||||
DpiScaler::scaled( const QMargins& margins ) const
|
||||
{
|
||||
return scaled( margins.left(),
|
||||
margins.top(),
|
||||
margins.right(),
|
||||
margins.bottom() );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
DpiScaler::scaledX( int x ) const
|
||||
{
|
||||
return qRound( x * m_ratioX );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
DpiScaler::scaledY( int y ) const
|
||||
{
|
||||
return qRound( y * m_ratioY );
|
||||
}
|
||||
|
||||
// static methods start here
|
||||
|
||||
QSize
|
||||
DpiScaler::scaled( const QPaintDevice* pd, int w, int h )
|
||||
{
|
||||
return QSize( scaledX( pd, w ), scaledY( pd, h ) );
|
||||
}
|
||||
|
||||
|
||||
QSize
|
||||
DpiScaler::scaled( const QPaintDevice* pd, const QSize& size )
|
||||
{
|
||||
return scaled( pd, size.width(), size.height() );
|
||||
}
|
||||
|
||||
|
||||
QMargins
|
||||
DpiScaler::scaled( const QPaintDevice* pd, int left, int top, int right, int bottom )
|
||||
{
|
||||
return QMargins( scaledX( pd, left ),
|
||||
scaledY( pd, top ),
|
||||
scaledX( pd, right ),
|
||||
scaledY( pd, bottom ) );
|
||||
}
|
||||
|
||||
|
||||
QMargins
|
||||
DpiScaler::scaled( const QPaintDevice* pd, const QMargins& margins )
|
||||
{
|
||||
return scaled( pd,
|
||||
margins.left(),
|
||||
margins.top(),
|
||||
margins.right(),
|
||||
margins.bottom() );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
DpiScaler::scaledX( const QPaintDevice* pd, int x )
|
||||
{
|
||||
return qRound( x * ratioX( pd ) );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
DpiScaler::scaledY( const QPaintDevice* pd, int y )
|
||||
{
|
||||
return qRound( y * ratioY( pd ) );
|
||||
}
|
||||
int DpiScaler::getFontSize()
|
||||
{
|
||||
return s_fontSize;
|
||||
}
|
||||
|
||||
void DpiScaler::setFontSize(int value)
|
||||
{
|
||||
s_fontSize = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
qreal
|
||||
DpiScaler::ratioX( const QPaintDevice* pd )
|
||||
{
|
||||
qreal ratioFromFH = ratioFromFontHeight();
|
||||
qreal ratioYFromDpi = pd->logicalDpiY() / s_baseDpi; //using Y because we compare with height
|
||||
|
||||
//if the error is less than 1%, we trust that the logical DPI setting has the best value
|
||||
if ( qAbs( ratioFromFH / ratioYFromDpi - 1 ) < 0.01 )
|
||||
return pd->logicalDpiX() / s_baseDpi;
|
||||
else
|
||||
return ratioFromFH;
|
||||
}
|
||||
|
||||
|
||||
qreal
|
||||
DpiScaler::ratioY( const QPaintDevice* pd )
|
||||
{
|
||||
qreal ratioFromFH = ratioFromFontHeight();
|
||||
qreal ratioYFromDpi = pd->logicalDpiY() / s_baseDpi; //using Y because we compare with height
|
||||
|
||||
//if the error is less than 1%, we trust that the logical DPI setting has the best value
|
||||
if ( qAbs( ratioFromFH / ratioYFromDpi - 1 ) < 0.01 )
|
||||
return ratioYFromDpi;
|
||||
else
|
||||
return ratioFromFH;
|
||||
}
|
||||
|
||||
|
||||
qreal
|
||||
DpiScaler::ratioFromFontHeight()
|
||||
{
|
||||
int fS = s_fontSize;
|
||||
QFont f;
|
||||
f.setPointSize( fS );
|
||||
int fH = QFontMetrics( f ).ascent() + 1; //a font's em-height should be ascent + 1px (baseline)
|
||||
|
||||
qreal basePpp = s_baseDpi / 72.; //72*(1.333)=96 dpi
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
const int baseFontSize = 13;
|
||||
#else
|
||||
const int baseFontSize = 8;
|
||||
#endif
|
||||
|
||||
qreal baseFontHeight = baseFontSize * basePpp; //we assume a minimum font size of 7pt
|
||||
|
||||
qreal ratioFromFontHeights = qMax( fH / baseFontHeight, 1. );
|
||||
return ratioFromFontHeights;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Tomahawk 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DPISCALER_H
|
||||
#define DPISCALER_H
|
||||
|
||||
|
||||
#include <QPaintDevice>
|
||||
#include <QMargins>
|
||||
#include <QSize>
|
||||
|
||||
namespace TomahawkUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The DpiScaler class provides some convenience methods to recompute fixed pixel sizes
|
||||
* into values suitable for different environment DPI settings.
|
||||
* Usage:
|
||||
* class Foo : public QWidget, private TomahawkUtils::DpiScaler {...};
|
||||
*/
|
||||
class DpiScaler
|
||||
{
|
||||
public:
|
||||
DpiScaler( const QPaintDevice* that );
|
||||
|
||||
QSize scaled( int w, int h ) const;
|
||||
QSize scaled( const QSize& size ) const;
|
||||
QMargins scaled( int left, int top, int right, int bottom ) const;
|
||||
QMargins scaled( const QMargins& margins ) const;
|
||||
int scaledX( int x ) const;
|
||||
int scaledY( int y ) const;
|
||||
|
||||
// convenience one-shot methods, usable without composing or private-inheriting DpiScaler
|
||||
static QSize scaled( const QPaintDevice* pd, int w, int h );
|
||||
static QSize scaled( const QPaintDevice* pd, const QSize& size );
|
||||
static QMargins scaled( const QPaintDevice* pd, int left, int top, int right, int bottom );
|
||||
static QMargins scaled( const QPaintDevice* pd, const QMargins& margins );
|
||||
static int scaledX( const QPaintDevice* pd, int x );
|
||||
static int scaledY( const QPaintDevice* pd, int y );
|
||||
|
||||
static int getFontSize();
|
||||
static void setFontSize(int value);
|
||||
|
||||
private:
|
||||
static int s_fontSize;
|
||||
inline static qreal ratioX( const QPaintDevice* pd );
|
||||
inline static qreal ratioY( const QPaintDevice* pd );
|
||||
inline static qreal ratioFromFontHeight();
|
||||
|
||||
qreal m_ratioX;
|
||||
qreal m_ratioY;
|
||||
|
||||
const QPaintDevice* that;
|
||||
|
||||
static const qreal s_baseDpi;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // DPISCALER_H
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "notifywidget.h"
|
||||
#include "ui_notifywidget.h"
|
||||
#include "core/log.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QPicture>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
NotifyWidget::NotifyWidget(int pos,QWidget *parent) :
|
||||
QWidget(parent, Qt::SplashScreen | Qt::WindowStaysOnTopHint),
|
||||
ui(new Ui::NotifyWidget),
|
||||
m_desktop(QDesktopWidget().availableGeometry()),
|
||||
m_id(pos)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
TomahawkUtils::DpiScaler::setFontSize(this->ui->titel->fontInfo().pointSize());
|
||||
m_scaler = new TomahawkUtils::DpiScaler(this);
|
||||
ui->closeButton->setMaximumWidth(ui->closeButton->height());
|
||||
QSize size = m_scaler->scaled(350, 90);
|
||||
setMaximumSize(size);
|
||||
setMinimumSize(size);
|
||||
resize(size);
|
||||
m_dest = QPoint(m_desktop.topRight().x() - width(), m_desktop.topRight().y() + (m_scaler->scaledY(10) + height()) * pos);
|
||||
}
|
||||
|
||||
NotifyWidget::~NotifyWidget()
|
||||
{
|
||||
delete m_scaler;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void NotifyWidget::display(const Notification ¬ification)
|
||||
{
|
||||
update(notification);
|
||||
move(m_desktop.topRight().x(), m_desktop.topRight().y() + (m_scaler->scaledY(10) + height()) * m_id);
|
||||
show();
|
||||
m_moveTimer = new QTimer(this);
|
||||
m_moveTimer->setInterval(3);
|
||||
connect( m_moveTimer, SIGNAL(timeout()), this, SLOT(slotMove()));
|
||||
m_moveTimer->start();
|
||||
}
|
||||
|
||||
void NotifyWidget::update(const Notification ¬ification)
|
||||
{
|
||||
m_notification = notification;
|
||||
ui->titel->setText(notification.title());
|
||||
ui->body->setText(notification.text());
|
||||
|
||||
QSize iconSize = m_scaler->scaled(65,65);
|
||||
ui->icon->setPixmap(QPixmap::fromImage(notification.icon().image().scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
|
||||
ui->icon->setMaximumSize(iconSize);
|
||||
|
||||
iconSize = m_scaler->scaled(20,20);
|
||||
QImage img = notification.application().icon().image().scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
ui->appIcon->setPixmap(QPixmap::fromImage(img));
|
||||
ui->appIcon->setMaximumSize(iconSize);
|
||||
|
||||
qulonglong r = 0;
|
||||
qulonglong g = 0;
|
||||
qulonglong b = 0;
|
||||
for(int x=0;x<img.width();++x)
|
||||
{
|
||||
for(int y=0;y<img.height();++y)
|
||||
{
|
||||
QRgb c = img.pixel(x,y);
|
||||
r += qRed(c);
|
||||
g += qGreen(c);
|
||||
b += qBlue(c);
|
||||
}
|
||||
}
|
||||
int s = img.width()*img.height();
|
||||
|
||||
QPalette p = palette();
|
||||
QColor bg = QColor(r/s,g/s, b/s,255);
|
||||
p.setColor(QPalette::All, QPalette::Window, bg);
|
||||
p.setColor(QPalette::All, QPalette::Background, bg);
|
||||
p.setColor(QPalette::All, QPalette::Base, bg);
|
||||
p.setColor(QPalette::All, QPalette::Text, Qt::white);
|
||||
p.setColor(QPalette::All, QPalette::BrightText, Qt::white);
|
||||
p.setColor(QPalette::All, QPalette::ButtonText, Qt::white);
|
||||
p.setColor(QPalette::All, QPalette::WindowText, Qt::white);
|
||||
setPalette(p);
|
||||
ui->closeButton->setPalette(p);
|
||||
ui->body->setPalette(p);
|
||||
ui->titel->setPalette(p);
|
||||
|
||||
}
|
||||
|
||||
Notification &NotifyWidget::notification()
|
||||
{
|
||||
return m_notification;
|
||||
}
|
||||
|
||||
int NotifyWidget::id()
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void NotifyWidget::slotMove()
|
||||
{
|
||||
move(pos().x()-1, pos().y());
|
||||
if(m_dest == pos())
|
||||
{
|
||||
m_moveTimer->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyWidget::on_closeButton_clicked()
|
||||
{
|
||||
emit dismissed();
|
||||
hide();
|
||||
}
|
||||
|
||||
void NotifyWidget::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
emit invoked();
|
||||
hide();
|
||||
QWidget::mousePressEvent(e);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NOTIFYWIDGET_H
|
||||
#define NOTIFYWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include "core/notification/notification.h"
|
||||
#include "DpiScaler.h"
|
||||
|
||||
namespace Ui {
|
||||
class NotifyWidget;
|
||||
}
|
||||
|
||||
class NotifyWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NotifyWidget(int pos, QWidget *parent = 0);
|
||||
~NotifyWidget();
|
||||
|
||||
void display(const Snore::Notification ¬ification);
|
||||
void update(const Snore::Notification ¬ification);
|
||||
|
||||
Snore::Notification ¬ification();
|
||||
|
||||
int id();
|
||||
|
||||
|
||||
signals:
|
||||
void invoked();
|
||||
void dismissed();
|
||||
|
||||
private slots:
|
||||
void slotMove();
|
||||
|
||||
void on_closeButton_clicked();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
|
||||
private:
|
||||
Ui::NotifyWidget *ui;
|
||||
QTimer *m_moveTimer;
|
||||
QPoint m_dest;
|
||||
QRect m_desktop;
|
||||
TomahawkUtils::DpiScaler *m_scaler;
|
||||
Snore::Notification m_notification;
|
||||
|
||||
int m_id;
|
||||
};
|
||||
|
||||
#endif // NOTIFYWIDGET_H
|
|
@ -0,0 +1,223 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NotifyWidget</class>
|
||||
<widget class="QWidget" name="NotifyWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>303</width>
|
||||
<height>122</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="appIcon">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>appIcon</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="icon">
|
||||
<property name="text">
|
||||
<string>Icon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="titel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="closeButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">X</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="body">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="palette">
|
||||
<palette>
|
||||
<active>
|
||||
<colorrole role="WindowText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</active>
|
||||
<inactive>
|
||||
<colorrole role="WindowText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</inactive>
|
||||
<disabled>
|
||||
<colorrole role="WindowText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</disabled>
|
||||
</palette>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="undoRedoEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Body</span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::NoTextInteraction</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "snorenotifier.h"
|
||||
#include "notifywidget.h"
|
||||
#include "core/notification/notification_p.h"
|
||||
#include "core/snore_p.h"
|
||||
#include <QApplication>
|
||||
|
||||
Q_EXPORT_PLUGIN2(libsnore_backend_snore,SnoreNotifier)
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
SnoreNotifier::SnoreNotifier():
|
||||
SnoreBackend("Snore", true, true, true),
|
||||
m_widgets(2)
|
||||
{
|
||||
moveToThread(qApp->thread());//TODO cleanup
|
||||
QTimer::singleShot(0, this, SLOT(setup()));
|
||||
|
||||
}
|
||||
|
||||
SnoreNotifier::~SnoreNotifier()
|
||||
{
|
||||
foreach (NotifyWidget *w, m_widgets)
|
||||
{
|
||||
w->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreNotifier::slotNotify(Snore::Notification notification)
|
||||
{
|
||||
|
||||
if(notification.isUpdate())
|
||||
{
|
||||
NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()];
|
||||
w->update(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
return;
|
||||
}
|
||||
else if(m_queue.isEmpty())
|
||||
{
|
||||
foreach (NotifyWidget *w, m_widgets)
|
||||
{
|
||||
if(w->isHidden())
|
||||
{
|
||||
w->display(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_queue.append(notification);
|
||||
}
|
||||
|
||||
void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
|
||||
{
|
||||
|
||||
NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()];
|
||||
if(!m_queue.isEmpty())
|
||||
{
|
||||
w->display(m_queue.takeLast());
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
}
|
||||
else
|
||||
{
|
||||
w->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SnoreNotifier::slotDismissed()
|
||||
{
|
||||
NotifyWidget *widget = qobject_cast<NotifyWidget*>(sender());
|
||||
Notification notification = widget->notification();
|
||||
closeNotification(notification, Notification::DISMISSED);
|
||||
slotCloseNotification(notification);
|
||||
}
|
||||
|
||||
void SnoreNotifier::slotInvoked()
|
||||
{
|
||||
NotifyWidget *widget = qobject_cast<NotifyWidget*>(sender());
|
||||
Notification notification = widget->notification();
|
||||
snore()->d()->notificationActionInvoked(notification);
|
||||
closeNotification(notification,Notification::CLOSED);
|
||||
slotCloseNotification(notification);
|
||||
}
|
||||
|
||||
void SnoreNotifier::setup()
|
||||
{
|
||||
for(int i=0;i<m_widgets.size();++i)
|
||||
{
|
||||
NotifyWidget *w = new NotifyWidget(i);
|
||||
m_widgets[i] = w;
|
||||
connect(w, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
|
||||
connect(w, SIGNAL(invoked()), this, SLOT(slotInvoked()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SNORENOTIFIER_H
|
||||
#define SNORENOTIFIER_H
|
||||
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include "notifywidget.h"
|
||||
|
||||
class SnoreNotifier : public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
SnoreNotifier();
|
||||
~SnoreNotifier();
|
||||
|
||||
// SnoreBackend interface
|
||||
public slots:
|
||||
virtual void slotNotify(Snore::Notification notification);
|
||||
virtual void slotCloseNotification(Snore::Notification notification);
|
||||
|
||||
private slots:
|
||||
void slotDismissed();
|
||||
void slotInvoked();
|
||||
|
||||
void setup();
|
||||
|
||||
private:
|
||||
|
||||
QList<Snore::Notification> m_queue;
|
||||
QVector<NotifyWidget*> m_widgets;
|
||||
};
|
||||
|
||||
#endif // SNORENOTIFIER_H
|
|
@ -97,20 +97,26 @@ void TrayIcon::slotTestNotification()
|
|||
{
|
||||
m_snore->registerApplication(m_app);
|
||||
}
|
||||
m_noti = Notification(m_app, m_alert, "Hello World", "This is Snore", Icon(":/root/snore.png"));
|
||||
m_noti.addAction(Action(1,"Test Action"));
|
||||
m_snore->broadcastNotification(m_noti);
|
||||
|
||||
QTimer::singleShot(m_noti.timeout()/2*1000,this,SLOT(sloutUpdateTestNotification()));
|
||||
Notification noti(m_app, m_alert, "Hello World", "This is Snore", Icon(":/root/snore.png"));
|
||||
noti.addAction(Action(1,"Test Action"));
|
||||
m_snore->broadcastNotification(noti);
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
m_notifications[timer] = noti;
|
||||
timer->setSingleShot(true);
|
||||
timer->setInterval(noti.timeout()/2*1000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(sloutUpdateTestNotification()));
|
||||
timer->start();
|
||||
|
||||
// m_snore->deregisterApplication(app);
|
||||
}
|
||||
|
||||
void TrayIcon::sloutUpdateTestNotification()
|
||||
{
|
||||
Notification update(m_noti, "Hello World", "This is Snore, color test", Icon("http://jweatherwatch.googlecode.com/svn/trunk/iconset/04.png"));
|
||||
QTimer *timer = qobject_cast<QTimer*>(sender());
|
||||
Notification noti = m_notifications.take(timer);
|
||||
Notification update(noti, "Hello World", "This is Snore, color test", Icon("http://jweatherwatch.googlecode.com/svn/trunk/iconset/04.png"));
|
||||
m_snore->broadcastNotification(update);
|
||||
m_noti = Notification();
|
||||
timer->deleteLater();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,8 @@ private:
|
|||
Snore::SnoreCore *m_snore;
|
||||
Snore::Application m_app;
|
||||
Snore::Alert m_alert;
|
||||
Snore::Notification m_noti;
|
||||
|
||||
QHash<QTimer*,Snore::Notification> m_notifications;
|
||||
|
||||
|
||||
public slots:
|
||||
|
|
Loading…
Reference in New Issue