Commit 263ff952 by Florian Müllner

app: Remove Connections dialog

After the latest changes, users can now create, modify and remove connections
without using the Connections dialog. Now the only functionality that is
exclusive to the dialog is the ability to disable connections temporarily,
which is only really useful during development - just move that to a dedicated
helper tool for that case and remove the dialog.
parent 8a28956b
......@@ -41,4 +41,5 @@ po/polari.pot
po/stamp-it
src/*.gresource
src/config.js
src/polari-accounts
src/org.gnome.Polari
......@@ -4,7 +4,6 @@
<file alias="gtk/menus.ui" preprocess="xml-stripblanks">resources/menus.ui</file>
<file alias="gtk/help-overlay.ui" preprocess="xml-stripblanks">resources/help-overlay.ui</file>
<file alias="connection-details.ui" preprocess="xml-stripblanks">resources/connection-details.ui</file>
<file alias="connection-list-dialog.ui" preprocess="xml-stripblanks">resources/connection-list-dialog.ui</file>
<file alias="entry-area.ui" preprocess="xml-stripblanks">resources/entry-area.ui</file>
<file alias="join-room-dialog.ui" preprocess="xml-stripblanks">resources/join-room-dialog.ui</file>
<file alias="main-window.ui" preprocess="xml-stripblanks">resources/main-window.ui</file>
......
......@@ -6,11 +6,6 @@ Icon=polari
Type=Application
StartupNotify=true
DBusActivatable=true
Actions=connections;
X-GNOME-UsesNotifications=true
Categories=GNOME;GTK;Network;IRCClient;
_Keywords=IRC;Internet;Relay;Chat;
[Desktop Action connections]
_Name=Show connections
Exec=gapplication action org.gnome.Polari connections
......@@ -2,18 +2,6 @@
<menu id="app-menu">
<section>
<item>
<attribute name="action">app.connections</attribute>
<attribute name="label" translatable="yes">Connections</attribute>
</item>
<!--
<item>
<attribute name="action">app.preferences</attribute>
<attribute name="label" translatable="yes">Preferences</attribute>
</item>
-->
</section>
<section>
<item>
<attribute name="action">win.show-help-overlay</attribute>
<attribute name="label" translatable="yes">Keyboard Shortcuts</attribute>
</item>
......
......@@ -2,7 +2,6 @@ data/appdata/org.gnome.Polari.appdata.xml.in
data/org.gnome.Polari.desktop.in
data/org.gnome.Polari.gschema.xml
[type: gettext/glade]data/resources/connection-details.ui
[type: gettext/glade]data/resources/connection-list-dialog.ui
[type: gettext/glade]data/resources/entry-area.ui
[type: gettext/glade]data/resources/help-overlay.ui
[type: gettext/glade]data/resources/join-room-dialog.ui
......
......@@ -27,6 +27,11 @@ nodist_app_SCRIPTS = $(APP_ID)
$(APP_ID): $(APP_ID).in $(top_srcdir)/configure.ac
$(AM_V_GEN) $(do_subst) $< > $@
nodist_noinst_SCRIPTS = polari-accounts
polari-accounts: polari-accounts.in
$(AM_V_GEN) $(do_subst) $< > $@ && chmod +x $@
resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/$(APP_ID).src.gresource.xml)
$(APP_ID).src.gresource: $(APP_ID).src.gresource.xml $(resource_files)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
......@@ -37,12 +42,14 @@ resource_DATA = $(APP_ID).src.gresource
EXTRA_DIST += \
$(APP_ID).in \
$(APP_ID).src.gresource.xml \
polari-accounts.in \
$(resource_files) \
$(NULL)
CLEANFILES += \
$(APP_ID) \
$(APP_ID).src.gresource \
polari-accounts \
$(NULL)
install-exec-hook:
......
......@@ -90,8 +90,6 @@ const Application = new Lang.Class({
{ name: 'edit-connection',
activate: Lang.bind(this, this._onEditConnection),
parameter_type: GLib.VariantType.new('o') },
{ name: 'connections',
activate: Lang.bind(this, this._onListConnections) },
{ name: 'preferences',
activate: Lang.bind(this, this._onShowPreferences) },
{ name: 'about',
......@@ -417,23 +415,6 @@ const Application = new Lang.Class({
action.change_state(GLib.Variant.new('b', !state.get_boolean()));
},
_onListConnections: function() {
if (this._connectionsDialog) {
this._connectionsDialog.widget.present();
return;
}
this.hold();
this._connectionsDialog = new Connections.ConnectionsDialog();
this._connectionsDialog.widget.show();
this._connectionsDialog.widget.connect('response',
Lang.bind(this, function(widget) {
widget.destroy();
this._connectionsDialog = null;
this.release();
}));
},
_onRemoveConnection: function(action, parameter){
let accountPath = parameter.deep_unpack();
let factory = Tp.AccountManager.dup().get_factory();
......
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Pango = imports.gi.Pango;
const Tp = imports.gi.TelepathyGLib;
const AccountsMonitor = imports.accountsMonitor;
const Lang = imports.lang;
const Signals = imports.signals;
const ConnectionsDialog = new Lang.Class({
Name: 'ConnectionsDialog',
_init: function() {
this._createWindow();
this._accountsMonitor = AccountsMonitor.getDefault();
this._accountAddedId =
this._accountsMonitor.connect('account-added', Lang.bind(this,
function(am, account) {
this._addAccount(account);
}));
this._accountRemovedId =
this._accountsMonitor.connect('account-removed', Lang.bind(this,
function(am, account) {
this._removeAccount(account);
}));
this._accountsMonitor.dupAccounts().forEach(Lang.bind(this, this._addAccount));
},
_createWindow: function() {
let app = Gio.Application.get_default();
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/Polari/connection-list-dialog.ui');
this.widget = builder.get_object('connection_list_dialog');
this.widget.transient_for = app.get_active_window();
this._listBox = builder.get_object('accounts_list');
this._listBox.connect('add', Lang.bind(this, this._syncVisibility));
this._listBox.connect('remove', Lang.bind(this, this._syncVisibility));
this._listBox.set_sort_func(function(row1, row2) {
return row1._account.display_name < row2._account.display_name ? -1 : 1;
});
let toolbar = builder.get_object('toolbar');
let context = toolbar.get_style_context();
context.set_junction_sides(Gtk.JunctionSides.TOP);
this._scrolledWindow = builder.get_object('scrolledwindow');
context = this._scrolledWindow.get_style_context();
context.set_junction_sides(Gtk.JunctionSides.BOTTOM);
this._emptyState = builder.get_object('empty_state');
let addButton = builder.get_object('add_button');
addButton.connect('clicked', Lang.bind(this, this._addConnection));
let remButton = builder.get_object('remove_button');
remButton.connect('clicked', Lang.bind(this, this._removeConnection));
remButton.sensitive = false;
let editButton = builder.get_object('edit_button');
editButton.connect('clicked', Lang.bind(this, this._editConnection));
editButton.sensitive = false;
this._listBox.connect('row-selected',
function(w, row) {
remButton.sensitive = row != null;
editButton.sensitive = row != null;
});
this.widget.connect('destroy', Lang.bind(this, this._onDestroy));
},
_addAccount: function(account) {
let row = new Gtk.ListBoxRow();
row._account = account;
let box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
spacing: 6, margin: 6 });
row.add(box);
let label = new Gtk.Label({ hexpand: true, halign: Gtk.Align.START,
ellipsize: Pango.EllipsizeMode.END });
box.add(label);
let sw = new Gtk.Switch();
box.add(sw);
this._listBox.add(row);
row.show_all();
account.bind_property('display-name', label, 'label',
GObject.BindingFlags.SYNC_CREATE);
account.bind_property('enabled', sw, 'state',
GObject.BindingFlags.SYNC_CREATE);
let id = account.connect('notify::display-name',
function() {
row.changed();
});
row.connect('destroy',
function() {
account.disconnect(id);
});
sw.connect('state-set',
function(w, state) {
account.set_enabled_async(state, Lang.bind(this,
function(a, res) {
a.set_enabled_finish(res);
}));
return true;
});
row.connect('key-press-event', Lang.bind(this,
function(w, ev) {
let [, keyval] = ev.get_keyval();
if (keyval == Gdk.KEY_space ||
keyval == Gdk.KEY_Return ||
keyval == Gdk.KEY_ISO_Enter ||
keyval == Gdk.KEY_KP_Enter)
sw.activate();
}));
},
_removeAccount: function(account) {
let rows = this._listBox.get_children();
for (let i = 0; i < rows.length; i++)
if (rows[i]._account == account) {
rows[i].destroy();
break;
}
},
_addConnection: function() {
this._showConnectionDetailsDialog(null);
},
_removeConnection: function() {
let row = this._listBox.get_selected_row();
row._account.remove_async(Lang.bind(this,
function(a, res) {
a.remove_finish(res); // TODO: Check for errors
}));
},
_editConnection: function() {
let account = this._listBox.get_selected_row()._account;
this._showConnectionDetailsDialog(account);
},
_showConnectionDetailsDialog: function(account) {
let dialog = new ConnectionDetailsDialog(account);
dialog.widget.transient_for = this.widget;
dialog.widget.show();
dialog.widget.connect('response',
function(w, response) {
dialog.widget.destroy();
});
},
_syncVisibility: function() {
let isEmpty = this._listBox.get_children() == 0;
this._emptyState.visible = isEmpty;
this._scrolledWindow.visible = !isEmpty;
},
_onDestroy: function() {
this._accountsMonitor.disconnect(this._accountAddedId);
this._accountsMonitor.disconnect(this._accountRemovedId);
}
});
const ConnectionDetails = new Lang.Class({
Name: 'ConnectionDetails',
Extends: Gtk.Box,
......
#!@GJS_CONSOLE@
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Pango = imports.gi.Pango;
const Tp = imports.gi.TelepathyGLib;
const Lang = imports.lang;
const AccountsWindow = new Lang.Class({
Name: 'AccountsWindow',
Extends: Gtk.ApplicationWindow,
_init: function(params) {
this.parent(params);
let scrolled = new Gtk.ScrolledWindow({ hscrollbar_policy: Gtk.PolicyType.NEVER,
shadow_type: Gtk.ShadowType.NONE });
this.add(scrolled);
this._list = new Gtk.ListBox();
this._list.set_sort_func(function(row1, row2) {
return row1.account.display_name.localeCompare(row2.account.display_name);
});
this._list.set_header_func(function(row, before) {
let header = row.get_header();
if (!before)
row.set_header(null);
else if (!header)
row.set_header(new Gtk.Separator({ orientation: Gtk.Orientation.HORIZONTAL }));
});
this._list.connect('row-activated', function(l, row) {
row.account.set_enabled_async(!row.account.enabled, null);
});
scrolled.add(this._list);
scrolled.show_all();
let am = Tp.AccountManager.dup();
am.prepare_async(null, Lang.bind(this, this._onPrepared));
},
_onPrepared: function(am) {
am.connect('account-validity-changed', Lang.bind(this,
function(am, account, valid) {
if (valid)
this._addAccount(account);
else
this._removeAccount(account);
}));
am.connect('account-removed', Lang.bind(this,
function(am, account) {
this._removeAccount(account);
}));
am.dup_valid_accounts().forEach(Lang.bind(this, this._addAccount));
},
_addAccount: function(account) {
if (account.protocol_name != 'irc')
return;
let row = new Gtk.ListBoxRow();
row.account = account;
let box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
spacing: 6, margin: 6 });
row.add(box);
let label = new Gtk.Label({ hexpand: true, halign: Gtk.Align.START,
ellipsize: Pango.EllipsizeMode.END });
box.add(label);
let sw = new Gtk.Switch();
box.add(sw);
this._list.add(row);
row.show_all();
account.bind_property('display-name', label, 'label',
GObject.BindingFlags.SYNC_CREATE);
account.bind_property('enabled', sw, 'state',
GObject.BindingFlags.SYNC_CREATE);
account.connect('notify::display-name', function() {
row.changed();
});
sw.connect('state-set', function(w, state) {
account.set_enabled_async(state, null);
return true;
});
},
_removeAccount: function(account) {
let rows = this._list.get_children();
for (let i = 0; i < rows.length; i++)
if (rows[i].account == account) {
rows[i].destroy();
break;
}
}
});
GLib.set_application_name("Polari Accounts");
let app = new Gtk.Application({ application_id: 'org.gnome.Polari.Accounts' });
app.connect('activate', function() {
let window = app.active_window;
if (!window)
window = new AccountsWindow({ application: app,
default_width: 400,
default_height: 300 });
window.present();
});
app.run(null);
......@@ -67,7 +67,6 @@ const ChatPlaceholder = new Lang.Class({
_init: function() {
this._accountsMonitor = AccountsMonitor.getDefault();
this._accountsMonitor.connect('accounts-changed', Lang.bind(this, this._checkAccounts));
let image = new Gtk.Image({ icon_name: 'polari-symbolic',
pixel_size: 96, halign: Gtk.Align.END,
......@@ -78,20 +77,10 @@ const ChatPlaceholder = new Lang.Class({
title.label = '<span letter_spacing="4500">%s</span>'.format(_("Polari"));
title.get_style_context().add_class('polari-background-title');
this._description = new Gtk.Label({ halign: Gtk.Align.CENTER, wrap: true,
margin_top: 24, use_markup: true });
this._description.get_style_context().add_class('polari-background-description');
this._instruction = new Gtk.Label({ halign: Gtk.Align.CENTER,
use_markup: true, wrap: true });
this._instruction.connect('activate-link', Lang.bind(this,
function(label, actionName) {
let app = Gio.Application.get_default();
let action = app.lookup_action(actionName);
if (action)
action.activate(null);
return action != null;
}));
let description = new Gtk.Label({ label: _("Join a room using the + button."),
halign: Gtk.Align.CENTER, wrap: true,
margin_top: 24, use_markup: true });
description.get_style_context().add_class('polari-background-description');
this.widget = new Gtk.Grid({ column_homogeneous: true, can_focus: false,
column_spacing: 18, hexpand: true, vexpand: true,
......@@ -99,32 +88,9 @@ const ChatPlaceholder = new Lang.Class({
this.widget.get_style_context().add_class('polari-background');
this.widget.attach(image, 0, 0, 1, 1);
this.widget.attach(title, 1, 0, 1, 1);
this.widget.attach(this._description, 0, 1, 2, 1);
this.widget.attach(this._instruction, 0, 2, 2, 1);
this.widget.attach(description, 0, 1, 2, 1);
this.widget.show_all();
this._checkAccounts();
},
_checkAccounts: function() {
let accounts = this._accountsMonitor.dupAccounts();
if (accounts.length == 0) {
this._description.label = _("Begin chatting by adding a new connection.");
/* translators: This will be used in the phrase: "Open Connections in the application menu" */
let href = '<a href="connections">%s</a>'.format(_("Connections"));
this._instruction.label = _("Open %s in the application menu.").format(href);
} else if (accounts.some(function(a) { return a.enabled; })) {
this._description.label = _("Join a room using the + button.");
this._instruction.label = '';
} else {
this._description.label = _("Your connections are disabled.");
/* translators: This will be used in the phrase: "Enable them by opening Connections in the application menu" */
let href = '<a href="connections">%s</a>'.format(_("Connections"));
this._instruction.label = _("Enable them by opening %s in the application menu.").format(href);
}
},
}
});
Signals.addSignalMethods(ChatPlaceholder.prototype);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment