Initial refactoring work, regressions expected

The 'browser' struct is superseded by MidoriBrowser, which actually
represents a window that holds pages, i.e. tabs. The tabs are currently
of the type MidoriWebView, which is a slightly enhanced WebView. Also
MidoriWebSettings is introduced to hold additional settings that Midori
needs.

The other two new classes are MidoriTrash, representing closed tabs and
windows and MidoriPanel, representing the side panel.

The refactoring allows for several features to be much more easily
implemented, such as full support for multiple windows and instant
saving of modified files, such as bookmarks or the session. Regressions
are expected and not everything is done yet.
This commit is contained in:
Christian Dywan 2008-03-10 22:26:09 +01:00
parent 622f8ee445
commit e1f62329f1
30 changed files with 5740 additions and 3673 deletions

20
HACKING
View file

@ -21,16 +21,16 @@ Source file example:
return; return;
#ifdef BAR_STRICT #ifdef BAR_STRICT
if(bar == FOO_N) if (bar == FOO_N)
{ {
g_print("illegal value for 'bar'.\n"); g_print ("illegal value for 'bar'.\n");
return; return;
} }
#endif #endif
// this is an example // this is an example
gint n; gint n;
switch(bar) switch (bar)
{ {
case FOO_FOO: case FOO_FOO:
n = bar + 1; n = bar + 1;
@ -43,9 +43,9 @@ Source file example:
} }
guint i; guint i;
for(i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
g_print("%s\n", foo); g_print ("%s\n", foo);
} }
} }
@ -74,12 +74,18 @@ Header file example:
typedef struct typedef struct
{ {
FooEnum fooBar; FooEnum foo_bar;
} FooStruct; } FooStruct;
// -- Declarations // -- Declarations
void void
foobar(FooEnum, const gchar*); foo_bar (FooEnum bar,
const gchar* foo);
const gchar*
foo_foo (FooStruct foo_struct,
guint number,
gboolean flag);
#endif /* !__FOO_H__ */ #endif /* !__FOO_H__ */

View file

@ -222,11 +222,9 @@ katze_throbber_destroy (GtkObject *object)
KatzeThrobberPrivate* priv = throbber->priv; KatzeThrobberPrivate* priv = throbber->priv;
katze_assign (priv->icon_name, NULL); katze_assign (priv->icon_name, NULL);
if (priv->pixbuf) katze_object_assign (priv->pixbuf, NULL);
katze_object_assign (priv->pixbuf, NULL);
katze_assign (priv->static_icon_name, NULL); katze_assign (priv->static_icon_name, NULL);
if (priv->static_pixbuf) katze_object_assign (priv->static_pixbuf, NULL);
katze_object_assign (priv->static_pixbuf, NULL);
katze_assign (priv->static_stock_id, NULL); katze_assign (priv->static_stock_id, NULL);
GTK_OBJECT_CLASS (katze_throbber_parent_class)->destroy (object); GTK_OBJECT_CLASS (katze_throbber_parent_class)->destroy (object);

View file

@ -38,7 +38,8 @@ typedef struct _KatzeThrobberClass KatzeThrobberClass;
struct _KatzeThrobber struct _KatzeThrobber
{ {
GtkMisc parent_object; GtkMisc parent_instance;
KatzeThrobberPrivate* priv; KatzeThrobberPrivate* priv;
}; };

View file

@ -15,11 +15,14 @@ bin_PROGRAMS = \
midori_SOURCES = \ midori_SOURCES = \
main.c main.h \ main.c main.h \
browser.c browser.h \ midori-browser.c midori-browser.h \
midori-panel.c midori-panel.h \
midori-trash.c midori-trash.h \
midori-webview.c midori-webview.h \
midori-websettings.c midori-websettings.h \
prefs.c prefs.h \ prefs.c prefs.h \
webSearch.c webSearch.h \ webSearch.c webSearch.h \
helpers.c helpers.h \ helpers.c helpers.h \
webView.c webView.h \
sokoke.c sokoke.h \ sokoke.c sokoke.h \
conf.c conf.h \ conf.c conf.h \
search.c search.h \ search.c search.h \

File diff suppressed because it is too large Load diff

View file

@ -1,600 +0,0 @@
/*
Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __BROWSER_H__
#define __BROWSER_H__ 1
#include "global.h"
#include <gtk/gtk.h>
// -- Types
typedef struct _CBrowser
{
// shared widgets
GtkWidget* window;
GtkActionGroup* actiongroup;
// menus
GtkWidget* menubar;
GtkWidget* menu_bookmarks;
GtkWidget* popup_bookmark;
GtkWidget* menu_window;
GtkWidget* popup_webView;
GtkWidget* popup_element;
GtkWidget* popup_editable;
GtkWidget* throbber;
// navibar
GtkWidget* navibar;
GtkWidget* newTab;
GtkWidget* location_icon;
GtkWidget* location;
GtkWidget* webSearch;
GtkWidget* closedTabs;
GtkWidget* fullscreen;
GtkWidget* bookmarkbar;
// panels
GtkWidget* panels;
GtkWidget* panels_notebook;
GtkWidget* panel_bookmarks;
GtkWidget* panel_pageholder;
GtkWidget* webViews;
// findbox
GtkWidget* findbox;
GtkWidget* findbox_text;
GtkToolItem* findbox_case;
GtkToolItem* findbox_highlight;
GtkWidget* statusbar;
GtkWidget* progress;
GtkWidget* icon_security;
GtkWidget* icon_newsfeed;
// view specific widgets
GtkWidget* webView_menu;
GtkWidget* webView_icon;
GtkWidget* webView_name;
GtkWidget* webView_close;
GtkWidget* webView;
// view specific values
gboolean hasMenubar;
gboolean hasToolbar;
gboolean hasLocation;
gboolean hasStatusbar;
gchar* elementUri; // the element the mouse is hovering on
gint loadedPercent; // -1 means "not loading"
//UNDEFINED favicon;
guint security;
gchar* statusMessage; // message from a webView
KatzeXbelItem* sessionItem;
} CBrowser;
enum
{
SEARCH_COL_ICON,
SEARCH_COL_TEXT,
SEARCH_COL_N
};
// -- Declarations
void
on_action_window_new_activate(GtkAction*, CBrowser*);
void
on_action_tab_new_activate(GtkAction*, CBrowser*);
void
on_action_open_activate(GtkAction*, CBrowser*);
void
on_action_tab_close_activate(GtkAction*, CBrowser*);
void
on_action_window_close_activate(GtkAction*, CBrowser*);
void
on_action_quit_activate(GtkAction*, CBrowser*);
void
on_action_edit_activate(GtkAction*, CBrowser*);
void
on_action_cut_activate(GtkAction*, CBrowser*);
void
on_action_copy_activate(GtkAction*, CBrowser*);
void
on_action_paste_activate(GtkAction*, CBrowser*);
void
on_action_delete_activate(GtkAction*, CBrowser*);
void
on_action_selectAll_activate(GtkAction*, CBrowser*);
void
on_action_find_activate(GtkAction*, CBrowser*);
void
on_action_find_next_activate(GtkAction*, CBrowser*);
void
on_action_find_previous_activate(GtkAction*, CBrowser*);
void
on_action_preferences_activate(GtkAction*, CBrowser*);
void
on_action_toolbar_navigation_activate(GtkToggleAction*, CBrowser*);
void
on_action_toolbar_bookmarks_activate(GtkToggleAction*, CBrowser*);
void
on_action_panels_activate(GtkToggleAction*, CBrowser*);
void
on_action_toolbar_status_activate(GtkToggleAction*, CBrowser*);
void
on_action_refresh_stop_activate(GtkAction*, CBrowser*);
void
on_action_zoom_in_activate(GtkAction*, CBrowser*);
void
on_action_zoom_out_activate(GtkAction*, CBrowser*);
void
on_action_zoom_normal_activate(GtkAction*, CBrowser*);
void
on_action_source_view_activate(GtkAction*, CBrowser*);
void
on_action_fullscreen_activate(GtkAction*, CBrowser*);
void
on_action_back_activate(GtkAction*, CBrowser*);
void
on_action_forward_activate(GtkAction*, CBrowser*);
void
on_action_home_activate(GtkAction*, CBrowser*);
void
on_action_location_activate(GtkAction*, CBrowser*);
void
on_action_webSearch_activate(GtkAction*, CBrowser*);
void
on_action_openInPanel_activate(GtkAction*, CBrowser*);
void
on_menu_tabsClosed_activate(GtkWidget*, CBrowser*);
void
on_menu_tabsClosed_item_activate(GtkWidget*, CBrowser*);
void
on_action_tabsClosed_clear_activate(GtkAction*, CBrowser*);
void
on_action_tabsClosed_undo_activate(GtkAction*, CBrowser*);
void
on_action_link_tab_new_activate(GtkAction*, CBrowser*);
void
on_action_link_tab_current_activate(GtkAction*, CBrowser*);
void
on_action_link_window_new_activate(GtkAction*, CBrowser*);
void
on_action_link_saveWith_activate(GtkAction*, CBrowser*);
void
on_action_link_copy_activate(GtkAction*, CBrowser*);
void
on_action_bookmarkOpen_activate(GtkAction*, CBrowser*);
void
on_action_bookmarkOpenTab_activate(GtkAction*, CBrowser*);
void
on_action_bookmarkOpenWindow_activate(GtkAction*, CBrowser*);
void
on_action_bookmarkEdit_activate(GtkAction*, CBrowser*);
void
on_action_bookmarkDelete_activate(GtkAction*, CBrowser*);
void
on_menu_bookmarks_item_activate(GtkWidget*, CBrowser*);
void
on_action_bookmark_new_activate(GtkAction*, CBrowser*);
void
on_action_manageSearchEngines_activate(GtkAction*, CBrowser*);
void
on_action_tab_previous_activate(GtkAction*, CBrowser*);
void
on_action_tab_next_activate(GtkAction*, CBrowser*);
void
on_action_about_activate(GtkAction*, CBrowser*);
gboolean
on_location_key_down(GtkWidget*, GdkEventKey*, CBrowser*);
CBrowser*
browser_new(CBrowser*);
// -- Action definitions
// TODO: Fill in a good description for each 'hm?'
static const GtkActionEntry entries[] = {
{ "File", NULL, "_File" },
{ "WindowNew", STOCK_WINDOW_NEW
, NULL, "<Ctrl>n"
, "Open a new window", G_CALLBACK(on_action_window_new_activate) },
{ "TabNew", STOCK_TAB_NEW
, NULL, "<Ctrl>t"
, "Open a new tab", G_CALLBACK(on_action_tab_new_activate) },
{ "Open", GTK_STOCK_OPEN
, NULL, "<Ctrl>o"
, "Open a file", G_CALLBACK(on_action_open_activate) },
{ "SaveAs", GTK_STOCK_SAVE_AS
, NULL, "<Ctrl>s"
, "Save to a file", NULL/*G_CALLBACK(on_action_saveas_activate)*/ },
{ "TabClose", STOCK_TAB_CLOSE
, NULL, "<Ctrl>w"
, "Close the current tab", G_CALLBACK(on_action_tab_close_activate) },
{ "WindowClose", STOCK_WINDOW_CLOSE
, NULL, "<Ctrl><Shift>w"
, "Close this window", G_CALLBACK(on_action_window_close_activate) },
{ "PageSetup", GTK_STOCK_PROPERTIES
, "Pa_ge Setup", ""
, "hm?", NULL/*G_CALLBACK(on_action_page_setup_activate)*/ },
{ "PrintPreview", GTK_STOCK_PRINT_PREVIEW
, NULL, ""
, "hm?", NULL/*G_CALLBACK(on_action_print_preview_activate)*/ },
{ "Print", GTK_STOCK_PRINT
, NULL, "<Ctrl>p"
, "hm?", NULL/*G_CALLBACK(on_action_print_activate)*/ },
{ "Quit", GTK_STOCK_QUIT
, NULL, "<Ctrl>q"
, "Quit the application", G_CALLBACK(on_action_quit_activate) },
{ "Edit", NULL, "_Edit", NULL, NULL, G_CALLBACK(on_action_edit_activate) },
{ "Undo", GTK_STOCK_UNDO
, NULL, "<Ctrl>z"
, "Undo the last modification", NULL/*G_CALLBACK(on_action_undo_activate)*/ },
{ "Redo", GTK_STOCK_REDO
, NULL, "<Ctrl><Shift>z"
, "Redo the last modification", NULL/*G_CALLBACK(on_action_redo_activate)*/ },
{ "Cut", GTK_STOCK_CUT
, NULL, "<Ctrl>x"
, "Cut the selected text", G_CALLBACK(on_action_cut_activate) },
{ "Copy", GTK_STOCK_COPY
, NULL, "<Ctrl>c"
, "Copy the selected text", G_CALLBACK(on_action_copy_activate) },
{ "Copy_", GTK_STOCK_COPY
, NULL, "<Ctrl>c"
, "Copy the selected text", G_CALLBACK(on_action_copy_activate) },
{ "Paste", GTK_STOCK_PASTE
, NULL, "<Ctrl>v"
, "Paste text from the clipboard", G_CALLBACK(on_action_paste_activate) },
{ "Delete", GTK_STOCK_DELETE
, NULL, NULL
, "Delete the selected text", G_CALLBACK(on_action_delete_activate) },
{ "SelectAll", GTK_STOCK_SELECT_ALL
, NULL, "<Ctrl>a"
, "Selected all text", G_CALLBACK(on_action_selectAll_activate) },
{ "FormFill", STOCK_FORM_FILL
, NULL, ""
, "hm?", NULL/*G_CALLBACK(on_action_formfill_activate)*/ },
{ "Find", GTK_STOCK_FIND
, NULL, "<Ctrl>f"
, "hm?", G_CALLBACK(on_action_find_activate) },
{ "FindNext", GTK_STOCK_GO_FORWARD
, "Find _Next", "<Ctrl>g"
, "hm?", G_CALLBACK(on_action_find_next_activate) },
{ "FindPrevious", GTK_STOCK_GO_BACK
, "Find _Previous", "<Ctrl><Shift>g"
, "hm?", G_CALLBACK(on_action_find_previous_activate) },
{ "FindQuick", GTK_STOCK_FIND
, "_Quick Find", "period"
, "hm?", NULL/*G_CALLBACK(on_action_find_quick_activate)*/ },
{ "ManageSearchEngines", GTK_STOCK_PROPERTIES
, "_Manage Search Engines", "<Ctrl><Alt>s"
, "hm?", G_CALLBACK(on_action_manageSearchEngines_activate) },
{ "Preferences", GTK_STOCK_PREFERENCES
, NULL, "<Ctrl><Alt>p"
, "hm?", G_CALLBACK(on_action_preferences_activate) },
{ "View", NULL, "_View" },
{ "Toolbars", NULL, "_Toolbars" },
{ "Refresh", GTK_STOCK_REFRESH
, NULL, "<Ctrl>r"
, "Refresh the current page", G_CALLBACK(on_action_refresh_stop_activate) },
// TODO: Is appointment-new a good choice?
// TODO: What if it isn't available?
{ "RefreshEvery", "appointment-new"
, "Refresh _Every...", ""
, "Refresh the current page", G_CALLBACK(on_action_refresh_stop_activate) },
{ "Stop", GTK_STOCK_STOP
, NULL, "Escape"
, "Stop loading of the current page", G_CALLBACK(on_action_refresh_stop_activate) },
{ "RefreshStop", GTK_STOCK_REFRESH
, NULL, ""
, NULL, G_CALLBACK(on_action_refresh_stop_activate) },
{ "ZoomIn", GTK_STOCK_ZOOM_IN
, NULL, "<Ctrl>plus"
, "hm?", G_CALLBACK(on_action_zoom_in_activate) },
{ "ZoomOut", GTK_STOCK_ZOOM_OUT
, NULL, "<Ctrl>minus"
, "hm?", G_CALLBACK(on_action_zoom_out_activate) },
{ "ZoomNormal", GTK_STOCK_ZOOM_100
, NULL, "<Ctrl>0"
, "hm?", G_CALLBACK(on_action_zoom_normal_activate) },
{ "BackgroundImage", STOCK_IMAGE
, "_Background Image", ""
, "hm?", NULL/*G_CALLBACK(on_action_background_image_activate)*/ },
{ "SourceView", STOCK_SOURCE_VIEW
, NULL, ""
, "hm?", /*G_CALLBACK(on_action_source_view_activate)*/ },
{ "SelectionSourceView", STOCK_SOURCE_VIEW
, "View Selection Source", ""
, "hm?", NULL/*G_CALLBACK(on_action_selection_source_view_activate)*/ },
{ "Properties", GTK_STOCK_PROPERTIES
, NULL, ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_activate)*/ },
{ "Fullscreen", GTK_STOCK_FULLSCREEN
, NULL, "F11"
, "Toggle fullscreen view", G_CALLBACK(on_action_fullscreen_activate) },
{ "Go", NULL, "_Go" },
{ "Back", GTK_STOCK_GO_BACK
, NULL, "<Alt>Left"
, "hm?", G_CALLBACK(on_action_back_activate) },
{ "Forward", GTK_STOCK_GO_FORWARD
, NULL, "<Alt>Right"
, "hm?", G_CALLBACK(on_action_forward_activate) },
{ "Home", STOCK_HOMEPAGE
, NULL, "<Alt>Home"
, "hm?", G_CALLBACK(on_action_home_activate) },
{ "Location", GTK_STOCK_JUMP_TO
, "Location...", "<Ctrl>l"
, "hm?", G_CALLBACK(on_action_location_activate) },
{ "Websearch", GTK_STOCK_FIND
, "Websearch...", "<Ctrl><Shift>f"
, "hm?", G_CALLBACK(on_action_webSearch_activate) },
{ "OpenInPageholder", GTK_STOCK_JUMP_TO
, "Open in Page_holder...", ""
, "hm?", G_CALLBACK(on_action_openInPanel_activate) },
{ "TabsClosed", STOCK_USER_TRASH
, "Closed Tabs", ""
, "hm?", NULL },
{ "TabsClosedClear", GTK_STOCK_CLEAR
, "Clear List of Closed Tabs", ""
, "hm?", G_CALLBACK(on_action_tabsClosed_clear_activate) },
{ "UndoTabClose", GTK_STOCK_UNDELETE
, "Undo Close Tab", ""
, "hm?", G_CALLBACK(on_action_tabsClosed_undo_activate) },
{ "LinkTabNew", STOCK_TAB_NEW
, "Open Link in New Tab", ""
, "hm?", G_CALLBACK(on_action_link_tab_new_activate) },
{ "LinkTabCurrent", NULL
, "Open Link in Current Tab", ""
, "hm?", G_CALLBACK(on_action_link_tab_current_activate) },
{ "LinkWindowNew", STOCK_WINDOW_NEW
, "Open Link in New Window", ""
, "hm?", G_CALLBACK(on_action_link_window_new_activate) },
{ "LinkBookmarkNew", STOCK_BOOKMARK_NEW
, NULL, ""
, "Bookmark this link", NULL/*G_CALLBACK(on_action_link_bookmark_activate)*/ },
{ "LinkSaveAs", GTK_STOCK_SAVE
, "Save Destination as...", ""
, "Save destination to a file", NULL/*G_CALLBACK(on_action_link_saveas_activate)*/ },
{ "LinkSaveWith", STOCK_DOWNLOADS
, "Download Destination", ""
, "Save destination with the chosen download manager", G_CALLBACK(on_action_link_saveWith_activate) },
{ "LinkCopy", GTK_STOCK_COPY
, "Copy Link Address", ""
, "Copy the link address to the clipboard", G_CALLBACK(on_action_link_copy_activate) },
{ "SelectionLinksNewTabs", NULL
, "Open Selected Links in Tabs", ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "SelectionTextTabNew", STOCK_TAB_NEW
, "Open <Selection> in New Tab", ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "SelectionTextTabCurrent", NULL
, "Open <Selection> in Current Tab", ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "SelectionTextWindowNew", STOCK_WINDOW_NEW
, "Open <Selection> in New Qindow", ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "SelectionSearch", GTK_STOCK_FIND
, "Search for <Selection>", ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "SelectionSearchWith", GTK_STOCK_FIND
, "Search for <Selection> with...", ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "ImageViewTabNew", STOCK_TAB_NEW
, "View Image in New Tab", ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "ImageViewTabCurrent", NULL
, "View image in current tab", ""
, "hm?", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "ImageSaveAs", GTK_STOCK_SAVE
, "Save Image as...", ""
, "Save image to a file", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "ImageSaveWith", STOCK_DOWNLOADS
, "Download Image", ""
, "Save image with the chosen download manager", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "ImageCopy", GTK_STOCK_COPY
, "Copy Image Address", ""
, "Copy the image address to the clipboard", NULL/*G_CALLBACK(on_action_properties_selection_activate)*/ },
{ "Bookmarks", NULL, "_Bookmarks" },
{ "BookmarkNew", STOCK_BOOKMARK_NEW
, NULL, "<Ctrl>d"
, "hm?", G_CALLBACK(on_action_bookmark_new_activate) },
{ "BookmarksManage", STOCK_BOOKMARKS
, "_Manage Bookmarks", "<Ctrl>b"
, "hm?", NULL/*G_CALLBACK(on_action_bookmarks_manage_activate)*/ },
{ "BookmarkOpen", GTK_STOCK_OPEN
, NULL, ""
, "hm?", G_CALLBACK(on_action_bookmarkOpen_activate) },
{ "BookmarkOpenTab", STOCK_TAB_NEW
, "Open in New _Tab", ""
, "hm?", G_CALLBACK(on_action_bookmarkOpenTab_activate) },
{ "BookmarkOpenWindow", STOCK_WINDOW_NEW
, "Open in New _Window", ""
, "hm?", G_CALLBACK(on_action_bookmarkOpenWindow_activate) },
{ "BookmarkEdit", GTK_STOCK_EDIT
, NULL, ""
, "hm?", G_CALLBACK(on_action_bookmarkEdit_activate) },
{ "BookmarkDelete", GTK_STOCK_DELETE
, NULL, ""
, "hm?", G_CALLBACK(on_action_bookmarkDelete_activate) },
{ "Tools", NULL, "_Tools" },
{ "Window", NULL, "_Window" },
{ "SessionLoad", GTK_STOCK_REVERT_TO_SAVED
, "_Load Session", ""
, "hm?", NULL/*G_CALLBACK(on_action_session_load_activate)*/ },
{ "SessionSave", GTK_STOCK_SAVE_AS
, "_Save Session", ""
, "hm?", NULL/*G_CALLBACK(on_action_session_save_activate)*/ },
{ "TabPrevious", GTK_STOCK_GO_BACK
, "_Previous Tab", "<Ctrl>Page_Up"
, "hm?", G_CALLBACK(on_action_tab_previous_activate) },
{ "TabNext", GTK_STOCK_GO_FORWARD
, "_Next Tab", "<Ctrl>Page_Down"
, "hm?", G_CALLBACK(on_action_tab_next_activate) },
{ "TabOverview", NULL
, "Tab _Overview", ""
, "hm?", NULL/*G_CALLBACK(on_action_tab_overview_activate)*/ },
{ "Help", NULL, "_Help" },
{ "HelpContents", GTK_STOCK_HELP
, "_Contents", "F1"
, "hm?", NULL/*G_CALLBACK(on_action_help_contents_activate)*/ },
{ "About", GTK_STOCK_ABOUT
, NULL, ""
, "hm?", G_CALLBACK(on_action_about_activate) },
};
static const guint entries_n = G_N_ELEMENTS(entries);
static const GtkToggleActionEntry toggle_entries[] = {
{ "PrivateBrowsing", NULL
, "P_rivate Browsing", ""
, "hm?", NULL/*G_CALLBACK(on_action_private_browsing_activate)*/
, FALSE },
{ "WorkOffline", GTK_STOCK_DISCONNECT
, "_Work Offline", ""
, "hm?", NULL/*G_CALLBACK(on_action_work_offline_activate)*/
, FALSE },
{ "ToolbarNavigation", NULL
, "_Navigationbar", ""
, "hm?", G_CALLBACK(on_action_toolbar_navigation_activate)
, FALSE },
{ "Panels", NULL
, "_Panels", "F9"
, "hm?", G_CALLBACK(on_action_panels_activate)
, FALSE },
{ "ToolbarBookmarks", NULL
, "_Bookmarkbar", ""
, "hm?", G_CALLBACK(on_action_toolbar_bookmarks_activate)
, FALSE },
{ "ToolbarDownloads", NULL
, "_Downloadbar", ""
, "hm?", NULL/*G_CALLBACK(on_action_toolbar_downloads_activate)*/
, FALSE },
{ "ToolbarStatus", NULL
, "_Statusbar", ""
, "hm?", G_CALLBACK(on_action_toolbar_status_activate)
, FALSE },
{ "RefreshEveryEnable", NULL
, "_Enabled", ""
, "hm?", NULL/*G_CALLBACK(on_action_reloadevery_enable_activate)*/
, FALSE },
{ "ReloadEveryActive", NULL
, "_Active", ""
, "hm?", NULL/*G_CALLBACK(on_action_reloadevery_active_activate)*/
, FALSE },
};
static const guint toggle_entries_n = G_N_ELEMENTS(toggle_entries);
static const GtkRadioActionEntry refreshevery_entries[] = {
{ "RefreshEvery30", NULL
, "30 seconds", ""
, "Refresh Every _30 Seconds", 30 },
{ "RefreshEvery60", NULL
, "60 seconds", ""
, "Refresh Every _60 Seconds", 60 },
{ "RefreshEvery300", NULL
, "5 minutes", ""
, "Refresh Every _5 Minutes", 300 },
{ "RefreshEvery900", NULL
, "15 minutes", ""
, "Refresh Every _15 Minutes", 900 },
{ "RefreshEvery1800", NULL
, "30 minutes", ""
, "Refresh Every 3_0 Minutes", 1800 },
{ "RefreshEveryCustom", NULL
, "Custom...", ""
, "Refresh by a _Custom Period", 0 },
};
static const guint refreshevery_entries_n = G_N_ELEMENTS(refreshevery_entries);
static const GtkRadioActionEntry panel_entries[] = {
{ "PanelDownloads", STOCK_DOWNLOADS
, NULL, ""
, "hm?", 0 },
{ "PanelBookmarks", STOCK_BOOKMARKS
, "_Bookmarks", ""
, "hm?", 1 },
{ "PanelConsole", STOCK_CONSOLE
, NULL, ""
, "hm?", 2 },
{ "PanelExtensions", STOCK_EXTENSIONS
, NULL, ""
, "hm?", 3 },
{ "PanelHistory", STOCK_HISTORY
, "_History", ""
, "hm?", 4 },
// TODO: We want a better icon here, but which one?
{ "PanelTabs", STOCK_TAB_NEW
, "_Tabs", ""
, "hm?", 5 },
// TODO: We probably want another icon here
{ "PanelPageholder", GTK_STOCK_CONVERT
, "_Pageholder", ""
, "hm?", 6 },
};
static const guint panel_entries_n = G_N_ELEMENTS(panel_entries);
#endif /* !__BROWSER_H__ */

