| 1 |
/* |
| 2 |
Copyright 2014 Canonical Ltd. |
| 3 |
|
| 4 |
This program is free software: you can redistribute it and/or modify it |
| 5 |
under the terms of the GNU General Public License version 3, as published |
| 6 |
by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, but |
| 9 |
WITHOUT ANY WARRANTY; without even the implied warranties of |
| 10 |
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 11 |
PURPOSE. See the GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License along |
| 14 |
with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
package cmessaging |
| 17 |
|
| 18 |
/* |
| 19 |
#include <glib.h> |
| 20 |
#include <messaging-menu/messaging-menu.h> |
| 21 |
|
| 22 |
// this is a .go file instead of a .c file because of dh-golang limitations |
| 23 |
|
| 24 |
void handleActivate(gchar* c_action, const gchar * c_notification , gpointer obj); |
| 25 |
|
| 26 |
static void activate_cb(MessagingMenuMessage* msg, gchar* action, GVariant* parameter, gpointer obj) { |
| 27 |
handleActivate(action, messaging_menu_message_get_id(msg), obj); |
| 28 |
} |
| 29 |
|
| 30 |
static GHashTable* map = NULL; |
| 31 |
|
| 32 |
void add_notification (const gchar* desktop_id, const gchar* notification_id, |
| 33 |
const gchar* icon_path, const gchar* summary, const gchar* body, |
| 34 |
gint64 timestamp, const gchar** actions, gpointer obj) { |
| 35 |
if (map == NULL) { |
| 36 |
map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); |
| 37 |
} |
| 38 |
|
| 39 |
MessagingMenuApp* app = g_hash_table_lookup (map, desktop_id); |
| 40 |
if (app == NULL) { |
| 41 |
GIcon* app_icon = g_icon_new_for_string (desktop_id, NULL); |
| 42 |
app = messaging_menu_app_new (desktop_id); |
| 43 |
messaging_menu_app_register (app); |
| 44 |
messaging_menu_app_append_source (app, "postal", app_icon, "Postal"); |
| 45 |
g_hash_table_insert (map, g_strdup (desktop_id), app); |
| 46 |
g_object_unref (app_icon); |
| 47 |
// app only has a single refcount, and it's stored in the map. No need to g_object_unref it! |
| 48 |
} |
| 49 |
|
| 50 |
GIcon* icon = g_icon_new_for_string(icon_path, NULL); |
| 51 |
MessagingMenuMessage* msg = messaging_menu_message_new(notification_id, icon, summary, |
| 52 |
"", body, |
| 53 |
timestamp); |
| 54 |
// Lomiri support for actions in the messaging menu is strange. Not doing that for now. |
| 55 |
messaging_menu_app_append_message(app, msg, "postal", TRUE); |
| 56 |
|
| 57 |
g_signal_connect(msg, "activate", G_CALLBACK(activate_cb), obj); |
| 58 |
g_object_unref(msg); |
| 59 |
} |
| 60 |
|
| 61 |
void remove_notification (const gchar* desktop_id, const gchar* notification_id) { |
| 62 |
if (map == NULL) { |
| 63 |
return; |
| 64 |
} |
| 65 |
MessagingMenuApp* app = g_hash_table_lookup (map, desktop_id); |
| 66 |
if (app == NULL) { |
| 67 |
// no app in the hash table, bailout |
| 68 |
return; |
| 69 |
} |
| 70 |
messaging_menu_app_remove_message_by_id (app, notification_id); |
| 71 |
} |
| 72 |
|
| 73 |
gboolean notification_exists (const gchar* desktop_id, const gchar* notification_id) { |
| 74 |
if (map == NULL) { |
| 75 |
return FALSE; |
| 76 |
} |
| 77 |
MessagingMenuApp* app = g_hash_table_lookup (map, desktop_id); |
| 78 |
if (app == NULL) { |
| 79 |
// no app in the hash table, bailout |
| 80 |
return FALSE; |
| 81 |
} |
| 82 |
MessagingMenuMessage* msg = messaging_menu_app_get_message(app, notification_id); |
| 83 |
if (msg != NULL) { |
| 84 |
// the notification is still there |
| 85 |
return TRUE; |
| 86 |
} |
| 87 |
return FALSE; |
| 88 |
} |
| 89 |
*/ |
| 90 |
import "C" |