]> spindle.queued.net Git - midori/commitdiff
Introduce compat.h which provides new api for old libraries
authorChristian Dywan <christian@twotoasts.de>
Sun, 8 Jun 2008 15:46:24 +0000 (17:46 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 8 Jun 2008 15:46:24 +0000 (17:46 +0200)
midori/Makefile.am
midori/compat.c [new file with mode: 0644]
midori/compat.h [new file with mode: 0644]
midori/midori-app.c
midori/midori-browser.c
midori/midori-webview.c
midori/midori-webview.h

index bda06d22ca52be04c56174292cf334a93ea3ac71..5f72dc2ff9aef61b14136e8c683efd7c42f45b47 100644 (file)
@@ -30,4 +30,5 @@ midori_SOURCES = \
     webSearch.c webSearch.h \
     gjs.c       gjs.h       \
     sokoke.c    sokoke.h    \
-    search.c    search.h
+    search.c    search.h    \
+    compat.c    compat.h
diff --git a/midori/compat.c b/midori/compat.c
new file mode 100644 (file)
index 0000000..d9ff8bb
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+#include "compat.h"
+
+#ifndef WEBKIT_CHECK_VERSION
+
+/**
+ * webkit_web_view_get_zoom_level:
+ * @web_view: a #WebKitWebView
+ *
+ * Retrieves the current zoom level.
+ *
+ * Return value: the zoom level, always 1.0 if not supported
+ **/
+gfloat
+webkit_web_view_get_zoom_level (WebKitWebView* web_view)
+{
+    g_return_val_if_fail (WEBKIT_IS_WEB_VIEW (web_view), 1.0);
+
+    if (g_object_class_find_property (G_OBJECT_GET_CLASS (web_view),
+                                      "zoom-level"))
+    {
+        gfloat zoom_level;
+        g_object_get (web_view, "zoom-level", &zoom_level, NULL);
+        return zoom_level;
+    }
+    return 1.0;
+}
+
+/**
+ * webkit_web_view_set_zoom_level:
+ * @web_view: a #WebKitWebView
+ *
+ * Sets the current zoom level.
+ *
+ * Does nothing if not supported.
+ **/
+void
+webkit_web_view_set_zoom_level (WebKitWebView* web_view,
+                                gfloat         zoom_level)
+{
+    g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+
+    if (g_object_class_find_property (G_OBJECT_GET_CLASS (web_view),
+                                      "zoom-level"))
+        g_object_set (web_view, "zoom-level", zoom_level, NULL);
+}
+
+/**
+ * webkit_web_view_zoom_in:
+ * @web_view: a #WebKitWebView
+ *
+ * Increases the current zoom level.
+ *
+ * Does nothing if not supported.
+ **/
+void
+webkit_web_view_zoom_in (WebKitWebView* web_view)
+{
+    g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+
+    gfloat zoom_level = webkit_web_view_get_zoom_level (web_view);
+    WebKitWebSettings* settings = webkit_web_view_get_settings (web_view);
+    gfloat zoom_step;
+    g_object_get (settings, "zoom-step", &zoom_step, NULL);
+    webkit_web_view_set_zoom_level (web_view, zoom_level + zoom_step);
+}
+
+/**
+ * webkit_web_view_zoom_out:
+ * @web_view: a #WebKitWebView
+ *
+ * Decreases the current zoom level.
+ *
+ * Does nothing if not supported.
+ **/
+void
+webkit_web_view_zoom_out (WebKitWebView* web_view)
+{
+    g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+
+    gfloat zoom_level = webkit_web_view_get_zoom_level (web_view);
+    WebKitWebSettings* settings = webkit_web_view_get_settings (web_view);
+    if (g_object_class_find_property (G_OBJECT_GET_CLASS (settings),
+                                      "zoom-step"))
+    {
+        gfloat zoom_step;
+        g_object_get (settings, "zoom-step", &zoom_step, NULL);
+        webkit_web_view_set_zoom_level (web_view, zoom_level - zoom_step);
+    }
+}
+
+#endif
diff --git a/midori/compat.h b/midori/compat.h
new file mode 100644 (file)
index 0000000..1547b11
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+#ifndef __COMPAT_H__
+#define __COMPAT_H__
+
+#include <webkit/webkit.h>
+
+G_BEGIN_DECLS
+
+#ifndef WEBKIT_CHECK_VERSION
+
+gfloat
+webkit_web_view_get_zoom_level         (WebKitWebView*     web_view);
+
+void
+webkit_web_view_set_zoom_level         (WebKitWebView*     web_view);
+
+void
+webkit_web_view_zoom_in                (WebKitWebView*     web_view);
+
+void
+webkit_web_view_zoom_out               (WebKitWebView*     web_view);
+
+#endif
+
+G_END_DECLS
+
+#endif /* __COMPAT_H__ */
index ae36b150bc28f503cc87ffa4f5692e030e6f7450..a77fd630b83e932e47b13fc9423a3d98d1eba40c 100644 (file)
@@ -379,8 +379,6 @@ midori_app_set_settings (MidoriApp*         app,
 {
     g_return_if_fail (MIDORI_IS_APP (app));
 
-    MidoriAppPrivate* priv = app->priv;
-
     g_object_set (app, "settings", settings, NULL);
 }
 
index bd055d831383336c45ecaa60949f4c1b27ba9bdf..2fa5c5eb21ccbf321364d2e52a5a7844da02b221 100644 (file)
@@ -179,7 +179,7 @@ _midori_browser_update_interface (MidoriBrowser* browser)
     {
         loading = midori_web_view_is_loading (MIDORI_WEB_VIEW (web_view));
         _action_set_sensitive (browser, "ZoomNormal",
-            midori_web_view_get_zoom_level (MIDORI_WEB_VIEW (web_view)) != 1.0);
+            webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW (web_view)) != 1.0);
         if (!g_object_class_find_property (G_OBJECT_GET_CLASS (web_view),
                                            "zoom-level"))
         {
@@ -1248,16 +1248,8 @@ _action_zoom_in_activate (GtkAction*     action,
                           MidoriBrowser* browser)
 {
     GtkWidget* web_view = midori_browser_get_current_web_view (browser);
-    if (web_view && g_object_class_find_property (
-        G_OBJECT_GET_CLASS (web_view), "zoom-level"))
-    {
-        MidoriBrowserPrivate* priv = browser->priv;
-
-        gfloat zoom_level, zoom_step;
-        g_object_get (web_view, "zoom-level", &zoom_level, NULL);
-        g_object_get (priv->settings, "zoom-step", &zoom_step, NULL);
-        g_object_set (web_view, "zoom-level", zoom_level + zoom_step, NULL);
-    }
+    if (web_view)
+        webkit_web_view_zoom_in (WEBKIT_WEB_VIEW (web_view));
 }
 
 static void
@@ -1265,16 +1257,8 @@ _action_zoom_out_activate (GtkAction*     action,
                            MidoriBrowser* browser)
 {
     GtkWidget* web_view = midori_browser_get_current_web_view (browser);
-    if (web_view && g_object_class_find_property (
-        G_OBJECT_GET_CLASS (web_view), "zoom-level"))
-    {
-        MidoriBrowserPrivate* priv = browser->priv;
-
-        gfloat zoom_level, zoom_step;
-        g_object_get (web_view, "zoom-level", &zoom_level, NULL);
-        g_object_get (priv->settings, "zoom-step", &zoom_step, NULL);
-        g_object_set (web_view, "zoom-level", zoom_level - zoom_step, NULL);
-    }
+    if (web_view)
+        webkit_web_view_zoom_out (WEBKIT_WEB_VIEW (web_view));
 }
 
 static void
@@ -1282,9 +1266,8 @@ _action_zoom_normal_activate (GtkAction*     action,
                               MidoriBrowser* browser)
 {
     GtkWidget* web_view = midori_browser_get_current_web_view (browser);
-    if (web_view && g_object_class_find_property (
-        G_OBJECT_GET_CLASS (web_view), "zoom-level"))
-        g_object_set (web_view, "zoom-level", 1.0, NULL);
+    if (web_view)
+        webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW (web_view), 1.0);
 }
 
 /*static void
index ec015ea1ec399d4e9a3a3c1f8055e71a0d892a1f..0c68b26bfb7b4f68ba00b4250c21909a45edd78c 100644 (file)
@@ -1080,26 +1080,3 @@ midori_web_view_get_link_uri (MidoriWebView* web_view)
     MidoriWebViewPrivate* priv = web_view->priv;
     return priv->link_uri;
 }
-
-/**
- * midori_web_view_get_zoom_level:
- * @web_view: a #MidoriWebView
- *
- * Retrieves the current zoom level.
- *
- * Return value: the zoom level, always 1 if not supported
- **/
-gfloat
-midori_web_view_get_zoom_level (MidoriWebView* web_view)
-{
-    g_return_val_if_fail (MIDORI_IS_WEB_VIEW (web_view), 1);
-
-    if (g_object_class_find_property (G_OBJECT_GET_CLASS (web_view),
-                                      "zoom-level"))
-    {
-        gfloat zoom_level;
-        g_object_get (web_view, "zoom-level", &zoom_level, NULL);
-        return zoom_level;
-    }
-    return 1;
-}
index 6117ccc9526e970724ce07224667f4471aeb4fb5..0905ce68bddc7ec6652c80e933a95f950aa9efa3 100644 (file)
@@ -107,9 +107,6 @@ midori_web_view_get_display_title      (MidoriWebView*     web_view);
 const gchar*
 midori_web_view_get_link_uri           (MidoriWebView*     web_view);
 
-gfloat
-midori_web_view_get_zoom_level         (MidoriWebView*     web_view);
-
 G_END_DECLS
 
 #endif /* __MIDORI_WEB_VIEW_H__ */