File indexing completed on 2024-05-26 04:48:41

0001 /*
0002     SnoreNotify is a Notification Framework based on Qt
0003     Copyright (C) 2013-2015  Hannah von Reth <vonreth@kde.org>
0004 
0005     SnoreNotify is free software: you can redistribute it and/or modify
0006     it under the terms of the GNU Lesser General Public License as published by
0007     the Free Software Foundation, either version 3 of the License, or
0008     (at your option) any later version.
0009 
0010     SnoreNotify is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013     GNU Lesser General Public License for more details.
0014 
0015     You should have received a copy of the GNU Lesser General Public License
0016     along with SnoreNotify.  If not, see <http://www.gnu.org/licenses/>.
0017 */
0018 
0019 #ifndef SNARLNETWORK_H
0020 #define SNARLNETWORK_H
0021 #include "libsnore/plugins/snorefrontend.h"
0022 #include "parser.h"
0023 
0024 #include <QTcpSocket>
0025 #include <QTcpServer>
0026 
0027 class SnarlNetworkFrontend : public Snore::SnoreFrontend
0028 {
0029     Q_OBJECT
0030     Q_INTERFACES(Snore::SnoreFrontend)
0031     Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0" FILE "snore_plugin.json")
0032     friend class Parser;
0033 public:
0034     static const int port = 9887;
0035 
0036 public:
0037     SnarlNetworkFrontend();
0038     ~SnarlNetworkFrontend();
0039 
0040 public Q_SLOTS:
0041     void slotActionInvoked(Snore::Notification notification) override;
0042     void slotNotificationClosed(Snore::Notification notification) override;
0043 
0044 private Q_SLOTS:
0045     void handleConnection();
0046     void handleMessages();
0047 
0048 private:
0049     QTcpServer *tcpServer;
0050     Parser *parser;
0051     QHash<QTcpSocket *, Snore::Application> m_applications;
0052 
0053     void callback(Snore::Notification &sn, const QString &msg);
0054 
0055     inline void write(QTcpSocket *dest, const QString &msg)
0056     {
0057         qCDebug(SNORE) << msg;
0058         dest->write(msg.toLatin1());
0059     }
0060 
0061 };
0062 
0063 #endif //SNARLNETWORK_H