Skip to content

Commit

Permalink
added basic context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
naxuroqa committed Jun 21, 2014
1 parent 3b9035d commit dd91b7c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/core/ToxSession.vala
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ namespace Venom {
lock(handle) {
ret = handle.join_groupchat(c.friend_id, g.public_key);
}
if(ret < 0)
if(ret < 0) {
return false;
}
g.group_id = ret;
_groups.set(ret, g);
return true;
Expand Down Expand Up @@ -497,9 +498,9 @@ namespace Venom {
return ret == 0;
}

public int invite_friend(int group_id, int friendnumber) {
public int invite_friend(Contact c, GroupChat g) {
lock(handle){
return handle.invite_friend(friendnumber, group_id);
return handle.invite_friend(c.friend_id, g.group_id);
}
}

Expand Down Expand Up @@ -660,6 +661,10 @@ namespace Venom {
return _contacts;
}

public unowned GLib.HashTable<int, GroupChat> get_groupchats() {
return _groups;
}

public uint8 send_file_request(int friend_number, uint64 file_size, string filename)
requires(filename != null)
{
Expand Down
42 changes: 42 additions & 0 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ namespace Venom {

contact_list_tree_view.entry_activated.connect(on_entry_activated);
contact_list_tree_view.key_press_event.connect(on_treeview_key_pressed);
contact_list_tree_view.button_release_event.connect(
on_treeview_button_release);

//ComboboxStatus signals
combobox_status.changed.connect(combobox_status_changed);
Expand Down Expand Up @@ -457,6 +459,27 @@ namespace Venom {
});
}

private bool on_treeview_button_release (Gdk.EventButton event) {
if(event.button == Gdk.BUTTON_SECONDARY) {
GLib.Object o = contact_list_tree_view.get_selected_entry();
Gtk.Menu menu = null;
if(o is Contact) {
menu = UITools.show_contact_context_menu(this, (Contact)o);
} else if(o is GroupChat) {
menu = UITools.show_groupchat_context_menu(this, (GroupChat)o);
} else {
// empty treeview clicked
return false;
}
menu.show_all();
menu.attach_to_widget(this, null);
menu.hide.connect(() => {menu.detach();});
menu.popup(null, null, null, 0, 0);
return false;
}
return false;
}

private void set_title_from_status(UserStatus status) {
this.our_title = _("Venom (%s)").printf(status.to_string());
string notify = "";
Expand Down Expand Up @@ -541,6 +564,10 @@ namespace Venom {
push_in = true;
}

public unowned GLib.HashTable<int, GroupChat> get_groupchats() {
return session.get_groupchats();
}

private void on_outgoing_message(Message message) {
session.on_own_message(message.to, message.message);
session.send_message(message.to.friend_id, message.message);
Expand Down Expand Up @@ -1071,6 +1098,21 @@ namespace Venom {
contact_removed(c);
}

public void invite_to_groupchat(Contact c, int groupchat_number = -1) {
GroupChat g = null;
if(groupchat_number < 0) {
g = session.add_groupchat();
if(g == null) {
stderr.printf(_("Could not create a new groupchat.\n"));
return;
}
groupchat_added(g);
} else {
g = get_groupchats().get(groupchat_number);
}
session.invite_friend(c, g);
}

public void remove_groupchat(GroupChat g) {
if(g == null)
return;
Expand Down
50 changes: 50 additions & 0 deletions src/ui/UITools.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,56 @@ namespace Venom {
return "really big file";
}
}

public static Gtk.Menu show_contact_context_menu( ContactListWindow w, Contact c ) {
Gtk.Menu menu = new Gtk.Menu();
/*
Gtk.MenuItem item = new Gtk.MenuItem.with_mnemonic("_Show");
item.activate.connect(() => { print("name: %s\n", c.get_name_string()); });
menu.append(item);*/

Gtk.MenuItem item = new Gtk.MenuItem.with_mnemonic(_("_Unfriend"));
item.activate.connect(() => { w.remove_contact(c); });
menu.append(item);
/*
item = new Gtk.MenuItem.with_mnemonic("_Block");
item.activate.connect(() => { w.block_contact(c); });
menu.append(item);*/

GLib.HashTable<int, GroupChat> groupchats = w.get_groupchats();
if(groupchats.size() > 0) {
Gtk.MenuItem groupchat_item = new Gtk.MenuItem.with_mnemonic(_("_Invite to ..."));
Gtk.Menu groupchat_submenu = new Gtk.Menu();

item = new Gtk.MenuItem.with_mnemonic(_("_New groupchat"));
item.activate.connect(() => { w.invite_to_groupchat(c); });
groupchat_submenu.append(item);

groupchats.foreach((key, val) => {
item = new Gtk.MenuItem.with_label(val.get_name_string());
item.activate.connect(() => { w.invite_to_groupchat(c, key); });
groupchat_submenu.append(item);
});
groupchat_item.submenu = groupchat_submenu;
menu.append(groupchat_item);
} else {
item = new Gtk.MenuItem.with_mnemonic(_("_Invite to new groupchat"));
item.activate.connect(() => { w.invite_to_groupchat(c); });
menu.append(item);
}
return menu;
}

public static Gtk.Menu show_groupchat_context_menu( ContactListWindow w, GroupChat g ) {
Gtk.Menu menu = new Gtk.Menu();

Gtk.MenuItem item = new Gtk.MenuItem.with_mnemonic(_("_Leave groupchat"));
item.activate.connect(() => { w.remove_groupchat(g ); });
menu.append(item);

return menu;
}

#if ENABLE_QR_ENCODE
public static Gdk.Pixbuf? qr_encode(string content) {
QR.Code code = QR.Code.encode_string(content, 0, QR.ECLevel.M, QR.Mode.EIGHT_BIT, false);
Expand Down

0 comments on commit dd91b7c

Please sign in to comment.