Skip to content

Commit

Permalink
Added a new widget to allow changing statusmessage and name by clicki…
Browse files Browse the repository at this point in the history
…ng on the label
  • Loading branch information
naxuroqa committed May 21, 2014
1 parent ededc28 commit bcb5aa9
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ SET( VENOM_SRC
ui/ConversationTextView.vala
ui/ConversationView.vala
ui/ConversationWidget.vala
ui/EditableLabel.vala
ui/FileTransferChatEntry.vala
ui/GroupConversationSidebar.vala
ui/GroupConversationWidget.vala
Expand Down
46 changes: 33 additions & 13 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ namespace Venom {
private Gtk.Image image_status;
private Gtk.Spinner spinner_status;
private Gtk.Image image_userimage;
private Gtk.Label label_name;
private Gtk.Label label_status;
private EditableLabel label_name;
private EditableLabel label_status;
private ContactListTreeView contact_list_tree_view;
private Gtk.ComboBox combobox_status;
private Gtk.Notebook notebook_conversations;
Expand Down Expand Up @@ -183,8 +183,17 @@ namespace Venom {
image_status = builder.get_object("image_status") as Gtk.Image;
spinner_status = builder.get_object("spinner_status") as Gtk.Spinner;
image_userimage = builder.get_object("image_userimage") as Gtk.Image;
label_name = builder.get_object("label_username") as Gtk.Label;
label_status = builder.get_object("label_userstatus") as Gtk.Label;

Gtk.Label label_name_child = builder.get_object("label_username") as Gtk.Label;
Gtk.Label label_status_child = builder.get_object("label_userstatus") as Gtk.Label;
Gtk.Box box_self_info_text = builder.get_object("box_self_info_text") as Gtk.Box;
box_self_info_text.remove(label_name_child);
box_self_info_text.remove(label_status_child);
label_name = new EditableLabel.with_label(label_name_child);
label_status = new EditableLabel.with_label(label_status_child);
box_self_info_text.pack_start(label_name, false);
box_self_info_text.pack_start(label_status, false);
box_self_info_text.show_all();

combobox_status = builder.get_object("combobox_status") as Gtk.ComboBox;
Gtk.ListStore liststore_status = new Gtk.ListStore (2, typeof(string), typeof(ContactFilter));
Expand Down Expand Up @@ -380,6 +389,17 @@ namespace Venom {
}
return false;
});

label_name.label_changed.connect((str) => {
if(str != "") {
User.instance.name = str;
}
});
label_status.label_changed.connect((str) => {
if(str != "") {
User.instance.status_message = str;
}
});
}

private void init_save_session_hooks() {
Expand All @@ -402,24 +422,24 @@ namespace Venom {
User.instance.name = session.get_self_name();
User.instance.status_message = session.get_self_status_message();

label_name.label = User.instance.name;
label_name.tooltip_text = User.instance.name;
label_name.label.label = User.instance.name;
label_name.label.tooltip_text = User.instance.name;

label_status.label = User.instance.status_message;
label_status.tooltip_text = User.instance.status_message;
label_status.label.label = User.instance.status_message;
label_status.label.tooltip_text = User.instance.status_message;

User.instance.notify["name"].connect(() => {
if( session.set_name(User.instance.name) ) {
label_name.label = User.instance.name;
label_name.tooltip_text = User.instance.name;
label_name.label.label = User.instance.name;
label_name.label.tooltip_text = User.instance.name;
} else {
stderr.printf("Could not change user name!\n");
}
});
User.instance.notify["status-message"].connect(() => {
if( session.set_status_message(User.instance.status_message) ) {
label_status.label = User.instance.status_message;
label_status.tooltip_text = User.instance.status_message;
label_status.label.label = User.instance.status_message;
label_status.label.tooltip_text = User.instance.status_message;
} else {
stderr.printf("Could not change user statusmessage!\n");
}
Expand Down Expand Up @@ -483,7 +503,7 @@ namespace Venom {
w.application = application;
w.user_name = User.instance.name;
w.max_name_length = Tox.MAX_NAME_LENGTH;
w.user_status = label_status.get_text();
w.user_status = label_status.label.label;
w.max_status_length = Tox.MAX_STATUSMESSAGE_LENGTH;
w.user_image = image_userimage.get_pixbuf();
w.user_id = Tools.bin_to_hexstring(session.get_address());
Expand Down
119 changes: 119 additions & 0 deletions src/ui/EditableLabel.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* EditableLabel.vala
*
* Copyright (C) 2013-2014 Venom authors and contributors
*
* This file is part of Venom.
*
* Venom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Venom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Venom. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Venom {
public class EditableLabel : Gtk.EventBox {
private Gtk.Box box_entry;
private Gtk.Box box_label;

public Gtk.Button button_cancel { get; set; }
public Gtk.Button button_ok { get; set; }
public Gtk.Entry entry { get; set; }
public Gtk.Label label { get; set; }

public signal void label_changed(string label_text);

public EditableLabel(string label = "") {
this.label = new Gtk.Label(label);
init_widgets();
init_signals();
}

public EditableLabel.with_label(Gtk.Label label) {
this.label = label;
init_widgets();
init_signals();
}

public void show_label() {
box_label.visible = true;
box_entry.visible = false;
}

public void show_entry() {
box_label.visible = false;
box_entry.no_show_all = false;
box_entry.show_all();
box_entry.visible = true;
}

private void init_widgets() {
entry = new Gtk.Entry();
button_ok = new Gtk.Button();
button_cancel = new Gtk.Button();

entry.has_frame = false;

button_ok.add(new Gtk.Image.from_icon_name("gtk-ok", Gtk.IconSize.MENU));
button_cancel.add(new Gtk.Image.from_icon_name("gtk-cancel", Gtk.IconSize.MENU));

Gtk.Box box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
box_label = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
box_entry = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);

box_label.pack_start(label);
box_entry.pack_start(entry);
box_entry.pack_start(button_ok);
box_entry.pack_start(button_cancel);
box.pack_start(box_label);
box.pack_start(box_entry);

box_entry.no_show_all = true;
box_entry.visible = false;
this.add(box);
}

private void on_cancel() {
show_label();
}

private void on_ok() {
show_label();
label_changed(entry.text);
}

private void init_signals() {
button_press_event.connect((event) => {
if(!box_entry.visible && event.button == Gdk.BUTTON_PRIMARY) {
entry.text = label.label;
show_entry();
entry.grab_focus();
return true;
}
return false;
});
button_cancel.clicked.connect(on_cancel);
button_ok.clicked.connect(on_ok);
entry.activate.connect(on_ok);
entry.key_release_event.connect((event) => {
if(event.keyval == Gdk.Key.Escape) {
on_cancel();
return true;
}
return false;
});
entry.focus_out_event.connect(() => {
on_cancel();
return false;
});
}
}
}
4 changes: 2 additions & 2 deletions src/ui/contact_list.ui
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox" id="self_info">
<object class="GtkBox" id="box_self_info">
<property name="height_request">59</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
Expand All @@ -206,7 +206,7 @@
</packing>
</child>
<child>
<object class="GtkBox" id="box6">
<object class="GtkBox" id="box_self_info_text">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
Expand Down

0 comments on commit bcb5aa9

Please sign in to comment.