]> spindle.queued.net Git - midori/commitdiff
Merge thread setup, stock items, argv, i18n into MidoriApp
authorChristian Dywan <christian@twotoasts.de>
Fri, 28 Oct 2011 20:18:05 +0000 (22:18 +0200)
committerChristian Dywan <christian@twotoasts.de>
Fri, 28 Oct 2011 20:49:10 +0000 (22:49 +0200)
midori/main.c
midori/midori-app.c
midori/midori-app.h
midori/sokoke.c
midori/sokoke.h
tests/browser.c
tests/extensions.c
tests/magic-uri.c
tests/properties.c

index 0333742a9187362b9658a7d86a68773b17795a43..615b324b14c91cafd150bcb88094aeaf3e56bffa 100644 (file)
     #include <libsoup/soup-cache.h>
 #endif
 
-#if ENABLE_NLS
-    #include <libintl.h>
-    #include <locale.h>
-#endif
-
 #ifdef HAVE_SIGNAL_H
     #include <signal.h>
 #endif
@@ -1975,24 +1970,6 @@ main (int    argc,
         #define midori_startup_timer(tmrmsg)
     #endif
 
-    #if ENABLE_NLS
-    setlocale (LC_ALL, "");
-    if (g_getenv ("MIDORI_NLSPATH"))
-        bindtextdomain (GETTEXT_PACKAGE, g_getenv ("MIDORI_NLSPATH"));
-    else
-    #ifdef G_OS_WIN32
-    {
-        gchar* path = sokoke_find_data_filename ("locale");
-        bindtextdomain (GETTEXT_PACKAGE, path);
-        g_free (path);
-    }
-    #else
-        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
-    #endif
-    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-    textdomain (GETTEXT_PACKAGE);
-    #endif
-
     #ifdef HAVE_SIGNAL_H
     #ifdef SIGHUP
     signal (SIGHUP, &signal_handler);
@@ -2008,8 +1985,7 @@ main (int    argc,
     #endif
     #endif
 
-    /* Preserve argument vector */
-    sokoke_get_argv (argv);
+    midori_app_setup (argv);
 
     /* Parse cli options */
     webapp = NULL;
@@ -2035,10 +2011,6 @@ main (int    argc,
         return 1;
     }
 
-    /* libSoup uses threads, so we need to initialize threads. */
-    if (!g_thread_supported ()) g_thread_init (NULL);
-    sokoke_register_stock_items ();
-
     if (config && !g_path_is_absolute (config))
     {
         g_critical (_("The specified configuration folder is invalid."));
index 26b81ce1a669fe86389dc03d0ab30760c6190dea..ca8abe36713601c2d1e8c6d1fbb1438549f4f0a0 100644 (file)
 #endif
 
 #include "midori-app.h"
+#include "midori-stock.h"
 #include "sokoke.h"
 
 #include <string.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 
+#if ENABLE_NLS
+    #include <libintl.h>
+    #include <locale.h>
+#endif
+
 #if HAVE_HILDON
     #include <libosso.h>
     #ifdef HAVE_HILDON_2_2
@@ -1277,3 +1283,151 @@ midori_app_send_notification (MidoriApp*   app,
     }
     #endif
 }
+
+/**
+ * midori_app_init:
+ *
+ * Saves the argument vector, initializes threading and registers
+ * several custom stock items and prepares localization.
+ *
+ * Since: 0.4.2
+ **/
+void
+midori_app_setup (gchar** argument_vector)
+{
+    GtkIconSource* icon_source;
+    GtkIconSet* icon_set;
+    GtkIconFactory* factory;
+    gsize i;
+
+    typedef struct
+    {
+        const gchar* stock_id;
+        const gchar* label;
+        GdkModifierType modifier;
+        guint keyval;
+        const gchar* fallback;
+    } FatStockItem;
+    static FatStockItem items[] =
+    {
+        { STOCK_EXTENSION, NULL, 0, 0, GTK_STOCK_CONVERT },
+        { STOCK_IMAGE, NULL, 0, 0, GTK_STOCK_ORIENTATION_PORTRAIT },
+        { STOCK_WEB_BROWSER, NULL, 0, 0, "gnome-web-browser" },
+        { STOCK_NEWS_FEED, NULL, 0, 0, GTK_STOCK_INDEX },
+        { STOCK_SCRIPT, NULL, 0, 0, GTK_STOCK_EXECUTE },
+        { STOCK_STYLE, NULL, 0, 0, GTK_STOCK_SELECT_COLOR },
+        { STOCK_TRANSFER, NULL, 0, 0, GTK_STOCK_SAVE },
+
+        { STOCK_BOOKMARK,       N_("_Bookmark"), 0, 0, GTK_STOCK_FILE },
+        { STOCK_BOOKMARKS,      N_("_Bookmarks"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_B, GTK_STOCK_DIRECTORY },
+        { STOCK_BOOKMARK_ADD,   N_("Add Boo_kmark"), 0, 0, "stock_add-bookmark" },
+        { STOCK_CONSOLE,        N_("_Console"), 0, 0, GTK_STOCK_DIALOG_WARNING },
+        { STOCK_EXTENSIONS,     N_("_Extensions"), 0, 0, GTK_STOCK_CONVERT },
+        { STOCK_HISTORY,        N_("_History"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_H, GTK_STOCK_SORT_ASCENDING },
+        { STOCK_HOMEPAGE,       N_("_Homepage"), 0, 0, GTK_STOCK_HOME },
+        { STOCK_SCRIPTS,        N_("_Userscripts"), 0, 0, GTK_STOCK_EXECUTE },
+        { STOCK_TAB_NEW,        N_("New _Tab"), 0, 0, GTK_STOCK_ADD },
+        { STOCK_TRANSFERS,      N_("_Transfers"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_J, GTK_STOCK_SAVE },
+        { STOCK_PLUGINS,        N_("Netscape p_lugins"), 0, 0, GTK_STOCK_CONVERT },
+        { STOCK_USER_TRASH,     N_("_Closed Tabs"), 0, 0, "gtk-undo-ltr" },
+        { STOCK_WINDOW_NEW,     N_("New _Window"), 0, 0, GTK_STOCK_ADD },
+        { GTK_STOCK_DIRECTORY,  N_("New _Folder"), 0, 0, NULL },
+    };
+
+    /* Preserve argument vector */
+    sokoke_get_argv (argument_vector);
+
+    /* libSoup uses threads, therefore if WebKit is built with libSoup
+     * or Midori is using it, we need to initialize threads. */
+    if (!g_thread_supported ()) g_thread_init (NULL);
+
+    #if ENABLE_NLS
+    setlocale (LC_ALL, "");
+    if (g_getenv ("MIDORI_NLSPATH"))
+        bindtextdomain (GETTEXT_PACKAGE, g_getenv ("MIDORI_NLSPATH"));
+    else
+    #ifdef G_OS_WIN32
+    {
+        gchar* path = sokoke_find_data_filename ("locale");
+        bindtextdomain (GETTEXT_PACKAGE, path);
+        g_free (path);
+    }
+    #else
+        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+    #endif
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+    #endif
+
+    g_type_init ();
+    factory = gtk_icon_factory_new ();
+    for (i = 0; i < G_N_ELEMENTS (items); i++)
+    {
+        icon_set = gtk_icon_set_new ();
+        icon_source = gtk_icon_source_new ();
+        if (items[i].fallback)
+        {
+            gtk_icon_source_set_icon_name (icon_source, items[i].fallback);
+            items[i].fallback = NULL;
+            gtk_icon_set_add_source (icon_set, icon_source);
+        }
+        gtk_icon_source_set_icon_name (icon_source, items[i].stock_id);
+        gtk_icon_set_add_source (icon_set, icon_source);
+        gtk_icon_source_free (icon_source);
+        gtk_icon_factory_add (factory, items[i].stock_id, icon_set);
+        gtk_icon_set_unref (icon_set);
+    }
+    gtk_stock_add_static ((GtkStockItem*)items, G_N_ELEMENTS (items));
+    gtk_icon_factory_add_default (factory);
+    g_object_unref (factory);
+
+    #if HAVE_HILDON
+    /* Maemo doesn't theme stock icons. So we map platform icons
+        to stock icons. These are all monochrome toolbar icons. */
+    typedef struct
+    {
+        const gchar* stock_id;
+        const gchar* icon_name;
+    } CompatItem;
+    static CompatItem compat_items[] =
+    {
+        { GTK_STOCK_ADD,        "general_add" },
+        { GTK_STOCK_BOLD,       "general_bold" },
+        { GTK_STOCK_CLOSE,      "general_close_b" },
+        { GTK_STOCK_DELETE,     "general_delete" },
+        { GTK_STOCK_DIRECTORY,  "general_toolbar_folder" },
+        { GTK_STOCK_FIND,       "general_search" },
+        { GTK_STOCK_FULLSCREEN, "general_fullsize_b" },
+        { GTK_STOCK_GO_BACK,    "general_back" },
+        { GTK_STOCK_GO_FORWARD, "general_forward" },
+        { GTK_STOCK_GO_UP,      "filemanager_folder_up" },
+        { GTK_STOCK_GOTO_FIRST, "pdf_viewer_first_page" },
+        { GTK_STOCK_GOTO_LAST,  "pdf_viewer_last_page" },
+        { GTK_STOCK_INFO,       "general_information" },
+        { GTK_STOCK_ITALIC,     "general_italic" },
+        { GTK_STOCK_JUMP_TO,    "general_move_to_folder" },
+        { GTK_STOCK_PREFERENCES,"general_settings" },
+        { GTK_STOCK_REFRESH,    "general_refresh" },
+        { GTK_STOCK_SAVE,       "notes_save" },
+        { GTK_STOCK_STOP,       "general_stop" },
+        { GTK_STOCK_UNDERLINE,  "notes_underline" },
+        { GTK_STOCK_ZOOM_IN,    "pdf_zoomin" },
+        { GTK_STOCK_ZOOM_OUT,   "pdf_zoomout" },
+    };
+
+    factory = gtk_icon_factory_new ();
+    for (i = 0; i < G_N_ELEMENTS (compat_items); i++)
+    {
+        icon_set = gtk_icon_set_new ();
+        icon_source = gtk_icon_source_new ();
+        gtk_icon_source_set_icon_name (icon_source, compat_items[i].icon_name);
+        gtk_icon_set_add_source (icon_set, icon_source);
+        gtk_icon_source_free (icon_source);
+        gtk_icon_factory_add (factory, compat_items[i].stock_id, icon_set);
+        gtk_icon_set_unref (icon_set);
+    }
+    gtk_icon_factory_add_default (factory);
+    g_object_unref (factory);
+    #endif
+}
+
index c9a10e0cf8502416558b046115986595e8cccce4..934ce0ce7501de28e5320264a0944a2acbc1f586 100644 (file)
@@ -79,6 +79,9 @@ midori_app_send_notification      (MidoriApp*         app,
                                    const gchar*       title,
                                    const gchar*       message);
 
+void
+midori_app_setup                  (gchar**            argument_vector);
+
 G_END_DECLS
 
 #endif /* __MIDORI_APP_H__ */
index f77011a5a3ae1d6dff011dc655c3940c60fcff42..6b12fb87f5b4e944df79a00326472e6fd79dc01f 100644 (file)
@@ -1184,124 +1184,6 @@ sokoke_days_between (const time_t* day1,
     return age;
 }
 
-/**
- * sokoke_register_stock_items:
- *
- * Registers several custom stock items used throughout Midori.
- **/
-void
-sokoke_register_stock_items (void)
-{
-    GtkIconSource* icon_source;
-    GtkIconSet* icon_set;
-    GtkIconFactory* factory;
-    gsize i;
-
-    typedef struct
-    {
-        const gchar* stock_id;
-        const gchar* label;
-        GdkModifierType modifier;
-        guint keyval;
-        const gchar* fallback;
-    } FatStockItem;
-    static FatStockItem items[] =
-    {
-        { STOCK_EXTENSION, NULL, 0, 0, GTK_STOCK_CONVERT },
-        { STOCK_IMAGE, NULL, 0, 0, GTK_STOCK_ORIENTATION_PORTRAIT },
-        { STOCK_WEB_BROWSER, NULL, 0, 0, "gnome-web-browser" },
-        { STOCK_NEWS_FEED, NULL, 0, 0, GTK_STOCK_INDEX },
-        { STOCK_SCRIPT, NULL, 0, 0, GTK_STOCK_EXECUTE },
-        { STOCK_STYLE, NULL, 0, 0, GTK_STOCK_SELECT_COLOR },
-        { STOCK_TRANSFER, NULL, 0, 0, GTK_STOCK_SAVE },
-
-        { STOCK_BOOKMARK,       N_("_Bookmark"), 0, 0, GTK_STOCK_FILE },
-        { STOCK_BOOKMARKS,      N_("_Bookmarks"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_B, GTK_STOCK_DIRECTORY },
-        { STOCK_BOOKMARK_ADD,   N_("Add Boo_kmark"), 0, 0, "stock_add-bookmark" },
-        { STOCK_CONSOLE,        N_("_Console"), 0, 0, GTK_STOCK_DIALOG_WARNING },
-        { STOCK_EXTENSIONS,     N_("_Extensions"), 0, 0, GTK_STOCK_CONVERT },
-        { STOCK_HISTORY,        N_("_History"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_H, GTK_STOCK_SORT_ASCENDING },
-        { STOCK_HOMEPAGE,       N_("_Homepage"), 0, 0, GTK_STOCK_HOME },
-        { STOCK_SCRIPTS,        N_("_Userscripts"), 0, 0, GTK_STOCK_EXECUTE },
-        { STOCK_TAB_NEW,        N_("New _Tab"), 0, 0, GTK_STOCK_ADD },
-        { STOCK_TRANSFERS,      N_("_Transfers"), GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_KEY_J, GTK_STOCK_SAVE },
-        { STOCK_PLUGINS,        N_("Netscape p_lugins"), 0, 0, GTK_STOCK_CONVERT },
-        { STOCK_USER_TRASH,     N_("_Closed Tabs"), 0, 0, "gtk-undo-ltr" },
-        { STOCK_WINDOW_NEW,     N_("New _Window"), 0, 0, GTK_STOCK_ADD },
-        { GTK_STOCK_DIRECTORY,  N_("New _Folder"), 0, 0, NULL },
-    };
-
-    factory = gtk_icon_factory_new ();
-    for (i = 0; i < G_N_ELEMENTS (items); i++)
-    {
-        icon_set = gtk_icon_set_new ();
-        icon_source = gtk_icon_source_new ();
-        if (items[i].fallback)
-        {
-            gtk_icon_source_set_icon_name (icon_source, items[i].fallback);
-            items[i].fallback = NULL;
-            gtk_icon_set_add_source (icon_set, icon_source);
-        }
-        gtk_icon_source_set_icon_name (icon_source, items[i].stock_id);
-        gtk_icon_set_add_source (icon_set, icon_source);
-        gtk_icon_source_free (icon_source);
-        gtk_icon_factory_add (factory, items[i].stock_id, icon_set);
-        gtk_icon_set_unref (icon_set);
-    }
-    gtk_stock_add_static ((GtkStockItem*)items, G_N_ELEMENTS (items));
-    gtk_icon_factory_add_default (factory);
-    g_object_unref (factory);
-
-    #if HAVE_HILDON
-    /* Maemo doesn't theme stock icons. So we map platform icons
-        to stock icons. These are all monochrome toolbar icons. */
-    typedef struct
-    {
-        const gchar* stock_id;
-        const gchar* icon_name;
-    } CompatItem;
-    static CompatItem compat_items[] =
-    {
-        { GTK_STOCK_ADD,        "general_add" },
-        { GTK_STOCK_BOLD,       "general_bold" },
-        { GTK_STOCK_CLOSE,      "general_close_b" },
-        { GTK_STOCK_DELETE,     "general_delete" },
-        { GTK_STOCK_DIRECTORY,  "general_toolbar_folder" },
-        { GTK_STOCK_FIND,       "general_search" },
-        { GTK_STOCK_FULLSCREEN, "general_fullsize_b" },
-        { GTK_STOCK_GO_BACK,    "general_back" },
-        { GTK_STOCK_GO_FORWARD, "general_forward" },
-        { GTK_STOCK_GO_UP,      "filemanager_folder_up" },
-        { GTK_STOCK_GOTO_FIRST, "pdf_viewer_first_page" },
-        { GTK_STOCK_GOTO_LAST,  "pdf_viewer_last_page" },
-        { GTK_STOCK_INFO,       "general_information" },
-        { GTK_STOCK_ITALIC,     "general_italic" },
-        { GTK_STOCK_JUMP_TO,    "general_move_to_folder" },
-        { GTK_STOCK_PREFERENCES,"general_settings" },
-        { GTK_STOCK_REFRESH,    "general_refresh" },
-        { GTK_STOCK_SAVE,       "notes_save" },
-        { GTK_STOCK_STOP,       "general_stop" },
-        { GTK_STOCK_UNDERLINE,  "notes_underline" },
-        { GTK_STOCK_ZOOM_IN,    "pdf_zoomin" },
-        { GTK_STOCK_ZOOM_OUT,   "pdf_zoomout" },
-    };
-
-    factory = gtk_icon_factory_new ();
-    for (i = 0; i < G_N_ELEMENTS (compat_items); i++)
-    {
-        icon_set = gtk_icon_set_new ();
-        icon_source = gtk_icon_source_new ();
-        gtk_icon_source_set_icon_name (icon_source, compat_items[i].icon_name);
-        gtk_icon_set_add_source (icon_set, icon_source);
-        gtk_icon_source_free (icon_source);
-        gtk_icon_factory_add (factory, compat_items[i].stock_id, icon_set);
-        gtk_icon_set_unref (icon_set);
-    }
-    gtk_icon_factory_add_default (factory);
-    g_object_unref (factory);
-    #endif
-}
-
 /**
  * sokoke_set_config_dir:
  * @new_config_dir: an absolute path, or %NULL
index 91ec24c1815d2768485c96a4a4f4b0babf467148..9e4d394384546d78c0b146d757152dcdde6ce792 100644 (file)
@@ -137,9 +137,6 @@ gint
 sokoke_days_between                     (const time_t*   day1,
                                          const time_t*   day2);
 
-void
-sokoke_register_stock_items             (void);
-
 const gchar*
 sokoke_set_config_dir                   (const gchar*    new_config_dir);
 
index db815d2f91f3a51ebcba0eb4f08abfb714efb104..866292324e77a4987e91177302ab7dbc08ff8976 100644 (file)
@@ -53,12 +53,9 @@ int
 main (int    argc,
       char** argv)
 {
-    /* libSoup uses threads, therefore if WebKit is built with libSoup
-       or Midori is using it, we need to initialize threads. */
-    if (!g_thread_supported ()) g_thread_init (NULL);
+    midori_app_setup (argv);
     g_test_init (&argc, &argv, NULL);
     gtk_init_check (&argc, &argv);
-    sokoke_register_stock_items ();
 
     g_test_add_func ("/browser/create", browser_create);
 
index 7cf676db740c1efe4e76c3f7cd100a6e38ca820c..b471da2a7b56dc4ceffc0dd005fb8aa014cf5b7f 100644 (file)
@@ -234,9 +234,9 @@ int
 main (int    argc,
       char** argv)
 {
+    midori_app_setup (argv);
     g_test_init (&argc, &argv, NULL);
     gtk_init_check (&argc, &argv);
-    if (!g_thread_supported ()) g_thread_init (NULL);
     soup_session_add_feature_by_type (webkit_get_default_session (),
         SOUP_TYPE_COOKIE_JAR);
 
index 328034c0710a25aee3cd0d430787ded5dbd412c2..f9ce3b534bd6905f2c99c56e142b8527e30087a9 100644 (file)
@@ -15,7 +15,7 @@
 #endif
 
 #include "sokoke.h"
-#include <midori/midori-core.h>
+#include <midori/midori.h>
 
 #define SM "http://www.searchmash.com/search/"
 
@@ -265,9 +265,7 @@ int
 main (int    argc,
       char** argv)
 {
-    /* libSoup uses threads, therefore if WebKit is built with libSoup
-       or Midori is using it, we need to initialize threads. */
-    if (!g_thread_supported ()) g_thread_init (NULL);
+    midori_app_setup (argv);
     g_test_init (&argc, &argv, NULL);
     gtk_init_check (&argc, &argv);
 
index 315a92e997482173b25187aa7402517c7338b44b..2504b0f9eb7980b87f1c066a11c5836d73fcc30d 100644 (file)
@@ -193,12 +193,9 @@ int
 main (int    argc,
       char** argv)
 {
-    /* libSoup uses threads, therefore if WebKit is built with libSoup
-       or Midori is using it, we need to initialize threads. */
-    if (!g_thread_supported ()) g_thread_init (NULL);
+    midori_app_setup (argv);
     g_test_init (&argc, &argv, NULL);
     gtk_init_check (&argc, &argv);
-    sokoke_register_stock_items ();
 
     g_test_add_data_func ("/properties/app",
         (gconstpointer)MIDORI_TYPE_APP, properties_type_test);