View file

@ -13,21 +13,19 @@
#define __GLOBAL_H__ 1 #define __GLOBAL_H__ 1
#include "conf.h" #include "conf.h"
#include "midori-websettings.h"
#include "../katze/katze.h" #include "../katze/katze.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <webkit/webkit.h> #include <webkit/webkit.h>
// -- globals // FIXME: Remove these globals
CConfig* config;
GList* searchEngines; // Items of type 'SearchEngine' GList* searchEngines; // Items of type 'SearchEngine'
GList* browsers; // Items of type 'CBrowser'
WebKitWebSettings* webSettings;
GtkAccelGroup* accel_group;
KatzeXbelItem* bookmarks; KatzeXbelItem* bookmarks;
KatzeXbelItem* session; CConfig* config;
KatzeXbelItem* tabtrash; MidoriWebSettings* webSettings;
// Custom stock items // Custom stock items
@ -37,13 +35,7 @@ KatzeXbelItem* tabtrash;
in order to reduce the amount of warnings :D */ in order to reduce the amount of warnings :D */
#define STOCK_BOOKMARK GTK_STOCK_FILE // "stock_bookmark" // "bookmark-web" #define STOCK_BOOKMARK GTK_STOCK_FILE // "stock_bookmark" // "bookmark-web"
#define STOCK_BOOKMARKS "bookmark-view"
#define STOCK_DOWNLOADS "package" // "download"
#define STOCK_CONSOLE "terminal" // "console" // MISSING
#define STOCK_EXTENSIONS "extension" // MISSING
#define STOCK_FORM_FILL "insert-text" // "form-fill" // MISSING #define STOCK_FORM_FILL "insert-text" // "form-fill" // MISSING
#define STOCK_HISTORY "document-open-recent"
#define STOCK_HISTORY_ "history-view"
#define STOCK_LOCATION "location-entry" #define STOCK_LOCATION "location-entry"
#define STOCK_NEWSFEED "gtk-index" // "newsfeed" // MISSING #define STOCK_NEWSFEED "gtk-index" // "newsfeed" // MISSING
#define STOCK_PLUGINS "plugin" // MISSING #define STOCK_PLUGINS "plugin" // MISSING

View file

