-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathclock.cpp
More file actions
62 lines (51 loc) · 1.74 KB
/
clock.cpp
File metadata and controls
62 lines (51 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <glibmm.h>
#include "clock.hpp"
void WayfireClock::init(Gtk::Box *container)
{
button = std::make_unique<WayfireMenuButton>("panel");
button->add_css_class("clock");
button->set_child(label);
button->show();
label.set_justify(Gtk::Justification::CENTER);
label.show();
update_label();
calendar.show();
button->get_popover()->add_css_class("clock-popover");
button->get_children()[0]->add_css_class("flat");
button->get_popover()->set_child(calendar);
btn_sig = button->get_popover()->signal_show().connect(
sigc::mem_fun(*this, &WayfireClock::on_calendar_shown));
container->append(*button);
timeout = Glib::signal_timeout().connect_seconds(
sigc::mem_fun(*this, &WayfireClock::update_label), 1);
}
void WayfireClock::on_calendar_shown()
{
auto now = Glib::DateTime::create_now_local();
/* GDateTime uses month in 1-12 format while GClender uses 0-11 */
// calendar.set_month(now.get_month() - 1, now.get_year());
calendar.select_day(now);
}
bool WayfireClock::update_label()
{
auto time = Glib::DateTime::create_now_local();
auto text = time.format(format.value());
/* Sometimes GLib::DateTime will add leading spaces. This results in
* unevenly balanced padding around the text, which looks quite bad.
*
* This could be circumvented with the modifiers the user passes to the
* format string, * but to remove the requirement that the user does
* something fancy, we just remove any leading spaces. */
int i = 0;
while (i < (int)text.length() && text[i] == ' ')
{
i++;
}
label.set_text(text.substr(i));
return 1;
}
WayfireClock::~WayfireClock()
{
btn_sig.disconnect();
timeout.disconnect();
}