[gnome-documents] application: Use Gtk.Application rather than custom DBus code



commit 8d9a1d1194887b6d6017c60b464ec5802145a19a
Author: Florian MÃllner <fmuellner gnome org>
Date:   Fri Nov 18 02:25:07 2011 +0100

    application: Use Gtk.Application rather than custom DBus code
    
    https://bugzilla.gnome.org/show_bug.cgi?id=665157

 src/application.js |   66 +++++++++++-----------------------------------------
 src/main.js        |    3 +-
 src/mainWindow.js  |    4 +-
 3 files changed, 17 insertions(+), 56 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 0cc7268..37ad66f 100644
--- a/src/application.js
+++ b/src/application.js
@@ -19,7 +19,6 @@
  *
  */
 
-const DBus = imports.dbus;
 const Lang = imports.lang;
 const Gettext = imports.gettext;
 
@@ -50,29 +49,6 @@ const TrackerController = imports.trackerController;
 const Tweener = imports.util.tweener;
 const WindowMode = imports.windowMode;
 
-const _GD_DBUS_PATH = '/org/gnome/Documents';
-
-const GdIface = {
-    name: 'org.gnome.Documents',
-
-    methods: [ { name: 'activate',
-                 inSignature: '',
-                 outSignature: '' } ]
-};
-
-function RemoteApplication() {
-    this._init();
-}
-
-RemoteApplication.prototype = {
-    _init: function() {
-        DBus.session.proxifyObject(this,
-                                   GdIface.name,
-                                   _GD_DBUS_PATH);
-    }
-}
-
-DBus.proxifyPrototype(RemoteApplication.prototype, GdIface);
 
 function Application() {
     this._init();
@@ -80,25 +56,19 @@ function Application() {
 
 Application.prototype = {
     _init: function() {
-        DBus.session.acquire_name(GdIface.name,
-                                  DBus.SINGLE_INSTANCE,
-                                  Lang.bind(this, this._onNameAcquired),
-                                  Lang.bind(this, this._onNameNotAcquired));
-    },
-
-    _onNameAcquired: function() {
-        DBus.session.exportObject(_GD_DBUS_PATH, this);
-        this._initReal();
-    },
-
-    _onNameNotAcquired: function() {
-        let remoteApp = new RemoteApplication();
-        remoteApp.activateRemote();
-
-        this.quit();
+        // TODO: subclass Gtk.Application once we support GObject inheritance,
+        //       see https://bugzilla.gnome.org/show_bug.cgi?id=663492
+        this.application = new Gtk.Application({
+            application_id: 'org.gnome.Documents'
+        });
+        this.application.connect('startup', Lang.bind(this, this._onStartup));
+        this.application.connect('activate', Lang.bind(this,
+            function() {
+                this._mainWindow.window.present();
+            }));
     },
 
-    _initReal: function() {
+    _onStartup: function() {
         Gettext.bindtextdomain('gnome-documents', Path.LOCALE_DIR);
         Gettext.textdomain('gnome-documents');
         String.prototype.format = Format.format;
@@ -119,14 +89,14 @@ Application.prototype = {
             Global.connection = Tracker.SparqlConnection.get(null);
         } catch (e) {
             log('Unable to connect to the tracker database: ' + e.toString());
-            this.quit();
+            return;
         }
 
         try {
             Global.goaClient = Goa.Client.new_sync(null);
         } catch (e) {
             log('Unable to create the GOA client: ' + e.toString());
-            this.quit();
+            return;
         }
 
         Global.connectionQueue = new TrackerController.TrackerConnectionQueue();
@@ -143,14 +113,6 @@ Application.prototype = {
         Global.modeController = new WindowMode.ModeController();
 
         this._mainWindow = new MainWindow.MainWindow();
-        this.activate();
-    },
-
-    activate: function() {
-        this._mainWindow.window.present();
-    },
-
-    quit: function() {
-        Gtk.main_quit();
+        this.application.add_window(this._mainWindow.window);
     }
 };
diff --git a/src/main.js b/src/main.js
index c03d1ef..de17463 100644
--- a/src/main.js
+++ b/src/main.js
@@ -19,10 +19,9 @@
  *
  */
 
-const Gtk = imports.gi.Gtk;
 const Application = imports.application;
 
 function start() {
     let application = new Application.Application();
-    Gtk.main();
+    application.application.run(null);
 }
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 29d5dc4..762f8a5 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -211,7 +211,7 @@ MainWindow.prototype = {
 
         if ((keyval == Gdk.KEY_q) &&
             ((state & Gdk.ModifierType.CONTROL_MASK) != 0)) {
-            this._quit();
+            this.window.destroy();
             return true;
         }
 
@@ -272,6 +272,6 @@ MainWindow.prototype = {
         // always save geometry before quitting
         this._saveWindowGeometry();
 
-        Global.application.quit();
+        return false;
     }
 };



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]