[Xfce4-commits] <postler:master> Hinted entries
Christian Dywan
noreply at xfce.org
Tue Feb 15 21:34:03 CET 2011
Updating branch refs/heads/master
to 54deaf1940fced5bd4b9ad9dc69ae908644fc957 (commit)
from c255cbcc2d9059c798e59eba5b3929bb9e18c4d6 (commit)
commit 54deaf1940fced5bd4b9ad9dc69ae908644fc957
Author: Sergio Spinatelli <spinatelli.sergio at gmail.com>
Date: Tue Feb 15 10:01:11 2011 +0100
Hinted entries
postler/elementary-entry.vala | 204 +++++++++++++++++++++++++++++++++++++
postler/postler-accountsetup.vala | 130 ++++++++++++++---------
postler/postler-bureau.vala | 35 ++----
3 files changed, 295 insertions(+), 74 deletions(-)
diff --git a/postler/elementary-entry.vala b/postler/elementary-entry.vala
new file mode 100644
index 0000000..c5dab3d
--- /dev/null
+++ b/postler/elementary-entry.vala
@@ -0,0 +1,204 @@
+/*
+ Copyright (C) 2011 Avi Romanoff <aviromanoff at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+namespace Elementary {
+
+public class Entry : Gtk.Entry {
+
+ public string hint_string;
+
+ public Entry (string hint_string="") {
+
+ this.hint_string = hint_string;
+
+ this.hint ();
+ this.focus_in_event.connect (on_focus_in);
+ this.focus_out_event.connect (on_focus_out);
+ this.drag_data_received.connect (on_drag_data_received);
+
+ }
+
+ private bool on_focus_in () {
+
+ if (get_text () == "") {
+ unhint ();
+ }
+ return false;
+
+ }
+
+ private bool on_focus_out () {
+
+ if (get_text () == "") {
+ hint ();
+ }
+ return false;
+
+ }
+
+ private void on_drag_data_received (Gdk.DragContext context, int x, int y,
+ Gtk.SelectionData selection, uint info, uint timestamp) {
+
+ on_focus_in ();
+
+ }
+
+ protected void hint () {
+
+ this.text = this.hint_string;
+ grey_out ();
+
+ }
+
+ protected void unhint () {
+
+ this.text = "";
+ reset_font ();
+
+ }
+
+ private void grey_out () {
+
+ var color = Gdk.Color ();
+ Gdk.Color.parse ("#999", out color);
+ this.modify_text (Gtk.StateType.NORMAL, color);
+ this.modify_font (Pango.FontDescription.from_string ("italic"));
+
+ }
+
+ private void reset_font () {
+
+ var color = Gdk.Color ();
+ Gdk.Color.parse ("#444", out color);
+ this.modify_text (Gtk.StateType.NORMAL, color);
+ this.modify_font (Pango.FontDescription.from_string ("normal"));
+
+ }
+
+ public new string get_text () {
+
+ if (text == this.hint_string) {
+ return "";
+ }
+ else {
+ return text;
+ }
+
+ }
+
+ public new void set_text(string text) {
+
+ if (text == "") {
+ hint();
+ } else {
+ unhint();
+ }
+
+ this.text = text;
+ }
+}
+
+public class SearchEntry : Entry {
+
+ bool is_searching;
+
+ public SearchEntry (string hint_string="") {
+
+ base(hint_string);
+ this.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, Gtk.STOCK_FIND);
+ this.changed.connect (manage_icon);
+ this.focus_in_event.connect (on_focus_in);
+ this.focus_out_event.connect (on_focus_out);
+ this.icon_press.connect (icon_pressed);
+ setup_clear_icon ();
+ this.is_searching = true;
+
+ }
+
+ private void setup_clear_icon () {
+
+ var stock_item = Gtk.StockItem ();
+ stock_item.stock_id = "edit-clear-symbolic";
+ stock_item.label = null;
+ stock_item.modifier = 0;
+ stock_item.keyval = 0;
+ stock_item.translation_domain = Gtk.STOCK_CLEAR;
+ var factory = new Gtk.IconFactory ();
+ var icon_set = new Gtk.IconSet ();
+ var icon_source = new Gtk.IconSource ();
+ icon_source.set_icon_name (Gtk.STOCK_CLEAR);
+ icon_set.add_source (icon_source);
+ icon_source.set_icon_name ("edit-clear-symbolic");
+ icon_set.add_source (icon_source);
+ factory.add ("edit-clear-symbolic", icon_set);
+ Gtk.stock_add ({stock_item});
+ factory.add_default ();
+
+ }
+
+ private new void hint () {
+
+ this.is_searching = false;
+ this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null);
+ base.hint ();
+
+ }
+
+ private new bool on_focus_in () {
+
+ if (!this.is_searching) {
+ this.unhint ();
+ this.is_searching = true;
+ }
+ return false;
+
+ }
+
+ private new bool on_focus_out () {
+
+ if (this.get_text() == "") {
+ this.hint ();
+ this.is_searching = false;
+ }
+ return false;
+
+ }
+
+ private void manage_icon () {
+
+ if (this.text != "") {
+ this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, "edit-clear-symbolic");
+ }
+ else {
+ this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null);
+ }
+
+ }
+
+ private void icon_pressed (Gtk.EntryIconPosition icon_position) {
+
+ if (icon_position == Gtk.EntryIconPosition.SECONDARY) {
+ this.is_searching = false;
+ this.text = "";
+ this.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, null);
+ this.is_searching = true;
+ }
+ else {
+ if (!this.is_focus && this.text == "") {
+ this.is_searching = false;
+ this.hint ();
+ }
+ }
+
+ }
+}
+
+}
diff --git a/postler/postler-accountsetup.vala b/postler/postler-accountsetup.vala
index 2e87ce6..6e5f52b 100644
--- a/postler/postler-accountsetup.vala
+++ b/postler/postler-accountsetup.vala
@@ -14,19 +14,19 @@ public class Postler.AccountWidget : Gtk.VBox {
Gtk.Box content_area;
Gtk.Box advanced_area;
- Gtk.Entry header;
- Gtk.Entry filter;
+ Elementary.Entry header;
+ Elementary.Entry filter;
- Gtk.Entry realname;
- public Gtk.Entry address;
- Gtk.Entry password;
- Gtk.Entry organization;
+ Elementary.Entry realname;
+ public Elementary.Entry address;
+ Elementary.Entry password;
+ Elementary.Entry organization;
Gtk.TextView signature;
- Gtk.Entry receiver;
- Gtk.Entry username;
- Gtk.Entry prefix;
- Gtk.Entry sender;
+ Elementary.Entry receiver;
+ Elementary.Entry username;
+ Elementary.Entry prefix;
+ Elementary.Entry sender;
AccountInfo info;
@@ -56,32 +56,37 @@ public class Postler.AccountWidget : Gtk.VBox {
string[] parts = query.split ("/", 2);
return_if_fail (parts[0] != null && parts[1] != null);
- header = new Gtk.Entry ();
- header.text = parts[0];
+ header = new Elementary.Entry ();
+ header.set_text (parts[0]);
add_label_entry (_("_Header"), header);
- filter = new Gtk.Entry ();
- filter.text = parts[1];
+ filter = new Elementary.Entry ();
+ filter.set_text (parts[1]);
add_label_entry (_("_Keywords"), filter);
content_area.show_all ();
pack_end (content_area, true, true, 0);
- address = new Gtk.Entry ();
+ address = new Elementary.Entry ();
return;
}
- realname = new Gtk.Entry ();
- realname.text = info.realname ?? "";
+ realname = new Elementary.Entry ("First Last");
+ if (info.realname != null)
+ realname.set_text (info.realname);
add_label_entry (_("_Full Name:"), realname);
- address = new Gtk.Entry ();
- address.text = info.address ?? "";
+ address = new Elementary.Entry ("email at example.com");
+ address.focus_out_event.connect (on_focus_out);
+ if (info.address != null)
+ address.set_text (info.address);
add_label_entry (_("_Email Address:"), address);
- password = new Gtk.Entry ();
+ password = new Elementary.Entry ("Password");
password.visibility = false;
- password.text = info.password ?? "";
+ if (info.password != null)
+ password.set_text (info.password);
add_label_entry (_("_Password:"), password);
- organization = new Gtk.Entry ();
- organization.text = info.organization ?? "";
+ organization = new Elementary.Entry ("Optional, Inc.");
+ if (info.organization != null)
+ organization.set_text (info.organization);
add_label_entry (_("_Organization:"), organization);
signature = new Gtk.TextView ();
@@ -97,17 +102,21 @@ public class Postler.AccountWidget : Gtk.VBox {
advanced_area = new Gtk.VBox (false, 4);
expander.add (advanced_area);
- receiver = new Gtk.Entry ();
- receiver.text = info.receive ?? "";
+ receiver = new Elementary.Entry ("imap.example.com");
+ if (info.receive != null)
+ receiver.set_text (info.receive);
add_label_entry (_("_Receiving Server:"), receiver, true);
- username = new Gtk.Entry ();
- username.text = info.username ?? "";
+ username = new Elementary.Entry ("Username");
+ if (info.username != null)
+ username.set_text (info.username);
add_label_entry (_("_Username:"), username, true);
- prefix = new Gtk.Entry ();
- prefix.text = info.prefix ?? "";
+ prefix = new Elementary.Entry ("Prefix");
+ if (info.prefix != null)
+ prefix.set_text (info.prefix);
add_label_entry (_("Prefi_x:"), prefix, true);
- sender = new Gtk.Entry ();
- sender.text = info.send ?? "";
+ sender = new Elementary.Entry ("smtp.example.com");
+ if (info.send != null)
+ sender.set_text (info.send);
sender.changed.connect ((widget) => {
/* "stmp." is a common typo, highlight entry if that happens */
if (sender.text.has_prefix ("stmp.")) {
@@ -122,10 +131,29 @@ public class Postler.AccountWidget : Gtk.VBox {
}
});
add_label_entry (_("Sen_ding Server:"), sender, true);
+ if (info.address != null)
+ set_servers_from_address ();
content_area.show_all ();
pack_end (content_area, true, true, 0);
}
+ bool on_focus_out () {
+ set_servers_from_address ();
+ return false;
+ }
+
+ void set_servers_from_address () {
+ string domain = address.get_text ();
+ if (domain == "")
+ return;
+
+ string user = domain.split ("@") [0];
+ domain = domain.split ("@") [1];
+ receiver.set_text ("imap." + domain);
+ sender.set_text ("smtp." + domain);
+ username.set_text (user);
+ }
+
void add_label_entry (string text, Gtk.Widget widget, bool advanced=false) {
var editable = (widget is Gtk.Bin) ? (widget as Gtk.Bin).get_child () : widget;
var hbox = new Gtk.HBox (false, 0);
@@ -137,9 +165,9 @@ public class Postler.AccountWidget : Gtk.VBox {
label.set_mnemonic_widget (editable);
sizegroup.add_widget (label);
hbox.pack_start (label, false, false, 4);
- if (editable is Gtk.Entry) {
+ if (editable is Elementary.Entry) {
label.xalign = 1.0f;
- (editable as Gtk.Entry).activate.connect ((editable) => {
+ (editable as Elementary.Entry).activate.connect ((editable) => {
apply (); });
}
else {
@@ -151,35 +179,35 @@ public class Postler.AccountWidget : Gtk.VBox {
public void apply () {
if (info.type == AccountType.SEARCH) {
- info.path = "search:" + header.text + "/" + filter.text;
+ info.path = "search:" + header.get_text () + "/" + filter.get_text ();
done (info);
return;
}
if (info.name == null)
- info.name = address.text;
+ info.name = address.get_text ();
/* Reset localised folders on server changes */
- if (info.address != address.text
- || info.password != password.text
- || info.receive != null && info.receive != receiver.text
- || info.username != null && info.username != username.text
- || info.prefix != null && info.prefix != username.text
- || info.send != null && info.send != sender.text) {
+ if (info.address != address.get_text ()
+ || info.password != password.get_text ()
+ || info.receive != null && info.receive != receiver.get_text ()
+ || info.username != null && info.username != username.get_text ()
+ || info.prefix != null && info.prefix != username.get_text ()
+ || info.send != null && info.send != sender.get_text ()) {
for (int i = 1; i < FolderType.MAX; i++)
info.folders[i] = null;
}
- info.realname = realname.text;
- info.address = address.text;
- info.password = password.text;
+ info.realname = realname.get_text ();
+ info.address = address.get_text ();
+ info.password = password.get_text ();
- info.organization = organization.text != "" ? organization.text : null;
+ info.organization = organization.get_text () != "" ? organization.get_text () : null;
info.signature = signature.buffer.text != "" ? signature.buffer.text : null;
- info.receive = receiver.text != "" ? receiver.text : null;
- info.username = username.text != "" ? username.text : null;
- info.prefix = prefix.text != "" ? prefix.text : null;
- info.send = sender.text != "" ? sender.text : null;
+ info.receive = receiver.get_text () != "" ? receiver.get_text () : null;
+ info.username = username.get_text () != "" ? username.get_text () : null;
+ info.prefix = prefix.get_text () != "" ? prefix.get_text () : null;
+ info.send = sender.get_text () != "" ? sender.get_text () : null;
done (info);
}
@@ -217,7 +245,7 @@ public class Postler.AccountSetup : Gtk.Dialog {
setup.set_response_sensitive (Gtk.ResponseType.APPLY, false);
setup.widget.address.changed.connect ((editable) => {
setup.set_response_sensitive (Gtk.ResponseType.APPLY,
- setup.widget.address.text.chr (-1, '@') != null);
+ setup.widget.address.get_text ().chr (-1, '@') != null);
});
setup.show ();
return setup;
@@ -254,7 +282,7 @@ public class Postler.AccountSetup : Gtk.Dialog {
setup.set_default_response (Gtk.ResponseType.APPLY);
setup.widget.address.changed.connect ((editable) => {
setup.set_response_sensitive (Gtk.ResponseType.APPLY,
- setup.widget.address.text.chr (-1, '@') != null);
+ setup.widget.address.get_text ().chr (-1, '@') != null);
});
setup.show ();
return setup;
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index dc0be24..2c5e690 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -18,7 +18,7 @@ public class Postler.Bureau : Gtk.Window {
Gtk.VBox shelf;
Gtk.Toolbar toolbar;
- Gtk.Entry search;
+ Elementary.SearchEntry search;
Gtk.Toolbar search_options;
public Postler.Folders folders;
Gtk.ProgressBar progressbar;
@@ -205,7 +205,7 @@ public class Postler.Bureau : Gtk.Window {
void search_entry_activated () {
var action = actions.get_action ("SearchSubject") as Gtk.RadioAction;
- if (search.text == "") {
+ if (search.get_text () == search.hint_string || search.get_text () == "") {
search_options.hide ();
action.set_current_value (0);
messages.search ("");
@@ -214,16 +214,16 @@ public class Postler.Bureau : Gtk.Window {
switch (action.get_current_value ()) {
case 0:
- messages.search (search.text, "subject");
+ messages.search (search.get_text (), "subject");
break;
case 1:
- messages.search (search.text, "from");
+ messages.search (search.get_text (), "from");
break;
case 2:
- messages.search (search.text, "to");
+ messages.search (search.get_text (), "to");
break;
case 3:
- messages.search (search.text, "fulltext");
+ messages.search (search.get_text (), "fulltext");
break;
default:
assert_not_reached ();
@@ -232,17 +232,9 @@ public class Postler.Bureau : Gtk.Window {
search_options.show ();
}
- void search_entry_changed () {
- if (search.text != "")
- search.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY,
- STOCK_EDIT_CLEAR_SYMBOLIC);
- else
- search.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null);
- }
-
void action_save_search () {
var account_info = new AccountInfo ();
- account_info.name = search.text;
+ account_info.name = search.get_text ();
account_info.type = AccountType.SEARCH;
unowned string header;
@@ -263,7 +255,7 @@ public class Postler.Bureau : Gtk.Window {
default:
assert_not_reached ();
}
- account_info.path = "search:" + header + "/" + search.text;
+ account_info.path = "search:" + header + "/" + search.get_text ();
accounts.add_info (account_info);
folders.populate ();
}
@@ -568,12 +560,9 @@ public class Postler.Bureau : Gtk.Window {
actions.get_action ("MessageNew").is_important = true;
var toolitem = new Gtk.ToolItem ();
toolbar.insert (toolitem, -1);
- search = new Gtk.Entry ();
- search.set_icon_from_stock (Gtk.EntryIconPosition.PRIMARY, STOCK_EDIT_FIND_SYMBOLIC);
+ search = new Elementary.SearchEntry ("Type To Search...");
search.activate.connect (search_entry_activated);
- search.changed.connect (search_entry_changed);
- search.icon_release.connect ((position, event) => {
- search.text = "";
+ search.icon_press.connect_after ((position, event) => {
search.activate ();
} );
toolitem.add (search);
@@ -718,7 +707,7 @@ public class Postler.Bureau : Gtk.Window {
var continue_button = new Gtk.Button.with_mnemonic (_("_Continue"));
continue_button.sensitive = false;
welcome.address.changed.connect (() => {
- continue_button.sensitive = welcome.address.text.chr (-1, '@') != null;
+ continue_button.sensitive = welcome.address.get_text ().chr (-1, '@') != null;
});
continue_button.clicked.connect (() => {
welcome.apply ();
@@ -726,7 +715,7 @@ public class Postler.Bureau : Gtk.Window {
continue_box.pack_end (continue_button, false, false, 0);
messages_box.pack_end (continue_box, false, false, 0);
welcome.done.connect ((info) => {
- if (welcome.address.text.chr (-1, '@') == null)
+ if (welcome.address.get_text ().chr (-1, '@') == null)
return;
welcome_box.hide ();
continue_box.hide ();
More information about the Xfce4-commits
mailing list