diff options
Diffstat (limited to 'DClock.vala')
-rw-r--r-- | DClock.vala | 389 |
1 files changed, 194 insertions, 195 deletions
diff --git a/DClock.vala b/DClock.vala index 14abcc1..f59b4f9 100644 --- a/DClock.vala +++ b/DClock.vala @@ -4,233 +4,232 @@ using Pango; using Panel; public class DClock : Panel.Applet { - private Gtk.ToggleButton button = null; - private Gtk.Label label = null; - private Panel.AppletOrient orient = (Panel.AppletOrient)(-1); - private BonoboUI.Verb[] verbs = null; - private time_t current_time; - private uint timeout = 0; + private Gtk.ToggleButton button = null; + private Gtk.Label label = null; + private Panel.AppletOrient orient = (Panel.AppletOrient)(-1); + private BonoboUI.Verb[] verbs = null; + private time_t current_time; + private uint timeout = 0; - private int size; - private int fixed_width = -1; - private int fixed_height = -1; - private Gtk.Allocation old_allocation; - - public DClock() { - } - - static construct { - Gtk.rc_parse_string("\n" + - " style \"dclock-applet-button-style\"\n" + - " {\n" + - " GtkWidget::focus-line-width=0\n" + - " GtkWidget::focus-padding=0\n" + - " }\n" + - "\n" + - " widget \"*.dclock-applet-button\" style \"dclock-applet-button-style\"\n" + - "\n"); - } - - private void create() { - set_flags(Panel.AppletFlags.EXPAND_MINOR); + private int size; + private int fixed_width = -1; + private int fixed_height = -1; + private Gtk.Allocation old_allocation; + + public DClock() { + } + + static construct { + Gtk.rc_parse_string("\n" + + " style \"dclock-applet-button-style\"\n" + + " {\n" + + " GtkWidget::focus-line-width=0\n" + + " GtkWidget::focus-padding=0\n" + + " }\n" + + "\n" + + " widget \"*.dclock-applet-button\" style \"dclock-applet-button-style\"\n" + + "\n"); + } + + private void create() { + set_flags(Panel.AppletFlags.EXPAND_MINOR); - button = new Gtk.ToggleButton(); - button.set_relief(Gtk.ReliefStyle.NONE); - button.set_name("dclock-applet-button"); - GLib.Signal.connect(button, "button_press_event", (GLib.Callback)do_not_eat_button_press, null); - GLib.Signal.connect(this, "change_orient", (GLib.Callback)applet_change_orient, this); - GLib.Signal.connect(button, "size_allocate", (GLib.Callback)change_pixel_size, this); - this.add(button); + button = new Gtk.ToggleButton(); + button.set_relief(Gtk.ReliefStyle.NONE); + button.set_name("dclock-applet-button"); + GLib.Signal.connect(button, "button_press_event", (GLib.Callback)do_not_eat_button_press, null); + GLib.Signal.connect(this, "change_orient", (GLib.Callback)applet_change_orient, this); + GLib.Signal.connect(button, "size_allocate", (GLib.Callback)change_pixel_size, this); + this.add(button); - label = new Gtk.Label(null); - GLib.Signal.connect(label, "size_request", (GLib.Callback)clock_size_request, this); - GLib.Signal.connect_swapped(label, "style_set", (GLib.Callback)unfix_size, this); - label.set_justify(Gtk.Justification.CENTER); - clock_update_text_gravity(label); - GLib.Signal.connect(label, "screen-changed", (GLib.Callback)clock_update_text_gravity, null); - button.add(label); + label = new Gtk.Label(null); + GLib.Signal.connect(label, "size_request", (GLib.Callback)clock_size_request, this); + GLib.Signal.connect_swapped(label, "style_set", (GLib.Callback)unfix_size, this); + label.set_justify(Gtk.Justification.CENTER); + clock_update_text_gravity(label); + GLib.Signal.connect(label, "screen-changed", (GLib.Callback)clock_update_text_gravity, null); + button.add(label); - set_border_width(0); - size = (int)get_size(); + set_border_width(0); + size = (int)get_size(); - set_background_widget(this); + set_background_widget(this); - verbs = new BonoboUI.Verb[2]; + verbs = new BonoboUI.Verb[2]; - verbs[0].cname = "About"; - verbs[0].cb = on_about_clicked; - verbs[0].user_data = this; + verbs[0].cname = "About"; + verbs[0].cb = on_about_clicked; + verbs[0].user_data = this; - verbs[1].cname = null; - verbs[1].cb = null; - verbs[1].user_data = null; + verbs[1].cname = null; + verbs[1].cb = null; + verbs[1].user_data = null; - string menuxml = "<popup name=\"button3\">" + - "<menuitem name=\"About Item\" verb=\"About\" _label=\"About\" pixtype=\"stock\" pixname=\"gnome-stock-about\"/>" + - "</popup>"; - setup_menu(menuxml, verbs, this); + string menuxml = "<popup name=\"button3\">" + + "<menuitem name=\"About Item\" verb=\"About\" _label=\"About\" pixtype=\"stock\" pixname=\"gnome-stock-about\"/>" + + "</popup>"; + setup_menu(menuxml, verbs, this); - show_all(); + show_all(); - refresh_clock_timeout(); - applet_change_orient(this, get_orient(), this); - } - - private void unfix_size() { - fixed_width = -1; - fixed_height = -1; - button.queue_resize(); - } - - private static void clock_size_request (Gtk.Widget clock, Gtk.Requisition req, DClock data) { - if(req.width > data.fixed_width) - data.fixed_width = req.width; - if (req.height > data.fixed_height) - data.fixed_height = req.height; - req.width = data.fixed_width; - req.height = data.fixed_height; - } + refresh_clock_timeout(); + applet_change_orient(this, get_orient(), this); + } + + private void unfix_size() { + fixed_width = -1; + fixed_height = -1; + button.queue_resize(); + } + + private static void clock_size_request (Gtk.Widget clock, Gtk.Requisition req, DClock data) { + if(req.width > data.fixed_width) + data.fixed_width = req.width; + if (req.height > data.fixed_height) + data.fixed_height = req.height; + req.width = data.fixed_width; + req.height = data.fixed_height; + } - private static void clock_update_text_gravity(Gtk.Label label) { - Pango.Layout layout; - Pango.Context context; - - layout = label.get_layout(); - context = layout.get_context(); - context.set_base_gravity(Pango.Gravity.AUTO); - } - private void update_timeformat() { - - } - - private void update_clock() { - current_time = time_t(); - string date_str = DDate.with_time_t(current_time).to_string(); - string time_str = Time.local(current_time).format("%H:%M"); - - label.set_text(date_str + ", " + time_str); - - update_orient(); - button.queue_resize(); - } - - /*private void refresh_clock() { - unfix_size(); - update_clock(); - }*/ + private static void clock_update_text_gravity(Gtk.Label label) { + Pango.Layout layout; + Pango.Context context; + + layout = label.get_layout(); + context = layout.get_context(); + context.set_base_gravity(Pango.Gravity.AUTO); + } + private void update_timeformat() { + + } + + private void update_clock() { + current_time = time_t(); + string date_str = DDate.with_time_t(current_time).to_string(); + string time_str = Time.local(current_time).format("%H:%M"); + + label.set_text(date_str + ", " + time_str); + + update_orient(); + button.queue_resize(); + } + + /*private void refresh_clock() { + unfix_size(); + update_clock(); + }*/ - private void refresh_clock_timeout() { - unfix_size(); + private void refresh_clock_timeout() { + unfix_size(); - update_timeformat(); + update_timeformat(); - if (timeout != 0) - GLib.Source.remove (timeout); + if (timeout != 0) + GLib.Source.remove (timeout); - update_clock(); + update_clock(); - clock_set_timeout(current_time); - } + clock_set_timeout(current_time); + } - /*private void refresh_click_timeout_time_only() { - if (timeout != 0) - GLib.Source.remove (timeout); - - clock_timeout_callback(this); - }*/ - - private void clock_set_timeout(time_t now) { - uint timeouttime; - - GLib.TimeVal tv = GLib.TimeVal(); - - timeouttime = (uint)((1000000 - tv.tv_usec)/1000 + 1 + 1000*(59 - now % 60)); - - timeout = GLib.Timeout.add (timeouttime, clock_timeout_callback); - } - - private bool clock_timeout_callback() { - time_t new_time = time_t(); - - if(new_time/60 != current_time/60) { - update_clock(); - } - - clock_set_timeout(new_time); - - return false; - } - - private static void on_about_clicked(BonoboUI.Component component, void* user_data, string cname) { + /*private void refresh_click_timeout_time_only() { + if (timeout != 0) + GLib.Source.remove (timeout); + + clock_timeout_callback(this); + }*/ + + private void clock_set_timeout(time_t now) { + uint timeouttime; + + GLib.TimeVal tv = GLib.TimeVal(); + + timeouttime = (uint)((1000000 - tv.tv_usec)/1000 + 1 + 1000*(59 - now % 60)); - } + timeout = GLib.Timeout.add (timeouttime, clock_timeout_callback); + } - private static bool do_not_eat_button_press(Gtk.Widget widget, Gdk.EventButton event) { - if(event.button != 1) - GLib.Signal.stop_emission_by_name(widget, "button_press_event"); + private bool clock_timeout_callback() { + time_t new_time = time_t(); + + if(new_time/60 != current_time/60) { + update_clock(); + } + + clock_set_timeout(new_time); + + return false; + } + + private static void on_about_clicked(BonoboUI.Component component, void* user_data, string cname) { + + } - return false; - } + private static bool do_not_eat_button_press(Gtk.Widget widget, Gdk.EventButton event) { + if(event.button != 1) + GLib.Signal.stop_emission_by_name(widget, "button_press_event"); - private static void change_pixel_size(Gtk.Widget widget, Gtk.Allocation allocation, DClock clock) { - if(clock.old_allocation.width == allocation.width && clock.old_allocation.height == allocation.height) - return; + return false; + } + + private static void change_pixel_size(Gtk.Widget widget, Gtk.Allocation allocation, DClock clock) { + if(clock.old_allocation.width == allocation.width && clock.old_allocation.height == allocation.height) + return; - clock.old_allocation.width = allocation.width; - clock.old_allocation.height = allocation.height; + clock.old_allocation.width = allocation.width; + clock.old_allocation.height = allocation.height; - int new_size; + int new_size; - if(clock.orient == Panel.AppletOrient.LEFT || clock.orient == Panel.AppletOrient.RIGHT) - new_size = allocation.width; - else - new_size = allocation.height; + if(clock.orient == Panel.AppletOrient.LEFT || clock.orient == Panel.AppletOrient.RIGHT) + new_size = allocation.width; + else + new_size = allocation.height; - clock.size = new_size; + clock.size = new_size; - clock.unfix_size(); - clock.update_timeformat(); - clock.update_clock(); - } + clock.unfix_size(); + clock.update_timeformat(); + clock.update_clock(); + } - void update_orient() { - double new_angle; - double angle; + void update_orient() { + double new_angle; + double angle; - if(orient == Panel.AppletOrient.LEFT) - new_angle = 270; - else if(orient == Panel.AppletOrient.RIGHT) - new_angle = 90; - else - new_angle = 0; + if(orient == Panel.AppletOrient.LEFT) + new_angle = 270; + else if(orient == Panel.AppletOrient.RIGHT) + new_angle = 90; + else + new_angle = 0; - angle = label.get_angle(); - if (angle != new_angle) { - unfix_size(); - label.set_angle(new_angle); - } - } + angle = label.get_angle(); + if (angle != new_angle) { + unfix_size(); + label.set_angle(new_angle); + } + } - private static void applet_change_orient(Panel.Applet applet, Panel.AppletOrient orient, DClock clock) { - if(orient == clock.orient) - return; + private static void applet_change_orient(Panel.Applet applet, Panel.AppletOrient orient, DClock clock) { + if(orient == clock.orient) + return; - clock.orient = orient; + clock.orient = orient; - clock.unfix_size(); - clock.update_clock(); - //update_calendar_popup (cd); - } - - private static bool factory(DClock applet, string iid, void *data) { - applet.create(); - return true; - } - - public static int main(string[] args) { - Gnome.Program.init("DClock", "0", Gnome.libgnomeui_module, args); - return Panel.Applet.factory_main("OAFIID:GNOME_DClock_Factory", typeof(DClock), (Panel.AppletFactoryCallback)factory); - } + clock.unfix_size(); + clock.update_clock(); + //update_calendar_popup (cd); + } + + private static bool factory(DClock applet, string iid, void *data) { + applet.create(); + return true; + } + + public static int main(string[] args) { + Gnome.Program.init("DClock", "0", Gnome.libgnomeui_module, args); + return Panel.Applet.factory_main("OAFIID:GNOME_DClock_Factory", typeof(DClock), (Panel.AppletFactoryCallback)factory); + } } - |