Set jid handle in ContactDetails, use LabelHybrids more, remove edit from StartConversation

This commit is contained in:
fiaxh 2017-06-16 14:29:02 +02:00
parent 7bbbb738fd
commit 26973c89e3
21 changed files with 197 additions and 273 deletions

View file

@ -26,7 +26,7 @@ public class Conversation : Object {
} }
public Encryption encryption { get; set; default = Encryption.NONE; } public Encryption encryption { get; set; default = Encryption.NONE; }
public Type type_ { get; set; } public Type type_ { get; set; }
public Message read_up_to { get; set; } public Message? read_up_to { get; set; }
public enum NotifySetting { DEFAULT, ON, OFF, HIGHLIGHT } public enum NotifySetting { DEFAULT, ON, OFF, HIGHLIGHT }
public NotifySetting notify_setting { get; set; default = NotifySetting.DEFAULT; } public NotifySetting notify_setting { get; set; default = NotifySetting.DEFAULT; }
@ -157,4 +157,4 @@ public class Conversation : Object {
} }
} }
} }

View file

@ -122,12 +122,12 @@ public class Database : Qlite.Database {
public class RosterTable : Table { public class RosterTable : Table {
public Column<int> account_id = new Column.Integer("account_id"); public Column<int> account_id = new Column.Integer("account_id");
public Column<string> jid = new Column.Text("jid"); public Column<string> jid = new Column.Text("jid");
public Column<string> name = new Column.Text("name"); public Column<string> handle = new Column.Text("name");
public Column<string> subscription = new Column.Text("subscription"); public Column<string> subscription = new Column.Text("subscription");
internal RosterTable(Database db) { internal RosterTable(Database db) {
base(db, "roster"); base(db, "roster");
init({account_id, jid, name, subscription}); init({account_id, jid, handle, subscription});
unique({account_id, jid}, "IGNORE"); unique({account_id, jid}, "IGNORE");
} }
} }
@ -333,4 +333,4 @@ public class Database : Qlite.Database {
} }
} }
} }

View file

@ -134,6 +134,11 @@ public class MucManager : StreamInteractionModule, Object {
} }
} }
public string? get_room_name(Account account, Jid jid) {
Core.XmppStream? stream = stream_interactor.get_stream(account);
return stream != null ? stream.get_flag(Xep.Muc.Flag.IDENTITY).get_room_name(jid.to_string()) : null;
}
public string? get_groupchat_subject(Jid jid, Account account) { public string? get_groupchat_subject(Jid jid, Account account) {
Core.XmppStream? stream = stream_interactor.get_stream(account); Core.XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) { if (stream != null) {

View file

@ -49,6 +49,11 @@ public class RosterManager : StreamInteractionModule, Object {
if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).add_jid(stream, jid.bare_jid.to_string(), handle); if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).add_jid(stream, jid.bare_jid.to_string(), handle);
} }
public void set_jid_handle(Account account, Jid jid, string? handle) {
Core.XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).set_jid_handle(stream, jid.bare_jid.to_string(), handle);
}
private void on_account_added(Account account) { private void on_account_added(Account account) {
stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).received_roster.connect( (stream, roster) => { stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).received_roster.connect( (stream, roster) => {
foreach (Roster.Item roster_item in roster) { foreach (Roster.Item roster_item in roster) {
@ -81,7 +86,7 @@ public class RosterStoreImpl : Roster.Storage, Object {
foreach (Qlite.Row row in db.roster.select().with(db.roster.account_id, "=", account.id)) { foreach (Qlite.Row row in db.roster.select().with(db.roster.account_id, "=", account.id)) {
Roster.Item item = new Roster.Item(); Roster.Item item = new Roster.Item();
item.jid = row[db.roster.jid]; item.jid = row[db.roster.jid];
item.name = row[db.roster.name]; item.name = row[db.roster.handle];
item.subscription = row[db.roster.subscription]; item.subscription = row[db.roster.subscription];
items[item.jid] = item; items[item.jid] = item;
} }
@ -115,7 +120,7 @@ public class RosterStoreImpl : Roster.Storage, Object {
db.roster.insert().or("REPLACE") db.roster.insert().or("REPLACE")
.value(db.roster.account_id, account.id) .value(db.roster.account_id, account.id)
.value(db.roster.jid, item.jid) .value(db.roster.jid, item.jid)
.value(db.roster.name, item.name) .value(db.roster.handle, item.name)
.value(db.roster.subscription, item.subscription) .value(db.roster.subscription, item.subscription)
.perform(); .perform();
} }
@ -128,4 +133,4 @@ public class RosterStoreImpl : Roster.Storage, Object {
} }
} }
} }

View file

@ -150,4 +150,4 @@ install(FILES
data/icons/dino-tick-symbolic.svg data/icons/dino-tick-symbolic.svg
DESTINATION DESTINATION
${ICON_INSTALL_DIR}/hicolor/scalable/status ${ICON_INSTALL_DIR}/hicolor/scalable/status
) )

View file

