[devhelp/application-menu: 4/7] core: port to GtkApplication and use the new application menus
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/application-menu: 4/7] core: port to GtkApplication and use the new application menus
- Date: Tue, 12 Jun 2012 10:59:38 +0000 (UTC)
commit 462c8f1299ed73efe4f5f54d8b4585d73b3ae501
Author: Aleksander Morgado <aleksander lanedo com>
Date: Tue Jun 12 12:49:19 2012 +0200
core: port to GtkApplication and use the new application menus
This patch evolves the `DhBase' into a fully featured new `DhApp', which
inherits from GtkApplication. The new `DhApp' will take care of every
`DhWindow' and `DhAssistant' associated to the application.
Application-specific actions are added to the new application menu:
* New window
* Preferences
* About Devhelp
* Quit
As part of this process of setting up the menu, the Preferences dialog
was modified not to be tied to any specific window.
https://bugzilla.gnome.org/show_bug.cgi?id=677927
data/ui/window.ui | 7 -
src/Makefile.am | 5 +-
src/dh-app.c | 406 +++++++++++++++++++++++++++++++++++++++++++++++
src/dh-app.h | 69 ++++++++
src/dh-assistant-view.c | 32 ++---
src/dh-assistant-view.h | 8 +-
src/dh-assistant.c | 6 +-
src/dh-assistant.h | 8 +-
src/dh-base.c | 235 ---------------------------
src/dh-base.h | 62 -------
src/dh-main.c | 239 ++++------------------------
src/dh-preferences.c | 46 ++++--
src/dh-preferences.h | 3 +-
src/dh-search.c | 1 -
src/dh-window.c | 127 +--------------
src/dh-window.h | 8 +-
16 files changed, 569 insertions(+), 693 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index 3018b54..ceec149 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -2,13 +2,11 @@
<ui>
<menubar name="MenuBar">
<menu action="FileMenu">
- <menuitem action="NewWindow"/>
<menuitem action="NewTab"/>
<separator/>
<menuitem action="Print"/>
<separator/>
<menuitem action="Close"/>
- <menuitem action="Quit"/>
</menu>
<menu action="EditMenu">
<menuitem action="Copy"/>
@@ -16,8 +14,6 @@
<menuitem action="Find"/>
<menuitem action="Find Next"/>
<menuitem action="Find Previous"/>
- <separator/>
- <menuitem action="Preferences"/>
</menu>
<menu action="ViewMenu">
<menuitem action="ZoomIn"/>
@@ -33,9 +29,6 @@
<menuitem action="ShowSearchTab"/>
<menuitem action="ShowContentsTab"/>
</menu>
- <menu action="HelpMenu">
- <menuitem action="About"/>
- </menu>
</menubar>
<toolbar name="Toolbar">
diff --git a/src/Makefile.am b/src/Makefile.am
index 355f254..11eceb3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,7 +52,7 @@ lib_LTLIBRARIES = libdevhelp-3.la
INST_H_FILES = \
dh-assistant.h \
dh-assistant-view.h \
- dh-base.h \
+ dh-app.h \
dh-book-manager.h \
dh-language.h \
dh-book.h \
@@ -73,7 +73,7 @@ libdevhelp_3_la_SOURCES = \
dh-enum-types.h \
dh-assistant.c \
dh-assistant-view.c \
- dh-base.c \
+ dh-app.c \
dh-book-manager.c \
dh-language.c \
dh-book.c \
@@ -126,4 +126,3 @@ endif
if HAVE_PLATFORM_X11
conf_platform_sources = ige-conf-gconf.c
endif
-
diff --git a/src/dh-app.c b/src/dh-app.c
new file mode 100644
index 0000000..13db0a0
--- /dev/null
+++ b/src/dh-app.c
@@ -0,0 +1,406 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2002 CodeFactory AB
+ * Copyright (C) 2002 Mikael Hallendal <micke imendio com>
+ * Copyright (C) 2004-2008 Imendio AB
+ * Copyright (C) 2012 Aleksander Morgado <aleksander gnu org>
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "ige-conf.h"
+#include "dh-util.h"
+#include "dh-app.h"
+#include "dh-preferences.h"
+#include "dh-window.h"
+#include "dh-assistant.h"
+
+struct _DhAppPrivate {
+ DhBookManager *book_manager;
+};
+
+G_DEFINE_TYPE (DhApp, dh_app, GTK_TYPE_APPLICATION);
+
+/******************************************************************************/
+
+DhBookManager *
+dh_app_peek_book_manager (DhApp *self)
+{
+ return self->priv->book_manager;
+}
+
+GtkWindow *
+dh_app_peek_first_window (DhApp *self)
+{
+ GList *l;
+
+ for (l = gtk_application_get_windows (GTK_APPLICATION (self));
+ l;
+ l = g_list_next (l)) {
+ if (DH_IS_WINDOW (l->data)) {
+ return GTK_WINDOW (l->data);
+ }
+ }
+
+ /* Create a new window */
+ dh_app_new_window (self);
+
+ /* And look for the newly created window again */
+ return dh_app_peek_first_window (self);
+}
+
+GtkWindow *
+dh_app_peek_assistant (DhApp *self)
+{
+ GList *l;
+
+ for (l = gtk_application_get_windows (GTK_APPLICATION (self));
+ l;
+ l = g_list_next (l)) {
+ if (DH_IS_ASSISTANT (l->data)) {
+ return GTK_WINDOW (l->data);
+ }
+ }
+
+ return NULL;
+}
+
+/******************************************************************************/
+/* Application action activators */
+
+void
+dh_app_new_window (DhApp *self)
+{
+ g_action_group_activate_action (G_ACTION_GROUP (self), "new-window", NULL);
+}
+
+void
+dh_app_quit (DhApp *self)
+{
+ g_action_group_activate_action (G_ACTION_GROUP (self), "quit", NULL);
+}
+
+void
+dh_app_search (DhApp *self,
+ const gchar *keyword)
+{
+ g_action_group_activate_action (G_ACTION_GROUP (self), "search", g_variant_new_string (keyword));
+}
+
+void
+dh_app_search_assistant (DhApp *self,
+ const gchar *keyword)
+{
+ g_action_group_activate_action (G_ACTION_GROUP (self), "search-assistant", g_variant_new_string (keyword));
+}
+
+void
+dh_app_focus_search (DhApp *self)
+{
+ g_action_group_activate_action (G_ACTION_GROUP (self), "focus-search", NULL);
+}
+
+void
+dh_app_raise (DhApp *self)
+{
+ g_action_group_activate_action (G_ACTION_GROUP (self), "raise", NULL);
+}
+
+/******************************************************************************/
+/* Application actions setup */
+
+static void
+new_window_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ DhApp *self = DH_APP (user_data);
+ GtkWidget *window;
+
+ window = dh_window_new (self);
+ gtk_application_add_window (GTK_APPLICATION (self), GTK_WINDOW (window));
+ gtk_widget_show_all (window);
+}
+
+static void
+preferences_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ dh_preferences_show_dialog ();
+}
+
+static void
+about_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ const gchar *authors[] = {
+ "Mikael Hallendal <micke imendio com>",
+ "Richard Hult <richard imendio com>",
+ "Johan Dahlin <johan gnome org>",
+ "Ross Burton <ross burtonini com>",
+ "Aleksander Morgado <aleksander lanedo com>",
+ NULL
+ };
+ const gchar **documenters = NULL;
+ const gchar *translator_credits = _("translator_credits");
+
+ /* i18n: Please don't translate "Devhelp" (it's marked as translatable
+ * for transliteration only) */
+ gtk_show_about_dialog (NULL,
+ "name", _("Devhelp"),
+ "version", PACKAGE_VERSION,
+ "comments", _("A developers' help browser for GNOME"),
+ "authors", authors,
+ "documenters", documenters,
+ "translator-credits",
+ (strcmp (translator_credits, "translator_credits") != 0 ?
+ translator_credits :
+ NULL),
+ "website", PACKAGE_URL,
+ "website-label", _("DevHelp Website"),
+ "logo-icon-name", PACKAGE_TARNAME,
+ NULL);
+}
+
+static void
+quit_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ DhApp *self = DH_APP (user_data);
+ GList *l;
+
+ /* Remove all windows registered in the application */
+ for (l = gtk_application_get_windows (GTK_APPLICATION (self));
+ l;
+ l = g_list_next (l)) {
+ gtk_application_remove_window (GTK_APPLICATION (self),
+ GTK_WINDOW (l->data));
+ }
+}
+
+static void
+search_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ DhApp *self = DH_APP (user_data);
+ GtkWindow *window;
+ const gchar *str;
+
+ window = dh_app_peek_first_window (self);
+ str = g_variant_get_string (parameter, NULL);
+ if (str[0] == '\0') {
+ g_warning ("Cannot search in application window: "
+ "No keyword given");
+ return;
+ }
+
+ dh_window_search (DH_WINDOW (window), str);
+ gtk_window_present (window);
+}
+
+static void
+search_assistant_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ DhApp *self = DH_APP (user_data);
+ GtkWindow *assistant;
+ const gchar *str;
+
+ str = g_variant_get_string (parameter, NULL);
+ if (str[0] == '\0') {
+ g_warning ("Cannot look for keyword in Search Assistant: "
+ "No keyword given");
+ return;
+ }
+
+ /* Look for an already registered assistant */
+ assistant = dh_app_peek_assistant (self);
+ if (!assistant) {
+ assistant = GTK_WINDOW (dh_assistant_new (self));
+ gtk_application_add_window (GTK_APPLICATION (self), assistant);
+ }
+
+ dh_assistant_search (DH_ASSISTANT (assistant), str);
+}
+
+static void
+focus_search_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ DhApp *self = DH_APP (user_data);
+ GtkWindow *window;
+
+ window = dh_app_peek_first_window (self);
+ dh_window_focus_search (DH_WINDOW (window));
+ gtk_window_present (window);
+}
+
+static void
+raise_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ DhApp *self = DH_APP (user_data);
+ GtkWindow *window;
+
+ /* Look for the first application window available and show it */
+ window = dh_app_peek_first_window (self);
+ gtk_window_present (window);
+}
+
+static GActionEntry app_entries[] = {
+ /* general actions */
+ { "new-window", new_window_cb, NULL, NULL, NULL },
+ { "preferences", preferences_cb, NULL, NULL, NULL },
+ { "about", about_cb, NULL, NULL, NULL },
+ { "quit", quit_cb, NULL, NULL, NULL },
+ /* additional commandline-specific actions */
+ { "search", search_cb, "s", NULL, NULL },
+ { "search-assistant", search_assistant_cb, "s", NULL, NULL },
+ { "focus-search", focus_search_cb, NULL, NULL, NULL },
+ { "raise", raise_cb, NULL, NULL, NULL },
+};
+
+static void
+setup_actions (DhApp *self)
+{
+ g_action_map_add_action_entries (G_ACTION_MAP (self),
+ app_entries, G_N_ELEMENTS (app_entries),
+ self);
+}
+
+/******************************************************************************/
+
+static void
+load_config_defaults (void)
+{
+ IgeConf *conf;
+ gchar *path;
+
+ conf = ige_conf_get ();
+ path = dh_util_build_data_filename ("devhelp", "devhelp.defaults", NULL);
+ ige_conf_add_defaults (conf, path);
+ g_free (path);
+}
+
+static void
+create_application_menu (DhApp *self)
+{
+ GMenu *menu, *section;
+
+ menu = g_menu_new ();
+
+ section = g_menu_new ();
+ g_menu_append (section, _("New window"), "app.new-window");
+ g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
+
+ section = g_menu_new ();
+ g_menu_append (section, _("Preferences"), "app.preferences");
+ g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
+
+ section = g_menu_new ();
+ g_menu_append (section, _("About Devhelp"), "app.about");
+ g_menu_append (section, _("Quit"), "app.quit");
+ g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
+
+ gtk_application_set_app_menu (GTK_APPLICATION (self),
+ G_MENU_MODEL (menu));
+}
+
+static void
+startup (GApplication *application)
+{
+ DhApp *self = DH_APP (application);
+
+ /* Chain up parent's startup */
+ G_APPLICATION_CLASS (dh_app_parent_class)->startup (application);
+
+ /* Setup application level actions */
+ setup_actions (self);
+
+ /* Create application menu */
+ create_application_menu (self);
+
+ /* Setup default configuration */
+ load_config_defaults ();
+
+ /* Load the book manager */
+ g_assert (self->priv->book_manager == NULL);
+ self->priv->book_manager = dh_book_manager_new ();
+ dh_book_manager_populate (self->priv->book_manager);
+}
+
+/******************************************************************************/
+
+DhApp *
+dh_app_new (void)
+{
+ DhApp *application;
+
+ g_type_init ();
+
+ /* i18n: Please don't translate "Devhelp" (it's marked as translatable
+ * for transliteration only) */
+ g_set_application_name (_("Devhelp"));
+ gtk_window_set_default_icon_name ("devhelp");
+
+ application = g_object_new (DH_TYPE_APP,
+ "application-id", "org.gnome.Devhelp",
+ "flags", G_APPLICATION_FLAGS_NONE,
+ "register-session", TRUE,
+ NULL);
+
+ return application;
+}
+
+static void
+dh_app_init (DhApp *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, DH_TYPE_APP, DhAppPrivate);
+}
+
+static void
+dispose (GObject *object)
+{
+ DhApp *self = DH_APP (object);
+
+ g_clear_object (&self->priv->book_manager);
+
+ G_OBJECT_CLASS (dh_app_parent_class)->dispose (object);
+}
+
+static void
+dh_app_class_init (DhAppClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (DhAppPrivate));
+
+ application_class->startup = startup;
+
+ object_class->dispose = dispose;
+}
diff --git a/src/dh-app.h b/src/dh-app.h
new file mode 100644
index 0000000..646cb82
--- /dev/null
+++ b/src/dh-app.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2012 Aleksander Morgado <aleksander gnu org>
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __DH_APP_H__
+#define __DH_APP_H__
+
+#include <gtk/gtk.h>
+
+#include "dh-book-manager.h"
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_APP (dh_app_get_type ())
+#define DH_APP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DH_TYPE_APP, DhApp))
+#define DH_APP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), DH_TYPE_APP, DhAppClass))
+#define DH_IS_APP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DH_TYPE_APP))
+#define DH_IS_APP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DH_TYPE_APP))
+#define DH_APP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DH_TYPE_APP, DhAppClass))
+
+typedef struct _DhApp DhApp;
+typedef struct _DhAppClass DhAppClass;
+typedef struct _DhAppPrivate DhAppPrivate;
+
+struct _DhApp {
+ GtkApplication parent_instance;
+ DhAppPrivate *priv;
+};
+
+struct _DhAppClass {
+ GtkApplicationClass parent_class;
+};
+
+GType dh_app_get_type (void) G_GNUC_CONST;
+
+DhApp *dh_app_new (void);
+
+DhBookManager *dh_app_peek_book_manager (DhApp *self);
+GtkWindow *dh_app_peek_first_window (DhApp *self);
+GtkWindow *dh_app_peek_assistant (DhApp *self);
+
+void dh_app_new_window (DhApp *self);
+void dh_app_quit (DhApp *self);
+void dh_app_search (DhApp *self,
+ const gchar *keyword);
+void dh_app_search_assistant (DhApp *self,
+ const gchar *keyword);
+void dh_app_focus_search (DhApp *self);
+void dh_app_raise (DhApp *self);
+
+G_END_DECLS
+
+#endif /* __DH_APP_H__ */
diff --git a/src/dh-assistant-view.c b/src/dh-assistant-view.c
index 663e5a3..a3f710f 100644
--- a/src/dh-assistant-view.c
+++ b/src/dh-assistant-view.c
@@ -30,7 +30,7 @@
#include "dh-window.h"
typedef struct {
- DhBase *base;
+ DhApp *application;
DhLink *link;
gchar *current_search;
gboolean snippet_loaded;
@@ -50,8 +50,8 @@ view_finalize (GObject *object)
g_object_unref (priv->link);
}
- if (priv->base) {
- g_object_unref (priv->base);
+ if (priv->application) {
+ g_object_unref (priv->application);
}
g_free (priv->current_search);
@@ -100,7 +100,7 @@ assistant_decide_policy (WebKitWebView *web_view,
return TRUE;
}
- window = dh_base_get_window (priv->base);
+ window = GTK_WIDGET (dh_app_peek_first_window (priv->application));
_dh_window_display_uri (DH_WINDOW (window), uri);
webkit_policy_decision_ignore (decision);
@@ -128,7 +128,7 @@ assistant_navigation_requested (WebKitWebView *web_view,
else if (g_str_has_prefix (uri, "file://")) {
GtkWidget *window;
- window = dh_base_get_window (priv->base);
+ window = GTK_WIDGET (dh_app_peek_first_window (priv->application));
_dh_window_display_uri (DH_WINDOW (window), uri);
}
@@ -172,18 +172,6 @@ dh_assistant_view_init (DhAssistantView *view)
{
}
-DhBase*
-dh_assistant_view_get_base (DhAssistantView *view)
-{
- DhAssistantViewPriv *priv;
-
- g_return_val_if_fail (DH_IS_ASSISTANT_VIEW (view), NULL);
-
- priv = GET_PRIVATE (view);
-
- return priv->base;
-}
-
GtkWidget*
dh_assistant_view_new (void)
{
@@ -471,7 +459,7 @@ dh_assistant_view_search (DhAssistantView *view,
g_free (priv->current_search);
priv->current_search = g_strdup (str);
- book_manager = dh_base_get_book_manager (dh_assistant_view_get_base (view));
+ book_manager = dh_app_peek_book_manager (priv->application);
prefix_link = NULL;
exact_link = NULL;
@@ -529,15 +517,15 @@ dh_assistant_view_search (DhAssistantView *view,
}
void
-dh_assistant_view_set_base (DhAssistantView *view,
- DhBase *base)
+dh_assistant_view_set_app (DhAssistantView *view,
+ DhApp *application)
{
DhAssistantViewPriv *priv;
g_return_if_fail (DH_IS_ASSISTANT_VIEW (view));
- g_return_if_fail (DH_IS_BASE (base));
+ g_return_if_fail (DH_IS_APP (application));
priv = GET_PRIVATE (view);
- priv->base = g_object_ref (base);
+ priv->application = g_object_ref (application);
}
diff --git a/src/dh-assistant-view.h b/src/dh-assistant-view.h
index 2ecfbce..0d1c4ee 100644
--- a/src/dh-assistant-view.h
+++ b/src/dh-assistant-view.h
@@ -26,7 +26,7 @@
#else
#include <webkit/webkit.h>
#endif
-#include "dh-base.h"
+#include "dh-app.h"
#include "dh-link.h"
G_BEGIN_DECLS
@@ -53,9 +53,9 @@ GType dh_assistant_view_get_type (void) G_GNUC_CONST;
GtkWidget* dh_assistant_view_new (void);
gboolean dh_assistant_view_search (DhAssistantView *view,
const gchar *str);
-DhBase* dh_assistant_view_get_base (DhAssistantView *view);
-void dh_assistant_view_set_base (DhAssistantView *view,
- DhBase *base);
+DhApp* dh_assistant_view_peek_app (DhAssistantView *view);
+void dh_assistant_view_set_app (DhAssistantView *view,
+ DhApp *application);
gboolean dh_assistant_view_set_link (DhAssistantView *view,
DhLink *link);
G_END_DECLS
diff --git a/src/dh-assistant.c b/src/dh-assistant.c
index c614c59..c262b1a 100644
--- a/src/dh-assistant.c
+++ b/src/dh-assistant.c
@@ -36,7 +36,7 @@ typedef struct {
static void dh_assistant_class_init (DhAssistantClass *klass);
static void dh_assistant_init (DhAssistant *assistant);
-G_DEFINE_TYPE (DhAssistant, dh_assistant, GTK_TYPE_WINDOW);
+G_DEFINE_TYPE (DhAssistant, dh_assistant, GTK_TYPE_APPLICATION_WINDOW);
#define GET_PRIVATE(instance) G_TYPE_INSTANCE_GET_PRIVATE \
(instance, DH_TYPE_ASSISTANT, DhAssistantPriv)
@@ -103,7 +103,7 @@ dh_assistant_init (DhAssistant *assistant)
}
GtkWidget *
-dh_assistant_new (DhBase *base)
+dh_assistant_new (DhApp *application)
{
GtkWidget *assistant;
DhAssistantPriv *priv;
@@ -112,7 +112,7 @@ dh_assistant_new (DhBase *base)
priv = GET_PRIVATE (assistant);
- dh_assistant_view_set_base (DH_ASSISTANT_VIEW (priv->view), base);
+ dh_assistant_view_set_app (DH_ASSISTANT_VIEW (priv->view), application);
return assistant;
}
diff --git a/src/dh-assistant.h b/src/dh-assistant.h
index 771ecbe..0204fb5 100644
--- a/src/dh-assistant.h
+++ b/src/dh-assistant.h
@@ -22,7 +22,7 @@
#define __DH_ASSISTANT_H__
#include <gtk/gtk.h>
-#include "dh-base.h"
+#include "dh-app.h"
G_BEGIN_DECLS
@@ -37,15 +37,15 @@ typedef struct _DhAssistant DhAssistant;
typedef struct _DhAssistantClass DhAssistantClass;
struct _DhAssistant {
- GtkWindow parent_instance;
+ GtkApplicationWindow parent_instance;
};
struct _DhAssistantClass {
- GtkWindowClass parent_class;
+ GtkApplicationWindowClass parent_class;
};
GType dh_assistant_get_type (void) G_GNUC_CONST;
-GtkWidget *dh_assistant_new (DhBase *base);
+GtkWidget *dh_assistant_new (DhApp *application);
gboolean dh_assistant_search (DhAssistant *assistant,
const gchar *str);
diff --git a/src/dh-main.c b/src/dh-main.c
index f4b8da4..2dd3117 100644
--- a/src/dh-main.c
+++ b/src/dh-main.c
@@ -32,7 +32,7 @@
#include <gdk/gdkx.h>
#endif
-#include "dh-base.h"
+#include "dh-app.h"
#include "dh-window.h"
#include "dh-assistant.h"
@@ -72,178 +72,39 @@ static GOptionEntry options[] = {
};
static void
-search_normal (DhWindow *window,
- const gchar *str)
+run_action (DhApp *application,
+ gboolean is_remote)
{
- if (str[0] == '\0') {
- return;
- }
-
- dh_window_search (window, str);
-}
-
-static gboolean
-search_assistant (DhBase *base,
- const gchar *str)
-{
- static GtkWidget *assistant;
-
- if (str[0] == '\0') {
- return FALSE;
- }
-
- if (!assistant) {
- assistant = dh_base_new_assistant (base);
- g_signal_connect (assistant, "destroy",
- G_CALLBACK (gtk_widget_destroyed),
- &assistant);
+ if (option_quit) {
+ dh_app_quit (application);
+ } else if (option_search) {
+ dh_app_search (application, option_search);
+ } else if (option_search_assistant) {
+ dh_app_search_assistant (application, option_search_assistant);
+ } else if (option_focus_search) {
+ dh_app_focus_search (application);
+ } else {
+ if (is_remote)
+ dh_app_raise (application);
}
-
- return dh_assistant_search (DH_ASSISTANT (assistant), str);
-}
-
-static GApplication *application = NULL;
-
-static void
-dh_quit (GAction *action,
- GVariant *parameter,
- gpointer data)
-{
- gtk_main_quit ();
-}
-
-static void
-dh_search (GAction *action,
- GVariant *parameter,
- gpointer data)
-{
- DhBase *base = data;
- GtkWidget *window;
-
- window = dh_base_get_window (base);
- search_normal (DH_WINDOW (window),
- g_variant_get_string (parameter, NULL));
- gtk_window_present (GTK_WINDOW (window));
-}
-
-static void
-dh_search_assistant (GAction *action,
- GVariant *parameter,
- gpointer data)
-{
- DhBase *base = data;
-
- search_assistant (base,
- g_variant_get_string (parameter, NULL));
}
static void
-dh_focus_search (GAction *action,
- GVariant *parameter,
- gpointer data)
+activate_cb (GtkApplication *application)
{
- DhBase *base = data;
- GtkWidget *window;
+ /* This is the primary instance */
+ dh_app_new_window (DH_APP (application));
- window = dh_base_get_window (base);
- dh_window_focus_search (DH_WINDOW (window));
- gtk_window_present (GTK_WINDOW (window));
-}
-
-static void
-dh_raise (GAction *action,
- GVariant *parameter,
- gpointer data)
-{
- DhBase *base = data;
- GtkWidget *window;
-
- window = dh_base_get_window (base);
- gtk_window_present (GTK_WINDOW (window));
-}
-
-enum
-{
- ACTION_QUIT,
- ACTION_SEARCH,
- ACTION_SEARCH_ASSISTANT,
- ACTION_FOCUS_SEARCH,
- ACTION_RAISE,
- N_ACTIONS,
-};
-
-static const struct dh_action {
- const gchar * const name;
- const GVariantType *expected_type;
- void (* handler) (GAction *action, GVariant *parameter, gpointer data);
-} actions[N_ACTIONS] = {
- [ACTION_QUIT] = { "quit", NULL, dh_quit },
- [ACTION_SEARCH] = { "search", G_VARIANT_TYPE_STRING, dh_search },
- [ACTION_SEARCH_ASSISTANT] = { "search-assistant", G_VARIANT_TYPE_STRING, dh_search_assistant },
- [ACTION_FOCUS_SEARCH] = { "focus-search", NULL, dh_focus_search },
- [ACTION_RAISE] = { "raise", NULL, dh_raise },
-};
-
-static void
-dh_register_actions (GApplication *application,
- DhBase *base)
-{
- guint i;
-
- GSimpleActionGroup *action_group;
- GSimpleAction *action;
-
- action_group = g_simple_action_group_new ();
-
- for (i = 0; i < G_N_ELEMENTS (actions); i++) {
- action = g_simple_action_new (actions[i].name, actions[i].expected_type);
- g_signal_connect (action, "activate", G_CALLBACK (actions[i].handler), base);
- g_simple_action_group_insert (action_group, G_ACTION (action));
- g_object_unref (action);
- }
-
- g_application_set_action_group (application, G_ACTION_GROUP (action_group));
- g_object_unref (action_group);
-}
-
-static int
-activate (GApplication *application,
- gpointer data)
-{
- DhBase *base = data;
-
- if (option_quit) {
- /* No running Devhelps so just quit */
- return EXIT_SUCCESS;
- }
-
- if (!option_search_assistant) {
- GtkWidget *window;
-
- window = dh_base_new_window (base);
-
- if (option_search) {
- search_normal (DH_WINDOW (window), option_search);
- }
-
- gtk_widget_show (window);
- } else {
- if (!search_assistant (base, option_search_assistant)) {
- return EXIT_SUCCESS;
- }
- }
-
- gtk_main ();
-
- return EXIT_SUCCESS;
+ /* Run the requested action from the command line */
+ run_action (DH_APP (application), FALSE);
}
int
main (int argc, char **argv)
{
- DhBase *base;
- GError *error = NULL;
- int status;
+ DhApp *application;
+ GError *error = NULL;
+ gint status;
#ifdef GDK_WINDOWING_QUARTZ
{
@@ -266,8 +127,6 @@ main (int argc, char **argv)
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- g_thread_init (NULL);
-
if (!gtk_init_with_args (&argc, &argv, NULL, options, GETTEXT_PACKAGE, &error)) {
g_printerr ("%s\n", error->message);
return EXIT_FAILURE;
@@ -278,66 +137,32 @@ main (int argc, char **argv)
return EXIT_SUCCESS;
}
- /* i18n: Please don't translate "Devhelp" (it's marked as translatable
- * for transliteration only) */
- g_set_application_name (_("Devhelp"));
- gtk_window_set_default_icon_name ("devhelp");
+ /* Create new DhApp */
+ application = dh_app_new ();
+ g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL);
- /* Create our base application. Needs to be created before the GApplication,
- * as we will pass it as data to the 'activate' callback */
- base = dh_base_new ();
-
- /* Create new GApplication */
- application = g_application_new ("org.gnome.Devhelp", 0);
-
- /* Register all known actions */
- g_signal_connect (application, "activate", G_CALLBACK (activate), base);
- dh_register_actions (application, base);
+ /* Set it as the default application */
+ g_application_set_default (G_APPLICATION (application));
/* Try to register the application... */
- if (!g_application_register (application, NULL, &error)) {
+ if (!g_application_register (G_APPLICATION (application), NULL, &error)) {
g_printerr ("Couldn't register Devhelp instance: '%s'\n",
error ? error->message : "");
g_object_unref (application);
- g_object_unref (base);
return EXIT_FAILURE;
}
/* Actions on a remote Devhelp already running? */
if (g_application_get_is_remote (G_APPLICATION (application))) {
- if (option_quit) {
- g_action_group_activate_action (G_ACTION_GROUP (application),
- actions[ACTION_QUIT].name,
- NULL);
- } else if (option_search) {
- g_debug ("Searching in remote instance... '%s'", option_search);
- g_action_group_activate_action (G_ACTION_GROUP (application),
- actions[ACTION_SEARCH].name,
- g_variant_new_string (option_search));
- } else if (option_search_assistant) {
- g_action_group_activate_action (G_ACTION_GROUP (application),
- actions[ACTION_SEARCH_ASSISTANT].name,
- g_variant_new_string (option_search_assistant));
- } else if (option_focus_search) {
- g_action_group_activate_action (G_ACTION_GROUP (application),
- actions[ACTION_FOCUS_SEARCH].name,
- NULL);
- } else {
- g_action_group_activate_action (G_ACTION_GROUP (application),
- actions[ACTION_RAISE].name,
- NULL);
- }
-
- gdk_notify_startup_complete ();
+ /* Run the requested action from the command line */
+ run_action (application, TRUE);
g_object_unref (application);
- g_object_unref (base);
return EXIT_SUCCESS;
}
- /* And run the GApplication */
- status = g_application_run (application, argc, argv);
+ /* And run the GtkApplication */
+ status = g_application_run (G_APPLICATION (application), argc, argv);
- g_object_unref (base);
g_object_unref (application);
return status;
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
index 0f33810..4d6581e 100644
--- a/src/dh-preferences.c
+++ b/src/dh-preferences.c
@@ -25,7 +25,7 @@
#include "dh-util.h"
#include "dh-preferences.h"
#include "ige-conf.h"
-#include "dh-base.h"
+#include "dh-app.h"
typedef struct {
GtkWidget *dialog;
@@ -119,22 +119,32 @@ static DhPreferences *prefs;
static void
preferences_init (void)
{
- if (!prefs) {
- prefs = g_new0 (DhPreferences, 1);
- prefs->book_manager = dh_base_get_book_manager (dh_base_get ());
- g_signal_connect (prefs->book_manager,
- "book-created",
- G_CALLBACK (preferences_bookshelf_book_created_cb),
- NULL);
- g_signal_connect (prefs->book_manager,
- "book-deleted",
- G_CALLBACK (preferences_bookshelf_book_deleted_cb),
- NULL);
- g_signal_connect (prefs->book_manager,
- "notify::group-by-language",
- G_CALLBACK (preferences_bookshelf_group_by_language_cb),
- NULL);
+ GApplication *app;
+
+ if (prefs) {
+ return;
+ }
+
+ app = g_application_get_default ();
+ if (!app) {
+ g_warning ("Cannot launch Preferences: No default application found");
+ return;
}
+
+ prefs = g_new0 (DhPreferences, 1);
+ prefs->book_manager = g_object_ref (dh_app_peek_book_manager (DH_APP (app)));
+ g_signal_connect (prefs->book_manager,
+ "book-created",
+ G_CALLBACK (preferences_bookshelf_book_created_cb),
+ NULL);
+ g_signal_connect (prefs->book_manager,
+ "book-deleted",
+ G_CALLBACK (preferences_bookshelf_book_deleted_cb),
+ NULL);
+ g_signal_connect (prefs->book_manager,
+ "notify::group-by-language",
+ G_CALLBACK (preferences_bookshelf_group_by_language_cb),
+ NULL);
}
static void
@@ -144,6 +154,7 @@ preferences_shutdown (void)
return;
}
+ g_object_unref (prefs->book_manager);
gtk_list_store_clear (prefs->bookshelf_store);
gtk_widget_destroy (GTK_WIDGET (prefs->dialog));
@@ -805,7 +816,7 @@ preferences_bookshelf_group_by_language_toggled_cb (GtkToggleButton *button,
}
void
-dh_preferences_show_dialog (GtkWindow *parent)
+dh_preferences_show_dialog (void)
{
gchar *path;
GtkBuilder *builder;
@@ -880,6 +891,5 @@ dh_preferences_show_dialog (GtkWindow *parent)
G_CALLBACK (preferences_dialog_response),
NULL);
- gtk_window_set_transient_for (GTK_WINDOW (prefs->dialog), parent);
gtk_widget_show_all (prefs->dialog);
}
diff --git a/src/dh-preferences.h b/src/dh-preferences.h
index f7f13d4..c7f6670 100644
--- a/src/dh-preferences.h
+++ b/src/dh-preferences.h
@@ -26,9 +26,8 @@
G_BEGIN_DECLS
-void dh_preferences_show_dialog (GtkWindow *parent);
+void dh_preferences_show_dialog (void);
G_END_DECLS
#endif /* __DH_PREFERENCES_H__ */
-
diff --git a/src/dh-search.c b/src/dh-search.c
index 84a19f9..bff8f90 100644
--- a/src/dh-search.c
+++ b/src/dh-search.c
@@ -30,7 +30,6 @@
#include "dh-keyword-model.h"
#include "dh-search.h"
#include "dh-preferences.h"
-#include "dh-base.h"
#include "dh-util.h"
#include "dh-book-manager.h"
#include "dh-book.h"
diff --git a/src/dh-window.c b/src/dh-window.c
index 032da17..10e4227 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -44,21 +44,17 @@
#include "dh-book-tree.h"
#include "dh-book-manager.h"
#include "dh-book.h"
-#include "dh-preferences.h"
#include "dh-search.h"
#include "dh-window.h"
#include "dh-util.h"
#include "dh-marshal.h"
#include "dh-enum-types.h"
#include "eggfindbar.h"
-#include "ige-conf.h"
#define FULLSCREEN_ANIMATION_SPEED 4
#define TAB_WIDTH_N_CHARS 15
struct _DhWindowPriv {
- DhBase *base;
-
GtkWidget *main_box;
GtkWidget *menu_box;
GtkWidget *hpaned;
@@ -164,25 +160,12 @@ static void window_close_tab (DhWindow *window,
gint page_num);
static gboolean do_search (DhWindow *window);
-G_DEFINE_TYPE (DhWindow, dh_window, GTK_TYPE_WINDOW);
+G_DEFINE_TYPE (DhWindow, dh_window, GTK_TYPE_APPLICATION_WINDOW);
#define GET_PRIVATE(instance) G_TYPE_INSTANCE_GET_PRIVATE \
(instance, DH_TYPE_WINDOW, DhWindowPriv);
static void
-window_activate_new_window (GtkAction *action,
- DhWindow *window)
-{
- DhWindowPriv *priv;
- GtkWidget *new_window;
-
- priv = window->priv;
-
- new_window = dh_base_new_window (priv->base);
- gtk_widget_show (new_window);
-}
-
-static void
window_activate_new_tab (GtkAction *action,
DhWindow *window)
{
@@ -237,13 +220,6 @@ window_activate_close (GtkAction *action,
}
static void
-window_activate_quit (GtkAction *action,
- DhWindow *window)
-{
- dh_base_quit (window->priv->base);
-}
-
-static void
window_activate_copy (GtkAction *action,
DhWindow *window)
{
@@ -658,13 +634,6 @@ window_leave_fullscreen_mode (GtkAction *action,
}
static void
-window_activate_preferences (GtkAction *action,
- DhWindow *window)
-{
- dh_preferences_show_dialog (GTK_WINDOW (window));
-}
-
-static void
window_activate_back (GtkAction *action,
DhWindow *window)
{
@@ -725,52 +694,15 @@ window_activate_show_search (GtkAction *action,
}
static void
-window_activate_about (GtkAction *action,
- DhWindow *window)
-{
- const gchar *authors[] = {
- "Mikael Hallendal <micke imendio com>",
- "Richard Hult <richard imendio com>",
- "Johan Dahlin <johan gnome org>",
- "Ross Burton <ross burtonini com>",
- "Aleksander Morgado <aleksander lanedo com>",
- NULL
- };
- const gchar **documenters = NULL;
- const gchar *translator_credits = _("translator_credits");
-
- /* i18n: Please don't translate "Devhelp" (it's marked as translatable
- * for transliteration only) */
- gtk_show_about_dialog (GTK_WINDOW (window),
- "name", _("Devhelp"),
- "version", PACKAGE_VERSION,
- "comments", _("A developers' help browser for GNOME"),
- "authors", authors,
- "documenters", documenters,
- "translator-credits",
- strcmp (translator_credits, "translator_credits") != 0 ?
- translator_credits : NULL,
- "website", PACKAGE_URL,
- "website-label", _("DevHelp Website"),
- "logo-icon-name", PACKAGE_TARNAME,
- NULL);
-}
-
-static void
window_open_link_cb (DhWindow *window,
const char *location,
DhOpenLinkFlags flags)
{
- DhWindowPriv *priv;
- priv = window->priv;
-
if (flags & DH_OPEN_LINK_NEW_TAB) {
window_open_new_tab (window, location, FALSE);
}
else if (flags & DH_OPEN_LINK_NEW_WINDOW) {
- GtkWidget *new_window;
- new_window = dh_base_new_window (priv->base);
- gtk_widget_show (new_window);
+ dh_app_new_window (DH_APP (gtk_window_get_application (GTK_WINDOW (window))));
}
}
@@ -782,16 +714,12 @@ static const GtkActionEntry actions[] = {
{ "HelpMenu", NULL, N_("_Help") },
/* File menu */
- { "NewWindow", GTK_STOCK_NEW, N_("_New Window"), "<control>N", NULL,
- G_CALLBACK (window_activate_new_window) },
{ "NewTab", GTK_STOCK_NEW, N_("New _Tab"), "<control>T", NULL,
G_CALLBACK (window_activate_new_tab) },
{ "Print", GTK_STOCK_PRINT, N_("_Printâ"), "<control>P", NULL,
G_CALLBACK (window_activate_print) },
{ "Close", GTK_STOCK_CLOSE, NULL, NULL, NULL,
G_CALLBACK (window_activate_close) },
- { "Quit", GTK_STOCK_QUIT, NULL, NULL, NULL,
- G_CALLBACK (window_activate_quit) },
/* Edit menu */
{ "Copy", GTK_STOCK_COPY, NULL, "<control>C", NULL,
@@ -802,8 +730,6 @@ static const GtkActionEntry actions[] = {
G_CALLBACK (window_find_next_cb) },
{ "Find Previous", GTK_STOCK_GO_BACK, N_("Find Previous"), "<shift><control>G", NULL,
G_CALLBACK (window_find_previous_cb) },
- { "Preferences", GTK_STOCK_PREFERENCES, NULL, NULL, NULL,
- G_CALLBACK (window_activate_preferences) },
/* Go menu */
{ "Back", GTK_STOCK_GO_BACK, NULL, "<alt>Left",
@@ -830,10 +756,6 @@ static const GtkActionEntry actions[] = {
N_("Use the normal text size"),
G_CALLBACK (window_activate_zoom_default) },
- /* About menu */
- { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL,
- G_CALLBACK (window_activate_about) },
-
/* Fullscreen toolbar */
{ "LeaveFullscreen", GTK_STOCK_LEAVE_FULLSCREEN, NULL,
NULL, N_("Leave fullscreen mode"),
@@ -853,22 +775,8 @@ static const gchar* important_actions[] = {
};
static void
-window_finalize (GObject *object)
-{
- DhWindowPriv *priv = GET_PRIVATE (object);
-
- g_object_unref (priv->base);
-
- G_OBJECT_CLASS (dh_window_parent_class)->finalize (object);
-}
-
-static void
dh_window_class_init (DhWindowClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = window_finalize;
-
signals[OPEN_LINK] =
g_signal_new ("open-link",
G_TYPE_FROM_CLASS (klass),
@@ -1094,7 +1002,6 @@ window_populate (DhWindow *window)
#ifdef GDK_WINDOWING_QUARTZ
{
- GtkWidget *widget, *sep;
GtkOSXApplication *theApp;
/* Hide toolbar labels. */
@@ -1103,25 +1010,6 @@ window_populate (DhWindow *window)
/* Setup menubar. */
theApp = g_object_new (GTK_TYPE_OSX_APPLICATION, NULL);
gtk_osxapplication_set_menu_bar (theApp, GTK_MENU_SHELL (menubar));
- gtk_widget_hide (menubar);
-
- widget = gtk_ui_manager_get_widget (priv->manager, "/MenuBar/FileMenu/Quit");
- gtk_widget_hide (widget);
-
- widget = gtk_ui_manager_get_widget (priv->manager, "/MenuBar/HelpMenu/About");
- gtk_osxapplication_insert_app_menu_item (theApp, widget, 0);
- sep = gtk_separator_menu_item_new ();
- g_object_ref (sep);
- gtk_osxapplication_insert_app_menu_item (theApp, sep, 1);
-
- widget = gtk_ui_manager_get_widget (priv->manager, "/MenuBar/EditMenu/Preferences");
- gtk_osxapplication_insert_app_menu_item (theApp, widget, 2);
- sep = gtk_separator_menu_item_new ();
- g_object_ref (sep);
- gtk_osxapplication_insert_app_menu_item (theApp, sep, 3);
-
- widget = gtk_ui_manager_get_widget (priv->manager, "/MenuBar/HelpMenu");
- gtk_osxapplication_set_help_menu (theApp, GTK_MENU_ITEM (widget));
g_signal_connect (theApp,
"NSApplicationWillTerminate",
@@ -1160,7 +1048,7 @@ window_populate (DhWindow *window)
GTK_SHADOW_IN);
gtk_container_set_border_width (GTK_CONTAINER (book_tree_sw), 2);
- book_manager = dh_base_get_book_manager (priv->base);
+ book_manager = dh_app_peek_book_manager (DH_APP (gtk_window_get_application (GTK_WINDOW (window))));
priv->book_tree = dh_book_tree_new (book_manager);
gtk_container_add (GTK_CONTAINER (book_tree_sw),
@@ -1236,12 +1124,10 @@ window_populate (DhWindow *window)
window_open_new_tab (window, NULL, TRUE);
}
-
static gchar *
find_library_equivalent (DhWindow *window,
const gchar *uri)
{
- DhWindowPriv *priv;
gchar **components;
GList *iter;
DhLink *link;
@@ -1255,8 +1141,7 @@ find_library_equivalent (DhWindow *window,
book_id = components[4];
filename = components[6];
- priv = window->priv;
- book_manager = dh_base_get_book_manager (priv->base);
+ book_manager = dh_app_peek_book_manager (DH_APP (gtk_window_get_application (GTK_WINDOW (window))));
/* use list pointer to iterate */
for (books = dh_book_manager_get_books (book_manager);
@@ -2016,7 +1901,7 @@ window_tab_set_title (DhWindow *window,
}
GtkWidget *
-dh_window_new (DhBase *base)
+dh_window_new (DhApp *application)
{
DhWindow *window;
DhWindowPriv *priv;
@@ -2024,7 +1909,7 @@ dh_window_new (DhBase *base)
window = g_object_new (DH_TYPE_WINDOW, NULL);
priv = window->priv;
- priv->base = g_object_ref (base);
+ gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (application));
window_populate (window);
diff --git a/src/dh-window.h b/src/dh-window.h
index 5b98f48..954d73e 100644
--- a/src/dh-window.h
+++ b/src/dh-window.h
@@ -24,7 +24,7 @@
#define __DH_WINDOW_H__
#include <gtk/gtk.h>
-#include "dh-base.h"
+#include "dh-app.h"
G_BEGIN_DECLS
@@ -46,12 +46,12 @@ typedef enum
} DhOpenLinkFlags;
struct _DhWindow {
- GtkWindow parent_instance;
+ GtkApplicationWindow parent_instance;
DhWindowPriv *priv;
};
struct _DhWindowClass {
- GtkWindowClass parent_class;
+ GtkApplicationWindowClass parent_class;
/* Signals */
void (*open_link) (DhWindow *window,
@@ -60,7 +60,7 @@ struct _DhWindowClass {
};
GType dh_window_get_type (void) G_GNUC_CONST;
-GtkWidget *dh_window_new (DhBase *base);
+GtkWidget *dh_window_new (DhApp *application);
void dh_window_search (DhWindow *window,
const gchar *str);
void dh_window_focus_search (DhWindow *window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]