diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a984fd8..74043f08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ endif () # Prepare Plugins set(DEFAULT_PLUGINS omemo;openpgp;http-files;ice;rtp) if (WIN32) - set(DEFAULT_PLUGINS ${DEFAULT_PLUGINS};win32-fonts) + set(DEFAULT_PLUGINS ${DEFAULT_PLUGINS};win32-fonts;windows-notification) endif (WIN32) foreach (plugin ${DEFAULT_PLUGINS}) if ("$CACHE{DINO_PLUGIN_ENABLED_${plugin}}" STREQUAL "") diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index ed7feb6e..e5b7a4b8 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -28,6 +28,10 @@ if(DINO_PLUGIN_ENABLED_notification-sound) add_subdirectory(notification-sound) endif(DINO_PLUGIN_ENABLED_notification-sound) +if(DINO_PLUGIN_ENABLED_windows-notification) + add_subdirectory(windows-notification) +endif(DINO_PLUGIN_ENABLED_windows-notification) + if(DINO_PLUGIN_ENABLED_win32-fonts) add_subdirectory(win32-fonts) endif(DINO_PLUGIN_ENABLED_win32-fonts) diff --git a/plugins/windows-notification/CMakeLists.txt b/plugins/windows-notification/CMakeLists.txt new file mode 100644 index 00000000..70b434f1 --- /dev/null +++ b/plugins/windows-notification/CMakeLists.txt @@ -0,0 +1,53 @@ +find_packages(WINDOWS_NOTIFICATION_PACKAGES REQUIRED + Gee + GLib + GModule + GObject + GTK3 +) + +vala_precompile(WINDOWS_NOTIFICATION_VALA_C +SOURCES + src/plugin.vala + src/register_plugin.vala +CUSTOM_VAPIS + ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi + ${CMAKE_BINARY_DIR}/exports/dino.vapi + ${CMAKE_BINARY_DIR}/exports/qlite.vapi + #${CMAKE_CURRENT_SOURCE_DIR}/vapi/openal.vapi +PACKAGES + ${WINDOWS_NOTIFICATION_PACKAGES} +) + +add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/exports/wintoast.h +COMMAND + cp ${CMAKE_CURRENT_SOURCE_DIR}/src/wintoast.h ${CMAKE_BINARY_DIR}/exports/wintoast.h +DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/src/wintoast.h +COMMENT + Copy header file wintoast.h +) + +add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/exports/wintoast.c +COMMAND + cp ${CMAKE_CURRENT_SOURCE_DIR}/src/wintoast.c ${CMAKE_BINARY_DIR}/exports/wintoast.c +DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/src/wintoast.c +COMMENT + Copy header file wintoast.c +) + +add_custom_target(wintoast +DEPENDS + ${CMAKE_BINARY_DIR}/exports/wintoast.h + ${CMAKE_BINARY_DIR}/exports/wintoast.c +) + +add_definitions(${VALA_CFLAGS}) +add_library(windows-notification SHARED ${WINDOWS_NOTIFICATION_VALA_C} src/wintoast.c) +target_link_libraries(windows-notification libdino ${WINDOWS_NOTIFICATION_PACKAGES}) +add_dependencies(windows-notification wintoast) +set_target_properties(windows-notification PROPERTIES PREFIX "") +set_target_properties(windows-notification PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/) + +install(TARGETS windows-notification ${PLUGIN_INSTALL}) diff --git a/plugins/windows-notification/src/plugin.vala b/plugins/windows-notification/src/plugin.vala new file mode 100644 index 00000000..43e76be0 --- /dev/null +++ b/plugins/windows-notification/src/plugin.vala @@ -0,0 +1,65 @@ +using Gee; +using Dino.Entities; + +namespace Dino.Plugins.WindowsNotification { +public class Plugin : RootInterface, Object { + + public Dino.Application app; + + // private class ConvData { + // public int ReadUpToId; + // public int Timestamp; + // } + // private int interval = 0; + // private HashMap conv_data = new HashMap(); + + [CCode (has_target = false)] + private delegate void notification_callback(void* conv); + + [CCode (cname = "init", cheader_filename = "wintoast.h")] + private static extern int init(notification_callback callback); + + [CCode (cname = "uninit", cheader_filename = "wintoast.h")] + private static extern void uninit(); + + [CCode (cname = "show_message", cheader_filename = "wintoast.h")] + private static extern int show_message(char* sender, char* message, char* imagePath, char* protocolName, void *conv); + + private void onclick_callback() { + // TODO: + // This callback should: + // * Open Dino + // * Open Conversation from notification + // * Go to line + // The callback will probably need to receive at least one parameter more. Not difficult to do. + } + + public void registered(Dino.Application app) { + this.app = app; + + init(onclick_callback); + + app.stream_interactor.get_module(NotificationEvents.IDENTITY).notify_content_item.connect((item, conversation) => { + if (item.type_ == "message") { + // key: conversation.id value: { conversation.read_up_to.id, last-time-notification-send } + // var conv = conv_data.get(conversation.id); + // if (conv.ReadUpToId == conversation.read_up_to.id) { + // if (now < conv.Timestamp + interval) { + // return; + // } + // } + var message_item = (MessageItem)item; + //var message = item.encryption == Encryption.NONE ? message_item.message.body : "*encrypted*"; + var message = message_item.message.body; + var sender = conversation.nickname != null ? conversation.nickname : conversation.counterpart.to_string(); + show_message(sender, message + "\n", "", "", this); + } + }); + } + + public void shutdown() { + uninit(); + } +} + +} diff --git a/plugins/windows-notification/src/register_plugin.vala b/plugins/windows-notification/src/register_plugin.vala new file mode 100644 index 00000000..5a8f70ac --- /dev/null +++ b/plugins/windows-notification/src/register_plugin.vala @@ -0,0 +1,3 @@ +public Type register_plugin(Module module) { + return typeof (Dino.Plugins.WindowsNotification.Plugin); +} diff --git a/plugins/windows-notification/src/wintoast.c b/plugins/windows-notification/src/wintoast.c new file mode 100644 index 00000000..f05aaddd --- /dev/null +++ b/plugins/windows-notification/src/wintoast.c @@ -0,0 +1,49 @@ +#include +#include + +#include "wintoast.h" + +void(*callback)(void*) = NULL; + +HMODULE library_handle = NULL; + +typedef void(*ClickCallbackType)(void*); +typedef int(*PidginWinToastLibInitType)(ClickCallbackType); +typedef int(*PidginWinToastLibShowMessageType)(const char*, const char*, const char*, const char*, void*); + +PidginWinToastLibInitType library_init = NULL; +PidginWinToastLibShowMessageType library_show_message = NULL; + +void init(ClickCallbackType notification_click_callback) { + printf("Inicializando\n"); + + callback = notification_click_callback; + library_handle = LoadLibrary("PidginWinToastLib.dll"); + if (library_handle) { + FARPROC function = GetProcAddress(library_handle, "pidginWinToastLibInit"); + if (function) { + library_init = (PidginWinToastLibInitType)function; + } + + function = GetProcAddress(library_handle, "pidginWinToastLibShowMessage"); + if (function) { + library_show_message = (PidginWinToastLibShowMessageType)function; + } + } + + if (library_init) { + library_init(notification_click_callback); + } +} + +void uninit() { + if (library_handle) { + FreeLibrary(library_handle); + } +} + +void show_message(const char * sender, const char * message, const char * imagePath, const char * protocolName, void *conv) { + if (library_show_message) { + library_show_message(sender, message, imagePath, protocolName, conv); + } +} \ No newline at end of file diff --git a/plugins/windows-notification/src/wintoast.h b/plugins/windows-notification/src/wintoast.h new file mode 100644 index 00000000..568d4bbc --- /dev/null +++ b/plugins/windows-notification/src/wintoast.h @@ -0,0 +1,8 @@ +#ifndef WINTOAST +#define WINTOAST 1 + +void init(void(*notification_click_callback)(void *conv)); +void uninit(); +void show_message(const char * sender, const char * message, const char * imagePath, const char * protocolName, void *conv); + +#endif \ No newline at end of file