[the-board] [ui] Implement DBus application proto directly
- From: Lucas Rocha <lucasr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [the-board] [ui] Implement DBus application proto directly
- Date: Mon, 22 Nov 2010 23:11:25 +0000 (UTC)
commit 8a857e005fce5180a903d2b67b417b7eaef56dc3
Author: Lucas Rocha <lucasr gnome org>
Date: Mon Nov 22 23:09:35 2010 +0000
[ui] Implement DBus application proto directly
We can't implement actions properly with GtkApplication in gjs yet
(needs to bind GVariant stuff first).
src/Makefile-js.am | 1 +
src/js/ui/application.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++
src/js/ui/main.js | 43 ++----------------
src/js/ui/mainWindow.js | 4 +-
4 files changed, 113 insertions(+), 41 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index c7e00a9..b0aa4ab 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -7,6 +7,7 @@ dist_jsmodel_DATA = \
jsuidir = $(pkgdatadir)/js/ui
dist_jsui_DATA = \
+ js/ui/application.js \
js/ui/background.js \
js/ui/main.js \
js/ui/mainWindow.js \
diff --git a/src/js/ui/application.js b/src/js/ui/application.js
new file mode 100644
index 0000000..aea033f
--- /dev/null
+++ b/src/js/ui/application.js
@@ -0,0 +1,106 @@
+// standard imports
+const DBus = imports.dbus;
+const Lang = imports.lang;
+
+// gi imports
+const Gtk = imports.gi.Gtk;
+const Mx = imports.gi.Mx;
+
+// ui imports
+const MainWindow = imports.ui.mainWindow;
+
+// util imports
+const Path = imports.util.path;
+
+const _THE_BOARD_DBUS_PATH = "/org/gnome/TheBoard";
+
+const TheBoardIface = {
+ name: "org.gnome.TheBoard",
+
+ methods: [ { name: "activate",
+ inSignature: '',
+ outSignature: '' } ],
+
+ signals: [],
+
+ properties: []
+};
+
+function RemoteApplication(args) {
+ this._init(args);
+}
+
+RemoteApplication.prototype = {
+ _init : function(args) {
+ DBus.session.proxifyObject(this,
+ TheBoardIface.name,
+ _THE_BOARD_DBUS_PATH);
+ }
+}
+
+DBus.proxifyPrototype(RemoteApplication.prototype,
+ TheBoardIface);
+
+function Application(args) {
+ this._init(args);
+}
+
+Application.prototype = {
+ _init : function(args) {
+ DBus.session.acquire_name(TheBoardIface.name,
+ DBus.SINGLE_INSTANCE,
+ Lang.bind(this, this._onNameAcquired),
+ Lang.bind(this, this._onNameNotAcquired));
+ },
+
+ _createMainWindow : function() {
+ this._mainWindow =
+ new MainWindow.MainWindow({ application: this });
+ },
+
+ _defineStyleAndThemes : function() {
+ let mxIcontheme = Mx.IconTheme.get_default();
+ mxIcontheme.set_search_paths([Path.ICONS_DIR]);
+
+ let gtkIcontheme = Gtk.IconTheme.get_default();
+ gtkIcontheme.append_search_path(Path.ICONS_DIR);
+
+ let style = Mx.Style.get_default();
+ style.load_from_file(Path.STYLE_DIR + "style.css");
+ },
+
+ _onNameAcquired : function() {
+ log('Application: acquired ' + TheBoardIface.name);
+
+ DBus.session.exportObject(_THE_BOARD_DBUS_PATH, this);
+
+ this._defineStyleAndThemes();
+ this._createMainWindow();
+
+ this._mainWindow.showAll();
+ },
+
+ _onNameNotAcquired : function() {
+ log('Application: could not acquire ' +
+ TheBoardIface.name +
+ ". Activating existing instance.");
+
+ let remoteApp = new RemoteApplication();
+ remoteApp.activateRemote();
+
+ this.quit();
+ },
+
+ // DBus method
+ activate : function(args) {
+ log('Application: activated via DBus');
+
+ this._mainWindow.present();
+ },
+
+ quit : function() {
+ Gtk.main_quit();
+ }
+}
+
+DBus.conformExport(Application.prototype, TheBoardIface);
diff --git a/src/js/ui/main.js b/src/js/ui/main.js
index cb3e453..3cfb185 100644
--- a/src/js/ui/main.js
+++ b/src/js/ui/main.js
@@ -2,54 +2,21 @@
const Gettext = imports.gettext;
// gi imports
-const GIO = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
-const Mx = imports.gi.Mx;
// ui imports
-const MainWindow = imports.ui.mainWindow;
+const Application = imports.ui.application;
// util imports
const Path = imports.util.path;
-let _mainWindow = null;
+function run() {
+ Gettext.bindtextdomain("the-board", Path.LOCALE_DIR);
-function onActivate(application) {
GLib.set_application_name("The Board");
- let mxIcontheme = Mx.IconTheme.get_default();
- mxIcontheme.set_search_paths([Path.ICONS_DIR]);
-
- let gtkIcontheme = Gtk.IconTheme.get_default();
- gtkIcontheme.append_search_path(Path.ICONS_DIR);
-
- let style = Mx.Style.get_default();
- style.load_from_file(Path.STYLE_DIR + "style.css");
-
- if (!_mainWindow) {
- _mainWindow =
- new MainWindow.MainWindow({ application: application });
-
- _mainWindow.showAll();
- } else {
- _mainWindow.present();
- }
-}
-
-function createApplication() {
- let application =
- Gtk.Application.new("org.gnome.TheBoard",
- GIO.ApplicationFlags.FLAGS_NONE);
-
- application.connect("activate", onActivate);
-
- return application;
-}
-
-function run() {
- Gettext.bindtextdomain("the-board", Path.LOCALE_DIR);
+ let application = new Application.Application();
- let application = createApplication();
- application.run(0, "");
+ Gtk.main();
}
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 0f196b6..5f63a88 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -87,8 +87,6 @@ MainWindow.prototype = {
skipTaskbarHint: false,
skipPagerHint: false });
- this._application.add_window(this._gtkWindow);
-
this._updateWindowSize();
let screen = Gdk.Screen.get_default();
@@ -599,7 +597,7 @@ MainWindow.prototype = {
},
_quitApp : function() {
- this._application.remove_window(this._gtkWindow);
+ this._application.quit();
},
_pasteClipboardContent : function() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]