diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 449f82a..c7abc82 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(qt-lib) +add_subdirectory(qt) diff --git a/examples/qt/CMakeLists.txt b/examples/qt/CMakeLists.txt index 2076f20..2f82e72 100644 --- a/examples/qt/CMakeLists.txt +++ b/examples/qt/CMakeLists.txt @@ -1,14 +1,14 @@ cmake_minimum_required(VERSION 3.0.0) -project(SnoreToastQtExample VERSION 0.1 LANGUAGES CXX) +project(SnoreToastCliQtExample VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) find_package(Qt5Core) find_package(Qt5Network) add_executable(${PROJECT_NAME} "main.cpp") target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network) diff --git a/examples/qt/main.cpp b/examples/qt/main.cpp index eb47733..daa05cf 100644 --- a/examples/qt/main.cpp +++ b/examples/qt/main.cpp @@ -1,74 +1,86 @@ /* SnoreToast is capable to invoke Windows 8 toast notifications. Copyright (C) 2019 Hannah von Reth SnoreToast is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SnoreToast is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with SnoreToast. If not, see . */ #include #include #include #include #include #include #include + +#include "../../src/snoretoastactions.h" + int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QLocalServer *server = new QLocalServer(); QObject::connect(server, &QLocalServer::newConnection, server, [server]() { auto sock = server->nextPendingConnection(); sock->waitForReadyRead(); - qDebug() << sock->bytesAvailable(); const QByteArray rawData = sock->readAll(); const QString data = QString::fromWCharArray(reinterpret_cast(rawData.constData()), rawData.size() / sizeof(wchar_t)); + QMap map; + for (const auto &str : data.split(";")) + { + const auto index = str.indexOf("="); + map[str.mid(0, index)] = str.mid(index + 1); + } + const auto action = map["action"]; + std::wstring waction(action.size(), 0); + action.toWCharArray(waction.data()); + std::wcout << qPrintable(data) << std::endl; + std::wcout << "Action: " << waction << " " << static_cast(SnoreToastActions::getAction(waction)) << std::endl; // TODO: parse data }); server->listen("foo"); std::wcout << qPrintable(server->fullServerName()) << std::endl; const QString appId = "SnoreToast.Qt.Example"; QProcess proc(&a); proc.start("SnoreToast.exe", { "-install", "SnoreToastTestQt", a.applicationFilePath(), appId }); proc.waitForFinished(); std::wcout << proc.exitCode() << std::endl; std::wcout << qPrintable(proc.readAll()) << std::endl; QTimer *timer = new QTimer(&a); a.connect(timer, &QTimer::timeout, timer, [&] { static int id = 0; if (id >= 10) { timer->stop(); } auto proc = new QProcess(&a); proc->start("SnoreToast.exe", { "-t", "test", "-m", "message", "-pipename", server->fullServerName(), "-w", "-id", QString::number(id++), "-appId", appId, "-application", a.applicationFilePath() }); proc->connect(proc, QOverload::of(&QProcess::finished), proc, [proc] { - std::wcout << qPrintable(proc->errorString()) << std::endl; std::wcout << qPrintable(proc->readAll()) << std::endl; std::wcout << proc->exitCode() << std::endl; }); }); timer->start(1000); return a.exec(); }