diff --git a/src/notifybypopup.h b/src/notifybypopup.h --- a/src/notifybypopup.h +++ b/src/notifybypopup.h @@ -29,7 +29,6 @@ #include class KNotification; -class KPassivePopup; class QDBusPendingCallWatcher; class NotifyByPopupPrivate; @@ -45,12 +44,8 @@ void close(KNotification *notification) override; void update(KNotification *notification, KNotifyConfig *config) override; -protected: - void timerEvent(QTimerEvent *event) override; private Q_SLOTS: - void onPassivePopupDestroyed(); - void onPassivePopupLinkClicked(const QString &link); // slot to catch appearance or disappearance of Notifications DBus service void onServiceOwnerChanged(const QString &, const QString &, const QString &); // slot which gets called when DBus signals that some notification action was invoked diff --git a/src/notifybypopup.cpp b/src/notifybypopup.cpp --- a/src/notifybypopup.cpp +++ b/src/notifybypopup.cpp @@ -24,17 +24,14 @@ #include "notifybypopup.h" #include "imageconverter.h" -#include "kpassivepopup.h" #include "knotifyconfig.h" #include "knotification.h" #include "debug_p.h" -#include #include #include #include #include -#include #include #include #include @@ -46,10 +43,8 @@ #include #include #include -#include #include #include -#include #include #include @@ -61,11 +56,6 @@ class NotifyByPopupPrivate { public: NotifyByPopupPrivate(NotifyByPopup *parent) : q(parent) {} - /** - * @internal - * Fills the KPassivePopup with data - */ - void fillPopup(KPassivePopup *popup, KNotification *notification, const KNotifyConfig &config); /** * Removes HTML from a given string. Replaces line breaks with \n and * HTML entities by their 'normal forms'. @@ -94,7 +84,6 @@ void getAppCaptionAndIconName(const KNotifyConfig &config, QString *appCaption, QString *iconName); /* * Query the dbus server for notification capabilities - * If no DBus server is present, use fallback capabilities for KPassivePopup */ void queryPopupServerCapabilities(); @@ -127,11 +116,6 @@ */ bool dbusServiceCapCacheDirty; - /** - * Keeps the map of notifications done in KPassivePopup - */ - QMap passivePopups; - /* * As we communicate with the notification server over dbus * we use only ids, this is for fast KNotifications lookup @@ -158,7 +142,6 @@ : KNotificationPlugin(parent), d(new NotifyByPopupPrivate(this)) { - d->animationTimer = 0; d->dbusServiceExists = false; d->dbusServiceCapCacheDirty = true; d->nextPosition = -1; @@ -182,10 +165,6 @@ NotifyByPopup::~NotifyByPopup() { - for (KPassivePopup *p : qAsConst(d->passivePopups)) { - p->deleteLater(); - } - delete d; } @@ -196,7 +175,7 @@ void NotifyByPopup::notify(KNotification *notification, const KNotifyConfig ¬ifyConfig) { - if (d->passivePopups.contains(notification) || d->galagoNotifications.contains(notification->id())) { + if (d->galagoNotifications.contains(notification->id())) { // notification is already on the screen, do nothing finish(notification); return; @@ -217,118 +196,14 @@ } return; } - - // Persistent => 0 == infinite timeout - // CloseOnTimeout => -1 == let the server decide - int timeout = (notification->flags() & KNotification::Persistent) ? 0 : -1; - - // Check if this object lives in the GUI thread and return if it doesn't - // as Qt cannot create/handle widgets in non-GUI threads - if (QThread::currentThread() != qApp->thread()) { - qCWarning(LOG_KNOTIFICATIONS) << "KNotification did not detect any running org.freedesktop.Notifications server and fallback notifications cannot be used from non-GUI thread!"; - return; - } - - if (!qobject_cast(QCoreApplication::instance())) { - qCWarning(LOG_KNOTIFICATIONS) << "KNotification did not detect any running org.freedesktop.Notifications server and fallback notifications cannot be used without a QApplication!"; - return; - } - - // last fallback - display the popup using KPassivePopup - KPassivePopup *pop = new KPassivePopup(notification->widget()); - d->passivePopups.insert(notification, pop); - d->fillPopup(pop, notification, notifyConfig); - - QRect screen = QGuiApplication::primaryScreen()->availableGeometry(); - if (d->nextPosition == -1) { - d->nextPosition = screen.top(); - } - pop->setAutoDelete(true); - connect(pop, &QObject::destroyed, this, &NotifyByPopup::onPassivePopupDestroyed); - - pop->setTimeout(timeout); - pop->adjustSize(); - pop->show(QPoint(screen.left() + screen.width()/2 - pop->width()/2 , d->nextPosition)); - d->nextPosition += pop->height(); -} - -void NotifyByPopup::onPassivePopupDestroyed() -{ - const QObject *destroyedPopup = sender(); - - if (!destroyedPopup) { - return; - } - - for (QMap::iterator it = d->passivePopups.begin(); it != d->passivePopups.end(); ++it) { - QObject *popup = it.value(); - if (popup && popup == destroyedPopup) { - finish(it.key()); - d->passivePopups.remove(it.key()); - break; - } - } - - //relocate popup - if (!d->animationTimer) { - d->animationTimer = startTimer(10); - } -} - -void NotifyByPopup::timerEvent(QTimerEvent *event) -{ - if (event->timerId() != d->animationTimer) { - KNotificationPlugin::timerEvent(event); - return; - } - - bool cont = false; - QRect screen = QGuiApplication::primaryScreen()->availableGeometry(); - d->nextPosition = screen.top(); - - for (KPassivePopup *popup : qAsConst(d->passivePopups)) - { - int y = popup->pos().y(); - if (y > d->nextPosition) { - y = qMax(y - 5, d->nextPosition); - d->nextPosition = y + popup->height(); - cont = cont || y != d->nextPosition; - popup->move(popup->pos().x(), y); - } else { - d->nextPosition += popup->height(); - } - } - - if (!cont) { - killTimer(d->animationTimer); - d->animationTimer = 0; - } -} - -void NotifyByPopup::onPassivePopupLinkClicked(const QString &link) -{ - unsigned int id = link.section(QLatin1Char('/') , 0 , 0).toUInt(); - unsigned int action = link.section(QLatin1Char('/') , 1 , 1).toUInt(); - - if (id == 0 || action == 0) { - return; - } - - emit actionInvoked(id, action); } void NotifyByPopup::close(KNotification *notification) { if (d->dbusServiceExists) { d->closeGalagoNotification(notification); } - if (d->passivePopups.contains(notification)) { - // this will call onPassivePopupDestroyed() - // which will call finish() on the notification - d->passivePopups[notification]->deleteLater(); - } - QMutableListIterator > iter(d->notificationQueue); while (iter.hasNext()) { auto &item = iter.next(); @@ -345,12 +220,6 @@ void NotifyByPopup::update(KNotification *notification, const KNotifyConfig ¬ifyConfig) { - if (d->passivePopups.contains(notification)) { - KPassivePopup *p = d->passivePopups[notification]; - d->fillPopup(p, notification, notifyConfig); - return; - } - // if Notifications DBus service exists on bus, // it'll be used instead if (d->dbusServiceExists) { @@ -371,13 +240,7 @@ emit finished(n); } } - QMap::const_iterator i = d->passivePopups.constBegin(); - while (i != d->passivePopups.constEnd()) { - emit finished(i.key()); - ++i; - } d->galagoNotifications.clear(); - d->passivePopups.clear(); d->dbusServiceCapCacheDirty = true; d->popupServerCapabilities.clear(); @@ -490,79 +353,6 @@ } } -void NotifyByPopupPrivate::fillPopup(KPassivePopup *popup, KNotification *notification, const KNotifyConfig ¬ifyConfig) -{ - QString appCaption; - QString iconName; - getAppCaptionAndIconName(notifyConfig, &appCaption, &iconName); - - // If we're at this place, it means there's no D-Bus service for notifications - // so we don't need to do D-Bus query for the capabilities. - // If queryPopupServerCapabilities() finds no service, it sets the KPassivePopup - // capabilities immediately, so we don't need to wait for callback as in the case - // of galago notifications - queryPopupServerCapabilities(); - - int iconDimension = QFontMetrics(QFont()).height(); - QPixmap appIcon = QIcon::fromTheme(iconName).pixmap(iconDimension, iconDimension); - - QWidget *vb = popup->standardView(notification->title().isEmpty() ? appCaption : notification->title(), - notification->pixmap().isNull() ? notification->text() : QString(), - appIcon); - - if (!notification->pixmap().isNull()) { - const QPixmap pix = notification->pixmap(); - QHBoxLayout *hbox = new QHBoxLayout(vb); - - QLabel *pil = new QLabel(); - pil->setPixmap(pix); - pil->setScaledContents(true); - - if (pix.height() > 80 && pix.height() > pix.width()) { - pil->setMaximumHeight(80); - pil->setMaximumWidth(80 * pix.width() / pix.height()); - } else if(pix.width() > 80 && pix.height() <= pix.width()) { - pil->setMaximumWidth(80); - pil->setMaximumHeight(80*pix.height()/pix.width()); - } - - hbox->addWidget(pil); - - QVBoxLayout *vb2 = new QVBoxLayout(vb); - QLabel *msg = new QLabel(notification->text()); - msg->setAlignment(Qt::AlignLeft); - - vb2->addWidget(msg); - - hbox->addLayout(vb2); - - vb->layout()->addItem(hbox); - } - - - if (!notification->actions().isEmpty()) { - QString linkCode = QStringLiteral("

