Cleanup cmake, metadata
This commit is contained in:
25
src/CMakeLists.txt
Normal file
25
src/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
set(neochat_SRCS
|
||||
accountlistmodel.cpp
|
||||
controller.cpp
|
||||
emojimodel.cpp
|
||||
imageclipboard.cpp
|
||||
matriximageprovider.cpp
|
||||
messageeventmodel.cpp
|
||||
roomlistmodel.cpp
|
||||
spectralroom.cpp
|
||||
spectraluser.cpp
|
||||
trayicon.cpp
|
||||
userlistmodel.cpp
|
||||
publicroomlistmodel.cpp
|
||||
userdirectorylistmodel.cpp
|
||||
utils.cpp
|
||||
main.cpp
|
||||
manager.cpp
|
||||
../res.qrc
|
||||
)
|
||||
|
||||
add_executable(neochat ${neochat_SRCS})
|
||||
|
||||
target_link_libraries(neochat Qt5::Widgets Qt5::Quick Qt5::Qml Qt5::Gui Qt5::Network Qt5::QuickControls2 KF5::Kirigami2 Quotient cmark::cmark ${QTKEYCHAIN_LIBRARIES})
|
||||
|
||||
install(TARGETS neochat ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "connection.h"
|
||||
#include "csapi/list_public_rooms.h"
|
||||
#include "notifications/manager.h"
|
||||
#include "room.h"
|
||||
#include "settings.h"
|
||||
#include "user.h"
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "imageclipboard.h"
|
||||
#include "matriximageprovider.h"
|
||||
#include "messageeventmodel.h"
|
||||
#include "notifications/manager.h"
|
||||
#include "manager.h"
|
||||
#include "publicroomlistmodel.h"
|
||||
#include "room.h"
|
||||
#include "roomlistmodel.h"
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "manager.h"
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <QtMac>
|
||||
#include <QPixmap>
|
||||
|
||||
@interface NSUserNotification (CFIPrivate)
|
||||
- (void)set_identityImage:(NSImage*)image;
|
||||
@end
|
||||
|
||||
NotificationsManager::NotificationsManager(QObject* parent) : QObject(parent) {}
|
||||
|
||||
void NotificationsManager::postNotification(const QString& roomId,
|
||||
const QString& eventId,
|
||||
const QString& roomName,
|
||||
const QString& senderName,
|
||||
const QString& text,
|
||||
const QImage& icon) {
|
||||
Q_UNUSED(roomId);
|
||||
Q_UNUSED(eventId);
|
||||
Q_UNUSED(icon);
|
||||
|
||||
NSUserNotification* notif = [[NSUserNotification alloc] init];
|
||||
|
||||
notif.title = roomName.toNSString();
|
||||
notif.subtitle = QString("%1 sent a message").arg(senderName).toNSString();
|
||||
notif.informativeText = text.toNSString();
|
||||
notif.soundName = NSUserNotificationDefaultSoundName;
|
||||
notif.contentImage = QtMac::toNSImage(QPixmap::fromImage(icon));
|
||||
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter]
|
||||
deliverNotification:notif];
|
||||
[notif autorelease];
|
||||
}
|
||||
|
||||
// unused
|
||||
void NotificationsManager::actionInvoked(uint, QString) {}
|
||||
|
||||
void NotificationsManager::notificationClosed(uint, uint) {}
|
||||
@@ -1,93 +0,0 @@
|
||||
#include "manager.h"
|
||||
#include "wintoastlib.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
using namespace WinToastLib;
|
||||
|
||||
class CustomHandler : public IWinToastHandler
|
||||
{
|
||||
public:
|
||||
CustomHandler(uint id, NotificationsManager *parent)
|
||||
: notificationID(id)
|
||||
, notificationsManager(parent)
|
||||
{
|
||||
}
|
||||
void toastActivated()
|
||||
{
|
||||
notificationsManager->actionInvoked(notificationID, "");
|
||||
}
|
||||
void toastActivated(int)
|
||||
{
|
||||
notificationsManager->actionInvoked(notificationID, "");
|
||||
}
|
||||
void toastFailed()
|
||||
{
|
||||
std::wcout << L"Error showing current toast" << std::endl;
|
||||
}
|
||||
void toastDismissed(WinToastDismissalReason)
|
||||
{
|
||||
notificationsManager->notificationClosed(notificationID, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
uint notificationID;
|
||||
NotificationsManager *notificationsManager;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
bool isInitialized = false;
|
||||
uint count = 0;
|
||||
|
||||
void init()
|
||||
{
|
||||
isInitialized = true;
|
||||
|
||||
WinToast::instance()->setAppName(L"Spectral");
|
||||
WinToast::instance()->setAppUserModelId(WinToast::configureAUMI(L"Spectral", L"Spectral"));
|
||||
if (!WinToast::instance()->initialize())
|
||||
std::wcout << "Your system in not compatible with toast notifications\n";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
NotificationsManager::NotificationsManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void NotificationsManager::postNotification(const QString &room_id, const QString &event_id, const QString &room_name, const QString &sender, const QString &text, const QImage &icon)
|
||||
{
|
||||
Q_UNUSED(room_id)
|
||||
Q_UNUSED(event_id)
|
||||
Q_UNUSED(icon)
|
||||
|
||||
if (!isInitialized)
|
||||
init();
|
||||
|
||||
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
|
||||
if (room_name != sender)
|
||||
templ.setTextField(QString("%1 - %2").arg(sender).arg(room_name).toStdWString(), WinToastTemplate::FirstLine);
|
||||
else
|
||||
templ.setTextField(QString("%1").arg(sender).toStdWString(), WinToastTemplate::FirstLine);
|
||||
templ.setTextField(QString("%1").arg(text).toStdWString(), WinToastTemplate::SecondLine);
|
||||
|
||||
count++;
|
||||
CustomHandler *customHandler = new CustomHandler(count, this);
|
||||
notificationIds[count] = roomEventId {room_id, event_id};
|
||||
|
||||
WinToast::instance()->showToast(templ, customHandler);
|
||||
}
|
||||
|
||||
void NotificationsManager::actionInvoked(uint id, QString action)
|
||||
{
|
||||
if (notificationIds.contains(id)) {
|
||||
roomEventId idEntry = notificationIds[id];
|
||||
emit notificationClicked(idEntry.roomId, idEntry.eventId);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationsManager::notificationClosed(uint id, uint reason)
|
||||
{
|
||||
notificationIds.remove(id);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,156 +0,0 @@
|
||||
#ifndef WINTOASTLIB_H
|
||||
#define WINTOASTLIB_H
|
||||
#include <Psapi.h>
|
||||
#include <ShObjIdl.h>
|
||||
#include <ShlObj.h>
|
||||
#include <WinUser.h>
|
||||
#include <Windows.h>
|
||||
#include <functiondiscoverykeys.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <propvarutil.h>
|
||||
#include <roapi.h>
|
||||
#include <sdkddkver.h>
|
||||
#include <string.h>
|
||||
#include <strsafe.h>
|
||||
#include <vector>
|
||||
#include <windows.ui.notifications.h>
|
||||
#include <winstring.h>
|
||||
#include <wrl/event.h>
|
||||
#include <wrl/implements.h>
|
||||
using namespace Microsoft::WRL;
|
||||
using namespace ABI::Windows::Data::Xml::Dom;
|
||||
using namespace ABI::Windows::Foundation;
|
||||
using namespace ABI::Windows::UI::Notifications;
|
||||
using namespace Windows::Foundation;
|
||||
|
||||
#define DEFAULT_SHELL_LINKS_PATH L"\\Microsoft\\Windows\\Start Menu\\Programs\\"
|
||||
#define DEFAULT_LINK_FORMAT L".lnk"
|
||||
namespace WinToastLib
|
||||
{
|
||||
class IWinToastHandler
|
||||
{
|
||||
public:
|
||||
enum WinToastDismissalReason {
|
||||
UserCanceled = ToastDismissalReason::ToastDismissalReason_UserCanceled,
|
||||
ApplicationHidden = ToastDismissalReason::ToastDismissalReason_ApplicationHidden,
|
||||
TimedOut = ToastDismissalReason::ToastDismissalReason_TimedOut
|
||||
};
|
||||
virtual ~IWinToastHandler()
|
||||
{
|
||||
}
|
||||
virtual void toastActivated() = 0;
|
||||
virtual void toastActivated(int actionIndex) = 0;
|
||||
virtual void toastDismissed(WinToastDismissalReason state) = 0;
|
||||
virtual void toastFailed() = 0;
|
||||
};
|
||||
|
||||
class WinToastTemplate
|
||||
{
|
||||
public:
|
||||
enum Duration { System, Short, Long };
|
||||
enum AudioOption { Default = 0, Silent = 1, Loop = 2 };
|
||||
enum TextField { FirstLine = 0, SecondLine, ThirdLine };
|
||||
enum WinToastTemplateType {
|
||||
ImageAndText01 = ToastTemplateType::ToastTemplateType_ToastImageAndText01,
|
||||
ImageAndText02 = ToastTemplateType::ToastTemplateType_ToastImageAndText02,
|
||||
ImageAndText03 = ToastTemplateType::ToastTemplateType_ToastImageAndText03,
|
||||
ImageAndText04 = ToastTemplateType::ToastTemplateType_ToastImageAndText04,
|
||||
Text01 = ToastTemplateType::ToastTemplateType_ToastText01,
|
||||
Text02 = ToastTemplateType::ToastTemplateType_ToastText02,
|
||||
Text03 = ToastTemplateType::ToastTemplateType_ToastText03,
|
||||
Text04 = ToastTemplateType::ToastTemplateType_ToastText04,
|
||||
WinToastTemplateTypeCount
|
||||
};
|
||||
|
||||
WinToastTemplate(_In_ WinToastTemplateType type = WinToastTemplateType::ImageAndText02);
|
||||
~WinToastTemplate();
|
||||
|
||||
void setTextField(_In_ const std::wstring &txt, _In_ TextField pos);
|
||||
void setImagePath(_In_ const std::wstring &imgPath);
|
||||
void setAudioPath(_In_ const std::wstring &audioPath);
|
||||
void setAttributionText(_In_ const std::wstring &attributionText);
|
||||
void addAction(_In_ const std::wstring &label);
|
||||
void setAudioOption(_In_ WinToastTemplate::AudioOption audioOption);
|
||||
void setDuration(_In_ Duration duration);
|
||||
void setExpiration(_In_ INT64 millisecondsFromNow);
|
||||
std::size_t textFieldsCount() const;
|
||||
std::size_t actionsCount() const;
|
||||
bool hasImage() const;
|
||||
const std::vector<std::wstring> &textFields() const;
|
||||
const std::wstring &textField(_In_ TextField pos) const;
|
||||
const std::wstring &actionLabel(_In_ int pos) const;
|
||||
const std::wstring &imagePath() const;
|
||||
const std::wstring &audioPath() const;
|
||||
const std::wstring &attributionText() const;
|
||||
INT64 expiration() const;
|
||||
WinToastTemplateType type() const;
|
||||
WinToastTemplate::AudioOption audioOption() const;
|
||||
Duration duration() const;
|
||||
|
||||
private:
|
||||
std::vector<std::wstring> _textFields;
|
||||
std::vector<std::wstring> _actions;
|
||||
std::wstring _imagePath = L"";
|
||||
std::wstring _audioPath = L"";
|
||||
std::wstring _attributionText = L"";
|
||||
INT64 _expiration = 0;
|
||||
AudioOption _audioOption = WinToastTemplate::AudioOption::Default;
|
||||
WinToastTemplateType _type = WinToastTemplateType::Text01;
|
||||
Duration _duration = Duration::System;
|
||||
};
|
||||
|
||||
class WinToast
|
||||
{
|
||||
public:
|
||||
enum WinToastError { NoError = 0, NotInitialized, SystemNotSupported, ShellLinkNotCreated, InvalidAppUserModelID, InvalidParameters, InvalidHandler, NotDisplayed, UnknownError };
|
||||
|
||||
enum ShortcutResult {
|
||||
SHORTCUT_UNCHANGED = 0,
|
||||
SHORTCUT_WAS_CHANGED = 1,
|
||||
SHORTCUT_WAS_CREATED = 2,
|
||||
|
||||
SHORTCUT_MISSING_PARAMETERS = -1,
|
||||
SHORTCUT_INCOMPATIBLE_OS = -2,
|
||||
SHORTCUT_COM_INIT_FAILURE = -3,
|
||||
SHORTCUT_CREATE_FAILED = -4
|
||||
};
|
||||
|
||||
WinToast(void);
|
||||
virtual ~WinToast();
|
||||
static WinToast *instance();
|
||||
static bool isCompatible();
|
||||
static bool isSupportingModernFeatures();
|
||||
static std::wstring configureAUMI(_In_ const std::wstring &companyName, _In_ const std::wstring &productName, _In_ const std::wstring &subProduct = std::wstring(), _In_ const std::wstring &versionInformation = std::wstring());
|
||||
virtual bool initialize(_Out_ WinToastError *error = nullptr);
|
||||
virtual bool isInitialized() const;
|
||||
virtual bool hideToast(_In_ INT64 id);
|
||||
virtual INT64 showToast(_In_ const WinToastTemplate &toast, _In_ IWinToastHandler *handler, _Out_ WinToastError *error = nullptr);
|
||||
virtual void clear();
|
||||
virtual enum ShortcutResult createShortcut();
|
||||
|
||||
const std::wstring &appName() const;
|
||||
const std::wstring &appUserModelId() const;
|
||||
void setAppUserModelId(_In_ const std::wstring &appName);
|
||||
void setAppName(_In_ const std::wstring &appName);
|
||||
|
||||
protected:
|
||||
bool _isInitialized;
|
||||
bool _hasCoInitialized;
|
||||
std::wstring _appName;
|
||||
std::wstring _aumi;
|
||||
std::map<INT64, ComPtr<IToastNotification>> _buffer;
|
||||
|
||||
HRESULT validateShellLinkHelper(_Out_ bool &wasChanged);
|
||||
HRESULT createShellLinkHelper();
|
||||
HRESULT setImageFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring &path);
|
||||
HRESULT setAudioFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring &path, _In_opt_ WinToastTemplate::AudioOption option = WinToastTemplate::AudioOption::Default);
|
||||
HRESULT setTextFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring &text, _In_ int pos);
|
||||
HRESULT setAttributionTextFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring &text);
|
||||
HRESULT addActionHelper(_In_ IXmlDocument *xml, _In_ const std::wstring &action, _In_ const std::wstring &arguments);
|
||||
HRESULT addDurationHelper(_In_ IXmlDocument *xml, _In_ const std::wstring &duration);
|
||||
ComPtr<IToastNotifier> notifier(_In_ bool *succeded) const;
|
||||
void setError(_Out_ WinToastError *error, _In_ WinToastError value);
|
||||
};
|
||||
}
|
||||
#endif // WINTOASTLIB_H
|
||||
Reference in New Issue
Block a user