Skip to content

Commit

Permalink
reworked settings dialog, replaced apply/cancel buttons with a close …
Browse files Browse the repository at this point in the history
…button, insta-applying settings via property binding now
  • Loading branch information
naxuroqa committed Jun 2, 2014
1 parent 3be4588 commit 53a0969
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 155 deletions.
8 changes: 8 additions & 0 deletions src/core/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
namespace Venom {
public class Settings : Object {

public const string MESSAGE_LOGGING_KEY = "enable-logging";
public const string DAYS_TO_LOG_KEY = "days-to-log";
public const string URGENCY_NOTIFICATION_KEY = "enable-urgency-notification";
public const string DEC_BINARY_PREFIX_KEY = "dec-binary-prefix";
public const string SEND_TYPING_STATUS_KEY = "send-typing-status";
public const string SHOW_TYPING_STATUS_KEY = "show-typing-status";
public const string DEFAULT_HOST_KEY = "default-host";

public bool enable_logging { get; set; default = false; }
public bool enable_urgency_notification { get; set; default = true; }
public int days_to_log { get; set; default = 180; }
Expand Down
3 changes: 1 addition & 2 deletions src/ui/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ namespace Venom {

private void on_preferences(GLib.SimpleAction action, GLib.Variant? parameter) {
if(settings_window == null) {
settings_window = new SettingsWindow();
settings_window = new SettingsWindow(contact_list_window);
settings_window.destroy.connect( () => {settings_window = null;});
settings_window.transient_for = contact_list_window;
settings_window.show_all();
} else {
settings_window.present();
Expand Down
6 changes: 4 additions & 2 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,10 @@ namespace Venom {
contact_added(c);
}
private void on_typing_change(Contact c, bool is_typing) {
ConversationWidget w = open_conversation_with(c);
w.on_typing_changed(is_typing);
if(Settings.instance.show_typing_status) {
ConversationWidget w = open_conversation_with(c);
w.on_typing_changed(is_typing);
}
}
private void on_friendmessage(Contact c, string message) {
stdout.printf("<%s> %s:%s\n", new DateTime.now_local().format("%F"), c.name != null ? c.name : "<%i>".printf(c.friend_id), message);
Expand Down
129 changes: 35 additions & 94 deletions src/ui/SettingsWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,115 +20,56 @@
*/

namespace Venom {
public class SettingsWindow : Gtk.Dialog {
private Gtk.CheckButton keep_history_checkbutton;
private Gtk.RadioButton history_keep_radio;
private Gtk.RadioButton history_delete_radio;
private Gtk.SpinButton history_delete_spinbutton;
private Gtk.CheckButton send_typing_checkbutton;
private Gtk.CheckButton show_typing_checkbutton;
private Gtk.CheckButton urgency_notification_checkbutton;
private Gtk.ListStore filesize_prefix_liststore;
private Gtk.ComboBox filesize_prefix_combobox;
private Gtk.Entry default_host_entry;
public class SettingsWindow : GLib.Object {
private Gtk.Dialog dialog;
public signal void destroy();

public bool keep_history {
get { return keep_history_checkbutton.active; }
set { keep_history_checkbutton.active = value; }
}
public int delete_history_after {
get { return history_keep_radio.active ? -1 : (int) history_delete_spinbutton.value; }
set {
if( value < 0 ) {
history_keep_radio.active = true;
} else {
history_delete_radio.active = true;
history_delete_spinbutton.value = value;
}
}
}
public bool send_typing {
get { return send_typing_checkbutton.active; }
set { send_typing_checkbutton.active = value; }
}
public bool show_typing {
get { return show_typing_checkbutton.active; }
set { show_typing_checkbutton.active = value; }
}
public bool urgency_notification {
get { return urgency_notification_checkbutton.active; }
set { urgency_notification_checkbutton.active = value; }
}

public bool dec_binary_prefix {
get { return filesize_prefix_combobox.active == 0; }
set { filesize_prefix_combobox.active = value ? 0 : 1; }
}

public string default_host {
get { return default_host_entry.text; }
set { default_host_entry.text = value; }
}

public SettingsWindow() {
this.title = "Settings";
public SettingsWindow( Gtk.Window parent ) {
Gtk.Builder builder = new Gtk.Builder();
try {
builder.add_from_resource("/org/gtk/venom/settings_window.ui");
} catch (GLib.Error e) {
stderr.printf("Loading conversation window failed!\n");
}
Gtk.Box settings_box = builder.get_object("settings_box") as Gtk.Box;
this.get_content_area().add(settings_box);

keep_history_checkbutton = builder.get_object("keep_history_checkbutton") as Gtk.CheckButton;
history_keep_radio = builder.get_object("history_keep_radio") as Gtk.RadioButton;
history_delete_radio = builder.get_object("history_delete_radio") as Gtk.RadioButton;
history_delete_spinbutton = builder.get_object("history_delete_spinbutton") as Gtk.SpinButton;
send_typing_checkbutton = builder.get_object("send_typing_checkbutton") as Gtk.CheckButton;
show_typing_checkbutton = builder.get_object("show_typing_checkbutton") as Gtk.CheckButton;
urgency_notification_checkbutton = builder.get_object("urgency_notification_checkbutton") as Gtk.CheckButton;
filesize_prefix_combobox = builder.get_object("filesize_prefix_combobox") as Gtk.ComboBox;
filesize_prefix_liststore = builder.get_object("filesize_prefix_liststore") as Gtk.ListStore;
default_host_entry = builder.get_object("default_host_entry") as Gtk.Entry;

Gtk.Box history_box = builder.get_object("history_box") as Gtk.Box;
keep_history_checkbutton.toggled.connect( () => {
history_box.sensitive = keep_history_checkbutton.active;
});
keep_history_checkbutton.toggled();
dialog = builder.get_object("dialog") as Gtk.Dialog;
dialog.set_transient_for(parent);

Gtk.CellRendererText renderer = new Gtk.CellRendererText();
filesize_prefix_combobox.pack_start(renderer, true);
filesize_prefix_combobox.add_attribute(renderer, "text", 0);
Gtk.SpinButton history_delete_spinbutton = builder.get_object("history_delete_spinbutton") as Gtk.SpinButton;

Settings settings = Settings.instance;
keep_history = settings.enable_logging;
delete_history_after = settings.days_to_log;
urgency_notification = settings.enable_urgency_notification;
send_typing = settings.send_typing_status;
show_typing = settings.show_typing_status;
dec_binary_prefix = settings.dec_binary_prefix;
default_host = settings.default_host;

add_buttons("_Cancel", Gtk.ResponseType.CANCEL, "_Save", Gtk.ResponseType.OK, null);
set_default_response(Gtk.ResponseType.CANCEL);

response.connect( (id) => {
if(id == Gtk.ResponseType.OK) {
settings.enable_logging = keep_history;
settings.days_to_log = delete_history_after;
settings.send_typing_status = send_typing;
settings.show_typing_status = show_typing;
settings.enable_urgency_notification = urgency_notification;
settings.dec_binary_prefix = dec_binary_prefix;
settings.default_host = default_host;
settings.bind_property(Settings.MESSAGE_LOGGING_KEY, builder.get_object("keep_history_checkbutton"), "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
settings.bind_property(Settings.MESSAGE_LOGGING_KEY, builder.get_object("history_box"), "sensitive", BindingFlags.SYNC_CREATE);
settings.bind_property(Settings.DAYS_TO_LOG_KEY, builder.get_object("history_keep_radio"), "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL,
(binding, srcval, ref targetval) => { if((int)srcval < 0) targetval.set_boolean(true); return true; },
(binding, srcval, ref targetval) => { if((bool)srcval) targetval.set_int(-1); return true; }
);
settings.bind_property(Settings.DAYS_TO_LOG_KEY, builder.get_object("history_delete_radio"), "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL,
(binding, srcval, ref targetval) => { if((int)srcval >= 0) targetval.set_boolean(true); return true; },
(binding, srcval, ref targetval) => { if((bool)srcval) targetval.set_int((int)history_delete_spinbutton.value); return true; }
);
settings.bind_property(Settings.DAYS_TO_LOG_KEY, builder.get_object("history_delete_spinbutton"), "value", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
settings.bind_property(Settings.SEND_TYPING_STATUS_KEY, builder.get_object("send_typing_checkbutton"), "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
settings.bind_property(Settings.SHOW_TYPING_STATUS_KEY, builder.get_object("show_typing_checkbutton"), "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
settings.bind_property(Settings.URGENCY_NOTIFICATION_KEY, builder.get_object("urgency_notification_checkbutton"), "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
settings.bind_property(Settings.DEFAULT_HOST_KEY, builder.get_object("default_host_entry"), "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
settings.bind_property(Settings.DEC_BINARY_PREFIX_KEY, builder.get_object("filesize_prefix_combobox"), "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL,
(binding, srcval, ref targetval) => {targetval.set_int((bool)srcval ? 0 : 1); return true;},
(binding, srcval, ref targetval) => {targetval.set_boolean((int)srcval == 0); return true;}
);
}

settings.save_settings(ResourceFactory.instance.config_filename);
}
public void show_all() {
dialog.show_all();
dialog.response.connect( () => {
Settings.instance.save_settings(ResourceFactory.instance.config_filename);
dialog.destroy();
destroy();
});
}

public void present() {
dialog.present();
}
}
}
139 changes: 82 additions & 57 deletions src/ui/settings_window.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.2 -->
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.4"/>
<object class="GtkListStore" id="filesize_prefix_liststore">
Expand All @@ -25,27 +25,53 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkBox" id="settings_box">
<property name="visible">True</property>
<object class="GtkDialog" id="dialog">
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkFrame" id="privacy_frame">
<property name="visible">True</property>
<property name="title" translatable="yes">Settings</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="privacy_alignment">
<object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
<property name="can_focus">True</property>
<property name="border_width">5</property>
<child>
<object class="GtkBox" id="privacy_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkCheckButton" id="keep_history_checkbutton">
Expand Down Expand Up @@ -175,7 +201,6 @@
<object class="GtkCheckButton" id="show_typing_checkbutton">
<property name="label" translatable="yes">Show me when others are typing</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
Expand All @@ -189,39 +214,23 @@
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="privacy_frame_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Privacy&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="miscellaneous_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="miscellaneous_alignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
<child type="tab">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Privacy</property>
</object>
<packing>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="miscellaneous_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="urgency_notification_checkbutton">
<property name="label" translatable="yes">Flash window when a new message arrives</property>
Expand Down Expand Up @@ -259,6 +268,13 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="model">filesize_prefix_liststore</property>
<property name="id_column">0</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand All @@ -282,7 +298,7 @@
<object class="GtkLabel" id="default_host_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Default Host:</property>
<property name="label" translatable="yes">Default Tox DNS ID suffix:</property>
</object>
<packing>
<property name="expand">False</property>
Expand Down Expand Up @@ -310,23 +326,32 @@
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Miscellaneous</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="miscellaneous_frame_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Miscellaneous&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<action-widgets>
<action-widget response="0">button1</action-widget>
</action-widgets>
</object>
</interface>

0 comments on commit 53a0969

Please sign in to comment.