Some preps for D-Bus notifications.
This commit is contained in:
parent
52db6b5ba4
commit
4287b4ccd1
@ -245,13 +245,24 @@ if(USE_QT_5)
|
|||||||
endif(USE_QT_5)
|
endif(USE_QT_5)
|
||||||
|
|
||||||
# Setup libraries.
|
# Setup libraries.
|
||||||
if(USE_QT_5)
|
if(UNIX)
|
||||||
find_package(Qt5 REQUIRED Sql WebKit WebKitWidgets Widgets Xml XmlPatterns Network LinguistTools PrintSupport)
|
# On Unices, enable D-Bus support.
|
||||||
else(USE_QT_5)
|
if(USE_QT_5)
|
||||||
set(QT_MIN_VERSION ${MINIMUM_QT_VERSION})
|
find_package(Qt5 REQUIRED DBus Sql WebKit WebKitWidgets Widgets Xml XmlPatterns Network LinguistTools PrintSupport)
|
||||||
find_package(Qt4 REQUIRED QtCore QtGui QtSql QtNetwork QtWebkit QtXml QtXmlPatterns)
|
else(USE_QT_5)
|
||||||
include(${QT_USE_FILE})
|
set(QT_MIN_VERSION ${MINIMUM_QT_VERSION})
|
||||||
endif(USE_QT_5)
|
find_package(Qt4 REQUIRED QtDBus QtCore QtGui QtSql QtNetwork QtWebkit QtXml QtXmlPatterns)
|
||||||
|
include(${QT_USE_FILE})
|
||||||
|
endif(USE_QT_5)
|
||||||
|
else(UNIX)
|
||||||
|
if(USE_QT_5)
|
||||||
|
find_package(Qt5 REQUIRED Sql WebKit WebKitWidgets Widgets Xml XmlPatterns Network LinguistTools PrintSupport)
|
||||||
|
else(USE_QT_5)
|
||||||
|
set(QT_MIN_VERSION ${MINIMUM_QT_VERSION})
|
||||||
|
find_package(Qt4 REQUIRED QtCore QtGui QtSql QtNetwork QtWebkit QtXml QtXmlPatterns)
|
||||||
|
include(${QT_USE_FILE})
|
||||||
|
endif(USE_QT_5)
|
||||||
|
endif(UNIX)
|
||||||
|
|
||||||
# Configure QStringBuilder behavior.
|
# Configure QStringBuilder behavior.
|
||||||
if(USE_QT_5)
|
if(USE_QT_5)
|
||||||
@ -722,18 +733,33 @@ if(USE_QT_5)
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(${EXE_NAME} Qt5::WinMain)
|
target_link_libraries(${EXE_NAME} Qt5::WinMain)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
|
if(UNIX)
|
||||||
|
# Use modules from Qt.
|
||||||
|
qt5_use_modules(${EXE_NAME}
|
||||||
|
DBus
|
||||||
|
Core
|
||||||
|
Widgets
|
||||||
|
Sql
|
||||||
|
Network
|
||||||
|
Xml
|
||||||
|
WebKit
|
||||||
|
WebKitWidgets
|
||||||
|
PrintSupport
|
||||||
|
)
|
||||||
|
else(UNIX)
|
||||||
# Use modules from Qt.
|
# Use modules from Qt.
|
||||||
qt5_use_modules(${EXE_NAME}
|
qt5_use_modules(${EXE_NAME}
|
||||||
Core
|
Core
|
||||||
Widgets
|
Widgets
|
||||||
Sql
|
Sql
|
||||||
Network
|
Network
|
||||||
Xml
|
Xml
|
||||||
WebKit
|
WebKit
|
||||||
WebKitWidgets
|
WebKitWidgets
|
||||||
PrintSupport
|
PrintSupport
|
||||||
)
|
)
|
||||||
|
endif(UNIX)
|
||||||
# Setup compilation for Qt 4.
|
# Setup compilation for Qt 4.
|
||||||
else(USE_QT_5)
|
else(USE_QT_5)
|
||||||
add_executable(${EXE_NAME} WIN32 MACOSX_BUNDLE
|
add_executable(${EXE_NAME} WIN32 MACOSX_BUNDLE
|
||||||
@ -744,16 +770,30 @@ else(USE_QT_5)
|
|||||||
${APP_QM}
|
${APP_QM}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Link modules from Qt.
|
if(UNIX)
|
||||||
target_link_libraries(${EXE_NAME}
|
# Link modules from Qt.
|
||||||
${QT_QTCORE_LIBRARY}
|
target_link_libraries(${EXE_NAME}
|
||||||
${QT_QTGUI_LIBRARY}
|
${QT_QTDBUS_LIBRARY}
|
||||||
${QT_QTNETWORK_LIBRARY}
|
${QT_QTCORE_LIBRARY}
|
||||||
${QT_QTSQL_LIBRARY}
|
${QT_QTGUI_LIBRARY}
|
||||||
${QT_QTXML_LIBRARY}
|
${QT_QTNETWORK_LIBRARY}
|
||||||
${QT_QTMAIN_LIBRARY}
|
${QT_QTSQL_LIBRARY}
|
||||||
${QT_QTWEBKIT_LIBRARY}
|
${QT_QTXML_LIBRARY}
|
||||||
)
|
${QT_QTMAIN_LIBRARY}
|
||||||
|
${QT_QTWEBKIT_LIBRARY}
|
||||||
|
)
|
||||||
|
else(UNIX)
|
||||||
|
# Link modules from Qt.
|
||||||
|
target_link_libraries(${EXE_NAME}
|
||||||
|
${QT_QTCORE_LIBRARY}
|
||||||
|
${QT_QTGUI_LIBRARY}
|
||||||
|
${QT_QTNETWORK_LIBRARY}
|
||||||
|
${QT_QTSQL_LIBRARY}
|
||||||
|
${QT_QTXML_LIBRARY}
|
||||||
|
${QT_QTMAIN_LIBRARY}
|
||||||
|
${QT_QTWEBKIT_LIBRARY}
|
||||||
|
)
|
||||||
|
endif(UNIX)
|
||||||
endif(USE_QT_5)
|
endif(USE_QT_5)
|
||||||
|
|
||||||
# Installation stage.
|
# Installation stage.
|
||||||
|
@ -33,10 +33,29 @@
|
|||||||
#include <Carbon/Carbon.h>
|
#include <Carbon/Carbon.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
#include <QtDBus>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Notification::Notification() : QWidget(0), m_title(QString()), m_text(QString()), m_icon(QPixmap()), m_screen(-1),
|
Notification::Notification() : QWidget(0), m_title(QString()), m_text(QString()), m_icon(QPixmap()), m_screen(-1),
|
||||||
m_width(-1), m_height(-1), m_padding(5), m_widgetMargin(2 * m_padding), m_timerId(0), m_clickTarget(NULL),
|
m_width(-1), m_height(-1), m_padding(5), m_widgetMargin(2 * m_padding), m_timerId(0), m_clickTarget(NULL),
|
||||||
m_clickSlot(NULL) {
|
m_clickSlot(NULL) {
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
m_dBusInterface = new QDBusInterface("org.freedesktop.Notifications",
|
||||||
|
"/org/freedesktop/Notifications",
|
||||||
|
"org.freedesktop.Notifications",
|
||||||
|
QDBusConnection::sessionBus(), this);
|
||||||
|
|
||||||
|
qDBusRegisterMetaType<QImage>();
|
||||||
|
|
||||||
|
if (m_dBusInterface->isValid()) {
|
||||||
|
// We have correct connection to interface.
|
||||||
|
//m_dBusInterface.connect()
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
setupWidget();
|
setupWidget();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
}
|
}
|
||||||
@ -45,6 +64,56 @@ Notification::~Notification() {
|
|||||||
qDebug("Destroying Notification instance.");
|
qDebug("Destroying Notification instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
QDBusArgument &operator<<(QDBusArgument& arg, const QImage& image) {
|
||||||
|
if(image.isNull()) {
|
||||||
|
arg.beginStructure();
|
||||||
|
arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
|
||||||
|
arg.endStructure();
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage scaled = image.scaledToHeight(100, Qt::SmoothTransformation);
|
||||||
|
scaled = scaled.convertToFormat(QImage::Format_ARGB32);
|
||||||
|
|
||||||
|
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
|
||||||
|
// ABGR -> ARGB
|
||||||
|
QImage i = scaled.rgbSwapped();
|
||||||
|
#else
|
||||||
|
// ABGR -> GBAR
|
||||||
|
QImage i(scaled.size(), scaled.format());
|
||||||
|
for (int y = 0; y < i.height(); ++y) {
|
||||||
|
QRgb* p = (QRgb*) scaled.scanLine(y);
|
||||||
|
QRgb* q = (QRgb*) i.scanLine(y);
|
||||||
|
QRgb* end = p + scaled.width();
|
||||||
|
while (p < end) {
|
||||||
|
*q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p));
|
||||||
|
p++;
|
||||||
|
q++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
arg.beginStructure();
|
||||||
|
arg << i.width();
|
||||||
|
arg << i.height();
|
||||||
|
arg << i.bytesPerLine();
|
||||||
|
arg << i.hasAlphaChannel();
|
||||||
|
int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3);
|
||||||
|
arg << i.depth() / channels;
|
||||||
|
arg << channels;
|
||||||
|
arg << QByteArray(reinterpret_cast<const char*>(i.bits()), i.byteCount());
|
||||||
|
arg.endStructure();
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDBusArgument &operator>>(const QDBusArgument& arg, QImage&) {
|
||||||
|
// This is needed to link but shouldn't be called.
|
||||||
|
Q_ASSERT(0);
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool Notification::areNotificationsActivated() {
|
bool Notification::areNotificationsActivated() {
|
||||||
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::UseFancyNotifications)).toBool();
|
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::UseFancyNotifications)).toBool();
|
||||||
}
|
}
|
||||||
@ -60,6 +129,29 @@ void Notification::notify(const QString &text, const QString &title, const QIcon
|
|||||||
m_title = title;
|
m_title = title;
|
||||||
m_icon = icon.pixmap(NOTIFICATION_ICON_SIZE, NOTIFICATION_ICON_SIZE);
|
m_icon = icon.pixmap(NOTIFICATION_ICON_SIZE, NOTIFICATION_ICON_SIZE);
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
/*
|
||||||
|
if (m_dBusInterface->isValid()) {
|
||||||
|
QVariantMap hints;
|
||||||
|
hints["image-data"] = QImage();// ;
|
||||||
|
|
||||||
|
QList<QVariant> argument_list;
|
||||||
|
argument_list << APP_NAME; // app_name
|
||||||
|
argument_list << (uint)0; // replace_id
|
||||||
|
argument_list << ""; // app_icon
|
||||||
|
argument_list << "aaa"; // summary
|
||||||
|
argument_list << "bbb"; // body
|
||||||
|
argument_list << QStringList(); // actions
|
||||||
|
argument_list << hints; // hints
|
||||||
|
argument_list << (int)1000; // timeout in ms
|
||||||
|
|
||||||
|
//m_dBusInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", argument_list);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#endif
|
||||||
|
|
||||||
if (m_clickTarget != NULL && m_clickSlot != NULL) {
|
if (m_clickTarget != NULL && m_clickSlot != NULL) {
|
||||||
// Connect invokation target.
|
// Connect invokation target.
|
||||||
connect(this, SIGNAL(clicked()), m_clickTarget, m_clickSlot, Qt::QueuedConnection);
|
connect(this, SIGNAL(clicked()), m_clickTarget, m_clickSlot, Qt::QueuedConnection);
|
||||||
|
@ -23,6 +23,19 @@
|
|||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
#include <QtDBus/QDBusArgument>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
|
class QDBusInterface;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
QDBusArgument &operator<<(QDBusArgument& arg, const QImage& image);
|
||||||
|
const QDBusArgument &operator>>(const QDBusArgument& arg, QImage&);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class Notification : public QWidget {
|
class Notification : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -77,6 +90,10 @@ class Notification : public QWidget {
|
|||||||
|
|
||||||
QObject *m_clickTarget;
|
QObject *m_clickTarget;
|
||||||
const char *m_clickSlot;
|
const char *m_clickSlot;
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
QDBusInterface *m_dBusInterface;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NOTIFICATION_H
|
#endif // NOTIFICATION_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user