[Xfce4-commits] <midori:master> Reflect custom app name in instance name

Christian Dywan noreply at xfce.org
Sun Dec 9 00:52:02 CET 2012


Updating branch refs/heads/master
         to 44667c8fe0e127b906d1b82b03707ef6e6ea1e06 (commit)
       from 59c957ac47d8c094d19c035bb9a780d162d480c9 (commit)

commit 44667c8fe0e127b906d1b82b03707ef6e6ea1e06
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Dec 9 00:49:18 2012 +0100

    Reflect custom app name in instance name

 midori/main.c            |    3 +-
 midori/midori-app.c      |   67 ++++++++++++++-------------------------------
 midori/midori-app.h      |    2 +-
 midori/midori-frontend.c |   10 ++++---
 midori/midori-frontend.h |    2 +-
 midori/midori.vapi       |    4 +-
 tests/app.vala           |    9 ++++--
 tests/browser.c          |    2 +-
 tests/extensions.c       |    6 ++--
 9 files changed, 43 insertions(+), 62 deletions(-)

diff --git a/midori/main.c b/midori/main.c
index 7fb8a7a..433bf3d 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -323,7 +323,8 @@ main (int    argc,
         return 0;
     }
 
-    MidoriApp* app = midori_normal_app_new (config, portable, diagnostic_dialog, webapp,
+    MidoriApp* app = midori_normal_app_new (config,
+        portable ? "portable" : "normal", diagnostic_dialog, webapp,
         execute ? NULL : uris, execute ? uris : NULL, inactivity_reset, block_uris);
     if (app == NULL)
         return 0;
diff --git a/midori/midori-app.c b/midori/midori-app.c
index 7017a5f..b661c64 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -221,7 +221,6 @@ _midori_app_add_browser (MidoriApp*     app,
         NULL);
     g_signal_connect_swapped (browser, "send-notification",
         G_CALLBACK (midori_app_send_notification), app);
-
     katze_array_add_item (app->browsers, browser);
 
     #if GTK_CHECK_VERSION (3, 0, 0)
@@ -692,7 +691,6 @@ midori_app_create_instance (MidoriApp* app)
     GdkDisplay* display;
     gchar* display_name;
     gchar* instance_name;
-    guint i, n;
     #if !HAVE_UNIQUE
     gboolean exists;
     GIOChannel* channel;
@@ -704,14 +702,16 @@ midori_app_create_instance (MidoriApp* app)
     {
         #if HAVE_UNIQUE
         const gchar* config = midori_paths_get_config_dir_for_reading ();
-        gchar* name_hash;
-        name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
-        katze_assign (app_name, g_strconcat ("midori", "_", name_hash, NULL));
+        gchar* config_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
+        gchar* name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, app_name, -1);
+        katze_assign (app_name, g_strconcat (PACKAGE_NAME,
+            "_", config_hash, "_", name_hash, NULL));
+        g_free (config_hash);
         g_free (name_hash);
-        g_object_notify (G_OBJECT (app), "name");
         #else
         katze_assign (app_name, g_strdup (PACKAGE_NAME));
         #endif
+        g_object_notify (G_OBJECT (app), "name");
     }
 
     #ifdef GDK_WINDOWING_X11
@@ -720,10 +720,7 @@ midori_app_create_instance (MidoriApp* app)
     #else
     display_name = g_strdup (gdk_display_get_name (display));
     #endif
-    n = strlen (display_name);
-    for (i = 0; i < n; i++)
-        if (strchr (":.\\/", display_name[i]))
-            display_name[i] = '_';
+    g_strdelimit (display_name, ":.\\/", '_');
     instance_name = g_strdup_printf ("de.twotoasts.%s_%s", app_name, display_name);
     g_free (display_name);
     katze_assign (app_name, instance_name);
@@ -807,7 +804,6 @@ midori_app_init (MidoriApp* app)
     #else
     app->program_notify_send = g_find_program_in_path ("notify-send");
     #endif
-
 }
 
 static void
