fixed eol
This commit is contained in:
parent
f88b0e4537
commit
68165cfe83
|
@ -1,2 +1,2 @@
|
|||
*.cpp eol=lf
|
||||
*.h eol=lf
|
||||
* text eol=lf
|
||||
|
||||
|
|
|
@ -1,230 +1,230 @@
|
|||
/*
|
||||
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 "core/log.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QDesktopServices>
|
||||
#include <QPicture>
|
||||
#include <QtDeclarative/QDeclarativeView>
|
||||
#include <QLayout>
|
||||
#include <QSize>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
NotifyWidget::NotifyWidget(int pos,QWidget *parent) :
|
||||
QDeclarativeView(QUrl("qrc:/notification.qml"), parent),
|
||||
m_moveTimer(new QTimer(this)),
|
||||
m_id(pos),
|
||||
m_mem(QString("SnoreNotifyWidget_rev%1_id%2").arg(QString::number(SHARED_MEM_TYPE_REV()), QString::number(m_id))),
|
||||
m_ready(true)
|
||||
{
|
||||
qmlNotification = rootObject();
|
||||
|
||||
this->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
| Qt::WindowDoesNotAcceptFocus
|
||||
#endif
|
||||
);
|
||||
if(m_mem.create(sizeof(SHARED_MEM_TYPE)))
|
||||
{
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data();
|
||||
data->free = true;
|
||||
data->date = QTime::currentTime();
|
||||
m_mem.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!m_mem.attach())
|
||||
{
|
||||
qFatal("Failed to atatche to shared mem");
|
||||
}
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data();
|
||||
m_mem.unlock();
|
||||
snoreDebug( SNORE_DEBUG ) << "Status" << data->free << data->date.elapsed() / 1000;
|
||||
}
|
||||
|
||||
|
||||
setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
||||
|
||||
|
||||
m_moveTimer->setInterval(1);
|
||||
connect( m_moveTimer, SIGNAL(timeout()), this, SLOT(slotMove()));
|
||||
|
||||
connect( qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked()));
|
||||
connect( qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
|
||||
}
|
||||
|
||||
NotifyWidget::~NotifyWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void NotifyWidget::display(const Notification ¬ification)
|
||||
{
|
||||
update(notification);
|
||||
m_dist = 0;
|
||||
m_moveTimer->start();
|
||||
snoreDebug( SNORE_DEBUG ) << notification.id();
|
||||
move(m_start);
|
||||
show();
|
||||
}
|
||||
|
||||
void NotifyWidget::update(const Notification ¬ification)
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << m_id << notification.id();
|
||||
m_notification = notification;
|
||||
|
||||
QRect desktop = QDesktopWidget().availableGeometry();
|
||||
|
||||
resize(computeSize());
|
||||
|
||||
int space = 10 * logicalDpiY() / dpisScale();
|
||||
|
||||
m_dest = QPoint(desktop.topRight().x() - width(), desktop.topRight().y() + space + (space + height()) * m_id);
|
||||
m_start = QPoint(desktop.topRight().x(), m_dest.y());
|
||||
|
||||
QColor color;
|
||||
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
|
||||
if(vcolor.isValid())
|
||||
{
|
||||
color = vcolor.value<QColor>();
|
||||
}
|
||||
else
|
||||
{
|
||||
color = computeBackgrondColor(notification.application().icon().image().scaled(20,20));
|
||||
notification.application().constHints().setPrivateValue(parent(), "backgroundColor", color);
|
||||
}
|
||||
QRgb gray = qGray(qGray(color.rgb()) - qGray(QColor(Qt::white).rgb()));
|
||||
QColor textColor = QColor(gray, gray, gray);
|
||||
QMetaObject::invokeMethod(qmlNotification, "update", Qt::QueuedConnection,
|
||||
Q_ARG( QVariant, notification.title()),
|
||||
Q_ARG( QVariant, notification.text()),
|
||||
Q_ARG( QVariant, QUrl::fromLocalFile(notification.icon().localUrl())),
|
||||
Q_ARG( QVariant, QUrl::fromLocalFile(notification.application().icon().localUrl())),
|
||||
Q_ARG( QVariant, color),
|
||||
Q_ARG( QVariant, textColor));
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool NotifyWidget::acquire()
|
||||
{
|
||||
bool out = false;
|
||||
if(m_ready)
|
||||
{
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data();
|
||||
snoreDebug( SNORE_DEBUG ) << m_id << data->free << data->date.elapsed() / 1000;
|
||||
bool timedout = data->date.elapsed() / 1000 > 60;
|
||||
if(data->free || timedout)
|
||||
{
|
||||
if(timedout)
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << "Notification Lock timed out" << data->date.elapsed() / 1000;
|
||||
}
|
||||
data->free = false;
|
||||
data->date = QTime::currentTime();
|
||||
m_ready = false;
|
||||
out = true;
|
||||
}
|
||||
m_mem.unlock();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool NotifyWidget::release()
|
||||
{
|
||||
bool out = false;
|
||||
if(!m_ready)
|
||||
{
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data();
|
||||
snoreDebug( SNORE_DEBUG ) << m_id << data->free << data->date.elapsed() / 1000 << m_notification.id();
|
||||
if(!data->free)
|
||||
{
|
||||
data->free = true;
|
||||
m_ready = true;
|
||||
out = true;
|
||||
}
|
||||
m_mem.unlock();
|
||||
hide();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Notification &NotifyWidget::notification()
|
||||
{
|
||||
return m_notification;
|
||||
}
|
||||
|
||||
int NotifyWidget::id()
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void NotifyWidget::slotMove()
|
||||
{
|
||||
QPoint dest(m_start.x() - m_dist++, m_start.y());
|
||||
move(dest);
|
||||
if(m_dist >= width())
|
||||
{
|
||||
m_moveTimer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyWidget::slotDismissed()
|
||||
{
|
||||
emit dismissed();
|
||||
}
|
||||
|
||||
void NotifyWidget::slotInvoked()
|
||||
{
|
||||
emit invoked();
|
||||
}
|
||||
|
||||
QColor NotifyWidget::computeBackgrondColor(const QImage &img)
|
||||
{
|
||||
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();
|
||||
|
||||
return QColor(r/s, g/s, b/s);
|
||||
|
||||
}
|
||||
|
||||
QSize NotifyWidget::computeSize()
|
||||
{
|
||||
int width = 365;
|
||||
int height = 100;
|
||||
return QSize(width * logicalDpiX() / dpisScale(), height * logicalDpiY() / dpisScale());
|
||||
}
|
||||
/*
|
||||
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 "core/log.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QDesktopServices>
|
||||
#include <QPicture>
|
||||
#include <QtDeclarative/QDeclarativeView>
|
||||
#include <QLayout>
|
||||
#include <QSize>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
NotifyWidget::NotifyWidget(int pos,QWidget *parent) :
|
||||
QDeclarativeView(QUrl("qrc:/notification.qml"), parent),
|
||||
m_moveTimer(new QTimer(this)),
|
||||
m_id(pos),
|
||||
m_mem(QString("SnoreNotifyWidget_rev%1_id%2").arg(QString::number(SHARED_MEM_TYPE_REV()), QString::number(m_id))),
|
||||
m_ready(true)
|
||||
{
|
||||
qmlNotification = rootObject();
|
||||
|
||||
this->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
| Qt::WindowDoesNotAcceptFocus
|
||||
#endif
|
||||
);
|
||||
if(m_mem.create(sizeof(SHARED_MEM_TYPE)))
|
||||
{
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data();
|
||||
data->free = true;
|
||||
data->date = QTime::currentTime();
|
||||
m_mem.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!m_mem.attach())
|
||||
{
|
||||
qFatal("Failed to atatche to shared mem");
|
||||
}
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data();
|
||||
m_mem.unlock();
|
||||
snoreDebug( SNORE_DEBUG ) << "Status" << data->free << data->date.elapsed() / 1000;
|
||||
}
|
||||
|
||||
|
||||
setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
||||
|
||||
|
||||
m_moveTimer->setInterval(1);
|
||||
connect( m_moveTimer, SIGNAL(timeout()), this, SLOT(slotMove()));
|
||||
|
||||
connect( qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked()));
|
||||
connect( qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
|
||||
}
|
||||
|
||||
NotifyWidget::~NotifyWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void NotifyWidget::display(const Notification ¬ification)
|
||||
{
|
||||
update(notification);
|
||||
m_dist = 0;
|
||||
m_moveTimer->start();
|
||||
snoreDebug( SNORE_DEBUG ) << notification.id();
|
||||
move(m_start);
|
||||
show();
|
||||
}
|
||||
|
||||
void NotifyWidget::update(const Notification ¬ification)
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << m_id << notification.id();
|
||||
m_notification = notification;
|
||||
|
||||
QRect desktop = QDesktopWidget().availableGeometry();
|
||||
|
||||
resize(computeSize());
|
||||
|
||||
int space = 10 * logicalDpiY() / dpisScale();
|
||||
|
||||
m_dest = QPoint(desktop.topRight().x() - width(), desktop.topRight().y() + space + (space + height()) * m_id);
|
||||
m_start = QPoint(desktop.topRight().x(), m_dest.y());
|
||||
|
||||
QColor color;
|
||||
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
|
||||
if(vcolor.isValid())
|
||||
{
|
||||
color = vcolor.value<QColor>();
|
||||
}
|
||||
else
|
||||
{
|
||||
color = computeBackgrondColor(notification.application().icon().image().scaled(20,20));
|
||||
notification.application().constHints().setPrivateValue(parent(), "backgroundColor", color);
|
||||
}
|
||||
QRgb gray = qGray(qGray(color.rgb()) - qGray(QColor(Qt::white).rgb()));
|
||||
QColor textColor = QColor(gray, gray, gray);
|
||||
QMetaObject::invokeMethod(qmlNotification, "update", Qt::QueuedConnection,
|
||||
Q_ARG( QVariant, notification.title()),
|
||||
Q_ARG( QVariant, notification.text()),
|
||||
Q_ARG( QVariant, QUrl::fromLocalFile(notification.icon().localUrl())),
|
||||
Q_ARG( QVariant, QUrl::fromLocalFile(notification.application().icon().localUrl())),
|
||||
Q_ARG( QVariant, color),
|
||||
Q_ARG( QVariant, textColor));
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool NotifyWidget::acquire()
|
||||
{
|
||||
bool out = false;
|
||||
if(m_ready)
|
||||
{
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data();
|
||||
snoreDebug( SNORE_DEBUG ) << m_id << data->free << data->date.elapsed() / 1000;
|
||||
bool timedout = data->date.elapsed() / 1000 > 60;
|
||||
if(data->free || timedout)
|
||||
{
|
||||
if(timedout)
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << "Notification Lock timed out" << data->date.elapsed() / 1000;
|
||||
}
|
||||
data->free = false;
|
||||
data->date = QTime::currentTime();
|
||||
m_ready = false;
|
||||
out = true;
|
||||
}
|
||||
m_mem.unlock();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool NotifyWidget::release()
|
||||
{
|
||||
bool out = false;
|
||||
if(!m_ready)
|
||||
{
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE*)m_mem.data();
|
||||
snoreDebug( SNORE_DEBUG ) << m_id << data->free << data->date.elapsed() / 1000 << m_notification.id();
|
||||
if(!data->free)
|
||||
{
|
||||
data->free = true;
|
||||
m_ready = true;
|
||||
out = true;
|
||||
}
|
||||
m_mem.unlock();
|
||||
hide();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Notification &NotifyWidget::notification()
|
||||
{
|
||||
return m_notification;
|
||||
}
|
||||
|
||||
int NotifyWidget::id()
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void NotifyWidget::slotMove()
|
||||
{
|
||||
QPoint dest(m_start.x() - m_dist++, m_start.y());
|
||||
move(dest);
|
||||
if(m_dist >= width())
|
||||
{
|
||||
m_moveTimer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyWidget::slotDismissed()
|
||||
{
|
||||
emit dismissed();
|
||||
}
|
||||
|
||||
void NotifyWidget::slotInvoked()
|
||||
{
|
||||
emit invoked();
|
||||
}
|
||||
|
||||
QColor NotifyWidget::computeBackgrondColor(const QImage &img)
|
||||
{
|
||||
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();
|
||||
|
||||
return QColor(r/s, g/s, b/s);
|
||||
|
||||
}
|
||||
|
||||
QSize NotifyWidget::computeSize()
|
||||
{
|
||||
int width = 365;
|
||||
int height = 100;
|
||||
return QSize(width * logicalDpiX() / dpisScale(), height * logicalDpiY() / dpisScale());
|
||||
}
|
||||
|
|
|
@ -1,98 +1,98 @@
|
|||
/*
|
||||
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 <QSharedMemory>
|
||||
#include "core/notification/notification.h"
|
||||
|
||||
#include <QtDeclarative>
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool free;
|
||||
QTime date;
|
||||
|
||||
}SHARED_MEM_TYPE;
|
||||
|
||||
inline int SHARED_MEM_TYPE_REV()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
class NotifyWidget : public QDeclarativeView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NotifyWidget(int pos, QWidget *parent = 0);
|
||||
~NotifyWidget();
|
||||
|
||||
void display(const Snore::Notification ¬ification);
|
||||
void update(const Snore::Notification ¬ification);
|
||||
|
||||
bool acquire();
|
||||
bool release();
|
||||
|
||||
Snore::Notification ¬ification();
|
||||
|
||||
int id();
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
void invoked();
|
||||
void dismissed();
|
||||
|
||||
private slots:
|
||||
void slotMove();
|
||||
|
||||
void slotDismissed();
|
||||
|
||||
void slotInvoked();
|
||||
|
||||
protected:
|
||||
QSize computeSize();
|
||||
|
||||
inline float dpisScale()
|
||||
{
|
||||
return 96.0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
QColor computeBackgrondColor(const QImage &img);
|
||||
QTimer *m_moveTimer;
|
||||
QPoint m_dest;
|
||||
QPoint m_start;
|
||||
int m_dist;
|
||||
Snore::Notification m_notification;
|
||||
|
||||
QObject *qmlNotification;
|
||||
|
||||
int m_id;
|
||||
QSharedMemory m_mem;
|
||||
bool m_ready;
|
||||
};
|
||||
|
||||
#endif // NOTIFYWIDGET_H
|
||||
/*
|
||||
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 <QSharedMemory>
|
||||
#include "core/notification/notification.h"
|
||||
|
||||
#include <QtDeclarative>
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool free;
|
||||
QTime date;
|
||||
|
||||
}SHARED_MEM_TYPE;
|
||||
|
||||
inline int SHARED_MEM_TYPE_REV()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
class NotifyWidget : public QDeclarativeView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NotifyWidget(int pos, QWidget *parent = 0);
|
||||
~NotifyWidget();
|
||||
|
||||
void display(const Snore::Notification ¬ification);
|
||||
void update(const Snore::Notification ¬ification);
|
||||
|
||||
bool acquire();
|
||||
bool release();
|
||||
|
||||
Snore::Notification ¬ification();
|
||||
|
||||
int id();
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
void invoked();
|
||||
void dismissed();
|
||||
|
||||
private slots:
|
||||
void slotMove();
|
||||
|
||||
void slotDismissed();
|
||||
|
||||
void slotInvoked();
|
||||
|
||||
protected:
|
||||
QSize computeSize();
|
||||
|
||||
inline float dpisScale()
|
||||
{
|
||||
return 96.0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
QColor computeBackgrondColor(const QImage &img);
|
||||
QTimer *m_moveTimer;
|
||||
QPoint m_dest;
|
||||
QPoint m_start;
|
||||
int m_dist;
|
||||
Snore::Notification m_notification;
|
||||
|
||||
QObject *qmlNotification;
|
||||
|
||||
int m_id;
|
||||
QSharedMemory m_mem;
|
||||
bool m_ready;
|
||||
};
|
||||
|
||||
#endif // NOTIFYWIDGET_H
|
||||
|
|
|
@ -1,188 +1,188 @@
|
|||
/*
|
||||
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>
|
||||
#include <QThread>
|
||||
|
||||
Q_EXPORT_PLUGIN2(libsnore_backend_snore,SnoreNotifier)
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
SnoreNotifier::SnoreNotifier():
|
||||
SnoreBackend("Snore", true, true, true),
|
||||
m_widgets(2)
|
||||
{
|
||||
}
|
||||
|
||||
SnoreNotifier::~SnoreNotifier()
|
||||
{
|
||||
foreach (NotifyWidget *w, m_widgets)
|
||||
{
|
||||
w->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreNotifier::slotNotify(Snore::Notification notification)
|
||||
{
|
||||
|
||||
if(notification.isUpdate())
|
||||
{
|
||||
if(notification.old().hints().privateValue(this, "id").isValid())
|
||||
{
|
||||
NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()];
|
||||
if(w->isVisible() && w->notification().isValid() && w->notification().id() == notification.old().id())
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << "replacing notification" << w->notification().id() << notification.id();
|
||||
w->update(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < m_queue.length(); ++i)
|
||||
{
|
||||
Notification n = m_queue.at(i);
|
||||
if(n.id() == notification.old().id())
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << "replacing qued notification" << n.id() << notification.id();
|
||||
m_queue.replace(i,notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_queue.isEmpty())
|
||||
{
|
||||
foreach (NotifyWidget *w, m_widgets)
|
||||
{
|
||||
if(w->acquire())
|
||||
{
|
||||
w->display(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_queue.append(notification);
|
||||
m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
|
||||
{
|
||||
NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()];
|
||||
w->hide();
|
||||
w->release();
|
||||
//the timer will show the next
|
||||
}
|
||||
|
||||
|
||||
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::slotProcessQueue()
|
||||
{
|
||||
if(m_queue.isEmpty())
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << "queue is empty";
|
||||
m_timer->stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (NotifyWidget *w, m_widgets)
|
||||
{
|
||||
if(w->acquire())
|
||||
{
|
||||
Notification notification = m_queue.takeFirst();
|
||||
w->display(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
if(m_queue.isEmpty())
|
||||
{
|
||||
m_timer->stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setInterval(500);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotProcessQueue()));
|
||||
}
|
||||
|
||||
|
||||
bool SnoreNotifier::initialize(SnoreCore *snore)
|
||||
{
|
||||
if(SnoreBackend::initialize(snore))
|
||||
{
|
||||
return metaObject()->invokeMethod(this, "setup", Qt::QueuedConnection);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SnoreNotifier::deinitialize()
|
||||
{
|
||||
if(SnoreBackend::deinitialize())
|
||||
{
|
||||
for(int i=0;i<m_widgets.size();++i)
|
||||
{
|
||||
m_widgets[i]->release();
|
||||
m_widgets[i]->deleteLater();
|
||||
}
|
||||
m_timer->deleteLater();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
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>
|
||||
#include <QThread>
|
||||
|
||||
Q_EXPORT_PLUGIN2(libsnore_backend_snore,SnoreNotifier)
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
SnoreNotifier::SnoreNotifier():
|
||||
SnoreBackend("Snore", true, true, true),
|
||||
m_widgets(2)
|
||||
{
|
||||
}
|
||||
|
||||
SnoreNotifier::~SnoreNotifier()
|
||||
{
|
||||
foreach (NotifyWidget *w, m_widgets)
|
||||
{
|
||||
w->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreNotifier::slotNotify(Snore::Notification notification)
|
||||
{
|
||||
|
||||
if(notification.isUpdate())
|
||||
{
|
||||
if(notification.old().hints().privateValue(this, "id").isValid())
|
||||
{
|
||||
NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()];
|
||||
if(w->isVisible() && w->notification().isValid() && w->notification().id() == notification.old().id())
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << "replacing notification" << w->notification().id() << notification.id();
|
||||
w->update(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < m_queue.length(); ++i)
|
||||
{
|
||||
Notification n = m_queue.at(i);
|
||||
if(n.id() == notification.old().id())
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << "replacing qued notification" << n.id() << notification.id();
|
||||
m_queue.replace(i,notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_queue.isEmpty())
|
||||
{
|
||||
foreach (NotifyWidget *w, m_widgets)
|
||||
{
|
||||
if(w->acquire())
|
||||
{
|
||||
w->display(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_queue.append(notification);
|
||||
m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
|
||||
{
|
||||
NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()];
|
||||
w->hide();
|
||||
w->release();
|
||||
//the timer will show the next
|
||||
}
|
||||
|
||||
|
||||
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::slotProcessQueue()
|
||||
{
|
||||
if(m_queue.isEmpty())
|
||||
{
|
||||
snoreDebug( SNORE_DEBUG ) << "queue is empty";
|
||||
m_timer->stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (NotifyWidget *w, m_widgets)
|
||||
{
|
||||
if(w->acquire())
|
||||
{
|
||||
Notification notification = m_queue.takeFirst();
|
||||
w->display(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
startTimeout(notification);
|
||||
if(m_queue.isEmpty())
|
||||
{
|
||||
m_timer->stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setInterval(500);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotProcessQueue()));
|
||||
}
|
||||
|
||||
|
||||
bool SnoreNotifier::initialize(SnoreCore *snore)
|
||||
{
|
||||
if(SnoreBackend::initialize(snore))
|
||||
{
|
||||
return metaObject()->invokeMethod(this, "setup", Qt::QueuedConnection);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SnoreNotifier::deinitialize()
|
||||
{
|
||||
if(SnoreBackend::deinitialize())
|
||||
{
|
||||
for(int i=0;i<m_widgets.size();++i)
|
||||
{
|
||||
m_widgets[i]->release();
|
||||
m_widgets[i]->deleteLater();
|
||||
}
|
||||
m_timer->deleteLater();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,59 +1,59 @@
|
|||
/*
|
||||
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();
|
||||
|
||||
virtual bool initialize(Snore::SnoreCore *snore);
|
||||
virtual bool deinitialize();
|
||||
|
||||
public slots:
|
||||
virtual void slotNotify(Snore::Notification notification);
|
||||
virtual void slotCloseNotification(Snore::Notification notification);
|
||||
|
||||
private slots:
|
||||
void slotDismissed();
|
||||
void slotInvoked();
|
||||
void slotProcessQueue();
|
||||
|
||||
void setup();
|
||||
|
||||
private:
|
||||
|
||||
QList<Snore::Notification> m_queue;
|
||||
QVector<NotifyWidget*> m_widgets;
|
||||
QTimer *m_timer;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SNORENOTIFIER_H
|
||||
/*
|
||||
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();
|
||||
|
||||
virtual bool initialize(Snore::SnoreCore *snore);
|
||||
virtual bool deinitialize();
|
||||
|
||||
public slots:
|
||||
virtual void slotNotify(Snore::Notification notification);
|
||||
virtual void slotCloseNotification(Snore::Notification notification);
|
||||
|
||||
private slots:
|
||||
void slotDismissed();
|
||||
void slotInvoked();
|
||||
void slotProcessQueue();
|
||||
|
||||
void setup();
|
||||
|
||||
private:
|
||||
|
||||
QList<Snore::Notification> m_queue;
|
||||
QVector<NotifyWidget*> m_widgets;
|
||||
QTimer *m_timer;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SNORENOTIFIER_H
|
||||
|
|
Loading…
Reference in New Issue