[devhelp/wip/devhelp-next] Split dh-util between lib and app
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/devhelp-next] Split dh-util between lib and app
- Date: Thu, 22 Feb 2018 18:06:36 +0000 (UTC)
commit ed0c8c83569a31e3ac86dfab77b07687fd769cc3
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Feb 22 18:53:15 2018 +0100
Split dh-util between lib and app
devhelp/dh-util.c | 145 -------------------------------------------
devhelp/dh-util.h | 13 +----
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/dh-app.c | 2 +-
src/dh-assistant.c | 2 +-
src/dh-preferences.c | 2 +-
src/dh-utils-app.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/dh-utils-app.h | 41 ++++++++++++
src/dh-window.c | 2 +-
10 files changed, 215 insertions(+), 161 deletions(-)
---
diff --git a/devhelp/dh-util.c b/devhelp/dh-util.c
index 6d0830c..5c6dda9 100644
--- a/devhelp/dh-util.c
+++ b/devhelp/dh-util.c
@@ -107,151 +107,6 @@ dh_util_create_data_uri_for_filename (const gchar *filename,
return uri;
}
-/* Set the given fonts on the given view. */
-void
-dh_util_view_set_font (WebKitWebView *view,
- const gchar *font_name_fixed,
- const gchar *font_name_variable)
-{
- PangoFontDescription *font_desc_fixed;
- PangoFontDescription *font_desc_variable;
- guint font_size_fixed;
- guint font_size_variable;
- guint font_size_fixed_px;
- guint font_size_variable_px;
- WebKitSettings *settings;
-
- g_return_if_fail (WEBKIT_IS_WEB_VIEW (view));
- g_return_if_fail (font_name_fixed != NULL);
- g_return_if_fail (font_name_variable != NULL);
-
- /* Get the font size. */
- font_desc_fixed = pango_font_description_from_string (font_name_fixed);
- font_desc_variable = pango_font_description_from_string (font_name_variable);
- font_size_fixed = pango_font_description_get_size (font_desc_fixed) / PANGO_SCALE;
- font_size_variable = pango_font_description_get_size (font_desc_variable) / PANGO_SCALE;
- font_size_fixed_px = webkit_settings_font_size_to_pixels (font_size_fixed);
- font_size_variable_px = webkit_settings_font_size_to_pixels (font_size_variable);
-
- /* Set the fonts. */
- settings = webkit_web_view_get_settings (view);
- webkit_settings_set_zoom_text_only (settings, TRUE);
- webkit_settings_set_monospace_font_family (settings, font_name_fixed);
- webkit_settings_set_default_monospace_font_size (settings, font_size_fixed_px);
- webkit_settings_set_serif_font_family (settings, font_name_variable);
- webkit_settings_set_default_font_size (settings, font_size_variable_px);
-
- g_debug ("Set font-fixed to '%s' (%i) and font-variable to '%s' (%i).",
- font_name_fixed, font_size_fixed_px, font_name_variable, font_size_variable_px);
-
- pango_font_description_free (font_desc_fixed);
- pango_font_description_free (font_desc_variable);
-}
-
-static void
-introspect_window_gsettings (GSettings *window_settings,
- gboolean *has_required_keys,
- gboolean *has_maximized_key)
-{
- GSettingsSchema *schema = NULL;
-
- g_object_get (window_settings,
- "settings-schema", &schema,
- NULL);
-
- *has_required_keys = (g_settings_schema_has_key (schema, "width") &&
- g_settings_schema_has_key (schema, "height"));
-
- *has_maximized_key = g_settings_schema_has_key (schema, "maximized");
-
- g_settings_schema_unref (schema);
-}
-
-void
-dh_util_window_settings_save (GtkWindow *window,
- GSettings *settings)
-{
- gboolean has_required_keys;
- gboolean has_maximized_key;
- gint width;
- gint height;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
- g_return_if_fail (G_IS_SETTINGS (settings));
-
- introspect_window_gsettings (settings, &has_required_keys, &has_maximized_key);
- g_return_if_fail (has_required_keys);
-
- if (has_maximized_key) {
- GdkWindowState state;
- gboolean maximized;
-
- state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
- maximized = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
-
- g_settings_set_boolean (settings, "maximized", maximized);
-
- /* If maximized don't save the size. */
- if (maximized)
- return;
- }
-
- /* Store the dimensions */
- gtk_window_get_size (GTK_WINDOW (window), &width, &height);
- g_settings_set_int (settings, "width", width);
- g_settings_set_int (settings, "height", height);
-}
-
-/* This should be called when @gtk_window is realized (i.e. its GdkWindow is
- * created) but not yet mapped (i.e. gtk_widget_show() has not yet been called,
- * so that when it is shown it already has the good size).
- */
-void
-dh_util_window_settings_restore (GtkWindow *gtk_window,
- GSettings *settings)
-{
- gboolean has_required_keys;
- gboolean has_maximized_key;
- gint width;
- gint height;
-
- g_return_if_fail (GTK_IS_WINDOW (gtk_window));
- g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (gtk_window)));
- g_return_if_fail (G_IS_SETTINGS (settings));
-
- introspect_window_gsettings (settings, &has_required_keys, &has_maximized_key);
- g_return_if_fail (has_required_keys);
-
- width = g_settings_get_int (settings, "width");
- height = g_settings_get_int (settings, "height");
-
- if (width > 1 && height > 1) {
- GdkDisplay *display;
- GdkWindow *gdk_window;
- GdkMonitor *monitor;
- GdkRectangle monitor_workarea;
- gint max_width;
- gint max_height;
-
- display = gtk_widget_get_display (GTK_WIDGET (gtk_window));
- /* To get the GdkWindow the widget must be realized. */
- gdk_window = gtk_widget_get_window (GTK_WIDGET (gtk_window));
- monitor = gdk_display_get_monitor_at_window (display, gdk_window);
- gdk_monitor_get_workarea (monitor, &monitor_workarea);
-
- max_width = monitor_workarea.width;
- max_height = monitor_workarea.height;
-
- width = CLAMP (width, 0, max_width);
- height = CLAMP (height, 0, max_height);
-
- gtk_window_set_default_size (gtk_window, width, height);
- }
-
- if (has_maximized_key && g_settings_get_boolean (settings, "maximized"))
- gtk_window_maximize (gtk_window);
-}
-
/* Adds q2 onto the end of q1, and frees q2. */
void
dh_util_queue_concat (GQueue *q1,
diff --git a/devhelp/dh-util.h b/devhelp/dh-util.h
index 6e55858..ff325de 100644
--- a/devhelp/dh-util.h
+++ b/devhelp/dh-util.h
@@ -21,8 +21,7 @@
#ifndef DH_UTIL_H
#define DH_UTIL_H
-#include <gtk/gtk.h>
-#include <webkit2/webkit2.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
@@ -34,16 +33,6 @@ void dh_util_ascii_strtitle (gchar *str);
gchar *dh_util_create_data_uri_for_filename (const gchar *filename,
const gchar *mime_type);
-void dh_util_view_set_font (WebKitWebView *view,
- const gchar *font_name_fixed,
- const gchar *font_name_variable);
-
-void dh_util_window_settings_save (GtkWindow *window,
- GSettings *settings);
-
-void dh_util_window_settings_restore (GtkWindow *gtk_window,
- GSettings *settings);
-
void dh_util_queue_concat (GQueue *q1,
GQueue *q2);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 21dc321..4e2b637 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -27,6 +27,7 @@ src/dh-preferences.c
src/dh-preferences.ui
src/dh-tab.c
src/dh-tab-label.c
+src/dh-utils-app.c
src/dh-web-view.c
src/dh-window.c
src/dh-window.ui
diff --git a/src/Makefile.am b/src/Makefile.am
index 5a88700..c4d4ae8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,7 @@ app_headers = \
dh-preferences.h \
dh-tab.h \
dh-tab-label.h \
+ dh-utils-app.h \
dh-web-view.h \
dh-window.h \
tepl-info-bar.h \
@@ -24,6 +25,7 @@ app_c_files = \
dh-preferences.c \
dh-tab.c \
dh-tab-label.c \
+ dh-utils-app.c \
dh-web-view.c \
dh-window.c \
tepl-info-bar.c \
diff --git a/src/dh-app.c b/src/dh-app.c
index d3b0ee0..9c66169 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -24,9 +24,9 @@
#include "dh-app.h"
#include <glib/gi18n.h>
#include "devhelp/dh-settings.h"
-#include "devhelp/dh-util.h"
#include "dh-assistant.h"
#include "dh-preferences.h"
+#include "dh-utils-app.h"
G_DEFINE_TYPE (DhApp, dh_app, GTK_TYPE_APPLICATION);
diff --git a/src/dh-assistant.c b/src/dh-assistant.c
index 411ca12..b5f74d4 100644
--- a/src/dh-assistant.c
+++ b/src/dh-assistant.c
@@ -20,7 +20,7 @@
#include "dh-assistant.h"
#include <devhelp/devhelp.h>
#include "devhelp/dh-settings.h"
-#include "devhelp/dh-util.h"
+#include "dh-utils-app.h"
#include "dh-window.h"
typedef struct {
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
index e253e4f..c0b09e9 100644
--- a/src/dh-preferences.c
+++ b/src/dh-preferences.c
@@ -23,7 +23,7 @@
#include <string.h>
#include <devhelp/devhelp.h>
#include "devhelp/dh-settings.h"
-#include "devhelp/dh-util.h"
+#include "dh-utils-app.h"
static GtkWidget *prefs_dialog = NULL;
diff --git a/src/dh-utils-app.c b/src/dh-utils-app.c
new file mode 100644
index 0000000..016256e
--- /dev/null
+++ b/src/dh-utils-app.c
@@ -0,0 +1,166 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2001 Mikael Hallendal <micke imendio com>
+ * Copyright (C) 2004, 2008 Imendio AB
+ * Copyright (C) 2015, 2017, 2018 Sébastien Wilmet <swilmet gnome 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "dh-utils-app.h"
+
+/* Set the given fonts on the given view. */
+void
+dh_util_view_set_font (WebKitWebView *view,
+ const gchar *font_name_fixed,
+ const gchar *font_name_variable)
+{
+ PangoFontDescription *font_desc_fixed;
+ PangoFontDescription *font_desc_variable;
+ guint font_size_fixed;
+ guint font_size_variable;
+ guint font_size_fixed_px;
+ guint font_size_variable_px;
+ WebKitSettings *settings;
+
+ g_return_if_fail (WEBKIT_IS_WEB_VIEW (view));
+ g_return_if_fail (font_name_fixed != NULL);
+ g_return_if_fail (font_name_variable != NULL);
+
+ /* Get the font size. */
+ font_desc_fixed = pango_font_description_from_string (font_name_fixed);
+ font_desc_variable = pango_font_description_from_string (font_name_variable);
+ font_size_fixed = pango_font_description_get_size (font_desc_fixed) / PANGO_SCALE;
+ font_size_variable = pango_font_description_get_size (font_desc_variable) / PANGO_SCALE;
+ font_size_fixed_px = webkit_settings_font_size_to_pixels (font_size_fixed);
+ font_size_variable_px = webkit_settings_font_size_to_pixels (font_size_variable);
+
+ /* Set the fonts. */
+ settings = webkit_web_view_get_settings (view);
+ webkit_settings_set_zoom_text_only (settings, TRUE);
+ webkit_settings_set_monospace_font_family (settings, font_name_fixed);
+ webkit_settings_set_default_monospace_font_size (settings, font_size_fixed_px);
+ webkit_settings_set_serif_font_family (settings, font_name_variable);
+ webkit_settings_set_default_font_size (settings, font_size_variable_px);
+
+ g_debug ("Set font-fixed to '%s' (%i) and font-variable to '%s' (%i).",
+ font_name_fixed, font_size_fixed_px, font_name_variable, font_size_variable_px);
+
+ pango_font_description_free (font_desc_fixed);
+ pango_font_description_free (font_desc_variable);
+}
+
+static void
+introspect_window_gsettings (GSettings *window_settings,
+ gboolean *has_required_keys,
+ gboolean *has_maximized_key)
+{
+ GSettingsSchema *schema = NULL;
+
+ g_object_get (window_settings,
+ "settings-schema", &schema,
+ NULL);
+
+ *has_required_keys = (g_settings_schema_has_key (schema, "width") &&
+ g_settings_schema_has_key (schema, "height"));
+
+ *has_maximized_key = g_settings_schema_has_key (schema, "maximized");
+
+ g_settings_schema_unref (schema);
+}
+
+void
+dh_util_window_settings_save (GtkWindow *window,
+ GSettings *settings)
+{
+ gboolean has_required_keys;
+ gboolean has_maximized_key;
+ gint width;
+ gint height;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+ g_return_if_fail (G_IS_SETTINGS (settings));
+
+ introspect_window_gsettings (settings, &has_required_keys, &has_maximized_key);
+ g_return_if_fail (has_required_keys);
+
+ if (has_maximized_key) {
+ GdkWindowState state;
+ gboolean maximized;
+
+ state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
+ maximized = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+
+ g_settings_set_boolean (settings, "maximized", maximized);
+
+ /* If maximized don't save the size. */
+ if (maximized)
+ return;
+ }
+
+ /* Store the dimensions */
+ gtk_window_get_size (GTK_WINDOW (window), &width, &height);
+ g_settings_set_int (settings, "width", width);
+ g_settings_set_int (settings, "height", height);
+}
+
+/* This should be called when @gtk_window is realized (i.e. its GdkWindow is
+ * created) but not yet mapped (i.e. gtk_widget_show() has not yet been called,
+ * so that when it is shown it already has the good size).
+ */
+void
+dh_util_window_settings_restore (GtkWindow *gtk_window,
+ GSettings *settings)
+{
+ gboolean has_required_keys;
+ gboolean has_maximized_key;
+ gint width;
+ gint height;
+
+ g_return_if_fail (GTK_IS_WINDOW (gtk_window));
+ g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (gtk_window)));
+ g_return_if_fail (G_IS_SETTINGS (settings));
+
+ introspect_window_gsettings (settings, &has_required_keys, &has_maximized_key);
+ g_return_if_fail (has_required_keys);
+
+ width = g_settings_get_int (settings, "width");
+ height = g_settings_get_int (settings, "height");
+
+ if (width > 1 && height > 1) {
+ GdkDisplay *display;
+ GdkWindow *gdk_window;
+ GdkMonitor *monitor;
+ GdkRectangle monitor_workarea;
+ gint max_width;
+ gint max_height;
+
+ display = gtk_widget_get_display (GTK_WIDGET (gtk_window));
+ /* To get the GdkWindow the widget must be realized. */
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (gtk_window));
+ monitor = gdk_display_get_monitor_at_window (display, gdk_window);
+ gdk_monitor_get_workarea (monitor, &monitor_workarea);
+
+ max_width = monitor_workarea.width;
+ max_height = monitor_workarea.height;
+
+ width = CLAMP (width, 0, max_width);
+ height = CLAMP (height, 0, max_height);
+
+ gtk_window_set_default_size (gtk_window, width, height);
+ }
+
+ if (has_maximized_key && g_settings_get_boolean (settings, "maximized"))
+ gtk_window_maximize (gtk_window);
+}
diff --git a/src/dh-utils-app.h b/src/dh-utils-app.h
new file mode 100644
index 0000000..e92b17a
--- /dev/null
+++ b/src/dh-utils-app.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2001-2002 Mikael Hallendal <micke imendio com>
+ * Copyright (C) 2004,2008 Imendio AB
+ * Copyright (C) 2015, 2017 Sébastien Wilmet <swilmet gnome 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DH_UTILS_APP_H
+#define DH_UTILS_APP_H
+
+#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+
+G_BEGIN_DECLS
+
+void dh_util_view_set_font (WebKitWebView *view,
+ const gchar *font_name_fixed,
+ const gchar *font_name_variable);
+
+void dh_util_window_settings_save (GtkWindow *window,
+ GSettings *settings);
+
+void dh_util_window_settings_restore (GtkWindow *gtk_window,
+ GSettings *settings);
+
+G_END_DECLS
+
+#endif /* DH_UTILS_APP_H */
diff --git a/src/dh-window.c b/src/dh-window.c
index 0d7ee61..4eff891 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -24,9 +24,9 @@
#include <webkit2/webkit2.h>
#include <devhelp/devhelp.h>
#include "devhelp/dh-settings.h"
-#include "devhelp/dh-util.h"
#include "dh-tab.h"
#include "dh-tab-label.h"
+#include "dh-utils-app.h"
#include "dh-web-view.h"
typedef struct {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]