Port from own logger to QLoggingCategory
This commit is contained in:
parent
9a8752ad09
commit
b5fcc90724
|
@ -15,7 +15,6 @@ public:
|
|||
DisplayTest():
|
||||
app(QStringLiteral("Test"), Icon::defaultIcon())
|
||||
{
|
||||
SnoreLog::setDebugLvl(3);
|
||||
SnoreCore &instance = SnoreCore::instance();
|
||||
instance.loadPlugins(SnorePlugin::BACKEND);
|
||||
instance.setSettingsValue(QStringLiteral("Timeout"), 5, LOCAL_SETTING);
|
||||
|
|
|
@ -14,7 +14,6 @@ class SnoreBenchmark : public QObject
|
|||
public:
|
||||
SnoreBenchmark()
|
||||
{
|
||||
SnoreLog::setDebugLvl(3);
|
||||
SnoreCore &instance = SnoreCore::instance();
|
||||
instance.loadPlugins(SnorePlugin::BACKEND);
|
||||
instance.setSettingsValue(QStringLiteral("Timeout"), 1, LOCAL_SETTING);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "snorenotify.h"
|
||||
#include "libsnore/log.h"
|
||||
#include "libsnore/version.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
|
|
@ -31,7 +31,7 @@ SnoreNotify::SnoreNotify()
|
|||
SnoreCore::instance().loadPlugins(SnorePlugin::ALL);
|
||||
m_trayIcon->initConextMenu();
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << "Snorenotfiy initialized with" << SnoreCore::instance().primaryNotificationBackend();
|
||||
qCDebug(SNORE) << "Snorenotfiy initialized with" << SnoreCore::instance().primaryNotificationBackend();
|
||||
}
|
||||
|
||||
SnoreNotify::~SnoreNotify()
|
||||
|
|
|
@ -58,7 +58,7 @@ void TrayIcon::initConextMenu()
|
|||
m_settings->setVisible(false);
|
||||
break;
|
||||
default:
|
||||
snoreDebug(SNORE_WARNING) << "unhandled role" << button->text() << box->buttonRole(button);
|
||||
qCWarning(SNORE) << "unhandled role" << button->text() << box->buttonRole(button);
|
||||
}
|
||||
});
|
||||
m_settings->layout()->addWidget(box);
|
||||
|
|
|
@ -29,7 +29,6 @@ list(APPEND SnoreNotify_SRCS
|
|||
alert_p.cpp
|
||||
hint.cpp
|
||||
lambdahint.cpp
|
||||
log.cpp
|
||||
settingsdialog.cpp
|
||||
utils.cpp
|
||||
${UI}
|
||||
|
@ -44,7 +43,6 @@ list(APPEND SnoreNotify_HDR
|
|||
alert.h
|
||||
hint.h
|
||||
lambdahint.h
|
||||
log.h
|
||||
settingsdialog.h
|
||||
snoreglobals.h
|
||||
utils.h
|
||||
|
|
|
@ -102,7 +102,7 @@ QDebug operator<< (QDebug debug, const Snore::Application &app)
|
|||
{
|
||||
if (app.isValid()) {
|
||||
debug << "Snore::Application(" << app.name() << ", ";
|
||||
foreach(const Alert & a, app.alerts()) {
|
||||
foreach (const Alert &a, app.alerts()) {
|
||||
debug << a << ", ";
|
||||
}
|
||||
debug << ")" ;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
#include "hint.h"
|
||||
#include "lambdahint.h"
|
||||
#include "log.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014-2015 Hannah 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 "log.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTime>
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
class LogData
|
||||
{
|
||||
public:
|
||||
int debugLevel = 0;
|
||||
QTextStream *logFile = nullptr;
|
||||
QFile *file = nullptr;
|
||||
|
||||
LogData()
|
||||
{
|
||||
debugLevel = qgetenv("LIBSNORE_DEBUG_LVL").toInt();
|
||||
if (qgetenv("LIBSNORE_LOG_TO_FILE").toInt() == 1) {
|
||||
|
||||
QString name = QDir::tempPath() + QStringLiteral("/libsnore/") +
|
||||
(qApp->applicationName().isEmpty() ? QString::number(qApp->applicationPid()) : qApp->applicationName()) +
|
||||
QLatin1String("-log.txt");
|
||||
if (!qEnvironmentVariableIsSet("LIBSNORE_LOGFILE")) {
|
||||
name = QString::fromUtf8(qgetenv("LIBSNORE_LOGFILE"));
|
||||
} else {
|
||||
QDir::temp().mkpath(QStringLiteral("libsnore"));
|
||||
}
|
||||
std::cout << "Started logging to " << name.toLocal8Bit().constData() << std::endl;
|
||||
|
||||
file = new QFile(name);
|
||||
if (!file->open(QFile::WriteOnly)) {
|
||||
qFatal("Failed to open log file %s", qPrintable(name));
|
||||
}
|
||||
logFile = new QTextStream(file);
|
||||
}
|
||||
}
|
||||
|
||||
~LogData()
|
||||
{
|
||||
delete logFile;
|
||||
delete file;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(LogData, s_data)
|
||||
|
||||
SnoreLog::SnoreLog(SnoreDebugLevels lvl):
|
||||
QDebug(&m_msg),
|
||||
m_lvl(lvl)
|
||||
{
|
||||
}
|
||||
|
||||
SnoreLog::~SnoreLog()
|
||||
{
|
||||
QByteArray message = QTime::currentTime().toString(QStringLiteral("hh:mm:ss: ")).toUtf8().constData();
|
||||
message.append(m_msg.toUtf8().constData());
|
||||
if (s_data->logFile) {
|
||||
*s_data->logFile << message.constData() << "\n";
|
||||
s_data->logFile->flush();
|
||||
}
|
||||
if (m_lvl == SNORE_WARNING) {
|
||||
std::wcerr << message.constData() << std::endl;
|
||||
} else if (s_data->debugLevel >= m_lvl) {
|
||||
std::wcout << message.constData() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreLog::setDebugLvl(int i)
|
||||
{
|
||||
s_data->debugLevel = i;
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014-2015 Hannah 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 SNORELOG_H
|
||||
#define SNORELOG_H
|
||||
|
||||
#include <QDebug>
|
||||
#include "snore_exports.h"
|
||||
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
/**
|
||||
* SnoreDebugLevels enumerates all possible debugg levels.
|
||||
*/
|
||||
enum SnoreDebugLevels {
|
||||
/**
|
||||
* The most important messages, will be diplayed if the debug level >= 1
|
||||
*/
|
||||
SNORE_WARNING = 0,
|
||||
|
||||
/**
|
||||
* Information messages, will be diplayed if the debug level >= 2
|
||||
*/
|
||||
SNORE_INFO = 1,
|
||||
|
||||
/**
|
||||
* Debug messages will be diplayed if the debug level >= 3
|
||||
*/
|
||||
SNORE_DEBUG = 2
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Logg macro use to logg messages.
|
||||
* snoreDebug( SNORE_DEBUG ) << "Message" << notification;
|
||||
*/
|
||||
|
||||
#if !defined(QT_NO_DEBUG_OUTPUT)
|
||||
#define snoreDebug(X) Snore::SnoreLog( X ) << #X << Q_FUNC_INFO
|
||||
#else
|
||||
#define snoreDebug(X) QNoDebug()
|
||||
#endif
|
||||
|
||||
namespace Snore
|
||||
{
|
||||
|
||||
/**
|
||||
* SnoreLog is a helper class to provide a logging system to Snore.
|
||||
* @author Hannah von Reth \<vonreth at kde.org\>
|
||||
*/
|
||||
class SNORE_EXPORT SnoreLog : public QDebug
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a debugg message whith a priority lvl.
|
||||
* Use the snoreDebug(lvl) macro for logging.<br>
|
||||
* snoreDebug( SNORE_DEBUG ) << "Message" << notification;
|
||||
* @param lvl
|
||||
*/
|
||||
SnoreLog(SnoreDebugLevels lvl);
|
||||
~SnoreLog();
|
||||
|
||||
/**
|
||||
* Sets the debug threshold
|
||||
* @param lvl the debug level
|
||||
*/
|
||||
static void setDebugLvl(int lvl);
|
||||
|
||||
private:
|
||||
SnoreDebugLevels m_lvl;
|
||||
QString m_msg;
|
||||
};
|
||||
}
|
||||
#endif // SNORELOG_H
|
|
@ -40,14 +40,14 @@ Icon Icon::defaultIcon()
|
|||
Icon Icon::fromWebUrl(const QUrl &url, int maxTime)
|
||||
{
|
||||
Icon icon = defaultIcon();
|
||||
snoreDebug(SNORE_DEBUG) << url;
|
||||
qCDebug(SNORE) << url;
|
||||
if (!s_downloadImageCache.contains(url)) {
|
||||
snoreDebug(SNORE_DEBUG) << "Downloading:" << url;
|
||||
qCDebug(SNORE) << "Downloading:" << url;
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply *reply = manager->get(request);
|
||||
QObject::connect(reply, &QNetworkReply::downloadProgress, [&](qint64 bytesReceived, qint64 bytesTotal) {
|
||||
snoreDebug(SNORE_DEBUG) << "Downloading:" << url << bytesReceived / double(bytesTotal) * 100.0 << "%";
|
||||
qCDebug(SNORE) << "Downloading:" << url << bytesReceived / double(bytesTotal) * 100.0 << "%";
|
||||
});
|
||||
|
||||
QTime time;
|
||||
|
@ -56,16 +56,16 @@ Icon Icon::fromWebUrl(const QUrl &url, int maxTime)
|
|||
qApp->processEvents(QEventLoop::AllEvents, maxTime);
|
||||
}
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
snoreDebug(SNORE_WARNING) << "Error downloading" << url << ":" << reply->errorString();
|
||||
qCWarning(SNORE) << "Error downloading" << url << ":" << reply->errorString();
|
||||
} else {
|
||||
if (reply->isFinished()) {
|
||||
QPixmap pix;
|
||||
pix.loadFromData(reply->readAll());
|
||||
icon = Icon(pix);
|
||||
s_downloadImageCache.insert(url, icon);
|
||||
snoreDebug(SNORE_DEBUG) << url << "added to cache.";
|
||||
qCDebug(SNORE) << url << "added to cache.";
|
||||
} else {
|
||||
snoreDebug(SNORE_DEBUG) << "Download of " << url << "timed out.";
|
||||
qCDebug(SNORE) << "Download of " << url << "timed out.";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ Icon Icon::fromWebUrl(const QUrl &url, int maxTime)
|
|||
manager->deleteLater();
|
||||
} else {
|
||||
icon = s_downloadImageCache.value(url, defaultIcon());
|
||||
snoreDebug(SNORE_DEBUG) << url << "from cache";
|
||||
qCDebug(SNORE) << url << "from cache";
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
|
|
@ -152,12 +152,12 @@ void Notification::addActiveIn(const QObject *o)
|
|||
bool contains = d->m_activeIn.contains(o);
|
||||
Q_ASSERT_X(!contains, Q_FUNC_INFO, "already active");
|
||||
if (contains) {
|
||||
snoreDebug(SNORE_WARNING) << o << "already active in" << id();
|
||||
qCWarning(SNORE) << o << "already active in" << id();
|
||||
return;
|
||||
}
|
||||
d->m_activeIn.insert(o);
|
||||
SnoreCorePrivate::instance()->m_activeNotifications[id()] = *this;
|
||||
snoreDebug(SNORE_INFO) << SnoreCorePrivate::instance()->m_activeNotifications.size();
|
||||
qCInfo(SNORE) << SnoreCorePrivate::instance()->m_activeNotifications.size();
|
||||
}
|
||||
|
||||
bool Notification::isActiveIn(const QObject *o) const
|
||||
|
@ -170,7 +170,7 @@ bool Notification::removeActiveIn(const QObject *o)
|
|||
bool out = d->m_activeIn.remove(o);
|
||||
if (d->m_activeIn.isEmpty()) {
|
||||
SnoreCorePrivate::instance()->m_activeNotifications.remove(id());
|
||||
snoreDebug(SNORE_INFO) << SnoreCorePrivate::instance()->m_activeNotifications.size();
|
||||
qCInfo(SNORE) << SnoreCorePrivate::instance()->m_activeNotifications.size();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "notification/notification_p.h"
|
||||
#include "notification/icon.h"
|
||||
#include "../hint.h"
|
||||
#include "libsnore/log.h"
|
||||
#include "libsnore/plugins/plugins.h"
|
||||
#include "libsnore/snore.h"
|
||||
|
||||
|
@ -44,8 +43,8 @@ NotificationData::NotificationData(const Snore::Application &application, const
|
|||
m_hints(m_application.constHints())
|
||||
{
|
||||
notificationCount++;
|
||||
snoreDebug(SNORE_INFO) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
snoreDebug(SNORE_INFO) << title << text;
|
||||
qCInfo(SNORE) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
qCInfo(SNORE) << title << text;
|
||||
}
|
||||
|
||||
Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority):
|
||||
|
@ -61,15 +60,15 @@ Snore::NotificationData::NotificationData(const Notification &old, const QString
|
|||
m_toReplace(old)
|
||||
{
|
||||
notificationCount++;
|
||||
snoreDebug(SNORE_INFO) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
snoreDebug(SNORE_INFO) << title << text;
|
||||
qCInfo(SNORE) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
qCInfo(SNORE) << title << text;
|
||||
}
|
||||
|
||||
NotificationData::~NotificationData()
|
||||
{
|
||||
stopTimeoutTimer();
|
||||
notificationCount--;
|
||||
snoreDebug(SNORE_INFO) << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason;
|
||||
qCInfo(SNORE) << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason;
|
||||
}
|
||||
|
||||
void NotificationData::setActionInvoked(const Snore::Action &action)
|
||||
|
@ -119,7 +118,7 @@ const SnorePlugin *NotificationData::source() const
|
|||
bool NotificationData::sourceAndTargetAreSimilar(const SnorePlugin *target)
|
||||
{
|
||||
if (source() && source()->name() == target->name()) {
|
||||
snoreDebug(SNORE_DEBUG) << "Source" << source() << "and Target" << target << "are the same.";
|
||||
qCDebug(SNORE) << "Source" << source() << "and Target" << target << "are the same.";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -49,7 +49,7 @@ PluginContainer::~PluginContainer()
|
|||
SnorePlugin *PluginContainer::load()
|
||||
{
|
||||
if (!m_loader.isLoaded() && !m_loader.load()) {
|
||||
snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << m_loader.errorString();
|
||||
qCWarning(SNORE) << "Failed loading plugin: " << m_loader.errorString();
|
||||
return nullptr;
|
||||
}
|
||||
if (!m_plugin) {
|
||||
|
@ -88,23 +88,23 @@ bool PluginContainer::isLoaded() const
|
|||
|
||||
void PluginContainer::updatePluginCache()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "Updating plugin cache";
|
||||
foreach(PluginContaienrHash list, s_pluginCache.values()) {
|
||||
qCDebug(SNORE) << "Updating plugin cache";
|
||||
foreach (PluginContaienrHash list, s_pluginCache.values()) {
|
||||
qDeleteAll(list);
|
||||
list.clear();
|
||||
}
|
||||
|
||||
foreach(const SnorePlugin::PluginTypes type, SnorePlugin::types()) {
|
||||
foreach(const QFileInfo & file, pluginDir().entryInfoList(
|
||||
QStringList(pluginFileFilters(type)), QDir::Files)) {
|
||||
snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath();
|
||||
foreach (const SnorePlugin::PluginTypes type, SnorePlugin::types()) {
|
||||
foreach (const QFileInfo &file, pluginDir().entryInfoList(
|
||||
QStringList(pluginFileFilters(type)), QDir::Files)) {
|
||||
qCDebug(SNORE) << "adding" << file.absoluteFilePath();
|
||||
QPluginLoader loader(file.absoluteFilePath());
|
||||
QJsonObject data = loader.metaData()[QStringLiteral("MetaData")].toObject();
|
||||
QString name = data.value(QStringLiteral("name")).toString();
|
||||
if (!name.isEmpty()) {
|
||||
PluginContainer *info = new PluginContainer(file.fileName(), name, type);
|
||||
s_pluginCache[type].insert(name, info);
|
||||
snoreDebug(SNORE_DEBUG) << "added" << name << "to cache";
|
||||
qCDebug(SNORE) << "added" << name << "to cache";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
|
|||
QTime time;
|
||||
time.start();
|
||||
updatePluginCache();
|
||||
snoreDebug(SNORE_DEBUG) << "Plugins loaded in:" << time.elapsed();
|
||||
qCDebug(SNORE) << "Plugins loaded in:" << time.elapsed();
|
||||
}
|
||||
|
||||
QHash<QString, PluginContainer *> out;
|
||||
|
@ -153,19 +153,19 @@ const QDir &PluginContainer::pluginDir()
|
|||
<< appDir + suffix
|
||||
<< appDir + QStringLiteral("/../lib/plugins") + suffix
|
||||
<< appDir + QStringLiteral("/../lib64/plugins") + suffix;
|
||||
foreach(const QString & p, list) {
|
||||
foreach (const QString &p, list) {
|
||||
path = QDir(p);
|
||||
|
||||
if (!path.entryInfoList(pluginFileFilters()).isEmpty()) {
|
||||
break;
|
||||
} else {
|
||||
snoreDebug(SNORE_DEBUG) << "Possible pluginpath:" << path.absolutePath() << "does not contain plugins.";
|
||||
qCDebug(SNORE) << "Possible pluginpath:" << path.absolutePath() << "does not contain plugins.";
|
||||
}
|
||||
}
|
||||
if (path.entryInfoList(pluginFileFilters()).isEmpty()) {
|
||||
snoreDebug(SNORE_WARNING) << "Couldnt find any plugins";
|
||||
qCWarning(SNORE) << "Couldnt find any plugins";
|
||||
}
|
||||
snoreDebug(SNORE_INFO) << "PluginPath is :" << path.absolutePath();
|
||||
qCInfo(SNORE) << "PluginPath is :" << path.absolutePath();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -33,13 +33,13 @@ SnorePlugin::SnorePlugin()
|
|||
{
|
||||
Q_ASSERT_X(thread() == qApp->thread(), Q_FUNC_INFO, "Plugin initialized in wrong thread");
|
||||
if (thread() != qApp->thread()) {
|
||||
snoreDebug(SNORE_WARNING) << "Plugin initialized in wrong thread.";
|
||||
qCWarning(SNORE) << "Plugin initialized in wrong thread.";
|
||||
}
|
||||
}
|
||||
|
||||
SnorePlugin::~SnorePlugin()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << name() << this << "deleted";
|
||||
qCDebug(SNORE) << name() << this << "deleted";
|
||||
}
|
||||
|
||||
bool SnorePlugin::isEnabled() const
|
||||
|
@ -116,7 +116,7 @@ void SnorePlugin::setDefaultSettings()
|
|||
void SnorePlugin::setErrorString(const QString &_error)
|
||||
{
|
||||
m_error = _error;
|
||||
snoreDebug(SNORE_WARNING) << name() << "encountered an error:" << m_error;
|
||||
qCWarning(SNORE) << name() << "encountered an error:" << m_error;
|
||||
disable();
|
||||
emit error(_error);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ SnoreBackend::SnoreBackend()
|
|||
|
||||
SnoreBackend::~SnoreBackend()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
|
||||
qCDebug(SNORE) << "Deleting" << name();
|
||||
}
|
||||
|
||||
void SnoreBackend::requestCloseNotification(Notification notification, Notification::CloseReasons reason)
|
||||
|
@ -80,7 +80,7 @@ void SnoreBackend::closeNotification(Notification n, Notification::CloseReasons
|
|||
n.old().removeActiveIn(this);
|
||||
}
|
||||
n.data()->setCloseReason(reason);
|
||||
snoreDebug(SNORE_DEBUG) << n << reason;
|
||||
qCDebug(SNORE) << n << reason;
|
||||
emit notificationClosed(n);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ SnoreFrontend::SnoreFrontend()
|
|||
|
||||
SnoreFrontend::~SnoreFrontend()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
|
||||
qCDebug(SNORE) << "Deleting" << name();
|
||||
}
|
||||
|
||||
void SnoreFrontend::slotActionInvoked(Notification)
|
||||
|
|
|
@ -37,7 +37,7 @@ SnoreSecondaryBackend::SnoreSecondaryBackend()
|
|||
|
||||
SnoreSecondaryBackend::~SnoreSecondaryBackend()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
|
||||
qCDebug(SNORE) << "Deleting" << name();
|
||||
}
|
||||
|
||||
void SnoreSecondaryBackend::slotNotify(Notification)
|
||||
|
|
|
@ -49,7 +49,7 @@ void SettingsDialog::initTabs()
|
|||
bool enabled = false;
|
||||
target->clear();
|
||||
if (types & type) {
|
||||
foreach(PluginSettingsWidget * widget, SnoreCore::instance().settingWidgets(type)) {
|
||||
foreach (PluginSettingsWidget *widget, SnoreCore::instance().settingWidgets(type)) {
|
||||
target->addTab(widget, widget->name());
|
||||
m_tabs.append(widget);
|
||||
enabled = true;
|
||||
|
@ -88,11 +88,11 @@ void SettingsDialog::on_pushButton_clicked()
|
|||
|
||||
void SettingsDialog::load()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "loading";
|
||||
qCDebug(SNORE) << "loading";
|
||||
loadPrimaryBackendBox(SnoreCore::instance().settingsValue(QStringLiteral("PrimaryBackend"), LOCAL_SETTING).toString());
|
||||
ui->timeoutSpinBox->setValue(SnoreCore::instance().settingsValue(QStringLiteral("Timeout"), LOCAL_SETTING).toInt());
|
||||
ui->disableNotificationSoundCheckBox->setChecked(SnoreCore::instance().settingsValue(QStringLiteral("Silent"), LOCAL_SETTING).toBool());
|
||||
foreach(auto widget, m_tabs) {
|
||||
foreach (auto widget, m_tabs) {
|
||||
widget->loadSettings();
|
||||
}
|
||||
}
|
||||
|
@ -114,9 +114,9 @@ void SettingsDialog::loadPrimaryBackendBox(const QString &backend)
|
|||
|
||||
void SettingsDialog::save()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "saving";
|
||||
qCDebug(SNORE) << "saving";
|
||||
bool dirty = false;
|
||||
foreach(auto w, m_tabs) {
|
||||
foreach (auto w, m_tabs) {
|
||||
w->saveSettings();
|
||||
dirty |= w->isDirty();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
using namespace Snore;
|
||||
|
||||
Q_LOGGING_CATEGORY(SNORE, "SNORE")
|
||||
|
||||
SnoreCore::SnoreCore(QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
|
@ -69,16 +71,16 @@ SnoreCore::~SnoreCore()
|
|||
void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
|
||||
{
|
||||
if (QThread::currentThread() != thread()) {
|
||||
snoreDebug(SNORE_DEBUG) << "Delayed Plugin loading." << QThread::currentThread() << thread();
|
||||
qCDebug(SNORE) << "Delayed Plugin loading." << QThread::currentThread() << thread();
|
||||
QMetaObject::invokeMethod(this, "loadPlugins", Qt::BlockingQueuedConnection, Q_ARG(Snore::SnorePlugin::PluginTypes, types));
|
||||
return;
|
||||
}
|
||||
Q_D(SnoreCore);
|
||||
setSettingsValue(QStringLiteral("PluginTypes"), QVariant::fromValue(types), LOCAL_SETTING);
|
||||
snoreDebug(SNORE_DEBUG) << "Loading plugin types:" << types;
|
||||
foreach(const SnorePlugin::PluginTypes type, SnorePlugin::types()) {
|
||||
qCDebug(SNORE) << "Loading plugin types:" << types;
|
||||
foreach (const SnorePlugin::PluginTypes type, SnorePlugin::types()) {
|
||||
if (type != SnorePlugin::ALL && types & type) {
|
||||
foreach(PluginContainer * info, PluginContainer::pluginCache(type).values()) {
|
||||
foreach (PluginContainer *info, PluginContainer::pluginCache(type).values()) {
|
||||
SnorePlugin *plugin = info->load();
|
||||
if (!plugin) {
|
||||
continue;
|
||||
|
@ -93,11 +95,11 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
|
|||
plugin->setEnabled(plugin->settingsValue(QStringLiteral("Enabled"), LOCAL_SETTING).toBool());
|
||||
break;
|
||||
default:
|
||||
snoreDebug(SNORE_WARNING) << "Plugin Cache corrupted\n" << info->file() << info->type();
|
||||
qCWarning(SNORE) << "Plugin Cache corrupted\n" << info->file() << info->type();
|
||||
continue;
|
||||
}
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << info->name() << "is a" << info->type();
|
||||
qCDebug(SNORE) << info->name() << "is a" << info->type();
|
||||
d->m_pluginNames[info->type()].append(info->name());
|
||||
auto key = qMakePair(type, info->name());
|
||||
Q_ASSERT_X(!d->m_plugins.contains(key), Q_FUNC_INFO, "Multiple plugins of the same type with the same name.");
|
||||
|
@ -109,19 +111,19 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
|
|||
}
|
||||
}
|
||||
d->slotInitPrimaryNotificationBackend();
|
||||
snoreDebug(SNORE_INFO) << "Loaded Plugins:" << d->m_pluginNames;
|
||||
qCInfo(SNORE) << "Loaded Plugins:" << d->m_pluginNames;
|
||||
}
|
||||
|
||||
void SnoreCore::broadcastNotification(Notification notification)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
if (d->m_activeNotifications.size() > d->maxNumberOfActiveNotifications()) {
|
||||
snoreDebug(SNORE_DEBUG) << "queue size:" << d->m_notificationQue.size() << "active size:" << d->m_activeNotifications.size();
|
||||
qCDebug(SNORE) << "queue size:" << d->m_notificationQue.size() << "active size:" << d->m_activeNotifications.size();
|
||||
d->m_notificationQue.append(notification);
|
||||
return;
|
||||
}
|
||||
Q_ASSERT_X(!notification.data()->isBroadcasted(), Q_FUNC_INFO, "Notification was already broadcasted.");
|
||||
snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout();
|
||||
qCDebug(SNORE) << "Broadcasting" << notification << "timeout:" << notification.timeout();
|
||||
if (d->m_notificationBackend != nullptr) {
|
||||
if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) {
|
||||
requestCloseNotification(notification.old(), Notification::REPLACED);
|
||||
|
@ -140,7 +142,7 @@ void SnoreCore::registerApplication(const Application &application)
|
|||
Q_D(SnoreCore);
|
||||
Q_ASSERT_X(!d->m_applications.contains(application.key()), Q_FUNC_INFO,
|
||||
"Applications mus be registered only once.");
|
||||
snoreDebug(SNORE_DEBUG) << "Registering Application:" << application;
|
||||
qCDebug(SNORE) << "Registering Application:" << application;
|
||||
d->m_applications.insert(application.key(), application);
|
||||
emit d->applicationRegistered(application);
|
||||
}
|
||||
|
@ -190,7 +192,7 @@ void SnoreCore::requestCloseNotification(Notification n, Notification::CloseReas
|
|||
Q_D(SnoreCore);
|
||||
bool wasQued = d->m_notificationQue.removeOne(n);
|
||||
if (wasQued) {
|
||||
snoreDebug(SNORE_DEBUG) << n << " was qued.";
|
||||
qCDebug(SNORE) << n << " was qued.";
|
||||
}
|
||||
if (!wasQued && d->m_notificationBackend) {
|
||||
d->m_notificationBackend->requestCloseNotification(n, r);
|
||||
|
@ -212,7 +214,7 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets(SnorePlugin::PluginTypes
|
|||
{
|
||||
Q_D(SnoreCore);
|
||||
QList<PluginSettingsWidget *> list;
|
||||
foreach(const QString & name, d->m_pluginNames[type]) {
|
||||
foreach (const QString &name, d->m_pluginNames[type]) {
|
||||
//TODO: mem leak?
|
||||
SnorePlugin *p = d->m_plugins[qMakePair(type, name)];
|
||||
PluginSettingsWidget *widget = p->settingsWidget();
|
||||
|
@ -247,7 +249,7 @@ void SnoreCore::setDefaultSettingsValue(const QString &key, const QVariant &valu
|
|||
Q_D(SnoreCore);
|
||||
QString nk = d->normalizeSettingsKey(key, type);
|
||||
if (!d->m_settings->contains(nk)) {
|
||||
snoreDebug(SNORE_DEBUG) << "Set default value" << nk << value;
|
||||
qCDebug(SNORE) << "Set default value" << nk << value;
|
||||
d->m_settings->setValue(nk, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "snore_exports.h"
|
||||
#include "snoreglobals.h"
|
||||
#include "log.h"
|
||||
#include "application.h"
|
||||
#include "notification/notification.h"
|
||||
#include "plugins/plugins.h"
|
||||
|
|
|
@ -34,19 +34,19 @@ using namespace Snore;
|
|||
SnoreCorePrivate::SnoreCorePrivate():
|
||||
m_localSettingsPrefix(qApp->applicationName().isEmpty() ? QStringLiteral("SnoreNotify") : qApp->applicationName())
|
||||
{
|
||||
if (!qEnvironmentVariableIsSet("LIBSNORE_SETTINGS_FILE")) {
|
||||
if (qEnvironmentVariableIsSet("LIBSNORE_SETTINGS_FILE")) {
|
||||
m_settings = new QSettings(QString::fromUtf8(qgetenv("LIBSNORE_SETTINGS_FILE")), QSettings::IniFormat);
|
||||
} else {
|
||||
m_settings = new QSettings(QStringLiteral("Snorenotify"), QStringLiteral("libsnore"), this);
|
||||
}
|
||||
snoreDebug(SNORE_INFO) << "Version:" << Version::version();
|
||||
qCInfo(SNORE) << "Version:" << Version::version();
|
||||
if (!Version::revision().isEmpty()) {
|
||||
snoreDebug(SNORE_INFO) << "Revision:" << Version::revision();
|
||||
qCInfo(SNORE) << "Revision:" << Version::revision();
|
||||
}
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << "Temp dir is" << tempPath();
|
||||
snoreDebug(SNORE_DEBUG) << "Snore settings are located in" << m_settings->fileName();
|
||||
snoreDebug(SNORE_DEBUG) << "Snore local settings are located in" << normalizeSettingsKey(QStringLiteral("Test"), LOCAL_SETTING);
|
||||
qCDebug(SNORE) << "Temp dir is" << tempPath();
|
||||
qCDebug(SNORE) << "Snore settings are located in" << m_settings->fileName();
|
||||
qCDebug(SNORE) << "Snore local settings are located in" << normalizeSettingsKey(QStringLiteral("Test"), LOCAL_SETTING);
|
||||
|
||||
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit()));
|
||||
}
|
||||
|
@ -85,13 +85,13 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
|
|||
}
|
||||
const QHash<QString, PluginContainer *> backends = PluginContainer::pluginCache(SnorePlugin::BACKEND);
|
||||
if (!backends.contains(backend)) {
|
||||
snoreDebug(SNORE_DEBUG) << "Unknown Backend:" << backend;
|
||||
qCDebug(SNORE) << "Unknown Backend:" << backend;
|
||||
return false;
|
||||
}
|
||||
snoreDebug(SNORE_DEBUG) << "Setting Notification Backend to:" << backend;
|
||||
qCDebug(SNORE) << "Setting Notification Backend to:" << backend;
|
||||
SnoreBackend *b = qobject_cast<SnoreBackend *>(backends.value(backend)->load());
|
||||
if (!b->isReady()) {
|
||||
snoreDebug(SNORE_DEBUG) << "Backend not ready:" << b->errorString();
|
||||
qCDebug(SNORE) << "Backend not ready:" << b->errorString();
|
||||
|
||||
emit q->primaryNotificationBackendError(b->errorString());
|
||||
return false;
|
||||
|
@ -115,7 +115,7 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
|
|||
bool SnoreCorePrivate::slotInitPrimaryNotificationBackend()
|
||||
{
|
||||
Q_Q(SnoreCore);
|
||||
snoreDebug(SNORE_DEBUG) << q->settingsValue(QStringLiteral("PrimaryBackend"), LOCAL_SETTING).toString();
|
||||
qCDebug(SNORE) << q->settingsValue(QStringLiteral("PrimaryBackend"), LOCAL_SETTING).toString();
|
||||
if (setBackendIfAvailible(q->settingsValue(QStringLiteral("PrimaryBackend"), LOCAL_SETTING).toString())) {
|
||||
return true;
|
||||
}
|
||||
|
@ -174,15 +174,15 @@ void SnoreCorePrivate::syncSettings()
|
|||
m_notificationBackend = nullptr;
|
||||
}
|
||||
if (!setBackendIfAvailible(newBackend)) {
|
||||
snoreDebug(SNORE_WARNING) << "Failed to set new backend" << q->settingsValue(QStringLiteral("PrimaryBackend"), LOCAL_SETTING).toString() << "restoring" << oldBackend;
|
||||
qCWarning(SNORE) << "Failed to set new backend" << q->settingsValue(QStringLiteral("PrimaryBackend"), LOCAL_SETTING).toString() << "restoring" << oldBackend;
|
||||
setBackendIfAvailible(oldBackend);
|
||||
}
|
||||
}
|
||||
|
||||
auto types = SnorePlugin::types();
|
||||
types.removeOne(SnorePlugin::BACKEND);
|
||||
foreach(auto type, types) {
|
||||
foreach(auto & pluginName, m_pluginNames[type]) {
|
||||
foreach (auto type, types) {
|
||||
foreach (auto &pluginName, m_pluginNames[type]) {
|
||||
auto key = qMakePair(type, pluginName);
|
||||
SnorePlugin *plugin = m_plugins.value(key);
|
||||
bool enable = m_plugins[key]->settingsValue(QStringLiteral("Enabled"), LOCAL_SETTING).toBool();
|
||||
|
@ -229,10 +229,10 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n)
|
|||
Q_Q(SnoreCore);
|
||||
emit q->notificationClosed(n);
|
||||
if (!n.removeActiveIn(q)) {
|
||||
snoreDebug(SNORE_WARNING) << n << "was already closed";
|
||||
qCWarning(SNORE) << n << "was already closed";
|
||||
}
|
||||
if (!m_notificationQue.isEmpty() && m_activeNotifications.size() < maxNumberOfActiveNotifications()) {
|
||||
snoreDebug(SNORE_DEBUG) << "Broadcast from queue" << m_notificationQue.size();
|
||||
qCDebug(SNORE) << "Broadcast from queue" << m_notificationQue.size();
|
||||
q->broadcastNotification(m_notificationQue.takeFirst());
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ void SnoreCorePrivate::slotAboutToQuit()
|
|||
{
|
||||
for (PluginContainer *p : PluginContainer::pluginCache(SnorePlugin::ALL)) {
|
||||
if (p->isLoaded()) {
|
||||
snoreDebug(SNORE_DEBUG) << "deinitialize" << p->name();
|
||||
qCDebug(SNORE) << "deinitialize" << p->name();
|
||||
p->load()->disable();
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void SnoreCorePrivate::startNotificationTimeoutTimer(Notification notification)
|
|||
}
|
||||
timer->setInterval(notification.timeout() * 1000);
|
||||
connect(timer, &QTimer::timeout, [q, notification]() {
|
||||
snoreDebug(SNORE_DEBUG) << notification;
|
||||
qCDebug(SNORE) << notification;
|
||||
q->requestCloseNotification(notification, Notification::TIMED_OUT);
|
||||
});
|
||||
timer->start();
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#ifndef SNOREGLOBALS
|
||||
#define SNOREGLOBALS
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
namespace Snore
|
||||
{
|
||||
|
||||
|
@ -29,5 +31,7 @@ enum SettingsType {
|
|||
|
||||
}
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(SNORE)
|
||||
|
||||
#endif // SNOREGLOBALS
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
|
@ -76,60 +75,60 @@ void Utils::raiseWindowToFront(qlonglong wid)
|
|||
static QRegExp regexp(QLatin1String(PATTERN));\
|
||||
STRING = STRING.replace(regexp, QStringLiteral("\\1"));\
|
||||
}\
|
||||
|
||||
QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
|
||||
{
|
||||
static QMutex mutex;
|
||||
if (tags == ALL_MARKUP) {
|
||||
|
||||
QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
|
||||
{
|
||||
static QMutex mutex;
|
||||
if (tags == ALL_MARKUP) {
|
||||
return string;
|
||||
} else if (tags == NO_MARKUP) {
|
||||
return QTextDocumentFragment::fromHtml(string).toPlainText();
|
||||
}
|
||||
|
||||
QMutexLocker lock(&mutex);
|
||||
if (~tags & Utils::BREAK) {
|
||||
static QRegExp br(QLatin1String("<br>"));
|
||||
string = string.replace(br, QStringLiteral("\n"));
|
||||
}
|
||||
if (~tags & Utils::HREF) {
|
||||
HTML_REPLACE(string, "<a href=.*>([^<]*)</a>");
|
||||
}
|
||||
if (~tags & Utils::ITALIC) {
|
||||
HTML_REPLACE(string, "<i>([^<]*)</i>");
|
||||
}
|
||||
if (~tags & Utils::BOLD) {
|
||||
HTML_REPLACE(string, "<b>([^<]*)</b>");
|
||||
}
|
||||
if (~tags & Utils::UNDERLINE) {
|
||||
HTML_REPLACE(string, "<u>([^<]*)</u>");
|
||||
}
|
||||
if (~tags & Utils::FONT) {
|
||||
HTML_REPLACE(string, "<font.*>([^<]*)</font>");
|
||||
}
|
||||
return string;
|
||||
} else if (tags == NO_MARKUP) {
|
||||
return QTextDocumentFragment::fromHtml(string).toPlainText();
|
||||
}
|
||||
|
||||
QMutexLocker lock(&mutex);
|
||||
if (~tags & Utils::BREAK) {
|
||||
static QRegExp br(QLatin1String("<br>"));
|
||||
string = string.replace(br, QStringLiteral("\n"));
|
||||
QByteArray Utils::dataFromImage(const QImage &image)
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
buffer.open(QBuffer::WriteOnly);
|
||||
image.save(&buffer, "PNG");
|
||||
return data;
|
||||
}
|
||||
if (~tags & Utils::HREF) {
|
||||
HTML_REPLACE(string, "<a href=.*>([^<]*)</a>");
|
||||
}
|
||||
if (~tags & Utils::ITALIC) {
|
||||
HTML_REPLACE(string, "<i>([^<]*)</i>");
|
||||
}
|
||||
if (~tags & Utils::BOLD) {
|
||||
HTML_REPLACE(string, "<b>([^<]*)</b>");
|
||||
}
|
||||
if (~tags & Utils::UNDERLINE) {
|
||||
HTML_REPLACE(string, "<u>([^<]*)</u>");
|
||||
}
|
||||
if (~tags & Utils::FONT) {
|
||||
HTML_REPLACE(string, "<font.*>([^<]*)</font>");
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
QByteArray Utils::dataFromImage(const QImage &image)
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
buffer.open(QBuffer::WriteOnly);
|
||||
image.save(&buffer, "PNG");
|
||||
return data;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
int Utils::attatchToActiveProcess()
|
||||
{
|
||||
int idActive = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
|
||||
return AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ? idActive : -1;
|
||||
}
|
||||
|
||||
void Utils::detatchActiveProcess(int idActive)
|
||||
{
|
||||
if (idActive != -1) {
|
||||
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
|
||||
int Utils::attatchToActiveProcess()
|
||||
{
|
||||
int idActive = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
|
||||
return AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ? idActive : -1;
|
||||
}
|
||||
|
||||
void Utils::detatchActiveProcess(int idActive)
|
||||
{
|
||||
if (idActive != -1) {
|
||||
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -50,7 +50,7 @@ void FreedesktopBackend::slotNotify(Notification noti)
|
|||
}
|
||||
|
||||
QStringList actions;
|
||||
foreach(int k, noti.actions().keys()) {
|
||||
foreach (int k, noti.actions().keys()) {
|
||||
actions << QString::number(k) << noti.actions()[k].name();
|
||||
}
|
||||
QVariantMap hints;
|
||||
|
@ -89,12 +89,12 @@ void FreedesktopBackend::slotNotify(Notification noti)
|
|||
m_dbusIdMap[id.value()] = noti;
|
||||
slotNotificationDisplayed(noti);
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << noti.id() << "|" << id.value();
|
||||
qCDebug(SNORE) << noti.id() << "|" << id.value();
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << id << m_dbusIdMap[id];
|
||||
qCDebug(SNORE) << id << m_dbusIdMap[id];
|
||||
Notification noti = m_dbusIdMap[id];
|
||||
if (!noti.isValid()) {
|
||||
return;
|
||||
|
@ -105,7 +105,7 @@ void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &action
|
|||
void FreedesktopBackend::slotCloseNotification(Notification notification)
|
||||
{
|
||||
uint id = notification.hints().privateValue(this, "id").toUInt();
|
||||
snoreDebug(SNORE_DEBUG) << notification.id() << id;
|
||||
qCDebug(SNORE) << notification.id() << id;
|
||||
m_interface->CloseNotification(id);
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ void FreedesktopBackend::slotNotificationClosed(const uint &id, const uint &reas
|
|||
closeReason = Notification::NONE;
|
||||
}
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << id << "|" << closeReason << reason;
|
||||
qCDebug(SNORE) << id << "|" << closeReason << reason;
|
||||
if (id == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -105,12 +105,12 @@ void FreedesktopBackend::slotNotify(Notification noti)
|
|||
m_dbusIdMap[id.value()] = noti;
|
||||
slotNotificationDisplayed(noti);
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << noti.id() << "|" << id.value();
|
||||
qCDebug(SNORE) << noti.id() << "|" << id.value();
|
||||
}
|
||||
|
||||
void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << id << m_dbusIdMap[id];
|
||||
qCDebug(SNORE) << id << m_dbusIdMap[id];
|
||||
Notification noti = m_dbusIdMap[id];
|
||||
if (!noti.isValid()) {
|
||||
return;
|
||||
|
@ -121,7 +121,7 @@ void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &action
|
|||
void FreedesktopBackend::slotCloseNotification(Notification notification)
|
||||
{
|
||||
uint id = notification.hints().privateValue(this, "id").toUInt();
|
||||
snoreDebug(SNORE_DEBUG) << notification.id() << id;
|
||||
qCDebug(SNORE) << notification.id() << id;
|
||||
m_interface->CloseNotification(id);
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ void FreedesktopBackend::slotNotificationClosed(const uint &id, const uint &reas
|
|||
closeReason = Notification::NONE;
|
||||
}
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << id << "|" << closeReason << reason;
|
||||
qCDebug(SNORE) << id << "|" << closeReason << reason;
|
||||
if (id == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ GrowlBackend::GrowlBackend()
|
|||
s_instance = this;
|
||||
|
||||
auto func = [](growl_callback_data * data)->void {
|
||||
snoreDebug(SNORE_DEBUG) << data->id << QString::fromUtf8(data->reason) << QString::fromUtf8(data->data);
|
||||
qCDebug(SNORE) << data->id << QString::fromUtf8(data->reason) << QString::fromUtf8(data->data);
|
||||
Notification n = Snore::SnoreCore::instance().getActiveNotificationByID(data->id);
|
||||
if (!n.isValid())
|
||||
{
|
||||
|
@ -74,10 +74,10 @@ bool GrowlBackend::isReady()
|
|||
|
||||
void GrowlBackend::slotRegisterApplication(const Application &application)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << application.name();
|
||||
qCDebug(SNORE) << application.name();
|
||||
std::vector<std::string> alerts;
|
||||
foreach(const Alert & a, application.alerts()) {
|
||||
snoreDebug(SNORE_DEBUG) << a.name();
|
||||
foreach (const Alert &a, application.alerts()) {
|
||||
qCDebug(SNORE) << a.name();
|
||||
alerts.push_back(a.name().toUtf8().constData());
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ void GrowlBackend::slotNotify(Notification notification)
|
|||
{
|
||||
Growl *growl = m_applications.value(notification.application().name());
|
||||
QString alert = notification.alert().name();
|
||||
snoreDebug(SNORE_DEBUG) << "Notify Growl:" << notification.application() << alert << notification.title();
|
||||
qCDebug(SNORE) << "Notify Growl:" << notification.application() << alert << notification.title();
|
||||
|
||||
GrowlNotificationData data(alert.toUtf8().constData(), notification.id(),
|
||||
notification.title().toUtf8().constData(),
|
||||
|
|
|
@ -68,11 +68,11 @@ BOOL installNSBundleHook()
|
|||
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
|
||||
{
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << "User clicked on notification";
|
||||
qCDebug(SNORE) << "User clicked on notification";
|
||||
int notificationId = [notification.userInfo[@"id"] intValue];
|
||||
[center removeDeliveredNotification: notification];
|
||||
if (not m_IdToNotification.contains(notificationId)) {
|
||||
snoreDebug(SNORE_WARNING) << "User clicked on notification that was not recognized";
|
||||
qCWarning(SNORE) << "User clicked on notification that was not recognized";
|
||||
return;
|
||||
}
|
||||
auto snoreNotification = m_IdToNotification.take(notificationId);
|
||||
|
|
|
@ -70,40 +70,40 @@ public:
|
|||
switch (action) {
|
||||
case SnarlEnums::CallbackInvoked:
|
||||
reason = Notification::ACTIVATED;
|
||||
snoreDebug(SNORE_DEBUG) << "Notification clicked";
|
||||
qCDebug(SNORE) << "Notification clicked";
|
||||
break;
|
||||
case SnarlEnums::NotifyAction:
|
||||
reason = Notification::ACTIVATED;
|
||||
snoreDebug(SNORE_DEBUG) << "Notification action invoked";
|
||||
qCDebug(SNORE) << "Notification action invoked";
|
||||
if (notification.isValid()) {
|
||||
m_snarl->slotNotificationActionInvoked(notification, notification.actions().value(data));
|
||||
}
|
||||
break;
|
||||
case SnarlEnums::CallbackClosed:
|
||||
reason = Notification::DISMISSED;
|
||||
snoreDebug(SNORE_DEBUG) << "Notification dismissed";
|
||||
qCDebug(SNORE) << "Notification dismissed";
|
||||
break;
|
||||
case SnarlEnums::CallbackTimedOut:
|
||||
reason = Notification::TIMED_OUT;
|
||||
snoreDebug(SNORE_DEBUG) << "Notification timed out";
|
||||
qCDebug(SNORE) << "Notification timed out";
|
||||
break;
|
||||
//away stuff
|
||||
case SnarlEnums::SnarlUserAway:
|
||||
snoreDebug(SNORE_DEBUG) << "Snalr user has gone away";
|
||||
qCDebug(SNORE) << "Snalr user has gone away";
|
||||
return true;
|
||||
case SnarlEnums::SnarlUserBack:
|
||||
snoreDebug(SNORE_DEBUG) << "Snalr user has returned";
|
||||
qCDebug(SNORE) << "Snalr user has returned";
|
||||
return true;
|
||||
default:
|
||||
snoreDebug(SNORE_WARNING) << "Unknown snarl action found!!";
|
||||
qCWarning(SNORE) << "Unknown snarl action found!!";
|
||||
return false;
|
||||
}
|
||||
if (notification.isValid()) {
|
||||
m_snarl->requestCloseNotification(notification, reason);
|
||||
m_snarl->m_idMap.take(msg->lParam);
|
||||
} else {
|
||||
snoreDebug(SNORE_WARNING) << "Snarl notification already closed" << msg->lParam << action;
|
||||
snoreDebug(SNORE_WARNING) << m_snarl->m_idMap;
|
||||
qCWarning(SNORE) << "Snarl notification already closed" << msg->lParam << action;
|
||||
qCWarning(SNORE) << m_snarl->m_idMap;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -177,9 +177,9 @@ void SnarlBackend::slotRegisterApplication(const Application &application)
|
|||
application.icon().localUrl(QSize(128, 128)).toUtf8().constData(),
|
||||
password.isEmpty() ? 0 : password.toUtf8().constData(),
|
||||
(HWND)m_eventLoop->winId(), SNORENOTIFIER_MESSAGE_ID);
|
||||
snoreDebug(SNORE_DEBUG) << result;
|
||||
qCDebug(SNORE) << result;
|
||||
|
||||
foreach(const Alert & alert, application.alerts()) {
|
||||
foreach (const Alert &alert, application.alerts()) {
|
||||
snarlInterface->AddClass(alert.name().toUtf8().constData(),
|
||||
alert.name().toUtf8().constData(),
|
||||
0, 0, alert.icon().localUrl(QSize(128, 128)).toUtf8().constData());
|
||||
|
@ -189,7 +189,7 @@ void SnarlBackend::slotRegisterApplication(const Application &application)
|
|||
void SnarlBackend::slotDeregisterApplication(const Application &application)
|
||||
{
|
||||
if (!m_applications.contains(application.name())) {
|
||||
snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << application.name();
|
||||
qCDebug(SNORE) << "Unknown apllication: " << application.name();
|
||||
return;
|
||||
}
|
||||
SnarlInterface *snarlInterface = m_applications.take(application.name());
|
||||
|
@ -201,7 +201,7 @@ void SnarlBackend::slotDeregisterApplication(const Application &application)
|
|||
void SnarlBackend::slotNotify(Notification notification)
|
||||
{
|
||||
if (!m_applications.contains(notification.application().name())) {
|
||||
snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << notification.application().name();
|
||||
qCDebug(SNORE) << "Unknown apllication: " << notification.application().name();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ void SnarlBackend::slotNotify(Notification notification)
|
|||
}
|
||||
|
||||
ULONG32 id = 0;
|
||||
snoreDebug(SNORE_DEBUG) << notification.icon();
|
||||
qCDebug(SNORE) << notification.icon();
|
||||
|
||||
if (!notification.isUpdate()) {
|
||||
id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(),
|
||||
|
@ -228,7 +228,7 @@ void SnarlBackend::slotNotify(Notification notification)
|
|||
Utils::dataFromImage(notification.icon().pixmap(QSize(128, 128)).toImage()).toBase64().constData(),
|
||||
priority);
|
||||
|
||||
foreach(const Action & a, notification.actions()) {
|
||||
foreach (const Action &a, notification.actions()) {
|
||||
snarlInterface->AddAction(id, a.name().toUtf8().constData(), (QLatin1Char('@') + QString::number(a.id())).toUtf8().constData());
|
||||
}
|
||||
m_idMap[id] = notification;
|
||||
|
@ -254,7 +254,7 @@ void SnarlBackend::slotNotify(Notification notification)
|
|||
void SnarlBackend::slotCloseNotification(Notification notification)
|
||||
{
|
||||
if (!m_applications.contains(notification.application().name())) {
|
||||
snoreDebug(SNORE_DEBUG) << "Unknown apllication: " << notification.application().name();
|
||||
qCDebug(SNORE) << "Unknown apllication: " << notification.application().name();
|
||||
return;
|
||||
}
|
||||
ULONG32 id = notification.hints().privateValue(this, "id").toUInt();
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "notifywidget.h"
|
||||
#include "snorenotifier.h"
|
||||
#include "libsnore/log.h"
|
||||
#include "libsnore/utils.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
@ -68,13 +67,13 @@ NotifyWidget::NotifyWidget(int id, const SnoreNotifier *parent) :
|
|||
m_mem.unlock();
|
||||
} else {
|
||||
if (!m_mem.attach()) {
|
||||
snoreDebug(SNORE_WARNING) << "Failed to atatche to shared mem";
|
||||
qCWarning(SNORE) << "Failed to atatche to shared mem";
|
||||
} else {
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
|
||||
m_mem.unlock();
|
||||
int elapsed = (QTime::currentTime().msecsSinceStartOfDay() - data->date) / 1000;
|
||||
snoreDebug(SNORE_DEBUG) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
qCDebug(SNORE) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +85,7 @@ NotifyWidget::~NotifyWidget()
|
|||
|
||||
void NotifyWidget::display(const Notification ¬ification)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << m_id << notification.id() << m_window->isVisible();
|
||||
qCDebug(SNORE) << m_id << notification.id() << m_window->isVisible();
|
||||
m_notification = notification;
|
||||
QColor color;
|
||||
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
|
||||
|
@ -128,11 +127,11 @@ bool NotifyWidget::acquire(int timeout)
|
|||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
|
||||
int elapsed = (QTime::currentTime().msecsSinceStartOfDay() - data->date) / 1000;
|
||||
snoreDebug(SNORE_DEBUG) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
qCDebug(SNORE) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
bool isTimedOut = elapsed > data->timeout;
|
||||
if (data->free || isTimedOut) {
|
||||
if (isTimedOut) {
|
||||
snoreDebug(SNORE_DEBUG) << "Notification Lock timed out" << elapsed;
|
||||
qCDebug(SNORE) << "Notification Lock timed out" << elapsed;
|
||||
}
|
||||
data->free = false;
|
||||
data->date = QTime::currentTime().msecsSinceStartOfDay();
|
||||
|
@ -155,7 +154,7 @@ bool NotifyWidget::release()
|
|||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
|
||||
int elapsed = (QTime::currentTime().msecsSinceStartOfDay() - data->date) / 1000;
|
||||
snoreDebug(SNORE_DEBUG) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
qCDebug(SNORE) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
if (!data->free) {
|
||||
data->free = true;
|
||||
m_ready = true;
|
||||
|
|
|
@ -69,14 +69,14 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
|||
if (notification.old().hints().privateValue(this, "id").isValid()) {
|
||||
NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()];
|
||||
if (w->notification().isValid() && w->notification().id() == notification.old().id()) {
|
||||
snoreDebug(SNORE_DEBUG) << "replacing notification" << w->notification().id() << notification.id();
|
||||
qCDebug(SNORE) << "replacing notification" << w->notification().id() << notification.id();
|
||||
display(w, notification);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < m_queue.length(); ++i) {
|
||||
Notification n = m_queue.at(i);
|
||||
if (n.id() == notification.old().id()) {
|
||||
snoreDebug(SNORE_DEBUG) << "replacing qued notification" << n.id() << notification.id();
|
||||
qCDebug(SNORE) << "replacing qued notification" << n.id() << notification.id();
|
||||
m_queue.replace(i, notification);
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
|||
return;
|
||||
}
|
||||
if (m_queue.isEmpty()) {
|
||||
foreach(NotifyWidget * w, m_widgets) {
|
||||
foreach (NotifyWidget *w, m_widgets) {
|
||||
if (w->acquire(notification.timeout())) {
|
||||
display(w, notification);
|
||||
return;
|
||||
|
@ -92,7 +92,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
|||
}
|
||||
}
|
||||
m_queue.append(notification);
|
||||
snoreDebug(SNORE_DEBUG) << "queing" << m_queue.size();
|
||||
qCDebug(SNORE) << "queing" << m_queue.size();
|
||||
if (!m_timer->isActive()) {
|
||||
m_timer->start();
|
||||
}
|
||||
|
@ -108,10 +108,10 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
|
|||
void SnoreNotifier::slotQueueTimeout()
|
||||
{
|
||||
if (m_queue.isEmpty()) {
|
||||
snoreDebug(SNORE_DEBUG) << "queue is empty";
|
||||
qCDebug(SNORE) << "queue is empty";
|
||||
m_timer->stop();
|
||||
} else {
|
||||
foreach(NotifyWidget * w, m_widgets) {
|
||||
foreach (NotifyWidget *w, m_widgets) {
|
||||
if (!m_queue.isEmpty() && w->acquire(m_queue.first().timeout())) {
|
||||
Notification notification = m_queue.takeFirst();
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
|
|
|
@ -48,7 +48,7 @@ void SnoreToast::slotNotify(Notification notification)
|
|||
if (notification.hints().value("silent").toBool() || notification.hints().value("sound").isValid()) {
|
||||
arguements << QLatin1String("-silent");
|
||||
}
|
||||
snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements;
|
||||
qCDebug(SNORE) << "SnoreToast" << arguements;
|
||||
|
||||
connect(p, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), [this, notification](int code) {
|
||||
Notification::CloseReasons reason = Notification::NONE;
|
||||
|
@ -69,7 +69,7 @@ void SnoreToast::slotNotify(Notification notification)
|
|||
break;
|
||||
case -1:
|
||||
//failed
|
||||
snoreDebug(SNORE_WARNING) << "SnoreToast failed to display " << notification;
|
||||
qCWarning(SNORE) << "SnoreToast failed to display " << notification;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -81,14 +81,14 @@ void SnoreToast::slotNotify(Notification notification)
|
|||
void SnoreToast::slotRegisterApplication(const Application &application)
|
||||
{
|
||||
if (!application.constHints().contains("windows-app-id")) {
|
||||
snoreDebug(SNORE_INFO) << "No windows-app-id found in hints. Installing default shortcut with appID.";
|
||||
qCInfo(SNORE) << "No windows-app-id found in hints. Installing default shortcut with appID.";
|
||||
QProcess *p = createProcess(Notification());
|
||||
QStringList arguements;
|
||||
arguements << QLatin1String("-install")
|
||||
<< QLatin1String("SnoreNotify\\") + qApp->applicationName()
|
||||
<< QDir::toNativeSeparators(qApp->applicationFilePath())
|
||||
<< appId(application);
|
||||
snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements;
|
||||
qCDebug(SNORE) << "SnoreToast" << arguements;
|
||||
p->start(QLatin1String("SnoreToast"), arguements);
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ void SnoreToast::slotCloseNotification(Notification notification)
|
|||
QStringList arguements;
|
||||
arguements << QLatin1String("-close")
|
||||
<< QString::number(notification.id());
|
||||
snoreDebug(SNORE_DEBUG) << "SnoreToast" << arguements;
|
||||
qCDebug(SNORE) << "SnoreToast" << arguements;
|
||||
p->start(QLatin1String("SnoreToast"), arguements);
|
||||
}
|
||||
|
||||
|
@ -119,13 +119,13 @@ QProcess *SnoreToast::createProcess(Notification noti)
|
|||
p->setReadChannelMode(QProcess::MergedChannels);
|
||||
|
||||
connect(p, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), [p](int, QProcess::ExitStatus) {
|
||||
snoreDebug(SNORE_DEBUG) << p->readAll();
|
||||
qCDebug(SNORE) << p->readAll();
|
||||
p->deleteLater();
|
||||
});
|
||||
|
||||
connect(p, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error), [this, p, noti](QProcess::ProcessError) {
|
||||
setErrorString(name() + p->errorString());
|
||||
snoreDebug(SNORE_DEBUG) << p->readAll();
|
||||
qCDebug(SNORE) << p->readAll();
|
||||
if (noti.isValid()) {
|
||||
closeNotification(noti, Notification::NONE);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ void TrayIconNotifer::slotCloseNotification(Notification n)
|
|||
{
|
||||
QSystemTrayIcon *icon = trayIcon(n.application());
|
||||
if (icon) {
|
||||
snoreDebug(SNORE_DEBUG) << n;
|
||||
qCDebug(SNORE) << n;
|
||||
m_currentlyDisplaying = false;
|
||||
displayNotification(icon);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ void PushoverFrontend::login(const QString &email, const QString &password, cons
|
|||
QNetworkReply *reply = m_manager.post(request, (QLatin1String("email=") + email + QLatin1String("&password=") + password).toUtf8().constData());
|
||||
|
||||
connect(reply, &QNetworkReply::finished, [reply, deviceName, this]() {
|
||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||
qCDebug(SNORE) << reply->error();
|
||||
QByteArray input = reply->readAll();
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
|
@ -76,7 +76,7 @@ void PushoverFrontend::login(const QString &email, const QString &password, cons
|
|||
if (message.value(QStringLiteral("status")).toInt() == 1) {
|
||||
registerDevice(message.value(QStringLiteral("secret")).toString(), deviceName);
|
||||
} else {
|
||||
snoreDebug(SNORE_WARNING) << "An error occure" << input;
|
||||
qCWarning(SNORE) << "An error occure" << input;
|
||||
emit loggedInChanged(false);
|
||||
}
|
||||
});
|
||||
|
@ -111,7 +111,7 @@ void PushoverFrontend::setDefaultSettings()
|
|||
void PushoverFrontend::slotActionInvoked(Notification notification)
|
||||
{
|
||||
if (notification.priority() == Notification::EMERGENCY) {
|
||||
snoreDebug(SNORE_WARNING) << "emergeency notification" << notification;
|
||||
qCWarning(SNORE) << "emergeency notification" << notification;
|
||||
acknowledgeNotification(notification);
|
||||
}
|
||||
}
|
||||
|
@ -129,49 +129,49 @@ QString PushoverFrontend::device()
|
|||
void PushoverFrontend::connectToService()
|
||||
{
|
||||
if (secret().isEmpty() || device().isEmpty()) {
|
||||
snoreDebug(SNORE_WARNING) << "not logged in";
|
||||
qCWarning(SNORE) << "not logged in";
|
||||
return;
|
||||
}
|
||||
snoreDebug(SNORE_DEBUG) << "Connecting ton service";
|
||||
qCDebug(SNORE) << "Connecting ton service";
|
||||
m_socket = new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this);
|
||||
|
||||
connect(m_socket.data(), &QWebSocket::binaryMessageReceived, [&](const QByteArray & msg) {
|
||||
char c = msg.at(0);
|
||||
switch (c) {
|
||||
case '#':
|
||||
snoreDebug(SNORE_DEBUG) << "still alive";
|
||||
qCDebug(SNORE) << "still alive";
|
||||
break;
|
||||
case '!':
|
||||
getMessages();
|
||||
break;
|
||||
case 'R':
|
||||
snoreDebug(SNORE_DEBUG) << "need to reconnect";
|
||||
qCDebug(SNORE) << "need to reconnect";
|
||||
m_socket->close();
|
||||
m_socket->deleteLater();
|
||||
connectToService();
|
||||
break;
|
||||
case 'E':
|
||||
snoreDebug(SNORE_WARNING) << "Connection Error";
|
||||
qCWarning(SNORE) << "Connection Error";
|
||||
emit error(QStringLiteral("Please Loggin to https://pushover.net and reanble your device."));
|
||||
emit loggedInChanged(false);
|
||||
m_socket->close();
|
||||
m_socket->deleteLater();
|
||||
break;
|
||||
default:
|
||||
snoreDebug(SNORE_WARNING) << "unknown message received" << msg;
|
||||
qCWarning(SNORE) << "unknown message received" << msg;
|
||||
}
|
||||
});
|
||||
connect(m_socket.data(), &QWebSocket::disconnected, [this]() {
|
||||
snoreDebug(SNORE_WARNING) << "disconnected";
|
||||
qCWarning(SNORE) << "disconnected";
|
||||
//TODO: use new style connect once we depend on qt 5.4
|
||||
QTimer::singleShot(500, this, SLOT(PushoverFrontend::connectToService()));
|
||||
});
|
||||
connect(m_socket.data(), static_cast<void (QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), [&](QAbstractSocket::SocketError error) {
|
||||
snoreDebug(SNORE_WARNING) << error << m_socket->errorString();
|
||||
qCWarning(SNORE) << error << m_socket->errorString();
|
||||
emit loggedInChanged(false);
|
||||
});
|
||||
connect(m_socket.data(), &QWebSocket::connected, [&]() {
|
||||
snoreDebug(SNORE_DEBUG) << "connecting";
|
||||
qCDebug(SNORE) << "connecting";
|
||||
m_socket->sendBinaryMessage((QLatin1String("login:") + device() + QLatin1Char(':') + secret() + QLatin1Char('\n')).toUtf8().constData());
|
||||
emit loggedInChanged(true);
|
||||
getMessages();
|
||||
|
@ -195,7 +195,7 @@ void PushoverFrontend::registerDevice(const QString &secret, const QString &devi
|
|||
QNetworkReply *reply = m_manager.post(request, (QLatin1String("os=O&secret=") + secret + QLatin1String("&name=") + deviceName).toUtf8().constData());
|
||||
|
||||
connect(reply, &QNetworkReply::finished, [reply, secret, this]() {
|
||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||
qCDebug(SNORE) << reply->error();
|
||||
QByteArray input = reply->readAll();
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
|
@ -205,7 +205,7 @@ void PushoverFrontend::registerDevice(const QString &secret, const QString &devi
|
|||
setSettingsValue(QStringLiteral("DeviceID"), message.value(QStringLiteral("id")).toString(), LOCAL_SETTING);;
|
||||
connectToService();
|
||||
} else {
|
||||
snoreDebug(SNORE_WARNING) << "An error occure" << input;
|
||||
qCWarning(SNORE) << "An error occure" << input;
|
||||
emit loggedInChanged(false);
|
||||
emit error(message.value(QStringLiteral("error")).toString());
|
||||
}
|
||||
|
@ -221,19 +221,19 @@ void PushoverFrontend::getMessages()
|
|||
QNetworkReply *reply = m_manager.get(request);
|
||||
|
||||
connect(reply, &QNetworkReply::finished, [reply, this]() {
|
||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||
qCDebug(SNORE) << reply->error();
|
||||
QByteArray input = reply->readAll();
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << input;
|
||||
qCDebug(SNORE) << input;
|
||||
|
||||
QJsonObject message = QJsonDocument::fromJson(input).object();
|
||||
|
||||
int latestID = -1;
|
||||
if (message.value(QStringLiteral("status")).toInt() == 1) {
|
||||
QJsonArray notifications = message.value(QStringLiteral("messages")).toArray();
|
||||
foreach(const QJsonValue & v, notifications) {
|
||||
foreach (const QJsonValue &v, notifications) {
|
||||
QJsonObject notification = v.toObject();
|
||||
|
||||
latestID = qMax(latestID, notification.value(QStringLiteral("id")).toInt());
|
||||
|
@ -267,7 +267,7 @@ void PushoverFrontend::getMessages()
|
|||
deleteMessages(latestID);
|
||||
}
|
||||
} else {
|
||||
snoreDebug(SNORE_WARNING) << "An error occure" << input;
|
||||
qCWarning(SNORE) << "An error occure" << input;
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -284,8 +284,8 @@ void PushoverFrontend::deleteMessages(int latestMessageId)
|
|||
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret() + QLatin1String("&message=") + QString::number(latestMessageId)).toUtf8().constData());
|
||||
|
||||
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
||||
qCDebug(SNORE) << reply->error();
|
||||
qCDebug(SNORE) << reply->readAll();
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
});
|
||||
|
@ -296,18 +296,18 @@ void PushoverFrontend::acknowledgeNotification(Notification notification)
|
|||
if (notification.constHints().value("acked").toInt() == 1) {
|
||||
return;
|
||||
}
|
||||
snoreDebug(SNORE_DEBUG) << notification.constHints().value("acked").toInt();
|
||||
qCDebug(SNORE) << notification.constHints().value("acked").toInt();
|
||||
QString receipt = notification.constHints().value("receipt").toString();
|
||||
|
||||
QNetworkRequest request(QUrl::fromEncoded((QLatin1String("https://api.pushover.net/1/receipts/") +
|
||||
receipt + QLatin1String("/acknowledge.json")).toUtf8().constData()));
|
||||
snoreDebug(SNORE_WARNING) << request.url();
|
||||
qCWarning(SNORE) << request.url();
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QLatin1String("application/x-www-form-urlencoded")));
|
||||
QNetworkReply *reply = m_manager.post(request, (QLatin1String("secret=") + secret()).toUtf8().constData());
|
||||
|
||||
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
||||
qCDebug(SNORE) << reply->error();
|
||||
qCDebug(SNORE) << reply->readAll();
|
||||
//TODO:parse reply
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
|
|
|
@ -50,7 +50,7 @@ Parser::Parser(SnarlNetworkFrontend *snarl):
|
|||
|
||||
void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *client)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << msg;
|
||||
qCDebug(SNORE) << msg;
|
||||
QStringList splitted(msg.split(QStringLiteral("#?")));
|
||||
snpTypes action(ERROR);
|
||||
|
||||
|
@ -64,7 +64,7 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *
|
|||
QByteArray key;
|
||||
QString value;
|
||||
|
||||
foreach(const QString & s, splitted) {
|
||||
foreach (const QString &s, splitted) {
|
||||
key = s.mid(0, s.indexOf(QLatin1String("="))).toLower().toLatin1();
|
||||
value = s.mid(s.indexOf(QLatin1String("=")) + 1);
|
||||
switch (getSnpType.value(key)) {
|
||||
|
@ -119,7 +119,7 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *
|
|||
}
|
||||
case ADD_CLASS:
|
||||
if (alertName.isEmpty()) {
|
||||
snoreDebug(SNORE_DEBUG) << "Error registering alert with empty name";
|
||||
qCDebug(SNORE) << "Error registering alert with empty name";
|
||||
break;
|
||||
}
|
||||
alert = Alert(alertName, icon);
|
||||
|
@ -129,7 +129,7 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *
|
|||
if (!snarl->m_applications.contains(client)) {
|
||||
snarl->m_applications[client] = Application(appName, icon);
|
||||
} else {
|
||||
snoreDebug(SNORE_DEBUG) << appName << "already registred";
|
||||
qCDebug(SNORE) << appName << "already registred";
|
||||
}
|
||||
break;
|
||||
case UNREGISTER:
|
||||
|
|
|
@ -52,7 +52,7 @@ SnarlNetworkFrontend::~SnarlNetworkFrontend()
|
|||
void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification)
|
||||
{
|
||||
if (notification.isActiveIn(this)) {
|
||||
snoreDebug(SNORE_DEBUG) << notification.closeReason();
|
||||
qCDebug(SNORE) << notification.closeReason();
|
||||
callback(notification, QStringLiteral("SNP/1.1/304/Notification acknowledged/"));
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ void SnarlNetworkFrontend::slotNotificationClosed(Snore::Notification notificati
|
|||
callback(notification, QStringLiteral("SNP/1.1/302/Notification cancelled/"));
|
||||
break;
|
||||
default:
|
||||
snoreDebug(SNORE_WARNING) << "Unhandled close reason" << notification.closeReason();
|
||||
qCWarning(SNORE) << "Unhandled close reason" << notification.closeReason();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ void SnarlNetworkFrontend::handleMessages()
|
|||
QTcpSocket *client = qobject_cast<QTcpSocket *>(sender());
|
||||
|
||||
QStringList messages(QString::fromLatin1(client->readAll()).trimmed().split(QStringLiteral("\r\n")));
|
||||
foreach(const QString & s, messages) {
|
||||
foreach (const QString &s, messages) {
|
||||
if (s.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#ifndef SNARLNETWORK_H
|
||||
#define SNARLNETWORK_H
|
||||
#include "libsnore/plugins/snorefrontend.h"
|
||||
#include "libsnore/log.h"
|
||||
#include "parser.h"
|
||||
|
||||
#include <QTcpSocket>
|
||||
|
@ -55,7 +54,7 @@ private:
|
|||
|
||||
inline void write(QTcpSocket *dest, const QString &msg)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << msg;
|
||||
qCDebug(SNORE) << msg;
|
||||
dest->write(msg.toLatin1());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "nma.h"
|
||||
#include "nmasettings.h"
|
||||
|
||||
#include "libsnore/log.h"
|
||||
#include "libsnore/utils.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
|
@ -52,8 +51,8 @@ void NotifyMyAndroid::slotNotify(Notification notification)
|
|||
|
||||
QNetworkReply *reply = m_manager.post(request, data.toUtf8().constData());
|
||||
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
||||
qCDebug(SNORE) << reply->error();
|
||||
qCDebug(SNORE) << reply->readAll();
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
});
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "pushover.h"
|
||||
#include "pushoversettings.h"
|
||||
|
||||
#include "libsnore/log.h"
|
||||
#include "libsnore/utils.h"
|
||||
#include "libsnore/notification/notification_p.h"
|
||||
|
||||
|
@ -61,8 +60,8 @@ void Pushover::slotNotify(Notification notification)
|
|||
|
||||
QHttpPart text;
|
||||
text.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"message\"")));
|
||||
snoreDebug(SNORE_DEBUG) << "Use Markup" << notification.constHints().value("use-markup").toBool();
|
||||
snoreDebug(SNORE_DEBUG) << "Message" << textString;
|
||||
qCDebug(SNORE) << "Use Markup" << notification.constHints().value("use-markup").toBool();
|
||||
qCDebug(SNORE) << "Message" << textString;
|
||||
text.setBody(textString.toUtf8().constData());
|
||||
mp->append(text);
|
||||
|
||||
|
@ -113,8 +112,8 @@ void Pushover::slotNotify(Notification notification)
|
|||
mp->setParent(reply);
|
||||
|
||||
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
||||
qCDebug(SNORE) << reply->error();
|
||||
qCDebug(SNORE) << reply->readAll();
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
});
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include "sound.h"
|
||||
#include "soundsettings.h"
|
||||
|
||||
#include "libsnore/log.h"
|
||||
|
||||
#include <QtMultimedia/QMediaPlayer>
|
||||
#include <QTimer>
|
||||
|
||||
|
@ -29,10 +27,10 @@ Sound::Sound():
|
|||
m_player(new QMediaPlayer(this))
|
||||
{
|
||||
// connect(m_player,QMediaPlayer::positionChanged,[](qint64 pos){
|
||||
// snoreDebug(SNORE_DEBUG) << "Player: " << pos;
|
||||
// qCDebug(SNORE) << "Player: " << pos;
|
||||
// });
|
||||
connect(m_player, &QMediaPlayer::stateChanged, [](QMediaPlayer::State state) {
|
||||
snoreDebug(SNORE_DEBUG) << "Player: " << state;
|
||||
qCDebug(SNORE) << "Player: " << state;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -58,10 +56,10 @@ void Sound::slotNotificationDisplayed(Snore::Notification notification)
|
|||
if (sound.isEmpty()) {
|
||||
sound = settingsValue(QLatin1String("Sound")).toString();
|
||||
}
|
||||
snoreDebug(SNORE_DEBUG) << "SoundFile:" << sound;
|
||||
qCDebug(SNORE) << "SoundFile:" << sound;
|
||||
if (!sound.isEmpty()) {
|
||||
m_player->setMedia(QUrl::fromLocalFile(sound));
|
||||
snoreDebug(SNORE_DEBUG) << "SoundFile:" << m_player->media().canonicalUrl();
|
||||
qCDebug(SNORE) << "SoundFile:" << m_player->media().canonicalUrl();
|
||||
m_player->play();
|
||||
QTimer *timeout = new QTimer(this);
|
||||
timeout->setSingleShot(true);
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "toasty.h"
|
||||
#include "toastysettings.h"
|
||||
|
||||
#include "libsnore/log.h"
|
||||
#include "libsnore/utils.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
|
@ -66,8 +65,8 @@ void Toasty::slotNotify(Notification notification)
|
|||
file->setParent(reply);
|
||||
|
||||
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
||||
qCDebug(SNORE) << reply->error();
|
||||
qCDebug(SNORE) << reply->readAll();
|
||||
reply->close();
|
||||
reply->deleteLater();
|
||||
});
|
||||
|
|
|
@ -46,7 +46,7 @@ bool setSetting(const QString &appName, SettingsType type, const QString &_key,
|
|||
|
||||
void listApps()
|
||||
{
|
||||
foreach(const QString & app, SettingsWindow::knownApps()) {
|
||||
foreach (const QString &app, SettingsWindow::knownApps()) {
|
||||
cout << qPrintable(app) << endl;
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ void listSettings(SettingsType type, const QString &application)
|
|||
prefix = QString();
|
||||
}
|
||||
cout << qPrintable(application) << endl;
|
||||
foreach(const QString & key, SettingsWindow::allSettingsKeysWithPrefix(
|
||||
Utils::normalizeSettingsKey(QLatin1String(""), type, prefix), settings, getAllKeys)) {
|
||||
foreach (const QString &key, SettingsWindow::allSettingsKeysWithPrefix(
|
||||
Utils::normalizeSettingsKey(QLatin1String(""), type, prefix), settings, getAllKeys)) {
|
||||
cout << " " << qPrintable(key) << ": " << qPrintable(settings.value(Utils::normalizeSettingsKey(key, type, prefix)).toString()) << endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,6 @@ void SettingsWindow::on_buttonBox_clicked(QAbstractButton *button)
|
|||
qApp->quit();
|
||||
break;
|
||||
default:
|
||||
snoreDebug(SNORE_WARNING) << "unhandled role" << button->text() << ui->buttonBox->buttonRole(button);
|
||||
qCWarning(SNORE) << "unhandled role" << button->text() << ui->buttonBox->buttonRole(button);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
QStringList groups = prefix.split(QLatin1Char('/'));
|
||||
QStringList out;
|
||||
|
||||
foreach(const QString & group, groups) {
|
||||
foreach (const QString &group, groups) {
|
||||
settings.beginGroup(group);
|
||||
}
|
||||
out = fun(settings);
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include <libsnore/snore.h>
|
||||
#include <libsnore/notification/notification.h>
|
||||
#include <libsnore/log.h>
|
||||
#include <libsnore/version.h>
|
||||
#include <libsnore/utils.h>
|
||||
|
||||
|
@ -39,7 +38,7 @@ using namespace std;
|
|||
|
||||
void bringToFront(QString pid)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << pid;
|
||||
qCDebug(SNORE) << pid;
|
||||
#ifdef Q_OS_WIN
|
||||
auto findWindowForPid = [](ulong pid) {
|
||||
// based on http://stackoverflow.com/a/21767578
|
||||
|
@ -112,7 +111,7 @@ int main(int argc, char *argv[])
|
|||
parser.addOption(_bringWindowToFront);
|
||||
|
||||
parser.process(app);
|
||||
snoreDebug(SNORE_DEBUG) << app.arguments();
|
||||
qCDebug(SNORE) << app.arguments();
|
||||
if (parser.isSet(title) && parser.isSet(message)) {
|
||||
SnoreCore &core = SnoreCore::instance();
|
||||
|
||||
|
|
Loading…
Reference in New Issue