@ -11,78 +11,24 @@
#include "helpers.h" #include "helpers.h"
#include "global.h"
#include "search.h" #include "search.h"
#include "sokoke.h" #include "sokoke.h"
#include "../katze/katze.h"
#include "midori-webview.h"
#include <katze/katze.h>
#include <string.h> #include <string.h>
#include <webkit/webkit.h> #include <webkit/webkit.h>
GtkIconTheme* get_icon_theme(GtkWidget* widget)
{
return gtk_icon_theme_get_for_screen(gtk_widget_get_screen(widget));
}
GtkWidget* menu_item_new(const gchar* text, const gchar* icon
, GCallback signal, gboolean sensitive, gpointer userdata)
{
GtkWidget* menuitem;
if(text)
menuitem = gtk_image_menu_item_new_with_mnemonic(text);
else
menuitem = gtk_image_menu_item_new_from_stock(icon, NULL);
if(icon)
{
GtkWidget* image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU);
if(gtk_image_get_storage_type(GTK_IMAGE(image)) == GTK_IMAGE_EMPTY)
image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_MENU);
if(gtk_image_get_storage_type(GTK_IMAGE(image)) != GTK_IMAGE_EMPTY)
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
else
g_print("Note: The icon %s is not available.", icon);
}
if(signal)
g_signal_connect(menuitem, "activate", signal, userdata);
gtk_widget_set_sensitive(GTK_WIDGET(menuitem), sensitive && signal);
return menuitem;
}
GtkToolItem* tool_button_new(const gchar* text, const gchar* icon
, gboolean important, gboolean sensitive, GCallback signal
, const gchar* tooltip, gpointer userdata)
{
GtkToolItem* toolbutton = gtk_tool_button_new(NULL, NULL);
GtkStockItem stockItem;
if(gtk_stock_lookup(icon, &stockItem))
toolbutton = gtk_tool_button_new_from_stock(icon);
else
{
GtkIconTheme* iconTheme = get_icon_theme(GTK_WIDGET(toolbutton));
if(gtk_icon_theme_has_icon(iconTheme, icon))
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(toolbutton), icon);
else
gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(toolbutton), GTK_STOCK_MISSING_IMAGE);
}
if(text)
gtk_tool_button_set_label(GTK_TOOL_BUTTON(toolbutton), text);
if(important)
gtk_tool_item_set_is_important(toolbutton, TRUE);
if(signal)
g_signal_connect(toolbutton, "clicked", signal, userdata);
gtk_widget_set_sensitive(GTK_WIDGET(toolbutton), sensitive && signal);
if(tooltip)
sokoke_tool_item_set_tooltip_text(toolbutton, tooltip);
return toolbutton;
}
GtkWidget* check_menu_item_new(const gchar* text GtkWidget* check_menu_item_new(const gchar* text
, GCallback signal, gboolean sensitive, gboolean active, CBrowser* browser) , GCallback signal, gboolean sensitive, gboolean active, gpointer userdata)
{ {
GtkWidget* menuitem = gtk_check_menu_item_new_with_mnemonic(text); GtkWidget* menuitem = gtk_check_menu_item_new_with_mnemonic(text);
gtk_widget_set_sensitive(menuitem, sensitive && signal); gtk_widget_set_sensitive(menuitem, sensitive && signal);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active);
if(signal) if(signal)
g_signal_connect(menuitem, "activate", signal, browser); g_signal_connect(menuitem, "activate", signal, userdata);
return menuitem; return menuitem;
} }
@ -91,10 +37,10 @@ GtkWidget* radio_button_new(GtkRadioButton* radio_button, const gchar* label)
return gtk_radio_button_new_with_mnemonic_from_widget(radio_button, label); return gtk_radio_button_new_with_mnemonic_from_widget(radio_button, label);
} }
void show_error(const gchar* text, const gchar* text2, CBrowser* browser) void show_error(const gchar* text, const gchar* text2, MidoriBrowser* browser)
{ {
GtkWidget* dialog = gtk_message_dialog_new( GtkWidget* dialog = gtk_message_dialog_new(
browser ? GTK_WINDOW(browser->window) : NULL browser ? GTK_WINDOW(browser) : NULL
, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, text); , 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, text);
if(text2) if(text2)
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), text2); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), text2);
@ -191,223 +137,6 @@ void entry_completion_append(GtkEntry* entry, const gchar* text)
gtk_list_store_set(GTK_LIST_STORE(completion_store), &iter, 0, text, -1); gtk_list_store_set(GTK_LIST_STORE(completion_store), &iter, 0, text, -1);
} }
GtkWidget* get_nth_webView(gint n, CBrowser* browser)
{
if(n < 0)
n = gtk_notebook_get_current_page(GTK_NOTEBOOK(browser->webViews));
GtkWidget* scrolled = gtk_notebook_get_nth_page(GTK_NOTEBOOK(browser->webViews), n);
return gtk_bin_get_child(GTK_BIN(scrolled));
}
gint get_webView_index(GtkWidget* webView, CBrowser* browser)
{
GtkWidget* scrolled = gtk_widget_get_parent(webView);
return gtk_notebook_page_num(GTK_NOTEBOOK(browser->webViews), scrolled);
}
CBrowser* get_browser_from_webView(GtkWidget* webView)
{
// FIXME: g_list_first
CBrowser* browser = NULL; GList* item = g_list_first(browsers);
do
{
browser = (CBrowser*)item->data;
if(browser->webView == webView)
return browser;
}
while((item = g_list_next(item)));
return NULL;
}
void update_favicon(CBrowser* browser)
{
if(browser->loadedPercent == -1)
{
if(0) //browser->favicon // Has favicon?
{
// TODO: use custom icon
// gtk_image_set_from_file(GTK_IMAGE(browser->icon_page), "image");
}
else if(0) // Known mime-type?
{
// TODO: Retrieve mime type and load icon; don't forget ftp listings
}
else
katze_throbber_set_static_stock_id(KATZE_THROBBER(browser->webView_icon)
, GTK_STOCK_FILE);
}
katze_throbber_set_animated(KATZE_THROBBER(browser->webView_icon)
, browser->loadedPercent != -1);
}
void update_security(CBrowser* browser)
{
const gchar* uri = katze_xbel_bookmark_get_href(browser->sessionItem);
// TODO: This check is bogus, until webkit tells us how secure a page is
if(g_str_has_prefix(uri, "https://"))
{
// TODO: highlighted entry indicates security, find an alternative
gtk_widget_modify_base(browser->location, GTK_STATE_NORMAL
, &browser->location->style->base[GTK_STATE_SELECTED]);
gtk_widget_modify_text(browser->location, GTK_STATE_NORMAL
, &browser->location->style->text[GTK_STATE_SELECTED]);
gtk_image_set_from_stock(GTK_IMAGE(browser->icon_security)
, GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_MENU);
}
else
{
gtk_widget_modify_base(browser->location, GTK_STATE_NORMAL, NULL);
gtk_widget_modify_text(browser->location, GTK_STATE_NORMAL, NULL);
gtk_image_set_from_stock(GTK_IMAGE(browser->icon_security)
, GTK_STOCK_INFO, GTK_ICON_SIZE_MENU);
}
}
void update_visibility(CBrowser* browser, gboolean visibility)
{
// A tabbed window shouldn't be manipulatable
if(gtk_notebook_get_n_pages(GTK_NOTEBOOK(browser->webViews)) > 1)
return;
// SHOULD SCRIPTS BE ABLE TO HIDE WINDOWS AT ALL?
if(0 && !visibility)
{
gtk_widget_hide(browser->window);
return;
}
else if(!visibility)
g_print("Window was not hidden.\n");
sokoke_widget_set_visible(browser->menubar, browser->hasMenubar);
sokoke_widget_set_visible(browser->navibar, browser->hasToolbar);
sokoke_widget_set_visible(browser->location, browser->hasLocation);
sokoke_widget_set_visible(browser->webSearch, browser->hasLocation);
sokoke_widget_set_visible(browser->statusbar, browser->hasStatusbar);
}
void action_set_active(const gchar* name, gboolean active, CBrowser* browser)
{
// This shortcut toggles activity state by an action name
GtkAction* action = gtk_action_group_get_action(browser->actiongroup, name);
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), active);
}
void action_set_sensitive(const gchar* name, gboolean sensitive, CBrowser* browser)
{
// This shortcut toggles sensitivity by an action name
GtkAction* action = gtk_action_group_get_action(browser->actiongroup, name);
gtk_action_set_sensitive(action, sensitive);
}
void action_set_visible(const gchar* name, gboolean visible, CBrowser* browser)
{
// This shortcut toggles visibility by an action name
GtkAction* action = gtk_action_group_get_action(browser->actiongroup, name);
gtk_action_set_visible(action, visible);
}
void update_statusbar(CBrowser* browser)
{
gtk_statusbar_pop(GTK_STATUSBAR(browser->statusbar), 1);
gtk_statusbar_push(GTK_STATUSBAR(browser->statusbar), 1
, browser->statusMessage ? browser->statusMessage : "");
if(browser->loadedPercent > -1)
{
if(browser->loadedPercent > -1)
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(browser->progress)
, browser->loadedPercent ? browser->loadedPercent / 100.0 : 0);
else
gtk_progress_bar_pulse(GTK_PROGRESS_BAR(browser->progress));
gchar* message = g_strdup_printf("%d%% loaded", browser->loadedPercent);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(browser->progress), message);
g_free(message);
}
}
void update_edit_items(CBrowser* browser)
{
GtkWidget* widget = gtk_window_get_focus(GTK_WINDOW(browser->window));
gboolean canCut = FALSE; gboolean canCopy = FALSE; gboolean canPaste = FALSE;
if(widget && (WEBKIT_IS_WEB_VIEW(widget) || GTK_IS_EDITABLE(widget)))
{
gboolean hasSelection = WEBKIT_IS_WEB_VIEW(widget)
? webkit_web_view_has_selection(WEBKIT_WEB_VIEW(widget))
: gtk_editable_get_selection_bounds(GTK_EDITABLE(widget), NULL, NULL);
canCut = WEBKIT_IS_WEB_VIEW(widget)
? webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(widget))
: hasSelection && gtk_editable_get_editable(GTK_EDITABLE(widget));
canCopy = WEBKIT_IS_WEB_VIEW(widget)
? webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(widget))
: hasSelection;
canPaste = WEBKIT_IS_WEB_VIEW(widget)
? webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(widget))
: gtk_editable_get_editable(GTK_EDITABLE(widget));
action_set_sensitive("SelectAll", TRUE, browser);
}
else
action_set_sensitive("SelectAll", FALSE, browser);
action_set_sensitive("Cut", canCut, browser);
action_set_sensitive("Copy", canCopy, browser);
action_set_sensitive("Paste", canPaste, browser);
action_set_sensitive("Delete", canCut, browser);
}
void update_gui_state(CBrowser* browser)
{
GtkWidget* webView = get_nth_webView(-1, browser);
action_set_sensitive("ZoomIn", FALSE, browser);//webkit_web_view_can_increase_text_size(WEBKIT_WEB_VIEW(webView), browser);
action_set_sensitive("ZoomOut", FALSE, browser);//webkit_web_view_can_decrease_text_size(WEBKIT_WEB_VIEW(webView)), browser);
action_set_sensitive("ZoomNormal", FALSE, browser);//webkit_web_view_get_text_size(WEBKIT_WEB_VIEW(webView)) != 1, browser);
action_set_sensitive("Back", webkit_web_view_can_go_back(WEBKIT_WEB_VIEW(webView)), browser);
action_set_sensitive("Forward", webkit_web_view_can_go_forward(WEBKIT_WEB_VIEW(webView)), browser);
action_set_sensitive("Refresh", browser->loadedPercent == -1, browser);
action_set_sensitive("Stop", browser->loadedPercent != -1, browser);
GtkAction* action = gtk_action_group_get_action(browser->actiongroup, "RefreshStop");
if(browser->loadedPercent == -1)
{
gtk_widget_set_sensitive(browser->throbber, FALSE);
g_object_set(action, "stock-id", GTK_STOCK_REFRESH, NULL);
g_object_set(action, "tooltip", "Refresh the current page", NULL);
gtk_widget_hide(browser->progress);
}
else
{
gtk_widget_set_sensitive(browser->throbber, TRUE);
g_object_set(action, "stock-id", GTK_STOCK_STOP, NULL);
g_object_set(action, "tooltip", "Stop loading the current page", NULL);
gtk_widget_show(browser->progress);
}
katze_throbber_set_animated(KATZE_THROBBER(browser->throbber)
, browser->loadedPercent != -1);
gtk_image_set_from_stock(GTK_IMAGE(browser->location_icon), GTK_STOCK_FILE
, GTK_ICON_SIZE_MENU);
}
void update_feeds(CBrowser* browser)
{
// TODO: Look for available feeds, requires dom access
}
void update_search_engines(CBrowser* browser)
{
// TODO: Look for available search engines, requires dom access
}
void update_browser_actions(CBrowser* browser)
{
gboolean active = gtk_notebook_get_n_pages(GTK_NOTEBOOK(browser->webViews)) > 1;
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(browser->webViews), active);
action_set_sensitive("TabClose", active, browser);
action_set_sensitive("TabPrevious", active, browser);
action_set_sensitive("TabNext", active, browser);
gboolean tabtrashEmpty = katze_xbel_folder_is_empty(tabtrash);
action_set_sensitive("UndoTabClose", !tabtrashEmpty, browser);
action_set_sensitive("TabsClosed", !tabtrashEmpty, browser);
}
gchar* magic_uri(const gchar* uri, gboolean search) gchar* magic_uri(const gchar* uri, gboolean search)
{ {
// Add file:// if we have a local path // Add file:// if we have a local path

View file

@ -12,28 +12,18 @@
#ifndef __HELPERS_H__ #ifndef __HELPERS_H__
#define __HELPERS_H__ 1 #define __HELPERS_H__ 1
#include "browser.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
GtkIconTheme* #include "midori-browser.h"
get_icon_theme(GtkWidget*);
GtkWidget* GtkWidget*
menu_item_new(const gchar*, const gchar*, GCallback, gboolean, gpointer); check_menu_item_new(const gchar*, GCallback, gboolean, gboolean, gpointer);
GtkToolItem*
tool_button_new(const gchar*, const gchar*
, gboolean, gboolean, GCallback, const gchar*, gpointer);
GtkWidget*
check_menu_item_new(const gchar*, GCallback, gboolean, gboolean, CBrowser*);
GtkWidget* GtkWidget*
radio_button_new(GtkRadioButton*, const gchar*); radio_button_new(GtkRadioButton*, const gchar*);
void void
show_error(const gchar*, const gchar*, CBrowser*); show_error(const gchar*, const gchar*, MidoriBrowser*);
gboolean gboolean
spawn_protocol_command(const gchar*, const gchar*); spawn_protocol_command(const gchar*, const gchar*);
@ -47,51 +37,6 @@ entry_setup_completion(GtkEntry*);
void void
entry_completion_append(GtkEntry*, const gchar*); entry_completion_append(GtkEntry*, const gchar*);
GtkWidget*
get_nth_webView(gint, CBrowser*);
gint
get_webView_index(GtkWidget*, CBrowser*);
CBrowser*
get_browser_from_webView(GtkWidget*);
void
update_favicon(CBrowser*);
void
update_security(CBrowser*);
void
update_visibility(CBrowser*, gboolean);
void
action_set_active(const gchar*, gboolean, CBrowser*);
void
action_set_sensitive(const gchar*, gboolean, CBrowser*);
void
action_set_visible(const gchar*, gboolean, CBrowser*);
void
update_statusbar(CBrowser*);
void
update_edit_items(CBrowser*);
void
update_gui_state(CBrowser*);
void
update_feeds(CBrowser*);
void
update_search_engines(CBrowser*);
void
update_browser_actions(CBrowser*);
gchar* gchar*
magic_uri(const gchar*, gboolean bSearch); magic_uri(const gchar*, gboolean bSearch);

153
src/main.c Executable file → Normal file
View file

@ -11,17 +11,18 @@
#include "main.h" #include "main.h"
#include "browser.h"
#include "global.h" #include "global.h"
#include "helpers.h" #include "helpers.h"
#include "sokoke.h" #include "sokoke.h"
#include "search.h" #include "search.h"
#include "webView.h"
#include "../katze/katze.h" #include "midori-websettings.h"
#include "midori-trash.h"
#include "midori-browser.h"
#include <katze/katze.h>
#include <string.h> #include <string.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <webkit/webkit.h>
#include "config.h" #include "config.h"
@ -40,12 +41,7 @@ static void stock_items_init(void)
{ STOCK_BOOKMARK, "Bookmark", 0, 0, NULL }, { STOCK_BOOKMARK, "Bookmark", 0, 0, NULL },
{ STOCK_BOOKMARK_NEW, "New Bookmark", 0, 0, NULL }, { STOCK_BOOKMARK_NEW, "New Bookmark", 0, 0, NULL },
{ STOCK_BOOKMARKS, "_Bookmarks", 0, 0, NULL },
{ STOCK_DOWNLOADS, "_Downloads", 0, 0, NULL },
{ STOCK_CONSOLE, "_Console", 0, 0, NULL },
{ STOCK_EXTENSIONS, "_Extensions", 0, 0, NULL },
{ STOCK_FORM_FILL, "_Form Fill", 0, 0, NULL }, { STOCK_FORM_FILL, "_Form Fill", 0, 0, NULL },
{ STOCK_HISTORY, "History", 0, 0, NULL },
{ STOCK_HOMEPAGE, "Homepage", 0, 0, NULL }, { STOCK_HOMEPAGE, "Homepage", 0, 0, NULL },
{ STOCK_LOCATION, "Location Entry", 0, 0, NULL }, { STOCK_LOCATION, "Location Entry", 0, 0, NULL },
{ STOCK_NEWSFEED, "Newsfeed", 0, 0, NULL }, { STOCK_NEWSFEED, "Newsfeed", 0, 0, NULL },
@ -81,7 +77,46 @@ static void stock_items_init(void)
g_object_unref(factory); g_object_unref(factory);
} }
// -- main function static gboolean
midori_browser_delete_event_cb (MidoriBrowser* browser,
GdkEvent* event,
GList* browsers)
{
browsers = g_list_remove (browsers, browser);
if (g_list_nth (browsers, 0))
return FALSE;
gtk_main_quit ();
return TRUE;
}
static void
midori_browser_quit_cb (MidoriBrowser* browser,
GdkEvent* event,
GList* browsers)
{
gtk_main_quit ();
}
static void
midori_browser_new_window_cb (MidoriBrowser* browser,
const gchar* uri,
GList* browsers)
{
MidoriBrowser* new_browser = g_object_new (MIDORI_TYPE_BROWSER,
// "settings", settings,
// "trash", trash,
NULL);
// gtk_window_add_accel_group (GTK_WINDOW (browser), accel_group);
g_object_connect (new_browser,
"signal::new-window", midori_browser_new_window_cb, browsers,
"signal::delete-event", midori_browser_delete_event_cb, browsers,
"signal::quit", midori_browser_quit_cb, browsers,
NULL);
browsers = g_list_prepend(browsers, new_browser);
gtk_widget_show (GTK_WIDGET (new_browser));
midori_browser_append_uri (new_browser, uri);
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -105,7 +140,7 @@ int main(int argc, char** argv)
if(version) if(version)
{ {
g_print(PACKAGE_STRING " - Copyright (c) 2007 Christian Dywan\n\n" g_print(PACKAGE_STRING " - Copyright (c) 2007-2008 Christian Dywan\n\n"
"GTK+2: " GTK_VER "\n" "GTK+2: " GTK_VER "\n"
"WebKit: " WEBKIT_VER "\n" "WebKit: " WEBKIT_VER "\n"
"Libsexy: " LIBSEXY_VER "\n" "Libsexy: " LIBSEXY_VER "\n"
@ -128,7 +163,7 @@ int main(int argc, char** argv)
g_mkdir_with_parents(configPath, 0755); g_mkdir_with_parents(configPath, 0755);
gchar* configFile = g_build_filename(configPath, "config", NULL); gchar* configFile = g_build_filename(configPath, "config", NULL);
error = NULL; error = NULL;
config = config_new(); /*CConfig* */config = config_new();
if(!config_from_file(config, configFile, &error)) if(!config_from_file(config, configFile, &error))
{ {
if(error->code != G_FILE_ERROR_NOENT) if(error->code != G_FILE_ERROR_NOENT)
@ -178,9 +213,9 @@ int main(int argc, char** argv)
g_free(configFile); g_free(configFile);
} }
configFile = g_build_filename(configPath, "tabtrash.xbel", NULL); configFile = g_build_filename(configPath, "tabtrash.xbel", NULL);
tabtrash = katze_xbel_folder_new(); KatzeXbelItem* xbel_trash = katze_xbel_folder_new();
error = NULL; error = NULL;
if(!katze_xbel_folder_from_file(tabtrash, configFile, &error)) if(!katze_xbel_folder_from_file(xbel_trash, configFile, &error))
{ {
if(error->code != G_FILE_ERROR_NOENT) if(error->code != G_FILE_ERROR_NOENT)
g_string_append_printf(errorMessages g_string_append_printf(errorMessages
@ -211,6 +246,7 @@ int main(int argc, char** argv)
search_engines_free(searchEngines); search_engines_free(searchEngines);
katze_xbel_item_unref(bookmarks); katze_xbel_item_unref(bookmarks);
katze_xbel_item_unref(_session); katze_xbel_item_unref(_session);
katze_xbel_item_unref(xbel_trash);
g_string_free(errorMessages, TRUE); g_string_free(errorMessages, TRUE);
return 0; return 0;
} }
@ -245,37 +281,68 @@ int main(int argc, char** argv)
} }
g_free(configPath); g_free(configPath);
accel_group = gtk_accel_group_new();
stock_items_init(); stock_items_init();
browsers = NULL;
webSettings = g_object_new(WEBKIT_TYPE_WEB_SETTINGS MidoriWebSettings* settings;
, "default-font-family" , config->defaultFontFamily settings = g_object_new (MIDORI_TYPE_WEB_SETTINGS,
, "default-font-size" , config->defaultFontSize "default-font-family", config->defaultFontFamily,
, "minimum-font-size" , config->minimumFontSize "default-font-size", config->defaultFontSize,
, "default-encoding" , config->defaultEncoding "minimum-font-size", config->minimumFontSize,
, "auto-load-images" , config->autoLoadImages "default-encoding", config->defaultEncoding,
, "auto-shrink-images" , config->autoShrinkImages "auto-load-images", config->autoLoadImages,
, "print-backgrounds" , config->printBackgrounds "auto-shrink-images", config->autoShrinkImages,
, "resizable-text-areas", config->resizableTextAreas "print-backgrounds", config->printBackgrounds,
, "user-stylesheet-uri" , config->userStylesheet ? config->userStylesheetUri : NULL "resizable-text-areas", config->resizableTextAreas,
, "enable-scripts" , config->enableScripts "user-stylesheet-uri",
, "enable-plugins" , config->enablePlugins config->userStylesheet ?
, NULL); config->userStylesheetUri : NULL,
"enable-scripts", config->enableScripts,
"enable-plugins", config->enablePlugins,
"tab-label-size", config->tabSize,
"close-button", config->tabClose,
"middle-click-goto", config->middleClickGoto,
NULL);
webSettings = settings;
session = katze_xbel_folder_new(); MidoriTrash* trash = g_object_new (MIDORI_TYPE_TRASH,
CBrowser* browser = NULL; "limit", 10,
guint n = katze_xbel_folder_get_n_items(_session); NULL);
guint i; guint i;
for(i = 0; i < n; i++) guint n = katze_xbel_folder_get_n_items (xbel_trash);
for (i = 0; i < n; i++)
{ {
KatzeXbelItem* item = katze_xbel_folder_get_nth_item(_session, i); KatzeXbelItem* item = katze_xbel_folder_get_nth_item (xbel_trash, i);
browser = browser_new(browser); midori_trash_prepend_xbel_item (trash, item);
webView_open(browser->webView, katze_xbel_bookmark_get_href(item));
} }
katze_xbel_item_unref(_session);
gtk_main(); GtkAccelGroup* accel_group = gtk_accel_group_new();
GList* browsers = NULL;
MidoriBrowser* browser = g_object_new (MIDORI_TYPE_BROWSER,
"settings", settings,
"trash", trash,
NULL);
gtk_window_add_accel_group (GTK_WINDOW (browser), accel_group);
g_object_connect (browser,
"signal::new-window", midori_browser_new_window_cb, browsers,
"signal::delete-event", midori_browser_delete_event_cb, browsers,
"signal::quit", midori_browser_quit_cb, browsers,
NULL);
browsers = g_list_prepend(browsers, browser);
gtk_widget_show (GTK_WIDGET (browser));
KatzeXbelItem* session = katze_xbel_folder_new ();
n = katze_xbel_folder_get_n_items (_session);
for (i = 0; i < n; i++)
{
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (_session, i);
midori_browser_append_xbel_item (browser, item);
}
katze_xbel_item_unref (_session);
gtk_main ();
g_object_unref (accel_group);
// Save configuration files // Save configuration files
configPath = g_build_filename(g_get_user_config_dir(), PACKAGE_NAME, NULL); configPath = g_build_filename(g_get_user_config_dir(), PACKAGE_NAME, NULL);
@ -300,13 +367,13 @@ int main(int argc, char** argv)
g_free(configFile); g_free(configFile);
configFile = g_build_filename(configPath, "tabtrash.xbel", NULL); configFile = g_build_filename(configPath, "tabtrash.xbel", NULL);
error = NULL; error = NULL;
if(!katze_xbel_folder_to_file(tabtrash, configFile, &error)) if (!katze_xbel_folder_to_file (xbel_trash, configFile, &error))
{ {
g_warning("Tabtrash couldn't be saved. %s", error->message); g_warning ("Tabtrash couldn't be saved. %s", error->message);
g_error_free(error); g_error_free (error);
} }
katze_xbel_item_unref(tabtrash); katze_xbel_item_unref (xbel_trash);
g_free(configFile); g_free (configFile);
if(config->startup == CONFIG_STARTUP_SESSION) if(config->startup == CONFIG_STARTUP_SESSION)
{ {
configFile = g_build_filename(configPath, "session.xbel", NULL); configFile = g_build_filename(configPath, "session.xbel", NULL);

2986
src/midori-browser.c Normal file

File diff suppressed because it is too large Load diff

90
src/midori-browser.h Normal file
View file

@ -0,0 +1,90 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __MIDORI_BROWSER_H__
#define __MIDORI_BROWSER_H__
#include <webkit/webkit.h>
#include <katze/katze.h>
G_BEGIN_DECLS
#define MIDORI_TYPE_BROWSER \
(midori_browser_get_type ())
#define MIDORI_BROWSER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_BROWSER, MidoriBrowser))
#define MIDORI_BROWSER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_BROWSER, MidoriBrowserClass))
#define MIDORI_IS_BROWSER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_BROWSER))
#define MIDORI_IS_BROWSER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_BROWSER))
#define MIDORI_BROWSER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_BROWSER, MidoriBrowserClass))
typedef struct _MidoriBrowser MidoriBrowser;
typedef struct _MidoriBrowserPrivate MidoriBrowserPrivate;
typedef struct _MidoriBrowserClass MidoriBrowserClass;
struct _MidoriBrowser
{
GtkWindow parent_instance;
MidoriBrowserPrivate* priv;
};
struct _MidoriBrowserClass
{
GtkWindowClass parent_class;
/* Signals */
void
(*quit) (MidoriBrowser* browser);
void
(*new_window) (MidoriBrowser* browser,
const gchar* uri);
};
GType
midori_browser_get_type (void);
GtkWidget*
midori_browser_new (void);
gint
midori_browser_append_tab (MidoriBrowser* browser,
GtkWidget* widget);
void
midori_browser_remove_tab (MidoriBrowser* browser,
GtkWidget* widget);
gint
midori_browser_append_xbel_item (MidoriBrowser* browser,
KatzeXbelItem* xbel_item);
gint
midori_browser_append_uri (MidoriBrowser* browser,
const gchar* uri);
GtkWidget*
midori_browser_get_current_page (MidoriBrowser* browser);
GtkWidget*
midori_browser_get_current_web_view (MidoriBrowser* browser);
KatzeXbelItem*
midori_browser_get_proxy_xbel_folder (MidoriBrowser* browser);
G_END_DECLS
#endif /* __MIDORI_BROWSER_H__ */

515
src/midori-panel.c Normal file
View file

@ -0,0 +1,515 @@
/*
Copyright (C) 2007-2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#include "midori-panel.h"
#include "sokoke.h"
G_DEFINE_TYPE (MidoriPanel, midori_panel, GTK_TYPE_HBOX)
struct _MidoriPanelPrivate
{
GtkWidget* toolbar;
GtkWidget* toolbar_label;
GtkWidget* frame;
GtkWidget* notebook;
GSList* group;
GtkMenu* menu;
};
#define MIDORI_PANEL_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
MIDORI_TYPE_PANEL, MidoriPanelPrivate))
enum
{
PROP_0,
PROP_SHADOW_TYPE,
PROP_MENU,
PROP_PAGE
};
enum {
CLOSE,
SWITCH_PAGE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static void
midori_panel_finalize (GObject* object);
static void
midori_panel_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec);
static void
midori_panel_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec);
static gboolean
midori_panel_close_cb (MidoriPanel* panel)
{
gtk_widget_hide (GTK_WIDGET (panel));
return FALSE;
}
static void
midori_cclosure_marshal_BOOLEAN__VOID (GClosure* closure, GValue* return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint, gpointer marshal_data)
{
typedef gboolean(*GMarshalFunc_BOOLEAN__VOID) (gpointer data1,
gpointer data2);
register GMarshalFunc_BOOLEAN__VOID callback;
register GCClosure* cc = (GCClosure*) closure;
register gpointer data1, data2;
gboolean v_return;
g_return_if_fail(return_value != NULL);
g_return_if_fail(n_param_values == 1);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer(param_values + 0);
}
else
{
data1 = g_value_peek_pointer(param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_BOOLEAN__VOID) (marshal_data ? marshal_data : cc->callback);
v_return = callback(data1, data2);
g_value_set_boolean (return_value, v_return);
}
static void
midori_panel_class_init (MidoriPanelClass* class)
{
signals[CLOSE] = g_signal_new (
"close",
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (MidoriPanelClass, close),
g_signal_accumulator_true_handled,
NULL,
midori_cclosure_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN, 0);
signals[SWITCH_PAGE] = g_signal_new (
"switch-page",
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (MidoriPanelClass, switch_page),
0,
NULL,
g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1,
G_TYPE_INT);
class->close = midori_panel_close_cb;
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_panel_finalize;
gobject_class->set_property = midori_panel_set_property;
gobject_class->get_property = midori_panel_get_property;
GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
g_object_class_install_property (gobject_class,
PROP_SHADOW_TYPE,
g_param_spec_enum (
"shadow-type",
"Shadow Type",
"Appearance of the shadow around each panel",
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_NONE,
flags));
g_object_class_install_property (gobject_class,
PROP_MENU,
g_param_spec_object (
"menu",
"Menu",
"Menu to hold panel items",
GTK_TYPE_MENU,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_PAGE,
g_param_spec_int (
"page",
"Page",
"The index of the current page",
-1, G_MAXINT, -1,
flags));
g_type_class_add_private (class, sizeof (MidoriPanelPrivate));
}
static void
midori_panel_button_close_clicked_cb (MidoriPanel* panel)
{
g_signal_emit (panel, signals[CLOSE], 0);
}
static void
midori_panel_init (MidoriPanel* panel)
{
panel->priv = MIDORI_PANEL_GET_PRIVATE (panel);
MidoriPanelPrivate* priv = panel->priv;
// Create the sidebar
priv->toolbar = gtk_toolbar_new ();
gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_BOTH);
gtk_toolbar_set_icon_size (GTK_TOOLBAR (priv->toolbar),
GTK_ICON_SIZE_BUTTON);
gtk_toolbar_set_orientation (GTK_TOOLBAR (priv->toolbar),
GTK_ORIENTATION_VERTICAL);
gtk_box_pack_start (GTK_BOX (panel), priv->toolbar, FALSE, FALSE, 0);
gtk_widget_show_all (priv->toolbar);
GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (panel), vbox, TRUE, TRUE, 0);
// Create the titlebar
GtkWidget* labelbar = gtk_toolbar_new ();
gtk_toolbar_set_icon_size (GTK_TOOLBAR (labelbar), GTK_ICON_SIZE_MENU);
gtk_toolbar_set_style (GTK_TOOLBAR (labelbar), GTK_TOOLBAR_ICONS);
GtkToolItem* toolitem = gtk_tool_item_new ();
gtk_tool_item_set_expand (toolitem, TRUE);
priv->toolbar_label = gtk_label_new (NULL);
gtk_misc_set_alignment (GTK_MISC (priv->toolbar_label), 0, 0.5);
gtk_container_add (GTK_CONTAINER (toolitem), priv->toolbar_label);
gtk_container_set_border_width (GTK_CONTAINER (toolitem), 6);
gtk_toolbar_insert (GTK_TOOLBAR (labelbar), toolitem, -1);
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), "Close panel");
sokoke_tool_item_set_tooltip_text (GTK_TOOL_ITEM (toolitem), "Close panel");
g_signal_connect (toolitem, "clicked",
G_CALLBACK (midori_panel_button_close_clicked_cb), panel);
gtk_toolbar_insert (GTK_TOOLBAR (labelbar), toolitem, -1);
gtk_box_pack_start (GTK_BOX (vbox), labelbar, FALSE, FALSE, 0);
gtk_widget_show_all (vbox);
// Create the notebook
priv->notebook = gtk_notebook_new ();
gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
priv->frame = gtk_frame_new (NULL);
gtk_container_add (GTK_CONTAINER (priv->frame), priv->notebook);
gtk_box_pack_start (GTK_BOX (vbox), priv->frame, TRUE, TRUE, 0);
gtk_widget_show_all (priv->frame);
}
static void
midori_panel_finalize (GObject* object)
{
MidoriPanel* panel = MIDORI_PANEL (object);
MidoriPanelPrivate* priv = panel->priv;
if (priv->menu)
{
// FIXME: Remove all menu items
}
G_OBJECT_CLASS (midori_panel_parent_class)->finalize (object);
}
static void
midori_panel_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec)
{
MidoriPanel* panel = MIDORI_PANEL (object);
MidoriPanelPrivate* priv = panel->priv;
switch (prop_id)
{
case PROP_SHADOW_TYPE:
gtk_frame_set_shadow_type (GTK_FRAME (priv->frame),
g_value_get_enum (value));
break;
case PROP_MENU:
katze_object_assign (priv->menu, g_value_get_object (value));
// FIXME: Move existing items to the new menu
break;
case PROP_PAGE:
gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
midori_panel_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec)
{
MidoriPanel* panel = MIDORI_PANEL (object);
MidoriPanelPrivate* priv = panel->priv;
switch (prop_id)
{
case PROP_SHADOW_TYPE:
g_value_set_enum (value,
gtk_frame_get_shadow_type (GTK_FRAME (priv->frame)));
break;
case PROP_MENU:
g_value_set_object (value, priv->menu);
break;
case PROP_PAGE:
g_value_set_int (value,
gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* midori_panel_new:
*
* Creates a new empty panel.
*
* Return value: a new #MidoriPanel
**/
GtkWidget*
midori_panel_new (void)
{
MidoriPanel* panel = g_object_new (MIDORI_TYPE_PANEL,
NULL);
return GTK_WIDGET (panel);
}
static void
midori_panel_menu_item_activate_cb (GtkWidget* widget,
MidoriPanel* panel)
{
GtkWidget* child = g_object_get_data (G_OBJECT (widget), "page");
guint n = midori_panel_page_num (panel, child);
midori_panel_set_current_page (panel, n);
g_signal_emit (panel, signals[SWITCH_PAGE], 0, n);
}
/**
* midori_panel_append_page:
* @panel: a #MidoriPanel
* @child: the child widget
* @icon: a stock ID or icon name, or %NULL
* @label: a string to use as the label, or %NULL
*
* Appends a new page to the panel.
*
* If @icon is an icon name, the according image is used as an
* icon for this page.
*
* If @label is given, it is used as the label of this page.
*
* In the case of an error, -1 is returned.
*
* Return value: the index of the new page, or -1
**/
gint
midori_panel_append_page (MidoriPanel* panel,
GtkWidget* child,
const gchar* icon,
const gchar* label)
{
g_return_val_if_fail (MIDORI_IS_PANEL (panel), -1);
g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
MidoriPanelPrivate* priv = panel->priv;
GtkWidget* scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
GTK_WIDGET_SET_FLAGS (scrolled, GTK_CAN_FOCUS);
gtk_widget_show (scrolled);
GtkWidget* widget;
GObjectClass* gobject_class = G_OBJECT_GET_CLASS (child);
if (GTK_WIDGET_CLASS (gobject_class)->set_scroll_adjustments_signal)
widget = child;
else
{
widget = gtk_viewport_new (NULL, NULL);
gtk_widget_show (widget);
gtk_container_add (GTK_CONTAINER (widget), child);
}
gtk_container_add (GTK_CONTAINER (scrolled), widget);
gtk_container_add (GTK_CONTAINER (priv->notebook), scrolled);
guint n = midori_panel_page_num (panel, child);
const gchar* text = label ? label : "Untitled";
GtkWidget* image;
GtkToolItem* toolitem = gtk_radio_tool_button_new (priv->group);
priv->group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (
toolitem));
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), text);
if (icon)
{
image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_BUTTON);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
}
g_object_set_data (G_OBJECT (toolitem), "page", child);
g_signal_connect (toolitem, "clicked",
G_CALLBACK (midori_panel_menu_item_activate_cb), panel);
gtk_widget_show_all (GTK_WIDGET (toolitem));
gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), toolitem, -1);
if (priv->menu)
{
GtkWidget* menuitem = gtk_image_menu_item_new_with_label (text);
if (icon)
{
image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem),
image);
}
gtk_widget_show_all (menuitem);
g_object_set_data (G_OBJECT (menuitem), "page", child);
g_signal_connect (menuitem, "activate",
G_CALLBACK (midori_panel_menu_item_activate_cb),
panel);
gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menuitem);
}
return n;
}
/**
* midori_panel_get_current_page:
* @panel: a #MidoriPanel
*
* Retrieves the index of the currently selected page.
*
* If @panel has no children, -1 is returned.
*
* Return value: the index of the current page, or -1
**/
gint
midori_panel_get_current_page (MidoriPanel* panel)
{
g_return_val_if_fail (MIDORI_IS_PANEL (panel), -1);
MidoriPanelPrivate* priv = panel->priv;
return gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
}
/**
* midori_panel_get_nth_page:
* @panel: a #MidoriPanel
*
* Retrieves the child widget of the nth page.
*
* If @panel has no children, -1 is returned.
*
* Return value: the child widget of the new page, or -1
**/
GtkWidget*
midori_panel_get_nth_page (MidoriPanel* panel,
guint page_num)
{
g_return_val_if_fail (MIDORI_IS_PANEL (panel), NULL);
MidoriPanelPrivate* priv = panel->priv;
return gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), page_num);
}
/**
* midori_panel_get_n_pages:
* @panel: a #MidoriPanel
*
* Retrieves the number of pages contained in the panel.
*
* Return value: the number of pages
**/
guint
midori_panel_get_n_pages (MidoriPanel* panel)
{
g_return_val_if_fail (MIDORI_IS_PANEL (panel), 0);
MidoriPanelPrivate* priv = panel->priv;
return gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
}
static GtkWidget*
_midori_panel_scrolled_for_child (MidoriPanel* panel,
GtkWidget* child)
{
GtkWidget* scrolled = gtk_widget_get_parent (GTK_WIDGET (child));
if (GTK_IS_VIEWPORT (scrolled))
scrolled = gtk_widget_get_parent (scrolled);
return scrolled;
}
/**
* midori_panel_page_num:
* @panel: a #MidoriPanel
*
* Retrieves the index of the page associated to @widget.
*
* If @panel has no children, -1 is returned.
*
* Return value: the index of page associated to @widget, or -1
**/
gint
midori_panel_page_num (MidoriPanel* panel,
GtkWidget* child)
{
g_return_val_if_fail (MIDORI_IS_PANEL (panel), -1);
MidoriPanelPrivate* priv = panel->priv;
GtkWidget* scrolled = _midori_panel_scrolled_for_child (panel, child);
return gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook), scrolled);
}
/**
* midori_panel_set_current_page:
* @panel: a #MidoriPanel
* @n: index of the page to switch to, or -1 to mean the last page
*
* Switches to the page with the given index.
*
* The child must be visible, otherwise the underlying GtkNotebook will
* silently ignore the attempt to switch the page.
**/
void
midori_panel_set_current_page (MidoriPanel* panel,
gint n)
{
g_return_if_fail (MIDORI_IS_PANEL (panel));
MidoriPanelPrivate* priv = panel->priv;
gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), n);
}

