diff --git a/src/libsnore/notification/icon_p.cpp b/src/libsnore/notification/icon_p.cpp index 1fa9d95..5d904dc 100644 --- a/src/libsnore/notification/icon_p.cpp +++ b/src/libsnore/notification/icon_p.cpp @@ -18,6 +18,7 @@ #include "icon_p.h" #include "../snore_p.h" +#include "../utils.h" #include #include @@ -30,7 +31,7 @@ QSet IconData::s_localImageCache; IconData::IconData(const QString &url): m_url(url), - m_hash(SnoreCorePrivate::computeHash(m_url.toLatin1())), + m_hash(Utils::computeMD5Hash(m_url.toLatin1())), m_localUrl(createLocalFileName(m_hash)), m_isLocalFile(false), m_isResource(m_url.startsWith(":/") || m_url.startsWith("qrc:/")) @@ -80,7 +81,7 @@ IconData::IconData(const QString &url): IconData::IconData(const QImage &img): m_img(img), - m_hash(SnoreCorePrivate::computeHash(Icon::dataFromImage(img))), + m_hash(Utils::computeMD5Hash(Icon::dataFromImage(img))), m_localUrl(createLocalFileName(m_hash)), m_isLocalFile(false), m_isResource(false), diff --git a/src/libsnore/snore.h b/src/libsnore/snore.h index ce31ac8..3d2da06 100644 --- a/src/libsnore/snore.h +++ b/src/libsnore/snore.h @@ -29,8 +29,6 @@ #include #include -#include -#include /** * Snore is a platform independent Qt notification framework. @@ -182,21 +180,6 @@ private: }; -/** - * - * @param string A string to decode of if needed. - * @return if the string was rhichtext or html encoded a decoded string, else the original string. - */ - -static inline QString toPlainText(const QString &string) -{ - if (Qt::mightBeRichText(string)) { - return QTextDocumentFragment::fromHtml(string).toPlainText(); - } else { - return string; - } -} - } #endif // SNORESERVER_H diff --git a/src/libsnore/snore_p.h b/src/libsnore/snore_p.h index 5231caf..37d15c0 100644 --- a/src/libsnore/snore_p.h +++ b/src/libsnore/snore_p.h @@ -25,7 +25,6 @@ #include #include -#include namespace Snore { @@ -35,11 +34,6 @@ class SNORE_EXPORT SnoreCorePrivate : public QObject Q_OBJECT public: - static inline QString computeHash(const QByteArray &data) - { - return QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex(); - } - static void registerMetaTypes(); /** diff --git a/src/libsnore/utils.h b/src/libsnore/utils.h index a7fb49b..8a66833 100644 --- a/src/libsnore/utils.h +++ b/src/libsnore/utils.h @@ -21,6 +21,9 @@ #include "snore_exports.h" #include +#include +#include +#include namespace Snore { class SNORE_EXPORT Utils : public QObject { @@ -29,9 +32,50 @@ public: Utils(QObject *parent = nullptr); ~Utils(); + /** + * Raise a window to the front. + * @param wid the Id of the window to raise. + * @param focus whether the window should request focus. + */ //TODO: make Wid usable with the meta system and change signature. Q_INVOKABLE static void bringWindowToFront(qlonglong wid, bool focus); + /** + * + * @param string A string to decode if needed. + * @return if the string was rhichtext or html encoded a decoded string, else the original string. + */ + static inline QString toPlainText(const QString &string) + { + if (Qt::mightBeRichText(string)) { + return QTextDocumentFragment::fromHtml(string).toPlainText(); + } else { + return string; + } + } + + /** + * + * @param string A string to encode if needed. + * @return if the string was rhichtext html encode string is returnd otherwise the original string. + */ + static inline QString toHtml(const QString &string) + { + if (Qt::mightBeRichText(string)) { + return QTextDocumentFragment::fromHtml(string).toHtml("UTF-8"); + } else { + return string; + } + } + + /** + * Computes a md5 hash of the provided data. + */ + static inline QString computeMD5Hash(const QByteArray &data) + { + return QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex(); + } + }; } diff --git a/src/plugins/backends/growl/growlbackend.cpp b/src/plugins/backends/growl/growlbackend.cpp index 0ab92e9..f8cdf57 100644 --- a/src/plugins/backends/growl/growlbackend.cpp +++ b/src/plugins/backends/growl/growlbackend.cpp @@ -21,6 +21,7 @@ #include "libsnore/snore.h" #include "libsnore/snore_p.h" +#include "libsnore/utils.h" using namespace Snore; @@ -87,11 +88,11 @@ 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 << Snore::toPlainText(notification.title()); + snoreDebug(SNORE_DEBUG) << "Notify Growl:" << notification.application() << alert << Utils::toPlainText(notification.title()); GrowlNotificationData data(alert.toUtf8().constData(), notification.id(), - Snore::toPlainText(notification.title()).toUtf8().constData(), - Snore::toPlainText(notification.text()).toUtf8().constData()); + Utils::toPlainText(notification.title()).toUtf8().constData(), + Utils::toPlainText(notification.text()).toUtf8().constData()); if (notification.icon().isValid()) { data.setIcon(notification.icon().localUrl().toUtf8().constData()); diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index 37e995b..045e9fd 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -21,6 +21,7 @@ #include "libsnore/snore.h" #include "libsnore/snore_p.h" +#include "libsnore/utils.h" #include "libsnore/plugins/plugins.h" #include "libsnore/plugins/snorebackend.h" #include "libsnore/notification/notification_p.h" @@ -216,8 +217,8 @@ void SnarlBackend::slotNotify(Notification notification) if (!notification.isUpdate()) { id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(), - Snore::toPlainText(notification.title()).toUtf8().constData(), - Snore::toPlainText(notification.text()).toUtf8().constData(), + Utils::toPlainText(notification.title()).toUtf8().constData(), + Utils::toPlainText(notification.text()).toUtf8().constData(), notification.timeout(), notification.icon().isLocalFile() ? notification.icon().localUrl().toUtf8().constData() : 0, !notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0, @@ -233,8 +234,8 @@ void SnarlBackend::slotNotify(Notification notification) id = notification.old().hints().privateValue(this, "id").toUInt(); snarlInterface->Update(id, notification.alert().name().toUtf8().constData(), - Snore::toPlainText(notification.title()).toUtf8().constData(), - Snore::toPlainText(notification.text()).toUtf8().constData(), + Utils::toPlainText(notification.title()).toUtf8().constData(), + Utils::toPlainText(notification.text()).toUtf8().constData(), notification.timeout(), notification.icon().isLocalFile() ? notification.icon().localUrl().toUtf8().constData() : 0, !notification.icon().isLocalFile() ? Icon::dataFromImage(notification.icon().image()).toBase64().constData() : 0, diff --git a/src/plugins/backends/snoretoast/snoretoast.cpp b/src/plugins/backends/snoretoast/snoretoast.cpp index 26662fc..b0962de 100644 --- a/src/plugins/backends/snoretoast/snoretoast.cpp +++ b/src/plugins/backends/snoretoast/snoretoast.cpp @@ -1,6 +1,8 @@ #include "snoretoast.h" #include "libsnore/snore.h" #include "libsnore/snore_p.h" +#include "libsnore/utils.h" + #include "libsnore/plugins/plugins.h" #include "libsnore/plugins/snorebackend.h" @@ -41,9 +43,9 @@ void SnoreToast::slotNotify(Notification notification) QStringList arguements; arguements << "-t" - << Snore::toPlainText(notification.title()) + << Utils::toPlainText(notification.title()) << "-m" - << Snore::toPlainText(notification.text()); + << Utils::toPlainText(notification.text()); if (notification.icon().isValid()) { arguements << "-p" << QDir::toNativeSeparators(notification.icon().localUrl()); diff --git a/src/plugins/backends/trayicon/trayiconnotifer.cpp b/src/plugins/backends/trayicon/trayiconnotifer.cpp index 3a078a7..4238729 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.cpp +++ b/src/plugins/backends/trayicon/trayiconnotifer.cpp @@ -1,6 +1,7 @@ #include "trayiconnotifer.h" #include "libsnore/snore.h" #include "libsnore/snore_p.h" +#include "libsnore/utils.h" #include using namespace Snore; @@ -83,7 +84,7 @@ void TrayIconNotifer::displayNotification(QSystemTrayIcon *icon) m_currentlyDisplaying = true; Notification notification = m_notificationQue.takeFirst(); m_displayed = notification.id(); - icon->showMessage(Snore::toPlainText(notification.title()), Snore::toPlainText(notification.text()), QSystemTrayIcon::NoIcon, notification.timeout() * 1000); + icon->showMessage(Utils::toPlainText(notification.title()), Utils::toPlainText(notification.text()), QSystemTrayIcon::NoIcon, notification.timeout() * 1000); startTimeout(notification); } diff --git a/src/plugins/secondary_backends/toasty/toasty.cpp b/src/plugins/secondary_backends/toasty/toasty.cpp index a64ac56..4c0953b 100644 --- a/src/plugins/secondary_backends/toasty/toasty.cpp +++ b/src/plugins/secondary_backends/toasty/toasty.cpp @@ -17,6 +17,7 @@ */ #include "toasty.h" #include "toastysettings.h" +#include "libsnore/utils.h" #include #include @@ -45,14 +46,15 @@ void Toasty::slotNotify(Notification notification) } QNetworkRequest request(QString("http://api.supertoasty.com/notify/%1").arg(key)); QHttpMultiPart *mp = new QHttpMultiPart(QHttpMultiPart::FormDataType); + QHttpPart title; title.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"title\"")); - title.setBody(Snore::toPlainText(notification.title()).toUtf8().constData()); + title.setBody(Utils::toPlainText(notification.title()).toUtf8().constData()); mp->append(title); QHttpPart text; text.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\"")); - text.setBody(Snore::toPlainText(notification.text()).toUtf8().constData()); + text.setBody(Utils::toPlainText(notification.text()).toUtf8().constData()); mp->append(text); QHttpPart app; @@ -89,5 +91,5 @@ void Toasty::slotNotify(Notification notification) PluginSettingsWidget *Toasty::settingsWidget() { - return new ToastySettings(this); + return new NotifyMyAndroidSettings(this); }