Remove inclusion of sys/socket.h from nntp-thread.c
[claws.git] / src / plugins / notification / notification_hotkeys.c
blobf2d51f045687ba1b46409486c0f4825cc0612999
1 /* Notification plugin for Claws Mail
2 * Copyright (C) 2005-2009 Holger Berndt and the Claws Mail Team.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 # include "claws-features.h"
21 #endif
23 #ifdef NOTIFICATION_HOTKEYS
25 #include "notification_hotkeys.h"
26 #include "notification_prefs.h"
27 #include "notification_core.h"
29 #include "gtkhotkey.h"
31 #define HOTKEYS_APP_ID "claws-mail"
32 #define HOTKEY_KEY_ID_TOGGLED "toggle-mainwindow"
34 static GtkHotkeyInfo *hotkey_toggle_mainwindow = NULL;
36 static void hotkey_toggle_mainwindow_activated(GtkHotkeyInfo *hotkey, guint event_time, gpointer data)
38 g_return_if_fail(GTK_HOTKEY_IS_INFO(hotkey));
39 debug_print("Notification plugin: Toggled hide/show window due to hotkey %s activation\n", gtk_hotkey_info_get_signature(hotkey));
40 notification_toggle_hide_show_window();
43 static void unbind_toggle_mainwindow()
45 GError *error = NULL;
46 GtkHotkeyRegistry *registry;
48 /* clean up old hotkey */
49 if(hotkey_toggle_mainwindow) {
50 if(gtk_hotkey_info_is_bound(hotkey_toggle_mainwindow)) {
51 error = NULL;
52 gtk_hotkey_info_unbind(hotkey_toggle_mainwindow, &error);
53 if(error) {
54 debug_print("Notification plugin: Failed to unbind toggle hotkey\n");
55 g_error_free(error);
56 return;
59 g_object_unref(hotkey_toggle_mainwindow);
60 hotkey_toggle_mainwindow = NULL;
62 registry = gtk_hotkey_registry_get_default();
63 if(gtk_hotkey_registry_has_hotkey(registry, HOTKEYS_APP_ID, HOTKEY_KEY_ID_TOGGLED)) {
64 error = NULL;
65 gtk_hotkey_registry_delete_hotkey(registry, HOTKEYS_APP_ID, HOTKEY_KEY_ID_TOGGLED, &error);
66 if(error) {
67 debug_print("Notification plugin: Failed to unregister toggle hotkey: %s\n", error->message);
68 g_error_free(error);
69 return;
74 static void update_hotkey_binding_toggle_mainwindow()
76 GError *error = NULL;
78 /* don't do anything if no signature is given */
79 if(!notify_config.hotkeys_toggle_mainwindow || !strcmp(notify_config.hotkeys_toggle_mainwindow, ""))
80 return;
82 unbind_toggle_mainwindow();
84 /* (re)create hotkey info */
85 hotkey_toggle_mainwindow = gtk_hotkey_info_new(HOTKEYS_APP_ID, HOTKEY_KEY_ID_TOGGLED, notify_config.hotkeys_toggle_mainwindow, NULL);
86 if(!hotkey_toggle_mainwindow) {
87 debug_print("Notification plugin: Failed to create toggle hotkey for '%s'\n", notify_config.hotkeys_toggle_mainwindow);
88 return;
91 /* try to register hotkey */
92 error = NULL;
93 gtk_hotkey_info_bind(hotkey_toggle_mainwindow, &error);
94 if(error) {
95 debug_print("Notification plugin: Failed to bind toggle hotkey to '%s': %s\n", notify_config.hotkeys_toggle_mainwindow, error->message);
96 g_error_free(error);
97 return;
100 g_signal_connect(hotkey_toggle_mainwindow, "activated", G_CALLBACK(hotkey_toggle_mainwindow_activated), NULL);
103 void notification_hotkeys_update_bindings()
105 debug_print("Notification plugin: Updating keybindings..\n");
106 if(notify_config.hotkeys_enabled) {
107 update_hotkey_binding_toggle_mainwindow();
109 else
110 notification_hotkeys_unbind_all();
113 void notification_hotkeys_unbind_all()
115 debug_print("Notification plugin: Unbinding all keybindings..\n");
116 unbind_toggle_mainwindow();
119 #endif /* NOTIFICATION_HOTKEYS */