@ -68,19 +68,6 @@
</child> </child>
</object> </object>
</child> </child>
<child>
<object class="GtkButton" id="edit_button">
<property name="sensitive">False</property>
<property name="visible">True</property>
<child>
<object class="GtkImage">
<property name="icon-name">document-edit-symbolic</property>
<property name="icon-size">1</property>
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child> <child>
<object class="GtkButton" id="remove_button"> <object class="GtkButton" id="remove_button">
<property name="sensitive">False</property> <property name="sensitive">False</property>
@ -105,4 +92,4 @@
</object> </object>
</child> </child>
</template> </template>
</interface> </interface>

View file

@ -30,7 +30,7 @@
<property name="margin-bottom">12</property> <property name="margin-bottom">12</property>
<property name="margin-right">100</property> <property name="margin-right">100</property>
<property name="margin-left">100</property> <property name="margin-left">100</property>
<property name="column-spacing">15</property> <property name="column-spacing">10</property>
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GtkImage" id="avatar"> <object class="GtkImage" id="avatar">
@ -45,6 +45,19 @@
<property name="height">2</property> <property name="height">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="DinoUiUtilEntryLabelHybrid" id="name_hybrid">
<property name="xalign">0</property>
<property name="expand">True</property>
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child> <child>
<object class="GtkLabel" id="name_label"> <object class="GtkLabel" id="name_label">
<property name="xalign">0</property> <property name="xalign">0</property>

View file

@ -64,13 +64,13 @@
<property name="toolbar-style">icons</property> <property name="toolbar-style">icons</property>
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GtkToolButton" id="add_button"> <object class="GtkToolButton" id="add_account_button">
<property name="icon-name">list-add-symbolic</property> <property name="icon-name">list-add-symbolic</property>
<property name="visible">True</property> <property name="visible">True</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkToolButton" id="remove_button"> <object class="GtkToolButton" id="remove_account_button">
<property name="icon-name">list-remove-symbolic</property> <property name="icon-name">list-remove-symbolic</property>
<property name="visible">True</property> <property name="visible">True</property>
</object> </object>
@ -178,35 +178,11 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkStack" id="password_stack"> <object class="DinoUiUtilEntryLabelHybrid" id="password_hybrid">
<property name="xalign">0</property>
<property name="width_request">200</property>
<property name="visibility">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<child>
<object class="GtkButton" id="password_button">
<property name="relief">none</property>
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="password_label">
<property name="xalign">0</property>
<property name="visible">True</property>
</object>
</child>
</object>
<packing>
<property name="name">label</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="password_entry">
<property name="hexpand">True</property>
<property name="input_purpose">password</property>
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="visibility">False</property>
</object>
<packing>
<property name="name">entry</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
@ -232,33 +208,10 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkStack" id="alias_stack"> <object class="DinoUiUtilEntryLabelHybrid" id="alias_hybrid">
<property name="xalign">0</property>
<property name="width_request">200</property>
<property name="visible">True</property> <property name="visible">True</property>
<child>
<object class="GtkButton" id="alias_button">
<property name="relief">none</property>
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="alias_label">
<property name="xalign">0</property>
<property name="visible">True</property>
</object>
</child>
</object>
<packing>
<property name="name">label</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="alias_entry">
<property name="hexpand">True</property>
<property name="width_request">200</property>
<property name="visible">True</property>
</object>
<packing>
<property name="name">entry</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>

View file

@ -48,4 +48,4 @@ void main(string[] args) {
} }
} }
} }

View file

@ -59,9 +59,6 @@ public class Dialog : Gtk.Dialog {
AddContactDialog add_contact_dialog = new AddContactDialog(stream_interactor); AddContactDialog add_contact_dialog = new AddContactDialog(stream_interactor);
add_contact_dialog.set_transient_for(this); add_contact_dialog.set_transient_for(this);
add_contact_dialog.present(); add_contact_dialog.present();
});
select_jid_fragment.edit_jid.connect(() => {
}); });
select_jid_fragment.remove_jid.connect((row) => { select_jid_fragment.remove_jid.connect((row) => {
ListRow list_row = roster_list.get_selected_row() as ListRow; ListRow list_row = roster_list.get_selected_row() as ListRow;
@ -74,4 +71,4 @@ public class Dialog : Gtk.Dialog {
} }
} }
} }

View file

@ -94,12 +94,6 @@ public class Dialog : Gtk.Dialog {
dialog.set_transient_for(this); dialog.set_transient_for(this);
dialog.present(); dialog.present();
}); });
select_fragment.edit_jid.connect((row) => {
ConferenceListRow conference_row = row as ConferenceListRow;
AddGroupchatDialog dialog = new AddGroupchatDialog.for_conference(stream_interactor, conference_row.account, conference_row.bookmark);
dialog.set_transient_for(this);
dialog.present();
});
select_fragment.remove_jid.connect((row) => { select_fragment.remove_jid.connect((row) => {
ConferenceListRow conference_row = row as ConferenceListRow; ConferenceListRow conference_row = row as ConferenceListRow;
stream_interactor.get_module(MucManager.IDENTITY).remove_bookmark(conference_row.account, conference_row.bookmark); stream_interactor.get_module(MucManager.IDENTITY).remove_bookmark(conference_row.account, conference_row.bookmark);
@ -165,4 +159,4 @@ public class Dialog : Gtk.Dialog {
} }
} }
} }

