Fix MUC join w/o bookmark, with psw; change some event listeners key_press->key_release

fixes #3
This commit is contained in:
fiaxh 2017-03-09 14:27:39 +01:00
parent 811e252de1
commit b1e6e51c4f
7 changed files with 66 additions and 38 deletions

View file

@ -26,9 +26,9 @@ public class MucManager : StreamInteractionModule, Object {
MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_pre_message_received); MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_pre_message_received);
} }
public void join(Account account, Jid jid, string nick) { public void join(Account account, Jid jid, string nick, string? password = null) {
Core.XmppStream stream = stream_interactor.get_stream(account); Core.XmppStream stream = stream_interactor.get_stream(account);
if (stream != null) Xep.Muc.Module.get_module(stream).enter(stream, jid.bare_jid.to_string(), nick, null, new MucEnterListenerImpl(this, jid, nick, account)); if (stream != null) Xep.Muc.Module.get_module(stream).enter(stream, jid.bare_jid.to_string(), nick, password, new MucEnterListenerImpl(this, jid, nick, account));
} }
public void part(Account account, Jid jid) { public void part(Account account, Jid jid) {

View file

@ -52,8 +52,8 @@ protected class AddGroupchatDialog : Gtk.Dialog {
cancel_button.clicked.connect(() => { close(); }); cancel_button.clicked.connect(() => { close(); });
ok_button.clicked.connect(on_ok_button_clicked); ok_button.clicked.connect(on_ok_button_clicked);
jid_entry.key_press_event.connect_after(after_jid_entry_key_press); jid_entry.key_release_event.connect(on_jid_key_release);
nick_entry.key_press_event.connect(check_ok); nick_entry.key_release_event.connect(check_ok);
} }
public AddGroupchatDialog.for_conference(StreamInteractor stream_interactor, Account account, Xmpp.Xep.Bookmarks.Conference conference) { public AddGroupchatDialog.for_conference(StreamInteractor stream_interactor, Account account, Xmpp.Xep.Bookmarks.Conference conference) {
@ -69,7 +69,7 @@ protected class AddGroupchatDialog : Gtk.Dialog {
alias_entry.text = conference.name; alias_entry.text = conference.name;
} }
private bool after_jid_entry_key_press() { private bool on_jid_key_release() {
check_ok(); check_ok();
if (!alias_entry_changed) { if (!alias_entry_changed) {
Jid? parsed_jid = Jid.parse(jid_entry.text); Jid? parsed_jid = Jid.parse(jid_entry.text);

View file

@ -1,3 +1,4 @@
using Gdk;
using Gtk; using Gtk;
using Dino.Entities; using Dino.Entities;
@ -31,21 +32,21 @@ protected class ConferenceDetailsFragment : Box {
} }
} }
public string jid { public string jid {
get { return jid_label.label; } get { return jid_entry.text; }
set { set {
jid_label.label = value; jid_label.label = value;
jid_entry.text = value; jid_entry.text = value;
} }
} }
public string nick { public string nick {
get { return nick_label.label; } get { return nick_entry.text; }
set { set {
nick_label.label = value; nick_label.label = value;
nick_entry.text = value; nick_entry.text = value;
} }
} }
public string password { public string password {
get { return password_label.label; } get { return password_entry.text == "" ? null : password_entry.text; }
set { set {
password_label.label = value; password_label.label = value;
password_entry.text = value; password_entry.text = value;
@ -115,13 +116,13 @@ protected class ConferenceDetailsFragment : Box {
nick_button.clicked.connect(() => { set_active_stack(nick_stack); }); nick_button.clicked.connect(() => { set_active_stack(nick_stack); });
password_button.clicked.connect(() => { set_active_stack(password_stack); }); password_button.clicked.connect(() => { set_active_stack(password_stack); });
accounts_comboboxtext.changed.connect(() => { accounts_label.label = accounts_comboboxtext.get_active_text(); }); accounts_comboboxtext.changed.connect(() => {accounts_label.label = accounts_comboboxtext.get_active_text(); });
jid_entry.key_press_event.connect(() => { jid_label.label = jid_entry.text; return false; }); jid_entry.key_release_event.connect(on_jid_key_release_event);
nick_entry.key_press_event.connect(() => { nick_label.label = nick_entry.text; return false; }); nick_entry.key_release_event.connect(on_nick_key_release_event);
password_entry.key_press_event.connect(() => { password_label.label = password_entry.text; return false; }); password_entry.key_release_event.connect(on_password_key_release_event);
jid_entry.key_press_event.connect(() => { done = true; return false; }); // just for notifying jid_entry.key_release_event.connect(() => { done = true; return false; }); // just for notifying
nick_entry.key_press_event.connect(() => { done = true; return false; }); nick_entry.key_release_event.connect(() => { done = true; return false; });
foreach (Account account in stream_interactor.get_accounts()) { foreach (Account account in stream_interactor.get_accounts()) {
accounts_comboboxtext.append_text(account.bare_jid.to_string()); accounts_comboboxtext.append_text(account.bare_jid.to_string());
@ -129,12 +130,38 @@ protected class ConferenceDetailsFragment : Box {
accounts_comboboxtext.set_active(0); accounts_comboboxtext.set_active(0);
} }
public void set_editable() {
accounts_stack.set_visible_child_name("entry");
nick_stack.set_visible_child_name("entry");
password_stack.set_visible_child_name("entry");
}
public void clear() { public void clear() {
jid = ""; jid = "";
nick = ""; nick = "";
password = ""; password = "";
} }
private bool on_jid_key_release_event(EventKey event) {
jid_label.label = jid_entry.text;
if (event.keyval == Key.Return) jid_stack.set_visible_child_name("label");
return false;
}
private bool on_nick_key_release_event(EventKey event) {
nick_label.label = nick_entry.text;
if (event.keyval == Key.Return) nick_stack.set_visible_child_name("label");
return false;
}
private bool on_password_key_release_event(EventKey event) {
string filler = "";
for (int i = 0; i < password_entry.text.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 void set_active_stack(Stack stack) { private void set_active_stack(Stack stack) {
stack.set_visible_child_name("entry"); stack.set_visible_child_name("entry");
if (stack != accounts_stack) accounts_stack.set_visible_child_name("label"); if (stack != accounts_stack) accounts_stack.set_visible_child_name("label");

View file

@ -59,7 +59,7 @@ public class Dialog : Gtk.Dialog {
cancel_button.clicked.connect(show_jid_add_view); cancel_button.clicked.connect(show_jid_add_view);
ok_button.label = "Join"; ok_button.label = "Join";
ok_button.sensitive = details_fragment.done; ok_button.sensitive = details_fragment.done;
ok_button.clicked.disconnect(show_conference_details_view); ok_button.clicked.disconnect(on_next_button_clicked);
ok_button.clicked.connect(on_ok_button_clicked); ok_button.clicked.connect(on_ok_button_clicked);
select_fragment.notify["done"].disconnect(set_ok_sensitive_from_select); select_fragment.notify["done"].disconnect(set_ok_sensitive_from_select);
details_fragment.notify["done"].connect(set_ok_sensitive_from_details); details_fragment.notify["done"].connect(set_ok_sensitive_from_details);
@ -131,12 +131,13 @@ public class Dialog : Gtk.Dialog {
ok_button.grab_focus(); ok_button.grab_focus();
} else if (row != null) { } else if (row != null) {
details_fragment.jid = row.jid.to_string(); details_fragment.jid = row.jid.to_string();
details_fragment.set_editable();
} }
show_conference_details_view(); show_conference_details_view();
} }
private void on_ok_button_clicked() { private void on_ok_button_clicked() {
MucManager.get_instance(stream_interactor).join(details_fragment.account, new Jid(details_fragment.jid), details_fragment.nick); MucManager.get_instance(stream_interactor).join(details_fragment.account, new Jid(details_fragment.jid), details_fragment.nick, details_fragment.password);
close(); close();
} }
@ -151,14 +152,14 @@ public class Dialog : Gtk.Dialog {
int difference = def_height - curr_height; int difference = def_height - curr_height;
Timer timer = new Timer(); Timer timer = new Timer();
Timeout.add((int) (stack.transition_duration / 30), Timeout.add((int) (stack.transition_duration / 30),
() => { () => {
ulong microsec; ulong microsec;
timer.elapsed(out microsec); timer.elapsed(out microsec);
ulong millisec = microsec / 1000; ulong millisec = microsec / 1000;
double partial = double.min(1, (double) millisec / stack.transition_duration); double partial = double.min(1, (double) millisec / stack.transition_duration);
resize(curr_width, (int) (curr_height + difference * partial)); resize(curr_width, (int) (curr_height + difference * partial));
return millisec < stack.transition_duration; return millisec < stack.transition_duration;
}); });
} }
} }

View file

@ -24,7 +24,7 @@ public class Dino.Ui.ConversationListTitlebar : Gtk.HeaderBar {
SimpleAction contacts_action = new SimpleAction("add_chat", null); SimpleAction contacts_action = new SimpleAction("add_chat", null);
contacts_action.activate.connect(() => { contacts_action.activate.connect(() => {
AddConversation.Chat.Dialog add_chat_dialog = new AddConversation.Chat.Dialog(stream_interactor); AddConversation.Chat.Dialog add_chat_dialog = new AddConversation.Chat.Dialog(stream_interactor);
add_chat_dialog.set_transient_for((ApplicationWindow) get_toplevel()); add_chat_dialog.set_transient_for((Window) get_toplevel());
add_chat_dialog.conversation_opened.connect((conversation) => conversation_opened(conversation)); add_chat_dialog.conversation_opened.connect((conversation) => conversation_opened(conversation));
add_chat_dialog.show(); add_chat_dialog.show();
}); });
@ -33,7 +33,7 @@ public class Dino.Ui.ConversationListTitlebar : Gtk.HeaderBar {
SimpleAction conference_action = new SimpleAction("add_conference", null); SimpleAction conference_action = new SimpleAction("add_conference", null);
conference_action.activate.connect(() => { conference_action.activate.connect(() => {
AddConversation.Conference.Dialog add_conference_dialog = new AddConversation.Conference.Dialog(stream_interactor); AddConversation.Conference.Dialog add_conference_dialog = new AddConversation.Conference.Dialog(stream_interactor);
add_conference_dialog.set_transient_for((ApplicationWindow) get_toplevel()); add_conference_dialog.set_transient_for((Window) get_toplevel());
add_conference_dialog.conversation_opened.connect((conversation) => conversation_opened(conversation)); add_conference_dialog.conversation_opened.connect((conversation) => conversation_opened(conversation));
add_conference_dialog.show(); add_conference_dialog.show();
}); });

View file

@ -22,7 +22,7 @@ public class View : Grid {
public View(StreamInteractor stream_interactor) { public View(StreamInteractor stream_interactor) {
conversation_list = new List(stream_interactor); conversation_list = new List(stream_interactor);
scrolled.add(conversation_list); scrolled.add(conversation_list);
search_entry.key_press_event.connect(search_key_press_event); search_entry.key_release_event.connect(search_key_release_event);
search_entry.search_changed.connect(search_changed); search_entry.search_changed.connect(search_changed);
} }
@ -41,7 +41,7 @@ public class View : Grid {
refilter(); refilter();
} }
private bool search_key_press_event(EventKey event) { private bool search_key_release_event(EventKey event) {
conversation_list.select_row(conversation_list.get_row_at_y(0)); conversation_list.select_row(conversation_list.get_row_at_y(0));
if (event.keyval == Key.Down) { if (event.keyval == Key.Down) {
ConversationRow? row = (ConversationRow) conversation_list.get_row_at_index(0); ConversationRow? row = (ConversationRow) conversation_list.get_row_at_index(0);

View file

@ -69,8 +69,8 @@ public class Dialog : Gtk.Window {
add_button.clicked.connect(add_button_clicked); add_button.clicked.connect(add_button_clicked);
no_accounts_add.clicked.connect(add_button_clicked); no_accounts_add.clicked.connect(add_button_clicked);
remove_button.clicked.connect(remove_button_clicked); remove_button.clicked.connect(remove_button_clicked);
password_entry.key_press_event.connect(on_password_entry_key_press_event); password_entry.key_release_event.connect(on_password_key_release_event);
alias_entry.key_press_event.connect(on_alias_entry_key_press_event); alias_entry.key_release_event.connect(on_alias_key_release_event);
image_button.clicked.connect(on_image_button_clicked); image_button.clicked.connect(on_image_button_clicked);
main_stack.set_visible_child_name("no_accounts"); main_stack.set_visible_child_name("no_accounts");
@ -188,23 +188,23 @@ public class Dialog : Gtk.Window {
return false; return false;
} }
private bool on_password_entry_key_press_event(EventKey event) { private bool on_password_key_release_event(EventKey event) {
Account account = (account_list.get_selected_row() as AccountRow).account; 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) { if (event.keyval == Key.Return) {
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;
password_stack.set_visible_child_name("label"); password_stack.set_visible_child_name("label");
} }
return false; return false;
} }
private bool on_alias_entry_key_press_event(EventKey event) { private bool on_alias_key_release_event(EventKey event) {
Account account = (account_list.get_selected_row() as AccountRow).account; 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) { if (event.keyval == Key.Return) {
account.alias = alias_entry.text;
alias_label.label = alias_entry.text;
alias_stack.set_visible_child_name("label"); alias_stack.set_visible_child_name("label");
} }
return false; return false;