fixed eol
This commit is contained in:
parent
a125761e6f
commit
86efd28f68
|
@ -1,48 +1,48 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "hint.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Hint::Hint(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void Hint::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
m_data[key] = value;
|
||||
}
|
||||
|
||||
QVariant Hint::value(const QString &key, const QVariant &defaultValue) const
|
||||
{
|
||||
if(m_data.contains(key))
|
||||
{
|
||||
return m_data[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
bool Hint::contains(const QString &key) const
|
||||
{
|
||||
return m_data.contains(key);
|
||||
}
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "hint.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Hint::Hint(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void Hint::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
m_data[key] = value;
|
||||
}
|
||||
|
||||
QVariant Hint::value(const QString &key, const QVariant &defaultValue) const
|
||||
{
|
||||
if(m_data.contains(key))
|
||||
{
|
||||
return m_data[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
bool Hint::contains(const QString &key) const
|
||||
{
|
||||
return m_data.contains(key);
|
||||
}
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 HINT_H
|
||||
#define HINT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariantHash>
|
||||
|
||||
#include "snore_exports.h"
|
||||
|
||||
namespace Snore
|
||||
{
|
||||
|
||||
|
||||
class SNORE_EXPORT Hint : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Hint(QObject *parent = 0);
|
||||
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const;
|
||||
bool contains ( const QString & key ) const;
|
||||
|
||||
private:
|
||||
QVariantHash m_data;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // HINT_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 HINT_H
|
||||
#define HINT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariantHash>
|
||||
|
||||
#include "snore_exports.h"
|
||||
|
||||
namespace Snore
|
||||
{
|
||||
|
||||
|
||||
class SNORE_EXPORT Hint : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Hint(QObject *parent = 0);
|
||||
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const;
|
||||
bool contains ( const QString & key ) const;
|
||||
|
||||
private:
|
||||
QVariantHash m_data;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // HINT_H
|
||||
|
|
|
@ -1,117 +1,117 @@
|
|||
/****************************************************************************************
|
||||
* Copyright (c) 2011-2012 Patrick von Reth <patrick.vonreth@gmail.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. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "icon.h"
|
||||
#include "../snore.h"
|
||||
|
||||
#include "notification/icon_p.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
|
||||
QHash<QString,QString> Icon::m_localImageCache;
|
||||
|
||||
Icon::Icon() :
|
||||
d(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Icon::Icon(const QImage &img):
|
||||
d(new IconData(img))
|
||||
{
|
||||
}
|
||||
|
||||
Icon::Icon(const QString &url):
|
||||
d(new IconData(url))
|
||||
{
|
||||
}
|
||||
|
||||
Icon::Icon(const Icon &other):
|
||||
d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
Icon &Icon::operator=(const Icon &other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Icon::~Icon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const QImage &Icon::image() const{
|
||||
if(d->m_img.isNull()){
|
||||
d->m_img = QImage(d->m_url);
|
||||
}
|
||||
return d->m_img;
|
||||
}
|
||||
|
||||
QString Icon::localUrl()const{
|
||||
if(d->m_localUrl.isEmpty())
|
||||
{
|
||||
if(m_localImageCache.contains(hash()))
|
||||
{
|
||||
d->m_localUrl = m_localImageCache[hash()];
|
||||
}
|
||||
else
|
||||
{
|
||||
d->m_localUrl = QString("%1%2.png").arg(SnoreCore::snoreTMP(), hash());
|
||||
image().save(d->m_localUrl ,"PNG");
|
||||
m_localImageCache[hash()] = d->m_localUrl;
|
||||
}
|
||||
}
|
||||
return d->m_localUrl;
|
||||
}
|
||||
|
||||
const QByteArray &Icon::imageData() const{
|
||||
if(d->m_data.isEmpty() && !image().isNull()){
|
||||
d->setImageData();
|
||||
}
|
||||
return d->m_data;
|
||||
}
|
||||
|
||||
QString Icon::hash() const{
|
||||
if(d->m_isLocalFile)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if(d->m_hash.isEmpty() && !imageData().isNull()){
|
||||
d->m_hash = IconData::computeHash(imageData());
|
||||
}
|
||||
return d->m_hash;
|
||||
}
|
||||
|
||||
bool Icon::isLocalFile() const
|
||||
{
|
||||
return d->m_isLocalFile;
|
||||
}
|
||||
|
||||
bool Icon::isEmpty() const{
|
||||
return d->m_hash.isEmpty() && d->m_img.isNull() && d->m_localUrl.isEmpty();
|
||||
}
|
||||
|
||||
bool Icon::isValid() const
|
||||
{
|
||||
return d;
|
||||
}
|
||||
|
||||
QString Icon::url() const
|
||||
{
|
||||
return d->m_url;
|
||||
}
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2011-2012 Patrick von Reth <patrick.vonreth@gmail.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. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "icon.h"
|
||||
#include "../snore.h"
|
||||
|
||||
#include "notification/icon_p.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
|
||||
QHash<QString,QString> Icon::m_localImageCache;
|
||||
|
||||
Icon::Icon() :
|
||||
d(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Icon::Icon(const QImage &img):
|
||||
d(new IconData(img))
|
||||
{
|
||||
}
|
||||
|
||||
Icon::Icon(const QString &url):
|
||||
d(new IconData(url))
|
||||
{
|
||||
}
|
||||
|
||||
Icon::Icon(const Icon &other):
|
||||
d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
Icon &Icon::operator=(const Icon &other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Icon::~Icon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const QImage &Icon::image() const{
|
||||
if(d->m_img.isNull()){
|
||||
d->m_img = QImage(d->m_url);
|
||||
}
|
||||
return d->m_img;
|
||||
}
|
||||
|
||||
QString Icon::localUrl()const{
|
||||
if(d->m_localUrl.isEmpty())
|
||||
{
|
||||
if(m_localImageCache.contains(hash()))
|
||||
{
|
||||
d->m_localUrl = m_localImageCache[hash()];
|
||||
}
|
||||
else
|
||||
{
|
||||
d->m_localUrl = QString("%1%2.png").arg(SnoreCore::snoreTMP(), hash());
|
||||
image().save(d->m_localUrl ,"PNG");
|
||||
m_localImageCache[hash()] = d->m_localUrl;
|
||||
}
|
||||
}
|
||||
return d->m_localUrl;
|
||||
}
|
||||
|
||||
const QByteArray &Icon::imageData() const{
|
||||
if(d->m_data.isEmpty() && !image().isNull()){
|
||||
d->setImageData();
|
||||
}
|
||||
return d->m_data;
|
||||
}
|
||||
|
||||
QString Icon::hash() const{
|
||||
if(d->m_isLocalFile)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if(d->m_hash.isEmpty() && !imageData().isNull()){
|
||||
d->m_hash = IconData::computeHash(imageData());
|
||||
}
|
||||
return d->m_hash;
|
||||
}
|
||||
|
||||
bool Icon::isLocalFile() const
|
||||
{
|
||||
return d->m_isLocalFile;
|
||||
}
|
||||
|
||||
bool Icon::isEmpty() const{
|
||||
return d->m_hash.isEmpty() && d->m_img.isNull() && d->m_localUrl.isEmpty();
|
||||
}
|
||||
|
||||
bool Icon::isValid() const
|
||||
{
|
||||
return d;
|
||||
}
|
||||
|
||||
QString Icon::url() const
|
||||
{
|
||||
return d->m_url;
|
||||
}
|
||||
|
|
|
@ -1,70 +1,70 @@
|
|||
/****************************************************************************************
|
||||
* Copyright (c) 2011-2012 Patrick von Reth <patrick.vonreth@gmail.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. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef NOTIFICATION_ICON_H
|
||||
#define NOTIFICATION_ICON_H
|
||||
#include "../snore_exports.h"
|
||||
|
||||
#include <QSharedData>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class IconData;
|
||||
|
||||
class SNORE_EXPORT Icon
|
||||
{
|
||||
public:
|
||||
Icon();
|
||||
Icon(const QImage &img);
|
||||
Icon(const class QString &url);
|
||||
Icon(const Icon &other);
|
||||
Icon &operator=(const Icon &other);
|
||||
~Icon();
|
||||
|
||||
const QImage &image() const;
|
||||
QString localUrl() const;
|
||||
QString url() const;
|
||||
const QByteArray &imageData() const ;
|
||||
QString hash() const;
|
||||
bool isLocalFile() const;
|
||||
bool isEmpty() const;
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
private:
|
||||
static QHash<QString,QString> m_localImageCache;
|
||||
|
||||
QExplicitlySharedDataPointer<IconData> d;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
inline QDebug operator<< ( QDebug debug, const Snore::Icon &icon )
|
||||
{
|
||||
if(icon.isValid())
|
||||
{
|
||||
debug << "Snore::Icon(" << icon.url() << ")" ;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug << "Snore::Icon(0x00)" ;
|
||||
}
|
||||
return debug.maybeSpace();
|
||||
}
|
||||
|
||||
|
||||
#endif // NOTIFICATION_ICON_H
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2011-2012 Patrick von Reth <patrick.vonreth@gmail.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. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef NOTIFICATION_ICON_H
|
||||
#define NOTIFICATION_ICON_H
|
||||
#include "../snore_exports.h"
|
||||
|
||||
#include <QSharedData>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class IconData;
|
||||
|
||||
class SNORE_EXPORT Icon
|
||||
{
|
||||
public:
|
||||
Icon();
|
||||
Icon(const QImage &img);
|
||||
Icon(const class QString &url);
|
||||
Icon(const Icon &other);
|
||||
Icon &operator=(const Icon &other);
|
||||
~Icon();
|
||||
|
||||
const QImage &image() const;
|
||||
QString localUrl() const;
|
||||
QString url() const;
|
||||
const QByteArray &imageData() const ;
|
||||
QString hash() const;
|
||||
bool isLocalFile() const;
|
||||
bool isEmpty() const;
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
private:
|
||||
static QHash<QString,QString> m_localImageCache;
|
||||
|
||||
QExplicitlySharedDataPointer<IconData> d;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
inline QDebug operator<< ( QDebug debug, const Snore::Icon &icon )
|
||||
{
|
||||
if(icon.isValid())
|
||||
{
|
||||
debug << "Snore::Icon(" << icon.url() << ")" ;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug << "Snore::Icon(0x00)" ;
|
||||
}
|
||||
return debug.maybeSpace();
|
||||
}
|
||||
|
||||
|
||||
#endif // NOTIFICATION_ICON_H
|
||||
|
|
|
@ -1,79 +1,79 @@
|
|||
#ifndef ICONDATA_H
|
||||
#define ICONDATA_H
|
||||
|
||||
|
||||
#include "notification.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QSharedData>
|
||||
#include <QBuffer>
|
||||
#include <QHash>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class IconData : public QSharedData
|
||||
{
|
||||
public:
|
||||
IconData(const QString &url):
|
||||
m_url(url),
|
||||
m_isLocalFile(false)
|
||||
{
|
||||
if(m_url.startsWith(":/"))
|
||||
{
|
||||
m_hash = computeHash(m_url.toLatin1());
|
||||
}
|
||||
else if(QFile(url).exists())
|
||||
{
|
||||
m_isLocalFile = true;
|
||||
m_localUrl = url;
|
||||
}
|
||||
}
|
||||
|
||||
IconData(const QImage &img):
|
||||
m_img(img),
|
||||
m_isLocalFile(false)
|
||||
{
|
||||
setImageData();
|
||||
}
|
||||
|
||||
~IconData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setImageData()
|
||||
{
|
||||
QBuffer buffer( &m_data );
|
||||
buffer.open( QBuffer::WriteOnly );
|
||||
m_img.save( &buffer, "PNG" );
|
||||
|
||||
if(m_hash.isEmpty())
|
||||
{
|
||||
m_hash = computeHash(m_data);
|
||||
}
|
||||
}
|
||||
|
||||
static QString computeHash(const QByteArray &data)
|
||||
{
|
||||
QCryptographicHash h(QCryptographicHash::Md5);
|
||||
h.addData(data);
|
||||
return h.result().toHex();
|
||||
}
|
||||
|
||||
QImage m_img;
|
||||
QByteArray m_data;
|
||||
QString m_localUrl;
|
||||
QString m_url;
|
||||
QString m_hash;
|
||||
bool m_isLocalFile;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(IconData)
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // ICONDATA_H
|
||||
#ifndef ICONDATA_H
|
||||
#define ICONDATA_H
|
||||
|
||||
|
||||
#include "notification.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QSharedData>
|
||||
#include <QBuffer>
|
||||
#include <QHash>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class IconData : public QSharedData
|
||||
{
|
||||
public:
|
||||
IconData(const QString &url):
|
||||
m_url(url),
|
||||
m_isLocalFile(false)
|
||||
{
|
||||
if(m_url.startsWith(":/"))
|
||||
{
|
||||
m_hash = computeHash(m_url.toLatin1());
|
||||
}
|
||||
else if(QFile(url).exists())
|
||||
{
|
||||
m_isLocalFile = true;
|
||||
m_localUrl = url;
|
||||
}
|
||||
}
|
||||
|
||||
IconData(const QImage &img):
|
||||
m_img(img),
|
||||
m_isLocalFile(false)
|
||||
{
|
||||
setImageData();
|
||||
}
|
||||
|
||||
~IconData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setImageData()
|
||||
{
|
||||
QBuffer buffer( &m_data );
|
||||
buffer.open( QBuffer::WriteOnly );
|
||||
m_img.save( &buffer, "PNG" );
|
||||
|
||||
if(m_hash.isEmpty())
|
||||
{
|
||||
m_hash = computeHash(m_data);
|
||||
}
|
||||
}
|
||||
|
||||
static QString computeHash(const QByteArray &data)
|
||||
{
|
||||
QCryptographicHash h(QCryptographicHash::Md5);
|
||||
h.addData(data);
|
||||
return h.result().toHex();
|
||||
}
|
||||
|
||||
QImage m_img;
|
||||
QByteArray m_data;
|
||||
QString m_localUrl;
|
||||
QString m_url;
|
||||
QString m_hash;
|
||||
bool m_isLocalFile;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(IconData)
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // ICONDATA_H
|
||||
|
|
|
@ -1,69 +1,69 @@
|
|||
#ifndef NOTIFICATIONDATA_H
|
||||
#define NOTIFICATIONDATA_H
|
||||
|
||||
|
||||
#include "notification/icon.h"
|
||||
#include "notification/notificationenums.h"
|
||||
#include "../hint.h"
|
||||
|
||||
#include <QSharedData>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class NotificationData : public QSharedData
|
||||
{
|
||||
|
||||
public:
|
||||
NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const Icon &icon,
|
||||
int timeout,NotificationEnums::Prioritys::prioritys priority ):
|
||||
m_id ( m_idCount++ ),
|
||||
m_updateID(0),
|
||||
m_timeout ( timeout ),
|
||||
m_source ( NULL),
|
||||
m_application ( application ),
|
||||
m_alert ( alert ),
|
||||
m_title ( title ),
|
||||
m_text ( text ),
|
||||
m_icon ( icon ),
|
||||
m_priority(priority),
|
||||
m_closeReason(NotificationEnums::CloseReasons::NONE),
|
||||
m_actionInvoked( NULL )
|
||||
{
|
||||
notificationCount++;
|
||||
qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
}
|
||||
|
||||
~NotificationData()
|
||||
{
|
||||
notificationCount--;
|
||||
qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
}
|
||||
|
||||
|
||||
uint m_id;
|
||||
uint m_updateID;
|
||||
int m_timeout;
|
||||
SnoreFrontend *m_source;
|
||||
QString m_application;
|
||||
QString m_alert;
|
||||
QString m_title;
|
||||
QString m_text;
|
||||
Icon m_icon;
|
||||
NotificationEnums::Prioritys::prioritys m_priority;
|
||||
NotificationEnums::CloseReasons::closeReasons m_closeReason;
|
||||
Notification::Action *m_actionInvoked;
|
||||
QHash<int,Notification::Action*> m_actions;
|
||||
Hint m_hints;
|
||||
|
||||
static uint notificationCount;
|
||||
static uint m_idCount;
|
||||
static int notificationMetaID;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(NotificationData)
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NOTIFICATIONDATA_H
|
||||
#ifndef NOTIFICATIONDATA_H
|
||||
#define NOTIFICATIONDATA_H
|
||||
|
||||
|
||||
#include "notification/icon.h"
|
||||
#include "notification/notificationenums.h"
|
||||
#include "../hint.h"
|
||||
|
||||
#include <QSharedData>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class NotificationData : public QSharedData
|
||||
{
|
||||
|
||||
public:
|
||||
NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const Icon &icon,
|
||||
int timeout,NotificationEnums::Prioritys::prioritys priority ):
|
||||
m_id ( m_idCount++ ),
|
||||
m_updateID(0),
|
||||
m_timeout ( timeout ),
|
||||
m_source ( NULL),
|
||||
m_application ( application ),
|
||||
m_alert ( alert ),
|
||||
m_title ( title ),
|
||||
m_text ( text ),
|
||||
m_icon ( icon ),
|
||||
m_priority(priority),
|
||||
m_closeReason(NotificationEnums::CloseReasons::NONE),
|
||||
m_actionInvoked( NULL )
|
||||
{
|
||||
notificationCount++;
|
||||
qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
}
|
||||
|
||||
~NotificationData()
|
||||
{
|
||||
notificationCount--;
|
||||
qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
}
|
||||
|
||||
|
||||
uint m_id;
|
||||
uint m_updateID;
|
||||
int m_timeout;
|
||||
SnoreFrontend *m_source;
|
||||
QString m_application;
|
||||
QString m_alert;
|
||||
QString m_title;
|
||||
QString m_text;
|
||||
Icon m_icon;
|
||||
NotificationEnums::Prioritys::prioritys m_priority;
|
||||
NotificationEnums::CloseReasons::closeReasons m_closeReason;
|
||||
Notification::Action *m_actionInvoked;
|
||||
QHash<int,Notification::Action*> m_actions;
|
||||
Hint m_hints;
|
||||
|
||||
static uint notificationCount;
|
||||
static uint m_idCount;
|
||||
static int notificationMetaID;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(NotificationData)
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NOTIFICATIONDATA_H
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 NOTIFICATIONENUMS_H
|
||||
#define NOTIFICATIONENUMS_H
|
||||
|
||||
#include <QFlags>
|
||||
|
||||
namespace Snore{
|
||||
namespace NotificationEnums{
|
||||
|
||||
namespace Prioritys{
|
||||
enum priority{
|
||||
LOW = -1,
|
||||
NORMAL = 0,
|
||||
HIGH = +1
|
||||
};
|
||||
Q_DECLARE_FLAGS(prioritys, priority)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(prioritys)
|
||||
}
|
||||
namespace CloseReasons{
|
||||
enum closeReason
|
||||
{
|
||||
NONE = 0,
|
||||
TIMED_OUT,
|
||||
DISMISSED,
|
||||
CLOSED
|
||||
};
|
||||
Q_DECLARE_FLAGS(closeReasons, closeReason)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(closeReasons)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // NOTIFICATIONENUMS_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 NOTIFICATIONENUMS_H
|
||||
#define NOTIFICATIONENUMS_H
|
||||
|
||||
#include <QFlags>
|
||||
|
||||
namespace Snore{
|
||||
namespace NotificationEnums{
|
||||
|
||||
namespace Prioritys{
|
||||
enum priority{
|
||||
LOW = -1,
|
||||
NORMAL = 0,
|
||||
HIGH = +1
|
||||
};
|
||||
Q_DECLARE_FLAGS(prioritys, priority)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(prioritys)
|
||||
}
|
||||
namespace CloseReasons{
|
||||
enum closeReason
|
||||
{
|
||||
NONE = 0,
|
||||
TIMED_OUT,
|
||||
DISMISSED,
|
||||
CLOSED
|
||||
};
|
||||
Q_DECLARE_FLAGS(closeReasons, closeReason)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(closeReasons)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // NOTIFICATIONENUMS_H
|
||||
|
|
|
@ -1,76 +1,76 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 PLUGINCONTAINER_H
|
||||
#define PLUGINCONTAINER_H
|
||||
#include "../snore_exports.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QSettings>
|
||||
#include <QFlag>
|
||||
|
||||
namespace Snore{
|
||||
class SnoreCore;
|
||||
class SnorePlugin;
|
||||
class SnoreFrontend;
|
||||
class SnoreBackend;
|
||||
class SnoreSecondaryBackend;
|
||||
|
||||
class SNORE_EXPORT PluginContainer{
|
||||
public:
|
||||
enum PluginType{
|
||||
ALL = 0x0,//for loading plugins
|
||||
BACKEND = 0x1,
|
||||
SECONDARY_BACKEND = 0x2,
|
||||
FRONTEND = 0x4,
|
||||
PLUGIN = 0x8
|
||||
};
|
||||
Q_DECLARE_FLAGS(PluginTypes, PluginType)
|
||||
|
||||
static QHash<QString,PluginContainer*> pluginCache();
|
||||
|
||||
PluginContainer(QString fileName,QString pluginName,PluginType type);
|
||||
~PluginContainer();
|
||||
SnorePlugin *load();
|
||||
void unload();
|
||||
const QString &file();
|
||||
const QString &name();
|
||||
PluginContainer::PluginType type();
|
||||
|
||||
|
||||
static PluginContainer::PluginType typeFromString(const QString &t);
|
||||
static const QStringList &types();
|
||||
|
||||
private:
|
||||
static void updatePluginCache();
|
||||
static QSettings &cacheFile();
|
||||
|
||||
static QHash<QString,PluginContainer*> s_pluginCache;
|
||||
|
||||
QPointer<SnorePlugin> m_instance;
|
||||
QString m_pluginFile;
|
||||
QString m_pluginName;
|
||||
PluginContainer::PluginType m_pluginType;
|
||||
};
|
||||
}
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::PluginContainer::PluginTypes)
|
||||
|
||||
|
||||
#endif//PLUGINCONTAINER_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 PLUGINCONTAINER_H
|
||||
#define PLUGINCONTAINER_H
|
||||
#include "../snore_exports.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QSettings>
|
||||
#include <QFlag>
|
||||
|
||||
namespace Snore{
|
||||
class SnoreCore;
|
||||
class SnorePlugin;
|
||||
class SnoreFrontend;
|
||||
class SnoreBackend;
|
||||
class SnoreSecondaryBackend;
|
||||
|
||||
class SNORE_EXPORT PluginContainer{
|
||||
public:
|
||||
enum PluginType{
|
||||
ALL = 0x0,//for loading plugins
|
||||
BACKEND = 0x1,
|
||||
SECONDARY_BACKEND = 0x2,
|
||||
FRONTEND = 0x4,
|
||||
PLUGIN = 0x8
|
||||
};
|
||||
Q_DECLARE_FLAGS(PluginTypes, PluginType)
|
||||
|
||||
static QHash<QString,PluginContainer*> pluginCache();
|
||||
|
||||
PluginContainer(QString fileName,QString pluginName,PluginType type);
|
||||
~PluginContainer();
|
||||
SnorePlugin *load();
|
||||
void unload();
|
||||
const QString &file();
|
||||
const QString &name();
|
||||
PluginContainer::PluginType type();
|
||||
|
||||
|
||||
static PluginContainer::PluginType typeFromString(const QString &t);
|
||||
static const QStringList &types();
|
||||
|
||||
private:
|
||||
static void updatePluginCache();
|
||||
static QSettings &cacheFile();
|
||||
|
||||
static QHash<QString,PluginContainer*> s_pluginCache;
|
||||
|
||||
QPointer<SnorePlugin> m_instance;
|
||||
QString m_pluginFile;
|
||||
QString m_pluginName;
|
||||
PluginContainer::PluginType m_pluginType;
|
||||
};
|
||||
}
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::PluginContainer::PluginTypes)
|
||||
|
||||
|
||||
#endif//PLUGINCONTAINER_H
|
||||
|
|
|
@ -1,82 +1,82 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNORE_PLUGINS_H
|
||||
#define SNORE_PLUGINS_H
|
||||
#include "../snore_exports.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QHash>
|
||||
#include <QTimer>
|
||||
#include <QtPlugin>
|
||||
#include <QPluginLoader>
|
||||
|
||||
namespace Snore{
|
||||
class Application;
|
||||
class SnoreCore;
|
||||
|
||||
|
||||
class SNORE_EXPORT SnorePlugin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SnorePlugin ( const QString &name);
|
||||
virtual ~SnorePlugin();
|
||||
virtual bool init( SnoreCore *snore );
|
||||
bool isInitialized();
|
||||
SnoreCore* snore();
|
||||
const QString &name() const;
|
||||
|
||||
protected:
|
||||
void startTimeout(uint id,int timeout);
|
||||
private slots:
|
||||
void notificationTimedOut();
|
||||
|
||||
private:
|
||||
SnorePlugin() {}
|
||||
QString m_name;
|
||||
bool m_initialized;
|
||||
QPointer<SnoreCore> m_snore;
|
||||
QHash<uint,QTimer*> m_timeouts;
|
||||
QList<uint> m_timeout_order;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Q_DECLARE_INTERFACE ( Snore::SnorePlugin,
|
||||
"org.Snore.SnorePlugin/1.0" )
|
||||
|
||||
//compatability defines to reduce the number of ifdefs to make fiat compile with qt4 and qt5
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
# if defined(Q_EXPORT_PLUGIN)
|
||||
# undef Q_EXPORT_PLUGIN
|
||||
# endif
|
||||
# if defined(Q_EXPORT_PLUGIN2)
|
||||
# undef Q_EXPORT_PLUGIN2
|
||||
# endif
|
||||
# define Q_EXPORT_PLUGIN(a)
|
||||
# define Q_EXPORT_PLUGIN2(a, b)
|
||||
#else
|
||||
# define Q_PLUGIN_METADATA(a)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif//SNORE_PLUGINS_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNORE_PLUGINS_H
|
||||
#define SNORE_PLUGINS_H
|
||||
#include "../snore_exports.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QHash>
|
||||
#include <QTimer>
|
||||
#include <QtPlugin>
|
||||
#include <QPluginLoader>
|
||||
|
||||
namespace Snore{
|
||||
class Application;
|
||||
class SnoreCore;
|
||||
|
||||
|
||||
class SNORE_EXPORT SnorePlugin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SnorePlugin ( const QString &name);
|
||||
virtual ~SnorePlugin();
|
||||
virtual bool init( SnoreCore *snore );
|
||||
bool isInitialized();
|
||||
SnoreCore* snore();
|
||||
const QString &name() const;
|
||||
|
||||
protected:
|
||||
void startTimeout(uint id,int timeout);
|
||||
private slots:
|
||||
void notificationTimedOut();
|
||||
|
||||
private:
|
||||
SnorePlugin() {}
|
||||
QString m_name;
|
||||
bool m_initialized;
|
||||
QPointer<SnoreCore> m_snore;
|
||||
QHash<uint,QTimer*> m_timeouts;
|
||||
QList<uint> m_timeout_order;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Q_DECLARE_INTERFACE ( Snore::SnorePlugin,
|
||||
"org.Snore.SnorePlugin/1.0" )
|
||||
|
||||
//compatability defines to reduce the number of ifdefs to make fiat compile with qt4 and qt5
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
# if defined(Q_EXPORT_PLUGIN)
|
||||
# undef Q_EXPORT_PLUGIN
|
||||
# endif
|
||||
# if defined(Q_EXPORT_PLUGIN2)
|
||||
# undef Q_EXPORT_PLUGIN2
|
||||
# endif
|
||||
# define Q_EXPORT_PLUGIN(a)
|
||||
# define Q_EXPORT_PLUGIN2(a, b)
|
||||
#else
|
||||
# define Q_PLUGIN_METADATA(a)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif//SNORE_PLUGINS_H
|
||||
|
|
|
@ -1,96 +1,96 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNORE_BACKEND_H
|
||||
#define SNORE_BACKEND_H
|
||||
#include "../snore_exports.h"
|
||||
#include "plugins.h"
|
||||
#include "../notification/notification.h"
|
||||
#include "../snore.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QFlag>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class SNORE_EXPORT SnoreBackend : public SnorePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnorePlugin)
|
||||
public:
|
||||
SnoreBackend(const QString &name, bool canCloseNotification, bool supportsRichtext );
|
||||
virtual ~SnoreBackend();
|
||||
virtual bool init(SnoreCore *snore);
|
||||
|
||||
void requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason );
|
||||
|
||||
Snore::Notification getActiveNotificationByID(uint id);
|
||||
|
||||
bool canCloseNotification();
|
||||
bool supportsRichtext();
|
||||
|
||||
signals:
|
||||
void closeNotification( Snore::Notification );
|
||||
|
||||
|
||||
public slots:
|
||||
virtual void slotRegisterApplication ( Snore::Application *application ) = 0;
|
||||
virtual void slotUnregisterApplication ( Snore::Application *application ) = 0;
|
||||
virtual void slotNotify ( Snore::Notification notification ) = 0;
|
||||
virtual void slotCloseNotification ( Snore::Notification notification );
|
||||
|
||||
protected:
|
||||
bool m_canCloseNotification;
|
||||
bool m_supportsRichtext;
|
||||
void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons);
|
||||
|
||||
|
||||
private:
|
||||
QHash<uint,Notification> m_activeNotifications;
|
||||
|
||||
void addActiveNotification(Notification n);
|
||||
friend void SnoreCore::broadcastNotification(Notification notification);
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Q_DECLARE_INTERFACE ( Snore::SnoreBackend,
|
||||
"org.Snore.NotificationBackend/1.0" )
|
||||
|
||||
namespace Snore{
|
||||
class SnoreCore;
|
||||
|
||||
class SNORE_EXPORT SnoreSecondaryBackend:public SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnorePlugin Snore::SnoreBackend)
|
||||
public:
|
||||
SnoreSecondaryBackend(const QString &name, bool supportsRhichtext);
|
||||
virtual ~SnoreSecondaryBackend();
|
||||
virtual bool init(SnoreCore *snore);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_INTERFACE ( Snore::SnoreSecondaryBackend,
|
||||
"org.Snore.SecondaryNotificationBackend/1.0" )
|
||||
|
||||
#endif//SNORE_BACKEND_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNORE_BACKEND_H
|
||||
#define SNORE_BACKEND_H
|
||||
#include "../snore_exports.h"
|
||||
#include "plugins.h"
|
||||
#include "../notification/notification.h"
|
||||
#include "../snore.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QFlag>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class SNORE_EXPORT SnoreBackend : public SnorePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnorePlugin)
|
||||
public:
|
||||
SnoreBackend(const QString &name, bool canCloseNotification, bool supportsRichtext );
|
||||
virtual ~SnoreBackend();
|
||||
virtual bool init(SnoreCore *snore);
|
||||
|
||||
void requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason );
|
||||
|
||||
Snore::Notification getActiveNotificationByID(uint id);
|
||||
|
||||
bool canCloseNotification();
|
||||
bool supportsRichtext();
|
||||
|
||||
signals:
|
||||
void closeNotification( Snore::Notification );
|
||||
|
||||
|
||||
public slots:
|
||||
virtual void slotRegisterApplication ( Snore::Application *application ) = 0;
|
||||
virtual void slotUnregisterApplication ( Snore::Application *application ) = 0;
|
||||
virtual void slotNotify ( Snore::Notification notification ) = 0;
|
||||
virtual void slotCloseNotification ( Snore::Notification notification );
|
||||
|
||||
protected:
|
||||
bool m_canCloseNotification;
|
||||
bool m_supportsRichtext;
|
||||
void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons);
|
||||
|
||||
|
||||
private:
|
||||
QHash<uint,Notification> m_activeNotifications;
|
||||
|
||||
void addActiveNotification(Notification n);
|
||||
friend void SnoreCore::broadcastNotification(Notification notification);
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Q_DECLARE_INTERFACE ( Snore::SnoreBackend,
|
||||
"org.Snore.NotificationBackend/1.0" )
|
||||
|
||||
namespace Snore{
|
||||
class SnoreCore;
|
||||
|
||||
class SNORE_EXPORT SnoreSecondaryBackend:public SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnorePlugin Snore::SnoreBackend)
|
||||
public:
|
||||
SnoreSecondaryBackend(const QString &name, bool supportsRhichtext);
|
||||
virtual ~SnoreSecondaryBackend();
|
||||
virtual bool init(SnoreCore *snore);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_INTERFACE ( Snore::SnoreSecondaryBackend,
|
||||
"org.Snore.SecondaryNotificationBackend/1.0" )
|
||||
|
||||
#endif//SNORE_BACKEND_H
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNORE_FRONTEND_H
|
||||
#define SNORE_FRONTEND_H
|
||||
#include "../snore_exports.h"
|
||||
#include "../notification/notification.h"
|
||||
#include "plugins.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QFlag>
|
||||
|
||||
namespace Snore{
|
||||
class Application;
|
||||
class SnoreCore;
|
||||
class SnorePlugin;
|
||||
|
||||
|
||||
class SNORE_EXPORT SnoreFrontend:public SnorePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnorePlugin)
|
||||
public:
|
||||
SnoreFrontend ( const QString &name);
|
||||
virtual ~SnoreFrontend();
|
||||
virtual bool init(SnoreCore *snore);
|
||||
|
||||
public slots:
|
||||
virtual void actionInvoked( Snore::Notification notification )=0;
|
||||
virtual void notificationClosed( Snore::Notification notification )=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_INTERFACE ( Snore::SnoreFrontend,
|
||||
"org.Snore.NotificationFrontend/1.0" )
|
||||
|
||||
#endif//SNORE_FRONTEND_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNORE_FRONTEND_H
|
||||
#define SNORE_FRONTEND_H
|
||||
#include "../snore_exports.h"
|
||||
#include "../notification/notification.h"
|
||||
#include "plugins.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QFlag>
|
||||
|
||||
namespace Snore{
|
||||
class Application;
|
||||
class SnoreCore;
|
||||
class SnorePlugin;
|
||||
|
||||
|
||||
class SNORE_EXPORT SnoreFrontend:public SnorePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnorePlugin)
|
||||
public:
|
||||
SnoreFrontend ( const QString &name);
|
||||
virtual ~SnoreFrontend();
|
||||
virtual bool init(SnoreCore *snore);
|
||||
|
||||
public slots:
|
||||
virtual void actionInvoked( Snore::Notification notification )=0;
|
||||
virtual void notificationClosed( Snore::Notification notification )=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_INTERFACE ( Snore::SnoreFrontend,
|
||||
"org.Snore.NotificationFrontend/1.0" )
|
||||
|
||||
#endif//SNORE_FRONTEND_H
|
||||
|
|
|
@ -1,298 +1,298 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "snore.h"
|
||||
#include "notification/notification.h"
|
||||
#include "plugins/plugincontainer.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "plugins/snorebackend.h"
|
||||
#include "plugins/snorefrontend.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
void SnoreCore::slotNotificationClosed(Notification n)
|
||||
{
|
||||
emit notificationClosed(n);
|
||||
}
|
||||
|
||||
QString const SnoreCore::snoreTMP(){
|
||||
static const QString tmp = QString("%1/SnoreNotify/").arg(QDir::temp().path());
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
SnoreCore::SnoreCore ( QSystemTrayIcon *trayIcon ) :
|
||||
m_trayIcon ( trayIcon )
|
||||
{
|
||||
QDir home ( snoreTMP() );
|
||||
if ( !home.exists() ){
|
||||
home.cdUp();
|
||||
home.mkdir("SnoreNotify");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const QDir &SnoreCore::pluginDir(){
|
||||
static QDir path(QString("%1/snoreplugins").arg(qApp->applicationDirPath()));
|
||||
if(!path.exists())
|
||||
{
|
||||
path = QDir(LIBSNORE_PLUGIN_PATH);
|
||||
}
|
||||
qDebug() << "PluginDir" << path.absolutePath();
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types )
|
||||
{
|
||||
qDebug() << "PluginInfo" << PluginContainer::pluginCache().keys();
|
||||
foreach ( PluginContainer *info, PluginContainer::pluginCache().values())
|
||||
{
|
||||
if(types == PluginContainer::ALL || types.testFlag(info->type()))
|
||||
{
|
||||
switch(info->type())
|
||||
{
|
||||
case PluginContainer::BACKEND:
|
||||
{
|
||||
qDebug() <<info->name()<<"is a Notification_Backend";
|
||||
m_notificationBackends.append( info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::SECONDARY_BACKEND:
|
||||
{
|
||||
if(!info->load()->init( this )){
|
||||
info->unload();
|
||||
break;
|
||||
}
|
||||
m_secondaryNotificationBackends.append(info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::FRONTEND:
|
||||
{
|
||||
qDebug() <<info->name()<<"is a Notification_Frontend";
|
||||
if(!info->load()->init( this )){
|
||||
info->unload();
|
||||
break;
|
||||
}
|
||||
m_Frontends.append(info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::PLUGIN:
|
||||
{
|
||||
qDebug() <<info->name()<<"is a SnorePlugin";
|
||||
if(!info->load()->init(this)){
|
||||
info->unload();
|
||||
break;
|
||||
}
|
||||
m_plugins.append(info->name());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
std::cerr<<"Plugin Cache corrupted"<<std::endl;
|
||||
std::cerr<<info->file().toLocal8Bit().constData()<<QString::number((int)info->type()).toLatin1().constData()<<std::endl;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
qDebug()<<"dont load "<<info->file()<<info->type();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::broadcastNotification ( Notification notification )
|
||||
{
|
||||
qDebug()<<"Broadcasting"<<notification<<"timeout:"<<notification.timeout();
|
||||
emit notify ( notification );
|
||||
if ( m_notificationBackend != NULL )
|
||||
{
|
||||
if(!m_notificationBackend->isInitialized()){
|
||||
qDebug()<<"Notification backend "<<m_notificationBackend<<" isnt initialized will snore will exit now";
|
||||
qApp->quit();
|
||||
}
|
||||
m_notificationBackend->slotNotify( notification );
|
||||
m_notificationBackend->addActiveNotification(notification);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SnoreCore::notificationActionInvoked ( Notification notification )
|
||||
{
|
||||
emit actionInvoked(notification);
|
||||
SnoreFrontend *nf = notification.source();
|
||||
if ( nf != NULL )
|
||||
{
|
||||
nf->actionInvoked ( notification );
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::registerApplication(Application *application)
|
||||
{
|
||||
if(!m_applications.contains(application->name()))
|
||||
{
|
||||
m_applications.insert ( application->name(),application );
|
||||
emit applicationInitialized ( application );
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::addApplication ( Application *application )
|
||||
{
|
||||
registerApplication(application);
|
||||
}
|
||||
|
||||
void SnoreCore::applicationIsInitialized ( Application *application )
|
||||
{
|
||||
registerApplication(application);
|
||||
}
|
||||
|
||||
void SnoreCore::removeApplication ( const QString& appName )
|
||||
{
|
||||
deregisterApplication( m_applications.value ( appName ) );
|
||||
}
|
||||
|
||||
void SnoreCore::deregisterApplication(Application *application)
|
||||
{
|
||||
emit applicationRemoved (application );
|
||||
m_applications.take ( application->name() );
|
||||
application->deleteLater();
|
||||
}
|
||||
|
||||
const ApplicationsList &SnoreCore::aplications() const
|
||||
{
|
||||
return m_applications;
|
||||
}
|
||||
|
||||
|
||||
const QStringList &SnoreCore::notificationBackends() const
|
||||
{
|
||||
return m_notificationBackends;
|
||||
}
|
||||
|
||||
const QStringList &SnoreCore::notificationFrontends() const
|
||||
{
|
||||
return m_Frontends;
|
||||
}
|
||||
|
||||
const QStringList &SnoreCore::secondaryNotificationBackends() const
|
||||
{
|
||||
return m_secondaryNotificationBackends;
|
||||
}
|
||||
|
||||
bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend )
|
||||
{
|
||||
if(!PluginContainer::pluginCache().contains(backend)){
|
||||
qDebug()<<"Unknown Backend:"<<backend;
|
||||
return false;
|
||||
}
|
||||
qDebug()<<"Setting Notification Backend to:"<<backend;
|
||||
SnoreBackend* b = qobject_cast<SnoreBackend*>(PluginContainer::pluginCache()[backend]->load());
|
||||
if(!b->isInitialized()){
|
||||
if(!b->init(this)){
|
||||
qDebug()<<"Failed to initialize"<<b->name();
|
||||
return false;
|
||||
}
|
||||
disconnect(m_notificationBackend,SIGNAL(closeNotification(Snore::Notification)));
|
||||
connect(b,SIGNAL(closeNotification(Snore::Notification)),this,SLOT(slotNotificationClosed(Snore::Notification)));
|
||||
}
|
||||
m_notificationBackend = b;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SnoreCore::setPrimaryNotificationBackend()
|
||||
{
|
||||
QStringList backends = notificationBackends();
|
||||
#ifdef Q_OS_WIN
|
||||
if(QSysInfo::windowsVersion() == QSysInfo::WV_WINDOWS8 && backends.contains("Windows 8"))
|
||||
{
|
||||
if(setPrimaryNotificationBackend("Windows 8"))
|
||||
return true;
|
||||
}
|
||||
if( backends.contains("Growl"))
|
||||
{
|
||||
if(setPrimaryNotificationBackend("Growl"))
|
||||
return true;
|
||||
}
|
||||
if( backends.contains("Snarl"))
|
||||
{
|
||||
if(setPrimaryNotificationBackend("Snarl"))
|
||||
return true;
|
||||
}
|
||||
#elif defined(Q_OS_LINUX)
|
||||
if( backends.contains("FreedesktopNotification_Backend"))
|
||||
{
|
||||
return setPrimaryNotificationBackend("FreedesktopNotification_Backend");
|
||||
}
|
||||
#elif defined(Q_OS_MAC)
|
||||
if( backends.contains("Growl"))
|
||||
{
|
||||
return setPrimaryNotificationBackend("Growl");
|
||||
}
|
||||
#endif
|
||||
if( trayIcon() && backends.contains("SystemTray"))
|
||||
{
|
||||
return setPrimaryNotificationBackend("SystemTray");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString SnoreCore::primaryNotificationBackend() const
|
||||
{
|
||||
if(m_notificationBackend.isNull())
|
||||
{
|
||||
return QString::null;
|
||||
}
|
||||
return m_notificationBackend->name();
|
||||
}
|
||||
|
||||
QSystemTrayIcon *SnoreCore::trayIcon(){
|
||||
return m_trayIcon;
|
||||
}
|
||||
|
||||
Notification SnoreCore::getActiveNotificationByID(uint id)
|
||||
{
|
||||
if(!m_notificationBackend->isInitialized()){
|
||||
qDebug()<<"Notification backend "<<m_notificationBackend<<" isn't initialized will snore will exit now";
|
||||
qApp->quit();
|
||||
}
|
||||
return m_notificationBackend->getActiveNotificationByID(id);
|
||||
}
|
||||
|
||||
void SnoreCore::requestCloseNotification(Notification n, NotificationEnums::CloseReasons::closeReasons r)
|
||||
{
|
||||
m_notificationBackend->requestCloseNotification(n,r);
|
||||
}
|
||||
|
||||
bool SnoreCore::primaryBackendSupportsRichtext()
|
||||
{
|
||||
return m_notificationBackend->supportsRichtext();
|
||||
}
|
||||
|
||||
Hint &SnoreCore::hints()
|
||||
{
|
||||
return m_hints;
|
||||
}
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "snore.h"
|
||||
#include "notification/notification.h"
|
||||
#include "plugins/plugincontainer.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "plugins/snorebackend.h"
|
||||
#include "plugins/snorefrontend.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
void SnoreCore::slotNotificationClosed(Notification n)
|
||||
{
|
||||
emit notificationClosed(n);
|
||||
}
|
||||
|
||||
QString const SnoreCore::snoreTMP(){
|
||||
static const QString tmp = QString("%1/SnoreNotify/").arg(QDir::temp().path());
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
SnoreCore::SnoreCore ( QSystemTrayIcon *trayIcon ) :
|
||||
m_trayIcon ( trayIcon )
|
||||
{
|
||||
QDir home ( snoreTMP() );
|
||||
if ( !home.exists() ){
|
||||
home.cdUp();
|
||||
home.mkdir("SnoreNotify");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const QDir &SnoreCore::pluginDir(){
|
||||
static QDir path(QString("%1/snoreplugins").arg(qApp->applicationDirPath()));
|
||||
if(!path.exists())
|
||||
{
|
||||
path = QDir(LIBSNORE_PLUGIN_PATH);
|
||||
}
|
||||
qDebug() << "PluginDir" << path.absolutePath();
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types )
|
||||
{
|
||||
qDebug() << "PluginInfo" << PluginContainer::pluginCache().keys();
|
||||
foreach ( PluginContainer *info, PluginContainer::pluginCache().values())
|
||||
{
|
||||
if(types == PluginContainer::ALL || types.testFlag(info->type()))
|
||||
{
|
||||
switch(info->type())
|
||||
{
|
||||
case PluginContainer::BACKEND:
|
||||
{
|
||||
qDebug() <<info->name()<<"is a Notification_Backend";
|
||||
m_notificationBackends.append( info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::SECONDARY_BACKEND:
|
||||
{
|
||||
if(!info->load()->init( this )){
|
||||
info->unload();
|
||||
break;
|
||||
}
|
||||
m_secondaryNotificationBackends.append(info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::FRONTEND:
|
||||
{
|
||||
qDebug() <<info->name()<<"is a Notification_Frontend";
|
||||
if(!info->load()->init( this )){
|
||||
info->unload();
|
||||
break;
|
||||
}
|
||||
m_Frontends.append(info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::PLUGIN:
|
||||
{
|
||||
qDebug() <<info->name()<<"is a SnorePlugin";
|
||||
if(!info->load()->init(this)){
|
||||
info->unload();
|
||||
break;
|
||||
}
|
||||
m_plugins.append(info->name());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
std::cerr<<"Plugin Cache corrupted"<<std::endl;
|
||||
std::cerr<<info->file().toLocal8Bit().constData()<<QString::number((int)info->type()).toLatin1().constData()<<std::endl;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
qDebug()<<"dont load "<<info->file()<<info->type();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::broadcastNotification ( Notification notification )
|
||||
{
|
||||
qDebug()<<"Broadcasting"<<notification<<"timeout:"<<notification.timeout();
|
||||
emit notify ( notification );
|
||||
if ( m_notificationBackend != NULL )
|
||||
{
|
||||
if(!m_notificationBackend->isInitialized()){
|
||||
qDebug()<<"Notification backend "<<m_notificationBackend<<" isnt initialized will snore will exit now";
|
||||
qApp->quit();
|
||||
}
|
||||
m_notificationBackend->slotNotify( notification );
|
||||
m_notificationBackend->addActiveNotification(notification);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SnoreCore::notificationActionInvoked ( Notification notification )
|
||||
{
|
||||
emit actionInvoked(notification);
|
||||
SnoreFrontend *nf = notification.source();
|
||||
if ( nf != NULL )
|
||||
{
|
||||
nf->actionInvoked ( notification );
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::registerApplication(Application *application)
|
||||
{
|
||||
if(!m_applications.contains(application->name()))
|
||||
{
|
||||
m_applications.insert ( application->name(),application );
|
||||
emit applicationInitialized ( application );
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::addApplication ( Application *application )
|
||||
{
|
||||
registerApplication(application);
|
||||
}
|
||||
|
||||
void SnoreCore::applicationIsInitialized ( Application *application )
|
||||
{
|
||||
registerApplication(application);
|
||||
}
|
||||
|
||||
void SnoreCore::removeApplication ( const QString& appName )
|
||||
{
|
||||
deregisterApplication( m_applications.value ( appName ) );
|
||||
}
|
||||
|
||||
void SnoreCore::deregisterApplication(Application *application)
|
||||
{
|
||||
emit applicationRemoved (application );
|
||||
m_applications.take ( application->name() );
|
||||
application->deleteLater();
|
||||
}
|
||||
|
||||
const ApplicationsList &SnoreCore::aplications() const
|
||||
{
|
||||
return m_applications;
|
||||
}
|
||||
|
||||
|
||||
const QStringList &SnoreCore::notificationBackends() const
|
||||
{
|
||||
return m_notificationBackends;
|
||||
}
|
||||
|
||||
const QStringList &SnoreCore::notificationFrontends() const
|
||||
{
|
||||
return m_Frontends;
|
||||
}
|
||||
|
||||
const QStringList &SnoreCore::secondaryNotificationBackends() const
|
||||
{
|
||||
return m_secondaryNotificationBackends;
|
||||
}
|
||||
|
||||
bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend )
|
||||
{
|
||||
if(!PluginContainer::pluginCache().contains(backend)){
|
||||
qDebug()<<"Unknown Backend:"<<backend;
|
||||
return false;
|
||||
}
|
||||
qDebug()<<"Setting Notification Backend to:"<<backend;
|
||||
SnoreBackend* b = qobject_cast<SnoreBackend*>(PluginContainer::pluginCache()[backend]->load());
|
||||
if(!b->isInitialized()){
|
||||
if(!b->init(this)){
|
||||
qDebug()<<"Failed to initialize"<<b->name();
|
||||
return false;
|
||||
}
|
||||
disconnect(m_notificationBackend,SIGNAL(closeNotification(Snore::Notification)));
|
||||
connect(b,SIGNAL(closeNotification(Snore::Notification)),this,SLOT(slotNotificationClosed(Snore::Notification)));
|
||||
}
|
||||
m_notificationBackend = b;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SnoreCore::setPrimaryNotificationBackend()
|
||||
{
|
||||
QStringList backends = notificationBackends();
|
||||
#ifdef Q_OS_WIN
|
||||
if(QSysInfo::windowsVersion() == QSysInfo::WV_WINDOWS8 && backends.contains("Windows 8"))
|
||||
{
|
||||
if(setPrimaryNotificationBackend("Windows 8"))
|
||||
return true;
|
||||
}
|
||||
if( backends.contains("Growl"))
|
||||
{
|
||||
if(setPrimaryNotificationBackend("Growl"))
|
||||
return true;
|
||||
}
|
||||
if( backends.contains("Snarl"))
|
||||
{
|
||||
if(setPrimaryNotificationBackend("Snarl"))
|
||||
return true;
|
||||
}
|
||||
#elif defined(Q_OS_LINUX)
|
||||
if( backends.contains("FreedesktopNotification_Backend"))
|
||||
{
|
||||
return setPrimaryNotificationBackend("FreedesktopNotification_Backend");
|
||||
}
|
||||
#elif defined(Q_OS_MAC)
|
||||
if( backends.contains("Growl"))
|
||||
{
|
||||
return setPrimaryNotificationBackend("Growl");
|
||||
}
|
||||
#endif
|
||||
if( trayIcon() && backends.contains("SystemTray"))
|
||||
{
|
||||
return setPrimaryNotificationBackend("SystemTray");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString SnoreCore::primaryNotificationBackend() const
|
||||
{
|
||||
if(m_notificationBackend.isNull())
|
||||
{
|
||||
return QString::null;
|
||||
}
|
||||
return m_notificationBackend->name();
|
||||
}
|
||||
|
||||
QSystemTrayIcon *SnoreCore::trayIcon(){
|
||||
return m_trayIcon;
|
||||
}
|
||||
|
||||
Notification SnoreCore::getActiveNotificationByID(uint id)
|
||||
{
|
||||
if(!m_notificationBackend->isInitialized()){
|
||||
qDebug()<<"Notification backend "<<m_notificationBackend<<" isn't initialized will snore will exit now";
|
||||
qApp->quit();
|
||||
}
|
||||
return m_notificationBackend->getActiveNotificationByID(id);
|
||||
}
|
||||
|
||||
void SnoreCore::requestCloseNotification(Notification n, NotificationEnums::CloseReasons::closeReasons r)
|
||||
{
|
||||
m_notificationBackend->requestCloseNotification(n,r);
|
||||
}
|
||||
|
||||
bool SnoreCore::primaryBackendSupportsRichtext()
|
||||
{
|
||||
return m_notificationBackend->supportsRichtext();
|
||||
}
|
||||
|
||||
Hint &SnoreCore::hints()
|
||||
{
|
||||
return m_hints;
|
||||
}
|
||||
|
|
242
src/core/snore.h
242
src/core/snore.h
|
@ -1,121 +1,121 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNORESERVER_H
|
||||
#define SNORESERVER_H
|
||||
|
||||
#include "snore_exports.h"
|
||||
#include "application.h"
|
||||
#include "plugins/plugincontainer.h"
|
||||
#include "notification/notification.h"
|
||||
#include "hint.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QTextDocument>
|
||||
#include <QTextDocumentFragment>
|
||||
|
||||
class QSystemTrayIcon;
|
||||
class QDir;
|
||||
|
||||
|
||||
namespace Snore{
|
||||
class SNORE_EXPORT SnoreCore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static const QString snoreTMP();
|
||||
static const QDir &pluginDir();
|
||||
|
||||
public:
|
||||
SnoreCore (QSystemTrayIcon *trayIcon = NULL );
|
||||
void loadPlugins ( PluginContainer::PluginTypes types );
|
||||
|
||||
|
||||
void broadcastNotification( Notification notification );
|
||||
void notificationActionInvoked( Notification notification );//TODO: move to private header
|
||||
|
||||
void registerApplication( Application *application );
|
||||
void deregisterApplication( Application *application );
|
||||
|
||||
void Q_DECL_DEPRECATED addApplication ( Application *application );
|
||||
void Q_DECL_DEPRECATED applicationIsInitialized ( Application* application );
|
||||
void Q_DECL_DEPRECATED removeApplication ( const QString& appName );
|
||||
|
||||
const ApplicationsList &aplications() const;
|
||||
|
||||
const QStringList ¬ificationBackends() const;
|
||||
const QStringList ¬ificationFrontends() const;
|
||||
const QStringList &secondaryNotificationBackends() const;
|
||||
|
||||
bool setPrimaryNotificationBackend( const QString &backend );
|
||||
bool setPrimaryNotificationBackend();
|
||||
const QString primaryNotificationBackend() const;
|
||||
QSystemTrayIcon *trayIcon();
|
||||
|
||||
Notification getActiveNotificationByID(uint id);
|
||||
|
||||
void requestCloseNotification(Notification,NotificationEnums::CloseReasons::closeReasons);
|
||||
|
||||
bool primaryBackendSupportsRichtext();
|
||||
|
||||
Hint &hints();
|
||||
|
||||
signals:
|
||||
void applicationInitialized( Snore::Application* );
|
||||
void applicationRemoved( Snore::Application* );
|
||||
void notify( Snore::Notification noti );
|
||||
void actionInvoked( Snore::Notification );
|
||||
void notificationClosed(Snore::Notification );
|
||||
|
||||
private slots:
|
||||
void slotNotificationClosed(Snore::Notification);
|
||||
|
||||
|
||||
private:
|
||||
Hint m_hints;
|
||||
|
||||
ApplicationsList m_applications;
|
||||
|
||||
|
||||
QStringList m_notificationBackends;
|
||||
QStringList m_Frontends;
|
||||
QStringList m_secondaryNotificationBackends;
|
||||
QStringList m_plugins;
|
||||
|
||||
QPointer<SnoreBackend> m_notificationBackend;
|
||||
|
||||
QSystemTrayIcon *m_trayIcon;
|
||||
};
|
||||
|
||||
|
||||
static inline QString toPlainText ( const QString &string)
|
||||
{
|
||||
if(Qt::mightBeRichText(string))
|
||||
{
|
||||
return QTextDocumentFragment::fromHtml(string).toPlainText();
|
||||
}
|
||||
else
|
||||
{
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // SNORESERVER_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNORESERVER_H
|
||||
#define SNORESERVER_H
|
||||
|
||||
#include "snore_exports.h"
|
||||
#include "application.h"
|
||||
#include "plugins/plugincontainer.h"
|
||||
#include "notification/notification.h"
|
||||
#include "hint.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QTextDocument>
|
||||
#include <QTextDocumentFragment>
|
||||
|
||||
class QSystemTrayIcon;
|
||||
class QDir;
|
||||
|
||||
|
||||
namespace Snore{
|
||||
class SNORE_EXPORT SnoreCore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static const QString snoreTMP();
|
||||
static const QDir &pluginDir();
|
||||
|
||||
public:
|
||||
SnoreCore (QSystemTrayIcon *trayIcon = NULL );
|
||||
void loadPlugins ( PluginContainer::PluginTypes types );
|
||||
|
||||
|
||||
void broadcastNotification( Notification notification );
|
||||
void notificationActionInvoked( Notification notification );//TODO: move to private header
|
||||
|
||||
void registerApplication( Application *application );
|
||||
void deregisterApplication( Application *application );
|
||||
|
||||
void Q_DECL_DEPRECATED addApplication ( Application *application );
|
||||
void Q_DECL_DEPRECATED applicationIsInitialized ( Application* application );
|
||||
void Q_DECL_DEPRECATED removeApplication ( const QString& appName );
|
||||
|
||||
const ApplicationsList &aplications() const;
|
||||
|
||||
const QStringList ¬ificationBackends() const;
|
||||
const QStringList ¬ificationFrontends() const;
|
||||
const QStringList &secondaryNotificationBackends() const;
|
||||
|
||||
bool setPrimaryNotificationBackend( const QString &backend );
|
||||
bool setPrimaryNotificationBackend();
|
||||
const QString primaryNotificationBackend() const;
|
||||
QSystemTrayIcon *trayIcon();
|
||||
|
||||
Notification getActiveNotificationByID(uint id);
|
||||
|
||||
void requestCloseNotification(Notification,NotificationEnums::CloseReasons::closeReasons);
|
||||
|
||||
bool primaryBackendSupportsRichtext();
|
||||
|
||||
Hint &hints();
|
||||
|
||||
signals:
|
||||
void applicationInitialized( Snore::Application* );
|
||||
void applicationRemoved( Snore::Application* );
|
||||
void notify( Snore::Notification noti );
|
||||
void actionInvoked( Snore::Notification );
|
||||
void notificationClosed(Snore::Notification );
|
||||
|
||||
private slots:
|
||||
void slotNotificationClosed(Snore::Notification);
|
||||
|
||||
|
||||
private:
|
||||
Hint m_hints;
|
||||
|
||||
ApplicationsList m_applications;
|
||||
|
||||
|
||||
QStringList m_notificationBackends;
|
||||
QStringList m_Frontends;
|
||||
QStringList m_secondaryNotificationBackends;
|
||||
QStringList m_plugins;
|
||||
|
||||
QPointer<SnoreBackend> m_notificationBackend;
|
||||
|
||||
QSystemTrayIcon *m_trayIcon;
|
||||
};
|
||||
|
||||
|
||||
static inline QString toPlainText ( const QString &string)
|
||||
{
|
||||
if(Qt::mightBeRichText(string))
|
||||
{
|
||||
return QTextDocumentFragment::fromHtml(string).toPlainText();
|
||||
}
|
||||
else
|
||||
{
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // SNORESERVER_H
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
#ifndef SNORE_EXPORT_H
|
||||
#define SNORE_EXPORT_H
|
||||
|
||||
|
||||
#if defined(HAVE_KDE)
|
||||
#include <kdemacros.h>
|
||||
#ifdef SNORECORE_DLL
|
||||
# define SNORE_EXPORT KDE_EXPORT
|
||||
#else
|
||||
# define SNORE_EXPORT KDE_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#include <QtGlobal>
|
||||
#ifdef SNORECORE_DLL
|
||||
# define SNORE_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define SNORE_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef SNORE_DEPRECATED
|
||||
# ifdef Q_CC_GNU
|
||||
# define SNORE_DEPRECATED __attribute__((deprecated))
|
||||
# elif defined(Q_CC_MSVC)
|
||||
# define SNORE_DEPRECATED __declspec(deprecated)
|
||||
# else
|
||||
# define SNORE_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif//SNORE_EXPORT_H
|
||||
#ifndef SNORE_EXPORT_H
|
||||
#define SNORE_EXPORT_H
|
||||
|
||||
|
||||
#if defined(HAVE_KDE)
|
||||
#include <kdemacros.h>
|
||||
#ifdef SNORECORE_DLL
|
||||
# define SNORE_EXPORT KDE_EXPORT
|
||||
#else
|
||||
# define SNORE_EXPORT KDE_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#include <QtGlobal>
|
||||
#ifdef SNORECORE_DLL
|
||||
# define SNORE_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define SNORE_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef SNORE_DEPRECATED
|
||||
# ifdef Q_CC_GNU
|
||||
# define SNORE_DEPRECATED __attribute__((deprecated))
|
||||
# elif defined(Q_CC_MSVC)
|
||||
# define SNORE_DEPRECATED __declspec(deprecated)
|
||||
# else
|
||||
# define SNORE_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif//SNORE_EXPORT_H
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
#ifndef SNORE_VERSION_H
|
||||
#define SNORE_VERSION_H
|
||||
#undef major
|
||||
#undef minor
|
||||
|
||||
#include "snore_exports.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class SNORE_EXPORT Version{
|
||||
public:
|
||||
static const QString version();
|
||||
|
||||
static const QString major();
|
||||
|
||||
static const QString minor();
|
||||
|
||||
static const QString suffix();
|
||||
|
||||
static const QString revision();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
#ifndef SNORE_VERSION_H
|
||||
#define SNORE_VERSION_H
|
||||
#undef major
|
||||
#undef minor
|
||||
|
||||
#include "snore_exports.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class SNORE_EXPORT Version{
|
||||
public:
|
||||
static const QString version();
|
||||
|
||||
static const QString major();
|
||||
|
||||
static const QString minor();
|
||||
|
||||
static const QString suffix();
|
||||
|
||||
static const QString revision();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,75 +1,75 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "fredesktopnotification.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QtGlobal>
|
||||
|
||||
|
||||
static int imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
|
||||
|
||||
|
||||
FreedesktopImageHint::FreedesktopImageHint(){
|
||||
|
||||
}
|
||||
|
||||
FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
|
||||
{
|
||||
QImage image(img.convertToFormat(QImage::Format_ARGB32));
|
||||
imageData = QByteArray((char*)image.rgbSwapped().bits(),image.numBytes());
|
||||
width = image.width();
|
||||
height = image.height();
|
||||
rowstride = image.bytesPerLine();
|
||||
hasAlpha = image.hasAlphaChannel();
|
||||
channels = image.isGrayscale()?1:hasAlpha?4:3;
|
||||
bitsPerSample = image.depth()/channels;
|
||||
|
||||
}
|
||||
|
||||
|
||||
QImage FreedesktopImageHint::toQImage() const {
|
||||
return QImage((uchar*)imageData.data(),width,height,QImage::Format_ARGB32 ).rgbSwapped();
|
||||
}
|
||||
|
||||
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) {
|
||||
a.beginStructure();
|
||||
a << i.width <<
|
||||
i.height <<
|
||||
i.rowstride <<
|
||||
i.hasAlpha <<
|
||||
i.bitsPerSample <<
|
||||
i.channels <<
|
||||
i.imageData;
|
||||
a.endStructure();
|
||||
return a;
|
||||
}
|
||||
|
||||
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) {
|
||||
a.beginStructure();
|
||||
a >> i.width >>
|
||||
i.height >>
|
||||
i.rowstride >>
|
||||
i.hasAlpha >>
|
||||
i.bitsPerSample >>
|
||||
i.channels >>
|
||||
i.imageData;
|
||||
a.endStructure();
|
||||
return a;
|
||||
}
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "fredesktopnotification.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QtGlobal>
|
||||
|
||||
|
||||
static int imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
|
||||
|
||||
|
||||
FreedesktopImageHint::FreedesktopImageHint(){
|
||||
|
||||
}
|
||||
|
||||
FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
|
||||
{
|
||||
QImage image(img.convertToFormat(QImage::Format_ARGB32));
|
||||
imageData = QByteArray((char*)image.rgbSwapped().bits(),image.numBytes());
|
||||
width = image.width();
|
||||
height = image.height();
|
||||
rowstride = image.bytesPerLine();
|
||||
hasAlpha = image.hasAlphaChannel();
|
||||
channels = image.isGrayscale()?1:hasAlpha?4:3;
|
||||
bitsPerSample = image.depth()/channels;
|
||||
|
||||
}
|
||||
|
||||
|
||||
QImage FreedesktopImageHint::toQImage() const {
|
||||
return QImage((uchar*)imageData.data(),width,height,QImage::Format_ARGB32 ).rgbSwapped();
|
||||
}
|
||||
|
||||
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) {
|
||||
a.beginStructure();
|
||||
a << i.width <<
|
||||
i.height <<
|
||||
i.rowstride <<
|
||||
i.hasAlpha <<
|
||||
i.bitsPerSample <<
|
||||
i.channels <<
|
||||
i.imageData;
|
||||
a.endStructure();
|
||||
return a;
|
||||
}
|
||||
|
||||
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) {
|
||||
a.beginStructure();
|
||||
a >> i.width >>
|
||||
i.height >>
|
||||
i.rowstride >>
|
||||
i.hasAlpha >>
|
||||
i.bitsPerSample >>
|
||||
i.channels >>
|
||||
i.imageData;
|
||||
a.endStructure();
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 FreedesktopNotification_H
|
||||
#define FreedesktopNotification_H
|
||||
|
||||
#include "core/notification/notification.h"
|
||||
|
||||
#include <QtDBus>
|
||||
#include <QMetaType>
|
||||
|
||||
|
||||
class FreedesktopImageHint
|
||||
{
|
||||
public:
|
||||
FreedesktopImageHint();
|
||||
FreedesktopImageHint(const QImage &img);
|
||||
QString hash()const;
|
||||
|
||||
QImage toQImage()const;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int rowstride;
|
||||
bool hasAlpha;
|
||||
int bitsPerSample;
|
||||
int channels;
|
||||
QByteArray imageData;
|
||||
QString _hash;
|
||||
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(FreedesktopImageHint);
|
||||
|
||||
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i);
|
||||
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) ;
|
||||
|
||||
#endif // FreedesktopNotification_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 FreedesktopNotification_H
|
||||
#define FreedesktopNotification_H
|
||||
|
||||
#include "core/notification/notification.h"
|
||||
|
||||
#include <QtDBus>
|
||||
#include <QMetaType>
|
||||
|
||||
|
||||
class FreedesktopImageHint
|
||||
{
|
||||
public:
|
||||
FreedesktopImageHint();
|
||||
FreedesktopImageHint(const QImage &img);
|
||||
QString hash()const;
|
||||
|
||||
QImage toQImage()const;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int rowstride;
|
||||
bool hasAlpha;
|
||||
int bitsPerSample;
|
||||
int channels;
|
||||
QByteArray imageData;
|
||||
QString _hash;
|
||||
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(FreedesktopImageHint);
|
||||
|
||||
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i);
|
||||
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) ;
|
||||
|
||||
#endif // FreedesktopNotification_H
|
||||
|
|
|
@ -1,128 +1,128 @@
|
|||
#include "freedesktopnotification_backend.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
#include "core/notification/notification.h"
|
||||
#include <QtCore>
|
||||
#include <QImage>
|
||||
#include "fredesktopnotification.h"
|
||||
#include "core/snore.h"
|
||||
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend )
|
||||
|
||||
|
||||
FreedesktopBackend::FreedesktopBackend () :
|
||||
SnoreBackend ( "FreedesktopNotification_Backend",true,true)
|
||||
{
|
||||
}
|
||||
|
||||
bool FreedesktopBackend::init(SnoreCore *snore){
|
||||
|
||||
m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
||||
QDBusConnection::sessionBus(), this );
|
||||
|
||||
QDBusPendingReply<QStringList> reply = m_interface->GetCapabilities();
|
||||
reply.waitForFinished();
|
||||
QStringList caps = reply.value();
|
||||
m_supportsRichtext = caps.contains( "body-markup" );
|
||||
connect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString)));
|
||||
connect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint)));
|
||||
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotRegisterApplication ( Application *application )
|
||||
{
|
||||
Q_UNUSED ( application );
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotUnregisterApplication ( Application *application )
|
||||
{
|
||||
Q_UNUSED ( application );
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotNotify ( Notification noti )
|
||||
{
|
||||
QStringList actions;
|
||||
foreach(int k,noti.actions().keys())
|
||||
{
|
||||
actions << QString::number(k) << noti.actions()[k]->name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QVariantMap hints;
|
||||
if(noti.icon().isValid())
|
||||
{
|
||||
FreedesktopImageHint image(noti.icon().image());
|
||||
hints["image_data"] = QVariant::fromValue(image);
|
||||
}
|
||||
|
||||
if(noti.priority() != NotificationEnums::Prioritys::NORMAL)
|
||||
{
|
||||
hints["urgency"] = (char)noti.priority()+1;
|
||||
}
|
||||
|
||||
|
||||
uint updateId = 0;
|
||||
if(noti.updateID() != 0)
|
||||
{
|
||||
updateId = m_snoreIdMap[noti.updateID()];
|
||||
m_dbusIdMap[updateId] = noti.id();
|
||||
m_snoreIdMap[noti.id()] = updateId;
|
||||
}
|
||||
|
||||
QString title = QString("%1 - %2").arg(noti.application(), noti.title());
|
||||
QString body(noti.text());
|
||||
if(!supportsRichtext())
|
||||
{
|
||||
title = Snore::toPlainText(title);
|
||||
body = Snore::toPlainText(body);
|
||||
}
|
||||
QDBusPendingReply<uint> id = m_interface->Notify(noti.application(), updateId, "", title,
|
||||
body, actions, hints, noti.sticky()?-1:noti.timeout()*1000);
|
||||
|
||||
if(noti.updateID() == 0)
|
||||
{
|
||||
id.waitForFinished();
|
||||
m_snoreIdMap[noti.id()] = id.value();
|
||||
m_dbusIdMap[id.value()] = noti.id();
|
||||
}
|
||||
}
|
||||
void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){
|
||||
Notification noti = getActiveNotificationByID(m_dbusIdMap[id]);
|
||||
if(!noti.isValid())
|
||||
return;
|
||||
noti.setActionInvoked ( actionID.toInt() );
|
||||
snore()->notificationActionInvoked ( noti );
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotCloseNotification ( Notification notification )
|
||||
{
|
||||
if(!m_snoreIdMap.contains(notification.id()))
|
||||
return;
|
||||
uint id = m_snoreIdMap.take(notification.id());
|
||||
m_dbusIdMap.remove(id);
|
||||
m_interface->CloseNotification(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason )
|
||||
{
|
||||
NotificationEnums::CloseReasons::closeReasons closeReason = NotificationEnums::CloseReasons::closeReasons(reason);
|
||||
qDebug() << Q_FUNC_INFO << "Closed" << id << "|" << closeReason << reason;
|
||||
if(id == 0)
|
||||
return;
|
||||
Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id));
|
||||
m_snoreIdMap.remove(noti.id());
|
||||
closeNotification(noti, closeReason);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include "freedesktopnotification_backend.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
#include "core/notification/notification.h"
|
||||
#include <QtCore>
|
||||
#include <QImage>
|
||||
#include "fredesktopnotification.h"
|
||||
#include "core/snore.h"
|
||||
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend )
|
||||
|
||||
|
||||
FreedesktopBackend::FreedesktopBackend () :
|
||||
SnoreBackend ( "FreedesktopNotification_Backend",true,true)
|
||||
{
|
||||
}
|
||||
|
||||
bool FreedesktopBackend::init(SnoreCore *snore){
|
||||
|
||||
m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
||||
QDBusConnection::sessionBus(), this );
|
||||
|
||||
QDBusPendingReply<QStringList> reply = m_interface->GetCapabilities();
|
||||
reply.waitForFinished();
|
||||
QStringList caps = reply.value();
|
||||
m_supportsRichtext = caps.contains( "body-markup" );
|
||||
connect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString)));
|
||||
connect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint)));
|
||||
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotRegisterApplication ( Application *application )
|
||||
{
|
||||
Q_UNUSED ( application );
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotUnregisterApplication ( Application *application )
|
||||
{
|
||||
Q_UNUSED ( application );
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotNotify ( Notification noti )
|
||||
{
|
||||
QStringList actions;
|
||||
foreach(int k,noti.actions().keys())
|
||||
{
|
||||
actions << QString::number(k) << noti.actions()[k]->name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QVariantMap hints;
|
||||
if(noti.icon().isValid())
|
||||
{
|
||||
FreedesktopImageHint image(noti.icon().image());
|
||||
hints["image_data"] = QVariant::fromValue(image);
|
||||
}
|
||||
|
||||
if(noti.priority() != NotificationEnums::Prioritys::NORMAL)
|
||||
{
|
||||
hints["urgency"] = (char)noti.priority()+1;
|
||||
}
|
||||
|
||||
|
||||
uint updateId = 0;
|
||||
if(noti.updateID() != 0)
|
||||
{
|
||||
updateId = m_snoreIdMap[noti.updateID()];
|
||||
m_dbusIdMap[updateId] = noti.id();
|
||||
m_snoreIdMap[noti.id()] = updateId;
|
||||
}
|
||||
|
||||
QString title = QString("%1 - %2").arg(noti.application(), noti.title());
|
||||
QString body(noti.text());
|
||||
if(!supportsRichtext())
|
||||
{
|
||||
title = Snore::toPlainText(title);
|
||||
body = Snore::toPlainText(body);
|
||||
}
|
||||
QDBusPendingReply<uint> id = m_interface->Notify(noti.application(), updateId, "", title,
|
||||
body, actions, hints, noti.sticky()?-1:noti.timeout()*1000);
|
||||
|
||||
if(noti.updateID() == 0)
|
||||
{
|
||||
id.waitForFinished();
|
||||
m_snoreIdMap[noti.id()] = id.value();
|
||||
m_dbusIdMap[id.value()] = noti.id();
|
||||
}
|
||||
}
|
||||
void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){
|
||||
Notification noti = getActiveNotificationByID(m_dbusIdMap[id]);
|
||||
if(!noti.isValid())
|
||||
return;
|
||||
noti.setActionInvoked ( actionID.toInt() );
|
||||
snore()->notificationActionInvoked ( noti );
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotCloseNotification ( Notification notification )
|
||||
{
|
||||
if(!m_snoreIdMap.contains(notification.id()))
|
||||
return;
|
||||
uint id = m_snoreIdMap.take(notification.id());
|
||||
m_dbusIdMap.remove(id);
|
||||
m_interface->CloseNotification(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason )
|
||||
{
|
||||
NotificationEnums::CloseReasons::closeReasons closeReason = NotificationEnums::CloseReasons::closeReasons(reason);
|
||||
qDebug() << Q_FUNC_INFO << "Closed" << id << "|" << closeReason << reason;
|
||||
if(id == 0)
|
||||
return;
|
||||
Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id));
|
||||
m_snoreIdMap.remove(noti.id());
|
||||
closeNotification(noti, closeReason);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
#ifndef FREEDESKTOPNOTIFICATION_H
|
||||
#define FREEDESKTOPNOTIFICATION_H
|
||||
#include "core/plugins/snorebackend.h"
|
||||
#include "notificationinterface.h"
|
||||
|
||||
class FreedesktopBackend:public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES ( Snore::SnoreBackend )
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
FreedesktopBackend();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
public slots:
|
||||
void slotNotify( Snore::Notification notification );
|
||||
void slotCloseNotification ( Snore::Notification notification );
|
||||
void slotRegisterApplication ( Snore::Application *application );
|
||||
void slotUnregisterApplication ( Snore::Application *application );
|
||||
|
||||
void slotActionInvoked(const uint &id,const QString &actionID);
|
||||
void slotNotificationClosed ( const uint &id,const uint &reason );
|
||||
|
||||
|
||||
private:
|
||||
org::freedesktop::Notifications* m_interface;
|
||||
QHash<uint,uint> m_dbusIdMap;
|
||||
QHash<uint,uint> m_snoreIdMap;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // FREEDESKTOPNOTIFICATION_H
|
||||
#ifndef FREEDESKTOPNOTIFICATION_H
|
||||
#define FREEDESKTOPNOTIFICATION_H
|
||||
#include "core/plugins/snorebackend.h"
|
||||
#include "notificationinterface.h"
|
||||
|
||||
class FreedesktopBackend:public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES ( Snore::SnoreBackend )
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
FreedesktopBackend();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
public slots:
|
||||
void slotNotify( Snore::Notification notification );
|
||||
void slotCloseNotification ( Snore::Notification notification );
|
||||
void slotRegisterApplication ( Snore::Application *application );
|
||||
void slotUnregisterApplication ( Snore::Application *application );
|
||||
|
||||
void slotActionInvoked(const uint &id,const QString &actionID);
|
||||
void slotNotificationClosed ( const uint &id,const uint &reason );
|
||||
|
||||
|
||||
private:
|
||||
org::freedesktop::Notifications* m_interface;
|
||||
QHash<uint,uint> m_dbusIdMap;
|
||||
QHash<uint,uint> m_snoreIdMap;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // FREEDESKTOPNOTIFICATION_H
|
||||
|
|
|
@ -1,154 +1,154 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "growl.h"
|
||||
#include "gntp.h"
|
||||
|
||||
#include "core/snore.h"
|
||||
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(growl,Growl)
|
||||
|
||||
Growl *Growl::s_instance = NULL;
|
||||
|
||||
Growl::Growl():
|
||||
SnoreBackend("Growl",false,false),
|
||||
m_id(0),
|
||||
m_defaultGNTP(NULL)
|
||||
{
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
Growl::~Growl()
|
||||
{
|
||||
if(snore() != NULL)
|
||||
{
|
||||
foreach(Application *a,snore()->aplications())
|
||||
{
|
||||
this->slotUnregisterApplication(a);
|
||||
}
|
||||
}
|
||||
delete m_defaultGNTP;
|
||||
}
|
||||
|
||||
bool Growl::init(SnoreCore *snore)
|
||||
{
|
||||
Icon icon(":/root/snore.png");
|
||||
m_defaultGNTP = new gntp("SnoreNotify", icon.localUrl().toUtf8().constData());
|
||||
|
||||
std::vector<std::string> alerts;
|
||||
alerts.push_back("Default");
|
||||
try
|
||||
{
|
||||
m_defaultGNTP->regist(alerts);
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << e.what();
|
||||
delete m_defaultGNTP;
|
||||
m_defaultGNTP = NULL;
|
||||
return false;
|
||||
}
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void Growl::slotRegisterApplication(Application *application)
|
||||
{
|
||||
gntp *growl = new gntp(application->name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData());
|
||||
|
||||
gntp::gntp_callback callback(&Growl::gntpCallback);
|
||||
growl->set_gntp_callback(callback);
|
||||
|
||||
// qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData();
|
||||
std::vector<std::string> alerts;
|
||||
foreach(Alert *a,application->alerts())
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData();
|
||||
alerts.push_back(a->name().toUtf8().constData());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
growl->regist(alerts);
|
||||
}catch(const std::exception& e)
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << e.what();
|
||||
}
|
||||
m_applications.insert(application->name(),growl);
|
||||
}
|
||||
|
||||
void Growl::slotUnregisterApplication(Application *application)
|
||||
{
|
||||
gntp *growl = m_applications.take(application->name());
|
||||
if(growl == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
delete growl;
|
||||
}
|
||||
|
||||
void Growl::slotNotify(Notification notification)
|
||||
{
|
||||
gntp *growl = m_applications.value(notification.application());
|
||||
QString alert = notification.alert();
|
||||
if(growl == NULL)
|
||||
{
|
||||
growl = m_defaultGNTP;
|
||||
alert = "Default";
|
||||
}
|
||||
// qDebug() << "Notify Growl:" <<notification.application() << alert << Snore::toPlainText(notification.title());
|
||||
try
|
||||
{
|
||||
growl->notify(alert.toUtf8().constData(),notification.id(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||
notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1");
|
||||
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data)
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << id << QString(reason.c_str()) << QString(data.c_str());
|
||||
Notification n = s_instance->snore()->getActiveNotificationByID(id);
|
||||
NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;
|
||||
if(reason == "TIMEDOUT")
|
||||
{
|
||||
r = NotificationEnums::CloseReasons::TIMED_OUT;
|
||||
}
|
||||
else if(reason == "CLOSED")
|
||||
{
|
||||
r = NotificationEnums::CloseReasons::DISMISSED;
|
||||
}
|
||||
else if(reason == "CLICK")
|
||||
{
|
||||
r = NotificationEnums::CloseReasons::CLOSED;
|
||||
s_instance->snore()->notificationActionInvoked(n);
|
||||
}
|
||||
s_instance->closeNotification(n,r);
|
||||
}
|
||||
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "growl.h"
|
||||
#include "gntp.h"
|
||||
|
||||
#include "core/snore.h"
|
||||
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(growl,Growl)
|
||||
|
||||
Growl *Growl::s_instance = NULL;
|
||||
|
||||
Growl::Growl():
|
||||
SnoreBackend("Growl",false,false),
|
||||
m_id(0),
|
||||
m_defaultGNTP(NULL)
|
||||
{
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
Growl::~Growl()
|
||||
{
|
||||
if(snore() != NULL)
|
||||
{
|
||||
foreach(Application *a,snore()->aplications())
|
||||
{
|
||||
this->slotUnregisterApplication(a);
|
||||
}
|
||||
}
|
||||
delete m_defaultGNTP;
|
||||
}
|
||||
|
||||
bool Growl::init(SnoreCore *snore)
|
||||
{
|
||||
Icon icon(":/root/snore.png");
|
||||
m_defaultGNTP = new gntp("SnoreNotify", icon.localUrl().toUtf8().constData());
|
||||
|
||||
std::vector<std::string> alerts;
|
||||
alerts.push_back("Default");
|
||||
try
|
||||
{
|
||||
m_defaultGNTP->regist(alerts);
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << e.what();
|
||||
delete m_defaultGNTP;
|
||||
m_defaultGNTP = NULL;
|
||||
return false;
|
||||
}
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void Growl::slotRegisterApplication(Application *application)
|
||||
{
|
||||
gntp *growl = new gntp(application->name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData());
|
||||
|
||||
gntp::gntp_callback callback(&Growl::gntpCallback);
|
||||
growl->set_gntp_callback(callback);
|
||||
|
||||
// qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData();
|
||||
std::vector<std::string> alerts;
|
||||
foreach(Alert *a,application->alerts())
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData();
|
||||
alerts.push_back(a->name().toUtf8().constData());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
growl->regist(alerts);
|
||||
}catch(const std::exception& e)
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << e.what();
|
||||
}
|
||||
m_applications.insert(application->name(),growl);
|
||||
}
|
||||
|
||||
void Growl::slotUnregisterApplication(Application *application)
|
||||
{
|
||||
gntp *growl = m_applications.take(application->name());
|
||||
if(growl == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
delete growl;
|
||||
}
|
||||
|
||||
void Growl::slotNotify(Notification notification)
|
||||
{
|
||||
gntp *growl = m_applications.value(notification.application());
|
||||
QString alert = notification.alert();
|
||||
if(growl == NULL)
|
||||
{
|
||||
growl = m_defaultGNTP;
|
||||
alert = "Default";
|
||||
}
|
||||
// qDebug() << "Notify Growl:" <<notification.application() << alert << Snore::toPlainText(notification.title());
|
||||
try
|
||||
{
|
||||
growl->notify(alert.toUtf8().constData(),notification.id(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||
notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1");
|
||||
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data)
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << id << QString(reason.c_str()) << QString(data.c_str());
|
||||
Notification n = s_instance->snore()->getActiveNotificationByID(id);
|
||||
NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;
|
||||
if(reason == "TIMEDOUT")
|
||||
{
|
||||
r = NotificationEnums::CloseReasons::TIMED_OUT;
|
||||
}
|
||||
else if(reason == "CLOSED")
|
||||
{
|
||||
r = NotificationEnums::CloseReasons::DISMISSED;
|
||||
}
|
||||
else if(reason == "CLICK")
|
||||
{
|
||||
r = NotificationEnums::CloseReasons::CLOSED;
|
||||
s_instance->snore()->notificationActionInvoked(n);
|
||||
}
|
||||
s_instance->closeNotification(n,r);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,53 +1,53 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 GROWL_BACKEND_H
|
||||
#define GROWL_BACKEND_H
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class Growl:public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
|
||||
public:
|
||||
Growl();
|
||||
~Growl();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
static void gntpCallback(const int &id,const std::string &reason,const std::string &data);
|
||||
|
||||
private:
|
||||
//a static instance for the static callback methode
|
||||
static Growl *s_instance;
|
||||
uint m_id;
|
||||
QHash<QString,class gntp*> m_applications;
|
||||
gntp *m_defaultGNTP;
|
||||
|
||||
public slots:
|
||||
void slotRegisterApplication(Snore::Application *application);
|
||||
void slotUnregisterApplication(Snore::Application *application);
|
||||
void slotNotify(Snore::Notification notification);
|
||||
};
|
||||
|
||||
|
||||
#endif // GROWL_BACKEND_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 GROWL_BACKEND_H
|
||||
#define GROWL_BACKEND_H
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class Growl:public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
|
||||
public:
|
||||
Growl();
|
||||
~Growl();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
static void gntpCallback(const int &id,const std::string &reason,const std::string &data);
|
||||
|
||||
private:
|
||||
//a static instance for the static callback methode
|
||||
static Growl *s_instance;
|
||||
uint m_id;
|
||||
QHash<QString,class gntp*> m_applications;
|
||||
gntp *m_defaultGNTP;
|
||||
|
||||
public slots:
|
||||
void slotRegisterApplication(Snore::Application *application);
|
||||
void slotUnregisterApplication(Snore::Application *application);
|
||||
void slotNotify(Snore::Notification notification);
|
||||
};
|
||||
|
||||
|
||||
#endif // GROWL_BACKEND_H
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,408 +1,408 @@
|
|||
#ifndef SNARL_INTERFACE_V42_H
|
||||
#define SNARL_INTERFACE_V42_H
|
||||
|
||||
#if defined(__MINGW32__) && !defined(MINGW_HAS_SECURE_API)
|
||||
#define MINGW_HAS_SECURE_API
|
||||
#endif
|
||||
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#ifndef SMTO_NOTIMEOUTIFNOTHUNG
|
||||
#define SMTO_NOTIMEOUTIFNOTHUNG 8
|
||||
#endif
|
||||
|
||||
|
||||
namespace Snarl {
|
||||
namespace V42 {
|
||||
|
||||
static LPCTSTR SnarlWindowClass = _T("w>Snarl");
|
||||
static LPCTSTR SnarlWindowTitle = _T("Snarl");
|
||||
|
||||
static LPCTSTR SnarlGlobalMsg = _T("SnarlGlobalEvent");
|
||||
static LPCTSTR SnarlAppMsg = _T("SnarlAppMessage");
|
||||
|
||||
static const DWORD WM_SNARLTEST = WM_USER + 237;
|
||||
|
||||
/// <summary>Application requests - these values appear in wParam.<para>Application should launch its settings UI</para></summary>
|
||||
static const WPARAM AppDoPrefs = 1;
|
||||
/// <summary>Application requests - these values appear in wParam.<para>Application should show its About... dialog</para></summary>
|
||||
static const WPARAM AppDoAbout = 2;
|
||||
|
||||
|
||||
// Enums put in own namespace, because ANSI C++ doesn't decorate enums with tagname :(
|
||||
namespace SnarlEnums {
|
||||
|
||||
/// <summary>
|
||||
/// Global event identifiers - sent as Windows broadcast messages.
|
||||
/// These values appear in wParam of the message.
|
||||
/// </summary>
|
||||
enum GlobalEvent
|
||||
{
|
||||
SnarlLaunched = 1, // Snarl has just started running
|
||||
SnarlQuit = 2, // Snarl is about to stop running
|
||||
SnarlGlobalStopped = 3, // Sent when stopped by user - Also sent to registered window
|
||||
SnarlGlobalStarted = 4, // Sent when started by user - Also sent to registered window
|
||||
};
|
||||
|
||||
enum SnarlStatus
|
||||
{
|
||||
Success = 0,
|
||||
|
||||
// Snarl-Stopped/Started/UserAway/UserBack is defined in the GlobalEvent struct in VB6 code,
|
||||
// but are sent directly to a registered window, so in C# they are defined here instead.
|
||||
// Implemented as of Snarl R2.4 Beta3
|
||||
SnarlStopped = 3, // Sent when stopped by user - Also sent as broadcast message
|
||||
SnarlStarted, // Sent when started by user - Also sent as broadcast message
|
||||
SnarlUserAway, // Away mode was enabled
|
||||
SnarlUserBack, // Away mode was disabled
|
||||
|
||||
// Win32 callbacks (renamed under V42)
|
||||
CallbackRightClick = 32, // Deprecated as of V42, ex. SNARL_NOTIFICATION_CLICKED/SNARL_NOTIFICATION_CANCELLED
|
||||
CallbackTimedOut,
|
||||
CallbackInvoked, // left clicked and no default callback assigned
|
||||
CallbackMenuSelected, // HIWORD(wParam) contains 1-based menu item index
|
||||
CallbackMiddleClick, // Deprecated as of V42
|
||||
CallbackClosed,
|
||||
|
||||
// critical errors
|
||||
ErrorFailed = 101, // miscellaneous failure
|
||||
ErrorUnknownCommand, // specified command not recognised
|
||||
ErrorTimedOut, // Snarl took too long to respond
|
||||
//104 gen critical #4
|
||||
//105 gen critical #5
|
||||
ErrorBadSocket = 106, // invalid socket (or some other socket-related error)
|
||||
ErrorBadPacket = 107, // badly formed request
|
||||
ErrorInvalidArg = 108, // arg supplied was invalid (Added in v42.56)
|
||||
ErrorArgMissing = 109, // required argument missing
|
||||
ErrorSystem, // internal system error
|
||||
//120 libsnarl critical block
|
||||
ErrorAccessDenied = 121, // libsnarl only
|
||||
//130 SNP/3.0-specific
|
||||
ErrorUnsupportedVersion = 131, // requested SNP version is not supported
|
||||
ErrorNoActionsProvided, // empty request
|
||||
ErrorUnsupportedEncryption, // requested encryption type is not supported
|
||||
ErrorUnsupportedHashing, // requested message hashing type is not supported
|
||||
|
||||
// warnings
|
||||
ErrorNotRunning = 201, // Snarl handling window not found
|
||||
ErrorNotRegistered,
|
||||
ErrorAlreadyRegistered, // not used yet; sn41RegisterApp() returns existing token
|
||||
ErrorClassAlreadyExists, // not used yet
|
||||
ErrorClassBlocked,
|
||||
ErrorClassNotFound,
|
||||
ErrorNotificationNotFound,
|
||||
ErrorFlooding, // notification generated by same class within quantum
|
||||
ErrorDoNotDisturb, // DnD mode is in effect was not logged as missed
|
||||
ErrorCouldNotDisplay, // not enough space on-screen to display notification
|
||||
ErrorAuthFailure, // password mismatch
|
||||
// Release 2.4.2
|
||||
ErrorDiscarded, // discarded for some reason, e.g. foreground app match
|
||||
ErrorNotSubscribed, // subscriber not found
|
||||
|
||||
// informational
|
||||
// code 250 reserved for future use
|
||||
WasMerged = 251, // notification was merged, returned token is the one we merged with
|
||||
|
||||
// callbacks
|
||||
// code 300 reserved for future use
|
||||
NotifyGone = 301, // reserved for future use
|
||||
|
||||
// The following are currently specific to SNP 2.0 and are effectively the
|
||||
// Win32 SNARL_CALLBACK_nnn constants with 270 added to them
|
||||
|
||||
// SNARL_NOTIFY_CLICK = 302 // indicates notification was right-clicked (deprecated as of V42)
|
||||
NotifyExpired = 303,
|
||||
NotifyInvoked = 304, // note this was "ACK" in a previous life
|
||||
NotifyMenu, // indicates an item was selected from user-defined menu (deprecated as of V42)
|
||||
// SNARL_NOTIFY_EX_CLICK // user clicked the middle mouse button (deprecated as of V42)
|
||||
NotifyClosed = 307, // // user clicked the notification's close gadget (GNTP only)
|
||||
|
||||
// the following is generic to SNP and the Win32 API
|
||||
NotifyAction = 308, // user picked an action from the list, the data value will indicate which one
|
||||
|
||||
|
||||
// C++ interface custom errors- not part of official API!
|
||||
ErrorCppInterface = 1001
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The priority of messages.
|
||||
/// See <cref>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Generic_API#notify</cref>
|
||||
/// </summary>
|
||||
enum MessagePriority
|
||||
{
|
||||
PriorityUndefined = -2,
|
||||
PriorityLow = -1,
|
||||
PriorityNormal = 0,
|
||||
PriorityHigh = 1
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Application flags - features this app supports.
|
||||
/// </summary>
|
||||
enum AppFlags
|
||||
{
|
||||
AppFlagNone = 0,
|
||||
AppHasPrefs = 1,
|
||||
AppHasAbout = 2,
|
||||
AppIsWindowless = 0x8000
|
||||
};
|
||||
|
||||
} // namespace SnarlEnums
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
/// SnarlParameterList class definition - Helper class, not meant for broad use
|
||||
// ----------------------------------------------------------------------------------------
|
||||
template<class T>
|
||||
class SnarlParameterList
|
||||
{
|
||||
public:
|
||||
typedef std::pair<std::basic_string<T>, std::basic_string<T> > PairType;
|
||||
|
||||
SnarlParameterList()
|
||||
{
|
||||
}
|
||||
|
||||
explicit SnarlParameterList(int initialCapacity)
|
||||
{
|
||||
list.reserve(initialCapacity);
|
||||
}
|
||||
|
||||
void Add(const T* _key, const T* _value)
|
||||
{
|
||||
if (_value != NULL)
|
||||
list.push_back(PairType(std::basic_string<T>(_key), std::basic_string<T>(_value))); //
|
||||
}
|
||||
|
||||
void Add(const T* _key, LONG32 _value)
|
||||
{
|
||||
std::basic_stringstream<T> valStr;
|
||||
valStr << _value;
|
||||
list.push_back(PairType(std::basic_string<T>(_key), valStr.str()));
|
||||
}
|
||||
|
||||
void Add(const T* _key, void* _value)
|
||||
{
|
||||
if (_value != NULL)
|
||||
{
|
||||
std::basic_stringstream<T> valStr;
|
||||
valStr << (INT_PTR)_value; // Uckly hack, to get stringstream to print void* as decimal not hex
|
||||
|
||||
list.push_back(PairType(std::basic_string<T>(_key), valStr.str()));
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<PairType>& GetList() const
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<PairType> list;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// SnarlInterface class definition
|
||||
// ----------------------------------------------------------------------------------------
|
||||
class SnarlInterface
|
||||
{
|
||||
public:
|
||||
/// <summary>Requests strings known by Snarl</summary>
|
||||
class Requests
|
||||
{
|
||||
public:
|
||||
static LPCSTR AddActionA() { return "addaction"; }
|
||||
static LPCWSTR AddActionW() { return L"addaction"; }
|
||||
static LPCSTR AddClassA() { return "addclass"; }
|
||||
static LPCWSTR AddClassW() { return L"addclass"; }
|
||||
static LPCSTR ClearActionsA() { return "clearactions"; }
|
||||
static LPCWSTR ClearActionsW() { return L"clearactions"; }
|
||||
static LPCSTR ClearClassesA() { return "clearclasses"; }
|
||||
static LPCWSTR ClearClassesW() { return L"clearclasses"; }
|
||||
static LPCSTR HelloA() { return "hello"; }
|
||||
static LPCWSTR HelloW() { return L"hello"; }
|
||||
static LPCSTR HideA() { return "hide"; }
|
||||
static LPCWSTR HideW() { return L"hide"; }
|
||||
static LPCSTR IsVisibleA() { return "isvisible"; }
|
||||
static LPCWSTR IsVisibleW() { return L"isvisible"; }
|
||||
static LPCSTR NotifyA() { return "notify"; }
|
||||
static LPCWSTR NotifyW() { return L"notify"; }
|
||||
static LPCSTR RegisterA() { return "reg"; } // register
|
||||
static LPCWSTR RegisterW() { return L"reg"; }
|
||||
static LPCSTR RemoveClassA() { return "remclass"; }
|
||||
static LPCWSTR RemoveClassW() { return L"remclass"; }
|
||||
static LPCSTR UnregisterA() { return "unregister"; }
|
||||
static LPCWSTR UnregisterW() { return L"unregister"; }
|
||||
static LPCSTR UpdateAppA() { return "updateapp"; }
|
||||
static LPCWSTR UpdateAppW() { return L"updateapp"; }
|
||||
static LPCSTR UpdateA() { return "update"; }
|
||||
static LPCWSTR UpdateW() { return L"update"; }
|
||||
static LPCSTR VersionA() { return "version"; }
|
||||
static LPCWSTR VersionW() { return L"version"; }
|
||||
};
|
||||
|
||||
SnarlInterface();
|
||||
virtual ~SnarlInterface();
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
// Static functions
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
// Use FreeString, when SnarlInterface returns a null terminated string pointer
|
||||
static LPTSTR AllocateString(size_t n) { return new TCHAR[n]; }
|
||||
static void FreeString(LPSTR str) { delete [] str; str = NULL; }
|
||||
static void FreeString(LPCSTR str) { delete [] str; }
|
||||
static void FreeString(LPWSTR str) { delete [] str; str = NULL; }
|
||||
static void FreeString(LPCWSTR str) { delete [] str; }
|
||||
|
||||
/// <summary>Send message to Snarl.</summary>
|
||||
/// <param name='request'>The request string. If using unicode version, the string will be UTF8 encoded before sending.</param>
|
||||
/// <param name='replyTimeout'>Time to wait before timeout - Default = 1000</param>
|
||||
/// <returns>
|
||||
/// Return zero or positive on Success.
|
||||
/// Negative on failure. (Get error code by abs(return_value))
|
||||
/// <see>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Windows_API#Return_Value</see>
|
||||
/// </returns>
|
||||
static LONG32 DoRequest(LPCSTR request, UINT replyTimeout = 1000);
|
||||
static LONG32 DoRequest(LPCWSTR request, UINT replyTimeout = 1000);
|
||||
|
||||
/// <summary>Escapes a string, so it can be passed to Snarl.</summary>
|
||||
/// <remarks>
|
||||
/// Should only be used, if you are using DoRequest() and not the helper functions.
|
||||
/// Remember to Escape each key/value pair individually.
|
||||
/// </remarks>
|
||||
static std::basic_string<char>& Escape(std::basic_string<char>& str);
|
||||
static std::basic_string<wchar_t>& Escape(std::basic_string<wchar_t>& str);
|
||||
|
||||
/// <summary>Returns the global Snarl Application message (V39)</summary>
|
||||
/// <returns>Returns Snarl application registered message.</returns>
|
||||
static UINT AppMsg();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the value of Snarl's global registered message.
|
||||
/// Notes:
|
||||
/// Snarl registers SNARL_GLOBAL_MSG during startup which it then uses to communicate
|
||||
/// with all running applications through a Windows broadcast message. This function can
|
||||
/// only fail if for some reason the Windows RegisterWindowMessage() function fails
|
||||
/// - given this, this function *cannnot* be used to test for the presence of Snarl.
|
||||
/// </summary>
|
||||
/// <returns>A 16-bit value (translated to 32-bit) which is the registered Windows message for Snarl.</returns>
|
||||
static UINT Broadcast();
|
||||
|
||||
/// <summary>
|
||||
/// Get the path to where Snarl is installed.
|
||||
/// ** Remember to call <see cref="FreeString(LPSTR)" /> on the returned string !!!
|
||||
/// </summary>
|
||||
/// <returns>Returns the path to where Snarl is installed.</returns>
|
||||
/// <remarks>This is a V39 API method.</remarks>
|
||||
static LPCTSTR GetAppPath();
|
||||
|
||||
/// <summary>
|
||||
/// Get the path to where the default Snarl icons are located.
|
||||
/// <para>** Remember to call <see cref="FreeString(LPSTR)" /> on the returned string !!!</para>
|
||||
/// </summary>
|
||||
/// <returns>Returns the path to where the default Snarl icons are located.</returns>
|
||||
/// <remarks>This is a V39 API method.</remarks>
|
||||
static LPCTSTR GetIconsPath();
|
||||
|
||||
/// <summary>Returns a handle to the Snarl Dispatcher window (V37)</summary>
|
||||
/// <returns>Returns handle to Snarl Dispatcher window, or zero if it's not found.</returns>
|
||||
/// <remarks>This is now the preferred way to test if Snarl is actually running.</remarks>
|
||||
static HWND GetSnarlWindow();
|
||||
|
||||
/// <summary>Get Snarl version, if it is running.</summary>
|
||||
/// <returns>Returns a number indicating Snarl version.</returns>
|
||||
static LONG32 GetVersion();
|
||||
|
||||
/// <summary>Check whether Snarl is running</summary>
|
||||
/// <returns>Returns true if Snarl system was found running.</returns>
|
||||
static BOOL IsSnarlRunning();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
/// <summary>Adds an action to an existing (on-screen or in the missed list) notification.</summary>
|
||||
LONG32 AddAction(LONG32 msgToken, LPCSTR label, LPCSTR cmd);
|
||||
LONG32 AddAction(LONG32 msgToken, LPCWSTR label, LPCWSTR cmd);
|
||||
|
||||
/// <summary>Add a notification class to Snarl.</summary>
|
||||
LONG32 AddClass(LPCSTR classId, LPCSTR name, LPCSTR title = NULL, LPCSTR text = NULL, LPCSTR icon = NULL, LPCSTR sound = NULL, LONG32 duration = NULL, LPCSTR callback = NULL, bool enabled = true);
|
||||
LONG32 AddClass(LPCWSTR classId, LPCWSTR name, LPCWSTR title = NULL, LPCWSTR text = NULL, LPCWSTR icon = NULL, LPCWSTR sound = NULL, LONG32 duration = -1, LPCWSTR callback = NULL, bool enabled = true);
|
||||
|
||||
/// <summary>Remove all notification classes in one call.</summary>
|
||||
LONG32 ClearActions(LONG32 msgToken);
|
||||
|
||||
/// <summary>Remove all notification classes in one call.</summary>
|
||||
LONG32 ClearClasses();
|
||||
|
||||
/// <summary>GetLastMsgToken() returns token of the last message sent to Snarl.</summary>
|
||||
/// <returns>Returns message token of last message.</returns>
|
||||
/// <remarks>This function is not in the official API!</remarks>
|
||||
LONG32 GetLastMsgToken() const;
|
||||
|
||||
/// <summary>Hide a Snarl notification.</summary>
|
||||
LONG32 Hide(LONG32 msgToken);
|
||||
|
||||
/// <summary>Test if a Snarl notification is visible. If the message is visible the function returns SnarlEnums::Success.</summary>
|
||||
LONG32 IsVisible(LONG32 msgToken);
|
||||
|
||||
/// <summary>Show a Snarl notification.</summary>
|
||||
/// <returns>Returns the notification token or negative on failure.</returns>
|
||||
/// <remarks>You can use <see cref="GetLastMsgToken()" /> to get the last token.</remarks>
|
||||
LONG32 Notify(LPCSTR classId = NULL, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR iconPath = NULL, LPCSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCSTR uid = NULL, LPCSTR callback = NULL, LPCSTR value = NULL);
|
||||
LONG32 Notify(LPCWSTR classId = NULL, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR iconPath = NULL, LPCWSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCWSTR uid = NULL, LPCWSTR callback = NULL, LPCWSTR value = NULL);
|
||||
|
||||
/// <summary>Register application with Snarl.</summary>
|
||||
/// <returns>The application token or negative on failure.</returns>
|
||||
/// <remarks>The application token is saved in SnarlInterface member variable, so just use return value to check for error.</remarks>
|
||||
LONG32 Register(LPCSTR signature, LPCSTR title, LPCSTR icon = NULL, LPCSTR password = NULL, HWND hWndReplyTo = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppFlagNone);
|
||||
LONG32 Register(LPCWSTR signature, LPCWSTR title, LPCWSTR icon = NULL, LPCWSTR password = NULL, HWND hWndReplyTo = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppFlagNone);
|
||||
|
||||
/// <summary>Remove a notification class added with AddClass().</summary>
|
||||
LONG32 RemoveClass(LPCSTR classId);
|
||||
LONG32 RemoveClass(LPCWSTR classId);
|
||||
|
||||
/// <summary>Update the text or other parameters of a visible Snarl notification.</summary>
|
||||
LONG32 Update(LONG32 msgToken, LPCSTR classId = NULL, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR iconPath = NULL, LPCSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCSTR callback = NULL, LPCSTR value = NULL);
|
||||
LONG32 Update(LONG32 msgToken, LPCWSTR classId = NULL, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR iconPath = NULL, LPCWSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCWSTR callback = NULL, LPCWSTR value = NULL);
|
||||
|
||||
/// <summary>Unregister application with Snarl when application is closing.</summary>
|
||||
LONG32 Unregister(LPCSTR signature);
|
||||
LONG32 Unregister(LPCWSTR signature);
|
||||
|
||||
/// <summary>Update information provided when calling RegisterApp.</summary>
|
||||
/*LONG32 UpdateApp(LPCSTR title = NULL, LPCSTR icon = NULL);
|
||||
LONG32 UpdateApp(LPCWSTR title = NULL, LPCWSTR icon = NULL);*/
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/// <summary>Convert a unicode string to UTF8</summary>
|
||||
/// <returns>Returns pointer to the new string - Remember to delete [] returned string !</returns>
|
||||
/// <remarks>Remember to call FreeString on returned string !!!</remarks>
|
||||
static LPSTR WideToUTF8(LPCWSTR szWideStr);
|
||||
|
||||
static LONG32 DoRequest(LPCSTR request, SnarlParameterList<char>& spl, UINT replyTimeout = 1000);
|
||||
static LONG32 DoRequest(LPCWSTR request, SnarlParameterList<wchar_t>& spl, UINT replyTimeout = 1000);
|
||||
|
||||
void SetPassword(LPCSTR password);
|
||||
void SetPassword(LPCWSTR password);
|
||||
void ClearPassword();
|
||||
|
||||
LONG32 appToken;
|
||||
LONG32 lastMsgToken;
|
||||
LPSTR szPasswordA;
|
||||
LPWSTR szPasswordW;
|
||||
}; // class SnarlInterface
|
||||
|
||||
} // namespace V42
|
||||
} // namespace Snarl
|
||||
|
||||
#endif // SNARL_INTERFACE_V42_H
|
||||
|
||||
#ifndef SNARL_INTERFACE_V42_H
|
||||
#define SNARL_INTERFACE_V42_H
|
||||
|
||||
#if defined(__MINGW32__) && !defined(MINGW_HAS_SECURE_API)
|
||||
#define MINGW_HAS_SECURE_API
|
||||
#endif
|
||||
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#ifndef SMTO_NOTIMEOUTIFNOTHUNG
|
||||
#define SMTO_NOTIMEOUTIFNOTHUNG 8
|
||||
#endif
|
||||
|
||||
|
||||
namespace Snarl {
|
||||
namespace V42 {
|
||||
|
||||
static LPCTSTR SnarlWindowClass = _T("w>Snarl");
|
||||
static LPCTSTR SnarlWindowTitle = _T("Snarl");
|
||||
|
||||
static LPCTSTR SnarlGlobalMsg = _T("SnarlGlobalEvent");
|
||||
static LPCTSTR SnarlAppMsg = _T("SnarlAppMessage");
|
||||
|
||||
static const DWORD WM_SNARLTEST = WM_USER + 237;
|
||||
|
||||
/// <summary>Application requests - these values appear in wParam.<para>Application should launch its settings UI</para></summary>
|
||||
static const WPARAM AppDoPrefs = 1;
|
||||
/// <summary>Application requests - these values appear in wParam.<para>Application should show its About... dialog</para></summary>
|
||||
static const WPARAM AppDoAbout = 2;
|
||||
|
||||
|
||||
// Enums put in own namespace, because ANSI C++ doesn't decorate enums with tagname :(
|
||||
namespace SnarlEnums {
|
||||
|
||||
/// <summary>
|
||||
/// Global event identifiers - sent as Windows broadcast messages.
|
||||
/// These values appear in wParam of the message.
|
||||
/// </summary>
|
||||
enum GlobalEvent
|
||||
{
|
||||
SnarlLaunched = 1, // Snarl has just started running
|
||||
SnarlQuit = 2, // Snarl is about to stop running
|
||||
SnarlGlobalStopped = 3, // Sent when stopped by user - Also sent to registered window
|
||||
SnarlGlobalStarted = 4, // Sent when started by user - Also sent to registered window
|
||||
};
|
||||
|
||||
enum SnarlStatus
|
||||
{
|
||||
Success = 0,
|
||||
|
||||
// Snarl-Stopped/Started/UserAway/UserBack is defined in the GlobalEvent struct in VB6 code,
|
||||
// but are sent directly to a registered window, so in C# they are defined here instead.
|
||||
// Implemented as of Snarl R2.4 Beta3
|
||||
SnarlStopped = 3, // Sent when stopped by user - Also sent as broadcast message
|
||||
SnarlStarted, // Sent when started by user - Also sent as broadcast message
|
||||
SnarlUserAway, // Away mode was enabled
|
||||
SnarlUserBack, // Away mode was disabled
|
||||
|
||||
// Win32 callbacks (renamed under V42)
|
||||
CallbackRightClick = 32, // Deprecated as of V42, ex. SNARL_NOTIFICATION_CLICKED/SNARL_NOTIFICATION_CANCELLED
|
||||
CallbackTimedOut,
|
||||
CallbackInvoked, // left clicked and no default callback assigned
|
||||
CallbackMenuSelected, // HIWORD(wParam) contains 1-based menu item index
|
||||
CallbackMiddleClick, // Deprecated as of V42
|
||||
CallbackClosed,
|
||||
|
||||
// critical errors
|
||||
ErrorFailed = 101, // miscellaneous failure
|
||||
ErrorUnknownCommand, // specified command not recognised
|
||||
ErrorTimedOut, // Snarl took too long to respond
|
||||
//104 gen critical #4
|
||||
//105 gen critical #5
|
||||
ErrorBadSocket = 106, // invalid socket (or some other socket-related error)
|
||||
ErrorBadPacket = 107, // badly formed request
|
||||
ErrorInvalidArg = 108, // arg supplied was invalid (Added in v42.56)
|
||||
ErrorArgMissing = 109, // required argument missing
|
||||
ErrorSystem, // internal system error
|
||||
//120 libsnarl critical block
|
||||
ErrorAccessDenied = 121, // libsnarl only
|
||||
//130 SNP/3.0-specific
|
||||
ErrorUnsupportedVersion = 131, // requested SNP version is not supported
|
||||
ErrorNoActionsProvided, // empty request
|
||||
ErrorUnsupportedEncryption, // requested encryption type is not supported
|
||||
ErrorUnsupportedHashing, // requested message hashing type is not supported
|
||||
|
||||
// warnings
|
||||
ErrorNotRunning = 201, // Snarl handling window not found
|
||||
ErrorNotRegistered,
|
||||
ErrorAlreadyRegistered, // not used yet; sn41RegisterApp() returns existing token
|
||||
ErrorClassAlreadyExists, // not used yet
|
||||
ErrorClassBlocked,
|
||||
ErrorClassNotFound,
|
||||
ErrorNotificationNotFound,
|
||||
ErrorFlooding, // notification generated by same class within quantum
|
||||
ErrorDoNotDisturb, // DnD mode is in effect was not logged as missed
|
||||
ErrorCouldNotDisplay, // not enough space on-screen to display notification
|
||||
ErrorAuthFailure, // password mismatch
|
||||
// Release 2.4.2
|
||||
ErrorDiscarded, // discarded for some reason, e.g. foreground app match
|
||||
ErrorNotSubscribed, // subscriber not found
|
||||
|
||||
// informational
|
||||
// code 250 reserved for future use
|
||||
WasMerged = 251, // notification was merged, returned token is the one we merged with
|
||||
|
||||
// callbacks
|
||||
// code 300 reserved for future use
|
||||
NotifyGone = 301, // reserved for future use
|
||||
|
||||
// The following are currently specific to SNP 2.0 and are effectively the
|
||||
// Win32 SNARL_CALLBACK_nnn constants with 270 added to them
|
||||
|
||||
// SNARL_NOTIFY_CLICK = 302 // indicates notification was right-clicked (deprecated as of V42)
|
||||
NotifyExpired = 303,
|
||||
NotifyInvoked = 304, // note this was "ACK" in a previous life
|
||||
NotifyMenu, // indicates an item was selected from user-defined menu (deprecated as of V42)
|
||||
// SNARL_NOTIFY_EX_CLICK // user clicked the middle mouse button (deprecated as of V42)
|
||||
NotifyClosed = 307, // // user clicked the notification's close gadget (GNTP only)
|
||||
|
||||
// the following is generic to SNP and the Win32 API
|
||||
NotifyAction = 308, // user picked an action from the list, the data value will indicate which one
|
||||
|
||||
|
||||
// C++ interface custom errors- not part of official API!
|
||||
ErrorCppInterface = 1001
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The priority of messages.
|
||||
/// See <cref>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Generic_API#notify</cref>
|
||||
/// </summary>
|
||||
enum MessagePriority
|
||||
{
|
||||
PriorityUndefined = -2,
|
||||
PriorityLow = -1,
|
||||
PriorityNormal = 0,
|
||||
PriorityHigh = 1
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Application flags - features this app supports.
|
||||
/// </summary>
|
||||
enum AppFlags
|
||||
{
|
||||
AppFlagNone = 0,
|
||||
AppHasPrefs = 1,
|
||||
AppHasAbout = 2,
|
||||
AppIsWindowless = 0x8000
|
||||
};
|
||||
|
||||
} // namespace SnarlEnums
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
/// SnarlParameterList class definition - Helper class, not meant for broad use
|
||||
// ----------------------------------------------------------------------------------------
|
||||
template<class T>
|
||||
class SnarlParameterList
|
||||
{
|
||||
public:
|
||||
typedef std::pair<std::basic_string<T>, std::basic_string<T> > PairType;
|
||||
|
||||
SnarlParameterList()
|
||||
{
|
||||
}
|
||||
|
||||
explicit SnarlParameterList(int initialCapacity)
|
||||
{
|
||||
list.reserve(initialCapacity);
|
||||
}
|
||||
|
||||
void Add(const T* _key, const T* _value)
|
||||
{
|
||||
if (_value != NULL)
|
||||
list.push_back(PairType(std::basic_string<T>(_key), std::basic_string<T>(_value))); //
|
||||
}
|
||||
|
||||
void Add(const T* _key, LONG32 _value)
|
||||
{
|
||||
std::basic_stringstream<T> valStr;
|
||||
valStr << _value;
|
||||
list.push_back(PairType(std::basic_string<T>(_key), valStr.str()));
|
||||
}
|
||||
|
||||
void Add(const T* _key, void* _value)
|
||||
{
|
||||
if (_value != NULL)
|
||||
{
|
||||
std::basic_stringstream<T> valStr;
|
||||
valStr << (INT_PTR)_value; // Uckly hack, to get stringstream to print void* as decimal not hex
|
||||
|
||||
list.push_back(PairType(std::basic_string<T>(_key), valStr.str()));
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<PairType>& GetList() const
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<PairType> list;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// SnarlInterface class definition
|
||||
// ----------------------------------------------------------------------------------------
|
||||
class SnarlInterface
|
||||
{
|
||||
public:
|
||||
/// <summary>Requests strings known by Snarl</summary>
|
||||
class Requests
|
||||
{
|
||||
public:
|
||||
static LPCSTR AddActionA() { return "addaction"; }
|
||||
static LPCWSTR AddActionW() { return L"addaction"; }
|
||||
static LPCSTR AddClassA() { return "addclass"; }
|
||||
static LPCWSTR AddClassW() { return L"addclass"; }
|
||||
static LPCSTR ClearActionsA() { return "clearactions"; }
|
||||
static LPCWSTR ClearActionsW() { return L"clearactions"; }
|
||||
static LPCSTR ClearClassesA() { return "clearclasses"; }
|
||||
static LPCWSTR ClearClassesW() { return L"clearclasses"; }
|
||||
static LPCSTR HelloA() { return "hello"; }
|
||||
static LPCWSTR HelloW() { return L"hello"; }
|
||||
static LPCSTR HideA() { return "hide"; }
|
||||
static LPCWSTR HideW() { return L"hide"; }
|
||||
static LPCSTR IsVisibleA() { return "isvisible"; }
|
||||
static LPCWSTR IsVisibleW() { return L"isvisible"; }
|
||||
static LPCSTR NotifyA() { return "notify"; }
|
||||
static LPCWSTR NotifyW() { return L"notify"; }
|
||||
static LPCSTR RegisterA() { return "reg"; } // register
|
||||
static LPCWSTR RegisterW() { return L"reg"; }
|
||||
static LPCSTR RemoveClassA() { return "remclass"; }
|
||||
static LPCWSTR RemoveClassW() { return L"remclass"; }
|
||||
static LPCSTR UnregisterA() { return "unregister"; }
|
||||
static LPCWSTR UnregisterW() { return L"unregister"; }
|
||||
static LPCSTR UpdateAppA() { return "updateapp"; }
|
||||
static LPCWSTR UpdateAppW() { return L"updateapp"; }
|
||||
static LPCSTR UpdateA() { return "update"; }
|
||||
static LPCWSTR UpdateW() { return L"update"; }
|
||||
static LPCSTR VersionA() { return "version"; }
|
||||
static LPCWSTR VersionW() { return L"version"; }
|
||||
};
|
||||
|
||||
SnarlInterface();
|
||||
virtual ~SnarlInterface();
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
// Static functions
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
// Use FreeString, when SnarlInterface returns a null terminated string pointer
|
||||
static LPTSTR AllocateString(size_t n) { return new TCHAR[n]; }
|
||||
static void FreeString(LPSTR str) { delete [] str; str = NULL; }
|
||||
static void FreeString(LPCSTR str) { delete [] str; }
|
||||
static void FreeString(LPWSTR str) { delete [] str; str = NULL; }
|
||||
static void FreeString(LPCWSTR str) { delete [] str; }
|
||||
|
||||
/// <summary>Send message to Snarl.</summary>
|
||||
/// <param name='request'>The request string. If using unicode version, the string will be UTF8 encoded before sending.</param>
|
||||
/// <param name='replyTimeout'>Time to wait before timeout - Default = 1000</param>
|
||||
/// <returns>
|
||||
/// Return zero or positive on Success.
|
||||
/// Negative on failure. (Get error code by abs(return_value))
|
||||
/// <see>http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Windows_API#Return_Value</see>
|
||||
/// </returns>
|
||||
static LONG32 DoRequest(LPCSTR request, UINT replyTimeout = 1000);
|
||||
static LONG32 DoRequest(LPCWSTR request, UINT replyTimeout = 1000);
|
||||
|
||||
/// <summary>Escapes a string, so it can be passed to Snarl.</summary>
|
||||
/// <remarks>
|
||||
/// Should only be used, if you are using DoRequest() and not the helper functions.
|
||||
/// Remember to Escape each key/value pair individually.
|
||||
/// </remarks>
|
||||
static std::basic_string<char>& Escape(std::basic_string<char>& str);
|
||||
static std::basic_string<wchar_t>& Escape(std::basic_string<wchar_t>& str);
|
||||
|
||||
/// <summary>Returns the global Snarl Application message (V39)</summary>
|
||||
/// <returns>Returns Snarl application registered message.</returns>
|
||||
static UINT AppMsg();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the value of Snarl's global registered message.
|
||||
/// Notes:
|
||||
/// Snarl registers SNARL_GLOBAL_MSG during startup which it then uses to communicate
|
||||
/// with all running applications through a Windows broadcast message. This function can
|
||||
/// only fail if for some reason the Windows RegisterWindowMessage() function fails
|
||||
/// - given this, this function *cannnot* be used to test for the presence of Snarl.
|
||||
/// </summary>
|
||||
/// <returns>A 16-bit value (translated to 32-bit) which is the registered Windows message for Snarl.</returns>
|
||||
static UINT Broadcast();
|
||||
|
||||
/// <summary>
|
||||
/// Get the path to where Snarl is installed.
|
||||
/// ** Remember to call <see cref="FreeString(LPSTR)" /> on the returned string !!!
|
||||
/// </summary>
|
||||
/// <returns>Returns the path to where Snarl is installed.</returns>
|
||||
/// <remarks>This is a V39 API method.</remarks>
|
||||
static LPCTSTR GetAppPath();
|
||||
|
||||
/// <summary>
|
||||
/// Get the path to where the default Snarl icons are located.
|
||||
/// <para>** Remember to call <see cref="FreeString(LPSTR)" /> on the returned string !!!</para>
|
||||
/// </summary>
|
||||
/// <returns>Returns the path to where the default Snarl icons are located.</returns>
|
||||
/// <remarks>This is a V39 API method.</remarks>
|
||||
static LPCTSTR GetIconsPath();
|
||||
|
||||
/// <summary>Returns a handle to the Snarl Dispatcher window (V37)</summary>
|
||||
/// <returns>Returns handle to Snarl Dispatcher window, or zero if it's not found.</returns>
|
||||
/// <remarks>This is now the preferred way to test if Snarl is actually running.</remarks>
|
||||
static HWND GetSnarlWindow();
|
||||
|
||||
/// <summary>Get Snarl version, if it is running.</summary>
|
||||
/// <returns>Returns a number indicating Snarl version.</returns>
|
||||
static LONG32 GetVersion();
|
||||
|
||||
/// <summary>Check whether Snarl is running</summary>
|
||||
/// <returns>Returns true if Snarl system was found running.</returns>
|
||||
static BOOL IsSnarlRunning();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
/// <summary>Adds an action to an existing (on-screen or in the missed list) notification.</summary>
|
||||
LONG32 AddAction(LONG32 msgToken, LPCSTR label, LPCSTR cmd);
|
||||
LONG32 AddAction(LONG32 msgToken, LPCWSTR label, LPCWSTR cmd);
|
||||
|
||||
/// <summary>Add a notification class to Snarl.</summary>
|
||||
LONG32 AddClass(LPCSTR classId, LPCSTR name, LPCSTR title = NULL, LPCSTR text = NULL, LPCSTR icon = NULL, LPCSTR sound = NULL, LONG32 duration = NULL, LPCSTR callback = NULL, bool enabled = true);
|
||||
LONG32 AddClass(LPCWSTR classId, LPCWSTR name, LPCWSTR title = NULL, LPCWSTR text = NULL, LPCWSTR icon = NULL, LPCWSTR sound = NULL, LONG32 duration = -1, LPCWSTR callback = NULL, bool enabled = true);
|
||||
|
||||
/// <summary>Remove all notification classes in one call.</summary>
|
||||
LONG32 ClearActions(LONG32 msgToken);
|
||||
|
||||
/// <summary>Remove all notification classes in one call.</summary>
|
||||
LONG32 ClearClasses();
|
||||
|
||||
/// <summary>GetLastMsgToken() returns token of the last message sent to Snarl.</summary>
|
||||
/// <returns>Returns message token of last message.</returns>
|
||||
/// <remarks>This function is not in the official API!</remarks>
|
||||
LONG32 GetLastMsgToken() const;
|
||||
|
||||
/// <summary>Hide a Snarl notification.</summary>
|
||||
LONG32 Hide(LONG32 msgToken);
|
||||
|
||||
/// <summary>Test if a Snarl notification is visible. If the message is visible the function returns SnarlEnums::Success.</summary>
|
||||
LONG32 IsVisible(LONG32 msgToken);
|
||||
|
||||
/// <summary>Show a Snarl notification.</summary>
|
||||
/// <returns>Returns the notification token or negative on failure.</returns>
|
||||
/// <remarks>You can use <see cref="GetLastMsgToken()" /> to get the last token.</remarks>
|
||||
LONG32 Notify(LPCSTR classId = NULL, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR iconPath = NULL, LPCSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCSTR uid = NULL, LPCSTR callback = NULL, LPCSTR value = NULL);
|
||||
LONG32 Notify(LPCWSTR classId = NULL, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR iconPath = NULL, LPCWSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCWSTR uid = NULL, LPCWSTR callback = NULL, LPCWSTR value = NULL);
|
||||
|
||||
/// <summary>Register application with Snarl.</summary>
|
||||
/// <returns>The application token or negative on failure.</returns>
|
||||
/// <remarks>The application token is saved in SnarlInterface member variable, so just use return value to check for error.</remarks>
|
||||
LONG32 Register(LPCSTR signature, LPCSTR title, LPCSTR icon = NULL, LPCSTR password = NULL, HWND hWndReplyTo = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppFlagNone);
|
||||
LONG32 Register(LPCWSTR signature, LPCWSTR title, LPCWSTR icon = NULL, LPCWSTR password = NULL, HWND hWndReplyTo = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppFlagNone);
|
||||
|
||||
/// <summary>Remove a notification class added with AddClass().</summary>
|
||||
LONG32 RemoveClass(LPCSTR classId);
|
||||
LONG32 RemoveClass(LPCWSTR classId);
|
||||
|
||||
/// <summary>Update the text or other parameters of a visible Snarl notification.</summary>
|
||||
LONG32 Update(LONG32 msgToken, LPCSTR classId = NULL, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR iconPath = NULL, LPCSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCSTR callback = NULL, LPCSTR value = NULL);
|
||||
LONG32 Update(LONG32 msgToken, LPCWSTR classId = NULL, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR iconPath = NULL, LPCWSTR iconBase64 = NULL, SnarlEnums::MessagePriority priority = SnarlEnums::PriorityUndefined, LPCWSTR callback = NULL, LPCWSTR value = NULL);
|
||||
|
||||
/// <summary>Unregister application with Snarl when application is closing.</summary>
|
||||
LONG32 Unregister(LPCSTR signature);
|
||||
LONG32 Unregister(LPCWSTR signature);
|
||||
|
||||
/// <summary>Update information provided when calling RegisterApp.</summary>
|
||||
/*LONG32 UpdateApp(LPCSTR title = NULL, LPCSTR icon = NULL);
|
||||
LONG32 UpdateApp(LPCWSTR title = NULL, LPCWSTR icon = NULL);*/
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/// <summary>Convert a unicode string to UTF8</summary>
|
||||
/// <returns>Returns pointer to the new string - Remember to delete [] returned string !</returns>
|
||||
/// <remarks>Remember to call FreeString on returned string !!!</remarks>
|
||||
static LPSTR WideToUTF8(LPCWSTR szWideStr);
|
||||
|
||||
static LONG32 DoRequest(LPCSTR request, SnarlParameterList<char>& spl, UINT replyTimeout = 1000);
|
||||
static LONG32 DoRequest(LPCWSTR request, SnarlParameterList<wchar_t>& spl, UINT replyTimeout = 1000);
|
||||
|
||||
void SetPassword(LPCSTR password);
|
||||
void SetPassword(LPCWSTR password);
|
||||
void ClearPassword();
|
||||
|
||||
LONG32 appToken;
|
||||
LONG32 lastMsgToken;
|
||||
LPSTR szPasswordA;
|
||||
LPWSTR szPasswordW;
|
||||
}; // class SnarlInterface
|
||||
|
||||
} // namespace V42
|
||||
} // namespace Snarl
|
||||
|
||||
#endif // SNARL_INTERFACE_V42_H
|
||||
|
||||
|
|
|
@ -1,258 +1,258 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "snarl.h"
|
||||
|
||||
#include "core/snore.h"
|
||||
#include "core/plugins/plugins.h"
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtDebug>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#define SNORENOTIFIER_MESSAGE_ID WM_USER + 238
|
||||
|
||||
using namespace Snore;
|
||||
using namespace Snarl::V42;
|
||||
|
||||
Q_EXPORT_PLUGIN2(snarl,SnarlBackend)
|
||||
|
||||
class SnarlBackend::SnarlWidget:public QWidget
|
||||
{
|
||||
//Q_OBJECT
|
||||
public:
|
||||
SnarlWidget(SnarlBackend * snarl):
|
||||
m_snarl(snarl)
|
||||
{
|
||||
SNARL_GLOBAL_MESSAGE = SnarlInterface::Broadcast();
|
||||
}
|
||||
|
||||
bool winEvent( MSG * msg, long * result ){
|
||||
Q_UNUSED(result);
|
||||
if(msg->message == SNARL_GLOBAL_MESSAGE){
|
||||
int action = msg->wParam;
|
||||
if(action == SnarlEnums::SnarlLaunched){
|
||||
foreach(Application *a,m_snarl->snore()->aplications()){
|
||||
m_snarl->slotRegisterApplication(a);
|
||||
}
|
||||
}
|
||||
|
||||
}else if(msg->message == SNORENOTIFIER_MESSAGE_ID){
|
||||
int action = msg->wParam & 0xffff;
|
||||
int data = (msg->wParam & 0xffffffff) >> 16;
|
||||
|
||||
Notification notification;
|
||||
if(msg->lParam != 0)
|
||||
{
|
||||
uint notificationID = 0;
|
||||
for(QHash<uint,LONG32>::iterator it = m_snarl->m_idMap.begin();it != m_snarl->m_idMap.end();++it)
|
||||
{
|
||||
if(it.value() == msg->lParam)
|
||||
{
|
||||
notificationID = it.key();
|
||||
break;
|
||||
}
|
||||
}
|
||||
notification = m_snarl->snore()->getActiveNotificationByID(notificationID);
|
||||
qDebug()<<"recived a Snarl callback id:"<<notificationID<< "|" << msg->lParam <<"action:"<<action<<"data:"<<data;
|
||||
}
|
||||
|
||||
NotificationEnums::CloseReasons::closeReasons reason = NotificationEnums::CloseReasons::NONE;
|
||||
switch(action){
|
||||
case SnarlEnums::CallbackInvoked:
|
||||
reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
break;
|
||||
case SnarlEnums::NotifyAction:
|
||||
reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
if(notification.isValid())
|
||||
{
|
||||
notification.setActionInvoked(data);
|
||||
m_snarl->snore()->notificationActionInvoked(notification);
|
||||
}
|
||||
break;
|
||||
case SnarlEnums::CallbackClosed:
|
||||
reason = NotificationEnums::CloseReasons::DISMISSED;
|
||||
break;
|
||||
case SnarlEnums::CallbackTimedOut:
|
||||
reason = NotificationEnums::CloseReasons::TIMED_OUT;
|
||||
break;
|
||||
//away stuff
|
||||
case SnarlEnums::SnarlUserAway:
|
||||
qDebug()<<"Snalr user has gone away";
|
||||
return true;
|
||||
case SnarlEnums::SnarlUserBack:
|
||||
qDebug()<<"Snalr user has returned";
|
||||
return true;
|
||||
default:
|
||||
qDebug()<<"Unknown snarl action found!!";
|
||||
return false;
|
||||
}
|
||||
if(notification.isValid())
|
||||
{
|
||||
m_snarl->closeNotification(notification,reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Snarl notification already closed" << msg->lParam << action;
|
||||
qDebug() << m_snarl->m_idMap;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
uint SNARL_GLOBAL_MESSAGE;
|
||||
SnarlBackend* m_snarl;
|
||||
|
||||
};
|
||||
|
||||
|
||||
SnarlBackend::SnarlBackend():
|
||||
SnoreBackend("Snarl",true,false),
|
||||
m_defautSnarlinetrface(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SnarlBackend::~SnarlBackend()
|
||||
{
|
||||
if(snore() != NULL){
|
||||
foreach(Application *a,snore()->aplications()){
|
||||
this->slotUnregisterApplication(a);
|
||||
}
|
||||
}
|
||||
if(m_defautSnarlinetrface)
|
||||
delete m_defautSnarlinetrface;
|
||||
}
|
||||
|
||||
|
||||
bool SnarlBackend::init(SnoreCore *snore){
|
||||
SnarlInterface *snarlInterface = new SnarlInterface();
|
||||
if(!snarlInterface->IsSnarlRunning())
|
||||
{
|
||||
delete snarlInterface;
|
||||
return false;
|
||||
}
|
||||
m_eventLoop = new SnarlBackend::SnarlWidget(this);
|
||||
m_applications.insert("SnoreNotify",snarlInterface);
|
||||
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
|
||||
m_defautSnarlinetrface = new SnarlInterface();
|
||||
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void SnarlBackend::slotRegisterApplication(Application *application){
|
||||
SnarlInterface *snarlInterface = NULL;
|
||||
if(m_applications.contains(application->name())){
|
||||
snarlInterface = m_applications.value(application->name());
|
||||
}else{
|
||||
snarlInterface = new SnarlInterface();
|
||||
m_applications.insert(application->name(),snarlInterface);
|
||||
}
|
||||
qDebug()<<"Register with Snarl"<<application->name();
|
||||
QString appName = application->name();
|
||||
appName = appName.replace(" ","_");//app sig must not contain spaces
|
||||
snarlInterface->Register(appName.toUtf8().constData(),
|
||||
application->name().toUtf8().constData(),
|
||||
application->icon().localUrl().toUtf8().constData(),
|
||||
0,(HWND)m_eventLoop->winId(),SNORENOTIFIER_MESSAGE_ID);
|
||||
|
||||
foreach(Alert *alert,application->alerts()){
|
||||
qDebug()<<"registering snarl alert"<<application->name();
|
||||
snarlInterface->AddClass(alert->name().toUtf8().constData(),
|
||||
alert->name().toUtf8().constData(),
|
||||
0,0,alert->icon().localUrl().toUtf8().constData());
|
||||
}
|
||||
}
|
||||
|
||||
void SnarlBackend::slotUnregisterApplication(Application *application){
|
||||
SnarlInterface *snarlInterface = m_applications.take(application->name());
|
||||
if(snarlInterface == NULL)
|
||||
return;
|
||||
QString appName = application->name();
|
||||
appName = appName.replace(" ","_");//app sig must not contain spaces
|
||||
snarlInterface->Unregister(appName.toUtf8().constData());
|
||||
delete snarlInterface;
|
||||
}
|
||||
|
||||
void SnarlBackend::slotNotify(Notification notification){
|
||||
SnarlInterface *snarlInterface = m_applications.value(notification.application());
|
||||
if(snarlInterface == NULL){
|
||||
qDebug()<<notification.application()<<"not in snarl interfaces, defaulting";
|
||||
qDebug()<<m_applications.keys();
|
||||
snarlInterface = m_defautSnarlinetrface;
|
||||
}
|
||||
|
||||
Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined;
|
||||
switch(notification.priority())
|
||||
{
|
||||
case NotificationEnums::Prioritys::LOW:
|
||||
priority = Snarl::V42::SnarlEnums::PriorityLow;
|
||||
break;
|
||||
case NotificationEnums::Prioritys::NORMAL:
|
||||
priority = Snarl::V42::SnarlEnums::PriorityNormal;
|
||||
break;
|
||||
case NotificationEnums::Prioritys::HIGH:
|
||||
priority = Snarl::V42::SnarlEnums::PriorityHigh;
|
||||
break;
|
||||
}
|
||||
|
||||
if(notification.updateID() == 0){
|
||||
ULONG32 id = snarlInterface->Notify(notification.alert().toUtf8().constData(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||
notification.timeout(),
|
||||
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
||||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
||||
priority);
|
||||
|
||||
foreach(const Notification::Action *a, notification.actions()){
|
||||
snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData());
|
||||
}
|
||||
m_idMap[notification.id()] = id;
|
||||
qDebug() << "snarl" << id << notification.id();
|
||||
startTimeout(notification.id(),notification.timeout());
|
||||
|
||||
}else{
|
||||
//update message
|
||||
snarlInterface->Update(m_idMap[notification.updateID()],
|
||||
notification.alert().toUtf8().constData(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||
notification.timeout(),
|
||||
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
||||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
||||
priority);
|
||||
m_idMap[notification.id()] = m_idMap[notification.updateID()];
|
||||
qDebug() << "snarl update" << m_idMap[notification.updateID()] << notification.id();
|
||||
startTimeout(notification.updateID(),notification.timeout());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SnarlBackend::slotCloseNotification(Notification notification)
|
||||
{
|
||||
m_defautSnarlinetrface->Hide(m_idMap.take(notification.id()));
|
||||
}
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "snarl.h"
|
||||
|
||||
#include "core/snore.h"
|
||||
#include "core/plugins/plugins.h"
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtDebug>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#define SNORENOTIFIER_MESSAGE_ID WM_USER + 238
|
||||
|
||||
using namespace Snore;
|
||||
using namespace Snarl::V42;
|
||||
|
||||
Q_EXPORT_PLUGIN2(snarl,SnarlBackend)
|
||||
|
||||
class SnarlBackend::SnarlWidget:public QWidget
|
||||
{
|
||||
//Q_OBJECT
|
||||
public:
|
||||
SnarlWidget(SnarlBackend * snarl):
|
||||
m_snarl(snarl)
|
||||
{
|
||||
SNARL_GLOBAL_MESSAGE = SnarlInterface::Broadcast();
|
||||
}
|
||||
|
||||
bool winEvent( MSG * msg, long * result ){
|
||||
Q_UNUSED(result);
|
||||
if(msg->message == SNARL_GLOBAL_MESSAGE){
|
||||
int action = msg->wParam;
|
||||
if(action == SnarlEnums::SnarlLaunched){
|
||||
foreach(Application *a,m_snarl->snore()->aplications()){
|
||||
m_snarl->slotRegisterApplication(a);
|
||||
}
|
||||
}
|
||||
|
||||
}else if(msg->message == SNORENOTIFIER_MESSAGE_ID){
|
||||
int action = msg->wParam & 0xffff;
|
||||
int data = (msg->wParam & 0xffffffff) >> 16;
|
||||
|
||||
Notification notification;
|
||||
if(msg->lParam != 0)
|
||||
{
|
||||
uint notificationID = 0;
|
||||
for(QHash<uint,LONG32>::iterator it = m_snarl->m_idMap.begin();it != m_snarl->m_idMap.end();++it)
|
||||
{
|
||||
if(it.value() == msg->lParam)
|
||||
{
|
||||
notificationID = it.key();
|
||||
break;
|
||||
}
|
||||
}
|
||||
notification = m_snarl->snore()->getActiveNotificationByID(notificationID);
|
||||
qDebug()<<"recived a Snarl callback id:"<<notificationID<< "|" << msg->lParam <<"action:"<<action<<"data:"<<data;
|
||||
}
|
||||
|
||||
NotificationEnums::CloseReasons::closeReasons reason = NotificationEnums::CloseReasons::NONE;
|
||||
switch(action){
|
||||
case SnarlEnums::CallbackInvoked:
|
||||
reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
break;
|
||||
case SnarlEnums::NotifyAction:
|
||||
reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
if(notification.isValid())
|
||||
{
|
||||
notification.setActionInvoked(data);
|
||||
m_snarl->snore()->notificationActionInvoked(notification);
|
||||
}
|
||||
break;
|
||||
case SnarlEnums::CallbackClosed:
|
||||
reason = NotificationEnums::CloseReasons::DISMISSED;
|
||||
break;
|
||||
case SnarlEnums::CallbackTimedOut:
|
||||
reason = NotificationEnums::CloseReasons::TIMED_OUT;
|
||||
break;
|
||||
//away stuff
|
||||
case SnarlEnums::SnarlUserAway:
|
||||
qDebug()<<"Snalr user has gone away";
|
||||
return true;
|
||||
case SnarlEnums::SnarlUserBack:
|
||||
qDebug()<<"Snalr user has returned";
|
||||
return true;
|
||||
default:
|
||||
qDebug()<<"Unknown snarl action found!!";
|
||||
return false;
|
||||
}
|
||||
if(notification.isValid())
|
||||
{
|
||||
m_snarl->closeNotification(notification,reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Snarl notification already closed" << msg->lParam << action;
|
||||
qDebug() << m_snarl->m_idMap;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
uint SNARL_GLOBAL_MESSAGE;
|
||||
SnarlBackend* m_snarl;
|
||||
|
||||
};
|
||||
|
||||
|
||||
SnarlBackend::SnarlBackend():
|
||||
SnoreBackend("Snarl",true,false),
|
||||
m_defautSnarlinetrface(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SnarlBackend::~SnarlBackend()
|
||||
{
|
||||
if(snore() != NULL){
|
||||
foreach(Application *a,snore()->aplications()){
|
||||
this->slotUnregisterApplication(a);
|
||||
}
|
||||
}
|
||||
if(m_defautSnarlinetrface)
|
||||
delete m_defautSnarlinetrface;
|
||||
}
|
||||
|
||||
|
||||
bool SnarlBackend::init(SnoreCore *snore){
|
||||
SnarlInterface *snarlInterface = new SnarlInterface();
|
||||
if(!snarlInterface->IsSnarlRunning())
|
||||
{
|
||||
delete snarlInterface;
|
||||
return false;
|
||||
}
|
||||
m_eventLoop = new SnarlBackend::SnarlWidget(this);
|
||||
m_applications.insert("SnoreNotify",snarlInterface);
|
||||
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
|
||||
m_defautSnarlinetrface = new SnarlInterface();
|
||||
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void SnarlBackend::slotRegisterApplication(Application *application){
|
||||
SnarlInterface *snarlInterface = NULL;
|
||||
if(m_applications.contains(application->name())){
|
||||
snarlInterface = m_applications.value(application->name());
|
||||
}else{
|
||||
snarlInterface = new SnarlInterface();
|
||||
m_applications.insert(application->name(),snarlInterface);
|
||||
}
|
||||
qDebug()<<"Register with Snarl"<<application->name();
|
||||
QString appName = application->name();
|
||||
appName = appName.replace(" ","_");//app sig must not contain spaces
|
||||
snarlInterface->Register(appName.toUtf8().constData(),
|
||||
application->name().toUtf8().constData(),
|
||||
application->icon().localUrl().toUtf8().constData(),
|
||||
0,(HWND)m_eventLoop->winId(),SNORENOTIFIER_MESSAGE_ID);
|
||||
|
||||
foreach(Alert *alert,application->alerts()){
|
||||
qDebug()<<"registering snarl alert"<<application->name();
|
||||
snarlInterface->AddClass(alert->name().toUtf8().constData(),
|
||||
alert->name().toUtf8().constData(),
|
||||
0,0,alert->icon().localUrl().toUtf8().constData());
|
||||
}
|
||||
}
|
||||
|
||||
void SnarlBackend::slotUnregisterApplication(Application *application){
|
||||
SnarlInterface *snarlInterface = m_applications.take(application->name());
|
||||
if(snarlInterface == NULL)
|
||||
return;
|
||||
QString appName = application->name();
|
||||
appName = appName.replace(" ","_");//app sig must not contain spaces
|
||||
snarlInterface->Unregister(appName.toUtf8().constData());
|
||||
delete snarlInterface;
|
||||
}
|
||||
|
||||
void SnarlBackend::slotNotify(Notification notification){
|
||||
SnarlInterface *snarlInterface = m_applications.value(notification.application());
|
||||
if(snarlInterface == NULL){
|
||||
qDebug()<<notification.application()<<"not in snarl interfaces, defaulting";
|
||||
qDebug()<<m_applications.keys();
|
||||
snarlInterface = m_defautSnarlinetrface;
|
||||
}
|
||||
|
||||
Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined;
|
||||
switch(notification.priority())
|
||||
{
|
||||
case NotificationEnums::Prioritys::LOW:
|
||||
priority = Snarl::V42::SnarlEnums::PriorityLow;
|
||||
break;
|
||||
case NotificationEnums::Prioritys::NORMAL:
|
||||
priority = Snarl::V42::SnarlEnums::PriorityNormal;
|
||||
break;
|
||||
case NotificationEnums::Prioritys::HIGH:
|
||||
priority = Snarl::V42::SnarlEnums::PriorityHigh;
|
||||
break;
|
||||
}
|
||||
|
||||
if(notification.updateID() == 0){
|
||||
ULONG32 id = snarlInterface->Notify(notification.alert().toUtf8().constData(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||
notification.timeout(),
|
||||
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
||||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
||||
priority);
|
||||
|
||||
foreach(const Notification::Action *a, notification.actions()){
|
||||
snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData());
|
||||
}
|
||||
m_idMap[notification.id()] = id;
|
||||
qDebug() << "snarl" << id << notification.id();
|
||||
startTimeout(notification.id(),notification.timeout());
|
||||
|
||||
}else{
|
||||
//update message
|
||||
snarlInterface->Update(m_idMap[notification.updateID()],
|
||||
notification.alert().toUtf8().constData(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||
notification.timeout(),
|
||||
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
||||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
||||
priority);
|
||||
m_idMap[notification.id()] = m_idMap[notification.updateID()];
|
||||
qDebug() << "snarl update" << m_idMap[notification.updateID()] << notification.id();
|
||||
startTimeout(notification.updateID(),notification.timeout());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SnarlBackend::slotCloseNotification(Notification notification)
|
||||
{
|
||||
m_defautSnarlinetrface->Hide(m_idMap.take(notification.id()));
|
||||
}
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNARL_BACKEND_H
|
||||
#define SNARL_BACKEND_H
|
||||
#include "core/plugins/snorebackend.h"
|
||||
#include "SnarlInterface.h"
|
||||
|
||||
|
||||
|
||||
class SnarlBackend:public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
SnarlBackend();
|
||||
~SnarlBackend();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
private:
|
||||
class SnarlWidget;
|
||||
SnarlBackend::SnarlWidget* m_eventLoop;
|
||||
QHash<QString,Snarl::V42::SnarlInterface*> m_applications;
|
||||
Snarl::V42::SnarlInterface* m_defautSnarlinetrface;
|
||||
|
||||
public slots:
|
||||
void slotRegisterApplication(Snore::Application *application);
|
||||
void slotUnregisterApplication(Snore::Application *application);
|
||||
void slotNotify(Snore::Notification notification);
|
||||
void slotCloseNotification(Snore::Notification notification);
|
||||
|
||||
private:
|
||||
QHash<uint,LONG32> m_idMap;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // SNARL_BACKEND_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNARL_BACKEND_H
|
||||
#define SNARL_BACKEND_H
|
||||
#include "core/plugins/snorebackend.h"
|
||||
#include "SnarlInterface.h"
|
||||
|
||||
|
||||
|
||||
class SnarlBackend:public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
SnarlBackend();
|
||||
~SnarlBackend();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
private:
|
||||
class SnarlWidget;
|
||||
SnarlBackend::SnarlWidget* m_eventLoop;
|
||||
QHash<QString,Snarl::V42::SnarlInterface*> m_applications;
|
||||
Snarl::V42::SnarlInterface* m_defautSnarlinetrface;
|
||||
|
||||
public slots:
|
||||
void slotRegisterApplication(Snore::Application *application);
|
||||
void slotUnregisterApplication(Snore::Application *application);
|
||||
void slotNotify(Snore::Notification notification);
|
||||
void slotCloseNotification(Snore::Notification notification);
|
||||
|
||||
private:
|
||||
QHash<uint,LONG32> m_idMap;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // SNARL_BACKEND_H
|
||||
|
|
|
@ -1,132 +1,132 @@
|
|||
#include "snoretoast.h"
|
||||
#include "core/snore.h"
|
||||
#include "core/plugins/plugins.h"
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QSysInfo>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(snoretoast,SnoreToast)
|
||||
|
||||
|
||||
SnoreToast::SnoreToast():
|
||||
SnoreBackend("Windows 8",false,false)
|
||||
{
|
||||
}
|
||||
|
||||
SnoreToast::~SnoreToast()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool SnoreToast::init(SnoreCore *snore)
|
||||
{
|
||||
if(QSysInfo::windowsVersion() != QSysInfo::WV_WINDOWS8)
|
||||
{
|
||||
qDebug() << "SnoreToast does not work on windows" << QSysInfo::windowsVersion();
|
||||
return false;
|
||||
}
|
||||
if(snore->hints().contains("WINDOWS_APP_ID"))
|
||||
{
|
||||
m_appID = snore->hints().value("WINDOWS_APP_ID").toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_appID = QString("%1.%2.SnoreToast").arg(qApp->organizationName(), qApp->applicationName()).remove(" ");
|
||||
|
||||
QProcess *p = new QProcess(this);
|
||||
p->setReadChannelMode(QProcess::MergedChannels);
|
||||
|
||||
QStringList arguements;
|
||||
arguements << "-install"
|
||||
<< QString("SnoreNotify\\%1").arg(qApp->applicationName())
|
||||
<< QDir::toNativeSeparators(qApp->applicationFilePath())
|
||||
<< m_appID;
|
||||
qDebug() << "SnoreToast" << arguements;
|
||||
p->start("SnoreToast", arguements);
|
||||
p->waitForFinished(-1);
|
||||
qDebug() << p->readAll();
|
||||
if(p->exitCode() != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void SnoreToast::slotRegisterApplication(Application *application)
|
||||
{
|
||||
Q_UNUSED(application)
|
||||
}
|
||||
|
||||
void SnoreToast::slotUnregisterApplication(Application *application)
|
||||
{
|
||||
Q_UNUSED(application)
|
||||
}
|
||||
|
||||
void SnoreToast::slotNotify(Notification notification)
|
||||
{
|
||||
QProcess *p = new QProcess(this);
|
||||
p->setReadChannelMode(QProcess::MergedChannels);
|
||||
|
||||
connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus)));
|
||||
connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill()));
|
||||
|
||||
QStringList arguements;
|
||||
arguements << "-t"
|
||||
<< Snore::toPlainText(notification.title())
|
||||
<< "-m"
|
||||
<< Snore::toPlainText(notification.text())
|
||||
<< "-p"
|
||||
// << notification.icon().isLocalFile()?QDir::toNativeSeparators(notification.icon().localUrl()):notification.icon().url()
|
||||
<< QDir::toNativeSeparators(notification.icon().localUrl())
|
||||
<< "-w"
|
||||
<< "-appID"
|
||||
<< m_appID;
|
||||
;
|
||||
if(notification.hints().value("silent",true).toBool())
|
||||
{
|
||||
arguements << "-silent";
|
||||
}
|
||||
qDebug() << "SnoreToast" << arguements;
|
||||
p->start("SnoreToast", arguements);
|
||||
|
||||
p->setProperty("SNORE_NOTIFICATION_ID",notification.id());
|
||||
}
|
||||
|
||||
void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
|
||||
{
|
||||
QProcess *p = qobject_cast<QProcess*>(sender());
|
||||
Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt());
|
||||
|
||||
NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
|
||||
switch(code)
|
||||
{
|
||||
case 0:
|
||||
reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
snore()->notificationActionInvoked(n);
|
||||
break;
|
||||
case 1:
|
||||
//hidden;
|
||||
break;
|
||||
case 2:
|
||||
reason = NotificationEnums::CloseReasons::DISMISSED;
|
||||
break;
|
||||
case 3:
|
||||
reason = NotificationEnums::CloseReasons::TIMED_OUT;
|
||||
break;
|
||||
case -1:
|
||||
//failed
|
||||
qWarning() << "SnoreToast failed to display " << n << p->readAll();
|
||||
break;
|
||||
}
|
||||
|
||||
closeNotification(n,reason);
|
||||
|
||||
}
|
||||
#include "snoretoast.h"
|
||||
#include "core/snore.h"
|
||||
#include "core/plugins/plugins.h"
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QSysInfo>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(snoretoast,SnoreToast)
|
||||
|
||||
|
||||
SnoreToast::SnoreToast():
|
||||
SnoreBackend("Windows 8",false,false)
|
||||
{
|
||||
}
|
||||
|
||||
SnoreToast::~SnoreToast()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool SnoreToast::init(SnoreCore *snore)
|
||||
{
|
||||
if(QSysInfo::windowsVersion() != QSysInfo::WV_WINDOWS8)
|
||||
{
|
||||
qDebug() << "SnoreToast does not work on windows" << QSysInfo::windowsVersion();
|
||||
return false;
|
||||
}
|
||||
if(snore->hints().contains("WINDOWS_APP_ID"))
|
||||
{
|
||||
m_appID = snore->hints().value("WINDOWS_APP_ID").toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_appID = QString("%1.%2.SnoreToast").arg(qApp->organizationName(), qApp->applicationName()).remove(" ");
|
||||
|
||||
QProcess *p = new QProcess(this);
|
||||
p->setReadChannelMode(QProcess::MergedChannels);
|
||||
|
||||
QStringList arguements;
|
||||
arguements << "-install"
|
||||
<< QString("SnoreNotify\\%1").arg(qApp->applicationName())
|
||||
<< QDir::toNativeSeparators(qApp->applicationFilePath())
|
||||
<< m_appID;
|
||||
qDebug() << "SnoreToast" << arguements;
|
||||
p->start("SnoreToast", arguements);
|
||||
p->waitForFinished(-1);
|
||||
qDebug() << p->readAll();
|
||||
if(p->exitCode() != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void SnoreToast::slotRegisterApplication(Application *application)
|
||||
{
|
||||
Q_UNUSED(application)
|
||||
}
|
||||
|
||||
void SnoreToast::slotUnregisterApplication(Application *application)
|
||||
{
|
||||
Q_UNUSED(application)
|
||||
}
|
||||
|
||||
void SnoreToast::slotNotify(Notification notification)
|
||||
{
|
||||
QProcess *p = new QProcess(this);
|
||||
p->setReadChannelMode(QProcess::MergedChannels);
|
||||
|
||||
connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus)));
|
||||
connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill()));
|
||||
|
||||
QStringList arguements;
|
||||
arguements << "-t"
|
||||
<< Snore::toPlainText(notification.title())
|
||||
<< "-m"
|
||||
<< Snore::toPlainText(notification.text())
|
||||
<< "-p"
|
||||
// << notification.icon().isLocalFile()?QDir::toNativeSeparators(notification.icon().localUrl()):notification.icon().url()
|
||||
<< QDir::toNativeSeparators(notification.icon().localUrl())
|
||||
<< "-w"
|
||||
<< "-appID"
|
||||
<< m_appID;
|
||||
;
|
||||
if(notification.hints().value("silent",true).toBool())
|
||||
{
|
||||
arguements << "-silent";
|
||||
}
|
||||
qDebug() << "SnoreToast" << arguements;
|
||||
p->start("SnoreToast", arguements);
|
||||
|
||||
p->setProperty("SNORE_NOTIFICATION_ID",notification.id());
|
||||
}
|
||||
|
||||
void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
|
||||
{
|
||||
QProcess *p = qobject_cast<QProcess*>(sender());
|
||||
Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt());
|
||||
|
||||
NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
|
||||
switch(code)
|
||||
{
|
||||
case 0:
|
||||
reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
snore()->notificationActionInvoked(n);
|
||||
break;
|
||||
case 1:
|
||||
//hidden;
|
||||
break;
|
||||
case 2:
|
||||
reason = NotificationEnums::CloseReasons::DISMISSED;
|
||||
break;
|
||||
case 3:
|
||||
reason = NotificationEnums::CloseReasons::TIMED_OUT;
|
||||
break;
|
||||
case -1:
|
||||
//failed
|
||||
qWarning() << "SnoreToast failed to display " << n << p->readAll();
|
||||
break;
|
||||
}
|
||||
|
||||
closeNotification(n,reason);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
#ifndef TOASTER_H
|
||||
#define TOASTER_H
|
||||
|
||||
#include "core/plugins/snorebackend.h"
|
||||
#include <QProcess>
|
||||
|
||||
class SnoreToast : public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
SnoreToast();
|
||||
~SnoreToast();
|
||||
bool init(Snore::SnoreCore *snore);
|
||||
|
||||
|
||||
// SnoreBackend interface
|
||||
public slots:
|
||||
void slotRegisterApplication(Snore::Application *application);
|
||||
void slotUnregisterApplication(Snore::Application *application);
|
||||
void slotNotify(Snore::Notification notification);
|
||||
|
||||
private slots:
|
||||
void slotToastNotificationClosed(int code, QProcess::ExitStatus);
|
||||
|
||||
private:
|
||||
QString m_appID;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // TOASTER_H
|
||||
#ifndef TOASTER_H
|
||||
#define TOASTER_H
|
||||
|
||||
#include "core/plugins/snorebackend.h"
|
||||
#include <QProcess>
|
||||
|
||||
class SnoreToast : public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
SnoreToast();
|
||||
~SnoreToast();
|
||||
bool init(Snore::SnoreCore *snore);
|
||||
|
||||
|
||||
// SnoreBackend interface
|
||||
public slots:
|
||||
void slotRegisterApplication(Snore::Application *application);
|
||||
void slotUnregisterApplication(Snore::Application *application);
|
||||
void slotNotify(Snore::Notification notification);
|
||||
|
||||
private slots:
|
||||
void slotToastNotificationClosed(int code, QProcess::ExitStatus);
|
||||
|
||||
private:
|
||||
QString m_appID;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // TOASTER_H
|
||||
|
|
|
@ -1,78 +1,78 @@
|
|||
#include "trayiconnotifer.h"
|
||||
#include "core/snore.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(trayicon,TrayIconNotifer)
|
||||
|
||||
TrayIconNotifer::TrayIconNotifer () :
|
||||
SnoreBackend ( "SystemTray",false,false ),
|
||||
m_trayIcon(NULL),
|
||||
m_displayed(-1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool TrayIconNotifer::init(SnoreCore *snore){
|
||||
m_trayIcon = snore->trayIcon();
|
||||
if(m_trayIcon == NULL)
|
||||
return false;
|
||||
connect(m_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked()));
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
|
||||
void TrayIconNotifer::slotRegisterApplication ( Application *application )
|
||||
{
|
||||
Q_UNUSED ( application )
|
||||
}
|
||||
void TrayIconNotifer::slotUnregisterApplication ( Application *application )
|
||||
{
|
||||
Q_UNUSED ( application )
|
||||
}
|
||||
|
||||
void TrayIconNotifer::slotNotify( Notification notification )
|
||||
{
|
||||
m_notificationQue.append(notification);
|
||||
if(m_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
|
||||
displayNotification();
|
||||
}
|
||||
}
|
||||
|
||||
void TrayIconNotifer::displayNotification(){
|
||||
qDebug()<<"Display"<<m_notificationQue.size();
|
||||
Notification notification = m_notificationQue.takeFirst();
|
||||
if(!m_notificationQue.isEmpty()){
|
||||
QTimer::singleShot(notification.timeout()*1000,this,SLOT(slotCloseNotificationByTimeout()));
|
||||
}
|
||||
|
||||
qDebug()<<"taking"<<notification.title();
|
||||
m_displayed = notification.id();
|
||||
m_trayIcon->showMessage ( Snore::toPlainText(notification.title()),Snore::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 );
|
||||
m_lastNotify.restart();
|
||||
}
|
||||
|
||||
void TrayIconNotifer::slotCloseNotificationByTimeout(){
|
||||
Notification n = snore()->getActiveNotificationByID(m_displayed);
|
||||
if(n.isValid()){
|
||||
closeNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
|
||||
}
|
||||
displayNotification();
|
||||
}
|
||||
|
||||
void TrayIconNotifer::actionInvoked(){
|
||||
qDebug()<<"Traicon invoked"<<m_displayed;
|
||||
|
||||
Notification n = snore()->getActiveNotificationByID(m_displayed);
|
||||
if(n.isValid()){
|
||||
snore()->notificationActionInvoked(n);
|
||||
closeNotification(n,NotificationEnums::CloseReasons::CLOSED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "trayiconnotifer.h"
|
||||
#include "core/snore.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(trayicon,TrayIconNotifer)
|
||||
|
||||
TrayIconNotifer::TrayIconNotifer () :
|
||||
SnoreBackend ( "SystemTray",false,false ),
|
||||
m_trayIcon(NULL),
|
||||
m_displayed(-1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool TrayIconNotifer::init(SnoreCore *snore){
|
||||
m_trayIcon = snore->trayIcon();
|
||||
if(m_trayIcon == NULL)
|
||||
return false;
|
||||
connect(m_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked()));
|
||||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
|
||||
void TrayIconNotifer::slotRegisterApplication ( Application *application )
|
||||
{
|
||||
Q_UNUSED ( application )
|
||||
}
|
||||
void TrayIconNotifer::slotUnregisterApplication ( Application *application )
|
||||
{
|
||||
Q_UNUSED ( application )
|
||||
}
|
||||
|
||||
void TrayIconNotifer::slotNotify( Notification notification )
|
||||
{
|
||||
m_notificationQue.append(notification);
|
||||
if(m_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
|
||||
displayNotification();
|
||||
}
|
||||
}
|
||||
|
||||
void TrayIconNotifer::displayNotification(){
|
||||
qDebug()<<"Display"<<m_notificationQue.size();
|
||||
Notification notification = m_notificationQue.takeFirst();
|
||||
if(!m_notificationQue.isEmpty()){
|
||||
QTimer::singleShot(notification.timeout()*1000,this,SLOT(slotCloseNotificationByTimeout()));
|
||||
}
|
||||
|
||||
qDebug()<<"taking"<<notification.title();
|
||||
m_displayed = notification.id();
|
||||
m_trayIcon->showMessage ( Snore::toPlainText(notification.title()),Snore::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 );
|
||||
m_lastNotify.restart();
|
||||
}
|
||||
|
||||
void TrayIconNotifer::slotCloseNotificationByTimeout(){
|
||||
Notification n = snore()->getActiveNotificationByID(m_displayed);
|
||||
if(n.isValid()){
|
||||
closeNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
|
||||
}
|
||||
displayNotification();
|
||||
}
|
||||
|
||||
void TrayIconNotifer::actionInvoked(){
|
||||
qDebug()<<"Traicon invoked"<<m_displayed;
|
||||
|
||||
Notification n = snore()->getActiveNotificationByID(m_displayed);
|
||||
if(n.isValid()){
|
||||
snore()->notificationActionInvoked(n);
|
||||
closeNotification(n,NotificationEnums::CloseReasons::CLOSED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
#ifndef TRAYICONNOTIFER_H
|
||||
#define TRAYICONNOTIFER_H
|
||||
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include <QTime>
|
||||
|
||||
namespace Snore{
|
||||
class SnoreCore;
|
||||
}
|
||||
|
||||
class QSystemTrayIcon;
|
||||
|
||||
class TrayIconNotifer:public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
TrayIconNotifer ();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
public slots:
|
||||
void slotRegisterApplication ( Snore::Application *application );
|
||||
void slotUnregisterApplication ( Snore::Application *application );
|
||||
void slotNotify ( Snore::Notification notification );
|
||||
|
||||
private:
|
||||
QSystemTrayIcon *m_trayIcon;
|
||||
QList<Snore::Notification > m_notificationQue;
|
||||
QTime m_lastNotify;
|
||||
uint m_displayed;
|
||||
|
||||
private slots:
|
||||
void displayNotification();
|
||||
void actionInvoked();
|
||||
void slotCloseNotificationByTimeout();
|
||||
};
|
||||
|
||||
#endif // TRAYICONNOTIFER_H
|
||||
#ifndef TRAYICONNOTIFER_H
|
||||
#define TRAYICONNOTIFER_H
|
||||
|
||||
#include "core/plugins/snorebackend.h"
|
||||
|
||||
#include <QTime>
|
||||
|
||||
namespace Snore{
|
||||
class SnoreCore;
|
||||
}
|
||||
|
||||
class QSystemTrayIcon;
|
||||
|
||||
class TrayIconNotifer:public Snore::SnoreBackend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreBackend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
|
||||
public:
|
||||
TrayIconNotifer ();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
public slots:
|
||||
void slotRegisterApplication ( Snore::Application *application );
|
||||
void slotUnregisterApplication ( Snore::Application *application );
|
||||
void slotNotify ( Snore::Notification notification );
|
||||
|
||||
private:
|
||||
QSystemTrayIcon *m_trayIcon;
|
||||
QList<Snore::Notification > m_notificationQue;
|
||||
QTime m_lastNotify;
|
||||
uint m_displayed;
|
||||
|
||||
private slots:
|
||||
void displayNotification();
|
||||
void actionInvoked();
|
||||
void slotCloseNotificationByTimeout();
|
||||
};
|
||||
|
||||
#endif // TRAYICONNOTIFER_H
|
||||
|
|
|
@ -1,145 +1,145 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "freedesktopnotificationfrontend.h"
|
||||
#include "notificationsadaptor.h"
|
||||
|
||||
#include "plugins/backends/freedesktop/fredesktopnotification.h"
|
||||
#include "core/snore.h"
|
||||
#include "core/version.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtDBus>
|
||||
#include <QImage>
|
||||
|
||||
#ifdef HAVE_KDE
|
||||
#include <KIconLoader>
|
||||
#endif
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(freedesktop,FreedesktopFrontend)
|
||||
|
||||
FreedesktopFrontend::FreedesktopFrontend():
|
||||
SnoreFrontend("Freedesktop")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FreedesktopFrontend::~FreedesktopFrontend(){
|
||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.unregisterService( "org.freedesktop.Notifications" );
|
||||
}
|
||||
|
||||
bool FreedesktopFrontend::init(SnoreCore *snore){
|
||||
new NotificationsAdaptor(this);
|
||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.registerService( "org.freedesktop.Notifications" );
|
||||
dbus.registerObject( "/org/freedesktop/Notifications", this );
|
||||
return SnoreFrontend::init(snore);
|
||||
}
|
||||
|
||||
void FreedesktopFrontend::actionInvoked(Notification notification) {
|
||||
if(notification.actionInvoked())
|
||||
{
|
||||
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id));
|
||||
}
|
||||
}
|
||||
|
||||
void FreedesktopFrontend::notificationClosed(Notification notification) {
|
||||
|
||||
qDebug()<<"Closing Dbus notification"<<notification<<"reason:"<<(int)notification.closeReason();
|
||||
emit NotificationClosed(notification.id(),notification.closeReason());
|
||||
}
|
||||
|
||||
uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
|
||||
const QString &app_icon, const QString &summary, const QString &body,
|
||||
const QStringList &actions, const QVariantMap &hints, int timeout)
|
||||
{
|
||||
Icon icon;
|
||||
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
|
||||
|
||||
if(hints.contains("image_data")){
|
||||
FreedesktopImageHint image;
|
||||
hints["image_data"].value<QDBusArgument>()>>image;
|
||||
icon = Icon(image.toQImage());
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = Icon(":/root/images/freedesktop-dbus.png");
|
||||
}
|
||||
|
||||
if(!snore()->aplications().contains(app_name)){
|
||||
#ifdef HAVE_KDE
|
||||
Icon appIcon(KIconLoader::global()->iconPath(app_icon, KIconLoader::Desktop));
|
||||
#else
|
||||
Icon appIcon(":/root/images/freedesktop-dbus.png");
|
||||
#endif
|
||||
Application *a = new Application(app_name,appIcon);
|
||||
a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon));
|
||||
snore()->addApplication(a);
|
||||
snore()->applicationIsInitialized(a);
|
||||
}
|
||||
|
||||
if (hints.contains("urgency")) {
|
||||
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
|
||||
}
|
||||
|
||||
Notification noti(app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,priotity);
|
||||
if(replaces_id != 0)
|
||||
{
|
||||
noti.setUpdateID(replaces_id);
|
||||
}
|
||||
noti.setSource(this);
|
||||
for(int i = 0;i < actions.length(); i+=2){
|
||||
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
|
||||
}
|
||||
|
||||
snore()->broadcastNotification(noti);
|
||||
startTimeout(noti.id(),noti.timeout());
|
||||
return noti.id();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FreedesktopFrontend::CloseNotification(uint id){
|
||||
Notification noti = snore()->getActiveNotificationByID(id);
|
||||
if(noti.isValid())
|
||||
{
|
||||
snore()->requestCloseNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList FreedesktopFrontend::GetCapabilities()
|
||||
{
|
||||
return QStringList()
|
||||
<< "body"
|
||||
<< "urgency"
|
||||
// << "body-hyperlinks"
|
||||
<< "body-markup"
|
||||
<< "icon-static"
|
||||
<< "actions";
|
||||
}
|
||||
|
||||
QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion)
|
||||
{
|
||||
vendor = "Snore";
|
||||
version = Version::version();
|
||||
specVersion = "0";
|
||||
return "Snore";
|
||||
}
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "freedesktopnotificationfrontend.h"
|
||||
#include "notificationsadaptor.h"
|
||||
|
||||
#include "plugins/backends/freedesktop/fredesktopnotification.h"
|
||||
#include "core/snore.h"
|
||||
#include "core/version.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtDBus>
|
||||
#include <QImage>
|
||||
|
||||
#ifdef HAVE_KDE
|
||||
#include <KIconLoader>
|
||||
#endif
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(freedesktop,FreedesktopFrontend)
|
||||
|
||||
FreedesktopFrontend::FreedesktopFrontend():
|
||||
SnoreFrontend("Freedesktop")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FreedesktopFrontend::~FreedesktopFrontend(){
|
||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.unregisterService( "org.freedesktop.Notifications" );
|
||||
}
|
||||
|
||||
bool FreedesktopFrontend::init(SnoreCore *snore){
|
||||
new NotificationsAdaptor(this);
|
||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.registerService( "org.freedesktop.Notifications" );
|
||||
dbus.registerObject( "/org/freedesktop/Notifications", this );
|
||||
return SnoreFrontend::init(snore);
|
||||
}
|
||||
|
||||
void FreedesktopFrontend::actionInvoked(Notification notification) {
|
||||
if(notification.actionInvoked())
|
||||
{
|
||||
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id));
|
||||
}
|
||||
}
|
||||
|
||||
void FreedesktopFrontend::notificationClosed(Notification notification) {
|
||||
|
||||
qDebug()<<"Closing Dbus notification"<<notification<<"reason:"<<(int)notification.closeReason();
|
||||
emit NotificationClosed(notification.id(),notification.closeReason());
|
||||
}
|
||||
|
||||
uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
|
||||
const QString &app_icon, const QString &summary, const QString &body,
|
||||
const QStringList &actions, const QVariantMap &hints, int timeout)
|
||||
{
|
||||
Icon icon;
|
||||
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
|
||||
|
||||
if(hints.contains("image_data")){
|
||||
FreedesktopImageHint image;
|
||||
hints["image_data"].value<QDBusArgument>()>>image;
|
||||
icon = Icon(image.toQImage());
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = Icon(":/root/images/freedesktop-dbus.png");
|
||||
}
|
||||
|
||||
if(!snore()->aplications().contains(app_name)){
|
||||
#ifdef HAVE_KDE
|
||||
Icon appIcon(KIconLoader::global()->iconPath(app_icon, KIconLoader::Desktop));
|
||||
#else
|
||||
Icon appIcon(":/root/images/freedesktop-dbus.png");
|
||||
#endif
|
||||
Application *a = new Application(app_name,appIcon);
|
||||
a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon));
|
||||
snore()->addApplication(a);
|
||||
snore()->applicationIsInitialized(a);
|
||||
}
|
||||
|
||||
if (hints.contains("urgency")) {
|
||||
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
|
||||
}
|
||||
|
||||
Notification noti(app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,priotity);
|
||||
if(replaces_id != 0)
|
||||
{
|
||||
noti.setUpdateID(replaces_id);
|
||||
}
|
||||
noti.setSource(this);
|
||||
for(int i = 0;i < actions.length(); i+=2){
|
||||
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
|
||||
}
|
||||
|
||||
snore()->broadcastNotification(noti);
|
||||
startTimeout(noti.id(),noti.timeout());
|
||||
return noti.id();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FreedesktopFrontend::CloseNotification(uint id){
|
||||
Notification noti = snore()->getActiveNotificationByID(id);
|
||||
if(noti.isValid())
|
||||
{
|
||||
snore()->requestCloseNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList FreedesktopFrontend::GetCapabilities()
|
||||
{
|
||||
return QStringList()
|
||||
<< "body"
|
||||
<< "urgency"
|
||||
// << "body-hyperlinks"
|
||||
<< "body-markup"
|
||||
<< "icon-static"
|
||||
<< "actions";
|
||||
}
|
||||
|
||||
QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion)
|
||||
{
|
||||
vendor = "Snore";
|
||||
version = Version::version();
|
||||
specVersion = "0";
|
||||
return "Snore";
|
||||
}
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 FREEDESKTOPNOTIFICATION_FRONTEND_H
|
||||
#define FREEDESKTOPNOTIFICATION_FRONTEND_H
|
||||
#include "core/plugins/snorefrontend.h"
|
||||
#include <QtDBus>
|
||||
|
||||
class FreedesktopFrontend:public Snore::SnoreFrontend{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreFrontend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0")
|
||||
public:
|
||||
FreedesktopFrontend();
|
||||
~FreedesktopFrontend();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
void actionInvoked(Snore::Notification notification);
|
||||
void notificationClosed(Snore::Notification notification);
|
||||
uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout);
|
||||
void CloseNotification( uint id );
|
||||
|
||||
QStringList GetCapabilities();
|
||||
QString GetServerInformation(QString& vendor, QString& version, QString& specVersion);
|
||||
|
||||
signals:
|
||||
void NotificationClosed( uint id, uint reason );
|
||||
void ActionInvoked( uint id, const QString& actionKey );
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif//FREEDESKTOPNOTIFICATION_FRONTEND_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 FREEDESKTOPNOTIFICATION_FRONTEND_H
|
||||
#define FREEDESKTOPNOTIFICATION_FRONTEND_H
|
||||
#include "core/plugins/snorefrontend.h"
|
||||
#include <QtDBus>
|
||||
|
||||
class FreedesktopFrontend:public Snore::SnoreFrontend{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreFrontend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0")
|
||||
public:
|
||||
FreedesktopFrontend();
|
||||
~FreedesktopFrontend();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
|
||||
void actionInvoked(Snore::Notification notification);
|
||||
void notificationClosed(Snore::Notification notification);
|
||||
uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout);
|
||||
void CloseNotification( uint id );
|
||||
|
||||
QStringList GetCapabilities();
|
||||
QString GetServerInformation(QString& vendor, QString& version, QString& specVersion);
|
||||
|
||||
signals:
|
||||
void NotificationClosed( uint id, uint reason );
|
||||
void ActionInvoked( uint id, const QString& actionKey );
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif//FREEDESKTOPNOTIFICATION_FRONTEND_H
|
||||
|
|
|
@ -1,205 +1,205 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "parser.h"
|
||||
#include "snarlnetwork.h"
|
||||
|
||||
#include "core/snore.h"
|
||||
#include "core/notification/notification.h"
|
||||
|
||||
|
||||
|
||||
#include <QDir>
|
||||
#include <QCryptographicHash>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkReply>
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Parser::Parser(SnarlNetworkFrontend *snarl):
|
||||
QObject(snarl),
|
||||
snarl(snarl)
|
||||
{
|
||||
getSnpType.insert("type",TYPE);
|
||||
getSnpType.insert("app",APP);
|
||||
getSnpType.insert("version",VERSION);
|
||||
getSnpType.insert("action",ACTION);
|
||||
getSnpType.insert("register",REGISTER);
|
||||
getSnpType.insert("add_class",ADD_CLASS);
|
||||
getSnpType.insert("notification",NOTIFICATION);
|
||||
getSnpType.insert("unregister",UNREGISTER);
|
||||
getSnpType.insert("class",CLASS);
|
||||
getSnpType.insert("title",TITLE);
|
||||
getSnpType.insert("text",TEXT);
|
||||
getSnpType.insert("icon",ICON);
|
||||
getSnpType.insert("timeout",TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
||||
SnarlNotification sNotification;
|
||||
sNotification.httpClient=false;
|
||||
sNotification.vailid=true;
|
||||
sNotification.clientSocket=client;
|
||||
sNotification.isNotification = false;
|
||||
|
||||
|
||||
snpTypes action(ERROR);
|
||||
if(msg.startsWith("GET ")){
|
||||
msg=msg.mid(msg.indexOf("/")+1);
|
||||
msg=msg.mid(0,msg.indexOf(" "));
|
||||
QByteArray dat(QByteArray::fromBase64(msg.toLatin1().data()));
|
||||
msg=QString(dat);
|
||||
qDebug()<<"Notification from a browser"<<msg;
|
||||
sNotification.httpClient=true;
|
||||
}
|
||||
|
||||
QString app;
|
||||
QString title;
|
||||
QString text;
|
||||
QString sntpIcon;
|
||||
QString icon;
|
||||
QString alert;
|
||||
int timeout=10;
|
||||
|
||||
QString key;
|
||||
QString value;
|
||||
QStringList splitted=msg.split("#?");
|
||||
foreach(QString s,splitted){
|
||||
key=s.mid(0,s.indexOf("=")).toLower();
|
||||
value=s.mid(s.indexOf("=")+1);
|
||||
switch(getSnpType.value(key)){
|
||||
case APP:
|
||||
app=value;
|
||||
break;
|
||||
case ACTION:
|
||||
action=getSnpType.value(value);
|
||||
sNotification.action=value;
|
||||
break;
|
||||
case TITLE:
|
||||
title=value;
|
||||
break;
|
||||
case TEXT:
|
||||
text=value;
|
||||
break;
|
||||
case ICON:
|
||||
sntpIcon=value;
|
||||
icon=downloadIcon(value);
|
||||
break;
|
||||
case CLASS:
|
||||
alert=value;
|
||||
case TIMEOUT:
|
||||
timeout=value.toInt();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sNotification.notification = Notification(app,alert,title,text,icon,timeout);
|
||||
sNotification.notification.setSource(snarl);
|
||||
|
||||
sNotification.notification.hints().setValue("SnarlIcon", sntpIcon);
|
||||
|
||||
|
||||
switch(action){
|
||||
case NOTIFICATION:{
|
||||
qDebug() << sNotification.notification.application();
|
||||
Application * appl = snarl->snore()->aplications().value(sNotification.notification.application());
|
||||
if(!snarl->snore()->aplications().contains(appl->name())){
|
||||
snarl->snore()->registerApplication(appl);
|
||||
}
|
||||
|
||||
if(!appl->alerts().value(sNotification.notification.alert())->isActive())
|
||||
break;
|
||||
sNotification.isNotification = true;
|
||||
return sNotification;
|
||||
break;
|
||||
}
|
||||
case ADD_CLASS:
|
||||
if(sNotification.notification.alert().isEmpty()){
|
||||
qDebug()<<"Error registering alert with empty name";
|
||||
break;
|
||||
}
|
||||
if(title.isEmpty())
|
||||
{
|
||||
title = alert;
|
||||
}
|
||||
snarl->m_applications.value(sNotification.notification.application())->addAlert(new Alert(alert,title));
|
||||
break;
|
||||
case REGISTER:
|
||||
if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){
|
||||
snarl->m_applications.insert(sNotification.notification.application(), new Application(sNotification.notification.application()));
|
||||
}
|
||||
else
|
||||
qDebug()<<sNotification.notification.application()<<"already registred";
|
||||
break;
|
||||
case UNREGISTER:
|
||||
snarl->snore()->deregisterApplication( snarl->snore()->aplications().value(sNotification.notification.application()) );
|
||||
break;
|
||||
case ERROR:
|
||||
default:
|
||||
sNotification.vailid=false;
|
||||
break;
|
||||
}
|
||||
sNotification.notification.hints().setValue("SnarlAction", sNotification.action);
|
||||
return sNotification;
|
||||
}
|
||||
|
||||
QString Parser::downloadIcon(const QString &address){
|
||||
if(address=="")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if(address.startsWith("file://"))
|
||||
{
|
||||
return QString(address.mid(7));
|
||||
}
|
||||
QByteArray arr=address.toUtf8();
|
||||
QUrl url = QUrl::fromEncoded(arr);
|
||||
|
||||
QCryptographicHash hash(QCryptographicHash::Md5);
|
||||
hash.addData(arr);
|
||||
QString filename=QDir::temp().path()+"/SnoreNotify/"+hash.result().toHex()+address.mid(address.lastIndexOf(".")-1);
|
||||
QFile file(filename);
|
||||
if(file.exists())
|
||||
return filename;
|
||||
|
||||
QByteArray reply=download(url);
|
||||
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(reply);
|
||||
|
||||
return filename;
|
||||
|
||||
}
|
||||
|
||||
QByteArray Parser::download(const QUrl &address){
|
||||
QNetworkAccessManager manager;
|
||||
QEventLoop loop;
|
||||
QNetworkRequest request(address);
|
||||
request.setRawHeader("User-Agent", "SnoreNotify");
|
||||
QNetworkReply *reply=manager.get(request);
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
return reply->readAll();
|
||||
}
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "parser.h"
|
||||
#include "snarlnetwork.h"
|
||||
|
||||
#include "core/snore.h"
|
||||
#include "core/notification/notification.h"
|
||||
|
||||
|
||||
|
||||
#include <QDir>
|
||||
#include <QCryptographicHash>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkReply>
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Parser::Parser(SnarlNetworkFrontend *snarl):
|
||||
QObject(snarl),
|
||||
snarl(snarl)
|
||||
{
|
||||
getSnpType.insert("type",TYPE);
|
||||
getSnpType.insert("app",APP);
|
||||
getSnpType.insert("version",VERSION);
|
||||
getSnpType.insert("action",ACTION);
|
||||
getSnpType.insert("register",REGISTER);
|
||||
getSnpType.insert("add_class",ADD_CLASS);
|
||||
getSnpType.insert("notification",NOTIFICATION);
|
||||
getSnpType.insert("unregister",UNREGISTER);
|
||||
getSnpType.insert("class",CLASS);
|
||||
getSnpType.insert("title",TITLE);
|
||||
getSnpType.insert("text",TEXT);
|
||||
getSnpType.insert("icon",ICON);
|
||||
getSnpType.insert("timeout",TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
||||
SnarlNotification sNotification;
|
||||
sNotification.httpClient=false;
|
||||
sNotification.vailid=true;
|
||||
sNotification.clientSocket=client;
|
||||
sNotification.isNotification = false;
|
||||
|
||||
|
||||
snpTypes action(ERROR);
|
||||
if(msg.startsWith("GET ")){
|
||||
msg=msg.mid(msg.indexOf("/")+1);
|
||||
msg=msg.mid(0,msg.indexOf(" "));
|
||||
QByteArray dat(QByteArray::fromBase64(msg.toLatin1().data()));
|
||||
msg=QString(dat);
|
||||
qDebug()<<"Notification from a browser"<<msg;
|
||||
sNotification.httpClient=true;
|
||||
}
|
||||
|
||||
QString app;
|
||||
QString title;
|
||||
QString text;
|
||||
QString sntpIcon;
|
||||
QString icon;
|
||||
QString alert;
|
||||
int timeout=10;
|
||||
|
||||
QString key;
|
||||
QString value;
|
||||
QStringList splitted=msg.split("#?");
|
||||
foreach(QString s,splitted){
|
||||
key=s.mid(0,s.indexOf("=")).toLower();
|
||||
value=s.mid(s.indexOf("=")+1);
|
||||
switch(getSnpType.value(key)){
|
||||
case APP:
|
||||
app=value;
|
||||
break;
|
||||
case ACTION:
|
||||
action=getSnpType.value(value);
|
||||
sNotification.action=value;
|
||||
break;
|
||||
case TITLE:
|
||||
title=value;
|
||||
break;
|
||||
case TEXT:
|
||||
text=value;
|
||||
break;
|
||||
case ICON:
|
||||
sntpIcon=value;
|
||||
icon=downloadIcon(value);
|
||||
break;
|
||||
case CLASS:
|
||||
alert=value;
|
||||
case TIMEOUT:
|
||||
timeout=value.toInt();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sNotification.notification = Notification(app,alert,title,text,icon,timeout);
|
||||
sNotification.notification.setSource(snarl);
|
||||
|
||||
sNotification.notification.hints().setValue("SnarlIcon", sntpIcon);
|
||||
|
||||
|
||||
switch(action){
|
||||
case NOTIFICATION:{
|
||||
qDebug() << sNotification.notification.application();
|
||||
Application * appl = snarl->snore()->aplications().value(sNotification.notification.application());
|
||||
if(!snarl->snore()->aplications().contains(appl->name())){
|
||||
snarl->snore()->registerApplication(appl);
|
||||
}
|
||||
|
||||
if(!appl->alerts().value(sNotification.notification.alert())->isActive())
|
||||
break;
|
||||
sNotification.isNotification = true;
|
||||
return sNotification;
|
||||
break;
|
||||
}
|
||||
case ADD_CLASS:
|
||||
if(sNotification.notification.alert().isEmpty()){
|
||||
qDebug()<<"Error registering alert with empty name";
|
||||
break;
|
||||
}
|
||||
if(title.isEmpty())
|
||||
{
|
||||
title = alert;
|
||||
}
|
||||
snarl->m_applications.value(sNotification.notification.application())->addAlert(new Alert(alert,title));
|
||||
break;
|
||||
case REGISTER:
|
||||
if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){
|
||||
snarl->m_applications.insert(sNotification.notification.application(), new Application(sNotification.notification.application()));
|
||||
}
|
||||
else
|
||||
qDebug()<<sNotification.notification.application()<<"already registred";
|
||||
break;
|
||||
case UNREGISTER:
|
||||
snarl->snore()->deregisterApplication( snarl->snore()->aplications().value(sNotification.notification.application()) );
|
||||
break;
|
||||
case ERROR:
|
||||
default:
|
||||
sNotification.vailid=false;
|
||||
break;
|
||||
}
|
||||
sNotification.notification.hints().setValue("SnarlAction", sNotification.action);
|
||||
return sNotification;
|
||||
}
|
||||
|
||||
QString Parser::downloadIcon(const QString &address){
|
||||
if(address=="")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if(address.startsWith("file://"))
|
||||
{
|
||||
return QString(address.mid(7));
|
||||
}
|
||||
QByteArray arr=address.toUtf8();
|
||||
QUrl url = QUrl::fromEncoded(arr);
|
||||
|
||||
QCryptographicHash hash(QCryptographicHash::Md5);
|
||||
hash.addData(arr);
|
||||
QString filename=QDir::temp().path()+"/SnoreNotify/"+hash.result().toHex()+address.mid(address.lastIndexOf(".")-1);
|
||||
QFile file(filename);
|
||||
if(file.exists())
|
||||
return filename;
|
||||
|
||||
QByteArray reply=download(url);
|
||||
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(reply);
|
||||
|
||||
return filename;
|
||||
|
||||
}
|
||||
|
||||
QByteArray Parser::download(const QUrl &address){
|
||||
QNetworkAccessManager manager;
|
||||
QEventLoop loop;
|
||||
QNetworkRequest request(address);
|
||||
request.setRawHeader("User-Agent", "SnoreNotify");
|
||||
QNetworkReply *reply=manager.get(request);
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
return reply->readAll();
|
||||
}
|
||||
|
|
|
@ -1,121 +1,121 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "snarlnetwork.h"
|
||||
#include "core/snore.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QTcpServer>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include <iostream>
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(snalnetwork,SnarlNetworkFrontend)
|
||||
|
||||
|
||||
SnarlNetworkFrontend::SnarlNetworkFrontend():
|
||||
SnoreFrontend("SnarlNetwork")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SnarlNetworkFrontend::~SnarlNetworkFrontend(){
|
||||
}
|
||||
|
||||
bool SnarlNetworkFrontend::init(SnoreCore *snore){
|
||||
parser=new Parser(this);
|
||||
tcpServer=new QTcpServer(this);
|
||||
if(!tcpServer->listen(QHostAddress::Any,port)){
|
||||
qDebug()<<"The port is already used";
|
||||
return false;
|
||||
}else{
|
||||
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
|
||||
std::cout<<"The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>"<<std::endl;
|
||||
}
|
||||
return SnoreFrontend::init(snore);
|
||||
}
|
||||
|
||||
|
||||
void SnarlNetworkFrontend::actionInvoked(Notification notification){
|
||||
//TODO:fix callback
|
||||
SnarlNotification sn=notifications.value(notification.id());
|
||||
if(notification.actionInvoked()->id == 1 )
|
||||
callback(sn,"SNP/1.1/304/Notification acknowledged/");
|
||||
else if(notification.actionInvoked()->id == 2)
|
||||
callback(sn,"SNP/1.1/302/Notification cancelled/");
|
||||
}
|
||||
void SnarlNetworkFrontend::notificationClosed(Notification notification){
|
||||
SnarlNotification sn=notifications.value(notification.id());
|
||||
if(notification.closeReason() == NotificationEnums::CloseReasons::TIMED_OUT)
|
||||
callback(sn,"SNP/1.1/303/Notification timed out/");
|
||||
else
|
||||
callback(sn,"SNP/1.1/307/Notification closed/");
|
||||
}
|
||||
|
||||
void SnarlNetworkFrontend::handleConnection(){
|
||||
QTcpSocket *client = tcpServer->nextPendingConnection();
|
||||
connect(client,SIGNAL(readyRead()),this,SLOT(handleMessages()));
|
||||
connect(client,SIGNAL(disconnected()), client, SLOT(deleteLater()));
|
||||
}
|
||||
|
||||
void SnarlNetworkFrontend::handleMessages(){
|
||||
QString out("SNP/1.1/0/OK");
|
||||
QTcpSocket *client=qobject_cast<QTcpSocket*>(sender());
|
||||
QStringList incommings(QString::fromUtf8(client->readAll()).split("\r\n"));
|
||||
foreach(const QString &msg,incommings){
|
||||
QString s=msg.trimmed();
|
||||
if(s == "")
|
||||
continue;
|
||||
SnarlNotification noti=parser->parse(s,client);
|
||||
if(!noti.vailid)
|
||||
continue;
|
||||
if(noti.isNotification){
|
||||
snore()->broadcastNotification(noti.notification);
|
||||
if(noti.notification.id()!=0){
|
||||
out+="/"+QString::number(noti.notification.id());
|
||||
notifications.insert(noti.notification.id(),noti);
|
||||
}
|
||||
}
|
||||
out+="\r\n";
|
||||
|
||||
client->write(out.toUtf8());
|
||||
if(noti.httpClient){
|
||||
client->disconnectFromHost();
|
||||
client->waitForDisconnected();
|
||||
}
|
||||
qDebug()<<out;
|
||||
}
|
||||
}
|
||||
|
||||
void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){
|
||||
notifications.remove(sn.notification.id());
|
||||
if(sn.clientSocket!=NULL&&!msg.isEmpty()){
|
||||
msg+=QString::number(sn.notification.id());
|
||||
qDebug()<<msg;
|
||||
sn.clientSocket->write(msg.toAscii()+"\r\n");
|
||||
sn.clientSocket->flush();
|
||||
|
||||
if(sn.httpClient){
|
||||
sn.clientSocket->waitForBytesWritten(-1);
|
||||
sn.clientSocket->disconnectFromHost();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "snarlnetwork.h"
|
||||
#include "core/snore.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QTcpServer>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include <iostream>
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(snalnetwork,SnarlNetworkFrontend)
|
||||
|
||||
|
||||
SnarlNetworkFrontend::SnarlNetworkFrontend():
|
||||
SnoreFrontend("SnarlNetwork")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SnarlNetworkFrontend::~SnarlNetworkFrontend(){
|
||||
}
|
||||
|
||||
bool SnarlNetworkFrontend::init(SnoreCore *snore){
|
||||
parser=new Parser(this);
|
||||
tcpServer=new QTcpServer(this);
|
||||
if(!tcpServer->listen(QHostAddress::Any,port)){
|
||||
qDebug()<<"The port is already used";
|
||||
return false;
|
||||
}else{
|
||||
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
|
||||
std::cout<<"The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>"<<std::endl;
|
||||
}
|
||||
return SnoreFrontend::init(snore);
|
||||
}
|
||||
|
||||
|
||||
void SnarlNetworkFrontend::actionInvoked(Notification notification){
|
||||
//TODO:fix callback
|
||||
SnarlNotification sn=notifications.value(notification.id());
|
||||
if(notification.actionInvoked()->id == 1 )
|
||||
callback(sn,"SNP/1.1/304/Notification acknowledged/");
|
||||
else if(notification.actionInvoked()->id == 2)
|
||||
callback(sn,"SNP/1.1/302/Notification cancelled/");
|
||||
}
|
||||
void SnarlNetworkFrontend::notificationClosed(Notification notification){
|
||||
SnarlNotification sn=notifications.value(notification.id());
|
||||
if(notification.closeReason() == NotificationEnums::CloseReasons::TIMED_OUT)
|
||||
callback(sn,"SNP/1.1/303/Notification timed out/");
|
||||
else
|
||||
callback(sn,"SNP/1.1/307/Notification closed/");
|
||||
}
|
||||
|
||||
void SnarlNetworkFrontend::handleConnection(){
|
||||
QTcpSocket *client = tcpServer->nextPendingConnection();
|
||||
connect(client,SIGNAL(readyRead()),this,SLOT(handleMessages()));
|
||||
connect(client,SIGNAL(disconnected()), client, SLOT(deleteLater()));
|
||||
}
|
||||
|
||||
void SnarlNetworkFrontend::handleMessages(){
|
||||
QString out("SNP/1.1/0/OK");
|
||||
QTcpSocket *client=qobject_cast<QTcpSocket*>(sender());
|
||||
QStringList incommings(QString::fromUtf8(client->readAll()).split("\r\n"));
|
||||
foreach(const QString &msg,incommings){
|
||||
QString s=msg.trimmed();
|
||||
if(s == "")
|
||||
continue;
|
||||
SnarlNotification noti=parser->parse(s,client);
|
||||
if(!noti.vailid)
|
||||
continue;
|
||||
if(noti.isNotification){
|
||||
snore()->broadcastNotification(noti.notification);
|
||||
if(noti.notification.id()!=0){
|
||||
out+="/"+QString::number(noti.notification.id());
|
||||
notifications.insert(noti.notification.id(),noti);
|
||||
}
|
||||
}
|
||||
out+="\r\n";
|
||||
|
||||
client->write(out.toUtf8());
|
||||
if(noti.httpClient){
|
||||
client->disconnectFromHost();
|
||||
client->waitForDisconnected();
|
||||
}
|
||||
qDebug()<<out;
|
||||
}
|
||||
}
|
||||
|
||||
void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){
|
||||
notifications.remove(sn.notification.id());
|
||||
if(sn.clientSocket!=NULL&&!msg.isEmpty()){
|
||||
msg+=QString::number(sn.notification.id());
|
||||
qDebug()<<msg;
|
||||
sn.clientSocket->write(msg.toAscii()+"\r\n");
|
||||
sn.clientSocket->flush();
|
||||
|
||||
if(sn.httpClient){
|
||||
sn.clientSocket->waitForBytesWritten(-1);
|
||||
sn.clientSocket->disconnectFromHost();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,70 +1,70 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNARLNETWORK_H
|
||||
#define SNARLNETWORK_H
|
||||
#include "core/plugins/snorefrontend.h"
|
||||
#include "parser.h"
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
namespace Snore{
|
||||
class Notification;
|
||||
class SnoreCore;
|
||||
}
|
||||
|
||||
struct SnarlNotification{
|
||||
Snore::Notification notification;
|
||||
QString action;
|
||||
bool httpClient;
|
||||
bool vailid;
|
||||
bool isNotification;
|
||||
QPointer<class QTcpSocket> clientSocket;
|
||||
};
|
||||
|
||||
class SnarlNetworkFrontend:public Snore::SnoreFrontend{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreFrontend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0")
|
||||
friend class Parser;
|
||||
public:
|
||||
static const int port=9887;
|
||||
|
||||
public:
|
||||
SnarlNetworkFrontend();
|
||||
~SnarlNetworkFrontend();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
void actionInvoked(Snore::Notification notification);
|
||||
void notificationClosed(Snore::Notification notification);
|
||||
|
||||
private slots:
|
||||
void handleConnection();
|
||||
void handleMessages();
|
||||
|
||||
private:
|
||||
class QTcpServer *tcpServer;
|
||||
Parser *parser;
|
||||
QHash<uint,SnarlNotification> notifications;
|
||||
QHash<QString,Snore::Application*> m_applications;
|
||||
|
||||
void callback(const SnarlNotification &sn,QString msg);
|
||||
|
||||
};
|
||||
|
||||
#endif //SNARLNETWORK_H
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 SNARLNETWORK_H
|
||||
#define SNARLNETWORK_H
|
||||
#include "core/plugins/snorefrontend.h"
|
||||
#include "parser.h"
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
namespace Snore{
|
||||
class Notification;
|
||||
class SnoreCore;
|
||||
}
|
||||
|
||||
struct SnarlNotification{
|
||||
Snore::Notification notification;
|
||||
QString action;
|
||||
bool httpClient;
|
||||
bool vailid;
|
||||
bool isNotification;
|
||||
QPointer<class QTcpSocket> clientSocket;
|
||||
};
|
||||
|
||||
class SnarlNetworkFrontend:public Snore::SnoreFrontend{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::SnoreFrontend)
|
||||
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0")
|
||||
friend class Parser;
|
||||
public:
|
||||
static const int port=9887;
|
||||
|
||||
public:
|
||||
SnarlNetworkFrontend();
|
||||
~SnarlNetworkFrontend();
|
||||
virtual bool init(Snore::SnoreCore *snore);
|
||||
void actionInvoked(Snore::Notification notification);
|
||||
void notificationClosed(Snore::Notification notification);
|
||||
|
||||
private slots:
|
||||
void handleConnection();
|
||||
void handleMessages();
|
||||
|
||||
private:
|
||||
class QTcpServer *tcpServer;
|
||||
Parser *parser;
|
||||
QHash<uint,SnarlNotification> notifications;
|
||||
QHash<QString,Snore::Application*> m_applications;
|
||||
|
||||
void callback(const SnarlNotification &sn,QString msg);
|
||||
|
||||
};
|
||||
|
||||
#endif //SNARLNETWORK_H
|
||||
|
|
|
@ -1,79 +1,79 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "snorenotify.h"
|
||||
#include "trayicon.h"
|
||||
#include "core/snore.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QList>
|
||||
#include <QDebug>
|
||||
#include <QPluginLoader>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QSettings>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
SnoreNotify::SnoreNotify():
|
||||
m_settings("TheOneRing","SnoreNotify")
|
||||
{
|
||||
qApp->setApplicationName("SnoreNotify");
|
||||
qApp->setOrganizationName("TheOneRing");
|
||||
m_trayIcon = new TrayIcon();
|
||||
m_snore = new SnoreCore(m_trayIcon->trayIcon());
|
||||
m_snore->loadPlugins(PluginContainer::ALL);
|
||||
load();
|
||||
m_trayIcon->initConextMenu(m_snore);
|
||||
|
||||
connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(exit()));
|
||||
qDebug() << "Snorenotfiy initialized with" << m_snore->primaryNotificationBackend();
|
||||
}
|
||||
|
||||
SnoreNotify::~SnoreNotify(){
|
||||
delete m_snore;
|
||||
delete m_trayIcon;
|
||||
}
|
||||
|
||||
void SnoreNotify::load(){
|
||||
if(m_settings.contains("notificationBackend"))
|
||||
{
|
||||
m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend").toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_snore->setPrimaryNotificationBackend();
|
||||
}
|
||||
}
|
||||
void SnoreNotify::save(){
|
||||
m_settings.setValue("notificationBackend",m_snore->primaryNotificationBackend());
|
||||
}
|
||||
|
||||
void SnoreNotify::exit(){
|
||||
qDebug()<<"Saving snore settings";
|
||||
foreach(Application *a,m_snore->aplications()){
|
||||
m_snore->removeApplication(a->name());
|
||||
}
|
||||
save();
|
||||
m_trayIcon->hide();
|
||||
}
|
||||
|
||||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2013 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 "snorenotify.h"
|
||||
#include "trayicon.h"
|
||||
#include "core/snore.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QList>
|
||||
#include <QDebug>
|
||||
#include <QPluginLoader>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QSettings>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
SnoreNotify::SnoreNotify():
|
||||
m_settings("TheOneRing","SnoreNotify")
|
||||
{
|
||||
qApp->setApplicationName("SnoreNotify");
|
||||
qApp->setOrganizationName("TheOneRing");
|
||||
m_trayIcon = new TrayIcon();
|
||||
m_snore = new SnoreCore(m_trayIcon->trayIcon());
|
||||
m_snore->loadPlugins(PluginContainer::ALL);
|
||||
load();
|
||||
m_trayIcon->initConextMenu(m_snore);
|
||||
|
||||
connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(exit()));
|
||||
qDebug() << "Snorenotfiy initialized with" << m_snore->primaryNotificationBackend();
|
||||
}
|
||||
|
||||
SnoreNotify::~SnoreNotify(){
|
||||
delete m_snore;
|
||||
delete m_trayIcon;
|
||||
}
|
||||
|
||||
void SnoreNotify::load(){
|
||||
if(m_settings.contains("notificationBackend"))
|
||||
{
|
||||
m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend").toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_snore->setPrimaryNotificationBackend();
|
||||
}
|
||||
}
|
||||
void SnoreNotify::save(){
|
||||
m_settings.setValue("notificationBackend",m_snore->primaryNotificationBackend());
|
||||
}
|
||||
|
||||
void SnoreNotify::exit(){
|
||||
qDebug()<<"Saving snore settings";
|
||||
foreach(Application *a,m_snore->aplications()){
|
||||
m_snore->removeApplication(a->name());
|
||||
}
|
||||
save();
|
||||
m_trayIcon->hide();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue