changeset 40:61134827e004

Added libsoup interface
author unexist
date Sun, 24 Jan 2010 01:55:13 +0100
parents 6838c7123945
children 9cd17ff76e97
files subtly/soup.rb
diffstat 1 files changed, 133 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/subtly/soup.rb	Sun Jan 24 01:55:13 2010 +0100
@@ -0,0 +1,133 @@
+##
+# @package subtly
+#
+# @file Soup bindings
+# @author Christoph Kappel <unexist@dorfelite.net>
+# @version $Id$
+#
+# This program can be distributed under the terms of the GNU GPL.
+##
+
+require "ffi"
+require "subtly/gobject"
+
+module Subtly
+  module Soup # {{{
+    class Uri # {{{
+      # Internal object
+      attr_accessor :uri
+
+      extend FFI::Library
+
+      ffi_lib("libwebkit-1.0")
+
+      ## initialize
+      # Create soup uri
+      #
+      # @param [String, #read]  uri  Uri to load
+      #
+      # @return [Object] New Soup
+      ##
+
+      def initialize(uri)
+        @uri = Subtly::Soup::Uri.ffi_init(uri)
+      end
+
+      ## finalize
+      # Kill soup instance
+      ##
+
+      def finalize
+        Subtly::Soup::Uri.ffi_finalize(@uri)
+      end
+
+      ## to_wid
+      # Get real widget from object
+      #
+      # @return [Pointer] Real widget
+      ##
+
+      def to_wid
+        @uri
+      end
+
+      private
+
+      ## ffi_init
+      # Create soup uri
+      #
+      # @param [String, #read]  uri_string  Uri to load
+      #
+      # @return [Pointer] A #SoupURI
+      ##
+
+      attach_function(:ffi_init,
+        :soup_uri_new, [ :string ], :pointer
+      )
+
+      ## ffi_finalize
+      # Free uri
+      #
+      # @param [String, #read]  urig  A #SoupURI
+      ##
+
+      attach_function(:ffi_finalize,
+        :soup_uri_free, [ :pointer ], :void
+      )
+    end # }}}
+
+    class Session # {{{
+      # Internal sesson
+      attr_accessor :session
+
+      # Default name
+      PROXY_URI = "proxy-uri"
+
+      extend FFI::Library
+
+      ffi_lib("libwebkit-1.0")
+
+      ## initialize
+      # Create session
+      #
+      # @param [Pointer, #read]  session  Session to wrap
+      #
+      # @return [Object] New Session
+      ##
+
+      def initialize(session)
+        @session = session
+      end
+
+      ## proxy=
+      # Set proxy
+      #
+      # @param [String, #read]  uri  Uri to proxy
+      ##
+
+      def proxy=(uri)
+        if(uri.empty?)
+          Subtly::Soup::Session.ffi_remove_feature(@session, PROXY_URI)
+        else
+          # Set uri
+          suri = Subtly::Soup::Uri.new(uri)
+          Subtly::GObject.set(@session, PROXY_URI, suri)
+          suri.finalize
+        end
+      end
+
+      private
+
+      ## ffi_remove_feature
+      # Removes a feature from session
+      #
+      # @param [Pointer, #read]  session       A #SoupSession
+      # @param [String,  #read]  feature_type  Type of feature
+      ##
+
+      attach_function(:ffi_remove_feature,
+        :soup_session_remove_feature_by_type, [ :pointer, :string ], :void
+      )
+    end # }}}
+  end # }}}
+end