diff options
author | TingPing <tingping@fedoraproject.org> | 2015-02-02 19:35:49 -0500 |
---|---|---|
committer | TingPing <tingping@fedoraproject.org> | 2015-02-04 20:24:53 -0500 |
commit | f4f27e438b0791e1c0708c4f031aa80c59d965b1 (patch) | |
tree | c68f1fb8cbbe88b7878e8fef690fd00c150f66ec /src/fe-gtk/notifications | |
parent | a216ed1df9394325bc573cd3f1693eb467a89938 (diff) |
Implement windows 8.1+ notifications
This splits notifications up into multiple backends currently only libnotify on unix and win8 toasts. The win8 backend was originally written by @leeter though heavily modified.
Diffstat (limited to 'src/fe-gtk/notifications')
-rw-r--r-- | src/fe-gtk/notifications/notification-backend.h | 27 | ||||
-rw-r--r-- | src/fe-gtk/notifications/notification-dummy.c | 39 | ||||
-rw-r--r-- | src/fe-gtk/notifications/notification-libnotify.c | 73 | ||||
-rw-r--r-- | src/fe-gtk/notifications/notification-windows.c | 87 | ||||
-rw-r--r-- | src/fe-gtk/notifications/notification-winrt.cpp | 100 | ||||
-rw-r--r-- | src/fe-gtk/notifications/notifications-winrt.vcxproj | 127 | ||||
-rw-r--r-- | src/fe-gtk/notifications/notifications-winrt.vcxproj.filters | 22 |
7 files changed, 475 insertions, 0 deletions
diff --git a/src/fe-gtk/notifications/notification-backend.h b/src/fe-gtk/notifications/notification-backend.h new file mode 100644 index 00000000..98686d73 --- /dev/null +++ b/src/fe-gtk/notifications/notification-backend.h @@ -0,0 +1,27 @@ +/* HexChat + * Copyright (C) 2015 Patrick Griffis. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef HEXCHAT_PLUGIN_NOTIFICATION_BACKEND_H +#define HEXCHAT_PLUGIN_NOTIFICATION_BACKEND_H + +int notification_backend_supported (void); +void notification_backend_show (const char *title, const char *text, int timeout); +int notification_backend_init (void); +void notification_backend_deinit (void); + +#endif diff --git a/src/fe-gtk/notifications/notification-dummy.c b/src/fe-gtk/notifications/notification-dummy.c new file mode 100644 index 00000000..1b719cfa --- /dev/null +++ b/src/fe-gtk/notifications/notification-dummy.c @@ -0,0 +1,39 @@ +/* HexChat + * Copyright (C) 2015 Patrick Griffis. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +void +notification_backend_show (const char *title, const char *text, int timeout) +{ +} + +int +notification_backend_init (void) +{ + return 0; +} + +void +notification_backend_deinit (void) +{ +} + +int +notification_backend_supported (void) +{ + return 0; +} diff --git a/src/fe-gtk/notifications/notification-libnotify.c b/src/fe-gtk/notifications/notification-libnotify.c new file mode 100644 index 00000000..d3e3a992 --- /dev/null +++ b/src/fe-gtk/notifications/notification-libnotify.c @@ -0,0 +1,73 @@ +/* HexChat + * Copyright (C) 2015 Patrick Griffis. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "config.h" +#include <glib.h> +#include <libnotify/notify.h> + +static gboolean strip_markup = FALSE; + +void +notification_backend_show (const char *title, const char *text, int timeout) +{ + NotifyNotification *notification; + + if (strip_markup) + text = g_markup_escape_text (text, -1); + + notification = notify_notification_new (title, text, "hexchat"); + notify_notification_set_hint (notification, "desktop-entry", g_variant_new_string ("hexchat")); + + notify_notification_set_timeout (notification, timeout); + notify_notification_show (notification, NULL); + + g_object_unref (notification); + if (strip_markup) + g_free ((char*)text); +} + +int +notification_backend_init (void) +{ + GList* server_caps; + + if (!NOTIFY_CHECK_VERSION (0, 7, 0)) + return 0; + + if (!notify_init (PACKAGE_NAME)) + return 0; + + server_caps = notify_get_server_caps (); + if (g_list_find_custom (server_caps, "body-markup", (GCompareFunc)g_strcmp0)) + strip_markup = TRUE; + g_list_free_full (server_caps, g_free); + + return 1; +} + +void +notification_backend_deinit (void) +{ + notify_uninit (); +} + +int +notification_backend_supported (void) +{ + return notify_is_initted (); +} diff --git a/src/fe-gtk/notifications/notification-windows.c b/src/fe-gtk/notifications/notification-windows.c new file mode 100644 index 00000000..16cf3412 --- /dev/null +++ b/src/fe-gtk/notifications/notification-windows.c @@ -0,0 +1,87 @@ +/* HexChat + * Copyright (C) 2015 Arnav Singh. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <gmodule.h> + +#include "hexchat.h" +#include "plugin.h" + +#include <Windows.h> + +void (*winrt_notification_backend_show) (const char *title, const char *text, int timeout) = NULL; +int (*winrt_notification_backend_init) (void) = NULL; +void (*winrt_notification_backend_deinit) (void) = NULL; +int (*winrt_notification_backend_supported) (void) = NULL; + +void +notification_backend_show (const char *title, const char *text, int timeout) +{ + if (winrt_notification_backend_show == NULL) + { + return; + } + + winrt_notification_backend_show (title, text, timeout); +} + +int +notification_backend_init (void) +{ + UINT original_error_mode; + GModule *module; + + /* Temporarily suppress the "DLL could not be loaded" dialog box before trying to load hcnotifications-winrt.dll */ + original_error_mode = GetErrorMode (); + SetErrorMode(SEM_FAILCRITICALERRORS); + module = module_load (HEXCHATLIBDIR "\\hcnotifications-winrt.dll"); + SetErrorMode (original_error_mode); + + if (module == NULL) + { + return 0; + } + + g_module_symbol (module, "notification_backend_show", (gpointer *) &winrt_notification_backend_show); + g_module_symbol (module, "notification_backend_init", (gpointer *) &winrt_notification_backend_init); + g_module_symbol (module, "notification_backend_deinit", (gpointer *) &winrt_notification_backend_deinit); + g_module_symbol (module, "notification_backend_supported", (gpointer *) &winrt_notification_backend_supported); + + return winrt_notification_backend_init (); +} + +void +notification_backend_deinit (void) +{ + if (winrt_notification_backend_deinit == NULL) + { + return; + } + + winrt_notification_backend_deinit (); +} + +int +notification_backend_supported (void) +{ + if (winrt_notification_backend_supported == NULL) + { + return 0; + } + + return winrt_notification_backend_supported (); +} diff --git a/src/fe-gtk/notifications/notification-winrt.cpp b/src/fe-gtk/notifications/notification-winrt.cpp new file mode 100644 index 00000000..74cc2e78 --- /dev/null +++ b/src/fe-gtk/notifications/notification-winrt.cpp @@ -0,0 +1,100 @@ +/* HexChat + * Copyright (c) 2014 Leetsoftwerx + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <string> +#include <codecvt> + +#include <roapi.h> +#include <windows.ui.notifications.h> + +using namespace Windows::UI::Notifications; +using namespace Windows::Data::Xml::Dom; + +static ToastNotifier ^ notifier = nullptr; + +static std::wstring +widen(const std::string & to_widen) +{ + std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter; + return converter.from_bytes(to_widen); +} + +extern "C" +{ + __declspec (dllexport) void + notification_backend_show (const char *title, const char *text, int timeout) + { + try + { + auto toastTemplate = ToastNotificationManager::GetTemplateContent (ToastTemplateType::ToastText02); + auto node_list = toastTemplate->GetElementsByTagName ("text"); + UINT node_count = node_list->Length; + + auto wtitle = widen (title); + node_list->GetAt (0)->AppendChild ( + toastTemplate->CreateTextNode (Platform::StringReference (wtitle.c_str (), wtitle.size ()))); + + auto wtext = widen (text); + node_list->GetAt (1)->AppendChild ( + toastTemplate->CreateTextNode (Platform::StringReference (wtext.c_str (), wtext.size ()))); + + // Mute sound, we already play our own + auto node = toastTemplate->SelectSingleNode ("/toast"); + auto audio_elem = toastTemplate->CreateElement ("audio"); + audio_elem->SetAttribute ("silent", "true"); + static_cast<XmlElement^>(node)->AppendChild (audio_elem); + + notifier->Show (ref new ToastNotification (toastTemplate)); + } + catch (Platform::Exception ^ ex) + { + } + catch (...) + { + } + } + + __declspec (dllexport) int + notification_backend_init (void) + { + if (!notifier) + notifier = ToastNotificationManager::CreateToastNotifier ("HexChat.Desktop.Notify"); + + if (FAILED (Windows::Foundation::Initialize (RO_INIT_SINGLETHREADED))) + return 0; + + return 1; + } + + __declspec (dllexport) void + notification_backend_deinit (void) + { + notifier = nullptr; + Windows::Foundation::Uninitialize (); + } + + __declspec (dllexport) int + notification_backend_supported (void) + { + return 1; + } +} diff --git a/src/fe-gtk/notifications/notifications-winrt.vcxproj b/src/fe-gtk/notifications/notifications-winrt.vcxproj new file mode 100644 index 00000000..7a4e9888 --- /dev/null +++ b/src/fe-gtk/notifications/notifications-winrt.vcxproj @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <ItemGroup> + <ClCompile Include="notification-winrt.cpp"> + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT> + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT> + </ClCompile> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{C53145CC-D021-40C9-B97C-0249AB9A43C9}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>notifications-winrt</RootNamespace> + <ProjectName>notifications-winrt</ProjectName> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v120</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="..\..\..\win32\hexchat.props" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="..\..\..\win32\hexchat.props" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <TargetName>hcnotifications-winrt</TargetName> + <OutDir>$(HexChatBin)</OutDir> + <IntDir>$(HexChatObj)$(ProjectName)\</IntDir> + <IncludePath>$(IncludePath)</IncludePath> + <LibraryPath>$(LibraryPath)</LibraryPath> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(HexChatBin)</OutDir> + <TargetName>hcnotifications-winrt</TargetName> + <IntDir>$(HexChatObj)$(ProjectName)\</IntDir> + <IncludePath>$(IncludePath)</IncludePath> + <LibraryPath>$(LibraryPath)</LibraryPath> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY;_CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;NDEBUG;_WINDOWS;_USRDLL;NOTIFICATIONS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <SDLCheck>true</SDLCheck> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <PrecompiledHeaderFile /> + <AdditionalUsingDirectories>$(VCInstallDir)vcpackages;$(FrameworkSdkDir)References\CommonConfiguration\Neutral;%(AdditionalUsingDirectories)</AdditionalUsingDirectories> + <WholeProgramOptimization>true</WholeProgramOptimization> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <LargeAddressAware>true</LargeAddressAware> + <FixedBaseAddress>false</FixedBaseAddress> + <ModuleDefinitionFile> + </ModuleDefinitionFile> + <AdditionalDependencies>$(DepLibs);mincore.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies> + <MinimumRequiredVersion>6.03</MinimumRequiredVersion> + <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY;_CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;NDEBUG;_WINDOWS;_USRDLL;NOTIFICATIONS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <SDLCheck>true</SDLCheck> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <PrecompiledHeaderFile /> + <AdditionalUsingDirectories>$(VCInstallDir)vcpackages;$(FrameworkSdkDir)References\CommonConfiguration\Neutral;%(AdditionalUsingDirectories)</AdditionalUsingDirectories> + <WholeProgramOptimization>true</WholeProgramOptimization> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <LargeAddressAware>true</LargeAddressAware> + <FixedBaseAddress>false</FixedBaseAddress> + <ModuleDefinitionFile> + </ModuleDefinitionFile> + <AdditionalDependencies>$(DepLibs);mincore.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies> + <MinimumRequiredVersion>6.03</MinimumRequiredVersion> + <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ No newline at end of file diff --git a/src/fe-gtk/notifications/notifications-winrt.vcxproj.filters b/src/fe-gtk/notifications/notifications-winrt.vcxproj.filters new file mode 100644 index 00000000..06f4e558 --- /dev/null +++ b/src/fe-gtk/notifications/notifications-winrt.vcxproj.filters @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="notification-winrt.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> +</Project> \ No newline at end of file |