aboutsummaryrefslogtreecommitdiff
path: root/module/data.c
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2014-01-28 16:50:47 +0100
committerJavier <dev.git@javispedro.com>2014-01-28 16:50:47 +0100
commitc2d6d46b9ca89cb1c0729ee599c3566d3d1e7cf7 (patch)
tree7e1e2285437816c06ac884d68284d854413cf41e /module/data.c
downloadtopmenu-gtk-c2d6d46b9ca89cb1c0729ee599c3566d3d1e7cf7.tar.gz
topmenu-gtk-c2d6d46b9ca89cb1c0729ee599c3566d3d1e7cf7.zip
initial import
Diffstat (limited to 'module/data.c')
-rw-r--r--module/data.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/module/data.c b/module/data.c
new file mode 100644
index 0000000..9225d01
--- /dev/null
+++ b/module/data.c
@@ -0,0 +1,156 @@
+#include "../libtopmenu-client/topmenu-monitor.h"
+
+#include "data.h"
+#include "appmenu.h"
+
+G_DEFINE_QUARK(topmenu-window-data, window_data)
+G_DEFINE_QUARK(topmenu-menu-shell-data, menu_shell_data)
+G_DEFINE_QUARK(topmenu-menu-item-data, menu_item_data)
+
+gboolean
+topmenu_is_blacklisted (void)
+{
+ return FALSE;
+}
+
+gboolean
+topmenu_is_window_blacklisted (GtkWindow *window)
+{
+ if (gtk_window_get_window_type (window) != GTK_WINDOW_TOPLEVEL)
+ return TRUE;
+
+ if (GTK_IS_PLUG (window))
+ return TRUE;
+
+ return FALSE;
+}
+
+static WindowData *
+window_data_new (void)
+{
+ return g_slice_new0 (WindowData);
+}
+
+static void
+window_data_free (gpointer data)
+{
+ WindowData *window_data = data;
+
+ if (window_data != NULL)
+ {
+ if (window_data->menus != NULL)
+ g_slist_free_full (window_data->menus, g_object_unref);
+
+ if (window_data->monitor_connection_id)
+ g_signal_handler_disconnect(topmenu_monitor_get_instance(),
+ window_data->monitor_connection_id);
+
+ if (window_data->appmenu.menu)
+ topmenu_appmenu_destroy(&window_data->appmenu);
+
+ if (window_data->appmenubar)
+ gtk_widget_destroy(GTK_WIDGET(window_data->appmenubar));
+
+ g_slice_free (WindowData, window_data);
+ }
+}
+
+static MenuShellData *
+menu_shell_data_new (void)
+{
+ return g_slice_new0 (MenuShellData);
+}
+
+static void
+menu_shell_data_free (gpointer data)
+{
+ if (data != NULL)
+ g_slice_free (MenuShellData, data);
+}
+
+static MenuItemData *
+menu_item_data_new (void)
+{
+ return g_slice_new0 (MenuItemData);
+}
+
+static void
+menu_item_data_free (gpointer data)
+{
+ if (data != NULL) {
+ MenuItemData *item_data = data;
+
+ if (item_data->proxy)
+ gtk_widget_destroy (GTK_WIDGET (item_data->proxy));
+
+ g_slice_free (MenuItemData, data);
+ }
+}
+
+MenuItemData *
+topmenu_get_menu_item_data (GtkMenuItem *menu_item)
+{
+ MenuItemData *menu_item_data;
+
+ g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL);
+
+ menu_item_data = g_object_get_qdata (G_OBJECT (menu_item), menu_item_data_quark ());
+
+ if (menu_item_data == NULL)
+ {
+ menu_item_data = menu_item_data_new ();
+
+ g_object_set_qdata_full (G_OBJECT (menu_item), menu_item_data_quark (), menu_item_data, menu_item_data_free);
+ }
+
+ return menu_item_data;
+}
+
+MenuShellData *
+topmenu_get_menu_shell_data (GtkMenuShell *menu_shell)
+{
+ MenuShellData *menu_shell_data;
+
+ g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_shell), NULL);
+
+ menu_shell_data = g_object_get_qdata (G_OBJECT (menu_shell), menu_shell_data_quark ());
+
+ if (menu_shell_data == NULL)
+ {
+ menu_shell_data = menu_shell_data_new ();
+
+ g_object_set_qdata_full (G_OBJECT (menu_shell), menu_shell_data_quark (), menu_shell_data, menu_shell_data_free);
+ }
+
+ return menu_shell_data;
+}
+
+WindowData *
+topmenu_get_window_data (GtkWindow *window)
+{
+ WindowData *window_data;
+
+ g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+
+ window_data = g_object_get_qdata (G_OBJECT (window), window_data_quark ());
+
+ if (window_data == NULL)
+ {
+ if (topmenu_is_window_blacklisted (window))
+ return NULL;
+
+ window_data = window_data_new ();
+
+ // Nothing to initialize right now.
+
+ g_object_set_qdata_full (G_OBJECT (window), window_data_quark (), window_data, window_data_free);
+ }
+
+ return window_data;
+}
+
+void
+topmenu_remove_window_data (GtkWindow *window)
+{
+ g_object_set_qdata (G_OBJECT (window), window_data_quark (), NULL);
+}