]> spindle.queued.net Git - midori/commitdiff
Implement MidoriViewable and "app" in MidoriConsole
authorChristian Dywan <christian@twotoasts.de>
Wed, 3 Dec 2008 23:31:40 +0000 (00:31 +0100)
committerChristian Dywan <christian@twotoasts.de>
Wed, 3 Dec 2008 23:31:40 +0000 (00:31 +0100)
midori/midori-console.c
midori/midori-console.h

index 507b26dcb01b0dfdfcf36796a11d3515d818de7b..4946caf2580a01645f98ba9a93327f9a27f4e0b7 100644 (file)
 
 #include "midori-console.h"
 
+#include "midori-app.h"
+#include "midori-browser.h"
+#include "midori-stock.h"
+#include "midori-view.h"
+
 #include "sokoke.h"
 #include <glib/gi18n.h>
 
@@ -20,14 +25,137 @@ struct _MidoriConsole
 
     GtkWidget* toolbar;
     GtkWidget* treeview;
+    MidoriApp* app;
 };
 
-G_DEFINE_TYPE (MidoriConsole, midori_console, GTK_TYPE_VBOX)
+struct _MidoriConsoleClass
+{
+    GtkVBoxClass parent_class;
+};
+
+static void
+midori_console_viewable_iface_init (MidoriViewableIface* iface);
+
+G_DEFINE_TYPE_WITH_CODE (MidoriConsole, midori_console, GTK_TYPE_VBOX,
+                         G_IMPLEMENT_INTERFACE (MIDORI_TYPE_VIEWABLE,
+                             midori_console_viewable_iface_init));
+
+enum
+{
+    PROP_0,
+
+    PROP_APP
+};
+
+static void
+midori_console_set_property (GObject*      object,
+                             guint         prop_id,
+                             const GValue* value,
+                             GParamSpec*   pspec);
+
+static void
+midori_console_get_property (GObject*    object,
+                             guint       prop_id,
+                             GValue*     value,
+                             GParamSpec* pspec);
 
 static void
 midori_console_class_init (MidoriConsoleClass* class)
 {
-    /* Nothing to do */
+    GObjectClass* gobject_class;
+    GParamFlags flags;
+
+    gobject_class = G_OBJECT_CLASS (class);
+    gobject_class->set_property = midori_console_set_property;
+    gobject_class->get_property = midori_console_get_property;
+
+    flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
+
+    g_object_class_install_property (gobject_class,
+                                     PROP_APP,
+                                     g_param_spec_object (
+                                     "app",
+                                     "App",
+                                     "The app",
+                                     MIDORI_TYPE_APP,
+                                     flags));
+}
+
+static const gchar*
+midori_console_get_label (MidoriViewable* viewable)
+{
+    return _("Console");
+}
+
+static const gchar*
+midori_console_get_stock_id (MidoriViewable* viewable)
+{
+    return STOCK_CONSOLE;
+}
+
+static void
+midori_console_viewable_iface_init (MidoriViewableIface* iface)
+{
+    iface->get_stock_id = midori_console_get_stock_id;
+    iface->get_label = midori_console_get_label;
+    iface->get_toolbar = midori_console_get_toolbar;
+}
+
+static void
+midori_view_console_message_cb (GtkWidget*     view,
+                                const gchar*   message,
+                                gint           line,
+                                const gchar*   source_id,
+                                MidoriConsole* console)
+{
+    midori_console_add (console, message, line, source_id);
+}
+
+static void
+midori_console_browser_add_tab_cb (MidoriBrowser* browser,
+                                   MidoriView*    view,
+                                   MidoriConsole* console)
+{
+    g_signal_connect (view, "console-message",
+        G_CALLBACK (midori_view_console_message_cb), console);
+}
+
+static void
+midori_console_set_property (GObject*      object,
+                             guint         prop_id,
+                             const GValue* value,
+                             GParamSpec*   pspec)
+{
+    MidoriConsole* console = MIDORI_CONSOLE (object);
+
+    switch (prop_id)
+    {
+    case PROP_APP:
+        console->app = g_value_get_object (value);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+midori_console_get_property (GObject*    object,
+                             guint       prop_id,
+                             GValue*     value,
+                             GParamSpec* pspec)
+{
+    MidoriConsole* console = MIDORI_CONSOLE (object);
+
+    switch (prop_id)
+    {
+    case PROP_APP:
+        g_value_set_object (value, console->app);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
 }
 
 static void
@@ -46,12 +174,7 @@ midori_console_treeview_render_icon_cb (GtkTreeViewColumn* column,
                                         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
@@ -92,6 +215,16 @@ midori_console_treeview_row_activated_cb (GtkTreeView*       treeview,
     }*/
 }
 
+static void
+midori_console_hierarchy_changed_cb (MidoriConsole* console,
+                                     GtkWidget*     old_parent)
+{
+    GtkWidget* browser = gtk_widget_get_toplevel (GTK_WIDGET (console));
+    if (GTK_WIDGET_TOPLEVEL (browser))
+        g_signal_connect (browser, "add-tab",
+            G_CALLBACK (midori_console_browser_add_tab_cb), console);
+}
+
 static void
 midori_console_init (MidoriConsole* console)
 {
@@ -122,6 +255,9 @@ midori_console_init (MidoriConsole* console)
                       console);
     gtk_widget_show (console->treeview);
     gtk_box_pack_start (GTK_BOX (console), console->treeview, TRUE, TRUE, 0);
+
+    g_signal_connect (console, "hierarchy-changed",
+        G_CALLBACK (midori_console_hierarchy_changed_cb), NULL);
 }
 
 /**
@@ -142,18 +278,21 @@ midori_console_new (void)
 
 /**
  * midori_console_get_toolbar:
+ * @console: a #MidoriConsole
  *
  * Retrieves the toolbar of the console. A new widget is created on
  * the first call of this function.
  *
- * Return value: a new #MidoriConsole
+ * Return value: a toolbar widget
+ *
+ * Deprecated: 0.1.2: Use midori_viewable_get_toolbar() instead.
  **/
 GtkWidget*
-midori_console_get_toolbar (MidoriConsole* console)
+midori_console_get_toolbar (MidoriViewable* console)
 {
     g_return_val_if_fail (MIDORI_IS_CONSOLE (console), NULL);
 
-    if (!console->toolbar)
+    if (!MIDORI_CONSOLE (console)->toolbar)
     {
         GtkWidget* toolbar;
         GtkToolItem* toolitem;
@@ -177,10 +316,10 @@ midori_console_get_toolbar (MidoriConsole* console)
             G_CALLBACK (midori_console_button_clear_clicked_cb), console);
         gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
         gtk_widget_show (GTK_WIDGET (toolitem));
-        console->toolbar = toolbar;
+        MIDORI_CONSOLE (console)->toolbar = toolbar;
     }
 
-    return console->toolbar;
+    return MIDORI_CONSOLE (console)->toolbar;
 }
 
 /**
index b4c096cfc6c727920bdd9465a7ddc90fe3d74140..011837dc5c99ba7a458d1feaba4667e5815a3a5d 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <katze/katze.h>
 
+#include "midori-viewable.h"
+
 G_BEGIN_DECLS
 
 #define MIDORI_TYPE_CONSOLE \
@@ -34,11 +36,6 @@ G_BEGIN_DECLS
 typedef struct _MidoriConsole                MidoriConsole;
 typedef struct _MidoriConsoleClass           MidoriConsoleClass;
 
-struct _MidoriConsoleClass
-{
-    GtkVBoxClass parent_class;
-};
-
 GType
 midori_console_get_type               (void);
 
@@ -46,7 +43,7 @@ GtkWidget*
 midori_console_new                    (void);
 
 GtkWidget*
-midori_console_get_toolbar            (MidoriConsole*       console);
+midori_console_get_toolbar            (MidoriViewable*      console);
 
 void
 midori_console_add                    (MidoriConsole*       console,