Browse Source
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.wip/appindicator

25 changed files with 871 additions and 147 deletions
@ -0,0 +1,27 @@
@@ -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 |
@ -0,0 +1,39 @@
@@ -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; |
||||
} |
@ -0,0 +1,73 @@
@@ -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 (); |
||||
} |
@ -0,0 +1,87 @@
@@ -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 (); |
||||
} |
@ -0,0 +1,100 @@
@@ -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; |
||||
} |
||||
} |
@ -0,0 +1,127 @@
@@ -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> |
@ -0,0 +1,22 @@
@@ -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> |
@ -0,0 +1,225 @@
@@ -0,0 +1,225 @@
|
||||
/* 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 "../common/hexchat-plugin.h" |
||||
#include "../common/inbound.h" /* For alert_match_word() */ |
||||
#include "notifications/notification-backend.h" |
||||
|
||||
static hexchat_plugin *ph; |
||||
|
||||
static gboolean |
||||
should_alert (void) |
||||
{ |
||||
int omit_away, omit_focused, omit_tray; |
||||
|
||||
if (hexchat_get_prefs (ph, "gui_focus_omitalerts", NULL, &omit_focused) == 3 && omit_focused) |
||||
{ |
||||
const char *status = hexchat_get_info (ph, "win_status"); |
||||
|
||||
if (status && !g_strcmp0 (status, "active")) |
||||
return FALSE; |
||||
} |
||||
|
||||
if (hexchat_get_prefs (ph, "away_omit_alerts", NULL, &omit_away) == 3 && omit_away) |
||||
{ |
||||
if (hexchat_get_info (ph, "away")) |
||||
return FALSE; |
||||
} |
||||
|
||||
if (hexchat_get_prefs (ph, "gui_tray_quiet", NULL, &omit_tray) == 3 && omit_tray) |
||||
{ |
||||
int tray_enabled; |
||||
|
||||
if (hexchat_get_prefs (ph, "gui_tray", NULL, &tray_enabled) == 3 && tray_enabled) |
||||
{ |
||||
const char *status = hexchat_get_info (ph, "win_status"); |
||||
|
||||
if (status && g_strcmp0 (status, "hidden") != 0) |
||||
return FALSE; |
||||
} |
||||
} |
||||
|
||||
return TRUE; |
||||
} |
||||
|
||||
/* Returns timeout in ms */ |
||||
static int |
||||
get_timeout (void) |
||||
{ |
||||
int timeout = 0; |
||||
hexchat_get_prefs (ph, "input_balloon_time", NULL, &timeout); |
||||
|
||||
return timeout * 1000; |
||||
} |
||||
|
||||
static gboolean |
||||
is_ignored (char *nick) |
||||
{ |
||||
const char *no_hilight; |
||||
|
||||
if (hexchat_get_prefs (ph, "irc_no_hilight", &no_hilight, NULL) == 1 && no_hilight) |
||||
{ |
||||
return alert_match_word (nick, (char*)no_hilight); |
||||
} |
||||
return FALSE; |
||||
} |
||||
|
||||
static void |
||||
show_notification (const char *title, const char *text) |
||||
{ |
||||
char *stripped_title, *stripped_text; |
||||
|
||||
/* Strip all colors */ |
||||
stripped_title = hexchat_strip (ph, title, -1, 7); |
||||
stripped_text = hexchat_strip (ph, text, -1, 7); |
||||
|
||||
notification_backend_show (stripped_title, stripped_text, get_timeout ()); |
||||
|
||||
hexchat_free (ph, stripped_title); |
||||
hexchat_free (ph, stripped_text); |
||||
} |
||||
|
||||
static void |
||||
show_notificationf (const char *text, const char *format, ...) |
||||
{ |
||||
va_list args; |
||||
char *buf; |
||||
|
||||
va_start (args, format); |
||||
buf = g_strdup_vprintf (format, args); |
||||
va_end (args); |
||||
|
||||
show_notification (buf, text); |
||||
g_free (buf); |
||||
} |
||||
|
||||
static int |
||||
incoming_hilight_cb (char *word[], gpointer userdata) |
||||
{ |
||||
int hilight; |
||||
|
||||
if (hexchat_get_prefs (ph, "input_balloon_hilight", NULL, &hilight) == 3 && hilight && should_alert()) |
||||
{ |
||||
show_notificationf (word[2], _("Highlighted message from: %s (%s)"), word[1], hexchat_get_info (ph, "channel")); |
||||
} |
||||
return HEXCHAT_EAT_NONE; |
||||
} |
||||
|
||||
static int |
||||
incoming_message_cb (char *word[], gpointer userdata) |
||||
{ |
||||
int message; |
||||
|
||||
if (hexchat_get_prefs (ph, "input_balloon_chans", NULL, &message) == 3 && message && should_alert ()) |
||||
{ |
||||
show_notificationf (word[2], _("Channel message from: %s (%s)"), word[1], hexchat_get_info (ph, "channel")); |
||||
} |
||||
return HEXCHAT_EAT_NONE; |
||||
} |
||||
|
||||
static int |
||||
incoming_priv_cb (char *word[], gpointer userdata) |
||||
{ |
||||
int priv; |
||||
|
||||
if (hexchat_get_prefs (ph, "input_balloon_priv", NULL, &priv) == 3 && priv && should_alert ()) |
||||
{ |
||||
const char *network = hexchat_get_info (ph, "network"); |
||||
if (!network) |
||||
network = hexchat_get_info (ph, "server"); |
||||
|
||||
if (userdata != NULL) /* Special event */ |
||||
{ |
||||
if (GPOINTER_TO_INT (userdata) == 3) |
||||
{ |
||||
if (!is_ignored (word[2])) |
||||
show_notificationf (word[1], _("File offer from: %s (%s)"), word[2], network); |
||||
} |
||||
else if (GPOINTER_TO_INT (userdata) == 2) |
||||
{ |
||||
if (!is_ignored (word[2])) |
||||
show_notificationf (word[1], _("Invited to channel by: %s (%s)"), word[2], network); |
||||
} |
||||
else |
||||
{ |
||||
if (!is_ignored (word[1])) |
||||
show_notificationf (word[2], _("Notice from: %s (%s)"), word[1], network); |
||||
} |
||||
} |
||||
else |
||||
show_notificationf (word[2], _("Private message from: %s (%s)"), word[1], network); |
||||
} |
||||
return HEXCHAT_EAT_NONE; |
||||
} |
||||
|
||||
static int |
||||
tray_cmd_cb (char *word[], char *word_eol[], gpointer userdata) |
||||
{ |
||||
if (word[2] && !g_ascii_strcasecmp (word[2], "-b") && word[3] && word[4]) |
||||
{ |
||||
if (should_alert ()) |
||||
show_notification (word[3], word_eol[4]); |
||||
return HEXCHAT_EAT_ALL; |
||||
} |
||||
|
||||
return HEXCHAT_EAT_NONE; |
||||
} |
||||
|
||||
int |
||||
notification_plugin_init (hexchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg) |
||||
{ |
||||
if (!notification_backend_init ()) |
||||
return 0; |
||||
|
||||
ph = plugin_handle; |
||||
*plugin_name = ""; |
||||
*plugin_desc = ""; |
||||
*plugin_version = ""; |
||||
|
||||
hexchat_hook_print (ph, "Channel Msg Hilight", HEXCHAT_PRI_LOWEST, incoming_hilight_cb, NULL); |
||||
hexchat_hook_print (ph, "Channel Action Hilight", HEXCHAT_PRI_LOWEST, incoming_hilight_cb, NULL); |
||||
|
||||
hexchat_hook_print (ph, "Channel Message", HEXCHAT_PRI_LOWEST, incoming_message_cb, NULL); |
||||
hexchat_hook_print (ph, "Channel Action", HEXCHAT_PRI_LOWEST, incoming_message_cb, NULL); |
||||
hexchat_hook_print (ph, "Channel Notice", HEXCHAT_PRI_LOWEST, incoming_message_cb, NULL); |
||||
|
||||
hexchat_hook_print (ph, "Private Message", HEXCHAT_PRI_LOWEST, incoming_priv_cb, NULL); |
||||
hexchat_hook_print (ph, "Private Message to Dialog", HEXCHAT_PRI_LOWEST, incoming_priv_cb, NULL); |
||||
hexchat_hook_print (ph, "Private Action", HEXCHAT_PRI_LOWEST, incoming_priv_cb, NULL); |
||||
hexchat_hook_print (ph, "Private Action to Dialog", HEXCHAT_PRI_LOWEST, incoming_priv_cb, NULL); |
||||
|
||||
/* Special events treated as priv */ |
||||
hexchat_hook_print (ph, "Notice", HEXCHAT_PRI_LOWEST, incoming_priv_cb, GINT_TO_POINTER (1)); |
||||
hexchat_hook_print (ph, "Invited", HEXCHAT_PRI_LOWEST, incoming_priv_cb, GINT_TO_POINTER (2)); |
||||
hexchat_hook_print (ph, "DCC Offer", HEXCHAT_PRI_LOWEST, incoming_priv_cb, GINT_TO_POINTER (3)); |
||||
|
||||
hexchat_hook_command (ph, "TRAY", HEXCHAT_PRI_HIGH, tray_cmd_cb, NULL, NULL); |
||||
|
||||
return 1; |
||||
} |
||||
|
||||
|
||||
int |
||||
notification_plugin_deinit (void) |
||||
{ |
||||
notification_backend_deinit (); |
||||
return 1; |
||||
} |
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
/* 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_H |
||||
#define HEXCHAT_PLUGIN_NOTIFICATION_H |
||||
|
||||
int notification_plugin_init (void *, char **, char **, char **, char *); |
||||
int notification_plugin_deinit (void *); |
||||
|
||||
#endif |