90
src/midori-panel.h Normal file
View file

@ -0,0 +1,90 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __MIDORI_PANEL_H__
#define __MIDORI_PANEL_H__
#include <gtk/gtk.h>
#include <katze/katze.h>
G_BEGIN_DECLS
#define MIDORI_TYPE_PANEL \
(midori_panel_get_type ())
#define MIDORI_PANEL(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_PANEL, MidoriPanel))
#define MIDORI_PANEL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_PANEL, MidoriPanelClass))
#define MIDORI_IS_PANEL(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_PANEL))
#define MIDORI_IS_PANEL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_PANEL))
#define MIDORI_PANEL_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_PANEL, MidoriPanelClass))
typedef struct _MidoriPanel MidoriPanel;
typedef struct _MidoriPanelPrivate MidoriPanelPrivate;
typedef struct _MidoriPanelClass MidoriPanelClass;
struct _MidoriPanel
{
GtkFrame parent_instance;
MidoriPanelPrivate* priv;
};
struct _MidoriPanelClass
{
GtkFrameClass parent_class;
/* Signals */
gboolean
(*close) (MidoriPanel* panel);
void
(*switch_page) (MidoriPanel* panel,
gint page);
};
GType
midori_panel_get_type (void);
GtkWidget*
midori_panel_new (void);
gint
midori_panel_append_page (MidoriPanel* panel,
GtkWidget* child,
const gchar* icon,
const gchar* label);
gint
midori_panel_get_current_page (MidoriPanel* panel);
GtkWidget*
midori_panel_get_nth_page (MidoriPanel* panel,
guint page_num);
guint
midori_panel_get_n_pages (MidoriPanel* panel);
gint
midori_panel_page_num (MidoriPanel* panel,
GtkWidget* child);
void
midori_panel_set_current_page (MidoriPanel* panel,
gint n);
G_END_DECLS
#endif /* __MIDORI_PANEL_H__ */

