From 405f565df843e0bb1be1f8aec222959c260923cf Mon Sep 17 00:00:00 2001
From: Ryan Niebur
Date: Wed, 23 Oct 2013 20:26:27 -0700
Subject: [PATCH] Imported Upstream version 0.4.3+dfsg
---
.gitignore | 2 +-
ChangeLog | 129 -
INSTALL | 23 +-
README | 16 +-
configure | 2 +-
data/about.css | 70 -
data/autosuggestcontrol.js | 10 +-
data/error.html | 60 +-
data/faq.css | 61 +-
data/faq.html | 495 +-
data/gtk3.css | 28 -
data/midori.desktop.in | 9 +-
data/speeddial-head.html | 176 +-
docs/api/wscript_build | 18 +-
extensions/adblock.c | 684 +-
extensions/addons.c | 59 +-
extensions/colorful-tabs.c | 5 +-
.../cookie-manager/cookie-manager-page.c | 43 +-
extensions/delayed-load.vala | 231 -
extensions/external-download-manager.vala | 314 -
extensions/feed-panel/feed-panel.c | 3 +-
extensions/formhistory.c | 600 ++
extensions/formhistory/formhistory-frontend.h | 74 -
.../formhistory/formhistory-gdom-frontend.c | 516 --
.../formhistory/formhistory-js-frontend.c | 143 -
extensions/formhistory/formhistory.c | 681 --
extensions/history-list.vala | 17 +-
extensions/shortcuts.c | 2 +
extensions/statusbar-features.c | 158 +-
extensions/tab-panel.c | 13 +-
extensions/toolbar-editor.c | 30 +-
extensions/web-cache.c | 3 +-
extensions/wscript_build | 9 +-
...internet-news-reader.png => news-feed.png} | Bin
...internet-news-reader.png => news-feed.png} | Bin
...internet-news-reader.svg => news-feed.svg} | 0
icons/wscript_build | 2 +-
katze/gtk3-compat.c | 65 +-
katze/gtk3-compat.h | 45 +-
katze/katze-array.c | 89 +-
katze/katze-arrayaction.c | 114 +-
katze/katze-http-cookies-sqlite.c | 154 +-
katze/katze-http-cookies.c | 6 +-
katze/katze-item.c | 88 +-
katze/katze-item.h | 9 +-
katze/katze-net.c | 47 +-
katze/katze-net.h | 2 +
katze/katze-preferences.c | 25 +-
katze/katze-throbber.c | 17 +-
katze/katze-utils.c | 117 +-
katze/katze-utils.h | 21 -
katze/katze.vapi | 25 -
katze/midori-hsts.vala | 143 -
katze/midori-paths.vala | 244 -
katze/midori-uri.vala | 63 +-
midori/gtkiconentry.c | 1914 ++++++
midori/gtkiconentry.h | 93 +-
midori/main.c | 992 +--
midori/marshal.list | 1 -
midori/midori-app.c | 296 +-
midori/midori-app.h | 13 +-
midori/midori-array.c | 77 +-
midori/midori-array.h | 7 -
midori/midori-bookmarks.c | 335 -
midori/midori-bookmarks.h | 32 -
midori/midori-browser.c | 2351 +++----
midori/midori-browser.h | 12 -
midori/midori-download.vala | 320 -
midori/midori-extension.c | 75 +-
midori/midori-locationaction.c | 817 +--
midori/midori-panedaction.c | 227 +
midori/midori-panedaction.h | 70 +
midori/midori-panedaction.vala | 79 -
midori/midori-panel.c | 112 +-
midori/midori-panel.h | 6 +-
midori/midori-platform.h | 14 +-
midori/midori-preferences.c | 80 +-
midori/midori-searchaction.c | 238 +-
midori/midori-searchaction.h | 10 -
midori/midori-settings.vala | 109 -
midori/midori-speeddial.vala | 401 --
midori/midori-stock.h | 44 +-
midori/midori-view.c | 2384 +++----
midori/midori-view.h | 55 +-
midori/midori-viewable.c | 163 +
midori/midori-viewable.h | 61 +
midori/midori-viewable.vala | 23 -
midori/midori-websettings.c | 1302 +++-
midori/midori-websettings.h | 38 +-
midori/midori.h | 2 +-
midori/midori.vapi | 71 +-
midori/socket.c | 223 +
midori/socket.h | 20 +
midori/sokoke.c | 917 ++-
midori/sokoke.h | 92 +-
midori/wscript_build | 23 +-
panels/midori-bookmarks.c | 267 +-
panels/midori-bookmarks.h | 18 +-
panels/midori-extensions.c | 17 +-
panels/midori-history.c | 114 +-
panels/midori-transfers.c | 82 +-
panels/midori-transfers.h | 6 +-
po/POTFILES.in | 9 +-
po/ar.po | 2319 +++----
po/ast.po | 34 +-
po/be.po | 3274 ----------
po/ca.po | 2297 ++++---
po/cs.po | 2839 ++++----
po/da.po | 1654 ++---
po/de.po | 2758 ++++----
po/el.po | 1935 +++---
po/en_GB.po | 2709 ++++----
po/eo.po | 2793 --------
po/es.po | 2851 ++++----
po/et.po | 22 +-
po/eu.po | 2958 ---------
po/fi.po | 38 +-
po/fr.po | 2488 +++----
po/gl.po | 2046 +++---
po/he.po | 1868 +++---
po/hr.po | 1654 ++---
po/hu.po | 2719 ++++----
po/id.po | 3055 ++++-----
po/it.po | 3172 ++++-----
po/ja.po | 2838 ++++----
po/ko.po | 2929 +++++----
po/lt.po | 2712 ++++----
po/nl.po | 2658 ++++----
po/no.po | 28 +-
po/pa.po | 32 +-
po/pl.po | 1705 +++--
po/pt.po | 2814 ++++----
po/pt_BR.po | 2754 ++++----
po/ro.po | 1662 ++---
po/ru.po | 2231 +++----
po/sk.po | 1380 ++--
po/sr.po | 3276 +++++-----
po/sr@latin.po | 16 +-
po/sv.po | 38 +-
po/tr.po | 2150 +++---
po/ug.po | 5785 ++++++++---------
po/uk.po | 2668 ++++----
po/zh_CN.po | 1615 +++--
po/zh_TW.po | 1815 +++---
tests/bookmarks.c | 208 -
tests/browser.c | 64 +-
tests/download.vala | 58 -
tests/extensions.c | 26 +-
tests/hsts.vala | 31 -
tests/magic-uri.c | 117 +-
tests/properties.c | 119 +-
tests/searchaction.vala | 46 -
tests/speeddial.vala | 92 -
tests/wscript_build | 16 +-
toolbars/midori-findbar.c | 96 +-
toolbars/midori-findbar.h | 7 +-
toolbars/midori-transferbar.c | 176 +-
tools/midori-dev | 2 +-
waf | Bin 92452 -> 0 bytes
waf-modules/wafadmin/3rdparty/boost.py | 225 +
waf-modules/wafadmin/3rdparty/fluid.py | 17 +
waf-modules/wafadmin/Build.py | 676 ++
waf-modules/wafadmin/Configure.py | 316 +
waf-modules/wafadmin/Constants.py | 47 +
waf-modules/wafadmin/Environment.py | 158 +
waf-modules/wafadmin/Logs.py | 97 +
waf-modules/wafadmin/Node.py | 496 ++
waf-modules/wafadmin/Options.py | 158 +
waf-modules/wafadmin/Runner.py | 165 +
waf-modules/wafadmin/Scripting.py | 414 ++
waf-modules/wafadmin/Task.py | 780 +++
waf-modules/wafadmin/TaskGen.py | 346 +
waf-modules/wafadmin/Tools/__init__.py | 4 +
waf-modules/wafadmin/Tools/ar.py | 26 +
waf-modules/wafadmin/Tools/bison.py | 26 +
waf-modules/wafadmin/Tools/cc.py | 70 +
waf-modules/wafadmin/Tools/ccroot.py | 397 ++
waf-modules/wafadmin/Tools/compiler_cc.py | 43 +
waf-modules/wafadmin/Tools/compiler_cxx.py | 43 +
waf-modules/wafadmin/Tools/compiler_d.py | 25 +
waf-modules/wafadmin/Tools/config_c.py | 532 ++
waf-modules/wafadmin/Tools/cs.py | 44 +
waf-modules/wafadmin/Tools/cxx.py | 71 +
waf-modules/wafadmin/Tools/d.py | 368 ++
waf-modules/wafadmin/Tools/dbus.py | 24 +
waf-modules/wafadmin/Tools/dmd.py | 44 +
waf-modules/wafadmin/Tools/flex.py | 12 +
waf-modules/wafadmin/Tools/gas.py | 27 +
waf-modules/wafadmin/Tools/gcc.py | 93 +
waf-modules/wafadmin/Tools/gdc.py | 36 +
waf-modules/wafadmin/Tools/glib2.py | 83 +
waf-modules/wafadmin/Tools/gnome.py | 163 +
waf-modules/wafadmin/Tools/gnu_dirs.py | 63 +
waf-modules/wafadmin/Tools/gob2.py | 10 +
waf-modules/wafadmin/Tools/gxx.py | 93 +
waf-modules/wafadmin/Tools/icc.py | 32 +
waf-modules/wafadmin/Tools/icpc.py | 31 +
waf-modules/wafadmin/Tools/intltool.py | 95 +
waf-modules/wafadmin/Tools/javaw.py | 162 +
waf-modules/wafadmin/Tools/kde4.py | 57 +
waf-modules/wafadmin/Tools/libtool.py | 239 +
waf-modules/wafadmin/Tools/lua.py | 13 +
waf-modules/wafadmin/Tools/misc.py | 302 +
waf-modules/wafadmin/Tools/msvc.py | 586 ++
waf-modules/wafadmin/Tools/nasm.py | 31 +
waf-modules/wafadmin/Tools/ocaml.py | 225 +
waf-modules/wafadmin/Tools/osx.py | 138 +
waf-modules/wafadmin/Tools/perl.py | 69 +
waf-modules/wafadmin/Tools/preproc.py | 616 ++
waf-modules/wafadmin/Tools/python.py | 278 +
waf-modules/wafadmin/Tools/qt4.py | 376 ++
waf-modules/wafadmin/Tools/ruby.py | 88 +
waf-modules/wafadmin/Tools/suncc.py | 56 +
waf-modules/wafadmin/Tools/suncxx.py | 56 +
waf-modules/wafadmin/Tools/tex.py | 183 +
waf-modules/wafadmin/Tools/unittestw.py | 211 +
waf-modules/wafadmin/Tools/vala.py | 235 +
waf-modules/wafadmin/Tools/winres.py | 32 +
waf-modules/wafadmin/Tools/xlc.py | 58 +
waf-modules/wafadmin/Tools/xlcxx.py | 58 +
waf-modules/wafadmin/Utils.py | 532 ++
waf-modules/wafadmin/__init__.py | 4 +
waf-modules/wafadmin/ansiterm.py | 158 +
waf-modules/wafadmin/pproc.py | 496 ++
waf-modules/wafadmin/py3kfixes.py | 104 +
waf-unpacked | 159 +
win32/makedist/makedist.midori | 178 +-
win32/makedist/midori-0.3.3.nsi | 299 +-
win32/x86-mingw32-opensuse/install.sh | 2 +-
wscript | 109 +-
230 files changed, 58280 insertions(+), 62399 deletions(-)
delete mode 100644 data/about.css
delete mode 100644 data/gtk3.css
delete mode 100644 extensions/delayed-load.vala
delete mode 100644 extensions/external-download-manager.vala
create mode 100644 extensions/formhistory.c
delete mode 100644 extensions/formhistory/formhistory-frontend.h
delete mode 100644 extensions/formhistory/formhistory-gdom-frontend.c
delete mode 100644 extensions/formhistory/formhistory-js-frontend.c
delete mode 100644 extensions/formhistory/formhistory.c
rename icons/16x16/{internet-news-reader.png => news-feed.png} (100%)
rename icons/22x22/{internet-news-reader.png => news-feed.png} (100%)
rename icons/scalable/{internet-news-reader.svg => news-feed.svg} (100%)
delete mode 100644 katze/katze.vapi
delete mode 100644 katze/midori-hsts.vala
delete mode 100644 katze/midori-paths.vala
delete mode 100644 midori/midori-bookmarks.c
delete mode 100644 midori/midori-bookmarks.h
delete mode 100644 midori/midori-download.vala
create mode 100644 midori/midori-panedaction.c
create mode 100644 midori/midori-panedaction.h
delete mode 100644 midori/midori-panedaction.vala
delete mode 100644 midori/midori-settings.vala
delete mode 100644 midori/midori-speeddial.vala
create mode 100644 midori/midori-viewable.c
create mode 100644 midori/midori-viewable.h
delete mode 100644 midori/midori-viewable.vala
delete mode 100644 po/be.po
delete mode 100644 po/eo.po
delete mode 100644 po/eu.po
delete mode 100644 tests/bookmarks.c
delete mode 100644 tests/download.vala
delete mode 100644 tests/hsts.vala
delete mode 100644 tests/searchaction.vala
delete mode 100644 tests/speeddial.vala
delete mode 100755 waf
create mode 100644 waf-modules/wafadmin/3rdparty/boost.py
create mode 100644 waf-modules/wafadmin/3rdparty/fluid.py
create mode 100644 waf-modules/wafadmin/Build.py
create mode 100644 waf-modules/wafadmin/Configure.py
create mode 100644 waf-modules/wafadmin/Constants.py
create mode 100644 waf-modules/wafadmin/Environment.py
create mode 100644 waf-modules/wafadmin/Logs.py
create mode 100644 waf-modules/wafadmin/Node.py
create mode 100644 waf-modules/wafadmin/Options.py
create mode 100644 waf-modules/wafadmin/Runner.py
create mode 100644 waf-modules/wafadmin/Scripting.py
create mode 100644 waf-modules/wafadmin/Task.py
create mode 100644 waf-modules/wafadmin/TaskGen.py
create mode 100644 waf-modules/wafadmin/Tools/__init__.py
create mode 100644 waf-modules/wafadmin/Tools/ar.py
create mode 100644 waf-modules/wafadmin/Tools/bison.py
create mode 100644 waf-modules/wafadmin/Tools/cc.py
create mode 100644 waf-modules/wafadmin/Tools/ccroot.py
create mode 100644 waf-modules/wafadmin/Tools/compiler_cc.py
create mode 100644 waf-modules/wafadmin/Tools/compiler_cxx.py
create mode 100644 waf-modules/wafadmin/Tools/compiler_d.py
create mode 100644 waf-modules/wafadmin/Tools/config_c.py
create mode 100644 waf-modules/wafadmin/Tools/cs.py
create mode 100644 waf-modules/wafadmin/Tools/cxx.py
create mode 100644 waf-modules/wafadmin/Tools/d.py
create mode 100644 waf-modules/wafadmin/Tools/dbus.py
create mode 100644 waf-modules/wafadmin/Tools/dmd.py
create mode 100644 waf-modules/wafadmin/Tools/flex.py
create mode 100644 waf-modules/wafadmin/Tools/gas.py
create mode 100644 waf-modules/wafadmin/Tools/gcc.py
create mode 100644 waf-modules/wafadmin/Tools/gdc.py
create mode 100644 waf-modules/wafadmin/Tools/glib2.py
create mode 100644 waf-modules/wafadmin/Tools/gnome.py
create mode 100644 waf-modules/wafadmin/Tools/gnu_dirs.py
create mode 100644 waf-modules/wafadmin/Tools/gob2.py
create mode 100644 waf-modules/wafadmin/Tools/gxx.py
create mode 100644 waf-modules/wafadmin/Tools/icc.py
create mode 100644 waf-modules/wafadmin/Tools/icpc.py
create mode 100644 waf-modules/wafadmin/Tools/intltool.py
create mode 100644 waf-modules/wafadmin/Tools/javaw.py
create mode 100644 waf-modules/wafadmin/Tools/kde4.py
create mode 100644 waf-modules/wafadmin/Tools/libtool.py
create mode 100644 waf-modules/wafadmin/Tools/lua.py
create mode 100644 waf-modules/wafadmin/Tools/misc.py
create mode 100644 waf-modules/wafadmin/Tools/msvc.py
create mode 100644 waf-modules/wafadmin/Tools/nasm.py
create mode 100644 waf-modules/wafadmin/Tools/ocaml.py
create mode 100644 waf-modules/wafadmin/Tools/osx.py
create mode 100644 waf-modules/wafadmin/Tools/perl.py
create mode 100644 waf-modules/wafadmin/Tools/preproc.py
create mode 100644 waf-modules/wafadmin/Tools/python.py
create mode 100644 waf-modules/wafadmin/Tools/qt4.py
create mode 100644 waf-modules/wafadmin/Tools/ruby.py
create mode 100644 waf-modules/wafadmin/Tools/suncc.py
create mode 100644 waf-modules/wafadmin/Tools/suncxx.py
create mode 100644 waf-modules/wafadmin/Tools/tex.py
create mode 100644 waf-modules/wafadmin/Tools/unittestw.py
create mode 100644 waf-modules/wafadmin/Tools/vala.py
create mode 100644 waf-modules/wafadmin/Tools/winres.py
create mode 100644 waf-modules/wafadmin/Tools/xlc.py
create mode 100644 waf-modules/wafadmin/Tools/xlcxx.py
create mode 100644 waf-modules/wafadmin/Utils.py
create mode 100644 waf-modules/wafadmin/__init__.py
create mode 100644 waf-modules/wafadmin/ansiterm.py
create mode 100644 waf-modules/wafadmin/pproc.py
create mode 100644 waf-modules/wafadmin/py3kfixes.py
create mode 100755 waf-unpacked
diff --git a/.gitignore b/.gitignore
index 4aaa84a2..e6c4297f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,7 @@ Makefile
.waf-*
.lock-wscript
-_build
+_build_
po/.intltool-merge-cache
po/LINGUAS
diff --git a/ChangeLog b/ChangeLog
index 676410b8..24f87ea7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,134 +1,5 @@
This file is licensed under the terms of the expat license, see the file EXPAT.
-v0.4.7:
- Unify download behavior: link fingerprints, space check, clearing, tooltips
- GIO-based check for enough space and permissions, GIO-based themed icons
- Show opener/ tab domain in download dialog:
- http://lcamtuf.coredump.cx/fldl/ http://lcamtuf.coredump.cx/switch/
- Extension to download with a specific command line
- Size in download dialog and fallback filename heuristic
-
- Windows: GTK+3, Faenza icons, gdb helper, Netscape plugins,
- ship CA bundle, fix View source, --portable/ -P on Windows
- Granite (Beta): about dialog, static notebook, no "New Tab" in toolbar, Print â Share
- Support building with Wayland-enabled GTK+3
- Theming: content view, secondary toolbar class, drop old icon names, bigger error icon
- Introduce --plain mode equivalent to GtkLauncher, lazy URLs for --snapshot/ -s
- Log bookmarks, history and downloads to zeitgeist
-
- Show security details and export certificates with GCR, error out instead of colored urlbar
- Only allow data: URLs in urlbar for images
- Recognize and cache HSTS, system-wide /etc/xdg/midori/hsts
- Strip HTTP Host to outsmart some filter proxies
-
- Completion: Fix PageUp/Down, Shift+Tab and wrap: This is consistent with GTK+ (excluding Tab) and Firefox
- Change Focus Current Tab to Ctrl+Alt+Home
- Fix Shift+Space for scrolling upwards
- Control+Alt+R: Readable mode
- Handle access key in link hints
- Drop speed dial keyboard access in favour of "." link hints
-
- No Open, Bookmark bar, Customize toolbar, Inspect page in app menu; split panel menu
- Use ellipsises instead of period thresomes
- Hinted text in bookmarks, history and cookie manager
- Ellipsize panels (except for Transfers)
- Add icon to bookmark dialog and remove labels
- Validate proxy server IP and render invalid URLs in GTK+3
- Rename "Toplevel" folder to "Bookmarks"
-
- Chrome identification option; "Automatic" user agent is Chrome-based
- Search: Create engines from search forms, remove "icon" field
- Copy Image s/Address// always copy both URL and data
- Rework debugging by introducing MIDORI_DEBUG; about:paths
- Adblock: Refresh filters based on file time and meta data, abp: links
- Optionally save website including resources
- Merged NextForward akin to StopReload
- PanedAction, Viewable, SpeedDial, (most of) Settings, Paths in Vala
- Improved database: requires sqlite 3.6.19 and 0.2.6 in import dialog
-
- Confirm Caret Browsing before enabling it
- Support for custom items in Statusbar Features (see FAQ)
- Draggable favicon as URL or text, URL icon for URL entries
- Remember if inspector was attached
- Open tabs in the background by default
- RTL support in special/ error pages
- Fix progressbar text with GTK+3
- Build fix: More robust GTK+2 version check
- Ensure progress in urlbar and tab match
- Zoom text and images by default
- Don't mixup tokens starting with the same letters
- Seemless running out of build folder
- No speed dial in --app/ --private, fix layout with many tiles
- Add X-GNOME-Fullname to .desktop and translate desktop shortcuts
- Delayed Load extension
-
-v0.4.6:
- + Fix crasher in geolocation infobar
- + Fix crasher in about:version on some systems
- + Fix crasher opening bookmarks from Unity global menu
- + Use WebKitFaviconDatabase as of WebKit 1.8.0
- + Use midori-prefixed temp folder in midori_view_save_source
- + Fix cancelling downloads with SteadyFlow or Aria2
- + Fix crash dialog instead of opening tab in a running window
- + Fix page icons in multi-frame sites (gmail, tumbler)
- + Distinguish Simplified and Traditional Chinese
- + Support go-jump-symbolic
- + Handle empty tabs due to download links with a target
- + Handle frame load interrupted in the unholy trinity
- + Fix libsoup version check and wrong SSL status in location
-
-v0.4.5:
- + Work around black border around widgets on Win32
- + Whitelist direct/ re-directed navigation requests in adblock
- + Require Vala 0.14
- + Provide geolocation diagnostics in about:geolocation
- + List available about: URLs and app instance name in about:version
- + Replace illegal characters in download filenames
- + Tweak app options on Win32 and use ShellExecuteEx in sokoke_show_uri
- + Use sokoke_show_uri in midori_browser_download_status_cb
- + External Download manager Steadyflow and Aria2 (with cookies)
- + Ensure adblock config folder when blocking images
- + Use sqlite WAL mode for history if available
- + Allow relative -c/ --config path
- + Context menus on Back and Forward toolbar items
- + Always show the tabbar by default
- + Use ubuntu-bug if it exists
- + Show inline find while typing and statusbar text in overlay with GTK+ 3.2
- + Esc/ closing "downloads still active" should cancel, not continue
- + Optional Granite support for notebook and bookmark dialog as pop-over
- + Ctrl+j to toggle statusbar aka downloads
- + Show at most 3 search engines in completion
- + Don't replace existing onclick/ blur with autosuggest
- + Implement low_memory_profile for FreeBSD and Win32
- + Use var in internal javascript, to fix Google apps
- + Handle download requests in frames
-
-v0.4.4:
- + Disable page cache with < 352 MB RAM
- + Display filename in download dialog
- + Fix box packing in GTK+3 (in most cases)
- + Enable experimental HTML5 fullscreen API
- + Harden IPv6 address recognition in location
- + Experimental site data policy support (see FAQ)
- + Close tabs by middle clicking close button
- + Merge cookies and other data in Clear Private Data
- + Improve KatzeArrayAction for Unity menuproxy compatibility
- + Use GDateTime for history to avoid broken C runtimes
- + Add Midori tag to DuckDuckGo default URI
- + Rewrite completion popup resizing
- + Streamline page icon loading stages and fallbacks
- + Disable clipboard work-around for WebKit >= 1.4.3
- + Re-word .desktop entry as an action
- + Display informative text in private browsing
- + Consistent clear icons in entries
- + Revised download filename generation
- + Add 'Open in Image Viewer' menu item
- + Formhistory 2.0 with GDOM support
- + Handle javascript: and mailto: links better
- + Handle = key in Ukrainian layout better
- + Fix bookmark export and deletion of bookmark folders
- + Speed dial shortcut re-reordering by DND
-
v0.4.3:
+ Implement about:widgets to test rendering
+ Fix resizing of inspector by applying a minimum size
diff --git a/INSTALL b/INSTALL
index f65e7a82..aed4768e 100644
--- a/INSTALL
+++ b/INSTALL
@@ -37,7 +37,7 @@ Midori is now built with debugging symbols.
Make sure you have installed 'gdb', the GNU Debugger.
-Run Midori as 'gdb _build/default/midori/midori'.
+Run Midori as 'gdb _build_/default/midori/midori'.
Inside gdb, type 'run'.
@@ -49,32 +49,27 @@ function names and line numbers.
If the problem is a warning and not a crash, try this:
-'G_DEBUG=all gdb _build/default/midori/midori'
+'G_DEBUG=all gdb _build_/default/midori/midori'
If you are interested in HTTP communication, try this:
-'MIDORI_DEBUG=headers _build/default/midori/midori'
+'MIDORI_SOUP_DEBUG=2 _build_/default/midori/midori'
-Where 'headers' can be replaced with 'body' to get full message contents.
+Where '2' can be a level between 0 and 3.
If you are interested in (non-) touchscreen behaviour, try this:
-'MIDORI_TOUCHSCREEN=1 _build/default/midori/midori', or
+'MIDORI_TOUCHSCREEN=1 _build_/default/midori/midori', or
-'MIDORI_TOUCHSCREEN=0 _build/default/midori/midori'
+'MIDORI_TOUCHSCREEN=0 _build_/default/midori/midori'
If you want to "dry run" without WebKitGTK+ rendering, try this:
-'MIDORI_DEBUG=unarmed _build/default/midori/midori'
+'MIDORI_UNARMED=1 _build_/default/midori/midori'
-If you want to test bookmarks, you can enable database tracing:
+To debug extensions you can specify the path:
-'MIDORI_DEBUG=bookmarks _build/default/midori/midori'
-
-To disable Netscape plugins, use MOZ_PLUGIN_PATH=/.
-
-When running from the build folder, extensions will also be located
-in the build folder (setting MIDORI_EXTENSION_PATH is no longer needed).
+'export MIDORI_EXTENSION_PATH=_build_/default/extensions'
For further information a tutorial for gdb and
reading up on how you can install debugging
diff --git a/README b/README
index cc78dc95..805d5db6 100644
--- a/README
+++ b/README
@@ -2,19 +2,19 @@ This file is licensed under the terms of the expat license, see the file EXPAT.
Midori is a lightweight web browser.
-* Full integration with GTK+2 and GTK+3.
-* Fast rendering with WebKit and HTML5 video with GStreamer.
+* Full integration with GTK+2.
+* Fast rendering with WebKit.
* Tabs, windows and session management.
-* History completion and configurable Web Search.
+* Flexibly configurable Web Search.
* User scripts and user styles support.
-* Adblock Plus compatible, external download manager support.
* Straightforward bookmark management.
-* Customizable interface, extensions written in C and Vala.
+* Customizable and extensible interface.
+* Extensions written in C.
-Requirements: GLib 2.22, GTK+ 2.16, WebkitGTK+ 1.1.17, libXML2,
- libsoup 2.27.90, sqlite 3.0, Vala 0.14
+Requirements: GLib 2.22, GTK+ 2.10, WebkitGTK+ 1.1.17, libXML2,
+ libsoup 2.27.90, sqlite 3.0, Vala 0.10
-Optional: GTK+ 3.0, Unique 0.9, libnotify, gcr
+Optional: GTK+ 3.0, Unique 0.9, libnotify
For installation instructions read INSTALL.
diff --git a/configure b/configure
index f5e9d8fa..f38dd4a4 100755
--- a/configure
+++ b/configure
@@ -130,7 +130,7 @@ clean:
distclean:
@$WAF distclean
- @-rm -rf _build
+ @-rm -rf _build_
@-rm -f Makefile
check:
diff --git a/data/about.css b/data/about.css
deleted file mode 100644
index 66cb3345..00000000
--- a/data/about.css
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- about: page style template for Midori.
- This file is licensed under the terms of the expat license, see the file EXPAT.
- */
-body {
- background-color: #eee;
- margin: 0;
- padding: 0;
-}
-
-#container {
- background: #f6fff3;
- min-width: 70%;
- max-width: 70%;
- margin: 2em auto 1em;
- padding: 1em;
- border: 0.2em solid #9acb7f;
- -webkit-border-radius: 1em;
-}
-
-#icon {
- float: left;
- padding-left: 1%;
- padding-top: 1%;
-}
-
-html[dir="rtl"] #icon {
- float: right;
- padding-right: 1%;
-}
-
-#main {
- float: right;
- width: 75%;
-}
-
-h1 {
- font-size: 1.4em;
- font-weight: bold;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
-}
-
-#logo {
- position: absolute; bottom: 15px;
- z-index: -1;
-}
-
-html[dir="ltr"] #logo {
- right: 15px;
-}
-
-html[dir="rtl"] #logo {
- left: 15px;
-}
-
-button span,
-button img {
- vertical-align: middle;
- padding: 2px 1px;
-}
-
-message {
- font-size: 1.1em;
-}
-
-description {
- font-size: 1em;
-}
diff --git a/data/autosuggestcontrol.js b/data/autosuggestcontrol.js
index 389bfd47..85a506ab 100644
--- a/data/autosuggestcontrol.js
+++ b/data/autosuggestcontrol.js
@@ -186,10 +186,10 @@ AutoSuggestControl.prototype.init = function () {
};
//assign onblur event handler (hides suggestions)
- if (!this.textbox.onblur)
- this.textbox.onblur = function () { oThis.hideSuggestions(); };
- if (!this.textbox.onclick)
- this.textbox.onclick = function () { oThis.hideSuggestions(); };
+ this.textbox.onblur =
+ this.textbox.onclick = function () {
+ oThis.hideSuggestions();
+ };
//create the suggestions dropdown
this.createDropDown();
@@ -299,7 +299,7 @@ function initSuggestions () {
if (inputs.length == 0)
return false;
- for (var i=0;i
-
+
+
{title}
-
+
diff --git a/data/faq.css b/data/faq.css
index 5d92ae19..eb96e13e 100644
--- a/data/faq.css
+++ b/data/faq.css
@@ -8,64 +8,29 @@ Stylesheet for Midori's documentation based on a version of Enrico Troeger.
@media screen {
- html, body {
- width: 100% !important;
- height: 100% !important;
- margin: 0 !important;
- padding: 0 !important;
+ body {
+ background-color: #f6fff3;
+ color: #404040;
+ margin-left: 0.4em;
+ width: 60em;
+ font-size: 90%;
}
- * {
- background: #f6fff3 !important;
- color: #404040 !important;
- font-size: 14pt !important;
- font-family: serif !important;
- text-align: justify !important;
- line-height: 1.4em !important;
- word-spacing: 0.4mm !important;
- letter-spacing: 0.2mm !important;
- -webkit-column-count: auto !important;
- -webkit-column-width: auto !important;
- -webkit-box-shadow: none !important;
- width: auto !important;
- word-wrap: break-word !important;
+ a {
+ color: #013100;
}
- div, p {
- padding: 5pt !important;
- }
-
- li {
- padding-left: 5pt !important;
- }
-
- img, *[accesskey], form *, form, iframe,
- *[id^=navigation], *[id$=navigation], *[id*=navigation], .collapsed, .expanded {
- display: none !important
- }
-
- /* FIXME: we want "images bigger than 50px here" */
- img[width] {
- display: inline !important
- }
-
- :link, :link * {
- color: #013100 !important;
- text-decoration: underline !important;
- }
-
- :visited, :visited * {
- color: #7E558E !important;
- text-decoration: underline !important;
+ a:visited {
+ color: #7E558E;
}
a:hover {
- text-decoration: none !important;
+ text-decoration: none;
}
h1, h2, h3 {
- font-family: serif !important;
- color: #002a00 !important;
+ font-family: sans-serif;
+ color: #002a00;
}
h1 {
diff --git a/data/faq.html b/data/faq.html
index a43a70bb..e4717731 100644
--- a/data/faq.html
+++ b/data/faq.html
@@ -7,7 +7,7 @@
midori:faq
-
+
@@ -17,13 +17,11 @@
-
-
-
+
-
+
@@ -34,35 +32,31 @@ var NS='midori';var JSINFO = {"id":"midori:faq","namespace":"midori"};
-
-
+
-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -82,10 +76,15 @@ This is a snapshot of Frequently Asked Questions designated for offline viewing.
-
+
+
+
+
+
+
@@ -132,9 +131,9 @@ Midori and all delivered artwork are licensed under the LGPL2.
-
-
-
+
+
+
@@ -194,12 +193,6 @@ Use a smaller toolbar:
gtk-toolbar-icon-size = GTK_ICON_SIZE_SMALL_TOOLBAR
-
-Only for those not running a complete DE like Xfce, Elementary, etcâ¦
-
-There is a preference: Preferences â Browsing â Toolbar Style: Small icons
-
-
Enable changing hotkeys while hovering menu items:
@@ -216,80 +209,7 @@ There appears to be an issue with Glib 2.16. The recommended solution is to upgr
-
-
-
-
-On Linux and BSD, you can set XDG_CACHE_HOME for all applications, or just Midori. Midori saves icons and cache files in that location. The default is ~/.cache.
-
-
-
-export XDG_CACHE_HOME=/dev/shm
-
-
-
-
-
-
-
-
-
-
-
-
-
-Midori >= 0.4.7 automatically picks up the Strict-Transport-Security header and caches sites locally. By design, there's no UI. System administrators can however place a pre-loaded cache at /etc/xdg/midori/hsts.
-
-
-
-
-
-
-
-
-Midori >= 0.4.7 supports http://git.gnome.org/browse/gcr/tree/gcr for certificate display and management, you can click the lock in the urlbar to see detailed information. Earlier versions, or one without gcr will not handle certificates beyond the lock icon in the urlbar.
-
-
-
-
-
-
-
-
-No key store is available or it's incorrectly setup. By default GNOME keyring can do this. Under Xfce it is recommended to enable âGNOME servicesâ under âSession and Startup settingsâ. Otherwise this can occur if a script doesn't correctly send the output of âgnome-keyring âstartupâ to the environment.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-WebKitGTK+ and thusly Midori on Windows doesn't support Flash or any other plugins. If WebKitGTK+ adds the feature in the future, we will support it. For now there's nothing we can do.
-
-
-
-Starting with WebkitGTK+ 1.8.2 (Midori 0.4.7) Netscape plugins are now supported.
-Midori should pick them up from standard netscape plugins locations.
-
-
-
-
-
+
@@ -307,17 +227,11 @@ You can either run that above line and run Midori in the same terminal afterward
-
+
-nspluginwrapper is a program that runs Flash and other Netscape plugins in a separate process. So a crash can't cresh the whole browser and Flash, which is GTK+2 can run in GTK+3.
-
-
-
-sudo apt-get install nspluginwrapper
-sudo nspluginwrapper -i /usr/lib/flashplugin-installer/libflashplayer.so
-nspluginwrapper -v -a -n -i
+Try searching for a package named nspluginwrapper or similar in your distribution repositories. It implements plugins in their own process so they can't drag down the whole browser.
@@ -332,28 +246,13 @@ That's a problem with WebKit. You can work around it to some extent if you
-
-
-
-
+
@@ -367,6 +266,8 @@ You need to have GStreamer plugins installed which implement the codecs.
You may need gstreamer0.10-alsa for ALSA, depending on your distribution.
+ With Arch Linux, you may need to install liboil explicitly if it is not installed already (see
this bug report).
+
You need plugins for Theora, gstreamer0.10-base and
MPEG -4 incluing aac (e.g. gst-plugins-faad), gstreamer0.10-bad. For WebM, you'll need plugins for vorbis (-base), matroska (-good), and vp8 (-bad). Have a look at
http://www.gstreamer.net/documentation/plugins.html for details.
For Youtube or Vimeo, you need WebKitGTK+ 1.1.20 or newer.
@@ -392,6 +293,36 @@ icedtea6 version 1.8 and above has been known to crash midori. If this is the c
+
+
+
+
+Currently only HTTP proxy servers are supported directly. A way to use SOCKS on Unix is to use tsocks with SSH as follows:
+
+
+ Install 'tsocks'
+
+ Open /etc/tsocks.conf in an editor
+
+ Type something like this, you can choose the port freely:
server = 127.0.0.1
+server_type = 5
+server_port = 5555
+
+
+ Open an
SSH connection with the same port:
ssh -D localhost:5555 myhost.com
+
+
+ Run Midori with âtsocksâ in front of it:
tsocks midori
+
+
+ Now you can use for example
http://www.whatsmyip.org/ to verify that you are using a SOCKS connection. The IP address should match the one of your
SSH host. Remember to keep the
SSH login running, and don't suspend it, otherwise it won't work.
+
+ If the connection fails for some reason, you should see a connection error.
+
+
+
+
+
@@ -500,138 +431,25 @@ As of git 2011-03-05 02:40:00 UTC and Midori 0.3.3 you can
Add a line to ~/.local/share/applications/mimeapps.list:
-
x-scheme-handler/magnet=transmission-gtk.desktop
+
x-scheme-handler/magnet=transmission-gtk.desktop
Or install an application which advertises the scheme like so:
-
MimeType=x-scheme-handler/magnet;
+
MimeType=x-scheme-handler/magnet;
Note that incomplete .desktop files will silently fail and it will look as if it doesn't exist.
-
-
-
-
-
-First enable spell checking:
-EditâPreferencesâBehavior and check âEnable Spell Checkingâ.
-
-
-
-Now while typing any errors should get underlined in red. To get suggestions, highlight the word and right-click. You should see a list of suggestions at the top of the menu.
-
-
-
-On Windows you need to download OpenOffice dictionaries , find the zipped file(s) for your locale(s) and unpack the contents into share/myspell/dicts/ in your Midori installation. The folder should contain *.aff and *.dic files
-
-
-
-
-
-
-
-
-You can change all values of WebKitWebSettings in the config file (~/.config/midori/config on unices, %APPDATA%\midori\config [please check :)] on Windows). For example, to disable Same Origin Policy for local files, add
-
-
enable-universal-access-from-file-uris=true
-
-
- to your config file.
-
-
-
-
-
-
-
- Activate the Statusbar Features plugin.
-
- Close Midori.
-
- Create a folder ~/.config/midori/extensions/libstatusbar-features.so/
-
- Create a text file âconfigâ
-
- Type the following for the default setup:
-
-
-
[settings]
- items=auto-load-images;enable-scripts;enable-plugins;identify-as;zoom-level
-
-
-Add button types separated by semicolon:
-
-
- proxy-type Proxy Server
-
- preferred-encoding Character Set/ Encoding
-
- enable-spell-checking Spell Check
-
- zoom-text-and-images Only zoom in text, or text and images
-
- first-party-cookies-only First party cookies only
-
-
-
-
-
-
-Most settings listed at http://webkitgtk.org/reference/webkitgtk/stable/WebKitWebSettings.html will also work as button types.
-
-
-
-
-
+
+
-
-
-
-
-
-As of Midori 0.4.4 you can add a hidden option to ~/.config/midori/config like so:
-
-
site-data-rules=-google.com,-facebook.com,!bugzilla.gnome.org,+bugs.launchpad.net
-
- Values prefixed with â-â are always blocked
-
- Values prefixed with â+â are always accepted
-
- Values prefixed with â!â are not cleared in Clear Private Data
-
- No wildcards.
-
- LSO, local storage and application caches ignore all policies.
-
-
-
-
-The feature is currently experimental and will change in future versions.
-
-
-
-
-
-
-
-
-The Advertisement Blocker can be activated under Extensions. It uses the same lists as Adblock Plus. URLs are blocked completely and never loaded. Lists can be added through the option button on the right side in the extension list.
-
-
-
-
-
-
-
-
-
-
+
+
@@ -651,13 +469,13 @@ There are two closely related features to open websites as dedicated windows of
-
-
+
+
-
-
-File menu/ App Menu button â Private Browsing
-
+
+ File menu/ App Menu button â Private Browsing
+
+
A private window is a separate process, so crashes don't affect the normal browser session. No sensitive data such as cookies, history or bookmarks are stored. No extensions are loaded. Panels are not available.
@@ -677,51 +495,10 @@ The same options available to -a/ âapp can be used for private browsing mode.
-
-
+
+
-
-On Windows builds, -P/ âportable causes all data to be written to the âprofileâ folder in the Midori folder. Everything, including temporary files and cache, is stored in a sub-folder without touching the system. So Midori can be run eg. from a USB stick on different machines.
-
-
-
-
-
-
-
-
-There is no specific mode, instead you use several command line switches. A typical fullscreen setup with no toolbar that opens about:blank and resets the session after 2 minutes of inactivity for instance:
-
-
midori -i 120 -e Fullscreen -e Navigationbar -a about:blank
-
-
-Available commands for -e can be listed with âmidori âhelp-executeâ.
-
-
-
-If needed, a customized profile can be created with âmidori -c /path/to/folderâ. Using the shortcut editor extension, keyboard shortcuts can be removed as needed. Afterwards just append â-c /path/to/folderâ to the kiosk mode command line.
-
-
-
-To restrict pages that can be opened, you can use a regular expression. The expression is a blacklist. To block undesirable sites you can do something like:
-
-
-b 'youtube|youporn'
-
-
-By negating the expression you can also whitelist pages.
-
-
-b '^(?!.*?(gmail|mail\.google|accounts\.google)).*'
-
-
-Any links outside end up in an error page. All images and other files won't be loaded.
-
-
-
-
-
-
-
By running a local proxy you can modify web content even before it has reached Midori. That allows you to do things similar to what user scripts and user styles provide and even others that neither is suitable for.
@@ -768,48 +545,14 @@ Mousehole is a scriptable proxy server written in Ruby.
-
-
-
-
-
-The coming libSoup 2.40 will support SOCKS proxies, see the relevant bug report .
-
-
-
-libSoup < 2.40 only supports HTTP proxy servers directly. A way to use SOCKS on Unix is to use tsocks with SSH as follows:
-
-
- Install 'tsocks'
-
- Open /etc/tsocks.conf in an editor
-
- Type something like this, you can choose the port freely:
server = 127.0.0.1
-server_type = 5
-server_port = 5555
-
-
- Open an
SSH connection with the same port:
ssh -D localhost:5555 myhost.com
-
-
- Run Midori with âtsocksâ in front of it:
tsocks midori
-
-
- Now you can use for example
http://www.whatsmyip.org/ to verify that you are using a SOCKS connection. The IP address should match the one of your
SSH host. Remember to keep the
SSH login running, and don't suspend it, otherwise it won't work.
-
- If the connection fails for some reason, you should see a connection error.
-
-
-
-
-
-
-
+
+
+
-
-
-
+
+
+
You can use the Vim-like key bindings [hjkl] to navigate a page. h=left j=down k=up l=right In a picture:
@@ -823,12 +566,12 @@ You can also use the arrow keys to do the same.
-
-
-
+
+
+
-To enable Hints in Midori, similar to vimperator in Firefox or xxxterm, press .
+To enable Hints in Midori [similar to those vimperator provides in Firefox], press .
@@ -836,9 +579,9 @@ With hints enabled, type the link number, and press Enter to open the link in th
-
-
-
+
+
+
Since Midori 0.3.5 Ctrl+Tab is supported by default.
@@ -849,18 +592,18 @@ In older versions you can enable the History List extension under Tools â Exte
-
-
-
+
+
+
Enable the Shortcuts extension Tools â Extensions. To edit a keybinding Tools â Customize Shortcutsâ¦
-
-
-
+
+
+
Default shortcuts for Find are:
@@ -869,7 +612,7 @@ Default shortcuts for Find are:
Find: Ctrl+f â/â and â,â
-FindNext: Ctrl+g and Enter
+FindNext: Ctrl+g
FindPrevious: Shift+Ctrl+g
@@ -884,9 +627,9 @@ When using Ctrl+f to bring up Find, use Ctrl+f again or ESC. When using â/â
-
-
-
+
+
+
By default the right mouse button initiates gestures.
@@ -914,9 +657,28 @@ Additionally, there are programs allowing mouse gestures system-wide, for exampl
+
+
+
-
-
+
+First enable spell checking:
+EditâPreferencesâBehavior and check âEnable Spell Checkingâ.
+
+
+
+Now while typing any errors should get underlined in red. To get suggestions, highlight the word and right-click. Should see a list of suggestions on the top of the menu.
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/gtk3.css b/data/gtk3.css
deleted file mode 100644
index e6353665..00000000
--- a/data/gtk3.css
+++ /dev/null
@@ -1,28 +0,0 @@
-.notebook tab .button {
- -GtkButton-default-border: 0;
- -GtkButton-default-outside-border: 0;
- -GtkButton-inner-border: 0;
- -GtkWidget-focus-line-width: 0;
- -GtkWidget-focus-padding: 0;
- padding: 0;
-}
-
-GtkOverlay > * {
- padding: 4px;
- border-style: solid;
- border-radius: 0 5px 0 0;
- border-width: 1px 1px 0 0;
-}
-
-GtkOverlay MidoriFindbar {
- border-radius: 0 0 0 5px;
- border-width: 0 0 1px 1px; /* top right bottom left */
-}
-
-/* Kill grey backround on inactive buttons */
-GtkDrawingArea,
-GtkImage,
-GtkImage:insensitive,
-GtkImage:selected {
- background-color: @transparent;
-}
diff --git a/data/midori.desktop.in b/data/midori.desktop.in
index fc6f39e7..8ec2364a 100644
--- a/data/midori.desktop.in
+++ b/data/midori.desktop.in
@@ -3,8 +3,7 @@ Version=1.0
Type=Application
_Name=Midori
_GenericName=Web Browser
-_X-GNOME-Fullname=Midori Web Browser
-_Comment=Browse the Web
+_Comment=Lightweight web browser
_X-GNOME-Keywords=Internet;WWW;Explorer
_X-AppInstall-Keywords=Internet;WWW;Explorer
Categories=GTK;Network;WebBrowser;
@@ -18,17 +17,17 @@ X-Osso-Service=midori
X-Ayatana-Desktop-Shortcuts=TabNew;WindowNew;Private
[TabNew Shortcut Group]
-_Name=New Tab
+Name=New _Tab
Exec=midori -e TabNew
TargetEnvironment=Unity
[WindowNew Shortcut Group]
-_Name=New Window
+Name=New _Window
Exec=midori -e WindowNew
TargetEnvironment=Unity
[Private Shortcut Group]
-_Name=New Private Browsing Window
+Name=New P_rivate Browsing Window
Exec=midori --private
TargetEnvironment=Unity
diff --git a/data/speeddial-head.html b/data/speeddial-head.html
index 89cb96bb..01249cf9 100644
--- a/data/speeddial-head.html
+++ b/data/speeddial-head.html
@@ -55,7 +55,10 @@
width: 85%;
height: 75%;
margin: auto;
- -webkit-box-shadow: 0 2px 5px rgba(0,0,0,.3), 0 0 0px #fff inset;
+ -webkit-box-shadow: 0 4px 18px rgba(0,0,0,.3), 0 0 2px #fff inset;
+ background-image: -webkit-gradient(
+ linear, center top, center bottom,
+ from(#f6f6f6), to(#e3e3e3));
border: 1px solid #bcbcbc;
border-bottom-color: #a0a0a0;
position: relative;
@@ -72,15 +75,9 @@
div.shortcut .preview.new .add {
display: block;
height: 100%;
- width: 100%;
+ width: 50%;
margin: 0 auto;
cursor: pointer;
- -webkit-box-shadow: 0 2px 5px rgba(0,0,0,.3), 0 0 0px #fff inset;
- background-image: -webkit-gradient(
- linear, center top, center bottom,
- from(#f6f6f6), to(#e3e3e3));
- background-repeat: repeat-x;
- -webkit-border-radius: 3px;
}
.title {
@@ -114,148 +111,95 @@
display:none;
}
- .selected {
- outline: 1px dotted black;
- background-color: #eef;
+ div.osd {
+ top: 9px;
+ position: fixed;
+ width: 100%;
+ text-align: right;
+ }
+
+ div.osd span {
+ border: 1px solid #999;
+ background-color: #f5f5f5;
+ padding: 8px;
+ color: #999;
+ -webkit-border-bottom-left-radius: 10px;
+ visibility: hidden;
}
-
+
+
+
+
diff --git a/docs/api/wscript_build b/docs/api/wscript_build
index df546b18..fdcecb50 100644
--- a/docs/api/wscript_build
+++ b/docs/api/wscript_build
@@ -6,20 +6,18 @@ import pproc as subprocess
import os
import Utils
-blddir = '_build' # recognized by ack
-
for module in ('midori', 'katze'):
try:
- if not os.access (blddir, os.F_OK):
- Utils.check_dir (blddir)
- if not os.access (blddir + '/docs', os.F_OK):
- Utils.check_dir (blddir + '/docs')
- if not os.access (blddir + '/docs/api', os.F_OK):
- Utils.check_dir (blddir + '/docs/api')
+ if not os.access ('_build_', os.F_OK):
+ Utils.check_dir ('_build_')
+ if not os.access ('_build_/docs', os.F_OK):
+ Utils.check_dir ('_build_/docs')
+ if not os.access ('_build_/docs/api', os.F_OK):
+ Utils.check_dir ('_build_/docs/api')
subprocess.call (['gtkdoc-scan', '--module=' + module,
- '--source-dir=' + module, '--output-dir=' + blddir + '/docs/api/' + module,
+ '--source-dir=' + module, '--output-dir=_build_/docs/api/' + module,
'--rebuild-sections', '--rebuild-types'])
- os.chdir (blddir + '/docs/api/' + module)
+ os.chdir ('_build_/docs/api/' + module)
subprocess.call (['gtkdoc-mktmpl', '--module=' + module,
'--output-dir=.' + module])
subprocess.call (['gtkdoc-mkdb', '--module=' + module,
diff --git a/extensions/adblock.c b/extensions/adblock.c
index 62f8fc7d..1b8e75e9 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -1,6 +1,6 @@
/*
- Copyright (C) 2009-2012 Christian Dywan
- Copyright (C) 2009-2012 Alexander Butenko
+ Copyright (C) 2009-2010 Christian Dywan
+ Copyright (C) 2009 Alexander Butenko
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -9,8 +9,8 @@
See the file COPYING for the full license text.
*/
+
#include
-#include "midori-core.h"
#include
#include "config.h"
@@ -30,111 +30,67 @@
(__filter[4] != '-' && __filter[5] != '-')
#ifdef G_ENABLE_DEBUG
#define adblock_debug(dmsg, darg1, darg2) \
- do { if (midori_debug ("adblock:match")) g_debug (dmsg, darg1, darg2); } while (0)
+ do { if (debug == 1) g_debug (dmsg, darg1, darg2); } while (0)
#else
#define adblock_debug(dmsg, darg1, darg2) /* nothing */
#endif
-static GHashTable* pattern = NULL;
-static GHashTable* keys = NULL;
-static GHashTable* optslist = NULL;
-static GHashTable* urlcache = NULL;
-static GHashTable* blockcssprivate = NULL;
-static GHashTable* navigationwhitelist = NULL;
-static GString* blockcss = NULL;
-static GList* update_list = NULL;
-static gboolean update_done = FALSE;
-
-static void
-adblock_parse_file (gchar* path);
+static GHashTable* pattern;
+static GHashTable* keys;
+static GHashTable* optslist;
+static GHashTable* urlcache;
+static GString* blockcss;
+static GString* blockcssprivate;
+static gchar* blockscript = NULL;
+#ifdef G_ENABLE_DEBUG
+static guint debug;
+#endif
static gboolean
-adblock_file_is_up_to_date (gchar* path);
+adblock_parse_file (gchar* path);
static void
adblock_reload_rules (MidoriExtension* extension,
gboolean custom_only);
static gchar*
-adblock_build_js (const gchar* uri)
+adblock_build_js (const gchar* private)
{
- gchar* domain;
- const gchar* style;
- GString* subdomain;
- GString* code;
- int cnt = 0, blockscnt = 0;
- gchar** subdomains;
-
- domain = midori_uri_parse_hostname (uri, NULL);
- subdomains = g_strsplit (domain, ".", -1);
- g_free (domain);
- if (!subdomains)
- return NULL;
-
- code = g_string_new (
+ return g_strdup_printf (
"window.addEventListener ('DOMContentLoaded',"
"function () {"
" if (document.getElementById('madblock'))"
" return;"
- " public = '");
-
- cnt = g_strv_length (subdomains) - 1;
- subdomain = g_string_new (subdomains [cnt]);
- g_string_prepend_c (subdomain, '.');
- cnt--;
- while (cnt >= 0)
- {
- g_string_prepend (subdomain, subdomains[cnt]);
- if ((style = g_hash_table_lookup (blockcssprivate, subdomain->str)))
- {
- g_string_append (code, style);
- g_string_append_c (code, ',');
- blockscnt++;
- }
- g_string_prepend_c (subdomain, '.');
- cnt--;
- }
- g_string_free (subdomain, TRUE);
- g_strfreev (subdomains);
-
- if (blockscnt == 0)
- return g_string_free (code, TRUE);
-
- g_string_append (code,
- " zz-non-existent {display: none !important}';"
+ // Get just domain name from URL
+ " var URL = location.href.match(/:\\/\\/(.[^/]+)/)[1];"
+ " var sites = new Array(); %s;"
+ " var public = '.madblockplaceholder ';"
+ // Split domain into subdomain parts
+ " var subdomains = URL.split ('.');"
+ " var hostname = subdomains [subdomains.length - 1];"
+ " var i = subdomains.length - 2;"
+ // Check if any of subdomains do have blocking rules
+ " while (i >= 0) {"
+ " hostname = subdomains [i] + '.' + hostname;"
+ " if (sites [hostname])"
+ " public += ', ' + sites [hostname];"
+ " i--;"
+ " }"
+ " public += ' {display: none !important}';"
" var mystyle = document.createElement('style');"
" mystyle.setAttribute('type', 'text/css');"
" mystyle.setAttribute('id', 'madblock');"
" mystyle.appendChild(document.createTextNode(public));"
" var head = document.getElementsByTagName('head')[0];"
" if (head) head.appendChild(mystyle);"
- "}, true);");
- return g_string_free (code, FALSE);
+ "}, true);",
+ private);
}
static GString*
adblock_fixup_regexp (const gchar* prefix,
gchar* src);
-static void
-adblock_destroy_db ()
-{
- if (blockcss)
- g_string_free (blockcss, TRUE);
- blockcss = NULL;
-
- g_hash_table_destroy (pattern);
- pattern = NULL;
- g_hash_table_destroy (optslist);
- optslist = NULL;
- g_hash_table_destroy (urlcache);
- urlcache = NULL;
- g_hash_table_destroy (blockcssprivate);
- blockcssprivate = NULL;
- g_hash_table_destroy (navigationwhitelist);
- navigationwhitelist = NULL;
-}
-
static void
adblock_init_db ()
{
@@ -150,16 +106,12 @@ adblock_init_db ()
urlcache = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)g_free);
- blockcssprivate = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)g_free);
- navigationwhitelist = g_hash_table_new_full (g_direct_hash, g_str_equal,
- NULL,
- (GDestroyNotify)g_free);
-
if (blockcss && blockcss->len > 0)
g_string_free (blockcss, TRUE);
+ if (blockcssprivate && blockcssprivate->len > 0)
+ g_string_free (blockcssprivate, TRUE);
blockcss = g_string_new ("z-non-exist");
+ blockcssprivate = g_string_new ("");
}
static void
@@ -167,26 +119,23 @@ adblock_download_notify_status_cb (WebKitDownload* download,
GParamSpec* pspec,
MidoriExtension* extension)
{
- if (update_done)
+ gchar* path;
+ MidoriApp* app;
+ MidoriWebSettings* settings;
+
+ if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_FINISHED)
return;
- if (webkit_download_get_status (download) == WEBKIT_DOWNLOAD_STATUS_FINISHED)
- {
- GList* li = NULL;
- for (li = update_list; li != NULL; li = g_list_next (li))
- {
- gchar* uri = g_strdup (webkit_download_get_destination_uri (download) + 7);
- if (g_strcmp0 (li->data, uri))
- update_list = g_list_remove (update_list, li->data);
- g_free (uri);
- }
- }
+ path = g_filename_from_uri (webkit_download_get_destination_uri (download), NULL, NULL);
+ adblock_parse_file (path);
+ g_free (path);
- if (g_list_length (update_list) == 0)
- {
- adblock_reload_rules (extension, FALSE);
- update_done = TRUE;
- }
+ app = midori_extension_get_app (extension);
+ settings = katze_object_get_object (app, "settings");
+ g_string_append (blockcss, " {display: none !important}\n");
+ midori_web_settings_add_style (settings, "adblock-blockcss", blockcss->str);
+ katze_assign (blockscript, adblock_build_js (blockcssprivate->str));
+ g_object_unref (settings);
}
static gchar*
@@ -202,7 +151,8 @@ adblock_get_filename_for_uri (const gchar* uri)
if (!strncmp (uri, "file", 4))
return g_strndup (uri + 7, strlen (uri) - 7);
- folder = g_build_filename (midori_paths_get_cache_dir (), "adblock", NULL);
+ folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
+ "adblock", NULL);
katze_mkdir_with_parents (folder, 0700);
filename = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
@@ -224,8 +174,6 @@ adblock_reload_rules (MidoriExtension* extension,
MidoriApp* app = midori_extension_get_app (extension);
MidoriWebSettings* settings = katze_object_get_object (app, "settings");
- if (pattern)
- adblock_destroy_db ();
adblock_init_db ();
custom_list = g_build_filename (midori_extension_get_config_dir (extension),
@@ -245,7 +193,7 @@ adblock_reload_rules (MidoriExtension* extension,
continue;
}
- if (!adblock_file_is_up_to_date (path))
+ if (!adblock_parse_file (path))
{
WebKitNetworkRequest* request;
WebKitDownload* download;
@@ -255,14 +203,11 @@ adblock_reload_rules (MidoriExtension* extension,
download = webkit_download_new (request);
g_object_unref (request);
webkit_download_set_destination_uri (download, destination);
- update_list = g_list_prepend (update_list, path);
g_free (destination);
g_signal_connect (download, "notify::status",
G_CALLBACK (adblock_download_notify_status_cb), extension);
webkit_download_start (download);
}
- else
- adblock_parse_file (path);
g_free (path);
i++;
}
@@ -270,6 +215,7 @@ adblock_reload_rules (MidoriExtension* extension,
g_strfreev (filters);
g_string_append (blockcss, " {display: none !important}\n");
+ katze_assign (blockscript, adblock_build_js (blockcssprivate->str));
midori_web_settings_add_style (settings, "adblock-blockcss", blockcss->str);
g_object_unref (settings);
}
@@ -502,8 +448,6 @@ adblock_get_preferences_dialog (MidoriExtension* extension)
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
#endif
NULL);
- katze_widget_add_class (gtk_dialog_get_widget_for_response (
- GTK_DIALOG (dialog), GTK_RESPONSE_HELP), "help_button");
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed), &dialog);
@@ -529,10 +473,8 @@ adblock_get_preferences_dialog (MidoriExtension* extension)
"and click \"Add\" to add it to the list. "
"You can find more lists at %s."),
#if GTK_CHECK_VERSION (2, 18, 0)
- "adblockplus.org/en/subscriptions "
"easylist.adblockplus.org ");
#else
- "http://adblockplus.org/en/subscriptions "
"http://easylist.adblockplus.org/ ");
#endif
#if GTK_CHECK_VERSION (2, 18, 0)
@@ -597,7 +539,6 @@ adblock_get_preferences_dialog (MidoriExtension* extension)
vbox = gtk_vbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 4);
button = gtk_button_new_from_stock (GTK_STOCK_ADD);
- g_object_set_data (G_OBJECT (dialog), "entry", entry);
g_object_set_data (G_OBJECT (button), "entry", entry);
g_signal_connect (button, "clicked",
G_CALLBACK (adblock_preferences_add_clicked_cb), liststore);
@@ -646,9 +587,8 @@ adblock_get_preferences_dialog (MidoriExtension* extension)
return dialog;
}
-static GtkWidget*
-adblock_show_preferences_dialog (MidoriExtension* extension,
- const gchar* uri)
+static void
+adblock_open_preferences_cb (MidoriExtension* extension)
{
static GtkWidget* dialog = NULL;
@@ -661,19 +601,6 @@ adblock_show_preferences_dialog (MidoriExtension* extension,
}
else
gtk_window_present (GTK_WINDOW (dialog));
-
- if (uri != NULL)
- {
- GtkWidget* entry = g_object_get_data (G_OBJECT (dialog), "entry");
- gtk_entry_set_text (GTK_ENTRY (entry), uri);
- }
- return dialog;
-}
-
-static void
-adblock_open_preferences_cb (MidoriExtension* extension)
-{
- adblock_show_preferences_dialog (extension, NULL);
}
static inline gint
@@ -695,9 +622,7 @@ adblock_check_rule (GRegex* regex,
return FALSE;
}
/* TODO: Domain opt check */
- #ifdef G_ENABLE_DEBUG
adblock_debug ("blocked by pattern regexp=%s -- %s", g_regex_get_pattern (regex), req_uri);
- #endif
return TRUE;
}
@@ -826,51 +751,13 @@ adblock_prepare_urihider_js (GList* uris)
return g_string_free (js, FALSE);
}
-static gboolean
-adblock_navigation_policy_decision_requested_cb (WebKitWebView* web_view,
- WebKitWebFrame* web_frame,
- WebKitNetworkRequest* request,
- WebKitWebNavigationAction* action,
- WebKitWebPolicyDecision* decision,
- MidoriExtension* extension)
-{
- const gchar* uri = webkit_network_request_get_uri (request);
- if (g_str_has_prefix (uri, "abp:"))
- {
- gchar** parts;
- gchar* filter;
- if (g_str_has_prefix (uri, "abp:subscribe?location="))
- uri = &uri[23];
- else if (g_str_has_prefix (uri, "abp://subscribe?location="))
- uri = &uri[25];
- else
- return FALSE;
-
- parts = g_strsplit (uri, "&", 2);
- filter = soup_uri_decode (parts[0]);
- webkit_web_policy_decision_ignore (decision);
- adblock_show_preferences_dialog (extension, filter);
- g_free (filter);
- g_strfreev (parts);
- return TRUE;
- }
-
- if (web_frame == webkit_web_view_get_main_frame (web_view))
- {
- const gchar* req_uri = webkit_network_request_get_uri (request);
- g_hash_table_replace (navigationwhitelist, web_view, g_strdup (req_uri));
- }
- return false;
-}
-
-
static void
adblock_resource_request_starting_cb (WebKitWebView* web_view,
WebKitWebFrame* web_frame,
WebKitWebResource* web_resource,
WebKitNetworkRequest* request,
WebKitNetworkResponse* response,
- MidoriView* view)
+ GtkWidget* image)
{
SoupMessage* msg;
GList* blocked_uris;
@@ -882,11 +769,12 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view,
if (midori_uri_is_blank (page_uri))
return;
- req_uri = webkit_network_request_get_uri (request);
-
- if (!g_strcmp0 (req_uri, g_hash_table_lookup (navigationwhitelist, web_view)))
+ /* Never filter the main page itself */
+ if (web_frame == webkit_web_view_get_main_frame (web_view)
+ && webkit_web_frame_get_load_status (web_frame) == WEBKIT_LOAD_PROVISIONAL)
return;
+ req_uri = webkit_network_request_get_uri (request);
if (!midori_uri_is_http (req_uri)
|| g_str_has_suffix (req_uri, "favicon.ico"))
return;
@@ -895,17 +783,8 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view,
if (!(msg && !g_strcmp0 (msg->method, "GET")))
return;
- if (response != NULL) /* request is caused by redirect */
- {
- if (web_frame == webkit_web_view_get_main_frame (web_view))
- {
- g_hash_table_replace (navigationwhitelist, web_view, g_strdup (req_uri));
- return;
- }
- }
-
#ifdef G_ENABLE_DEBUG
- if (midori_debug ("adblock:time"))
+ if (debug == 2)
g_test_timer_start ();
#endif
if (adblock_is_matched (req_uri, page_uri))
@@ -916,7 +795,7 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view,
g_object_set_data (G_OBJECT (web_view), "blocked-uris", blocked_uris);
}
#ifdef G_ENABLE_DEBUG
- if (midori_debug ("adblock:time"))
+ if (debug == 2)
g_debug ("match: %f%s", g_test_timer_elapsed (), "seconds");
#endif
@@ -975,16 +854,16 @@ adblock_custom_block_image_cb (GtkWidget* widget,
custom_list = g_build_filename (midori_extension_get_config_dir (extension),
CUSTOM_LIST_NAME, NULL);
- katze_mkdir_with_parents (midori_extension_get_config_dir (extension), 0700);
- if ((list = g_fopen (custom_list, "a+")))
+ if (!(list = g_fopen (custom_list, "a+")))
{
- g_fprintf (list, "%s\n", gtk_entry_get_text (GTK_ENTRY (entry)));
- fclose (list);
- adblock_reload_rules (extension, TRUE);
- g_debug ("%s: Updated custom list\n", G_STRFUNC);
+ g_free (custom_list);
+ return;
}
- else
- g_debug ("%s: Failed to open custom list %s\n", G_STRFUNC, custom_list);
+
+ g_fprintf (list, "%s\n", gtk_entry_get_text (GTK_ENTRY (entry)));
+ fclose (list);
+ adblock_reload_rules (extension, TRUE);
+
g_free (custom_list);
gtk_widget_destroy (dialog);
}
@@ -1053,19 +932,13 @@ adblock_window_object_cleared_cb (WebKitWebView* web_view,
JSObjectRef js_window)
{
const char *page_uri;
- gchar* script;
page_uri = webkit_web_frame_get_uri (web_frame);
/* Don't add adblock css into speeddial and about: pages */
if (!midori_uri_is_http (page_uri))
return;
- script = adblock_build_js (page_uri);
- if (!script)
- return;
-
- g_free (sokoke_js_script_eval (js_context, script, NULL));
- g_free (script);
+ g_free (sokoke_js_script_eval (js_context, blockscript, NULL));
}
static void
@@ -1074,33 +947,31 @@ adblock_add_tab_cb (MidoriBrowser* browser,
MidoriExtension* extension)
{
GtkWidget* web_view = midori_view_get_web_view (view);
+ GtkWidget* image = g_object_get_data (G_OBJECT (browser), "status-image");
g_signal_connect (web_view, "window-object-cleared",
G_CALLBACK (adblock_window_object_cleared_cb), 0);
g_signal_connect_after (web_view, "populate-popup",
G_CALLBACK (adblock_populate_popup_cb), extension);
- g_signal_connect (web_view, "navigation-policy-decision-requested",
- G_CALLBACK (adblock_navigation_policy_decision_requested_cb), extension);
g_signal_connect (web_view, "resource-request-starting",
- G_CALLBACK (adblock_resource_request_starting_cb), view);
+ G_CALLBACK (adblock_resource_request_starting_cb), image);
g_signal_connect (web_view, "load-finished",
- G_CALLBACK (adblock_load_finished_cb), view);
-}
-
-static void
-adblock_remove_tab_cb (MidoriBrowser* browser,
- MidoriView* view,
- MidoriExtension* extension)
-{
- GtkWidget* web_view = midori_view_get_web_view (view);
- g_hash_table_remove (navigationwhitelist, web_view);
+ G_CALLBACK (adblock_load_finished_cb), image);
}
static void
adblock_deactivate_cb (MidoriExtension* extension,
MidoriBrowser* browser);
+static void
+adblock_add_tab_foreach_cb (MidoriView* view,
+ MidoriBrowser* browser,
+ MidoriExtension* extension)
+{
+ adblock_add_tab_cb (browser, view, extension);
+}
+
static void
adblock_app_add_browser_cb (MidoriApp* app,
MidoriBrowser* browser,
@@ -1108,8 +979,6 @@ adblock_app_add_browser_cb (MidoriApp* app,
{
GtkWidget* statusbar;
GtkWidget* image;
- GtkWidget* view;
- gint i;
statusbar = katze_object_get_object (browser, "statusbar");
image = NULL;
@@ -1119,14 +988,10 @@ adblock_app_add_browser_cb (MidoriApp* app,
g_object_set_data_full (G_OBJECT (browser), "status-image", image,
(GDestroyNotify)gtk_widget_destroy);
- i = 0;
- while((view = midori_browser_get_nth_tab(browser, i++)))
- adblock_add_tab_cb (browser, MIDORI_VIEW (view), extension);
-
+ midori_browser_foreach (browser,
+ (GtkCallback)adblock_add_tab_foreach_cb, extension);
g_signal_connect (browser, "add-tab",
G_CALLBACK (adblock_add_tab_cb), extension);
- g_signal_connect (browser, "remove-tab",
- G_CALLBACK (adblock_remove_tab_cb), extension);
g_signal_connect (extension, "open-preferences",
G_CALLBACK (adblock_open_preferences_cb), extension);
g_signal_connect (extension, "deactivate",
@@ -1224,9 +1089,7 @@ adblock_compile_regexp (GString* gpatt,
if (!g_regex_match_simple ("[\\*]", sig, G_REGEX_UNGREEDY, G_REGEX_MATCH_NOTEMPTY) &&
!g_hash_table_lookup (keys, sig))
{
- #ifdef G_ENABLE_DEBUG
adblock_debug ("sig: %s %s", sig, patt);
- #endif
g_hash_table_insert (keys, sig, regex);
g_hash_table_insert (optslist, sig, g_strdup (opts));
signature_count++;
@@ -1236,9 +1099,7 @@ adblock_compile_regexp (GString* gpatt,
if (g_regex_match_simple ("^\\*", sig, G_REGEX_UNGREEDY, G_REGEX_MATCH_NOTEMPTY) &&
!g_hash_table_lookup (pattern, patt))
{
- #ifdef G_ENABLE_DEBUG
adblock_debug ("patt2: %s %s", sig, patt);
- #endif
g_hash_table_insert (pattern, patt, regex);
g_hash_table_insert (optslist, patt, g_strdup (opts));
}
@@ -1254,9 +1115,7 @@ adblock_compile_regexp (GString* gpatt,
}
else
{
- #ifdef G_ENABLE_DEBUG
adblock_debug ("patt: %s%s", patt, "");
- #endif
/* Pattern is a regexp chars */
g_hash_table_insert (pattern, patt, regex);
g_hash_table_insert (optslist, patt, g_strdup (opts));
@@ -1311,9 +1170,7 @@ adblock_add_url_pattern (gchar* prefix,
format_patt = adblock_fixup_regexp (prefix, patt);
- #ifdef G_ENABLE_DEBUG
adblock_debug ("got: %s opts %s", format_patt->str, opts);
- #endif
should_free = adblock_compile_regexp (format_patt, opts);
if (data[1] && data[2])
@@ -1343,22 +1200,6 @@ adblock_frame_add (gchar* line)
g_string_append (blockcss, line);
}
-static void
-adblock_update_css_hash (gchar* domain,
- gchar* value)
-{
- const gchar* olddata;
- gchar* newdata;
-
- if ((olddata = g_hash_table_lookup (blockcssprivate, domain)))
- {
- newdata = g_strconcat (olddata, " , ", value, NULL);
- g_hash_table_replace (blockcssprivate, g_strdup (domain), newdata);
- }
- else
- g_hash_table_insert (blockcssprivate, g_strdup (domain), g_strdup (value));
-}
-
static inline void
adblock_frame_add_private (const gchar* line,
const gchar* sep)
@@ -1390,16 +1231,18 @@ adblock_frame_add_private (const gchar* line,
/* Ignore Firefox-specific option */
if (!g_strcmp0 (domain, "~pregecko2"))
continue;
- /* FIXME: ~ should negate match */
+ /* strip ~ from domain */
if (domain[0] == '~')
domain++;
- adblock_update_css_hash (g_strstrip (domain), data[1]);
+ g_string_append_printf (blockcssprivate, ";sites['%s']+=',%s'",
+ g_strstrip (domain), data[1]);
}
g_strfreev (domains);
}
else
{
- adblock_update_css_hash (data[0], data[1]);
+ g_string_append_printf (blockcssprivate, ";sites['%s']+=',%s'",
+ data[0], data[1]);
}
g_strfreev (data);
}
@@ -1407,92 +1250,12 @@ adblock_frame_add_private (const gchar* line,
static gchar*
adblock_parse_line (gchar* line)
{
- /*
- * AdblockPlus rule reference based on http://adblockplus.org/en/filters
- * Block URL:
- * http://example.com/ads/banner123.gif
- * http://example.com/ads/banner*.gif
- * http://example.com/ads/*
- * Partial match for "ad":
- * *ad*
- * ad
- * Block example.com/annoyingflash.swf but not example.com/swf/:
- * swf|
- * Block bad.example/banner.gif but not good.example/analyze?http://bad.example:
- * |http://baddomain.example/
- * Block http(s) example.com but not badexample.com or good.example/analyze?http://bad.example:
- * ||example.com/banner.gif
- * Block example.com/ and example.com:8000/ but not example.com.ar/:
- * http://example.com^
- * A ^ matches anything that isn't A-Za-z0-0_-.%
- * Block example.com:8000/foo.bar?a=12&b=%D1%82%D0%B5:
- * ^example.com^
- * ^%D1%82%D0%B5^
- * ^foo.bar^
- * TODO: ^ is partially supported by Midori
- * Block banner123 and banner321 with a regex:
- * /banner\d+/
- * Never block URIs with "advice":
- * @@advice
- * No blocking at all:
- * @@http://example.com
- * @@|http://example.com
- * TODO: @@ is currently ignored by Midori.
- * Element hiding by class:
- * ##textad
- * ##div.textad
- * Element hiding by id:
- * ##div#sponsorad
- * ##*#sponsorad
- * Match example.com/ and something.example.com/ but not example.org/
- * example.com##*.sponsor
- * Match multiple domains:
- * domain1.example,domain2.example,domain3.example##*.sponsor
- * Match on any domain but "example.com":
- * ~example.com##*.sponsor
- * Match on "example.com" except "foo.example.com":
- * example.com,~foo.example.com##*.sponsor
- * By design rules only apply to full domain names:
- * "domain" is NOT equal to "domain.example,domain.test."
- * In Firefox rules can apply to browser UI:
- * browser##menuitem#javascriptConsole will hide the Console menuitem
- * Hide tables with width attribute 80%:
- * ##table[width="80%"]
- * Hide all div with title attribute containing "adv":
- * ##div[title*="adv"]
- * Hide div with title starting with "adv" and ending with "ert":
- * ##div[title^="adv"][title$="ert"]
- * Match tables with width attribute 80% and bgcolor attribute white:
- * table[width="80%"][bgcolor="white"]
- * TODO: [] is currently ignored by Midori
- * Hide anything following div with class "adheader":
- * ##div.adheader + *
- * Old CSS element hiding syntax, officially deprecated:
- * #div(id=foo)
- * Match anything but "example.com"
- * ~example.com##*.sponsor
- * TODO: ~ is currently ignored by Midori
- * Match "example.com" domain except "foo.example.com":
- * example.com,~foo.example.com##*.sponsor
- * ! Comment
- * Supported options after a trailing $:
- * domain,third-party,~pregecko2
- * Official options (not all supported by Midori):
- * script,image,stylesheet,object,xmlhttprequest,object-subrequest,
- * subdocument,document,elemhide,popup,third-party,sitekey,match-case
- * collapse,donottrack,pregecko2
- * Deprecated:
- * background,xbl,ping,dtd
- * Inverse options:
- * ~script,~image,~stylesheet,~object,~xmlhttprequest,~collapse,
- * ~object-subrequest,~subdocument,~document,~elemhide,~third-party,
- * ~pregecko2
- **/
-
- /* Skip invalid, empty and comment lines */
- if (!(line && line[0] != ' ' && line[0] != '!' && line[0]))
+ if (!line)
+ return NULL;
+ g_strchomp (line);
+ /* Ignore comments and new lines */
+ if (line[0] == '!')
return NULL;
-
/* FIXME: No support for whitelisting */
if (line[0] == '@' && line[1] == '@')
return NULL;
@@ -1500,7 +1263,9 @@ adblock_parse_line (gchar* line)
if (line[0] == '[')
return NULL;
- g_strchomp (line);
+ /* Skip garbage */
+ if (line[0] == ' ' || !line[0])
+ return NULL;
/* Got CSS block hider */
if (line[0] == '#' && line[1] == '#' )
@@ -1518,13 +1283,13 @@ adblock_parse_line (gchar* line)
adblock_frame_add_private (line, "##");
return NULL;
}
+
/* Got per domain CSS hider rule. Workaround */
if (strchr (line, '#'))
{
adblock_frame_add_private (line, "#");
return NULL;
}
-
/* Got URL blocker rule */
if (line[0] == '|' && line[1] == '|' )
{
@@ -1540,156 +1305,7 @@ adblock_parse_line (gchar* line)
return adblock_add_url_pattern ("", "uri", line);
}
-static GDateMonth
-str_month_name_to_gdate (const gchar* month)
-{
- guint i;
- const gchar* months[] = {
- "", "January", "February", "March", "April", "May", "June",
- "July", "August", "September", "October", "November", "December"
- };
-
- for (i = 0; i < G_N_ELEMENTS (months); i++)
- {
- if (strncmp (month, months[i], 3) == 0)
- return i;
- }
- return 0;
-}
-
static gboolean
-adblock_file_is_up_to_date (gchar* path)
-{
- FILE* file;
- gchar line[2000];
-
- /* Check a chunk of header for update info */
- if ((file = g_fopen (path, "r")))
- {
- gint days_to_expire = 0;
- gchar* timestamp = NULL;
- guint i;
- gboolean found_meta = FALSE;
- gint fs_days_elapsed, days_elapsed = 0, least_days;
-
- for (i = 0; i <= 15; i++)
- {
- fgets (line, 2000, file);
- if (strncmp ("! Expires", line, 9) == 0)
- {
- gchar** parts = g_strsplit (line, " ", 4);
- days_to_expire = atoi (parts[2]);
- g_strfreev (parts);
- found_meta = TRUE;
- }
- if (strncmp ("! This list expires after", line, 25) == 0)
- {
- gchar** parts = g_strsplit (line, " ", 7);
-
- if (strncmp (parts[6], "days", 4) == 0)
- days_to_expire = atoi (parts[5]);
- if (strncmp (parts[6], "hours", 5) == 0)
- days_to_expire = (atoi (parts[5])) / 24;
-
- g_strfreev (parts);
- found_meta = TRUE;
- }
-
- if (strncmp ("! Last modified", line, 15) == 0
- || strncmp ("! Updated", line, 9) == 0)
- {
- gchar** parts = g_strsplit (line, ":", 2);
- timestamp = g_strdup (parts[1] + 1);
- g_strchomp (timestamp);
- g_strfreev (parts);
- found_meta = TRUE;
- }
- }
-
- if (!found_meta)
- {
- g_print ("Adblock: no metadata found in %s (broken download?)\n", path);
- return FALSE;
- }
-
- /* query filesystem about file change, maybe there is no update yet
- * or there is no "modified" metadata to check, otherwise we will repeatedly
- * download files that have no new updates */
- {
- GDate* current = g_date_new ();
- GDate* fs_mod_date = g_date_new ();
- GTimeVal mod_time;
- GFile* filter_file = g_file_new_for_path (path);
- GFileInfo* info = g_file_query_info (filter_file, "time:modified", 0, NULL, NULL);
-
- g_file_info_get_modification_time (info, &mod_time);
- g_date_set_time_t (current, time (NULL));
- g_date_set_time_val (fs_mod_date, &mod_time);
-
- fs_days_elapsed = g_date_days_between (fs_mod_date, current);
-
- g_date_free (current);
- g_date_free (fs_mod_date);
- }
-
- /* If there is no update metadata but file is valid, assume one week */
- if ((!days_to_expire && !timestamp) && fs_days_elapsed < 7)
- return TRUE;
-
- if (days_to_expire && timestamp != NULL)
- {
- GDate* current = g_date_new ();
- GDate* mod_date = g_date_new ();
- gchar** parts;
- gboolean use_dots = FALSE;
-
- /* Common dates are 20 Mar 2012, 20.08.2012 */
- if (g_strrstr (timestamp, "."))
- {
- use_dots = TRUE;
- parts = g_strsplit (timestamp, ".", 4);
- }
- else
- parts = g_strsplit (timestamp, " ", 4);
-
- g_date_set_day (mod_date, atoi (parts[0]));
-
- if (use_dots)
- g_date_set_month (mod_date, atoi (parts[1]));
- else
- g_date_set_month (mod_date, str_month_name_to_gdate (parts[1]));
-
- g_date_set_year (mod_date, atoi (parts[2]));
- g_strfreev (parts);
-
- g_date_set_time_t (current, time (NULL));
- days_elapsed = g_date_days_between (mod_date, current);
-
- g_date_free (current);
- g_date_free (mod_date);
- g_free (timestamp);
- }
-
- /* File from the future? Assume up to date */
- if (days_elapsed < 0)
- {
- g_print ("Adblock: file %s appears to be from the future,"
- "check your system clock!\n", path);
- return TRUE;
- }
-
- least_days = days_elapsed < fs_days_elapsed ? days_elapsed : fs_days_elapsed;
- if (least_days < days_to_expire)
- return TRUE;
- else
- return FALSE;
-
- return TRUE;
- }
- return FALSE;
-}
-
-static void
adblock_parse_file (gchar* path)
{
FILE* file;
@@ -1700,7 +1316,9 @@ adblock_parse_file (gchar* path)
while (fgets (line, 2000, file))
adblock_parse_line (line);
fclose (file);
+ return TRUE;
}
+ return FALSE;
}
static void
@@ -1709,25 +1327,24 @@ adblock_deactivate_tabs (MidoriView* view,
MidoriExtension* extension)
{
GtkWidget* web_view = midori_view_get_web_view (view);
+ GtkWidget* image = g_object_get_data (G_OBJECT (browser), "status-image");
+ g_signal_handlers_disconnect_by_func (
+ browser, adblock_add_tab_cb, extension);
g_signal_handlers_disconnect_by_func (
web_view, adblock_window_object_cleared_cb, 0);
g_signal_handlers_disconnect_by_func (
web_view, adblock_populate_popup_cb, extension);
g_signal_handlers_disconnect_by_func (
- web_view, adblock_resource_request_starting_cb, view);
- g_signal_handlers_disconnect_by_func (
- web_view, adblock_load_finished_cb, view);
+ web_view, adblock_resource_request_starting_cb, image);
g_signal_handlers_disconnect_by_func (
- web_view, adblock_navigation_policy_decision_requested_cb, extension);
+ web_view, adblock_load_finished_cb, image);
}
static void
adblock_deactivate_cb (MidoriExtension* extension,
MidoriBrowser* browser)
{
- gint i;
- GtkWidget* view;
MidoriApp* app = midori_extension_get_app (extension);
MidoriWebSettings* settings = katze_object_get_object (app, "settings");
@@ -1739,15 +1356,18 @@ adblock_deactivate_cb (MidoriExtension* extension,
app, adblock_app_add_browser_cb, extension);
g_signal_handlers_disconnect_by_func (
browser, adblock_add_tab_cb, extension);
- g_signal_handlers_disconnect_by_func (
- browser, adblock_remove_tab_cb, extension);
+ midori_browser_foreach (browser, (GtkCallback)adblock_deactivate_tabs, browser);
- i = 0;
- while((view = midori_browser_get_nth_tab(browser, i++)))
- adblock_deactivate_tabs (MIDORI_VIEW (view), browser, extension);
+ if (blockcss)
+ g_string_free (blockcss, TRUE);
+ if (blockcssprivate)
+ g_string_free (blockcssprivate, TRUE);
- adblock_destroy_db ();
midori_web_settings_remove_style (settings, "adblock-blockcss");
+ blockcssprivate = blockcss = NULL;
+ g_hash_table_destroy (pattern);
+ g_hash_table_destroy (optslist);
+ g_hash_table_destroy (urlcache);
g_object_unref (settings);
}
@@ -1755,9 +1375,25 @@ static void
adblock_activate_cb (MidoriExtension* extension,
MidoriApp* app)
{
+ #ifdef G_ENABLE_DEBUG
+ const gchar* debug_mode;
+ #endif
KatzeArray* browsers;
MidoriBrowser* browser;
+ #ifdef G_ENABLE_DEBUG
+ debug_mode = g_getenv ("MIDORI_ADBLOCK");
+ if (debug_mode)
+ {
+ if (*debug_mode == '1')
+ debug = 1;
+ else if (*debug_mode == '2')
+ debug = 2;
+ else
+ debug = 0;
+ }
+ #endif
+
adblock_reload_rules (extension, FALSE);
browsers = katze_object_get_object (app, "browsers");
@@ -1790,57 +1426,6 @@ test_adblock_parse (void)
g_assert_cmpstr (adblock_parse_line ("http://bla.blub/*"), ==, "http://bla.blub/");
}
-static void
-test_subscription_update (void)
-{
- gint temp;
- gchar* filename;
-
- temp = g_file_open_tmp ("midori_adblock_update_test_XXXXXX", &filename, NULL);
- close (temp);
-
- g_file_set_contents (filename, "", -1, NULL);
- g_assert (!adblock_file_is_up_to_date (filename));
-
- g_file_set_contents (filename,
- "[Adblock Plus 1.1]\n"
- "! Checksum: 48f6Qdo4PsNogsurLvQ71w\n"
- "! Title: EasyList\n"
- "! Last modified: 05 Sep 2010 11:00 UTC\n"
- "! This list expires after 48 hours\n",
- -1, NULL);
- g_assert (!adblock_file_is_up_to_date (filename));
-
- g_file_set_contents (filename,
- "[Adblock Plus 1.1]\n"
- "! Checksum: 48f6Qdo4PsNogsurLvQ71w\n"
- "! Title: EasyList\n"
- "! Last modified: 05.09.2010 11:00 UTC\n"
- "! Expires: 2 days (update frequency)\n",
- -1, NULL);
- g_assert (!adblock_file_is_up_to_date (filename));
-
- g_file_set_contents (filename,
- "[Adblock Plus 1.1]\n"
- "! Checksum: 48f6Qdo4PsNogsurLvQ71w\n"
- "! Title: EasyList\n"
- "! Updated: 05 Nov 2014 11:00 UTC\n"
- "! Expires: 5 days (update frequency)\n",
- -1, NULL);
- g_assert (adblock_file_is_up_to_date (filename));
-
- g_file_set_contents (filename,
- "[Adblock]\n"
- "! dutchblock v3\n"
- "! This list expires after 14 days\n"
- "|http://b*.mookie1.com/\n",
- -1, NULL);
- g_assert (adblock_file_is_up_to_date (filename));
-
- g_unlink (filename);
- g_free (filename);
-}
-
static void
test_adblock_pattern (void)
{
@@ -1904,7 +1489,6 @@ extension_test (void)
{
g_test_add_func ("/extensions/adblock/parse", test_adblock_parse);
g_test_add_func ("/extensions/adblock/pattern", test_adblock_pattern);
- g_test_add_func ("/extensions/adblock/update", test_subscription_update);
}
#endif
@@ -1914,7 +1498,7 @@ extension_init (void)
MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION,
"name", _("Advertisement blocker"),
"description", _("Block advertisements according to a filter list"),
- "version", "0.6" MIDORI_VERSION_SUFFIX,
+ "version", "0.5" MIDORI_VERSION_SUFFIX,
"authors", "Christian Dywan ",
NULL);
midori_extension_install_string_list (extension, "filters", NULL, G_MAXSIZE);
diff --git a/extensions/addons.c b/extensions/addons.c
index 37e42fb7..7c566f41 100644
--- a/extensions/addons.c
+++ b/extensions/addons.c
@@ -14,7 +14,6 @@
/* This extensions add support for user addons: userscripts and userstyles */
#include
-#include "midori-core.h"
#include
#include "config.h"
@@ -183,8 +182,8 @@ addons_install_response (GtkWidget* infobar,
if (!filename)
filename = g_path_get_basename (uri);
- folder_path = g_build_path (G_DIR_SEPARATOR_S,
- midori_paths_get_user_data_dir (), PACKAGE_NAME, folder, NULL);
+ folder_path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
+ PACKAGE_NAME, folder, NULL);
if (!g_file_test (folder_path, G_FILE_TEST_EXISTS))
katze_mkdir_with_parents (folder_path, 0700);
@@ -294,13 +293,13 @@ addons_button_add_clicked_cb (GtkToolItem* toolitem,
if (addons->kind == ADDONS_USER_SCRIPTS)
{
addons_type = g_strdup ("userscripts");
- path = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_user_data_dir (),
+ path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
PACKAGE_NAME, "scripts", NULL);
}
else if (addons->kind == ADDONS_USER_STYLES)
{
addons_type = g_strdup ("userstyles");
- path = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_user_data_dir (),
+ path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
PACKAGE_NAME, "styles", NULL);
}
else
@@ -337,13 +336,23 @@ addons_button_add_clicked_cb (GtkToolItem* toolitem,
if (!g_file_test (path, G_FILE_TEST_EXISTS))
katze_mkdir_with_parents (path, 0700);
+ #if !GTK_CHECK_VERSION (2, 14, 0)
+ files = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dialog));
+ #else
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
+ #endif
+
while (files)
{
GFile* src_file;
GError* error = NULL;
+ #if !GTK_CHECK_VERSION (2, 14, 0)
+ src_file = g_file_new_for_path (files);
+ #else
src_file = files->data;
+ #endif
+
if (G_IS_FILE (src_file))
{
GFile* dest_file;
@@ -482,7 +491,7 @@ addons_open_in_editor_clicked_cb (GtkWidget* toolitem,
g_object_get (settings, "text-editor", &text_editor, NULL);
if (text_editor && *text_editor)
- sokoke_spawn_program (text_editor, TRUE, element->fullpath, TRUE);
+ sokoke_spawn_program (text_editor, element->fullpath);
else
{
gchar* element_uri = g_filename_to_uri (element->fullpath, NULL, NULL);
@@ -513,13 +522,10 @@ addons_open_target_folder_clicked_cb (GtkWidget* toolitem,
folder = g_path_get_dirname (element->fullpath);
}
else
- {
- folder = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_user_data_dir (),
- PACKAGE_NAME, addons->kind == ADDONS_USER_SCRIPTS
- ? "scripts" : "styles", NULL);
- katze_mkdir_with_parents (folder, 0700);
- }
-
+ folder = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
+ PACKAGE_NAME,
+ addons->kind == ADDONS_USER_SCRIPTS
+ ? "scripts" : "styles", NULL);
folder_uri = g_filename_to_uri (folder, NULL, NULL);
g_free (folder);
@@ -777,10 +783,11 @@ addons_treeview_render_text_cb (GtkTreeViewColumn* column,
gtk_tree_model_get (model, iter, 0, &element, -1);
- g_object_set (renderer, "text", element->displayname,
- "sensitive", element->enabled,
- "ellipsize", PANGO_ELLIPSIZE_END,
- NULL);
+ g_object_set (renderer, "text", element->displayname, NULL);
+ if (!element->enabled)
+ g_object_set (renderer, "sensitive", false, NULL);
+ else
+ g_object_set (renderer, "sensitive", true, NULL);
}
static void
@@ -824,16 +831,19 @@ addons_get_directories (AddonsKind kind)
else
g_assert_not_reached ();
- path = g_build_path (G_DIR_SEPARATOR_S, midori_paths_get_user_data_dir (),
+ path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
PACKAGE_NAME, folder_name, NULL);
- directories = g_slist_prepend (directories, path);
+ if (g_access (path, X_OK) == 0)
+ directories = g_slist_prepend (directories, path);
+ else
+ g_free (path);
datadirs = g_get_system_data_dirs ();
while (*datadirs)
{
path = g_build_path (G_DIR_SEPARATOR_S, *datadirs,
PACKAGE_NAME, folder_name, NULL);
- if (g_slist_find (directories, path) == NULL)
+ if (g_slist_find (directories, path) == NULL && g_access (path, X_OK) == 0)
directories = g_slist_prepend (directories, path);
else
g_free (path);
@@ -1325,9 +1335,8 @@ addons_init (Addons* addons)
G_CALLBACK (addons_cell_renderer_toggled_cb), addons);
gtk_tree_view_append_column (GTK_TREE_VIEW (addons->treeview), column);
column = gtk_tree_view_column_new ();
- gtk_tree_view_column_set_expand (column, TRUE);
renderer_text = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer_text, TRUE);
+ gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
(GtkTreeCellDataFunc)addons_treeview_render_text_cb,
addons->treeview, NULL);
@@ -1678,10 +1687,10 @@ addons_save_settings (MidoriApp* app,
config_dir = midori_extension_get_config_dir (extension);
config_file = g_build_filename (config_dir, "addons", NULL);
- if (config_dir != NULL)
- katze_mkdir_with_parents (config_dir, 0700);
+ katze_mkdir_with_parents (config_dir, 0700);
sokoke_key_file_save_to_file (keyfile, config_file, &error);
- if (error && midori_extension_get_config_dir (extension) != NULL)
+ /* If the folder is /, this is a test run, thus no error */
+ if (error && !g_str_equal (config_dir, "/"))
{
g_warning (_("The configuration of the extension '%s' couldn't be saved: %s\n"),
_("User addons"), error->message);
diff --git a/extensions/colorful-tabs.c b/extensions/colorful-tabs.c
index 9bb84c3b..bb261d58 100644
--- a/extensions/colorful-tabs.c
+++ b/extensions/colorful-tabs.c
@@ -48,10 +48,11 @@ colorful_tabs_view_notify_uri_cb (MidoriView* view,
if (!midori_uri_is_blank (midori_view_get_display_uri (view))
&& (hostname = midori_uri_parse_hostname (midori_view_get_display_uri (view), NULL))
- && midori_view_get_icon_uri (view) != NULL)
+ && katze_object_get_enum (view, "load-status") == MIDORI_LOAD_FINISHED)
{
icon = midori_view_get_icon (view);
- if (icon != NULL)
+
+ if (midori_view_get_icon_uri (view) != NULL)
{
GdkPixbuf* newpix;
guchar* pixels;
diff --git a/extensions/cookie-manager/cookie-manager-page.c b/extensions/cookie-manager/cookie-manager-page.c
index 186e310e..d21d128d 100644
--- a/extensions/cookie-manager/cookie-manager-page.c
+++ b/extensions/cookie-manager/cookie-manager-page.c
@@ -702,6 +702,7 @@ static gchar *cm_get_domain_description_text(const gchar *domain, gint cookie_co
}
+#if GTK_CHECK_VERSION(2, 12, 0)
static gboolean cm_tree_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode,
GtkTooltip *tooltip, CookieManagerPage *cmp)
{
@@ -730,6 +731,8 @@ static gboolean cm_tree_query_tooltip(GtkWidget *widget, gint x, gint y, gboolea
return FALSE;
}
+#endif
+
static gboolean cm_filter_match(const gchar *haystack, const gchar *needle)
{
@@ -809,20 +812,25 @@ static void cm_filter_entry_changed_cb(GtkEditable *editable, CookieManagerPage
if (priv->ignore_changed_filter)
return;
- if (!g_object_get_data (G_OBJECT (editable), "sokoke_has_default"))
- text = gtk_entry_get_text(GTK_ENTRY(editable));
- else
- text = NULL;
+ text = gtk_entry_get_text(GTK_ENTRY(editable));
cm_filter_tree(cmp, text);
cookie_manager_update_filter(priv->parent, text);
- if (text && *text)
- gtk_tree_view_collapse_all(GTK_TREE_VIEW(priv->treeview));
- else
+ if (*text != '\0')
gtk_tree_view_expand_all(GTK_TREE_VIEW(priv->treeview));
+ else
+ gtk_tree_view_collapse_all(GTK_TREE_VIEW(priv->treeview));
}
+
+static void cm_filter_entry_clear_icon_released_cb(GtkIconEntry *e, gint pos, gint btn, gpointer data)
+{
+ if (pos == GTK_ICON_ENTRY_SECONDARY)
+ gtk_entry_set_text(GTK_ENTRY(e), "");
+}
+
+
static void cm_tree_selection_changed_cb(GtkTreeSelection *selection, CookieManagerPage *cmp)
{
GList *rows;
@@ -994,7 +1002,6 @@ static void cm_tree_render_text_cb(GtkTreeViewColumn *column, GtkCellRenderer *r
}
else
g_object_set(renderer, "text", name, NULL);
- g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
g_free(name);
}
@@ -1015,7 +1022,6 @@ static GtkWidget *cm_tree_prepare(CookieManagerPage *cmp)
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(
_("Name"), renderer, "text", COOKIE_MANAGER_COL_NAME, NULL);
- gtk_tree_view_column_set_expand (column, TRUE);
gtk_tree_view_column_set_sort_indicator(column, TRUE);
gtk_tree_view_column_set_sort_column_id(column, COOKIE_MANAGER_COL_NAME);
gtk_tree_view_column_set_resizable(column, TRUE);
@@ -1039,8 +1045,10 @@ static GtkWidget *cm_tree_prepare(CookieManagerPage *cmp)
g_signal_connect(treeview, "popup-menu", G_CALLBACK(cm_tree_popup_menu_cb), cmp);
/* tooltips */
+#if GTK_CHECK_VERSION(2, 12, 0)
gtk_widget_set_has_tooltip(treeview, TRUE);
g_signal_connect(treeview, "query-tooltip", G_CALLBACK(cm_tree_query_tooltip), cmp);
+#endif
/* drag'n'drop */
gtk_tree_view_enable_model_drag_source(
@@ -1092,6 +1100,7 @@ static void cookie_manager_page_init(CookieManagerPage *self)
GtkWidget *desc_swin;
GtkWidget *paned;
GtkWidget *filter_hbox;
+ GtkWidget *filter_label;
GtkWidget *treeview;
CookieManagerPagePrivate *priv;
@@ -1123,15 +1132,29 @@ static void cookie_manager_page_init(CookieManagerPage *self)
tree_swin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tree_swin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(tree_swin), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(tree_swin), treeview);
gtk_widget_show(tree_swin);
- priv->filter_entry = sokoke_search_entry_new (_("Search Cookies by Name or Domain"));
+ filter_label = gtk_label_new(_("Filter:"));
+ gtk_widget_show(filter_label);
+
+ priv->filter_entry = gtk_icon_entry_new();
+ gtk_widget_set_tooltip_text(priv->filter_entry,
+ _("Enter a filter string to show only cookies whose name or domain "
+ "field match the entered filter"));
gtk_widget_show(priv->filter_entry);
+ gtk_icon_entry_set_icon_from_stock(GTK_ICON_ENTRY(priv->filter_entry),
+ GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_CLEAR);
+ gtk_icon_entry_set_icon_highlight(GTK_ICON_ENTRY (priv->filter_entry),
+ GTK_ICON_ENTRY_SECONDARY, TRUE);
+ g_signal_connect(priv->filter_entry, "icon-release",
+ G_CALLBACK(cm_filter_entry_clear_icon_released_cb), NULL);
g_signal_connect(priv->filter_entry, "changed", G_CALLBACK(cm_filter_entry_changed_cb), self);
g_signal_connect(priv->filter_entry, "activate", G_CALLBACK(cm_filter_entry_changed_cb), self);
filter_hbox = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(filter_hbox), filter_label, FALSE, FALSE, 3);
gtk_box_pack_start(GTK_BOX(filter_hbox), priv->filter_entry, TRUE, TRUE, 3);
gtk_widget_show(filter_hbox);
diff --git a/extensions/delayed-load.vala b/extensions/delayed-load.vala
deleted file mode 100644
index 83af2539..00000000
--- a/extensions/delayed-load.vala
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- Copyright (C) 2012 André Stösel
-
- 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.
-*/
-
-using Gtk;
-using Katze;
-using Midori;
-
-namespace DelayedLoad {
- private class PreferencesDialog : Dialog {
- protected Manager dl_manager;
- protected Scale slider;
-
- public PreferencesDialog (Manager manager) {
- this.dl_manager = manager;
-
- this.title = _("Preferences for %s").printf ( _("Delayed load"));
- if (this.get_class ().find_property ("has-separator") != null)
- this.set ("has-separator", false);
- this.border_width = 5;
- this.set_modal (true);
- this.set_default_size (350, 100);
- this.create_widgets ();
-
- this.response.connect (response_cb);
- }
-
- private void response_cb (Dialog source, int response_id) {
- switch (response_id) {
- case ResponseType.APPLY:
- this.dl_manager.set_integer ("delay", (int) (this.slider.get_value () * 1000));
- this.dl_manager.preferences_changed ();
- this.destroy ();
- break;
- case ResponseType.CANCEL:
- this.destroy ();
- break;
- }
- }
-
- private void create_widgets () {
- Label text = new Label (_("Delay in seconds until loading the page:"));
-#if HAVE_GTK3
- this.slider = new Scale.with_range (Orientation.HORIZONTAL, 0, 15, 0.1);
-#else
- this.slider = new HScale.with_range (0, 15, 0.1);
-#endif
-
- int delay = this.dl_manager.get_integer ("delay");
- if (delay > 0)
- this.slider.set_value ((float)delay / 1000);
-
-#if HAVE_GTK3
- Gtk.Box vbox = get_content_area () as Gtk.Box;
- vbox.pack_start (text, false, false, 0);
- vbox.pack_start (this.slider, false, true, 0);
-#else
- this.vbox.pack_start (text, false, false, 0);
- this.vbox.pack_start (this.slider, false, true, 0);
-#endif
-
- this.add_button (Gtk.STOCK_CANCEL, ResponseType.CANCEL);
- this.add_button (Gtk.STOCK_APPLY, ResponseType.APPLY);
-
- this.show_all ();
- }
- }
-
- private class TabShaker : GLib.Object {
- public unowned Midori.Browser browser;
- public GLib.PtrArray tasks;
-
- public bool reload_tab () {
- if (tasks.len == 1) {
- Midori.View? view = browser.tab as Midori.View;
- Midori.View scheduled_view = tasks.index (0) as Midori.View;
- if (scheduled_view == view) {
- Katze.Item item = view.get_proxy_item ();
- item.ref();
-
- int64 delay = item.get_meta_integer ("delay");
- if (delay == -2) {
- view.reload (true);
- }
- }
- }
- tasks.remove_index (0);
- return false;
- }
-
- public TabShaker (Midori.Browser browser) {
- this.browser = browser;
- }
-
- construct {
- this.tasks = new GLib.PtrArray ();
- }
- }
-
- private class Manager : Midori.Extension {
- private int timeout = 0;
- private bool timeout_handler = false;
- private HashTable tasks;
-
- public signal void preferences_changed ();
-
- private void preferences_changed_cb () {
- this.timeout = get_integer ("delay");
- }
-
- private void show_preferences () {
- PreferencesDialog dialog = new PreferencesDialog (this);
- dialog.show ();
- }
-
- private void schedule_reload (Midori.Browser browser, Midori.View view) {
- if (this.timeout == 0)
- view.reload (true);
- else {
- unowned TabShaker shaker = tasks.get (browser);
- if (shaker != null) {
- shaker.tasks.add (view);
- Timeout.add (this.timeout, shaker.reload_tab);
- }
- }
- }
-
- private void tab_changed (Midori.View? old_view, Midori.View? new_view) {
- if (new_view != null) {
- Midori.App app = get_app ();
- Midori.Browser browser = app.browser;
-
- Katze.Item item = new_view.get_proxy_item ();
- item.ref();
-
- int64 delay = item.get_meta_integer ("delay");
- if (delay == -2 && new_view.progress < 1.0) {
- this.schedule_reload (browser, new_view);
- }
- }
- }
-
- private bool reload_first_tab () {
- Midori.App app = get_app ();
- Midori.Browser? browser = app.browser;
- Midori.View? view = browser.tab as Midori.View;
-
- if (view != null) {
- Katze.Item item = view.get_proxy_item ();
- item.ref();
-
- int64 delay = item.get_meta_integer ("delay");
- if (delay != 1) {
- unowned WebKit.WebView web_view = view.get_web_view ();
- WebKit.LoadStatus load_status = web_view.load_status;
- if (load_status == WebKit.LoadStatus.FINISHED) {
- if (this.timeout != 0)
- this.tasks.set (browser, new TabShaker (browser));
-
- if (view.progress < 1.0)
- this.schedule_reload (browser, view);
-
- return false;
- }
- }
- }
-
- return true;
- }
-
- private void browser_added (Midori.Browser browser) {
- browser.switch_tab.connect_after (this.tab_changed);
- }
-
- private void browser_removed (Midori.Browser browser) {
- browser.switch_tab.disconnect (this.tab_changed);
- }
-
- public void activated (Midori.App app) {
- /* FIXME: override behavior without changing the preference */
- app.settings.load_on_startup = MidoriStartup.DELAYED_PAGES;
-
- this.preferences_changed ();
-
- Midori.Browser? focused_browser = app.browser;
- if (focused_browser == null)
- Timeout.add (50, this.reload_first_tab);
-
- foreach (Midori.Browser browser in app.get_browsers ()) {
- browser_added (browser);
- }
- app.add_browser.connect (browser_added);
- }
-
- public void deactivated () {
- Midori.App app = get_app ();
- foreach (Midori.Browser browser in app.get_browsers ()) {
- browser_removed (browser);
- }
- app.add_browser.disconnect (browser_added);
- }
-
- internal Manager () {
- GLib.Object (name: _("Delayed load"),
- description: _("Delay page load until you actually use the tab."),
- version: "0.1",
- authors: "André Stösel ");
-
- install_integer ("delay", 0);
-
- activate.connect (this.activated);
- deactivate.connect (this.deactivated);
- open_preferences.connect (show_preferences);
- preferences_changed.connect (preferences_changed_cb);
-
- this.tasks = new HashTable (GLib.direct_hash, GLib.direct_equal);
- }
- }
-}
-
-public Midori.Extension extension_init () {
- return new DelayedLoad.Manager ();
-}
-
diff --git a/extensions/external-download-manager.vala b/extensions/external-download-manager.vala
deleted file mode 100644
index b8c60142..00000000
--- a/extensions/external-download-manager.vala
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- Copyright (C) 2012 André Stösel
-
- 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.
-*/
-
-using Gtk;
-using Soup;
-using Katze;
-using Midori;
-using WebKit;
-
-namespace EDM {
- [DBus (name = "net.launchpad.steadyflow.App")]
- interface SteadyflowInterface : GLib.Object {
- public abstract void AddFile (string url) throws IOError;
- }
-
- private class DownloadRequest : GLib.Object {
- public string uri;
- public string auth;
- public string referer;
- public string? cookie_header;
- }
-
- internal Manager manager;
-
- private class Manager : GLib.Object {
- private CookieJar cookie_jar;
- private GLib.PtrArray download_managers = new GLib.PtrArray ();
-
- public bool download_requested (Midori.View view, WebKit.Download download) {
- Midori.DownloadType download_type = download.get_data ("midori-download-type");
-
- if (download_type == Midori.DownloadType.SAVE) {
- var dlReq = new DownloadRequest ();
- dlReq.uri = download.get_uri ();
-
- var request = download.get_network_request ();
- var message = request.get_message ();
- weak MessageHeaders headers = message.request_headers;
-
- dlReq.auth = headers.get ("Authorization");
- dlReq.referer = headers.get ("Referer");
- dlReq.cookie_header = this.cookie_jar.get_cookies (new Soup.URI (dlReq.uri), true);
-
- for (var i = 0 ; i < download_managers.len; i++) {
- var dm = download_managers.index (i) as ExternalDownloadManager;
- if (dm.download (dlReq))
- return true;
- }
- }
- return false;
- }
-
- public void tab_added (Midori.Browser browser, Midori.View view) {
- view.download_requested.connect (download_requested);
- }
-
- public void tab_removed (Midori.Browser browser, Midori.View view) {
- view.download_requested.disconnect(download_requested);
- }
-
- public void browser_added (Midori.Browser browser) {
- foreach (var tab in browser.get_tabs ())
- tab_added (browser, tab);
- browser.add_tab.connect (tab_added);
- browser.remove_tab.connect (tab_removed);
- }
-
- public void browser_removed (Midori.Browser browser) {
- foreach (var tab in browser.get_tabs ())
- tab_removed (browser, tab);
- browser.add_tab.disconnect (tab_added);
- browser.remove_tab.disconnect (tab_removed);
- }
-
- public void activated (Midori.Extension extension, Midori.App app) {
- this.download_managers.add (extension);
- if (this.download_managers.len == 1) {
- foreach (var browser in app.get_browsers ())
- browser_added (browser);
- app.add_browser.connect (browser_added);
- }
- }
-
- public void deactivated (Midori.Extension extension) {
- this.download_managers.remove (extension);
- if (this.download_managers.len == 0) {
- var app = extension.get_app ();
- foreach (var browser in app.get_browsers ())
- browser_removed (browser);
- app.add_browser.disconnect (browser_added);
- }
- }
-
- construct {
- var session = WebKit.get_default_session ();
- this.cookie_jar = session.get_feature (typeof (CookieJar)) as CookieJar;
- }
- }
-
- private abstract class ExternalDownloadManager : Midori.Extension {
- public void activated (Midori.App app) {
- manager.activated (this, app);
- }
-
- public void deactivated () {
- manager.deactivated (this);
- }
-
- public void handle_exception (GLib.Error error) {
- string ext_name;
- this.get ("name",out ext_name);
- var dialog = new MessageDialog (null, DialogFlags.MODAL,
- MessageType.ERROR, ButtonsType.CLOSE,
- _("An error occurred when attempting to download a file with the following plugin:\n" +
- "%s\n\n" +
- "Error:\n%s\n\n" +
- "Carry on without this plugin."
- ),
- ext_name, error.message);
- dialog.response.connect ((a) => { dialog.destroy (); });
- dialog.run ();
- }
-
- public abstract bool download (DownloadRequest dlReq);
- }
-
- private class Aria2 : ExternalDownloadManager {
- public override bool download (DownloadRequest dlReq) {
- var url = value_array_new ();
- value_array_insert (url, 0, typeof (string), dlReq.uri);
-
- GLib.HashTable options = value_hash_new ();
- var referer = new GLib.Value (typeof (string));
- referer.set_string (dlReq.referer);
- options.insert ("referer", referer);
-
- var headers = value_array_new ();
- if (dlReq.cookie_header != null) {
- value_array_insert (headers, 0, typeof (string), "Cookie: %s".printf(dlReq.cookie_header));
- }
-
- if (headers.n_values > 0)
- options.insert ("header", headers);
-
- var message = XMLRPC.request_new ("http://127.0.0.1:6800/rpc",
- "aria2.addUri",
- typeof (ValueArray), url,
- typeof(HashTable), options);
- var session = new SessionSync ();
- session.send_message (message);
-
- try {
- Value v;
- XMLRPC.parse_method_response ((string) message.response_body.flatten ().data, -1, out v);
- return true;
- } catch (Error e) {
- this.handle_exception (e);
- }
-
- return false;
- }
-
- internal Aria2 () {
- GLib.Object (name: _("External Download Manager - Aria2"),
- description: _("Download files with Aria2"),
- version: "0.1" + Midori.VERSION_SUFFIX,
- authors: "André Stösel ",
- key: "aria2");
-
- this.activate.connect (activated);
- this.deactivate.connect (deactivated);
- }
- }
-
- private class SteadyFlow : ExternalDownloadManager {
- public override bool download (DownloadRequest dlReq) {
- try {
- SteadyflowInterface dm = Bus.get_proxy_sync (
- BusType.SESSION,
- "net.launchpad.steadyflow.App",
- "/net/launchpad/steadyflow/app");
- dm.AddFile (dlReq.uri);
- return true;
- } catch (Error e) {
- this.handle_exception (e);
- }
- return false;
- }
-
- internal SteadyFlow () {
- GLib.Object (name: _("External Download Manager - SteadyFlow"),
- description: _("Download files with SteadyFlow"),
- version: "0.1" + Midori.VERSION_SUFFIX,
- authors: "André Stösel ",
- key: "steadyflow");
-
- this.activate.connect (activated);
- this.deactivate.connect (deactivated);
- }
- }
-
- private class CommandLinePreferences : Dialog {
- protected Entry input;
- protected CommandLine commandline;
-
- public CommandLinePreferences(CommandLine cl) {
- this.commandline = cl;
-
- string ext_name;
- this.get ("name",out ext_name);
-
- this.title = _("Preferences for %s").printf (ext_name);
- if (this.get_class ().find_property ("has-separator") != null)
- this.set ("has-separator", false);
- this.border_width = 5;
- this.set_modal (true);
- this.set_default_size (400, 100);
- this.create_widgets ();
-
- this.response.connect (response_cb);
- }
-
- private void response_cb (Dialog source, int response_id) {
- switch (response_id) {
- case ResponseType.APPLY:
- this.commandline.set_string ("commandline", this.input.get_text ());
- this.destroy ();
- break;
- case ResponseType.CANCEL:
- this.destroy ();
- break;
- }
- }
-
- private void create_widgets () {
- Label text = new Label (_("Command:"));
- this.input = new Entry ();
- this.input.set_text (this.commandline.get_string ("commandline"));
-
-
-#if HAVE_GTK3
- Gtk.Box vbox = get_content_area () as Gtk.Box;
- vbox.pack_start (text, false, false, 0);
- vbox.pack_start (this.input, false, true, 0);
-#else
- this.vbox.pack_start (text, false, false, 0);
- this.vbox.pack_start (this.input, false, true, 0);
-#endif
-
- this.add_button (Gtk.STOCK_CANCEL, ResponseType.CANCEL);
- this.add_button (Gtk.STOCK_APPLY, ResponseType.APPLY);
-
- this.show_all ();
- }
- }
-
- private class CommandLine : ExternalDownloadManager {
- private void show_preferences () {
- CommandLinePreferences dialog = new CommandLinePreferences (this);
- dialog.show ();
- }
-
- public override bool download (DownloadRequest dlReq) {
- try {
- string cmd = this.get_string ("commandline");
- cmd = cmd.replace("{REFERER}", GLib.Shell.quote (dlReq.referer));
- if (dlReq.cookie_header != null) {
- cmd = cmd.replace("{COOKIES}", GLib.Shell.quote ("Cookie: " + dlReq.cookie_header));
- } else {
- cmd = cmd.replace("{COOKIES}", "\'\'");
- }
- cmd = cmd.replace("{URL}", GLib.Shell.quote (dlReq.uri));
- GLib.Process.spawn_command_line_async (cmd);
- return true;
- } catch (Error e) {
- this.handle_exception (e);
- }
- return false;
- }
-
- internal CommandLine () {
- GLib.Object (name: _("External Download Manager - CommandLine"),
- description: _("Download files with a specified command"),
- version: "0.1" + Midori.VERSION_SUFFIX,
- authors: "André Stösel ",
- key: "commandline");
-
- this.install_string ("commandline", "wget --no-check-certificate --referer={REFERER} --header={COOKIES} {URL}");
-
- this.activate.connect (activated);
- this.deactivate.connect (deactivated);
- this.open_preferences.connect (show_preferences);
- }
- }
-}
-
-public Katze.Array extension_init () {
- EDM.manager = new EDM.Manager();
-
- var extensions = new Katze.Array( typeof (Midori.Extension));
- extensions.add_item (new EDM.Aria2 ());
- extensions.add_item (new EDM.SteadyFlow ());
- extensions.add_item (new EDM.CommandLine ());
- return extensions;
-}
-
diff --git a/extensions/feed-panel/feed-panel.c b/extensions/feed-panel/feed-panel.c
index de0d457e..327237dc 100644
--- a/extensions/feed-panel/feed-panel.c
+++ b/extensions/feed-panel/feed-panel.c
@@ -840,8 +840,7 @@ feed_panel_init (FeedPanel* panel)
webview = webkit_web_view_new ();
#if GTK_CHECK_VERSION(3,0,0)
- font_desc = (PangoFontDescription*)gtk_style_context_get_font (
- gtk_widget_get_style_context (treeview), GTK_STATE_FLAG_NORMAL);
+ font_desc = gtk_style_context_get_font(gtk_widget_get_style_context(treeview), GTK_STATE_FLAG_NORMAL);
#else
font_desc = treeview->style->font_desc;
#endif
diff --git a/extensions/formhistory.c b/extensions/formhistory.c
new file mode 100644
index 00000000..00e9ea72
--- /dev/null
+++ b/extensions/formhistory.c
@@ -0,0 +1,600 @@
+/*
+ Copyright (C) 2009 Alexander Butenko
+ Copyright (C) 2009 Christian Dywan
+
+ 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.
+*/
+
+#define MAXCHARS 60
+#define MINCHARS 2
+
+#include
+#include
+
+#include "config.h"
+#if HAVE_UNISTD_H
+ #include
+#endif
+
+static GHashTable* global_keys;
+static gchar* jsforms;
+
+
+static void
+formhistory_toggle_state_cb (GtkAction* action,
+ MidoriBrowser* browser);
+
+static gboolean
+formhistory_prepare_js ()
+{
+ gchar* autosuggest;
+ gchar* style;
+ guint i;
+ gchar* file;
+
+ file = sokoke_find_data_filename ("autosuggestcontrol.js", TRUE);
+ if (!g_file_get_contents (file, &autosuggest, NULL, NULL))
+ {
+ g_free (file);
+ return FALSE;
+ }
+ g_strchomp (autosuggest);
+
+ katze_assign (file, sokoke_find_data_filename ("autosuggestcontrol.css", TRUE));
+ if (!g_file_get_contents (file, &style, NULL, NULL))
+ {
+ g_free (file);
+ return FALSE;
+ }
+ g_strchomp (style);
+ i = 0;
+ while (style[i])
+ {
+ if (style[i] == '\n')
+ style[i] = ' ';
+ i++;
+ }
+
+ jsforms = g_strdup_printf (
+ "%s"
+ "window.addEventListener ('DOMContentLoaded',"
+ "function () {"
+ " if (document.getElementById('formhistory'))"
+ " return;"
+ " if (!initSuggestions ())"
+ " return;"
+ " var mystyle = document.createElement('style');"
+ " mystyle.setAttribute('type', 'text/css');"
+ " mystyle.setAttribute('id', 'formhistory');"
+ " mystyle.appendChild(document.createTextNode('%s'));"
+ " var head = document.getElementsByTagName('head')[0];"
+ " if (head) head.appendChild(mystyle);"
+ "}, true);",
+ autosuggest,
+ style);
+ g_strstrip (jsforms);
+ g_free (file);
+ g_free (style);
+ g_free (autosuggest);
+ return TRUE;
+}
+
+static gchar*
+formhistory_fixup_value (char* value)
+{
+ guint i = 0;
+ g_strchomp (value);
+ while (value[i])
+ {
+ if (value[i] == '\n')
+ value[i] = ' ';
+ else if (value[i] == '"')
+ value[i] = '\'';
+ i++;
+ }
+ return value;
+}
+
+static gchar*
+formhistory_build_js ()
+{
+ GString* suggestions;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ suggestions = g_string_new (
+ "function FormSuggestions(eid) { "
+ "arr = new Array();");
+ g_hash_table_iter_init (&iter, global_keys);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ g_string_append_printf (suggestions, " arr[\"%s\"] = [%s]; ",
+ (gchar*)key, (gchar*)value);
+ }
+ g_string_append (suggestions, "this.suggestions = arr[eid]; }");
+ g_string_append (suggestions, jsforms);
+ return g_string_free (suggestions, FALSE);
+}
+
+static void
+formhistory_update_database (gpointer db,
+ const gchar* key,
+ const gchar* value)
+{
+ gchar* sqlcmd;
+ gchar* errmsg;
+ gint success;
+
+ sqlcmd = sqlite3_mprintf ("INSERT INTO forms VALUES"
+ "('%q', '%q', '%q')",
+ NULL, key, value);
+ success = sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg);
+ sqlite3_free (sqlcmd);
+ if (success != SQLITE_OK)
+ {
+ g_printerr (_("Failed to add form value: %s\n"), errmsg);
+ g_free (errmsg);
+ return;
+ }
+}
+
+static gboolean
+formhistory_update_main_hash (gchar* key,
+ gchar* value)
+{
+ guint length;
+ gchar* tmp;
+
+ if (!(value && *value))
+ return FALSE;
+ length = strlen (value);
+ if (length > MAXCHARS || length < MINCHARS)
+ return FALSE;
+
+ formhistory_fixup_value (key);
+ formhistory_fixup_value (value);
+ if ((tmp = g_hash_table_lookup (global_keys, (gpointer)key)))
+ {
+ gchar* rvalue = g_strdup_printf ("\"%s\"",value);
+ gchar* patt = g_regex_escape_string (rvalue, -1);
+ if (!g_regex_match_simple (patt, tmp,
+ G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY))
+ {
+ gchar* new_value = g_strdup_printf ("%s%s,", tmp, rvalue);
+ g_hash_table_insert (global_keys, g_strdup (key), new_value);
+ g_free (rvalue);
+ g_free (patt);
+ }
+ else
+ {
+ g_free (rvalue);
+ g_free (patt);
+ return FALSE;
+ }
+ }
+ else
+ {
+ gchar* new_value = g_strdup_printf ("\"%s\",",value);
+ g_hash_table_replace (global_keys, g_strdup (key), new_value);
+ }
+ return TRUE;
+}
+
+static gboolean
+formhistory_navigation_decision_cb (WebKitWebView* web_view,
+ WebKitWebFrame* web_frame,
+ WebKitNetworkRequest* request,
+ WebKitWebNavigationAction* action,
+ WebKitWebPolicyDecision* decision,
+ MidoriExtension* extension)
+{
+ /* The script returns form data in the form "field_name|,|value|,|field_type".
+ We are handling only input fields with 'text' or 'password' type.
+ The field separator is "|||" */
+ const gchar* script = "function dumpForm (inputs) {"
+ " var out = '';"
+ " for (i=0;iF");
+ gtk_action_set_accel_group (action, acg);
+ gtk_action_connect_accelerator (action);
+
+ if (midori_extension_get_boolean (extension, "always-load"))
+ {
+ midori_browser_foreach (browser,
+ (GtkCallback)formhistory_add_tab_foreach_cb, extension);
+ g_signal_connect (browser, "add-tab",
+ G_CALLBACK (formhistory_add_tab_cb), extension);
+ }
+ g_signal_connect (extension, "deactivate",
+ G_CALLBACK (formhistory_deactivate_cb), browser);
+}
+
+static void
+formhistory_deactivate_tabs (MidoriView* view,
+ MidoriBrowser* browser,
+ MidoriExtension* extension)
+{
+ GtkWidget* web_view = midori_view_get_web_view (view);
+ g_signal_handlers_disconnect_by_func (
+ web_view, formhistory_window_object_cleared_cb, NULL);
+ g_signal_handlers_disconnect_by_func (
+ web_view, formhistory_navigation_decision_cb, extension);
+}
+
+static void
+formhistory_deactivate_cb (MidoriExtension* extension,
+ MidoriBrowser* browser)
+{
+ MidoriApp* app = midori_extension_get_app (extension);
+ sqlite3* db;
+
+ GtkActionGroup* action_group = midori_browser_get_action_group (browser);
+ GtkAction* action;
+
+ g_signal_handlers_disconnect_by_func (
+ browser, formhistory_add_tab_cb, extension);
+ g_signal_handlers_disconnect_by_func (
+ extension, formhistory_deactivate_cb, browser);
+ g_signal_handlers_disconnect_by_func (
+ app, formhistory_app_add_browser_cb, extension);
+ midori_browser_foreach (browser,
+ (GtkCallback)formhistory_deactivate_tabs, extension);
+
+ g_object_set_data (G_OBJECT (browser), "FormHistoryExtension", NULL);
+ action = gtk_action_group_get_action ( action_group, "FormHistoryToggleState");
+ if (action != NULL)
+ {
+ gtk_action_group_remove_action (action_group, action);
+ g_object_unref (action);
+ }
+
+ katze_assign (jsforms, NULL);
+ if (global_keys)
+ g_hash_table_destroy (global_keys);
+
+ if ((db = g_object_get_data (G_OBJECT (extension), "formhistory-db")))
+ sqlite3_close (db);
+}
+
+static int
+formhistory_add_field (gpointer data,
+ int argc,
+ char** argv,
+ char** colname)
+{
+ gint i;
+ gint ncols = 3;
+
+ /* Test whether have the right number of columns */
+ g_return_val_if_fail (argc % ncols == 0, 1);
+
+ for (i = 0; i < (argc - ncols) + 1; i++)
+ {
+ if (argv[i])
+ {
+ if (colname[i] && !g_ascii_strcasecmp (colname[i], "domain")
+ && colname[i + 1] && !g_ascii_strcasecmp (colname[i + 1], "field")
+ && colname[i + 2] && !g_ascii_strcasecmp (colname[i + 2], "value"))
+ {
+ gchar* key = argv[i + 1];
+ formhistory_update_main_hash (g_strdup (key), g_strdup (argv[i + 2]));
+ }
+ }
+ }
+ return 0;
+}
+
+static void
+formhistory_activate_cb (MidoriExtension* extension,
+ MidoriApp* app)
+{
+ const gchar* config_dir;
+ gchar* filename;
+ sqlite3* db;
+ char* errmsg = NULL, *errmsg2 = NULL;
+ KatzeArray* browsers;
+ MidoriBrowser* browser;
+
+ global_keys = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)g_free);
+ if(!jsforms)
+ formhistory_prepare_js ();
+ config_dir = midori_extension_get_config_dir (extension);
+ katze_mkdir_with_parents (config_dir, 0700);
+ filename = g_build_filename (config_dir, "forms.db", NULL);
+ if (sqlite3_open (filename, &db) != SQLITE_OK)
+ {
+ /* If the folder is /, this is a test run, thus no error */
+ if (!g_str_equal (midori_extension_get_config_dir (extension), "/"))
+ g_warning (_("Failed to open database: %s\n"), sqlite3_errmsg (db));
+ sqlite3_close (db);
+ }
+ g_free (filename);
+ if ((sqlite3_exec (db, "CREATE TABLE IF NOT EXISTS "
+ "forms (domain text, field text, value text)",
+ NULL, NULL, &errmsg) == SQLITE_OK)
+ && (sqlite3_exec (db, "SELECT domain, field, value FROM forms ",
+ formhistory_add_field,
+ NULL, &errmsg2) == SQLITE_OK))
+ g_object_set_data (G_OBJECT (extension), "formhistory-db", db);
+ else
+ {
+ if (errmsg)
+ {
+ g_critical (_("Failed to execute database statement: %s\n"), errmsg);
+ sqlite3_free (errmsg);
+ if (errmsg2)
+ {
+ g_critical (_("Failed to execute database statement: %s\n"), errmsg2);
+ sqlite3_free (errmsg2);
+ }
+ }
+ sqlite3_close (db);
+ }
+
+ browsers = katze_object_get_object (app, "browsers");
+ KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
+ formhistory_app_add_browser_cb (app, browser, extension);
+ g_signal_connect (app, "add-browser",
+ G_CALLBACK (formhistory_app_add_browser_cb), extension);
+
+ g_object_unref (browsers);
+}
+
+static void
+formhistory_preferences_response_cb (GtkWidget* dialog,
+ gint response_id,
+ MidoriExtension* extension)
+{
+ GtkWidget* checkbox;
+ gboolean old_state;
+ gboolean new_state;
+ MidoriApp* app;
+ KatzeArray* browsers;
+ MidoriBrowser* browser;
+
+ if (response_id == GTK_RESPONSE_APPLY)
+ {
+ checkbox = g_object_get_data (G_OBJECT (dialog), "always-load-checkbox");
+ new_state = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
+ old_state = midori_extension_get_boolean (extension, "always-load");
+
+ if (old_state != new_state)
+ {
+ midori_extension_set_boolean (extension, "always-load", new_state);
+
+ app = midori_extension_get_app (extension);
+ browsers = katze_object_get_object (app, "browsers");
+ KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
+ {
+ midori_browser_foreach (browser,
+ (GtkCallback)formhistory_deactivate_tabs, extension);
+ g_signal_handlers_disconnect_by_func (
+ browser, formhistory_add_tab_cb, extension);
+
+ if (new_state)
+ {
+ midori_browser_foreach (browser,
+ (GtkCallback)formhistory_add_tab_foreach_cb, extension);
+ g_signal_connect (browser, "add-tab",
+ G_CALLBACK (formhistory_add_tab_cb), extension);
+ }
+ }
+ }
+ }
+ gtk_widget_destroy (dialog);
+}
+
+static void
+formhistory_preferences_cb (MidoriExtension* extension)
+{
+ GtkWidget* dialog;
+ GtkWidget* content_area;
+ GtkWidget* checkbox;
+
+ dialog = gtk_dialog_new ();
+
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_APPLY, GTK_RESPONSE_APPLY);
+
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ checkbox = gtk_check_button_new_with_label (_("only activate form history via hotkey (Ctrl+Shift+F) per tab"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox),
+ !midori_extension_get_boolean (extension, "always-load"));
+ g_object_set_data (G_OBJECT (dialog), "always-load-checkbox", checkbox);
+ gtk_container_add (GTK_CONTAINER (content_area), checkbox);
+
+ g_signal_connect (dialog,
+ "response",
+ G_CALLBACK (formhistory_preferences_response_cb),
+ extension);
+ gtk_widget_show_all (dialog);
+}
+
+static void
+formhistory_toggle_state_cb (GtkAction* action,
+ MidoriBrowser* browser)
+{
+ MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
+ MidoriExtension* extension = g_object_get_data (G_OBJECT (browser), "FormHistoryExtension");
+ GtkWidget* web_view = midori_view_get_web_view (view);
+
+ if (g_signal_handler_find (web_view, G_SIGNAL_MATCH_FUNC,
+ g_signal_lookup ("window-object-cleared", MIDORI_TYPE_VIEW), 0, NULL,
+ formhistory_window_object_cleared_cb, extension))
+ {
+ formhistory_deactivate_tabs (view, browser, extension);
+ } else {
+ formhistory_add_tab_cb (browser, view, extension);
+ }
+}
+
+
+#if G_ENABLE_DEBUG
+/*
+
+
+ autosuggest testcase
+
+
+
+
+ */
+#endif
+
+MidoriExtension*
+extension_init (void)
+{
+ gboolean should_init = TRUE;
+ const gchar* ver;
+ gchar* desc;
+ MidoriExtension* extension;
+
+ if (formhistory_prepare_js ())
+ {
+ ver = "1.0" MIDORI_VERSION_SUFFIX;
+ desc = g_strdup (_("Stores history of entered form data"));
+ }
+ else
+ {
+ desc = g_strdup_printf (_("Not available: %s"),
+ _("Resource files not installed"));
+ ver = NULL;
+ should_init = FALSE;
+ }
+
+ extension = g_object_new (MIDORI_TYPE_EXTENSION,
+ "name", _("Form history filler"),
+ "description", desc,
+ "version", ver,
+ "authors", "Alexander V. Butenko ",
+ NULL);
+
+ g_free (desc);
+
+ if (should_init)
+ {
+ midori_extension_install_boolean (extension, "always-load", TRUE);
+ g_signal_connect (extension, "activate",
+ G_CALLBACK (formhistory_activate_cb), NULL);
+ g_signal_connect (extension, "open-preferences",
+ G_CALLBACK (formhistory_preferences_cb), NULL);
+ }
+
+ return extension;
+}
diff --git a/extensions/formhistory/formhistory-frontend.h b/extensions/formhistory/formhistory-frontend.h
deleted file mode 100644
index 378ae65e..00000000
--- a/extensions/formhistory/formhistory-frontend.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- Copyright (C) 2009-2012 Alexander Butenko
- Copyright (C) 2009-2012 Christian Dywan
-
- 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.
-*/
-
-#ifndef __FORMHISTORY_FRONTEND_H__
-#define __FORMHISTORY_FRONTEND_H__
-#include
-#include
-
-#include "config.h"
-#if HAVE_UNISTD_H
- #include
-#endif
-
-#if WEBKIT_CHECK_VERSION (1, 3, 1)
- #define FORMHISTORY_USE_GDOM 1
-#else
- #define FORMHISTORY_USE_JS 1
-#endif
-#define MAXPASSSIZE 64
-
-typedef struct
-{
- sqlite3* db;
- #ifdef FORMHISTORY_USE_GDOM
- WebKitDOMElement* element;
- int completion_timeout;
- GtkTreeModel* completion_model;
- GtkWidget* treeview;
- GtkWidget* popup;
- gchar* oldkeyword;
- glong selection_index;
- #else
- gchar* jsforms;
- #endif
- gchar* master_password;
- int master_password_canceled;
-} FormHistoryPriv;
-
-typedef struct
-{
- gchar* domain;
- gchar* form_data;
- FormHistoryPriv* priv;
-} FormhistoryPasswordEntry;
-
-FormHistoryPriv*
-formhistory_private_new ();
-
-void
-formhistory_private_destroy (FormHistoryPriv *priv);
-
-gboolean
-formhistory_construct_popup_gui (FormHistoryPriv* priv);
-
-void
-formhistory_setup_suggestions (WebKitWebView* web_view,
- JSContextRef js_context,
- MidoriExtension* extension);
-
-#ifdef FORMHISTORY_USE_GDOM
-void
-formhistory_suggestions_hide_cb (WebKitDOMElement* element,
- WebKitDOMEvent* dom_event,
- FormHistoryPriv* priv);
-#endif
-
-#endif
diff --git a/extensions/formhistory/formhistory-gdom-frontend.c b/extensions/formhistory/formhistory-gdom-frontend.c
deleted file mode 100644
index 76e03617..00000000
--- a/extensions/formhistory/formhistory-gdom-frontend.c
+++ /dev/null
@@ -1,516 +0,0 @@
-/*
- Copyright (C) 2009-2012 Alexander Butenko
- Copyright (C) 2009-2012 Christian Dywan
-
- 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.
-*/
-#include "formhistory-frontend.h"
-#ifdef FORMHISTORY_USE_GDOM
-#define COMPLETION_DELAY 200
-
-FormHistoryPriv*
-formhistory_private_new ()
-{
- FormHistoryPriv* priv;
-
- priv = g_slice_new (FormHistoryPriv);
- priv->oldkeyword = g_strdup ("");
- priv->selection_index = -1;
- return priv;
-}
-
-void
-formhistory_suggestions_hide_cb (WebKitDOMElement* element,
- WebKitDOMEvent* dom_event,
- FormHistoryPriv* priv)
-{
- if (gtk_widget_get_visible (priv->popup))
- gtk_widget_hide (priv->popup);
- priv->selection_index = -1;
-}
-
-static void
-formhistory_suggestion_set (GtkTreePath* path,
- FormHistoryPriv* priv)
-{
- GtkTreeIter iter;
- gchar* value;
-
- if (!gtk_tree_model_get_iter (priv->completion_model, &iter, path))
- return;
-
- gtk_tree_model_get (priv->completion_model, &iter, 0, &value, -1);
- g_object_set (priv->element, "value", value, NULL);
- g_free (value);
-}
-
-static gboolean
-formhistory_suggestion_selected_cb (GtkWidget* treeview,
- GdkEventButton* event,
- FormHistoryPriv* priv)
-
-{
- GtkTreePath* path;
-
- if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview),
- event->x, event->y, &path, NULL, NULL, NULL))
- {
- formhistory_suggestion_set (path, priv);
- formhistory_suggestions_hide_cb (NULL, NULL, priv);
- gtk_tree_path_free (path);
- return TRUE;
- }
- return FALSE;
-}
-static void
-formhistory_suggestion_remove (GtkTreePath* path,
- FormHistoryPriv* priv)
-{
- GtkTreeIter iter;
- gchar* sqlcmd;
- char* errmsg = NULL;
- gchar* name;
- gchar* value;
-
- if (!gtk_tree_model_get_iter (priv->completion_model, &iter, path))
- return;
-
- if (!priv->db)
- return;
-
- gtk_tree_model_get (priv->completion_model, &iter, 0, &value, -1);
- g_object_get (priv->element, "name", &name, NULL);
- gtk_list_store_remove (GTK_LIST_STORE (priv->completion_model), &iter);
-
- sqlcmd = sqlite3_mprintf ("DELETE FROM forms WHERE field = '%q' AND value = '%q'",
- name, value);
- g_free (name);
- g_free (value);
- sqlite3_exec (priv->db, sqlcmd, NULL, NULL, &errmsg);
- sqlite3_free (sqlcmd);
-}
-
-static void
-get_absolute_offset_for_element (WebKitDOMElement* element,
- WebKitDOMDocument* element_document,
- WebKitDOMNodeList* frames,
- glong* x,
- glong* y,
- gboolean ismainframe)
-{
- WebKitDOMElement* offset_parent;
- gint offset_top = 0, offset_left = 0;
- gulong i;
-
- g_object_get (element, "offset-left", &offset_left,
- "offset-top", &offset_top,
- "offset-parent", &offset_parent,
- NULL);
- *x += offset_left;
- *y += offset_top;
- /* To avoid deadlock check only first element of the mainframe parent */
- if (ismainframe == TRUE)
- return;
- if (offset_parent)
- goto finish;
-
- /* Element havent returned any parents. Thats mean or there is no parents or we are inside the frame
- Loop over all frames we have to find frame == element_document which is a root for our element
- and get its offsets */
- for (i = 0; i < webkit_dom_node_list_get_length (frames); i++)
- {
- WebKitDOMDocument *fdoc;
- WebKitDOMNode *frame = webkit_dom_node_list_item (frames, i);
-
- if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (frame))
- fdoc = webkit_dom_html_iframe_element_get_content_document (WEBKIT_DOM_HTML_IFRAME_ELEMENT (frame));
- else
- fdoc = webkit_dom_html_frame_element_get_content_document (WEBKIT_DOM_HTML_FRAME_ELEMENT (frame));
- if (fdoc == element_document)
- {
- offset_parent = WEBKIT_DOM_ELEMENT (frame);
- ismainframe = TRUE;
- /* Add extra 4px to ~cover size of borders */
- *y += 4;
- break;
- }
- }
-finish:
- if (offset_parent)
- get_absolute_offset_for_element (offset_parent, element_document, frames, x, y, ismainframe);
-}
-
-static void
-formhistory_reposition_popup (FormHistoryPriv* priv)
-{
- WebKitDOMDocument* element_document;
- WebKitDOMNodeList* frames;
- GtkWidget* view;
- GdkWindow* window;
- GtkWidget* toplevel;
- gint rx, ry;
- gint wx, wy;
- glong x = 0, y = 0;
- glong height;
-
- view = g_object_get_data (G_OBJECT (priv->element), "webview");
- toplevel = gtk_widget_get_toplevel (view);
- /* Position of a root window */
- window = gtk_widget_get_window (toplevel);
- gdk_window_get_position (window, &rx, &ry);
-
- /* Postion of webview in root window */
- window = gtk_widget_get_window (view);
- gdk_window_get_position (window, &wx, &wy);
-
- /* Position of editbox on the webview */
- frames = g_object_get_data (G_OBJECT (priv->element), "framelist");
- element_document = g_object_get_data (G_OBJECT (priv->element), "doc");
- get_absolute_offset_for_element (priv->element, element_document, frames, &x, &y, FALSE);
- /* Add height as menu should start under editbox, now on top of it */
- g_object_get (priv->element, "client-height", &height, NULL);
- y += height + 1;
- gtk_window_move (GTK_WINDOW (priv->popup), rx + wx + x, ry +wy + y);
-
- /* Window configuration */
- gtk_window_set_screen (GTK_WINDOW (priv->popup), gtk_widget_get_screen (view));
- gtk_window_set_transient_for (GTK_WINDOW (priv->popup), GTK_WINDOW (toplevel));
- gtk_tree_view_columns_autosize (GTK_TREE_VIEW (priv->treeview));
- /* FIXME: Adjust size according to treeview width and some reasonable height */
- gtk_window_resize (GTK_WINDOW (priv->popup), 50, 80);
-}
-
-static gboolean
-formhistory_suggestions_show (FormHistoryPriv* priv)
-{
- GtkListStore* store;
- static sqlite3_stmt* stmt;
- gchar* value, * name;
- const char* sqlcmd;
- gint result;
- gchar* likedvalue;
- int pos = 0;
-
- g_return_val_if_fail (priv->element, FALSE);
-
- g_object_get (priv->element,
- "name", &name,
- "value", &value,
- NULL);
-
- katze_assign (priv->oldkeyword, g_strdup (value));
- if (!priv->popup)
- formhistory_construct_popup_gui (priv);
-
- if (!stmt)
- {
- if (!priv->db)
- goto free_data;
-
- sqlcmd = "SELECT DISTINCT value FROM forms WHERE field = ?1 and value like ?2";
- sqlite3_prepare_v2 (priv->db, sqlcmd, strlen (sqlcmd) + 1, &stmt, NULL);
- }
-
- likedvalue = g_strdup_printf ("%s%%", value);
- sqlite3_bind_text (stmt, 1, name, -1, NULL);
- sqlite3_bind_text (stmt, 2, likedvalue, -1, g_free);
- result = sqlite3_step (stmt);
-
- if (result != SQLITE_ROW)
- {
- if (result == SQLITE_ERROR)
- g_print (_("Failed to select suggestions\n"));
- sqlite3_reset (stmt);
- sqlite3_clear_bindings (stmt);
- formhistory_suggestions_hide_cb (NULL, NULL, priv);
- goto free_data;
- }
-
- store = GTK_LIST_STORE (priv->completion_model);
- gtk_list_store_clear (store);
-
- while (result == SQLITE_ROW)
- {
- const unsigned char* text = sqlite3_column_text (stmt, 0);
- pos++;
- gtk_list_store_insert_with_values (store, NULL, pos, 0, text, -1);
- result = sqlite3_step (stmt);
- }
- sqlite3_reset (stmt);
- sqlite3_clear_bindings (stmt);
-
- if (!gtk_widget_get_visible (priv->popup))
- {
- formhistory_reposition_popup (priv);
- gtk_widget_show_all (priv->popup);
- }
-
-free_data:
- g_free (name);
- g_free (value);
- return FALSE;
-}
-
-static void
-formhistory_editbox_key_pressed_cb (WebKitDOMElement* element,
- WebKitDOMEvent* dom_event,
- FormHistoryPriv* priv)
-{
- glong key;
- GtkTreePath* path;
- gchar* keyword;
- gint matches;
-
- /* FIXME: Priv is still set after module is disabled */
- g_return_if_fail (priv);
- g_return_if_fail (element);
-
- if (priv->completion_timeout > 0)
- g_source_remove (priv->completion_timeout);
-
- katze_object_assign (priv->element, g_object_ref (element));
-
- key = webkit_dom_ui_event_get_key_code (WEBKIT_DOM_UI_EVENT (dom_event));
- switch (key)
- {
- /* ESC key*/
- case 27:
- case 35:
- case 36:
- /* Left key*/
- case 37:
- /* Right key*/
- case 39:
- /* Enter key*/
- case 13:
- if (key == 27)
- g_object_set (element, "value", priv->oldkeyword, NULL);
- formhistory_suggestions_hide_cb (element, dom_event, priv);
- return;
- break;
- /* Del key */
- case 46:
- /* Up key */
- case 38:
- /* Down key */
- case 40:
-
- if (!gtk_widget_get_visible (priv->popup))
- {
- formhistory_suggestions_show (priv);
- return;
- }
- matches = gtk_tree_model_iter_n_children (priv->completion_model, NULL);
- if (key == 38)
- {
- if (priv->selection_index <= 0)
- priv->selection_index = matches - 1;
- else
- priv->selection_index = MAX (priv->selection_index - 1, 0);
- }
- else if (key == 40)
- {
- if (priv->selection_index == matches - 1)
- priv->selection_index = 0;
- else
- priv->selection_index = MIN (priv->selection_index + 1, matches -1);
- }
- if (priv->selection_index == -1)
- {
- /* No element is selected */
- return;
- }
-
- path = gtk_tree_path_new_from_indices (priv->selection_index, -1);
- if (key == 46)
- {
- g_object_set (element, "value", priv->oldkeyword, NULL);
- formhistory_suggestion_remove (path, priv);
- matches--;
- }
-
- if (matches == 0)
- formhistory_suggestions_hide_cb (element, dom_event, priv);
- else
- {
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path, NULL, FALSE);
- formhistory_suggestion_set (path, priv);
- }
- gtk_tree_path_free (path);
- return;
- break;
- /* PgUp, PgDn, Ins */
- case 33:
- case 34:
- case 45:
- /* Shift, Ctrl, Alt, Tab, Caps Lock*/
- case 16:
- case 17:
- case 18:
- case 20:
- case 9:
- return;
- break;
- }
-
- g_object_get (element, "value", &keyword, NULL);
- if (!(keyword && *keyword && *keyword != ' '))
- {
- formhistory_suggestions_hide_cb (element, dom_event, priv);
- goto free_data;
- }
-
- /* If the same keyword is submitted there's no need to regenerate suggestions */
- if (gtk_widget_get_visible (priv->popup) &&
- !g_strcmp0 (keyword, priv->oldkeyword))
- goto free_data;
- priv->completion_timeout = g_timeout_add (COMPLETION_DELAY,
- (GSourceFunc)formhistory_suggestions_show, priv);
-free_data:
- g_free (keyword);
-}
-
-static void
-formhistory_DOMContentLoaded_cb (WebKitDOMElement* window,
- WebKitDOMEvent* dom_event,
- FormHistoryPriv* priv)
-{
- gulong i;
- WebKitDOMDocument* doc;
- WebKitDOMNodeList* inputs;
- WebKitDOMNodeList* frames;
- GtkWidget* web_view;
-
- if (WEBKIT_DOM_IS_DOCUMENT (window))
- doc = WEBKIT_DOM_DOCUMENT (window);
- else
- doc = webkit_dom_dom_window_get_document (WEBKIT_DOM_DOM_WINDOW (window));
- inputs = webkit_dom_document_query_selector_all (doc, "input[type='text']", NULL);
- frames = g_object_get_data (G_OBJECT (window), "framelist");
- web_view = g_object_get_data (G_OBJECT (window), "webview");
-
- for (i = 0; i < webkit_dom_node_list_get_length (inputs); i++)
- {
- WebKitDOMNode* element = webkit_dom_node_list_item (inputs, i);
- #if WEBKIT_CHECK_VERSION (1, 6, 1)
- gchar* autocomplete = webkit_dom_html_input_element_get_autocomplete (
- WEBKIT_DOM_HTML_INPUT_ELEMENT (element));
- gboolean off = !g_strcmp0 (autocomplete, "off");
- g_free (autocomplete);
- if (off)
- continue;
- #endif
-
- g_object_set_data (G_OBJECT (element), "doc", doc);
- g_object_set_data (G_OBJECT (element), "webview", web_view);
- g_object_set_data (G_OBJECT (element), "framelist", frames);
- /* Add dblclick? */
- webkit_dom_event_target_add_event_listener (
- WEBKIT_DOM_EVENT_TARGET (element), "keyup",
- G_CALLBACK (formhistory_editbox_key_pressed_cb), false,
- priv);
- webkit_dom_event_target_add_event_listener (
- WEBKIT_DOM_EVENT_TARGET (element), "blur",
- G_CALLBACK (formhistory_suggestions_hide_cb), false,
- priv);
- }
-}
-
-void
-formhistory_setup_suggestions (WebKitWebView* web_view,
- JSContextRef js_context,
- MidoriExtension* extension)
-{
- WebKitDOMDocument* doc;
- WebKitDOMNodeList* frames;
- gulong i;
-
- FormHistoryPriv* priv = g_object_get_data (G_OBJECT (extension), "priv");
- doc = webkit_web_view_get_dom_document (web_view);
- frames = webkit_dom_document_query_selector_all (doc, "iframe, frame", NULL);
- g_object_set_data (G_OBJECT (doc), "framelist", frames);
- g_object_set_data (G_OBJECT (doc), "webview", web_view);
- /* Connect to DOMContentLoaded of the main frame */
- webkit_dom_event_target_add_event_listener(
- WEBKIT_DOM_EVENT_TARGET (doc), "DOMContentLoaded",
- G_CALLBACK (formhistory_DOMContentLoaded_cb), false,
- priv);
-
- /* Connect to DOMContentLoaded of frames */
- for (i = 0; i < webkit_dom_node_list_get_length (frames); i++)
- {
- WebKitDOMDOMWindow* framewin;
-
- WebKitDOMNode* frame = webkit_dom_node_list_item (frames, i);
- if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (frame))
- framewin = webkit_dom_html_iframe_element_get_content_window (WEBKIT_DOM_HTML_IFRAME_ELEMENT (frame));
- else
- framewin = webkit_dom_html_frame_element_get_content_window (WEBKIT_DOM_HTML_FRAME_ELEMENT (frame));
- g_object_set_data (G_OBJECT (framewin), "framelist", frames);
- g_object_set_data (G_OBJECT (framewin), "webview", (GtkWidget*)web_view);
- webkit_dom_event_target_add_event_listener (
- WEBKIT_DOM_EVENT_TARGET (framewin), "DOMContentLoaded",
- G_CALLBACK (formhistory_DOMContentLoaded_cb), false,
- priv);
- }
- formhistory_suggestions_hide_cb (NULL, NULL, priv);
-}
-
-void
-formhistory_private_destroy (FormHistoryPriv *priv)
-{
- if (priv->db)
- {
- sqlite3_close (priv->db);
- priv->db = NULL;
- }
- katze_assign (priv->oldkeyword, NULL);
- gtk_widget_destroy (priv->popup);
- priv->popup = NULL;
- katze_object_assign (priv->element, NULL);
- g_slice_free (FormHistoryPriv, priv);
-}
-
-gboolean
-formhistory_construct_popup_gui (FormHistoryPriv* priv)
-{
- GtkTreeModel* model = NULL;
- GtkWidget* popup;
- GtkWidget* popup_frame;
- GtkWidget* scrolled;
- GtkWidget* treeview;
- GtkCellRenderer* renderer;
- GtkTreeViewColumn* column;
-
- model = (GtkTreeModel*) gtk_list_store_new (1, G_TYPE_STRING);
- priv->completion_model = model;
- popup = gtk_window_new (GTK_WINDOW_POPUP);
- gtk_window_set_type_hint (GTK_WINDOW (popup), GDK_WINDOW_TYPE_HINT_COMBO);
- popup_frame = gtk_frame_new (NULL);
- gtk_frame_set_shadow_type (GTK_FRAME (popup_frame), GTK_SHADOW_ETCHED_IN);
- gtk_container_add (GTK_CONTAINER (popup), popup_frame);
- scrolled = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
- "hscrollbar-policy", GTK_POLICY_NEVER,
- "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL);
- gtk_container_add (GTK_CONTAINER (popup_frame), scrolled);
- treeview = gtk_tree_view_new_with_model (model);
- priv->treeview = treeview;
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
- gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (treeview), TRUE);
- gtk_container_add (GTK_CONTAINER (scrolled), treeview);
- gtk_widget_set_size_request (gtk_scrolled_window_get_vscrollbar (
- GTK_SCROLLED_WINDOW (scrolled)), -1, 0);
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("suggestions", renderer, "text", 0, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
- priv->popup = popup;
-
- g_signal_connect (treeview, "button-press-event",
- G_CALLBACK (formhistory_suggestion_selected_cb), priv);
- return TRUE;
-}
-#endif
diff --git a/extensions/formhistory/formhistory-js-frontend.c b/extensions/formhistory/formhistory-js-frontend.c
deleted file mode 100644
index ec64d7ac..00000000
--- a/extensions/formhistory/formhistory-js-frontend.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- Copyright (C) 2009-2012 Alexander Butenko
- Copyright (C) 2009-2012 Christian Dywan
-
- 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.
-*/
-#include "formhistory-frontend.h"
-#ifdef FORMHISTORY_USE_JS
-
-FormHistoryPriv*
-formhistory_private_new ()
-{
- FormHistoryPriv* priv;
-
- priv = g_slice_new (FormHistoryPriv);
- return priv;
-}
-
-gboolean
-formhistory_construct_popup_gui (FormHistoryPriv* priv)
-{
- gchar* autosuggest;
- gchar* style;
- guint i;
- gchar* file;
-
- file = midori_app_find_res_filename ("autosuggestcontrol.js");
- if (!g_file_get_contents (file, &autosuggest, NULL, NULL))
- {
- g_free (file);
- return FALSE;
- }
- g_strchomp (autosuggest);
-
- katze_assign (file, midori_app_find_res_filename ("autosuggestcontrol.css"));
- if (!g_file_get_contents (file, &style, NULL, NULL))
- {
- g_free (file);
- return FALSE;
- }
- g_strchomp (style);
- g_free (file);
-
- i = 0;
- while (style[i])
- {
- if (style[i] == '\n')
- style[i] = ' ';
- i++;
- }
-
- priv->jsforms = g_strdup_printf (
- "%s"
- "window.addEventListener ('DOMContentLoaded',"
- "function () {"
- " if (document.getElementById('formhistory'))"
- " return;"
- " if (!initSuggestions ())"
- " return;"
- " var mystyle = document.createElement('style');"
- " mystyle.setAttribute('type', 'text/css');"
- " mystyle.setAttribute('id', 'formhistory');"
- " mystyle.appendChild(document.createTextNode('%s'));"
- " var head = document.getElementsByTagName('head')[0];"
- " if (head) head.appendChild(mystyle);"
- "}, true);",
- autosuggest,
- style);
- g_strstrip (priv->jsforms);
- g_free (style);
- g_free (autosuggest);
- return TRUE;
-}
-
-void
-formhistory_setup_suggestions (WebKitWebView* web_view,
- JSContextRef js_context,
- MidoriExtension* extension)
-{
- GString* suggestions;
- FormHistoryPriv* priv;
- static sqlite3_stmt* stmt;
- const char* sqlcmd;
- const unsigned char* key;
- const unsigned char* value;
-
- gint result, pos;
-
- priv = g_object_get_data (G_OBJECT (extension), "priv");
- if (!priv->db)
- return;
-
- if (!stmt)
- {
- sqlcmd = "SELECT DISTINCT group_concat(value,'\",\"'), field FROM forms \
- GROUP BY field ORDER BY field";
- sqlite3_prepare_v2 (priv->db, sqlcmd, strlen (sqlcmd) + 1, &stmt, NULL);
- }
- result = sqlite3_step (stmt);
- if (result != SQLITE_ROW)
- {
- if (result == SQLITE_ERROR)
- g_print (_("Failed to select suggestions\n"));
- sqlite3_reset (stmt);
- return;
- }
- suggestions = g_string_new (
- "function FormSuggestions(eid) { "
- "arr = new Array();");
-
- while (result == SQLITE_ROW)
- {
- pos++;
- value = sqlite3_column_text (stmt, 0);
- key = sqlite3_column_text (stmt, 1);
- if (value)
- {
- g_string_append_printf (suggestions, " arr[\"%s\"] = [\"%s\"]; ",
- (gchar*)key, (gchar*)value);
- }
- result = sqlite3_step (stmt);
- }
- g_string_append (suggestions, "this.suggestions = arr[eid]; }");
- g_string_append (suggestions, priv->jsforms);
- sokoke_js_script_eval (js_context, suggestions->str, NULL);
- g_string_free (suggestions, TRUE);
-}
-
-void
-formhistory_private_destroy (FormHistoryPriv *priv)
-{
- if (priv->db)
- {
- sqlite3_close (priv->db);
- priv->db = NULL;
- }
- katze_assign (priv->jsforms, NULL);
- g_slice_free (FormHistoryPriv, priv);
-}
-#endif
diff --git a/extensions/formhistory/formhistory.c b/extensions/formhistory/formhistory.c
deleted file mode 100644
index fca8aada..00000000
--- a/extensions/formhistory/formhistory.c
+++ /dev/null
@@ -1,681 +0,0 @@
-/*
- Copyright (C) 2009-2012 Alexander Butenko
- Copyright (C) 2009-2012 Christian Dywan
-
- 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.
-*/
-#define MAXCHARS 60
-#define MINCHARS 2
-#define GTK_RESPONSE_IGNORE 99
-#include "formhistory-frontend.h"
-
-static void
-formhistory_toggle_state_cb (GtkAction* action,
- MidoriBrowser* browser);
-
-static void
-formhistory_update_database (gpointer db,
- const gchar* host,
- const gchar* key,
- const gchar* value)
-{
- gchar* sqlcmd;
- gchar* errmsg;
- gint success;
-
- if (!(value && *value))
- return;
-
- sqlcmd = sqlite3_mprintf ("INSERT INTO forms VALUES"
- "('%q', '%q', '%q')",
- host, key, value);
- success = sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg);
- sqlite3_free (sqlcmd);
- if (success != SQLITE_OK)
- {
- g_printerr (_("Failed to add form value: %s\n"), errmsg);
- g_free (errmsg);
- return;
- }
-}
-
-static gchar*
-formhistory_get_login_data (gpointer db,
- const gchar* domain)
-{
- static sqlite3_stmt* stmt;
- const char* sqlcmd;
- gint result;
- gchar* value = NULL;
-
- if (!stmt)
- {
- sqlcmd = "SELECT value FROM forms WHERE domain = ?1 and field = 'MidoriPasswordManager' limit 1";
- sqlite3_prepare_v2 (db, sqlcmd, strlen (sqlcmd) + 1, &stmt, NULL);
- }
- sqlite3_bind_text (stmt, 1, domain, -1, NULL);
- result = sqlite3_step (stmt);
- if (result == SQLITE_ROW)
- value = g_strdup ((gchar*)sqlite3_column_text (stmt, 0));
- sqlite3_reset (stmt);
- sqlite3_clear_bindings (stmt);
- return value;
-}
-
-static gboolean
-formhistory_check_master_password (GtkWidget* parent,
- FormHistoryPriv* priv)
-{
- GtkWidget* dialog;
- GtkWidget* content_area;
- GtkWidget* hbox;
- GtkWidget* image;
- GtkWidget* label;
- GtkWidget* entry;
- const gchar* title;
- static int alive;
- gboolean ret = FALSE;
-
- /* Password is set */
- if (priv->master_password && *priv->master_password)
- return TRUE;
-
- /* Other prompt is active */
- if (alive == 1)
- return FALSE;
-
- /* Prompt was cancelled */
- if (priv->master_password_canceled == 1)
- return FALSE;
-
- alive = 1;
- title = _("Form history");
- dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent),
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK, GTK_RESPONSE_OK,
- NULL);
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_DIALOG_AUTHENTICATION);
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- gtk_container_set_border_width (GTK_CONTAINER (content_area), 5);
-
- hbox = gtk_hbox_new (FALSE, 8);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
- image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
- GTK_ICON_SIZE_DIALOG);
- gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
-
- label = gtk_label_new (_("Master password required\n"
- "to open password database"));
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- gtk_container_add (GTK_CONTAINER (content_area), hbox);
-
- entry = gtk_entry_new ();
- g_object_set (entry, "truncate-multiline", TRUE, NULL);
- gtk_entry_set_visibility(GTK_ENTRY (entry),FALSE);
- gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
- gtk_container_add (GTK_CONTAINER (content_area), entry);
-
- gtk_widget_show_all (entry);
- gtk_widget_show_all (hbox);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
- {
- /* FIXME: add password verification */
- katze_assign (priv->master_password,
- g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))));
- ret = TRUE;
- }
- else
- priv->master_password_canceled = 1;
-
- gtk_widget_destroy (dialog);
- alive = 0;
-
- return ret;
-}
-
-static gchar*
-formhistory_encrypt (const gchar* data,
- const gchar* password)
-{
- /* TODO: Implement persistent storage/ keyring support */
- return NULL;
-}
-
-static void
-formhistory_remember_password_response (GtkWidget* infobar,
- gint response_id,
- FormhistoryPasswordEntry* entry)
-{
- gchar* encrypted_form;
-
- if (response_id == GTK_RESPONSE_IGNORE)
- goto cleanup;
-
- if (formhistory_check_master_password (NULL, entry->priv))
- {
- if (response_id != GTK_RESPONSE_ACCEPT)
- katze_assign (entry->form_data, g_strdup ("never"));
-
- if ((encrypted_form = formhistory_encrypt (entry->form_data,
- entry->priv->master_password)))
- formhistory_update_database (entry->priv->db, entry->domain, "MidoriPasswordManager", encrypted_form);
- g_free (encrypted_form);
- }
-
-cleanup:
- g_free (entry->form_data);
- g_free (entry->domain);
- g_slice_free (FormhistoryPasswordEntry, entry);
- gtk_widget_destroy (infobar);
-}
-
-static gboolean
-formhistory_navigation_decision_cb (WebKitWebView* web_view,
- WebKitWebFrame* web_frame,
- WebKitNetworkRequest* request,
- WebKitWebNavigationAction* action,
- WebKitWebPolicyDecision* decision,
- MidoriExtension* extension)
-{
- FormHistoryPriv* priv;
- JSContextRef js_context;
- gchar* value;
-
- /* The script returns form data in the form "field_name|,|value|,|field_type".
- We are handling only input fields with 'text' or 'password' type.
- The field separator is "|||" */
- const gchar* script = "function dumpForm (inputs) {"
- " var out = '';"
- " for (var i = 0; i < inputs.length; i++) {"
- " if (inputs[i].getAttribute('autocomplete') == 'off' && "
- " inputs[i].type == 'text')"
- " continue;"
- " if (inputs[i].value && (inputs[i].type == 'text' || inputs[i].type == 'password')) {"
- " var ename = inputs[i].getAttribute('name');"
- " var eid = inputs[i].getAttribute('id');"
- " if (!eid && ename)"
- " eid=ename;"
- " out += eid+'|,|'+inputs[i].value +'|,|'+inputs[i].type +'|||';"
- " }"
- " }"
- " return out;"
- "}"
- "dumpForm (document.getElementsByTagName('input'))";
-
- if (webkit_web_navigation_action_get_reason (action) != WEBKIT_WEB_NAVIGATION_REASON_FORM_SUBMITTED)
- return FALSE;
-
- priv = g_object_get_data (G_OBJECT (extension), "priv");
- js_context = webkit_web_frame_get_global_context (web_frame);
- value = sokoke_js_script_eval (js_context, script, NULL);
-
-#ifdef FORMHISTORY_USE_GDOM
- formhistory_suggestions_hide_cb (NULL, NULL, priv);
-#endif
- if (value && *value)
- {
- gchar** inputs = g_strsplit (value, "|||", 0);
- guint i = 0;
- while (inputs[i] != NULL)
- {
- gchar** parts = g_strsplit (inputs[i], "|,|", 3);
- if (parts && parts[0] && parts[1] && parts[2])
- {
- if (strcmp (parts[2], "password"))
- formhistory_update_database (priv->db, NULL, parts[0], parts[1]);
- #if WEBKIT_CHECK_VERSION (1, 3, 8)
- else
- {
- gchar* data;
- gchar* domain;
- #if 0
- FormhistoryPasswordEntry* entry;
- #endif
-
- domain = midori_uri_parse_hostname (webkit_web_frame_get_uri (web_frame), NULL);
- data = formhistory_get_login_data (priv->db, domain);
- if (data)
- {
- g_free (data);
- g_free (domain);
- break;
- }
- #if 0
- entry = g_slice_new (FormhistoryPasswordEntry);
- /* Domain and form data are freed from infopanel callback*/
- entry->form_data = g_strdup (value);
- entry->domain = domain;
- entry->priv = priv;
- g_object_set_data (G_OBJECT (web_view), "FormHistoryPasswordEntry", entry);
- #endif
- }
- #endif
- }
- g_strfreev (parts);
- i++;
- }
- g_strfreev (inputs);
- g_free (value);
- }
- return FALSE;
-}
-
-static void
-formhistory_window_object_cleared_cb (WebKitWebView* web_view,
- WebKitWebFrame* web_frame,
- JSContextRef js_context,
- JSObjectRef js_window,
- MidoriExtension* extension)
-{
- const gchar* page_uri;
- FormhistoryPasswordEntry* entry;
- GtkWidget* view;
-
- page_uri = webkit_web_frame_get_uri (web_frame);
- if (!page_uri)
- return;
-
- if (!midori_uri_is_http (page_uri) && !g_str_has_prefix (page_uri, "file"))
- return;
-
- formhistory_setup_suggestions (web_view, js_context, extension);
-
- #if WEBKIT_CHECK_VERSION (1, 3, 8)
- entry = g_object_get_data (G_OBJECT (web_view), "FormHistoryPasswordEntry");
- if (entry)
- {
- const gchar* message = _("Remember password on this page?");
- view = midori_browser_get_current_tab (midori_app_get_browser (
- midori_extension_get_app (extension)));
- midori_view_add_info_bar (MIDORI_VIEW (view), GTK_MESSAGE_QUESTION, message,
- G_CALLBACK (formhistory_remember_password_response), entry,
- _("Remember"), GTK_RESPONSE_ACCEPT,
- _("Not now"), GTK_RESPONSE_IGNORE,
- _("Never for this page"), GTK_RESPONSE_CANCEL, NULL);
- g_object_set_data (G_OBJECT (web_view), "FormHistoryPasswordEntry", NULL);
- }
- #endif
-}
-
-#if WEBKIT_CHECK_VERSION (1, 3, 8)
-static gchar*
-formhistory_decrypt (const gchar* data,
- const gchar* password)
-{
- /* TODO: Implement persistent storage/ keyring support */
- return NULL;
-}
-
-static void
-formhistory_fill_login_data (JSContextRef js_context,
- FormHistoryPriv* priv,
- const gchar* data)
-{
- gchar* decrypted_data = NULL;
- guint i = 0;
- GString *script;
- gchar** inputs;
-
- /* Handle case that user dont want to store password */
- if (!strncmp (data, "never", 5))
- return;
-
- #if 0
- if (!formhistory_check_master_password (NULL, priv))
- return;
- #endif
-
- if (!(decrypted_data = formhistory_decrypt (data, priv->master_password)))
- return;
-
- script = g_string_new ("");
- inputs = g_strsplit (decrypted_data, "|||", 0);
- while (inputs[i] != NULL)
- {
- gchar** parts = g_strsplit (inputs[i], "|,|", 3);
- if (parts && parts[0] && parts[1] && parts[2])
- {
- g_string_append_printf (script, "node = null;"
- "node = document.getElementById ('%s');"
- "if (!node) { node = document.getElementsByName ('%s')[0]; }"
- "if (node && node.type == '%s') { node.value = '%s'; }",
- parts[0], parts[0], parts[2], parts[1]);
- }
- g_strfreev (parts);
- i++;
- }
- g_free (decrypted_data);
- g_strfreev (inputs);
- g_free (sokoke_js_script_eval (js_context, script->str, NULL));
- g_string_free (script, TRUE);
-}
-
-static void
-formhistory_frame_loaded_cb (WebKitWebView* web_view,
- WebKitWebFrame* web_frame,
- MidoriExtension* extension)
-{
- const gchar* page_uri;
- const gchar* count_request;
- FormHistoryPriv* priv;
- JSContextRef js_context;
- gchar* data;
- gchar* domain;
- gchar* count;
-
- page_uri = webkit_web_frame_get_uri (web_frame);
- if (!page_uri)
- return;
-
- count_request = "document.querySelectorAll('input[type=password]').length";
- js_context = webkit_web_frame_get_global_context (web_frame);
- count = sokoke_js_script_eval (js_context, count_request, NULL);
- if (count && count[0] == '0')
- {
- g_free (count);
- return;
- }
- g_free (count);
-
- priv = g_object_get_data (G_OBJECT (extension), "priv");
- domain = midori_uri_parse_hostname (webkit_web_frame_get_uri (web_frame), NULL);
- data = formhistory_get_login_data (priv->db, domain);
- g_free (domain);
-
- if (!data)
- return;
- formhistory_fill_login_data (js_context, priv, data);
- g_free (data);
-}
-#endif
-
-static void
-formhistory_deactivate_cb (MidoriExtension* extension,
- MidoriBrowser* browser);
-
-static void
-formhistory_add_tab_cb (MidoriBrowser* browser,
- MidoriView* view,
- MidoriExtension* extension)
-{
- GtkWidget* web_view = midori_view_get_web_view (view);
-
- g_signal_connect (web_view, "window-object-cleared",
- G_CALLBACK (formhistory_window_object_cleared_cb), extension);
- g_signal_connect (web_view, "navigation-policy-decision-requested",
- G_CALLBACK (formhistory_navigation_decision_cb), extension);
-
- #if WEBKIT_CHECK_VERSION (1, 3, 8)
- g_signal_connect (web_view, "onload-event",
- G_CALLBACK (formhistory_frame_loaded_cb), extension);
- #endif
-}
-
-static void
-formhistory_add_tab_foreach_cb (MidoriView* view,
- MidoriExtension* extension)
-{
- formhistory_add_tab_cb (NULL, view, extension);
-}
-
-static void
-formhistory_app_add_browser_cb (MidoriApp* app,
- MidoriBrowser* browser,
- MidoriExtension* extension)
-{
-
- GtkAccelGroup* acg = gtk_accel_group_new ();
- GtkActionGroup* action_group = midori_browser_get_action_group (browser);
- GtkAction* action = gtk_action_new ("FormHistoryToggleState",
- _("Toggle form history state"),
- _("Activate or deactivate form history for the current tab."), NULL);
- gtk_window_add_accel_group (GTK_WINDOW (browser), acg);
-
- g_object_set_data (G_OBJECT (browser), "FormHistoryExtension", extension);
-
- g_signal_connect (action, "activate",
- G_CALLBACK (formhistory_toggle_state_cb), browser);
-
- gtk_action_group_add_action_with_accel (action_group, action, "F");
- gtk_action_set_accel_group (action, acg);
- gtk_action_connect_accelerator (action);
-
- if (midori_extension_get_boolean (extension, "always-load"))
- {
- midori_browser_foreach (browser,
- (GtkCallback)formhistory_add_tab_foreach_cb, extension);
- g_signal_connect (browser, "add-tab",
- G_CALLBACK (formhistory_add_tab_cb), extension);
- }
- g_signal_connect (extension, "deactivate",
- G_CALLBACK (formhistory_deactivate_cb), browser);
-}
-
-static void
-formhistory_deactivate_tab (MidoriView* view,
- MidoriExtension* extension)
-{
- GtkWidget* web_view = midori_view_get_web_view (view);
-
- g_signal_handlers_disconnect_by_func (
- web_view, formhistory_window_object_cleared_cb, extension);
- g_signal_handlers_disconnect_by_func (
- web_view, formhistory_navigation_decision_cb, extension);
- #if WEBKIT_CHECK_VERSION (1, 3, 8)
- g_signal_handlers_disconnect_by_func (
- web_view, formhistory_frame_loaded_cb, extension);
- #endif
-}
-
-static void
-formhistory_deactivate_cb (MidoriExtension* extension,
- MidoriBrowser* browser)
-{
- MidoriApp* app = midori_extension_get_app (extension);
- FormHistoryPriv* priv = g_object_get_data (G_OBJECT (extension), "priv");
-
- GtkActionGroup* action_group = midori_browser_get_action_group (browser);
- GtkAction* action;
-
- g_signal_handlers_disconnect_by_func (
- browser, formhistory_add_tab_cb, extension);
- g_signal_handlers_disconnect_by_func (
- extension, formhistory_deactivate_cb, browser);
- g_signal_handlers_disconnect_by_func (
- app, formhistory_app_add_browser_cb, extension);
- midori_browser_foreach (browser,
- (GtkCallback)formhistory_deactivate_tab, extension);
-
- g_object_set_data (G_OBJECT (browser), "FormHistoryExtension", NULL);
- action = gtk_action_group_get_action (action_group, "FormHistoryToggleState");
- if (action != NULL)
- {
- gtk_action_group_remove_action (action_group, action);
- g_object_unref (action);
- }
-
- formhistory_private_destroy (priv);
-}
-
-static void
-formhistory_activate_cb (MidoriExtension* extension,
- MidoriApp* app)
-{
- const gchar* config_dir;
- gchar* filename;
- sqlite3* db;
- char* errmsg = NULL, *errmsg2 = NULL;
- KatzeArray* browsers;
- MidoriBrowser* browser;
- FormHistoryPriv* priv;
-
- priv = formhistory_private_new ();
- priv->master_password = NULL;
- priv->master_password_canceled = 0;
- formhistory_construct_popup_gui (priv);
-
- config_dir = midori_extension_get_config_dir (extension);
- if (config_dir != NULL)
- katze_mkdir_with_parents (config_dir, 0700);
- filename = g_build_filename (config_dir, "forms.db", NULL);
- if (sqlite3_open (filename, &db) != SQLITE_OK)
- {
- if (config_dir != NULL)
- g_warning (_("Failed to open database: %s\n"), sqlite3_errmsg (db));
- sqlite3_close (db);
- }
- g_free (filename);
- if ((sqlite3_exec (db, "CREATE TABLE IF NOT EXISTS "
- "forms (domain text, field text, value text)",
- NULL, NULL, &errmsg) == SQLITE_OK))
- {
- sqlite3_exec (db,
- /* "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY" */
- "PRAGMA count_changes = OFF; PRAGMA journal_mode = TRUNCATE;",
- NULL, NULL, &errmsg);
- priv->db = db;
- }
- else
- {
- if (errmsg)
- {
- g_critical (_("Failed to execute database statement: %s\n"), errmsg);
- sqlite3_free (errmsg);
- if (errmsg2)
- {
- g_critical (_("Failed to execute database statement: %s\n"), errmsg2);
- sqlite3_free (errmsg2);
- }
- }
- sqlite3_close (db);
- }
-
- g_object_set_data (G_OBJECT (extension), "priv", priv);
- browsers = katze_object_get_object (app, "browsers");
- KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
- formhistory_app_add_browser_cb (app, browser, extension);
- g_signal_connect (app, "add-browser",
- G_CALLBACK (formhistory_app_add_browser_cb), extension);
-
- g_object_unref (browsers);
-}
-
-static void
-formhistory_preferences_response_cb (GtkWidget* dialog,
- gint response_id,
- MidoriExtension* extension)
-{
- GtkWidget* checkbox;
- gboolean old_state;
- gboolean new_state;
- MidoriApp* app;
- KatzeArray* browsers;
- MidoriBrowser* browser;
-
- if (response_id == GTK_RESPONSE_APPLY)
- {
- checkbox = g_object_get_data (G_OBJECT (dialog), "always-load-checkbox");
- new_state = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
- old_state = midori_extension_get_boolean (extension, "always-load");
-
- if (old_state != new_state)
- {
- midori_extension_set_boolean (extension, "always-load", new_state);
-
- app = midori_extension_get_app (extension);
- browsers = katze_object_get_object (app, "browsers");
- KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
- {
- midori_browser_foreach (browser,
- (GtkCallback)formhistory_deactivate_tab, extension);
- g_signal_handlers_disconnect_by_func (
- browser, formhistory_add_tab_cb, extension);
-
- if (new_state)
- {
- midori_browser_foreach (browser,
- (GtkCallback)formhistory_add_tab_foreach_cb, extension);
- g_signal_connect (browser, "add-tab",
- G_CALLBACK (formhistory_add_tab_cb), extension);
- }
- }
- }
- }
- gtk_widget_destroy (dialog);
-}
-
-static void
-formhistory_preferences_cb (MidoriExtension* extension)
-{
- GtkWidget* dialog;
- GtkWidget* content_area;
- GtkWidget* checkbox;
-
- dialog = gtk_dialog_new ();
-
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
- gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_APPLY, GTK_RESPONSE_APPLY);
-
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- checkbox = gtk_check_button_new_with_label (_("Only activate form history via hotkey (Ctrl+Shift+F) per tab"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox),
- !midori_extension_get_boolean (extension, "always-load"));
- g_object_set_data (G_OBJECT (dialog), "always-load-checkbox", checkbox);
- gtk_container_add (GTK_CONTAINER (content_area), checkbox);
- /* FIXME: Add pref to disable password manager */
-
- g_signal_connect (dialog,
- "response",
- G_CALLBACK (formhistory_preferences_response_cb),
- extension);
- gtk_widget_show_all (dialog);
-}
-
-static void
-formhistory_toggle_state_cb (GtkAction* action,
- MidoriBrowser* browser)
-{
- MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
- MidoriExtension* extension = g_object_get_data (G_OBJECT (browser), "FormHistoryExtension");
- GtkWidget* web_view = midori_view_get_web_view (view);
-
- if (g_signal_handler_find (web_view, G_SIGNAL_MATCH_FUNC,
- g_signal_lookup ("window-object-cleared", MIDORI_TYPE_VIEW), 0, NULL,
- formhistory_window_object_cleared_cb, extension))
- {
- formhistory_deactivate_tab (view, extension);
- }
- else
- formhistory_add_tab_cb (browser, view, extension);
-}
-
-MidoriExtension*
-extension_init (void)
-{
- MidoriExtension* extension;
-
-
- extension = g_object_new (MIDORI_TYPE_EXTENSION,
- "name", _("Form history filler"),
- "description", _("Stores history of entered form data"),
- "version", "2.0" MIDORI_VERSION_SUFFIX,
- "authors", "Alexander V. Butenko ",
- NULL);
-
- midori_extension_install_boolean (extension, "always-load", TRUE);
- g_signal_connect (extension, "activate",
- G_CALLBACK (formhistory_activate_cb), NULL);
- g_signal_connect (extension, "open-preferences",
- G_CALLBACK (formhistory_preferences_cb), NULL);
-
- return extension;
-}
diff --git a/extensions/history-list.vala b/extensions/history-list.vala
index 499bb740..44af649f 100644
--- a/extensions/history-list.vala
+++ b/extensions/history-list.vala
@@ -462,7 +462,7 @@ namespace HistoryList {
tab_added (browser, tab);
browser.add_tab.connect (tab_added);
browser.remove_tab.connect (tab_removed);
- browser.switch_tab.connect (this.tab_changed);
+ browser.notify["tab"].connect (this.tab_changed);
}
void browser_removed (Midori.Browser browser) {
@@ -491,7 +491,7 @@ namespace HistoryList {
browser.add_tab.disconnect (tab_added);
browser.remove_tab.disconnect (tab_removed);
- browser.switch_tab.disconnect (this.tab_changed);
+ browser.notify["tab"].disconnect (this.tab_changed);
}
void tab_added (Midori.Browser browser, Midori.View view) {
@@ -520,18 +520,21 @@ namespace HistoryList {
}
}
- void tab_changed (Midori.View? old_view, Midori.View? new_view) {
+ void tab_changed (GLib.Object window, GLib.ParamSpec pspec) {
if(this.ignoreNextChange) {
this.ignoreNextChange = false;
} else {
- Midori.Browser? browser = Midori.Browser.get_for_widget (new_view);
- Midori.View? last_view
- = browser.get_data ("history-list-last-change");
+ Midori.Browser browser = window as Midori.Browser;
+ Midori.View view = null;
+ Midori.View last_view = null;
+ browser.get ("tab", ref view);
+
+ last_view = browser.get_data ("history-list-last-change");
if (last_view != null) {
this.tab_list_resort (browser, last_view);
}
- browser.set_data ("history-list-last-change", new_view);
+ browser.set_data ("history-list-last-change", view);
}
}
diff --git a/extensions/shortcuts.c b/extensions/shortcuts.c
index b4cb0427..552f1694 100644
--- a/extensions/shortcuts.c
+++ b/extensions/shortcuts.c
@@ -180,6 +180,8 @@ shortcuts_get_preferences_dialog (MidoriExtension* extension)
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
#endif
NULL);
+ g_signal_connect (dialog, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &dialog);
gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_PROPERTIES);
sokoke_widget_get_text_size (dialog, "M", &width, &height);
gtk_window_set_default_size (GTK_WINDOW (dialog), width * 52, height * 24);
diff --git a/extensions/statusbar-features.c b/extensions/statusbar-features.c
index e2210d7f..76ca2d3b 100644
--- a/extensions/statusbar-features.c
+++ b/extensions/statusbar-features.c
@@ -66,14 +66,11 @@ statusbar_features_browser_notify_tab_cb (MidoriBrowser* browser,
GtkWidget* combobox)
{
MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
- gchar* text;
-
- if (view == NULL)
- return;
-
- text = g_strdup_printf ("%d%%", (gint)(midori_view_get_zoom_level (view) * 100));
- gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combobox))), text);
- g_free (text);
+ gchar* zoom_level_text = g_strdup_printf ("%d%%",
+ (gint)(midori_view_get_zoom_level (view) * 100));
+ gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combobox))),
+ zoom_level_text);
+ g_free (zoom_level_text);
}
static void
@@ -107,81 +104,6 @@ statusbar_features_zoom_level_changed_cb (GtkWidget* combobox,
midori_view_set_zoom_level (view, zoom_level / 100.0);
}
-GtkWidget*
-statusbar_features_property_proxy (MidoriWebSettings* settings,
- const gchar* property,
- GtkWidget* toolbar)
-{
- const gchar* kind = NULL;
- GtkWidget* button;
- GtkWidget* image;
- if (!strcmp (property, "auto-load-images")
- || !strcmp (property, "enable-scripts")
- || !strcmp (property, "enable-plugins"))
- kind = "toggle";
- else if (!strcmp (property, "identify-as"))
- kind = "custom-user-agent";
- else if (strstr (property, "font") != NULL)
- kind = "font";
- else if (!strcmp (property, "zoom-level"))
- {
- MidoriBrowser* browser = midori_browser_get_for_widget (toolbar);
- gint i;
- button = gtk_combo_box_text_new_with_entry ();
- gtk_entry_set_width_chars (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (button))), 4);
- for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++)
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (button), zoom_levels[i].label);
- g_signal_connect (button, "changed",
- G_CALLBACK (statusbar_features_zoom_level_changed_cb), browser);
- g_signal_connect (browser, "notify::tab",
- G_CALLBACK (statusbar_features_browser_notify_tab_cb), button);
- statusbar_features_browser_notify_tab_cb (browser, NULL, button);
- return button;
- }
-
- button = katze_property_proxy (settings, property, kind);
- if (GTK_IS_BIN (button))
- {
- GtkWidget* label = gtk_bin_get_child (GTK_BIN (button));
- if (GTK_IS_LABEL (label))
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- }
-
- if (!strcmp (property, "auto-load-images"))
- {
- g_object_set_data (G_OBJECT (button), "feature-label", _("Images"));
- image = gtk_image_new_from_stock (STOCK_IMAGE, GTK_ICON_SIZE_MENU);
- gtk_button_set_image (GTK_BUTTON (button), image);
- gtk_widget_set_tooltip_text (button, _("Load images automatically"));
- statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
- g_signal_connect (toolbar, "notify::toolbar-style",
- G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
- }
- if (!strcmp (property, "enable-scripts"))
- {
- g_object_set_data (G_OBJECT (button), "feature-label", _("Scripts"));
- image = gtk_image_new_from_stock (STOCK_SCRIPT, GTK_ICON_SIZE_MENU);
- gtk_button_set_image (GTK_BUTTON (button), image);
- gtk_widget_set_tooltip_text (button, _("Enable scripts"));
- statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
- g_signal_connect (toolbar, "notify::toolbar-style",
- G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
- }
- else if (!strcmp (property, "enable-plugins"))
- {
- if (!midori_web_settings_has_plugin_support ())
- gtk_widget_hide (button);
- g_object_set_data (G_OBJECT (button), "feature-label", _("Netscape plugins"));
- image = gtk_image_new_from_stock (STOCK_PLUGINS, GTK_ICON_SIZE_MENU);
- gtk_button_set_image (GTK_BUTTON (button), image);
- gtk_widget_set_tooltip_text (button, _("Enable Netscape plugins"));
- statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
- g_signal_connect (toolbar, "notify::toolbar-style",
- G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
- }
- return button;
-}
-
static void
statusbar_features_app_add_browser_cb (MidoriApp* app,
MidoriBrowser* browser,
@@ -192,8 +114,8 @@ statusbar_features_app_add_browser_cb (MidoriApp* app,
MidoriWebSettings* settings;
GtkWidget* toolbar;
GtkWidget* button;
+ GtkWidget* image;
gsize i;
- gchar** filters;
/* FIXME: Monitor each view and modify its settings individually
instead of merely replicating the global preferences. */
@@ -202,37 +124,48 @@ statusbar_features_app_add_browser_cb (MidoriApp* app,
bbox = gtk_hbox_new (FALSE, 0);
settings = midori_browser_get_settings (browser);
toolbar = katze_object_get_object (browser, "navigationbar");
-
- filters = midori_extension_get_string_list (extension, "items", NULL);
- if (filters && *filters)
- {
- i = 0;
- while (filters[i] != NULL)
- {
- button = statusbar_features_property_proxy (settings, filters[i], toolbar);
- gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
- i++;
- }
- }
- else
- {
- button = statusbar_features_property_proxy (settings, "auto-load-images", toolbar);
- gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
- button = statusbar_features_property_proxy (settings, "enable-scripts", toolbar);
- gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
- button = statusbar_features_property_proxy (settings, "enable-plugins", toolbar);
- gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
- button = statusbar_features_property_proxy (settings, "identify-as", toolbar);
- gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
- button = statusbar_features_property_proxy (settings, "zoom-level", toolbar);
- gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
- }
+ button = katze_property_proxy (settings, "auto-load-images", "toggle");
+ g_object_set_data (G_OBJECT (button), "feature-label", _("Images"));
+ image = gtk_image_new_from_stock (STOCK_IMAGE, GTK_ICON_SIZE_MENU);
+ gtk_button_set_image (GTK_BUTTON (button), image);
+ gtk_widget_set_tooltip_text (button, _("Load images automatically"));
+ statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
+ g_signal_connect (toolbar, "notify::toolbar-style",
+ G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
+ gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
+ button = katze_property_proxy (settings, "enable-scripts", "toggle");
+ g_object_set_data (G_OBJECT (button), "feature-label", _("Scripts"));
+ image = gtk_image_new_from_stock (STOCK_SCRIPTS, GTK_ICON_SIZE_MENU);
+ gtk_button_set_image (GTK_BUTTON (button), image);
+ gtk_widget_set_tooltip_text (button, _("Enable scripts"));
+ statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
+ g_signal_connect (toolbar, "notify::toolbar-style",
+ G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
+ gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
+ button = katze_property_proxy (settings, "enable-plugins", "toggle");
+ g_object_set_data (G_OBJECT (button), "feature-label", _("Netscape plugins"));
+ image = gtk_image_new_from_stock (STOCK_PLUGINS, GTK_ICON_SIZE_MENU);
+ gtk_button_set_image (GTK_BUTTON (button), image);
+ gtk_widget_set_tooltip_text (button, _("Enable Netscape plugins"));
+ statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
+ g_signal_connect (toolbar, "notify::toolbar-style",
+ G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
+ gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
+ button = katze_property_proxy (settings, "identify-as", "custom-user-agent");
+ gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
+ button = gtk_combo_box_text_new_with_entry ();
+ gtk_entry_set_width_chars (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (button))), 4);
+ for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++)
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (button), zoom_levels[i].label);
+ gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 2);
+ g_signal_connect (button, "changed",
+ G_CALLBACK (statusbar_features_zoom_level_changed_cb), browser);
+ g_signal_connect (browser, "notify::tab",
+ G_CALLBACK (statusbar_features_browser_notify_tab_cb), button);
gtk_widget_show_all (bbox);
- gtk_box_pack_end (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3);
+ gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3);
g_object_unref (statusbar);
- g_object_unref (toolbar);
- g_strfreev (filters);
g_signal_connect (extension, "deactivate",
G_CALLBACK (statusbar_features_deactivate_cb), bbox);
}
@@ -261,7 +194,6 @@ extension_init (void)
"version", "0.1" MIDORI_VERSION_SUFFIX,
"authors", "Christian Dywan ",
NULL);
- midori_extension_install_string_list (extension, "items", NULL, G_MAXSIZE);
g_signal_connect (extension, "activate",
G_CALLBACK (statusbar_features_activate_cb), NULL);
diff --git a/extensions/tab-panel.c b/extensions/tab-panel.c
index 44e23e6a..fa54bdf5 100644
--- a/extensions/tab-panel.c
+++ b/extensions/tab-panel.c
@@ -143,6 +143,7 @@ midori_extension_cursor_or_row_changed_cb (GtkTreeView* treeview,
/* Nothing to do */
}
+#if GTK_CHECK_VERSION (2, 12, 0)
static gboolean
tab_panel_treeview_query_tooltip_cb (GtkWidget* treeview,
gint x,
@@ -170,6 +171,7 @@ tab_panel_treeview_query_tooltip_cb (GtkWidget* treeview,
return TRUE;
}
+#endif
static void
midori_extension_row_activated_cb (GtkTreeView* treeview,
@@ -229,12 +231,12 @@ midori_extension_button_release_event_cb (GtkWidget* widget,
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
event->x, event->y, NULL, &column, NULL, NULL)
&& column == gtk_tree_view_get_column (GTK_TREE_VIEW (widget), 1))
- midori_browser_remove_tab (browser, view);
+ gtk_widget_destroy (view);
else
midori_browser_set_current_tab (browser, view);
}
else if (event->button == 2)
- midori_browser_remove_tab (midori_browser_get_for_widget (widget), view);
+ gtk_widget_destroy (view);
else
tab_panel_popup (widget, event, view);
@@ -417,7 +419,8 @@ tab_panel_browser_add_tab_cb (MidoriBrowser* browser,
GtkWidget* view,
MidoriExtension* extension)
{
- gint page = midori_browser_page_num (browser, view);
+ GtkWidget* notebook = katze_object_get_object (browser, "notebook");
+ gint page = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), view);
MidoriWebSettings* settings = midori_browser_get_settings (browser);
gboolean minimized = katze_object_get_boolean (view, "minimized");
GdkPixbuf* icon = midori_view_get_icon (MIDORI_VIEW (view));
@@ -465,6 +468,8 @@ tab_panel_browser_add_tab_cb (MidoriBrowser* browser,
g_signal_connect (view, "notify::title",
G_CALLBACK (tab_panel_view_notify_title_cb), extension);
}
+
+ g_object_unref (notebook);
}
static void
@@ -532,9 +537,11 @@ tab_panel_app_add_browser_cb (MidoriApp* app,
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (treeview), FALSE);
+ #if GTK_CHECK_VERSION (2, 12, 0)
g_signal_connect (treeview, "query-tooltip",
G_CALLBACK (tab_panel_treeview_query_tooltip_cb), NULL);
gtk_widget_set_has_tooltip (treeview, TRUE);
+ #endif
column = gtk_tree_view_column_new ();
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
diff --git a/extensions/toolbar-editor.c b/extensions/toolbar-editor.c
index 93486682..6d3e10a3 100644
--- a/extensions/toolbar-editor.c
+++ b/extensions/toolbar-editor.c
@@ -46,6 +46,8 @@ static const GtkTargetEntry tb_editor_dnd_targets[] =
};
static const gint tb_editor_dnd_targets_len = G_N_ELEMENTS(tb_editor_dnd_targets);
+static void tb_editor_browser_populate_tool_menu_cb(MidoriBrowser *browser, GtkWidget *menu, MidoriExtension *ext);
+
static void tb_editor_browser_populate_toolbar_menu_cb(MidoriBrowser *browser, GtkWidget *menu,
MidoriExtension *ext);
@@ -56,6 +58,7 @@ static void tb_editor_deactivate_cb(MidoriExtension *extension, MidoriBrowser *b
{
MidoriApp *app = midori_extension_get_app(extension);
+ g_signal_handlers_disconnect_by_func(browser, tb_editor_browser_populate_tool_menu_cb, extension);
g_signal_handlers_disconnect_by_func(browser, tb_editor_browser_populate_toolbar_menu_cb, extension);
g_signal_handlers_disconnect_by_func(extension, tb_editor_deactivate_cb, browser);
g_signal_handlers_disconnect_by_func(app, tb_editor_app_add_browser_cb, extension);
@@ -104,12 +107,7 @@ static GSList *tb_editor_array_to_list(const gchar **items)
name = items;
while (*name != NULL)
{
- #ifdef HAVE_GRANITE
- /* A "new tab" button is already part of the notebook */
- if (*name[0] != '\0' && strcmp (*name, "TabNew"))
- #else
if (*name[0] != '\0')
- #endif
list = g_slist_append(list, g_strdup(*name));
name++;
}
@@ -396,7 +394,11 @@ static TBEditorWidget *tb_editor_create_dialog(MidoriBrowser *parent)
GTK_WINDOW(parent),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
- vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+#if !GTK_CHECK_VERSION(3,0,0)
+ vbox = (GTK_DIALOG(dialog))->vbox;
+#else
+ vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
+#endif
gtk_box_set_spacing(GTK_BOX(vbox), 6);
gtk_widget_set_name(dialog, "GeanyDialog");
gtk_window_set_default_size(GTK_WINDOW(dialog), -1, 400);
@@ -408,7 +410,7 @@ static TBEditorWidget *tb_editor_create_dialog(MidoriBrowser *parent)
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
label = gtk_label_new(
- _("Select items to be displayed on the toolbar. Items can be reordered by drag and drop."));
+ _("Select items to be displayed on the toolbar. Items can be reodered by drag and drop."));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
tree_available = gtk_tree_view_new();
@@ -576,6 +578,17 @@ static void tb_editor_menu_configure_toolbar_activate_cb(GtkWidget *menuitem, Mi
g_free(tbw);
}
+static void tb_editor_browser_populate_tool_menu_cb(MidoriBrowser *browser, GtkWidget *menu, MidoriExtension *ext)
+{
+ GtkWidget *menuitem;
+
+ menuitem = gtk_menu_item_new_with_mnemonic (_("Customize _Toolbar..."));
+ g_signal_connect (menuitem, "activate",
+ G_CALLBACK (tb_editor_menu_configure_toolbar_activate_cb), browser);
+ gtk_widget_show (menuitem);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+}
+
static void tb_editor_browser_populate_toolbar_menu_cb(MidoriBrowser *browser, GtkWidget *menu,
MidoriExtension *ext)
{
@@ -585,7 +598,7 @@ static void tb_editor_browser_populate_toolbar_menu_cb(MidoriBrowser *browser, G
separator = gtk_separator_menu_item_new ();
gtk_widget_show (separator);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
- menuitem = gtk_menu_item_new_with_mnemonic (_("_Customize Toolbarâ¦"));
+ menuitem = gtk_menu_item_new_with_mnemonic (_("_Customize..."));
g_signal_connect (menuitem, "activate",
G_CALLBACK (tb_editor_menu_configure_toolbar_activate_cb), browser);
gtk_widget_show (menuitem);
@@ -594,6 +607,7 @@ static void tb_editor_browser_populate_toolbar_menu_cb(MidoriBrowser *browser, G
static void tb_editor_app_add_browser_cb(MidoriApp *app, MidoriBrowser *browser, MidoriExtension *ext)
{
+ g_signal_connect(browser, "populate-tool-menu", G_CALLBACK(tb_editor_browser_populate_tool_menu_cb), ext);
g_signal_connect(browser, "populate-toolbar-menu", G_CALLBACK(tb_editor_browser_populate_toolbar_menu_cb), ext);
g_signal_connect(ext, "deactivate", G_CALLBACK(tb_editor_deactivate_cb), browser);
}
diff --git a/extensions/web-cache.c b/extensions/web-cache.c
index 53ea445b..a3e592bf 100644
--- a/extensions/web-cache.c
+++ b/extensions/web-cache.c
@@ -28,7 +28,8 @@ web_cache_get_cache_dir (void)
{
static gchar* cache_dir = NULL;
if (!cache_dir)
- cache_dir = g_build_filename (midori_paths_get_cache_dir (), "web", NULL);
+ cache_dir = g_build_filename (g_get_user_cache_dir (),
+ PACKAGE_NAME, "web", NULL);
return cache_dir;
}
diff --git a/extensions/wscript_build b/extensions/wscript_build
index 152d8206..e209aed4 100644
--- a/extensions/wscript_build
+++ b/extensions/wscript_build
@@ -28,16 +28,13 @@ for extension in extensions:
continue
source = extension
- if bld.env['platform'] == 'win32' and target in ['external-download-manager']:
- continue
-
obj = bld.new_task_gen ('cc', 'shlib')
obj.target = target
- obj.includes = '.. ../katze ../midori'
+ obj.includes = '..'
obj.source = source
obj.uselib = 'UNIQUE LIBSOUP GIO GTK SQLITE WEBKIT LIBXML HILDON'
- obj.vapi_dirs = '../midori ../katze'
- obj.packages = 'glib-2.0 gio-2.0 libsoup-2.4 midori midori-core katze'
+ obj.vapi_dirs = '../midori'
+ obj.packages = 'glib-2.0 gio-2.0 libsoup-2.4 midori'
if bld.env['HAVE_GTK3']:
obj.packages += ' gtk+-3.0 webkitgtk-3.0'
else:
diff --git a/icons/16x16/internet-news-reader.png b/icons/16x16/news-feed.png
similarity index 100%
rename from icons/16x16/internet-news-reader.png
rename to icons/16x16/news-feed.png
diff --git a/icons/22x22/internet-news-reader.png b/icons/22x22/news-feed.png
similarity index 100%
rename from icons/22x22/internet-news-reader.png
rename to icons/22x22/news-feed.png
diff --git a/icons/scalable/internet-news-reader.svg b/icons/scalable/news-feed.svg
similarity index 100%
rename from icons/scalable/internet-news-reader.svg
rename to icons/scalable/news-feed.svg
diff --git a/icons/wscript_build b/icons/wscript_build
index 4e2345c9..6421b80c 100644
--- a/icons/wscript_build
+++ b/icons/wscript_build
@@ -41,4 +41,4 @@ def add_image (bld, category, name):
add_image (bld, 'categories', 'extension')
add_image (bld, 'apps', 'midori')
-add_image (bld, 'status', 'internet-news-reader')
+add_image (bld, 'status', 'news-feed')
diff --git a/katze/gtk3-compat.c b/katze/gtk3-compat.c
index d7fd2495..0c0a4369 100644
--- a/katze/gtk3-compat.c
+++ b/katze/gtk3-compat.c
@@ -27,9 +27,9 @@ sokoke_on_entry_focus_in_event (GtkEntry* entry,
g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
if (has_default)
{
+ gtk_entry_set_text (entry, "");
g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
GINT_TO_POINTER (0));
- gtk_entry_set_text (entry, "");
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
PANGO_STYLE_NORMAL);
}
@@ -46,9 +46,9 @@ sokoke_on_entry_focus_out_event (GtkEntry* entry,
{
const gchar* default_text = (const gchar*)g_object_get_data (
G_OBJECT (entry), "sokoke_default_text");
+ gtk_entry_set_text (entry, default_text);
g_object_set_data (G_OBJECT (entry),
"sokoke_has_default", GINT_TO_POINTER (1));
- gtk_entry_set_text (entry, default_text);
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
PANGO_STYLE_ITALIC);
}
@@ -71,15 +71,14 @@ gtk_entry_set_placeholder_text (GtkEntry* entry,
const gchar* default_text)
{
/* Note: The default text initially overwrites any previous text */
- gchar* old_value = g_object_get_data (G_OBJECT (entry), "sokoke_default_text");
- g_object_set_data (G_OBJECT (entry), "sokoke_default_text", (gpointer)default_text);
-
- if (default_text == NULL)
- g_object_set_data (G_OBJECT (entry), "sokoke_has_default", GINT_TO_POINTER (0));
- else if (!old_value)
+ gchar* old_value = g_object_get_data (G_OBJECT (entry),
+ "sokoke_default_text");
+ if (!old_value)
{
- g_object_set_data (G_OBJECT (entry), "sokoke_has_default", GINT_TO_POINTER (1));
- sokoke_widget_set_pango_font_style (GTK_WIDGET (entry), PANGO_STYLE_ITALIC);
+ g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
+ GINT_TO_POINTER (1));
+ sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
+ PANGO_STYLE_ITALIC);
gtk_entry_set_text (entry, default_text);
g_signal_connect (entry, "drag-data-received",
G_CALLBACK (sokoke_on_entry_drag_data_received), NULL);
@@ -90,19 +89,55 @@ gtk_entry_set_placeholder_text (GtkEntry* entry,
}
else if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
{
- gint has_default = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
+ gint has_default = GPOINTER_TO_INT (
+ g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
if (has_default)
{
gtk_entry_set_text (entry, default_text);
- sokoke_widget_set_pango_font_style (GTK_WIDGET (entry), PANGO_STYLE_ITALIC);
+ sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
+ PANGO_STYLE_ITALIC);
}
}
+ g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
+ (gpointer)default_text);
}
+#endif
+
+#if !GTK_CHECK_VERSION (2, 12, 0)
-const gchar*
-gtk_entry_get_placeholder_text (GtkEntry* entry)
+void
+gtk_widget_set_has_tooltip (GtkWidget* widget,
+ gboolean has_tooltip)
{
- return g_object_get_data (G_OBJECT (entry), "sokoke_default_text");
+ /* Do nothing */
}
+
+void
+gtk_widget_set_tooltip_text (GtkWidget* widget,
+ const gchar* text)
+{
+ if (text && *text)
+ {
+ static GtkTooltips* tooltips = NULL;
+ if (G_UNLIKELY (!tooltips))
+ tooltips = gtk_tooltips_new ();
+ gtk_tooltips_set_tip (tooltips, widget, text, NULL);
+ }
+}
+
+void
+gtk_tool_item_set_tooltip_text (GtkToolItem* toolitem,
+ const gchar* text)
+{
+ if (text && *text)
+ {
+ static GtkTooltips* tooltips = NULL;
+ if (G_UNLIKELY (!tooltips))
+ tooltips = gtk_tooltips_new ();
+
+ gtk_tool_item_set_tooltip (toolitem, tooltips, text, NULL);
+ }
+}
+
#endif
diff --git a/katze/gtk3-compat.h b/katze/gtk3-compat.h
index a8450af2..fddfe977 100644
--- a/katze/gtk3-compat.h
+++ b/katze/gtk3-compat.h
@@ -6,7 +6,7 @@
G_BEGIN_DECLS
-#if GTK_CHECK_VERSION (3, 2, 0) && defined (GTK_DISABLE_DEPRECATED)
+#if GTK_CHECK_VERSION (3, 2, 0)
#define GTK_TYPE_VBOX GTK_TYPE_BOX
#define GtkVBox GtkBox
#define GtkVBoxClass GtkBoxClass
@@ -39,6 +39,25 @@ G_BEGIN_DECLS
#define g_format_size(sz) g_format_size_for_display ((goffset)sz)
#endif
+#if !GTK_CHECK_VERSION (2, 14, 0)
+ #define gtk_dialog_get_content_area(dlg) dlg->vbox
+ #define gtk_dialog_get_action_area(dlg) dlg->action_area
+ #define gtk_widget_get_window(wdgt) wdgt->window
+ #define gtk_adjustment_get_page_size(adj) adj->page_size
+ #define gtk_adjustment_get_upper(adj) adj->upper
+ #define gtk_adjustment_get_lower(adj) adj->lower
+ #define gtk_adjustment_get_value(adj) adj->value
+#endif
+
+#if !GTK_CHECK_VERSION (2, 16, 0)
+ #define GTK_ACTIVATABLE GTK_WIDGET
+ #define gtk_activatable_get_related_action gtk_widget_get_action
+ #define gtk_menu_item_set_label(menuitem, label) \
+ gtk_label_set_label (GTK_LABEL (GTK_BIN (menuitem)->child), \
+ label ? label : "");
+ #define gtk_image_menu_item_set_always_show_image(menuitem, yesno) ()
+#endif
+
#if !GTK_CHECK_VERSION (2, 18, 0)
#define gtk_widget_is_toplevel(widget) GTK_WIDGET_TOPLEVEL (widget)
#define gtk_widget_has_focus(widget) GTK_WIDGET_HAS_FOCUS (widget)
@@ -70,10 +89,24 @@ G_BEGIN_DECLS
#if !GTK_CHECK_VERSION (3, 2, 0) && defined (HAVE_HILDON_2_2)
#define gtk_entry_set_placeholder_text hildon_gtk_entry_set_placeholder_text
- #define gtk_entry_get_placeholder_text hildon_gtk_entry_get_placeholder_text
#elif !GTK_CHECK_VERSION (3, 2, 0)
- void gtk_entry_set_placeholder_text (GtkEntry* entry, const gchar* text);
- const gchar* gtk_entry_get_placeholder_text (GtkEntry* entry);
+ #define gtk_entry_set_placeholder_text sokoke_entry_set_default_text
+#endif
+
+#if !GTK_CHECK_VERSION(2, 12, 0)
+
+void
+gtk_widget_set_has_tooltip (GtkWidget* widget,
+ gboolean has_tooltip);
+
+void
+gtk_widget_set_tooltip_text (GtkWidget* widget,
+ const gchar* text);
+
+void
+gtk_tool_item_set_tooltip_text (GtkToolItem* toolitem,
+ const gchar* text);
+
#endif
#if !GTK_CHECK_VERSION (2, 24 ,0)
@@ -116,10 +149,6 @@ G_BEGIN_DECLS
#define GDK_KEY_Return GDK_Return
#endif
-#ifndef GDK_IS_X11_DISPLAY
- #define GDK_IS_X11_DISPLAY(display) TRUE
-#endif
-
G_END_DECLS
#endif
diff --git a/katze/katze-array.c b/katze/katze-array.c
index 602c1647..49291d03 100644
--- a/katze/katze-array.c
+++ b/katze/katze-array.c
@@ -74,13 +74,6 @@ GList* kalistglobal;
static void
katze_array_finalize (GObject* object);
-static void
-_katze_array_update (KatzeArray* array)
-{
- g_object_set_data (G_OBJECT (array), "last-update",
- GINT_TO_POINTER (time (NULL)));
-}
-
static void
_katze_array_add_item (KatzeArray* array,
gpointer item)
@@ -91,7 +84,6 @@ _katze_array_add_item (KatzeArray* array,
katze_item_set_parent (item, array);
array->items = g_list_append (array->items, item);
- _katze_array_update (array);
}
static void
@@ -103,7 +95,6 @@ _katze_array_remove_item (KatzeArray* array,
if (KATZE_IS_ITEM (item))
katze_item_set_parent (item, NULL);
g_object_unref (item);
- _katze_array_update (array);
}
static void
@@ -113,7 +104,6 @@ _katze_array_move_item (KatzeArray* array,
{
array->items = g_list_remove (array->items, item);
array->items = g_list_insert (array->items, item, position);
- _katze_array_update (array);
}
static void
@@ -122,10 +112,9 @@ _katze_array_clear (KatzeArray* array)
GObject* item;
while ((item = g_list_nth_data (array->items, 0)))
- g_signal_emit (array, signals[REMOVE_ITEM], 0, item);
+ katze_array_remove_item (array, item);
g_list_free (array->items);
array->items = NULL;
- _katze_array_update (array);
}
static void
@@ -203,7 +192,7 @@ katze_array_class_init (KatzeArrayClass* class)
"update",
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
- G_STRUCT_OFFSET (KatzeArrayClass, update),
+ 0,
0,
NULL,
g_cclosure_marshal_VOID__VOID,
@@ -216,7 +205,6 @@ katze_array_class_init (KatzeArrayClass* class)
class->remove_item = _katze_array_remove_item;
class->move_item = _katze_array_move_item;
class->clear = _katze_array_clear;
- class->update = _katze_array_update;
}
static void
@@ -229,11 +217,14 @@ katze_array_init (KatzeArray* array)
static void
katze_array_finalize (GObject* object)
{
- KatzeArray* array = KATZE_ARRAY (object);
- GList* items;
+ KatzeArray* array;
+ guint i;
+ gpointer item;
- for (items = array->items; items; items = g_list_next (items))
- g_object_unref (items->data);
+ array = KATZE_ARRAY (object);
+ i = 0;
+ while ((item = g_list_nth_data (array->items, i++)))
+ g_object_unref (item);
g_list_free (array->items);
G_OBJECT_CLASS (katze_array_parent_class)->finalize (object);
@@ -373,44 +364,37 @@ katze_array_get_item_index (KatzeArray* array,
/**
* katze_array_find_token:
* @array: a #KatzeArray
- * @token: a token string, or "token keywords" string
+ * @token: a token string
*
* Looks up an item in the array which has the specified token.
*
- * This function will fail if the type of the list
- * is not based on #KatzeItem children.
+ * This function will silently fail if the type of the list
+ * is not based on #GObject and only #KatzeItem children
+ * are checked for their token, any other objects are skipped.
*
* Note that @token is by definition unique to one item.
*
- * Since 0.4.4 @token can be a "token keywords" string.
- *
* Return value: an item, or %NULL
**/
gpointer
katze_array_find_token (KatzeArray* array,
const gchar* token)
{
- goffset token_length;
- GList* items;
+ guint i;
+ gpointer item;
g_return_val_if_fail (KATZE_IS_ARRAY (array), NULL);
- g_return_val_if_fail (katze_array_is_a (array, KATZE_TYPE_ITEM), NULL);
- g_return_val_if_fail (token != NULL, NULL);
-
- token_length = strchr (token, ' ') - token;
- if (token_length < 1)
- token_length = strlen (token);
- for (items = array->items; items; items = g_list_next (items))
+ i = 0;
+ while ((item = g_list_nth_data (array->items, i++)))
{
- const gchar* found_token = ((KatzeItem*)items->data)->token;
- if (found_token != NULL)
- {
- guint bigger_item = strlen (found_token) > token_length ? strlen (found_token) : token_length;
-
- if (strncmp (token, found_token, bigger_item) == 0)
- return items->data;
- }
+ const gchar* found_token;
+
+ if (!KATZE_IS_ITEM (item))
+ continue;
+ found_token = ((KatzeItem*)item)->token;
+ if (!g_strcmp0 (found_token, token))
+ return item;
}
return NULL;
}
@@ -422,8 +406,9 @@ katze_array_find_token (KatzeArray* array,
*
* Looks up an item in the array which has the specified URI.
*
- * This function will fail if the type of the list
- * is not based on #KatzeItem children.
+ * This function will silently fail if the type of the list
+ * is not based on #GObject and only #KatzeItem children
+ * are checked for their token, any other objects are skipped.
*
* Return value: an item, or %NULL
*
@@ -433,17 +418,19 @@ gpointer
katze_array_find_uri (KatzeArray* array,
const gchar* uri)
{
- GList* items;
+ guint i;
+ gpointer item;
- g_return_val_if_fail (KATZE_IS_ARRAY (array), NULL);
- g_return_val_if_fail (katze_array_is_a (array, KATZE_TYPE_ITEM), NULL);
- g_return_val_if_fail (uri != NULL, NULL);
-
- for (items = array->items; items; items = g_list_next (items))
+ i = 0;
+ while ((item = g_list_nth_data (array->items, i++)))
{
- const gchar* found_uri = ((KatzeItem*)items->data)->uri;
- if (found_uri != NULL && !strcmp (found_uri, uri))
- return items->data;
+ const gchar* found_uri;
+
+ if (!KATZE_IS_ITEM (item))
+ continue;
+ found_uri = ((KatzeItem*)item)->uri;
+ if (!g_strcmp0 (found_uri, uri))
+ return item;
}
return NULL;
}
diff --git a/katze/katze-arrayaction.c b/katze/katze-arrayaction.c
index e5edad6a..5ce84f52 100644
--- a/katze/katze-arrayaction.c
+++ b/katze/katze-arrayaction.c
@@ -355,16 +355,11 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
gint summand;
KatzeItem* item;
GtkWidget* menuitem;
+ const gchar* icon_name;
+ GdkPixbuf* icon;
GtkWidget* image;
GtkWidget* submenu;
- g_return_if_fail (KATZE_IS_ARRAY_ACTION (array_action));
- g_return_if_fail (KATZE_IS_ITEM (array));
- g_return_if_fail (GTK_IS_MENU_SHELL (menu));
- g_return_if_fail (GTK_IS_TOOL_ITEM (proxy)
- || GTK_IS_MENU_ITEM (proxy)
- || GTK_IS_WINDOW (proxy));
-
if (!KATZE_IS_ARRAY (array))
return;
@@ -390,7 +385,18 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
}
menuitem = katze_image_menu_item_new_ellipsized (
katze_item_get_name (item));
- image = katze_item_get_image (item);
+ if ((icon_name = katze_item_get_icon (item)) && *icon_name)
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+ else
+ {
+ if (KATZE_ITEM_IS_FOLDER (item))
+ icon = gtk_widget_render_icon (menuitem,
+ GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
+ else
+ icon = katze_load_cached_icon (katze_item_get_uri (item), proxy);
+ image = gtk_image_new_from_pixbuf (icon);
+ g_object_unref (icon);
+ }
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
gtk_image_menu_item_set_always_show_image (
GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
@@ -400,13 +406,8 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
{
submenu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
- /* Make sure menu appears to contain items */
- gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
- gtk_separator_menu_item_new ());
g_signal_connect (menuitem, "select",
G_CALLBACK (katze_array_action_menu_item_select_cb), array_action);
- g_signal_connect (menuitem, "activate",
- G_CALLBACK (katze_array_action_menu_item_select_cb), array_action);
}
else
{
@@ -420,39 +421,21 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
}
}
-static gboolean
-katze_array_action_menu_item_need_update (KatzeArrayAction* array_action,
- GtkWidget* proxy)
+static void
+katze_array_action_menu_item_select_cb (GtkWidget* proxy,
+ KatzeArrayAction* array_action)
{
GtkWidget* menu;
KatzeArray* array;
- gint last_array_update, last_proxy_update;
gboolean handled;
- array = g_object_get_data (G_OBJECT (proxy), "KatzeItem");
- /* last-update is set on all arrays; consider public API */
- last_array_update = GPOINTER_TO_INT (
- g_object_get_data (G_OBJECT (array), "last-update"));
- last_proxy_update = GPOINTER_TO_INT (
- g_object_get_data (G_OBJECT (proxy), "last-update"));
- if (last_proxy_update > last_array_update)
- return FALSE;
-
menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy));
gtk_container_foreach (GTK_CONTAINER (menu),
(GtkCallback)(gtk_widget_destroy), NULL);
+
+ array = g_object_get_data (G_OBJECT (proxy), "KatzeItem");
katze_array_action_generate_menu (array_action, array, GTK_MENU_SHELL (menu), proxy);
g_signal_emit (array_action, signals[POPULATE_FOLDER], 0, menu, array, &handled);
- g_object_set_data (G_OBJECT (proxy), "last-update",
- GINT_TO_POINTER (time (NULL)));
- return TRUE;
-}
-
-static void
-katze_array_action_menu_item_select_cb (GtkWidget* proxy,
- KatzeArrayAction* array_action)
-{
- katze_array_action_menu_item_need_update (array_action, proxy);
}
static void
@@ -475,21 +458,20 @@ katze_array_action_proxy_clicked_cb (GtkWidget* proxy,
KatzeArray* array;
gboolean handled = FALSE;
- array = (KatzeArray*)g_object_get_data (G_OBJECT (proxy), "KatzeItem");
if (GTK_IS_MENU_ITEM (proxy))
{
- if (katze_array_action_menu_item_need_update (array_action, proxy))
- {
- g_signal_emit (array_action, signals[POPULATE_FOLDER], 0,
- gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)),
- array, &handled);
- if (!handled)
- g_signal_emit (array_action, signals[POPULATE_POPUP], 0,
- gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)));
- }
+ g_object_set_data (G_OBJECT (proxy), "KatzeItem", array_action->array);
+ katze_array_action_menu_item_select_cb (proxy, array_action);
+ g_signal_emit (array_action, signals[POPULATE_FOLDER], 0,
+ gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)),
+ array_action->array, &handled);
+ if (!handled)
+ g_signal_emit (array_action, signals[POPULATE_POPUP], 0,
+ gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)));
return;
}
+ array = (KatzeArray*)g_object_get_data (G_OBJECT (proxy), "KatzeArray");
if (KATZE_IS_ITEM (array) && katze_item_get_uri ((KatzeItem*)array))
{
katze_array_action_activate_item (array_action, KATZE_ITEM (array), 1);
@@ -570,6 +552,7 @@ katze_array_action_item_notify_cb (KatzeItem* item,
const gchar* property;
const gchar* title;
const gchar* desc;
+ GdkPixbuf* icon;
GtkWidget* image;
if (!G_IS_PARAM_SPEC_STRING (pspec))
@@ -596,13 +579,16 @@ katze_array_action_item_notify_cb (KatzeItem* item,
}
else if (KATZE_ITEM_IS_BOOKMARK (item) && !strcmp (property, "uri"))
{
- image = katze_item_get_image (item);
+ icon = katze_load_cached_icon (katze_item_get_uri (item), GTK_WIDGET (toolitem));
+ image = gtk_image_new_from_pixbuf (icon);
+ g_object_unref (icon);
gtk_widget_show (image);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
}
else if (!strcmp (property, "icon"))
{
- image = katze_item_get_image (item);
+ image = gtk_image_new_from_icon_name (katze_item_get_icon (item),
+ GTK_ICON_SIZE_MENU);
gtk_widget_show (image);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
}
@@ -614,12 +600,25 @@ katze_array_action_proxy_create_menu_proxy_cb (GtkWidget* proxy,
{
KatzeArrayAction* array_action;
GtkWidget* menuitem;
+ const gchar* icon_name;
GtkWidget* image;
+ GdkPixbuf* icon;
array_action = g_object_get_data (G_OBJECT (proxy), "KatzeArrayAction");
menuitem = katze_image_menu_item_new_ellipsized (
katze_item_get_name (item));
- image = katze_item_get_image (item);
+ if ((icon_name = katze_item_get_icon (item)) && *icon_name)
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+ else
+ {
+ if (KATZE_ITEM_IS_FOLDER (item))
+ icon = gtk_widget_render_icon (menuitem,
+ GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
+ else
+ icon = katze_load_cached_icon (katze_item_get_uri (item), proxy);
+ image = gtk_image_new_from_pixbuf (icon);
+ g_object_unref (icon);
+ }
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
gtk_image_menu_item_set_always_show_image (
GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
@@ -675,6 +674,7 @@ katze_array_action_create_tool_item_for (KatzeArrayAction* array_action,
const gchar* uri;
const gchar* desc;
GtkToolItem* toolitem;
+ GdkPixbuf* icon;
GtkWidget* image;
GtkWidget* label;
@@ -686,12 +686,20 @@ katze_array_action_create_tool_item_for (KatzeArrayAction* array_action,
return gtk_separator_tool_item_new ();
if (KATZE_ITEM_IS_FOLDER (item))
+ {
toolitem = gtk_toggle_tool_button_new ();
+ icon = gtk_widget_render_icon (GTK_WIDGET (toolitem),
+ GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
+ }
else
+ {
toolitem = gtk_tool_button_new (NULL, "");
+ icon = katze_load_cached_icon (uri, GTK_WIDGET (toolitem));
+ }
g_signal_connect (toolitem, "create-menu-proxy",
G_CALLBACK (katze_array_action_proxy_create_menu_proxy_cb), item);
- image = katze_item_get_image (item);
+ image = gtk_image_new_from_pixbuf (icon);
+ g_object_unref (icon);
gtk_widget_show (image);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
label = gtk_label_new (NULL);
@@ -731,9 +739,6 @@ static void
katze_array_action_connect_proxy (GtkAction* action,
GtkWidget* proxy)
{
- KatzeArrayAction* array_action = KATZE_ARRAY_ACTION (action);
- g_object_set_data (G_OBJECT (proxy), "KatzeItem", array_action->array);
-
GTK_ACTION_CLASS (katze_array_action_parent_class)->connect_proxy (
action, proxy);
@@ -745,10 +750,9 @@ katze_array_action_connect_proxy (GtkAction* action,
else if (GTK_IS_MENU_ITEM (proxy))
{
gtk_menu_item_set_submenu (GTK_MENU_ITEM (proxy), gtk_menu_new ());
+ /* FIXME: 'select' doesn't cover all ways of selection */
g_signal_connect (proxy, "select",
G_CALLBACK (katze_array_action_proxy_clicked_cb), action);
- g_signal_connect (proxy, "activate",
- G_CALLBACK (katze_array_action_proxy_clicked_cb), action);
}
}
diff --git a/katze/katze-http-cookies-sqlite.c b/katze/katze-http-cookies-sqlite.c
index 10eb3f33..be3202ed 100644
--- a/katze/katze-http-cookies-sqlite.c
+++ b/katze/katze-http-cookies-sqlite.c
@@ -27,7 +27,7 @@
#include
#define QUERY_ALL "SELECT id, name, value, host, path, expiry, lastAccessed, isSecure, isHttpOnly FROM moz_cookies;"
-#define CREATE_TABLE "CREATE TABLE IF NOT EXISTS moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER)"
+#define CREATE_TABLE "CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER)"
#define QUERY_INSERT "INSERT INTO moz_cookies VALUES(NULL, %Q, %Q, %Q, %Q, %d, NULL, %d, %d);"
#define QUERY_DELETE "DELETE FROM moz_cookies WHERE name=%Q AND host=%Q;"
@@ -71,6 +71,80 @@ G_DEFINE_TYPE_WITH_CODE (KatzeHttpCookiesSqlite, katze_http_cookies_sqlite, G_TY
Copyright (C) 2009 Collabora Ltd.
Mostly copied from libSoup 2.30, coding style retained */
+static void
+try_create_table (sqlite3 *db)
+{
+ char *error = NULL;
+
+ if (sqlite3_exec (db, CREATE_TABLE, NULL, NULL, &error)) {
+ g_warning ("Failed to execute query: %s", error);
+ sqlite3_free (error);
+ }
+}
+
+static void
+exec_query_with_try_create_table (sqlite3* db,
+ const char* sql,
+ int (*callback)(void*,int,char**,char**),
+ void *argument)
+{
+ char *error = NULL;
+ gboolean try_create = TRUE;
+
+try_exec:
+ if (sqlite3_exec (db, sql, callback, argument, &error)) {
+ if (try_create) {
+ try_create = FALSE;
+ try_create_table (db);
+ sqlite3_free (error);
+ error = NULL;
+ goto try_exec;
+ } else {
+ g_warning ("Failed to execute query: %s", error);
+ sqlite3_free (error);
+ }
+ }
+}
+
+static int
+callback (void *data, int argc, char **argv, char **colname)
+{
+ SoupCookie *cookie = NULL;
+ SoupCookieJar *jar = SOUP_COOKIE_JAR (data);
+
+ char *name, *value, *host, *path;
+ gint64 expire_time;
+ time_t now;
+ int max_age;
+ gboolean http_only = FALSE, secure = FALSE;
+
+ now = time (NULL);
+
+ name = argv[COL_NAME];
+ value = argv[COL_VALUE];
+ host = argv[COL_HOST];
+ path = argv[COL_PATH];
+ expire_time = g_ascii_strtoull (argv[COL_EXPIRY], NULL, 10);
+
+ if (now >= expire_time)
+ return 0;
+ max_age = (expire_time - now <= G_MAXINT ? expire_time - now : G_MAXINT);
+
+ http_only = (g_strcmp0 (argv[COL_HTTP_ONLY], "1") == 0);
+ secure = (g_strcmp0 (argv[COL_SECURE], "1") == 0);
+
+ cookie = soup_cookie_new (name, value, host, path, max_age);
+
+ if (secure)
+ soup_cookie_set_secure (cookie, TRUE);
+ if (http_only)
+ soup_cookie_set_http_only (cookie, TRUE);
+
+ soup_cookie_jar_add_cookie (jar, cookie);
+
+ return 0;
+}
+
/* Follows sqlite3 convention; returns TRUE on error */
static gboolean
katze_http_cookies_sqlite_open_db (KatzeHttpCookiesSqlite* http_cookies)
@@ -83,91 +157,23 @@ katze_http_cookies_sqlite_open_db (KatzeHttpCookiesSqlite* http_cookies)
return TRUE;
}
- if (sqlite3_exec (http_cookies->db, CREATE_TABLE, NULL, NULL, &error)) {
- g_warning ("Failed to execute query: %s", error);
- sqlite3_free (error);
- }
-
- if (sqlite3_exec (http_cookies->db, "PRAGMA secure_delete = 1;",
- NULL, NULL, &error)) {
+ if (sqlite3_exec (http_cookies->db, "PRAGMA synchronous = OFF; PRAGMA secure_delete = 1;", NULL, NULL, &error)) {
g_warning ("Failed to execute query: %s", error);
sqlite3_free (error);
}
- sqlite3_exec (http_cookies->db,
- /* Arguably cookies are like a cache, so performance over integrity */
- "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;"
- "PRAGMA count_changes = OFF; PRAGMA journal_mode = TRUNCATE;",
- NULL, NULL, &error);
-
return FALSE;
}
static void
katze_http_cookies_sqlite_load (KatzeHttpCookiesSqlite* http_cookies)
{
- const char *name, *value, *host, *path;
- sqlite3_stmt* stmt;
- SoupCookie *cookie = NULL;
- gint64 expire_time;
- time_t now;
- int max_age;
- gboolean http_only = FALSE, secure = FALSE;
- char *query;
- int result;
-
if (http_cookies->db == NULL) {
if (katze_http_cookies_sqlite_open_db (http_cookies))
return;
}
- sqlite3_prepare_v2 (http_cookies->db, QUERY_ALL, strlen (QUERY_ALL) + 1, &stmt, NULL);
- result = sqlite3_step (stmt);
- if (result != SQLITE_ROW)
- {
- if (result == SQLITE_ERROR)
- g_print (_("Failed to load cookies\n"));
- sqlite3_reset (stmt);
- return;
- }
-
- while (result == SQLITE_ROW)
- {
- now = time (NULL);
- name = (const char*)sqlite3_column_text (stmt, COL_NAME);
- value = (const char*)sqlite3_column_text (stmt, COL_VALUE);
- host = (const char*)sqlite3_column_text (stmt, COL_HOST);
- path = (const char*)sqlite3_column_text (stmt, COL_PATH);
- expire_time = sqlite3_column_int64 (stmt,COL_EXPIRY);
- secure = sqlite3_column_int (stmt, COL_SECURE);
- http_only = sqlite3_column_int (stmt, COL_HTTP_ONLY);
-
- if (now >= expire_time)
- {
- /* Cookie expired, remove it from database */
- query = sqlite3_mprintf (QUERY_DELETE, name, host);
- sqlite3_exec (http_cookies->db, QUERY_DELETE, NULL, NULL, NULL);
- sqlite3_free (query);
- result = sqlite3_step (stmt);
- continue;
- }
- max_age = (expire_time - now <= G_MAXINT ? expire_time - now : G_MAXINT);
- cookie = soup_cookie_new (name, value, host, path, max_age);
-
- if (secure)
- soup_cookie_set_secure (cookie, TRUE);
- if (http_only)
- soup_cookie_set_http_only (cookie, TRUE);
-
- soup_cookie_jar_add_cookie (http_cookies->jar, cookie);
- result = sqlite3_step (stmt);
- }
-
- if (stmt)
- {
- sqlite3_reset (stmt);
- sqlite3_clear_bindings (stmt);
- }
+ exec_query_with_try_create_table (http_cookies->db, QUERY_ALL, callback, http_cookies->jar);
}
static void
katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar* jar,
@@ -207,14 +213,14 @@ katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar* jar,
}
}
- if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
+ if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
http_cookies->counter++;
if (old_cookie) {
query = sqlite3_mprintf (QUERY_DELETE,
old_cookie->name,
old_cookie->domain);
- sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL);
+ exec_query_with_try_create_table (http_cookies->db, query, NULL, NULL);
sqlite3_free (query);
}
@@ -228,7 +234,7 @@ katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar* jar,
expires,
new_cookie->secure,
new_cookie->http_only);
- sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL);
+ exec_query_with_try_create_table (http_cookies->db, query, NULL, NULL);
sqlite3_free (query);
}
}
diff --git a/katze/katze-http-cookies.c b/katze/katze-http-cookies.c
index 1ccb8d9a..a25f62a1 100644
--- a/katze/katze-http-cookies.c
+++ b/katze/katze-http-cookies.c
@@ -211,7 +211,7 @@ katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies)
goto failed;
g_free (temporary_filename);
- if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
+ if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
{
g_print ("KatzeHttpCookies: %d cookies changed\n", http_cookies->counter);
http_cookies->counter = 0;
@@ -223,7 +223,7 @@ failed:
fclose (f);
g_unlink (temporary_filename);
g_free (temporary_filename);
- if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
+ if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
g_print ("KatzeHttpCookies: Failed to write '%s'\n",
http_cookies->filename);
return FALSE;
@@ -263,7 +263,7 @@ katze_http_cookies_jar_changed_cb (SoupCookieJar* jar,
}
}
- if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
+ if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
http_cookies->counter++;
if (!http_cookies->timeout && (old_cookie || new_cookie->expires))
diff --git a/katze/katze-item.c b/katze/katze-item.c
index 43ed856c..1d3a3ee7 100644
--- a/katze/katze-item.c
+++ b/katze/katze-item.c
@@ -15,8 +15,6 @@
#include
-#include
-
/**
* SECTION:katze-item
* @short_description: A useful item
@@ -317,8 +315,6 @@ katze_item_set_name (KatzeItem* item,
g_return_if_fail (KATZE_IS_ITEM (item));
katze_assign (item->name, g_strdup (name));
- if (item->parent)
- katze_array_update ((KatzeArray*)item->parent);
g_object_notify (G_OBJECT (item), "name");
}
@@ -418,86 +414,9 @@ katze_item_set_icon (KatzeItem* item,
g_return_if_fail (KATZE_IS_ITEM (item));
katze_item_set_meta_string (item, "icon", icon);
- if (item->parent)
- katze_array_update ((KatzeArray*)item->parent);
g_object_notify (G_OBJECT (item), "icon");
}
-/**
- * katze_item_get_pixbuf:
- * @item: a #KatzeItem
- * @widget: a #GtkWidget, or %NULL
- *
- * Retrieves a #GdkPixbuf fit to display @item.
- *
- * Return value: the icon of the item
- *
- * Since: 0.4.6
- **/
-GdkPixbuf*
-katze_item_get_pixbuf (KatzeItem* item,
- GtkWidget* widget)
-{
- GdkPixbuf* pixbuf;
-
- g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
-
- if (item->uri == NULL)
- return NULL;
-
- #if WEBKIT_CHECK_VERSION (1, 8, 0)
- /* FIXME: Don't hard-code icon size */
- if ((pixbuf = webkit_favicon_database_try_get_favicon_pixbuf (
- webkit_get_favicon_database (), item->uri, 16, 16)))
- return pixbuf;
- #else
- if ((pixbuf = g_object_get_data (G_OBJECT (item), "pixbuf")))
- return pixbuf;
- #endif
- return NULL;
-}
-
-/**
- * katze_item_get_image:
- * @item: a #KatzeItem
- *
- * Retrieves a #GtkImage fit to display @item.
- *
- * Return value: the icon of the item
- *
- * Since: 0.4.4
- **/
-GtkWidget*
-katze_item_get_image (KatzeItem* item)
-{
- GtkWidget* image;
- GdkPixbuf* pixbuf;
- const gchar* icon;
-
- g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
-
- if (KATZE_ITEM_IS_FOLDER (item))
- image = gtk_image_new_from_stock (GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU);
- /* FIXME: Pass widget for icon size */
- else if ((pixbuf = katze_item_get_pixbuf (item, NULL)))
- image = gtk_image_new_from_pixbuf (pixbuf);
- else if ((icon = katze_item_get_icon (item)) && !strchr (icon, '/'))
- image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_MENU);
- else
- {
- if (!(icon && (pixbuf = katze_load_cached_icon (icon, NULL))))
- pixbuf = katze_load_cached_icon (item->uri, NULL);
- if (pixbuf)
- {
- image = gtk_image_new_from_pixbuf (pixbuf);
- g_object_unref (pixbuf);
- }
- else
- image = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
- }
- return image;
-}
-
/**
* katze_item_get_token:
* @item: a #KatzeItem
@@ -608,22 +527,17 @@ katze_item_set_meta_data_value (KatzeItem* item,
* Return value: a string, or %NULL
*
* Since: 0.1.8
- *
- * Since 0.4.4 "" is treated like %NULL.
**/
const gchar*
katze_item_get_meta_string (KatzeItem* item,
const gchar* key)
{
- const gchar* value;
-
g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
g_return_val_if_fail (key != NULL, NULL);
if (g_str_has_prefix (key, "midori:"))
key = &key[7];
- value = g_hash_table_lookup (item->metadata, key);
- return value && *value ? value : NULL;
+ return g_hash_table_lookup (item->metadata, key);
}
/**
diff --git a/katze/katze-item.h b/katze/katze-item.h
index 0bd44fdb..40c250f8 100644
--- a/katze/katze-item.h
+++ b/katze/katze-item.h
@@ -12,7 +12,7 @@
#ifndef __KATZE_ITEM_H__
#define __KATZE_ITEM_H__
-#include
+#include
G_BEGIN_DECLS
@@ -91,13 +91,6 @@ void
katze_item_set_icon (KatzeItem* item,
const gchar* icon);
-GdkPixbuf*
-katze_item_get_pixbuf (KatzeItem* item,
- GtkWidget* widget);
-
-GtkWidget*
-katze_item_get_image (KatzeItem* item);
-
const gchar*
katze_item_get_token (KatzeItem* item);
diff --git a/katze/katze-net.c b/katze/katze-net.c
index 10b55bff..f873d08c 100644
--- a/katze/katze-net.c
+++ b/katze/katze-net.c
@@ -27,6 +27,9 @@
struct _KatzeNet
{
GObject parent_instance;
+
+ gchar* cache_path;
+ guint cache_size;
};
struct _KatzeNetClass
@@ -51,14 +54,37 @@ katze_net_class_init (KatzeNetClass* class)
static void
katze_net_init (KatzeNet* net)
{
+ net->cache_path = g_build_filename (g_get_user_cache_dir (),
+ PACKAGE_NAME, NULL);
}
static void
katze_net_finalize (GObject* object)
{
+ KatzeNet* net = KATZE_NET (object);
+
+ katze_assign (net->cache_path, NULL);
+
G_OBJECT_CLASS (katze_net_parent_class)->finalize (object);
}
+static KatzeNet*
+katze_net_new (void)
+{
+ static KatzeNet* net = NULL;
+
+ if (!net)
+ {
+ net = g_object_new (KATZE_TYPE_NET, NULL);
+ /* Since this is a "singleton", keep an extra reference */
+ g_object_ref (net);
+ }
+ else
+ g_object_ref (net);
+
+ return net;
+}
+
typedef struct
{
KatzeNetStatusCb status_cb;
@@ -83,28 +109,29 @@ katze_net_get_cached_path (KatzeNet* net,
const gchar* uri,
const gchar* subfolder)
{
+ gchar* cache_path;
gchar* checksum;
gchar* extension;
gchar* cached_filename;
gchar* cached_path;
+ net = katze_net_new ();
+
+ if (subfolder)
+ cache_path = g_build_filename (net->cache_path, subfolder, NULL);
+ else
+ cache_path = net->cache_path;
+ katze_mkdir_with_parents (cache_path, 0700);
checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
+
extension = g_strrstr (uri, ".");
cached_filename = g_strdup_printf ("%s%s", checksum,
extension ? extension : "");
g_free (checksum);
-
+ cached_path = g_build_filename (cache_path, cached_filename, NULL);
+ g_free (cached_filename);
if (subfolder)
- {
- gchar* cache_path = g_build_filename (midori_paths_get_cache_dir (), subfolder, NULL);
- katze_mkdir_with_parents (cache_path, 0700);
- cached_path = g_build_filename (cache_path, cached_filename, NULL);
g_free (cache_path);
- }
- else
- cached_path = g_build_filename (midori_paths_get_cache_dir (), cached_filename, NULL);
-
- g_free (cached_filename);
return cached_path;
}
diff --git a/katze/katze-net.h b/katze/katze-net.h
index eea2df41..5658ff47 100644
--- a/katze/katze-net.h
+++ b/katze/katze-net.h
@@ -14,6 +14,8 @@
#include "katze-utils.h"
+#include
+
G_BEGIN_DECLS
#define KATZE_TYPE_NET \
diff --git a/katze/katze-preferences.c b/katze/katze-preferences.c
index 6108fd4a..e4fd18aa 100644
--- a/katze/katze-preferences.c
+++ b/katze/katze-preferences.c
@@ -15,13 +15,6 @@
#include
#endif
-#ifdef HAVE_GRANITE
- #if HAVE_OSX
- #error FIXME granite on OSX is not implemented
- #endif
- #include
-#endif
-
#if HAVE_HILDON
#include "katze-scrolled.h"
#include
@@ -110,8 +103,11 @@ katze_preferences_init (KatzePreferences* preferences)
gtk_dialog_add_buttons (GTK_DIALOG (preferences),
GTK_STOCK_HELP, GTK_RESPONSE_HELP,
NULL);
- katze_widget_add_class (gtk_dialog_get_widget_for_response (
- GTK_DIALOG (preferences), GTK_RESPONSE_HELP), "help_button");
+ #if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_style_context_add_class (gtk_widget_get_style_context (
+ gtk_dialog_get_widget_for_response (GTK_DIALOG (preferences),
+ GTK_RESPONSE_HELP)), "help_button");
+ #endif
gtk_dialog_add_buttons (GTK_DIALOG (preferences),
#if HAVE_HILDON
@@ -206,12 +202,7 @@ katze_preferences_prepare (KatzePreferences* preferences)
g_signal_connect (priv->scrolled, "destroy",
G_CALLBACK (gtk_widget_destroyed), &priv->scrolled);
#else
- #ifdef HAVE_GRANITE
- /* FIXME: granite: should return GtkWidget* like GTK+ */
- priv->notebook = (GtkWidget*)granite_widgets_static_notebook_new (FALSE);
- #else
priv->notebook = gtk_notebook_new ();
- #endif
gtk_container_set_border_width (GTK_CONTAINER (priv->notebook), 6);
#if HAVE_OSX
@@ -305,14 +296,8 @@ katze_preferences_add_category (KatzePreferences* preferences,
priv->sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_widget_show (priv->page);
gtk_container_set_border_width (GTK_CONTAINER (priv->page), 4);
- #ifdef HAVE_GRANITE
- granite_widgets_static_notebook_append_page (
- GRANITE_WIDGETS_STATIC_NOTEBOOK (priv->notebook),
- priv->page, GTK_LABEL (gtk_label_new (label)));
- #else
gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
priv->page, gtk_label_new (label));
- #endif
#if HAVE_OSX
priv->toolbutton = GTK_WIDGET (priv->toolbutton ?
gtk_radio_tool_button_new_from_widget (
diff --git a/katze/katze-throbber.c b/katze/katze-throbber.c
index 85c206fc..d8c71b93 100644
--- a/katze/katze-throbber.c
+++ b/katze/katze-throbber.c
@@ -97,12 +97,12 @@ katze_throbber_realize (GtkWidget* widget);
#if GTK_CHECK_VERSION (3, 0, 0)
static void
katze_throbber_get_preferred_height (GtkWidget *widget,
- gint *minimal_height,
- gint *natural_height);
+ gint *minimal_width,
+ gint *natural_width);
static void
katze_throbber_get_preferred_width (GtkWidget *widget,
- gint *minimal_width,
- gint *natural_width);
+ gint *minimal_width,
+ gint *natural_width);
#endif
static void
katze_throbber_unrealize (GtkWidget* widget);
@@ -495,8 +495,8 @@ katze_throbber_set_animated (KatzeThrobber* throbber,
(GSourceFunc)katze_throbber_timeout,
throbber,
(GDestroyNotify)katze_throbber_timeout_destroy);
- #endif
gtk_widget_queue_draw (GTK_WIDGET (throbber));
+ #endif
g_object_notify (G_OBJECT (throbber), "animated");
}
@@ -857,14 +857,14 @@ katze_throbber_size_request (GtkWidget* widget,
#if GTK_CHECK_VERSION (3, 0, 0)
static void
katze_throbber_get_preferred_height (GtkWidget *widget,
- gint *minimal_height,
- gint *natural_height)
+ gint *minimal_width,
+ gint *natural_width)
{
GtkRequisition requisition;
katze_throbber_size_request (widget, &requisition);
- *minimal_height = *natural_height = requisition.height;
+ *minimal_width = *natural_width = requisition.height;
}
static void
@@ -902,7 +902,6 @@ katze_throbber_aligned_coords (GtkWidget* widget,
#endif
#if GTK_CHECK_VERSION (3, 0, 0)
- allocation.x = allocation.y = 0;
allocation.width = gtk_widget_get_allocated_width (widget);
allocation.height = gtk_widget_get_allocated_height (widget);
gtk_widget_get_preferred_size (widget, &requisition, NULL);
diff --git a/katze/katze-utils.c b/katze/katze-utils.c
index 9c5ef9c6..ac9df02d 100644
--- a/katze/katze-utils.c
+++ b/katze/katze-utils.c
@@ -277,6 +277,7 @@ proxy_combo_box_changed_cb (GtkComboBox* button,
if (custom_value)
{
+ #if GTK_CHECK_VERSION (2, 12, 0)
if (value == custom_value)
gtk_widget_set_tooltip_text (GTK_WIDGET (button), NULL);
else
@@ -285,6 +286,7 @@ proxy_combo_box_changed_cb (GtkComboBox* button,
gtk_widget_set_tooltip_text (GTK_WIDGET (button), custom_text);
g_free (custom_text);
}
+ #endif
}
}
#endif
@@ -329,13 +331,7 @@ proxy_widget_string_destroy_cb (GtkWidget* proxy,
static GList*
katze_app_info_get_all_for_category (const gchar* category)
{
- #ifdef _WIN32
- /* FIXME: Real filtering by category would be better */
- const gchar* content_type = g_content_type_from_mime_type (category);
- GList* all_apps = g_app_info_get_all_for_type (content_type);
- #else
GList* all_apps = g_app_info_get_all ();
- #endif
GList* apps = NULL;
guint i = 0;
GAppInfo* info;
@@ -521,8 +517,14 @@ katze_property_proxy (gpointer object,
string = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (widget),
string ? string : "");
+ #if GTK_CHECK_VERSION (2, 12, 0)
g_signal_connect (widget, "file-set",
G_CALLBACK (proxy_uri_file_set_cb), object);
+ #else
+ if (pspec->flags & G_PARAM_WRITABLE)
+ g_signal_connect (widget, "selection-changed",
+ G_CALLBACK (proxy_uri_file_set_cb), object);
+ #endif
}
else if (type == G_TYPE_PARAM_STRING && (_hint == I_("font")
|| _hint == I_("font-monospace")))
@@ -810,10 +812,11 @@ katze_property_proxy (gpointer object,
G_CALLBACK (proxy_entry_focus_out_event_cb), object);
g_object_set_data_full (G_OBJECT (entry), "property",
g_strdup (custom), g_free);
- gtk_widget_set_tooltip_text (widget, NULL);
}
+ #if GTK_CHECK_VERSION (2, 12, 0)
else
gtk_widget_set_tooltip_text (widget, custom_text);
+ #endif
g_free (custom_text);
@@ -828,6 +831,10 @@ katze_property_proxy (gpointer object,
widget = gtk_label_new (gettext (nick));
g_free (string);
+ #if GTK_CHECK_VERSION (2, 12, 0)
+ if (!gtk_widget_get_tooltip_text (widget))
+ gtk_widget_set_tooltip_text (widget, g_param_spec_get_blurb (pspec));
+ #endif
gtk_widget_set_sensitive (widget, pspec->flags & G_PARAM_WRITABLE);
g_object_set_data_full (G_OBJECT (widget), "property",
@@ -868,8 +875,16 @@ katze_property_label (gpointer object,
return gtk_label_new (property);
}
+ #ifdef HAVE_HILDON_2_2
+ if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_ENUM)
+ return gtk_label_new (NULL);
+ #endif
+
nick = g_param_spec_get_nick (pspec);
widget = gtk_label_new (nick);
+ #if GTK_CHECK_VERSION (2, 12, 0)
+ gtk_widget_set_tooltip_text (widget, g_param_spec_get_blurb (pspec));
+ #endif
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
return widget;
@@ -895,29 +910,21 @@ katze_widget_popup_position_menu (GtkMenu* menu,
GtkRequisition widget_req;
KatzePopupInfo* info = user_data;
GtkWidget* widget = info->widget;
- GdkWindow* window = gtk_widget_get_window (widget);
gint widget_height;
- if (!window)
- return;
-
- #if !GTK_CHECK_VERSION (3, 0, 0)
- if (GTK_IS_ENTRY (widget))
- window = gdk_window_get_parent (window);
- #endif
+ gtk_widget_get_allocation (widget, &allocation);
/* Retrieve size and position of both widget and menu */
- gtk_widget_get_allocation (widget, &allocation);
- gdk_window_get_origin (window, &wx, &wy);
- wx += allocation.x;
- wy += allocation.y;
- #if GTK_CHECK_VERSION (3, 0, 0)
- gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
- gtk_widget_get_preferred_size (widget, &widget_req, NULL);
- #else
+ if (!gtk_widget_get_has_window (widget))
+ {
+ gdk_window_get_position (gtk_widget_get_window (widget), &wx, &wy);
+ wx += allocation.x;
+ wy += allocation.y;
+ }
+ else
+ gdk_window_get_origin (gtk_widget_get_window (widget), &wx, &wy);
gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
gtk_widget_size_request (widget, &widget_req);
- #endif
menu_width = menu_req.width;
widget_height = widget_req.height; /* Better than allocation.height */
@@ -1183,16 +1190,6 @@ katze_strip_mnemonics (const gchar* original)
return result;
}
-const gchar*
-katze_skip_whitespace (const gchar* str)
-{
- if (str == NULL)
- return NULL;
- while (*str == ' ' || *str == '\t' || *str == '\n')
- str++;
- return str;
-}
-
/**
* katze_object_has_property:
* @object: a #GObject
@@ -1502,7 +1499,8 @@ katze_load_cached_icon (const gchar* uri,
filename = g_strdup_printf ("%s%s", checksum, ext ? ext : "");
g_free (icon_uri);
g_free (checksum);
- path = g_build_filename (midori_paths_get_cache_dir (), "icons", filename, NULL);
+ path = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
+ "icons", filename, NULL);
g_free (filename);
if ((icon = gdk_pixbuf_new_from_file_at_size (path, 16, 16, NULL)))
{
@@ -1522,15 +1520,6 @@ katze_uri_entry_changed_cb (GtkWidget* entry,
{
const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry));
gboolean valid = midori_uri_is_location (uri);
- if (!valid && g_object_get_data (G_OBJECT (entry), "allow_%s"))
- valid = uri && g_str_has_prefix (uri, "%s");
- if (!valid)
- valid = midori_uri_is_ip_address (uri);
-
- #if GTK_CHECK_VERSION (3, 2, 0)
- g_object_set_data (G_OBJECT (entry), "invalid", GINT_TO_POINTER (*uri && !valid));
- gtk_widget_queue_draw (entry);
- #else
if (*uri && !valid)
{
GdkColor bg_color = { 0 };
@@ -1545,34 +1534,11 @@ katze_uri_entry_changed_cb (GtkWidget* entry,
gtk_widget_modify_base (entry, GTK_STATE_NORMAL, NULL);
gtk_widget_modify_text (entry, GTK_STATE_NORMAL, NULL);
}
- #endif
if (other_widget != NULL)
gtk_widget_set_sensitive (other_widget, valid);
}
-#if GTK_CHECK_VERSION (3, 2, 0)
-static gboolean
-katze_uri_entry_draw_cb (GtkWidget* entry,
- cairo_t* cr,
- GtkWidget* other_widget)
-{
- const GdkRGBA color = { 0.9, 0., 0., 1. };
- double width = gtk_widget_get_allocated_width (entry);
- double height = gtk_widget_get_allocated_height (entry);
-
- if (!g_object_get_data (G_OBJECT (entry), "invalid"))
- return FALSE;
-
- /* FIXME: error-underline-color requires GtkTextView */
- gdk_cairo_set_source_rgba (cr, &color);
-
- pango_cairo_show_error_underline (cr, width * 0.15, height / 1.9,
- width * 0.75, height / 1.9 / 2);
- return TRUE;
-}
-#endif
-
/**
* katze_uri_entry_new:
* @other_widget: a #GtkWidget, or %NULL
@@ -1590,28 +1556,11 @@ GtkWidget*
katze_uri_entry_new (GtkWidget* other_widget)
{
GtkWidget* entry = gtk_entry_new ();
-
- gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY,
- g_themed_icon_new_with_default_fallbacks ("text-html-symbolic"));
g_signal_connect (entry, "changed",
G_CALLBACK (katze_uri_entry_changed_cb), other_widget);
- #if GTK_CHECK_VERSION (3, 2, 0)
- g_signal_connect_after (entry, "draw",
- G_CALLBACK (katze_uri_entry_draw_cb), other_widget);
- #endif
return entry;
}
-void
-katze_widget_add_class (GtkWidget* widget,
- const gchar* class_name)
-{
- #if GTK_CHECK_VERSION (3,0,0)
- GtkStyleContext* context = gtk_widget_get_style_context (widget);
- gtk_style_context_add_class (context, class_name);
- #endif
-}
-
/**
* katze_assert_str_equal:
* @input: a string
diff --git a/katze/katze-utils.h b/katze/katze-utils.h
index bf97cbff..643b4238 100644
--- a/katze/katze-utils.h
+++ b/katze/katze-utils.h
@@ -58,20 +58,6 @@ G_BEGIN_DECLS
**/
#define katze_strv_assign(lvalue, rvalue) lvalue = (g_strfreev (lvalue), rvalue)
-/**
- * katze_str_non_null:
- * @str: a string, or %NULL
- *
- * Returns "" if @str is %NULL.
- *
- * Since: 0.4.4
- **/
-static inline const gchar*
-katze_str_non_null (const gchar* str)
-{
- return str ? str : "";
-}
-
GtkWidget*
katze_property_proxy (gpointer object,
const gchar* property,
@@ -115,9 +101,6 @@ katze_bookmark_populate_tree_view (KatzeArray* array,
gchar*
katze_strip_mnemonics (const gchar* original);
-const gchar*
-katze_skip_whitespace (const gchar* str);
-
gboolean
katze_object_has_property (gpointer object,
const gchar* property);
@@ -160,10 +143,6 @@ katze_load_cached_icon (const gchar* uri,
GtkWidget*
katze_uri_entry_new (GtkWidget* other_widget);
-void
-katze_widget_add_class (GtkWidget* widget,
- const gchar* class_name);
-
void
katze_assert_str_equal (const gchar* input,
const gchar* result,
diff --git a/katze/katze.vapi b/katze/katze.vapi
deleted file mode 100644
index 1627568b..00000000
--- a/katze/katze.vapi
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Copyright (C) 2012 André Stösel
- This file is licensed under the terms of the expat license, see the file EXPAT. */
-
-[CCode (cprefix = "Katze", lower_case_cprefix = "katze_")]
-namespace Katze {
- static string assert_str_equal (string input, string result, string expected);
-
- [CCode (cheader_filename = "katze/katze.h")]
- public class Array : Katze.Item {
- public Array (GLib.Type type);
- public void add_item (GLib.Object item);
- }
-
- [CCode (cheader_filename = "katze/katze.h")]
- public class Item : GLib.Object {
- public string? uri { get; set; }
- public string? name { get; set; }
- public string? text { get; set; }
-
- public bool get_meta_boolean (string key);
- public int64 get_meta_integer (string key);
- public void set_meta_integer (string key, int64 value);
- }
-}
-
diff --git a/katze/midori-hsts.vala b/katze/midori-hsts.vala
deleted file mode 100644
index a878a6ec..00000000
--- a/katze/midori-hsts.vala
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- Copyright (C) 2012 Christian Dywan
-
- 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.
-*/
-
-namespace Midori {
- public class HSTS : GLib.Object, Soup.SessionFeature {
- public class Directive {
- public Soup.Date? expires = null;
- public bool sub_domains = false;
-
- public Directive (bool include_sub_domains) {
- expires = new Soup.Date.from_now (int.MAX);
- sub_domains = include_sub_domains;
- }
-
- public Directive.from_header (string header) {
- var param_list = Soup.header_parse_param_list (header);
- if (param_list == null)
- return;
-
- string? max_age = param_list.lookup ("max-age");
- if (max_age != null)
- expires = new Soup.Date.from_now (max_age.to_int ());
- // if (param_list.lookup_extended ("includeSubDomains", null, null))
- if ("includeSubDomains" in header)
- sub_domains = true;
- Soup.header_free_param_list (param_list);
- }
-
- public bool is_valid () {
- return expires != null && !expires.is_past ();
- }
- }
-
- File file;
- HashTable whitelist;
- bool debug = false;
-
- public HSTS (owned string filename) {
- whitelist = new HashTable (str_hash, str_equal);
- read_cache (File.new_for_path (Paths.get_preset_filename (null, "hsts")));
- file = File.new_for_path (filename);
- read_cache (file);
- if (strcmp (Environment.get_variable ("MIDORI_DEBUG"), "hsts") == 0)
- debug = true;
- }
-
- async void read_cache (File file) {
- try {
- var stream = new DataInputStream (yield file.read_async ());
- do {
- string? line = yield stream.read_line_async ();
- if (line == null)
- break;
- string[] parts = line.split (" ", 2);
- if (parts[0] == null || parts[1] == null)
- break;
- var directive = new Directive.from_header (parts[1]);
- if (directive.is_valid ())
- append_to_whitelist (parts[0], directive);
- } while (true);
- }
- catch (Error error) { }
- }
-
- /* No sub-features */
- public bool add_feature (Type type) { return false; }
- public bool remove_feature (Type type) { return false; }
- public bool has_feature (Type type) { return false; }
-
- public void attach (Soup.Session session) { session.request_queued.connect (queued); }
- public void detach (Soup.Session session) { /* FIXME disconnect */ }
-
- /* Never called but required by the interface */
- public void request_started (Soup.Session session, Soup.Message msg, Soup.Socket socket) { }
- public void request_queued (Soup.Session session, Soup.Message message) { }
- public void request_unqueued (Soup.Session session, Soup.Message msg) { }
-
- bool should_secure_host (string host) {
- Directive? directive = whitelist.lookup (host);
- if (directive == null)
- directive = whitelist.lookup ("*." + host);
- return directive != null && directive.is_valid ();
- }
-
- void queued (Soup.Session session, Soup.Message message) {
- if (should_secure_host (message.uri.host)) {
- message.uri.set_scheme ("https");
- session.requeue_message (message);
- if (debug)
- stdout.printf ("HSTS: Enforce %s\n", message.uri.host);
- }
- else if (message.uri.scheme == "http")
- message.finished.connect (strict_transport_security_handled);
- }
-
- void append_to_whitelist (string host, Directive directive) {
- whitelist.insert (host, directive);
- if (directive.sub_domains)
- whitelist.insert ("*." + host, directive);
- }
-
- async void append_to_cache (string host, string header) {
- if (Midori.Paths.is_readonly ())
- return;
-
- try {
- var stream = file.append_to/* FIXME _async*/ (FileCreateFlags.NONE);
- yield stream.write_async ((host + " " + header + "\n").data);
- yield stream.flush_async ();
- }
- catch (Error error) {
- critical ("Failed to update %s: %s", file.get_path (), error.message);
- }
- }
-
- void strict_transport_security_handled (Soup.Message message) {
- if (message == null || message.uri == null)
- return;
-
- unowned string? hsts = message.response_headers.get_one ("Strict-Transport-Security");
- if (hsts == null)
- return;
-
- var directive = new Directive.from_header (hsts);
- if (directive.is_valid ()) {
- append_to_whitelist (message.uri.host, directive);
- append_to_cache (message.uri.host, hsts);
- }
- if (debug)
- stdout.printf ("HSTS: '%s' sets '%s' valid? %s\n",
- message.uri.host, hsts, directive.is_valid ().to_string ());
- }
-
- }
-}
diff --git a/katze/midori-paths.vala b/katze/midori-paths.vala
deleted file mode 100644
index 16efc739..00000000
--- a/katze/midori-paths.vala
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- Copyright (C) 2012 Christian Dywan
-
- 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.
-*/
-
-namespace GLib {
- #if HAVE_WIN32
- extern static string win32_get_package_installation_directory_of_module (void* hmodule = null);
- #endif
-}
-
-extern const string LIBDIR;
-extern const string MDATADIR;
-extern const string PACKAGE_NAME;
-extern const string SYSCONFDIR;
-extern const string MIDORI_VERSION_SUFFIX;
-
-namespace Midori {
- public enum RuntimeMode {
- UNDEFINED,
- NORMAL,
- APP,
- PRIVATE,
- PORTABLE
- }
-
- namespace Paths {
- static string? exec_path = null;
- static string[] command_line = null;
- static RuntimeMode mode = RuntimeMode.UNDEFINED;
-
- static string? config_dir = null;
- static string? readonly_dir = null;
- static string? cache_dir = null;
- static string? user_data_dir = null;
- static string? tmp_dir = null;
-
- public static string get_readonly_config_dir () {
- assert (mode != RuntimeMode.UNDEFINED);
- return readonly_dir ?? config_dir;
- }
-
- public static string get_readonly_config_filename (string filename) {
- assert (mode != RuntimeMode.UNDEFINED);
- return Path.build_path (Path.DIR_SEPARATOR_S,
- readonly_dir ?? config_dir, filename);
- }
-
- public bool is_readonly () {
- assert (mode != RuntimeMode.UNDEFINED);
- return readonly_dir != null;
- }
-
- public static void init (RuntimeMode new_mode, string? config_base) {
- assert (mode == RuntimeMode.UNDEFINED);
- assert (new_mode != RuntimeMode.UNDEFINED);
- mode = new_mode;
- if (mode == RuntimeMode.PORTABLE) {
- config_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- exec_path, "profile", "config");
- cache_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- exec_path, "profile", "cache");
- user_data_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- exec_path, "profile", "misc");
- tmp_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- exec_path, "profile", "tmp");
- }
- else if (mode == RuntimeMode.PRIVATE || mode == RuntimeMode.APP) {
- /* Use mock folders in development builds */
- if ("." in MIDORI_VERSION_SUFFIX)
- config_dir = cache_dir = user_data_dir = config_base;
- else
- config_dir = cache_dir = user_data_dir = "/";
- readonly_dir = config_base ?? Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_config_dir (), PACKAGE_NAME);
- tmp_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_tmp_dir (), "midori-" + Environment.get_user_name ());
- }
- else {
- config_dir = config_base ?? Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_config_dir (), PACKAGE_NAME);
- cache_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_cache_dir (), PACKAGE_NAME);
- user_data_dir = Environment.get_user_data_dir ();
- tmp_dir = Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_tmp_dir (), "midori-" + Environment.get_user_name ());
- }
- if (strcmp (Environment.get_variable ("MIDORI_DEBUG"), "paths") == 0) {
- stdout.printf ("config: %s\ncache: %s\nuser_data: %s\ntmp: %s\n",
- config_dir, cache_dir, user_data_dir, tmp_dir);
- }
- }
-
- public static unowned string get_config_dir () {
- assert (config_dir != null);
- return config_dir;
- }
-
- public static string get_config_filename (string filename) {
- assert (mode != RuntimeMode.UNDEFINED);
- assert (config_dir != null);
- return Path.build_path (Path.DIR_SEPARATOR_S, config_dir, filename);
- }
-
- public static unowned string get_cache_dir () {
- assert (cache_dir != null);
- return cache_dir;
- }
-
- public static unowned string get_user_data_dir () {
- assert (user_data_dir != null);
- return user_data_dir;
- }
-
- public static unowned string get_tmp_dir () {
- assert (tmp_dir != null);
- return tmp_dir;
- }
-
- public static void init_exec_path (string[] new_command_line) {
- assert (command_line == null);
- command_line = new_command_line;
- #if HAVE_WIN32
- exec_path = win32_get_package_installation_directory_of_module ();
- #else
- string? executable;
- try {
- if (!Path.is_absolute (command_line[0])) {
- string program = Environment.find_program_in_path (command_line[0]);
- if (FileUtils.test (program, FileTest.IS_SYMLINK))
- executable = FileUtils.read_link (program);
- else
- executable = program;
- }
- else
- executable = FileUtils.read_link (command_line[0]);
- }
- catch (Error error) {
- executable = command_line[0];
- }
-
- exec_path = File.new_for_path (executable).get_parent ().get_parent ().get_path ();
- #endif
- if (strcmp (Environment.get_variable ("MIDORI_DEBUG"), "paths") == 0) {
- stdout.printf ("command_line: %s\nexec_path: %s\nres: %s\nlib: %s\n",
- get_command_line_str (), exec_path,
- get_res_filename (""), get_lib_path (PACKAGE_NAME));
- }
- }
-
- public static unowned string[] get_command_line () {
- assert (command_line != null);
- return command_line;
- }
-
- public static string get_command_line_str () {
- assert (command_line != null);
- return "".joinv (" ", command_line).replace (Environment.get_home_dir (), "~");
- }
-
- public static string get_lib_path (string package) {
- assert (command_line != null);
- #if HAVE_WIN32
- return Path.build_filename (exec_path, "lib", package);
- #else
- string path = Path.build_filename (exec_path, "lib", package);
- if (Posix.access (path, Posix.F_OK) == 0)
- return path;
-
- if (package == PACKAGE_NAME) {
- /* Fallback to build folder */
- path = Path.build_filename ((File.new_for_path (exec_path).get_path ()), "extensions");
- if (Posix.access (path, Posix.F_OK) == 0)
- return path;
- }
-
- return Path.build_filename (LIBDIR, PACKAGE_NAME);
- #endif
- }
-
- public static string get_res_filename (string filename) {
- assert (command_line != null);
- #if HAVE_WIN32
- return Path.build_filename (exec_path, "share", PACKAGE_NAME, "res", filename);
- #else
- string path = Path.build_filename (exec_path, "share", PACKAGE_NAME, "res", filename);
- if (Posix.access (path, Posix.F_OK) == 0)
- return path;
-
- /* Fallback to build folder */
- path = Path.build_filename ((File.new_for_path (exec_path)
- .get_parent ().get_parent ().get_path ()), "data", filename);
- if (Posix.access (path, Posix.F_OK) == 0)
- return path;
-
- return Path.build_filename (MDATADIR, PACKAGE_NAME, "res", filename);
- #endif
- }
-
- public static string get_data_filename (string filename, bool res) {
- assert (command_line != null);
- string res1 = res ? PACKAGE_NAME : "";
- string res2 = res ? "res" : "";
-
- #if HAVE_WIN32
- return Path.build_filename (exec_path, "share", res1, res2, filename);
- #else
- string path = Path.build_filename (get_user_data_dir (), res1, res2, filename);
- if (Posix.access (path, Posix.F_OK) == 0)
- return path;
-
- foreach (string data_dir in Environment.get_system_data_dirs ()) {
- path = Path.build_filename (data_dir, res1, res2, filename);
- if (Posix.access (path, Posix.F_OK) == 0)
- return path;
- }
-
- return Path.build_filename (MDATADIR, res1, res2, filename);
- #endif
- }
-
- public static string get_preset_filename (string? folder, string filename) {
- assert (config_dir != null);
-
- #if HAVE_WIN32
- return Path.build_filename (exec_path, "etc", "xdg", PACKAGE_NAME, folder ?? "", filename);
- #else
- foreach (string config_dir in Environment.get_system_config_dirs ()) {
- string path = Path.build_filename (config_dir, PACKAGE_NAME, folder ?? "", filename);
- if (Posix.access (path, Posix.F_OK) == 0)
- return path;
- }
-
- return Path.build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, folder ?? "", filename);
- #endif
- }
- }
-}
diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala
index 05ebceab..e01ba484 100644
--- a/katze/midori-uri.vala
+++ b/katze/midori-uri.vala
@@ -85,9 +85,6 @@ namespace Midori {
if (uri == null)
return keywords;
string escaped = GLib.Uri.escape_string (keywords, ":/", true);
- /* Allow DuckDuckGo to distinguish Midori and in turn share revenue */
- if (uri == "https://duckduckgo.com/?q=%s")
- return "https://duckduckgo.com/?q=%s&t=midori".printf (escaped);
if (uri.str ("%s") != null)
return uri.printf (escaped);
return uri + escaped;
@@ -114,69 +111,43 @@ namespace Midori {
|| (uri.has_prefix ("geo:") && uri.chr (-1, ',') != null)
|| uri.has_prefix ("javascript:"));
}
-
+ public static bool is_email (string? uri) {
+ return uri != null
+ && (uri.chr (-1, '@') != null || uri.has_prefix ("mailto:"))
+ /* :// and @ together would mean login credentials */
+ && uri.str ("://") == null;
+ }
public static bool is_ip_address (string? uri) {
/* Quick check for IPv4 or IPv6, no validation.
FIXME: Schemes are not handled
hostname_is_ip_address () is not used because
we'd have to separate the path from the URI first. */
- if (uri == null)
- return false;
- /* Skip leading user/ password */
- if (uri.chr (-1, '@') != null)
- return is_ip_address (uri.split ("@")[1]);
- /* IPv4 */
- if (uri[0] != '0' && uri[0].isdigit () && (uri.chr (4, '.') != null))
- return true;
- /* IPv6 */
- if (uri[0].isalnum () && uri[1].isalnum ()
- && uri[2].isalnum () && uri[3].isalnum () && uri[4] == ':'
- && (uri[5] == ':' || uri[5].isalnum ()))
- return true;
- return false;
+ return uri != null && uri[0].isdigit ()
+ && (uri.chr (4, '.') != null || uri.chr (4, ':') != null);
}
public static bool is_valid (string? uri) {
return uri != null
&& uri.chr (-1, ' ') == null
&& (URI.is_location (uri) || uri.chr (-1, '.') != null);
}
-
- public static string? get_folder (string uri) {
- /* Base the start folder on the current view's uri if it is local */
- try {
- string? filename = Filename.from_uri (uri);
- if (filename != null) {
- string? dirname = Path.get_dirname (filename);
- if (dirname != null && FileUtils.test (dirname, FileTest.IS_DIR))
- return dirname;
- }
- }
- catch (Error error) { }
- return null;
- }
-
public static GLib.ChecksumType get_fingerprint (string uri,
out string checksum, out string label) {
/* http://foo.bar/baz/spam.eggs#!algo!123456 */
- unowned string display = null;
- GLib.ChecksumType type = (GLib.ChecksumType)int.MAX;
-
unowned string delimiter = "#!md5!";
+ unowned string display = _("MD5-Checksum:");
+ GLib.ChecksumType type = GLib.ChecksumType.MD5;
unowned string? fragment = uri.str (delimiter);
- if (fragment != null) {
- display = _("MD5-Checksum:");
- type = GLib.ChecksumType.MD5;
- }
-
- delimiter = "#!sha1!";
- fragment = uri.str (delimiter);
- if (fragment != null) {
+ if (fragment == null) {
+ delimiter = "#!sha1!";
display = _("SHA1-Checksum:");
type = GLib.ChecksumType.SHA1;
+ fragment = uri.str (delimiter);
+ }
+ if (fragment == null) {
+ type = (GLib.ChecksumType)int.MAX;
+ display = null;
}
-
- /* No SHA256: no known usage and no need for strong encryption */
if (&checksum != null)
checksum = fragment != null
diff --git a/midori/gtkiconentry.c b/midori/gtkiconentry.c
index c15ac1f6..44fddc03 100644
--- a/midori/gtkiconentry.c
+++ b/midori/gtkiconentry.c
@@ -1,5 +1,27 @@
+/*
+ * Copyright (C) 2004-2006 Christian Hammond.
+ * Copyright (C) 2008 Cody Russell
+ *
+ * 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
#include "gtkiconentry.h"
+#if GTK_CHECK_VERSION (2, 16, 0)
+
void
gtk_icon_entry_set_icon_from_pixbuf (GtkEntry* entry,
GtkEntryIconPosition position,
@@ -14,3 +36,1895 @@ gtk_icon_entry_set_icon_from_pixbuf (GtkEntry* entry,
gtk_entry_set_icon_activatable (entry, position, activatable);
}
+#else
+
+#include
+
+#if GTK_CHECK_VERSION (2, 14, 0)
+#define _GTK_IMAGE_GICON GTK_IMAGE_GICON
+#else
+#define _GTK_IMAGE_GICON 8
+#endif
+
+#ifndef GTK_PARAM_READABLE
+#define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
+#endif
+
+#ifndef GTK_PARAM_WRITABLE
+#define GTK_PARAM_WRITABLE G_PARAM_WRITABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
+#endif
+
+#ifndef GTK_PARAM_READWRITE
+#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
+#endif
+
+#define P_(s) (s)
+
+#define ICON_MARGIN 2
+#define MAX_ICONS 2
+
+#define IS_VALID_ICON_ENTRY_POSITION(pos) \
+ ((pos) == GTK_ICON_ENTRY_PRIMARY || \
+ (pos) == GTK_ICON_ENTRY_SECONDARY)
+
+typedef struct
+{
+ GdkPixbuf *pixbuf;
+ gboolean highlight;
+ gboolean hovered;
+ GdkWindow *window;
+ gchar *tooltip_text;
+ GdkCursorType cursor_type;
+ gboolean custom_cursor;
+ GtkImageType storage_type;
+ GIcon *gicon;
+ gchar *icon_name;
+ gboolean insensitive;
+} EntryIconInfo;
+
+struct _GtkIconEntryPrivate
+{
+ gdouble fraction;
+ EntryIconInfo icons[MAX_ICONS];
+
+ gulong icon_released_id;
+};
+
+enum
+{
+ ICON_PRESSED,
+ ICON_RELEASED,
+ LAST_SIGNAL
+};
+
+enum
+{
+ PROP_0,
+ PROP_PIXBUF_PRIMARY,
+ PROP_PIXBUF_SECONDARY,
+ PROP_STOCK_PRIMARY,
+ PROP_STOCK_SECONDARY,
+ PROP_ICON_NAME_PRIMARY,
+ PROP_ICON_NAME_SECONDARY,
+ PROP_GICON_PRIMARY,
+ PROP_GICON_SECONDARY,
+ PROP_SENSITIVITY_PRIMARY,
+ PROP_SENSITIVITY_SECONDARY
+};
+
+static void gtk_icon_entry_editable_init (GtkEditableClass *iface);
+static void gtk_icon_entry_finalize (GObject *obj);
+static void gtk_icon_entry_dispose (GObject *obj);
+static void gtk_icon_entry_map (GtkWidget *widget);
+static void gtk_icon_entry_unmap (GtkWidget *widget);
+static void gtk_icon_entry_realize (GtkWidget *widget);
+static void gtk_icon_entry_unrealize (GtkWidget *widget);
+static void gtk_icon_entry_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void gtk_icon_entry_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gint gtk_icon_entry_expose (GtkWidget *widget,
+ GdkEventExpose *event);
+static gint gtk_icon_entry_enter_notify (GtkWidget *widget,
+ GdkEventCrossing *event);
+static gint gtk_icon_entry_leave_notify (GtkWidget *widget,
+ GdkEventCrossing *event);
+static gint gtk_icon_entry_button_press (GtkWidget *widget,
+ GdkEventButton *event);
+static gint gtk_icon_entry_button_release (GtkWidget *widget,
+ GdkEventButton *event);
+static void gtk_icon_entry_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_icon_entry_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gtk_icon_entry_style_set (GtkWidget *widget,
+ GtkStyle *prev_style);
+static void gtk_icon_entry_set_icon_internal (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ GdkPixbuf *pixbuf);
+static void icon_theme_changed (GtkIconEntry *entry);
+
+
+static GtkEntryClass *parent_class = NULL;
+static guint signals[LAST_SIGNAL] = {0};
+
+G_DEFINE_TYPE_EXTENDED (GtkIconEntry, gtk_icon_entry, GTK_TYPE_ENTRY,
+ 0,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
+ gtk_icon_entry_editable_init));
+
+static void
+gtk_icon_entry_class_init (GtkIconEntryClass *klass)
+{
+ GObjectClass *gobject_class;
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+ GtkEntryClass *entry_class;
+
+ parent_class = g_type_class_peek_parent(klass);
+
+ gobject_class = G_OBJECT_CLASS(klass);
+ object_class = GTK_OBJECT_CLASS(klass);
+ widget_class = GTK_WIDGET_CLASS(klass);
+ entry_class = GTK_ENTRY_CLASS(klass);
+
+ gobject_class->finalize = gtk_icon_entry_finalize;
+ gobject_class->dispose = gtk_icon_entry_dispose;
+ gobject_class->set_property = gtk_icon_entry_set_property;
+ gobject_class->get_property = gtk_icon_entry_get_property;
+
+ widget_class->map = gtk_icon_entry_map;
+ widget_class->unmap = gtk_icon_entry_unmap;
+ widget_class->realize = gtk_icon_entry_realize;
+ widget_class->unrealize = gtk_icon_entry_unrealize;
+ widget_class->size_request = gtk_icon_entry_size_request;
+ widget_class->size_allocate = gtk_icon_entry_size_allocate;
+ widget_class->expose_event = gtk_icon_entry_expose;
+ widget_class->enter_notify_event = gtk_icon_entry_enter_notify;
+ widget_class->leave_notify_event = gtk_icon_entry_leave_notify;
+ widget_class->button_press_event = gtk_icon_entry_button_press;
+ widget_class->button_release_event = gtk_icon_entry_button_release;
+ widget_class->style_set = gtk_icon_entry_style_set;
+
+ /**
+ * GtkIconEntry::icon-pressed:
+ * @entry: The entry on which the signal is emitted.
+ * @icon_pos: The position of the clicked icon.
+ * @button: The mouse button clicked.
+ *
+ * The ::icon-pressed signal is emitted when an icon is clicked.
+ */
+ if (!(signals[ICON_PRESSED] = g_signal_lookup ("icon-pressed", GTK_TYPE_ENTRY)))
+ signals[ICON_PRESSED] =
+ g_signal_new ("icon-pressed",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GtkIconEntryClass, icon_pressed),
+ NULL, NULL,
+ gtk_marshal_VOID__INT_INT,
+ G_TYPE_NONE, 2,
+ G_TYPE_INT,
+ G_TYPE_INT);
+
+ /**
+ * GtkIconEntry::icon-release:
+ * @entry: The entry on which the signal is emitted.
+ * @icon_pos: The position of the clicked icon.
+ * @button: The mouse button clicked.
+ *
+ * The ::icon-release signal is emitted on the button release from a
+ * mouse click.
+ */
+ if (!(signals[ICON_RELEASED] = g_signal_lookup ("icon-release", GTK_TYPE_ENTRY)))
+ signals[ICON_RELEASED] =
+ g_signal_new ("icon-release",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GtkIconEntryClass, icon_released),
+ NULL, NULL,
+ gtk_marshal_VOID__INT_INT,
+ G_TYPE_NONE, 2,
+ G_TYPE_INT,
+ G_TYPE_INT);
+
+ /**
+ * GtkIconEntry:pixbuf-primary:
+ *
+ * An image to use as the primary icon for the entry.
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_PIXBUF_PRIMARY,
+ g_param_spec_object ("pixbuf-primary",
+ P_("Primary pixbuf"),
+ P_("Primary pixbuf for the entry"),
+ GDK_TYPE_PIXBUF,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkIconEntry:pixbuf-secondary:
+ *
+ * An image to use as the secondary icon for the entry.
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_PIXBUF_SECONDARY,
+ g_param_spec_object ("pixbuf-secondary",
+ P_("Secondary pixbuf"),
+ P_("Secondary pixbuf for the entry"),
+ GDK_TYPE_PIXBUF,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_STOCK_PRIMARY,
+ g_param_spec_string ("stock-primary",
+ P_("Primary stock ID"),
+ P_("Stock ID for primary icon"),
+ NULL,
+ GTK_PARAM_WRITABLE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_STOCK_SECONDARY,
+ g_param_spec_string ("stock-secondary",
+ P_("Secondary stock ID"),
+ P_("Stock ID for secondary icon"),
+ NULL,
+ GTK_PARAM_WRITABLE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_ICON_NAME_PRIMARY,
+ g_param_spec_string ("icon-name-primary",
+ P_("Primary icon name"),
+ P_("Icon name for primary icon"),
+ NULL,
+ GTK_PARAM_WRITABLE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_ICON_NAME_SECONDARY,
+ g_param_spec_string ("icon-name-secondary",
+ P_("Secondary icon name"),
+ P_("Icon name for secondary icon"),
+ NULL,
+ GTK_PARAM_WRITABLE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_GICON_PRIMARY,
+ g_param_spec_object ("gicon-primary",
+ P_("Primary GIcon"),
+ P_("GIcon for primary icon"),
+ G_TYPE_ICON,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_GICON_SECONDARY,
+ g_param_spec_object ("gicon-secondary",
+ P_("Secondary GIcon"),
+ P_("GIcon for secondary icon"),
+ G_TYPE_ICON,
+ GTK_PARAM_READWRITE));
+
+ g_type_class_add_private (klass, sizeof (GtkIconEntryPrivate));
+}
+
+static void
+gtk_icon_entry_editable_init (GtkEditableClass *iface)
+{
+};
+
+/* GTK+/ GtkEntry internal helper function
+ Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ Modified by the GTK+ Team and others 1997-2000
+ Copied from Gtk+ 2.13, whitespace adjusted */
+static void
+gtk_entry_get_pixel_ranges (GtkEntry *entry,
+ gint **ranges,
+ gint *n_ranges)
+{
+ gint start_char, end_char;
+
+ if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
+ &start_char, &end_char))
+ {
+ PangoLayout *layout = gtk_entry_get_layout (entry);
+ PangoLayoutLine *line = pango_layout_get_lines (layout)->data;
+ const char *text = pango_layout_get_text (layout);
+ gsize start_index = g_utf8_offset_to_pointer (text, start_char) - text;
+ gsize end_index = g_utf8_offset_to_pointer (text, end_char) - text;
+ gint real_n_ranges, i;
+
+ pango_layout_line_get_x_ranges (line,
+ start_index, end_index, ranges, &real_n_ranges);
+
+ if (ranges)
+ {
+ gint *r = *ranges;
+
+ for (i = 0; i < real_n_ranges; ++i)
+ {
+ r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
+ r[2 * i] = r[2 * i] / PANGO_SCALE;
+ }
+ }
+
+ if (n_ranges)
+ *n_ranges = real_n_ranges;
+ }
+ else
+ {
+ if (n_ranges)
+ *n_ranges = 0;
+ if (ranges)
+ *ranges = NULL;
+ }
+}
+
+/* GTK+/ GtkEntry internal helper function
+ Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ Modified by the GTK+ Team and others 1997-2000
+ Copied from Gtk+ 2.13, whitespace adjusted
+ Code adjusted to not rely on internal qdata */
+static void
+_gtk_entry_effective_inner_border (GtkEntry *entry,
+ GtkBorder *border)
+{
+ static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
+ GtkBorder *tmp_border;
+
+ tmp_border = (GtkBorder*) gtk_entry_get_inner_border (entry);
+
+ if (tmp_border)
+ {
+ *border = *tmp_border;
+ return;
+ }
+
+ gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
+
+ if (tmp_border)
+ {
+ *border = *tmp_border;
+ gtk_border_free (tmp_border);
+ return;
+ }
+
+ *border = default_inner_border;
+}
+
+static void
+gtk_entry_borders (GtkEntry* entry,
+ gint* xborder,
+ gint* yborder,
+ gboolean* interior_focus,
+ gint* focus_width)
+{
+ GtkWidget *widget = GTK_WIDGET (entry);
+
+ if (entry->has_frame)
+ {
+ *xborder = widget->style->xthickness;
+ *yborder = widget->style->ythickness;
+ }
+ else
+ {
+ *xborder = 0;
+ *yborder = 0;
+ }
+
+ gtk_widget_style_get (widget, "interior-focus", interior_focus,
+ "focus-line-width", focus_width, NULL);
+
+ if (interior_focus)
+ {
+ *xborder += *focus_width;
+ *yborder += *focus_width;
+ }
+}
+
+/* GTK+/ GtkEntry internal helper function
+ Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ Modified by the GTK+ Team and others 1997-2000
+ Copied from Gtk+ 2.13, whitespace adjusted */
+static void
+gtk_entry_get_text_area_size (GtkEntry *entry,
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height)
+{
+ gint frame_height;
+ gint xborder, yborder;
+ gboolean interior_focus;
+ gint focus_width;
+ GtkRequisition requisition;
+ GtkWidget *widget = GTK_WIDGET (entry);
+
+ gtk_widget_get_child_requisition (widget, &requisition);
+ gtk_entry_borders (entry, &xborder, &yborder, &interior_focus, &focus_width);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gdk_drawable_get_size (widget->window, NULL, &frame_height);
+ else
+ frame_height = requisition.height;
+
+ if (GTK_WIDGET_HAS_FOCUS (widget) && interior_focus)
+ frame_height -= 2 * focus_width;
+
+ if (x)
+ *x = xborder;
+
+ if (y)
+ *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
+
+ if (width)
+ *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
+
+ if (height)
+ *height = requisition.height - yborder * 2;
+}
+
+/* GTK+/ GtkEntry internal helper function
+ Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ Modified by the GTK+ Team and others 1997-2000
+ Copied from Gtk+ 2.13, whitespace adjusted */
+static void
+get_layout_position (GtkEntry *entry,
+ gint *x,
+ gint *y)
+{
+ PangoLayout *layout;
+ PangoRectangle logical_rect;
+ gint area_width, area_height;
+ GtkBorder inner_border;
+ gint y_pos;
+ PangoLayoutLine *line;
+
+ layout = gtk_entry_get_layout (entry);
+
+ gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
+
+ area_height = PANGO_SCALE *
+ (area_height - inner_border.top - inner_border.bottom);
+
+ line = pango_layout_get_lines (layout)->data;
+ pango_layout_line_get_extents (line, NULL, &logical_rect);
+
+ /* Align primarily for locale's ascent/descent */
+ y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
+ entry->ascent + logical_rect.y);
+
+ /* Now see if we need to adjust to fit in actual drawn string */
+ if (logical_rect.height > area_height)
+ y_pos = (area_height - logical_rect.height) / 2;
+ else if (y_pos < 0)
+ y_pos = 0;
+ else if (y_pos + logical_rect.height > area_height)
+ y_pos = area_height - logical_rect.height;
+
+ y_pos = inner_border.top + y_pos / PANGO_SCALE;
+
+ if (x)
+ *x = inner_border.left - entry->scroll_offset;
+
+ if (y)
+ *y = y_pos;
+}
+
+/* GTK+/ GtkEntry internal helper function
+ Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ Modified by the GTK+ Team and others 1997-2000
+ Copied from Gtk+ 2.13, whitespace adjusted
+ Code adjusted to not rely on internal _gtk_entry_ensure_layout */
+static void
+gtk_entry_draw_text (GtkEntry *entry)
+{
+ GtkWidget *widget;
+
+ if (!entry->visible && entry->invisible_char == 0)
+ return;
+
+ if (GTK_WIDGET_DRAWABLE (entry))
+ {
+ PangoLayout *layout = gtk_entry_get_layout (entry);
+ cairo_t *cr;
+ gint x, y;
+ gint start_pos, end_pos;
+
+ widget = GTK_WIDGET (entry);
+
+ get_layout_position (entry, &x, &y);
+
+ cr = gdk_cairo_create (entry->text_area);
+
+ cairo_move_to (cr, x, y);
+ gdk_cairo_set_source_color (cr, &widget->style->text [widget->state]);
+ pango_cairo_show_layout (cr, layout);
+
+ if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
+ &start_pos, &end_pos))
+ {
+ gint *ranges;
+ gint n_ranges, i;
+ PangoRectangle logical_rect;
+ GdkColor *selection_color, *text_color;
+ GtkBorder inner_border;
+
+ pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+ gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
+
+ if (GTK_WIDGET_HAS_FOCUS (entry))
+ {
+ selection_color = &widget->style->base [GTK_STATE_SELECTED];
+ text_color = &widget->style->text [GTK_STATE_SELECTED];
+ }
+ else
+ {
+ selection_color = &widget->style->base [GTK_STATE_ACTIVE];
+ text_color = &widget->style->text [GTK_STATE_ACTIVE];
+ }
+
+ _gtk_entry_effective_inner_border (entry, &inner_border);
+
+ for (i = 0; i < n_ranges; ++i)
+ cairo_rectangle (cr,
+ inner_border.left -
+ entry->scroll_offset + ranges[2 * i],
+ y,
+ ranges[2 * i + 1],
+ logical_rect.height);
+
+ cairo_clip (cr);
+
+ gdk_cairo_set_source_color (cr, selection_color);
+ cairo_paint (cr);
+
+ cairo_move_to (cr, x, y);
+ gdk_cairo_set_source_color (cr, text_color);
+ pango_cairo_show_layout (cr, layout);
+
+ g_free (ranges);
+ }
+
+ cairo_destroy (cr);
+ }
+}
+
+static gboolean
+entry_expose_event (GtkWidget* entry,
+ GdkEventExpose* event,
+ GtkIconEntry* icon_entry)
+{
+ GtkIconEntryPrivate *priv;
+ GdkWindow* text_area;
+ gint width, height;
+
+ priv = icon_entry->priv;
+ text_area = GTK_ENTRY (entry)->text_area;
+ gdk_drawable_get_size (text_area, &width, &height);
+
+ if (priv->fraction > 0.0)
+ {
+ gtk_paint_box (entry->style, text_area,
+ GTK_STATE_SELECTED, GTK_SHADOW_OUT,
+ &event->area, entry, "entry-progress",
+ 0, 0, priv->fraction * width, height);
+ gtk_entry_draw_text (GTK_ENTRY (entry));
+ }
+ return FALSE;
+}
+
+static void
+gtk_icon_entry_init (GtkIconEntry *entry)
+{
+ entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry, GTK_TYPE_ICON_ENTRY,
+ GtkIconEntryPrivate);
+
+ g_signal_connect_after (entry, "expose-event",
+ G_CALLBACK (entry_expose_event), entry);
+}
+
+static void
+gtk_icon_entry_finalize (GObject *obj)
+{
+ GtkIconEntry *entry;
+
+ g_return_if_fail (obj != NULL);
+ g_return_if_fail (GTK_IS_ICON_ENTRY(obj));
+
+ entry = GTK_ICON_ENTRY (obj);
+
+ G_OBJECT_CLASS (parent_class)->finalize (obj);
+}
+
+static void
+gtk_icon_entry_dispose (GObject *obj)
+{
+ GtkIconEntry *entry;
+
+ entry = GTK_ICON_ENTRY (obj);
+
+ gtk_icon_entry_set_icon_from_pixbuf (entry, GTK_ICON_ENTRY_PRIMARY, NULL);
+ gtk_icon_entry_set_icon_from_pixbuf (entry, GTK_ICON_ENTRY_SECONDARY, NULL);
+
+ G_OBJECT_CLASS (parent_class)->dispose (obj);
+}
+
+static void
+gtk_icon_entry_map (GtkWidget *widget)
+{
+ GtkIconEntryPrivate *priv;
+ GdkCursor *cursor;
+
+ if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
+ {
+ int i;
+
+ GTK_WIDGET_CLASS (parent_class)->map (widget);
+
+ priv = GTK_ICON_ENTRY (widget)->priv;
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ if (priv->icons[i].pixbuf != NULL)
+ gdk_window_show (priv->icons[i].window);
+
+ if (priv->icons[i].custom_cursor == TRUE && !priv->icons[i].insensitive)
+ {
+ cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
+ priv->icons[i].cursor_type);
+
+ gdk_window_set_cursor (priv->icons[i].window, cursor);
+ gdk_cursor_unref (cursor);
+ }
+ }
+
+ GTK_WIDGET_CLASS (parent_class)->map (widget);
+ }
+}
+
+static void
+gtk_icon_entry_unmap (GtkWidget *widget)
+{
+ GtkIconEntryPrivate *priv;
+
+ if (GTK_WIDGET_MAPPED (widget))
+ {
+ int i;
+
+ priv = GTK_ICON_ENTRY (widget)->priv;
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ if (priv->icons[i].pixbuf != NULL)
+ {
+ gdk_window_hide (priv->icons[i].window);
+ }
+ }
+
+ GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+ }
+}
+
+static void
+gtk_icon_entry_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkIconEntry *entry = GTK_ICON_ENTRY (object);
+
+ switch (prop_id)
+ {
+ case PROP_PIXBUF_PRIMARY:
+ gtk_icon_entry_set_icon_from_pixbuf (entry,
+ GTK_ICON_ENTRY_PRIMARY,
+ g_value_get_object (value));
+ break;
+
+ case PROP_PIXBUF_SECONDARY:
+ gtk_icon_entry_set_icon_from_pixbuf (entry,
+ GTK_ICON_ENTRY_SECONDARY,
+ g_value_get_object (value));
+ break;
+
+ case PROP_STOCK_PRIMARY:
+ gtk_icon_entry_set_icon_from_stock (entry,
+ GTK_ICON_ENTRY_PRIMARY,
+ g_value_get_string (value));
+ break;
+
+ case PROP_STOCK_SECONDARY:
+ gtk_icon_entry_set_icon_from_stock (entry,
+ GTK_ICON_ENTRY_SECONDARY,
+ g_value_get_string (value));
+ break;
+
+ case PROP_ICON_NAME_PRIMARY:
+ gtk_icon_entry_set_icon_from_icon_name (entry,
+ GTK_ICON_ENTRY_PRIMARY,
+ g_value_get_string (value));
+ break;
+
+ case PROP_ICON_NAME_SECONDARY:
+ gtk_icon_entry_set_icon_from_icon_name (entry,
+ GTK_ICON_ENTRY_SECONDARY,
+ g_value_get_string (value));
+ break;
+
+ case PROP_GICON_PRIMARY:
+ gtk_icon_entry_set_icon_from_gicon (entry,
+ GTK_ICON_ENTRY_PRIMARY,
+ g_value_get_object (value));
+ break;
+
+ case PROP_GICON_SECONDARY:
+ gtk_icon_entry_set_icon_from_gicon (entry,
+ GTK_ICON_ENTRY_SECONDARY,
+ g_value_get_object (value));
+ break;
+ }
+}
+
+static void
+gtk_icon_entry_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkIconEntry *entry = GTK_ICON_ENTRY (object);
+
+ switch (prop_id)
+ {
+ case PROP_PIXBUF_PRIMARY:
+ g_value_set_object (value,
+ gtk_icon_entry_get_pixbuf (entry,
+ GTK_ICON_ENTRY_PRIMARY));
+ break;
+
+ case PROP_PIXBUF_SECONDARY:
+ g_value_set_object (value,
+ gtk_icon_entry_get_pixbuf (entry,
+ GTK_ICON_ENTRY_SECONDARY));
+ break;
+
+ case PROP_GICON_PRIMARY:
+ g_value_set_object (value,
+ gtk_icon_entry_get_gicon (entry,
+ GTK_ICON_ENTRY_PRIMARY));
+ break;
+
+ case PROP_GICON_SECONDARY:
+ g_value_set_object (value,
+ gtk_icon_entry_get_gicon (entry,
+ GTK_ICON_ENTRY_SECONDARY));
+ }
+}
+
+static gint
+get_icon_width (GtkIconEntry *entry, GtkIconEntryPosition icon_pos)
+{
+ gint menu_icon_width;
+ gint width;
+ GtkIconEntryPrivate *priv;
+ EntryIconInfo *icon_info;
+
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ if (icon_info->pixbuf == NULL)
+ return 0;
+
+ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &menu_icon_width, NULL);
+
+ width = MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
+
+ return width;
+}
+
+static void
+get_borders (GtkIconEntry *entry, gint *xborder, gint *yborder)
+{
+ GtkWidget *widget = GTK_WIDGET (entry);
+ gint focus_width;
+ gboolean interior_focus;
+
+ gtk_widget_style_get (widget,
+ "interior-focus", &interior_focus,
+ "focus-line-width", &focus_width,
+ NULL);
+
+ if (gtk_entry_get_has_frame (GTK_ENTRY (entry)))
+ {
+ *xborder = widget->style->xthickness;
+ *yborder = widget->style->ythickness;
+ }
+ else
+ {
+ *xborder = 0;
+ *yborder = 0;
+ }
+
+ if (!interior_focus)
+ {
+ *xborder += focus_width;
+ *yborder += focus_width;
+ }
+}
+
+static void
+get_text_area_size (GtkIconEntry *entry, GtkAllocation *alloc)
+{
+ GtkWidget *widget = GTK_WIDGET (entry);
+ GtkRequisition requisition;
+ gint xborder, yborder;
+
+ gtk_widget_get_child_requisition (widget, &requisition);
+ get_borders (entry, &xborder, &yborder);
+
+ alloc->x = xborder;
+ alloc->y = yborder;
+ alloc->width = widget->allocation.width - xborder * 2;
+ alloc->height = requisition.height - yborder * 2;
+}
+
+static void
+get_icon_allocation (GtkIconEntry *icon_entry,
+ gboolean left,
+ GtkAllocation *widget_alloc,
+ GtkAllocation *text_area_alloc,
+ GtkAllocation *allocation,
+ GtkIconEntryPosition *icon_pos)
+{
+ gboolean rtl;
+
+ rtl = (gtk_widget_get_direction (GTK_WIDGET (icon_entry)) ==
+ GTK_TEXT_DIR_RTL);
+
+ if (left)
+ *icon_pos = (rtl ? GTK_ICON_ENTRY_SECONDARY : GTK_ICON_ENTRY_PRIMARY);
+ else
+ *icon_pos = (rtl ? GTK_ICON_ENTRY_PRIMARY : GTK_ICON_ENTRY_SECONDARY);
+
+ allocation->y = text_area_alloc->y;
+ allocation->width = get_icon_width(icon_entry, *icon_pos);
+ allocation->height = text_area_alloc->height;
+
+ if (left)
+ {
+ allocation->x = text_area_alloc->x + ICON_MARGIN;
+ }
+ else
+ {
+ allocation->x = text_area_alloc->x + text_area_alloc->width -
+ allocation->width - ICON_MARGIN;
+ }
+}
+
+static void
+gtk_icon_entry_realize (GtkWidget *widget)
+{
+ GtkIconEntry *entry;
+ GtkIconEntryPrivate *priv;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ int i;
+
+ entry = GTK_ICON_ENTRY (widget);
+ priv = entry->priv;
+
+ GTK_WIDGET_CLASS (parent_class)->realize (widget);
+
+ attributes.x = 0;
+ attributes.y = 0;
+ attributes.width = 1;
+ attributes.height = 1;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.event_mask = gtk_widget_get_events (widget);
+ attributes.event_mask |=
+ (GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ EntryIconInfo *icon_info;
+
+ icon_info = &priv->icons[i];
+ icon_info->window = gdk_window_new (widget->window, &attributes,
+ attributes_mask);
+ gdk_window_set_user_data (icon_info->window, widget);
+
+ gdk_window_set_background (icon_info->window,
+ &widget->style->base[GTK_WIDGET_STATE(widget)]);
+ }
+
+ gtk_widget_queue_resize (widget);
+}
+
+static void
+gtk_icon_entry_unrealize (GtkWidget *widget)
+{
+ GtkIconEntry *entry;
+ GtkIconEntryPrivate *priv;
+ int i;
+
+ entry = GTK_ICON_ENTRY (widget);
+ priv = entry->priv;
+
+ GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ EntryIconInfo *icon_info = &priv->icons[i];
+
+ gdk_window_destroy (icon_info->window);
+ icon_info->window = NULL;
+ }
+}
+
+static void
+gtk_icon_entry_size_request (GtkWidget *widget, GtkRequisition *requisition)
+{
+ GtkEntry *gtkentry;
+ GtkIconEntry *entry;
+ gint icon_widths = 0;
+ int i;
+
+ gtkentry = GTK_ENTRY(widget);
+ entry = GTK_ICON_ENTRY(widget);
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ int icon_width = get_icon_width (entry, i);
+
+ if (icon_width > 0)
+ {
+ icon_widths += icon_width + ICON_MARGIN;
+ }
+ }
+
+ GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
+
+ if (icon_widths > requisition->width)
+ requisition->width += icon_widths;
+}
+
+static void
+place_windows (GtkIconEntry *icon_entry, GtkAllocation *widget_alloc)
+{
+ GtkIconEntryPosition left_icon_pos;
+ GtkIconEntryPosition right_icon_pos;
+ GtkAllocation left_icon_alloc;
+ GtkAllocation right_icon_alloc;
+ GtkAllocation text_area_alloc;
+ GtkIconEntryPrivate *priv;
+ gint y;
+
+ priv = icon_entry->priv;
+
+ get_text_area_size (icon_entry, &text_area_alloc);
+
+ /* DJW center text/icon
+ * TODO flicker needs to be eliminated
+ */
+ gdk_window_get_geometry (GTK_ENTRY (icon_entry)->text_area, NULL, &y, NULL, NULL, NULL);
+ text_area_alloc.y = y;
+
+ get_icon_allocation (icon_entry, TRUE, widget_alloc, &text_area_alloc,
+ &left_icon_alloc, &left_icon_pos);
+ get_icon_allocation (icon_entry, FALSE, widget_alloc, &text_area_alloc,
+ &right_icon_alloc, &right_icon_pos);
+
+ if (left_icon_alloc.width > 0)
+ {
+ text_area_alloc.x = left_icon_alloc.x + left_icon_alloc.width + ICON_MARGIN;
+ }
+
+ if (right_icon_alloc.width > 0)
+ {
+ text_area_alloc.width -= right_icon_alloc.width + ICON_MARGIN;
+ }
+
+ text_area_alloc.width -= text_area_alloc.x;
+
+ gdk_window_move_resize (priv->icons[left_icon_pos].window,
+ left_icon_alloc.x, left_icon_alloc.y,
+ left_icon_alloc.width, left_icon_alloc.height);
+
+ gdk_window_move_resize (priv->icons[right_icon_pos].window,
+ right_icon_alloc.x, right_icon_alloc.y,
+ right_icon_alloc.width, right_icon_alloc.height);
+
+ gdk_window_move_resize (GTK_ENTRY (icon_entry)->text_area,
+ text_area_alloc.x, text_area_alloc.y,
+ text_area_alloc.width, text_area_alloc.height);
+}
+
+static void
+gtk_icon_entry_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+ g_return_if_fail (GTK_IS_ICON_ENTRY(widget));
+ g_return_if_fail (allocation != NULL);
+
+ widget->allocation = *allocation;
+
+ GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ place_windows (GTK_ICON_ENTRY (widget), allocation);
+}
+
+static GdkPixbuf *
+get_pixbuf_from_icon (GtkIconEntry *entry, GtkIconEntryPosition icon_pos)
+{
+ EntryIconInfo *icon_info;
+ GtkIconEntryPrivate *priv;
+
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ g_object_ref (icon_info->pixbuf);
+
+ return icon_info->pixbuf;
+}
+
+/* Kudos to the gnome-panel guys. */
+static void
+colorshift_pixbuf (GdkPixbuf *dest, GdkPixbuf *src, int shift)
+{
+ gint i, j;
+ gint width, height, has_alpha, src_rowstride, dest_rowstride;
+ guchar *target_pixels;
+ guchar *original_pixels;
+ guchar *pix_src;
+ guchar *pix_dest;
+ int val;
+ guchar r, g, b;
+
+ has_alpha = gdk_pixbuf_get_has_alpha (src);
+ width = gdk_pixbuf_get_width (src);
+ height = gdk_pixbuf_get_height (src);
+ src_rowstride = gdk_pixbuf_get_rowstride (src);
+ dest_rowstride = gdk_pixbuf_get_rowstride (dest);
+ original_pixels = gdk_pixbuf_get_pixels (src);
+ target_pixels = gdk_pixbuf_get_pixels (dest);
+
+ for (i = 0; i < height; i++)
+ {
+ pix_dest = target_pixels + i * dest_rowstride;
+ pix_src = original_pixels + i * src_rowstride;
+
+ for (j = 0; j < width; j++)
+ {
+ r = *(pix_src++);
+ g = *(pix_src++);
+ b = *(pix_src++);
+
+ val = r + shift;
+ *(pix_dest++) = CLAMP(val, 0, 255);
+
+ val = g + shift;
+ *(pix_dest++) = CLAMP(val, 0, 255);
+
+ val = b + shift;
+ *(pix_dest++) = CLAMP(val, 0, 255);
+
+ if (has_alpha)
+ *(pix_dest++) = *(pix_src++);
+ }
+ }
+}
+
+static void
+draw_icon (GtkWidget *widget, GtkIconEntryPosition icon_pos)
+{
+ GtkIconEntry *entry;
+ GtkIconEntryPrivate *priv;
+ EntryIconInfo *icon_info;
+ GdkPixbuf *pixbuf;
+ gint x, y, width, height;
+
+ entry = GTK_ICON_ENTRY (widget);
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ if (icon_info->pixbuf == NULL || !GTK_WIDGET_REALIZED (widget))
+ return;
+
+ if ((pixbuf = get_pixbuf_from_icon (entry, icon_pos)) == NULL)
+ return;
+
+ gdk_drawable_get_size (icon_info->window, &width, &height);
+
+ if (width == 1 || height == 1)
+ {
+ /*
+ * size_allocate hasn't been called yet. These are the default values.
+ */
+ return;
+ }
+
+ if (gdk_pixbuf_get_height (pixbuf) > height)
+ {
+ GdkPixbuf *temp_pixbuf;
+ int scale;
+
+ scale = height - (2 * ICON_MARGIN);
+
+ temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
+ GDK_INTERP_BILINEAR);
+
+ g_object_unref (pixbuf);
+
+ pixbuf = temp_pixbuf;
+ }
+
+ x = (width - gdk_pixbuf_get_width(pixbuf)) / 2;
+ y = (height - gdk_pixbuf_get_height(pixbuf)) / 2;
+
+ if (icon_info->insensitive)
+ {
+ GdkPixbuf *temp_pixbuf;
+
+ temp_pixbuf = gdk_pixbuf_copy (pixbuf);
+
+ gdk_pixbuf_saturate_and_pixelate (pixbuf,
+ temp_pixbuf,
+ 0.8f,
+ TRUE);
+ g_object_unref (pixbuf);
+ pixbuf = temp_pixbuf;
+ }
+ else if (icon_info->hovered)
+ {
+ GdkPixbuf *temp_pixbuf;
+
+ temp_pixbuf = gdk_pixbuf_copy (pixbuf);
+
+ colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
+
+ g_object_unref (pixbuf);
+
+ pixbuf = temp_pixbuf;
+ }
+
+ gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
+ 0, 0, x, y, -1, -1,
+ GDK_RGB_DITHER_NORMAL, 0, 0);
+
+ g_object_unref (pixbuf);
+}
+
+static gint
+gtk_icon_entry_expose (GtkWidget *widget, GdkEventExpose *event)
+{
+ GtkIconEntry *entry;
+ GtkIconEntryPrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_ICON_ENTRY (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ entry = GTK_ICON_ENTRY (widget);
+ priv = entry->priv;
+
+ if (GTK_WIDGET_DRAWABLE (widget))
+ {
+ gboolean found = FALSE;
+ int i;
+
+ for (i = 0; i < MAX_ICONS && !found; i++)
+ {
+ EntryIconInfo *icon_info = &priv->icons[i];
+
+ if (event->window == icon_info->window)
+ {
+ gint width;
+ GtkAllocation text_area_alloc;
+
+ get_text_area_size (entry, &text_area_alloc);
+ gdk_drawable_get_size (icon_info->window, &width, NULL);
+
+ gtk_paint_flat_box (widget->style, icon_info->window,
+ GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
+ NULL, widget, "entry_bg",
+ 0, 0, width, text_area_alloc.height);
+
+ draw_icon (widget, i);
+
+ found = TRUE;
+ }
+ }
+
+ if (!found)
+ GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+ }
+
+ return FALSE;
+}
+
+static gint
+gtk_icon_entry_enter_notify (GtkWidget *widget, GdkEventCrossing *event)
+{
+ GtkIconEntry *entry;
+ GtkIconEntryPrivate *priv;
+ int i;
+
+ entry = GTK_ICON_ENTRY (widget);
+ priv = entry->priv;
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ if (event->window == priv->icons[i].window)
+ {
+ if (gtk_icon_entry_get_icon_highlight (entry, i))
+ {
+ priv->icons[i].hovered = TRUE;
+
+ if (priv->icons[i].tooltip_text != NULL)
+ {
+ gtk_widget_set_tooltip_text (widget,
+ priv->icons[i].tooltip_text);
+ gtk_widget_set_has_tooltip (widget, TRUE);
+ } else {
+ gtk_widget_set_has_tooltip (widget, FALSE);
+ }
+
+ gtk_widget_queue_draw (widget);
+
+ break;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+static gint
+gtk_icon_entry_leave_notify (GtkWidget *widget, GdkEventCrossing *event)
+{
+ GtkIconEntry *entry;
+ GtkIconEntryPrivate *priv;
+ int i;
+
+ entry = GTK_ICON_ENTRY (widget);
+ priv = entry->priv;
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ if (event->window == priv->icons[i].window)
+ {
+ if (gtk_icon_entry_get_icon_highlight (entry, i))
+ {
+ priv->icons[i].hovered = FALSE;
+
+ gtk_widget_set_has_tooltip (widget, FALSE);
+ gtk_widget_queue_draw (widget);
+
+ break;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+static gint
+gtk_icon_entry_button_press (GtkWidget *widget, GdkEventButton *event)
+{
+ GtkIconEntry *entry;
+ GtkIconEntryPrivate *priv;
+ int i;
+
+ entry = GTK_ICON_ENTRY (widget);
+ priv = entry->priv;
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ if (event->window == priv->icons[i].window)
+ {
+ if (event->button == 1 && gtk_icon_entry_get_icon_highlight (entry, i))
+ {
+ priv->icons[i].hovered = FALSE;
+
+ gtk_widget_queue_draw (widget);
+ }
+
+ g_signal_emit (entry, signals[ICON_PRESSED], 0, i, event->button);
+
+ return TRUE;
+ }
+ }
+
+ if (GTK_WIDGET_CLASS (parent_class)->button_press_event)
+ return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
+
+ return FALSE;
+}
+
+static gint
+gtk_icon_entry_button_release (GtkWidget *widget, GdkEventButton *event)
+{
+ GtkIconEntry *entry;
+ GtkIconEntryPrivate *priv;
+ int i;
+
+ entry = GTK_ICON_ENTRY (widget);
+ priv = entry->priv;
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ GdkWindow *icon_window = priv->icons[i].window;
+
+ if (event->window == icon_window)
+ {
+ int width, height;
+ gdk_drawable_get_size (icon_window, &width, &height);
+
+ if (event->button == 1 &&
+ gtk_icon_entry_get_icon_highlight (entry, i) &&
+ event->x >= 0 && event->y >= 0 &&
+ event->x <= width && event->y <= height)
+ {
+ priv->icons[i].hovered = TRUE;
+
+ gtk_widget_queue_draw (widget);
+ }
+
+ g_signal_emit (entry, signals[ICON_RELEASED], 0, i, event->button);
+
+ return TRUE;
+ }
+ }
+
+ if (GTK_WIDGET_CLASS (parent_class)->button_release_event)
+ return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
+
+ return FALSE;
+}
+
+static void
+gtk_icon_entry_style_set (GtkWidget *widget, GtkStyle *prev_style)
+{
+ GtkIconEntry *icon_entry;
+
+ icon_entry = GTK_ICON_ENTRY (widget);
+
+ if (GTK_WIDGET_CLASS (gtk_icon_entry_parent_class)->style_set)
+ GTK_WIDGET_CLASS (gtk_icon_entry_parent_class)->style_set (widget, prev_style);
+
+ icon_theme_changed (icon_entry);
+}
+
+static void
+icon_theme_changed (GtkIconEntry *entry)
+{
+ GtkIconEntryPrivate *priv;
+ int i;
+
+ priv = entry->priv;
+
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ if (priv->icons[i].storage_type == GTK_IMAGE_ICON_NAME)
+ {
+ g_object_unref (priv->icons[i].pixbuf);
+ priv->icons[i].pixbuf = NULL;
+
+ gtk_icon_entry_set_icon_from_icon_name (entry, i, priv->icons[i].icon_name);
+ }
+ else if (priv->icons[i].storage_type == _GTK_IMAGE_GICON)
+ {
+ g_object_unref (priv->icons[i].pixbuf);
+ priv->icons[i].pixbuf = NULL;
+
+ gtk_icon_entry_set_icon_from_gicon (entry, i, priv->icons[i].gicon);
+ }
+ }
+
+ gtk_widget_queue_draw (GTK_WIDGET (entry));
+}
+
+static void
+gtk_icon_entry_set_icon_internal (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ GdkPixbuf *pixbuf)
+{
+ EntryIconInfo *icon_info;
+ GtkIconEntryPrivate *priv;
+
+ g_return_if_fail (entry != NULL);
+ g_return_if_fail (GTK_IS_ICON_ENTRY (entry));
+ g_return_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos));
+
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ if (pixbuf == icon_info->pixbuf)
+ return;
+
+ if (icon_pos == GTK_ICON_ENTRY_SECONDARY &&
+ priv->icon_released_id != 0)
+ {
+ g_signal_handler_disconnect (entry, priv->icon_released_id);
+ priv->icon_released_id = 0;
+ }
+
+ if (pixbuf == NULL)
+ {
+ if (icon_info->pixbuf != NULL)
+ {
+ g_object_unref (icon_info->pixbuf);
+ icon_info->pixbuf = NULL;
+
+ /* Explicitly check, as the pointer may become invalidated
+ * during destruction.
+ */
+ if (icon_info->window != NULL && GDK_IS_WINDOW (icon_info->window))
+ gdk_window_hide (icon_info->window);
+ }
+ }
+ else
+ {
+ if (icon_info->window != NULL && icon_info->pixbuf == NULL)
+ gdk_window_show (icon_info->window);
+
+ icon_info->pixbuf = pixbuf;
+ g_object_ref (pixbuf);
+ }
+
+ gtk_widget_queue_draw (GTK_WIDGET (entry));
+}
+
+/**
+ * gtk_icon_entry_new
+ *
+ * Creates a new GtkIconEntry widget.
+ *
+ * Returns a new #GtkIconEntry.
+ */
+GtkWidget *
+gtk_icon_entry_new (void)
+{
+ return GTK_WIDGET (g_object_new (GTK_TYPE_ICON_ENTRY, NULL));
+}
+
+/**
+ * gtk_icon_entry_set_icon_from_pixbuf
+ * @entry: A #GtkIconEntry.
+ * @position: Icon position.
+ * @pixbuf: A #GdkPixbuf.
+ *
+ * Sets the icon shown in the specified position using a pixbuf.
+ */
+void
+gtk_icon_entry_set_icon_from_pixbuf (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ GdkPixbuf *pixbuf)
+{
+ EntryIconInfo *icon_info;
+ GtkIconEntryPrivate *priv;
+
+ g_return_if_fail (entry != NULL);
+ g_return_if_fail (GTK_IS_ICON_ENTRY (entry));
+ g_return_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos));
+
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ if (pixbuf == icon_info->pixbuf)
+ return;
+
+ if (icon_pos == GTK_ICON_ENTRY_SECONDARY &&
+ priv->icon_released_id != 0)
+ {
+ g_signal_handler_disconnect (entry, priv->icon_released_id);
+ priv->icon_released_id = 0;
+ }
+
+ if (pixbuf == NULL)
+ {
+ if (icon_info->pixbuf != NULL)
+ {
+ g_object_unref (icon_info->pixbuf);
+ icon_info->pixbuf = NULL;
+
+ /* Explicitly check, as the pointer may become invalidated
+ * during destruction.
+ */
+ if (icon_info->window != NULL && GDK_IS_WINDOW (icon_info->window))
+ gdk_window_hide (icon_info->window);
+ }
+ }
+ else
+ {
+ if (icon_info->window != NULL && icon_info->pixbuf == NULL)
+ gdk_window_show (icon_info->window);
+
+ icon_info->pixbuf = pixbuf;
+ g_object_ref (pixbuf);
+ }
+
+ gtk_widget_queue_draw (GTK_WIDGET (entry));
+}
+
+/**
+ * gtk_icon_entry_set_icon_from_stock
+ * @entry: A #GtkIconEntry.
+ * @position: Icon position.
+ * @stock_id: The name of the stock item.
+ *
+ * Sets the icon shown in the entry at the specified position from a stock image.
+ */
+void
+gtk_icon_entry_set_icon_from_stock (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ const gchar *stock_id)
+{
+ GdkPixbuf *pixbuf;
+
+ /* FIXME: Due to a bug in GtkIconEntry we need to set a non-NULL icon */
+ if (! stock_id)
+ stock_id = GTK_STOCK_INFO;
+
+ pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
+ stock_id,
+ GTK_ICON_SIZE_MENU,
+ NULL);
+
+ gtk_icon_entry_set_icon_internal (entry,
+ icon_pos,
+ pixbuf);
+}
+
+/**
+ * gtk_icon_entry_set_icon_from_icon_name
+ * @entry: A #GtkIconEntry;
+ * @icon_pos: The position at which to set the icon
+ * @icon_name: An icon name
+ *
+ * Sets the icon shown in the entry at the specified position from the current
+ * icon theme. If the icon name isn't known, a "broken image" icon will be
+ * displayed instead. If the current icon theme is changed, the icon will be
+ * updated appropriately.
+ */
+void
+gtk_icon_entry_set_icon_from_icon_name (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ const gchar *icon_name)
+{
+ GdkPixbuf *pixbuf = NULL;
+ EntryIconInfo *icon_info;
+ GtkIconEntryPrivate *priv;
+ GdkScreen *screen;
+ GtkIconTheme *icon_theme;
+ GtkSettings *settings;
+ gint width, height;
+ GError *error = NULL;
+
+ g_return_if_fail (entry != NULL);
+ g_return_if_fail (GTK_IS_ICON_ENTRY (entry));
+ g_return_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos));
+
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (entry));
+ icon_theme = gtk_icon_theme_get_for_screen (screen);
+ settings = gtk_settings_get_for_screen (screen);
+
+ if (icon_name != NULL)
+ {
+ gtk_icon_size_lookup_for_settings (settings,
+ GTK_ICON_SIZE_MENU,
+ &width, &height);
+
+ pixbuf = gtk_icon_theme_load_icon (icon_theme,
+ icon_name,
+ MIN (width, height), 0, &error);
+
+ if (pixbuf == NULL)
+ {
+ g_error_free (error);
+ pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
+ GTK_STOCK_MISSING_IMAGE,
+ GTK_ICON_SIZE_MENU,
+ NULL);
+ }
+ }
+
+ gtk_icon_entry_set_icon_internal (entry,
+ icon_pos,
+ pixbuf);
+}
+
+/**
+ * gtk_icon_entry_set_icon_from_gicon
+ * @entry: A #GtkIconEntry;
+ * @icon_pos: The position at which to set the icon
+ * @icon: The icon to set
+ *
+ * Sets the icon shown in the entry at the specified position from the current
+ * icon theme. If the icon isn't known, a "broken image" icon will be displayed
+ * instead. If the current icon theme is changed, the icon will be updated
+ * appropriately.
+ */
+void
+gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ GIcon *icon)
+{
+ GdkPixbuf *pixbuf = NULL;
+ GtkIconEntryPrivate *priv;
+ EntryIconInfo *icon_info;
+ GdkScreen *screen;
+ GtkIconTheme *icon_theme;
+ GtkSettings *settings;
+ gint width, height;
+ GError *error = NULL;
+ GtkIconInfo *info;
+
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (entry));
+ icon_theme = gtk_icon_theme_get_for_screen (screen);
+ settings = gtk_settings_get_for_screen (screen);
+
+ if (icon != NULL)
+ {
+ gtk_icon_size_lookup_for_settings (settings,
+ GTK_ICON_SIZE_MENU,
+ &width, &height);
+
+ #if GTK_CHECK_VERSION (2, 14, 0)
+ info = gtk_icon_theme_lookup_by_gicon (icon_theme,
+ icon,
+ MIN (width, height), 0);
+ #else
+ info = NULL;
+ #endif
+ pixbuf = gtk_icon_info_load_icon (info, &error);
+ if (pixbuf == NULL)
+ {
+ g_error_free (error);
+ pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
+ GTK_STOCK_MISSING_IMAGE,
+ GTK_ICON_SIZE_MENU,
+ NULL);
+ }
+ }
+
+ gtk_icon_entry_set_icon_internal ((GtkIconEntry*)entry,
+ icon_pos,
+ pixbuf);
+}
+
+/**
+ * gtk_icon_entry_set_cursor
+ * @entry: A #GtkIconEntry;
+ * @icon_pos: The position at which to set the cursor
+ * @cursor_type: A #GdkCursorType; describing the cursor to set
+ *
+ * Sets an alternate mouse cursor used for the specified icon.
+ */
+void
+gtk_icon_entry_set_cursor (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ GdkCursorType cursor_type)
+{
+ EntryIconInfo *icon_info;
+ GtkIconEntryPrivate *priv;
+ GdkCursor *cursor;
+
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ icon_info->cursor_type = cursor_type;
+ icon_info->custom_cursor = TRUE;
+
+ if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
+ {
+ cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (entry)),
+ cursor_type);
+
+ gdk_window_set_cursor (icon_info->window, cursor);
+ gdk_cursor_unref (cursor);
+ }
+}
+
+/**
+ * gtk_icon_entry_set_icon_highlight
+ * @entry: A #GtkIconEntry;
+ * @position: Icon position.
+ * @highlight: TRUE if the icon should highlight on mouse-over
+ *
+ * Determines whether the icon will highlight on mouse-over.
+ */
+void
+gtk_icon_entry_set_icon_highlight (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ gboolean highlight)
+{
+ EntryIconInfo *icon_info;
+ GtkIconEntryPrivate *priv;
+
+ priv = entry->priv;
+
+ g_return_if_fail (entry != NULL);
+ g_return_if_fail (GTK_IS_ICON_ENTRY (entry));
+ g_return_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos));
+
+ icon_info = &priv->icons[icon_pos];
+
+ if (icon_info->highlight == highlight)
+ return;
+
+ icon_info->highlight = highlight;
+}
+
+/**
+ * gtk_icon_entry_get_pixbuf
+ * @entry: A #GtkIconEntry.
+ * @position: Icon position.
+ *
+ * Retrieves the image used for the icon. Unlike the other methods of setting
+ * and getting icon data, this method will work regardless of whether the icon
+ * was set using a #GdkPixbuf, a #GIcon, a stock item, or an icon name.
+ *
+ * Returns: A #GdkPixbuf, or NULL if no icon is set for this position.
+ */
+GdkPixbuf *
+gtk_icon_entry_get_pixbuf (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos)
+{
+ GtkIconEntryPrivate *priv;
+
+ g_return_val_if_fail (entry != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_ICON_ENTRY (entry), NULL);
+ g_return_val_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos), NULL);
+
+ priv = entry->priv;
+
+ return priv->icons[icon_pos].pixbuf;
+}
+
+/**
+ * gtk_icon_entry_get_gicon
+ * @entry: A #GtkIconEntry
+ * @position: Icon position.
+ *
+ * Retrieves the GIcon used for the icon, or NULL if there is no icon or if
+ * the icon was set by some other method (e.g., by stock, pixbuf, or icon name).
+ *
+ * Returns: A #GIcon, or NULL if no icon is set or if the icon is not a GIcon.
+ */
+GIcon *
+gtk_icon_entry_get_gicon (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos)
+{
+ GtkIconEntryPrivate *priv;
+ EntryIconInfo *icon_info;
+
+ g_return_val_if_fail (entry != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_ICON_ENTRY (entry), NULL);
+ g_return_val_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos), NULL);
+
+ priv = entry->priv;
+ icon_info = &priv->icons[icon_pos];
+
+ return icon_info->storage_type == _GTK_IMAGE_GICON ? icon_info->gicon : NULL;
+}
+
+/**
+ * gtk_icon_entry_get_icon_highlight
+ * @entry: A #GtkIconEntry.
+ * @position: Icon position.
+ *
+ * Retrieves whether entry will highlight the icon on mouseover.
+ *
+ * Returns: TRUE if icon highlights.
+ */
+gboolean
+gtk_icon_entry_get_icon_highlight (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos)
+{
+ GtkIconEntryPrivate *priv;
+
+ g_return_val_if_fail (entry != NULL, FALSE);
+ g_return_val_if_fail (GTK_IS_ICON_ENTRY (entry), FALSE);
+ g_return_val_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos), FALSE);
+
+ priv = entry->priv;
+
+ return priv->icons[icon_pos].highlight;
+}
+
+/**
+ * gtk_icon_entry_set_tooltip
+ * @entry: A #GtkIconEntry.
+ * @position: Icon position.
+ * @text: The text to be used for the tooltip.
+ *
+ * Sets the tooltip text used for the specified icon.
+ */
+void
+gtk_icon_entry_set_tooltip (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ const gchar *text)
+{
+ EntryIconInfo *icon_info;
+ GtkIconEntryPrivate *priv;
+ gchar *new_tooltip;
+
+ g_return_if_fail (entry != NULL);
+ g_return_if_fail (GTK_IS_ICON_ENTRY (entry));
+ g_return_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos));
+
+ priv = entry->priv;
+
+ icon_info = &priv->icons[icon_pos];
+
+ new_tooltip = g_strdup (text);
+ if (icon_info->tooltip_text != NULL)
+ g_free (icon_info->tooltip_text);
+ icon_info->tooltip_text = new_tooltip;
+}
+
+/**
+ * gtk_icon_entry_set_icon_sensitive
+ * @entry: A #GtkIconEntry.
+ * @position: Icon position.
+ * @sensitive: Specifies whether the icon should appear sensitive or insensitive.
+ *
+ * Sets the sensitivity for the specified icon.
+ */
+void
+gtk_icon_entry_set_icon_sensitive (const GtkIconEntry *icon_entry,
+ GtkIconEntryPosition icon_pos,
+ gboolean sensitive)
+{
+ EntryIconInfo *icon_info;
+ GtkIconEntryPrivate *priv;
+
+ g_return_if_fail (icon_entry != NULL);
+ g_return_if_fail (GTK_IS_ICON_ENTRY (icon_entry));
+ g_return_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos));
+
+ priv = icon_entry->priv;
+
+ icon_info = &priv->icons[icon_pos];
+
+ icon_info->insensitive = !sensitive;
+
+ if (icon_info->custom_cursor == TRUE && GTK_WIDGET_REALIZED (GTK_WIDGET (icon_entry)))
+ {
+ GdkCursor *cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (icon_entry)),
+ sensitive ? icon_info->cursor_type : GDK_ARROW);
+ gdk_window_set_cursor (icon_info->window, cursor);
+ gdk_cursor_unref (cursor);
+ }
+}
+
+void
+gtk_icon_entry_set_progress_fraction (GtkIconEntry *icon_entry,
+ gdouble fraction)
+{
+ GtkIconEntryPrivate *priv;
+
+ g_return_if_fail (GTK_IS_ICON_ENTRY (icon_entry));
+
+ priv = icon_entry->priv;
+ priv->fraction = CLAMP (fraction, 0.0, 1.0);
+
+ if (GTK_ENTRY (icon_entry)->text_area)
+ gdk_window_invalidate_rect (GTK_ENTRY (icon_entry)->text_area, NULL, FALSE);
+}
+
+#endif
diff --git a/midori/gtkiconentry.h b/midori/gtkiconentry.h
index daa1819d..18ec4e10 100644
--- a/midori/gtkiconentry.h
+++ b/midori/gtkiconentry.h
@@ -26,6 +26,7 @@
G_BEGIN_DECLS
+#if GTK_CHECK_VERSION (2, 16, 0)
#define GtkIconEntry GtkEntry
#define GtkIconEntryPosition GtkEntryIconPosition
#define GTK_ICON_ENTRY_PRIMARY GTK_ENTRY_ICON_PRIMARY
@@ -41,9 +42,99 @@ G_BEGIN_DECLS
GtkEntryIconPosition position,
GdkPixbuf* pixbuf);
#define gtk_icon_entry_set_tooltip gtk_entry_set_icon_tooltip_text
- #define gtk_icon_entry_get_tooltip gtk_entry_get_icon_tooltip_text
#define gtk_icon_entry_set_icon_highlight gtk_entry_set_icon_activatable
#define gtk_icon_entry_set_progress_fraction gtk_entry_set_progress_fraction
+#else
+
+#define GTK_TYPE_ICON_ENTRY (gtk_icon_entry_get_type())
+#define GTK_ICON_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_ICON_ENTRY, GtkIconEntry))
+#define GTK_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_ICON_ENTRY, GtkIconEntryClass))
+#define GTK_IS_ICON_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_ICON_ENTRY))
+#define GTK_IS_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_ICON_ENTRY))
+#define GTK_ICON_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ICON_ENTRY, GtkIconEntryClass))
+
+typedef enum
+{
+ GTK_ICON_ENTRY_PRIMARY,
+ GTK_ICON_ENTRY_SECONDARY
+} GtkIconEntryPosition;
+
+typedef struct _GtkIconEntry GtkIconEntry;
+typedef struct _GtkIconEntryClass GtkIconEntryClass;
+typedef struct _GtkIconEntryPrivate GtkIconEntryPrivate;
+
+struct _GtkIconEntry
+{
+ GtkEntry parent_object;
+
+ GtkIconEntryPrivate* priv;
+};
+
+struct _GtkIconEntryClass
+{
+ GtkEntryClass parent_class;
+
+ /* Signals */
+ void (*icon_pressed) (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ int button);
+ void (*icon_released) (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ int button);
+
+ void (*gtk_reserved1) (void);
+ void (*gtk_reserved2) (void);
+ void (*gtk_reserved3) (void);
+ void (*gtk_reserved4) (void);
+};
+
+GType gtk_icon_entry_get_type (void) G_GNUC_CONST;
+
+GtkWidget* gtk_icon_entry_new (void);
+
+void gtk_icon_entry_set_icon_from_pixbuf (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ GdkPixbuf *pixbuf);
+void gtk_icon_entry_set_icon_from_stock (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ const gchar *stock_id);
+void gtk_icon_entry_set_icon_from_icon_name (GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ const gchar *icon_name);
+
+void gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ GIcon *icon);
+
+GdkPixbuf* gtk_icon_entry_get_pixbuf (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos);
+
+GIcon* gtk_icon_entry_get_gicon (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos);
+
+void gtk_icon_entry_set_icon_highlight (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos,
+ gboolean highlight);
+
+gboolean gtk_icon_entry_get_icon_highlight (const GtkIconEntry *entry,
+ GtkIconEntryPosition icon_pos);
+
+void gtk_icon_entry_set_cursor (const GtkIconEntry *icon_entry,
+ GtkIconEntryPosition icon_pos,
+ GdkCursorType cursor_type);
+
+void gtk_icon_entry_set_tooltip (const GtkIconEntry *icon_entry,
+ GtkIconEntryPosition icon_pos,
+ const gchar *text);
+
+void gtk_icon_entry_set_icon_sensitive (const GtkIconEntry *icon_entry,
+ GtkIconEntryPosition icon_pos,
+ gboolean sensitive);
+
+void gtk_icon_entry_set_progress_fraction (GtkIconEntry *icon_entry,
+ gdouble fraction);
+
+#endif
G_END_DECLS
diff --git a/midori/main.c b/midori/main.c
index 2d3af37a..3800457e 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -13,7 +13,6 @@
#include "midori-app.h"
#include "midori-array.h"
#include "midori-bookmarks.h"
-#include "panels/midori-bookmarks.h"
#include "midori-extension.h"
#include "midori-extensions.h"
#include "midori-history.h"
@@ -45,6 +44,12 @@
#include
#endif
+#if HAVE_HILDON
+ #define BOOKMARK_FILE "/home/user/.bookmarks/MyBookmarks.xml"
+#else
+ #define BOOKMARK_FILE "bookmarks.xbel"
+#endif
+
#ifdef HAVE_X11_EXTENSIONS_SCRNSAVER_H
#include
#include
@@ -52,11 +57,18 @@
#include
#endif
+static gchar*
+build_config_filename (const gchar* filename)
+{
+ return g_build_filename (sokoke_set_config_dir (NULL), filename, NULL);
+}
+
static MidoriWebSettings*
-settings_and_accels_new (gchar*** extensions)
+settings_and_accels_new (const gchar* config,
+ gchar*** extensions)
{
MidoriWebSettings* settings = midori_web_settings_new ();
- gchar* config_file = midori_paths_get_readonly_config_filename ("config");
+ gchar* config_file = g_build_filename (config, "config", NULL);
GKeyFile* key_file = g_key_file_new ();
GError* error = NULL;
GObjectClass* class;
@@ -76,7 +88,7 @@ settings_and_accels_new (gchar*** extensions)
if (error->code == G_FILE_ERROR_NOENT)
{
GError* inner_error = NULL;
- katze_assign (config_file, midori_paths_get_preset_filename (NULL, "config"));
+ katze_assign (config_file, sokoke_find_config_filename (NULL, "config"));
g_key_file_load_from_file (key_file, config_file,
G_KEY_FILE_KEEP_COMMENTS, &inner_error);
if (inner_error != NULL)
@@ -149,9 +161,9 @@ settings_and_accels_new (gchar*** extensions)
g_key_file_free (key_file);
/* Load accelerators */
- katze_assign (config_file, midori_paths_get_config_filename ("accels"));
+ katze_assign (config_file, g_build_filename (config, "accels", NULL));
if (g_access (config_file, F_OK) != 0)
- katze_assign (config_file, midori_paths_get_preset_filename (NULL, "accels"));
+ katze_assign (config_file, sokoke_find_config_filename (NULL, "accels"));
gtk_accel_map_load (config_file);
g_free (config_file);
@@ -248,8 +260,15 @@ settings_save_to_file (MidoriWebSettings* settings,
}
g_free (pspecs);
- /* Take frozen list of active extensions until preferences reset it */
- if ((_extensions = g_object_get_data (G_OBJECT (app), "extensions")))
+ if (extensions)
+ {
+ KATZE_ARRAY_FOREACH_ITEM (extension, extensions)
+ if (midori_extension_is_active (extension))
+ g_key_file_set_boolean (key_file, "extensions",
+ g_object_get_data (G_OBJECT (extension), "filename"), TRUE);
+ g_object_unref (extensions);
+ }
+ else if ((_extensions = g_object_get_data (G_OBJECT (app), "extensions")))
{
i = 0;
while (_extensions[i])
@@ -258,30 +277,7 @@ settings_save_to_file (MidoriWebSettings* settings,
i++;
}
}
- else if (extensions)
- {
- KATZE_ARRAY_FOREACH_ITEM (extension, extensions)
- if (midori_extension_is_active (extension))
- {
- const gchar* filename = g_object_get_data (
- G_OBJECT (extension), "filename");
-
- gchar* key;
- gchar* term;
- key = katze_object_get_string (extension, "key");
- if (key && *key)
- term = g_strdup_printf ("%s/%s", filename, key);
- else
- term = g_strdup (filename);
-
- g_key_file_set_boolean (key_file, "extensions", term, TRUE);
-
- g_free (key);
- g_free (term);
- }
- g_object_unref (extensions);
- }
saved = sokoke_key_file_save_to_file (key_file, filename, error);
g_key_file_free (key_file);
return saved;
@@ -304,6 +300,8 @@ search_engines_new_from_file (const gchar* filename,
key_file = g_key_file_new ();
g_key_file_load_from_file (key_file, filename,
G_KEY_FILE_KEEP_COMMENTS, error);
+ /*g_key_file_load_from_data_dirs(keyFile, sFilename, NULL
+ , G_KEY_FILE_KEEP_COMMENTS, error);*/
engines = g_key_file_get_groups (key_file, NULL);
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (search_engines),
&n_properties);
@@ -329,9 +327,10 @@ search_engines_new_from_file (const gchar* filename,
}
static KatzeArray*
-search_engines_new_from_folder (GString* error_messages)
+search_engines_new_from_folder (const gchar* config,
+ GString* error_messages)
{
- gchar* config_file = midori_paths_get_config_filename ("search");
+ gchar* config_file = g_build_filename (config, "search", NULL);
GError* error = NULL;
KatzeArray* search_engines;
@@ -345,10 +344,18 @@ search_engines_new_from_folder (GString* error_messages)
}
if (!error && katze_array_is_empty (search_engines))
{
+ g_object_unref (search_engines);
+ #ifdef G_OS_WIN32
+ gchar* dir = g_win32_get_package_installation_directory_of_module (NULL);
katze_assign (config_file,
- midori_paths_get_preset_filename (NULL, "search"));
- katze_object_assign (search_engines,
- search_engines_new_from_file (config_file, NULL));
+ g_build_filename (dir, "etc", "xdg", PACKAGE_NAME, "search", NULL));
+ g_free (dir);
+ search_engines = search_engines_new_from_file (config_file, NULL);
+ #else
+ katze_assign (config_file,
+ sokoke_find_config_filename (NULL, "search"));
+ search_engines = search_engines_new_from_file (config_file, NULL);
+ #endif
}
else if (error)
{
@@ -416,6 +423,7 @@ midori_history_clear_cb (KatzeArray* array,
static gboolean
midori_history_initialize (KatzeArray* array,
const gchar* filename,
+ const gchar* bookmarks_filename,
char** errmsg)
{
sqlite3* db;
@@ -423,9 +431,6 @@ midori_history_initialize (KatzeArray* array,
sqlite3_stmt* stmt;
gint result;
gchar* sql;
- gchar* bookmarks_filename;
-
- g_return_val_if_fail (errmsg != NULL, FALSE);
if (sqlite3_open (filename, &db) != SQLITE_OK)
{
@@ -436,13 +441,7 @@ midori_history_initialize (KatzeArray* array,
return FALSE;
}
- if (sqlite3_exec (db,
- "PRAGMA journal_mode = WAL; PRAGMA cache_size = 32100;",
- NULL, NULL, errmsg) != SQLITE_OK)
- sqlite3_exec (db, "PRAGMA journal_mode = TRUNCATE;", NULL, NULL, errmsg);
- sqlite3_exec (db,
- "PRAGMA synchronous = NORMAL; PRAGMA temp_store = MEMORY;",
- NULL, NULL, errmsg);
+ sqlite3_exec (db, "PRAGMA journal_mode = TRUNCATE;", NULL, NULL, errmsg);
if (*errmsg)
{
g_warning ("Failed to set journal mode: %s", *errmsg);
@@ -477,9 +476,7 @@ midori_history_initialize (KatzeArray* array,
"COMMIT;",
NULL, NULL, errmsg);
- bookmarks_filename = midori_paths_get_config_filename ("bookmarks_v2.db");
sql = g_strdup_printf ("ATTACH DATABASE '%s' AS bookmarks", bookmarks_filename);
- g_free (bookmarks_filename);
sqlite3_exec (db, sql, NULL, NULL, errmsg);
g_free (sql);
g_object_set_data (G_OBJECT (array), "db", db);
@@ -509,6 +506,93 @@ midori_history_terminate (KatzeArray* array,
sqlite3_close (db);
}
+static void
+midori_bookmarks_add_item_cb (KatzeArray* array,
+ KatzeItem* item,
+ sqlite3* db)
+{
+ midori_bookmarks_insert_item_db (db, item,
+ katze_item_get_meta_string (item, "folder"));
+}
+
+static void
+midori_bookmarks_remove_item_cb (KatzeArray* array,
+ KatzeItem* item,
+ sqlite3* db)
+{
+ gchar* sqlcmd;
+ char* errmsg = NULL;
+
+ if (KATZE_ITEM_IS_BOOKMARK (item))
+ sqlcmd = sqlite3_mprintf (
+ "DELETE FROM bookmarks WHERE uri = '%q' "
+ " AND folder = '%q'",
+ katze_item_get_uri (item),
+ katze_item_get_meta_string (item, "folder"));
+
+ else
+ sqlcmd = sqlite3_mprintf (
+ "DELETE FROM bookmarks WHERE title = '%q'"
+ " AND folder = '%q'",
+ katze_item_get_name (item),
+ katze_item_get_meta_string (item, "folder"));
+
+ if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
+ {
+ g_printerr (_("Failed to remove history item: %s\n"), errmsg);
+ sqlite3_free (errmsg);
+ }
+
+ sqlite3_free (sqlcmd);
+}
+
+static sqlite3*
+midori_bookmarks_initialize (KatzeArray* array,
+ const gchar* filename,
+ char** errmsg)
+{
+ sqlite3* db;
+
+ if (sqlite3_open (filename, &db) != SQLITE_OK)
+ {
+ if (errmsg)
+ *errmsg = g_strdup_printf (_("Failed to open database: %s\n"),
+ sqlite3_errmsg (db));
+ sqlite3_close (db);
+ return NULL;
+ }
+
+ if (sqlite3_exec (db,
+ "CREATE TABLE IF NOT EXISTS "
+ "bookmarks (uri text, title text, folder text, "
+ "desc text, app integer, toolbar integer);",
+ NULL, NULL, errmsg) != SQLITE_OK)
+ return NULL;
+ g_signal_connect (array, "add-item",
+ G_CALLBACK (midori_bookmarks_add_item_cb), db);
+ g_signal_connect (array, "remove-item",
+ G_CALLBACK (midori_bookmarks_remove_item_cb), db);
+ return db;
+}
+
+static void
+midori_bookmarks_import (const gchar* filename,
+ sqlite3* db)
+{
+ KatzeArray* bookmarks;
+ GError* error = NULL;
+
+ bookmarks = katze_array_new (KATZE_TYPE_ARRAY);
+
+ if (!midori_array_from_file (bookmarks, filename, "xbel", &error))
+ {
+ g_warning (_("The bookmarks couldn't be saved. %s"), error->message);
+ g_error_free (error);
+ return;
+ }
+ midori_bookmarks_import_array_db (db, bookmarks, "");
+}
+
static void
settings_notify_cb (MidoriWebSettings* settings,
GParamSpec* pspec,
@@ -518,10 +602,10 @@ settings_notify_cb (MidoriWebSettings* settings,
gchar* config_file;
/* Skip state related properties to avoid disk IO */
- if (pspec && midori_settings_delay_saving (MIDORI_SETTINGS (settings), pspec->name))
+ if (pspec && pspec->flags & MIDORI_PARAM_DELAY_SAVING)
return;
- config_file = midori_paths_get_config_filename ("config");
+ config_file = build_config_filename ("config");
if (!settings_save_to_file (settings, app, config_file, &error))
{
g_warning (_("The configuration couldn't be saved. %s"), error->message);
@@ -530,13 +614,22 @@ settings_notify_cb (MidoriWebSettings* settings,
g_free (config_file);
}
+static void
+extension_activate_cb (MidoriExtension* extension,
+ MidoriApp* app)
+{
+ MidoriWebSettings* settings = katze_object_get_object (app, "settings");
+ settings_notify_cb (settings, NULL, app);
+ g_object_unref (settings);
+}
+
static void
accel_map_changed_cb (GtkAccelMap* accel_map,
gchar* accel_path,
guint accel_key,
GdkModifierType accel_mods)
{
- gchar* config_file = midori_paths_get_config_filename ("accels");
+ gchar* config_file = build_config_filename ("accels");
gtk_accel_map_save (config_file);
g_free (config_file);
}
@@ -546,7 +639,7 @@ midori_search_engines_modify_cb (KatzeArray* array,
gpointer item,
KatzeArray* search_engines)
{
- gchar* config_file = midori_paths_get_config_filename ("search");
+ gchar* config_file = build_config_filename ("search");
GError* error = NULL;
if (!search_engines_save_to_file (search_engines, config_file, &error))
{
@@ -581,7 +674,7 @@ static void
midori_trash_remove_item_cb (KatzeArray* trash,
GObject* item)
{
- gchar* config_file = midori_paths_get_config_filename ("tabtrash.xbel");
+ gchar* config_file = build_config_filename ("tabtrash.xbel");
GError* error = NULL;
midori_trash_add_item_no_save_cb (trash, item);
if (!midori_array_to_file (trash, config_file, "xbel", &error))
@@ -600,51 +693,19 @@ midori_trash_add_item_cb (KatzeArray* trash,
midori_trash_remove_item_cb (trash, item);
}
-static void
-midori_load_module (MidoriApp* app,
- const gchar* extension_path,
- const gchar* filename,
- gboolean activate);
static void
midori_browser_show_preferences_cb (MidoriBrowser* browser,
KatzePreferences* preferences,
MidoriApp* app)
{
KatzeArray* array;
- gchar* extension_path;
GtkWidget* scrolled;
GtkWidget* addon;
GList* children;
GtkWidget* page;
- if (!g_module_supported ())
- return;
-
- array = katze_object_get_object (app, "extensions");
- if ((extension_path = midori_paths_get_lib_path (PACKAGE_NAME)))
- {
- GDir* extension_dir = NULL;
- if ((extension_dir = g_dir_open (extension_path, 0, NULL)))
- {
- const gchar* filename;
- while ((filename = g_dir_read_name (extension_dir)))
- {
- /* Ignore files which don't have the correct suffix */
- if (!g_str_has_suffix (filename, G_MODULE_SUFFIX))
- continue;
-
- midori_load_module (app, extension_path, filename, FALSE);
- }
- g_dir_close (extension_dir);
- }
- g_free (extension_path);
- }
-
-
- /* Reset frozen list: allow active extensions to be saved */
- g_object_set_data (G_OBJECT (app), "extensions", NULL);
-
/* Hide if there are no extensions at all */
+ array = katze_object_get_object (app, "extensions");
if (!katze_array_get_nth_item (array, 0))
{
g_object_unref (array);
@@ -660,7 +721,7 @@ midori_browser_show_preferences_cb (MidoriBrowser* browser,
gtk_widget_reparent (g_list_nth_data (children, 0), scrolled);
g_list_free (children);
page = katze_preferences_add_category (preferences,
- _("Extensions"), STOCK_EXTENSION);
+ _("Extensions"), STOCK_EXTENSIONS);
gtk_box_pack_start (GTK_BOX (page), scrolled, TRUE, TRUE, 4);
}
@@ -676,17 +737,12 @@ midori_browser_privacy_preferences_cb (MidoriBrowser* browser,
katze_preferences_add_category (preferences, _("Privacy"), GTK_STOCK_INDEX);
katze_preferences_add_group (preferences, NULL);
- button = gtk_label_new (_("Delete old Cookies after:"));
- gtk_misc_set_alignment (GTK_MISC (button), 0.0, 0.5);
- gtk_widget_set_tooltip_text (button, _("The maximum number of days to save cookies for"));
+ button = katze_property_label (settings, "maximum-cookie-age");
katze_preferences_add_widget (preferences, button, "indented");
button = katze_property_proxy (settings, "maximum-cookie-age", "days");
- gtk_widget_set_tooltip_text (button, _("The maximum number of days to save cookies for"));
katze_preferences_add_widget (preferences, button, "spanned");
#ifdef HAVE_LIBSOUP_2_29_91
button = katze_property_proxy (settings, "first-party-cookies-only", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Only accept Cookies from sites you visit"));
- gtk_widget_set_tooltip_text (button, _("Block cookies sent by third-party websites"));
katze_preferences_add_widget (preferences, button, "filled");
#endif
@@ -698,24 +754,15 @@ midori_browser_privacy_preferences_cb (MidoriBrowser* browser,
g_free (markup);
katze_preferences_add_widget (preferences, label, "filled");
button = katze_property_proxy (settings, "enable-offline-web-application-cache", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Enable offline web application cache"));
katze_preferences_add_widget (preferences, button, "indented");
button = katze_property_proxy (settings, "enable-html5-local-storage", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Enable HTML5 local storage support"));
katze_preferences_add_widget (preferences, button, "spanned");
button = katze_property_proxy (settings, "strip-referer", NULL);
- /* i18n: Reworded: Shorten details propagated when going to another page */
- gtk_button_set_label (GTK_BUTTON (button), _("Strip referrer details sent to websites"));
- /* i18n: Referer here is not a typo but a technical term */
- gtk_widget_set_tooltip_text (button, _("Whether the \"Referer\" header should be shortened to the hostname"));
katze_preferences_add_widget (preferences, button, "indented");
katze_preferences_add_widget (preferences, gtk_label_new (NULL), "indented");
- button = gtk_label_new (_("Delete pages from history after:"));
- gtk_misc_set_alignment (GTK_MISC (button), 0.0, 0.5);
- gtk_widget_set_tooltip_text (button, _("The maximum number of days to save the history for"));
+ button = katze_property_label (settings, "maximum-history-age");
katze_preferences_add_widget (preferences, button, "indented");
button = katze_property_proxy (settings, "maximum-history-age", "days");
- gtk_widget_set_tooltip_text (button, _("The maximum number of days to save the history for"));
katze_preferences_add_widget (preferences, button, "spanned");
}
@@ -752,7 +799,7 @@ static guint save_timeout = 0;
static gboolean
midori_session_save_timeout_cb (KatzeArray* session)
{
- gchar* config_file = midori_paths_get_config_filename ("session.xbel");
+ gchar* config_file = build_config_filename ("session.xbel");
GError* error = NULL;
if (!midori_array_to_file (session, config_file, "xbel", &error))
{
@@ -784,7 +831,7 @@ static void
midori_app_quit_cb (MidoriBrowser* browser,
KatzeArray* session)
{
- gchar* config_file = midori_paths_get_config_filename ("running");
+ gchar* config_file = build_config_filename ("running");
g_unlink (config_file);
g_free (config_file);
@@ -876,69 +923,63 @@ soup_session_settings_notify_first_party_cb (MidoriWebSettings* settings,
}
#endif
-#if defined (HAVE_LIBSOUP_2_34_0)
-/* Implemented in MidoriLocationAction */
-void
-midori_map_add_message (SoupMessage* message);
-
-static void
-midori_soup_session_request_started_cb (SoupSession* session,
- SoupMessage* message,
- SoupSocket* socket,
- gpointer user_data)
-{
- midori_map_add_message (message);
-}
-#endif
-
static void
midori_soup_session_settings_accept_language_cb (SoupSession* session,
SoupMessage* msg,
MidoriWebSettings* settings)
{
- const gchar* accept = midori_web_settings_get_accept_language (settings);
- soup_message_headers_append (msg->request_headers, "Accept-Language", accept);
+ gchar* languages = katze_object_get_string (settings, "preferred-languages");
+ gchar* accpt;
+
+ /* Empty, use the system locales */
+ if (!(languages && *languages))
+ accpt = sokoke_accept_languages (g_get_language_names ());
+ /* No =, no ., looks like a list of language names */
+ else if (!(strchr (languages, '=') && strchr (languages, '.')))
+ {
+ gchar ** lang_names = g_strsplit_set (languages, ",; ", -1);
+ accpt = sokoke_accept_languages ((const gchar* const *)lang_names);
+ g_strfreev (lang_names);
+ }
+ /* Presumably a well formatted list including priorities */
+ else
+ accpt = languages;
+
+ if (accpt != languages)
+ g_free (languages);
+ soup_message_headers_append (msg->request_headers, "Accept-Language", accpt);
+ g_free (accpt);
if (katze_object_get_boolean (settings, "strip-referer"))
{
const gchar* referer
= soup_message_headers_get_one (msg->request_headers, "Referer");
SoupURI* destination = soup_message_get_uri (msg);
- SoupURI* stripped_uri;
- if (referer && destination && !strstr (referer, destination->host)
- && (stripped_uri = soup_uri_new (referer)))
+ if (referer && destination && !strstr (referer, destination->host))
{
+ SoupURI* stripped_uri = soup_uri_new (referer);
gchar* stripped_referer;
- soup_uri_set_path (stripped_uri, "");
+ soup_uri_set_path (stripped_uri, NULL);
soup_uri_set_query (stripped_uri, NULL);
stripped_referer = soup_uri_to_string (stripped_uri, FALSE);
soup_uri_free (stripped_uri);
- if (strcmp (stripped_referer, referer))
- {
- if (midori_debug ("referer"))
- g_message ("Referer '%s' stripped to '%s'", referer, stripped_referer);
- soup_message_headers_replace (msg->request_headers, "Referer",
- stripped_referer);
- }
+ if (g_getenv ("MIDORI_SOUP_DEBUG"))
+ g_message ("Referer stripped");
+ soup_message_headers_replace (msg->request_headers, "Referer",
+ stripped_referer);
g_free (stripped_referer);
}
-
- /* With HTTP, Host is optional. Strip to outsmart some filter proxies */
- if (destination && destination->scheme == SOUP_URI_SCHEME_HTTP)
- soup_message_headers_remove (msg->request_headers, "Host");
}
}
static void
midori_soup_session_debug (SoupSession* session)
{
- gint soup_debug_level = 0;
- if (midori_debug ("headers"))
- soup_debug_level = SOUP_LOGGER_LOG_HEADERS;
- else if (midori_debug ("body"))
- soup_debug_level = SOUP_LOGGER_LOG_BODY;
- if (soup_debug_level > 0)
+ const char* soup_debug = g_getenv ("MIDORI_SOUP_DEBUG");
+
+ if (soup_debug)
{
+ gint soup_debug_level = atoi (soup_debug);
SoupLogger* logger = soup_logger_new (soup_debug_level, -1);
soup_logger_attach (logger, session);
g_object_unref (logger);
@@ -950,7 +991,6 @@ midori_load_soup_session (gpointer settings)
{
SoupSession* session = webkit_get_default_session ();
- #ifndef G_OS_WIN32
#if defined (HAVE_LIBSOUP_2_37_1)
g_object_set (session,
"ssl-use-system-ca-file", TRUE,
@@ -981,17 +1021,6 @@ midori_load_soup_session (gpointer settings)
g_warning (_("No root certificate file is available. "
"SSL certificates cannot be verified."));
#endif
- #else /* G_OS_WIN32 */
- /* We cannot use "ssl-use-system-ca-file" on Windows
- * some GTLS backend pieces are missing currently.
- * Instead we specify the bundle we ship ourselves */
- gchar* certificate_file = midori_paths_get_res_filename ("ca-bundle.crt");
- g_object_set (session,
- "ssl-ca-file", certificate_file,
- "ssl-strict", FALSE,
- NULL);
- g_free (certificate_file);
- #endif
#if !WEBKIT_CHECK_VERSION (1, 3, 5)
/* See http://stevesouders.com/ua/index.php */
@@ -1000,7 +1029,6 @@ midori_load_soup_session (gpointer settings)
NULL);
#endif
- g_object_set_data (G_OBJECT (session), "midori-settings", settings);
soup_session_settings_notify_http_proxy_cb (settings, NULL, session);
g_signal_connect (settings, "notify::http-proxy",
G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session);
@@ -1013,23 +1041,9 @@ midori_load_soup_session (gpointer settings)
G_CALLBACK (soup_session_settings_notify_first_party_cb), session);
#endif
- #if WEBKIT_CHECK_VERSION (1, 8, 0)
- gchar* cache = g_build_filename (midori_paths_get_user_data_dir (),
- "webkit", "icondatabase", NULL);
- webkit_favicon_database_set_path (webkit_get_favicon_database (), cache);
- g_free (cache);
- #endif
-
- #if defined (HAVE_LIBSOUP_2_34_0)
- g_signal_connect (session, "request-started",
- G_CALLBACK (midori_soup_session_request_started_cb), session);
- #endif
g_signal_connect (session, "request-queued",
G_CALLBACK (midori_soup_session_settings_accept_language_cb), settings);
- soup_session_add_feature (session, SOUP_SESSION_FEATURE (
- midori_hsts_new (midori_paths_get_readonly_config_filename ("hsts"))));
-
midori_soup_session_debug (session);
g_object_set_data (G_OBJECT (session), "midori-session-initialized", (void*)1);
@@ -1051,7 +1065,6 @@ static void
button_disable_extensions_clicked_cb (GtkWidget* button,
MidoriApp* app)
{
- /* Reset frozen list of active extensions */
g_object_set_data (G_OBJECT (app), "extensions", NULL);
gtk_widget_set_sensitive (button, FALSE);
}
@@ -1105,7 +1118,6 @@ midori_show_diagnostic_dialog (MidoriWebSettings* settings,
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4);
gtk_widget_show_all (align);
button = katze_property_proxy (settings, "show-crash-dialog", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Show a dialog after Midori crashed"));
gtk_widget_show (button);
gtk_container_add (GTK_CONTAINER (content_area), button);
gtk_container_set_focus_child (GTK_CONTAINER (dialog), gtk_dialog_get_action_area (GTK_DIALOG (dialog)));
@@ -1161,7 +1173,7 @@ midori_load_soup_session_full (gpointer settings)
midori_load_soup_session (settings);
- config_file = midori_paths_get_config_filename ("logins");
+ config_file = build_config_filename ("logins");
feature = g_object_new (KATZE_TYPE_HTTP_AUTH, "filename", config_file, NULL);
soup_session_add_feature (session, feature);
g_object_unref (feature);
@@ -1171,7 +1183,7 @@ midori_load_soup_session_full (gpointer settings)
soup_session_add_feature (session, SOUP_SESSION_FEATURE (jar));
g_object_unref (jar);
- katze_assign (config_file, midori_paths_get_config_filename ("cookies.db"));
+ katze_assign (config_file, build_config_filename ("cookies.db"));
have_new_cookies = g_access (config_file, F_OK) == 0;
feature = g_object_new (KATZE_TYPE_HTTP_COOKIES_SQLITE, NULL);
g_object_set_data_full (G_OBJECT (feature), "filename",
@@ -1181,7 +1193,7 @@ midori_load_soup_session_full (gpointer settings)
if (!have_new_cookies)
{
- katze_assign (config_file, midori_paths_get_config_filename ("cookies.txt"));
+ katze_assign (config_file, build_config_filename ("cookies.txt"));
if (g_access (config_file, F_OK) == 0)
{
g_message ("Importing cookies from txt to sqlite3");
@@ -1194,7 +1206,8 @@ midori_load_soup_session_full (gpointer settings)
}
#if WEBKIT_CHECK_VERSION (1, 3, 11)
- katze_assign (config_file, g_build_filename (midori_paths_get_cache_dir (), "web", NULL));
+ katze_assign (config_file, g_build_filename (g_get_user_cache_dir (),
+ PACKAGE_NAME, "web", NULL));
feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0));
soup_session_add_feature (session, feature);
soup_cache_set_max_size (SOUP_CACHE (feature),
@@ -1206,135 +1219,95 @@ midori_load_soup_session_full (gpointer settings)
return FALSE;
}
-static void
-midori_load_extension (MidoriApp* app,
- MidoriExtension* extension,
- const gchar* filename)
-{
- KatzeArray* extensions = katze_object_get_object (app, "extensions");
- /* Signal that we want the extension to load and save */
- g_object_set_data_full (G_OBJECT (extension), "filename",
- g_strdup (filename), g_free);
- if (midori_extension_is_prepared (extension))
- midori_extension_get_config_dir (extension);
- katze_array_add_item (extensions, extension);
- g_object_unref (extensions);
-}
-
-static void
-midori_load_module (MidoriApp* app,
- const gchar* extension_path,
- const gchar* filename,
- gboolean activate)
-{
- gchar* fullname;
- GModule* module;
- typedef GObject* (*extension_init_func)(void);
- extension_init_func extension_init;
- GObject* extension = NULL;
- static GHashTable* modules = NULL;
-
- if (strchr (filename, '/'))
- {
- gchar* clean = g_strndup (filename, strchr (filename, '/') - filename);
- fullname = g_build_filename (extension_path, clean, NULL);
- g_free (clean);
- }
- else
- fullname = g_build_filename (extension_path, filename, NULL);
-
- module = g_module_open (fullname, G_MODULE_BIND_LOCAL);
- g_free (fullname);
-
- /* GModule detects repeated loading but exposes no API to check it.
- Skip any modules that were loaded before. */
- if (modules == NULL)
- modules = g_hash_table_new (g_direct_hash, g_direct_equal);
- if (g_hash_table_lookup (modules, module))
- return;
- g_hash_table_insert (modules, module, g_strdup (filename));
-
- if (module && g_module_symbol (module, "extension_init",
- (gpointer) &extension_init)
- && (extension = extension_init ()))
- {
- if (MIDORI_IS_EXTENSION (extension))
- {
- midori_load_extension (app, MIDORI_EXTENSION (extension), filename);
- if (activate)
- g_signal_emit_by_name (extension, "activate", app);
- }
- else if (KATZE_IS_ARRAY (extension))
- {
- MidoriExtension* extension_item;
- KATZE_ARRAY_FOREACH_ITEM (extension_item, KATZE_ARRAY (extension))
- if (MIDORI_IS_EXTENSION (extension_item))
- {
- gchar* key;
-
- midori_load_extension (app, extension_item, filename);
- if (activate)
- {
- key = katze_object_get_string (extension_item, "key");
- if (key && strstr (filename, key))
- g_signal_emit_by_name (extension_item, "activate", app);
- g_free (key);
- }
- }
- }
- }
-
- if (!extension && g_module_error () != NULL)
- {
- KatzeArray* extensions = katze_object_get_object (app, "extensions");
- extension = g_object_new (MIDORI_TYPE_EXTENSION,
- "name", filename,
- "description", g_module_error (),
- NULL);
- g_warning ("%s", g_module_error ());
- katze_array_add_item (extensions, extension);
- g_object_unref (extensions);
- }
- g_object_unref (extension);
-}
-
-static void
-extensions_update_cb (KatzeArray* extensions,
- MidoriApp* app)
-{
- MidoriWebSettings* settings = katze_object_get_object (app, "settings");
- settings_notify_cb (settings, NULL, app);
- g_object_unref (settings);
-}
-
static gboolean
midori_load_extensions (gpointer data)
{
MidoriApp* app = MIDORI_APP (data);
- gchar** keys = g_object_get_data (G_OBJECT (app), "extensions");
+ gchar** active_extensions = g_object_get_data (G_OBJECT (app), "extensions");
KatzeArray* extensions;
#ifdef G_ENABLE_DEBUG
- gboolean startup_timer = midori_debug ("startup");
+ gboolean startup_timer = g_getenv ("MIDORI_STARTTIME") != NULL;
GTimer* timer = startup_timer ? g_timer_new () : NULL;
#endif
/* Load extensions */
extensions = katze_array_new (MIDORI_TYPE_EXTENSION);
- g_signal_connect (extensions, "update", G_CALLBACK (extensions_update_cb), app);
g_object_set (app, "extensions", extensions, NULL);
-
if (g_module_supported ())
{
gchar* extension_path;
- if (keys && (extension_path = midori_paths_get_lib_path (PACKAGE_NAME)))
+ GDir* extension_dir = NULL;
+
+ if (!(extension_path = g_strdup (g_getenv ("MIDORI_EXTENSION_PATH"))))
+ extension_path = sokoke_find_lib_path (PACKAGE_NAME);
+ if (extension_path != NULL)
+ extension_dir = g_dir_open (extension_path, 0, NULL);
+ if (extension_dir != NULL)
{
- gint i = 0;
const gchar* filename;
- while ((filename = keys[i++]))
- midori_load_module (app, extension_path, filename, TRUE);
- g_free (extension_path);
+
+ while ((filename = g_dir_read_name (extension_dir)))
+ {
+ gchar* fullname;
+ GModule* module;
+ typedef MidoriExtension* (*extension_init_func)(void);
+ extension_init_func extension_init;
+ MidoriExtension* extension = NULL;
+
+ /* Ignore files which don't have the correct suffix */
+ if (!g_str_has_suffix (filename, G_MODULE_SUFFIX))
+ continue;
+
+ fullname = g_build_filename (extension_path, filename, NULL);
+ module = g_module_open (fullname, G_MODULE_BIND_LOCAL);
+ g_free (fullname);
+
+ if (module && g_module_symbol (module, "extension_init",
+ (gpointer) &extension_init))
+ {
+ extension = extension_init ();
+ if (extension != NULL)
+ {
+ /* Signal that we want the extension to load and save */
+ g_object_set_data_full (G_OBJECT (extension), "filename",
+ g_strdup (filename), g_free);
+ if (midori_extension_is_prepared (extension))
+ midori_extension_get_config_dir (extension);
+ }
+ }
+
+ if (!extension)
+ {
+ /* No extension, no error: not available, not shown */
+ if (g_module_error () == NULL)
+ continue;
+
+ extension = g_object_new (MIDORI_TYPE_EXTENSION,
+ "name", filename,
+ "description", g_module_error (),
+ NULL);
+ g_warning ("%s", g_module_error ());
+ }
+ katze_array_add_item (extensions, extension);
+ if (active_extensions)
+ {
+ guint i = 0;
+ gchar* name;
+ while ((name = active_extensions[i++]))
+ if (!g_strcmp0 (filename, name))
+ g_signal_emit_by_name (extension, "activate", app);
+ }
+ g_signal_connect_after (extension, "activate",
+ G_CALLBACK (extension_activate_cb), app);
+ g_signal_connect_after (extension, "deactivate",
+ G_CALLBACK (extension_activate_cb), app);
+ g_object_unref (extension);
+ }
+ g_dir_close (extension_dir);
}
+ g_free (extension_path);
}
+ g_strfreev (active_extensions);
#ifdef G_ENABLE_DEBUG
if (startup_timer)
@@ -1349,7 +1322,7 @@ midori_browser_action_last_session_activate_cb (GtkAction* action,
MidoriBrowser* browser)
{
KatzeArray* old_session = katze_array_new (KATZE_TYPE_ITEM);
- gchar* config_file = midori_paths_get_readonly_config_filename ("session.old.xbel");
+ gchar* config_file = build_config_filename ("session.old.xbel");
GError* error = NULL;
if (midori_array_from_file (old_session, config_file, "xbel", &error))
{
@@ -1383,7 +1356,7 @@ midori_load_session (gpointer data)
gint64 current;
gchar** command = g_object_get_data (G_OBJECT (app), "execute-command");
#ifdef G_ENABLE_DEBUG
- gboolean startup_timer = midori_debug ("startup");
+ gboolean startup_timer = g_getenv ("MIDORI_STARTTIME") != NULL;
GTimer* timer = startup_timer ? g_timer_new () : NULL;
#endif
@@ -1391,7 +1364,7 @@ midori_load_session (gpointer data)
g_signal_connect_after (katze_object_get_object (app, "settings"), "notify",
G_CALLBACK (settings_notify_cb), app);
- config_file = midori_paths_get_readonly_config_filename ("session.old.xbel");
+ config_file = build_config_filename ("session.old.xbel");
if (g_access (config_file, F_OK) == 0)
{
GtkActionGroup* action_group = midori_browser_get_action_group (browser);
@@ -1403,7 +1376,7 @@ midori_load_session (gpointer data)
midori_app_add_browser (app, browser);
gtk_widget_show (GTK_WIDGET (browser));
- katze_assign (config_file, midori_paths_get_readonly_config_filename ("accels"));
+ katze_assign (config_file, build_config_filename ("accels"));
g_signal_connect_after (gtk_accel_map_get (), "changed",
G_CALLBACK (accel_map_changed_cb), NULL);
@@ -1447,7 +1420,7 @@ midori_load_session (gpointer data)
g_object_unref (settings);
g_object_unref (_session);
- katze_assign (config_file, midori_paths_get_readonly_config_filename ("session.xbel"));
+ katze_assign (config_file, build_config_filename ("session.xbel"));
g_signal_connect_after (browser, "add-tab",
G_CALLBACK (midori_browser_session_cb), session);
g_signal_connect_after (browser, "remove-tab",
@@ -1501,6 +1474,21 @@ snapshot_load_finished_cb (GtkWidget* web_view,
gtk_main_quit ();
}
+static void
+midori_web_app_browser_notify_load_status_cb (MidoriBrowser* browser,
+ GParamSpec* pspec,
+ gpointer data)
+{
+ if (katze_object_get_enum (browser, "load-status") != MIDORI_LOAD_PROVISIONAL)
+ {
+ GtkWidget* view = midori_browser_get_current_tab (browser);
+ GdkPixbuf* icon = midori_view_get_icon (MIDORI_VIEW (view));
+ if (midori_view_is_blank (MIDORI_VIEW (view)))
+ icon = NULL;
+ gtk_window_set_icon (GTK_WINDOW (browser), icon);
+ }
+}
+
static MidoriBrowser*
midori_web_app_browser_new_window_cb (MidoriBrowser* browser,
MidoriBrowser* new_browser,
@@ -1522,7 +1510,7 @@ midori_remove_config_file (gint clear_prefs,
{
if ((clear_prefs & flag) == flag)
{
- gchar* config_file = midori_paths_get_config_filename (filename);
+ gchar* config_file = build_config_filename (filename);
g_unlink (config_file);
g_free (config_file);
}
@@ -1533,10 +1521,11 @@ midori_prepare_uri (const gchar *uri)
{
gchar* uri_ready;
- if (g_str_has_prefix(uri, "javascript:"))
+ if (g_path_is_absolute (uri))
+ return g_filename_to_uri (uri, NULL, NULL);
+ else if (g_str_has_prefix(uri, "javascript:"))
return NULL;
- else if (g_file_test (uri, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)
- && !g_path_is_absolute (uri))
+ else if (g_file_test (uri, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
{
gchar* current_dir = g_get_current_dir ();
uri_ready = g_strconcat ("file://", current_dir,
@@ -1559,6 +1548,93 @@ signal_handler (int signal_id)
}
#endif
+static GKeyFile*
+speeddial_new_from_file (const gchar* config,
+ GError** error)
+{
+
+ GKeyFile* key_file = g_key_file_new ();
+ gchar* config_file = g_build_filename (config, "speeddial", NULL);
+ guint i = 0;
+ gchar* json_content;
+ gsize json_length;
+ GString* script;
+ JSGlobalContextRef js_context;
+ gchar* keyfile;
+ gchar* thumb_dir;
+ gchar** tiles;
+
+ if (g_key_file_load_from_file (key_file, config_file, G_KEY_FILE_NONE, error))
+ {
+ g_free (config_file);
+ return key_file;
+ }
+
+ katze_assign (config_file, g_build_filename (config, "speeddial.json", NULL));
+ if (!g_file_get_contents (config_file, &json_content, &json_length, NULL))
+ {
+ katze_assign (json_content, g_strdup ("'{}'"));
+ json_length = strlen ("'{}'");
+ }
+
+ script = g_string_sized_new (json_length);
+ g_string_append (script, "var json = JSON.parse (");
+ g_string_append_len (script, json_content, json_length);
+ g_string_append (script, "); "
+ "var keyfile = '';"
+ "for (i in json['shortcuts']) {"
+ "var tile = json['shortcuts'][i];"
+ "keyfile += '[Dial ' + tile['id'].substring (1) + ']\\n'"
+ " + 'uri=' + tile['href'] + '\\n'"
+ " + 'img=' + tile['img'] + '\\n'"
+ " + 'title=' + tile['title'] + '\\n\\n';"
+ "} "
+ "var columns = json['width'] ? json['width'] : 3;"
+ "var rows = json['shortcuts'] ? json['shortcuts'].length / columns : 0;"
+ "keyfile += '[settings]\\n'"
+ " + 'columns=' + columns + '\\n'"
+ " + 'rows=' + (rows > 3 ? rows : 3) + '\\n\\n';"
+ "keyfile;");
+ g_free (json_content);
+ js_context = JSGlobalContextCreateInGroup (NULL, NULL);
+ keyfile = sokoke_js_script_eval (js_context, script->str, NULL);
+ JSGlobalContextRelease (js_context);
+ g_string_free (script, TRUE);
+ g_key_file_load_from_data (key_file, keyfile, -1, 0, NULL);
+ g_free (keyfile);
+ tiles = g_key_file_get_groups (key_file, NULL);
+ thumb_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_cache_dir (),
+ PACKAGE_NAME, "thumbnails", NULL);
+ if (!g_file_test (thumb_dir, G_FILE_TEST_EXISTS))
+ katze_mkdir_with_parents (thumb_dir, 0700);
+ g_free (thumb_dir);
+
+ while (tiles[i] != NULL)
+ {
+ gsize sz;
+ gchar* uri = g_key_file_get_string (key_file, tiles[i], "uri", NULL);
+ gchar* img = g_key_file_get_string (key_file, tiles[i], "img", NULL);
+ if (img != NULL && (uri && *uri && *uri != '#'))
+ {
+ guchar* decoded = g_base64_decode (img, &sz);
+ gchar* thumb_path = sokoke_build_thumbnail_path (uri);
+ g_file_set_contents (thumb_path, (gchar*)decoded, sz, NULL);
+ g_free (thumb_path);
+ g_free (decoded);
+ }
+ g_free (img);
+ g_free (uri);
+ g_key_file_remove_key (key_file, tiles[i], "img", NULL);
+ i++;
+ }
+ g_strfreev (tiles);
+
+ katze_assign (config_file, g_build_filename (config, "speeddial", NULL));
+ sokoke_key_file_save_to_file (key_file, config_file, NULL);
+ g_free (config_file);
+ return key_file;
+}
+
static void
midori_soup_session_block_uris_cb (SoupSession* session,
SoupMessage* msg,
@@ -1599,16 +1675,9 @@ midori_inactivity_timeout (gpointer data)
if (has_extension == -1)
{
GdkDisplay* display = gtk_widget_get_display (GTK_WIDGET (mit->browser));
- if (GDK_IS_X11_DISPLAY (display))
- {
- xdisplay = GDK_DISPLAY_XDISPLAY (display);
- has_extension = XScreenSaverQueryExtension (xdisplay,
- &event_base, &error_base);
- }
- else
- {
- has_extension = 0;
- }
+ xdisplay = GDK_DISPLAY_XDISPLAY (display);
+ has_extension = XScreenSaverQueryExtension (xdisplay,
+ &event_base, &error_base);
}
if (has_extension)
@@ -1626,7 +1695,7 @@ midori_inactivity_timeout (gpointer data)
GList* data_items = sokoke_register_privacy_item (NULL, NULL, NULL);
while ((view = midori_browser_get_nth_tab (mit->browser, i++)))
- midori_browser_remove_tab (mit->browser, view);
+ gtk_widget_destroy (view);
midori_browser_set_current_uri (mit->browser, mit->uri);
/* Clear all private data */
if (history != NULL)
@@ -1660,24 +1729,31 @@ midori_setup_inactivity_reset (MidoriBrowser* browser,
}
}
+static void
+midori_clear_page_icons_cb (void)
+{
+ gchar* cache = g_build_filename (g_get_user_cache_dir (),
+ PACKAGE_NAME, "icons", NULL);
+ sokoke_remove_path (cache, TRUE);
+ g_free (cache);
+ cache = g_build_filename (g_get_user_data_dir (),
+ "webkit", "icondatabase", NULL);
+ sokoke_remove_path (cache, TRUE);
+ g_free (cache);
+}
+
static void
midori_clear_web_cookies_cb (void)
{
SoupSession* session = webkit_get_default_session ();
- MidoriWebSettings* settings = g_object_get_data (G_OBJECT (session), "midori-settings");
SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
GSList* cookies = soup_cookie_jar_all_cookies (SOUP_COOKIE_JAR (jar));
SoupSessionFeature* feature;
- gchar* cache;
- /* HTTP Cookies/ Web Cookies */
for (; cookies != NULL; cookies = g_slist_next (cookies))
{
- const gchar* domain = ((SoupCookie*)cookies->data)->domain;
- if (midori_web_settings_get_site_data_policy (settings, domain)
- == MIDORI_SITE_DATA_PRESERVE)
- continue;
- soup_cookie_jar_delete_cookie ((SoupCookieJar*)jar, cookies->data);
+ SoupCookie* cookie = cookies->data;
+ soup_cookie_jar_delete_cookie ((SoupCookieJar*)jar, cookie);
}
soup_cookies_free (cookies);
/* Removing KatzeHttpCookies makes it save outstanding changes */
@@ -1688,45 +1764,27 @@ midori_clear_web_cookies_cb (void)
soup_session_add_feature (session, feature);
g_object_unref (feature);
}
+}
- /* Local shared objects/ Flash cookies */
- if (midori_web_settings_has_plugin_support ())
- {
- #ifdef GDK_WINDOWING_X11
- cache = g_build_filename (g_get_home_dir (), ".macromedia", "Flash_Player", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- #elif defined(GDK_WINDOWING_WIN32)
- cache = g_build_filename (g_get_user_data_dir (), "Macromedia", "Flash Player", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- #elif defined(GDK_WINDOWING_QUARTZ)
- cache = g_build_filename (g_get_home_dir (), "Library", "Preferences",
- "Macromedia", "Flash Player", NULL);
+#ifdef GDK_WINDOWING_X11
+static void
+midori_clear_flash_cookies_cb (void)
+{
+ gchar* cache = g_build_filename (g_get_home_dir (), ".macromedia",
+ "Flash_Player", NULL);
sokoke_remove_path (cache, TRUE);
g_free (cache);
- #endif
- }
-
- /* HTML5 databases */
- webkit_remove_all_web_databases ();
-
- /* HTML5 offline application caches */
- #if WEBKIT_CHECK_VERSION (1, 3, 13)
- /* Changing the size implies clearing the cache */
- webkit_application_cache_set_maximum_size (
- webkit_application_cache_get_maximum_size () - 1);
- #endif
}
+#endif
static void
midori_clear_saved_logins_cb (void)
{
sqlite3* db;
- gchar* path = g_build_filename (midori_paths_get_config_dir (), "logins", NULL);
+ gchar* path = g_build_filename (sokoke_set_config_dir (NULL), "logins", NULL);
g_unlink (path);
/* Form History database, written by the extension */
- katze_assign (path, g_build_filename (midori_paths_get_config_dir (),
+ katze_assign (path, g_build_filename (sokoke_set_config_dir (NULL),
"extensions", MIDORI_MODULE_PREFIX "formhistory." G_MODULE_SUFFIX, "forms.db", NULL));
if (sqlite3_open (path, &db) == SQLITE_OK)
{
@@ -1736,34 +1794,35 @@ midori_clear_saved_logins_cb (void)
g_free (path);
}
+static void
+midori_clear_html5_databases_cb (void)
+{
+ webkit_remove_all_web_databases ();
+}
+
#if WEBKIT_CHECK_VERSION (1, 3, 11)
static void
midori_clear_web_cache_cb (void)
{
SoupSession* session = webkit_get_default_session ();
SoupSessionFeature* feature = soup_session_get_feature (session, SOUP_TYPE_CACHE);
- gchar* cache = g_build_filename (midori_paths_get_cache_dir (), "web", NULL);
+ gchar* path = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME, "web", NULL);
soup_cache_clear (SOUP_CACHE (feature));
soup_cache_flush (SOUP_CACHE (feature));
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
+ sokoke_remove_path (path, TRUE);
+ g_free (path);
}
#endif
+#if WEBKIT_CHECK_VERSION (1, 3, 13)
static void
-midori_clear_page_icons_cb (void)
+midori_clear_offline_appcache_cb (void)
{
- gchar* cache = g_build_filename (midori_paths_get_cache_dir (), "icons", NULL);
- /* FIXME: Exclude search engine icons */
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- cache = g_build_filename (midori_paths_get_user_data_dir (), "webkit", "icondatabase", NULL);
- sokoke_remove_path (cache, TRUE);
- g_free (cache);
- #if WEBKIT_CHECK_VERSION (1, 8, 0)
- webkit_favicon_database_clear (webkit_get_favicon_database ());
- #endif
+ /* Changing the size implies clearing the cache */
+ unsigned long long maximum = webkit_application_cache_get_maximum_size ();
+ webkit_application_cache_set_maximum_size (maximum - 1);
}
+#endif
static void
midori_log_to_file (const gchar* log_domain,
@@ -1814,8 +1873,6 @@ main (int argc,
gchar* webapp;
gchar* config;
gboolean private;
- gboolean portable;
- gboolean plain;
gboolean diagnostic_dialog;
gboolean back_from_crash;
gboolean run;
@@ -1840,12 +1897,6 @@ main (int argc,
#endif
{ "private", 'p', 0, G_OPTION_ARG_NONE, &private,
N_("Private browsing, no changes are saved"), NULL },
- #ifdef G_OS_WIN32
- { "portable", 'P', 0, G_OPTION_ARG_NONE, &portable,
- N_("Portable mode, all runtime files are stored in one place"), NULL },
- #endif
- { "plain", '\0', 0, G_OPTION_ARG_NONE, &plain,
- N_("Plain GTK+ window with WebKit, akin to GtkLauncher"), NULL },
{ "diagnostic-dialog", 'd', 0, G_OPTION_ARG_NONE, &diagnostic_dialog,
N_("Show a diagnostic dialog"), NULL },
{ "run", 'r', 0, G_OPTION_ARG_NONE, &run,
@@ -1875,7 +1926,9 @@ main (int argc,
gchar** extensions;
MidoriWebSettings* settings;
gchar* config_file;
- MidoriSpeedDial* dial;
+ gchar* bookmarks_file;
+ GKeyFile* speeddial;
+ gboolean bookmarks_exist;
MidoriStartup load_on_startup;
KatzeArray* search_engines;
KatzeArray* bookmarks;
@@ -1891,19 +1944,34 @@ main (int argc,
gint max_history_age;
gint clear_prefs = MIDORI_CLEAR_NONE;
#ifdef G_ENABLE_DEBUG
- gboolean startup_timer = midori_debug ("startup");
+ gboolean startup_timer = g_getenv ("MIDORI_STARTTIME") != NULL;
#define midori_startup_timer(tmrmsg) if (startup_timer) \
g_debug (tmrmsg, (g_test_timer_last () - g_test_timer_elapsed ()) * -1)
#else
#define midori_startup_timer(tmrmsg)
#endif
+ #ifdef HAVE_SIGNAL_H
+ #ifdef SIGHUP
+ signal (SIGHUP, &signal_handler);
+ #endif
+ #ifdef SIGINT
+ signal (SIGINT, &signal_handler);
+ #endif
+ #ifdef SIGTERM
+ signal (SIGTERM, &signal_handler);
+ #endif
+ #ifdef SIGQUIT
+ signal (SIGQUIT, &signal_handler);
+ #endif
+ #endif
+
+ midori_app_setup (argv);
+
/* Parse cli options */
webapp = NULL;
config = NULL;
private = FALSE;
- portable = FALSE;
- plain = FALSE;
back_from_crash = FALSE;
diagnostic_dialog = FALSE;
run = FALSE;
@@ -1916,36 +1984,40 @@ main (int argc,
block_uris = NULL;
inactivity_reset = 0;
error = NULL;
- if (!midori_app_setup (&argc, &argv, entries, &error))
+ if (!gtk_init_with_args (&argc, &argv, _("[Addresses]"), entries,
+ GETTEXT_PACKAGE, &error))
{
g_print ("%s - %s\n", _("Midori"), error->message);
g_error_free (error);
return 1;
}
- /* Relative config path */
if (config && !g_path_is_absolute (config))
{
- gchar* old_config = config;
- gchar* current_dir = g_get_current_dir ();
- config = g_build_filename (current_dir, old_config, NULL);
- g_free (current_dir);
- g_free (old_config);
+ g_critical (_("The specified configuration folder is invalid."));
+ return 1;
}
- g_set_application_name (_("Midori"));
- /* Versioned prgname to override menuproxy blacklist */
- g_set_prgname (PACKAGE_NAME "4");
+ /* Private browsing, window title, default config folder */
+ if (private)
+ {
+ if (!config && !webapp)
+ config = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
+ /* Mask the timezone, which can be read by Javascript */
+ g_setenv ("TZ", "UTC", TRUE);
+ }
+ else
+ g_set_application_name (_("Midori"));
if (version)
{
g_print (
"%s %s\n\n"
- "Copyright (c) 2007-2012 Christian Dywan\n\n"
+ "Copyright (c) 2007-2011 Christian Dywan\n\n"
"%s\n"
"\t%s\n\n"
"%s\n"
- "\thttp://www.midori-browser.org\n",
+ "\thttp://www.twotoasts.de\n",
_("Midori"), PACKAGE_VERSION,
_("Please report comments, suggestions and bugs to:"),
PACKAGE_BUGREPORT,
@@ -1959,21 +2031,11 @@ main (int argc,
MidoriBrowser* browser = midori_browser_new ();
GtkActionGroup* action_group = midori_browser_get_action_group (browser);
GList* actions = gtk_action_group_list_actions (action_group);
- GList* temp = actions;
- guint length = 1;
- gchar* space;
-
- for (; temp; temp = g_list_next (temp))
- {
- GtkAction* action = temp->data;
- length = MAX (length, 1 + strlen (gtk_action_get_name (action)));
- }
-
- space = g_strnfill (length, ' ');
for (; actions; actions = g_list_next (actions))
{
GtkAction* action = actions->data;
const gchar* name = gtk_action_get_name (action);
+ const gchar* space = " ";
gchar* padding = g_strndup (space, strlen (space) - strlen (name));
gchar* label = katze_object_get_string (action, "label");
gchar* stripped = katze_strip_mnemonics (label);
@@ -1985,7 +2047,6 @@ main (int argc,
g_free (label);
g_free (stripped);
}
- g_free (space);
g_list_free (actions);
gtk_widget_destroy (GTK_WIDGET (browser));
return 0;
@@ -1996,7 +2057,6 @@ main (int argc,
gchar* filename;
gint fd;
GtkWidget* web_view;
- gchar* uri;
#if HAVE_OFFSCREEN
GtkWidget* offscreen;
GdkScreen* screen;
@@ -2033,9 +2093,7 @@ main (int argc,
#endif
g_signal_connect (web_view, "load-finished",
G_CALLBACK (snapshot_load_finished_cb), filename);
- uri = midori_prepare_uri (snapshot);
- webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), uri);
- g_free (uri);
+ webkit_web_view_open (WEBKIT_WEB_VIEW (web_view), snapshot);
gtk_main ();
g_free (filename);
return 0;
@@ -2046,65 +2104,34 @@ main (int argc,
g_log_set_default_handler (midori_log_to_file, (gpointer)logfile);
}
- if (plain)
- {
- GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- GtkWidget* scrolled = gtk_scrolled_window_new (NULL, NULL);
- GtkWidget* web_view = webkit_web_view_new ();
- gchar* uri = midori_prepare_uri (
- (uris != NULL && uris[0]) ? uris[0] : "http://www.example.com");
-
- gint width, height;
- GdkRectangle monitor;
- GdkScreen* screen = gtk_window_get_screen (GTK_WINDOW (window));
- gdk_screen_get_monitor_geometry (screen, 0, &monitor);
- width = monitor.width / 1.7; height = monitor.height / 1.7;
- gtk_window_set_default_size (GTK_WINDOW (window), width, height);
-
- gtk_container_add (GTK_CONTAINER (window), scrolled);
- gtk_container_add (GTK_CONTAINER (scrolled), web_view);
- g_signal_connect (window, "delete-event",
- G_CALLBACK (gtk_main_quit), window);
- gtk_widget_show_all (window);
- webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), uri);
- g_free (uri);
- gtk_main ();
- return 0;
- }
-
- #ifdef HAVE_SIGNAL_H
- #ifdef SIGHUP
- signal (SIGHUP, &signal_handler);
- #endif
- #ifdef SIGINT
- signal (SIGINT, &signal_handler);
- #endif
- #ifdef SIGTERM
- signal (SIGTERM, &signal_handler);
- #endif
- #ifdef SIGQUIT
- signal (SIGQUIT, &signal_handler);
- #endif
- #endif
-
+ sokoke_register_privacy_item ("page-icons", _("Website icons"),
+ G_CALLBACK (midori_clear_page_icons_cb));
/* i18n: Logins and passwords in websites and web forms */
sokoke_register_privacy_item ("formhistory", _("Saved logins and _passwords"),
G_CALLBACK (midori_clear_saved_logins_cb));
- sokoke_register_privacy_item ("web-cookies", _("Cookies and Website data"),
+ sokoke_register_privacy_item ("web-cookies", _("Cookies"),
G_CALLBACK (midori_clear_web_cookies_cb));
+ #ifdef GDK_WINDOWING_X11
+ sokoke_register_privacy_item ("flash-cookies", _("'Flash' Cookies"),
+ G_CALLBACK (midori_clear_flash_cookies_cb));
+ #endif
+ sokoke_register_privacy_item ("html5-databases", _("HTML5 _Databases"),
+ G_CALLBACK (midori_clear_html5_databases_cb));
#if WEBKIT_CHECK_VERSION (1, 3, 11)
- /* TODO: Preserve page icons of search engines and merge privacy items */
sokoke_register_privacy_item ("web-cache", _("Web Cache"),
G_CALLBACK (midori_clear_web_cache_cb));
+ sokoke_register_privacy_item ("offline-appcache", _("Offline Application Cache"),
+ G_CALLBACK (midori_clear_offline_appcache_cb));
#endif
- sokoke_register_privacy_item ("page-icons", _("Website icons"),
- G_CALLBACK (midori_clear_page_icons_cb));
/* Web Application or Private Browsing support */
if (webapp || private || run)
{
SoupSession* session = webkit_get_default_session ();
MidoriBrowser* browser = midori_browser_new ();
+ /* Update window icon according to page */
+ g_signal_connect (browser, "notify::load-status",
+ G_CALLBACK (midori_web_app_browser_notify_load_status_cb), NULL);
g_signal_connect (browser, "new-window",
G_CALLBACK (midori_web_app_browser_new_window_cb), NULL);
g_object_set_data (G_OBJECT (webkit_get_default_session ()),
@@ -2112,28 +2139,21 @@ main (int argc,
midori_startup_timer ("Browser: \t%f");
- if (private)
- midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, config);
- else if (webapp)
- midori_paths_init (MIDORI_RUNTIME_MODE_APP, config);
- else
- midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
-
- if (private || !webapp)
+ if (config)
{
- settings = settings_and_accels_new (&extensions);
+ settings = settings_and_accels_new (config, &extensions);
g_strfreev (extensions);
- search_engines = search_engines_new_from_folder (NULL);
+ search_engines = search_engines_new_from_folder (config, NULL);
g_object_set (browser, "search-engines", search_engines, NULL);
g_object_unref (search_engines);
+ speeddial = speeddial_new_from_file (config, &error);
+ g_object_set (browser, "speed-dial", speeddial, NULL);
}
else
settings = g_object_ref (midori_browser_get_settings (browser));
if (private)
{
- /* Mask the timezone, which can be read by Javascript */
- g_setenv ("TZ", "UTC", TRUE);
/* In-memory trash for re-opening closed tabs */
trash = katze_array_new (KATZE_TYPE_ITEM);
g_signal_connect_after (trash, "add-item",
@@ -2162,9 +2182,12 @@ main (int argc,
"gtk-application-prefer-dark-theme", TRUE,
NULL);
#endif
+ }
- g_object_set (gtk_settings_get_default (),
- "gtk-recent-files-max-age", 0, NULL);
+ if (private || !config)
+ {
+ /* Disable saving by setting an unwritable folder */
+ sokoke_set_config_dir ("/");
}
midori_load_soup_session (settings);
@@ -2223,7 +2246,6 @@ main (int argc,
g_object_set (settings,
"show-menubar", FALSE,
"show-navigationbar", FALSE,
- "always-show-tabbar", FALSE,
"toolbar-items", "Back,Forward,ReloadStop,Location,Homepage",
"show-statusbar", FALSE,
"enable-developer-extras", FALSE,
@@ -2261,10 +2283,6 @@ main (int argc,
}
}
- /* Informative text for private browsing unless we have a URI */
- if (private && webapp == NULL && uris == NULL)
- midori_browser_add_uri (browser, "about:private");
-
if (midori_browser_get_current_uri (browser) == NULL)
midori_browser_add_uri (browser, "about:blank");
@@ -2278,17 +2296,9 @@ main (int argc,
if (inactivity_reset > 0)
g_error ("--inactivity-reset is currently only supported with --app.");
- if (portable)
- {
- g_object_set (gtk_settings_get_default (),
- "gtk-recent-files-max-age", 0, NULL);
- midori_paths_init (MIDORI_RUNTIME_MODE_PORTABLE, config);
- }
- else
- midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
-
- app = midori_app_new ();
- katze_assign (config, g_strdup (midori_paths_get_config_dir ()));
+ sokoke_set_config_dir (config);
+ app = midori_app_new ();
+ katze_assign (config, (gchar*)sokoke_set_config_dir (NULL));
midori_startup_timer ("App created: \t%f");
/* FIXME: The app might be 'running' but actually showing a dialog
@@ -2333,13 +2343,13 @@ main (int argc,
/* Load configuration file */
error_messages = g_string_new (NULL);
error = NULL;
- settings = settings_and_accels_new (&extensions);
+ settings = settings_and_accels_new (config, &extensions);
g_object_set (settings, "enable-developer-extras", TRUE, NULL);
g_object_set (settings, "enable-html5-database", TRUE, NULL);
midori_startup_timer ("Config and accels read: \t%f");
/* Load search engines */
- search_engines = search_engines_new_from_folder (error_messages);
+ search_engines = search_engines_new_from_folder (config, error_messages);
/* Pick first search engine as default if not set */
g_object_get (settings, "location-entry-search", &uri, NULL);
if (!(uri && *uri) && !katze_array_is_empty (search_engines))
@@ -2352,13 +2362,30 @@ main (int argc,
midori_startup_timer ("Search read: \t%f");
bookmarks = katze_array_new (KATZE_TYPE_ARRAY);
+ bookmarks_file = g_build_filename (config, "bookmarks.db", NULL);
+ bookmarks_exist = g_access (bookmarks_file, F_OK) == 0;
errmsg = NULL;
- if ((db = midori_bookmarks_initialize (bookmarks, &errmsg)) == NULL)
+ if ((db = midori_bookmarks_initialize (bookmarks, bookmarks_file, &errmsg)) == NULL)
{
g_string_append_printf (error_messages,
_("Bookmarks couldn't be loaded: %s\n"), errmsg);
errmsg = NULL;
}
+ else if (!bookmarks_exist)
+ {
+ /* Initial creation, import old bookmarks */
+ gchar* old_bookmarks;
+ if (g_path_is_absolute (BOOKMARK_FILE))
+ old_bookmarks = g_strdup (BOOKMARK_FILE);
+ else
+ old_bookmarks = g_build_filename (config, BOOKMARK_FILE, NULL);
+ if (g_access (old_bookmarks, F_OK) == 0)
+ {
+ midori_bookmarks_import (old_bookmarks, db);
+ /* Leave old bookmarks around */
+ }
+ g_free (old_bookmarks);
+ }
g_object_set_data (G_OBJECT (bookmarks), "db", db);
midori_startup_timer ("Bookmarks read: \t%f");
@@ -2368,7 +2395,7 @@ main (int argc,
#if HAVE_LIBXML
if (load_on_startup >= MIDORI_STARTUP_LAST_OPEN_PAGES)
{
- katze_assign (config_file, midori_paths_get_readonly_config_filename ("session.xbel"));
+ katze_assign (config_file, build_config_filename ("session.xbel"));
error = NULL;
if (!midori_array_from_file (_session, config_file, "xbel", &error))
{
@@ -2399,16 +2426,17 @@ main (int argc,
katze_assign (config_file, g_build_filename (config, "history.db", NULL));
errmsg = NULL;
- if (!midori_history_initialize (history, config_file, &errmsg))
+ if (!midori_history_initialize (history, config_file, bookmarks_file, &errmsg))
{
g_string_append_printf (error_messages,
_("The history couldn't be loaded: %s\n"), errmsg);
errmsg = NULL;
}
+ g_free (bookmarks_file);
midori_startup_timer ("History read: \t%f");
- katze_assign (config_file, g_build_filename (config, "speeddial", NULL));
- dial = midori_speed_dial_new (config_file, NULL);
+ error = NULL;
+ speeddial = speeddial_new_from_file (config, &error);
/* In case of errors */
if (error_messages->len)
@@ -2497,7 +2525,7 @@ main (int argc,
G_CALLBACK (midori_trash_remove_item_cb), NULL);
katze_item_set_parent (KATZE_ITEM (_session), app);
- g_object_set_data_full (G_OBJECT (app), "extensions", extensions, (GDestroyNotify)g_strfreev);
+ g_object_set_data (G_OBJECT (app), "extensions", extensions);
/* We test for the presence of a dummy file which is created once
and deleted during normal runtime, but persists in case of a crash. */
katze_assign (config_file, g_build_filename (config, "running", NULL));
@@ -2525,7 +2553,7 @@ main (int argc,
"trash", trash,
"search-engines", search_engines,
"history", history,
- "speed-dial", dial,
+ "speed-dial", speeddial,
NULL);
g_object_unref (history);
g_object_unref (search_engines);
@@ -2583,12 +2611,12 @@ main (int argc,
load_on_startup = katze_object_get_int (settings, "load-on-startup");
if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES)
{
- katze_assign (config_file, midori_paths_get_config_filename ("session.xbel"));
+ katze_assign (config_file, g_build_filename (config, "session.xbel", NULL));
g_unlink (config_file);
}
g_object_unref (settings);
- g_object_unref (dial);
+ g_key_file_free (speeddial);
g_object_unref (app);
g_free (config_file);
return 0;
diff --git a/midori/marshal.list b/midori/marshal.list
index df8bfd3f..b0808f8a 100644
--- a/midori/marshal.list
+++ b/midori/marshal.list
@@ -6,7 +6,6 @@ OBJECT:OBJECT
VOID:BOOLEAN,STRING
VOID:OBJECT,ENUM,BOOLEAN
VOID:OBJECT,INT,INT
-VOID:OBJECT,OBJECT
VOID:POINTER,INT
VOID:STRING,BOOLEAN
VOID:STRING,INT,STRING
diff --git a/midori/midori-app.c b/midori/midori-app.c
index e6b5a200..0666e6f0 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -21,11 +21,9 @@
#include "midori-app.h"
#include "midori-platform.h"
-#include "midori-core.h"
#include
#include
-#include
#include
#if ENABLE_NLS
@@ -70,6 +68,10 @@ struct _MidoriApp
{
GObject parent_instance;
+ MidoriBrowser* browser;
+ GtkAccelGroup* accel_group;
+
+ gchar* name;
MidoriWebSettings* settings;
KatzeArray* bookmarks;
KatzeArray* trash;
@@ -79,7 +81,6 @@ struct _MidoriApp
KatzeArray* extensions;
KatzeArray* browsers;
- MidoriBrowser* browser;
MidoriAppInstance instance;
#if !HAVE_HILDON || !HAVE_LIBNOTIFY
@@ -87,8 +88,6 @@ struct _MidoriApp
#endif
};
-static gchar* app_name = NULL;
-
struct _MidoriAppClass
{
GObjectClass parent_class;
@@ -217,6 +216,7 @@ _midori_app_add_browser (MidoriApp* app,
g_return_if_fail (MIDORI_IS_APP (app));
g_return_if_fail (MIDORI_IS_BROWSER (browser));
+ gtk_window_add_accel_group (GTK_WINDOW (browser), app->accel_group);
g_object_connect (browser,
"signal::focus-in-event", midori_browser_focus_in_event_cb, app,
"signal::new-window", midori_browser_new_window_cb, app,
@@ -229,32 +229,6 @@ _midori_app_add_browser (MidoriApp* app,
katze_array_add_item (app->browsers, browser);
- #if GTK_CHECK_VERSION (3, 0, 0)
- if (app->browser == NULL)
- {
- gchar* filename;
- if ((filename = midori_paths_get_res_filename ("gtk3.css")))
- {
- GtkCssProvider* css_provider = gtk_css_provider_new ();
- GError* error = NULL;
- gtk_css_provider_load_from_path (css_provider, filename, &error);
- if (error == NULL)
- {
- gtk_style_context_add_provider_for_screen (
- gtk_widget_get_screen (GTK_WIDGET (browser)),
- GTK_STYLE_PROVIDER (css_provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- }
- else
- {
- g_warning ("Failed to load \"%s\": %s", filename, error->message);
- g_error_free (error);
- }
- g_free (filename);
- }
- }
- #endif
-
app->browser = browser;
#if HAVE_UNIQUE
/* We *do not* let unique watch windows because that includes
@@ -746,35 +720,25 @@ midori_app_create_instance (MidoriApp* app)
GIOChannel* channel;
#endif
- if (!(display = gdk_display_get_default ()))
- return MidoriAppInstanceNull;
-
+ if (!app->name)
{
- #if HAVE_UNIQUE
- const gchar* config = midori_paths_get_config_dir ();
+ const gchar* config = sokoke_set_config_dir (NULL);
gchar* name_hash;
name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
- katze_assign (app_name, g_strconcat ("midori", "_", name_hash, NULL));
+ app->name = g_strconcat ("midori", "_", name_hash, NULL);
g_free (name_hash);
g_object_notify (G_OBJECT (app), "name");
- #else
- katze_assign (app_name, g_strdup (PACKAGE_NAME));
- #endif
}
- #ifdef GDK_WINDOWING_X11
- /* On X11: :0 or :0.0 which is equivalent */
- display_name = g_strndup (gdk_display_get_name (display), 2);
- #else
+ if (!(display = gdk_display_get_default ()))
+ return MidoriAppInstanceNull;
+
display_name = g_strdup (gdk_display_get_name (display));
- #endif
n = strlen (display_name);
for (i = 0; i < n; i++)
if (strchr (":.\\/", display_name[i]))
display_name[i] = '_';
- instance_name = g_strdup_printf ("de.twotoasts.%s_%s", app_name, display_name);
- g_free (display_name);
- katze_assign (app_name, instance_name);
+ instance_name = g_strdup_printf ("de.twotoasts.%s_%s", app->name, display_name);
#if HAVE_UNIQUE
instance = unique_app_new (instance_name, NULL);
@@ -782,7 +746,7 @@ midori_app_create_instance (MidoriApp* app)
g_signal_connect (instance, "message-received",
G_CALLBACK (midori_browser_message_received_cb), app);
#else
- instance = socket_init (instance_name, midori_paths_get_config_dir (), &exists);
+ instance = socket_init (instance_name, sokoke_set_config_dir (NULL), &exists);
g_object_set_data (G_OBJECT (app), "sock-exists",
exists ? (gpointer)0xdeadbeef : NULL);
if (instance != MidoriAppInstanceNull)
@@ -792,19 +756,19 @@ midori_app_create_instance (MidoriApp* app)
(GIOFunc)midori_app_io_channel_watch_cb, app);
}
#endif
+
+ g_free (instance_name);
+ g_free (display_name);
+
#endif
return instance;
}
-const gchar*
-midori_app_get_name (MidoriApp* app)
-{
- return app_name;
-}
-
static void
midori_app_init (MidoriApp* app)
{
+ app->accel_group = gtk_accel_group_new ();
+
app->settings = NULL;
app->bookmarks = NULL;
app->trash = NULL;
@@ -829,7 +793,9 @@ midori_app_finalize (GObject* object)
{
MidoriApp* app = MIDORI_APP (object);
- katze_assign (app_name, NULL);
+ g_object_unref (app->accel_group);
+
+ katze_assign (app->name, NULL);
katze_object_assign (app->settings, NULL);
katze_object_assign (app->bookmarks, NULL);
katze_object_assign (app->trash, NULL);
@@ -869,7 +835,7 @@ midori_app_set_property (GObject* object,
switch (prop_id)
{
case PROP_NAME:
- katze_assign (app_name, g_value_dup_string (value));
+ katze_assign (app->name, g_value_dup_string (value));
break;
case PROP_SETTINGS:
katze_object_assign (app->settings, g_value_dup_object (value));
@@ -909,7 +875,7 @@ midori_app_get_property (GObject* object,
switch (prop_id)
{
case PROP_NAME:
- g_value_set_string (value, app_name);
+ g_value_set_string (value, app->name);
break;
case PROP_SETTINGS:
g_value_set_object (value, app->settings);
@@ -1145,19 +1111,7 @@ midori_app_send_command (MidoriApp* app,
/* g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); */
g_return_val_if_fail (command != NULL, FALSE);
- if (midori_app_instance_is_running (app))
- {
- MidoriBrowser* browser = midori_browser_new ();
- int i;
- for (i=0; command && command[i]; i++)
- {
- gboolean action_known = (gtk_action_group_get_action (midori_browser_get_action_group (browser), command[i]) != NULL);
- if (!action_known)
- g_warning (_("Unexpected action '%s'."), command[i]);
- }
- gtk_widget_destroy (GTK_WIDGET (browser));
- }
- else
+ if (!midori_app_instance_is_running (app))
return midori_app_command_received (app, "command", command, NULL);
#if HAVE_HILDON
@@ -1350,80 +1304,63 @@ midori_app_send_notification (MidoriApp* app,
*
* Since: 0.4.2
**/
-gboolean
-midori_app_setup (gint *argc,
- gchar** *argument_vector,
- const GOptionEntry *entries,
- GError* *error)
+void
+midori_app_setup (gchar** argument_vector)
{
GtkIconSource* icon_source;
GtkIconSet* icon_set;
GtkIconFactory* factory;
gsize i;
- gboolean success;
- static GtkStockItem items[] =
+ typedef struct
+ {
+ const gchar* stock_id;
+ const gchar* label;
+ GdkModifierType modifier;
+ guint keyval;
+ const gchar* fallback;
+ } FatStockItem;
+ static FatStockItem items[] =
{
- { STOCK_IMAGE },
- { STOCK_WEB_BROWSER },
- { STOCK_NEWS_FEED },
- { STOCK_STYLE },
-
- { STOCK_BOOKMARKS, N_("_Bookmarks"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_B },
- { STOCK_BOOKMARK_ADD, N_("Add Boo_kmark") },
- { STOCK_EXTENSION, N_("_Extensions") },
- { STOCK_HISTORY, N_("_History"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_H },
- { STOCK_SCRIPT, N_("_Userscripts") },
- { STOCK_STYLE, N_("User_styles") },
- { STOCK_TAB_NEW, N_("New _Tab") },
- { STOCK_TRANSFER, N_("_Transfers"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_J },
- { STOCK_PLUGINS, N_("Netscape p_lugins") },
- { STOCK_USER_TRASH, N_("_Closed Tabs") },
- { STOCK_WINDOW_NEW, N_("New _Window") },
- { STOCK_FOLDER_NEW, N_("New _Folder") },
+ { STOCK_EXTENSION, NULL, 0, 0, GTK_STOCK_CONVERT },
+ { STOCK_IMAGE, NULL, 0, 0, GTK_STOCK_ORIENTATION_PORTRAIT },
+ { STOCK_WEB_BROWSER, NULL, 0, 0, "gnome-web-browser" },
+ { STOCK_NEWS_FEED, NULL, 0, 0, GTK_STOCK_INDEX },
+ { STOCK_SCRIPT, NULL, 0, 0, GTK_STOCK_EXECUTE },
+ { STOCK_STYLE, NULL, 0, 0, GTK_STOCK_SELECT_COLOR },
+ { STOCK_TRANSFER, NULL, 0, 0, GTK_STOCK_SAVE },
+
+ { STOCK_BOOKMARK, N_("_Bookmark"), 0, 0, GTK_STOCK_FILE },
+ { STOCK_BOOKMARKS, N_("_Bookmarks"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_B, GTK_STOCK_DIRECTORY },
+ { STOCK_BOOKMARK_ADD, N_("Add Boo_kmark"), 0, 0, "stock_add-bookmark" },
+ { STOCK_CONSOLE, N_("_Console"), 0, 0, GTK_STOCK_DIALOG_WARNING },
+ { STOCK_EXTENSIONS, N_("_Extensions"), 0, 0, GTK_STOCK_CONVERT },
+ { STOCK_HISTORY, N_("_History"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_H, GTK_STOCK_SORT_ASCENDING },
+ { STOCK_HOMEPAGE, N_("_Homepage"), 0, 0, GTK_STOCK_HOME },
+ { STOCK_SCRIPTS, N_("_Userscripts"), 0, 0, GTK_STOCK_EXECUTE },
+ { STOCK_TAB_NEW, N_("New _Tab"), 0, 0, GTK_STOCK_ADD },
+ { STOCK_TRANSFERS, N_("_Transfers"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_J, GTK_STOCK_SAVE },
+ { STOCK_PLUGINS, N_("Netscape p_lugins"), 0, 0, GTK_STOCK_CONVERT },
+ { STOCK_USER_TRASH, N_("_Closed Tabs"), 0, 0, "gtk-undo-ltr" },
+ { STOCK_WINDOW_NEW, N_("New _Window"), 0, 0, GTK_STOCK_ADD },
+ { GTK_STOCK_DIRECTORY, N_("New _Folder"), 0, 0, NULL },
};
- /* Print messages to stdout on Win32 console, cf. AbiWord
- * http://svn.abisource.com/abiword/trunk/src/wp/main/win/Win32Main.cpp */
- #ifdef _WIN32
- if (fileno (stdout) != -1
- && _get_osfhandle (fileno (stdout)) != -1)
- {
- /* stdout is already being redirected to a file */
- }
- else
- {
- typedef BOOL (WINAPI *AttachConsole_t) (DWORD);
- AttachConsole_t p_AttachConsole =
- (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
- if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
- {
- freopen ("CONOUT$", "w", stdout);
- dup2 (fileno (stdout), 1);
- freopen ("CONOUT$", "w", stderr);
- dup2 (fileno (stderr), 2);
- }
- }
- #endif
+ /* Preserve argument vector */
+ sokoke_get_argv (argument_vector);
/* libSoup uses threads, therefore if WebKit is built with libSoup
* or Midori is using it, we need to initialize threads. */
- #if !GLIB_CHECK_VERSION (2, 32, 0)
if (!g_thread_supported ()) g_thread_init (NULL);
- #endif
-
- /* Midori.Paths uses GFile */
- g_type_init ();
- /* Preserve argument vector */
- midori_paths_init_exec_path (*argument_vector, *argc);
#if ENABLE_NLS
+ setlocale (LC_ALL, "");
if (g_getenv ("MIDORI_NLSPATH"))
bindtextdomain (GETTEXT_PACKAGE, g_getenv ("MIDORI_NLSPATH"));
else
#ifdef G_OS_WIN32
{
- gchar* path = midori_paths_get_data_filename ("locale", FALSE);
+ gchar* path = sokoke_find_data_filename ("locale", FALSE);
bindtextdomain (GETTEXT_PACKAGE, path);
g_free (path);
}
@@ -1434,14 +1371,18 @@ midori_app_setup (gint *argc,
textdomain (GETTEXT_PACKAGE);
#endif
- success = gtk_init_with_args (argc, argument_vector, _("[Addresses]"),
- entries, GETTEXT_PACKAGE, error);
-
+ g_type_init ();
factory = gtk_icon_factory_new ();
for (i = 0; i < G_N_ELEMENTS (items); i++)
{
icon_set = gtk_icon_set_new ();
icon_source = gtk_icon_source_new ();
+ if (items[i].fallback)
+ {
+ gtk_icon_source_set_icon_name (icon_source, items[i].fallback);
+ items[i].fallback = NULL;
+ gtk_icon_set_add_source (icon_set, icon_source);
+ }
gtk_icon_source_set_icon_name (icon_source, items[i].stock_id);
gtk_icon_set_add_source (icon_set, icon_source);
gtk_icon_source_free (icon_source);
@@ -1452,43 +1393,76 @@ midori_app_setup (gint *argc,
gtk_icon_factory_add_default (factory);
g_object_unref (factory);
- return success;
-}
+ #if HAVE_HILDON
+ /* Maemo doesn't theme stock icons. So we map platform icons
+ to stock icons. These are all monochrome toolbar icons. */
+ typedef struct
+ {
+ const gchar* stock_id;
+ const gchar* icon_name;
+ } CompatItem;
+ static CompatItem compat_items[] =
+ {
+ { GTK_STOCK_ADD, "general_add" },
+ { GTK_STOCK_BOLD, "general_bold" },
+ { GTK_STOCK_CLOSE, "general_close_b" },
+ { GTK_STOCK_DELETE, "general_delete" },
+ { GTK_STOCK_DIRECTORY, "general_toolbar_folder" },
+ { GTK_STOCK_FIND, "general_search" },
+ { GTK_STOCK_FULLSCREEN, "general_fullsize_b" },
+ { GTK_STOCK_GO_BACK, "general_back" },
+ { GTK_STOCK_GO_FORWARD, "general_forward" },
+ { GTK_STOCK_GO_UP, "filemanager_folder_up" },
+ { GTK_STOCK_GOTO_FIRST, "pdf_viewer_first_page" },
+ { GTK_STOCK_GOTO_LAST, "pdf_viewer_last_page" },
+ { GTK_STOCK_INFO, "general_information" },
+ { GTK_STOCK_ITALIC, "general_italic" },
+ { GTK_STOCK_JUMP_TO, "general_move_to_folder" },
+ { GTK_STOCK_PREFERENCES,"general_settings" },
+ { GTK_STOCK_REFRESH, "general_refresh" },
+ { GTK_STOCK_SAVE, "notes_save" },
+ { GTK_STOCK_STOP, "general_stop" },
+ { GTK_STOCK_UNDERLINE, "notes_underline" },
+ { GTK_STOCK_ZOOM_IN, "pdf_zoomin" },
+ { GTK_STOCK_ZOOM_OUT, "pdf_zoomout" },
+ };
-gboolean
-midori_debug (const gchar* token)
-{
- static const gchar* debug_token = NULL;
- const gchar* debug = g_getenv ("MIDORI_DEBUG");
- const gchar* debug_tokens = "headers body referer cookies paths hsts unarmed ";
- const gchar* full_debug_tokens = "adblock:match adblock:time startup bookmarks ";
- if (debug_token == NULL)
+ factory = gtk_icon_factory_new ();
+ for (i = 0; i < G_N_ELEMENTS (compat_items); i++)
{
- gchar* found_token;
- if (debug && (found_token = strstr (full_debug_tokens, debug)) && *(found_token + strlen (debug)) == ' ')
- {
- #ifdef G_ENABLE_DEBUG
- debug_token = g_intern_static_string (debug);
- #else
- g_warning ("Value '%s' for MIDORI_DEBUG requires a full debugging build.", debug);
- #endif
- }
- else if (debug && (found_token = strstr (debug_tokens, debug)) && *(found_token + strlen (debug)) == ' ')
- debug_token = g_intern_static_string (debug);
- else if (debug)
- g_warning ("Unrecognized value '%s' for MIDORI_DEBUG.", debug);
- else
- debug_token = "NONE";
- if (!debug_token)
+ icon_set = gtk_icon_set_new ();
+ icon_source = gtk_icon_source_new ();
+ gtk_icon_source_set_icon_name (icon_source, compat_items[i].icon_name);
+ gtk_icon_set_add_source (icon_set, icon_source);
+ gtk_icon_source_free (icon_source);
+ gtk_icon_factory_add (factory, compat_items[i].stock_id, icon_set);
+ gtk_icon_set_unref (icon_set);
+ }
+ gtk_icon_factory_add_default (factory);
+ g_object_unref (factory);
+ #endif
+
+ /* Print messages to stdout on Win32 console, cf. AbiWord
+ * http://svn.abisource.com/abiword/trunk/src/wp/main/win/Win32Main.cpp */
+ #ifdef _WIN32
+ if (fileno (stdout) != -1
+ && _get_osfhandle (fileno (stdout)) != -1)
+ {
+ /* stdout is already being redirected to a file */
+ }
+ else
+ {
+ typedef BOOL (WINAPI *AttachConsole_t) (DWORD);
+ AttachConsole_t p_AttachConsole =
+ (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
+ if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
{
- debug_token = "INVALID";
- g_print ("Supported values: %s\nWith full debugging: %s\n",
- debug_tokens, full_debug_tokens);
+ freopen ("CONOUT$", "w", stdout);
+ dup2 (fileno (stdout), 1);
+ freopen ("CONOUT$", "w", stderr);
+ dup2 (fileno (stderr), 2);
}
}
- if (debug_token != g_intern_static_string ("NONE")
- && !strstr (debug_tokens, token) && !strstr (full_debug_tokens, token))
- g_warning ("Token '%s' passed to midori_debug is not a known token.", token);
- return debug_token == g_intern_static_string (token);
+ #endif
}
diff --git a/midori/midori-app.h b/midori/midori-app.h
index 07af1927..934ce0ce 100644
--- a/midori/midori-app.h
+++ b/midori/midori-app.h
@@ -41,9 +41,6 @@ midori_app_get_type (void) G_GNUC_CONST;
MidoriApp*
midori_app_new (void);
-const gchar*
-midori_app_get_name (MidoriApp* app);
-
gboolean
midori_app_instance_is_running (MidoriApp* app);
@@ -82,14 +79,8 @@ midori_app_send_notification (MidoriApp* app,
const gchar* title,
const gchar* message);
-gboolean
-midori_app_setup (gint *argc,
- gchar** *argument_vector,
- const GOptionEntry *entries,
- GError* *error);
-
-gboolean
-midori_debug (const gchar* token);
+void
+midori_app_setup (gchar** argument_vector);
G_END_DECLS
diff --git a/midori/midori-array.c b/midori/midori-array.c
index aa10715e..1567ce50 100644
--- a/midori/midori-array.c
+++ b/midori/midori-array.c
@@ -982,26 +982,24 @@ katze_item_set_value_from_column (sqlite3_stmt* stmt,
item->added = date;
}
else if (g_str_equal (name, "day") || g_str_equal (name, "app")
- || g_str_equal (name, "toolbar") || g_str_equal (name, "id")
- || g_str_equal (name, "parentid") || g_str_equal (name, "seq")
- || g_str_equal (name, "pos_panel") || g_str_equal (name, "pos_bar"))
+ || g_str_equal (name, "toolbar"))
{
gint value;
value = sqlite3_column_int64 (stmt, column);
katze_item_set_meta_integer (item, name, value);
}
+ else if (g_str_equal (name, "folder"))
+ {
+ const unsigned char* folder;
+ folder = sqlite3_column_text (stmt, column);
+ katze_item_set_meta_string (item, name, (gchar*)folder);
+ }
else if (g_str_equal (name, "desc"))
{
const unsigned char* text;
text = sqlite3_column_text (stmt, column);
item->text = g_strdup ((gchar*)text);
}
- else if (g_str_equal (name, "sql"))
- {
- const unsigned char* sql;
- sql = sqlite3_column_text (stmt, column);
- katze_item_set_meta_string (item, name, (gchar*)sql);
- }
else
g_warn_if_reached ();
}
@@ -1069,32 +1067,28 @@ katze_array_from_sqlite (sqlite3* db,
}
/**
- * midori_array_query_recursive:
+ * midori_array_query:
* @array: the main bookmark array
* @fields: comma separated list of fields
* @condition: condition, like "folder = '%q'"
* @value: a value to be inserted if @condition contains %q
- * @recursive: if %TRUE include children
*
* Stores the result in a #KatzeArray.
*
* Return value: a #KatzeArray on success, %NULL otherwise
*
- * Since: 0.4.4
+ * Since: 0.4.3
**/
KatzeArray*
-midori_array_query_recursive (KatzeArray* bookmarks,
- const gchar* fields,
- const gchar* condition,
- const gchar* value,
- gboolean recursive)
+midori_array_query (KatzeArray* bookmarks,
+ const gchar* fields,
+ const gchar* condition,
+ const gchar* value)
{
sqlite3* db;
gchar* sqlcmd;
char* sqlcmd_value;
KatzeArray* array;
- KatzeItem* item;
- GList* list;
g_return_val_if_fail (KATZE_IS_ARRAY (bookmarks), NULL);
g_return_val_if_fail (fields, NULL);
@@ -1104,7 +1098,7 @@ midori_array_query_recursive (KatzeArray* bookmarks,
return NULL;
sqlcmd = g_strdup_printf ("SELECT %s FROM bookmarks WHERE %s "
- "ORDER BY (uri='') ASC, title DESC", fields, condition);
+ "ORDER BY title DESC", fields, condition);
if (strstr (condition, "%q"))
{
sqlcmd_value = sqlite3_mprintf (sqlcmd, value ? value : "");
@@ -1114,49 +1108,6 @@ midori_array_query_recursive (KatzeArray* bookmarks,
else
array = katze_array_from_sqlite (db, sqlcmd);
g_free (sqlcmd);
-
- if (!recursive)
- return array;
-
- KATZE_ARRAY_FOREACH_ITEM_L (item, array, list)
- {
- if (KATZE_ITEM_IS_FOLDER (item))
- {
- gchar* parentid = g_strdup_printf ("%" G_GINT64_FORMAT,
- katze_item_get_meta_integer (item, "id"));
- KatzeArray* subarray = midori_array_query_recursive (bookmarks,
- fields, "parentid=%q", parentid, TRUE);
- katze_item_set_name (KATZE_ITEM (subarray), item->name);
- katze_array_add_item (array, subarray);
-
- g_free (parentid);
- }
- }
- g_list_free (list);
return array;
}
-/**
- * midori_array_query:
- * @array: the main bookmark array
- * @fields: comma separated list of fields
- * @condition: condition, like "folder = '%q'"
- * @value: a value to be inserted if @condition contains %q
- *
- * Stores the result in a #KatzeArray.
- *
- * Return value: a #KatzeArray on success, %NULL otherwise
- *
- * Since: 0.4.3
- *
- * Deprecated: 0.4.4: Use midori_array_query_recursive() instead.
- **/
-KatzeArray*
-midori_array_query (KatzeArray* bookmarks,
- const gchar* fields,
- const gchar* condition,
- const gchar* value)
-{
- return midori_array_query_recursive (bookmarks, fields, condition, value, FALSE);
-}
-
diff --git a/midori/midori-array.h b/midori/midori-array.h
index 1ff78638..35b4e17c 100644
--- a/midori/midori-array.h
+++ b/midori/midori-array.h
@@ -36,13 +36,6 @@ midori_array_query (KatzeArray* array,
const gchar* condition,
const gchar* value);
-KatzeArray*
-midori_array_query_recursive (KatzeArray* array,
- const gchar* fields,
- const gchar* condition,
- const gchar* value,
- gboolean recursive);
-
KatzeArray*
katze_array_from_sqlite (sqlite3* db,
const gchar* sqlcmd);
diff --git a/midori/midori-bookmarks.c b/midori/midori-bookmarks.c
deleted file mode 100644
index bbcb3eda..00000000
--- a/midori/midori-bookmarks.c
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- Copyright (C) 2010 Christian Dywan
- Copyright (C) 2010 Alexander Butenko
-
- 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 "midori-bookmarks.h"
-#include "panels/midori-bookmarks.h"
-#include "midori-array.h"
-#include "sokoke.h"
-#include "midori-core.h"
-
-#include
-#include
-
-#include
-#ifdef HAVE_UNISTD_H
- #include
-#endif
-
-#ifdef G_ENABLE_DEBUG
-void midori_bookmarks_dbtracer(void* dummy, const char* query)
-{
- g_printerr ("%s\n", query);
-}
-#endif
-
-void
-midori_bookmarks_add_item_cb (KatzeArray* array,
- KatzeItem* item,
- sqlite3* db)
-{
- midori_bookmarks_insert_item_db (db, item,
- katze_item_get_meta_integer (item, "parentid"));
-}
-
-void
-midori_bookmarks_remove_item_cb (KatzeArray* array,
- KatzeItem* item,
- sqlite3* db)
-{
- gchar* sqlcmd;
- char* errmsg = NULL;
-
-
- sqlcmd = sqlite3_mprintf (
- "DELETE FROM bookmarks WHERE id = %" G_GINT64_FORMAT ";",
- katze_item_get_meta_integer (item, "id"));
-
- if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
- {
- g_printerr (_("Failed to remove history item: %s\n"), errmsg);
- sqlite3_free (errmsg);
- }
-
- sqlite3_free (sqlcmd);
-}
-
-#define _APPEND_TO_SQL_ERRORMSG(custom_errmsg) \
- do { \
- if (sql_errmsg) \
- { \
- g_string_append_printf (errmsg_str, "%s : %s\n", custom_errmsg, sql_errmsg); \
- sqlite3_free (sql_errmsg); \
- } \
- else \
- g_string_append (errmsg_str, custom_errmsg); \
- } while (0)
-
-gboolean
-midori_bookmarks_import_from_old_db (sqlite3* db,
- const gchar* oldfile,
- gchar** errmsg)
-{
- gint sql_errcode;
- gboolean failure = FALSE;
- gchar* sql_errmsg = NULL;
- GString* errmsg_str = g_string_new (NULL);
- gchar* attach_stmt = sqlite3_mprintf ("ATTACH DATABASE %Q AS old_db;", oldfile);
- const gchar* convert_stmts =
- "BEGIN TRANSACTION;"
- "INSERT INTO main.bookmarks (parentid, title, uri, desc, app, toolbar) "
- "SELECT NULL AS parentid, title, uri, desc, app, toolbar "
- "FROM old_db.bookmarks;"
- "UPDATE main.bookmarks SET parentid = ("
- "SELECT id FROM main.bookmarks AS b1 WHERE b1.title = ("
- "SELECT folder FROM old_db.bookmarks WHERE title = main.bookmarks.title));"
- "COMMIT;";
- const gchar* detach_stmt = "DETACH DATABASE old_db;";
-
- *errmsg = NULL;
- sql_errcode = sqlite3_exec (db, attach_stmt, NULL, NULL, &sql_errmsg);
- sqlite3_free (attach_stmt);
-
- if (sql_errcode != SQLITE_OK)
- {
- _APPEND_TO_SQL_ERRORMSG (_("failed to ATTACH old db"));
- goto convert_failed;
- }
-
- if (sqlite3_exec (db, convert_stmts, NULL, NULL, &sql_errmsg) != SQLITE_OK)
- {
- failure = TRUE;
- _APPEND_TO_SQL_ERRORMSG (_("failed to import from old db"));
-
- /* try to get back to previous state */
- if (sqlite3_exec (db, "ROLLBACK TRANSACTION;", NULL, NULL, &sql_errmsg) != SQLITE_OK)
- _APPEND_TO_SQL_ERRORMSG (_("failed to rollback the transaction"));
- }
-
- if (sqlite3_exec (db, detach_stmt, NULL, NULL, &sql_errmsg) != SQLITE_OK)
- _APPEND_TO_SQL_ERRORMSG (_("failed to DETACH "));
-
- if (failure)
- {
- convert_failed:
- *errmsg = g_string_free (errmsg_str, FALSE);
- g_print ("ERRORR: %s\n", errmsg_str->str);
- return FALSE;
- }
-
- return TRUE;
-}
-#undef _APPEND_TO_SQL_ERRORMSG
-
-sqlite3*
-midori_bookmarks_initialize (KatzeArray* array,
- char** errmsg)
-{
- sqlite3* db;
- gchar* oldfile;
- gchar* newfile;
- gboolean newfile_did_exist, oldfile_exists;
- const gchar* create_stmt;
- gchar* sql_errmsg = NULL;
- gchar* import_errmsg = NULL;
-
- g_return_val_if_fail (errmsg != NULL, NULL);
-
- oldfile = g_build_filename (midori_paths_get_config_dir (), "bookmarks.db", NULL);
- oldfile_exists = g_access (oldfile, F_OK) == 0;
- newfile = g_build_filename (midori_paths_get_config_dir (), "bookmarks_v2.db", NULL);
- newfile_did_exist = g_access (newfile, F_OK) == 0;
-
- /* sqlite3_open will create the file if it did not exists already */
- if (sqlite3_open (newfile, &db) != SQLITE_OK)
- {
- if (db)
- *errmsg = g_strdup_printf (_("failed to open database: %s\n"),
- sqlite3_errmsg (db));
- else
- *errmsg = g_strdup (_("failed to open database\n"));
-
- goto init_failed;
- }
-
-#ifdef G_ENABLE_DEBUG
- if (midori_debug ("bookmarks"))
- sqlite3_trace (db, midori_bookmarks_dbtracer, NULL);
-#endif
-
- create_stmt = /* Table structure */
- "CREATE TABLE IF NOT EXISTS bookmarks "
- "(id INTEGER PRIMARY KEY AUTOINCREMENT, "
- "parentid INTEGER DEFAULT NULL, "
- "title TEXT, uri TEXT, desc TEXT, app INTEGER, toolbar INTEGER, "
- "pos_panel INTEGER, pos_bar INTEGER, "
- "created DATE DEFAULT CURRENT_TIMESTAMP, "
- "last_visit DATE, visit_count INTEGER DEFAULT 0, "
- "nick TEXT, "
- "FOREIGN KEY(parentid) REFERENCES bookmarks(id) "
- "ON DELETE CASCADE); PRAGMA foreign_keys = ON;"
-
- /* trigger: insert panel position */
- "CREATE TRIGGER IF NOT EXISTS bookmarkInsertPosPanel "
- "AFTER INSERT ON bookmarks FOR EACH ROW "
- "BEGIN UPDATE bookmarks SET pos_panel = ("
- "SELECT ifnull(MAX(pos_panel),0)+1 FROM bookmarks WHERE "
- "(NEW.parentid IS NOT NULL AND parentid = NEW.parentid) "
- "OR (NEW.parentid IS NULL AND parentid IS NULL)) "
- "WHERE id = NEW.id; END;"
-
- /* trigger: insert Bookmarkbar position */
- "CREATE TRIGGER IF NOT EXISTS bookmarkInsertPosBar "
- "AFTER INSERT ON bookmarks FOR EACH ROW WHEN NEW.toolbar=1 "
- "BEGIN UPDATE bookmarks SET pos_bar = ("
- "SELECT ifnull(MAX(pos_bar),0)+1 FROM bookmarks WHERE "
- "((NEW.parentid IS NOT NULL AND parentid = NEW.parentid) "
- "OR (NEW.parentid IS NULL AND parentid IS NULL)) AND toolbar=1) "
- "WHERE id = NEW.id; END;"
-
- /* trigger: update panel position */
- "CREATE TRIGGER IF NOT EXISTS bookmarkUpdatePosPanel "
- "BEFORE UPDATE OF parentid ON bookmarks FOR EACH ROW "
- "WHEN ((NEW.parentid IS NULL OR OLD.parentid IS NULL) "
- "AND NEW.parentid IS NOT OLD.parentid) OR "
- "((NEW.parentid IS NOT NULL AND OLD.parentid IS NOT NULL) "
- "AND NEW.parentid!=OLD.parentid) "
- "BEGIN UPDATE bookmarks SET pos_panel = pos_panel-1 "
- "WHERE ((OLD.parentid IS NOT NULL AND parentid = OLD.parentid) "
- "OR (OLD.parentid IS NULL AND parentid IS NULL)) AND pos_panel > OLD.pos_panel; "
- "UPDATE bookmarks SET pos_panel = ("
- "SELECT ifnull(MAX(pos_panel),0)+1 FROM bookmarks "
- "WHERE (NEW.parentid IS NOT NULL AND parentid = NEW.parentid) "
- "OR (NEW.parentid IS NULL AND parentid IS NULL)) "
- "WHERE id = OLD.id; END;"
-
- /* trigger: update Bookmarkbar position */
- "CREATE TRIGGER IF NOT EXISTS bookmarkUpdatePosBar0 "
- "AFTER UPDATE OF parentid, toolbar ON bookmarks FOR EACH ROW "
- "WHEN ((NEW.parentid IS NULL OR OLD.parentid IS NULL) "
- "AND NEW.parentid IS NOT OLD.parentid) "
- "OR ((NEW.parentid IS NOT NULL AND OLD.parentid IS NOT NULL) "
- "AND NEW.parentid!=OLD.parentid) OR (OLD.toolbar=1 AND NEW.toolbar=0) "
- "BEGIN UPDATE bookmarks SET pos_bar = NULL WHERE id = NEW.id; "
- "UPDATE bookmarks SET pos_bar = pos_bar-1 "
- "WHERE ((OLD.parentid IS NOT NULL AND parentid = OLD.parentid) "
- "OR (OLD.parentid IS NULL AND parentid IS NULL)) AND pos_bar > OLD.pos_bar; END;"
-
- /* trigger: update Bookmarkbar position */
- "CREATE TRIGGER IF NOT EXISTS bookmarkUpdatePosBar1 "
- "BEFORE UPDATE OF parentid, toolbar ON bookmarks FOR EACH ROW "
- "WHEN ((NEW.parentid IS NULL OR OLD.parentid IS NULL) "
- "AND NEW.parentid IS NOT OLD.parentid) OR "
- "((NEW.parentid IS NOT NULL AND OLD.parentid IS NOT NULL) "
- "AND NEW.parentid!=OLD.parentid) OR (OLD.toolbar=0 AND NEW.toolbar=1) "
- "BEGIN UPDATE bookmarks SET pos_bar = ("
- "SELECT ifnull(MAX(pos_bar),0)+1 FROM bookmarks WHERE "
- "(NEW.parentid IS NOT NULL AND parentid = NEW.parentid) "
- "OR (NEW.parentid IS NULL AND parentid IS NULL)) "
- "WHERE id = OLD.id; END;"
-
- /* trigger: delete panel position */
- "CREATE TRIGGER IF NOT EXISTS bookmarkDeletePosPanel "
- "AFTER DELETE ON bookmarks FOR EACH ROW "
- "BEGIN UPDATE bookmarks SET pos_panel = pos_panel-1 "
- "WHERE ((OLD.parentid IS NOT NULL AND parentid = OLD.parentid) "
- "OR (OLD.parentid IS NULL AND parentid IS NULL)) AND pos_panel > OLD.pos_panel; END;"
-
- /* trigger: delete Bookmarkbar position */
- "CREATE TRIGGER IF NOT EXISTS bookmarkDeletePosBar "
- "AFTER DELETE ON bookmarks FOR EACH ROW WHEN OLD.toolbar=1 "
- "BEGIN UPDATE bookmarks SET pos_bar = pos_bar-1 "
- "WHERE ((OLD.parentid IS NOT NULL AND parentid = OLD.parentid) "
- "OR (OLD.parentid IS NULL AND parentid IS NULL)) AND pos_bar > OLD.pos_bar; END;";
-
-
- if (newfile_did_exist)
- {
- /* we are done */
- goto init_success;
- }
- else
- {
- /* initial creation */
- if (sqlite3_exec (db, create_stmt, NULL, NULL, &sql_errmsg) != SQLITE_OK)
- {
-
- if (errmsg)
- {
- if (sql_errmsg)
- {
- *errmsg = g_strdup_printf (_("could not create bookmarks table: %s\n"), sql_errmsg);
- sqlite3_free (sql_errmsg);
- }
- else
- *errmsg = g_strdup (_("could not create bookmarks table"));
- }
-
- /* we can as well remove the new file */
- g_unlink (newfile);
- goto init_failed;
- }
-
- }
-
- if (oldfile_exists)
- /* import from old db */
- if (!midori_bookmarks_import_from_old_db (db, oldfile, &import_errmsg))
- {
- if (errmsg)
- {
- if (import_errmsg)
- {
- *errmsg = g_strdup_printf (_("could not import from old database: %s\n"), import_errmsg);
- g_free (import_errmsg);
- }
- else
- *errmsg = g_strdup_printf (_("could not import from old database"));
- }
- }
-
- init_success:
- g_free (newfile);
- g_free (oldfile);
- g_signal_connect (array, "add-item",
- G_CALLBACK (midori_bookmarks_add_item_cb), db);
- g_signal_connect (array, "remove-item",
- G_CALLBACK (midori_bookmarks_remove_item_cb), db);
-
- return db;
-
- init_failed:
- g_free (newfile);
- g_free (oldfile);
-
- if (db)
- sqlite3_close (db);
-
- return NULL;
-}
-
-void
-midori_bookmarks_import (const gchar* filename,
- sqlite3* db)
-{
- KatzeArray* bookmarks;
- GError* error = NULL;
-
- bookmarks = katze_array_new (KATZE_TYPE_ARRAY);
-
- if (!midori_array_from_file (bookmarks, filename, "xbel", &error))
- {
- g_warning (_("The bookmarks couldn't be saved. %s"), error->message);
- g_error_free (error);
- return;
- }
- midori_bookmarks_import_array_db (db, bookmarks, 0);
-}
diff --git a/midori/midori-bookmarks.h b/midori/midori-bookmarks.h
deleted file mode 100644
index e4a3f8d6..00000000
--- a/midori/midori-bookmarks.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- Copyright (C) 2010 Christian Dywan
- Copyright (C) 2010 Alexander Butenko
-
- 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
-#include
-
-void
-midori_bookmarks_add_item_cb (KatzeArray* array,
- KatzeItem* item,
- sqlite3* db);
-
-void
-midori_bookmarks_remove_item_cb (KatzeArray* array,
- KatzeItem* item,
- sqlite3* db);
-
-sqlite3*
-midori_bookmarks_initialize (KatzeArray* array,
- char** errmsg);
-
-void
-midori_bookmarks_import (const gchar* filename,
- sqlite3* db);
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 12da322e..72770e11 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -13,13 +13,13 @@
#include "midori-browser.h"
-#include "midori-app.h"
#include "midori-array.h"
#include "midori-view.h"
#include "midori-preferences.h"
#include "midori-panel.h"
#include "midori-locationaction.h"
#include "midori-searchaction.h"
+#include "midori-panedaction.h"
#include "midori-findbar.h"
#include "midori-transferbar.h"
#include "midori-platform.h"
@@ -33,19 +33,14 @@
#include
#include
-
-#ifdef HAVE_GRANITE
- #include
-#endif
-
-#ifdef HAVE_ZEITGEIST
- #include
-#endif
-
#ifdef HAVE_UNISTD_H
#include
#endif
+#include
+#include
+#include
+
#ifdef HAVE_HILDON_2_2
#include
#include
@@ -70,6 +65,7 @@ struct _MidoriBrowser
GtkActionGroup* action_group;
GtkWidget* menubar;
+ GtkWidget* menu_tools;
GtkWidget* throbber;
GtkWidget* navigationbar;
GtkWidget* bookmarkbar;
@@ -100,7 +96,7 @@ struct _MidoriBrowser
KatzeArray* trash;
KatzeArray* search_engines;
KatzeArray* history;
- MidoriSpeedDial* dial;
+ GKeyFile* speeddial;
gboolean show_tabs;
gboolean show_navigationbar;
@@ -145,7 +141,6 @@ enum
ADD_TAB,
REMOVE_TAB,
MOVE_TAB,
- SWITCH_TAB,
ACTIVATE_ACTION,
ADD_DOWNLOAD,
SEND_NOTIFICATION,
@@ -180,11 +175,12 @@ midori_browser_get_property (GObject* object,
void
midori_bookmarks_import_array_db (sqlite3* db,
KatzeArray* array,
- gint64 parentid);
+ gchar* folder);
-gboolean
-midori_bookmarks_update_item_db (sqlite3* db,
- KatzeItem* item);
+void
+midori_bookmarks_export_array_db (sqlite3* db,
+ KatzeArray* array,
+ const gchar* folder);
void
midori_browser_open_bookmark (MidoriBrowser* browser,
@@ -206,8 +202,7 @@ _midori_browser_set_toolbar_style (MidoriBrowser* browser,
GtkWidget*
midori_panel_construct_menu_item (MidoriPanel* panel,
- MidoriViewable* viewable,
- gboolean popup);
+ MidoriViewable* viewable);
static void
midori_browser_settings_notify (MidoriWebSettings* web_settings,
@@ -262,12 +257,8 @@ static gboolean
_toggle_tabbar_smartly (MidoriBrowser* browser,
gboolean ignore_fullscreen)
{
- gboolean has_tabs = midori_browser_get_n_pages (browser) > 1;
-#ifdef HAVE_GRANITE
- gboolean show_tabs = !midori_browser_is_fullscreen (browser) || ignore_fullscreen;
- granite_widgets_dynamic_notebook_set_show_tabs (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), show_tabs);
-#else
+ gboolean has_tabs =
+ gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), 1) != NULL;
gboolean show_tabs =
browser->show_tabs
&& (!midori_browser_is_fullscreen (browser) || ignore_fullscreen)
@@ -276,7 +267,6 @@ _toggle_tabbar_smartly (MidoriBrowser* browser,
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), show_tabs);
gtk_notebook_set_show_border (GTK_NOTEBOOK (browser->notebook), show_tabs);
-#endif
return has_tabs;
}
@@ -296,30 +286,16 @@ _midori_browser_update_actions (MidoriBrowser* browser)
}
static void
-midori_browser_update_secondary_icon (MidoriBrowser* browser,
- MidoriView* view,
- GtkAction* action)
-{
- if (g_object_get_data (G_OBJECT (view), "news-feeds"))
- {
- midori_location_action_set_secondary_icon (
- MIDORI_LOCATION_ACTION (action), STOCK_NEWS_FEED);
- _action_set_sensitive (browser, "AddNewsFeed", TRUE);
- }
- else
- {
- midori_location_action_set_secondary_icon (
- MIDORI_LOCATION_ACTION (action), NULL);
- _action_set_sensitive (browser, "AddNewsFeed", FALSE);
- }
-}
-
-static void
-_midori_browser_update_interface (MidoriBrowser* browser,
- MidoriView* view)
+_midori_browser_update_interface (MidoriBrowser* browser)
{
+ GtkWidget* widget = midori_browser_get_current_tab (browser);
+ MidoriView* view = MIDORI_VIEW (widget);
+ gboolean loading = midori_view_get_load_status (view) != MIDORI_LOAD_FINISHED;
+ gboolean can_reload = midori_view_can_reload (view);
GtkAction* action;
+ _action_set_sensitive (browser, "Reload", can_reload);
+ _action_set_sensitive (browser, "Stop", can_reload && loading);
_action_set_sensitive (browser, "Back", midori_view_can_go_back (view));
_action_set_sensitive (browser, "Forward", midori_view_can_go_forward (view));
_action_set_sensitive (browser, "Previous",
@@ -327,9 +303,10 @@ _midori_browser_update_interface (MidoriBrowser* browser,
_action_set_sensitive (browser, "Next",
midori_view_get_next_page (view) != NULL);
- _action_set_sensitive (browser, "AddSpeedDial", !midori_view_is_blank (view));
- _action_set_sensitive (browser, "BookmarkAdd", !midori_view_is_blank (view));
+ gtk_action_set_visible (_action_by_name (browser, "AddSpeedDial"),
+ !midori_view_is_blank (view));
_action_set_sensitive (browser, "SaveAs", midori_view_can_save (view));
+ _action_set_sensitive (browser, "Print", midori_view_can_print (view));
_action_set_sensitive (browser, "ZoomIn", midori_view_can_zoom_in (view));
_action_set_sensitive (browser, "ZoomOut", midori_view_can_zoom_out (view));
_action_set_sensitive (browser, "ZoomNormal",
@@ -338,75 +315,101 @@ _midori_browser_update_interface (MidoriBrowser* browser,
midori_view_can_view_source (view));
_action_set_sensitive (browser, "SourceView",
midori_view_can_view_source (view));
+ _action_set_sensitive (browser, "Find",
+ midori_view_can_find (view));
+ _action_set_sensitive (browser, "FindNext",
+ midori_view_can_find (view));
+ _action_set_sensitive (browser, "FindPrevious",
+ midori_view_can_find (view));
+ midori_findbar_set_can_find (MIDORI_FINDBAR (browser->find),
+ midori_view_can_find (view));
- action = _action_by_name (browser, "NextForward");
- if (midori_view_can_go_forward (view))
+ action = _action_by_name (browser, "ReloadStop");
+ if (!loading)
{
g_object_set (action,
- "stock-id", GTK_STOCK_GO_FORWARD,
- "tooltip", _("Go forward to the next page"),
- "sensitive", TRUE, NULL);
+ "stock-id", GTK_STOCK_REFRESH,
+ "tooltip", _("Reload the current page"),
+ "sensitive", can_reload, NULL);
+ katze_item_set_meta_integer (midori_view_get_proxy_item (view),
+ "dont-write-history", -1);
}
else
{
g_object_set (action,
- "stock-id", GTK_STOCK_MEDIA_NEXT,
- "tooltip", _("Go to the next sub-page"),
- "sensitive", midori_view_get_next_page (view) != NULL, NULL);
+ "stock-id", GTK_STOCK_STOP,
+ "tooltip", _("Stop loading the current page"), NULL);
}
+ #if HAVE_HILDON
+ #if HILDON_CHECK_VERSION (2, 2, 0)
+ hildon_gtk_window_set_progress_indicator (GTK_WINDOW (browser), loading);
+ #endif
+ #else
+ gtk_widget_set_sensitive (browser->throbber, loading);
+ katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
+ #endif
+
action = _action_by_name (browser, "Location");
+ if (g_object_get_data (G_OBJECT (view), "news-feeds"))
+ {
+ midori_location_action_set_secondary_icon (
+ MIDORI_LOCATION_ACTION (action), STOCK_NEWS_FEED);
+ gtk_action_set_sensitive (_action_by_name (browser, "AddNewsFeed"), TRUE);
+ }
+ else
+ {
+ midori_location_action_set_secondary_icon (
+ MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
+ gtk_action_set_sensitive (_action_by_name (browser, "AddNewsFeed"), FALSE);
+ }
midori_location_action_set_security_hint (
MIDORI_LOCATION_ACTION (action), midori_view_get_security (view));
- midori_browser_update_secondary_icon (browser, view, action);
}
static void
_midori_browser_set_statusbar_text (MidoriBrowser* browser,
- MidoriView* view,
const gchar* text)
{
- #if GTK_CHECK_VERSION (3, 2, 0)
- gboolean is_location = FALSE;
- #else
GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser));
gboolean is_location = widget && GTK_IS_ENTRY (widget)
&& GTK_IS_ALIGNMENT (gtk_widget_get_parent (widget));
- #endif
katze_assign (browser->statusbar_text, midori_uri_format_for_display (text));
- if (view == NULL)
- return;
- if (!gtk_widget_get_visible (browser->statusbar) && !is_location
- && text && *text)
- {
- #if GTK_CHECK_VERSION (3, 2, 0)
- midori_view_set_overlay_text (view, browser->statusbar_text);
- #else
- GtkAction* action = _action_by_name (browser, "Location");
- MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action);
- midori_location_action_set_text (location_action, browser->statusbar_text);
- midori_location_action_set_secondary_icon (location_action, NULL);
- #endif
- }
- else if (!gtk_widget_get_visible (browser->statusbar) && !is_location)
+ if (!browser->show_statusbar && !is_location)
{
- #if GTK_CHECK_VERSION (3, 2, 0)
- midori_view_set_overlay_text (view, NULL);
- #else
GtkAction* action = _action_by_name (browser, "Location");
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action);
- midori_browser_update_secondary_icon (browser, view, action);
- midori_location_action_set_text (location_action,
- midori_view_get_display_uri (view));
- #endif
+ if (text && *text)
+ {
+ midori_location_action_set_text (location_action, browser->statusbar_text);
+ midori_location_action_set_icon (location_action, NULL);
+ midori_location_action_set_secondary_icon (location_action, NULL);
+ }
+ else
+ {
+ GtkWidget* view = midori_browser_get_current_tab (browser);
+ if (G_LIKELY (view))
+ {
+ if (g_object_get_data (G_OBJECT (view), "news-feeds"))
+ midori_location_action_set_secondary_icon (
+ location_action, STOCK_NEWS_FEED);
+ else
+ midori_location_action_set_secondary_icon (
+ location_action, GTK_STOCK_JUMP_TO);
+ midori_location_action_set_text (location_action,
+ midori_view_get_display_uri (MIDORI_VIEW (view)));
+ midori_location_action_set_icon (location_action,
+ midori_view_get_icon (MIDORI_VIEW (view)));
+ }
+ }
}
else
{
gtk_statusbar_pop (GTK_STATUSBAR (browser->statusbar), 1);
gtk_statusbar_push (GTK_STATUSBAR (browser->statusbar), 1,
- katze_str_non_null (browser->statusbar_text));
+ browser->statusbar_text ? browser->statusbar_text : "");
}
}
@@ -423,74 +426,18 @@ static void
_midori_browser_update_progress (MidoriBrowser* browser,
MidoriView* view)
{
- GtkAction* action;
- gdouble progress = midori_view_get_progress (view);
- gboolean loading = progress > 0.0;
-
- action = _action_by_name (browser, "Location");
- midori_location_action_set_progress (MIDORI_LOCATION_ACTION (action), progress);
+ MidoriLocationAction* action;
+ gdouble progress;
- _action_set_sensitive (browser, "Reload", !loading);
- _action_set_sensitive (browser, "Stop", loading);
-
- action = _action_by_name (browser, "ReloadStop");
- if (!loading)
- {
- g_object_set (action,
- "stock-id", GTK_STOCK_REFRESH,
- "tooltip", _("Reload the current page"), NULL);
- katze_item_set_meta_integer (midori_view_get_proxy_item (view),
- "dont-write-history", -1);
- }
- else
- {
- g_object_set (action,
- "stock-id", GTK_STOCK_STOP,
- "tooltip", _("Stop loading the current page"), NULL);
- }
-
- gtk_widget_set_sensitive (browser->throbber, loading);
- katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
-}
-
-/**
- * midori_browser_update_history:
- * @item: a #KatzeItem
- * @type: "website", "bookmark" or "download"
- * @event: "access", "leave", "modify", "delete"
- *
- * Since: 0.4.7
- **/
-void
-midori_browser_update_history (KatzeItem* item,
- const gchar* type,
- const gchar* event)
-{
- #ifdef HAVE_ZEITGEIST
- const gchar* inter;
- if (strstr (event, "access"))
- inter = ZEITGEIST_ZG_ACCESS_EVENT;
- else if (strstr (event, "leave"))
- inter = ZEITGEIST_ZG_LEAVE_EVENT;
- else if (strstr (event, "modify"))
- inter = ZEITGEIST_ZG_MODIFY_EVENT;
- else if (strstr (event, "create"))
- inter = ZEITGEIST_ZG_CREATE_EVENT;
- else if (strstr (event, "delete"))
- inter = ZEITGEIST_ZG_DELETE_EVENT;
+ action = MIDORI_LOCATION_ACTION (_action_by_name (browser, "Location"));
+ progress = midori_view_get_progress (view);
+ /* When we are finished, we don't want to *see* progress anymore */
+ if (midori_view_get_load_status (view) == MIDORI_LOAD_FINISHED)
+ progress = 0.0;
+ /* When loading we want to see at minimum 10% progress */
else
- g_assert_not_reached ();
- zeitgeist_log_insert_events_no_reply (zeitgeist_log_get_default (),
- zeitgeist_event_new_full (inter, ZEITGEIST_ZG_USER_ACTIVITY,
- "application://midori.desktop",
- zeitgeist_subject_new_full (
- item->uri,
- strstr (type, "bookmark") ? ZEITGEIST_NFO_BOOKMARK : ZEITGEIST_NFO_WEBSITE,
- zeitgeist_manifestation_for_uri (item->uri),
- katze_item_get_meta_string (item, "mime-type"), NULL, item->name, NULL),
- NULL),
- NULL);
- #endif
+ progress = CLAMP (progress, 0.1, 1.0);
+ midori_location_action_set_progress (action, progress);
}
static void
@@ -519,8 +466,6 @@ midori_browser_update_history_title (MidoriBrowser* browser,
g_printerr (_("Failed to update title: %s\n"), sqlite3_errmsg (db));
sqlite3_reset (stmt);
sqlite3_clear_bindings (stmt);
-
- midori_browser_update_history (item, "website", "access");
}
static void
@@ -539,11 +484,19 @@ midori_view_notify_icon_cb (MidoriView* view,
GParamSpec* pspec,
MidoriBrowser* browser)
{
+ const gchar* uri;
+ GtkAction* action;
+
if (midori_browser_get_current_tab (browser) != (GtkWidget*)view)
return;
- if (midori_paths_is_readonly () /* APP, PRIVATE */)
- gtk_window_set_icon (GTK_WINDOW (browser), midori_view_get_icon (view));
+ uri = midori_view_get_display_uri (view);
+ action = _action_by_name (browser, "Location");
+ if (browser->maximum_history_age)
+ midori_location_action_set_icon_for_uri (
+ MIDORI_LOCATION_ACTION (action), midori_view_get_icon (view), uri);
+ midori_location_action_set_icon (MIDORI_LOCATION_ACTION (action),
+ midori_view_get_icon (view));
}
static void
@@ -559,22 +512,27 @@ midori_view_notify_load_status_cb (GtkWidget* widget,
uri = midori_view_get_display_uri (view);
action = _action_by_name (browser, "Location");
+ if (load_status == MIDORI_LOAD_COMMITTED)
+ midori_location_action_add_uri (MIDORI_LOCATION_ACTION (action), uri);
+
if (widget == midori_browser_get_current_tab (browser))
{
if (load_status == MIDORI_LOAD_COMMITTED)
{
midori_location_action_set_text (
MIDORI_LOCATION_ACTION (action), uri);
+ midori_location_action_set_secondary_icon (
+ MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
g_object_notify (G_OBJECT (browser), "uri");
}
- _midori_browser_update_interface (browser, view);
- _midori_browser_set_statusbar_text (browser, view, NULL);
+ _midori_browser_update_interface (browser);
+ _midori_browser_set_statusbar_text (browser, NULL);
/* This is a hack to ensure that the address entry is focussed
with speed dial open. */
if (midori_view_is_blank (view))
- midori_browser_activate_action (browser, "Location");
+ gtk_action_activate (_action_by_name (browser, "Location"));
}
g_object_notify (G_OBJECT (browser), "load-status");
@@ -625,6 +583,9 @@ midori_view_notify_title_cb (GtkWidget* widget,
MidoriBrowser* browser)
{
MidoriView* view = MIDORI_VIEW (widget);
+ const gchar* title;
+
+ title = midori_view_get_display_title (view);
if (midori_view_get_load_status (view) == MIDORI_LOAD_COMMITTED)
{
@@ -654,7 +615,7 @@ midori_view_notify_title_cb (GtkWidget* widget,
}
if (widget == midori_browser_get_current_tab (browser))
- midori_browser_set_title (browser, midori_view_get_display_title (view));
+ midori_browser_set_title (browser, title);
}
static void
@@ -664,11 +625,9 @@ midori_view_notify_minimized_cb (GtkWidget* widget,
{
if (katze_object_get_boolean (widget, "minimized"))
{
- #ifndef HAVE_GRANITE
GtkNotebook* notebook = GTK_NOTEBOOK (browser->notebook);
GtkWidget* label = gtk_notebook_get_tab_label (notebook, widget);
gtk_widget_set_size_request (label, -1, -1);
- #endif
}
else
midori_browser_notebook_size_allocate_cb (NULL, NULL, browser);
@@ -694,16 +653,15 @@ midori_view_notify_statusbar_text_cb (GtkWidget* view,
if (view == midori_browser_get_current_tab (browser))
{
g_object_get (view, "statusbar-text", &text, NULL);
- _midori_browser_set_statusbar_text (browser, MIDORI_VIEW (view), text);
+ _midori_browser_set_statusbar_text (browser, text);
g_free (text);
}
}
static GtkWidget*
-midori_bookmark_folder_button_new (KatzeArray* array,
- gboolean new_bookmark,
- gint64 selected,
- gint64 parentid)
+midori_bookmark_folder_button_new (KatzeArray* array,
+ gboolean new_bookmark,
+ const gchar* selected)
{
GtkListStore* model;
GtkWidget* combo;
@@ -712,16 +670,16 @@ midori_bookmark_folder_button_new (KatzeArray* array,
sqlite3* db;
sqlite3_stmt* statement;
gint result;
- const gchar* sqlcmd = "SELECT title, id FROM bookmarks WHERE uri='' ORDER BY title ASC";
+ const gchar* sqlcmd = "SELECT title from bookmarks where uri=''";
- model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT64);
+ model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "text", 0);
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "ellipsize", 1);
gtk_list_store_insert_with_values (model, NULL, G_MAXINT,
- 0, _("Bookmarks"), 1, PANGO_ELLIPSIZE_END, 2, (gint64)0, -1);
+ 0, _("Toplevel folder"), 1, PANGO_ELLIPSIZE_END, -1);
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
db = g_object_get_data (G_OBJECT (array), "db");
@@ -731,45 +689,34 @@ midori_bookmark_folder_button_new (KatzeArray* array,
while ((result = sqlite3_step (statement)) == SQLITE_ROW)
{
const unsigned char* name = sqlite3_column_text (statement, 0);
- gint64 id = sqlite3_column_int64 (statement, 1);
-
- /* do not show the folder itself */
- if (id != selected)
- {
- gtk_list_store_insert_with_values (model, NULL, G_MAXINT,
- 0, name, 1, PANGO_ELLIPSIZE_END, 2, id, -1);
-
- if (!new_bookmark && id == parentid)
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), n);
- n++;
- }
+ gtk_list_store_insert_with_values (model, NULL, G_MAXINT,
+ 0, name, 1, PANGO_ELLIPSIZE_END, -1);
+ if (!new_bookmark && !g_strcmp0 (selected, (gchar*)name))
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), n);
+ n++;
}
if (n < 2)
gtk_widget_set_sensitive (combo, FALSE);
return combo;
}
-static gint64
+static gchar*
midori_bookmark_folder_button_get_active (GtkWidget* combo)
{
- gint64 id;
+ gchar* selected = NULL;
GtkTreeIter iter;
- g_return_val_if_fail (GTK_IS_COMBO_BOX (combo), 0);
+ g_return_val_if_fail (GTK_IS_COMBO_BOX (combo), NULL);
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
{
- gchar* selected = NULL;
GtkTreeModel* model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
- gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 0, &selected, 2, &id, -1);
-
- if (g_str_equal (selected, _("Bookmarks")))
- id = 0;
-
- g_free (selected);
+ gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 0, &selected, -1);
+ if (g_str_equal (selected, _("Toplevel folder")))
+ katze_assign (selected, g_strdup (""));
}
- return id;
+ return selected;
}
static void
@@ -795,14 +742,13 @@ midori_browser_edit_bookmark_add_speed_dial_cb (GtkWidget* button,
midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
KatzeItem* bookmark,
gboolean new_bookmark,
- gboolean is_folder,
- GtkWidget* proxy)
+ gboolean is_folder)
{
const gchar* title;
GtkWidget* dialog;
GtkWidget* content_area;
+ GtkSizeGroup* sizegroup;
GtkWidget* view;
- GtkWidget* vbox;
GtkWidget* hbox;
GtkWidget* label;
const gchar* value;
@@ -826,48 +772,18 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
title = new_bookmark ? _("New folder") : _("Edit folder");
else
title = new_bookmark ? _("New bookmark") : _("Edit bookmark");
- #ifdef HAVE_GRANITE
- if (proxy != NULL)
- {
- /* FIXME: granite: should return GtkWidget* like GTK+ */
- dialog = (GtkWidget*)granite_widgets_pop_over_new ();
- granite_widgets_pop_over_move_to_widget (
- GRANITE_WIDGETS_POP_OVER (dialog), proxy, TRUE);
- }
- else
- #endif
- {
- dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (browser),
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, NULL, NULL);
- }
- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ dialog = gtk_dialog_new_with_buttons (
+ title, GTK_WINDOW (browser),
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- new_bookmark ? GTK_STOCK_ADD : GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
-
+ new_bookmark ? GTK_STOCK_ADD : GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox),
- gtk_image_new_from_stock (STOCK_BOOKMARK_ADD, GTK_ICON_SIZE_DIALOG), FALSE, FALSE, 0);
- vbox = gtk_vbox_new (FALSE, 0);
- #ifdef HAVE_GRANITE
- if (proxy != NULL)
- {
- gchar* markup = g_strdup_printf ("%s ", title);
- label = gtk_label_new (markup);
- g_free (markup);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
- }
- #endif
- label = gtk_label_new (_("Type a name for this bookmark and choose where to keep it."));
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 12);
- gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 12);
-
- gtk_box_pack_start (GTK_BOX (content_area), hbox, FALSE, FALSE, 0);
gtk_window_set_icon_name (GTK_WINDOW (dialog),
new_bookmark ? GTK_STOCK_ADD : GTK_STOCK_REMOVE);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
gtk_container_set_border_width (GTK_CONTAINER (content_area), 5);
+ sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
if (!bookmark)
{
@@ -884,6 +800,11 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
"name", midori_view_get_display_title (MIDORI_VIEW (view)), NULL);
}
+ hbox = gtk_hbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
+ label = gtk_label_new_with_mnemonic (_("_Title:"));
+ gtk_size_group_add_widget (sizegroup, label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
entry_title = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (entry_title), TRUE);
value = katze_item_get_name (bookmark);
@@ -892,11 +813,18 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
GTK_DIALOG (dialog));
g_signal_connect (entry_title, "changed",
G_CALLBACK (midori_browser_edit_bookmark_title_changed_cb), dialog);
- gtk_container_add (GTK_CONTAINER (content_area), entry_title);
+ gtk_box_pack_start (GTK_BOX (hbox), entry_title, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ gtk_widget_show_all (hbox);
entry_uri = NULL;
if (!is_folder)
{
+ hbox = gtk_hbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
+ label = gtk_label_new_with_mnemonic (_("_Address:"));
+ gtk_size_group_add_widget (sizegroup, label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
entry_uri = katze_uri_entry_new (
#if GTK_CHECK_VERSION (2, 20, 0)
gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT));
@@ -910,41 +838,72 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
#endif
gtk_entry_set_activates_default (GTK_ENTRY (entry_uri), TRUE);
gtk_entry_set_text (GTK_ENTRY (entry_uri), katze_item_get_uri (bookmark));
- gtk_container_add (GTK_CONTAINER (content_area), entry_uri);
+ gtk_box_pack_start (GTK_BOX (hbox), entry_uri, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ gtk_widget_show_all (hbox);
}
+ hbox = gtk_hbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
+ label = gtk_label_new_with_mnemonic (_("_Folder:"));
+ gtk_size_group_add_widget (sizegroup, label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
combo_folder = midori_bookmark_folder_button_new (browser->bookmarks,
- new_bookmark, katze_item_get_meta_integer (bookmark, "id"),
- katze_item_get_meta_integer (bookmark, "parentid"));
- gtk_container_add (GTK_CONTAINER (content_area), combo_folder);
+ new_bookmark, katze_item_get_meta_string (bookmark, "folder"));
+ gtk_box_pack_start (GTK_BOX (hbox), combo_folder, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ gtk_widget_show_all (hbox);
if (new_bookmark && !is_folder)
{
+ hbox = gtk_hbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 1);
+ label = gtk_label_new (NULL);
+ gtk_size_group_add_widget (sizegroup, label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
label = gtk_button_new_with_mnemonic (_("Add to _Speed Dial"));
g_signal_connect (label, "clicked",
G_CALLBACK (midori_browser_edit_bookmark_add_speed_dial_cb), bookmark);
- gtk_container_add (GTK_CONTAINER (content_area), label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ gtk_widget_show_all (hbox);
}
+ hbox = gtk_hbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 1);
+ label = gtk_label_new (NULL);
+ gtk_size_group_add_widget (sizegroup, label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
check_toolbar = gtk_check_button_new_with_mnemonic (_("Show in the tool_bar"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_toolbar),
katze_item_get_meta_boolean (bookmark, "toolbar"));
- gtk_container_add (GTK_CONTAINER (content_area), check_toolbar);
+ gtk_box_pack_start (GTK_BOX (hbox), check_toolbar, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ gtk_widget_show_all (hbox);
check_app = NULL;
if (!is_folder)
{
+ hbox = gtk_hbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 1);
+ label = gtk_label_new (NULL);
+ gtk_size_group_add_widget (sizegroup, label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
check_app = gtk_check_button_new_with_mnemonic (_("Run as _web application"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_app),
katze_item_get_meta_boolean (bookmark, "app"));
- gtk_container_add (GTK_CONTAINER (content_area), check_app);
+ gtk_box_pack_start (GTK_BOX (hbox), check_app, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ gtk_widget_show_all (hbox);
}
- gtk_widget_show_all (content_area);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
- gint64 selected;
+ gchar* selected;
+
+ if (!new_bookmark)
+ katze_array_remove_item (browser->bookmarks, bookmark);
katze_item_set_name (bookmark,
gtk_entry_get_text (GTK_ENTRY (entry_title)));
@@ -959,17 +918,13 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
}
selected = midori_bookmark_folder_button_get_active (combo_folder);
- katze_item_set_meta_integer (bookmark, "parentid", selected);
-
- if (new_bookmark)
- katze_array_add_item (browser->bookmarks, bookmark);
- else
- midori_bookmarks_update_item_db (db, bookmark);
- midori_browser_update_history (bookmark, "bookmark", new_bookmark ? "create" : "modify");
+ katze_item_set_meta_string (bookmark, "folder", selected);
+ katze_array_add_item (browser->bookmarks, bookmark);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_toolbar)))
if (!gtk_widget_get_visible (browser->bookmarkbar))
_action_set_active (browser, "Bookmarkbar", TRUE);
+ g_free (selected);
return_status = TRUE;
}
if (gtk_widget_get_visible (browser->bookmarkbar))
@@ -984,8 +939,54 @@ midori_browser_prepare_download (MidoriBrowser* browser,
const gchar* uri)
{
- if (!midori_download_has_enough_space (download, uri))
+ guint64 total_size = webkit_download_get_total_size (download);
+ GFile* file = g_file_new_for_uri (uri);
+ GFile* folder = g_file_get_parent (file);
+ GError* error = NULL;
+ GFileInfo* info = g_file_query_filesystem_info (folder,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, &error);
+ guint64 free_space = g_file_info_get_attribute_uint64 (info,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+ gchar* path = g_file_get_path (folder);
+ gboolean can_write = g_access (path, W_OK) == 0;
+ g_free (path);
+ g_object_unref (file);
+ g_object_unref (folder);
+ if (free_space < total_size || !can_write)
+ {
+ gchar* message;
+ gchar* detailed_message;
+
+ if (!can_write)
+ {
+ message = g_strdup_printf (
+ _("The file \"%s\" can't be saved in this folder."), &uri[7]);
+ detailed_message = g_strdup_printf (
+ _("You don't have permission to write in this location."));
+ }
+ else if (free_space < total_size)
+ {
+ gchar* total_size_string = g_format_size (total_size);
+ gchar* free_space_string = g_format_size (free_space);
+ message = g_strdup_printf (
+ _("There is not enough free space to download \"%s\"."),
+ &uri[7]);
+ detailed_message = g_strdup_printf (
+ _("The file needs %s but only %s are left."),
+ total_size_string, free_space_string);
+ g_free (total_size_string);
+ g_free (free_space_string);
+ }
+ else
+ g_assert_not_reached ();
+
+ sokoke_message_dialog (GTK_MESSAGE_ERROR, message, detailed_message, FALSE);
+ g_free (message);
+ g_free (detailed_message);
+ g_object_unref (download);
return FALSE;
+ }
+
webkit_download_set_destination_uri (download, uri);
g_signal_emit (browser, signals[ADD_DOWNLOAD], 0, download);
midori_transferbar_add_download_item (MIDORI_TRANSFERBAR (browser->transferbar), download);
@@ -994,60 +995,23 @@ midori_browser_prepare_download (MidoriBrowser* browser,
return TRUE;
}
-static void
-midori_browser_save_resources (MidoriView* view,
- const gchar* folder)
-{
- WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
- WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view);
- WebKitWebDataSource* data_source = webkit_web_frame_get_data_source (frame);
- GList* resources = webkit_web_data_source_get_subresources (data_source);
- GList* list;
-
- katze_mkdir_with_parents (folder, 0700);
-
- for (list = resources; list; list = g_list_next (list))
- {
- WebKitWebResource* resource = WEBKIT_WEB_RESOURCE (list->data);
- GString* data = webkit_web_resource_get_data (resource);
-
- /* Resource could be adblocked, skip it in that case */
- if (!g_strcmp0 (webkit_web_resource_get_uri (resource), "about:blank"))
- continue;
-
- gchar* sub_filename = midori_download_get_filename_suggestion_for_uri (
- webkit_web_resource_get_mime_type (resource),
- webkit_web_resource_get_uri (resource));
- gchar* sub_path = g_build_filename (folder, sub_filename, NULL);
- sub_path = midori_download_get_unique_filename (sub_path);
- if (data)
- {
- GError* error = NULL;
- if (!g_file_set_contents (sub_path, data->str, data->len, &error))
- {
- g_warning ("Failed to save %s: %s", sub_filename, error->message);
- g_error_free (error);
- }
- }
- else
- g_warning ("Skipping empty resource %s", sub_filename);
- g_free (sub_filename);
- g_free (sub_path);
- }
- g_list_free (resources);
-}
+static gchar*
+midori_browser_save_source (const gchar* uri,
+ const gchar* data,
+ const size_t len,
+ const gchar* outfile);
static void
midori_browser_save_uri (MidoriBrowser* browser,
- MidoriView* view,
const gchar* uri)
{
static gchar* last_dir = NULL;
+ gboolean folder_set = FALSE;
GtkWidget* dialog;
- const gchar* title = midori_view_get_display_title (view);
gchar* filename;
- gboolean file_only = TRUE;
- GtkWidget* checkbox = NULL;
+ gchar* dirname;
+ gchar* last_slash;
+ gchar* folder;
if (!gtk_widget_get_visible (GTK_WIDGET (browser)))
return;
@@ -1056,56 +1020,53 @@ midori_browser_save_uri (MidoriBrowser* browser,
GTK_WINDOW (browser), GTK_FILE_CHOOSER_ACTION_SAVE);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
- if (uri == NULL)
- uri = midori_view_get_display_uri (view);
-
- if (midori_view_can_view_source (view))
+ if (uri)
{
- file_only = FALSE;
- checkbox = gtk_check_button_new_with_mnemonic (_("Save associated _resources"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE);
- gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), checkbox);
- }
+ /* Base the start folder on the current view's uri if it is local */
+ filename = g_filename_from_uri (uri, NULL, NULL);
+ if (filename)
+ {
+ dirname = g_path_get_dirname (filename);
+ if (dirname && g_file_test (dirname, G_FILE_TEST_IS_DIR))
+ {
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), dirname);
+ folder_set = TRUE;
+ }
- if (last_dir && *last_dir)
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir);
- else
- {
- gchar* dirname = midori_uri_get_folder (uri);
- if (dirname == NULL)
- dirname = katze_object_get_string (browser->settings, "download-folder");
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), dirname);
- g_free (dirname);
- }
+ g_free (dirname);
+ g_free (filename);
+ }
- if (!file_only && !g_str_equal (title, uri))
- filename = midori_download_clean_filename (title);
- else
- {
- gchar* mime_type = katze_object_get_object (view, "mime-type");
- filename = midori_download_get_filename_suggestion_for_uri (mime_type, uri);
- g_free (mime_type);
+ /* Try to provide a good default filename, UTF-8 encoded */
+ filename = soup_uri_decode (uri);
+ last_slash = g_strrstr (filename, "/") + 1;
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), last_slash);
+ g_free (filename);
}
- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
- g_free (filename);
+
+ if (!folder_set && last_dir && *last_dir)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
{
+ GtkWidget* view;
+ GtkWidget* web_view;
+ WebKitWebDataSource *data_source;
+ WebKitWebFrame *frame;
+ const GString *data;
+
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- if (checkbox != NULL)
- file_only = !file_only && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
- if (!file_only && !g_str_equal (title, uri))
- {
- gchar* fullname = g_strconcat (filename, ".html", NULL);
- midori_view_save_source (view, uri, fullname);
- g_free (fullname);
- }
- else
- midori_view_save_source (view, uri, filename);
- if (!file_only)
- midori_browser_save_resources (view, filename);
- katze_assign (last_dir,
- gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog)));
+ folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
+ view = midori_browser_get_current_tab (browser);
+ web_view = midori_view_get_web_view (MIDORI_VIEW (view));
+ frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
+ data_source = webkit_web_frame_get_data_source (frame);
+ data = webkit_web_data_source_get_data (data_source);
+ if (data)
+ midori_browser_save_source (uri, data->str, data->len, filename);
+
+ g_free (last_dir);
+ last_dir = folder;
}
gtk_widget_destroy (dialog);
}
@@ -1115,19 +1076,41 @@ midori_view_save_as_cb (GtkWidget* menuitem,
const gchar* uri,
GtkWidget* view)
{
- MidoriBrowser* browser = midori_browser_get_for_widget (view);
- midori_browser_save_uri (browser, MIDORI_VIEW (view), uri);
+ MidoriBrowser* browser;
+
+ browser = midori_browser_get_for_widget (menuitem);
+ midori_browser_save_uri (browser, uri);
}
-static void
-midori_browser_speed_dial_refresh_cb (MidoriSpeedDial* dial,
- MidoriBrowser* browser)
+static gchar*
+midori_browser_speed_dial_get_next_free_slot (MidoriView* view)
{
- GList* tabs = midori_browser_get_tabs (browser);
- for (; tabs != NULL; tabs = g_list_next (tabs))
- if (midori_view_is_blank (tabs->data))
- midori_view_reload (tabs->data, FALSE);
- g_list_free (tabs);
+ MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
+ GKeyFile* key_file;
+ guint slot_count = 0, slot = 1, i;
+ gchar** groups;
+
+ g_object_get (browser, "speed-dial", &key_file, NULL);
+
+ groups = g_key_file_get_groups (key_file, NULL);
+ for (i = 0; groups[i]; i++)
+ {
+ if (g_key_file_has_key (key_file, groups[i], "uri", NULL))
+ slot_count++;
+ }
+
+ while (slot <= slot_count)
+ {
+ gchar* dial_id = g_strdup_printf ("Dial %d", slot);
+ if (!g_key_file_has_group (key_file, dial_id))
+ {
+ g_free (dial_id);
+ return g_strdup_printf ("s%d", slot);
+ }
+ g_free (dial_id);
+ slot++;
+ }
+ return g_strdup_printf ("s%d", slot_count + 1);
}
static void
@@ -1135,14 +1118,44 @@ midori_browser_add_speed_dial (MidoriBrowser* browser)
{
GdkPixbuf* img;
GtkWidget* view = midori_browser_get_current_tab (browser);
+ gchar* uri = g_strdup (midori_view_get_display_uri (MIDORI_VIEW (view)));
+ gchar* title = g_strdup (midori_view_get_display_title (MIDORI_VIEW (view)));
+ gchar* slot_id = midori_browser_speed_dial_get_next_free_slot (MIDORI_VIEW (view));
+
+ if (slot_id == NULL)
+ {
+ g_free (uri);
+ g_free (title);
+ return;
+ }
if ((img = midori_view_get_snapshot (MIDORI_VIEW (view), 240, 160)))
{
- midori_speed_dial_add (browser->dial,
- midori_view_get_display_uri (MIDORI_VIEW (view)),
- midori_view_get_display_title (MIDORI_VIEW (view)), img);
+ GKeyFile* key_file;
+ gchar* dial_id = g_strdup_printf ("Dial %s", slot_id + 1);
+ gchar* file_path = sokoke_build_thumbnail_path (uri);
+ gchar* thumb_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_cache_dir (),
+ PACKAGE_NAME, "thumbnails", NULL);
+ g_object_get (browser, "speed-dial", &key_file, NULL);
+
+ g_key_file_set_string (key_file, dial_id, "uri", uri);
+ g_key_file_set_string (key_file, dial_id, "title", title);
+
+ if (!g_file_test (thumb_dir, G_FILE_TEST_EXISTS))
+ katze_mkdir_with_parents (thumb_dir, 0700);
+
+ gdk_pixbuf_save (img, file_path, "png", NULL, "compression", "7", NULL);
+
+ midori_view_save_speed_dial_config (MIDORI_VIEW (view), key_file);
+
g_object_unref (img);
+ g_free (file_path);
+ g_free (thumb_dir);
+ g_free (dial_id);
}
+ g_free (uri);
+ g_free (title);
+ g_free (slot_id);
}
@@ -1163,7 +1176,7 @@ midori_browser_tab_leave_notify_event_cb (GtkWidget* widget,
GdkEventCrossing* event,
MidoriBrowser* browser)
{
- _midori_browser_set_statusbar_text (browser, MIDORI_VIEW (widget), NULL);
+ _midori_browser_set_statusbar_text (browser, NULL);
return TRUE;
}
@@ -1172,7 +1185,7 @@ midori_view_activate_action_cb (GtkWidget* view,
const gchar* action,
MidoriBrowser* browser)
{
- midori_browser_activate_action (browser, action);
+ _midori_browser_activate_action (browser, action);
}
static void
@@ -1191,8 +1204,6 @@ midori_view_attach_inspector_cb (GtkWidget* view,
gtk_widget_show_all (browser->inspector);
browser->inspector_view = inspector_view;
gtk_widget_destroy (toplevel);
- if (!katze_object_get_boolean (browser->settings, "last-inspector-attached"))
- g_object_set (browser->settings, "last-inspector-attached", TRUE, NULL);
}
static void
@@ -1206,8 +1217,6 @@ midori_view_detach_inspector_cb (GtkWidget* view,
gtk_container_remove (GTK_CONTAINER (scrolled), GTK_WIDGET (inspector_view));
gtk_container_add (GTK_CONTAINER (scrolled), browser->inspector_view);
gtk_widget_hide (paned);
- if (katze_object_get_boolean (browser->settings, "last-inspector-attached"))
- g_object_set (browser->settings, "last-inspector-attached", FALSE, NULL);
}
static void
@@ -1237,23 +1246,19 @@ midori_browser_view_copy_history (GtkWidget* view_to,
}
}
-static gboolean
+static gint
midori_browser_notify_new_tab_timeout_cb (MidoriBrowser *browser)
{
- #ifndef G_OS_WIN32
gtk_window_set_opacity (GTK_WINDOW (browser), 1);
- #endif
- return G_SOURCE_REMOVE;
+ return 0;
}
static void
-midori_browser_notify_new_tab (MidoriBrowser* browser)
+midori_browser_notify_new_tab (MidoriBrowser *browser)
{
if (katze_object_get_boolean (browser->settings, "flash-window-on-new-bg-tabs"))
{
- #ifndef G_OS_WIN32
gtk_window_set_opacity (GTK_WINDOW (browser), 0.8);
- #endif
g_timeout_add (100, (GSourceFunc) midori_browser_notify_new_tab_timeout_cb, browser);
}
}
@@ -1307,9 +1312,9 @@ midori_view_new_view_cb (GtkWidget* view,
gint n = midori_browser_add_tab (browser, new_view);
if (where != MIDORI_NEW_VIEW_BACKGROUND)
midori_browser_set_current_page (browser, n);
+ else
+ midori_browser_notify_new_tab (browser);
}
- else
- midori_browser_notify_new_tab (browser);
if (!user_initiated)
{
@@ -1329,43 +1334,21 @@ midori_view_new_view_cb (GtkWidget* view,
}
static void
-midori_browser_download_status_cb (WebKitDownload* download,
- GParamSpec* pspec,
- GtkWidget* widget)
+midori_view_download_save_as_response_cb (GtkWidget* dialog,
+ gint response,
+ MidoriBrowser* browser)
{
- const gchar* uri = webkit_download_get_destination_uri (download);
- switch (webkit_download_get_status (download))
+ WebKitDownload* download = g_object_get_data (G_OBJECT (dialog), "download");
+ if (response == GTK_RESPONSE_OK)
{
- case WEBKIT_DOWNLOAD_STATUS_FINISHED:
- if (!sokoke_show_uri (gtk_widget_get_screen (widget), uri, 0, NULL))
- {
- sokoke_message_dialog (GTK_MESSAGE_ERROR,
- _("Error opening the image!"),
- _("Can not open selected image in a default viewer."), FALSE);
- }
- break;
- case WEBKIT_DOWNLOAD_STATUS_ERROR:
- webkit_download_cancel (download);
- sokoke_message_dialog (GTK_MESSAGE_ERROR,
- _("Error downloading the image!"),
- _("Can not download selected image."), FALSE);
- break;
- case WEBKIT_DOWNLOAD_STATUS_CREATED:
- case WEBKIT_DOWNLOAD_STATUS_STARTED:
- case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
- break;
+ gchar* uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+ if (midori_browser_prepare_download (browser, download, uri))
+ webkit_download_start (download);
+ g_free (uri);
}
-}
-
-static gboolean
-midori_browser_remove_tab_idle (gpointer view)
-{
- MidoriBrowser* browser;
-
- g_return_val_if_fail (GTK_IS_WIDGET (view), FALSE);
- browser = midori_browser_get_for_widget (GTK_WIDGET (view));
- midori_browser_remove_tab (browser, GTK_WIDGET (view));
- return G_SOURCE_REMOVE;
+ else
+ g_object_unref (download);
+ gtk_widget_hide (dialog);
}
static gboolean
@@ -1373,92 +1356,90 @@ midori_view_download_requested_cb (GtkWidget* view,
WebKitDownload* download,
MidoriBrowser* browser)
{
- MidoriDownloadType type = midori_download_get_type (download);
- GtkWidget* web_view;
- WebKitWebFrame* web_frame;
- WebKitWebDataSource* datasource;
- gboolean handled;
-
- g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
- handled = TRUE;
- if (type == MIDORI_DOWNLOAD_CANCEL)
- {
- handled = FALSE;
- }
- else if (type == MIDORI_DOWNLOAD_OPEN_IN_VIEWER)
+ if (!webkit_download_get_destination_uri (download))
{
- gchar* destination_uri =
- midori_download_prepare_destination_uri (download, NULL);
- midori_browser_prepare_download (browser, download, destination_uri);
- g_signal_connect (download, "notify::status",
- G_CALLBACK (midori_browser_download_status_cb), GTK_WIDGET (browser));
- g_free (destination_uri);
- webkit_download_start (download);
- }
- else if (!webkit_download_get_destination_uri (download))
- {
- if (type == MIDORI_DOWNLOAD_SAVE_AS)
+ gchar* folder;
+ if (g_object_get_data (G_OBJECT (download), "save-as-download"))
{
static GtkWidget* dialog = NULL;
- gchar* filename;
if (!dialog)
{
- gchar* folder;
dialog = sokoke_file_chooser_dialog_new (_("Save file"),
GTK_WINDOW (browser), GTK_FILE_CHOOSER_ACTION_SAVE);
gtk_file_chooser_set_do_overwrite_confirmation (
GTK_FILE_CHOOSER (dialog), TRUE);
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
- folder = midori_uri_get_folder (webkit_download_get_uri (download));
- if (folder == NULL)
- folder = katze_object_get_string (browser->settings, "download-folder");
+ folder = katze_object_get_string (browser->settings, "download-folder");
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), folder);
g_free (folder);
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed), &dialog);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (midori_view_download_save_as_response_cb), browser);
}
g_object_set_data (G_OBJECT (dialog), "download", download);
- filename = midori_download_get_suggested_filename (download);
- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
- g_free (filename);
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
+ webkit_download_get_suggested_filename (download));
+ gtk_widget_show (dialog);
+ }
+ else
+ {
+ const gchar* suggested;
+ gchar* basename;
+ gchar* filename;
+ gchar* uri;
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+ if (g_object_get_data (G_OBJECT (download), "open-download"))
+ folder = g_strdup (g_get_tmp_dir ());
+ else
+ folder = katze_object_get_string (browser->settings, "download-folder");
+ suggested = webkit_download_get_suggested_filename (download);
+ /* The suggested name may contain a folder name */
+ basename = g_path_get_basename (suggested);
+ filename = g_build_filename (folder, basename, NULL);
+ g_free (basename);
+ /* If the filename exists, choose a different name */
+ if (g_access (filename, F_OK) == 0)
{
- gtk_widget_hide (dialog);
- gchar* uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
- if (!midori_browser_prepare_download (browser, download, uri))
+ /* Put the number in front of the extension */
+ gchar* extension = strrchr (filename, '.');
+ gsize length = extension ? (gsize)(extension - filename) : strlen (filename);
+ do
{
- g_free (uri);
- return FALSE;
+ if (g_ascii_isdigit (filename[length - 1]))
+ filename[length - 1] += 1; /* FIXME: This will increment '9' to ':' */
+ else
+ {
+ gchar* new_filename;
+ if (extension)
+ {
+ /* Change the '.' to a '\0' to put the 0 in between */
+ *extension++ = '\0';
+ new_filename= g_strconcat (filename, "0.", extension, NULL);
+ }
+ else
+ new_filename = g_strconcat (filename, "0", NULL);
+ katze_assign (filename, new_filename);
+ if (extension)
+ {
+ extension = strrchr (filename, '.');
+ length = extension - filename;
+ }
+ else
+ length = strlen (filename);
+ }
}
- g_free (uri);
+ while (g_access (filename, F_OK) == 0);
}
- else
- {
- gtk_widget_hide (dialog);
- return FALSE;
- }
- }
- else
- {
- gchar* folder = type == MIDORI_DOWNLOAD_OPEN ? NULL
- : katze_object_get_string (browser->settings, "download-folder");
- gchar* destination_uri =
- midori_download_prepare_destination_uri (download, folder);
- midori_browser_prepare_download (browser, download, destination_uri);
- g_free (destination_uri);
+ g_free (folder);
+ uri = g_filename_to_uri (filename, NULL, NULL);
+ g_free (filename);
+ midori_browser_prepare_download (browser, download, uri);
+ g_free (uri);
}
- webkit_download_start (download);
}
-
- /* Close empty tabs due to download links with a target */
- web_view = midori_view_get_web_view (MIDORI_VIEW (view));
- web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
- datasource = webkit_web_frame_get_data_source (web_frame);
- if (midori_view_is_blank (MIDORI_VIEW (view)) && webkit_web_data_source_get_data (datasource) == NULL)
- g_idle_add (midori_browser_remove_tab_idle, view);
- return handled;
+ return TRUE;
}
static void
@@ -1470,70 +1451,57 @@ midori_view_search_text_cb (GtkWidget* view,
midori_findbar_search_text (MIDORI_FINDBAR (browser->find), view, found, typing);
}
-gint
-midori_browser_get_n_pages (MidoriBrowser* browser)
-{
- #ifdef HAVE_GRANITE
- return granite_widgets_dynamic_notebook_get_n_tabs (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook));
- #else
- return gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook));
- #endif
-}
-
-static void
-midori_browser_tab_destroy_cb (MidoriView* view,
+static gboolean
+midori_browser_tab_destroy_cb (GtkWidget* widget,
MidoriBrowser* browser)
{
- if (browser->proxy_array)
+ KatzeItem* item;
+
+ if (browser->proxy_array && MIDORI_IS_VIEW (widget))
{
- KatzeItem* item = midori_view_get_proxy_item (view);
- if (katze_array_get_item_index (browser->proxy_array, item) != -1)
- {
- if (!midori_view_is_blank (view))
- {
- if (browser->trash)
- katze_array_add_item (browser->trash, item);
- midori_browser_update_history (item, "website", "leave");
- }
- katze_array_remove_item (browser->proxy_array, item);
- }
+ item = midori_view_get_proxy_item (MIDORI_VIEW (widget));
+ if (browser->trash && !midori_view_is_blank (MIDORI_VIEW (widget)))
+ katze_array_add_item (browser->trash, item);
+ katze_array_remove_item (browser->proxy_array, item);
+ }
+
+ _midori_browser_update_actions (browser);
+
+ /* This callback must only be called once, but we need to ensure
+ that "remove-tab" is emitted in any case */
+ g_signal_handlers_disconnect_by_func (widget,
+ midori_browser_tab_destroy_cb, browser);
+
+ g_signal_emit (browser, signals[REMOVE_TAB], 0, widget);
/* We don't ever want to be in a situation with no tabs,
so just create an empty one if the last one is closed.
The only exception is when we are closing the window,
which is indicated by the proxy array having been unset. */
- if (midori_browser_get_n_pages (browser) == 0)
- midori_browser_add_uri (browser, "");
- }
-
- _midori_browser_update_actions (browser);
-}
-
-static void
-_midori_browser_remove_tab (MidoriBrowser* browser,
- GtkWidget* widget)
-{
+ if (browser->proxy_array && !midori_browser_get_current_tab (browser))
+ midori_browser_add_uri (browser, "");
+ return FALSE;
}
-#ifndef HAVE_GRANITE
static void
midori_browser_notebook_resize (MidoriBrowser* browser,
GdkRectangle* allocation)
{
gint new_size = 0;
- gint n = MAX (1, gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)));
+ gint n = gtk_notebook_get_n_pages (GTK_NOTEBOOK(browser->notebook));
const gint max_size = 150;
gint min_size;
gint icon_size = 16;
GtkAllocation notebook_size;
GList* children;
+ g_return_if_fail (n > 0);
+
if (allocation != NULL)
notebook_size.width = allocation->width;
else
gtk_widget_get_allocation (browser->notebook, ¬ebook_size);
- new_size = notebook_size.width / n;
+ new_size = notebook_size.width / n - 7;
gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (browser->notebook),
GTK_ICON_SIZE_MENU, &icon_size, NULL);
@@ -1560,29 +1528,36 @@ midori_browser_notebook_resize (MidoriBrowser* browser,
gtk_widget_set_size_request (label, new_size, -1);
}
}
-#endif
static void
midori_browser_notebook_size_allocate_cb (GtkWidget* widget,
GdkRectangle* allocation,
MidoriBrowser* browser)
{
- #ifndef HAVE_GRANITE
if (!gtk_notebook_get_show_tabs (GTK_NOTEBOOK (browser->notebook)))
return;
midori_browser_notebook_resize (browser, allocation);
- #endif
}
static void
-midori_browser_connect_tab (MidoriBrowser* browser,
- GtkWidget* view)
+_midori_browser_add_tab (MidoriBrowser* browser,
+ GtkWidget* view)
{
- KatzeItem* item = midori_view_get_proxy_item (MIDORI_VIEW (view));
- katze_array_add_item (browser->proxy_array, item);
+ GtkNotebook* notebook = GTK_NOTEBOOK (browser->notebook);
+ GtkWidget* tab_label;
+ KatzeItem* item;
+ guint n;
gtk_widget_set_can_focus (view, TRUE);
+ tab_label = midori_view_get_proxy_tab_label (MIDORI_VIEW (view));
+ /* Don't resize empty bin, which is used for thumbnail tabs */
+ if (GTK_IS_BIN (tab_label) && gtk_bin_get_child (GTK_BIN (tab_label))
+ && !katze_object_get_boolean (view, "minimized"))
+ gtk_widget_set_size_request (tab_label, browser->last_tab_size, -1);
+ item = midori_view_get_proxy_item (MIDORI_VIEW (view));
+ katze_array_add_item (browser->proxy_array, item);
+
g_object_connect (view,
"signal::notify::icon",
midori_view_notify_icon_cb, browser,
@@ -1612,7 +1587,7 @@ midori_browser_connect_tab (MidoriBrowser* browser,
midori_view_new_window_cb, browser,
"signal::new-view",
midori_view_new_view_cb, browser,
- "signal-after::download-requested",
+ "signal::download-requested",
midori_view_download_requested_cb, browser,
"signal::search-text",
midori_view_search_text_cb, browser,
@@ -1622,51 +1597,36 @@ midori_browser_connect_tab (MidoriBrowser* browser,
midori_view_add_speed_dial_cb, browser,
"signal::leave-notify-event",
midori_browser_tab_leave_notify_event_cb, browser,
- "signal::destroy",
- midori_browser_tab_destroy_cb, browser,
NULL);
-}
-
-static void
-_midori_browser_add_tab (MidoriBrowser* browser,
- GtkWidget* view)
-{
- GtkWidget* notebook = browser->notebook;
- KatzeItem* item = midori_view_get_proxy_item (MIDORI_VIEW (view));
- #ifndef HAVE_GRANITE
- GtkWidget* tab_label;
- #endif
- guint n;
-
- midori_browser_connect_tab (browser, view);
if (!katze_item_get_meta_boolean (item, "append") &&
katze_object_get_boolean (browser->settings, "open-tabs-next-to-current"))
{
- n = midori_browser_get_current_page (browser) + 1;
+ n = gtk_notebook_get_current_page (notebook) + 1;
katze_array_move_item (browser->proxy_array, item, n);
}
else
- n = midori_browser_get_n_pages (browser);
+ n = -1;
+ gtk_notebook_insert_page (notebook, view, tab_label, n);
katze_item_set_meta_integer (item, "append", -1);
-#ifdef HAVE_GRANITE
- granite_widgets_dynamic_notebook_insert_tab (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (notebook),
- midori_view_get_tab (MIDORI_VIEW (view)), n);
-#else
- tab_label = midori_view_get_proxy_tab_label (MIDORI_VIEW (view));
- /* Don't resize empty bin, which is used for thumbnail tabs */
- if (GTK_IS_BIN (tab_label) && gtk_bin_get_child (GTK_BIN (tab_label))
- && !katze_object_get_boolean (view, "minimized"))
- gtk_widget_set_size_request (tab_label, browser->last_tab_size, -1);
- gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), view, tab_label, n);
- gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), view, TRUE);
- gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), view, TRUE);
- midori_browser_notebook_size_allocate_cb (browser->notebook, NULL, browser);
-#endif
+ gtk_notebook_set_tab_reorderable (notebook, view, TRUE);
+ gtk_notebook_set_tab_detachable (notebook, view, TRUE);
+
+ /* We want the tab to be removed if the widget is destroyed */
+ g_signal_connect (view, "destroy",
+ G_CALLBACK (midori_browser_tab_destroy_cb), browser);
_midori_browser_update_actions (browser);
+ midori_browser_notebook_size_allocate_cb (browser->notebook, NULL, browser);
+}
+
+static void
+_midori_browser_remove_tab (MidoriBrowser* browser,
+ GtkWidget* view)
+{
+ gtk_widget_destroy (view);
+ midori_browser_notebook_size_allocate_cb (browser->notebook, NULL, browser);
}
/**
@@ -1685,17 +1645,10 @@ midori_browser_foreach (MidoriBrowser* browser,
GtkCallback callback,
gpointer callback_data)
{
- g_return_if_fail (MIDORI_IS_BROWSER (browser));
+ g_return_if_fail (MIDORI_IS_BROWSER (browser));
- #ifdef HAVE_GRANITE
- /* FIXME */
- if (GTK_IS_BIN (browser->notebook))
- gtk_container_foreach (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (
- browser->notebook))), callback, callback_data);
- else
- #endif
- gtk_container_foreach (GTK_CONTAINER (browser->notebook),
- callback, callback_data);
+ gtk_container_foreach (GTK_CONTAINER (browser->notebook),
+ callback, callback_data);
}
static void
@@ -1719,14 +1672,14 @@ midori_browser_key_press_event (GtkWidget* widget,
&& event->keyval == GDK_KEY_Tab
&& (event->state & GDK_CONTROL_MASK))
{
- midori_browser_activate_action (browser, "TabNext");
+ gtk_action_activate (_action_by_name (browser, "TabNext"));
return TRUE;
}
else if (event->keyval == GDK_KEY_ISO_Left_Tab
&& (event->state & GDK_CONTROL_MASK)
&& (event->state & GDK_SHIFT_MASK))
{
- midori_browser_activate_action (browser, "TabPrevious");
+ gtk_action_activate (_action_by_name (browser, "TabPrevious"));
return TRUE;
}
/* Interpret Ctrl+= as Zoom In for compatibility */
@@ -1739,7 +1692,7 @@ midori_browser_key_press_event (GtkWidget* widget,
/* Interpret F5 as reloading for compatibility */
else if (event->keyval == GDK_KEY_F5)
{
- midori_browser_activate_action (browser, "Reload");
+ gtk_action_activate (_action_by_name (browser, "Reload"));
return TRUE;
}
@@ -1748,13 +1701,12 @@ midori_browser_key_press_event (GtkWidget* widget,
gtk_widget_grab_focus (midori_browser_get_current_tab (MIDORI_BROWSER (widget)));
else if (G_OBJECT_TYPE (focus) == WEBKIT_TYPE_WEB_VIEW
&& event->keyval == GDK_KEY_space
- && (!(event->state & GDK_SHIFT_MASK))
&& !webkit_web_view_can_cut_clipboard (WEBKIT_WEB_VIEW (focus))
&& !webkit_web_view_can_paste_clipboard (WEBKIT_WEB_VIEW (focus)))
{
/* Space at the bottom of the page: Go to next page */
- MidoriView* view = midori_view_get_for_widget (focus);
GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (focus));
+ MidoriView* view = MIDORI_VIEW (gtk_widget_get_parent (GTK_WIDGET (scrolled)));
GtkAdjustment* vadjust = gtk_scrolled_window_get_vadjustment (scrolled);
if (gtk_adjustment_get_value (vadjust)
== (gtk_adjustment_get_upper (vadjust) - gtk_adjustment_get_page_size (vadjust)))
@@ -1789,12 +1741,12 @@ midori_browser_key_press_event (GtkWidget* widget,
if ((event->keyval == GDK_KEY_BackSpace)
&& (event->state & GDK_SHIFT_MASK))
{
- midori_browser_activate_action (browser, "Forward");
+ gtk_action_activate (_action_by_name (browser, "Forward"));
return TRUE;
}
else if (event->keyval == GDK_KEY_BackSpace)
{
- midori_browser_activate_action (browser, "Back");
+ gtk_action_activate (_action_by_name (browser, "Back"));
return TRUE;
}
@@ -1885,28 +1837,6 @@ midori_browser_class_init (MidoriBrowserClass* class)
G_TYPE_NONE, 3,
GTK_TYPE_NOTEBOOK, G_TYPE_INT, G_TYPE_INT);
- /**
- * MidoriBrowser::switch-tab:
- * @browser: the object on which the signal is emitted
- * @old_view: the previous tab
- * @new_view: the new tab
- *
- * Emitted when a tab is switched.
- * There's no guarantee what the current tab is.
- *
- * Since: 0.4.7
- */
- signals[SWITCH_TAB] = g_signal_new (
- "switch-tab",
- G_TYPE_FROM_CLASS (class),
- (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
- 0,
- 0,
- NULL,
- midori_cclosure_marshal_VOID__OBJECT_OBJECT,
- G_TYPE_NONE, 2,
- G_TYPE_OBJECT, G_TYPE_OBJECT);
-
signals[ACTIVATE_ACTION] = g_signal_new (
"activate-action",
G_TYPE_FROM_CLASS (class),
@@ -2080,11 +2010,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
"notebook",
"Notebook",
"The notebook containing the views",
- #ifdef HAVE_GRANITE
- GRANITE_WIDGETS_TYPE_DYNAMIC_NOTEBOOK,
- #else
GTK_TYPE_NOTEBOOK,
- #endif
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
@@ -2254,16 +2180,16 @@ midori_browser_class_init (MidoriBrowserClass* class)
* The speed dial configuration file.
*
* Since: 0.3.4
- * Since 0.4.7 this is a Midori.SpeedDial instance.
*/
g_object_class_install_property (gobject_class,
PROP_SPEED_DIAL,
g_param_spec_pointer (
"speed-dial",
"Speeddial",
- "Speed dial",
+ "Pointer to key-value object with speed dial items",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
/**
* MidoriBrowser:show-tabs:
*
@@ -2299,7 +2225,13 @@ static void
_action_window_new_activate (GtkAction* action,
MidoriBrowser* browser)
{
- midori_view_new_window_cb (NULL, "", browser);
+ MidoriBrowser* new_browser;
+ g_signal_emit (browser, signals[NEW_WINDOW], 0, NULL, &new_browser);
+ if (new_browser)
+ {
+ midori_browser_add_uri (new_browser, "");
+ midori_browser_activate_action (new_browser, "Location");
+ }
}
static void
@@ -2314,7 +2246,8 @@ static void
_action_private_browsing_activate (GtkAction* action,
MidoriBrowser* browser)
{
- sokoke_spawn_app ("about:private", TRUE);
+ const gchar* uri = midori_browser_get_current_uri (browser);
+ sokoke_spawn_app (uri && *uri ? uri : "about:blank", TRUE);
}
static void
@@ -2380,8 +2313,7 @@ static void
_action_save_as_activate (GtkAction* action,
MidoriBrowser* browser)
{
- GtkWidget* view = midori_browser_get_current_tab (browser);
- midori_browser_save_uri (browser, MIDORI_VIEW (view), NULL);
+ midori_browser_save_uri (browser, midori_browser_get_current_uri (browser));
}
static void
@@ -2456,9 +2388,9 @@ midori_browser_subscribe_to_news_feed (MidoriBrowser* browser,
/* Special-case Liferea because a helper script may be required */
if (g_str_equal (browser->news_aggregator, "liferea")
&& g_find_program_in_path ("liferea-add-feed"))
- sokoke_spawn_program ("liferea-add-feed", FALSE, feed, TRUE);
+ sokoke_spawn_program ("liferea-add-feed", feed);
else
- sokoke_spawn_program (browser->news_aggregator, TRUE, feed, TRUE);
+ sokoke_spawn_program (browser->news_aggregator, feed);
g_free (feed);
}
else
@@ -2527,7 +2459,11 @@ _action_compact_add_activate (GtkAction* action,
g_free (label);
gtk_widget_set_name (button, "GtkButton-thumb");
gtk_box_pack_start (box, button, TRUE, TRUE, 4);
+ #if GTK_CHECK_VERSION (2, 16, 0)
gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
+ #else
+ gtk_action_connect_proxy (action, button);
+ #endif
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), dialog);
}
@@ -2542,16 +2478,16 @@ _action_tab_close_activate (GtkAction* action,
MidoriBrowser* browser)
{
GtkWidget* widget = midori_browser_get_current_tab (browser);
- MidoriView* view = MIDORI_VIEW (widget);
- gboolean last_tab = midori_browser_get_n_pages (browser) == 1;
- if (last_tab && midori_paths_is_readonly () /* APP, PRIVATE */)
+ gboolean last_tab =
+ gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), 1) == NULL;
+ if (last_tab && sokoke_is_app_or_private ())
{
gtk_widget_destroy (GTK_WIDGET (browser));
return;
}
- if (last_tab && midori_view_is_blank (view))
+ if (last_tab && midori_view_is_blank (MIDORI_VIEW (widget)))
return;
- midori_browser_remove_tab (browser, widget);
+ gtk_widget_destroy (widget);
}
static void
@@ -2570,36 +2506,8 @@ _action_print_activate (GtkAction* action,
if (!gtk_widget_get_visible (GTK_WIDGET (browser)))
return;
- if (!(view = midori_browser_get_current_tab (browser)))
- return;
-
- #ifdef HAVE_GRANITE
- /* FIXME: Blacklist/ custom contract doesn't work
- gchar* blacklisted_contracts[] = { "print", NULL }; */
- /* FIXME: granite: should return GtkWidget* like GTK+ */
- GtkWidget* dialog = (GtkWidget*)granite_widgets_pop_over_new ();
- GtkWidget* content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- /* FIXME: granite: should return GtkWidget* like GTK+ */
- gchar* filename = midori_view_save_source (MIDORI_VIEW (view), NULL, NULL);
- const gchar* mime_type = katze_item_get_meta_string (
- midori_view_get_proxy_item (MIDORI_VIEW (view)), "mime-type");
- GtkWidget* contractor = (GtkWidget*)granite_widgets_contractor_view_new (
- filename, mime_type, 32, TRUE);
- /* granite_widgets_contractor_view_add_item (GRANITE_WIDGETS_CONTRACTOR_VIEW (
- contractor), _("_Print"), _("Send document to the printer"), "document-print",
- 32, G_MAXINT, midori_view_print, view);
- granite_widgets_contractor_view_name_blacklist (GRANITE_WIDGETS_CONTRACTOR_VIEW (
- contractor), blacklisted_contracts, -1); */
- g_free (filename);
- gtk_container_add (GTK_CONTAINER (content_area), contractor);
- gtk_widget_show (contractor);
- gtk_widget_show (dialog);
- if (gtk_widget_get_visible (browser->navigationbar))
- granite_widgets_pop_over_move_to_widget (
- GRANITE_WIDGETS_POP_OVER (dialog), browser->navigationbar, TRUE);
- #else
- midori_view_print (MIDORI_VIEW (view));
- #endif
+ if ((view = midori_browser_get_current_tab (browser)))
+ midori_view_print (MIDORI_VIEW (view));
}
static void
@@ -2689,7 +2597,6 @@ _action_copy_activate (GtkAction* action,
MidoriBrowser* browser)
{
GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser));
-#if !WEBKIT_CHECK_VERSION (1, 4, 3)
/* Work around broken clipboard handling for the sake of the user */
if (WEBKIT_IS_WEB_VIEW (widget))
{
@@ -2699,7 +2606,6 @@ _action_copy_activate (GtkAction* action,
sokoke_widget_copy_clipboard (widget, selected);
return;
}
-#endif
if (G_LIKELY (widget) && g_signal_lookup ("copy-clipboard", G_OBJECT_TYPE (widget)))
g_signal_emit_by_name (widget, "copy-clipboard");
}
@@ -2765,14 +2671,14 @@ static void
_action_find_next_activate (GtkAction* action,
MidoriBrowser* browser)
{
- midori_findbar_find_text (MIDORI_FINDBAR (browser->find), NULL, TRUE);
+ midori_findbar_find (MIDORI_FINDBAR (browser->find), TRUE);
}
static void
_action_find_previous_activate (GtkAction* action,
MidoriBrowser* browser)
{
- midori_findbar_find_text (MIDORI_FINDBAR (browser->find), NULL, FALSE);
+ midori_findbar_find (MIDORI_FINDBAR (browser->find), FALSE);
}
static void
@@ -2806,7 +2712,7 @@ midori_browser_get_toolbar_actions (MidoriBrowser* browser)
static const gchar* actions[] = {
"WindowNew", "TabNew", "Open", "SaveAs", "Print", "Find",
"Fullscreen", "Preferences", "Window", "Bookmarks",
- "ReloadStop", "ZoomIn", "TabClose", "NextForward",
+ "ReloadStop", "ZoomIn", "TabClose",
"ZoomOut", "Separator", "Back", "Forward", "Homepage",
"Panel", "Trash", "Search", "BookmarkAdd", "Previous", "Next", NULL };
@@ -2994,7 +2900,7 @@ _action_tools_populate_popup (GtkAction* action,
j = 0;
while ((widget = midori_panel_get_nth_page (panel, j++)))
{
- menuitem = midori_panel_construct_menu_item (panel, MIDORI_VIEWABLE (widget), FALSE);
+ menuitem = midori_panel_construct_menu_item (panel, MIDORI_VIEWABLE (widget));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
}
continue;
@@ -3021,35 +2927,14 @@ _action_bookmarks_populate_folder (GtkAction* action,
KatzeArray* folder,
MidoriBrowser* browser)
{
- gint64 id;
+ const gchar* folder_name;
KatzeArray* bookmarks;
GtkWidget* menuitem;
- id = katze_item_get_meta_integer (KATZE_ITEM (folder), "id");
-
- if (id == -1)
- {
- if (!(bookmarks = midori_array_query (browser->bookmarks,
- "id, title, parentid, uri, app, pos_panel, pos_bar", "parentid is NULL", NULL)))
- {
- g_warning ("midori_array_query returned NULL)");
- return FALSE;
- }
- }
- else
- {
- gchar *parentid = g_strdup_printf ("%" G_GINT64_FORMAT, id);
-
- if (!(bookmarks = midori_array_query (browser->bookmarks,
- "id, title, parentid, uri, app, pos_panel, pos_bar", "parentid = %q", parentid)))
- {
- g_warning ("midori_array_query returned NULL (id='%s')", parentid);
- g_free (parentid);
- return FALSE;
- }
-
- g_free (parentid);
- }
+ folder_name = katze_item_get_name (KATZE_ITEM (folder));
+ if (!(bookmarks = midori_array_query (browser->bookmarks,
+ "uri, title, app, folder", "folder = '%q'", folder_name)))
+ return FALSE;
/* Clear items from dummy array here */
gtk_container_foreach (GTK_CONTAINER (menu),
@@ -3113,9 +2998,9 @@ _action_window_activate_item_alt (GtkAction* action,
for (i = 0; i < n; i++)
{
GtkWidget* view;
- view = midori_browser_get_nth_tab (browser, i);
+ view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), i);
if (midori_view_get_proxy_item (MIDORI_VIEW (view)) == item)
- midori_browser_set_current_page (browser, i);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), i);
}
}
@@ -3127,32 +3012,33 @@ _action_compact_menu_populate_popup (GtkAction* action,
static const GtkActionEntry actions[] = {
{ "TabNew" },
{ "WindowNew" },
- { "PrivateBrowsing" },
{ NULL },
+ { "Open" },
{ "Find" },
#if !HAVE_HILDON
{ "Print" },
+ { "InspectPage" },
#endif
- { "Fullscreen" },
{ NULL },
+ { "PrivateBrowsing" },
#if !HAVE_HILDON
- { "p" },
- { NULL },
- { "BookmarksImport" },
- { "BookmarksExport" },
{ "ClearPrivateData" },
#if defined (GDK_WINDOWING_X11)
{ "AddDesktopShortcut" },
#endif
+ { NULL },
+ { "BookmarksImport"},
+ { "BookmarksExport"},
+ { NULL },
+ { "Fullscreen" },
+ { "Panel" },
{ "-" },
#endif
{ NULL },
#if !HAVE_HILDON
- #ifndef HAVE_GRANITE
{ "HelpFAQ" },
{ "HelpBugs"},
#endif
- #endif
{ "About" },
{ "Preferences" },
#if HAVE_HILDON
@@ -3198,21 +3084,6 @@ _action_compact_menu_populate_popup (GtkAction* action,
g_signal_emit (browser, signals[POPULATE_TOOL_MENU], 0, menu);
continue;
}
- else if (actions[i].name[0] == 'p')
- {
- MidoriPanel* panel;
- gsize j;
- GtkWidget* widget;
-
- panel = MIDORI_PANEL (browser->panel);
- j = 0;
- while ((widget = midori_panel_get_nth_page (panel, j++)))
- {
- menuitem = midori_panel_construct_menu_item (panel, MIDORI_VIEWABLE (widget), TRUE);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
- }
- continue;
- }
menuitem = sokoke_action_create_popup_menu_item (
_action_by_name (browser, actions[i].name));
}
@@ -3232,7 +3103,7 @@ midori_preferences_response_help_cb (GtkWidget* preferences,
MidoriBrowser* browser)
{
if (response == GTK_RESPONSE_HELP)
- midori_browser_activate_action (browser, "HelpFAQ");
+ gtk_action_activate (_action_by_name (browser, "HelpFAQ"));
}
static void
@@ -3258,19 +3129,6 @@ _action_preferences_activate (GtkAction* action,
gtk_window_present (GTK_WINDOW (dialog));
}
-static gboolean
-midori_browser_has_native_menubar (void)
-{
- #if HAVE_HILDON
- return TRUE;
- #else
- static const gchar* ubuntu_menuproxy = NULL;
- if (ubuntu_menuproxy == NULL)
- ubuntu_menuproxy = g_getenv ("UBUNTU_MENUPROXY");
- return ubuntu_menuproxy && strstr (ubuntu_menuproxy, ".so") != NULL;
- #endif
-}
-
static void
_action_menubar_activate (GtkToggleAction* menubar_action,
MidoriBrowser* browser)
@@ -3281,9 +3139,6 @@ _action_menubar_activate (GtkToggleAction* menubar_action,
GList* children;
gchar* items;
- if (midori_browser_has_native_menubar ())
- active = FALSE;
-
toolbar_items = g_string_new (NULL);
children = gtk_container_get_children (GTK_CONTAINER (browser->navigationbar));
for (; children != NULL; children = g_list_next (children))
@@ -3377,14 +3232,13 @@ _action_reload_stop_activate (GtkAction* action,
{
GdkModifierType state = (GdkModifierType)0;
gint x, y;
- GdkWindow* window;
gboolean from_cache = TRUE;
if (!strcmp (gtk_action_get_name (action), "ReloadUncached"))
from_cache = FALSE;
- else if ((window = gtk_widget_get_window (GTK_WIDGET (browser))))
+ else
{
- gdk_window_get_pointer (window, &x, &y, &state);
+ gdk_window_get_pointer (NULL, &x, &y, &state);
if (state & GDK_SHIFT_MASK)
from_cache = FALSE;
}
@@ -3433,8 +3287,6 @@ _action_view_encoding_activate (GtkAction* action,
const gchar* encoding;
if (!strcmp (name, "EncodingChinese"))
encoding = "BIG5";
- else if (!strcmp (name, "EncodingChineseSimplified"))
- encoding = "GB18030";
else if (!strcmp (name, "EncodingJapanese"))
encoding = "SHIFT_JIS";
else if (!strcmp (name, "EncodingKorean"))
@@ -3452,19 +3304,112 @@ _action_view_encoding_activate (GtkAction* action,
}
}
+static gchar*
+midori_browser_get_uri_extension (const gchar* uri)
+{
+ gchar* slash;
+ gchar* period;
+ gchar* ext_end;
+
+ /* Find the last slash in the URI and search for the last period
+ *after* the last slash. This is not completely accurate
+ but should cover most (simple) URIs */
+ slash = strrchr (uri, '/');
+ /* Huh, URI without slashes? */
+ if (!slash)
+ return NULL;
+
+ ext_end = period = strrchr (slash, '.');
+ if (!period)
+ return NULL;
+
+ /* Skip the period */
+ ext_end++;
+ /* If *ext_end is 0 here, the URI ended with a period, so skip */
+ if (!*ext_end)
+ return NULL;
+
+ /* Find the end of the extension */
+ while (*ext_end && g_ascii_isalnum (*ext_end))
+ ext_end++;
+
+ *ext_end = 0;
+ return g_strdup (period);
+}
+
+static gchar*
+midori_browser_save_source (const gchar* uri,
+ const gchar* data,
+ const size_t len,
+ const gchar* outfile)
+{
+ gchar* unique_filename;
+ gint fd;
+ FILE* fp;
+ size_t ret;
+
+ if (!outfile)
+ {
+ gchar* filename;
+ gchar* extension;
+
+ extension = midori_browser_get_uri_extension (uri);
+ filename = g_strdup_printf ("%uXXXXXX%s",
+ g_str_hash (uri), extension && *extension ? extension : ".htm");
+ g_free (extension);
+ fd = g_file_open_tmp (filename, &unique_filename, NULL);
+ g_free (filename);
+ }
+ else
+ {
+ unique_filename = g_strdup (outfile);
+ fd = g_open (unique_filename, O_WRONLY|O_CREAT, 0644);
+ }
+
+ if (fd != -1)
+ {
+ if ((fp = fdopen (fd, "w")))
+ {
+ ret = fwrite (data, 1, len, fp);
+ fclose (fp);
+ if ((ret - len) != 0)
+ {
+ g_warning ("Error writing to file %s "
+ "in midori_browser_source_transfer_cb()", unique_filename);
+ katze_assign (unique_filename, NULL);
+ }
+ }
+ close (fd);
+ }
+ return unique_filename;
+}
+
static void
_action_source_view_activate (GtkAction* action,
MidoriBrowser* browser)
{
+ WebKitWebDataSource *data_source;
+ WebKitWebFrame *frame;
+ const GString *data;
GtkWidget* view;
+ GtkWidget* web_view;
gchar* text_editor;
gchar* filename = NULL;
+ const gchar* uri;
if (!(view = midori_browser_get_current_tab (browser)))
return;
- filename = midori_view_save_source (MIDORI_VIEW (view), NULL, NULL);
g_object_get (browser->settings, "text-editor", &text_editor, NULL);
+ uri = midori_view_get_display_uri (MIDORI_VIEW (view));
+ web_view = midori_view_get_web_view (MIDORI_VIEW (view));
+ frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
+ data_source = webkit_web_frame_get_data_source (frame);
+ data = webkit_web_data_source_get_data (data_source);
+ if (!data)
+ return;
+
+ filename = midori_browser_save_source (uri, data->str, data->len, NULL);
if (!(text_editor && *text_editor))
{
GtkWidget* source;
@@ -3482,7 +3427,7 @@ _action_source_view_activate (GtkAction* action,
}
else
{
- sokoke_spawn_program (text_editor, TRUE, filename, TRUE);
+ sokoke_spawn_program (text_editor, filename);
g_free (filename);
}
g_free (text_editor);
@@ -3492,33 +3437,7 @@ static void
_action_caret_browsing_activate (GtkAction* action,
MidoriBrowser* browser)
{
- gint response;
- GtkWidget* dialog;
-
- if (!gtk_widget_get_visible (GTK_WIDGET (browser)))
- return;
-
- if (!katze_object_get_boolean (browser->settings, "enable-caret-browsing"))
- {
- dialog = gtk_message_dialog_new (GTK_WINDOW (browser),
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
- GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
- _("Toggle text cursor navigation"));
- gtk_window_set_title (GTK_WINDOW (dialog), _("Toggle text cursor navigation"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("Pressing F7 toggles Caret Browsing. When active, a text cursor appears in all websites."));
- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- _("_Enable Caret Browsing"), GTK_RESPONSE_ACCEPT,
- NULL);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- if (response != GTK_RESPONSE_ACCEPT)
- return;
- }
-
+ _("Toggle text cursor navigation");
g_object_set (browser->settings, "enable-caret-browsing",
!katze_object_get_boolean (browser->settings, "enable-caret-browsing"), NULL);
}
@@ -3535,9 +3454,6 @@ _action_fullscreen_activate (GtkAction* action,
state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (browser)));
if (state & GDK_WINDOW_STATE_FULLSCREEN)
{
- if (katze_object_get_boolean (G_OBJECT (browser->settings), "show-menubar"))
- gtk_widget_show (browser->menubar);
-
if (katze_object_get_boolean (G_OBJECT (browser->settings), "show-panel"))
gtk_widget_show (browser->panel);
@@ -3555,18 +3471,12 @@ _action_fullscreen_activate (GtkAction* action,
}
else
{
- gtk_widget_hide (browser->menubar);
gtk_widget_hide (browser->panel);
gtk_widget_hide (browser->bookmarkbar);
gtk_widget_hide (browser->navigationbar);
gtk_widget_hide (browser->statusbar);
- #ifdef HAVE_GRANITE
- granite_widgets_dynamic_notebook_set_show_tabs (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), FALSE);
- #else
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), FALSE);
gtk_notebook_set_show_border (GTK_NOTEBOOK (browser->notebook), FALSE);
- #endif
gtk_window_fullscreen (GTK_WINDOW (browser));
}
@@ -3596,71 +3506,6 @@ _action_scroll_somewhere_activate (GtkAction* action,
webkit_web_view_move_cursor (web_view, GTK_MOVEMENT_VISUAL_POSITIONS, 1);
}
-static void
-_action_readable_activate (GtkAction* action,
- MidoriBrowser* browser)
-{
- GtkWidget* view = midori_browser_get_current_tab (browser);
- gchar* filename;
- gchar* stylesheet;
- gint i;
- gchar* script;
- gchar* exception;
-
- if (!view)
- return;
-
- filename = midori_paths_get_res_filename ("faq.css");
- stylesheet = NULL;
- if (!g_file_get_contents (filename, &stylesheet, NULL, NULL))
- {
- katze_assign (filename, midori_paths_get_data_filename ("doc/midori/faq.css", FALSE));
- g_file_get_contents (filename, &stylesheet, NULL, NULL);
- }
- if (!(stylesheet && *stylesheet))
- {
- g_free (filename);
- g_free (stylesheet);
- midori_view_add_info_bar (MIDORI_VIEW (view), GTK_MESSAGE_ERROR,
- "Stylesheet faq.css not found", NULL, view,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
- return;
- }
-
- i = 0;
- while (stylesheet[i])
- {
- /* Replace line breaks with spaces */
- if (stylesheet[i] == '\n' || stylesheet[i] == '\r')
- stylesheet[i] = ' ';
- /* Change all single quotes to double quotes */
- else if (stylesheet[i] == '\'')
- stylesheet[i] = '\"';
- i++;
- }
-
- script = g_strdup_printf (
- "(function () {"
- "var style = document.createElement ('style');"
- "style.setAttribute ('type', 'text/css');"
- "style.appendChild (document.createTextNode ('%s'));"
- "var head = document.getElementsByTagName ('head')[0];"
- "if (head) head.appendChild (style);"
- "else document.documentElement.insertBefore"
- "(style, document.documentElement.firstChild);"
- "}) ();", stylesheet);
- g_free (stylesheet);
- exception = NULL;
- if (!midori_view_execute_script (MIDORI_VIEW (view), script, &exception))
- {
- midori_view_add_info_bar (MIDORI_VIEW (view), GTK_MESSAGE_ERROR,
- exception, NULL, view,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
- g_free (exception);
- }
- g_free (script);
-}
-
static gboolean
_action_navigation_activate (GtkAction* action,
MidoriBrowser* browser)
@@ -3689,10 +3534,8 @@ _action_navigation_activate (GtkAction* action,
return FALSE;
view = MIDORI_VIEW (tab);
- name = gtk_action_get_name (action);
- if (!strcmp (name, "NextForward"))
- name = midori_view_can_go_forward (view) ? "Forward" : "Next";
+ name = gtk_action_get_name (action);
if (g_str_equal (name, "Back"))
{
@@ -3812,14 +3655,8 @@ static void
_action_location_focus_in (GtkAction* action,
MidoriBrowser* browser)
{
- GdkScreen* screen = gtk_widget_get_screen (browser->notebook);
- GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
- if (gtk_icon_theme_has_icon (icon_theme, "go-jump-symbolic"))
- midori_location_action_set_secondary_icon (
- MIDORI_LOCATION_ACTION (action), "go-jump-symbolic");
- else
- midori_location_action_set_secondary_icon (
- MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
+ midori_location_action_set_secondary_icon (
+ MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
}
static void
@@ -3831,54 +3668,63 @@ _action_location_focus_out (GtkAction* action,
if (!browser->show_navigationbar || midori_browser_is_fullscreen (browser))
gtk_widget_hide (browser->navigationbar);
- midori_browser_update_secondary_icon (browser, MIDORI_VIEW (view), action);
+ if (g_object_get_data (G_OBJECT (view), "news-feeds"))
+ midori_location_action_set_secondary_icon (
+ MIDORI_LOCATION_ACTION (action), STOCK_NEWS_FEED);
+ else
+ midori_location_action_set_secondary_icon (
+ MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
}
static void
_action_location_reset_uri (GtkAction* action,
MidoriBrowser* browser)
{
- GtkWidget* view;
- if ((view = midori_browser_get_current_tab (browser)))
- {
- midori_location_action_set_text (MIDORI_LOCATION_ACTION (action),
- midori_view_get_display_uri (MIDORI_VIEW (view)));
- }
+ const gchar* uri;
+
+ uri = midori_browser_get_current_uri (browser);
+ midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri);
}
+
static void
_action_location_submit_uri (GtkAction* action,
const gchar* uri,
gboolean new_tab,
MidoriBrowser* browser)
{
+ gchar* stripped_uri;
gchar* new_uri;
gint n;
- uri = katze_skip_whitespace (uri);
- new_uri = sokoke_magic_uri (uri);
+ stripped_uri = g_strdup (uri);
+ g_strstrip (stripped_uri);
+ new_uri = sokoke_magic_uri (stripped_uri);
if (!new_uri)
{
- const gchar* keywords = NULL;
+ gchar** parts;
+ gchar* keywords = NULL;
const gchar* search_uri = NULL;
- KatzeItem* item;
/* Do we have a keyword and a string? */
- if (browser->search_engines
- && (item = katze_array_find_token (browser->search_engines, uri)))
+ parts = g_strsplit (stripped_uri, " ", 2);
+ if (parts[0] && browser->search_engines)
{
- keywords = strchr (uri, ' ');
- if (keywords != NULL)
- keywords++;
- else
- keywords = "";
- search_uri = katze_item_get_uri (item);
+ KatzeItem* item;
+ if ((item = katze_array_find_token (browser->search_engines, parts[0])))
+ {
+ keywords = g_strdup (parts[1] ? parts[1] : "");
+ search_uri = katze_item_get_uri (item);
+ }
}
+ g_strfreev (parts);
- if (keywords == NULL)
+ if (keywords)
+ g_free (stripped_uri);
+ else
{
- keywords = uri;
+ keywords = stripped_uri;
search_uri = browser->location_entry_search;
}
new_uri = midori_uri_for_search (search_uri, keywords);
@@ -3907,7 +3753,11 @@ _action_location_submit_uri (GtkAction* action,
if (sqlite3_step (statement) == SQLITE_DONE)
sqlite3_clear_bindings (statement);
}
+
+ g_free (keywords);
}
+ else
+ g_free (stripped_uri);
if (new_tab)
{
@@ -4030,10 +3880,7 @@ _action_search_submit (GtkAction* action,
search = midori_uri_for_search (url, keywords);
if (new_tab)
- {
- int n = midori_browser_add_uri (browser, search);
- midori_browser_set_current_page_smartly (browser, n);
- }
+ midori_browser_add_uri (browser, search);
else
midori_browser_set_current_uri (browser, search);
@@ -4045,11 +3892,13 @@ _action_search_activate (GtkAction* action,
MidoriBrowser* browser)
{
GSList* proxies = gtk_action_get_proxies (action);
+ guint i = 0;
+ GtkWidget* proxy;
const gchar* uri;
gchar* search;
- for (; proxies != NULL; proxies = g_slist_next (proxies))
- if (GTK_IS_TOOL_ITEM (proxies->data))
+ while (((proxy = g_slist_nth_data (proxies, i++))))
+ if (GTK_IS_TOOL_ITEM (proxy))
{
if (!gtk_widget_get_visible (browser->navigationbar))
gtk_widget_show (browser->navigationbar);
@@ -4188,7 +4037,13 @@ midori_browser_bookmark_open_in_window_activate_cb (GtkWidget* menuitem,
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
uri = katze_item_get_uri (item);
- midori_view_new_window_cb (NULL, uri, browser);
+
+ if (uri && *uri)
+ {
+ MidoriBrowser* new_browser;
+ g_signal_emit (browser, signals[NEW_WINDOW], 0, NULL, &new_browser);
+ midori_browser_add_uri (new_browser, uri);
+ }
}
static void
@@ -4200,9 +4055,9 @@ midori_browser_bookmark_edit_activate_cb (GtkWidget* menuitem,
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
if (KATZE_ITEM_IS_BOOKMARK (item))
- midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE, NULL);
+ midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
else
- midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, TRUE, NULL);
+ midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, TRUE);
}
static void
@@ -4300,19 +4155,10 @@ static void
_action_bookmark_add_activate (GtkAction* action,
MidoriBrowser* browser)
{
- GtkWidget* proxy = NULL;
- GSList* proxies = gtk_action_get_proxies (action);
- for (; proxies != NULL; proxies = g_slist_next (proxies))
- if (GTK_IS_TOOL_ITEM (proxies->data))
- {
- proxy = proxies->data;
- break;
- }
-
if (g_str_equal (gtk_action_get_name (action), "BookmarkFolderAdd"))
- midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, TRUE, proxy);
+ midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, TRUE);
else
- midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE, proxy);
+ midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE);
}
static void
@@ -4332,7 +4178,6 @@ _action_bookmarks_import_activate (GtkAction* action,
{ ".kde/share/apps/konqueror/bookmarks.xml", N_("Konqueror"), "konqueror" },
{ ".gnome2/epiphany/bookmarks.rdf", N_("Epiphany"), "epiphany" },
{ ".mozilla/firefox/*/bookmarks.html", N_("Firefox (%s)"), "firefox" },
- { ".config/midori/bookmarks.xbel", N_("Midori 0.2.6"), "midori" },
};
GtkWidget* dialog;
@@ -4353,7 +4198,7 @@ _action_bookmarks_import_activate (GtkAction* action,
return;
dialog = gtk_dialog_new_with_buttons (
- _("Import bookmarksâ¦"), GTK_WINDOW (browser),
+ _("Import bookmarks..."), GTK_WINDOW (browser),
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
_("_Import bookmarks"), GTK_RESPONSE_ACCEPT,
@@ -4438,16 +4283,23 @@ _action_bookmarks_import_activate (GtkAction* action,
gtk_container_add (GTK_CONTAINER (content_area), hbox);
gtk_widget_show_all (hbox);
- combobox_folder = midori_bookmark_folder_button_new (browser->bookmarks,
- FALSE, 0, 0);
- gtk_container_add (GTK_CONTAINER (content_area), combobox_folder);
-
+ hbox = gtk_hbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
+ label = gtk_label_new_with_mnemonic (_("_Folder:"));
+ gtk_size_group_add_widget (sizegroup, label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ combobox_folder = midori_bookmark_folder_button_new (browser->bookmarks,
+ FALSE, NULL);
+ gtk_box_pack_start (GTK_BOX (hbox), combobox_folder, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ gtk_widget_show_all (hbox);
+
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
GtkTreeIter iter;
gchar* path = NULL;
- gint64 selected;
+ gchar* selected = NULL;
GError* error;
sqlite3* db = g_object_get_data (G_OBJECT (browser->bookmarks), "db");
@@ -4480,6 +4332,7 @@ _action_bookmarks_import_activate (GtkAction* action,
midori_bookmarks_import_array_db (db, bookmarks, selected);
katze_array_update (browser->bookmarks);
g_object_unref (bookmarks);
+ g_free (selected);
g_free (path);
}
else
@@ -4495,6 +4348,7 @@ _action_bookmarks_export_activate (GtkAction* action,
const gchar* format;
gchar* path = NULL;
GError* error;
+ sqlite3* db;
KatzeArray* bookmarks;
if (!browser->bookmarks || !gtk_widget_get_visible (GTK_WIDGET (browser)))
@@ -4535,8 +4389,9 @@ wrong_format:
return;
error = NULL;
- bookmarks = midori_array_query_recursive (browser->bookmarks,
- "*", "parentid IS NULL", NULL, TRUE);
+ db = g_object_get_data (G_OBJECT (browser->history), "db");
+ bookmarks = katze_array_new (KATZE_TYPE_ARRAY);
+ midori_bookmarks_export_array_db (db, bookmarks, "");
if (!midori_array_to_file (bookmarks, path, format, &error))
{
sokoke_message_dialog (GTK_MESSAGE_ERROR,
@@ -4667,8 +4522,6 @@ _action_clear_private_data_activate (GtkAction* action,
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
_("_Clear private data"), GTK_RESPONSE_ACCEPT, NULL);
- katze_widget_add_class (gtk_dialog_get_widget_for_response (
- GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT), "noundo");
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
screen = gtk_widget_get_screen (GTK_WIDGET (browser));
@@ -4754,19 +4607,13 @@ _action_tab_move_backward_activate (GtkAction* action,
MidoriBrowser* browser)
{
gint new_pos;
- gint cur_pos = midori_browser_get_current_page (browser);
- GtkWidget* widget = midori_browser_get_nth_tab (browser, cur_pos);
+ gint cur_pos = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+ GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), cur_pos);
if (cur_pos > 0)
new_pos = cur_pos - 1;
else
- new_pos = midori_browser_get_n_pages (browser) - 1;
- #ifdef HAVE_GRANITE
- granite_widgets_dynamic_notebook_set_tab_position (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook),
- midori_view_get_tab (MIDORI_VIEW (widget)), new_pos);
- #else
+ new_pos = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)) - 1;
gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, new_pos);
- #endif
g_signal_emit (browser, signals[MOVE_TAB], 0, browser->notebook, cur_pos, new_pos);
}
@@ -4775,19 +4622,13 @@ _action_tab_move_forward_activate (GtkAction* action,
MidoriBrowser* browser)
{
gint new_pos;
- gint cur_pos = midori_browser_get_current_page (browser);
- GtkWidget* widget = midori_browser_get_nth_tab (browser, cur_pos);
- if (cur_pos == (midori_browser_get_n_pages (browser) - 1))
+ gint cur_pos = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+ GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), cur_pos);
+ if (cur_pos == (gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)) - 1))
new_pos = 0;
else
new_pos = cur_pos + 1;
- #ifdef HAVE_GRANITE
- granite_widgets_dynamic_notebook_set_tab_position (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook),
- midori_view_get_tab (MIDORI_VIEW (widget)), new_pos);
- #else
gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, new_pos);
- #endif
g_signal_emit (browser, signals[MOVE_TAB], 0, browser->notebook, cur_pos, new_pos);
}
@@ -4795,8 +4636,8 @@ static void
_action_tab_previous_activate (GtkAction* action,
MidoriBrowser* browser)
{
- gint n = midori_browser_get_current_page (browser);
- midori_browser_set_current_page (browser, n - 1);
+ gint n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n - 1);
}
static void
@@ -4804,10 +4645,10 @@ _action_tab_next_activate (GtkAction* action,
MidoriBrowser* browser)
{
/* Advance one tab or jump to the first one if we are at the last one */
- gint n = midori_browser_get_current_page (browser);
- if (n == midori_browser_get_n_pages (browser) - 1)
+ gint n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+ if (n == gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)) - 1)
n = -1;
- midori_browser_set_current_page (browser, n + 1);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n + 1);
}
static void
@@ -4900,33 +4741,6 @@ _action_about_activate_email (GtkAboutDialog* about,
}
#endif
-static gchar*
-midori_browser_get_docs (gboolean error)
-{
- #ifdef G_OS_WIN32
- gchar* path = midori_paths_get_data_filename ("doc/midori/faq.html", FALSE);
- if (g_access (path, F_OK) == 0)
- return g_filename_to_uri (path, NULL, NULL);
- else
- {
- #ifdef DOCDIR
- if (g_access (DOCDIR "/faq.html", F_OK) == 0)
- return g_strdup ("file://" DOCDIR "/faq.html");
- else
- #endif
- return error ? g_strdup ("error:nodocs share/doc/midori/faq.html") : NULL;
- }
- g_free (path);
- #else
- #ifdef DOCDIR
- if (g_access (DOCDIR "/faq.html", F_OK) == 0)
- return g_strdup ("file://" DOCDIR "/faq.html");
- else
- #endif
- return error ? g_strdup ("error:nodocs " DOCDIR "/faq.html") : NULL;
- #endif
-}
-
static void
_action_about_activate (GtkAction* action,
MidoriBrowser* browser)
@@ -4944,54 +4758,75 @@ _action_about_activate (GtkAction* action,
gtk_about_dialog_set_email_hook (_action_about_activate_email, NULL, NULL);
gtk_about_dialog_set_url_hook (_action_about_activate_link, browser, NULL);
#endif
-#ifdef HAVE_GRANITE
- gchar* docs = midori_browser_get_docs (FALSE);
- granite_widgets_show_about_dialog (GTK_WINDOW (browser),
- "translate", "https://translations.xfce.org/projects/p/midori/",
- "bug", PACKAGE_BUGREPORT,
- "help", docs,
- "copyright", "2007-2012 Christian Dywan",
-#else
gtk_show_about_dialog (GTK_WINDOW (browser),
- "wrap-license", TRUE,
- "copyright", "Copyright © 2007-2012 Christian Dywan",
-#endif
"logo-icon-name", gtk_window_get_icon_name (GTK_WINDOW (browser)),
- "program-name", PACKAGE_NAME,
+ "name", PACKAGE_NAME,
"version", PACKAGE_VERSION,
"comments", comments,
- "website", "http://www.midori-browser.org",
+ "copyright", "Copyright © 2007-2011 Christian Dywan",
+ "website", "http://www.twotoasts.de",
"authors", credits_authors,
"documenters", credits_documenters,
"artists", credits_artists,
"license", license,
+ "wrap-license", TRUE,
"translator-credits", _("translator-credits"),
NULL);
g_free (comments);
- #ifdef HAVE_GRANITE
- g_free (docs);
- #endif
}
static void
_action_help_link_activate (GtkAction* action,
MidoriBrowser* browser)
{
- const gchar* action_name = gtk_action_get_name (action);
- gchar* uri = NULL;
- if (!strncmp ("HelpFAQ", action_name, 7))
- uri = midori_browser_get_docs (TRUE);
- else if (!strncmp ("HelpBugs", action_name, 8))
+ const gchar* action_name;
+ const gchar* uri;
+ gint n;
+ #if defined (G_OS_WIN32) && defined (DOCDIR)
+ gchar* free_uri = NULL;
+ #endif
+
+ action_name = gtk_action_get_name (action);
+ if (!strncmp ("HelpFAQ", action_name, 7))
{
- if (!g_spawn_command_line_async ("ubuntu-bug " PACKAGE_NAME, NULL))
- uri = g_strdup (PACKAGE_BUGREPORT);
+ #ifdef G_OS_WIN32
+ {
+ #ifdef DOCDIR
+ gchar* path = sokoke_find_data_filename ("doc/midori/faq.html", FALSE);
+ uri = free_uri = g_filename_to_uri (path, NULL, NULL);
+ if (g_access (path, F_OK) != 0)
+ {
+ if (g_access (DOCDIR "/faq.html", F_OK) == 0)
+ uri = "file://" DOCDIR "/faq.html";
+ else
+ #endif
+ uri = "error:nodocs share/doc/midori/faq.html";
+ #ifdef DOCDIR
+ }
+ g_free (path);
+ #endif
+ }
+ #else
+ #ifdef DOCDIR
+ uri = "file://" DOCDIR "/faq.html";
+ if (g_access (DOCDIR "/faq.html", F_OK) != 0)
+ #endif
+ uri = "error:nodocs " DOCDIR "/faq.html";
+ #endif
}
+ else if (!strncmp ("HelpBugs", action_name, 8))
+ uri = PACKAGE_BUGREPORT;
+ else
+ uri = NULL;
if (uri)
{
- gint n = midori_browser_add_uri (browser, uri);
+ n = midori_browser_add_uri (browser, uri);
midori_browser_set_current_page (browser, n);
- g_free (uri);
+
+ #if defined (G_OS_WIN32) && defined (DOCDIR)
+ g_free (free_uri);
+ #endif
}
}
@@ -5038,7 +4873,7 @@ midori_panel_cycle_child_focus_cb (GtkWidget* hpaned,
|| !gtk_widget_get_ancestor (focus, GTK_TYPE_PANED))
{
g_signal_stop_emission_by_name (hpaned, "cycle-child-focus");
- midori_browser_activate_action (browser, "Location");
+ gtk_action_activate (_action_by_name (browser, "Location"));
return TRUE;
}
return FALSE;
@@ -5112,52 +4947,60 @@ midori_panel_close_cb (MidoriPanel* panel,
}
static void
-midori_browser_switched_tab (MidoriBrowser* browser,
- GtkWidget* old_widget,
- MidoriView* new_view,
- gint new_page)
+gtk_notebook_switch_page_cb (GtkWidget* notebook,
+ gpointer page,
+ guint page_num,
+ MidoriBrowser* browser)
{
+ GtkWidget* widget;
GtkAction* action;
const gchar* text;
- const gchar* uri;
-
- if (old_widget != NULL)
- {
- action = _action_by_name (browser, "Location");
- text = midori_location_action_get_text (MIDORI_LOCATION_ACTION (action));
- g_object_set_data_full (G_OBJECT (old_widget), "midori-browser-typed-text",
- g_strdup (text), g_free);
- }
- if (new_view == NULL)
- {
- g_signal_emit (browser, signals[SWITCH_TAB], 0, old_widget, new_view);
+ if (!(widget = midori_browser_get_current_tab (browser)))
return;
- }
- g_return_if_fail (MIDORI_IS_VIEW (new_view));
+ action = _action_by_name (browser, "Location");
+ text = midori_location_action_get_text (MIDORI_LOCATION_ACTION (action));
+ g_object_set_data_full (G_OBJECT (widget), "midori-browser-typed-text",
+ g_strdup (text), g_free);
+}
+
+static void
+gtk_notebook_switch_page_after_cb (GtkWidget* notebook,
+ gpointer page,
+ guint page_num,
+ MidoriBrowser* browser)
+{
+ GtkWidget* widget;
+ MidoriView* view;
+ const gchar* uri;
+ GtkAction* action;
+
+ if (!(widget = midori_browser_get_current_tab (browser)))
+ return;
- uri = g_object_get_data (G_OBJECT (new_view), "midori-browser-typed-text");
+ view = MIDORI_VIEW (widget);
+ uri = g_object_get_data (G_OBJECT (widget), "midori-browser-typed-text");
if (!uri)
- uri = midori_view_get_display_uri (new_view);
- midori_browser_set_title (browser, midori_view_get_display_title (new_view));
+ uri = midori_view_get_display_uri (view);
+ midori_browser_set_title (browser, midori_view_get_display_title (view));
action = _action_by_name (browser, "Location");
midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri);
- if (midori_paths_is_readonly () /* APP, PRIVATE */)
- gtk_window_set_icon (GTK_WINDOW (browser), midori_view_get_icon (new_view));
+ midori_location_action_set_icon (MIDORI_LOCATION_ACTION (action),
+ midori_view_get_icon (view));
if (browser->proxy_array)
- katze_item_set_meta_integer (KATZE_ITEM (browser->proxy_array), "current", new_page);
+ katze_item_set_meta_integer (KATZE_ITEM (browser->proxy_array), "current",
+ midori_browser_get_current_page (browser));
g_object_notify (G_OBJECT (browser), "tab");
- g_signal_emit (browser, signals[SWITCH_TAB], 0, old_widget, new_view);
- _midori_browser_set_statusbar_text (browser, new_view, NULL);
- _midori_browser_update_interface (browser, new_view);
- _midori_browser_update_progress (browser, new_view);
+ _midori_browser_set_statusbar_text (browser, NULL);
+ _midori_browser_update_interface (browser);
+ _midori_browser_update_progress (browser, view);
}
static void
-midori_browser_notebook_page_reordered_cb (GtkWidget* notebook,
+midori_browser_notebook_page_reordered_cb (GtkNotebook* notebook,
MidoriView* view,
guint page_num,
MidoriBrowser* browser)
@@ -5167,9 +5010,19 @@ midori_browser_notebook_page_reordered_cb (GtkWidget* notebook,
g_object_notify (G_OBJECT (browser), "tab");
}
+static gboolean
+midori_browser_notebook_reorder_tab_cb (GtkNotebook* notebook,
+ GtkDirectionType arg1,
+ gboolean arg2,
+ gpointer user_data)
+{
+ g_signal_stop_emission_by_name (notebook, "reorder-tab");
+ return TRUE;
+}
+
static GtkWidget*
-midori_browser_notebook_create_window_cb (GtkWidget* notebook,
- GtkWidget* view,
+midori_browser_notebook_create_window_cb (GtkNotebook* notebook,
+ MidoriView* view,
gint x,
gint y,
MidoriBrowser* browser)
@@ -5178,119 +5031,18 @@ midori_browser_notebook_create_window_cb (GtkWidget* notebook,
g_signal_emit (browser, signals[NEW_WINDOW], 0, NULL, &new_browser);
if (new_browser)
{
- GtkWidget* new_notebook = new_browser->notebook;
- gtk_window_move (GTK_WINDOW (new_browser), x, y);
+ GtkWidget* new_notebook = katze_object_get_object (new_browser, "notebook");
+ g_object_unref (new_notebook);
+ gtk_window_move (GTK_WINDOW (browser), x, y);
return new_notebook;
}
else /* No MidoriApp, so this is app or private mode */
return NULL;
}
-#ifdef HAVE_GRANITE
-static void
-midori_browser_notebook_tab_added_cb (GtkWidget* notebook,
- GraniteWidgetsTab* tab,
- MidoriBrowser* browser)
-{
- GtkWidget* view = midori_view_new_with_item (NULL, browser->settings);
- midori_view_set_tab (MIDORI_VIEW (view), tab);
- midori_browser_connect_tab (browser, view);
- /* FIXME: signal add-tab */
- _midori_browser_update_actions (browser);
- midori_view_set_uri (MIDORI_VIEW (view), "");
-}
-
-static gboolean
-midori_browser_notebook_tab_removed_cb (GtkWidget* notebook,
- GraniteWidgetsTab* tab,
- MidoriBrowser* browser)
-{
- MidoriView* view = MIDORI_VIEW (granite_widgets_tab_get_page (tab));
- g_signal_emit (browser, signals[REMOVE_TAB], 0, view);
- gtk_widget_destroy (view);
- return TRUE;
-}
-
-static void
-midori_browser_notebook_tab_switched_cb (GraniteWidgetsDynamicNotebook* notebook,
- GraniteWidgetsTab* old_tab,
- GraniteWidgetsTab* new_tab,
- MidoriBrowser* browser)
-{
- gint new_pos = granite_widgets_dynamic_notebook_get_tab_position (notebook, new_tab);
-
- midori_browser_switched_tab (browser,
- old_tab ? granite_widgets_tab_get_page (old_tab) : NULL,
- MIDORI_VIEW (granite_widgets_tab_get_page (new_tab)), new_pos);
-}
-
-static void
-midori_browser_notebook_tab_moved_cb (GtkWidget* notebook,
- GraniteWidgetsTab* tab,
- gint old_pos,
- gboolean new_window,
- gint x,
- gint y,
- MidoriBrowser* browser)
-{
- GtkWidget* view = granite_widgets_tab_get_page (tab);
- if (new_window)
- {
- GtkWidget* notebook = midori_browser_notebook_create_window_cb (
- browser->notebook, view, x, y, browser);
- if (notebook != NULL)
- {
- g_object_ref (tab);
- granite_widgets_dynamic_notebook_remove_tab (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), tab);
- granite_widgets_dynamic_notebook_insert_tab (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (notebook), tab, 0);
- g_object_unref (tab);
- }
- }
- else
- {
- gint new_pos = granite_widgets_dynamic_notebook_get_tab_position (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (notebook), tab);
- midori_browser_notebook_page_reordered_cb (notebook,
- MIDORI_VIEW (view), new_pos, browser);
- }
-}
-#else
-static void
-midori_browser_notebook_switch_page_cb (GtkWidget* notebook,
- gpointer page,
- guint page_num,
- MidoriBrowser* browser)
-{
- midori_browser_switched_tab (browser,
- midori_browser_get_current_tab (browser),
- MIDORI_VIEW (midori_browser_get_nth_tab (browser, page_num)), page_num);
-}
-
-static void
-midori_browser_notebook_page_removed_cb (GtkWidget* notebook,
- GtkWidget* view,
- guint page_num,
- MidoriBrowser* browser)
-{
- _midori_browser_remove_tab (browser, view);
- midori_browser_notebook_size_allocate_cb (browser->notebook, NULL, browser);
-}
-
-static gboolean
-midori_browser_notebook_reorder_tab_cb (GtkNotebook* notebook,
- GtkDirectionType arg1,
- gboolean arg2,
- gpointer user_data)
-{
- g_signal_stop_emission_by_name (notebook, "reorder-tab");
- return TRUE;
-}
-
static void
-midori_browser_menu_item_switch_tab_cb (GtkWidget* menuitem,
- MidoriBrowser* browser)
+midori_browser_switch_tab_cb (GtkWidget* menuitem,
+ MidoriBrowser* browser)
{
gint page = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), "index"));
midori_browser_set_current_page (browser, page);
@@ -5339,7 +5091,7 @@ midori_browser_notebook_button_press_event_after_cb (GtkNotebook* notebook,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_object_set_data (G_OBJECT (menuitem), "index", GINT_TO_POINTER (i));
g_signal_connect (menuitem, "activate",
- G_CALLBACK (midori_browser_menu_item_switch_tab_cb), browser);
+ G_CALLBACK (midori_browser_switch_tab_cb), browser);
i++;
}
g_list_free (tabs);
@@ -5350,7 +5102,6 @@ midori_browser_notebook_button_press_event_after_cb (GtkNotebook* notebook,
return FALSE;
}
-#endif
static void
_action_undo_tab_close_activate (GtkAction* action,
@@ -5396,16 +5147,16 @@ static const GtkActionEntry entries[] =
NULL, "o",
N_("Open a file"), G_CALLBACK (_action_open_activate) },
{ "SaveAs", GTK_STOCK_SAVE_AS,
- N_("_Save Page Asâ¦"), "s",
+ N_("_Save Page As..."), "s",
N_("Save to a file"), G_CALLBACK (_action_save_as_activate) },
{ "AddSpeedDial", NULL,
N_("Add to Speed _dial"), "h",
NULL, G_CALLBACK (_action_add_speed_dial_activate) },
{ "AddDesktopShortcut", NULL,
#if HAVE_HILDON
- N_("Add Shortcut to the _desktop"), "",
+ N_("Add Shortcut to the _desktop"), "j",
#else
- N_("Create _Launcher"), "",
+ N_("Create _Launcher"), "j",
#endif
NULL, G_CALLBACK (_action_add_desktop_shortcut_activate) },
{ "AddNewsFeed", NULL,
@@ -5420,15 +5171,9 @@ static const GtkActionEntry entries[] =
{ "WindowClose", NULL,
N_("C_lose Window"), "w",
NULL, G_CALLBACK (_action_window_close_activate) },
- #ifdef HAVE_GRANITE
- { "Print", "document-export",
- N_("_Share"), "p",
- NULL, G_CALLBACK (_action_print_activate) },
- #else
{ "Print", GTK_STOCK_PRINT,
NULL, "p",
N_("Print the current page"), G_CALLBACK (_action_print_activate) },
- #endif
{ "Quit", GTK_STOCK_QUIT,
N_("Close a_ll Windows"), "q",
NULL, G_CALLBACK (_action_quit_activate) },
@@ -5456,7 +5201,7 @@ static const GtkActionEntry entries[] =
NULL, "a",
NULL, G_CALLBACK (_action_select_all_activate) },
{ "Find", GTK_STOCK_FIND,
- N_("_Findâ¦"), "f",
+ N_("_Find..."), "f",
N_("Find a word or phrase in the page"), G_CALLBACK (_action_find_activate) },
{ "FindNext", GTK_STOCK_GO_FORWARD,
N_("Find _Next"), "g",
@@ -5480,7 +5225,7 @@ static const GtkActionEntry entries[] =
NULL, "Escape",
N_("Stop loading the current page"), G_CALLBACK (_action_reload_stop_activate) },
{ "ReloadStop", GTK_STOCK_STOP,
- NULL, "",
+ NULL, "r",
N_("Reload the current page"), G_CALLBACK (_action_reload_stop_activate) },
{ "ZoomIn", GTK_STOCK_ZOOM_IN,
NULL, "plus",
@@ -5513,9 +5258,6 @@ static const GtkActionEntry entries[] =
{ "ScrollRight", NULL,
N_("Scroll _Right"), "l",
NULL, G_CALLBACK (_action_scroll_somewhere_activate) },
- { "Readable", NULL,
- N_("_Readable"), "R",
- NULL, G_CALLBACK (_action_readable_activate) },
{ "Go", NULL, N_("_Go") },
{ "Back", GTK_STOCK_GO_BACK,
@@ -5532,11 +5274,8 @@ static const GtkActionEntry entries[] =
NULL, "Right",
/* i18n: Visit the following logical page, ie. in a forum or blog */
N_("Go to the next sub-page"), G_CALLBACK (_action_navigation_activate) },
- { "NextForward", GTK_STOCK_MEDIA_NEXT,
- NULL, "",
- N_("Go to the next sub-page"), G_CALLBACK (_action_navigation_activate) },
- { "Homepage", GTK_STOCK_HOME,
- N_("_Homepage"), "Home",
+ { "Homepage", STOCK_HOMEPAGE,
+ NULL, "Home",
N_("Go to your homepage"), G_CALLBACK (_action_navigation_activate) },
{ "TrashEmpty", GTK_STOCK_CLEAR,
N_("Empty Trash"), "",
@@ -5578,7 +5317,7 @@ static const GtkActionEntry entries[] =
{ "TabMoveForward", NULL, N_("_Move Tab Forward"), "Page_Down",
NULL, G_CALLBACK (_action_tab_move_forward_activate) },
{ "TabCurrent", NULL,
- N_("Focus _Current Tab"), "Home",
+ N_("Focus _Current Tab"), "Home",
NULL, G_CALLBACK (_action_tab_current_activate) },
{ "NextView", NULL,
N_("Focus _Next view"), "F6",
@@ -5601,12 +5340,12 @@ static const GtkActionEntry entries[] =
N_("_Frequent Questions"), "F1",
NULL, G_CALLBACK (_action_help_link_activate) },
{ "HelpBugs", NULL,
- N_("_Report a Problemâ¦"), NULL,
+ N_("_Report a Problem..."), NULL,
NULL, G_CALLBACK (_action_help_link_activate) },
{ "About", GTK_STOCK_ABOUT,
NULL, "",
NULL, G_CALLBACK (_action_about_activate) },
- { "Dummy", NULL, N_("_Tools") },
+ { "Dummy", NULL, "Dummy" },
};
static const guint entries_n = G_N_ELEMENTS (entries);
@@ -5629,7 +5368,7 @@ static const GtkToggleActionEntry toggle_entries[] =
NULL, G_CALLBACK (_action_bookmarkbar_activate),
FALSE },
{ "Statusbar", NULL,
- N_("_Statusbar"), "j",
+ N_("_Statusbar"), "",
NULL, G_CALLBACK (_action_statusbar_activate),
FALSE },
};
@@ -5641,10 +5380,7 @@ static const GtkRadioActionEntry encoding_entries[] =
N_("_Automatic"), "",
NULL, 1 },
{ "EncodingChinese", NULL,
- N_("Chinese Traditional (BIG5)"), "",
- NULL, 1 },
- { "EncodingChineseSimplified", NULL,
- N_("Chinese Simplified (GB18030)"), "",
+ N_("Chinese (BIG5)"), "",
NULL, 1 },
{ "EncodingJapanese", NULL,
/* i18n: A double underscore "__" is used to prevent the mnemonic */
@@ -5663,7 +5399,7 @@ static const GtkRadioActionEntry encoding_entries[] =
N_("Western (ISO-8859-1)"), "",
NULL, 1 },
{ "EncodingCustom", NULL,
- N_("Customâ¦"), "",
+ N_("Custom..."), "",
NULL, 1 },
};
static const guint encoding_entries_n = G_N_ELEMENTS (encoding_entries);
@@ -5680,6 +5416,19 @@ midori_browser_window_state_event_cb (MidoriBrowser* browser,
else if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)
window_state = MIDORI_WINDOW_FULLSCREEN;
g_object_set (browser->settings, "last-window-state", window_state, NULL);
+
+ if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
+ {
+ if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)
+ {
+ gtk_widget_hide (browser->menubar);
+ }
+ else
+ {
+ if (katze_object_get_boolean (browser->settings, "show-menubar"))
+ gtk_widget_show (browser->menubar);
+ }
+ }
}
static gboolean
@@ -5745,15 +5494,13 @@ midori_browser_destroy_cb (MidoriBrowser* browser)
/* Destroy panel first, so panels don't need special care */
gtk_widget_destroy (browser->panel);
- #ifndef HAVE_GRANITE
+ /* Destroy tabs second, so child widgets don't need special care */
g_signal_handlers_disconnect_by_func (browser->notebook,
midori_browser_notebook_reorder_tab_cb,
NULL);
g_signal_handlers_disconnect_by_func (browser->notebook,
midori_browser_notebook_size_allocate_cb,
browser);
- #endif
- /* Destroy tabs second, so child widgets don't need special care */
gtk_container_foreach (GTK_CONTAINER (browser->notebook),
(GtkCallback) gtk_widget_destroy, NULL);
}
@@ -5818,7 +5565,6 @@ static const gchar* ui_markup =
""
" "
" "
- " "
" "
" "
" "
@@ -5828,7 +5574,6 @@ static const gchar* ui_markup =
" "
" "
" "
- " "
""
""
" "
@@ -5851,7 +5596,6 @@ static const gchar* ui_markup =
" "
/* For accelerators to work all actions need to be used
*somewhere* in the UI definition */
- /* These also show up in Unity's HUD */
""
" "
" "
@@ -5907,7 +5651,7 @@ midori_browser_realize_cb (GtkStyle* style,
if (gtk_icon_theme_has_icon (icon_theme, "midori"))
gtk_window_set_icon_name (GTK_WINDOW (browser), "midori");
else
- gtk_window_set_icon_name (GTK_WINDOW (browser), STOCK_WEB_BROWSER);
+ gtk_window_set_icon_name (GTK_WINDOW (browser), "web-browser");
}
}
@@ -5986,7 +5730,8 @@ midori_browser_accel_switch_tab_activate_cb (GtkAccelGroup* accel_group,
/* Switch to n-th tab. 9 and 0 go to the last tab. */
n = keyval - GDK_KEY_0;
browser = g_object_get_data (G_OBJECT (accel_group), "midori-browser");
- if ((view = midori_browser_get_nth_tab (browser, n < 9 ? n - 1 : -1)))
+ if ((view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook),
+ n < 9 ? n - 1 : -1)))
midori_browser_set_current_tab (browser, view);
}
}
@@ -6112,15 +5857,15 @@ midori_browser_init (MidoriBrowser* browser)
GtkSettings* gtk_settings;
GtkWidget* hpaned;
GtkWidget* vpaned;
+ GtkRcStyle* rcstyle;
GtkWidget* scrolled;
- KatzeArray* dummy_array;
browser->settings = midori_web_settings_new ();
browser->proxy_array = katze_array_new (KATZE_TYPE_ARRAY);
browser->bookmarks = NULL;
browser->trash = NULL;
browser->search_engines = NULL;
- browser->dial = NULL;
+ browser->speeddial = NULL;
/* Setup the window metrics */
g_signal_connect (browser, "realize",
@@ -6132,10 +5877,7 @@ midori_browser_init (MidoriBrowser* browser)
g_signal_connect (browser, "destroy",
G_CALLBACK (midori_browser_destroy_cb), NULL);
gtk_window_set_role (GTK_WINDOW (browser), "browser");
- gtk_window_set_icon_name (GTK_WINDOW (browser), STOCK_WEB_BROWSER);
- #if GTK_CHECK_VERSION (3, 4, 0)
- gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (browser), TRUE);
- #endif
+ gtk_window_set_icon_name (GTK_WINDOW (browser), "web-browser");
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (browser), vbox);
gtk_widget_show (vbox);
@@ -6169,7 +5911,7 @@ midori_browser_init (MidoriBrowser* browser)
}
/* Hide the 'Dummy' which only holds otherwise unused actions */
- _action_set_visible (browser, "Dummy", FALSE);
+ g_object_set (_action_by_name (browser, "Dummy"), "visible", FALSE, NULL);
action = g_object_new (KATZE_TYPE_SEPARATOR_ACTION,
"name", "Separator",
@@ -6180,7 +5922,7 @@ midori_browser_init (MidoriBrowser* browser)
action = g_object_new (MIDORI_TYPE_LOCATION_ACTION,
"name", "Location",
- "label", _("_Locationâ¦"),
+ "label", _("_Location..."),
"stock-id", GTK_STOCK_JUMP_TO,
"tooltip", _("Open a particular location"),
NULL);
@@ -6204,7 +5946,7 @@ midori_browser_init (MidoriBrowser* browser)
action = g_object_new (MIDORI_TYPE_SEARCH_ACTION,
"name", "Search",
- "label", _("_Web Searchâ¦"),
+ "label", _("_Web Search..."),
"stock-id", GTK_STOCK_FIND,
"tooltip", _("Run a web search"),
NULL);
@@ -6244,14 +5986,12 @@ midori_browser_init (MidoriBrowser* browser)
gtk_action_group_add_action_with_accel (browser->action_group, action, "");
g_object_unref (action);
- dummy_array = katze_array_new (KATZE_TYPE_ARRAY);
- katze_array_update (dummy_array);
action = g_object_new (KATZE_TYPE_ARRAY_ACTION,
"name", "Bookmarks",
"label", _("_Bookmarks"),
"stock-id", STOCK_BOOKMARKS,
"tooltip", _("Show the saved bookmarks"),
- "array", dummy_array /* updated, unique */,
+ "array", browser->proxy_array, /* Use a non-empty array here */
NULL);
g_object_connect (action,
"signal::populate-folder",
@@ -6261,15 +6001,12 @@ midori_browser_init (MidoriBrowser* browser)
NULL);
gtk_action_group_add_action_with_accel (browser->action_group, action, "");
g_object_unref (action);
- g_object_unref (dummy_array);
- dummy_array = katze_array_new (KATZE_TYPE_ITEM);
- katze_array_update (dummy_array);
action = g_object_new (KATZE_TYPE_ARRAY_ACTION,
"name", "Tools",
"label", _("_Tools"),
"stock-id", GTK_STOCK_PREFERENCES,
- "array", dummy_array /* updated, unique */,
+ "array", katze_array_new (KATZE_TYPE_ITEM),
NULL);
g_object_connect (action,
"signal::populate-popup",
@@ -6279,7 +6016,6 @@ midori_browser_init (MidoriBrowser* browser)
NULL);
gtk_action_group_add_action (browser->action_group, action);
g_object_unref (action);
- g_object_unref (dummy_array);
action = g_object_new (KATZE_TYPE_ARRAY_ACTION,
"name", "Window",
@@ -6315,7 +6051,6 @@ midori_browser_init (MidoriBrowser* browser)
browser->menubar = gtk_ui_manager_get_widget (ui_manager, "/menubar");
gtk_box_pack_start (GTK_BOX (vbox), browser->menubar, FALSE, FALSE, 0);
gtk_widget_hide (browser->menubar);
- _action_set_visible (browser, "Menubar", !midori_browser_has_native_menubar ());
#if HAVE_HILDON
#if HILDON_CHECK_VERSION (2, 2, 0)
browser->menubar = hildon_app_menu_new ();
@@ -6347,6 +6082,7 @@ midori_browser_init (MidoriBrowser* browser)
#endif
gtk_menu_shell_append (GTK_MENU_SHELL (browser->menubar), menuitem);
#endif
+ browser->menu_tools = gtk_menu_new ();
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (
gtk_ui_manager_get_widget (ui_manager, "/menubar/File/WindowNew")), NULL);
@@ -6369,6 +6105,9 @@ midori_browser_init (MidoriBrowser* browser)
g_signal_connect (forward, "button-press-event",
G_CALLBACK (midori_browser_menu_item_middle_click_event_cb), browser);
+ #if HAVE_HILDON
+ _action_set_visible (browser, "Menubar", FALSE);
+ #endif
_action_set_sensitive (browser, "EncodingCustom", FALSE);
_action_set_visible (browser, "LastSession", FALSE);
#if !HAVE_HILDON && !defined (GDK_WINDOWING_X11)
@@ -6386,7 +6125,9 @@ midori_browser_init (MidoriBrowser* browser)
/* Create the navigationbar */
browser->navigationbar = gtk_ui_manager_get_widget (
ui_manager, "/toolbar_navigation");
- katze_widget_add_class (browser->navigationbar, "primary-toolbar");
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_style_context_add_class(gtk_widget_get_style_context(browser->navigationbar), "primary-toolbar");
+#endif
/* FIXME: Settings should be connected with screen changes */
gtk_settings = gtk_widget_get_settings (GTK_WIDGET (browser));
if (gtk_settings)
@@ -6418,7 +6159,10 @@ midori_browser_init (MidoriBrowser* browser)
/* Bookmarkbar */
browser->bookmarkbar = gtk_toolbar_new ();
- katze_widget_add_class (browser->bookmarkbar, "secondary-toolbar");
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_style_context_add_class (
+ gtk_widget_get_style_context (browser->bookmarkbar), "secondary-toolbar");
+#endif
gtk_widget_set_name (browser->bookmarkbar, "MidoriBookmarkbar");
gtk_toolbar_set_icon_size (GTK_TOOLBAR (browser->bookmarkbar),
GTK_ICON_SIZE_MENU);
@@ -6462,51 +6206,23 @@ midori_browser_init (MidoriBrowser* browser)
vpaned = gtk_vpaned_new ();
gtk_paned_pack2 (GTK_PANED (hpaned), vpaned, TRUE, FALSE);
gtk_widget_show (vpaned);
- #ifdef HAVE_GRANITE
- /* FIXME: granite: should return GtkWidget* like GTK+ */
- browser->notebook = (GtkWidget*)granite_widgets_dynamic_notebook_new ();
- granite_widgets_dynamic_notebook_set_allow_new_window (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), TRUE);
- /* FIXME: work-around a bug */
- gtk_widget_show_all (browser->notebook);
- #else
browser->notebook = gtk_notebook_new ();
- gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE);
- #endif
- #if !GTK_CHECK_VERSION (3, 0, 0)
- {
/* Remove the inner border between scrollbars and the window border */
- GtkRcStyle* rcstyle = gtk_rc_style_new ();
+ rcstyle = gtk_rc_style_new ();
rcstyle->xthickness = 0;
gtk_widget_modify_style (browser->notebook, rcstyle);
g_object_unref (rcstyle);
- }
- #endif
+ gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE);
gtk_paned_pack1 (GTK_PANED (vpaned), browser->notebook, FALSE, FALSE);
- #ifdef HAVE_GRANITE
- /* FIXME menu items */
- g_signal_connect (browser->notebook, "tab-added",
- G_CALLBACK (midori_browser_notebook_tab_added_cb),
- browser);
- g_signal_connect (browser->notebook, "tab-removed",
- G_CALLBACK (midori_browser_notebook_tab_removed_cb),
- browser);
- g_signal_connect (browser->notebook, "tab-switched",
- G_CALLBACK (midori_browser_notebook_tab_switched_cb),
- browser);
- g_signal_connect (browser->notebook, "tab-moved",
- G_CALLBACK (midori_browser_notebook_tab_moved_cb),
- browser);
- #else
g_signal_connect (browser->notebook, "switch-page",
- G_CALLBACK (midori_browser_notebook_switch_page_cb),
+ G_CALLBACK (gtk_notebook_switch_page_cb),
browser);
+ g_signal_connect_after (browser->notebook, "switch-page",
+ G_CALLBACK (gtk_notebook_switch_page_after_cb),
+ browser);
g_signal_connect (browser->notebook, "page-reordered",
G_CALLBACK (midori_browser_notebook_page_reordered_cb),
browser);
- g_signal_connect (browser->notebook, "page-removed",
- G_CALLBACK (midori_browser_notebook_page_removed_cb),
- browser);
g_signal_connect (browser->notebook, "size-allocate",
G_CALLBACK (midori_browser_notebook_size_allocate_cb),
browser);
@@ -6517,7 +6233,6 @@ midori_browser_init (MidoriBrowser* browser)
G_CALLBACK (midori_browser_notebook_reorder_tab_cb), NULL);
g_signal_connect (browser->notebook, "create-window",
G_CALLBACK (midori_browser_notebook_create_window_cb), browser);
- #endif
gtk_widget_show (browser->notebook);
/* Inspector container */
@@ -6570,12 +6285,7 @@ midori_browser_init (MidoriBrowser* browser)
gtk_box_pack_start (GTK_BOX (vbox), browser->statusbar, FALSE, FALSE, 0);
browser->transferbar = g_object_new (MIDORI_TYPE_TRANSFERBAR, NULL);
- #if GTK_CHECK_VERSION (3, 0, 0)
- /* FIXME: Transfers should go between text and statusbar features like GTK+2 */
- gtk_box_pack_end (GTK_BOX (browser->statusbar_contents), browser->transferbar, FALSE, FALSE, 3);
- #else
gtk_box_pack_start (GTK_BOX (browser->statusbar_contents), browser->transferbar, FALSE, FALSE, 3);
- #endif
gtk_toolbar_set_show_arrow (GTK_TOOLBAR (browser->transferbar), FALSE);
gtk_widget_show (browser->transferbar);
@@ -6611,7 +6321,7 @@ midori_browser_finalize (GObject* object)
katze_object_assign (browser->trash, NULL);
katze_object_assign (browser->search_engines, NULL);
katze_object_assign (browser->history, NULL);
- browser->dial = NULL;
+ browser->speeddial = NULL;
katze_assign (browser->news_aggregator, NULL);
@@ -6655,97 +6365,6 @@ _midori_browser_set_toolbar_style (MidoriBrowser* browser,
gtk_toolbar_style);
}
-static void
-midori_browser_toolbar_popup_context_menu_history_cb (GtkMenuItem* menu_item,
- MidoriBrowser* browser)
-{
- gint steps = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "steps"));
- MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
- midori_view_go_back_or_forward (view, steps);
-}
-
-static void
-midori_browser_toolbar_popup_context_menu_history (MidoriBrowser* browser,
- GtkWidget* widget,
- gboolean back,
- gint x,
- gint y)
-{
- const gint step = back ? -1 : 1;
- gint steps = step;
- GtkWidget* menu;
- GtkWidget* menu_item;
- WebKitWebBackForwardList* list;
- WebKitWebHistoryItem* current_item;
- WebKitWebHistoryItem* history_item;
- WebKitWebHistoryItem* (*history_next)(WebKitWebBackForwardList*);
- void (*history_action)(WebKitWebBackForwardList*);
-
- list = webkit_web_view_get_back_forward_list (
- WEBKIT_WEB_VIEW (midori_view_get_web_view (
- MIDORI_VIEW (midori_browser_get_current_tab (browser)))));
-
- if (!list)
- return;
-
- menu = gtk_menu_new ();
-
- history_action = back ?
- webkit_web_back_forward_list_go_back :
- webkit_web_back_forward_list_go_forward;
- history_next = back ?
- webkit_web_back_forward_list_get_back_item :
- webkit_web_back_forward_list_get_forward_item;
- current_item = webkit_web_back_forward_list_get_current_item (list);
-
- for (; (history_item = history_next (list)); history_action (list), steps += step)
- {
- #if WEBKIT_CHECK_VERSION (1, 3, 13)
- gchar* icon_uri;
- gchar* icon_path;
- GdkPixbuf* pixbuf;
- GdkPixbuf* pixbuf_scaled = NULL;
- #endif
-
- menu_item = gtk_image_menu_item_new_with_label (
- webkit_web_history_item_get_title (history_item));
- #if WEBKIT_CHECK_VERSION (1, 3, 13)
- icon_uri = webkit_icon_database_get_icon_uri (webkit_get_icon_database (),
- webkit_web_history_item_get_uri (history_item));
- icon_path = katze_net_get_cached_path (NULL, icon_uri, "icons");
- if ((pixbuf = gdk_pixbuf_new_from_file (icon_path, NULL)))
- {
- gint w = 16, h = 16;
- gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
- GTK_ICON_SIZE_MENU, &w, &h);
- pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf,
- w, h, GDK_INTERP_BILINEAR);
- }
- gtk_image_menu_item_set_image (
- GTK_IMAGE_MENU_ITEM (menu_item),
- pixbuf_scaled ? gtk_image_new_from_pixbuf (pixbuf_scaled) :
- gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU));
- g_free (icon_uri);
- g_free (icon_path);
- #endif
- g_object_set_data (G_OBJECT (menu_item), "uri",
- (gpointer) webkit_web_history_item_get_uri (history_item));
- g_object_set_data (G_OBJECT (menu_item), "steps", GINT_TO_POINTER (steps));
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
- g_signal_connect (G_OBJECT (menu_item), "activate",
- G_CALLBACK (midori_browser_toolbar_popup_context_menu_history_cb),
- browser);
- if (steps == (10 - 1))
- break;
- }
-
- webkit_web_back_forward_list_go_to_item (list, current_item);
- gtk_widget_show_all (menu);
-
- katze_widget_popup (widget, GTK_MENU (menu), NULL,
- KATZE_MENU_POSITION_LEFT);
-}
-
static gboolean
midori_browser_toolbar_item_button_press_event_cb (GtkWidget* toolitem,
GdkEventButton* event,
@@ -6765,29 +6384,11 @@ midori_browser_toolbar_item_button_press_event_cb (GtkWidget* toolitem,
}
else if (MIDORI_EVENT_CONTEXT_MENU (event))
{
- if (g_object_get_data (G_OBJECT (toolitem), "history-back"))
- {
- midori_browser_toolbar_popup_context_menu_history (
- browser,
- GTK_IS_BIN (toolitem) && gtk_bin_get_child (GTK_BIN (toolitem)) ?
- gtk_widget_get_parent (toolitem) : toolitem,
- TRUE, event->x, event->y);
- }
- else if (g_object_get_data (G_OBJECT (toolitem), "history-forward"))
- {
- midori_browser_toolbar_popup_context_menu_history (
- browser,
- GTK_IS_BIN (toolitem) && gtk_bin_get_child (GTK_BIN (toolitem)) ?
+ midori_browser_toolbar_popup_context_menu_cb (
+ GTK_IS_BIN (toolitem) && gtk_bin_get_child (GTK_BIN (toolitem)) ?
gtk_widget_get_parent (toolitem) : toolitem,
- FALSE, event->x, event->y);
- }
- else
- {
- midori_browser_toolbar_popup_context_menu_cb (
- GTK_IS_BIN (toolitem) && gtk_bin_get_child (GTK_BIN (toolitem)) ?
- gtk_widget_get_parent (toolitem) : toolitem,
- event->x, event->y, event->button, browser);
- }
+ event->x, event->y, event->button, browser);
+
return TRUE;
}
return FALSE;
@@ -6877,28 +6478,14 @@ _midori_browser_set_toolbar_items (MidoriBrowser* browser,
}
else if (token_current != token_dontcare && token_last == token_dontcare)
continue;
- #ifdef HAVE_GRANITE
- /* A "new tab" button is already part of the notebook */
- else if (!strcmp (gtk_action_get_name (action), "TabNew"))
- continue;
- #endif
else
toolitem = gtk_action_create_tool_item (action);
if (gtk_bin_get_child (GTK_BIN (toolitem)))
- {
- if (!g_strcmp0 (*name, "Back"))
- g_object_set_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (toolitem))),
- "history-back", (void*) 0xdeadbeef);
- else if (!g_strcmp0 (*name, "Forward"))
- g_object_set_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (toolitem))),
- "history-forward", (void*) 0xdeadbeef);
-
g_signal_connect (gtk_bin_get_child (GTK_BIN (toolitem)),
"button-press-event",
G_CALLBACK (midori_browser_toolbar_item_button_press_event_cb),
browser);
- }
else
{
gtk_tool_item_set_use_drag_window (GTK_TOOL_ITEM (toolitem), TRUE);
@@ -6976,15 +6563,8 @@ _midori_browser_update_settings (MidoriBrowser* browser)
"news-aggregator", &browser->news_aggregator,
NULL);
- #ifdef HAVE_GRANITE
- granite_widgets_dynamic_notebook_set_tabs_closable (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), close_buttons_on_tabs);
- #endif
midori_findbar_set_close_button_left (MIDORI_FINDBAR (browser->find),
katze_object_get_boolean (browser->settings, "close-buttons-left"));
- if (browser->dial != NULL)
- midori_speed_dial_set_close_buttons_left (browser->dial,
- katze_object_get_boolean (browser->settings, "close-buttons-left"));
if (remember_last_window_size)
{
@@ -7096,21 +6676,29 @@ midori_browser_settings_notify (MidoriWebSettings* web_settings,
_toggle_tabbar_smartly (browser, FALSE);
else if (name == g_intern_string ("show-menubar"))
{
- _action_set_active (browser, "Menubar", g_value_get_boolean (&value));
+ gtk_toggle_action_set_active (
+ GTK_TOGGLE_ACTION (_action_by_name (browser, "Menubar")),
+ g_value_get_boolean (&value));
}
else if (name == g_intern_string ("show-navigationbar"))
{
browser->show_navigationbar = g_value_get_boolean (&value);
- _action_set_active (browser, "Navigationbar", g_value_get_boolean (&value));
+ gtk_toggle_action_set_active (
+ GTK_TOGGLE_ACTION (_action_by_name (browser, "Navigationbar")),
+ g_value_get_boolean (&value));
}
else if (name == g_intern_string ("show-bookmarkbar"))
{
- _action_set_active (browser, "Bookmarkbar", g_value_get_boolean (&value));
+ gtk_toggle_action_set_active (
+ GTK_TOGGLE_ACTION (_action_by_name (browser, "Bookmarkbar")),
+ g_value_get_boolean (&value));
}
else if (name == g_intern_string ("show-statusbar"))
{
browser->show_statusbar = g_value_get_boolean (&value);
- _action_set_active (browser, "Statusbar", g_value_get_boolean (&value));
+ gtk_toggle_action_set_active (
+ GTK_TOGGLE_ACTION (_action_by_name (browser, "Statusbar")),
+ g_value_get_boolean (&value));
}
else if (name == g_intern_string ("location-entry-search"))
{
@@ -7126,8 +6714,6 @@ midori_browser_settings_notify (MidoriWebSettings* web_settings,
{
midori_findbar_set_close_button_left (MIDORI_FINDBAR (browser->find),
g_value_get_boolean (&value));
- midori_speed_dial_set_close_buttons_left (browser->dial,
- katze_object_get_boolean (browser->settings, "close-buttons-left"));
}
else if (!g_object_class_find_property (G_OBJECT_GET_CLASS (web_settings),
name))
@@ -7193,7 +6779,6 @@ midori_bookmarkbar_remove_item_cb (KatzeArray* bookmarks,
{
if (gtk_widget_get_visible (browser->bookmarkbar))
midori_bookmarkbar_populate (browser);
- midori_browser_update_history (item, "bookmark", "delete");
}
static void
@@ -7209,10 +6794,9 @@ midori_bookmarkbar_populate (MidoriBrowser* browser)
gtk_separator_tool_item_new (), -1);
array = midori_array_query (browser->bookmarks,
- "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "toolbar = 1", NULL);
+ "uri, title, desc, app, folder, toolbar", "toolbar = 1", NULL);
if (!array)
{
- g_warning ("midori_array_query returned NULL");
_action_set_sensitive (browser, "BookmarkAdd", FALSE);
_action_set_sensitive (browser, "BookmarkFolderAdd", FALSE);
return;
@@ -7224,22 +6808,10 @@ midori_bookmarkbar_populate (MidoriBrowser* browser)
midori_bookmarkbar_insert_item (browser->bookmarkbar, item);
else
{
- gint64 id = katze_item_get_meta_integer (item, "id");
- gchar* parentid = g_strdup_printf ("%" G_GINT64_FORMAT, id);
KatzeArray* subfolder = midori_array_query (browser->bookmarks,
- "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid = %q AND uri != ''",
- parentid);
-
- if (subfolder)
- {
- katze_item_set_name (KATZE_ITEM (subfolder), katze_item_get_name (item));
- katze_item_set_meta_integer (KATZE_ITEM (subfolder), "id", id);
- midori_bookmarkbar_insert_item (browser->bookmarkbar, KATZE_ITEM (subfolder));
- }
- else
- g_warning ("midori_array_query returned NULL (id='%s')", parentid);
-
- g_free (parentid);
+ "uri, title, desc, app", "folder = '%q' AND uri != ''", katze_item_get_name (item));
+ katze_item_set_name (KATZE_ITEM (subfolder), katze_item_get_name (item));
+ midori_bookmarkbar_insert_item (browser->bookmarkbar, KATZE_ITEM (subfolder));
}
}
_action_set_sensitive (browser, "BookmarkAdd", TRUE);
@@ -7327,9 +6899,7 @@ midori_browser_set_property (GObject* object,
midori_browser_set_current_tab (browser, g_value_get_object (value));
break;
case PROP_STATUSBAR_TEXT:
- _midori_browser_set_statusbar_text (browser,
- MIDORI_VIEW (midori_browser_get_current_tab (browser)),
- g_value_get_string (value));
+ _midori_browser_set_statusbar_text (browser, g_value_get_string (value));
break;
case PROP_SETTINGS:
g_signal_handlers_disconnect_by_func (browser->settings,
@@ -7342,7 +6912,7 @@ midori_browser_set_property (GObject* object,
_midori_browser_update_settings (browser);
g_signal_connect (browser->settings, "notify",
G_CALLBACK (midori_browser_settings_notify), browser);
- midori_browser_foreach (browser,
+ gtk_container_foreach (GTK_CONTAINER (browser->notebook),
(GtkCallback) midori_view_set_settings, browser->settings);
break;
case PROP_BOOKMARKS:
@@ -7390,9 +6960,7 @@ midori_browser_set_property (GObject* object,
midori_browser_set_history (browser, g_value_get_object (value));
break;
case PROP_SPEED_DIAL:
- browser->dial = g_value_get_pointer (value);
- g_signal_connect (browser->dial, "refresh",
- G_CALLBACK (midori_browser_speed_dial_refresh_cb), browser);
+ browser->speeddial = g_value_get_pointer (value);
break;
case PROP_SHOW_TABS:
browser->show_tabs = g_value_get_boolean (value);
@@ -7464,7 +7032,7 @@ midori_browser_get_property (GObject* object,
g_value_set_object (value, browser->history);
break;
case PROP_SPEED_DIAL:
- g_value_set_pointer (value, browser->dial);
+ g_value_set_pointer (value, browser->speeddial);
break;
case PROP_SHOW_TABS:
g_value_set_boolean (value, browser->show_tabs);
@@ -7516,39 +7084,9 @@ midori_browser_add_tab (MidoriBrowser* browser,
g_critical ("midori_load_soup_session was not called!");
g_signal_emit (browser, signals[ADD_TAB], 0, view);
- return midori_browser_page_num (browser, view);
-}
-
-/**
- * midori_browser_page_num:
- * @browser: a #MidoriBrowser
- * @widget: a widget in the browser
- *
- * Retrieves the position of @widget in the browser.
- *
- * If there is no page present at all, -1 is returned.
- *
- * Return value: the index of the widget, or -1
- *
- * Since: 0.4.5
- **/
-gint
-midori_browser_page_num (MidoriBrowser* browser,
- GtkWidget* view)
-{
- g_return_val_if_fail (MIDORI_IS_BROWSER (browser), -1);
- g_return_val_if_fail (MIDORI_IS_VIEW (view), -1);
-
-#ifdef HAVE_GRANITE
- return granite_widgets_dynamic_notebook_get_tab_position (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook),
- midori_view_get_tab (MIDORI_VIEW (view)));
-#else
return gtk_notebook_page_num (GTK_NOTEBOOK (browser->notebook), view);
-#endif
}
-
/**
* midori_browser_remove_tab:
* @browser: a #MidoriBrowser
@@ -7565,13 +7103,6 @@ midori_browser_remove_tab (MidoriBrowser* browser,
g_return_if_fail (GTK_IS_WIDGET (view));
g_signal_emit (browser, signals[REMOVE_TAB], 0, view);
- #ifdef HAVE_GRANITE
- granite_widgets_dynamic_notebook_remove_tab (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook),
- midori_view_get_tab (MIDORI_VIEW (view)));
- #else
- gtk_widget_destroy (view);
- #endif
}
/**
@@ -7800,18 +7331,12 @@ midori_browser_set_current_page (MidoriBrowser* browser,
g_return_if_fail (MIDORI_IS_BROWSER (browser));
- view = midori_browser_get_nth_tab (browser, n);
+ view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), n);
g_return_if_fail (view != NULL);
- #ifdef HAVE_GRANITE
- granite_widgets_dynamic_notebook_set_current (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook),
- midori_view_get_tab (MIDORI_VIEW (view)));
- #else
gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n);
- #endif
if (midori_view_is_blank (MIDORI_VIEW (view)))
- midori_browser_activate_action (browser, "Location");
+ gtk_action_activate (_action_by_name (browser, "Location"));
else
gtk_widget_grab_focus (view);
@@ -7836,14 +7361,7 @@ midori_browser_get_current_page (MidoriBrowser* browser)
{
g_return_val_if_fail (MIDORI_IS_BROWSER (browser), -1);
- #ifdef HAVE_GRANITE
- GraniteWidgetsTab* tab = granite_widgets_dynamic_notebook_get_current (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook));
- return tab ? granite_widgets_dynamic_notebook_get_tab_position (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), tab) : -1;
- #else
return gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
- #endif
}
/**
@@ -7863,19 +7381,9 @@ GtkWidget*
midori_browser_get_nth_tab (MidoriBrowser* browser,
gint page)
{
-#ifdef HAVE_GRANITE
- GraniteWidgetsTab* tab;
-
- g_return_val_if_fail (MIDORI_IS_BROWSER (browser), NULL);
-
- tab = granite_widgets_dynamic_notebook_get_tab_by_index (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), page);
- return tab != NULL ? granite_widgets_tab_get_page (tab) : NULL;
-#else
g_return_val_if_fail (MIDORI_IS_BROWSER (browser), NULL);
return gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), page);
-#endif
}
/**
@@ -7898,7 +7406,7 @@ midori_browser_set_current_tab (MidoriBrowser* browser,
g_return_if_fail (MIDORI_IS_BROWSER (browser));
g_return_if_fail (GTK_IS_WIDGET (view));
- n = midori_browser_page_num (browser, view);
+ n = gtk_notebook_page_num (GTK_NOTEBOOK (browser->notebook), view);
midori_browser_set_current_page (browser, n);
}
@@ -7919,22 +7427,15 @@ midori_browser_set_current_tab (MidoriBrowser* browser,
GtkWidget*
midori_browser_get_current_tab (MidoriBrowser* browser)
{
- #ifdef HAVE_GRANITE
- GraniteWidgetsTab* tab;
- #else
gint n;
- #endif
g_return_val_if_fail (MIDORI_IS_BROWSER (browser), NULL);
- #ifdef HAVE_GRANITE
- tab = granite_widgets_dynamic_notebook_get_current (
- GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook));
- return tab ? granite_widgets_tab_get_page (tab) : NULL;
- #else
- n = midori_browser_get_current_page (browser);
- return (n >= 0) ? midori_browser_get_nth_tab (browser, n) : NULL;
- #endif
+ n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+ if (n >= 0)
+ return gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), n);
+ else
+ return NULL;
}
/**
diff --git a/midori/midori-browser.h b/midori/midori-browser.h
index 320006a3..a3cc979d 100644
--- a/midori/midori-browser.h
+++ b/midori/midori-browser.h
@@ -152,16 +152,9 @@ GtkWidget*
midori_browser_get_current_tab (MidoriBrowser* browser);
#define midori_browser_get_tab midori_browser_get_current_tab
-gint
-midori_browser_page_num (MidoriBrowser* browser,
- GtkWidget* view);
-
GList*
midori_browser_get_tabs (MidoriBrowser* browser);
-gint
-midori_browser_get_n_pages (MidoriBrowser* browser);
-
KatzeArray*
midori_browser_get_proxy_items (MidoriBrowser* browser);
@@ -180,11 +173,6 @@ midori_browser_get_toolbar_actions (MidoriBrowser* browser);
MidoriWebSettings*
midori_browser_get_settings (MidoriBrowser* browser);
-void
-midori_browser_update_history (KatzeItem* item,
- const gchar* type,
- const gchar* event);
-
G_END_DECLS
#endif /* __MIDORI_BROWSER_H__ */
diff --git a/midori/midori-download.vala b/midori/midori-download.vala
deleted file mode 100644
index 32d9464b..00000000
--- a/midori/midori-download.vala
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- Copyright (C) 2012 Christian Dywan
-
- 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.
-*/
-
-namespace Sokoke {
- extern static bool show_uri (Gdk.Screen screen, string uri, uint32 timestamp) throws Error;
- extern static bool message_dialog (Gtk.MessageType type, string short, string detailed, bool modal);
-}
-
-namespace Midori {
- namespace Download {
- public static bool is_finished (WebKit.Download download) {
- switch (download.status) {
- case WebKit.DownloadStatus.FINISHED:
- case WebKit.DownloadStatus.CANCELLED:
- case WebKit.DownloadStatus.ERROR:
- return true;
- default:
- return false;
- }
- }
-
- public static int get_type (WebKit.Download download) {
- return download.get_data ("midori-download-type");
- }
-
- public static void set_type (WebKit.Download download, int type) {
- download.set_data ("midori-download-type", type);
- }
-
- public static double get_progress (WebKit.Download download) {
- /* Avoid a bug in WebKit */
- if (download.status == WebKit.DownloadStatus.CREATED)
- return 0.0;
- return download.progress;
- }
-
- public static string get_tooltip (WebKit.Download download) {
- string filename = Path.get_basename (download.destination_uri);
- /* i18n: Download tooltip (size): 4KB of 43MB */
- string size = _("%s of %s").printf (
- format_size (download.current_size),
- format_size (download.total_size));
-
- /* Finished, no speed or remaining time */
- if (is_finished (download) || download.status == WebKit.DownloadStatus.CREATED)
- return "%s\n%s".printf (filename, size);
-
- uint64 total_size = download.total_size, current_size = download.current_size;
- double elapsed = download.get_elapsed_time (),
- diff = elapsed / current_size,
- estimated = (total_size - current_size) * diff;
- int hour = 3600, minute = 60;
- int hours = (int)(estimated / hour),
- minutes = (int)((estimated - (hours * hour)) / minute),
- seconds = (int)((estimated - (hours * hour) - (minutes * minute)));
- string hours_ = ngettext ("%d hour", "%d hours", hours).printf (hours);
- string minutes_ = ngettext ("%d minute", "%d minutes", minutes).printf (minutes);
- string seconds_ = ngettext ("%d second", "%d seconds", seconds).printf (seconds);
- double last_time = download.get_data ("last-time");
- uint64 last_size = download.get_data ("last-size");
-
- string eta = "";
- if (estimated > 0) {
- if (hours > 0)
- eta = hours_ + ", " + minutes_;
- else if (minutes >= 10)
- eta = minutes_;
- else if (minutes < 10 && minutes > 0)
- eta = minutes_ + ", " + seconds_;
- else if (seconds > 0)
- eta = seconds_;
- if (eta != "")
- /* i18n: Download tooltip (estimated time) : - 1 hour, 5 minutes remaning */
- eta = _(" - %s remaining").printf (eta);
- }
-
- string speed;
- if (elapsed != last_time) {
- speed = format_size ((uint64)(
- (current_size - last_size) / (elapsed - last_time)));
- }
- else
- /* i18n: Unknown number of bytes, used for transfer rate like ?B/s */
- speed = _("?B");
- /* i18n: Download tooltip (transfer rate): (130KB/s) */
- speed = _(" (%s/s)").printf (speed);
- if (elapsed - last_time > 5.0) {
- download.set_data ("last-time", (int)elapsed);
- download.set_data ("last-size", current_size);
- }
-
- return "%s\n%s %s%s".printf (filename, size, speed, eta);
- }
-
- public static string get_content_type (WebKit.Download download, string? mime_type) {
- string? content_type = ContentType.guess (download.suggested_filename, null, null);
- if (content_type == null) {
- content_type = ContentType.from_mime_type (mime_type);
- if (content_type == null)
- content_type = ContentType.from_mime_type ("application/octet-stream");
- }
- return content_type;
- }
-
- public static bool has_wrong_checksum (WebKit.Download download) {
- int status = download.get_data ("checksum-status");
- if (status == 0) {
- /* Link Fingerprint */
- string? original_uri = download.network_request.get_data ("midori-original-uri");
- if (original_uri == null)
- original_uri = download.get_uri ();
- string? fingerprint;
- ChecksumType checksum_type = URI.get_fingerprint (original_uri, out fingerprint, null);
- /* By default, no wrong checksum */
- status = 2;
- if (fingerprint != null) {
- try {
- string filename = Filename.from_uri (download.destination_uri);
- string contents;
- size_t length;
- bool y = FileUtils.get_contents (filename, out contents, out length);
- string checksum = Checksum.compute_for_string (checksum_type, contents, length);
- /* Checksums are case-insensitive */
- if (!y || fingerprint.ascii_casecmp (checksum) != 0)
- status = 1; /* wrong checksum */
- }
- catch (Error error) {
- status = 1; /* wrong checksum */
- }
- }
- download.set_data ("checksum-status", status);
- }
- return status == 1;
- }
-
- public static bool action_clear (WebKit.Download download, Gtk.Widget widget) throws Error {
- switch (download.status) {
- case WebKit.DownloadStatus.CREATED:
- case WebKit.DownloadStatus.STARTED:
- download.cancel ();
- break;
- case WebKit.DownloadStatus.FINISHED:
- if (open (download, widget))
- return true;
- break;
- case WebKit.DownloadStatus.CANCELLED:
- return true;
- default:
- critical ("action_clear: %d", download.status);
- warn_if_reached ();
- break;
- }
- return false;
- }
-
- public static string action_stock_id (WebKit.Download download) {
- switch (download.status) {
- case WebKit.DownloadStatus.CREATED:
- case WebKit.DownloadStatus.STARTED:
- return Gtk.Stock.CANCEL;
- case WebKit.DownloadStatus.FINISHED:
- if (has_wrong_checksum (download))
- return Gtk.Stock.DIALOG_WARNING;
- return Gtk.Stock.OPEN;
- case WebKit.DownloadStatus.CANCELLED:
- return Gtk.Stock.CLEAR;
- default:
- critical ("action_stock_id: %d", download.status);
- warn_if_reached ();
- return Gtk.Stock.MISSING_IMAGE;
- }
- }
-
- public static bool open (WebKit.Download download, Gtk.Widget widget) throws Error {
- if (!has_wrong_checksum (download))
- return Sokoke.show_uri (widget.get_screen (),
- download.destination_uri, Gtk.get_current_event_time ());
-
- Sokoke.message_dialog (Gtk.MessageType.WARNING,
- _("The downloaded file is erroneous."),
- _("The checksum provided with the link did not match. This means the file is probably incomplete or was modified afterwards."),
- true);
- return false;
- }
-
- public unowned string fallback_extension (string? extension, string mime_type) {
- if (extension != null && extension[0] != '\0')
- return extension;
- if ("css" in mime_type)
- return ".css";
- if ("javascript" in mime_type)
- return ".js";
- if ("html" in mime_type)
- return ".htm";
- if ("plain" in mime_type)
- return ".txt";
- return "";
- }
-
- public string clean_filename (string filename) {
- #if HAVE_WIN32
- return filename.delimit ("/\\<>:\"|?*", '_');
- #else
- return filename.delimit ("/", '_');
- #endif
- }
-
- public string get_suggested_filename (WebKit.Download download) {
- /* https://bugs.webkit.org/show_bug.cgi?id=83161
- https://d19vezwu8eufl6.cloudfront.net/nlp/slides%2F03-01-FormalizingNB.pdf */
- return clean_filename (download.get_suggested_filename ());
- }
-
- public string get_filename_suggestion_for_uri (string mime_type, string uri) {
- /* Try to provide a good default filename, UTF-8 encoded */
- string filename = clean_filename (Soup.URI.decode (uri));
- /* Take the rest of the URI if needed */
- if (filename.has_suffix ("/") || uri.index_of_char ('.') == -1)
- return Path.build_filename (filename, fallback_extension (null, mime_type));
- return filename;
- }
-
- public static string? get_extension_for_uri (string uri, out string basename = null) {
- if (&basename != null)
- basename = null;
- /* Find the last slash and the last period *after* the last slash. */
- int last_slash = uri.last_index_of_char ('/');
- /* Huh, URI without slashes? */
- if (last_slash == -1)
- return null;
- int period = uri.last_index_of_char ('.', last_slash);
- if (period == -1)
- return null;
- /* The extension, or "." if it ended with a period */
- string extension = uri.substring (period, -1);
- if (&basename != null)
- basename = uri.substring (0, period);
- return extension;
-
- }
-
- public string get_unique_filename (string filename) {
- if (Posix.access (filename, Posix.F_OK) == 0) {
- string basename;
- string? extension = get_extension_for_uri (filename, out basename);
- string? new_filename = null;
- int i = 0;
- do {
- new_filename = "%s-%d%s".printf (basename, i++, extension ?? "");
- } while (Posix.access (new_filename, Posix.F_OK) == 0);
- return new_filename;
- }
- return filename;
- }
-
- public string prepare_destination_uri (WebKit.Download download, string? folder) {
- string suggested_filename = get_suggested_filename (download);
- string basename = File.new_for_uri (suggested_filename).get_basename ();
- string download_dir;
- if (folder == null) {
- download_dir = Paths.get_tmp_dir ();
- Katze.mkdir_with_parents (download_dir, 0700);
- }
- else
- download_dir = folder;
- string destination_filename = Path.build_filename (download_dir, basename);
- try {
- return Filename.to_uri (get_unique_filename (destination_filename));
- }
- catch (Error error) {
- return "file://" + destination_filename;
- }
- }
-
- public static bool has_enough_space (WebKit.Download download, string uri) {
- var folder = File.new_for_uri (uri).get_parent ();
- bool can_write;
- uint64 free_space;
- try {
- var info = folder.query_filesystem_info ("filesystem::free");
- free_space = info.get_attribute_uint64 ("filesystem::free");
- info = folder.query_info ("access::can-write", 0);
- can_write = info.get_attribute_boolean ("access::can-write");
- }
- catch (Error error) {
- can_write = false;
- free_space = 0;
- }
-
- if (free_space < download.total_size || !can_write) {
- string message;
- string detailed_message;
- if (!can_write) {
- message = _("The file \"%s\" can't be saved in this folder.").printf (
- Path.get_basename (uri));
- detailed_message = _("You don't have permission to write in this location.");
- }
- else if (free_space < download.total_size) {
- message = _("There is not enough free space to download \"%s\".").printf (
- Path.get_basename (uri));
- detailed_message = _("The file needs %s but only %s are left.").printf (
- format_size (download.total_size), format_size (free_space));
- }
- else
- assert_not_reached ();
- Sokoke.message_dialog (Gtk.MessageType.ERROR, message, detailed_message, false);
- return false;
- }
- return true;
- }
- }
-}
diff --git a/midori/midori-extension.c b/midori/midori-extension.c
index 01f518cc..7927e72f 100644
--- a/midori/midori-extension.c
+++ b/midori/midori-extension.c
@@ -14,7 +14,6 @@
#include
#include "midori-platform.h"
-#include "midori-core.h"
#include
G_DEFINE_TYPE (MidoriExtension, midori_extension, G_TYPE_OBJECT);
@@ -26,7 +25,6 @@ struct _MidoriExtensionPrivate
gchar* version;
gchar* authors;
gchar* website;
- gchar* key;
MidoriApp* app;
gint active;
@@ -129,8 +127,7 @@ enum
PROP_DESCRIPTION,
PROP_VERSION,
PROP_AUTHORS,
- PROP_WEBSITE,
- PROP_KEY
+ PROP_WEBSITE
};
enum {
@@ -263,23 +260,6 @@ midori_extension_class_init (MidoriExtensionClass* class)
NULL,
flags));
- /**
- * MidoriExtension:key:
- *
- * The extension key.
- * Needed if there is more than one extension object in a single module.
- *
- * Since: 0.4.5
- */
- g_object_class_install_property (gobject_class,
- PROP_KEY,
- g_param_spec_string (
- "key",
- "Key",
- "The extension key",
- NULL,
- flags));
-
g_type_class_add_private (class, sizeof (MidoriExtensionPrivate));
}
@@ -318,10 +298,10 @@ midori_extension_activate_cb (MidoriExtension* extension,
strlen (filename) - strlen ("." G_MODULE_SUFFIX));
else
filename = g_strdup (filename);
- folder = g_build_filename ("extensions", filename, NULL);
+ folder = g_strconcat ("extensions/", filename, NULL);
g_free (filename);
katze_assign (config_file,
- midori_paths_get_preset_filename (folder, "config"));
+ sokoke_find_config_filename (folder, "config"));
g_free (folder);
g_key_file_load_from_file (extension->priv->key_file, config_file,
G_KEY_FILE_KEEP_COMMENTS, NULL);
@@ -341,32 +321,29 @@ midori_extension_activate_cb (MidoriExtension* extension,
if (setting->type == G_TYPE_BOOLEAN)
{
MESettingBoolean* setting_ = (MESettingBoolean*)setting;
- if (extension->priv->key_file
- && g_key_file_has_key (extension->priv->key_file, "settings", setting_->name, NULL))
- setting_->value = g_key_file_get_boolean (extension->priv->key_file,
- "settings", setting->name, NULL);
+ if (extension->priv->key_file)
+ setting_->value = sokoke_key_file_get_boolean_default (
+ extension->priv->key_file,
+ "settings", setting->name, setting_->default_value, NULL);
else
setting_->value = setting_->default_value;
}
else if (setting->type == G_TYPE_INT)
{
MESettingInteger* setting_ = (MESettingInteger*)setting;
- if (extension->priv->key_file
- && g_key_file_has_key (extension->priv->key_file, "settings", setting_->name, NULL))
- setting_->value = g_key_file_get_integer (extension->priv->key_file,
- "settings", setting_->name, NULL);
+ if (extension->priv->key_file)
+ setting_->value = sokoke_key_file_get_integer_default (
+ extension->priv->key_file,
+ "settings", setting->name, setting_->default_value, NULL);
else
setting_->value = setting_->default_value;
}
else if (setting->type == G_TYPE_STRING)
{
if (extension->priv->key_file)
- {
- setting->value = g_key_file_get_string (
- extension->priv->key_file, "settings", setting->name, NULL);
- if (setting->value == NULL)
- setting->value = setting->default_value;
- }
+ setting->value = sokoke_key_file_get_string_default (
+ extension->priv->key_file,
+ "settings", setting->name, setting->default_value, NULL);
else
setting->value = g_strdup (setting->default_value);
}
@@ -375,10 +352,10 @@ midori_extension_activate_cb (MidoriExtension* extension,
MESettingStringList* setting_ = (MESettingStringList*)setting;
if (extension->priv->key_file)
{
- setting_->value = g_key_file_get_string_list (extension->priv->key_file,
- "settings", setting->name, &setting_->length, NULL);
- if (setting_->value == NULL)
- setting_->value = g_strdupv (setting_->default_value);
+ setting_->value = sokoke_key_file_get_string_list_default (
+ extension->priv->key_file,
+ "settings", setting->name, &setting_->length,
+ setting_->default_value, &setting_->default_length, NULL);
}
else
setting_->value = g_strdupv (setting_->default_value);
@@ -423,7 +400,6 @@ midori_extension_finalize (GObject* object)
katze_assign (extension->priv->version, NULL);
katze_assign (extension->priv->authors, NULL);
katze_assign (extension->priv->website, NULL);
- katze_assign (extension->priv->key, NULL);
katze_assign (extension->priv->config_dir, NULL);
g_list_free (extension->priv->lsettings);
@@ -470,9 +446,6 @@ midori_extension_set_property (GObject* object,
case PROP_WEBSITE:
katze_assign (extension->priv->website, g_value_dup_string (value));
break;
- case PROP_KEY:
- katze_assign (extension->priv->key, g_value_dup_string (value));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -504,9 +477,6 @@ midori_extension_get_property (GObject* object,
case PROP_WEBSITE:
g_value_set_string (value, extension->priv->website);
break;
- case PROP_KEY:
- g_value_set_string (value, extension->priv->key);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -649,11 +619,10 @@ midori_extension_get_config_dir (MidoriExtension* extension)
if (!extension->priv->config_dir)
{
gchar* filename = g_object_get_data (G_OBJECT (extension), "filename");
- if (filename != NULL)
- extension->priv->config_dir = g_build_filename (
- midori_paths_get_config_dir (), "extensions", filename, NULL);
- else
- extension->priv->config_dir = NULL;
+ if (!filename)
+ return "/";
+ extension->priv->config_dir = g_build_filename (
+ sokoke_set_config_dir (NULL), "extensions", filename, NULL);
}
return extension->priv->config_dir;
diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index 5bd0b7da..47d2e3d0 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -277,175 +277,43 @@ midori_location_action_create_model (void)
}
static void
-midori_location_action_popup_position (MidoriLocationAction* action,
- gint matches)
+midori_location_action_popup_position (GtkWidget* popup,
+ GtkWidget* widget)
{
- GtkWidget* popup = action->popup;
- GtkWidget* widget = action->entry;
GdkWindow* window = gtk_widget_get_window (widget);
- gint wx, wy, x_border, y_border, items;
+ gint wx, wy;
GtkRequisition menu_req;
GtkRequisition widget_req;
GdkScreen* screen;
gint monitor_num;
GdkRectangle monitor;
- GtkAllocation alloc;
- gint height, sep, width, toplevel_height;
- gboolean above;
- GtkWidget* scrolled = gtk_widget_get_parent (action->treeview);
- GtkWidget* toplevel;
- GtkTreePath* path;
-
- if (!window)
- return;
+ GtkAllocation allocation;
- gtk_widget_get_allocation (widget, &alloc);
- #if GTK_CHECK_VERSION (3, 0, 0)
- gtk_widget_get_preferred_size (widget, &widget_req, NULL);
- #else
- gtk_widget_size_request (widget, &widget_req);
- #endif
gdk_window_get_origin (window, &wx, &wy);
- #if GTK_CHECK_VERSION (3, 0, 0)
- wx += alloc.x;
- wy += alloc.y + (alloc.height - widget_req.height) / 2;
- #endif
- /* _gtk_entry_get_borders (GTK_ENTRY (widget), &x_border, &y_border); */
- x_border = y_border = 0;
+ if (!gtk_widget_get_has_window (widget))
+ {
+ GtkAllocation alloc;
+ gtk_widget_get_allocation (widget, &alloc);
+ wx += alloc.x;
+ wy += alloc.y;
+ }
- gtk_tree_view_column_cell_get_size (
- gtk_tree_view_get_column (GTK_TREE_VIEW (action->treeview), 0),
- NULL, NULL, NULL, NULL, &height);
- gtk_widget_style_get (action->treeview, "vertical-separator", &sep, NULL);
- height += sep;
+ gtk_widget_size_request (popup, &menu_req);
+ gtk_widget_size_request (widget, &widget_req);
- /* Constrain to screen/ window size */
screen = gtk_widget_get_screen (widget);
monitor_num = gdk_screen_get_monitor_at_window (screen, window);
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
- toplevel = gtk_widget_get_toplevel (widget);
- gtk_window_get_size (GTK_WINDOW (toplevel), NULL, &toplevel_height);
- toplevel_height = MIN (toplevel_height, monitor.height);
- if (wy > toplevel_height / 2)
- items = MIN (matches, ((monitor.y + wy) / height) - 1);
- else
- items = MIN (matches, ((toplevel_height - wy) / height) - 1);
- width = MIN (alloc.width, monitor.width) - 2 * x_border;
- gtk_tree_view_columns_autosize (GTK_TREE_VIEW (action->treeview));
- #if GTK_CHECK_VERSION (3, 0, 0)
- gtk_widget_set_size_request (scrolled, width, -1);
- gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (scrolled), width);
- gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolled), items * height);
- gtk_widget_get_preferred_size (popup, &menu_req, NULL);
- #else
- gtk_widget_set_size_request (scrolled, width, items * height);
- gtk_widget_size_request (popup, &menu_req);
- #endif
-
- if (wx < monitor.x)
- wx = monitor.x;
- else if (wx + menu_req.width > monitor.x + monitor.width)
- wx = monitor.x + monitor.width - menu_req.width;
-
- if (wy + widget_req.height + menu_req.height <= monitor.y + monitor.height ||
- wy - monitor.y < (monitor.y + monitor.height) - (wy + widget_req.height))
- {
+ if (wy + widget_req.height + menu_req.height <= monitor.y + monitor.height
+ || wy - monitor.y < (monitor.y + monitor.height) - (wy + widget_req.height))
wy += widget_req.height;
- above = FALSE;
- }
else
- {
wy -= menu_req.height;
- above = TRUE;
- }
-
- path = gtk_tree_path_new_from_indices (above ? matches - 1 : 0, -1);
- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (action->treeview), path,
- NULL, FALSE, 0.0, 0.0);
- gtk_tree_path_free (path);
-
- gtk_window_move (GTK_WINDOW (popup), wx, wy);
-}
-
-static int
-midori_location_action_add_search_engines (MidoriLocationAction* action,
- GtkListStore* store,
- gint matches)
-{
- KatzeItem* item;
- gint i = 0;
- #ifndef G_OS_WIN32
- GtkStyle* style;
- #endif
-
- gtk_widget_realize (action->treeview);
- #ifndef G_OS_WIN32
- style = gtk_widget_get_style (action->treeview);
- #endif
-
- /* FIXME: choose 3 most frequently except for default */
- KATZE_ARRAY_FOREACH_ITEM (item, action->search_engines)
- {
- gchar* uri;
- gchar* title;
- const gchar* text;
- gchar* desc;
- GdkPixbuf* icon;
-
- uri = midori_uri_for_search (katze_item_get_uri (item), action->key);
- title = g_strdup_printf (_("Search with %s"), katze_item_get_name (item));
- text = katze_item_get_text (item);
- desc = g_strdup_printf ("%s\n%s", title, text ? text : uri);
- icon = midori_search_action_get_icon (item, action->treeview, NULL, FALSE);
- gtk_list_store_insert_with_values (store, NULL, matches + i,
- URI_COL, uri, TITLE_COL, desc, YALIGN_COL, 0.25,
- #ifndef G_OS_WIN32
- BACKGROUND_COL, style ? &style->bg[GTK_STATE_NORMAL] : NULL,
- #endif
- STYLE_COL, 1, FAVICON_COL, icon, -1);
- g_free (uri);
- g_free (title);
- g_free (desc);
- if (icon != NULL)
- g_object_unref (icon);
- i++;
-
- if (i > 2 && matches > 0)
- {
- gtk_list_store_insert_with_values (store, NULL, matches + i,
- URI_COL, "about:search", TITLE_COL, _("Search withâ¦"),
- YALIGN_COL, 0.25,
- #ifndef G_OS_WIN32
- BACKGROUND_COL, style ? &style->bg[GTK_STATE_NORMAL] : NULL,
- #endif
- STYLE_COL, 1, FAVICON_COL, NULL, -1);
- i++;
- break;
- }
- }
- return i;
-}
-
-static void
-midori_location_action_complete (MidoriLocationAction* action,
- gboolean new_tab,
- const gchar* uri)
-{
- if (!strcmp (uri, "about:search"))
- {
- GtkListStore* store = GTK_LIST_STORE (action->completion_model);
- gtk_list_store_clear (store);
- midori_location_action_popup_position (action,
- midori_location_action_add_search_engines (action, store, 0));
- }
- else
- {
- midori_location_action_popdown_completion (action);
- gtk_entry_set_text (GTK_ENTRY (action->entry), uri);
- g_signal_emit (action, signals[SUBMIT_URI], 0, uri, new_tab);
- }
+ gtk_window_move (GTK_WINDOW (popup), wx, wy);
+ gtk_widget_get_allocation (widget, &allocation);
+ gtk_window_resize (GTK_WINDOW (popup), allocation.width, 1);
}
static gboolean
@@ -463,9 +331,13 @@ midori_location_action_treeview_button_press_cb (GtkWidget* treeview,
gtk_tree_model_get_iter (action->completion_model, &iter, path);
gtk_tree_path_free (path);
+
+ midori_location_action_popdown_completion (action);
+
gtk_tree_model_get (action->completion_model, &iter, URI_COL, &uri, -1);
- midori_location_action_complete (action,
- MIDORI_MOD_NEW_TAB (event->state), uri);
+ gtk_entry_set_text (GTK_ENTRY (action->entry), uri);
+ g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
+ MIDORI_MOD_NEW_TAB (event->state));
g_free (uri);
return TRUE;
@@ -485,20 +357,28 @@ midori_location_action_popup_timeout_cb (gpointer data)
gint result;
static sqlite3_stmt* stmt;
const gchar* sqlcmd;
- gint matches, searches;
+ gint matches, searches, height, screen_height, browser_height, sep;
+ MidoriBrowser* browser;
+ GtkStyle* style;
if (!action->entry || !gtk_widget_has_focus (action->entry) || !action->history)
return FALSE;
/* No completion when typing a search token */
- if (action->search_engines
- && katze_array_find_token (action->search_engines, action->key))
+ if (action->search_engines != NULL)
{
- midori_location_action_popdown_completion (action);
- return FALSE;
+ gchar** parts = g_strsplit (action->key, " ", 2);
+ if (parts && *parts && parts[1]
+ && katze_array_find_token (action->search_engines, *parts))
+ {
+ g_strfreev (parts);
+ midori_location_action_popdown_completion (action);
+ return FALSE;
+ }
+ g_strfreev (parts);
}
- /* Empty string or starting with a space means: no completion */
+ /* Empaty string or starting with a space means: no completion */
if (!(action->key && *action->key && *action->key != ' '))
{
midori_location_action_popdown_completion (action);
@@ -563,8 +443,6 @@ midori_location_action_popup_timeout_cb (gpointer data)
popup = gtk_window_new (GTK_WINDOW_POPUP);
gtk_window_set_type_hint (GTK_WINDOW (popup), GDK_WINDOW_TYPE_HINT_COMBO);
- /* Window managers may ignore programmatic resize without this */
- gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
popup_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (popup_frame), GTK_SHADOW_ETCHED_IN);
gtk_container_add (GTK_CONTAINER (popup), popup_frame);
@@ -593,8 +471,6 @@ midori_location_action_popup_timeout_cb (gpointer data)
renderer = gtk_cell_renderer_text_new ();
g_object_set_data (G_OBJECT (renderer), "location-action", action);
gtk_cell_renderer_set_fixed_size (renderer, 1, -1);
- gtk_cell_renderer_text_set_fixed_height_from_font (
- GTK_CELL_RENDERER_TEXT (renderer), 2);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
"cell-background-gdk", BACKGROUND_COL,
@@ -613,6 +489,7 @@ midori_location_action_popup_timeout_cb (gpointer data)
gtk_list_store_clear (store);
matches = searches = 0;
+ style = gtk_widget_get_style (action->treeview);
while (result == SQLITE_ROW)
{
sqlite3_int64 type = sqlite3_column_int64 (stmt, 0);
@@ -630,11 +507,9 @@ midori_location_action_popup_timeout_cb (gpointer data)
else if (type == 2 /* search_view */)
{
gchar* search_title = g_strdup_printf (_("Search for %s"), title);
- gchar* search_desc = g_strdup_printf ("%s\n%s", search_title, uri);
gtk_list_store_insert_with_values (store, NULL, matches,
- URI_COL, uri, TITLE_COL, search_desc, YALIGN_COL, 0.25,
+ URI_COL, uri, TITLE_COL, search_title, YALIGN_COL, 0.25,
STYLE_COL, 1, FAVICON_COL, icon, -1);
- g_free (search_desc);
g_free (search_title);
}
if (icon != NULL)
@@ -643,15 +518,34 @@ midori_location_action_popup_timeout_cb (gpointer data)
matches++;
result = sqlite3_step (stmt);
}
+ sqlite3_reset (stmt);
+ sqlite3_clear_bindings (stmt);
- if (stmt)
+ if (action->search_engines)
{
- sqlite3_reset (stmt);
- sqlite3_clear_bindings (stmt);
- }
+ KatzeItem* item;
+ i = 0;
+ KATZE_ARRAY_FOREACH_ITEM (item, action->search_engines)
+ {
+ gchar* uri;
+ gchar* title;
+ GdkPixbuf* icon;
- if (action->search_engines)
- searches += midori_location_action_add_search_engines (action, store, matches);
+ uri = midori_uri_for_search (katze_item_get_uri (item), action->key);
+ title = g_strdup_printf (_("Search with %s"), katze_item_get_name (item));
+ icon = midori_search_action_get_icon (item, action->treeview, NULL, FALSE);
+ gtk_list_store_insert_with_values (store, NULL, matches + i,
+ URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
+ BACKGROUND_COL, style ? &style->bg[GTK_STATE_NORMAL] : NULL,
+ STYLE_COL, 1, FAVICON_COL, icon, -1);
+ g_free (uri);
+ g_free (title);
+ if (icon != NULL)
+ g_object_unref (icon);
+ i++;
+ }
+ searches += i;
+ }
if (!gtk_widget_get_visible (action->popup))
{
@@ -659,10 +553,22 @@ midori_location_action_popup_timeout_cb (gpointer data)
gtk_window_set_screen (GTK_WINDOW (action->popup),
gtk_widget_get_screen (action->entry));
gtk_window_set_transient_for (GTK_WINDOW (action->popup), GTK_WINDOW (toplevel));
- gtk_widget_show_all (action->popup);
+ gtk_tree_view_columns_autosize (GTK_TREE_VIEW (action->treeview));
}
- midori_location_action_popup_position (action, matches + searches);
+ browser = midori_browser_get_for_widget (action->entry);
+ column = gtk_tree_view_get_column (GTK_TREE_VIEW (action->treeview), 0);
+ gtk_tree_view_column_cell_get_size (column, NULL, NULL, NULL, NULL, &height);
+ screen_height = gdk_screen_get_height (gtk_widget_get_screen (action->popup));
+ gtk_window_get_size (GTK_WINDOW (browser), NULL, &browser_height);
+ screen_height = MIN (MIN (browser_height, screen_height / 1.5), screen_height / 1.5);
+ gtk_widget_style_get (action->treeview, "vertical-separator", &sep, NULL);
+ /* FIXME: Instead of 1.5 we should relate to the height of one line */
+ height = MIN (matches * height + (matches + searches) * sep
+ + searches * height / 1.5, screen_height);
+ gtk_widget_set_size_request (action->treeview, -1, height);
+ midori_location_action_popup_position (action->popup, action->entry);
+ gtk_widget_show_all (action->popup);
return FALSE;
}
@@ -822,31 +728,15 @@ midori_location_action_activate (GtkAction* action)
GTK_ACTION_CLASS (midori_location_action_parent_class)->activate (action);
}
-static void
-midori_location_action_entry_drag_data_get_cb (GtkWidget* entry,
- GdkDragContext* context,
- GtkSelectionData* data,
- guint info,
- guint32 time,
- GtkAction* action)
-{
- if (gtk_entry_get_current_icon_drag_source (GTK_ENTRY (entry)) == GTK_ENTRY_ICON_PRIMARY)
- {
- const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry));
- gchar** uris = g_strsplit (uri, uri, 1);
- gtk_selection_data_set_uris (data, uris);
- g_strfreev (uris);
- }
-}
-
static GtkWidget*
midori_location_action_create_tool_item (GtkAction* action)
{
GtkWidget* toolitem;
GtkWidget* alignment;
GtkWidget* entry;
-
- GtkTargetList *targetlist;
+ #if HAVE_HILDON
+ HildonGtkInputMode mode;
+ #endif
toolitem = GTK_WIDGET (gtk_tool_item_new ());
gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
@@ -855,21 +745,48 @@ midori_location_action_create_tool_item (GtkAction* action)
gtk_widget_show (alignment);
gtk_container_add (GTK_CONTAINER (toolitem), alignment);
+ #if HAVE_HILDON
+ entry = gtk_entry_new ();
+ mode = hildon_gtk_entry_get_input_mode (GTK_ENTRY (entry));
+ mode &= ~HILDON_GTK_INPUT_MODE_AUTOCAP;
+ hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry), mode);
+ #else
entry = gtk_icon_entry_new ();
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_FILE);
+ /* Work-around icon being activatable by default */
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (entry),
- GTK_ICON_ENTRY_PRIMARY, TRUE);
+ GTK_ICON_ENTRY_PRIMARY, FALSE);
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (entry),
GTK_ICON_ENTRY_SECONDARY, TRUE);
-
- targetlist = gtk_target_list_new (NULL, 0);
- gtk_target_list_add_uri_targets (targetlist, 0);
- gtk_entry_set_icon_drag_source (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, targetlist, GDK_ACTION_ASK | GDK_ACTION_COPY | GDK_ACTION_LINK);
- gtk_target_list_unref (targetlist);
- g_signal_connect (entry, "drag-data-get",
- G_CALLBACK (midori_location_action_entry_drag_data_get_cb), action);
+ #endif
gtk_widget_show (entry);
gtk_container_add (GTK_CONTAINER (alignment), entry);
+ #if GTK_CHECK_VERSION (3, 0, 0)
+ {
+ static const gchar default_style[] =
+ ".security_unknown {\n"
+ "background-image: none;\n"
+ "background-color: #ef7070;\n"
+ "color: #000;\n"
+ "}\n"
+ ".security_trusted {\n"
+ "background-image: none;\n"
+ "background-color: #d1eeb9;\n"
+ "color: #000;\n"
+ "}\n";
+ GtkCssProvider* css_provider;
+ GtkStyleContext* context;
+
+ css_provider = gtk_css_provider_new ();
+ context = gtk_widget_get_style_context (entry);
+ gtk_css_provider_load_from_data (css_provider, default_style, -1, NULL);
+ gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
+ }
+ #endif
+
return toolitem;
}
@@ -953,30 +870,27 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
GtkTreeModel* model = location_action->completion_model;
GtkTreeIter iter;
gint selected = location_action->completion_index;
+ midori_location_action_popdown_completion (location_action);
if (selected > -1 &&
gtk_tree_model_iter_nth_child (model, &iter, NULL, selected))
{
gchar* uri;
gtk_tree_model_get (model, &iter, URI_COL, &uri, -1);
+ gtk_entry_set_text (entry, uri);
if (is_enter)
- midori_location_action_complete (location_action,
- MIDORI_MOD_NEW_TAB (event->state), uri);
- else
- {
- midori_location_action_popdown_completion (location_action);
- gtk_entry_set_text (entry, uri);
- }
+ g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
+ MIDORI_MOD_NEW_TAB (event->state));
g_free (uri);
return TRUE;
}
- midori_location_action_popdown_completion (location_action);
}
- if (is_enter && (text = gtk_entry_get_text (entry)) && *text)
- g_signal_emit (action, signals[SUBMIT_URI], 0, text,
- MIDORI_MOD_NEW_TAB (event->state));
+ if (is_enter)
+ if ((text = gtk_entry_get_text (entry)) && *text)
+ g_signal_emit (action, signals[SUBMIT_URI], 0, text,
+ MIDORI_MOD_NEW_TAB (event->state));
break;
case GDK_KEY_Escape:
{
@@ -992,6 +906,10 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
/* Return FALSE to allow Escape to stop loading */
return FALSE;
}
+ case GDK_KEY_Page_Up:
+ case GDK_KEY_Page_Down:
+ if (!(location_action->popup && gtk_widget_get_visible (location_action->popup)))
+ return TRUE;
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
{
@@ -1040,12 +958,7 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
case GDK_KEY_KP_Up:
case GDK_KEY_Tab:
case GDK_KEY_ISO_Left_Tab:
- case GDK_KEY_Page_Down:
- case GDK_KEY_Page_Up:
{
- if ((event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down) &&
- !(location_action->popup && gtk_widget_get_visible (location_action->popup)))
- return TRUE;
if (location_action->popup && gtk_widget_get_visible (location_action->popup))
{
GtkTreeModel* model = location_action->completion_model;
@@ -1055,62 +968,35 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
gint selected = location_action->completion_index;
if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down
- || ((event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)
- && !(event->state & GDK_SHIFT_MASK)))
- {
- selected = selected + 1;
- if (selected == matches)
- selected = -1;
- }
- else if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up
- || ((event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)
- && (event->state & GDK_SHIFT_MASK)))
+ || event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)
+ selected = MIN (selected + 1, matches -1);
+ else if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
{
if (selected == -1)
selected = matches - 1;
else
- selected = selected - 1;
+ selected = MAX (selected - 1, 0);
}
else if (event->keyval == GDK_KEY_Page_Down)
- {
- if (selected == -1)
- selected = 0;
- else if (selected < matches - 1)
- selected = MIN (selected + 14, matches -1);
- else
- selected = -1;
- }
+ selected = MIN (selected + 14, matches -1);
else if (event->keyval == GDK_KEY_Page_Up)
- {
- if (selected == -1)
- selected = matches - 1;
- else if (selected > 0)
- selected = MAX (selected - 14, 0);
- else
- selected = -1;
- }
+ selected = MAX (selected - 14, 0);
else if (event->keyval != GDK_KEY_KP_Delete && event->keyval != GDK_KEY_Delete)
g_assert_not_reached ();
- if (selected != -1)
- {
- path = gtk_tree_path_new_from_indices (selected, -1);
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (location_action->treeview),
- path, NULL, FALSE);
- gtk_tree_path_free (path);
+ path = gtk_tree_path_new_from_indices (selected, -1);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (location_action->treeview),
+ path, NULL, FALSE);
+ gtk_tree_path_free (path);
- if (gtk_tree_model_iter_nth_child (model, &iter, NULL, selected))
- {
- gchar* uri;
- gtk_tree_model_get (model, &iter, URI_COL, &uri, -1);
- /* Update the layout without actually changing the text */
- pango_layout_set_text (gtk_entry_get_layout (entry), uri, -1);
- g_free (uri);
- }
+ if (gtk_tree_model_iter_nth_child (model, &iter, NULL, selected))
+ {
+ gchar* uri;
+ gtk_tree_model_get (model, &iter, URI_COL, &uri, -1);
+ /* Update the layout without actually changing the text */
+ pango_layout_set_text (gtk_entry_get_layout (entry), uri, -1);
+ g_free (uri);
}
- else
- gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (location_action->treeview)));
-
location_action->completion_index = selected;
return TRUE;
}
@@ -1174,237 +1060,12 @@ midori_location_action_focus_out_event_cb (GtkWidget* widget,
return FALSE;
}
-#ifdef HAVE_GCR
- #define GCR_API_SUBJECT_TO_CHANGE
- #include
-#endif
-
-#if defined (HAVE_LIBSOUP_2_34_0)
-static GHashTable* message_map = NULL;
-void
-midori_map_add_message (SoupMessage* message)
-{
- SoupURI* uri = soup_message_get_uri (message);
- if (message_map == NULL)
- message_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- g_return_if_fail (uri && uri->host);
- g_hash_table_insert (message_map, g_strdup (uri->host), g_object_ref (message));
-}
-
-SoupMessage*
-midori_map_get_message (SoupMessage* message)
-{
- SoupURI* uri = soup_message_get_uri (message);
- SoupMessage* full;
- g_return_val_if_fail (uri && uri->host, message);
- full = g_hash_table_lookup (message_map, uri->host);
- g_return_val_if_fail (full, message);
- return full;
-}
-
-#ifdef HAVE_GCR
-typedef enum {
- MIDORI_CERT_TRUST,
- MIDORI_CERT_REVOKE,
- MIDORI_CERT_EXPORT,
-} MidoriCertTrust;
-
-static void
-midori_location_action_cert_response_cb (GtkWidget* dialog,
- gint response,
- GcrCertificate* gcr_cert)
-{
- gchar* peer = g_object_get_data (G_OBJECT (gcr_cert), "peer");
- GError* error = NULL;
- if (response == MIDORI_CERT_TRUST)
- gcr_trust_add_pinned_certificate (gcr_cert, GCR_PURPOSE_SERVER_AUTH, peer, NULL, &error);
- else if (response == MIDORI_CERT_REVOKE)
- gcr_trust_remove_pinned_certificate (gcr_cert, GCR_PURPOSE_SERVER_AUTH, peer, NULL, &error);
- else if (response == MIDORI_CERT_EXPORT)
- {
- /* FIXME: Would be nice if GcrCertificateExporter became public */
- gchar* filename = g_strconcat (peer, ".crt", NULL);
- GtkWidget* dialog = sokoke_file_chooser_dialog_new (_("Export certificate"),
- NULL, GTK_FILE_CHOOSER_ACTION_SAVE);
- gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
- g_free (filename);
-
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
- {
- gsize n_data;
- gconstpointer data = gcr_certificate_get_der_data (gcr_cert, &n_data);
- g_return_if_fail (data);
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- g_file_set_contents (filename, data, n_data, NULL);
- g_free (filename);
- }
- gtk_widget_destroy (dialog);
- }
- if (error != NULL)
- {
- g_warning ("Error %s trust: %s", response == MIDORI_CERT_TRUST ?
- "granting" : "revoking", error->message);
- g_error_free (error);
- }
- gtk_widget_destroy (dialog);
-}
-#endif
-
-const gchar*
-midori_location_action_tls_flags_to_string (GTlsCertificateFlags tls_flags)
-{
- const gchar* tls_error;
- if (tls_flags & G_TLS_CERTIFICATE_UNKNOWN_CA)
- tls_error = _("The signing certificate authority is not known.");
- else if (tls_flags & G_TLS_CERTIFICATE_BAD_IDENTITY)
- tls_error = _("The certificate does not match the expected identity of the site that it was retrieved from.");
- else if(tls_flags & G_TLS_CERTIFICATE_NOT_ACTIVATED)
- tls_error = _("The certificate's activation time is still in the future.");
- else if (tls_flags & G_TLS_CERTIFICATE_EXPIRED)
- tls_error = _("The certificate has expired");
- else if (tls_flags & G_TLS_CERTIFICATE_REVOKED)
- tls_error = _("The certificate has been revoked according to the GTlsConnection's certificate revocation list.");
- else if (tls_flags & G_TLS_CERTIFICATE_INSECURE)
- tls_error = _("The certificate's algorithm is considered insecure.");
- else if (tls_flags & G_TLS_CERTIFICATE_GENERIC_ERROR)
- tls_error = _("Some other error occurred validating the certificate.");
- else
- tls_error = "Unknown GTLSCertificateFlags value";
- return tls_error;
-}
-
-void
-midori_location_action_show_page_info (GtkWidget* widget,
- GtkBox* box,
- GtkWidget* dialog)
-{
- MidoriBrowser* browser = midori_browser_get_for_widget (widget);
- MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
- WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
- WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (web_view);
- WebKitWebDataSource* source = webkit_web_frame_get_data_source (web_frame);
- WebKitNetworkRequest* request = webkit_web_data_source_get_request (source);
- SoupMessage* message = midori_map_get_message (webkit_network_request_get_message (request));
- GTlsCertificate* tls_cert;
- GTlsCertificateFlags tls_flags;
-
- g_return_if_fail (message);
- g_object_get (message, "tls-certificate", &tls_cert, "tls-errors", &tls_flags, NULL);
-
- if (tls_cert == NULL)
- return;
-
- #ifdef HAVE_GCR
- GByteArray* der_cert;
- GcrCertificate* gcr_cert;
- GtkWidget* details;
- SoupURI* uri = soup_message_get_uri (message);
-
- g_object_get (tls_cert, "certificate", &der_cert, NULL);
- gcr_cert = gcr_simple_certificate_new (
- der_cert->data, der_cert->len);
- g_byte_array_unref (der_cert);
- details = (GtkWidget*)gcr_certificate_details_widget_new (gcr_cert);
- gtk_widget_show (details);
- gtk_container_add (GTK_CONTAINER (box), details);
- if (gcr_trust_is_certificate_pinned (gcr_cert, GCR_PURPOSE_SERVER_AUTH, uri->host, NULL, NULL))
- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- ("_Don't trust this website"), MIDORI_CERT_REVOKE, NULL);
- else if (tls_flags > 0)
- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- ("_Trust this website"), MIDORI_CERT_TRUST, NULL);
- gtk_container_child_set (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
- gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Export certificate"), MIDORI_CERT_EXPORT),
- "secondary", TRUE, NULL);
-
- g_object_set_data_full (G_OBJECT (gcr_cert), "peer", g_strdup (uri->host), (GDestroyNotify)g_free);
- g_object_set_data_full (G_OBJECT (dialog), "gcr-cert", gcr_cert, (GDestroyNotify)g_object_unref);
- g_signal_connect (dialog, "response",
- G_CALLBACK (midori_location_action_cert_response_cb), gcr_cert);
- /* With GTK+2 the scrolled contents can't communicate a natural size to the window */
- #if !GTK_CHECK_VERSION (3, 0, 0)
- gtk_window_set_default_size (GTK_WINDOW (dialog), 250, 200);
- #endif
- #else
- const gchar* tls_error = midori_location_action_tls_flags_to_string (tls_flags);
-
- if (!g_tls_certificate_get_issuer (tls_cert))
- gtk_box_pack_start (box, gtk_label_new (_("Self-signed")), FALSE, FALSE, 0);
-
- gtk_box_pack_start (box, gtk_label_new (tls_error), FALSE, FALSE, 0);
- #endif
-
- g_object_unref (tls_cert);
-}
-#endif
-
-#ifndef HAVE_GRANITE
-static gboolean
-midori_location_action_dialog_focus_out_cb (GtkWidget* dialog,
- GdkEvent* event,
- gpointer user_data)
-{
- gtk_widget_destroy (dialog);
- return TRUE;
-}
-#endif
-
static void
midori_location_action_icon_released_cb (GtkWidget* widget,
GtkIconEntryPosition icon_pos,
gint button,
GtkAction* action)
{
- /* The dialog should "toggle" like a menu, as far as users go
- FIXME: Half-working: the dialog closes but re-opens */
- static GtkWidget* dialog = NULL;
- if (icon_pos == GTK_ICON_ENTRY_PRIMARY && dialog != NULL)
- gtk_widget_destroy (dialog);
-
- if (icon_pos == GTK_ICON_ENTRY_PRIMARY)
- {
- const gchar* title = _("Security details");
- GtkWidget* content_area;
- GtkWidget* hbox;
- #ifdef HAVE_GRANITE
- gint root_x, root_y;
- GdkRectangle icon_rect;
- /* FIXME: granite: should return GtkWidget* like GTK+ */
- dialog = (GtkWidget*)granite_widgets_pop_over_new ();
- gchar* markup = g_strdup_printf ("%s ", title);
- GtkWidget* label = gtk_label_new (markup);
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- g_free (markup);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- gtk_box_pack_start (GTK_BOX (content_area), label, FALSE, FALSE, 0);
- gtk_entry_get_icon_area (GTK_ENTRY (widget), icon_pos, &icon_rect);
- gdk_window_get_root_coords (gtk_widget_get_window (widget),
- icon_rect.x + icon_rect.width / 2, icon_rect.y + icon_rect.height,
- &root_x, &root_y);
- granite_widgets_pop_over_move_to_coords (GRANITE_WIDGETS_POP_OVER (dialog),
- root_x, root_y, TRUE);
- #else
- dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (gtk_widget_get_toplevel (widget)),
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, NULL, NULL);
- /* FIXME: check focus-in on the transient-for window instead of
- focus-out-event */
- g_signal_connect (dialog, "focus-out-event",
- G_CALLBACK (midori_location_action_dialog_focus_out_cb), NULL);
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- #endif
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), gtk_image_new_from_gicon (
- gtk_entry_get_icon_gicon (GTK_ENTRY (widget), icon_pos), GTK_ICON_SIZE_DIALOG), FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox),
- gtk_label_new (gtk_icon_entry_get_tooltip (GTK_ICON_ENTRY (widget), icon_pos)), FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (content_area), hbox, FALSE, FALSE, 0);
- #if defined (HAVE_LIBSOUP_2_34_0)
- midori_location_action_show_page_info (widget, GTK_BOX (content_area), dialog);
- #endif
- g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &dialog);
- gtk_widget_show_all (dialog);
- }
if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
{
gboolean result;
@@ -1758,7 +1419,7 @@ midori_location_action_get_text (MidoriLocationAction* location_action)
* @location_action: a #MidoriLocationAction
* @text: a string
*
- * Sets the entry text to @text.
+ * Sets the entry text to @text and, if applicable, updates the icon.
*
* Since: 0.2.0
**/
@@ -1767,6 +1428,7 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
const gchar* text)
{
GSList* proxies;
+ GdkPixbuf* icon;
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
g_return_if_fail (text != NULL);
@@ -1779,12 +1441,21 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
if (!(proxies = gtk_action_get_proxies (GTK_ACTION (location_action))))
return;
+ if (!(icon = katze_load_cached_icon (location_action->uri, NULL)))
+ icon = g_object_ref (location_action->default_icon);
+
for (; proxies != NULL; proxies = g_slist_next (proxies))
if (GTK_IS_TOOL_ITEM (proxies->data))
{
GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
gtk_entry_set_text (GTK_ENTRY (entry), text);
+ #if !HAVE_HILDON
+ gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_PRIMARY, icon);
+ #endif
}
+
+ g_object_unref (icon);
}
/**
@@ -1794,12 +1465,33 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
*
* Sets the icon shown on the left hand side.
*
- * Deprecated: 0.4.6: The left hand icon only shows security status.
+ * Note: Since 0.1.8 %NULL can be passed to indicate that the
+ * visible URI refers to a target, not the current location.
**/
void
midori_location_action_set_icon (MidoriLocationAction* location_action,
GdkPixbuf* icon)
{
+ #if !HAVE_HILDON
+ GSList* proxies;
+
+ g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
+ g_return_if_fail (!icon || GDK_IS_PIXBUF (icon));
+
+ proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
+
+ for (; proxies != NULL; proxies = g_slist_next (proxies))
+ if (GTK_IS_TOOL_ITEM (proxies->data))
+ {
+ GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
+ if (icon)
+ gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_PRIMARY, icon);
+ else
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_JUMP_TO);
+ }
+ #endif
}
void
@@ -1812,42 +1504,58 @@ midori_location_action_add_uri (MidoriLocationAction* location_action,
katze_assign (location_action->uri, g_strdup (uri));
}
-/**
- * midori_location_action_add_item:
- * @location_action: a #MidoriLocationAction
- * @icon: a #GdkPixbuf or %NULL
- * @title: a string
- *
- * Adds the item to the location, historically this added it to
- * completion suggestions and updated the left side icon.
- *
- * Deprecated: 0.4.6: The left hand icon only shows security status.
- **/
-
void
midori_location_action_add_item (MidoriLocationAction* location_action,
const gchar* uri,
GdkPixbuf* icon,
const gchar* title)
{
+ #if !HAVE_HILDON
+ GSList* proxies;
+ #endif
+
+ g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
+ g_return_if_fail (uri != NULL);
+ g_return_if_fail (title != NULL);
+ g_return_if_fail (!icon || GDK_IS_PIXBUF (icon));
+
+ #if !HAVE_HILDON
+ proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
+
+ for (; proxies != NULL; proxies = g_slist_next (proxies))
+ if (GTK_IS_TOOL_ITEM (proxies->data))
+ {
+ GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
+ gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_PRIMARY, icon);
+ }
+ #endif
}
-/**
- * midori_location_action_set_icon_for_uri:
- * @location_action: a #MidoriLocationAction
- * @icon: a #GdkPixbuf
- * @uri: an URI string
- *
- * Sets the icon for the specified URI.
- *
- * Deprecated: 0.4.4
- **/
void
midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action,
GdkPixbuf* icon,
const gchar* uri)
{
- midori_location_action_set_icon (location_action, icon);
+ #if !HAVE_HILDON
+ GSList* proxies;
+ #endif
+
+ g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
+ g_return_if_fail (!icon || GDK_IS_PIXBUF (icon));
+ g_return_if_fail (uri != NULL);
+
+ #if !HAVE_HILDON
+ proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
+
+ for (; proxies != NULL; proxies = g_slist_next (proxies))
+ if (GTK_IS_TOOL_ITEM (proxies->data))
+ {
+ GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
+ gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_PRIMARY, icon);
+ }
+ #endif
}
/**
@@ -1901,15 +1609,6 @@ midori_location_action_set_progress (MidoriLocationAction* location_action,
}
}
-/**
- * midori_location_action_set_security_hint:
- * @location_action: a #MidoriLocationAction
- * @icon: a stock ID, or an icon name
- *
- * Sets the secondary, ie right hand side icon.
- *
- * Since 0.4.6 @icon can be a stock ID or an icon name.
- **/
void
midori_location_action_set_secondary_icon (MidoriLocationAction* location_action,
const gchar* stock_id)
@@ -1920,6 +1619,7 @@ midori_location_action_set_secondary_icon (MidoriLocationAction* location_action
GtkStockItem stock_item;
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
+ g_return_if_fail (!stock_id || gtk_stock_lookup (stock_id, &stock_item));
katze_assign (location_action->secondary_icon, g_strdup (stock_id));
@@ -1930,12 +1630,8 @@ midori_location_action_set_secondary_icon (MidoriLocationAction* location_action
if (GTK_IS_TOOL_ITEM (proxies->data))
{
GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
- if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
- gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
- GTK_ICON_ENTRY_SECONDARY, stock_id);
- else
- gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
- GTK_ICON_ENTRY_SECONDARY, stock_id);
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY, stock_id);
}
#endif
}
@@ -1963,30 +1659,77 @@ midori_location_action_set_security_hint (MidoriLocationAction* location_action,
for (; proxies != NULL; proxies = g_slist_next (proxies))
if (GTK_IS_TOOL_ITEM (proxies->data))
{
+ const gchar* bg_color = NULL;
+ const gchar* fg_color = NULL;
GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
+ GdkScreen* screen = gtk_widget_get_screen (entry);
+ GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
if (hint == MIDORI_SECURITY_UNKNOWN)
{
- gchar* icon_names[] = { "channel-insecure-symbolic", "lock-insecure", "dialog-information", NULL };
- gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY,
- g_themed_icon_new_from_names (icon_names, -1));
+ bg_color = "#ef7070";
+ fg_color = "#000";
+ #if !HAVE_HILDON
+ if (gtk_icon_theme_has_icon (icon_theme, "channel-insecure-symbolic"))
+ gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY, "channel-insecure-symbolic");
+ else if (gtk_icon_theme_has_icon (icon_theme, "lock-insecure"))
+ gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY, "lock-insecure");
+ else
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_INFO);
gtk_icon_entry_set_tooltip (GTK_ICON_ENTRY (entry),
- GTK_ICON_ENTRY_PRIMARY, _("Not verified"));
+ GTK_ICON_ENTRY_SECONDARY, _("Not verified"));
+ #endif
}
else if (hint == MIDORI_SECURITY_TRUSTED)
{
- gchar* icon_names[] = { "channel-secure-symbolic", "lock-secure", "locked", NULL };
- gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY,
- g_themed_icon_new_from_names (icon_names, -1));
+ bg_color = "#d1eeb9";
+ fg_color = "#000";
+ #if !HAVE_HILDON
+ if (gtk_icon_theme_has_icon (icon_theme, "channel-secure-symbolic"))
+ gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY, "channel-secure-symbolic");
+ else if (gtk_icon_theme_has_icon (icon_theme, "lock-secure"))
+ gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY, "lock-secure");
+ else
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_DIALOG_AUTHENTICATION);
gtk_icon_entry_set_tooltip (GTK_ICON_ENTRY (entry),
- GTK_ICON_ENTRY_PRIMARY, _("Verified and encrypted connection"));
+ GTK_ICON_ENTRY_SECONDARY, _("Verified and encrypted connection"));
+ #endif
}
else if (hint == MIDORI_SECURITY_NONE)
- {
- gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY,
- g_themed_icon_new_with_default_fallbacks ("text-html-symbolic"));
gtk_icon_entry_set_tooltip (GTK_ICON_ENTRY (entry),
- GTK_ICON_ENTRY_PRIMARY, _("Open, unencrypted connection"));
+ GTK_ICON_ENTRY_SECONDARY, NULL);
+
+ {
+ #if GTK_CHECK_VERSION (3, 0, 0)
+ GtkStyleContext* context = gtk_widget_get_style_context (entry);
+ if (hint == MIDORI_SECURITY_UNKNOWN)
+ {
+ gtk_style_context_add_class (context, "security_unknown");
+ gtk_style_context_remove_class (context, "security_trusted");
+ }
+ else if (hint == MIDORI_SECURITY_TRUSTED)
+ {
+ gtk_style_context_add_class (context, "security_trusted");
+ gtk_style_context_remove_class (context, "security_unknown");
+ }
+ else if (hint == MIDORI_SECURITY_NONE)
+ {
+ gtk_style_context_remove_class (context, "security_unknown");
+ gtk_style_context_remove_class (context, "security_trusted");
+ }
+ #else
+ GdkColor color = { 0 };
+ if (bg_color) gdk_color_parse (bg_color, &color);
+ gtk_widget_modify_base (entry, GTK_STATE_NORMAL, bg_color ? &color : NULL);
+ if (fg_color) gdk_color_parse (fg_color, &color);
+ gtk_widget_modify_text (entry, GTK_STATE_NORMAL, fg_color ? &color : NULL);
+ #endif
}
}
}
diff --git a/midori/midori-panedaction.c b/midori/midori-panedaction.c
new file mode 100644
index 00000000..e858b8a5
--- /dev/null
+++ b/midori/midori-panedaction.c
@@ -0,0 +1,227 @@
+/*
+ Copyright (C) 2011 Peter Hatina
+
+ 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
+#include
+#include "midori-panedaction.h"
+
+struct _MidoriPanedActionChild
+{
+ GtkWidget* widget;
+ gchar* name;
+ gboolean resize;
+ gboolean shrink;
+};
+
+struct _MidoriPanedAction
+{
+ GtkAction parent_instance;
+ GtkWidget* hpaned;
+ GtkWidget* toolitem;
+ struct _MidoriPanedActionChild child1;
+ struct _MidoriPanedActionChild child2;
+};
+
+struct _MidoriPanedActionClass
+{
+ GtkActionClass parent_class;
+};
+
+G_DEFINE_TYPE (MidoriPanedAction, midori_paned_action, GTK_TYPE_ACTION);
+
+static GtkWidget*
+midori_paned_action_create_tool_item (GtkAction *action);
+
+static void
+midori_paned_action_finalize (GObject* object);
+
+static void
+midori_paned_action_init (MidoriPanedAction* paned_action)
+{
+ paned_action->hpaned = NULL;
+ paned_action->toolitem = NULL;
+ memset ((void*) &paned_action->child1, 0, sizeof (struct _MidoriPanedActionChild));
+ memset ((void*) &paned_action->child2, 0, sizeof (struct _MidoriPanedActionChild));
+}
+
+static void
+midori_paned_action_finalize (GObject* object)
+{
+ MidoriPanedAction* paned_action = MIDORI_PANED_ACTION (object);
+
+ g_object_unref (G_OBJECT (paned_action->toolitem));
+ g_object_unref (G_OBJECT (paned_action->hpaned));
+ katze_assign (paned_action->child1.name, NULL);
+ katze_assign (paned_action->child2.name, NULL);
+
+ G_OBJECT_CLASS (midori_paned_action_parent_class)->finalize (object);
+}
+
+static void
+midori_paned_action_class_init (MidoriPanedActionClass* class)
+{
+ GObjectClass* gobject_class;
+ GtkActionClass* action_class;
+
+ gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->finalize = midori_paned_action_finalize;
+
+ action_class = GTK_ACTION_CLASS (class);
+ action_class->create_tool_item = midori_paned_action_create_tool_item;
+}
+
+static GtkWidget*
+midori_paned_action_create_tool_item (GtkAction* action)
+{
+ MidoriPanedAction* paned_action = MIDORI_PANED_ACTION (action);
+ GtkWidget* alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
+ paned_action->hpaned = gtk_hpaned_new ();
+ paned_action->toolitem = GTK_WIDGET (gtk_tool_item_new ());
+ gtk_tool_item_set_expand (GTK_TOOL_ITEM (paned_action->toolitem), TRUE);
+ gtk_container_add (GTK_CONTAINER (paned_action->toolitem), alignment);
+ gtk_container_add (GTK_CONTAINER (alignment), GTK_WIDGET (paned_action->hpaned));
+
+ gtk_paned_pack1 (GTK_PANED (paned_action->hpaned),
+ paned_action->child1.widget,
+ paned_action->child1.resize,
+ paned_action->child1.shrink);
+ gtk_paned_pack2 (GTK_PANED (paned_action->hpaned),
+ paned_action->child2.widget,
+ paned_action->child2.resize,
+ paned_action->child2.shrink);
+
+ gtk_widget_show_all (GTK_WIDGET (paned_action->toolitem));
+ return paned_action->toolitem;
+}
+
+/**
+ * midori_paned_action_set_child1:
+ * @paned_action: a #MidoriPanedAction
+ * @child1: a #GtkWidget to be added into GtkHPaned container
+ * @name: string name for the child2
+ * @resize: should child1 expand when the MidoriPanedAction is resized
+ * @shrink: can child1 be made smaller than its requisition
+ **/
+void
+midori_paned_action_set_child1 (MidoriPanedAction* paned_action,
+ GtkWidget* child1,
+ const gchar* name,
+ gboolean resize,
+ gboolean shrink)
+{
+ g_return_if_fail (MIDORI_IS_PANED_ACTION (paned_action));
+
+ katze_assign (paned_action->child1.name, g_strdup (name));
+ paned_action->child1.widget = child1;
+ paned_action->child1.resize = resize;
+ paned_action->child1.shrink = shrink;
+}
+
+/**
+ * midori_paned_action_set_child1:
+ * @paned_action: a #MidoriPanedAction
+ * @child2: a #GtkWidget to be added into GtkHPaned container
+ * @name: string name for the child2
+ * @resize: should child2 expand when the MidoriPanedAction is resized
+ * @shrink: can child2 be made smaller than its requisition
+ **/
+void
+midori_paned_action_set_child2 (MidoriPanedAction* paned_action,
+ GtkWidget* child2,
+ const gchar* name,
+ gboolean resize,
+ gboolean shrink)
+{
+ g_return_if_fail (MIDORI_IS_PANED_ACTION (paned_action));
+
+ katze_assign (paned_action->child2.name, g_strdup (name));
+ paned_action->child2.widget = child2;
+ paned_action->child2.resize = resize;
+ paned_action->child2.shrink = shrink;
+}
+
+/**
+ * midori_paned_action_get_child1:
+ * @paned_action: a #MidoriPanedAction
+ *
+ * returns the first child held in GtkHPaned container
+ **/
+GtkWidget*
+midori_paned_action_get_child1 (MidoriPanedAction* paned_action)
+{
+ g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL);
+
+ return paned_action->child1.widget;
+}
+
+/**
+ * midori_paned_action_get_child1:
+ * @paned_action: a #MidoriPanedAction
+ *
+ * returns the second child held in GtkHPaned container
+ **/
+GtkWidget*
+midori_paned_action_get_child2 (MidoriPanedAction* paned_action)
+{
+ g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL);
+
+ return paned_action->child2.widget;
+}
+
+/**
+ * midori_paned_action_get_child1:
+ * @paned_action: a #MidoriPanedAction
+ * @name: string name for one of the children
+ *
+ * returns a child specified by its name
+ **/
+GtkWidget*
+midori_paned_action_get_child_by_name (MidoriPanedAction* paned_action,
+ const gchar* name)
+{
+ g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
+ if (g_strcmp0 (name, paned_action->child1.name) == 0)
+ return midori_paned_action_get_child1 (paned_action);
+ else if (g_strcmp0 (name, paned_action->child2.name) == 0)
+ return midori_paned_action_get_child2 (paned_action);
+
+ return NULL;
+}
+
+/**
+ * midori_paned_action_get_child1_name:
+ * @paned_action a #MidoriPanedAction
+ *
+ * Returns: The name of the first child
+ **/
+const gchar*
+midori_paned_action_get_child1_name (MidoriPanedAction* paned_action)
+{
+ g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL);
+
+ return paned_action->child1.name;
+}
+
+/**
+ * midori_paned_action_get_child2_name:
+ * @paned_action a #MidoriPanedAction
+ *
+ * Returns: The name of the second child
+ **/
+const gchar*
+midori_paned_action_get_child2_name (MidoriPanedAction* paned_action)
+{
+ g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL);
+
+ return paned_action->child2.name;
+}
diff --git a/midori/midori-panedaction.h b/midori/midori-panedaction.h
new file mode 100644
index 00000000..58444735
--- /dev/null
+++ b/midori/midori-panedaction.h
@@ -0,0 +1,70 @@
+/*
+ Copyright (C) 2011 Peter Hatina
+
+ 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 __MIDORI_PANED_ACTION_H__
+#define __MIDORI_PANED_ACTION_H__
+
+#include
+
+G_BEGIN_DECLS
+
+#define MIDORI_TYPE_PANED_ACTION \
+ (midori_paned_action_get_type ())
+#define MIDORI_PANED_ACTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_PANED_ACTION, MidoriPanedAction))
+#define MIDORI_PANED_ACTION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_PANED_ACTION, MidoriPanedActionClass))
+#define MIDORI_IS_PANED_ACTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_PANED_ACTION))
+#define MIDORI_IS_PANED_ACTION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_PANED_ACTION))
+#define MIDORI_PANED_ACTION_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_PANED_ACTION, MidoriPanedActionClass))
+
+typedef struct _MidoriPanedAction MidoriPanedAction;
+typedef struct _MidoriPanedActionClass MidoriPanedActionClass;
+
+GType
+midori_paned_action_get_type (void) G_GNUC_CONST;
+
+void
+midori_paned_action_set_child1 (MidoriPanedAction* paned_action,
+ GtkWidget* child1,
+ const gchar* name,
+ gboolean resize,
+ gboolean shrink);
+
+void
+midori_paned_action_set_child2 (MidoriPanedAction* paned_action,
+ GtkWidget* child2,
+ const gchar* name,
+ gboolean resize,
+ gboolean shrink);
+
+GtkWidget*
+midori_paned_action_get_child1 (MidoriPanedAction* paned_action);
+
+GtkWidget*
+midori_paned_action_get_child2 (MidoriPanedAction* paned_action);
+
+GtkWidget*
+midori_paned_action_get_child_by_name (MidoriPanedAction* paned_action,
+ const gchar* name);
+
+const gchar*
+midori_paned_action_get_child1_name (MidoriPanedAction* paned_action);
+
+const gchar*
+midori_paned_action_get_child2_name (MidoriPanedAction* paned_action);
+
+G_END_DECLS
+
+#endif // __MIDORI_PANED_ACTION_H__
diff --git a/midori/midori-panedaction.vala b/midori/midori-panedaction.vala
deleted file mode 100644
index dd7ecde3..00000000
--- a/midori/midori-panedaction.vala
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- Copyright (C) 2011 Peter Hatina
-
- 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.
-*/
-
-namespace Midori {
- public class PanedAction : Gtk.Action {
- Gtk.HPaned? hpaned = null;
- Gtk.ToolItem? toolitem = null;
- Child child1 = new Child();
- Child child2 = new Child();
-
- private struct Child {
- protected Gtk.Widget widget;
- string name;
- bool resize;
- bool shrink;
- }
-
- public override unowned Gtk.Widget create_tool_item () {
- Gtk.Alignment alignment = new Gtk.Alignment (0.0f, 0.5f, 1.0f, 0.1f);
- hpaned = new Gtk.HPaned ();
- toolitem = new Gtk.ToolItem ();
- toolitem.set_expand (true);
- toolitem.add (alignment);
- alignment.add (hpaned);
-
- hpaned.pack1 (child1.widget, child1.resize, child1.shrink);
- hpaned.pack2 (child2.widget, child2.resize, child2.shrink);
- toolitem.show_all ();
- return toolitem;
- }
-
- public void set_child1 (Gtk.Widget widget, string name, bool resize, bool shrink) {
- child1.widget = widget;
- child1.name = name;
- child1.resize = resize;
- child1.shrink = shrink;
- }
-
- public void set_child2 (Gtk.Widget widget, string name, bool resize, bool shrink) {
- child2.widget = widget;
- child2.name = name;
- child2.resize = resize;
- child2.shrink = shrink;
- }
-
- public Gtk.Widget? get_child1 () {
- return child1.widget;
- }
-
- public Gtk.Widget? get_child2 () {
- return child2.widget;
- }
-
- public Gtk.Widget? get_child_by_name (string name) {
- if (name == child1.name)
- return child1.widget;
- else if (name == child2.name)
- return child2.widget;
- return null;
- }
-
- public string get_child1_name () {
- return child1.name;
- }
-
- public string get_child2_name () {
- return child2.name;
- }
- }
-}
-
diff --git a/midori/midori-panel.c b/midori/midori-panel.c
index 22ec10c7..ffe110e6 100644
--- a/midori/midori-panel.c
+++ b/midori/midori-panel.c
@@ -253,6 +253,36 @@ static GtkWidget*
_midori_panel_child_for_scrolled (MidoriPanel* panel,
GtkWidget* scrolled);
+static gboolean
+midori_panel_detached_window_delete_event_cb (GtkWidget* window,
+ GdkEvent* event,
+ MidoriPanel* panel)
+{
+ /* FIXME: The panel will not end up at its original position */
+ /* FIXME: The menuitem may be mispositioned */
+ GtkWidget* vbox = gtk_bin_get_child (GTK_BIN (window));
+ GtkWidget* scrolled = g_object_get_data (G_OBJECT (window), "scrolled");
+ GtkWidget* toolbar = g_object_get_data (G_OBJECT (scrolled), "panel-toolbar");
+ GtkWidget* menuitem = g_object_get_data (G_OBJECT (scrolled), "panel-menuitem");
+ GtkWidget* viewable = _midori_panel_child_for_scrolled (panel, scrolled);
+ GtkToolItem* toolitem;
+ gint n;
+
+ g_object_ref (toolbar);
+ gtk_container_remove (GTK_CONTAINER (vbox), toolbar);
+ gtk_container_add (GTK_CONTAINER (panel->toolbook), toolbar);
+ g_object_unref (toolbar);
+ g_object_ref (scrolled);
+ gtk_container_remove (GTK_CONTAINER (vbox), scrolled);
+ n = gtk_notebook_append_page (GTK_NOTEBOOK (panel->notebook), scrolled, NULL);
+ g_object_unref (scrolled);
+ toolitem = midori_panel_construct_tool_item (panel, MIDORI_VIEWABLE (viewable));
+ if (menuitem)
+ g_object_set_data (G_OBJECT (menuitem), "toolitem", toolitem);
+ midori_panel_set_current_page (panel, n);
+ return FALSE;
+}
+
static void
midori_panel_widget_destroy_cb (GtkWidget* viewable,
GtkWidget* widget)
@@ -262,6 +292,57 @@ midori_panel_widget_destroy_cb (GtkWidget* viewable,
viewable, midori_panel_widget_destroy_cb, widget);
}
+static void
+midori_panel_detach_page (MidoriPanel* panel,
+ gint n)
+{
+ GtkToolItem* toolitem = gtk_toolbar_get_nth_item (
+ GTK_TOOLBAR (panel->toolbar), n);
+ const gchar* title = gtk_tool_button_get_label (GTK_TOOL_BUTTON (toolitem));
+ GtkWidget* toolbar = gtk_notebook_get_nth_page (
+ GTK_NOTEBOOK (panel->toolbook), n);
+ GtkWidget* scrolled = gtk_notebook_get_nth_page (
+ GTK_NOTEBOOK (panel->notebook), n);
+ GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
+ #if HAVE_HILDON
+ GtkWidget* window = hildon_window_new ();
+ hildon_program_add_window (hildon_program_get_instance (), HILDON_WINDOW (window));
+ #else
+ GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE);
+ gtk_window_set_default_size (GTK_WINDOW (window), 250, 400);
+ gtk_window_set_transient_for (GTK_WINDOW (window),
+ GTK_WINDOW (gtk_widget_get_toplevel (panel->notebook)));
+ #endif
+ gtk_widget_show (vbox);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ g_object_set_data (G_OBJECT (window), "scrolled", scrolled);
+ gtk_window_set_title (GTK_WINDOW (window), title);
+ g_signal_handlers_disconnect_by_func (
+ _midori_panel_child_for_scrolled (panel, scrolled),
+ midori_panel_widget_destroy_cb, toolitem);
+ gtk_container_remove (GTK_CONTAINER (panel->toolbar), GTK_WIDGET (toolitem));
+ g_object_ref (toolbar);
+ gtk_container_remove (GTK_CONTAINER (panel->toolbook), toolbar);
+ #if HAVE_HILDON
+ hildon_window_add_toolbar (HILDON_WINDOW (window), GTK_TOOLBAR (toolbar));
+ #else
+ gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
+ #endif
+ g_object_unref (toolbar);
+ g_object_set_data (G_OBJECT (scrolled), "panel-toolbar", toolbar);
+ g_object_ref (scrolled);
+ gtk_container_remove (GTK_CONTAINER (panel->notebook), scrolled);
+ gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
+ g_object_unref (scrolled);
+ midori_panel_set_current_page (panel, n > 0 ? n - 1 : 0);
+ toolitem = gtk_toolbar_get_nth_item (GTK_TOOLBAR (panel->toolbar),
+ n > 0 ? n - 1 : 0);
+ g_signal_connect (window, "delete-event",
+ G_CALLBACK (midori_panel_detached_window_delete_event_cb), panel);
+ gtk_widget_show (window);
+}
+
static void
midori_panel_button_align_clicked_cb (GtkWidget* toolitem,
MidoriPanel* panel)
@@ -300,7 +381,6 @@ midori_panel_init (MidoriPanel* panel)
/* Create the titlebar */
labelbar = gtk_toolbar_new ();
- katze_widget_add_class (labelbar, "secondary-toolbar");
panel->labelbar = labelbar;
gtk_toolbar_set_icon_size (GTK_TOOLBAR (labelbar), GTK_ICON_SIZE_MENU);
gtk_toolbar_set_style (GTK_TOOLBAR (labelbar), GTK_TOOLBAR_ICONS);
@@ -346,7 +426,6 @@ midori_panel_init (MidoriPanel* panel)
/* Create the notebook */
panel->notebook = gtk_notebook_new ();
- katze_widget_add_class (panel->notebook, "content-view");
gtk_notebook_set_show_border (GTK_NOTEBOOK (panel->notebook), FALSE);
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (panel->notebook), FALSE);
panel->frame = gtk_frame_new (NULL);
@@ -491,15 +570,13 @@ midori_panel_set_right_aligned (MidoriPanel* panel,
/* Private function, used by MidoriBrowser */
/* static */ GtkWidget*
midori_panel_construct_menu_item (MidoriPanel* panel,
- MidoriViewable* viewable,
- gboolean popup)
+ MidoriViewable* viewable)
{
GtkAction* action;
GtkWidget* menuitem;
action = g_object_get_data (G_OBJECT (viewable), "midori-panel-action");
- menuitem = popup ? sokoke_action_create_popup_menu_item (action)
- : gtk_action_create_menu_item (action);
+ menuitem = gtk_action_create_menu_item (action);
g_object_set_data (G_OBJECT (menuitem), "page", viewable);
if (gtk_widget_get_visible (GTK_WIDGET (viewable)))
@@ -561,9 +638,24 @@ midori_panel_action_activate_cb (GtkRadioAction* action,
GtkWidget* viewable = g_object_get_data (G_OBJECT (action), "viewable");
gint n = midori_panel_page_num (panel, viewable);
- midori_panel_set_current_page (panel, n);
- g_signal_emit (panel, signals[SWITCH_PAGE], 0, n);
- gtk_widget_show (GTK_WIDGET (panel));
+ /* If the panel is detached, focus the window */
+ if (n == -1)
+ {
+ GtkWidget* toplevel = gtk_widget_get_toplevel (viewable);
+ gtk_window_present (GTK_WINDOW (toplevel));
+ return;
+ }
+
+ if (panel->open_panels_in_windows
+ && gtk_radio_action_get_current_value (action)
+ == katze_object_get_int (action, "value"))
+ midori_panel_detach_page (panel, n);
+ else
+ {
+ midori_panel_set_current_page (panel, n);
+ g_signal_emit (panel, signals[SWITCH_PAGE], 0, n);
+ gtk_widget_show (GTK_WIDGET (panel));
+ }
}
/**
@@ -618,7 +710,7 @@ midori_panel_append_page (MidoriPanel* panel,
{
scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_NEVER,
+ GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_widget_set_can_focus (scrolled, TRUE);
gtk_widget_show (scrolled);
diff --git a/midori/midori-panel.h b/midori/midori-panel.h
index c5cd2756..87166674 100644
--- a/midori/midori-panel.h
+++ b/midori/midori-panel.h
@@ -12,7 +12,11 @@
#ifndef __MIDORI_PANEL_H__
#define __MIDORI_PANEL_H__
-#include "midori-core.h"
+#include
+
+#include
+
+#include "midori-viewable.h"
G_BEGIN_DECLS
diff --git a/midori/midori-platform.h b/midori/midori-platform.h
index b74339af..e974ed81 100644
--- a/midori/midori-platform.h
+++ b/midori/midori-platform.h
@@ -33,11 +33,15 @@
#endif
#define MIDORI_EVENT_NEW_TAB(evt) \
- (evt != NULL \
- && ((((GdkEventButton*)evt)->button == 1 \
- && MIDORI_MOD_NEW_TAB(((GdkEventButton*)evt)->state)) \
- || (((GdkEventButton*)evt)->button == 2)))
+ ((((GdkEventButton*)evt)->button == 1 \
+ && MIDORI_MOD_NEW_TAB(((GdkEventButton*)evt)->state)) \
+ || (((GdkEventButton*)evt)->button == 2))
+
+#ifndef G_OS_WIN32
+ #define MIDORI_MODULE_PREFIX "lib"
+#else
+ #define MIDORI_MODULE_PREFIX ""
+#endif
-#define MIDORI_MODULE_PREFIX "lib"
#endif /* !__MIDORI_PLATFORM_H__ */
diff --git a/midori/midori-preferences.c b/midori/midori-preferences.c
index cbdf69bb..6bfe1218 100644
--- a/midori/midori-preferences.c
+++ b/midori/midori-preferences.c
@@ -11,8 +11,6 @@
#include "midori-preferences.h"
-#include "midori-app.h"
-#include "midori-core.h"
#include "midori-platform.h"
#include
@@ -294,7 +292,7 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
#define SPANNED_ADD(__widget) \
katze_preferences_add_widget (_preferences, __widget, "spanned")
/* Page "General" */
- if (!midori_paths_is_readonly ())
+ if (!sokoke_is_app_or_private ())
{
PAGE_NEW (GTK_STOCK_HOME, _("Startup"));
FRAME_NEW (NULL);
@@ -302,8 +300,7 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
INDENTED_ADD (label);
button = katze_property_proxy (settings, "load-on-startup", NULL);
SPANNED_ADD (button);
- label = gtk_label_new (_("Homepage:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ label = katze_property_label (settings, "homepage");
INDENTED_ADD (label);
entry = katze_property_proxy (settings, "homepage", "address");
SPANNED_ADD (entry);
@@ -353,8 +350,7 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
button = katze_property_proxy (settings, "enforce-font-family", NULL);
INDENTED_ADD (button);
#endif
- label = gtk_label_new (_("Preferred Encoding"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ label = katze_property_label (settings, "preferred-encoding");
INDENTED_ADD (label);
button = katze_property_proxy (settings, "preferred-encoding", "custom-default-encoding");
SPANNED_ADD (button);
@@ -364,14 +360,12 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
FRAME_NEW (NULL);
#if !HAVE_HILDON
button = katze_property_proxy (settings, "auto-load-images", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Load images automatically"));
INDENTED_ADD (button);
button = katze_property_proxy (settings, "enable-spell-checking", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Enable Spell Checking"));
SPANNED_ADD (button);
/* Disable spell check option if there are no enchant modules */
{
- gchar* enchant_path = midori_paths_get_lib_path ("enchant");
+ gchar* enchant_path = sokoke_find_lib_path ("enchant");
if (enchant_path == NULL)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
@@ -381,15 +375,11 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
g_free (enchant_path);
}
button = katze_property_proxy (settings, "enable-scripts", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Enable scripts"));
INDENTED_ADD (button);
button = katze_property_proxy (settings, "enable-plugins", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Enable Netscape plugins"));
- gtk_widget_set_sensitive (button, midori_web_settings_has_plugin_support ());
SPANNED_ADD (button);
#endif
button = katze_property_proxy (settings, "zoom-text-and-images", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Zoom Text and Images"));
INDENTED_ADD (button);
button = katze_property_proxy (settings, "javascript-can-open-windows-automatically", NULL);
gtk_button_set_label (GTK_BUTTON (button), _("Allow scripts to open popups"));
@@ -397,42 +387,23 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
SPANNED_ADD (button);
if (katze_widget_has_touchscreen_mode (parent ?
GTK_WIDGET (parent) : GTK_WIDGET (preferences)))
- {
button = katze_property_proxy (settings, "kinetic-scrolling", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Kinetic scrolling"));
- gtk_widget_set_tooltip_text (button, _("Whether scrolling should kinetically move according to speed"));
- }
else
- {
button = katze_property_proxy (settings, "middle-click-opens-selection", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Middle click opens Selection"));
- gtk_widget_set_tooltip_text (button, _("Load an address from the selection via middle click"));
- }
INDENTED_ADD (button);
- if (katze_object_has_property (settings, "enable-webgl"))
- {
- button = katze_property_proxy (settings, "enable-webgl", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Enable WebGL support"));
- SPANNED_ADD (button);
- }
- #ifndef G_OS_WIN32
button = katze_property_proxy (settings, "flash-window-on-new-bg-tabs", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Flash window on background tabs"));
- INDENTED_ADD (button);
- #endif
-
+ SPANNED_ADD (button);
FRAME_NEW (NULL);
- button = gtk_label_new (_("Preferred languages"));
- gtk_misc_set_alignment (GTK_MISC (button), 0.0, 0.5);
+ button = katze_property_label (settings, "preferred-languages");
INDENTED_ADD (button);
entry = katze_property_proxy (settings, "preferred-languages", "languages");
- gtk_widget_set_tooltip_text (entry, _("A comma separated list of languages preferred for rendering multilingual webpages, for example \"de\", \"ru,nl\" or \"en-us;q=1.0, fr-fr;q=0.667\""));
SPANNED_ADD (entry);
- label = gtk_label_new (_("Save downloaded files to:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ #if !HAVE_HILDON
+ label = katze_property_label (settings, "download-folder");
INDENTED_ADD (label);
button = katze_property_proxy (settings, "download-folder", "folder");
SPANNED_ADD (button);
+ #endif
/* Page "Interface" */
PAGE_NEW (GTK_STOCK_CONVERT, _("Browsing"));
@@ -450,51 +421,45 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
INDENTED_ADD (label);
button = katze_property_proxy (settings, "open-new-pages-in", NULL);
SPANNED_ADD (button);
- button = katze_property_proxy (settings, "close-buttons-on-tabs", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Close Buttons on Tabs"));
- INDENTED_ADD (button);
- #ifndef HAVE_GRANITE
+ #if !HAVE_HILDON
button = katze_property_proxy (settings, "always-show-tabbar", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Always Show Tabbar"));
+ INDENTED_ADD (button);
+ button = katze_property_proxy (settings, "close-buttons-on-tabs", NULL);
SPANNED_ADD (button);
#endif
button = katze_property_proxy (settings, "open-tabs-next-to-current", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Open Tabs next to Current"));
- gtk_widget_set_tooltip_text (button, _("Whether to open new tabs next to the current tab or after the last one"));
INDENTED_ADD (button);
button = katze_property_proxy (settings, "open-tabs-in-the-background", NULL);
- gtk_button_set_label (GTK_BUTTON (button), _("Open tabs in the background"));
SPANNED_ADD (button);
-
+ #if !HAVE_HILDON
INDENTED_ADD (gtk_label_new (NULL));
- label = gtk_label_new (_("Text Editor"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ label = katze_property_label (settings, "text-editor");
INDENTED_ADD (label);
entry = katze_property_proxy (settings, "text-editor", "application-text/plain");
SPANNED_ADD (entry);
- label = gtk_label_new (_("News Aggregator"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ label = katze_property_label (settings, "news-aggregator");
INDENTED_ADD (label);
entry = katze_property_proxy (settings, "news-aggregator", "application-News");
SPANNED_ADD (entry);
+ #endif
/* Page "Network" */
PAGE_NEW (GTK_STOCK_NETWORK, _("Network"));
FRAME_NEW (NULL);
- label = gtk_label_new (_("Proxy server"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ #if !HAVE_HILDON
+ label = katze_property_label (settings, "proxy-type");
INDENTED_ADD (label);
button = katze_property_proxy (settings, "proxy-type", NULL);
SPANNED_ADD (button);
label = gtk_label_new (_("Hostname"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
INDENTED_ADD (label);
- entry = katze_property_proxy (settings, "http-proxy", "address");
+ entry = katze_property_proxy (settings, "http-proxy", NULL);
SPANNED_ADD (entry);
g_signal_connect (settings, "notify::proxy-type",
G_CALLBACK (midori_preferences_notify_proxy_type_cb), entry);
midori_preferences_notify_proxy_type_cb (settings, NULL, entry);
- label = gtk_label_new (_("Port"));
+ label = katze_property_label (settings, "http-proxy-port");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
INDENTED_ADD (label);
entry = katze_property_proxy (settings, "http-proxy-port", NULL);
@@ -502,14 +467,13 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
g_signal_connect (settings, "notify::proxy-type",
G_CALLBACK (midori_preferences_notify_proxy_type_cb), entry);
midori_preferences_notify_proxy_type_cb (settings, NULL, entry);
+ #endif
#if WEBKIT_CHECK_VERSION (1, 3, 11)
if (soup_session_get_feature (webkit_get_default_session (), SOUP_TYPE_CACHE))
{
- label = gtk_label_new (_("Web Cache"));
- gtk_widget_set_tooltip_text (label, _("The maximum size of cached pages on disk"));
+ label = katze_property_label (settings, "maximum-cache-size");
INDENTED_ADD (label);
button = katze_property_proxy (settings, "maximum-cache-size", NULL);
- gtk_widget_set_tooltip_text (button, _("The maximum size of cached pages on disk"));
SPANNED_ADD (button);
label = gtk_label_new (_("MB"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c
index 7d01734c..00425812 100644
--- a/midori/midori-searchaction.c
+++ b/midori/midori-searchaction.c
@@ -311,7 +311,7 @@ midori_search_action_create_tool_item (GtkAction* action)
GtkWidget* alignment;
toolitem = GTK_WIDGET (gtk_tool_item_new ());
- entry = sokoke_search_entry_new (NULL);
+ entry = gtk_icon_entry_new ();
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (entry),
GTK_ICON_ENTRY_PRIMARY, TRUE);
alignment = gtk_alignment_new (0, 0.5, 1, 0.1);
@@ -432,7 +432,7 @@ midori_search_action_get_icon (KatzeItem* item,
else if (gtk_icon_theme_has_icon (icon_theme, "edit-find-option"))
*icon_name = "edit-find-option";
else
- *icon_name = STOCK_EDIT_FIND;
+ *icon_name = "edit-find";
return NULL;
}
@@ -876,189 +876,21 @@ midori_search_action_editor_name_changed_cb (GtkWidget* entry,
GTK_RESPONSE_ACCEPT, text && *text);
}
-gchar*
-midori_search_action_token_for_uri (const gchar* uri)
+static inline const gchar*
+STR_NON_NULL (const gchar* string)
{
- guint len, i;
- gchar** parts;
- gchar* hostname = NULL, *path = NULL;
-
- path = midori_uri_parse_hostname (uri, NULL);
- parts = g_strsplit (path, ".", -1);
- g_free (path);
-
- len = g_strv_length (parts);
- if (len > 2)
- {
- for (i = len; i == 0; i--)
- {
- if (parts[i] && *parts[i])
- if (strlen (parts[i]) > 3)
- {
- hostname = g_strdup (parts[i]);
- break;
- }
- }
- }
- else
- hostname = g_strdup (parts[0]);
-
- if (!hostname)
- hostname = g_strdup (parts[1]);
-
- g_strfreev (parts);
-
- if (strlen (hostname) > 4)
- {
- GString* str = g_string_new (NULL);
- int j, count = 0;
-
- for (j = 0; count < 4; j++)
- {
- if (hostname[j] == 'a'
- || hostname[j] == 'e'
- || hostname[j] == 'i'
- || hostname[j] == 'o'
- || hostname[j] == 'u')
- continue;
- else
- {
- g_string_append_c (str, hostname[j]);
- count++;
- }
- }
- return g_string_free (str, FALSE);
- }
- return g_strdup (hostname);
+ return string ? string : "";
}
-KatzeItem*
-midori_search_action_get_engine_for_form (WebKitWebView* web_view,
- PangoEllipsizeMode ellipsize)
-{
- #if WEBKIT_CHECK_VERSION (1, 5, 0)
- WebKitDOMDocument* doc;
- WebKitDOMHTMLFormElement* active_form;
- WebKitDOMHTMLCollection* form_nodes;
- WebKitDOMElement* active_element;
- gchar* token_element;
- const gchar* title;
- GString* uri_str;
- gulong form_len;
- const gchar* action;
- guint i;
- KatzeItem* item;
- gchar** parts;
-
- #if WEBKIT_CHECK_VERSION (1, 9, 5)
- doc = webkit_web_frame_get_dom_document (web_view);
- #else
- if (webkit_web_view_get_focused_frame (web_view) != webkit_web_view_get_main_frame (web_view))
- return NULL;
- doc = webkit_web_view_get_dom_document (web_view);
- #endif
-
- active_element = webkit_dom_html_document_get_active_element ((WebKitDOMHTMLDocument*)doc);
- active_form = webkit_dom_html_input_element_get_form ((WebKitDOMHTMLInputElement*)active_element);
-
- if (!active_form)
- return NULL;
-
- token_element = webkit_dom_element_get_attribute (active_element, "name");
-
- form_nodes = webkit_dom_html_form_element_get_elements (active_form);
- form_len = webkit_dom_html_form_element_get_length (active_form);
-
- /* action NULL or "": relative path */
- if ((action = webkit_dom_html_form_element_get_action (active_form)) && *action)
- uri_str = g_string_new (action);
- else
- {
- gchar* hostname = midori_uri_parse_hostname (webkit_web_view_get_uri (web_view), NULL);
- uri_str = g_string_new ("http://");
- g_string_append (uri_str, hostname);
- g_free (hostname);
- }
- g_string_append_c (uri_str, '?');
-
- for (i = 0; i < form_len; i++)
- {
- WebKitDOMNode* form_node = webkit_dom_html_collection_item (form_nodes, i);
- WebKitDOMElement* form_element = (WebKitDOMElement*) form_node;
- gchar* name = webkit_dom_element_get_attribute (form_element, "name");
-
- if (name && *name)
- {
- if (!g_strcmp0 (token_element, name))
- g_string_append_printf (uri_str, "%s=%s&", name, "\%s");
- else
- {
- gchar* value;
- if (!g_strcmp0 (webkit_dom_element_get_tag_name (form_element), "SELECT"))
- {
- WebKitDOMHTMLSelectElement* select_element = (WebKitDOMHTMLSelectElement*) form_element;
- gulong pos = webkit_dom_html_select_element_get_selected_index (select_element);
- WebKitDOMNode* selected_node = webkit_dom_html_select_element_item (select_element, pos);
- WebKitDOMElement* selected_element = (WebKitDOMElement*) selected_node;
-
- value = webkit_dom_element_get_attribute (selected_element, "value");
- }
- else
- value = webkit_dom_element_get_attribute (form_element, "value");
-
- g_string_append_printf (uri_str, "%s=%s&", name, value);
- g_free (value);
- }
- g_free (name);
- }
- }
-
- title = webkit_web_view_get_title (web_view);
-
- item = katze_item_new ();
- item->uri = g_string_free (uri_str, FALSE);
- item->token = midori_search_action_token_for_uri (webkit_web_view_get_uri (web_view));
-
- if (strstr (title, " - "))
- parts = g_strsplit (title, " - ", 2);
- else if (strstr (title, ": "))
- parts = g_strsplit (title, ": ", 2);
- else
- parts = NULL;
- if (parts != NULL)
- {
- /* See midori_view_set_title: title can be first or last */
- if (ellipsize == PANGO_ELLIPSIZE_END)
- {
- item->name = g_strdup (parts[0]);
- item->text = g_strdup (parts[1]);
- }
- else
- {
- item->name = g_strdup (parts[1]);
- item->text = g_strdup (parts[2]);
- }
- g_strfreev (parts);
- }
- else
- item->name = g_strdup (title);
-
- g_free (token_element);
- return item;
- #else
- return NULL;
- #endif
-}
-
-void
+static void
midori_search_action_get_editor (MidoriSearchAction* search_action,
- KatzeItem* item,
gboolean new_engine)
{
GtkWidget* toplevel;
GtkWidget* dialog;
GtkWidget* content_area;
GtkSizeGroup* sizegroup;
+ KatzeItem* item;
GtkWidget* hbox;
GtkWidget* label;
GtkTreeModel* liststore;
@@ -1067,6 +899,7 @@ midori_search_action_get_editor (MidoriSearchAction* search_action,
GtkWidget* entry_name;
GtkWidget* entry_description;
GtkWidget* entry_uri;
+ GtkWidget* entry_icon;
GtkWidget* entry_token;
toplevel = gtk_widget_get_toplevel (search_action->treeview);
@@ -1086,6 +919,7 @@ midori_search_action_get_editor (MidoriSearchAction* search_action,
if (new_engine)
{
+ item = katze_item_new ();
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GTK_RESPONSE_ACCEPT, FALSE);
}
@@ -1106,8 +940,9 @@ midori_search_action_get_editor (MidoriSearchAction* search_action,
g_signal_connect (entry_name, "changed",
G_CALLBACK (midori_search_action_editor_name_changed_cb), dialog);
gtk_entry_set_activates_default (GTK_ENTRY (entry_name), TRUE);
- gtk_entry_set_text (GTK_ENTRY (entry_name),
- katze_str_non_null (katze_item_get_name (item)));
+ if (!new_engine)
+ gtk_entry_set_text (GTK_ENTRY (entry_name),
+ STR_NON_NULL (katze_item_get_name (item)));
gtk_box_pack_start (GTK_BOX (hbox), entry_name, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (content_area), hbox);
gtk_widget_show_all (hbox);
@@ -1119,8 +954,9 @@ midori_search_action_get_editor (MidoriSearchAction* search_action,
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
entry_description = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (entry_description), TRUE);
- gtk_entry_set_text (GTK_ENTRY (entry_description)
- , katze_str_non_null (katze_item_get_text (item)));
+ if (!new_engine)
+ gtk_entry_set_text (GTK_ENTRY (entry_description)
+ , STR_NON_NULL (katze_item_get_text (item)));
gtk_box_pack_start (GTK_BOX (hbox), entry_description, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (content_area), hbox);
gtk_widget_show_all (hbox);
@@ -1136,14 +972,28 @@ midori_search_action_get_editor (MidoriSearchAction* search_action,
#else
NULL);
#endif
- g_object_set_data (G_OBJECT (entry_uri), "allow_%s", (void*)1);
gtk_entry_set_activates_default (GTK_ENTRY (entry_uri), TRUE);
- gtk_entry_set_text (GTK_ENTRY (entry_uri),
- katze_str_non_null (katze_item_get_uri (item)));
+ if (!new_engine)
+ gtk_entry_set_text (GTK_ENTRY (entry_uri)
+ , STR_NON_NULL (katze_item_get_uri (item)));
gtk_box_pack_start (GTK_BOX (hbox), entry_uri, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (content_area), hbox);
gtk_widget_show_all (hbox);
+ hbox = gtk_hbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
+ label = gtk_label_new_with_mnemonic (_("_Icon:"));
+ gtk_size_group_add_widget (sizegroup, label);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ entry_icon = gtk_entry_new ();
+ gtk_entry_set_activates_default (GTK_ENTRY (entry_icon), TRUE);
+ if (!new_engine)
+ gtk_entry_set_text (GTK_ENTRY (entry_icon)
+ , STR_NON_NULL (katze_item_get_icon (item)));
+ gtk_box_pack_start (GTK_BOX (hbox), entry_icon, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+ gtk_widget_show_all (hbox);
+
hbox = gtk_hbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
label = gtk_label_new_with_mnemonic (_("_Token:"));
@@ -1151,8 +1001,9 @@ midori_search_action_get_editor (MidoriSearchAction* search_action,
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
entry_token = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (entry_token), TRUE);
- gtk_entry_set_text (GTK_ENTRY (entry_token)
- , katze_str_non_null (katze_item_get_token (item)));
+ if (!new_engine)
+ gtk_entry_set_text (GTK_ENTRY (entry_token)
+ , STR_NON_NULL (katze_item_get_token (item)));
gtk_box_pack_start (GTK_BOX (hbox), entry_token, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (content_area), hbox);
gtk_widget_show_all (hbox);
@@ -1164,6 +1015,7 @@ midori_search_action_get_editor (MidoriSearchAction* search_action,
"name", gtk_entry_get_text (GTK_ENTRY (entry_name)),
"text", gtk_entry_get_text (GTK_ENTRY (entry_description)),
"uri", gtk_entry_get_text (GTK_ENTRY (entry_uri)),
+ "icon", gtk_entry_get_text (GTK_ENTRY (entry_icon)),
"token", gtk_entry_get_text (GTK_ENTRY (entry_token)),
NULL);
@@ -1188,7 +1040,7 @@ midori_search_action_activate_edit_cb (GtkTreeView *treeview,
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
if (gtk_tree_selection_get_selected (selection, NULL, NULL))
- midori_search_action_get_editor (search_action, NULL, FALSE);
+ midori_search_action_get_editor (search_action, FALSE);
}
@@ -1196,7 +1048,7 @@ static void
midori_search_action_dialog_add_cb (GtkWidget* widget,
MidoriSearchAction* search_action)
{
- midori_search_action_get_editor (search_action, katze_item_new (), TRUE);
+ midori_search_action_get_editor (search_action, TRUE);
}
static void
@@ -1209,7 +1061,7 @@ midori_search_action_dialog_edit_cb (GtkWidget* widget,
treeview = search_action->treeview;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
if (gtk_tree_selection_get_selected (selection, NULL, NULL))
- midori_search_action_get_editor (search_action, NULL, FALSE);
+ midori_search_action_get_editor (search_action, FALSE);
}
static void
@@ -1457,8 +1309,6 @@ midori_search_action_get_dialog (MidoriSearchAction* search_action)
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
#endif
NULL);
- katze_widget_add_class (gtk_dialog_get_widget_for_response (
- GTK_DIALOG (dialog), GTK_RESPONSE_HELP), "help_button");
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed), &search_action->dialog);
gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_PROPERTIES);
@@ -1493,11 +1343,6 @@ midori_search_action_get_dialog (MidoriSearchAction* search_action)
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
(GtkTreeCellDataFunc)midori_search_action_dialog_render_tick_cb,
treeview, NULL);
- renderer_text = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
- gtk_tree_view_column_set_cell_data_func (column, renderer_text,
- (GtkTreeCellDataFunc)midori_search_action_dialog_render_token,
- treeview, NULL);
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
@@ -1508,6 +1353,11 @@ midori_search_action_get_dialog (MidoriSearchAction* search_action)
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
(GtkTreeCellDataFunc)midori_search_action_dialog_render_text,
treeview, NULL);
+ renderer_text = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start (column, renderer_text, TRUE);
+ gtk_tree_view_column_set_cell_data_func (column, renderer_text,
+ (GtkTreeCellDataFunc)midori_search_action_dialog_render_token,
+ treeview, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
diff --git a/midori/midori-searchaction.h b/midori/midori-searchaction.h
index 1f1d2200..c8d0ed88 100644
--- a/midori/midori-searchaction.h
+++ b/midori/midori-searchaction.h
@@ -13,7 +13,6 @@
#define __MIDORI_SEARCH_ACTION_H__
#include
-#include
G_BEGIN_DECLS
@@ -73,15 +72,6 @@ midori_search_action_set_default_item (MidoriSearchAction* search_action,
GtkWidget*
midori_search_action_get_dialog (MidoriSearchAction* search_action);
-void
-midori_search_action_get_editor (MidoriSearchAction* search_action,
- KatzeItem* item,
- gboolean new_engine);
-
-KatzeItem*
-midori_search_action_get_engine_for_form (WebKitWebView* web_view,
- PangoEllipsizeMode ellipsize);
-
G_END_DECLS
#endif /* __MIDORI_SEARCH_ACTION_H__ */
diff --git a/midori/midori-settings.vala b/midori/midori-settings.vala
deleted file mode 100644
index 70d213c2..00000000
--- a/midori/midori-settings.vala
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- Copyright (C) 2008-2012 Christian Dywan
- Copyright (C) 2011 Peter Hatina
-
- 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.
-*/
-
-namespace Midori {
- [CCode (cprefix = "MIDORI_WINDOW_")]
- public enum WindowState {
- NORMAL,
- MINIMIZED,
- MAXIMIZED,
- FULLSCREEN
- }
- /* Since: 0.1.3 */
-
- public class Settings : WebKit.WebSettings {
- public bool remember_last_window_size { get; set; default = true; }
- public int last_window_width { get; set; default = 0; }
- public int last_window_height { get; set; default = 0; }
- public int last_panel_position { get; set; default = 0; }
- public int last_panel_page { get; set; default = 0; }
- public int last_web_search { get; set; default = 0; }
- /* Since: 0.4.3 */
- // [IntegerType (min = 10, max = int.max)]
- public int search_width { get; set; default = 200; }
- /* Since: 0.4.7 */
- public bool last_inspector_attached { get; set; default = false; }
- /* Since: 0.1.3 */
- public WindowState last_window_state { get; set; default = WindowState.NORMAL; }
-
- public string? location_entry_search { get; set; default = null; }
- /* Since: 0.1.7 */
- public int clear_private_data { get; set; default = 0; }
- /* Since: 0.2.9 */
- public string? clear_data { get; set; default = null; }
-
- public bool compact_sidepanel { get; set; default = false; }
- /* Since: 0.2.2 */
- public bool open_panels_in_windows { get; set; default = false; }
- /* Since: 0.1.3 */
- public bool right_align_sidepanel { get; set; default = false; }
-
- public bool show_menubar { get; set; default = false; }
- public bool show_navigationbar { get; set; default = true; }
- public bool show_bookmarkbar { get; set; default = false; }
- public bool show_panel { get; set; default = false; }
- public bool show_statusbar { get; set; default = true; }
- /* Since: 0.1.2 */
- public bool show_crash_dialog { get; set; default = true; }
- public string toolbar_items { get; set; default =
- "TabNew,Back,NextForward,ReloadStop,BookmarkAdd,Location,Search,Trash,CompactMenu"; }
- /* Since: 0.1.4 */
- // [Deprecated (since = "0.4.7")]
- public bool find_while_typing { get; set; default = false; }
-
- public bool open_popups_in_tabs { get; set; default = true; }
- /* Since: 0.1.3 */
- public bool zoom_text_and_images { get; set; default = true; }
- /* Since: 0.2.0 */
- public bool kinetic_scrolling { get; set; default = true; }
- public bool middle_click_opens_selection { get; set; default = true; }
- public bool flash_window_on_new_bg_tabs { get; set; default = false; }
-
- public bool close_buttons_on_tabs { get; set; default = true; }
- public bool open_tabs_in_the_background { get; set; default = true; }
- public bool open_tabs_next_to_current { get; set; default = true; }
- public bool always_show_tabbar { get; set; default = true; }
-
- public string homepage { get; set; default = "http://www.google.com"; }
- static string default_download_folder () {
- return Environment.get_user_special_dir (UserDirectory.DOWNLOAD)
- ?? Environment.get_home_dir ();
- }
- public string download_folder { get; set; default = default_download_folder (); }
- public string? text_editor { get; set; default = null; }
- /* Since: 0.1.6 */
- public string? news_aggregator { get; set; default = null; }
-
- public string http_proxy { get; set; default = null; }
- /* Since: 0.4.2 */
- // [IntegerType (min = 1, max = 65535)]
- public int http_proxy_port { get; set; default = 8080; }
- /* Since: 0.3.4 */
- // [IntegerType (min = 0, int.max)]
- public int maximum_cache_size { get; set; default = 100; }
- /* Since: 0.3.4 */
- public bool strip_referer { get; set; default = false; }
- /* Since: 0.4.2 */
- public bool first_party_cookies_only { get; set; default = true; }
- // [IntegerType (min = 0, int.max)]
- public int maximum_cookie_age { get; set; default = 30; }
- // [IntegerType (min = 0, int.max)]
- public int maximum_history_age { get; set; default = 30; }
-
- /* Since: 0.4.7 */
- public bool delay_saving (string property) {
- return property.has_prefix ("last-")
- || property == "user-stylesheet-uri"
- || property.has_suffix ("-width");
- }
- }
-}
diff --git a/midori/midori-speeddial.vala b/midori/midori-speeddial.vala
deleted file mode 100644
index 392257d3..00000000
--- a/midori/midori-speeddial.vala
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- Copyright (C) 2011-2012 Christian Dywan
-
- 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.
-*/
-
-namespace Katze {
- extern static string mkdir_with_parents (string pathname, int mode);
-}
-
-namespace Sokoke {
- extern static string js_script_eval (void* ctx, string script, void* error);
-}
-
-namespace Midori {
- public errordomain SpeedDialError {
- INVALID_MESSAGE,
- NO_ACTION,
- NO_ID,
- NO_URL,
- NO_TITLE,
- NO_ID2,
- INVALID_ACTION,
- }
-
- public class SpeedDial : GLib.Object {
- string filename;
- string? html = null;
- List thumb_queue = null;
- WebKit.WebView thumb_view = null;
- Spec? spec = null;
-
- public GLib.KeyFile keyfile;
- public bool close_buttons_left { get; set; default = false; }
- public signal void refresh ();
-
- public class Spec {
- public string dial_id;
- public string uri;
- public Spec (string dial_id, string uri) {
- this.dial_id = dial_id;
- this.uri = uri;
- }
- }
-
- public SpeedDial (string new_filename, string? fallback = null) {
- filename = new_filename;
- keyfile = new GLib.KeyFile ();
- try {
- keyfile.load_from_file (filename, GLib.KeyFileFlags.NONE);
- }
- catch (GLib.Error io_error) {
- string json;
- size_t len;
- try {
- FileUtils.get_contents (fallback ?? (filename + ".json"),
- out json, out len);
- }
- catch (GLib.Error fallback_error) {
- json = "'{}'";
- len = 4;
- }
-
- var script = new StringBuilder.sized (len);
- script.append ("var json = JSON.parse (");
- script.append_len (json, (ssize_t)len);
- script.append ("""
- );
- var keyfile = '';
- for (var i in json['shortcuts']) {
- var tile = json['shortcuts'][i];
- keyfile += '[Dial ' + tile['id'].substring (1) + ']\n'
- + 'uri=' + tile['href'] + '\n'
- + 'img=' + tile['img'] + '\n'
- + 'title=' + tile['title'] + '\n\n';
- }
- var columns = json['width'] ? json['width'] : 3;
- var rows = json['shortcuts'] ? json['shortcuts'].length / columns : 0;
- keyfile += '[settings]\n'
- + 'columns=' + columns + '\n'
- + 'rows=' + (rows > 3 ? rows : 3) + '\n\n';
- keyfile;
- """);
-
- try {
- keyfile.load_from_data (
- Sokoke.js_script_eval (null, script.str, null),
- -1, 0);
- }
- catch (GLib.Error eval_error) {
- GLib.critical ("Failed to parse %s as speed dial JSON: %s",
- fallback ?? (filename + ".json"), eval_error.message);
- }
- Katze.mkdir_with_parents (
- Path.build_path (Path.DIR_SEPARATOR_S,
- Environment.get_user_cache_dir (),
- "midori", "thumbnails"), 0700);
-
- foreach (string tile in keyfile.get_groups ()) {
- try {
- string img = keyfile.get_string (tile, "img");
- keyfile.remove_key (tile, "img");
- string uri = keyfile.get_string (tile, "uri");
- if (img != null && uri[0] != '\0' && uri[0] != '#') {
- uchar[] decoded = Base64.decode (img);
- FileUtils.set_data (build_thumbnail_path (uri), decoded);
- }
- }
- catch (GLib.Error img_error) {
- /* img and uri can be missing */
- }
- }
- }
- }
-
- public string get_next_free_slot (out uint count = null) {
- uint slot_count = 0;
- foreach (string tile in keyfile.get_groups ()) {
- try {
- if (keyfile.has_key (tile, "uri"))
- slot_count++;
- }
- catch (KeyFileError error) { }
- }
- if (&count != null)
- count = slot_count;
-
- uint slot = 1;
- while (slot <= slot_count) {
- string tile = "Dial %u".printf (slot);
- if (!keyfile.has_group (tile))
- return tile;
- slot++;
- }
-
- return "Dial %u".printf (slot_count + 1);
- }
-
- public void add (string uri, string title, Gdk.Pixbuf img) {
- string id = get_next_free_slot ();
- add_with_id (id, uri, title, img);
- }
-
- public void add_with_id (string id, string uri, string title, Gdk.Pixbuf img) {
- keyfile.set_string (id, "uri", uri);
- keyfile.set_string (id, "title", title);
-
- Katze.mkdir_with_parents (Path.build_path (Path.DIR_SEPARATOR_S,
- Paths.get_cache_dir (), "thumbnails"), 0700);
- string filename = build_thumbnail_path (uri);
- try {
- img.save (filename, "png", null, "compression", "7", null);
- }
- catch (Error error) {
- critical ("Failed to save speed dial thumbnail: %s", error.message);
- }
- save ();
- }
-
- string build_thumbnail_path (string filename) {
- string thumbnail = Checksum.compute_for_string (ChecksumType.MD5, filename) + ".png";
- return Path.build_filename (Paths.get_cache_dir (), "thumbnails", thumbnail);
- }
-
- public unowned string get_html () throws Error {
- bool load_missing = true;
-
- if (html != null)
- return html;
-
- string? head = null;
- string filename = Paths.get_res_filename ("speeddial-head.html");
- if (keyfile != null
- && FileUtils.get_contents (filename, out head, null)) {
- string header = head.replace ("{title}", _("Speed Dial")).
- replace ("{click_to_add}", _("Click to add a shortcut")).
- replace ("{enter_shortcut_address}", _("Enter shortcut address")).
- replace ("{enter_shortcut_name}", _("Enter shortcut title")).
- replace ("{are_you_sure}", _("Are you sure you want to delete this shortcut?"));
- var markup = new StringBuilder (header);
-
- uint slot_count = 1;
- string dial_id = get_next_free_slot (out slot_count);
- uint next_slot = dial_id.substring (5, -1).to_int ();
-
- /* Try to guess the best X by X grid size */
- uint grid_index = 3;
- while ((grid_index * grid_index) < slot_count)
- grid_index++;
-
- /* Percent width size of one slot */
- uint slot_size = (100 / grid_index);
-
- /* No editing in private/ app mode or without scripts */
- markup.append_printf (
- "%s%s" +
- "\n",
- Paths.is_readonly () ? "" : "",
- Paths.is_readonly () ? "" : " ",
- slot_size + 1, slot_size - 4);
-
- /* Combined width of slots should always be less than 100%.
- * Use half of the remaining percentage as a margin size */
- uint div_factor;
- if (slot_size * grid_index >= 100 && grid_index > 4)
- div_factor = 8;
- else
- div_factor = 2;
- uint margin = (100 - ((slot_size - 4) * grid_index)) / div_factor;
- if (margin > 9)
- margin = margin % 10;
-
- markup.append_printf (
- "", margin);
- if (close_buttons_left)
- markup.append_printf (
- "");
-
- foreach (string tile in keyfile.get_groups ()) {
- try {
- string uri = keyfile.get_string (tile, "uri");
- if (uri != null && uri.str ("://") != null && tile.has_prefix ("Dial ")) {
- string title = keyfile.get_string (tile, "title");
- string thumb_filename = build_thumbnail_path (uri);
- uint slot = tile.substring (5, -1).to_int ();
- string encoded;
- try {
- uint8[] thumb;
- FileUtils.get_data (thumb_filename, out thumb);
- encoded = Base64.encode (thumb);
- }
- catch (FileError error) {
- encoded = null;
- if (load_missing)
- get_thumb (tile, uri);
- }
- markup.append_printf ("""
-
-
-
-
%s
- """,
- slot, uri, encoded ?? "", title, title ?? "");
- }
- else if (tile != "settings")
- keyfile.remove_group (tile);
- }
- catch (KeyFileError error) { }
- }
-
- markup.append_printf ("""
-
- """,
- next_slot, _("Click to add a shortcut"));
- markup.append_printf (" \n\n\n");
- html = markup.str;
- }
- else
- html = "";
-
- return html;
- }
-
- public void save_message (string message) throws Error {
- if (!message.has_prefix ("speed_dial-save-"))
- throw new SpeedDialError.INVALID_MESSAGE ("Invalid message '%s'", message);
-
- string msg = message.substring (16, -1);
- string[] parts = msg.split (" ", 4);
- if (parts[0] == null)
- throw new SpeedDialError.NO_ACTION ("No action.");
- string action = parts[0];
-
- if (parts[1] == null)
- throw new SpeedDialError.NO_ID ("No ID argument.");
- string dial_id = "Dial " + parts[1];
-
- if (action == "delete") {
- string uri = keyfile.get_string (dial_id, "uri");
- string file_path = build_thumbnail_path (uri);
- keyfile.remove_group (dial_id);
- FileUtils.unlink (file_path);
- }
- else if (action == "add") {
- if (parts[2] == null)
- throw new SpeedDialError.NO_URL ("No URL argument.");
- keyfile.set_string (dial_id, "uri", parts[2]);
- get_thumb (dial_id, parts[2]);
- }
- else if (action == "rename") {
- if (parts[2] == null)
- throw new SpeedDialError.NO_TITLE ("No title argument.");
- string title = parts[2];
- keyfile.set_string (dial_id, "title", title);
- }
- else if (action == "swap") {
- if (parts[2] == null)
- throw new SpeedDialError.NO_ID2 ("No ID2 argument.");
- string dial2_id = "Dial " + parts[2];
-
- string uri = keyfile.get_string (dial_id, "uri");
- string title = keyfile.get_string (dial_id, "title");
- string uri2 = keyfile.get_string (dial2_id, "uri");
- string title2 = keyfile.get_string (dial2_id, "title");
-
- keyfile.set_string (dial_id, "uri", uri2);
- keyfile.set_string (dial2_id, "uri", uri);
- keyfile.set_string (dial_id, "title", title2);
- keyfile.set_string (dial2_id, "title", title);
- }
- else
- throw new SpeedDialError.INVALID_ACTION ("Invalid action '%s'", action);
-
- save ();
- }
-
- void save () {
- html = null;
-
- try {
- FileUtils.set_contents (filename, keyfile.to_data ());
- }
- catch (Error error) {
- critical ("Failed to update speed dial: %s", error.message);
- }
- refresh ();
- }
-
- void load_status (GLib.Object thumb_view_, ParamSpec pspec) {
- if (thumb_view.load_status != WebKit.LoadStatus.FINISHED)
- return;
-
- return_if_fail (spec != null);
- #if HAVE_OFFSCREEN
- var img = (thumb_view.parent as Gtk.OffscreenWindow).get_pixbuf ();
- var pixbuf_scaled = img.scale_simple (240, 160, Gdk.InterpType.TILES);
- img = pixbuf_scaled;
- #else
- thumb_view.realize ();
- var img = midori_view_web_view_get_snapshot (thumb_view, 240, 160);
- #endif
- unowned string title = thumb_view.get_title ();
- add_with_id (spec.dial_id, spec.uri, title ?? spec.uri, img);
-
- thumb_queue.remove (spec);
- if (thumb_queue != null && thumb_queue.data != null) {
- spec = thumb_queue.data;
- thumb_view.load_uri (spec.uri);
- }
- else
- /* disconnect_by_func (thumb_view, load_status) */;
- }
-
- void get_thumb (string dial_id, string uri) {
- if (thumb_view == null) {
- thumb_view = new WebKit.WebView ();
- var settings = new WebKit.WebSettings ();
- settings. set ("enable-scripts", false,
- "enable-plugins", false,
- "auto-load-images", true,
- "enable-html5-database", false,
- "enable-html5-local-storage", false);
- if (settings.get_class ().find_property ("enable-java-applet") != null)
- settings.set ("enable-java-applet", false);
- thumb_view.settings = settings;
- #if HAVE_OFFSCREEN
- var offscreen = new Gtk.OffscreenWindow ();
- offscreen.add (thumb_view);
- thumb_view.set_size_request (800, 600);
- offscreen.show_all ();
- #else
- /* What we are doing here is a bit of a hack. In order to render a
- thumbnail we need a new view and load the url in it. But it has
- to be visible and packed in a container. So we secretly pack it
- into the notebook of the parent browser. */
- notebook.add (thumb_view);
- thumb_view.destroy.connect (Gtk.widget_destroyed);
- /* We use an empty label. It's not invisible but hard to spot. */
- notebook.set_tab_label (thumb_view, new Gtk.EventBox ());
- thumb_view.show ();
- #endif
- }
-
- thumb_queue.append (new Spec (dial_id, uri));
- if (thumb_queue.nth_data (1) != null)
- return;
-
- spec = thumb_queue.data;
- thumb_view.notify["load-status"].connect (load_status);
- thumb_view.load_uri (spec.uri);
- }
- }
-}
-
diff --git a/midori/midori-stock.h b/midori/midori-stock.h
index a28d3edf..7fe9f127 100644
--- a/midori/midori-stock.h
+++ b/midori/midori-stock.h
@@ -12,28 +12,42 @@
#ifndef __MIDORI_STOCK_H__
#define __MIDORI_STOCK_H__ 1
-/* Stock items */
+/* Custom stock items
+ We should distribute these
+ Names should match with epiphany and/ or xdg spec */
+
+#define STOCK_BOOKMARK "stock_bookmark"
#define STOCK_BOOKMARKS "user-bookmarks"
+#define STOCK_CONSOLE "terminal"
#define STOCK_EXTENSION "extension"
+#define STOCK_EXTENSIONS "extension"
#define STOCK_HISTORY "document-open-recent"
#define STOCK_WEB_BROWSER "web-browser"
-#define STOCK_NEWS_FEED "internet-news-reader"
-#define STOCK_STYLE "preferences-desktop-theme"
+#define STOCK_NEWS_FEED "news-feed"
+#define STOCK_STYLE "gnome-settings-theme"
#define STOCK_TRANSFER "package"
-#define STOCK_PLUGINS "application-x-shockwave-flash"
+#define STOCK_TRANSFERS "package"
+#define STOCK_PLUGINS "gnome-mime-application-x-shockwave-flash"
+
#define STOCK_BOOKMARK_ADD "bookmark-new"
-#define STOCK_IMAGE "image-x-generic"
+#define STOCK_HOMEPAGE "go-home"
+#define STOCK_IMAGE "gnome-mime-image"
#define STOCK_NETWORK_OFFLINE "network-offline"
-#define STOCK_SCRIPT "text-x-javascript"
-#define STOCK_SEND "mail-send"
-#define STOCK_TAB_NEW "tab-new"
-#define STOCK_USER_TRASH "user-trash"
-#define STOCK_WINDOW_NEW "window-new"
-#define STOCK_FOLDER_NEW "folder-new"
-#define STOCK_EDIT_CLEAR "edit-clear"
-#define STOCK_EDIT_FIND "edit-find"
-#define STOCK_STOP "stop"
-#define STOCK_URL "text-html"
+#define STOCK_SCRIPT "stock_script"
+#define STOCK_SCRIPTS "gnome-settings-theme"
+#define STOCK_SEND "stock_mail-send"
+#define STOCK_TAB_NEW "stock_new-tab"
+#define STOCK_USER_TRASH "gnome-stock-trash"
+#define STOCK_WINDOW_NEW "stock_new-window"
+
+#if defined (HAVE_HILDON) && HAVE_HILDON
+ #undef STOCK_BOOKMARKS
+ #define STOCK_BOOKMARKS "general_mybookmarks_folder"
+ #undef STOCK_NEWS_FEED
+ #define STOCK_NEWS_FEED "general_rss"
+ #undef STOCK_WEB_BROWSER
+ #define STOCK_WEB_BROWSER "general_web"
+#endif
#endif /* !__MIDORI_STOCK_H__ */
diff --git a/midori/midori-view.c b/midori/midori-view.c
index b3b6634b..b82939c0 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -13,27 +13,11 @@
#include "midori-view.h"
#include "midori-browser.h"
#include "midori-searchaction.h"
-#include "midori-app.h"
#include "midori-platform.h"
#include "midori-core.h"
-#include "midori-findbar.h"
#include "marshal.h"
-#include
-
-#ifdef HAVE_GRANITE
-#include
-#endif
-
-#ifdef HAVE_GCR
- #define GCR_API_SUBJECT_TO_CHANGE
- #include
-
-SoupMessage*
-midori_map_get_message (SoupMessage* message);
-#endif
-
#include
#include
#include
@@ -42,14 +26,10 @@ midori_map_get_message (SoupMessage* message);
#include
#include
+#include
#if HAVE_UNISTD_H
#include
#endif
-
-#include
-#include
-#include
-
#ifndef G_OS_WIN32
#include
#endif
@@ -77,14 +57,10 @@ midori_view_web_view_get_snapshot (GtkWidget* web_view,
gint width,
gint height);
-static gboolean
-midori_view_display_error (MidoriView* view,
- const gchar* uri,
- const gchar* title,
- const gchar* message,
- const gchar* description,
- const gchar* try_again,
- WebKitWebFrame* web_frame);
+static void
+midori_view_speed_dial_get_thumb (MidoriView* view,
+ gchar* dial_id,
+ gchar* url);
struct _MidoriView
{
@@ -103,7 +79,6 @@ struct _MidoriView
gchar* statusbar_text;
WebKitHitTestResult* hit_test;
gchar* link_uri;
- gboolean button_press_handled;
gboolean has_selection;
gchar* selected_text;
MidoriWebSettings* settings;
@@ -118,25 +93,15 @@ struct _MidoriView
gint alerts;
GtkWidget* menu_item;
- PangoEllipsizeMode ellipsize;
- #ifdef HAVE_GRANITE
- GraniteWidgetsTab* tab;
- #else
GtkWidget* tab_label;
GtkWidget* tab_icon;
GtkWidget* tab_title;
GtkWidget* tab_close;
- #endif
KatzeItem* item;
gint scrollh, scrollv;
gboolean back_forward_set;
+ GHashTable* memory;
GtkWidget* scrolled_window;
-
- #if GTK_CHECK_VERSION (3, 2, 0)
- GtkWidget* overlay;
- GtkWidget* overlay_label;
- GtkWidget* overlay_find;
- #endif
};
struct _MidoriViewClass
@@ -219,6 +184,10 @@ enum {
static guint signals[LAST_SIGNAL];
+static gchar* speeddial_markup = NULL;
+static GtkWidget* thumb_view = NULL;
+static GList* thumb_queue = NULL;
+
static void
midori_view_finalize (GObject* object);
@@ -243,6 +212,10 @@ midori_view_settings_notify_cb (MidoriWebSettings* settings,
GParamSpec* pspec,
MidoriView* view);
+static void
+midori_view_speed_dial_save (MidoriView* view,
+ const gchar* message);
+
static void
midori_view_class_init (MidoriViewClass* class)
{
@@ -519,7 +492,7 @@ midori_view_class_init (MidoriViewClass* class)
"mime-type",
"MIME Type",
"The MIME type of the currently loaded page",
- NULL,
+ "text/html",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
@@ -653,8 +626,12 @@ midori_view_set_title (MidoriView* view, const gchar* title)
#endif
display_title = midori_view_get_display_title (view);
+ if (view->tab_label)
+ {
/* If the title starts with the presumed name of the website, we
ellipsize differently, to emphasize the subtitle */
+ if (gtk_label_get_angle (GTK_LABEL (view->tab_title)) == 0.0)
+ {
SoupURI* uri = soup_uri_new (view->uri);
const gchar* host = uri ? (uri->host ? uri->host : "") : "";
const gchar* name = g_str_has_prefix (host, "www.") ? &host[4] : host;
@@ -663,25 +640,16 @@ midori_view_set_title (MidoriView* view, const gchar* title)
if (name[i] == '.')
break;
if (!g_ascii_strncasecmp (display_title, name, i))
- view->ellipsize = PANGO_ELLIPSIZE_START;
+ gtk_label_set_ellipsize (GTK_LABEL (view->tab_title), PANGO_ELLIPSIZE_START);
else
- view->ellipsize = PANGO_ELLIPSIZE_END;
+ gtk_label_set_ellipsize (GTK_LABEL (view->tab_title), PANGO_ELLIPSIZE_END);
if (uri)
soup_uri_free (uri);
- #ifdef HAVE_GRANITE
- if (view->tab)
- g_object_set (view->tab,
- "label", display_title, "ellipsize-mode", view->ellipsize, NULL);
- #else
- if (view->tab_label)
- {
+ }
gtk_label_set_text (GTK_LABEL (view->tab_title), display_title);
gtk_widget_set_tooltip_text (view->tab_icon, display_title);
gtk_widget_set_tooltip_text (view->tab_title, display_title);
- if (gtk_label_get_angle (GTK_LABEL (view->tab_title)) == 0.0)
- gtk_label_set_ellipsize (GTK_LABEL (view->tab_title), view->ellipsize);
}
- #endif
if (view->menu_item)
gtk_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (
view->menu_item))), display_title);
@@ -694,16 +662,9 @@ midori_view_apply_icon (MidoriView* view,
const gchar* icon_name)
{
katze_item_set_icon (view->item, icon_name);
- /* katze_item_get_image knows about this pixbuf */
- g_object_set_data_full (G_OBJECT (view->item), "pixbuf", g_object_ref (icon),
- (GDestroyNotify)g_object_unref);
katze_object_assign (view->icon, icon);
g_object_notify (G_OBJECT (view), "icon");
- #ifdef HAVE_GRANITE
- if (view->tab)
- g_object_set (view->tab, "icon", icon, NULL);
- #else
if (view->tab_icon)
{
if (icon_name && !strchr (icon_name, '/'))
@@ -713,82 +674,120 @@ midori_view_apply_icon (MidoriView* view,
katze_throbber_set_static_pixbuf (KATZE_THROBBER (view->tab_icon),
view->icon);
}
- #endif
if (view->menu_item)
{
- GtkWidget* image = katze_item_get_image (view->item);
+ GtkWidget* image;
+ if (icon_name && !strchr (icon_name, '/'))
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+ else
+ image = gtk_image_new_from_pixbuf (view->icon);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (view->menu_item), image);
}
}
+static gboolean
+midori_view_mime_icon (MidoriView* view,
+ GtkIconTheme* icon_theme,
+ const gchar* format,
+ const gchar* part1,
+ const gchar* part2)
+{
+ gchar* icon_name;
+ GdkPixbuf* icon;
+
+ icon_name = part2 ? g_strdup_printf (format, part1, part2)
+ : g_strdup_printf (format, part1);
+ if (!(icon = gtk_icon_theme_load_icon (icon_theme, icon_name, 16, 0, NULL)))
+ {
+ g_free (icon_name);
+ return FALSE;
+ }
+
+ g_object_ref (icon);
+ midori_view_apply_icon (view, icon, icon_name);
+ g_free (icon_name);
+ return TRUE;
+}
+
static void
-midori_view_unset_icon (MidoriView* view)
+midori_view_update_icon (MidoriView* view,
+ GdkPixbuf* icon)
{
GdkScreen* screen;
- GtkIconTheme* icon_theme;
- GIcon* icon;
- gchar** icon_names;
- GdkPixbuf* pixbuf = NULL;
-
- if (!((screen = gtk_widget_get_screen (view->web_view))
- && (icon_theme = gtk_icon_theme_get_for_screen (screen))))
- return;
+ GtkIconTheme* theme;
+ gchar** parts = NULL;
- if (view->mime_type != NULL)
+ if (icon)
{
- gchar* content_type = g_content_type_from_mime_type (view->mime_type);
- icon = g_content_type_get_icon (content_type);
- g_free (content_type);
- g_themed_icon_append_name (G_THEMED_ICON (icon), "text-html");
+ midori_view_apply_icon (view, icon, view->icon_uri);
+ return;
}
- else
- icon = g_themed_icon_new ("text-html");
- if ((icon_names = (gchar**)g_themed_icon_get_names (G_THEMED_ICON (icon))))
- while (*icon_names)
+ if (!((screen = gtk_widget_get_screen (GTK_WIDGET (view)))
+ && (theme = gtk_icon_theme_get_for_screen (screen))))
+ return;
+ if (view->mime_type == NULL)
+ return;
+
+ if (!((parts = g_strsplit (view->mime_type, "/", 2)) && (*parts && parts[1])))
{
- if ((pixbuf = gtk_icon_theme_load_icon (icon_theme, *icon_names, 16, 0, NULL)))
- break;
- icon_names++;
+ /* This is a hack to have a Find icon in the location while the
+ blank page has a File icon. */
+ icon = gtk_widget_render_icon (GTK_WIDGET (view),
+ GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL);
+ midori_view_apply_icon (view, icon, GTK_STOCK_FILE);
+ goto free_parts;
}
- g_object_unref (icon);
- midori_view_apply_icon (view, pixbuf, GTK_STOCK_FILE);
+ if (midori_view_mime_icon (view, theme, "%s-%s", *parts, parts[1]))
+ goto free_parts;
+ if (midori_view_mime_icon (view, theme, "gnome-mime-%s-%s", *parts, parts[1]))
+ goto free_parts;
+ if (midori_view_mime_icon (view, theme, "%s-x-generic", *parts, NULL))
+ goto free_parts;
+ if (midori_view_mime_icon (view, theme, "gnome-mime-%s-x-generic", *parts, NULL))
+ goto free_parts;
+
+ icon = gtk_widget_render_icon (GTK_WIDGET (view),
+ GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
+ midori_view_apply_icon (view, icon, NULL);
+
+free_parts:
+ g_strfreev (parts);
}
-#if !WEBKIT_CHECK_VERSION (1, 8, 0)
-static void
-katze_net_object_maybe_unref (gpointer object)
+typedef struct
{
- if (object)
- g_object_unref (object);
-}
+ gchar* icon_file;
+ gchar* icon_uri;
+ MidoriView* view;
+} KatzeNetIconPriv;
-static GHashTable*
-midori_view_get_memory (void)
+static void
+katze_net_icon_priv_free (KatzeNetIconPriv* priv)
{
- static GHashTable* memory = NULL;
- if (!memory)
- memory = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, katze_net_object_maybe_unref);
- return (memory);
+ g_free (priv->icon_file);
+ g_free (priv->icon_uri);
+ g_slice_free (KatzeNetIconPriv, priv);
}
static gboolean
katze_net_icon_status_cb (KatzeNetRequest* request,
- MidoriView* view)
+ KatzeNetIconPriv* priv)
{
switch (request->status)
{
case KATZE_NET_VERIFIED:
if (request->mime_type && strncmp (request->mime_type, "image/", 6))
{
+ katze_net_icon_priv_free (priv);
return FALSE;
}
break;
case KATZE_NET_MOVED:
break;
default:
+ katze_net_icon_priv_free (priv);
return FALSE;
}
return TRUE;
@@ -796,7 +795,7 @@ katze_net_icon_status_cb (KatzeNetRequest* request,
static void
katze_net_icon_transfer_cb (KatzeNetRequest* request,
- MidoriView* view)
+ KatzeNetIconPriv* priv)
{
GdkPixbuf* pixbuf;
FILE* fp;
@@ -811,62 +810,61 @@ katze_net_icon_transfer_cb (KatzeNetRequest* request,
pixbuf = NULL;
if (request->data)
{
- gchar* icon_file = katze_net_get_cached_path (NULL, view->icon_uri, "icons");
- if ((fp = fopen (icon_file, "wb")))
+ if ((fp = fopen (priv->icon_file, "wb")))
{
ret = fwrite (request->data, 1, request->length, fp);
fclose (fp);
if ((ret - request->length != 0))
{
g_warning ("Error writing to file %s "
- "in katze_net_icon_transfer_cb()", icon_file);
+ "in katze_net_icon_transfer_cb()", priv->icon_file);
}
+ pixbuf = gdk_pixbuf_new_from_file (priv->icon_file, NULL);
}
- g_free (icon_file);
-
- pixbuf = katze_pixbuf_new_from_buffer ((guchar*)request->data,
+ else
+ pixbuf = katze_pixbuf_new_from_buffer ((guchar*)request->data,
request->length, request->mime_type, NULL);
+ if (pixbuf)
+ g_object_ref (pixbuf);
+
+ g_hash_table_insert (priv->view->memory,
+ g_strdup (priv->icon_file), pixbuf);
}
if (!pixbuf)
{
- midori_view_unset_icon (view);
+ midori_view_update_icon (priv->view, NULL);
+ katze_net_icon_priv_free (priv);
return;
}
- g_hash_table_insert (midori_view_get_memory (), g_strdup (view->icon_uri), pixbuf);
- settings = gtk_widget_get_settings (view->web_view);
+ settings = gtk_widget_get_settings (priv->view->web_view);
gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, icon_width, icon_height, GDK_INTERP_BILINEAR);
- midori_view_apply_icon (view, pixbuf_scaled, view->icon_uri);
+
+ g_object_unref (pixbuf);
+
+ katze_assign (priv->view->icon_uri, g_strdup (priv->icon_uri));
+ midori_view_update_icon (priv->view, pixbuf_scaled);
+ katze_net_icon_priv_free (priv);
}
-#endif
static void
_midori_web_view_load_icon (MidoriView* view)
{
- GdkPixbuf* pixbuf = NULL;
+ GdkPixbuf* pixbuf;
+ gchar* icon_file;
gint icon_width, icon_height;
- GtkSettings* settings;
-
- #if WEBKIT_CHECK_VERSION (1, 8, 0)
- settings = gtk_widget_get_settings (view->web_view);
- gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
- &icon_width, &icon_height);
- if ((pixbuf = webkit_web_view_try_get_favicon_pixbuf (
- WEBKIT_WEB_VIEW (view->web_view), 16, 16)))
- midori_view_apply_icon (view, pixbuf, view->icon_uri);
- #else
GdkPixbuf* pixbuf_scaled;
+ GtkSettings* settings;
- if (!midori_uri_is_http (view->icon_uri))
- katze_assign (view->icon_uri, NULL);
+ pixbuf = NULL;
- if (midori_uri_is_http (view->uri) || g_str_has_prefix (view->uri, "file://"))
+ if (midori_uri_is_http (view->icon_uri) || midori_uri_is_http (view->uri))
{
- gchar* icon_file = NULL;
- if (!view->icon_uri)
+ gchar* icon_uri = g_strdup (view->icon_uri);
+ if (!icon_uri)
{
guint i = 8;
while (view->uri[i] != '\0' && view->uri[i] != '/')
@@ -874,33 +872,42 @@ _midori_web_view_load_icon (MidoriView* view)
if (view->uri[i] == '/')
{
gchar* path = g_strndup (view->uri, i);
- view->icon_uri = g_strdup_printf ("%s/favicon.ico", path);
+ icon_uri = g_strdup_printf ("%s/favicon.ico", path);
g_free (path);
}
else
- view->icon_uri = g_strdup_printf ("%s/favicon.ico", view->uri);
+ icon_uri = g_strdup_printf ("%s/favicon.ico", view->uri);
}
- if (g_hash_table_lookup_extended (midori_view_get_memory (),
- view->icon_uri, NULL, (gpointer)&pixbuf))
+ icon_file = katze_net_get_cached_path (NULL, icon_uri, "icons");
+ if (g_hash_table_lookup_extended (view->memory,
+ icon_file, NULL, (gpointer)&pixbuf))
{
- g_warn_if_fail (pixbuf != NULL);
- g_object_ref (pixbuf);
+ g_free (icon_file);
+ if (pixbuf)
+ {
+ g_object_ref (pixbuf);
+ katze_assign (view->icon_uri, icon_uri);
+ }
}
- else if ((icon_file = katze_net_get_cached_path (NULL, view->icon_uri, "icons")) &&
- (pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL)))
+ else if ((pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL)))
{
- g_hash_table_insert (midori_view_get_memory (),
- g_strdup (view->icon_uri), g_object_ref (pixbuf));
+ g_free (icon_file);
+ katze_assign (view->icon_uri, icon_uri);
}
else if (!view->special)
{
- katze_net_load_uri (NULL, view->icon_uri,
+ KatzeNetIconPriv* priv;
+
+ priv = g_slice_new (KatzeNetIconPriv);
+ priv->icon_file = icon_file;
+ priv->icon_uri = icon_uri;
+ priv->view = view;
+
+ katze_net_load_uri (NULL, icon_uri,
(KatzeNetStatusCb)katze_net_icon_status_cb,
- (KatzeNetTransferCb)katze_net_icon_transfer_cb, view);
+ (KatzeNetTransferCb)katze_net_icon_transfer_cb, priv);
}
-
- g_free (icon_file);
}
if (pixbuf)
@@ -912,9 +919,9 @@ _midori_web_view_load_icon (MidoriView* view)
icon_height, GDK_INTERP_BILINEAR);
g_object_unref (pixbuf);
pixbuf = pixbuf_scaled;
- midori_view_apply_icon (view, pixbuf, view->icon_uri);
}
- #endif
+
+ midori_view_update_icon (view, pixbuf);
}
static void
@@ -930,15 +937,9 @@ midori_view_update_load_status (MidoriView* view,
view->load_status = load_status;
g_object_notify (G_OBJECT (view), "load-status");
- #ifdef HAVE_GRANITE
- if (view->tab)
- g_object_set (view->tab, "working",
- midori_view_get_progress (view) > 0.0, NULL);
- #else
if (view->tab_icon)
katze_throbber_set_animated (KATZE_THROBBER (view->tab_icon),
- midori_view_get_progress (view) > 0.0);
- #endif
+ view->load_status != MIDORI_LOAD_FINISHED);
}
static gboolean
@@ -959,7 +960,7 @@ midori_view_web_view_navigation_decision_cb (WebKitWebView* web_view
g_free (new_uri);
return TRUE;
}
- else if (sokoke_external_uri (uri))
+ else if (g_str_has_prefix (uri, "mailto:") || sokoke_external_uri (uri))
{
if (sokoke_show_uri (gtk_widget_get_screen (GTK_WIDGET (web_view)),
uri, GDK_CURRENT_TIME, NULL))
@@ -968,61 +969,6 @@ midori_view_web_view_navigation_decision_cb (WebKitWebView* web_view
return TRUE;
}
}
- else if (g_str_has_prefix (uri, "data:image/"))
- {
- /* For security reasons, main content served as data: is limited to images
- http://lcamtuf.coredump.cx/switch/ */
- webkit_web_policy_decision_ignore (decision);
- return TRUE;
- }
- #ifdef HAVE_GCR
- else if (/* view->special && */ !strncmp (uri, "https", 5))
- {
- /* We show an error page if the certificate is invalid.
- If a "special", unverified page loads a form, it must be that page.
- if (webkit_web_navigation_action_get_reason (action) == WEBKIT_WEB_NAVIGATION_REASON_FORM_SUBMITTED)
- FIXME: Verify more stricly that this cannot be eg. a simple Reload */
- if (webkit_web_navigation_action_get_reason (action) == WEBKIT_WEB_NAVIGATION_REASON_RELOAD)
- {
- SoupMessage* message = webkit_network_request_get_message (request);
- if (!(soup_message_get_flags (message) & SOUP_MESSAGE_CERTIFICATE_TRUSTED))
- {
- SoupURI* soup_uri = soup_message_get_uri (message);
- GTlsCertificate* tls_cert;
- GcrCertificate* gcr_cert;
- GByteArray* der_cert;
-
- message = midori_map_get_message (message);
- g_object_get (message, "tls-certificate", &tls_cert, NULL);
- g_return_val_if_fail (tls_cert != NULL, FALSE);
- g_object_get (tls_cert, "certificate", &der_cert, NULL);
- gcr_cert = gcr_simple_certificate_new (der_cert->data, der_cert->len);
- g_byte_array_unref (der_cert);
- if (soup_uri && soup_uri->host && !gcr_trust_is_certificate_pinned (gcr_cert, GCR_PURPOSE_SERVER_AUTH, soup_uri->host, NULL, NULL))
- {
- GError* error = NULL;
- gcr_trust_add_pinned_certificate (gcr_cert, GCR_PURPOSE_SERVER_AUTH, soup_uri->host, NULL, &error);
- if (error != NULL)
- {
- gchar* slots = g_strjoinv (" , ", (gchar**)gcr_pkcs11_get_trust_lookup_uris ());
- gchar* title = g_strdup_printf ("Error granting trust: %s", error->message);
- midori_view_stop_loading (view);
- midori_view_display_error (view, view->uri,
- view->title ? view->title : view->uri, title, slots,
- _("Trust this website"), NULL);
- g_free (title);
- g_free (slots);
- g_error_free (error);
- }
- }
- else
- g_warn_if_reached ();
- g_object_unref (gcr_cert);
- g_object_unref (tls_cert);
- }
- }
- }
- #endif
view->special = FALSE;
/* Remove link labels */
@@ -1064,11 +1010,6 @@ webkit_web_view_load_started_cb (WebKitWebView* web_view,
g_object_thaw_notify (G_OBJECT (view));
}
-#ifdef HAVE_GCR
-const gchar*
-midori_location_action_tls_flags_to_string (GTlsCertificateFlags flags);
-#endif
-
static void
webkit_web_view_load_committed_cb (WebKitWebView* web_view,
WebKitWebFrame* web_frame,
@@ -1077,9 +1018,6 @@ webkit_web_view_load_committed_cb (WebKitWebView* web_view,
const gchar* uri;
GList* children;
- if (web_frame != webkit_web_view_get_main_frame (web_view))
- return;
-
g_object_freeze_notify (G_OBJECT (view));
uri = webkit_web_frame_get_uri (web_frame);
@@ -1105,7 +1043,7 @@ webkit_web_view_load_committed_cb (WebKitWebView* web_view,
g_object_notify (G_OBJECT (view), "uri");
g_object_set (view, "title", NULL, NULL);
- midori_view_unset_icon (view);
+ midori_view_update_icon (view, NULL);
if (!strncmp (uri, "https", 5))
{
@@ -1121,40 +1059,6 @@ webkit_web_view_load_committed_cb (WebKitWebView* web_view,
if (message
&& soup_message_get_flags (message) & SOUP_MESSAGE_CERTIFICATE_TRUSTED)
view->security = MIDORI_SECURITY_TRUSTED;
- #ifdef HAVE_GCR
- else if (!view->special && message != NULL)
- {
- GTlsCertificate* tls_cert;
- GcrCertificate* gcr_cert;
- GByteArray* der_cert;
- SoupURI* soup_uri;
-
- message = midori_map_get_message (message);
- g_object_get (message, "tls-certificate", &tls_cert, NULL);
- g_return_if_fail (tls_cert != NULL);
- g_object_get (tls_cert, "certificate", &der_cert, NULL);
- gcr_cert = gcr_simple_certificate_new (der_cert->data, der_cert->len);
- g_byte_array_unref (der_cert);
- soup_uri = soup_message_get_uri (message);
- if (gcr_trust_is_certificate_pinned (gcr_cert, GCR_PURPOSE_SERVER_AUTH, soup_uri->host, NULL, NULL))
- view->security = MIDORI_SECURITY_TRUSTED;
- else
- {
- GTlsCertificateFlags tls_flags;
- view->security = MIDORI_SECURITY_UNKNOWN;
- g_object_get (message, "tls-errors", &tls_flags, NULL);
- midori_view_stop_loading (view);
- midori_view_display_error (
- view, view->uri, view->title ? view->title : view->uri,
- _("Security unknown"),
- midori_location_action_tls_flags_to_string (tls_flags),
- _("Trust this website"),
- NULL);
- }
- g_object_unref (tls_cert);
- g_object_unref (gcr_cert);
- }
- #endif
else
#endif
view->security = MIDORI_SECURITY_UNKNOWN;
@@ -1190,12 +1094,12 @@ midori_view_web_view_resource_request_cb (WebKitWebView* web_view,
const gchar* uri = webkit_network_request_get_uri (request);
/* Only apply custom URIs to special pages for security purposes */
- if (!view->special && !midori_view_is_blank (view))
+ if (!view->special)
return;
if (g_str_has_prefix (uri, "res://"))
{
- gchar* filepath = midori_paths_get_res_filename (&uri[6]);
+ gchar* filepath = sokoke_find_data_filename (&uri[6], TRUE);
gchar* file_uri = g_filename_to_uri (filepath, NULL, NULL);
g_free (filepath);
webkit_network_request_set_uri (request, file_uri);
@@ -1211,14 +1115,10 @@ midori_view_web_view_resource_request_cb (WebKitWebView* web_view,
gint real_icon_size;
GtkIconInfo* icon_info;
const gchar* icon_filename;
- static gint icon_size_large_dialog = 0;
-
- if (!icon_size_large_dialog)
- icon_size_large_dialog = gtk_icon_size_register ("large-dialog", 64, 64);
if (g_ascii_isalpha (icon_name[0]))
icon_size = strstr (icon_name, "dialog") ?
- icon_size_large_dialog : GTK_ICON_SIZE_BUTTON;
+ GTK_ICON_SIZE_DIALOG : GTK_ICON_SIZE_BUTTON;
else if (g_ascii_isdigit (icon_name[0]))
{
guint i = 0;
@@ -1298,8 +1198,7 @@ midori_view_infobar_response_cb (GtkWidget* infobar,
{
void (*response_cb) (GtkWidget*, gint, gpointer);
response_cb = g_object_get_data (G_OBJECT (infobar), "midori-infobar-cb");
- if (response_cb != NULL)
- response_cb (infobar, response, data_object);
+ response_cb (infobar, response, data_object);
gtk_widget_destroy (infobar);
}
#else
@@ -1311,8 +1210,7 @@ midori_view_info_bar_button_cb (GtkWidget* button,
gint response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "midori-infobar-response"));
void (*response_cb) (GtkWidget*, gint, gpointer);
response_cb = g_object_get_data (G_OBJECT (infobar), "midori-infobar-cb");
- if (response_cb != NULL)
- response_cb (infobar, response, data_object);
+ response_cb (infobar, response, data_object);
gtk_widget_destroy (infobar);
}
#endif
@@ -1352,6 +1250,7 @@ midori_view_add_info_bar (MidoriView* view,
const gchar* button_text;
g_return_val_if_fail (message != NULL, NULL);
+ g_return_val_if_fail (response_cb != NULL, NULL);
va_start (args, first_button_text);
@@ -1428,32 +1327,15 @@ midori_view_web_view_database_quota_exceeded_cb (WebKitWebView* web_view,
MidoriView* view)
{
const gchar* uri = webkit_web_frame_get_uri (web_frame);
- MidoriSiteDataPolicy policy = midori_web_settings_get_site_data_policy (view->settings, uri);
-
- switch (policy)
- {
- case MIDORI_SITE_DATA_BLOCK:
- {
- WebKitSecurityOrigin* origin = webkit_web_database_get_security_origin (database);
- webkit_security_origin_set_web_database_quota (origin, 0);
- webkit_web_database_remove (database);
- }
- case MIDORI_SITE_DATA_ACCEPT:
- case MIDORI_SITE_DATA_PRESERVE:
- return;
- case MIDORI_SITE_DATA_UNDETERMINED:
- {
- gchar* hostname = midori_uri_parse_hostname (uri, NULL);
- gchar* message = g_strdup_printf (_("%s wants to save an HTML5 database."),
- hostname && *hostname ? hostname : uri);
- midori_view_add_info_bar (view, GTK_MESSAGE_QUESTION, message,
- G_CALLBACK (midori_view_database_response_cb), database,
- _("_Deny"), GTK_RESPONSE_REJECT, _("_Allow"), GTK_RESPONSE_ACCEPT,
- NULL);
- g_free (hostname);
- g_free (message);
- }
- }
+ gchar* hostname = midori_uri_parse_hostname (uri, NULL);
+ gchar* message = g_strdup_printf (_("%s wants to save an HTML5 database."),
+ hostname && *hostname ? hostname : uri);
+ midori_view_add_info_bar (view, GTK_MESSAGE_QUESTION, message,
+ G_CALLBACK (midori_view_database_response_cb), database,
+ _("_Deny"), GTK_RESPONSE_REJECT, _("_Allow"), GTK_RESPONSE_ACCEPT,
+ NULL);
+ g_free (hostname);
+ g_free (message);
}
#if WEBKIT_CHECK_VERSION (1, 1, 23)
@@ -1466,7 +1348,6 @@ midori_view_location_response_cb (GtkWidget* infobar,
webkit_geolocation_policy_allow (decision);
else
webkit_geolocation_policy_deny (decision);
- g_object_unref (decision);
}
static gboolean
@@ -1479,9 +1360,8 @@ midori_view_web_view_geolocation_decision_cb (WebKitWebView* w
gchar* hostname = midori_uri_parse_hostname (uri, NULL);
gchar* message = g_strdup_printf (_("%s wants to know your location."),
hostname && *hostname ? hostname : uri);
- /* FIXME: decision should be released even if neither buttons's pressed */
midori_view_add_info_bar (view, GTK_MESSAGE_QUESTION,
- message, G_CALLBACK (midori_view_location_response_cb), g_object_ref (decision),
+ message, G_CALLBACK (midori_view_location_response_cb), decision,
_("_Deny"), GTK_RESPONSE_REJECT, _("_Allow"), GTK_RESPONSE_ACCEPT,
NULL);
g_free (hostname);
@@ -1513,7 +1393,7 @@ midori_view_display_error (MidoriView* view,
const gchar* try_again,
WebKitWebFrame* web_frame)
{
- gchar* path = midori_paths_get_res_filename ("error.html");
+ gchar* path = sokoke_find_data_filename ("error.html", TRUE);
gchar* template;
if (g_file_get_contents (path, &template, NULL, NULL))
@@ -1525,8 +1405,6 @@ midori_view_display_error (MidoriView* view,
title_escaped = g_markup_escape_text (title, -1);
icon = katze_item_get_icon (view->item);
result = sokoke_replace_variables (template,
- "{dir}", gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL ?
- "rtl" : "ltr",
"{title}", title_escaped,
"{icon}", icon ? icon : "",
"{message}", message,
@@ -1561,15 +1439,13 @@ webkit_web_view_load_error_cb (WebKitWebView* web_view,
gchar* message;
gboolean result;
- /* The unholy trinity; also ignored in Webkit's default error handler */
switch (error->code)
{
case WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD:
/* A plugin will take over. That's expected, it's not fatal. */
+ return FALSE;
case WEBKIT_NETWORK_ERROR_CANCELLED:
/* Mostly initiated by JS redirects. */
- case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
- /* A frame load is cancelled because of a download. */
return FALSE;
}
@@ -1616,97 +1492,63 @@ webkit_web_view_load_finished_cb (WebKitWebView* web_view,
midori_view_apply_scroll_position (view);
- if (web_frame == webkit_web_view_get_main_frame (web_view))
+ view->progress = 1.0;
+ g_object_notify (G_OBJECT (view), "progress");
+ midori_view_update_load_status (view, MIDORI_LOAD_FINISHED);
+
+ if (1)
{
JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
- /* Icon: URI, News Feed: $URI|title, Search: :URI|title */
+ /* Join news feeds into like this: URI1|title1,URI2|title2 */
gchar* value = sokoke_js_script_eval (js_context,
- "(function (l) { var f = new Array (); for (var i in l) "
+ "(function (l) { var f = new Array (); for (i in l) "
"{ var t = l[i].type; var r = l[i].rel; "
"if (t && (t.indexOf ('rss') != -1 || t.indexOf ('atom') != -1)) "
- "f.push ('$' + l[i].href + '|' + l[i].title);"
- "else if (r == 'search' && t == 'application/opensearchdescription+xml') "
- "f.push (':' + l[i].href + '|' + l[i].title); "
+ "f.push (l[i].href + '|' + l[i].title);"
#if !WEBKIT_CHECK_VERSION (1, 1, 18)
"else if (r && r.indexOf ('icon') != -1) f.push (l[i].href); "
#endif
"} return f; })("
"document.getElementsByTagName ('link'));", NULL);
-
- /* FIXME: If URI or title contains , parsing will break */
gchar** items = g_strsplit (value, ",", 0);
- gchar** current_item = items;
+ guint i = 0;
gchar* default_uri = NULL;
if (view->news_feeds != NULL)
katze_array_clear (view->news_feeds);
else
view->news_feeds = katze_array_new (KATZE_TYPE_ITEM);
-
- while (current_item && *current_item)
+ if (items != NULL)
+ while (items[i] != NULL)
{
- const gchar* uri_and_title = *current_item;
- if (uri_and_title[0] == '$')
+ gchar** parts = g_strsplit (items[i], "|", 2);
+ if (parts == NULL)
+ ;
+ else if (*parts && parts[1])
{
- const gchar* title;
- gchar* uri;
- KatzeItem* item;
-
- uri_and_title++;
- if (uri_and_title == NULL)
- continue;
- title = strchr (uri_and_title, '|');
- if (title == NULL)
- goto news_feeds_continue;
- title++;
-
- uri = g_strndup (uri_and_title, title - 1 - uri_and_title);
- item = g_object_new (KATZE_TYPE_ITEM,
- "uri", uri, "name", title, NULL);
+ KatzeItem* item = g_object_new (KATZE_TYPE_ITEM,
+ "uri", parts[0], "name", parts[1], NULL);
katze_array_add_item (view->news_feeds, item);
g_object_unref (item);
if (!default_uri)
- default_uri = uri;
- else
- g_free (uri);
- }
- else if (uri_and_title[0] == ':')
- {
- const gchar* title;
-
- uri_and_title++;
- if (uri_and_title == NULL)
- continue;
- title = strchr (uri_and_title, '|');
- if (title == NULL)
- goto news_feeds_continue;
- title++;
- /* TODO: Parse search engine XML
- midori_view_add_info_bar (view, GTK_MESSAGE_INFO, title,
- G_CALLBACK (midori_view_open_search_response_cb), view,
- _("_Save Search engine"), GTK_RESPONSE_ACCEPT, NULL); */
+ default_uri = g_strdup (parts[0]);
}
#if !WEBKIT_CHECK_VERSION (1, 1, 18)
else
- katze_assign (view->icon_uri, g_strdup (uri_and_title));
+ katze_assign (view->icon_uri, g_strdup (*parts));
#endif
- news_feeds_continue:
- current_item++;
+ g_strfreev (parts);
+ i++;
}
g_strfreev (items);
-
g_object_set_data_full (G_OBJECT (view), "news-feeds", default_uri, g_free);
g_free (value);
-
- #if !WEBKIT_CHECK_VERSION (1, 4, 3)
- _midori_web_view_load_icon (view);
- #endif
+ /* Ensure load-status is notified again, whether it changed or not */
+ g_object_notify (G_OBJECT (view), "load-status");
}
- view->progress = 1.0;
- g_object_notify (G_OBJECT (view), "progress");
- midori_view_update_load_status (view, MIDORI_LOAD_FINISHED);
+ _midori_web_view_load_icon (view);
g_object_thaw_notify (G_OBJECT (view));
}
@@ -1780,13 +1622,6 @@ webkit_web_view_hovering_over_link_cb (WebKitWebView* web_view,
g_object_set (view, "statusbar-text", link_uri, NULL);
}
-static gboolean
-midori_view_always_same_tab (const gchar* uri)
-{
- /* No opening in tab, window or app for Javascript or mailto links */
- return g_str_has_prefix (uri, "javascript:") || g_str_has_prefix (uri, "mailto:");
-}
-
static void
midori_view_ensure_link_uri (MidoriView* view,
gint *x,
@@ -1825,9 +1660,9 @@ midori_view_ensure_link_uri (MidoriView* view,
| GDK_MOD1_MASK | GDK_META_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK )
static gboolean
-midori_view_web_view_button_press_event_cb (WebKitWebView* web_view,
- GdkEventButton* event,
- MidoriView* view)
+gtk_widget_button_press_event_cb (WebKitWebView* web_view,
+ GdkEventButton* event,
+ MidoriView* view)
{
GtkClipboard* clipboard;
gchar* uri;
@@ -1838,17 +1673,12 @@ midori_view_web_view_button_press_event_cb (WebKitWebView* web_view,
event->state = event->state & MIDORI_KEYS_MODIFIER_MASK;
midori_view_ensure_link_uri (view, NULL, NULL, event);
link_uri = midori_view_get_link_uri (view);
- view->button_press_handled = FALSE;
switch (event->button)
{
case 1:
if (!link_uri)
return FALSE;
-
- if (midori_view_always_same_tab (link_uri))
- return FALSE;
-
if (MIDORI_MOD_NEW_TAB (event->state))
{
/* Open link in new tab */
@@ -1856,32 +1686,31 @@ midori_view_web_view_button_press_event_cb (WebKitWebView* web_view,
if (MIDORI_MOD_BACKGROUND (event->state))
background = !background;
g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
- view->button_press_handled = TRUE;
return TRUE;
}
else if (MIDORI_MOD_NEW_WINDOW (event->state))
{
/* Open link in new window */
g_signal_emit (view, signals[NEW_WINDOW], 0, link_uri);
- view->button_press_handled = TRUE;
return TRUE;
}
break;
case 2:
if (link_uri)
{
- if (midori_view_always_same_tab (link_uri))
- return FALSE;
-
/* Open link in new tab */
background = view->open_tabs_in_the_background;
if (MIDORI_MOD_BACKGROUND (event->state))
background = !background;
g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
- view->button_press_handled = TRUE;
return TRUE;
}
- if (view->middle_click_opens_selection)
+ else if (MIDORI_MOD_SCROLL (event->state))
+ {
+ midori_view_set_zoom_level (MIDORI_VIEW (view), 1.0);
+ return FALSE; /* Allow Ctrl + Middle click */
+ }
+ else if (view->middle_click_opens_selection)
{
gboolean is_editable;
WebKitHitTestResult* result;
@@ -1891,63 +1720,55 @@ midori_view_web_view_button_press_event_cb (WebKitWebView* web_view,
context = katze_object_get_int (result, "context");
is_editable = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
g_object_unref (result);
- if (!is_editable)
+ if (is_editable)
+ return FALSE;
+
+ clipboard = gtk_clipboard_get_for_display (
+ gtk_widget_get_display (GTK_WIDGET (view)),
+ GDK_SELECTION_PRIMARY);
+ if ((uri = gtk_clipboard_wait_for_text (clipboard)))
{
- clipboard = gtk_clipboard_get_for_display (
- gtk_widget_get_display (GTK_WIDGET (view)),
- GDK_SELECTION_PRIMARY);
- if ((uri = gtk_clipboard_wait_for_text (clipboard)))
+ guint i = 0;
+ while (uri[i++] != '\0')
+ if (uri[i] == '\n' || uri[i] == '\r')
+ uri[i] = ' ';
+ g_strstrip (uri);
+
+ /* Hold Alt to search for the selected word */
+ if (event->state & GDK_MOD1_MASK)
{
- guint i = 0;
- while (uri[i++] != '\0')
- if (uri[i] == '\n' || uri[i] == '\r')
- uri[i] = ' ';
- g_strstrip (uri);
-
- /* Hold Alt to search for the selected word */
- if (event->state & GDK_MOD1_MASK)
+ new_uri = sokoke_magic_uri (uri);
+ if (!new_uri)
{
- new_uri = sokoke_magic_uri (uri);
- if (!new_uri)
- {
- gchar* search = katze_object_get_string (
- view->settings, "location-entry-search");
- new_uri = midori_uri_for_search (search, uri);
- g_free (search);
- }
- katze_assign (uri, new_uri);
- }
- else if (midori_uri_is_location (uri))
- {
- if (MIDORI_MOD_NEW_TAB (event->state))
- {
- background = view->open_tabs_in_the_background;
- if (MIDORI_MOD_BACKGROUND (event->state))
- background = !background;
- g_signal_emit (view, signals[NEW_TAB], 0, uri, background);
- }
- else
- {
- midori_view_set_uri (MIDORI_VIEW (view), uri);
- gtk_widget_grab_focus (GTK_WIDGET (view));
- }
- g_free (uri);
- view->button_press_handled = TRUE;
- return TRUE;
- }
- else
- {
- g_free (uri);
+ gchar* search = katze_object_get_string (
+ view->settings, "location-entry-search");
+ new_uri = midori_uri_for_search (search, uri);
+ g_free (search);
}
+ katze_assign (uri, new_uri);
+ }
+ else if (!midori_uri_is_location (uri))
+ {
+ g_free (uri);
+ return FALSE;
+ }
+
+ if (MIDORI_MOD_NEW_TAB (event->state))
+ {
+ background = view->open_tabs_in_the_background;
+ if (MIDORI_MOD_BACKGROUND (event->state))
+ background = !background;
+ g_signal_emit (view, signals[NEW_TAB], 0, uri, background);
+ }
+ else
+ {
+ midori_view_set_uri (MIDORI_VIEW (view), uri);
+ gtk_widget_grab_focus (GTK_WIDGET (view));
}
+ g_free (uri);
+ return TRUE;
}
}
- if (MIDORI_MOD_SCROLL (event->state))
- {
- midori_view_set_zoom_level (MIDORI_VIEW (view), 1.0);
- return FALSE; /* Allow Ctrl + Middle click */
- }
- return FALSE;
break;
case 3:
if (event->state & GDK_CONTROL_MASK)
@@ -1957,17 +1778,14 @@ midori_view_web_view_button_press_event_cb (WebKitWebView* web_view,
midori_view_populate_popup (view, menu, TRUE);
katze_widget_popup (GTK_WIDGET (web_view), GTK_MENU (menu), event,
KATZE_MENU_POSITION_CURSOR);
- view->button_press_handled = TRUE;
return TRUE;
}
break;
case 8:
midori_view_go_back (view);
- view->button_press_handled = TRUE;
return TRUE;
case 9:
midori_view_go_forward (view);
- view->button_press_handled = TRUE;
return TRUE;
/*
* On some fancier mice the scroll wheel can be used to scroll horizontally.
@@ -1977,8 +1795,8 @@ midori_view_web_view_button_press_event_cb (WebKitWebView* web_view,
* accidentally being interpreted as first button clicks.
*/
case 11:
+ return TRUE;
case 12:
- view->button_press_handled = TRUE;
return TRUE;
}
@@ -1988,17 +1806,6 @@ midori_view_web_view_button_press_event_cb (WebKitWebView* web_view,
return FALSE;
}
-static gboolean
-midori_view_web_view_button_release_event_cb (WebKitWebView* web_view,
- GdkEventButton* event,
- MidoriView* view)
-{
- gboolean button_press_handled = view->button_press_handled;
- view->button_press_handled = FALSE;
-
- return button_press_handled;
-}
-
static gboolean
midori_view_inspector_window_key_press_event_cb (GtkWidget* window,
GdkEventKey* event,
@@ -2011,183 +1818,128 @@ midori_view_inspector_window_key_press_event_cb (GtkWidget* window,
return FALSE;
}
-static void
-handle_link_hints (WebKitWebView* web_view,
- GdkEventKey* event,
- MidoriView* view)
-{
- gint digit = g_ascii_digit_value (event->keyval);
- gunichar uc = gdk_keyval_to_unicode (event->keyval);
- gchar* result = NULL;
- WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (web_view);
- JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
-
- if (view->find_links < 0)
- {
- /* Links are currently off, turn them on */
- result = sokoke_js_script_eval (js_context,
- " var style_func = (function (selector, rule) { "
- " var style = document.createElement ('style');"
- " style.setAttribute ('type', 'text/css');"
- " var heads = document.getElementsByTagName ('head');"
- " heads[0].appendChild (style);"
- " document.styleSheets[0].insertRule (selector + ' ' + rule);"
- " } );"
- " style_func ('.midoriHKD87346', '{ "
- " font-size:small !important; font-weight:bold !important;"
- " z-index:500; border-radius:0.3em; line-height:1 !important;"
- " background: white !important; color: black !important;"
- " border:1px solid gray; padding:0 0.1em !important;"
- " position:absolute; display:inline !important; }');"
- " style_func ('.midori_access_key_fc04de', '{ "
- " font-size:small !important; font-weight:bold !important;"
- " z-index:500; border-radius:0.3em; line-height:1 !important;"
- " background: black !important; color: white !important;"
- " border:1px solid gray; padding:0 0.1em 0.2em 0.1em !important;"
- " position:absolute; display:inline !important; }');"
- " var label_count = 0;"
- " for (i in document.links) {"
- " if (document.links[i].href && document.links[i].insertBefore) {"
- " var child = document.createElement ('span');"
- " if (document.links[i].accessKey && isNaN (document.links[i].accessKey)) {"
- " child.setAttribute ('class', 'midori_access_key_fc04de');"
- " child.appendChild (document.createTextNode (document.links[i].accessKey));"
- " } else {"
- " child.setAttribute ('class', 'midoriHKD87346');"
- " child.appendChild (document.createTextNode (label_count));"
- " label_count++;"
- " }"
- " document.links[i].insertBefore (child); } }",
- NULL);
- view->find_links = 0; /* Links are now on */
- g_free (result);
- return;
- }
-
- if (event->keyval == '.')
- {
- /* Pressed '.' with links on, so turn them off */
- result = sokoke_js_script_eval (js_context,
- "var links = document.getElementsByClassName ('midoriHKD87346');"
- "for (var i = links.length - 1; i >= 0; i--) {"
- " var parent = links[i].parentNode;"
- " parent.removeChild(links[i]); }",
- NULL);
- g_free (result);
- result = sokoke_js_script_eval (js_context,
- "var links = document.getElementsByClassName ('midori_access_key_fc04de');"
- "if (links != undefined && links.length > 0) {"
- " for (var i = links.length - 1; i >= 0; i--) {"
- " var parent = links[i].parentNode;"
- " parent.removeChild(links[i]); } }",
- NULL);
- g_free (result);
- view->find_links = -1;
- return;
- }
-
- /* Links are already on at this point, so process the input character */
-
- if (digit != -1 && event->keyval != GDK_KEY_Return && event->keyval != GDK_KEY_Escape)
- {
- /* Got a digit, add it to the link count/ number */
- if (view->find_links > 0)
- view->find_links *= 10;
- view->find_links += digit;
- return;
- }
-
- if (event->keyval == GDK_KEY_Escape)
- {
- // Clear the link count/number
- view->find_links = 0;
- return;
- }
-
- if (g_unichar_isalpha (uc))
- {
- /* letter pressed if we have a corresponding accessKey and grab URI */
- gchar* script = NULL;
- gchar* utf8 = NULL;
- gulong sz = g_unichar_to_utf8 (uc, NULL);
-
- utf8 = g_malloc0 (sz);
- g_unichar_to_utf8 (uc, utf8);
- script = g_strdup_printf (
- "var l = 'undefined';"
- "for (i in document.links) {"
- " if ( document.links[i].href &&"
- " document.links[i].accessKey == \"%s\" )"
- " {"
- " l = document.links[i].href;"
- " break;"
- " }"
- "}"
- "if (l != 'undefined') { l; }"
- , utf8
- );
- g_free (utf8);
- result = sokoke_js_script_eval (js_context, script, NULL);
- g_free (script);
- }
- else if (event->keyval == GDK_KEY_Return)
- {
- /* Return pressed, grab URI if we have a link with the entered number */
- gchar* script = g_strdup_printf (
- "var links = document.getElementsByClassName ('midoriHKD87346');"
- "var i = %d; var return_key = %d;"
- "if (return_key) {"
- " if (typeof links[i] != 'undefined')"
- " links[i].parentNode.href; }",
- view->find_links, event->keyval == GDK_KEY_Return
- );
- result = sokoke_js_script_eval (js_context, script, NULL);
- g_free (script);
- }
-
- /* Check the URI we grabbed to see if it's valid, if so go there */
- if (midori_uri_is_location (result))
- {
- if (MIDORI_MOD_NEW_TAB (event->state))
- {
- gboolean background = view->open_tabs_in_the_background;
- if (MIDORI_MOD_BACKGROUND (event->state))
- background = !background;
- g_signal_emit (view, signals[NEW_TAB], 0, result, background);
- }
- else
- midori_view_set_uri (view, result);
- view->find_links = -1; /* Turn off link mode */
- }
- else /* Invalid URI, start over... */
- view->find_links = 0;
-
- if (result)
- g_free (result);
- return;
-}
-
static gboolean
gtk_widget_key_press_event_cb (WebKitWebView* web_view,
GdkEventKey* event,
MidoriView* view)
{
guint character;
+ gint digit = g_ascii_digit_value (event->keyval);
event->state = event->state & MIDORI_KEYS_MODIFIER_MASK;
/* Handle oddities in Russian keyboard layouts */
- if (event->hardware_keycode == ';' || event->hardware_keycode == '=')
+ if (event->hardware_keycode == ';')
event->keyval = ',';
else if (event->hardware_keycode == '<')
event->keyval = '.';
/* Find links by number: . to show links, type number, Return to go */
- if ( event->keyval == '.' || view->find_links > -1 )
+ if (event->keyval == '.'
+ || (view->find_links > -1
+ && (digit != -1 || event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_Escape)))
{
- handle_link_hints (web_view, event, view);
- return FALSE;
- }
+ WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (web_view);
+ JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
+ gchar* result;
+
+ if (view->find_links == -1)
+ {
+ result = sokoke_js_script_eval (js_context,
+ " var style_func = (function (selector, rule) { "
+ " var style = document.createElement ('style');"
+ " style.setAttribute ('type', 'text/css');"
+ " var heads = document.getElementsByTagName ('head');"
+ " heads[0].appendChild (style);"
+ " document.styleSheets[0].insertRule (selector + ' ' + rule);"
+ " } );"
+ " style_func ('.midoriHKD87346', '{ "
+ " font-size:small !important; font-weight:bold !important;"
+ " z-index:500; border-radius:0.3em; line-height:1 !important;"
+ " background: white !important; color: black !important;"
+ " border:1px solid gray; padding:0 0.1em !important;"
+ " position:absolute; display:inline !important; }');"
+ " style_func ('.midori_access_key_fc04de', '{ "
+ " font-size:small !important; font-weight:bold !important;"
+ " z-index:500; border-radius:0.3em; line-height:1 !important;"
+ " background: black !important; color: white !important;"
+ " border:1px solid gray; padding:0 0.1em 0.2em 0.1em !important;"
+ " position:absolute; display:inline !important; }');"
+ " var label_count = 0;"
+ " for (i in document.links) {"
+ " if (document.links[i].href && document.links[i].insertBefore) {"
+ " var child = document.createElement ('span');"
+ " if (document.links[i].accessKey && isNaN (document.links[i].accessKey)) {"
+ " child.setAttribute ('class', 'midori_access_key_fc04de');"
+ " child.appendChild (document.createTextNode (document.links[i].accessKey));"
+ " } else {"
+ " child.setAttribute ('class', 'midoriHKD87346');"
+ " child.appendChild (document.createTextNode (label_count));"
+ " label_count++;"
+ " }"
+ " document.links[i].insertBefore (child); } }",
+ NULL);
+ view->find_links = 0;
+ }
+ else if (digit != -1 && event->keyval != GDK_KEY_Return && event->keyval != GDK_KEY_Escape)
+ {
+ if (view->find_links > -1)
+ view->find_links *= 10;
+ view->find_links += digit;
+ }
+ else if (event->keyval == GDK_KEY_Escape)
+ {
+ view->find_links = 0;
+ }
+ else if (event->keyval == GDK_KEY_Return)
+ {
+ gchar* script;
+ script = g_strdup_printf (
+ "var links = document.getElementsByClassName ('midoriHKD87346');"
+ "var i = %d; var return_key = %d;"
+ "if (return_key) {"
+ " if (typeof links[i] != 'undefined')"
+ " links[i].parentNode.href; }",
+ view->find_links, event->keyval == GDK_KEY_Return
+ );
+ result = sokoke_js_script_eval (js_context, script, NULL);
+ if (midori_uri_is_location (result))
+ {
+ if (MIDORI_MOD_NEW_TAB (event->state))
+ {
+ gboolean background = view->open_tabs_in_the_background;
+ if (MIDORI_MOD_BACKGROUND (event->state))
+ background = !background;
+ g_signal_emit (view, signals[NEW_TAB], 0, result, background);
+ }
+ else
+ midori_view_set_uri (view, result);
+ }
+ g_free (script);
+ g_free (result);
+ view->find_links = 0;
+ }
+ else
+ {
+ result = sokoke_js_script_eval (js_context,
+ "var links = document.getElementsByClassName ('midoriHKD87346');"
+ "for (var i = links.length - 1; i >= 0; i--) {"
+ " var parent = links[i].parentNode;"
+ " parent.removeChild(links[i]); }",
+ NULL);
+ g_free (result);
+ result = sokoke_js_script_eval (js_context,
+ "var links = document.getElementsByClassName ('midori_access_key_fc04de');"
+ "if (links != undefined && links.length > 0) {"
+ " for (var i = links.length - 1; i >= 0; i--) {"
+ " var parent = links[i].parentNode;"
+ " parent.removeChild(links[i]); } }",
+ NULL);
+ g_free (result);
+ view->find_links = -1;
+ }
+ return FALSE;
+ }
/* Find inline */
if (event->keyval == ',' || event->keyval == '/' || event->keyval == GDK_KEY_KP_Divide)
@@ -2203,12 +1955,7 @@ gtk_widget_key_press_event_cb (WebKitWebView* web_view,
&& !webkit_web_view_can_paste_clipboard (web_view))
{
gchar* text = character ? g_strdup_printf ("%c", character) : NULL;
- #if GTK_CHECK_VERSION(3, 2, 0)
- midori_findbar_search_text (MIDORI_FINDBAR (view->overlay_find),
- (GtkWidget*)view, TRUE, katze_str_non_null (text));
- #else
g_signal_emit (view, signals[SEARCH_TEXT], 0, TRUE, text ? text : "");
- #endif
g_free (text);
return TRUE;
}
@@ -2256,31 +2003,23 @@ midori_web_view_menu_link_copy_activate_cb (GtkWidget* widget,
MidoriView* view)
{
if (g_str_has_prefix (view->link_uri, "mailto:"))
- sokoke_widget_copy_clipboard (widget, view->link_uri + 7, NULL, NULL);
+ sokoke_widget_copy_clipboard (widget, view->link_uri + 7);
else
- sokoke_widget_copy_clipboard (widget, view->link_uri, NULL, NULL);
+ sokoke_widget_copy_clipboard (widget, view->link_uri);
}
static void
-midori_view_download_uri (MidoriView* view,
- MidoriDownloadType type,
- const gchar* uri)
+midori_web_view_menu_save_activate_cb (GtkWidget* widget,
+ MidoriView* view)
{
- WebKitNetworkRequest* request = webkit_network_request_new (uri);
+ WebKitNetworkRequest* request = webkit_network_request_new (view->link_uri);
WebKitDownload* download = webkit_download_new (request);
gboolean handled;
g_object_unref (request);
- midori_download_set_type (download, type);
+ g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
}
-static void
-midori_web_view_menu_save_activate_cb (GtkWidget* widget,
- MidoriView* view)
-{
- midori_view_download_uri (view, MIDORI_DOWNLOAD_SAVE_AS, view->link_uri);
-}
-
static void
midori_web_view_menu_image_new_tab_activate_cb (GtkWidget* widget,
MidoriView* view)
@@ -2291,73 +2030,12 @@ midori_web_view_menu_image_new_tab_activate_cb (GtkWidget* widget,
g_free (uri);
}
-static GString*
-midori_view_get_data_for_uri (MidoriView* view,
- const gchar* uri)
-{
- WebKitWebView* web_view = WEBKIT_WEB_VIEW (view->web_view);
- WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view);
- WebKitWebDataSource* data_source = webkit_web_frame_get_data_source (frame);
- GList* resources = webkit_web_data_source_get_subresources (data_source);
- GList* list;
- GString* result;
-
- for (list = resources; list; list = g_list_next (list))
- {
- WebKitWebResource* resource = WEBKIT_WEB_RESOURCE (list->data);
- GString* data = webkit_web_resource_get_data (resource);
- if (!g_strcmp0 (webkit_web_resource_get_uri (resource), uri))
- {
- result = data;
- break;
- }
- }
- g_list_free (resources);
- return result;
-}
-
-static void
-midori_view_clipboard_get_image_cb (GtkClipboard* clipboard,
- GtkSelectionData* selection_data,
- guint info,
- gpointer user_data)
-{
- MidoriView* view = MIDORI_VIEW (g_object_get_data (user_data, "view"));
- WebKitHitTestResult* hit_test = user_data;
- gchar* uri = katze_object_get_string (hit_test, "image-uri");
- /* if (gtk_selection_data_targets_include_image (selection_data, TRUE)) */
- {
- GString* data = midori_view_get_data_for_uri (view, uri);
- if (data != NULL)
- {
- GInputStream* stream = g_memory_input_stream_new_from_data (data->str, data->len, NULL);
- GError* error = NULL;
- GdkPixbuf* pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error);
- g_object_unref (stream);
- if (error != NULL)
- {
- g_critical ("Error copying pixbuf: %s\n", error->message);
- g_error_free (error);
- }
- gtk_selection_data_set_pixbuf (selection_data, pixbuf);
- g_object_unref (pixbuf);
- }
- else
- g_warn_if_reached ();
- }
- /* if (gtk_selection_data_targets_include_text (selection_data)) */
- gtk_selection_data_set_text (selection_data, uri, -1);
- g_free (uri);
-}
-
static void
midori_web_view_menu_image_copy_activate_cb (GtkWidget* widget,
MidoriView* view)
{
gchar* uri = katze_object_get_string (view->hit_test, "image-uri");
- g_object_set_data (G_OBJECT (view->hit_test), "view", view);
- sokoke_widget_copy_clipboard (widget,
- uri, midori_view_clipboard_get_image_cb, view->hit_test);
+ sokoke_widget_copy_clipboard (widget, uri);
g_free (uri);
}
@@ -2366,16 +2044,12 @@ midori_web_view_menu_image_save_activate_cb (GtkWidget* widget,
MidoriView* view)
{
gchar* uri = katze_object_get_string (view->hit_test, "image-uri");
- midori_view_download_uri (view, MIDORI_DOWNLOAD_SAVE_AS, uri);
- g_free (uri);
-}
-
-static void
-midori_web_view_open_in_viewer_cb (GtkWidget* widget,
- MidoriView* view)
-{
- gchar* uri = katze_object_get_string (view->hit_test, "image-uri");
- midori_view_download_uri (view, MIDORI_DOWNLOAD_OPEN_IN_VIEWER, uri);
+ WebKitNetworkRequest* request = webkit_network_request_new (uri);
+ WebKitDownload* download = webkit_download_new (request);
+ gboolean handled;
+ g_object_unref (request);
+ g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
+ g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
g_free (uri);
}
@@ -2384,7 +2058,7 @@ midori_web_view_menu_video_copy_activate_cb (GtkWidget* widget,
MidoriView* view)
{
gchar* uri = katze_object_get_string (view->hit_test, "media-uri");
- sokoke_widget_copy_clipboard (widget, uri, NULL, NULL);
+ sokoke_widget_copy_clipboard (widget, uri);
g_free (uri);
}
@@ -2393,7 +2067,12 @@ midori_web_view_menu_video_save_activate_cb (GtkWidget* widget,
MidoriView* view)
{
gchar* uri = katze_object_get_string (view->hit_test, "media-uri");
- midori_view_download_uri (view, MIDORI_DOWNLOAD_SAVE_AS, uri);
+ WebKitNetworkRequest* request = webkit_network_request_new (uri);
+ WebKitDownload* download = webkit_download_new (request);
+ gboolean handled;
+ g_object_unref (request);
+ g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
+ g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
g_free (uri);
}
@@ -2459,7 +2138,7 @@ static void
midori_web_view_menu_copy_activate_cb (GtkWidget* widget,
MidoriView* view)
{
- sokoke_widget_copy_clipboard (widget, view->selected_text, NULL, NULL);
+ sokoke_widget_copy_clipboard (widget, view->selected_text);
}
static void
@@ -2470,15 +2149,6 @@ midori_view_tab_label_menu_window_new_cb (GtkWidget* menuitem,
midori_view_get_display_uri (MIDORI_VIEW (view)));
}
-static void
-midori_web_view_open_frame_in_new_tab_cb (GtkWidget* widget,
- MidoriView* view)
-{
- WebKitWebFrame* web_frame = webkit_web_view_get_focused_frame (WEBKIT_WEB_VIEW (view->web_view));
- g_signal_emit (view, signals[NEW_TAB], 0,
- webkit_web_frame_get_uri (web_frame), view->open_tabs_in_the_background);
-}
-
static void
midori_web_view_menu_inspect_element_activate_cb (GtkWidget* widget,
MidoriView* view)
@@ -2493,19 +2163,6 @@ midori_web_view_menu_inspect_element_activate_cb (GtkWidget* widget,
webkit_web_inspector_show (inspector);
}
-#if WEBKIT_CHECK_VERSION (1, 5, 0)
-static void
-midori_view_menu_add_search_engine_cb (GtkWidget* widget,
- MidoriView* view)
-{
- MidoriBrowser* browser = midori_browser_get_for_widget (view->web_view);
- GtkActionGroup* actions = midori_browser_get_action_group (browser);
- GtkAction* action = gtk_action_group_get_action (actions, "Search");
- KatzeItem* item = g_object_get_data (G_OBJECT (widget), "item");
- midori_search_action_get_editor (MIDORI_SEARCH_ACTION (action), item, TRUE);
-}
-#endif
-
static GtkWidget*
midori_view_insert_menu_item (GtkMenuShell* menu,
gint position,
@@ -2567,7 +2224,6 @@ midori_view_populate_popup (MidoriView* view,
WebKitWebView* web_view = WEBKIT_WEB_VIEW (view->web_view);
GtkWidget* widget = GTK_WIDGET (view);
MidoriBrowser* browser = midori_browser_get_for_widget (widget);
- GdkWindowState state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (browser)));
GtkActionGroup* actions = midori_browser_get_action_group (browser);
GtkMenuShell* menu_shell = GTK_MENU_SHELL (menu);
GtkWidget* menuitem;
@@ -2589,8 +2245,7 @@ midori_view_populate_popup (MidoriView* view,
context = katze_object_get_int (view->hit_test, "context");
has_selection = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION;
/* Ensure view->selected_text */
- if (!midori_view_has_selection (view))
- has_selection = false;
+ midori_view_has_selection (view);
is_editable = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
is_image = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE;
is_media = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
@@ -2611,23 +2266,6 @@ midori_view_populate_popup (MidoriView* view,
gtk_widget_set_sensitive (menuitem,
webkit_web_view_can_undo (web_view));
gtk_menu_shell_prepend (menu_shell, menuitem);
-
- #if WEBKIT_CHECK_VERSION (1, 5, 0)
- {
- KatzeItem* item = midori_search_action_get_engine_for_form (
- WEBKIT_WEB_VIEW (view->web_view), view->ellipsize);
- if (item != NULL)
- {
- menuitem = midori_view_insert_menu_item (menu_shell, -1,
- _("Add _search engine..."), NULL,
- G_CALLBACK (midori_view_menu_add_search_engine_cb), widget);
- g_object_set_data (G_OBJECT (menuitem), "item", item);
- gtk_menu_shell_append (menu_shell, menuitem);
- gtk_widget_show (menuitem);
- }
- }
- #endif
-
if (manual)
{
menuitem = sokoke_action_create_popup_menu_item (
@@ -2712,8 +2350,6 @@ midori_view_populate_popup (MidoriView* view,
}
if (view->link_uri)
{
- if (!midori_view_always_same_tab (view->link_uri))
- {
midori_view_insert_menu_item (menu_shell, -1,
_("Open Link in New _Tab"), STOCK_TAB_NEW,
G_CALLBACK (midori_web_view_menu_new_tab_activate_cb), widget);
@@ -2728,18 +2364,12 @@ midori_view_populate_popup (MidoriView* view,
midori_view_insert_menu_item (menu_shell, -1,
_("Open Link as Web A_pplication"), NULL,
G_CALLBACK (midori_web_view_menu_web_app_activate_cb), widget);
- }
-
midori_view_insert_menu_item (menu_shell, -1,
_("Copy Link de_stination"), NULL,
G_CALLBACK (midori_web_view_menu_link_copy_activate_cb), widget);
-
- if (!midori_view_always_same_tab (view->link_uri))
- {
midori_view_insert_menu_item (menu_shell, -1,
NULL, GTK_STOCK_SAVE_AS,
G_CALLBACK (midori_web_view_menu_save_activate_cb), widget);
- }
}
if (is_image)
@@ -2750,14 +2380,11 @@ midori_view_populate_popup (MidoriView* view,
_("Open _Image in New Tab"), STOCK_TAB_NEW,
G_CALLBACK (midori_web_view_menu_image_new_tab_activate_cb), widget);
midori_view_insert_menu_item (menu_shell, -1,
- _("Copy Im_age"), NULL,
+ _("Copy Image _Address"), NULL,
G_CALLBACK (midori_web_view_menu_image_copy_activate_cb), widget);
midori_view_insert_menu_item (menu_shell, -1,
_("Save I_mage"), GTK_STOCK_SAVE,
G_CALLBACK (midori_web_view_menu_image_save_activate_cb), widget);
- midori_view_insert_menu_item (menu_shell, -1,
- _("Open in Image _Viewer"), GTK_STOCK_OPEN,
- G_CALLBACK (midori_web_view_open_in_viewer_cb), widget);
}
if (is_media)
@@ -2826,15 +2453,11 @@ midori_view_populate_popup (MidoriView* view,
midori_view_insert_menu_item (menu_shell, 0,
_("_Search the Web"), GTK_STOCK_FIND,
G_CALLBACK (midori_web_view_menu_search_web_activate_cb), widget);
- /* FIXME: choose 3 most frequently */
g_strstrip (view->selected_text);
if (midori_uri_is_valid (view->selected_text))
{
- /* :// and @ together would mean login credentials */
- if (g_str_has_prefix (view->selected_text, "mailto:")
- || (strchr (view->selected_text, '@') != NULL
- && strstr (view->selected_text, "://") == NULL))
+ if (midori_uri_is_email (view->selected_text))
{
gchar* text = g_strdup_printf (_("Send a message to %s"), view->selected_text);
menuitem = midori_view_insert_menu_item (menu_shell, -1,
@@ -2894,12 +2517,6 @@ midori_view_populate_popup (MidoriView* view,
menuitem = sokoke_action_create_popup_menu_item (
gtk_action_group_get_action (actions, "UndoTabClose"));
gtk_menu_shell_append (menu_shell, menuitem);
-
- if (webkit_web_view_get_focused_frame (web_view) != webkit_web_view_get_main_frame (web_view))
- menuitem = midori_view_insert_menu_item (menu_shell, -1,
- _("Open _Frame in New Tab"), NULL,
- G_CALLBACK (midori_web_view_open_frame_in_new_tab_cb), widget);
-
menuitem = gtk_image_menu_item_new_from_stock (STOCK_WINDOW_NEW, NULL);
gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), _("Open in New _Window"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
@@ -2924,7 +2541,6 @@ midori_view_populate_popup (MidoriView* view,
static const GtkActionEntry encodings[] = {
{ "EncodingAutomatic" },
{ "EncodingChinese" },
- { "EncodingChineseSimplified" },
{ "EncodingJapanese" },
{ "EncodingKorean" },
{ "EncodingRussian" },
@@ -2961,7 +2577,7 @@ midori_view_populate_popup (MidoriView* view,
gtk_action_group_get_action (actions, "BookmarkAdd"));
gtk_menu_shell_append (menu_shell, menuitem);
- if (!midori_view_is_blank (view) && !midori_paths_is_readonly ())
+ if (!midori_view_is_blank (view) && !sokoke_is_app_or_private ())
{
menuitem = sokoke_action_create_popup_menu_item (
gtk_action_group_get_action (actions, "AddSpeedDial"));
@@ -2998,6 +2614,7 @@ midori_view_populate_popup (MidoriView* view,
g_object_set_data (G_OBJECT (menuitem), "y", GINT_TO_POINTER (y));
}
+ GdkWindowState state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (browser)));
if (state & GDK_WINDOW_STATE_FULLSCREEN)
{
menuitem = sokoke_action_create_popup_menu_item (
@@ -3050,8 +2667,8 @@ static gboolean
webkit_web_view_web_view_ready_cb (GtkWidget* web_view,
MidoriView* view)
{
+ GtkWidget* new_view = gtk_widget_get_parent (gtk_widget_get_parent (web_view));
MidoriNewView where = MIDORI_NEW_VIEW_TAB;
- GtkWidget* new_view = GTK_WIDGET (midori_view_get_for_widget (web_view));
/* FIXME: Open windows opened by scripts in tabs if they otherwise
would be replacing the page the user opened. */
@@ -3087,8 +2704,6 @@ webkit_web_view_create_web_view_cb (GtkWidget* web_view,
g_signal_connect (new_view->web_view, "web-view-ready",
G_CALLBACK (webkit_web_view_web_view_ready_cb), view);
}
- g_object_set_data_full (G_OBJECT (new_view), "opener-uri",
- g_strdup (webkit_web_frame_get_uri (web_frame)), g_free);
return new_view->web_view;
}
@@ -3100,6 +2715,27 @@ webkit_web_view_mime_type_decision_cb (GtkWidget* web_view,
WebKitWebPolicyDecision* decision,
MidoriView* view)
{
+ GtkWidget* dialog;
+ gchar* content_type;
+ gchar* description;
+ gchar* file_type;
+ WebKitWebDataSource* datasource;
+ WebKitNetworkRequest* original_request;
+ const gchar* original_uri;
+ gchar* fingerprint;
+ gchar* fplabel;
+ #if GTK_CHECK_VERSION (2, 14, 0)
+ GIcon* icon;
+ GtkWidget* image;
+ #endif
+ gchar* title;
+ GdkScreen* screen;
+ GtkIconTheme* icon_theme;
+ gint response;
+
+ if (web_frame != webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)))
+ return FALSE;
+
if (webkit_web_view_can_show_mime_type (WEBKIT_WEB_VIEW (web_view), mime_type))
{
gboolean view_source = FALSE;
@@ -3107,120 +2743,61 @@ webkit_web_view_mime_type_decision_cb (GtkWidget* web_view,
if (midori_view_is_blank (view))
view_source = webkit_web_view_get_view_source_mode (WEBKIT_WEB_VIEW (web_view));
+ /* Render raw XML, including news feeds, as source */
+ if (!view_source && (!strcmp (mime_type, "application/xml")
+ || !strcmp (mime_type, "text/xml")))
+ view_source = TRUE;
webkit_web_view_set_view_source_mode (WEBKIT_WEB_VIEW (web_view), view_source);
- if (web_frame == webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)))
- {
- katze_assign (view->mime_type, g_strdup (mime_type));
- katze_item_set_meta_string (view->item, "mime-type", mime_type);
- midori_view_unset_icon (view);
- g_object_notify (G_OBJECT (view), "mime-type");
- }
+ katze_assign (view->mime_type, g_strdup (mime_type));
+ midori_view_update_icon (view, NULL);
+ g_object_notify (G_OBJECT (view), "mime-type");
return FALSE;
}
- g_object_set_data(G_OBJECT (view), "download-mime-type", (gpointer)mime_type);
- webkit_web_policy_decision_download (decision);
- g_object_set_data(G_OBJECT (view), "download-mime-type", NULL);
- return TRUE;
-}
-
-static gboolean
-webkit_web_view_download_requested_cb (GtkWidget* web_view,
- WebKitDownload* download,
- MidoriView* view)
-{
- gchar* opener_uri;
- gchar* hostname;
- GtkWidget* dialog;
- gchar* content_type;
- gchar* description;
- WebKitWebFrame* web_frame;
- WebKitWebDataSource* datasource;
- GString* details;
- GIcon* icon;
- GtkWidget* image;
- gchar* title;
- GdkScreen* screen;
- GtkIconTheme* icon_theme;
- gint response;
- gboolean handled;
- /* Opener may differ from displaying view:
- http://lcamtuf.coredump.cx/fldl/ http://lcamtuf.coredump.cx/switch/ */
- opener_uri = g_object_get_data (G_OBJECT (view), "opener-uri");
- hostname = midori_uri_parse_hostname (
- opener_uri ? opener_uri : midori_view_get_display_uri (view), NULL);
- dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
- _("Open or download file from %s"), hostname);
- g_free (hostname);
- content_type = midori_download_get_content_type (download,
- g_object_get_data (G_OBJECT (view), "download-mime-type"));
+ dialog = gtk_message_dialog_new (
+ NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
+ _("Open or download file"));
+ content_type = g_content_type_from_mime_type (mime_type);
+ if (!content_type)
+ #ifdef G_OS_WIN32
+ content_type = g_content_type_get_mime_type ("*");
+ #else
+ content_type = g_strdup ("application/octet-stream");
+ #endif
description = g_content_type_get_description (content_type);
+ #if GTK_CHECK_VERSION (2, 14, 0)
icon = g_content_type_get_icon (content_type);
- g_themed_icon_append_name (G_THEMED_ICON (icon), "text-html");
+ g_themed_icon_append_name (G_THEMED_ICON (icon), "document-x-generic");
image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
g_object_unref (icon);
gtk_widget_show (image);
gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
-
- details = g_string_sized_new (20 * 4);
- g_string_append_printf (details, _("File Name: %s"),
- webkit_download_get_suggested_filename (download));
- g_string_append_c (details, '\n');
-
- if (g_strrstr (description, content_type))
- g_string_append_printf (details, _("File Type: '%s'"), content_type);
+ #endif
+ g_free (content_type);
+ if (g_strrstr (description, mime_type))
+ file_type = g_strdup_printf (_("File Type: '%s'"), mime_type);
else
- g_string_append_printf (details, _("File Type: %s ('%s')"), description, content_type);
- g_string_append_c (details, '\n');
+ file_type = g_strdup_printf (_("File Type: %s ('%s')"), description, mime_type);
g_free (description);
- g_free (content_type);
/* Link Fingerprint */
/* We look at the original URI because redirection would lose the fragment */
- web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
datasource = webkit_web_frame_get_provisional_data_source (web_frame);
- if (datasource)
- {
- gchar* fingerprint;
- gchar* fplabel;
- WebKitNetworkRequest* original_request = webkit_web_data_source_get_initial_request (datasource);
- const gchar* original_uri = webkit_network_request_get_uri (original_request);
- midori_uri_get_fingerprint (original_uri, &fingerprint, &fplabel);
- if (fplabel && fingerprint)
- {
- WebKitNetworkRequest* request = webkit_download_get_network_request (download);
-
- g_string_append (details, fplabel);
- g_string_append_c (details, ' ');
- g_string_append (details, fingerprint);
- g_string_append_c (details, '\n');
-
- /* Propagate original URI to make it available when the download finishes */
- g_object_set_data_full (G_OBJECT (request), "midori-original-uri",
- g_strdup (original_uri), g_free);
- }
- g_free (fplabel);
- g_free (fingerprint);
-
- }
-
- if (webkit_download_get_total_size (download) > webkit_download_get_current_size (download))
- {
- gchar* total = g_format_size (webkit_download_get_total_size (download));
- g_string_append_printf (details, _("Size: %s"), total);
- g_string_append_c (details, '\n');
- g_free (total);
- }
-
+ original_request = webkit_web_data_source_get_initial_request (datasource);
+ original_uri = webkit_network_request_get_uri (original_request);
+ midori_uri_get_fingerprint (original_uri, &fingerprint, &fplabel);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", details->str);
- g_string_free (details, TRUE);
+ "%s\n%s %s", file_type, fplabel ? fplabel : "", fingerprint ? fingerprint : "");
+ g_free (fingerprint);
+ g_free (fplabel);
+ g_free (file_type);
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
/* i18n: A file open dialog title, ie. "Open http://fila.com/manual.tgz" */
- title = g_strdup_printf (_("Open %s"), webkit_download_get_uri (download));
+ title = g_strdup_printf (_("Open %s"),
+ webkit_network_request_get_uri (request));
gtk_window_set_title (GTK_WINDOW (dialog), title);
g_free (title);
screen = gtk_widget_get_screen (dialog);
@@ -3233,18 +2810,58 @@ webkit_web_view_download_requested_cb (GtkWidget* web_view,
gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_OPEN);
}
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- GTK_STOCK_SAVE, MIDORI_DOWNLOAD_SAVE,
- GTK_STOCK_SAVE_AS, MIDORI_DOWNLOAD_SAVE_AS,
- GTK_STOCK_CANCEL, MIDORI_DOWNLOAD_CANCEL,
- GTK_STOCK_OPEN, MIDORI_DOWNLOAD_OPEN,
+ GTK_STOCK_SAVE, 1,
+ GTK_STOCK_SAVE_AS, 4,
+ GTK_STOCK_CANCEL, 2,
+ GTK_STOCK_OPEN, 3,
NULL);
-
response = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
- if (response == GTK_RESPONSE_DELETE_EVENT)
- response = MIDORI_DOWNLOAD_CANCEL;
- midori_download_set_type (download, response);
+ g_object_set_data (G_OBJECT (view), "open-download", (gpointer)0);
+ switch (response)
+ {
+ case 4:
+ g_object_set_data (G_OBJECT (view), "save-as-download", (gpointer)1);
+ webkit_web_policy_decision_download (decision);
+ webkit_web_view_stop_loading (WEBKIT_WEB_VIEW (view->web_view));
+ return TRUE;
+ case 3:
+ g_object_set_data (G_OBJECT (view), "open-download", (gpointer)1);
+ case 1:
+ webkit_web_policy_decision_download (decision);
+ /* Apparently WebKit will continue loading which ends in an error.
+ It's unclear whether it's a bug or we are doing something wrong. */
+ webkit_web_view_stop_loading (WEBKIT_WEB_VIEW (view->web_view));
+ return TRUE;
+ case 2:
+ default:
+ /* Apparently WebKit will continue loading which ends in an error.
+ It's unclear whether it's a bug or we are doing something wrong. */
+ webkit_web_view_stop_loading (WEBKIT_WEB_VIEW (view->web_view));
+ return FALSE;
+ }
+}
+static gboolean
+webkit_web_view_download_requested_cb (GtkWidget* web_view,
+ WebKitDownload* download,
+ MidoriView* view)
+{
+ gboolean handled;
+ /* Propagate original URI to make it available when the download finishes */
+ WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
+ WebKitWebDataSource* datasource = webkit_web_frame_get_provisional_data_source (web_frame);
+ WebKitNetworkRequest* original_request = webkit_web_data_source_get_initial_request (datasource);
+ const gchar* original_uri = webkit_network_request_get_uri (original_request);
+ WebKitNetworkRequest* request = webkit_download_get_network_request (download);
+ g_object_set_data_full (G_OBJECT (request), "midori-original-uri",
+ g_strdup (original_uri), g_free);
+ g_object_set_data (G_OBJECT (download), "open-download",
+ g_object_get_data (G_OBJECT (view), "open-download"));
+ g_object_set_data (G_OBJECT (download), "save-as-download",
+ g_object_get_data (G_OBJECT (view), "save-as-download"));
+ g_object_set_data (G_OBJECT (view), "open-download", (gpointer)0);
+ g_object_set_data (G_OBJECT (view), "save-as-download", (gpointer)0);
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
return handled;
}
@@ -3261,17 +2878,7 @@ webkit_web_view_console_message_cb (GtkWidget* web_view,
return FALSE;
if (!strncmp (message, "speed_dial-save", 13))
- {
- MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
- MidoriSpeedDial* dial = katze_object_get_object (browser, "speed-dial");
- GError* error = NULL;
- midori_speed_dial_save_message (dial, message, &error);
- if (error != NULL)
- {
- g_critical ("Failed speed dial message: %s\n", error->message);
- g_error_free (error);
- }
- }
+ midori_view_speed_dial_save (view, message);
else
g_signal_emit (view, signals[CONSOLE_MESSAGE], 0, message, line, source_id);
return TRUE;
@@ -3388,6 +2995,23 @@ midori_view_notify_vadjustment_cb (MidoriView* view,
G_CALLBACK (midori_view_vadjustment_notify_value_cb), view);
}
+static void
+katze_net_object_maybe_unref (gpointer object)
+{
+ if (object)
+ g_object_unref (object);
+}
+
+static GHashTable* midori_view_get_memory (void)
+{
+ static GHashTable* memory = NULL;
+ if (!memory)
+ memory = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, katze_net_object_maybe_unref);
+ return g_hash_table_ref (memory);
+
+}
+
static void
midori_view_init (MidoriView* view)
{
@@ -3397,6 +3021,7 @@ midori_view_init (MidoriView* view)
view->mime_type = NULL;
view->icon = NULL;
view->icon_uri = NULL;
+ view->memory = midori_view_get_memory ();
view->progress = 0.0;
view->load_status = MIDORI_LOAD_FINISHED;
view->minimized = FALSE;
@@ -3422,32 +3047,7 @@ midori_view_init (MidoriView* view)
view->scrolled_window = katze_scrolled_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view->scrolled_window),
GTK_SHADOW_NONE);
-
- #if GTK_CHECK_VERSION(3, 2, 0)
- view->overlay = gtk_overlay_new ();
- gtk_widget_show (view->overlay);
- gtk_container_add (GTK_CONTAINER (view->overlay), view->scrolled_window);
- gtk_box_pack_start (GTK_BOX (view), view->overlay, TRUE, TRUE, 0);
-
- /* Overlays must be created before showing GtkOverlay as of GTK+ 3.2 */
- {
- GtkWidget* frame = gtk_frame_new (NULL);
- view->overlay_label = gtk_label_new (NULL);
- gtk_widget_show (view->overlay_label);
- gtk_container_add (GTK_CONTAINER (frame), view->overlay_label);
- gtk_widget_set_halign (frame, GTK_ALIGN_START);
- gtk_widget_set_valign (frame, GTK_ALIGN_END);
- gtk_overlay_add_overlay (GTK_OVERLAY (view->overlay), frame);
- }
- view->overlay_find = g_object_new (MIDORI_TYPE_FINDBAR, NULL);
- gtk_widget_set_halign (view->overlay_find, GTK_ALIGN_END);
- gtk_widget_set_valign (view->overlay_find, GTK_ALIGN_START);
- gtk_overlay_add_overlay (GTK_OVERLAY (view->overlay),
- view->overlay_find);
- gtk_widget_set_no_show_all (view->overlay_find, TRUE);
- #else
gtk_box_pack_start (GTK_BOX (view), view->scrolled_window, TRUE, TRUE, 0);
- #endif
g_signal_connect (view->item, "meta-data-changed",
G_CALLBACK (midori_view_item_meta_data_changed), view);
@@ -3477,6 +3077,12 @@ midori_view_finalize (GObject* object)
katze_object_assign (view->icon, NULL);
katze_assign (view->icon_uri, NULL);
+ if (view->memory)
+ {
+ g_hash_table_unref (view->memory);
+ view->memory = NULL;
+ }
+
katze_assign (view->statusbar_text, NULL);
katze_assign (view->link_uri, NULL);
katze_assign (view->selected_text, NULL);
@@ -3511,15 +3117,8 @@ midori_view_set_property (GObject* object,
view->minimized ? 1 : -1);
g_signal_handlers_unblock_by_func (view->item,
midori_view_item_meta_data_changed, view);
- #ifdef HAVE_GRANITE
- if (view->tab)
- g_object_set (view->tab, "label",
- "fixed", view->minimized, NULL);
- //view->minimized ? NULL : midori_view_get_display_title(view), NULL);
- #else
if (view->tab_label)
sokoke_widget_set_visible (view->tab_title, !view->minimized);
- #endif
break;
case PROP_ZOOM_LEVEL:
midori_view_set_zoom_level (view, g_value_get_float (value));
@@ -3730,10 +3329,8 @@ midori_view_settings_notify_cb (MidoriWebSettings* settings,
else if (name == g_intern_string ("close-buttons-on-tabs"))
{
view->close_buttons_on_tabs = g_value_get_boolean (&value);
- #ifndef HAVE_GRANITE
sokoke_widget_set_visible (view->tab_close,
view->close_buttons_on_tabs);
- #endif
}
else if (name == g_intern_string ("open-new-pages-in"))
view->open_new_pages_in = g_value_get_enum (&value);
@@ -3803,14 +3400,7 @@ midori_view_get_progress (MidoriView* view)
{
g_return_val_if_fail (MIDORI_IS_VIEW (view), 0.0);
- /* When we are finished, we don't want to *see* progress anymore */
- if (view->load_status == MIDORI_LOAD_FINISHED)
- return 0.0;
- /* Full progress but not finished: presumably all loaded */
- if (view->progress == 1.0)
- return 0.0;
- /* When loading we want to see at minimum 10% progress */
- return CLAMP (view->progress, 0.1, 1.0);
+ return view->progress;
}
static void
@@ -3820,21 +3410,21 @@ midori_view_web_inspector_construct_window (gpointer inspector,
MidoriView* view)
{
gchar* title;
- const gchar* label;
+ gchar* label;
GtkWidget* window;
GtkWidget* toplevel;
GdkScreen* screen;
gint width, height;
- const gchar* icon_name;
GtkIconTheme* icon_theme;
GdkPixbuf* icon;
GdkPixbuf* gray_icon;
- label = midori_view_get_display_title (view);
+ label = g_strdup (midori_view_get_display_title (view));
title = g_strdup_printf (_("Inspect page - %s"), label);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), title);
g_free (title);
+ g_free (label);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
if (gtk_widget_is_toplevel (toplevel))
@@ -3848,10 +3438,9 @@ midori_view_web_inspector_construct_window (gpointer inspector,
}
/* Attempt to make a gray version of the icon on the fly */
- icon_name = gtk_window_get_icon_name (GTK_WINDOW (toplevel));
icon_theme = gtk_icon_theme_get_for_screen (
gtk_widget_get_screen (GTK_WIDGET (view)));
- icon = gtk_icon_theme_load_icon (icon_theme, icon_name, 32,
+ icon = gtk_icon_theme_load_icon (icon_theme, "midori", 32,
GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
if (icon)
{
@@ -3865,12 +3454,9 @@ midori_view_web_inspector_construct_window (gpointer inspector,
g_object_unref (icon);
}
else
- gtk_window_set_icon_name (GTK_WINDOW (window), icon_name);
- #if GTK_CHECK_VERSION (3, 4, 0)
- gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (window), TRUE);
- #endif
+ gtk_window_set_icon_name (GTK_WINDOW (window), "midori");
gtk_container_add (GTK_CONTAINER (window), inspector_view);
- gtk_widget_show_all (inspector_view);
+ gtk_widget_show_all (window);
g_signal_connect (window, "key-press-event",
G_CALLBACK (midori_view_inspector_window_key_press_event_cb), NULL);
@@ -3902,13 +3488,7 @@ midori_view_web_inspector_show_window_cb (WebKitWebInspector* inspector,
GtkWidget* window = gtk_widget_get_toplevel (GTK_WIDGET (inspector_view));
if (!window)
return FALSE;
- if (katze_object_get_boolean (view->settings, "last-inspector-attached"))
- g_signal_emit_by_name (inspector, "attach-window");
- else
- {
- gtk_widget_show (window);
- gtk_window_present (GTK_WINDOW (window));
- }
+ gtk_window_present (GTK_WINDOW (window));
return TRUE;
}
@@ -3959,7 +3539,7 @@ midori_view_construct_web_view (MidoriView* view)
view->web_view = webkit_web_view_new ();
/* Load something to avoid a bug where WebKit might not set a main frame */
- webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view->web_view), "");
+ webkit_web_view_open (WEBKIT_WEB_VIEW (view->web_view), "");
#if HAVE_HILDON
gtk_widget_tap_and_hold_setup (view->web_view, NULL, NULL, 0);
@@ -4001,9 +3581,7 @@ midori_view_construct_web_view (MidoriView* view)
"signal::hovering-over-link",
webkit_web_view_hovering_over_link_cb, view,
"signal::button-press-event",
- midori_view_web_view_button_press_event_cb, view,
- "signal::button-release-event",
- midori_view_web_view_button_release_event_cb, view,
+ gtk_widget_button_press_event_cb, view,
"signal-after::key-press-event",
gtk_widget_key_press_event_cb, view,
"signal::scroll-event",
@@ -4053,22 +3631,20 @@ midori_view_construct_web_view (MidoriView* view)
NULL);
}
-static void
-list_netscape_plugins (GString* ns_plugins,
- JSContextRef js_context)
+static gchar* list_netscape_plugins ()
{
- if (!midori_web_settings_has_plugin_support ())
- return;
-
+ GtkWidget* web_view = webkit_web_view_new ();
+ WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
+ JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
/* Joins available plugins like this: URI1|title1,URI2|title2 */
gchar* value = sokoke_js_script_eval (js_context,
- "function plugins (l) { var f = new Array (); for (var i in l) "
+ "function plugins (l) { var f = new Array (); for (i in l) "
"{ var p = l[i].name + '|' + l[i].filename; "
"if (f.indexOf (p) == -1) f.push (p); } return f; }"
"plugins (navigator.plugins)", NULL);
gchar** items = g_strsplit (value, ",", 0);
guint i = 0;
- g_string_append (ns_plugins, "Netscape Plugins: ");
+ GString* ns_plugins = g_string_new (NULL);
if (items != NULL)
while (items[i] != NULL)
{
@@ -4086,83 +3662,155 @@ list_netscape_plugins (GString* ns_plugins,
}
if (g_str_has_prefix (value, "undefined"))
g_string_append (ns_plugins, "No plugins found ");
- g_string_append (ns_plugins, "
");
g_strfreev (items);
g_free (value);
-}
-
-static void
-list_geolocation (GString* markup)
-{
- g_string_append (markup,
- " "
- "No Geolocation without Javascript "
- "");
+ gtk_widget_destroy (web_view);
+ return g_string_free (ns_plugins, FALSE);
}
static gchar*
-list_video_formats (JSContextRef js_context)
+list_video_formats ()
{
+ GtkWidget* web_view = webkit_web_view_new ();
+ WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
+ JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
gchar* value = sokoke_js_script_eval (js_context,
"var supported = function (format) { "
"var video = document.createElement('video');"
- "return !!video.canPlayType && video.canPlayType (format) != 'no' "
- "? 'x' : ' '; };"
- "' H264 [' +"
- "supported('video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"') + ']' + "
- "' Ogg Theora [' + "
- "supported('video/ogg; codecs=\"theora, vorbis\"') + ']' + "
- "' WebM [' + "
- "supported('video/webm; codecs=\"vp8, vorbis\"') + ']' "
+ "return !!video.canPlayType && video.canPlayType (format) != 'no' };"
+ "' H264: ' + "
+ "supported('video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"') + "
+ "' Ogg Theora: ' + "
+ "supported('video/ogg; codecs=\"theora, vorbis\"') + "
+ "' WebM: ' + "
+ "supported('video/webm; codecs=\"vp8, vorbis\"')"
"", NULL);
+ gtk_widget_destroy (web_view);
return value;
}
-static const gchar* valid_about_uris[] = {
- "about:widgets",
- "about:private",
- "error:nodocs",
- "http://.invalid",
- "about:geolocation",
- "about:paths",
-};
+static gchar*
+prepare_speed_dial_html (MidoriView* view,
+ gboolean load_missing)
+{
+ MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
+ GKeyFile* key_file;
+ GString* markup = NULL;
+ guint slot_count = 1, i, grid_index = 3, slot_size;
+ gchar* speed_dial_head;
+ gchar* file_path;
+ gchar** groups;
+
+ g_object_get (browser, "speed-dial", &key_file, NULL);
+ file_path = sokoke_find_data_filename ("speeddial-head-" MIDORI_VERSION ".html", TRUE);
+
+ if (key_file != NULL
+ && g_access (file_path, F_OK) == 0
+ && g_file_get_contents (file_path, &speed_dial_head, NULL, NULL))
+ {
+ gchar* header = sokoke_replace_variables (speed_dial_head,
+ "{title}", _("Speed Dial"),
+ "{click_to_add}", _("Click to add a shortcut"),
+ "{enter_shortcut_address}", _("Enter shortcut address"),
+ "{enter_shortcut_name}", _("Enter shortcut title"),
+ "{are_you_sure}", _("Are you sure you want to delete this shortcut?"),
+ NULL);
-static void
-list_about_uris (GString* markup)
-{
- g_string_append (markup, "");
- guint i;
- for (i = 0; i < G_N_ELEMENTS (valid_about_uris); i++)
- g_string_append_printf (markup, "%s ",
- valid_about_uris[i], valid_about_uris[i]);
+ markup = g_string_new (header);
+
+ g_free (speed_dial_head);
+ g_free (file_path);
+ g_free (header);
+ }
+ else
+ {
+ g_free (file_path);
+ return NULL;
+ }
+
+ groups = g_key_file_get_groups (key_file, NULL);
+ for (i = 0; groups[i]; i++)
+ {
+ if (g_key_file_has_key (key_file, groups[i], "uri", NULL))
+ slot_count++;
+ }
+
+ /* try to guess the best X by X grid size */
+ while ((grid_index * grid_index) < slot_count)
+ grid_index++;
+
+ /* percent width size of one slot */
+ slot_size = (100 / grid_index);
+ /* No editing in private/ app mode or without scripts */
+ g_string_append_printf (markup,
+ "%s%s"
+ "\n",
+ sokoke_is_app_or_private () ? "" : "",
+ sokoke_is_app_or_private () ? "" : " ",
+ slot_size + 1, slot_size - 4);
+
+ /* Combined width of slots should always be less than 100%.
+ * Use half of the remaining percentage as a margin size */
+ g_string_append_printf (markup,
+ "",
+ (100 - ((slot_size - 4) * grid_index)) / 2);
+
+ if (katze_object_get_boolean (view->settings, "close-buttons-left"))
+ g_string_append_printf (markup,
+ "");
+
+ for (i = 0; groups[i]; i++)
+ {
+ gchar* uri = g_key_file_get_string (key_file, groups[i], "uri", NULL);
+ if (uri && strstr (uri, "://"))
+ {
+ gchar* title = g_key_file_get_string (key_file, groups[i], "title", NULL);
+ gchar* thumb_file = sokoke_build_thumbnail_path (uri);
+ gchar* encoded;
+ guint slot = atoi (groups[i] + strlen ("Dial "));
+
+ if (g_access (thumb_file, F_OK) == 0)
+ {
+ gsize sz;
+ gchar* thumb_content;
+ g_file_get_contents (thumb_file, &thumb_content, &sz, NULL);
+ encoded = g_base64_encode ((guchar*)thumb_content, sz);
+ g_free (thumb_content);
+ }
+ else
+ {
+ encoded = NULL;
+ if (load_missing)
+ midori_view_speed_dial_get_thumb (view, groups[i], uri);
+ }
+ g_free (thumb_file);
+
+ g_string_append_printf (markup,
+ "
"
+ "
"
+ "
"
+ "
%s
\n",
+ slot, slot, uri, encoded ? encoded : "", slot, title ? title : "");
+
+ g_free (title);
+ g_free (encoded);
+ }
+ else if (strcmp (groups[i], "settings"))
+ g_key_file_remove_group (key_file, groups[i], NULL);
+
+ g_free (uri);
+ }
+ g_strfreev (groups);
+
+ g_string_append_printf (markup,
+ "\n",
+ slot_count + 1, slot_count + 1, _("Click to add a shortcut"));
+ g_string_append_printf (markup,
+ " \n