diff --git a/src/Makefile.am b/src/Makefile.am index 04dccba1..93d0f86e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ midori_SOURCES = \ main.c main.h \ midori-browser.c midori-browser.h \ midori-panel.c midori-panel.h \ + midori-console.c midori-console.h \ midori-trash.c midori-trash.h \ midori-webview.c midori-webview.h \ midori-websettings.c midori-websettings.h \ diff --git a/src/midori-browser.c b/src/midori-browser.c index afb2acd6..fd35e658 100644 --- a/src/midori-browser.c +++ b/src/midori-browser.c @@ -22,6 +22,7 @@ #include "sokoke.h" #include "midori-webview.h" #include "midori-panel.h" +#include "midori-console.h" #include "midori-trash.h" #include @@ -51,6 +52,7 @@ struct _MidoriBrowserPrivate GtkWidget* panel; GtkWidget* panel_bookmarks; + GtkWidget* panel_console; GtkWidget* panel_pageholder; GtkWidget* notebook; @@ -99,15 +101,15 @@ static void midori_browser_finalize (GObject* object); static void -midori_browser_set_property (GObject* object, - guint prop_id, +midori_browser_set_property (GObject* object, + guint prop_id, const GValue* value, - GParamSpec* pspec); + GParamSpec* pspec); static void -midori_browser_get_property (GObject* object, - guint prop_id, - GValue* value, +midori_browser_get_property (GObject* object, + guint prop_id, + GValue* value, GParamSpec* pspec); static GtkAction* @@ -199,7 +201,7 @@ _midori_browser_update_interface (MidoriBrowser* browser) } static GtkWidget* -_midori_browser_scrolled_for_child (MidoriBrowser* panel, +_midori_browser_scrolled_for_child (MidoriBrowser* browser, GtkWidget* child) { GtkWidget* scrolled = gtk_widget_get_parent (child); @@ -209,7 +211,7 @@ _midori_browser_scrolled_for_child (MidoriBrowser* panel, } static GtkWidget* -_midori_browser_child_for_scrolled (MidoriBrowser* panel, +_midori_browser_child_for_scrolled (MidoriBrowser* browser, GtkWidget* scrolled) { GtkWidget* child = gtk_bin_get_child (GTK_BIN (scrolled)); @@ -374,8 +376,11 @@ midori_web_view_console_message_cb (GtkWidget* web_view, const gchar* source_id, MidoriBrowser* browser) { - // FIXME: We want this to appear in a panel - return FALSE; + MidoriBrowserPrivate* priv = browser->priv; + + midori_console_add (MIDORI_CONSOLE (priv->panel_console), + message, line, source_id); + return TRUE; } static void @@ -623,8 +628,8 @@ _action_quit_activate (GtkAction* action, } static void -_action_edit_activate(GtkAction* action, - MidoriBrowser* browser) +_action_edit_activate (GtkAction* action, + MidoriBrowser* browser) { GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); gboolean can_cut = FALSE, can_copy = FALSE, can_paste = FALSE; @@ -654,8 +659,8 @@ _action_edit_activate(GtkAction* action, } static void -_action_cut_activate(GtkAction* action, - MidoriBrowser* browser) +_action_cut_activate (GtkAction* action, + MidoriBrowser* browser) { GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); if (G_LIKELY (widget)) @@ -663,8 +668,8 @@ _action_cut_activate(GtkAction* action, } static void -_action_copy_activate(GtkAction* action, - MidoriBrowser* browser) +_action_copy_activate (GtkAction* action, + MidoriBrowser* browser) { GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); if (G_LIKELY (widget)) @@ -672,8 +677,8 @@ _action_copy_activate(GtkAction* action, } static void -_action_paste_activate(GtkAction* action, - MidoriBrowser* browser) +_action_paste_activate (GtkAction* action, + MidoriBrowser* browser) { GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); if (G_LIKELY (widget)) @@ -681,8 +686,8 @@ _action_paste_activate(GtkAction* action, } static void -_action_delete_activate(GtkAction* action, - MidoriBrowser* browser) +_action_delete_activate (GtkAction* action, + MidoriBrowser* browser) { GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); if (G_LIKELY (widget)) @@ -695,13 +700,13 @@ _action_delete_activate(GtkAction* action, } static void -_action_select_all_activate(GtkAction* action, - MidoriBrowser* browser) +_action_select_all_activate (GtkAction* action, + MidoriBrowser* browser) { GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); if (G_LIKELY (widget)) { - if (GTK_IS_ENTRY (widget)) + if (GTK_IS_EDITABLE (widget)) gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); else g_signal_emit_by_name (widget, "select-all"); @@ -1316,22 +1321,23 @@ midori_panel_bookmarks_button_release_event_cb (GtkWidget* widget, if (event->button != 2 && event->button != 3) return FALSE; - GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); + GtkTreeSelection* selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (widget)); if (selection) { GtkTreeModel* model; GtkTreeIter iter; - if (gtk_tree_selection_get_selected(selection, &model, &iter)) + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { KatzeXbelItem* item; - gtk_tree_model_get(model, &iter, 0, &item, -1); - if (event->button == 2 && katze_xbel_item_is_bookmark(item)) + gtk_tree_model_get (model, &iter, 0, &item, -1); + if (event->button == 2 && katze_xbel_item_is_bookmark (item)) { - const gchar* uri = katze_xbel_bookmark_get_href(item); + const gchar* uri = katze_xbel_bookmark_get_href (item); midori_browser_append_uri (browser, uri); } else - _midori_panel_bookmarks_popup(widget, event, item, browser); + _midori_panel_bookmarks_popup (widget, event, item, browser); return TRUE; } } @@ -1342,23 +1348,24 @@ static void midori_panel_bookmarks_popup_menu_cb (GtkWidget* widget, MidoriBrowser* browser) { - GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); + GtkTreeSelection* selection = gtk_tree_view_get_selection ( + GTK_TREE_VIEW (widget)); if (selection) { GtkTreeModel* model; GtkTreeIter iter; - if (gtk_tree_selection_get_selected(selection, &model, &iter)) + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { KatzeXbelItem* item; - gtk_tree_model_get(model, &iter, 0, &item, -1); - _midori_panel_bookmarks_popup(widget, NULL, item, browser); + gtk_tree_model_get (model, &iter, 0, &item, -1); + _midori_panel_bookmarks_popup (widget, NULL, item, browser); } } } static void -_tree_store_insert_folder (GtkTreeStore* treestore, - GtkTreeIter* parent, +_tree_store_insert_folder (GtkTreeStore* treestore, + GtkTreeIter* parent, KatzeXbelItem* folder) { guint n = katze_xbel_folder_get_n_items (folder); @@ -1430,7 +1437,7 @@ midori_browser_bookmarks_item_render_text_cb (GtkTreeViewColumn* column, g_object_set (renderer, "markup", _("Separator"), NULL); else g_object_set (renderer, "markup", NULL, - "text", katze_xbel_item_get_title(item), NULL); + "text", katze_xbel_item_get_title (item), NULL); } static void @@ -1443,7 +1450,7 @@ midori_browser_bookmark_menu_folder_activate_cb (GtkWidget* menuitem, MidoriBrowser* browser) { GtkWidget* menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menuitem)); - gtk_container_foreach(GTK_CONTAINER (menu), (GtkCallback) gtk_widget_destroy, NULL);//... + gtk_container_foreach (GTK_CONTAINER (menu), (GtkCallback) gtk_widget_destroy, NULL);//... KatzeXbelItem* folder = (KatzeXbelItem*)g_object_get_data(G_OBJECT (menuitem), "KatzeXbelItem"); _midori_browser_create_bookmark_menu (browser, folder, menu); // Remove all menuitems when the menu is hidden. @@ -1456,7 +1463,7 @@ static void midori_browser_bookmarkbar_folder_activate_cb (GtkToolItem* toolitem, MidoriBrowser* browser) { - GtkWidget* menu = gtk_menu_new(); + GtkWidget* menu = gtk_menu_new (); KatzeXbelItem* folder = (KatzeXbelItem*)g_object_get_data ( G_OBJECT (toolitem), "KatzeXbelItem"); _midori_browser_create_bookmark_menu (browser, folder, menu); @@ -1471,7 +1478,8 @@ static void midori_browser_menu_bookmarks_item_activate_cb (GtkWidget* widget, MidoriBrowser* browser) { - KatzeXbelItem* item = (KatzeXbelItem*)g_object_get_data(G_OBJECT(widget), "KatzeXbelItem"); + KatzeXbelItem* item = (KatzeXbelItem*)g_object_get_data (G_OBJECT (widget), + "KatzeXbelItem"); GtkWidget* web_view = midori_browser_get_current_web_view (browser); g_object_set (web_view, "uri", katze_xbel_bookmark_get_href (item), NULL); } @@ -1813,7 +1821,7 @@ _action_trash_empty_activate (GtkAction* action, static void _action_bookmark_delete_activate (GtkAction* action, - MidoriBrowser* browser) + MidoriBrowser* browser) { MidoriBrowserPrivate* priv = browser->priv; @@ -2514,7 +2522,7 @@ midori_browser_init (MidoriBrowser* browser) NULL); midori_panel_bookmarks_cursor_or_row_changed_cb (GTK_TREE_VIEW (treeview), browser); - gtk_box_pack_start (GTK_BOX (box), treeview, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), treeview, TRUE, TRUE, 0); priv->panel_bookmarks = treeview; gtk_widget_show_all (box); midori_panel_append_page (MIDORI_PANEL (priv->panel), @@ -2531,12 +2539,10 @@ midori_browser_init (MidoriBrowser* browser) "package", _("Transfers")); // Console - priv->panel_pageholder = g_object_new (MIDORI_TYPE_WEB_VIEW, - "uri", "about:blank", - NULL); - gtk_widget_show (priv->panel_pageholder); + priv->panel_console = midori_console_new (); + gtk_widget_show (priv->panel_console); midori_panel_append_page (MIDORI_PANEL (priv->panel), - priv->panel_pageholder, + priv->panel_console, "terminal", _("Console")); // History diff --git a/src/midori-console.c b/src/midori-console.c new file mode 100644 index 00000000..95189219 --- /dev/null +++ b/src/midori-console.c @@ -0,0 +1,192 @@ +/* + Copyright (C) 2008 Christian Dywan + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +#include "midori-console.h" + +#include "sokoke.h" +#include + +G_DEFINE_TYPE (MidoriConsole, midori_console, GTK_TYPE_VBOX) + +struct _MidoriConsolePrivate +{ + GtkWidget* treeview; +}; + +#define MIDORI_CONSOLE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ + MIDORI_TYPE_CONSOLE, MidoriConsolePrivate)) + +static void +midori_console_class_init (MidoriConsoleClass* class) +{ + g_type_class_add_private (class, sizeof (MidoriConsolePrivate)); +} + +static void +midori_console_button_clear_clicked_cb (GtkToolItem* toolitem, + MidoriConsole* console) +{ + MidoriConsolePrivate* priv = console->priv; + + GtkTreeModel* model = gtk_tree_view_get_model ( + GTK_TREE_VIEW (priv->treeview)); + gtk_tree_store_clear (GTK_TREE_STORE (model)); +} + +static void +midori_console_treeview_render_icon_cb (GtkTreeViewColumn* column, + GtkCellRenderer* renderer, + GtkTreeModel* model, + GtkTreeIter* iter, + GtkWidget* treeview) +{ + // gchar* source_id; + // gtk_tree_model_get (model, iter, 2, &source_id, -1); + + g_object_set (renderer, "stock-id", GTK_STOCK_DIALOG_WARNING, NULL); + + // g_free (source_id); +} + +static void +midori_console_treeview_render_text_cb (GtkTreeViewColumn* column, + GtkCellRenderer* renderer, + GtkTreeModel* model, + GtkTreeIter* iter, + GtkWidget* treeview) +{ + gchar* message; + gint line; + gchar* source_id; + gtk_tree_model_get (model, iter, 0, &message, 1, &line, 2, &source_id, -1); + + gchar* text = g_strdup_printf ("%d @ %s\n%s", line, source_id, message); + g_object_set (renderer, "text", text, NULL); + g_free (text); + + g_free (message); + g_free (source_id); +} + +static void +midori_console_treeview_row_activated_cb (GtkTreeView* treeview, + GtkTreePath* path, + GtkTreeViewColumn* column, + MidoriConsole* console) +{ + /*GtkTreeModel* model = gtk_tree_view_get_model (treeview); + GtkTreeIter iter; + if (gtk_tree_model_get_iter (model, &iter, path)) + { + gchar* source_id; + gtk_tree_model_get (model, &iter, 2, &source_id, -1); + g_free (source_id); + }*/ +} + +static void +midori_console_init (MidoriConsole* console) +{ + console->priv = MIDORI_CONSOLE_GET_PRIVATE (console); + + MidoriConsolePrivate* priv = console->priv; + + // Create the toolbar + GtkWidget* toolbar = gtk_toolbar_new (); + gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ); + gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON); + GtkToolItem* toolitem = gtk_tool_item_new (); + // TODO: What about a find entry here that filters e.g. by url? + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); + toolitem = gtk_separator_tool_item_new (); + gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (toolitem), + FALSE); + gtk_tool_item_set_expand (toolitem, TRUE); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); + toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR); + gtk_tool_item_set_is_important (toolitem, TRUE); + g_signal_connect (toolitem, "clicked", + G_CALLBACK (midori_console_button_clear_clicked_cb), console); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); + gtk_widget_show_all (toolbar); + gtk_box_pack_start (GTK_BOX (console), toolbar, FALSE, FALSE, 0); + + // Create the treeview + GtkTreeViewColumn* column; + GtkCellRenderer* renderer_text; + GtkCellRenderer* renderer_pixbuf; + GtkTreeStore* treestore = gtk_tree_store_new (3, G_TYPE_STRING, + G_TYPE_INT, + G_TYPE_STRING); + priv->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (treestore)); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->treeview), FALSE); + column = gtk_tree_view_column_new (); + renderer_pixbuf = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE); + gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf, + (GtkTreeCellDataFunc)midori_console_treeview_render_icon_cb, + priv->treeview, NULL); + renderer_text = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (column, renderer_text, FALSE); + gtk_tree_view_column_set_cell_data_func (column, renderer_text, + (GtkTreeCellDataFunc)midori_console_treeview_render_text_cb, + priv->treeview, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column); + g_object_unref (treestore); + g_signal_connect (priv->treeview, "row-activated", + G_CALLBACK (midori_console_treeview_row_activated_cb), + console); + gtk_widget_show (priv->treeview); + gtk_box_pack_start (GTK_BOX (console), priv->treeview, TRUE, TRUE, 0); +} + +/** + * midori_console_new: + * + * Creates a new empty console. + * + * Return value: a new #MidoriConsole + **/ +GtkWidget* +midori_console_new (void) +{ + MidoriConsole* console = g_object_new (MIDORI_TYPE_CONSOLE, + NULL); + + return GTK_WIDGET (console); +} + +/** + * midori_console_add: + * @console: a #MidoriConsole + * @message: a descriptive message + * @line: the line in the source file + * @source_id: the source + * + * Adds a new message to the console. + **/ +void +midori_console_add (MidoriConsole* console, + const gchar* message, + gint line, + const gchar* source_id) +{ + g_return_if_fail (MIDORI_IS_CONSOLE (console)); + + MidoriConsolePrivate* priv = console->priv; + + GtkTreeView* treeview = GTK_TREE_VIEW (priv->treeview); + GtkTreeModel* treemodel = gtk_tree_view_get_model (treeview); + gtk_tree_store_insert_with_values (GTK_TREE_STORE (treemodel), + NULL, NULL, G_MAXINT, + 0, message, 1, line, 2, source_id, -1); +} diff --git a/src/midori-console.h b/src/midori-console.h new file mode 100644 index 00000000..91898b95 --- /dev/null +++ b/src/midori-console.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2008 Christian Dywan + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +#ifndef __MIDORI_CONSOLE_H__ +#define __MIDORI_CONSOLE_H__ + +#include + +#include + +G_BEGIN_DECLS + +#define MIDORI_TYPE_CONSOLE \ + (midori_console_get_type ()) +#define MIDORI_CONSOLE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_CONSOLE, MidoriConsole)) +#define MIDORI_CONSOLE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_CONSOLE, MidoriConsoleClass)) +#define MIDORI_IS_CONSOLE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_CONSOLE)) +#define MIDORI_IS_CONSOLE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_CONSOLE)) +#define MIDORI_CONSOLE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_CONSOLE, MidoriConsoleClass)) + +typedef struct _MidoriConsole MidoriConsole; +typedef struct _MidoriConsolePrivate MidoriConsolePrivate; +typedef struct _MidoriConsoleClass MidoriConsoleClass; + +struct _MidoriConsole +{ + GtkVBox parent_instance; + + MidoriConsolePrivate* priv; +}; + +struct _MidoriConsoleClass +{ + GtkVBoxClass parent_class; +}; + +GType +midori_console_get_type (void); + +GtkWidget* +midori_console_new (void); + +void +midori_console_add (MidoriConsole* panel, + const gchar* message, + gint line, + const gchar* source_id); + +G_END_DECLS + +#endif /* __MIDORI_CONSOLE_H__ */