327
src/midori-trash.c Normal file
View file

@ -0,0 +1,327 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#include "midori-trash.h"
#include "sokoke.h"
G_DEFINE_TYPE (MidoriTrash, midori_trash, G_TYPE_OBJECT)
struct _MidoriTrashPrivate
{
guint limit;
KatzeXbelItem* xbel_folder;
};
#define MIDORI_TRASH_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
MIDORI_TYPE_TRASH, MidoriTrashPrivate))
enum
{
PROP_0,
PROP_LIMIT
};
enum {
INSERTED,
REMOVED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static void
midori_trash_finalize (GObject* object);
static void
midori_trash_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec);
static void
midori_trash_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec);
static void
midori_trash_class_init (MidoriTrashClass* class)
{
signals[INSERTED] = g_signal_new(
"inserted",
G_TYPE_FROM_CLASS(class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (MidoriTrashClass, inserted),
0,
NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
signals[REMOVED] = g_signal_new(
"removed",
G_TYPE_FROM_CLASS(class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (MidoriTrashClass, removed),
0,
NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_trash_finalize;
gobject_class->set_property = midori_trash_set_property;
gobject_class->get_property = midori_trash_get_property;
GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
g_object_class_install_property (gobject_class,
PROP_LIMIT,
g_param_spec_uint (
"limit",
"Limit",
"The maximum number of items",
0, G_MAXUINT, 10,
flags));
g_type_class_add_private (class, sizeof (MidoriTrashPrivate));
}
static void
midori_trash_init (MidoriTrash* trash)
{
trash->priv = MIDORI_TRASH_GET_PRIVATE (trash);
MidoriTrashPrivate* priv = trash->priv;
priv->xbel_folder = katze_xbel_folder_new ();
}
static void
midori_trash_finalize (GObject* object)
{
MidoriTrash* trash = MIDORI_TRASH (object);
MidoriTrashPrivate* priv = trash->priv;
katze_xbel_item_unref (priv->xbel_folder);
G_OBJECT_CLASS (midori_trash_parent_class)->finalize (object);
}
static void
midori_trash_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec)
{
MidoriTrash* trash = MIDORI_TRASH (object);
MidoriTrashPrivate* priv = trash->priv;
switch (prop_id)
{
case PROP_LIMIT:
priv->limit = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
midori_trash_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec)
{
MidoriTrash* trash = MIDORI_TRASH (object);
MidoriTrashPrivate* priv = trash->priv;
switch (prop_id)
{
case PROP_LIMIT:
g_value_set_uint (value, priv->limit);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* midori_trash_new:
* @limit: the maximum number of items
*
* Creates a new #MidoriTrash that can contain a specified number of items,
* meaning that each additional item will replace the oldest existing item.
*
* The value 0 for @limit actually means that there is no limit.
*
* You will typically want to assign this to a #MidoriBrowser.
*
* Return value: a new #MidoriTrash
**/
MidoriTrash*
midori_trash_new (guint limit)
{
MidoriTrash* trash = g_object_new (MIDORI_TYPE_TRASH,
"limit", limit,
NULL);
return trash;
}
/**
* midori_trash_is_empty:
* @trash: a #MidoriTrash
*
* Determines whether the @trash contains no items.
*
* Return value: %TRUE if there are no items, %FALSE otherwise
**/
gboolean
midori_trash_is_empty (MidoriTrash* trash)
{
g_return_val_if_fail (MIDORI_IS_TRASH (trash), FALSE);
MidoriTrashPrivate* priv = trash->priv;
return katze_xbel_folder_is_empty (priv->xbel_folder);
}
/**
* midori_trash_get_n_items:
* @trash: a #MidoriTrash
*
* Determines the number of items in @trash.
*
* Return value: the current number of items
**/
guint
midori_trash_get_n_items (MidoriTrash* trash)
{
g_return_val_if_fail (MIDORI_IS_TRASH (trash), 0);
MidoriTrashPrivate* priv = trash->priv;
return katze_xbel_folder_get_n_items (priv->xbel_folder);
}
/**
* midori_trash_get_nth_xbel_item:
* @trash: a #MidoriTrash
* @n: the index of an item
*
* Retrieve an item contained in @trash by its index.
*
* Note that you mustn't unref this item.
*
* Return value: the index at the given index or %NULL
**/
KatzeXbelItem*
midori_trash_get_nth_xbel_item (MidoriTrash* trash,
guint n)
{
g_return_val_if_fail (MIDORI_IS_TRASH (trash), 0);
MidoriTrashPrivate* priv = trash->priv;
return katze_xbel_folder_get_nth_item (priv->xbel_folder, n);
}
/**
* midori_trash_prepend_xbel_item:
* @trash: a #MidoriTrash
* @xbel_item: a #KatzeXbelItem
*
* Prepends a #KatzeXbelItem to @trash.
*
* The item is copied. If there is a limit set, the oldest item is
* removed automatically.
*
* Return value: %TRUE if there are no items, %FALSE otherwise
**/
void
midori_trash_prepend_xbel_item (MidoriTrash* trash,
KatzeXbelItem* xbel_item)
{
g_return_if_fail (MIDORI_IS_TRASH (trash));
MidoriTrashPrivate* priv = trash->priv;
KatzeXbelItem* copy = katze_xbel_item_copy (xbel_item);
katze_xbel_folder_prepend_item (priv->xbel_folder, copy);
g_signal_emit (trash, signals[INSERTED], 0, 0);
guint n = katze_xbel_folder_get_n_items (priv->xbel_folder);
if (n > 10)
{
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder,
n - 1);
g_signal_emit (trash, signals[REMOVED], 0, n - 1);
katze_xbel_item_unref (item);
}
}
/**
* midori_trash_remove_nth_item:
* @trash: a #MidoriTrash
* @n: the index of an item
*
* Removes the item at the specified position from @trash.
*
* Nothing happens if the function fails.
**/
void
midori_trash_remove_nth_item (MidoriTrash* trash,
guint n)
{
g_return_if_fail (MIDORI_IS_TRASH (trash));
MidoriTrashPrivate* priv = trash->priv;
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder, n);
if (!n)
return;
katze_xbel_folder_remove_item (priv->xbel_folder, item);
g_signal_emit (trash, signals[REMOVED], 0, n);
katze_xbel_item_unref (item);
}
/**
* midori_trash_empty:
* @trash: a #MidoriTrash
*
* Deletes all items currently contained in @trash.
**/
void
midori_trash_empty (MidoriTrash* trash)
{
g_return_if_fail (MIDORI_IS_TRASH (trash));
MidoriTrashPrivate* priv = trash->priv;
guint n = katze_xbel_folder_get_n_items (priv->xbel_folder);
guint i;
for (i = 0; i < n; i++)
{
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder,
i);
g_signal_emit (trash, signals[REMOVED], 0, i);
katze_xbel_item_unref (item);
}
}

85
src/midori-trash.h Normal file
View file

@ -0,0 +1,85 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __MIDORI_TRASH_H__
#define __MIDORI_TRASH_H__
#include <katze/katze.h>
G_BEGIN_DECLS
#define MIDORI_TYPE_TRASH \
(midori_trash_get_type ())
#define MIDORI_TRASH(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_TRASH, MidoriTrash))
#define MIDORI_TRASH_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_TRASH, MidoriTrashClass))
#define MIDORI_IS_TRASH(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_TRASH))
#define MIDORI_IS_TRASH_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_TRASH))
#define MIDORI_TRASH_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_TRASH, MidoriTrashClass))
typedef struct _MidoriTrash MidoriTrash;
typedef struct _MidoriTrashPrivate MidoriTrashPrivate;
typedef struct _MidoriTrashClass MidoriTrashClass;
struct _MidoriTrash
{
GObject parent_instance;
MidoriTrashPrivate* priv;
};
struct _MidoriTrashClass
{
GObjectClass parent_class;
/* Signals */
void
(*inserted) (MidoriTrash* trash,
guint n);
void
(*removed) (MidoriTrash* trash,
guint n);
};
GType
midori_trash_get_type (void);
MidoriTrash*
midori_trash_new (guint limit);
gboolean
midori_trash_is_empty (MidoriTrash* trash);
guint
midori_trash_get_n_items (MidoriTrash* trash);
KatzeXbelItem*
midori_trash_get_nth_xbel_item (MidoriTrash* trash,
guint n);
void
midori_trash_prepend_xbel_item (MidoriTrash* trash,
KatzeXbelItem* xbel_item);
void
midori_trash_remove_nth_item (MidoriTrash* trash,
guint n);
void
midori_trash_empty (MidoriTrash* trash);
G_END_DECLS
#endif /* __MIDORI_TRASH_H__ */

200
src/midori-websettings.c Normal file
View file

@ -0,0 +1,200 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#include "midori-webview.h"
#include "sokoke.h"
G_DEFINE_TYPE (MidoriWebSettings, midori_web_settings, WEBKIT_TYPE_WEB_SETTINGS)
struct _MidoriWebSettingsPrivate
{
gint tab_label_size;
gboolean close_button;
gboolean middle_click_goto;
};
#define MIDORI_WEB_SETTINGS_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
MIDORI_TYPE_WEB_SETTINGS, MidoriWebSettingsPrivate))
enum
{
PROP_0,
PROP_TAB_LABEL_SIZE,
PROP_CLOSE_BUTTON,
PROP_MIDDLE_CLICK_GOTO
};
static void
midori_web_settings_finalize (GObject* object);
static void
midori_web_settings_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec);
static void
midori_web_settings_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec);
static void
midori_web_settings_class_init (MidoriWebSettingsClass* class)
{
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_web_settings_finalize;
gobject_class->set_property = midori_web_settings_set_property;
gobject_class->get_property = midori_web_settings_get_property;
GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
g_object_class_install_property (gobject_class,
PROP_TAB_LABEL_SIZE,
g_param_spec_int (
"tab-label-size",
"Tab Label Size",
"The desired tab label size",
0, G_MAXINT, 10,
flags));
g_object_class_install_property (gobject_class,
PROP_CLOSE_BUTTON,
g_param_spec_boolean (
"close-button",
"Close Button",
"Whether the associated tab has a close button",
FALSE,
flags));
g_object_class_install_property (gobject_class,
PROP_MIDDLE_CLICK_GOTO,
g_param_spec_boolean (
"middle-click-goto",
"Middle Click Goto",
"Load an uri from the selection via middle click",
FALSE,
flags));
g_type_class_add_private (class, sizeof (MidoriWebSettingsPrivate));
}
static void
midori_web_settings_init (MidoriWebSettings* web_settings)
{
web_settings->priv = MIDORI_WEB_SETTINGS_GET_PRIVATE (web_settings);
}
static void
midori_web_settings_finalize (GObject* object)
{
G_OBJECT_CLASS (midori_web_settings_parent_class)->finalize (object);
}
static void
midori_web_settings_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec)
{
MidoriWebSettings* web_settings = MIDORI_WEB_SETTINGS (object);
MidoriWebSettingsPrivate* priv = web_settings->priv;
switch (prop_id)
{
case PROP_TAB_LABEL_SIZE:
priv->tab_label_size = g_value_get_int (value);
break;
case PROP_CLOSE_BUTTON:
priv->close_button = g_value_get_boolean (value);
break;
case PROP_MIDDLE_CLICK_GOTO:
priv->middle_click_goto = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
midori_web_settings_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec)
{
MidoriWebSettings* web_settings = MIDORI_WEB_SETTINGS (object);
MidoriWebSettingsPrivate* priv = web_settings->priv;
switch (prop_id)
{
case PROP_TAB_LABEL_SIZE:
g_value_set_int (value, priv->tab_label_size);
break;
case PROP_CLOSE_BUTTON:
g_value_set_boolean (value, priv->close_button);
break;
case PROP_MIDDLE_CLICK_GOTO:
g_value_set_boolean (value, priv->middle_click_goto);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* midori_web_settings_new:
*
* Creates a new #MidoriWebSettings instance with default values.
*
* You will typically want to assign this to a #MidoriWebView or #MidoriBrowser.
*
* Return value: a new #MidoriWebSettings
**/
MidoriWebSettings*
midori_web_settings_new (void)
{
MidoriWebSettings* web_settings = g_object_new (MIDORI_TYPE_WEB_SETTINGS,
NULL);
return web_settings;
}
/**
* midori_web_settings_copy:
*
* Copies an existing #MidoriWebSettings instance.
*
* Return value: a new #MidoriWebSettings
**/
MidoriWebSettings*
midori_web_settings_copy (MidoriWebSettings* web_settings)
{
g_return_val_if_fail (MIDORI_IS_WEB_SETTINGS (web_settings), NULL);
MidoriWebSettingsPrivate* priv = web_settings->priv;
MidoriWebSettings* copy;
copy = MIDORI_WEB_SETTINGS (webkit_web_settings_copy (WEBKIT_WEB_SETTINGS (web_settings)));
g_object_set (copy,
"tab-label-size", priv->tab_label_size,
"close-button", priv->close_button,
"middle-click-goto", priv->middle_click_goto,
NULL);
return copy;
}

89
src/midori-websettings.h Normal file
View file

@ -0,0 +1,89 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __MIDORI_WEB_SETTINGS_H__
#define __MIDORI_WEB_SETTINGS_H__
#include <webkit/webkit.h>
#include <katze/katze.h>
G_BEGIN_DECLS
#define MIDORI_TYPE_WEB_SETTINGS \
(midori_web_settings_get_type ())
#define MIDORI_WEB_SETTINGS(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_WEB_SETTINGS, MidoriWebSettings))
#define MIDORI_WEB_SETTINGS_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_WEB_SETTINGS, MidoriWebSettingsClass))
#define MIDORI_IS_WEB_SETTINGS(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_WEB_SETTINGS))
#define MIDORI_IS_WEB_SETTINGS_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_WEB_SETTINGS))
#define MIDORI_WEB_SETTINGS_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_WEB_SETTINGS, MidoriWebSettingsClass))
typedef struct _MidoriWebSettings MidoriWebSettings;
typedef struct _MidoriWebSettingsPrivate MidoriWebSettingsPrivate;
typedef struct _MidoriWebSettingsClass MidoriWebSettingsClass;
struct _MidoriWebSettings
{
WebKitWebSettings parent_instance;
MidoriWebSettingsPrivate* priv;
};
struct _MidoriWebSettingsClass
{
WebKitWebSettingsClass parent_class;
/* Signals */
void
(*progress_started) (MidoriWebSettings* web_settings,
guint progress);
void
(*progress_changed) (MidoriWebSettings* web_settings,
guint progress);
void
(*progress_done) (MidoriWebSettings* web_settings,
guint progress);
void
(*load_done) (MidoriWebSettings* web_settings,
WebKitWebFrame* frame);
void
(*statusbar_text_changed) (MidoriWebSettings* web_settings,
const gchar* text);
void
(*element_motion) (MidoriWebSettings* web_settings,
const gchar* link_uri);
void
(*close) (MidoriWebSettings* web_settings);
void
(*new_tab) (MidoriWebSettings* web_settings,
const gchar* uri);
void
(*new_window) (MidoriWebSettings* web_settings,
const gchar* uri);
};
GType
midori_web_settings_get_type (void);
MidoriWebSettings*
midori_web_settings_new (void);
MidoriWebSettings*
midori_web_settings_copy (MidoriWebSettings* web_settings);
G_END_DECLS
#endif /* __MIDORI_WEB_SETTINGS_H__ */

1039
src/midori-webview.c Normal file

File diff suppressed because it is too large Load diff

118
src/midori-webview.h Normal file
View file

@ -0,0 +1,118 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __MIDORI_WEB_VIEW_H__
#define __MIDORI_WEB_VIEW_H__
#include <webkit/webkit.h>
#include <katze/katze.h>
#include "midori-websettings.h"
G_BEGIN_DECLS
#define MIDORI_TYPE_WEB_VIEW \
(midori_web_view_get_type ())
#define MIDORI_WEB_VIEW(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_WEB_VIEW, MidoriWebView))
#define MIDORI_WEB_VIEW_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_WEB_VIEW, MidoriWebViewClass))
#define MIDORI_IS_WEB_VIEW(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_WEB_VIEW))
#define MIDORI_IS_WEB_VIEW_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_WEB_VIEW))
#define MIDORI_WEB_VIEW_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_WEB_VIEW, MidoriWebViewClass))
typedef struct _MidoriWebView MidoriWebView;
typedef struct _MidoriWebViewPrivate MidoriWebViewPrivate;
typedef struct _MidoriWebViewClass MidoriWebViewClass;
struct _MidoriWebView
{
WebKitWebView parent_instance;
MidoriWebViewPrivate* priv;
};
struct _MidoriWebViewClass
{
WebKitWebViewClass parent_class;
/* Signals */
void
(*progress_started) (MidoriWebView* web_view,
guint progress);
void
(*progress_changed) (MidoriWebView* web_view,
guint progress);
void
(*progress_done) (MidoriWebView* web_view,
guint progress);
void
(*load_done) (MidoriWebView* web_view,
WebKitWebFrame* frame);
void
(*statusbar_text_changed) (MidoriWebView* web_view,
const gchar* text);
void
(*element_motion) (MidoriWebView* web_view,
const gchar* link_uri);
void
(*close) (MidoriWebView* web_view);
void
(*new_tab) (MidoriWebView* web_view,
const gchar* uri);
void
(*new_window) (MidoriWebView* web_view,
const gchar* uri);
void
(*create_web_view) (MidoriWebView* web_view,
MidoriWebView* new_web_view);
};
GType
midori_web_view_get_type (void);
GtkWidget*
midori_web_view_new (void);
void
midori_web_view_set_settings (MidoriWebView* web_view,
MidoriWebSettings* web_settings);
GtkWidget*
midori_web_view_get_proxy_menu_item (MidoriWebView* web_view);
GtkWidget*
midori_web_view_get_proxy_tab_label (MidoriWebView* web_view);
KatzeXbelItem*
midori_web_view_get_proxy_xbel_item (MidoriWebView* web_view);
gboolean
midori_web_view_is_loading (MidoriWebView* web_view);
gint
midori_web_view_get_progress (MidoriWebView* web_view);
const gchar*
midori_web_view_get_display_uri (MidoriWebView* web_view);
const gchar*
midori_web_view_get_display_title (MidoriWebView* web_view);
const gchar*
midori_web_view_get_link_uri (MidoriWebView* web_view);
G_END_DECLS
#endif /* __MIDORI_WEB_VIEW_H__ */

View file

@ -152,62 +152,45 @@ static void on_prefs_userStylesheetUri_file_set(GtkWidget* widget, CPrefs* prefs
static void on_prefs_toolbarstyle_changed(GtkWidget* widget, CPrefs* prefs) static void on_prefs_toolbarstyle_changed(GtkWidget* widget, CPrefs* prefs)
{ {
config->toolbarStyle = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); config->toolbarStyle = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
gtk_toolbar_set_style(GTK_TOOLBAR(prefs->browser->navibar) /*gtk_toolbar_set_style(GTK_TOOLBAR(prefs->browser->navibar)
, config_to_toolbarstyle(config->toolbarStyle)); , config_to_toolbarstyle(config->toolbarStyle));*/
} }
static void on_prefs_toolbarSmall_toggled(GtkWidget* widget, CPrefs* prefs) static void on_prefs_toolbarSmall_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->toolbarSmall = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->toolbarSmall = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
gtk_toolbar_set_icon_size(GTK_TOOLBAR(prefs->browser->navibar) /*gtk_toolbar_set_icon_size(GTK_TOOLBAR(prefs->browser->navibar)
, config_to_toolbariconsize(config->toolbarSmall)); , config_to_toolbariconsize(config->toolbarSmall));*/
} }
static void on_prefs_tabClose_toggled(GtkWidget* widget, CPrefs* prefs) static void on_prefs_tabClose_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->tabClose = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->tabClose = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
GList* items = browsers; g_object_set(webSettings, "close-button", config->tabClose, NULL);
do
{
CBrowser* browser = (CBrowser*)items->data;
sokoke_widget_set_visible(browser->webView_close, config->tabClose);
}
while((items = g_list_next(items)));
g_list_free(items);
} }
static void on_prefs_tabSize_changed(GtkWidget* widget, CPrefs* prefs) static void on_prefs_tabSize_changed(GtkWidget* widget, CPrefs* prefs)
{ {
config->tabSize = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget)); config->tabSize = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
gint w, h; g_object_set(webSettings, "tab-label-size", config->tabSize, NULL);
sokoke_widget_get_text_size(prefs->browser->webView_name, "M", &w, &h);
GList* items = browsers;
do
{
CBrowser* browser = (CBrowser*)items->data;
gtk_widget_set_size_request(GTK_WIDGET(browser->webView_name)
, w * config->tabSize, -1);
}
while((items = g_list_next(items)));
g_list_free(items);
} }
static void on_prefs_toolbarWebSearch_toggled(GtkWidget* widget, CPrefs* prefs) static void on_prefs_toolbarWebSearch_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->toolbarWebSearch = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->toolbarWebSearch = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
sokoke_widget_set_visible(prefs->browser->webSearch, config->toolbarWebSearch); //sokoke_widget_set_visible(prefs->browser->webSearch, config->toolbarWebSearch);
} }
static void on_prefs_toolbarNewTab_toggled(GtkWidget* widget, CPrefs* prefs) static void on_prefs_toolbarNewTab_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->toolbarNewTab = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->toolbarNewTab = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
sokoke_widget_set_visible(prefs->browser->newTab, config->toolbarNewTab); //sokoke_widget_set_visible(prefs->browser->newTab, config->toolbarNewTab);
} }
static void on_prefs_toolbarClosedTabs_toggled(GtkWidget* widget, CPrefs* prefs) static void on_prefs_toolbarClosedTabs_toggled(GtkWidget* widget, CPrefs* prefs)
{ {
config->toolbarClosedTabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); config->toolbarClosedTabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
sokoke_widget_set_visible(prefs->browser->closedTabs, config->toolbarClosedTabs); //sokoke_widget_set_visible(prefs->browser->closedTabs, config->toolbarClosedTabs);
} }
static gboolean on_prefs_locationsearch_focus_out(GtkWidget* widget static gboolean on_prefs_locationsearch_focus_out(GtkWidget* widget
@ -233,7 +216,10 @@ static void on_prefs_protocols_render_icon(GtkTreeViewColumn* column
gchar* path; gchar* path;
if((path = g_find_program_in_path(binary))) if((path = g_find_program_in_path(binary)))
{ {
GtkIconTheme* icon_theme = get_icon_theme(prefs->treeview); GdkScreen* screen = gtk_widget_get_screen(prefs->treeview);
if(!screen)
screen = gdk_screen_get_default();
GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen(screen);
if(g_path_is_absolute(binary)) if(g_path_is_absolute(binary))
{ {
g_free(path); path = g_path_get_basename(binary); g_free(path); path = g_path_get_basename(binary);
@ -308,16 +294,14 @@ static void on_prefs_protocols_combobox_changed(GtkWidget* widget, CPrefs* prefs
gtk_widget_set_sensitive(prefs->add, command == NULL); gtk_widget_set_sensitive(prefs->add, command == NULL);
} }
GtkWidget* prefs_preferences_dialog_new(CBrowser* browser) GtkWidget* prefs_preferences_dialog_new(MidoriBrowser* browser)
{ {
gchar* dialogTitle = g_strdup_printf("%s Preferences", g_get_application_name()); gchar* dialogTitle = g_strdup_printf("%s Preferences", g_get_application_name());
GtkWidget* dialog = gtk_dialog_new_with_buttons(dialogTitle GtkWidget* dialog = gtk_dialog_new_with_buttons(dialogTitle
, GTK_WINDOW(browser->window) , GTK_WINDOW(browser)
, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR , GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR
, GTK_STOCK_HELP , GTK_STOCK_HELP, GTK_RESPONSE_HELP
, GTK_RESPONSE_HELP , GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE
, GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
, NULL); , NULL);
gtk_window_set_icon_name(GTK_WINDOW(dialog), GTK_STOCK_PREFERENCES); gtk_window_set_icon_name(GTK_WINDOW(dialog), GTK_STOCK_PREFERENCES);
// TODO: Implement some kind of help function // TODO: Implement some kind of help function
@ -326,7 +310,6 @@ GtkWidget* prefs_preferences_dialog_new(CBrowser* browser)
CPrefs* prefs = g_new0(CPrefs, 1); CPrefs* prefs = g_new0(CPrefs, 1);
prefs->browser = browser; prefs->browser = browser;
//prefs->window = dialog;
g_signal_connect(dialog, "response", G_CALLBACK(g_free), prefs); g_signal_connect(dialog, "response", G_CALLBACK(g_free), prefs);
// TODO: Do we want tooltips for explainations or can we omit that? // TODO: Do we want tooltips for explainations or can we omit that?
@ -334,7 +317,7 @@ GtkWidget* prefs_preferences_dialog_new(CBrowser* browser)
// TODO: Take multiple windows into account when applying changes // TODO: Take multiple windows into account when applying changes
GtkWidget* xfce_heading; GtkWidget* xfce_heading;
if((xfce_heading = sokoke_xfce_header_new( if((xfce_heading = sokoke_xfce_header_new(
gtk_window_get_icon_name(GTK_WINDOW(browser->window)), dialogTitle))) gtk_window_get_icon_name(GTK_WINDOW(browser)), dialogTitle)))
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox) gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox)
, xfce_heading, FALSE, FALSE, 0); , xfce_heading, FALSE, FALSE, 0);
g_free(dialogTitle); g_free(dialogTitle);

View file

@ -12,7 +12,7 @@
#ifndef __PREFS_H__ #ifndef __PREFS_H__
#define __PREFS_H__ 1 #define __PREFS_H__ 1
#include "browser.h" #include "midori-browser.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -20,8 +20,7 @@
typedef struct typedef struct
{ {
CBrowser* browser; MidoriBrowser* browser;
//GtkWidget* window;
GtkWidget* userStylesheetUri; GtkWidget* userStylesheetUri;
GtkWidget* treeview; GtkWidget* treeview;
GtkWidget* combobox; GtkWidget* combobox;
@ -38,6 +37,6 @@ enum
// -- Declarations // -- Declarations
GtkWidget* GtkWidget*
prefs_preferences_dialog_new(CBrowser*); prefs_preferences_dialog_new(MidoriBrowser*);
#endif /* !__PREFS_H__ */ #endif /* !__PREFS_H__ */

View file

@ -12,7 +12,7 @@
#include "search.h" #include "search.h"
#include "sokoke.h" #include "sokoke.h"
#include "../katze/katze.h" #include <katze/katze.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View file

@ -34,18 +34,6 @@ void sokoke_combo_box_add_strings(GtkComboBox* combobox
va_end(args); va_end(args);
} }
void sokoke_radio_action_set_current_value(GtkRadioAction* action
, gint currentValue)
{
// Activates the group member with the given value
#if GTK_CHECK_VERSION(2, 10, 0)
gtk_radio_action_set_current_value(action, currentValue);
#else
// TODO: Implement this for older gtk
UNIMPLEMENTED
#endif
}
void sokoke_widget_set_visible(GtkWidget* widget, gboolean visible) void sokoke_widget_set_visible(GtkWidget* widget, gboolean visible)
{ {
// Show or hide the widget // Show or hide the widget
@ -304,86 +292,3 @@ void sokoke_menu_item_set_accel(GtkMenuItem* menuitem, const gchar* path
g_free(accel); g_free(accel);
} }
} }
gboolean sokoke_entry_can_undo(GtkEntry* entry)
{
// TODO: Can we undo the last input?
return FALSE;
}
gboolean sokoke_entry_can_redo(GtkEntry* entry)
{
// TODO: Can we redo the last input?
return FALSE;
}
void sokoke_entry_undo(GtkEntry* entry)
{
// TODO: Implement undo
UNIMPLEMENTED
}
void sokoke_entry_redo(GtkEntry* entry)
{
// TODO: Implement redo
UNIMPLEMENTED
}
static gboolean sokoke_on_undo_entry_key_down(GtkEntry* widget, GdkEventKey* event
, gpointer userdata)
{
switch(event->keyval)
{
case GDK_Undo:
sokoke_entry_undo(widget);
return FALSE;
case GDK_Redo:
sokoke_entry_redo(widget);
return FALSE;
default:
return FALSE;
}
}
static void sokoke_on_undo_entry_populate_popup(GtkEntry* entry, GtkMenu* menu
, gpointer userdata)
{
// Enhance the entry's menu with undo and redo items.
GtkWidget* menuitem = gtk_separator_menu_item_new();
gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show(menuitem);
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_REDO, NULL);
g_signal_connect(menuitem, "activate", G_CALLBACK(sokoke_entry_redo), userdata);
gtk_widget_set_sensitive(menuitem, sokoke_entry_can_redo(entry));
gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show(menuitem);
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_UNDO, NULL);
g_signal_connect(menuitem, "activate", G_CALLBACK(sokoke_entry_undo), userdata);
gtk_widget_set_sensitive(menuitem, sokoke_entry_can_undo(entry));
gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show(menuitem);
}
gboolean sokoke_entry_get_can_undo(GtkEntry* entry)
{
// TODO: Is this entry undo enabled?
return FALSE;
}
void sokoke_entry_set_can_undo(GtkEntry* entry, gboolean canUndo)
{
if(canUndo)
{
g_signal_connect(entry, "key-press-event"
, G_CALLBACK(sokoke_on_undo_entry_key_down), NULL);
g_signal_connect(entry, "populate-popup"
, G_CALLBACK(sokoke_on_undo_entry_populate_popup), NULL);
}
else
{
g_signal_handlers_disconnect_by_func(entry
, G_CALLBACK(sokoke_on_undo_entry_key_down), NULL);
g_signal_handlers_disconnect_by_func(entry
, G_CALLBACK(sokoke_on_undo_entry_populate_popup), NULL);
}
}

View file

@ -20,9 +20,6 @@
void void
sokoke_combo_box_add_strings(GtkComboBox*, const gchar*, ...); sokoke_combo_box_add_strings(GtkComboBox*, const gchar*, ...);
void
sokoke_radio_action_set_current_value(GtkRadioAction*, gint);
void void
sokoke_widget_set_visible(GtkWidget*, gboolean); sokoke_widget_set_visible(GtkWidget*, gboolean);
@ -70,22 +67,4 @@ sokoke_widget_get_text_size(GtkWidget*, const gchar*, gint*, gint*);
void void
sokoke_menu_item_set_accel(GtkMenuItem*, const gchar*, const gchar*, GdkModifierType); sokoke_menu_item_set_accel(GtkMenuItem*, const gchar*, const gchar*, GdkModifierType);
gboolean
sokoke_entry_can_undo(GtkEntry*);
gboolean
sokoke_entry_can_redo(GtkEntry*);
void
sokoke_entry_undo(GtkEntry*);
void
sokoke_entry_redo(GtkEntry*);
gboolean
sokoke_entry_get_can_undo(GtkEntry*);
void
sokoke_entry_set_can_undo(GtkEntry*, gboolean);
#endif /* !__SOKOKE_H__ */ #endif /* !__SOKOKE_H__ */

242
src/ui.h
View file

@ -12,246 +12,4 @@
#ifndef __UI_H__ #ifndef __UI_H__
#define __UI_H__ 1 #define __UI_H__ 1
// -- Credits
static const gchar* credits_authors[] = { "Christian Dywan <christian@twotoasts.de>", NULL };
static const gchar* credits_documenters/*[]*/ = /*{ */NULL/* }*/;
static const gchar* credits_artists[] = { "Nancy Runge <nancy@twotoasts.de>", NULL };
// -- Licenses
static const gchar* license =
"This library is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU Lesser General Public\n"
"License as published by the Free Software Foundation; either\n"
"version 2.1 of the License, or (at your option) any later version.\n";
// -- User interface description
static const gchar* ui_markup =
"<ui>"
"<menubar>"
"<menu action='File'>"
"<menuitem action='WindowNew'/>"
"<menuitem action='TabNew'/>"
"<separator/>"
"<menuitem action='Open'/>"
"<separator/>"
"<menuitem action='SaveAs'/>"
"<separator/>"
"<menuitem action='TabClose'/>"
"<menuitem action='WindowClose'/>"
"<separator/>"
"<menuitem action='PageSetup'/>"
"<menuitem action='PrintPreview'/>"
"<menuitem action='Print'/>"
"<separator/>"
"<menuitem action='PrivateBrowsing'/>"
"<menuitem action='WorkOffline'/>"
"<separator/>"
"<menuitem action='Quit'/>"
"</menu>"
"<menu action='Edit'>"
"<menuitem action='Undo'/>"
"<menuitem action='Redo'/>"
"<separator/>"
"<menuitem action='Cut'/>"
"<menuitem action='Copy'/>"
"<menuitem action='Paste'/>"
"<menuitem action='Delete'/>"
"<separator/>"
"<menuitem action='SelectAll'/>"
"<separator/>"
"<menuitem action='ManageSearchEngines'/>"
"<menuitem action='Preferences'/>"
"</menu>"
"<menu action='View'>"
"<menu action='Toolbars'>"
"<menuitem action='ToolbarNavigation'/>"
"<menuitem action='ToolbarBookmarks'/>"
"<menuitem action='ToolbarDownloads'/>"
"<menuitem action='ToolbarStatus'/>"
"</menu>"
"<menuitem action='Panels'/>"
"<separator/>"
"<menuitem action='Refresh'/>"
"<menuitem action='Stop'/>"
"<menu action='RefreshEvery'>"
"<menuitem action='RefreshEveryEnable'/>"
"<separator/>"
"<menuitem action='RefreshEvery30'/>"
"<menuitem action='RefreshEvery60'/>"
"<menuitem action='RefreshEvery300'/>"
"<menuitem action='RefreshEvery900'/>"
"<menuitem action='RefreshEvery1800'/>"
"<menuitem action='RefreshEveryCustom'/>"
"</menu>"
"<separator/>"
"<menuitem action='ZoomIn'/>"
"<menuitem action='ZoomOut'/>"
"<menuitem action='ZoomNormal'/>"
"<separator/>"
"<menuitem action='SourceView'/>"
"<menuitem action='Fullscreen'/>"
"</menu>"
"<menu action='Go'>"
"<menuitem action='Back'/>"
"<menuitem action='Forward'/>"
"<menuitem action='Home'/>"
"<menuitem action='Location'/>"
"<menuitem action='Websearch'/>"
"<menuitem action='OpenInPageholder'/>"
"<menu action='TabsClosed'>"
// Closed tabs shall be prepended here
"<separator/>"
"<menuitem action='TabsClosedClear'/>"
"</menu>"
"<separator/>"
"<menuitem action='Find'/>"
"<menuitem action='FindNext'/>"
"<menuitem action='FindPrevious'/>"
"<separator/>"
"<menuitem action='FormFill'/>"
"</menu>"
"<menu action='Bookmarks'>"
"<menuitem action='BookmarkNew'/>"
"<menuitem action='BookmarksManage'/>"
"<separator/>"
// Bookmarks shall be appended here
"</menu>"
"<menu action='Tools'>"
"<menuitem action='PanelDownloads'/>"
"<menuitem action='PanelBookmarks'/>"
"<menuitem action='PanelHistory'/>"
"<menuitem action='PanelTabs'/>"
"<menuitem action='PanelPageholder'/>"
"<menuitem action='PanelExtensions'/>"
"<menuitem action='PanelConsole'/>"
"<separator/>"
// TODO: Insert widgets and custom tools here
"</menu>"
"<menu action='Window'>"
"<menuitem action='SessionLoad'/>"
"<menuitem action='SessionSave'/>"
"<separator/>"
"<menuitem action='TabPrevious'/>"
"<menuitem action='TabNext'/>"
"<menuitem action='TabOverview'/>"
"<separator/>"
// All open tabs shall be appended here
"</menu>"
"<menu action='Help'>"
"<menuitem action='HelpContents'/>"
"<menuitem action='About'/>"
"</menu>"
"</menubar>"
"<toolbar name='toolbar_navigation'>"
"<toolitem action='TabNew'/>"
"<toolitem action='Back'/>"
"<toolitem action='Forward'/>"
"<toolitem action='RefreshStop'/>"
"<toolitem action='Home'/>"
"<toolitem action='FormFill'/>"
"<placeholder name='Location'/>"
"<placeholder name='WebSearch'/>"
"<placeholder name='TabTrash'/>"
"</toolbar>"
"<toolbar name='toolbar_panels'>"
"<toolitem action='PanelDownloads'/>"
"<toolitem action='PanelBookmarks'/>"
"<toolitem action='PanelHistory'/>"
"<toolitem action='PanelTabs'/>"
"<toolitem action='PanelPageholder'/>"
"<toolitem action='PanelExtensions'/>"
"<toolitem action='PanelConsole'/>"
"</toolbar>"
"<toolbar name='toolbar_bookmarks'>"
"<toolitem action='BookmarkNew'/>"
"<toolitem action='BookmarkEdit'/>"
"<toolitem action='BookmarkDelete'/>"
"</toolbar>"
"<popup name='popup_bookmark'>"
"<menuitem action='BookmarkOpen'/>"
"<menuitem action='BookmarkOpenTab'/>"
"<menuitem action='BookmarkOpenWindow'/>"
"<separator/>"
"<menuitem action='BookmarkEdit'/>"
"<menuitem action='BookmarkDelete'/>"
"</popup>"
"<popup name='popup_webView'>"
"<menuitem action='Back'/>"
"<menuitem action='Forward'/>"
"<menuitem action='Refresh'/>"
"<menuitem action='Stop'/>"
"<menu action='RefreshEvery'>"
"<menuitem action='RefreshEveryEnable'/>"
"<separator/>"
"<menuitem action='RefreshEvery30'/>"
"<menuitem action='RefreshEvery60'/>"
"<menuitem action='RefreshEvery300'/>"
"<menuitem action='RefreshEvery900'/>"
"<menuitem action='RefreshEvery1800'/>"
"<menuitem action='RefreshEveryCustom'/>"
"</menu>"
"<separator/>"
"<menuitem action='SelectionLinksNewTabs'/>"
"<menuitem action='SelectionTextTabNew'/>"
"<menuitem action='SelectionTextTabCurrent'/>"
"<menuitem action='SelectionTextWindowNew'/>"
"<separator/>"
"<menuitem action='UndoTabClose'/>"
"<menuitem action='SaveAs'/>"
"<menuitem action='BookmarkNew'/>"
"<menuitem action='Print'/>"
"<separator/>"
"<menuitem action='SelectAll'/>"
"<separator/>"
"<menuitem action='BackgroundImage'/>"
"<menuitem action='SourceView'/>"
"<menuitem action='Properties'/>"
"</popup>"
"<popup name='popup_element'>"
"<menuitem action='LinkTabNew'/>"
"<menuitem action='LinkTabCurrent'/>"
"<menuitem action='LinkWindowNew'/>"
"<separator/>"
"<menuitem action='LinkSaveAs'/>"
"<menuitem action='LinkSaveWith'/>"
"<menuitem action='LinkCopy'/>"
"<menuitem action='LinkBookmarkNew'/>"
"<separator/>"
"<menuitem action='SelectionLinksNewTabs'/>"
"<menuitem action='SelectionTextTabNew'/>"
"<menuitem action='SelectionTextTabCurrent'/>"
"<menuitem action='SelectionTextWindowNew'/>"
"<separator/>"
"<menuitem action='ImageViewTabNew'/>"
"<menuitem action='ImageViewTabCurrent'/>"
"<menuitem action='ImageSaveAs'/>"
"<menuitem action='ImageSaveWith'/>"
"<menuitem action='ImageCopy'/>"
"<separator/>"
"<menuitem action='ImageViewTabNew'/>"
"<menuitem action='ImageViewTabCurrent'/>"
"<separator/>"
"<menuitem action='Copy_'/>"
"<menuitem action='SelectionSearch'/>"
"<menuitem action='SelectionSearchWith'/>"
"<menuitem action='SelectionSourceView'/>"
"<separator/>"
"<menuitem action='Properties'/>"
"</popup>"
"<popup name='popup_editable'>"
"<menuitem action='Undo'/>"
"<menuitem action='Redo'/>"
"<separator/>"
"<menuitem action='Cut'/>"
"<menuitem action='Copy'/>"
"<menuitem action='Paste'/>"
"<menuitem action='Delete'/>"
"<separator/>"
"<menuitem action='SelectAll'/>"
"</popup>"
"</ui>";
#endif /* !__UI_H__ */ #endif /* !__UI_H__ */

View file

@ -19,12 +19,12 @@
#include <string.h> #include <string.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
void update_searchEngine(guint index, CBrowser* browser) void update_searchEngine(guint index, GtkWidget* search)
{ {
guint n = g_list_length(searchEngines); guint n = g_list_length(searchEngines);
// Display a default icon in case we have no engines // Display a default icon in case we have no engines
if(!n) if(!n)
sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(browser->webSearch), SEXY_ICON_ENTRY_PRIMARY sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(search), SEXY_ICON_ENTRY_PRIMARY
, GTK_IMAGE(gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU))); , GTK_IMAGE(gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU)));
// Change the icon and default text according to the chosen engine // Change the icon and default text according to the chosen engine
else else
@ -34,24 +34,24 @@ void update_searchEngine(guint index, CBrowser* browser)
index = 0; index = 0;
SearchEngine* engine = (SearchEngine*)g_list_nth_data(searchEngines, index); SearchEngine* engine = (SearchEngine*)g_list_nth_data(searchEngines, index);
GdkPixbuf* pixbuf = load_web_icon(search_engine_get_icon(engine) GdkPixbuf* pixbuf = load_web_icon(search_engine_get_icon(engine)
, GTK_ICON_SIZE_MENU, browser->navibar); , GTK_ICON_SIZE_MENU, search);
sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(browser->webSearch) sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(search)
, SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf))); , SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf)));
g_object_unref(pixbuf); g_object_unref(pixbuf);
sokoke_entry_set_default_text(GTK_ENTRY(browser->webSearch) sokoke_entry_set_default_text(GTK_ENTRY(search)
, search_engine_get_short_name(engine)); , search_engine_get_short_name(engine));
config->searchEngine = index; config->searchEngine = index;
} }
} }
void on_webSearch_engine_activate(GtkWidget* widget, CBrowser* browser) void on_webSearch_engine_activate(GtkWidget* widget, MidoriBrowser* browser)
{ {
guint index = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(widget), "engine")); guint index = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(widget), "engine"));
update_searchEngine(index, browser); update_searchEngine(index, widget);
} }
void on_webSearch_icon_released(GtkWidget* widget, SexyIconEntryPosition* pos void on_webSearch_icon_released(GtkWidget* widget, SexyIconEntryPosition* pos
, gint button, CBrowser* browser) , gint button, MidoriBrowser* browser)
{ {
GtkWidget* menu = gtk_menu_new(); GtkWidget* menu = gtk_menu_new();
guint n = g_list_length(searchEngines); guint n = g_list_length(searchEngines);
@ -84,14 +84,14 @@ void on_webSearch_icon_released(GtkWidget* widget, SexyIconEntryPosition* pos
gtk_widget_show(menuitem); gtk_widget_show(menuitem);
} }
menuitem = gtk_separator_menu_item_new(); /*menuitem = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show(menuitem); gtk_widget_show(menuitem);
GtkAction* action = gtk_action_group_get_action( GtkAction* action = gtk_action_group_get_action(
browser->actiongroup, "ManageSearchEngines"); browser->actiongroup, "ManageSearchEngines");
menuitem = gtk_action_create_menu_item(action); menuitem = gtk_action_create_menu_item(action);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show(menuitem); gtk_widget_show(menuitem);*/
sokoke_widget_popup(widget, GTK_MENU(menu), NULL); sokoke_widget_popup(widget, GTK_MENU(menu), NULL);
} }
@ -299,16 +299,16 @@ static void on_webSearch_remove(GtkWidget* widget, CWebSearch* webSearch)
gtk_list_store_remove(GTK_LIST_STORE(liststore), &iter); gtk_list_store_remove(GTK_LIST_STORE(liststore), &iter);
search_engine_free(searchEngine); search_engine_free(searchEngine);
searchEngines = g_list_remove(searchEngines, searchEngine); searchEngines = g_list_remove(searchEngines, searchEngine);
update_searchEngine(config->searchEngine, webSearch->browser); //update_searchEngine(config->searchEngine, webSearch->browser);
webSearch_toggle_edit_buttons(g_list_nth(searchEngines, 0) != NULL, webSearch); webSearch_toggle_edit_buttons(g_list_nth(searchEngines, 0) != NULL, webSearch);
// FIXME: we want to allow undo of some kind // FIXME: we want to allow undo of some kind
} }
GtkWidget* webSearch_manageSearchEngines_dialog_new(CBrowser* browser) GtkWidget* webSearch_manageSearchEngines_dialog_new(MidoriBrowser* browser)
{ {
const gchar* dialogTitle = "Manage search engines"; const gchar* dialogTitle = "Manage search engines";
GtkWidget* dialog = gtk_dialog_new_with_buttons(dialogTitle GtkWidget* dialog = gtk_dialog_new_with_buttons(dialogTitle
, GTK_WINDOW(browser->window) , GTK_WINDOW(browser)
, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR , GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR
, GTK_STOCK_HELP , GTK_STOCK_HELP
, GTK_RESPONSE_HELP , GTK_RESPONSE_HELP
@ -394,7 +394,7 @@ GtkWidget* webSearch_manageSearchEngines_dialog_new(CBrowser* browser)
return dialog; return dialog;
} }
gboolean on_webSearch_key_down(GtkWidget* widget, GdkEventKey* event, CBrowser* browser) gboolean on_webSearch_key_down(GtkWidget* widget, GdkEventKey* event, MidoriBrowser* browser)
{ {
GdkModifierType state = (GdkModifierType)0; GdkModifierType state = (GdkModifierType)0;
gint x, y; gdk_window_get_pointer(NULL, &x, &y, &state); gint x, y; gdk_window_get_pointer(NULL, &x, &y, &state);
@ -403,25 +403,25 @@ gboolean on_webSearch_key_down(GtkWidget* widget, GdkEventKey* event, CBrowser*
switch(event->keyval) switch(event->keyval)
{ {
case GDK_Up: case GDK_Up:
update_searchEngine(config->searchEngine - 1, browser); //update_searchEngine(config->searchEngine - 1, browser);
return TRUE; return TRUE;
case GDK_Down: case GDK_Down:
update_searchEngine(config->searchEngine + 1, browser); //update_searchEngine(config->searchEngine + 1, browser);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
gboolean on_webSearch_scroll(GtkWidget* webView, GdkEventScroll* event, CBrowser* browser) gboolean on_webSearch_scroll(GtkWidget* webView, GdkEventScroll* event, MidoriBrowser* browser)
{ {
if(event->direction == GDK_SCROLL_DOWN) if(event->direction == GDK_SCROLL_DOWN)
update_searchEngine(config->searchEngine + 1, browser); ;//update_searchEngine(config->searchEngine + 1, browser);
else if(event->direction == GDK_SCROLL_UP) else if(event->direction == GDK_SCROLL_UP)
update_searchEngine(config->searchEngine - 1, browser); ;//update_searchEngine(config->searchEngine - 1, browser);
return TRUE; return TRUE;
} }
void on_webSearch_activate(GtkWidget* widget, CBrowser* browser) void on_webSearch_activate(GtkWidget* widget, MidoriBrowser* browser)
{ {
const gchar* keywords = gtk_entry_get_text(GTK_ENTRY(widget)); const gchar* keywords = gtk_entry_get_text(GTK_ENTRY(widget));
gchar* url; gchar* url;
@ -436,6 +436,7 @@ void on_webSearch_activate(GtkWidget* widget, CBrowser* browser)
else else
search = g_strconcat(url, " ", keywords, NULL); search = g_strconcat(url, " ", keywords, NULL);
entry_completion_append(GTK_ENTRY(widget), keywords); entry_completion_append(GTK_ENTRY(widget), keywords);
webkit_web_view_open(WEBKIT_WEB_VIEW(get_nth_webView(-1, browser)), search); GtkWidget* webView = midori_browser_get_current_web_view(browser);
webkit_web_view_open(WEBKIT_WEB_VIEW(webView), search);
g_free(search); g_free(search);
} }

View file

@ -12,7 +12,7 @@
#ifndef __WEBSEARCH_H__ #ifndef __WEBSEARCH_H__
#define __WEBSEARCH_H__ 1 #define __WEBSEARCH_H__ 1
#include "browser.h" #include "midori-browser.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libsexy/sexy.h> #include <libsexy/sexy.h>
@ -22,7 +22,7 @@
typedef struct typedef struct
{ {
CBrowser* browser; MidoriBrowser* browser;
GtkWidget* window; GtkWidget* window;
GtkWidget* treeview; GtkWidget* treeview;
GtkWidget* edit; GtkWidget* edit;
@ -38,24 +38,24 @@ enum
// -- Declarations // -- Declarations
void void
update_searchEngine(guint, CBrowser*); update_searchEngine(guint, GtkWidget*);
void void
on_webSearch_icon_released(GtkWidget*, SexyIconEntryPosition*, gint, CBrowser*); on_webSearch_icon_released(GtkWidget*, SexyIconEntryPosition*, gint, MidoriBrowser*);
void void
on_webSearch_engine_activate(GtkWidget*, CBrowser*); on_webSearch_engine_activate(GtkWidget*, MidoriBrowser*);
void void
on_webSearch_activate(GtkWidget*, CBrowser*); on_webSearch_activate(GtkWidget*, MidoriBrowser*);
GtkWidget* GtkWidget*
webSearch_manageSearchEngines_dialog_new(CBrowser*); webSearch_manageSearchEngines_dialog_new(MidoriBrowser*);
gboolean gboolean
on_webSearch_key_down(GtkWidget*, GdkEventKey*, CBrowser*); on_webSearch_key_down(GtkWidget*, GdkEventKey*, MidoriBrowser*);
gboolean gboolean
on_webSearch_scroll(GtkWidget*, GdkEventScroll*, CBrowser*); on_webSearch_scroll(GtkWidget*, GdkEventScroll*, MidoriBrowser*);
#endif /* !__WEBSEARCH_H__ */ #endif /* !__WEBSEARCH_H__ */

View file

@ -1,376 +0,0 @@
/*
Copyright (C) 2007-2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#include "webView.h"
#include "helpers.h"
#include "sokoke.h"
#include "../katze/katze.h"
#include <string.h>
WebKitNavigationResponse on_webView_navigation_requested(GtkWidget* webView
, WebKitWebFrame* frame, WebKitNetworkRequest* networkRequest)
{
WebKitNavigationResponse response = WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
// TODO: Ask webkit wether it knows the protocol for "unknown protcol"
// TODO: This isn't the place for uri scheme handling
const gchar* uri = webkit_network_request_get_uri(networkRequest);
gchar* protocol = strtok(g_strdup(uri), ":");
if(spawn_protocol_command(protocol, uri))
response = WEBKIT_NAVIGATION_RESPONSE_IGNORE;
g_free(protocol);
return response;
}
void on_webView_title_changed(GtkWidget* webView, WebKitWebFrame* frame
, const gchar* title, CBrowser* browser)
{
const gchar* newTitle;
if(title)
newTitle = title;
else
newTitle = webkit_web_frame_get_uri(frame);
katze_xbel_item_set_title(browser->sessionItem, newTitle);
gtk_label_set_text(GTK_LABEL(browser->webView_name), newTitle);
sokoke_widget_set_tooltip_text(gtk_widget_get_parent(
gtk_widget_get_parent(browser->webView_name)), newTitle);
gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(
browser->webView_menu))), newTitle);
if(webView == get_nth_webView(-1, browser))
{
gchar* windowTitle = g_strconcat(newTitle, " - ", PACKAGE_NAME, NULL);
gtk_window_set_title(GTK_WINDOW(browser->window), windowTitle);
g_free(windowTitle);
}
}
void on_webView_icon_changed(GtkWidget* webView, WebKitWebFrame* widget
, CBrowser* browser)
{
// TODO: Implement icon updates; currently this isn't ever called anyway
const gchar* icon = NULL;
UNIMPLEMENTED
if(icon)
{
gtk_label_set_text(GTK_LABEL(browser->webView_name), "icon");
gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(
browser->webView_menu))), "icon");
if(webView == get_nth_webView(-1, browser))
{
gchar* windowTitle = g_strconcat("icon", " - ", PACKAGE_NAME, NULL);
gtk_window_set_title(GTK_WINDOW(browser->window), windowTitle);
g_free(windowTitle);
}
}
}
void on_webView_load_started(GtkWidget* webView, WebKitWebFrame* widget
, CBrowser* browser)
{
browser->loadedPercent = 0;
update_favicon(browser);
if(webView == get_nth_webView(-1, browser))
{
update_gui_state(browser);
update_statusbar(browser);
}
}
void on_webView_load_committed(GtkWidget* webView, WebKitWebFrame* frame
, CBrowser* browser)
{
const gchar* uri = webkit_web_frame_get_uri(frame);
gchar* newUri = g_strdup(uri ? uri : "");
katze_xbel_bookmark_set_href(browser->sessionItem, newUri);
if(webView == get_nth_webView(-1, browser))
{
gtk_entry_set_text(GTK_ENTRY(browser->location), newUri);
gtk_label_set_text(GTK_LABEL(browser->webView_name), newUri);
katze_assign(browser->statusMessage, NULL);
}
}
void on_webView_load_changed(GtkWidget* webView, gint progress, CBrowser* browser)
{
browser->loadedPercent = progress;
if(webView == get_nth_webView(-1, browser))
update_statusbar(browser);
}
void on_webView_load_finished(GtkWidget* webView, WebKitWebFrame* widget
, CBrowser* browser)
{
browser->loadedPercent = -1;
update_favicon(browser);
if(webView == get_nth_webView(-1, browser))
update_gui_state(browser);
}
void on_webView_status_message(GtkWidget* webView, const gchar* text, CBrowser* browser)
{
katze_assign(browser->statusMessage, g_strdup(text));
update_statusbar(browser);
}
void on_webView_selection_changed(GtkWidget* webView, CBrowser* browser)
{
UNIMPLEMENTED
}
gboolean on_webView_console_message(GtkWidget* webView
, const gchar* message, gint line, const gchar* sourceId, CBrowser* browser)
{
return FALSE;
}
void on_webView_link_hover(GtkWidget* webView, const gchar* tooltip
, const gchar* uri, CBrowser* browser)
{
katze_assign(browser->statusMessage, g_strdup(uri));
update_statusbar(browser);
katze_assign(browser->elementUri, g_strdup(uri));
}
/*
GtkWidget* on_webView_window_open(GtkWidget* webView, const gchar* sUri
, CBrowser* browser)
{
// A window is created
// TODO: Respect config->iNewPages
// TODO: Find out if this comes from a script or a click
// TODO: Block scripted popups, return NULL and show status icon
CBrowser* newBrowser = browser_new(config->openPopupsInTabs ? browser : NULL);
return newBrowser->webView;
}
*/
void webView_popup(GtkWidget* webView, GdkEventButton* event, CBrowser* browser)
{
gboolean isLink = browser->elementUri != NULL; // Did we right-click a link?
gboolean haveLinks = FALSE; // TODO: Are several links selected?
gboolean isImage = FALSE; // TODO: Did we right-click an image?
gboolean isEditable = webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(webView));
gboolean hasSelection = webkit_web_view_has_selection(WEBKIT_WEB_VIEW(webView));
update_edit_items(browser);
// Download manager available?
const gchar* downloadManager = g_datalist_get_data(&config->protocols_commands, "download");
gboolean canDownload = downloadManager && *downloadManager;
action_set_visible("LinkTabNew", isLink, browser);
action_set_visible("LinkTabCurrent", isLink, browser);
action_set_visible("LinkWindowNew", isLink, browser);
action_set_visible("LinkSaveAs", isLink, browser);
action_set_visible("LinkSaveWith", isLink && canDownload, browser);
action_set_visible("LinkCopy", isLink, browser);
action_set_visible("LinkBookmarkNew", isLink, browser);
action_set_visible("SelectionLinksNewTabs", haveLinks && hasSelection, browser);
action_set_visible("SelectionTextTabNew", haveLinks && hasSelection, browser);
action_set_visible("SelectionTextTabCurrent", haveLinks && hasSelection, browser);
action_set_visible("SelectionTextWindowNew", haveLinks && hasSelection, browser);
action_set_visible("ImageViewTabNew", isImage, browser);
action_set_visible("ImageViewTabCurrent", isImage, browser);
action_set_visible("ImageSaveAs", isImage, browser);
action_set_visible("ImageSaveWith", isImage && canDownload, browser);
action_set_visible("ImageCopy", isImage, browser);
action_set_visible("Copy_", hasSelection || isEditable, browser);
action_set_visible("SelectionSearch", hasSelection, browser);
action_set_visible("SelectionSearchWith", hasSelection, browser);
action_set_visible("SelectionSourceView", hasSelection, browser);
action_set_visible("SourceView", !hasSelection, browser);
if(isEditable)
sokoke_widget_popup(webView, GTK_MENU(browser->popup_editable), event);
else if(isLink || isImage || hasSelection)
sokoke_widget_popup(webView, GTK_MENU(browser->popup_element), event);
else
sokoke_widget_popup(webView, GTK_MENU(browser->popup_webView), event);
}
gboolean on_webView_button_press(GtkWidget* webView, GdkEventButton* event
, CBrowser* browser)
{
GdkModifierType state = (GdkModifierType)0;
gint x, y;
gdk_window_get_pointer(NULL, &x, &y, &state);
switch(event->button)
{
case 1:
if(!browser->elementUri)
return FALSE;
if(state & GDK_SHIFT_MASK)
{
// Open link in new window
CBrowser* curBrowser = browser_new(NULL);
webkit_web_view_open(WEBKIT_WEB_VIEW(curBrowser->webView), browser->elementUri);
return TRUE;
}
else if(state & GDK_MOD1_MASK)
{
// Open link in new tab
CBrowser* curBrowser = browser_new(browser);
webkit_web_view_open(WEBKIT_WEB_VIEW(curBrowser->webView), browser->elementUri);
return TRUE;
}
break;
case 2:
if(state & GDK_CONTROL_MASK)
{
//webkit_web_view_set_text_size(WEBKIT_WEB_VIEW(webView), 1);
return TRUE;
}
else
{
if(!browser->elementUri)
return FALSE;
// Open link in new tab
CBrowser* curBrowser = browser_new(browser);
webkit_web_view_open(WEBKIT_WEB_VIEW(curBrowser->webView), browser->elementUri);
return TRUE;
}
break;
case 3:
webView_popup(webView, event, browser);
return TRUE;
}
return FALSE;
}
gboolean on_webView_button_press_after(GtkWidget* webView, GdkEventButton* event
, CBrowser* browser)
{
if(event->button == 2 && config->middleClickGoto)
{
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
gchar* text = gtk_clipboard_wait_for_text(clipboard);
gchar* uri = NULL;
if(text && strchr(text, '.') && !strchr(text, ' '))
uri = magic_uri(text, FALSE);
g_free(text);
if(uri)
{
webkit_web_view_open(WEBKIT_WEB_VIEW(browser->webView), uri);
g_free(uri);
return TRUE;
}
}
return FALSE;
}
void on_webView_popup(GtkWidget* webView, CBrowser* browser)
{
webView_popup(webView, NULL, browser);
}
gboolean on_webView_scroll(GtkWidget* webView, GdkEventScroll* event
, CBrowser* browser)
{
GdkModifierType state = (GdkModifierType)0;
gint x, y;
gdk_window_get_pointer(NULL, &x, &y, &state);
if(state & GDK_CONTROL_MASK)
{
/*const gfloat size = webkit_web_view_get_text_size(WEBKIT_WEB_VIEW(webView));
if(event->direction == GDK_SCROLL_DOWN)
webkit_web_view_set_text_size(WEBKIT_WEB_VIEW(webView), size + 0.1);
else if(event->direction == GDK_SCROLL_UP)
webView_set_text_size(WEBKIT_WEB_VIEW(webView), size - 0.1);*/
return TRUE;
}
else
return FALSE;
}
gboolean on_webView_leave(GtkWidget* webView, GdkEventCrossing* event, CBrowser* browser)
{
katze_assign(browser->statusMessage, NULL);
update_statusbar(browser);
return TRUE;
}
void on_webView_destroy(GtkWidget* widget, CBrowser* browser)
{
// Update browser list, free memory and possibly quit
GList* tmp = g_list_find(browsers, browser);
browsers = g_list_delete_link(browsers, tmp);
g_free(browser->elementUri);
g_free(browser->statusMessage);
// FIXME: Multiple windows are not taken into account
if(!g_list_nth(browsers, 0))
{
g_object_unref(browser->actiongroup);
g_object_unref(browser->popup_bookmark);
g_object_unref(browser->popup_webView);
g_object_unref(browser->popup_element);
g_object_unref(browser->popup_editable);
guint i;
guint n = katze_xbel_folder_get_n_items(bookmarks);
for(i = 0; i < n; i++)
katze_xbel_item_unref(katze_xbel_folder_get_nth_item(bookmarks, i));
gtk_main_quit();
}
}
// webView actions begin here
GtkWidget* webView_new(GtkWidget** scrolled)
{
*scrolled = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(*scrolled)
, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
GTK_WIDGET_SET_FLAGS(*scrolled, GTK_CAN_FOCUS);
GtkWidget* webView = webkit_web_view_new();
gtk_container_add(GTK_CONTAINER(*scrolled), webView);
return webView;
}
void webView_open(GtkWidget* webView, const gchar* uri)
{
webkit_web_view_open(WEBKIT_WEB_VIEW(webView), uri);
// We need to check the browser first
// No browser means this is a panel
CBrowser* browser = get_browser_from_webView(webView);
if(browser)
{
katze_xbel_bookmark_set_href(browser->sessionItem, uri);
katze_xbel_item_set_title(browser->sessionItem, "");
}
}
void webView_close(GtkWidget* webView, CBrowser* browser)
{
browser = get_browser_from_webView(webView);
const gchar* uri = katze_xbel_bookmark_get_href(browser->sessionItem);
katze_xbel_folder_remove_item(session, browser->sessionItem);
if(uri && *uri)
{
katze_xbel_folder_prepend_item(tabtrash, browser->sessionItem);
guint n = katze_xbel_folder_get_n_items(tabtrash);
if(n > 10)
{
KatzeXbelItem* item = katze_xbel_folder_get_nth_item(tabtrash, n - 1);
katze_xbel_item_unref(item);
}
}
else
katze_xbel_item_unref(browser->sessionItem);
gtk_widget_destroy(browser->webView_menu);
gtk_notebook_remove_page(GTK_NOTEBOOK(browser->webViews)
, get_webView_index(webView, browser));
update_browser_actions(browser);
}

View file

@ -1,87 +0,0 @@
/*
Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __webView_H__
#define __webView_H__ 1
#include <gtk/gtk.h>
#include "browser.h"
#include "debug.h"
#include <webkit/webkit.h>
WebKitNavigationResponse
on_webView_navigation_requested(GtkWidget* webView, WebKitWebFrame* frame
, WebKitNetworkRequest* networkRequest);
void
on_webView_title_changed(GtkWidget*, WebKitWebFrame*, const gchar*, CBrowser*);
void
on_webView_icon_changed(GtkWidget*, WebKitWebFrame*, CBrowser*);
void
on_webView_load_started(GtkWidget* , WebKitWebFrame*, CBrowser*);
void
on_webView_load_committed(GtkWidget* , WebKitWebFrame*, CBrowser*);
void
on_webView_load_changed(GtkWidget*, gint progress, CBrowser*);
void
on_webView_load_finished(GtkWidget*, WebKitWebFrame*, CBrowser*);
void
on_webView_status_message(GtkWidget*, const gchar*, CBrowser*);
void
on_webView_selection_changed(GtkWidget*, CBrowser*);
gboolean
on_webView_console_message(GtkWidget*, const gchar*, gint, const gchar*, CBrowser*);
void
on_webView_link_hover(GtkWidget*, const gchar*, const gchar*, CBrowser*);
/*
GtkWidget*
on_webView_window_open(GtkWidget*, const gchar*, CBrowser*);
*/
gboolean
on_webView_button_press(GtkWidget*, GdkEventButton*, CBrowser*);
gboolean
on_webView_button_press_after(GtkWidget*, GdkEventButton*, CBrowser*);
void
on_webView_popup(GtkWidget*, CBrowser*);
gboolean
on_webView_scroll(GtkWidget*, GdkEventScroll*, CBrowser*);
gboolean
on_webView_leave(GtkWidget*, GdkEventCrossing*, CBrowser*);
void
on_webView_destroy(GtkWidget*, CBrowser*);
GtkWidget*
webView_new(GtkWidget**);
void
webView_open(GtkWidget*, const gchar*);
void
webView_close(GtkWidget*, CBrowser*);
#endif /* !__webView_H__ */