"); - int i = 0; - const auto actionList = notification->actions(); - for (const QString &it : actionList) { - i++; - linkCode += QStringLiteral(" %3").arg(QString::number(notification->id()), QString::number(i), it.toHtmlEscaped()); - } - - linkCode += QLatin1String("

"); - QLabel *link = new QLabel(linkCode , vb ); - link->setTextInteractionFlags(Qt::LinksAccessibleByMouse); - link->setOpenExternalLinks(false); - //link->setAlignment( AlignRight ); - QObject::connect(link, &QLabel::linkActivated, - q, &NotifyByPopup::onPassivePopupLinkClicked); - QObject::connect(link, &QLabel::linkActivated, - popup, &QWidget::hide); - } - - popup->setView( vb ); -} - bool NotifyByPopupPrivate::sendNotificationToGalagoServer(KNotification *notification, const KNotifyConfig ¬ifyConfig_nocheck, bool update) { uint updateId = galagoNotifications.key(notification, 0); @@ -749,12 +539,6 @@ void NotifyByPopupPrivate::queryPopupServerCapabilities() { - if (!dbusServiceExists) { - // Return capabilities of the KPassivePopup implementation - popupServerCapabilities = QStringList() << QStringLiteral("actions") << QStringLiteral("body") << QStringLiteral("body-hyperlinks") - << QStringLiteral("body-markup") << QStringLiteral("icon-static"); - } - if (dbusServiceCapCacheDirty) { QDBusMessage m = QDBusMessage::createMethodCall(QString::fromLatin1(dbusServiceName), QString::fromLatin1(dbusPath),