View file

@ -9,7 +9,6 @@ namespace Dino.Ui.AddConversation {
public class SelectJidFragment : Gtk.Box { public class SelectJidFragment : Gtk.Box {
public signal void add_jid(); public signal void add_jid();
public signal void edit_jid(ListRow row);
public signal void remove_jid(ListRow row); public signal void remove_jid(ListRow row);
public bool done { public bool done {
get { get {
@ -20,7 +19,6 @@ public class SelectJidFragment : Gtk.Box {
[GtkChild] private Entry entry; [GtkChild] private Entry entry;
[GtkChild] private Box box; [GtkChild] private Box box;
[GtkChild] private Button add_button; [GtkChild] private Button add_button;
[GtkChild] private Button edit_button;
[GtkChild] private Button remove_button; [GtkChild] private Button remove_button;
private StreamInteractor stream_interactor; private StreamInteractor stream_interactor;
@ -45,7 +43,6 @@ public class SelectJidFragment : Gtk.Box {
entry.changed.connect(on_entry_changed); entry.changed.connect(on_entry_changed);
add_button.clicked.connect(() => { add_jid(); }); add_button.clicked.connect(() => { add_jid(); });
remove_button.clicked.connect(() => { remove_jid(filterable_list.get_selected_row() as ListRow); }); remove_button.clicked.connect(() => { remove_jid(filterable_list.get_selected_row() as ListRow); });
edit_button.clicked.connect(() => { edit_jid(filterable_list.get_selected_row() as ListRow); });
} }
private void on_entry_changed() { private void on_entry_changed() {
@ -71,7 +68,6 @@ public class SelectJidFragment : Gtk.Box {
private void check_buttons_active() { private void check_buttons_active() {
ListBoxRow? row = filterable_list.get_selected_row(); ListBoxRow? row = filterable_list.get_selected_row();
bool active = row != null && !row.get_type().is_a(typeof(AddListRow)); bool active = row != null && !row.get_type().is_a(typeof(AddListRow));
edit_button.sensitive = active;
remove_button.sensitive = active; remove_button.sensitive = active;
} }
@ -115,4 +111,4 @@ public abstract class FilterableList : Gtk.ListBox {
public abstract int sort(ListBoxRow row1, ListBoxRow row2); public abstract int sort(ListBoxRow row1, ListBoxRow row2);
} }
} }

View file

@ -1,6 +1,7 @@
using Gee; using Gee;
using Gtk; using Gtk;
using Markup; using Markup;
using Pango;
using Dino.Entities; using Dino.Entities;
@ -10,6 +11,7 @@ namespace Dino.Ui.ContactDetails {
public class Dialog : Gtk.Dialog { public class Dialog : Gtk.Dialog {
[GtkChild] public Image avatar; [GtkChild] public Image avatar;
[GtkChild] public Util.EntryLabelHybrid name_hybrid;
[GtkChild] public Label name_label; [GtkChild] public Label name_label;
[GtkChild] public Label jid_label; [GtkChild] public Label jid_label;
[GtkChild] public Label account_label; [GtkChild] public Label account_label;
@ -22,6 +24,11 @@ public class Dialog : Gtk.Dialog {
private HashMap<string, ListBox> categories = new HashMap<string, ListBox>(); private HashMap<string, ListBox> categories = new HashMap<string, ListBox>();
private Util.LabelHybridGroup hybrid_group = new Util.LabelHybridGroup(); private Util.LabelHybridGroup hybrid_group = new Util.LabelHybridGroup();
construct {
name_hybrid.label.attributes = new AttrList();
name_hybrid.label.attributes.insert(attr_weight_new(Weight.BOLD));
}
public Dialog(StreamInteractor stream_interactor, Conversation conversation) { public Dialog(StreamInteractor stream_interactor, Conversation conversation) {
Object(use_header_bar : 1); Object(use_header_bar : 1);
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
@ -29,11 +36,7 @@ public class Dialog : Gtk.Dialog {
title = conversation.type_ == Conversation.Type.GROUPCHAT ? _("Conference Details") : _("Contact Details"); title = conversation.type_ == Conversation.Type.GROUPCHAT ? _("Conference Details") : _("Contact Details");
(get_header_bar() as HeaderBar).set_subtitle(Util.get_conversation_display_name(stream_interactor, conversation)); (get_header_bar() as HeaderBar).set_subtitle(Util.get_conversation_display_name(stream_interactor, conversation));
setup_top();
name_label.label = Util.get_conversation_display_name(stream_interactor, conversation);
jid_label.label = conversation.counterpart.to_string();
account_label.label = "via " + conversation.account.bare_jid.to_string();
Util.image_set_from_scaled_pixbuf(avatar, (new AvatarGenerator(50, 50, avatar.scale_factor)).draw_conversation(stream_interactor, conversation));
contact_details.add.connect(add_entry); contact_details.add.connect(add_entry);
@ -50,7 +53,26 @@ public class Dialog : Gtk.Dialog {
}); });
} }
public void add_entry(string category, string label, string? description, Widget w) { private void setup_top() {
if (conversation.type_ == Conversation.Type.CHAT) {
name_label.visible = false;
jid_label.set_padding(new Button().get_style_context().get_padding(StateFlags.NORMAL).left + 1, 0);
name_hybrid.text = Util.get_conversation_display_name(stream_interactor, conversation);
destroy.connect(() => {
if (name_hybrid.text != Util.get_conversation_display_name(stream_interactor, conversation)) {
stream_interactor.get_module(RosterManager.IDENTITY).set_jid_handle(conversation.account, conversation.counterpart, name_hybrid.text);
}
});
} else {
name_hybrid.visible = false;
name_label.label = Util.get_conversation_display_name(stream_interactor, conversation);
}
jid_label.label = conversation.counterpart.to_string();
account_label.label = "via " + conversation.account.bare_jid.to_string();
Util.image_set_from_scaled_pixbuf(avatar, (new AvatarGenerator(50, 50, avatar.scale_factor)).draw_conversation(stream_interactor, conversation));
}
private void add_entry(string category, string label, string? description, Widget w) {
add_category(category); add_category(category);
ListBoxRow list_row = new ListBoxRow() { activatable=false, visible=true }; ListBoxRow list_row = new ListBoxRow() { activatable=false, visible=true };
@ -71,11 +93,11 @@ public class Dialog : Gtk.Dialog {
Widget widget = w; Widget widget = w;
if (widget.get_type().is_a(typeof(Entry))) { if (widget.get_type().is_a(typeof(Entry))) {
Util.EntryLabelHybrid hybrid = new Util.EntryLabelHybrid(widget as Entry) { xalign=1, visible=true }; Util.EntryLabelHybrid hybrid = new Util.EntryLabelHybrid.wrap(widget as Entry) { xalign=1, visible=true };
hybrid_group.add(hybrid); hybrid_group.add(hybrid);
widget = hybrid; widget = hybrid;
} else if (widget.get_type().is_a(typeof(ComboBoxText))) { } else if (widget.get_type().is_a(typeof(ComboBoxText))) {
Util.ComboBoxTextLabelHybrid hybrid = new Util.ComboBoxTextLabelHybrid(widget as ComboBoxText) { xalign=1, visible=true }; Util.ComboBoxTextLabelHybrid hybrid = new Util.ComboBoxTextLabelHybrid.wrap(widget as ComboBoxText) { xalign=1, visible=true };
hybrid_group.add(hybrid); hybrid_group.add(hybrid);
widget = hybrid; widget = hybrid;
} }
@ -95,7 +117,7 @@ public class Dialog : Gtk.Dialog {
}); });
} }
public void add_category(string category) { private void add_category(string category) {
if (!categories.has_key(category)) { if (!categories.has_key(category)) {
ListBox list_box = new ListBox() { selection_mode=SelectionMode.NONE, visible=true }; ListBox list_box = new ListBox() { selection_mode=SelectionMode.NONE, visible=true };
categories[category] = list_box; categories[category] = list_box;

View file

@ -16,24 +16,15 @@ public class Dialog : Gtk.Dialog {
[GtkChild] public Stack main_stack; [GtkChild] public Stack main_stack;
[GtkChild] public ListBox account_list; [GtkChild] public ListBox account_list;
[GtkChild] public Button no_accounts_add; [GtkChild] public Button no_accounts_add;
[GtkChild] public ToolButton add_button; [GtkChild] public ToolButton add_account_button;
[GtkChild] public ToolButton remove_button; [GtkChild] public ToolButton remove_account_button;
[GtkChild] public Image image; [GtkChild] public Image image;
[GtkChild] public Button image_button; [GtkChild] public Button image_button;
[GtkChild] public Label jid_label; [GtkChild] public Label jid_label;
[GtkChild] public Label state_label; [GtkChild] public Label state_label;
[GtkChild] public Switch active_switch; [GtkChild] public Switch active_switch;
[GtkChild] public Util.EntryLabelHybrid password_hybrid;
[GtkChild] public Stack password_stack; [GtkChild] public Util.EntryLabelHybrid alias_hybrid;
[GtkChild] public Label password_label;
[GtkChild] public Button password_button;
[GtkChild] public Entry password_entry;
[GtkChild] public Stack alias_stack;
[GtkChild] public Label alias_label;
[GtkChild] public Button alias_button;
[GtkChild] public Entry alias_entry;
[GtkChild] public Grid settings_list; [GtkChild] public Grid settings_list;
private ArrayList<Plugins.AccountSettingsWidget> plugin_widgets = new ArrayList<Plugins.AccountSettingsWidget>(); private ArrayList<Plugins.AccountSettingsWidget> plugin_widgets = new ArrayList<Plugins.AccountSettingsWidget>();
@ -45,12 +36,19 @@ public class Dialog : Gtk.Dialog {
construct { construct {
Util.force_error_color(state_label, ".is_error"); Util.force_error_color(state_label, ".is_error");
account_list.row_selected.connect(on_account_list_row_selected); account_list.row_selected.connect(on_account_list_row_selected);
add_button.clicked.connect(on_add_button_clicked); add_account_button.clicked.connect(show_add_account_dialog);
no_accounts_add.clicked.connect(on_add_button_clicked); no_accounts_add.clicked.connect(show_add_account_dialog);
remove_button.clicked.connect(on_remove_button_clicked); remove_account_button.clicked.connect(() => {
password_entry.key_release_event.connect(on_password_key_release_event); AccountRow? account_row = account_list.get_selected_row() as AccountRow;
alias_entry.key_release_event.connect(on_alias_key_release_event); if (selected_account != null) remove_account(account_row);
image_button.clicked.connect(on_image_button_clicked); });
image_button.clicked.connect(show_select_avatar);
alias_hybrid.entry.key_release_event.connect(() => { selected_account.alias = alias_hybrid.text; return false; });
password_hybrid.entry.key_release_event.connect(() => { selected_account.password = password_hybrid.text; return false; });
Util.LabelHybridGroup label_hybrid_group = new Util.LabelHybridGroup();
label_hybrid_group.add(alias_hybrid);
label_hybrid_group.add(password_hybrid);
main_stack.set_visible_child_name("no_accounts"); main_stack.set_visible_child_name("no_accounts");
@ -61,13 +59,11 @@ public class Dialog : Gtk.Dialog {
Plugins.AccountSettingsWidget widget = e.get_widget(); Plugins.AccountSettingsWidget widget = e.get_widget();
plugin_widgets.add(widget); plugin_widgets.add(widget);
widget.visible = true; widget.visible = true;
widget.activated.connect(child_activated);
Label label = new Label(e.name); Label label = new Label(e.name) { xalign=1, yalign=0, visible=true };
label.get_style_context().add_class("dim-label"); label.get_style_context().add_class("dim-label");
label.set_padding(0, e.label_top_padding == -1 ? default_top_padding : e.label_top_padding); label.set_padding(0, e.label_top_padding == -1 ? default_top_padding : e.label_top_padding);
label.yalign = 0;
label.xalign = 1;
label.visible = true;
settings_list.attach(label, 0, row_index); settings_list.attach(label, 0, row_index);
settings_list.attach(widget, 1, row_index, 2); settings_list.attach(widget, 1, row_index, 2);
row_index++; row_index++;
@ -111,7 +107,7 @@ public class Dialog : Gtk.Dialog {
return account_item; return account_item;
} }
private void on_add_button_clicked() { private void show_add_account_dialog() {
AddAccountDialog add_account_dialog = new AddAccountDialog(stream_interactor); AddAccountDialog add_account_dialog = new AddAccountDialog(stream_interactor);
add_account_dialog.set_transient_for(this); add_account_dialog.set_transient_for(this);
add_account_dialog.added.connect((account) => { add_account_dialog.added.connect((account) => {
@ -123,18 +119,15 @@ public class Dialog : Gtk.Dialog {
add_account_dialog.present(); add_account_dialog.present();
} }
private void on_remove_button_clicked() { private void remove_account(AccountRow account_item) {
AccountRow account_item = account_list.get_selected_row() as AccountRow; account_list.remove(account_item);
if (account_item != null) { account_list.queue_draw();
account_list.remove(account_item); if (account_item.account.enabled) account_disabled(account_item.account);
account_list.queue_draw(); account_item.account.remove();
if (account_item.account.enabled) account_disabled(account_item.account); if (account_list.get_row_at_index(0) != null) {
account_item.account.remove(); account_list.select_row(account_list.get_row_at_index(0));
if (account_list.get_row_at_index(0) != null) { } else {
account_list.select_row(account_list.get_row_at_index(0)); main_stack.set_visible_child_name("no_accounts");
} else {
main_stack.set_visible_child_name("no_accounts");
}
} }
} }
@ -146,59 +139,34 @@ public class Dialog : Gtk.Dialog {
} }
} }
private void on_image_button_clicked() { private void show_select_avatar() {
FileChooserDialog chooser = new FileChooserDialog ( FileChooserDialog chooser = new FileChooserDialog (
_("Select avatar"), this, FileChooserAction.OPEN, _("Select avatar"), this, FileChooserAction.OPEN,
_("Cancel"), ResponseType.CANCEL, _("Cancel"), ResponseType.CANCEL,
_("Select"), ResponseType.ACCEPT); _("Select"), ResponseType.ACCEPT);
FileFilter filter = new FileFilter(); FileFilter filter = new FileFilter();
filter.add_mime_type("image/*"); filter.add_mime_type("image/*");
chooser.set_filter(filter); chooser.set_filter(filter);
if (chooser.run() == Gtk.ResponseType.ACCEPT) { if (chooser.run() == Gtk.ResponseType.ACCEPT) {
string uri = chooser.get_filename(); string uri = chooser.get_filename();
Account account = (account_list.get_selected_row() as AccountRow).account; stream_interactor.get_module(AvatarManager.IDENTITY).publish(selected_account, uri);
stream_interactor.get_module(AvatarManager.IDENTITY).publish(account, uri);
} }
chooser.close(); chooser.close();
} }
private bool on_active_switch_state_changed(bool state) { private bool on_active_switch_state_changed(bool state) {
Account account = (account_list.get_selected_row() as AccountRow).account; selected_account.enabled = state;
account.enabled = state;
if (state) { if (state) {
if (account.enabled) account_disabled(account); if (selected_account.enabled) account_disabled(selected_account);
account_enabled(account); account_enabled(selected_account);
} else { } else {
account_disabled(account); account_disabled(selected_account);
}
return false;
}
private bool on_password_key_release_event(EventKey event) {
Account account = (account_list.get_selected_row() as AccountRow).account;
account.password = password_entry.text;
string filler = "";
for (int i = 0; i < account.password.length; i++) filler += password_entry.get_invisible_char().to_string();
password_label.label = filler;
if (event.keyval == Key.Return) {
password_stack.set_visible_child_name("label");
}
return false;
}
private bool on_alias_key_release_event(EventKey event) {
Account account = (account_list.get_selected_row() as AccountRow).account;
account.alias = alias_entry.text;
alias_label.label = alias_entry.text;
if (event.keyval == Key.Return) {
alias_stack.set_visible_child_name("label");
} }
return false; return false;
} }
private void on_received_avatar(Pixbuf pixbuf, Jid jid, Account account) { private void on_received_avatar(Pixbuf pixbuf, Jid jid, Account account) {
Account curr_account = (account_list.get_selected_row() as AccountRow).account; if (selected_account.equals(account) && jid.equals(account.bare_jid)) {
if (curr_account.equals(account) && jid.equals(account.bare_jid)) {
Util.image_set_from_scaled_pixbuf(image, (new AvatarGenerator(50, 50, image.scale_factor)).draw_account(stream_interactor, account)); Util.image_set_from_scaled_pixbuf(image, (new AvatarGenerator(50, 50, image.scale_factor)).draw_account(stream_interactor, account));
} }
} }
@ -210,27 +178,17 @@ public class Dialog : Gtk.Dialog {
active_switch.set_active(account.enabled); active_switch.set_active(account.enabled);
jid_label.label = account.bare_jid.to_string(); jid_label.label = account.bare_jid.to_string();
string filler = ""; alias_hybrid.text = account.alias;
for (int i = 0; i < account.password.length; i++) filler += password_entry.get_invisible_char().to_string(); password_hybrid.entry.input_purpose = InputPurpose.PASSWORD;
password_label.label = filler; password_hybrid.text = account.password;
password_stack.set_visible_child_name("label");
password_entry.text = account.password;
alias_stack.set_visible_child_name("label");
alias_label.label = account.alias;
alias_entry.text = account.alias;
update_status_label(account); update_status_label(account);
password_button.clicked.connect(() => { set_active_stack(password_stack); });
alias_button.clicked.connect(() => { set_active_stack(alias_stack); });
active_switch.state_set.connect(on_active_switch_state_changed); active_switch.state_set.connect(on_active_switch_state_changed);
foreach(Plugins.AccountSettingsWidget widget in plugin_widgets) { foreach(Plugins.AccountSettingsWidget widget in plugin_widgets) {
widget.set_account(account); widget.set_account(account);
} }
child_activated(null);
} }
private void update_status_label(Account account) { private void update_status_label(Account account) {
@ -259,20 +217,6 @@ public class Dialog : Gtk.Dialog {
} }
} }
private void child_activated(Gtk.Widget? widget) {
if (widget != password_stack) password_stack.set_visible_child_name("label");
if (widget != alias_stack) alias_stack.set_visible_child_name("label");
foreach(var w in plugin_widgets) {
if (widget != (Gtk.Widget)w) w.deactivate();
}
}
private void set_active_stack(Stack stack) {
stack.set_visible_child_name("entry");
child_activated(stack);
}
private string get_connection_error_description(ConnectionManager.ConnectionError error) { private string get_connection_error_description(ConnectionManager.ConnectionError error) {
switch (error.source) { switch (error.source) {
case ConnectionManager.ConnectionError.Source.SASL: case ConnectionManager.ConnectionError.Source.SASL:
@ -287,4 +231,3 @@ public class Dialog : Gtk.Dialog {
} }
} }

View file

@ -118,4 +118,4 @@ public static bool is_24h_format() {
return settings_format == "24h" || p_format == " "; return settings_format == "24h" || p_format == " ";
} }
} }

View file

@ -8,7 +8,7 @@ public class LabelHybrid : Stack {
public Label label = new Label("") { visible=true }; public Label label = new Label("") { visible=true };
protected Button button = new Button() { relief=ReliefStyle.NONE, visible=true }; protected Button button = new Button() { relief=ReliefStyle.NONE, visible=true };
public void init(Widget widget) { internal virtual void init(Widget widget) {
button.add(label); button.add(label);
add_named(button, "label"); add_named(button, "label");
add_named(widget, "widget"); add_named(widget, "widget");
@ -33,7 +33,13 @@ public class EntryLabelHybrid : LabelHybrid {
get { return entry.text; } get { return entry.text; }
set { set {
entry.text = value; entry.text = value;
label.label = value; if (visibility) {
label.label = value;
} else {
string filler = "";
for (int i = 0; i < value.length; i++) filler += entry.get_invisible_char().to_string();
label.label = filler;
}
} }
} }
@ -50,11 +56,26 @@ public class EntryLabelHybrid : LabelHybrid {
} }
} }
private Entry entry; private Entry? entry_;
public Entry entry {
get {
if (entry_ == null) {
entry_ = new Entry() { visible=true };
init(entry_);
}
return entry_;
}
set { entry_ = value; }
}
public EntryLabelHybrid(Entry? e = null) { public EntryLabelHybrid.wrap(Entry e) {
entry = e ?? new Entry() { visible=true }; init(e);
init(entry); }
internal override void init(Widget widget) {
Entry? e = widget as Entry; if (e == null) return;
entry = e;
base.init(entry);
update_label(); update_label();
entry.key_release_event.connect((event) => { entry.key_release_event.connect((event) => {
@ -84,11 +105,29 @@ public class ComboBoxTextLabelHybrid : LabelHybrid {
set { label.xalign = value; } set { label.xalign = value; }
} }
private ComboBoxText combobox; private ComboBoxText combobox_;
public ComboBoxText combobox {
get {
if (combobox_ == null) {
combobox_ = new ComboBoxText() { visible=true };
init(combobox_);
}
return combobox_;
}
set { combobox_ = combobox; }
}
public ComboBoxTextLabelHybrid(ComboBoxText? cb = null) { public ComboBoxTextLabelHybrid.wrap(ComboBoxText cb) {
combobox = cb ?? new ComboBoxText() { visible=true }; combobox_ = cb;
init(combobox); init(cb);
}
public void append(string id, string text) { combobox.append(id, text); }
public string get_active_text() { return combobox.get_active_text(); }
internal override void init(Widget widget) {
ComboBoxText? combobox = widget as ComboBoxText; if (combobox == null) return;
base.init(combobox);
update_label(); update_label();
combobox.changed.connect(() => { combobox.changed.connect(() => {
@ -100,9 +139,6 @@ public class ComboBoxTextLabelHybrid : LabelHybrid {
}); });
} }
public void append(string id, string text) { combobox.append(id, text); }
public string get_active_text() { return combobox.get_active_text(); }
private void update_label() { private void update_label() {
label.label = combobox.get_active_text(); label.label = combobox.get_active_text();
} }
@ -126,4 +162,4 @@ public class LabelHybridGroup {
} }
} }
} }

View file

@ -143,4 +143,4 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
} }
} }
} }

View file

@ -38,13 +38,11 @@ public class Module : XmppStreamModule, Iq.Handler {
* @param handle Handle to be set. If null, any handle will be removed. * @param handle Handle to be set. If null, any handle will be removed.
*/ */
public void set_jid_handle(XmppStream stream, string jid, string? handle) { public void set_jid_handle(XmppStream stream, string jid, string? handle) {
Item roster_item = new Item(); Flag flag = stream.get_flag(Flag.IDENTITY);
roster_item.jid = jid; Item item = flag.get_item(jid) ?? new Item() { jid=jid };
if (handle != null) { item.name = handle != null ? handle : "";
roster_item.name = handle;
}
roster_set(stream, roster_item); roster_set(stream, item);
} }
public void on_iq_set(XmppStream stream, Iq.Stanza iq) { public void on_iq_set(XmppStream stream, Iq.Stanza iq) {

View file

@ -20,44 +20,4 @@ namespace Xmpp {
uint32 b5_2 = Random.next_int(); uint32 b5_2 = Random.next_int();
return "%08x-%04x-%04x-%04x-%04x%08x".printf(b1, b2, b3, b4, b5_1, b5_2); return "%08x-%04x-%04x-%04x-%04x%08x".printf(b1, b2, b3, b4, b5_1, b5_2);
} }
}
public class Tuple<A,B> : Object {
public A a { get; private set; }
public B b { get; private set; }
public Tuple(A a, B b) {
this.a = a;
this.b = b;
}
public static Tuple<A,B> create<A,B>(A a, B b) {
return new Tuple<A,B>(a,b);
}
}
public class Triple<A,B,C> : Tuple<A,B> {
public C c { get; private set; }
public Triple(A a, B b, C c) {
base(a, b);
this.c = c;
}
public static new Triple<A,B,C> create<A,B,C>(A a, B b, C c) {
return new Triple<A,B,C>(a, b, c);
}
}
public class Quadruple<A,B,C,D> : Triple<A,B,C> {
public D d { get; private set; }
public Quadruple(A a, B b, C c, D d) {
base (a, b, c);
this.d = d;
}
public static new Quadruple<A,B,C,D> create<A,B,C,D>(A a, B b, C c, D d) {
return new Quadruple<A,B,C,D>(a, b, c, d);
}
}
}

View file

@ -8,6 +8,7 @@ public class Flag : XmppStreamFlag {
public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "muc"); public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "muc");
private HashMap<string, Gee.List<Feature>> room_features = new HashMap<string, Gee.List<Feature>>(); private HashMap<string, Gee.List<Feature>> room_features = new HashMap<string, Gee.List<Feature>>();
private HashMap<string, string> room_names = new HashMap<string, string>();
private HashMap<string, string> enter_ids = new HashMap<string, string>(); private HashMap<string, string> enter_ids = new HashMap<string, string>();
private HashMap<string, string> own_nicks = new HashMap<string, string>(); private HashMap<string, string> own_nicks = new HashMap<string, string>();
@ -18,6 +19,8 @@ public class Flag : XmppStreamFlag {
private HashMap<string, HashMap<string, Affiliation>> affiliations = new HashMap<string, HashMap<string, Affiliation>>(); private HashMap<string, HashMap<string, Affiliation>> affiliations = new HashMap<string, HashMap<string, Affiliation>>();
private HashMap<string, Role> occupant_role = new HashMap<string, Role>(); private HashMap<string, Role> occupant_role = new HashMap<string, Role>();
public string? get_room_name(string jid) { return room_names.has_key(jid) ? room_names[jid] : null; }
public bool has_room_feature(string jid, Feature feature) { public bool has_room_feature(string jid, Feature feature) {
return room_features.has_key(jid) && room_features[jid].contains(feature); return room_features.has_key(jid) && room_features[jid].contains(feature);
} }
@ -59,6 +62,10 @@ public class Flag : XmppStreamFlag {
public string? get_muc_subject(string bare_jid) { return subjects[bare_jid]; } public string? get_muc_subject(string bare_jid) { return subjects[bare_jid]; }
internal void set_room_name(string jid, string name) {
room_names[jid] = name;
}
internal void set_room_features(string jid, Gee.List<Feature> features) { internal void set_room_features(string jid, Gee.List<Feature> features) {
room_features[jid] = features; room_features[jid] = features;
} }
@ -121,4 +128,4 @@ public class Flag : XmppStreamFlag {
internal override string get_id() { return IDENTITY.id; } internal override string get_id() { return IDENTITY.id; }
} }
} }

View file

@ -10,6 +10,7 @@ private const string NS_URI_OWNER = NS_URI + "#owner";
private const string NS_URI_USER = NS_URI + "#user"; private const string NS_URI_USER = NS_URI + "#user";
public enum MucEnterError { public enum MucEnterError {
NONE,
PASSWORD_REQUIRED, PASSWORD_REQUIRED,
BANNED, BANNED,
ROOM_DOESNT_EXIST, ROOM_DOESNT_EXIST,
@ -64,7 +65,7 @@ public class Module : XmppStreamModule {
public signal void room_configuration_changed(XmppStream stream, string jid, StatusCode code); public signal void room_configuration_changed(XmppStream stream, string jid, StatusCode code);
public signal void room_entered(XmppStream stream, string jid, string nick); public signal void room_entered(XmppStream stream, string jid, string nick);
public signal void room_enter_error(XmppStream stream, string jid, MucEnterError error); public signal void room_enter_error(XmppStream stream, string jid, MucEnterError? error); // TODO "?" shoudln't be necessary (vala bug), remove someday
public signal void self_removed_from_room(XmppStream stream, string jid, StatusCode code); public signal void self_removed_from_room(XmppStream stream, string jid, StatusCode code);
public signal void removed_from_room(XmppStream stream, string jid, StatusCode? code); public signal void removed_from_room(XmppStream stream, string jid, StatusCode? code);
@ -213,7 +214,7 @@ public class Module : XmppStreamModule {
string bare_jid = get_bare_jid(presence.from); string bare_jid = get_bare_jid(presence.from);
ErrorStanza? error_stanza = presence.get_error(); ErrorStanza? error_stanza = presence.get_error();
if (flag.get_enter_id(bare_jid) == presence.id) { if (flag.get_enter_id(bare_jid) == presence.id) {
MucEnterError? error = null; MucEnterError error = MucEnterError.NONE;
switch (error_stanza.condition) { switch (error_stanza.condition) {
case ErrorStanza.CONDITION_NOT_AUTHORIZED: case ErrorStanza.CONDITION_NOT_AUTHORIZED:
if (ErrorStanza.TYPE_AUTH == error_stanza.type_) error = MucEnterError.PASSWORD_REQUIRED; if (ErrorStanza.TYPE_AUTH == error_stanza.type_) error = MucEnterError.PASSWORD_REQUIRED;
@ -240,7 +241,7 @@ public class Module : XmppStreamModule {
if (ErrorStanza.TYPE_CANCEL == error_stanza.type_) error = MucEnterError.USE_RESERVED_ROOMNICK; if (ErrorStanza.TYPE_CANCEL == error_stanza.type_) error = MucEnterError.USE_RESERVED_ROOMNICK;
break; break;
} }
if (error != null) room_enter_error(stream, bare_jid, error); if (error != MucEnterError.NONE) room_enter_error(stream, bare_jid, error);
flag.finish_muc_enter(bare_jid); flag.finish_muc_enter(bare_jid);
} }
} }
@ -312,6 +313,13 @@ public class Module : XmppStreamModule {
Gee.List<Feature> features = new ArrayList<Feature>(); Gee.List<Feature> features = new ArrayList<Feature>();
if (query_result != null) { if (query_result != null) {
foreach (ServiceDiscovery.Identity identity in query_result.identities) {
if (identity.category == "conference") {
stream.get_flag(Flag.IDENTITY).set_room_name(jid, identity.name);
}
}
foreach (string feature in query_result.features) { foreach (string feature in query_result.features) {
Feature? parsed = null; Feature? parsed = null;
switch (feature) { switch (feature) {