[polari] Add a 'room-menu' action
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] Add a 'room-menu' action
- Date: Thu, 8 Aug 2013 13:06:16 +0000 (UTC)
commit 1e2d53baa7049349c2ab7318a3ea5e30f9ac7f1b
Author: Florian Müllner <florian muellner gmail com>
Date: Sun Jul 21 17:32:05 2013 +0200
Add a 'room-menu' action
... and use it to disable the menu when no accounts are set up /
enabled.
data/resources/main-window.ui | 1 +
src/application.js | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 844a6df..fa6b1b0 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -34,6 +34,7 @@
<property name="halign">center</property>
<property name="valign">center</property>
<property name="menu_model">join_menu</property>
+ <property name="action_name">app.room-menu</property>
<style>
<class name="image-button"/>
</style>
diff --git a/src/application.js b/src/application.js
index 410bfa1..358d7fc 100644
--- a/src/application.js
+++ b/src/application.js
@@ -1,6 +1,7 @@
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
+const Tp = imports.gi.TelepathyGLib;
const ChatroomManager = imports.chatroomManager;
const Config = imports.config;
@@ -35,14 +36,20 @@ const Application = new Lang.Class({
resource._register();
this._chatroomManager = ChatroomManager.getDefault();
+ this._accountManager = Tp.AccountManager.dup();
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/polari/app-menu.ui');
this.set_app_menu(builder.get_object('app-menu'));
let actionEntries = [
+ { name: 'room-menu',
+ activate: Lang.bind(this, this._onToggleAction),
+ create_hook: Lang.bind(this, this._accountActionsCreateHook),
+ state: GLib.Variant.new('b', false) },
{ name: 'join-room',
activate: Lang.bind(this, this._onJoinRoom),
+ create_hook: Lang.bind(this, this._accountActionsCreateHook),
accel: '<Primary>n' },
{ name: 'message-user',
activate: Lang.bind(this, this._onMessageUser) },
@@ -107,6 +114,36 @@ const Application = new Lang.Class({
this._window.window.present();
},
+ _updateAccountAction: function(action) {
+ action.enabled = this._accountManager.dup_valid_accounts().filter(
+ function(a) {
+ return a.enabled;
+ }).length > 0;
+ },
+
+ _accountActionsCreateHook: function(action) {
+ this._accountManager.connect('account-enabled', Lang.bind(this,
+ function() {
+ this._updateAccountAction(action);
+ }));
+ this._accountManager.connect('account-disabled', Lang.bind(this,
+ function() {
+ this._updateAccountAction(action);
+ }));
+ this._accountManager.connect('account-validity-changed', Lang.bind(this,
+ function() {
+ this._updateAccountAction(action);
+ }));
+ this._accountManager.connect('account-removed', Lang.bind(this,
+ function() {
+ this._updateAccountAction(action);
+ }));
+ this._accountManager.prepare_async(null, Lang.bind(this,
+ function() {
+ this._updateAccountAction(action);
+ }));
+ },
+
_updateRoomAction: function(action) {
action.enabled = this._chatroomManager.roomCount > 0;
if (action.state && !action.enabled)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]