summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontends/gtk/cookies.c51
-rw-r--r--frontends/gtk/cookies.h12
-rw-r--r--frontends/gtk/gui.c6
-rw-r--r--frontends/gtk/scaffolding.c8
4 files changed, 50 insertions, 27 deletions
diff --git a/frontends/gtk/cookies.c b/frontends/gtk/cookies.c
index 76894fab4..f252e6b3c 100644
--- a/frontends/gtk/cookies.c
+++ b/frontends/gtk/cookies.c
@@ -35,7 +35,11 @@
#include "gtk/treeview.h"
#include "gtk/resources.h"
-#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
+static struct nsgtk_treeview *cookies_treeview;
+static GtkBuilder *cookie_builder;
+static GtkWindow *wndCookies = NULL;
+
+#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
GtkMenuItem *widget, gpointer g)
#define MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) }
#define MENUHANDLER(x) gboolean nsgtk_on_##x##_activate(GtkMenuItem *widget, \
@@ -80,9 +84,7 @@ static struct menu_events menu_events[] = {
{NULL, NULL}
};
-static struct nsgtk_treeview *cookies_treeview;
-static GtkBuilder *cookie_builder;
-GtkWindow *wndCookies;
+
/**
* Connects menu events in the cookies window.
@@ -102,13 +104,21 @@ static void nsgtk_cookies_init_menu(void)
}
}
-/* exported interface documented in gtk/cookies.h */
-nserror nsgtk_cookies_init(void)
+/**
+ * Creates the window for the cookies tree.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+static nserror nsgtk_cookies_init(void)
{
GtkScrolledWindow *scrolled;
GtkDrawingArea *drawing_area;
nserror res;
+ if (wndCookies != NULL) {
+ return NSERROR_OK;
+ }
+
res = nsgtk_builder_new_from_resname("cookies", &cookie_builder);
if (res != NSERROR_OK) {
LOG("Cookie UI builder init failed");
@@ -147,14 +157,6 @@ nserror nsgtk_cookies_init(void)
}
-/**
- * Destroys the cookies window and performs any other necessary cleanup actions.
- */
-void nsgtk_cookies_destroy(void)
-{
- /** \todo what about cookie_builder? */
- nsgtk_treeview_destroy(cookies_treeview);
-}
/* edit menu */
@@ -219,3 +221,24 @@ MENUHANDLER(collapse_cookies)
cookie_manager_contract(false);
return TRUE;
}
+
+/* exported function documented gtk/cookies.h */
+nserror nsgtk_cookies_present(void)
+{
+ nserror res;
+
+ res = nsgtk_cookies_init();
+ if (res == NSERROR_OK) {
+ gtk_window_present(wndCookies);
+ }
+ return res;
+}
+
+/* exported function documented gtk/cookies.h */
+void nsgtk_cookies_destroy(void)
+{
+ /** \todo what about cookie_builder? */
+ if (wndCookies != NULL) {
+ nsgtk_treeview_destroy(cookies_treeview);
+ }
+}
diff --git a/frontends/gtk/cookies.h b/frontends/gtk/cookies.h
index 2d5c56d52..2af05e154 100644
--- a/frontends/gtk/cookies.h
+++ b/frontends/gtk/cookies.h
@@ -23,15 +23,19 @@
#ifndef __NSGTK_COOKIES_H__
#define __NSGTK_COOKIES_H__
-extern GtkWindow *wndCookies;
-
/**
- * Creates the window for the cookies tree.
+ * make the cookie window visible.
*
* \return NSERROR_OK on success else appropriate error code on faliure.
*/
-nserror nsgtk_cookies_init(void);
+nserror nsgtk_cookies_present(void);
+/**
+ * Free any resources allocated for the cookie window.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
void nsgtk_cookies_destroy(void);
+
#endif /* __NSGTK_COOKIES_H__ */
diff --git a/frontends/gtk/gui.c b/frontends/gtk/gui.c
index e0044b54b..af24d4018 100644
--- a/frontends/gtk/gui.c
+++ b/frontends/gtk/gui.c
@@ -313,12 +313,6 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
return error;
}
- error = nsgtk_cookies_init();
- if (error != NSERROR_OK) {
- LOG("Unable to initialise cookies window.");
- return error;
- }
-
error = nsgtk_hotlist_init();
if (error != NSERROR_OK) {
LOG("Unable to initialise hotlist window.");
diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c
index cd3779e1e..811c84444 100644
--- a/frontends/gtk/scaffolding.c
+++ b/frontends/gtk/scaffolding.c
@@ -1523,9 +1523,11 @@ MULTIHANDLER(showbookmarks)
MULTIHANDLER(showcookies)
{
- gtk_widget_show(GTK_WIDGET(wndCookies));
- gdk_window_raise(nsgtk_widget_get_window(GTK_WIDGET(wndCookies)));
-
+ nserror res;
+ res = nsgtk_cookies_present();
+ if (res != NSERROR_OK) {
+ LOG("Unable to initialise cookies window.");
+ }
return TRUE;
}