diff --git a/CMakeLists.txt b/CMakeLists.txt index 48f8b026b..5b70067fe 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -245,13 +245,24 @@ if(USE_QT_5) endif(USE_QT_5) # Setup libraries. -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) +if(UNIX) + # On Unices, enable D-Bus support. + if(USE_QT_5) + find_package(Qt5 REQUIRED DBus Sql WebKit WebKitWidgets Widgets Xml XmlPatterns Network LinguistTools PrintSupport) + else(USE_QT_5) + set(QT_MIN_VERSION ${MINIMUM_QT_VERSION}) + 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. if(USE_QT_5) @@ -722,18 +733,33 @@ if(USE_QT_5) if(WIN32) target_link_libraries(${EXE_NAME} Qt5::WinMain) 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. - qt5_use_modules(${EXE_NAME} - Core - Widgets - Sql - Network - Xml - WebKit - WebKitWidgets - PrintSupport - ) + qt5_use_modules(${EXE_NAME} + Core + Widgets + Sql + Network + Xml + WebKit + WebKitWidgets + PrintSupport + ) + endif(UNIX) # Setup compilation for Qt 4. else(USE_QT_5) add_executable(${EXE_NAME} WIN32 MACOSX_BUNDLE @@ -744,16 +770,30 @@ else(USE_QT_5) ${APP_QM} ) - # 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} - ) + if(UNIX) + # Link modules from Qt. + target_link_libraries(${EXE_NAME} + ${QT_QTDBUS_LIBRARY} + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${QT_QTNETWORK_LIBRARY} + ${QT_QTSQL_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) # Installation stage. diff --git a/src/gui/notifications/notification.cpp b/src/gui/notifications/notification.cpp index 453c75125..366a35c24 100644 --- a/src/gui/notifications/notification.cpp +++ b/src/gui/notifications/notification.cpp @@ -33,10 +33,29 @@ #include #endif +#if defined(Q_OS_LINUX) +#include +#endif + 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_clickSlot(NULL) { + +#if defined(Q_OS_LINUX) + m_dBusInterface = new QDBusInterface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + QDBusConnection::sessionBus(), this); + + qDBusRegisterMetaType(); + + if (m_dBusInterface->isValid()) { + // We have correct connection to interface. + //m_dBusInterface.connect() + } +#endif + setupWidget(); loadSettings(); } @@ -45,6 +64,56 @@ Notification::~Notification() { 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(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() { 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_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 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) { // Connect invokation target. connect(this, SIGNAL(clicked()), m_clickTarget, m_clickSlot, Qt::QueuedConnection); diff --git a/src/gui/notifications/notification.h b/src/gui/notifications/notification.h index 6ca6b9c9c..bb5f2a931 100644 --- a/src/gui/notifications/notification.h +++ b/src/gui/notifications/notification.h @@ -23,6 +23,19 @@ #include +#if defined(Q_OS_LINUX) +#include +#include + +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 { Q_OBJECT @@ -77,6 +90,10 @@ class Notification : public QWidget { QObject *m_clickTarget; const char *m_clickSlot; + +#if defined(Q_OS_LINUX) + QDBusInterface *m_dBusInterface; +#endif }; #endif // NOTIFICATION_H