@@ -935,12 +931,9 @@ midori_app_get_property (GObject*    object,
  * Return value: a new #MidoriApp
  **/
 MidoriApp*
-midori_app_new (void)
+midori_app_new (const gchar* name)
 {
-    MidoriApp* app = g_object_new (MIDORI_TYPE_APP,
-                                   NULL);
-
-    return app;
+    return g_object_new (MIDORI_TYPE_APP, "name", name, NULL);
 }
 
 /**
@@ -964,12 +957,10 @@ midori_app_instance_is_running (MidoriApp* app)
         app->instance = midori_app_create_instance (app);
 
     #if HAVE_UNIQUE
-    if (app->instance)
-        return unique_app_is_running (app->instance);
+    return app->instance && unique_app_is_running (app->instance);
     #else
-        return g_object_get_data (G_OBJECT (app), "sock-exists") != NULL;
+    return g_object_get_data (G_OBJECT (app), "sock-exists") != NULL;
     #endif
-    return FALSE;
 }
 
 /**
@@ -986,17 +977,13 @@ midori_app_instance_is_running (MidoriApp* app)
 gboolean
 midori_app_instance_send_activate (MidoriApp* app)
 {
-    #if HAVE_UNIQUE
-    UniqueResponse response;
-    #endif
-
-    /* g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); */
+    g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
     g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
 
     #if HAVE_UNIQUE
     if (app->instance)
     {
-        response = unique_app_send_message (app->instance, UNIQUE_ACTIVATE, NULL);
+        UniqueResponse response = unique_app_send_message (app->instance, UNIQUE_ACTIVATE, NULL);
         if (response == UNIQUE_RESPONSE_OK)
             return TRUE;
     }
@@ -1022,17 +1009,13 @@ midori_app_instance_send_activate (MidoriApp* app)
 gboolean
 midori_app_instance_send_new_browser (MidoriApp* app)
 {
-    #if HAVE_UNIQUE
-    UniqueResponse response;
-    #endif
-
-    /* g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); */
+    g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
     g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
 
     #if HAVE_UNIQUE
     if (app->instance)
     {
-        response = unique_app_send_message (app->instance, UNIQUE_NEW, NULL);
+        UniqueResponse response = unique_app_send_message (app->instance, UNIQUE_NEW, NULL);
         if (response == UNIQUE_RESPONSE_OK)
             return TRUE;
     }
@@ -1062,11 +1045,6 @@ gboolean
 midori_app_instance_send_uris (MidoriApp* app,
                                gchar**    uris)
 {
-    #if HAVE_UNIQUE
-    UniqueMessageData* message;
-    UniqueResponse response;
-    #endif
-
     g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
     g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
     g_return_val_if_fail (uris != NULL, FALSE);
@@ -1074,6 +1052,8 @@ midori_app_instance_send_uris (MidoriApp* app,
     #if HAVE_UNIQUE
     if (app->instance)
     {
+        UniqueMessageData* message;
+        UniqueResponse response;
         /* Encode any IDN addresses because libUnique doesn't like them */
         int i = 0;
         while (uris[i] != NULL)
@@ -1121,11 +1101,6 @@ gboolean
 midori_app_send_command (MidoriApp* app,
                          gchar**    command)
 {
-    #if HAVE_UNIQUE
-    UniqueMessageData* message;
-    UniqueResponse response;
-    #endif
-
     g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
     g_return_val_if_fail (command != NULL, FALSE);
 
@@ -1147,7 +1122,8 @@ midori_app_send_command (MidoriApp* app,
     #if HAVE_UNIQUE
     if (app->instance)
     {
-        message = unique_message_data_new ();
+        UniqueResponse response;
+        UniqueMessageData* message = unique_message_data_new ();
         unique_message_data_set_uris (message, command);
         response = unique_app_send_message (app->instance,
             MIDORI_UNIQUE_COMMAND, message);
@@ -1305,11 +1281,10 @@ midori_app_send_notification (MidoriApp*   app,
     #if HAVE_LIBNOTIFY
     if (notify_is_initted ())
     {
-        NotifyNotification* note;
         #if NOTIFY_CHECK_VERSION (0, 7, 0)
-        note = notify_notification_new (title, message, "midori");
+        NotifyNotification* note = notify_notification_new (title, message, "midori");
         #else
-        note = notify_notification_new (title, message, "midori", NULL);
+        NotifyNotification* note = notify_notification_new (title, message, "midori", NULL);
         #endif
         notify_notification_show (note, NULL);
         g_object_unref (note);
diff --git a/midori/midori-app.h b/midori/midori-app.h
index b63034d..7e5bdd5 100644
--- a/midori/midori-app.h
+++ b/midori/midori-app.h
@@ -39,7 +39,7 @@ GType
 midori_app_get_type               (void) G_GNUC_CONST;
 
 MidoriApp*
-midori_app_new                    (void);
+midori_app_new                    (const gchar*       name);
 
 const gchar*
 midori_app_get_name               (MidoriApp*         app);
diff --git a/midori/midori-frontend.c b/midori/midori-frontend.c
index 0ad7ea3..bbbf82c 100644
--- a/midori/midori-frontend.c
+++ b/midori/midori-frontend.c
@@ -371,7 +371,7 @@ midori_frontend_diagnostic_dialog (MidoriApp*         app,
 
 MidoriApp*
 midori_normal_app_new (const gchar* config,
-                       gboolean     portable,
+                       gchar*       nickname,
                        gboolean     diagnostic_dialog,
                        const gchar* webapp,
                        gchar**      open_uris,
@@ -379,12 +379,14 @@ midori_normal_app_new (const gchar* config,
                        gint         inactivity_reset,
                        const gchar* block_uris)
 {
-    if (portable)
+    if (g_str_has_suffix (nickname, "portable"))
         midori_paths_init (MIDORI_RUNTIME_MODE_PORTABLE, config);
-    else
+    else if (g_str_has_suffix (nickname, "normal"))
         midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
+    else
+        g_assert_not_reached ();
 
-    MidoriApp* app = midori_app_new ();
+    MidoriApp* app = midori_app_new (nickname);
     if (midori_app_instance_is_running (app))
     {
         gboolean result = FALSE;
diff --git a/midori/midori-frontend.h b/midori/midori-frontend.h
index a421caa..32a2233 100644
--- a/midori/midori-frontend.h
+++ b/midori/midori-frontend.h
@@ -32,7 +32,7 @@ midori_private_app_new (const gchar* config,
 
 MidoriApp*
 midori_normal_app_new (const gchar* config,
-                       gboolean     portable,
+                       gchar*       nickname,
                        gboolean     diagnostic_dialog,
                        const gchar* webapp,
                        gchar**      open_uris,
diff --git a/midori/midori.vapi b/midori/midori.vapi
index 275f0de..860391e 100644
--- a/midori/midori.vapi
+++ b/midori/midori.vapi
@@ -13,13 +13,13 @@ namespace Midori {
         string? webapp, [CCode (array_length = false)] string[]? uris, [CCode (array_length = false)] string[]? commands, int reset, string? block);
     public static void private_app_new (string? config,
         string? webapp, [CCode (array_length = false)] string[]? uris, [CCode (array_length = false)] string[]? commands, int reset, string? block);
-    public static App normal_app_new (string? config, bool portable, bool diagnostic,
+    public static App normal_app_new (string? config, string nickname, bool diagnostic,
         string? webapp, [CCode (array_length = false)] string[]? uris, [CCode (array_length = false)] string[]? commands, int reset, string? block);
     public static void normal_app_on_quit (App app);
 
     [CCode (cheader_filename = "midori/midori.h")]
     public class App : GLib.Object {
-        public App ();
+        public App (string? name=null);
         public static void setup ([CCode (array_length_pos = 0.9)] ref unowned string[] args, [CCode (array_length = false)] GLib.OptionEntry[]? entries);
         public Browser create_browser ();
         public GLib.List<weak Browser> get_browsers ();
diff --git a/tests/app.vala b/tests/app.vala
index 0ded6b0..c56d57d 100644
--- a/tests/app.vala
+++ b/tests/app.vala
@@ -15,7 +15,7 @@ void app_normal () {
     Midori.Test.idle_timeouts ();
     Midori.Test.log_set_fatal_handler_for_icons ();
     Midori.Paths.Test.reset_runtime_mode ();
-    var app = Midori.normal_app_new (null, false, false, null, null, null, -1, null);
+    var app = Midori.normal_app_new (null, "test-normal", false, null, null, null, -1, null);
     var loop = MainContext.default ();
     do { loop.iteration (true); } while (loop.pending ());
     for (var i = 0 ; i < 7; i++) {
@@ -24,10 +24,12 @@ void app_normal () {
         do { loop.iteration (true); } while (loop.pending ());
     }
     Midori.normal_app_on_quit (app);
+    /* FIXME
     for (var i = 0 ; i < 7; i++) {
         app.settings.maximum_cache_size++;
         do { loop.iteration (true); } while (loop.pending ());
     }
+    */
 
     Midori.Test.release_max_timeout ();
 }
@@ -35,7 +37,8 @@ void app_normal () {
 void app_custom_config () {
     Midori.Test.log_set_fatal_handler_for_icons ();
     Midori.Paths.Test.reset_runtime_mode ();
-    var app = Midori.normal_app_new ("/tmp/mylittlepony", false, false, null, null, null, -1, null);
+    var app = Midori.normal_app_new ("/tmp/mylittlepony",
+        "test-custom-config-normal", false, null, null, null, -1, null);
     var loop = MainContext.default ();
     do { loop.iteration (true); } while (loop.pending ());
     Midori.normal_app_on_quit (app);
@@ -61,7 +64,7 @@ void app_extensions () {
     Midori.Test.idle_timeouts ();
     Midori.Test.log_set_fatal_handler_for_icons ();
     Midori.Paths.Test.reset_runtime_mode ();
-    var app = Midori.normal_app_new (null, false, false, null, null, null, -1, null);
+    var app = Midori.normal_app_new (null, "test-extensions-normal", false, null, null, null, -1, null);
     var loop = MainContext.default ();
     do { loop.iteration (true); } while (loop.pending ());
     Midori.Extension.load_from_folder (app, null, true);
diff --git a/tests/browser.c b/tests/browser.c
index 0cd4c51..146b92c 100644
--- a/tests/browser.c
+++ b/tests/browser.c
@@ -28,7 +28,7 @@ browser_create (void)
 
     midori_test_log_set_fatal_handler_for_icons ();
 
-    app = midori_app_new ();
+    app = midori_app_new (NULL);
     settings = midori_web_settings_new ();
     g_object_set (app, "settings", settings, NULL);
     browser = midori_app_create_browser (app);
diff --git a/tests/extensions.c b/tests/extensions.c
index 5bf886f..642f48f 100644
--- a/tests/extensions.c
+++ b/tests/extensions.c
@@ -32,7 +32,7 @@ extension_create (void)
     MidoriApp* app;
     MidoriExtension* extension;
 
-    app = midori_app_new ();
+    app = midori_app_new (NULL);
     extension = g_object_new (MIDORI_TYPE_EXTENSION, NULL);
     g_assert (!midori_extension_is_prepared (extension));
     g_object_set (extension, "name", "TestExtension",
@@ -98,7 +98,7 @@ extension_settings (void)
     gchar** names;
     gsize names_n;
 
-    app = midori_app_new ();
+    app = midori_app_new (NULL);
     extension = extension_mock_object ();
     midori_extension_install_boolean (extension, "nihilist", TRUE);
     nihilist = midori_extension_get_boolean (extension, "nihilist");
@@ -166,7 +166,7 @@ extension_settings (void)
 static void
 extension_activate (gconstpointer data)
 {
-    MidoriApp* app = midori_app_new ();
+    MidoriApp* app = midori_app_new (NULL);
     g_object_set (app, "settings", midori_web_settings_new (), NULL);
     midori_extension_activate (G_OBJECT (data), NULL, TRUE, app);
     /* TODO: MidoriCompletion */


More information about the Xfce4-commits mailing list