Merge lp:~achmyr/docky/large-clock into lp:docky

Proposed by Alex Chmyr
Status: Needs review
Proposed branch: lp:~achmyr/docky/large-clock
Merge into: lp:docky
Diff against target: 175 lines (+91/-9)
1 file modified
StandardPlugins/Clock/src/ClockDockItem.cs (+91/-9)
To merge this branch: bzr merge lp:~achmyr/docky/large-clock
Reviewer Review Type Date Requested Status
Docky Core Pending
Review via email: mp+63450@code.launchpad.net

Description of the change

This is minor update to Clock Docklet to make it full-sized. For this change, there was added:
- 1 new option to menu - "Large Digital Clock" - digits occupying whole Docky height
- Added seconds and changed appropriate timer

To post a comment you must log in.

Unmerged revisions

1810. By Alex Chmyr

Added Large clock

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'StandardPlugins/Clock/src/ClockDockItem.cs'
2--- StandardPlugins/Clock/src/ClockDockItem.cs 2011-03-13 16:47:29 +0000
3+++ StandardPlugins/Clock/src/ClockDockItem.cs 2011-06-04 03:03:29 +0000
4@@ -69,6 +69,19 @@
5 }
6 }
7
8+ bool large_digital = prefs.Get<bool> ("ShowLargeDigital", false);
9+ bool ShowLargeDigital {
10+ get { return large_digital; }
11+ set {
12+ if (large_digital == value)
13+ return;
14+ large_digital = value;
15+ prefs.Set<bool> ("ShowLargeDigital", value);
16+ CheckForThemes ();
17+ ScalableRendering = !large_digital;
18+ }
19+ }
20+
21 bool show_date = prefs.Get<bool> ("ShowDate", false);
22 bool ShowDate {
23 get { return show_date; }
24@@ -148,11 +161,20 @@
25 painter = new CalendarPainter ();
26 CheckForThemes ();
27
28- timer = GLib.Timeout.Add (1000, ClockUpdateTimer);
29+ timer = GLib.Timeout.Add (100, ClockUpdateTimer);
30 }
31
32 public override bool Square {
33- get { return !IsSmall || !ShowDigital; }
34+ get { return !(IsSmall && ShowDigital) && !ShowLargeDigital; }
35+ }
36+
37+ int LargeClockSize (int size){
38+ int resultSize = (int)(4.5 * size) + 5;
39+ if(ShowDate)
40+ resultSize += 6 * size;
41+ if(!ShowMilitary)
42+ resultSize += (int)(1.5 * size);
43+ return resultSize;
44 }
45
46 public override string UniqueID ()
47@@ -162,7 +184,7 @@
48
49 bool ClockUpdateTimer ()
50 {
51- if (minute != DateTime.UtcNow.Minute) {
52+ if (ShowLargeDigital || minute != DateTime.UtcNow.Minute) {
53 QueueRedraw ();
54 minute = DateTime.UtcNow.Minute;
55 }
56@@ -184,7 +206,9 @@
57 {
58 if (Square)
59 return base.CreateIconBuffer (model, size);
60- else
61+ else if(ShowLargeDigital)
62+ return new DockySurface (LargeClockSize(size), size, model);
63+ else
64 return new DockySurface (2 * size, size, model);
65 }
66
67@@ -197,9 +221,11 @@
68
69 if (!ShowDigital)
70 MakeAnalogIcon (surface.Context, Math.Min (surface.Width, surface.Height));
71- else if (Square)
72+ else if (ShowLargeDigital)
73+ MakeLargeDigitalIcon(surface);
74+ else if (Square)
75 MakeSquareDigitalIcon (surface);
76- else
77+ else
78 MakeRectangularDigitalIcon (surface);
79 }
80
81@@ -305,7 +331,7 @@
82 layout.FontDescription = new Gtk.Style().FontDescription;
83 layout.FontDescription.Weight = Pango.Weight.Bold;
84 layout.Ellipsize = Pango.EllipsizeMode.None;
85- layout.Width = Pango.Units.FromPixels (surface.Width);
86+ layout.Width = (surface.Width);
87
88
89 // draw the time, outlined
90@@ -370,6 +396,54 @@
91 }
92 }
93
94+ void MakeLargeDigitalIcon (DockySurface surface)
95+ {
96+ Context cr = surface.Context;
97+
98+ // shared by all text
99+ using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) {
100+ layout.FontDescription = new Gtk.Style().FontDescription;
101+ layout.FontDescription.Weight = Pango.Weight.Bold;
102+ layout.Ellipsize = Pango.EllipsizeMode.None;
103+ layout.Width = surface.Width;
104+ layout.SingleParagraphMode = true;
105+
106+ // draw the time, outlined
107+ layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (surface.Height - 2);
108+
109+ int xDateOffset = 5;
110+ if(ShowDate) {
111+ drawText(cr, layout, xDateOffset, 0, DateTime.Now.ToString("ddd,"));
112+ xDateOffset += (int)(2.5 * surface.Height);
113+ drawText(cr, layout, xDateOffset, 0, DateTime.Now.ToString("MMM"));
114+ xDateOffset += (int)(1.8 * surface.Height);
115+ drawText(cr, layout, xDateOffset, 0, DateTime.Now.ToString("dd"));
116+ xDateOffset += (int)(1.5 * surface.Height);
117+ }
118+
119+ if(ShowMilitary) {
120+ drawText(cr, layout, xDateOffset, 0, DateTime.Now.ToString("HH:mm:ss"));
121+ } else {
122+ drawText(cr, layout, xDateOffset, 0, DateTime.Now.ToString("h:mm:ss"));
123+ drawText(cr, layout, xDateOffset + (int)(4.5 * surface.Height), 0, DateTime.Now.ToString("tt"));
124+ }
125+ layout.FontDescription.Dispose ();
126+ layout.Context.Dispose ();
127+ }
128+ }
129+
130+ void drawText(Context cr, Pango.Layout layout, int x, int y, string text) {
131+ layout.SetMarkup(text);
132+ cr.MoveTo (x, y);
133+ Pango.CairoHelper.LayoutPath (cr, layout);
134+ cr.LineWidth = 2;
135+ cr.Color = new Cairo.Color (0, 0, 0, 0.5);
136+ cr.StrokePreserve ();
137+ cr.Color = new Cairo.Color (1, 1, 1, 0.8);
138+ cr.Fill ();
139+
140+ }
141+
142 void MakeAnalogIcon (Context cr, int size)
143 {
144 int center = size / 2;
145@@ -409,7 +483,7 @@
146
147 protected override ClickAnimation OnClicked (uint button, Gdk.ModifierType mod, double xPercent, double yPercent)
148 {
149- if (button == 1)
150+ if (button == 1 && !ShowLargeDigital)
151 ShowPainter (painter);
152 return ClickAnimation.None;
153 }
154@@ -428,12 +502,20 @@
155 protected override MenuList OnGetMenuItems ()
156 {
157 MenuList list = base.OnGetMenuItems ();
158+
159 list[MenuListContainer.Actions].Add (new IconMenuItem (Catalog.GetString ("Di_gital Clock"), ShowDigital ? "gtk-apply" : "gtk-remove", (o, a) =>
160 {
161 ShowDigital = !ShowDigital;
162 QueueRedraw ();
163 }));
164-
165+ if(ShowDigital) {
166+ list[MenuListContainer.Actions].Add (new IconMenuItem (Catalog.GetString ("L_arge Digital Clock"), ShowLargeDigital ? "gtk-apply" : "gtk-remove", (o, a) =>
167+ {
168+ ShowLargeDigital = !ShowLargeDigital;
169+ QueueRedraw ();
170+ }));
171+ }
172+
173 list[MenuListContainer.Actions].Add (new IconMenuItem (Catalog.GetString ("24-Hour _Clock"), ShowMilitary ? "gtk-apply" : "gtk-remove", (o, a) =>
174 {
175 ShowMilitary = !ShowMilitary;

Subscribers

People subscribed via source and target branches

to status/vote changes: