aboutsummaryrefslogtreecommitdiff
path: root/src/formatter-desktop.cpp
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-14 23:07:10 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-14 23:07:10 -0600
commitee64bb2698adfe27e55615a8856b0e2c78ad8469 (patch)
treeb8fb6e1440ac700f7f51e5c765303abb315c6399 /src/formatter-desktop.cpp
parent3b8833efe6ab21387b6f73b4a4ef757445801623 (diff)
downloadayatana-indicator-datetime-ee64bb2698adfe27e55615a8856b0e2c78ad8469.tar.gz
ayatana-indicator-datetime-ee64bb2698adfe27e55615a8856b0e2c78ad8469.tar.bz2
ayatana-indicator-datetime-ee64bb2698adfe27e55615a8856b0e2c78ad8469.zip
Function: add fully-tested ActionGroups, per-profile Menus, state object.
Form: Add code annotations/comments. Remove dead code. Use Mir style guide. Todo: GSettings toggles, sync with new dbus-test-runner API, get GNOME Panel building again
Diffstat (limited to 'src/formatter-desktop.cpp')
-rw-r--r--src/formatter-desktop.cpp258
1 files changed, 130 insertions, 128 deletions
diff --git a/src/formatter-desktop.cpp b/src/formatter-desktop.cpp
index 8390967..3f942f4 100644
--- a/src/formatter-desktop.cpp
+++ b/src/formatter-desktop.cpp
@@ -35,165 +35,167 @@ class DesktopFormatter::Impl
{
public:
- Impl (DesktopFormatter * owner, const std::shared_ptr<Clock>& clock):
- owner_(owner),
- clock_(clock),
- settings_(g_settings_new(SETTINGS_INTERFACE))
- {
- const gchar * const keys[] = { "changed::" SETTINGS_SHOW_SECONDS_S,
- "changed::" SETTINGS_TIME_FORMAT_S,
- "changed::" SETTINGS_TIME_FORMAT_S,
- "changed::" SETTINGS_CUSTOM_TIME_FORMAT_S,
- "changed::" SETTINGS_SHOW_DAY_S,
- "changed::" SETTINGS_SHOW_DATE_S,
- "changed::" SETTINGS_SHOW_YEAR_S };
- for (guint i=0, n=G_N_ELEMENTS(keys); i<n; i++)
- g_signal_connect(settings_, keys[i], G_CALLBACK(onSettingsChanged), this);
-
- rebuildHeaderFormat();
- }
+Impl(DesktopFormatter * owner, const std::shared_ptr<Clock>& clock):
+ m_owner(owner),
+ m_clock(clock),
+ m_settings(g_settings_new(SETTINGS_INTERFACE))
+{
+ const gchar * const keys[] = { "changed::" SETTINGS_SHOW_SECONDS_S,
+ "changed::" SETTINGS_TIME_FORMAT_S,
+ "changed::" SETTINGS_TIME_FORMAT_S,
+ "changed::" SETTINGS_CUSTOM_TIME_FORMAT_S,
+ "changed::" SETTINGS_SHOW_DAY_S,
+ "changed::" SETTINGS_SHOW_DATE_S,
+ "changed::" SETTINGS_SHOW_YEAR_S };
+ for(const auto& key : keys)
+ g_signal_connect(m_settings, key, G_CALLBACK(onSettingsChanged), this);
+
+ rebuildHeaderFormat();
+}
- ~Impl()
- {
- g_signal_handlers_disconnect_by_data (settings_, this);
- g_object_unref (settings_);
- }
+~Impl()
+{
+ g_signal_handlers_disconnect_by_data(m_settings, this);
+ g_object_unref(m_settings);
+}
private:
- static void onSettingsChanged (GSettings * changed G_GNUC_UNUSED,
- const gchar * key G_GNUC_UNUSED,
- gpointer gself)
- {
- static_cast<Impl*>(gself)->rebuildHeaderFormat();
- }
+static void onSettingsChanged(GSettings * /*changed*/,
+ const gchar * /*key*/,
+ gpointer gself)
+{
+ static_cast<Impl*>(gself)->rebuildHeaderFormat();
+}
- void rebuildHeaderFormat()
- {
- gchar * fmt = getHeaderLabelFormatString (settings_);
- owner_->headerFormat.set(fmt);
- g_free (fmt);
- }
+void rebuildHeaderFormat()
+{
+ auto fmt = getHeaderLabelFormatString(m_settings);
+ m_owner->headerFormat.set(fmt);
+ g_free(fmt);
+}
private:
- gchar* getHeaderLabelFormatString (GSettings * s) const
- {
- char * fmt;
- const TimeFormatMode mode = (TimeFormatMode) g_settings_get_enum (s, SETTINGS_TIME_FORMAT_S);
-
- if (mode == TIME_FORMAT_MODE_CUSTOM)
- {
- fmt = g_settings_get_string (s, SETTINGS_CUSTOM_TIME_FORMAT_S);
- }
- else
- {
- const bool show_day = g_settings_get_boolean (s, SETTINGS_SHOW_DAY_S);
- const bool show_date = g_settings_get_boolean (s, SETTINGS_SHOW_DATE_S);
- const bool show_year = show_date && g_settings_get_boolean (s, SETTINGS_SHOW_YEAR_S);
- const char * date_fmt = getDateFormat (show_day, show_date, show_year);
- const char * time_fmt = getFullTimeFormatString (s);
- fmt = joinDateAndTimeFormatStrings (date_fmt, time_fmt);
- }
-
- return fmt;
- }
+gchar* getHeaderLabelFormatString(GSettings* s) const
+{
+ char * fmt;
+ const auto mode = g_settings_get_enum(s, SETTINGS_TIME_FORMAT_S);
- const gchar* T_(const gchar* in) const
+ if (mode == TIME_FORMAT_MODE_CUSTOM)
{
- return owner_->T_(in);
+ fmt = g_settings_get_string(s, SETTINGS_CUSTOM_TIME_FORMAT_S);
}
-
- const gchar* getDateFormat (bool show_day, bool show_date, bool show_year) const
+ else
{
- const char * fmt;
-
- if (show_day && show_date && show_year)
- /* TRANSLATORS: a strftime(3) format showing the weekday, date, and year */
- fmt = T_("%a %b %e %Y");
- else if (show_day && show_date)
- fmt = T_("%a %b %e");
- else if (show_day && show_year)
- /* TRANSLATORS: a strftime(3) format showing the weekday and year. */
- fmt = T_("%a %Y");
- else if (show_day)
- /* TRANSLATORS: a strftime(3) format showing the weekday. */
- fmt = T_("%a");
- else if (show_date && show_year)
- /* TRANSLATORS: a strftime(3) format showing the date and year */
- fmt = T_("%b %e %Y");
- else if (show_date)
- /* TRANSLATORS: a strftime(3) format showing the date */
- fmt = T_("%b %e");
- else if (show_year)
- /* TRANSLATORS: a strftime(3) format showing the year */
- fmt = T_("%Y");
- else
- fmt = nullptr;
-
- return fmt;
+ const auto show_day = g_settings_get_boolean(s, SETTINGS_SHOW_DAY_S);
+ const auto show_date = g_settings_get_boolean(s, SETTINGS_SHOW_DATE_S);
+ const auto show_year = show_date && g_settings_get_boolean(s, SETTINGS_SHOW_YEAR_S);
+ const auto date_fmt = getDateFormat(show_day, show_date, show_year);
+ const auto time_fmt = getFullTimeFormatString(s);
+ fmt = joinDateAndTimeFormatStrings(date_fmt, time_fmt);
}
- const gchar * getFullTimeFormatString (GSettings * settings) const
- {
- const bool show_seconds = g_settings_get_boolean (settings, SETTINGS_SHOW_SECONDS_S);
+ return fmt;
+}
+
+const gchar* T_(const gchar* in) const
+{
+ return m_owner->T_(in);
+}
- bool twelvehour;
- switch (g_settings_get_enum (settings, SETTINGS_TIME_FORMAT_S))
- {
- case TIME_FORMAT_MODE_LOCALE_DEFAULT:
- twelvehour = is_locale_12h();
- break;
+const gchar* getDateFormat(bool show_day, bool show_date, bool show_year) const
+{
+ const char * fmt;
+
+ if (show_day && show_date && show_year)
+ /* TRANSLATORS: a strftime(3) format showing the weekday, date, and year */
+ fmt = T_("%a %b %e %Y");
+ else if (show_day && show_date)
+ /* TRANSLATORS: a strftime(3) format showing the weekday and date */
+ fmt = T_("%a %b %e");
+ else if (show_day && show_year)
+ /* TRANSLATORS: a strftime(3) format showing the weekday and year. */
+ fmt = T_("%a %Y");
+ else if (show_day)
+ /* TRANSLATORS: a strftime(3) format showing the weekday. */
+ fmt = T_("%a");
+ else if (show_date && show_year)
+ /* TRANSLATORS: a strftime(3) format showing the date and year */
+ fmt = T_("%b %e %Y");
+ else if (show_date)
+ /* TRANSLATORS: a strftime(3) format showing the date */
+ fmt = T_("%b %e");
+ else if (show_year)
+ /* TRANSLATORS: a strftime(3) format showing the year */
+ fmt = T_("%Y");
+ else
+ fmt = nullptr;
+
+ return fmt;
+}
- case TIME_FORMAT_MODE_24_HOUR:
- twelvehour = FALSE;
- break;
+const gchar* getFullTimeFormatString(GSettings* settings) const
+{
+ auto show_seconds = g_settings_get_boolean(settings, SETTINGS_SHOW_SECONDS_S);
+
+ bool twelvehour;
+ switch (g_settings_get_enum(settings, SETTINGS_TIME_FORMAT_S))
+ {
+ case TIME_FORMAT_MODE_LOCALE_DEFAULT:
+ twelvehour = is_locale_12h();
+ break;
- default:
- twelvehour = TRUE;
- break;
- }
+ case TIME_FORMAT_MODE_24_HOUR:
+ twelvehour = false;
+ break;
- return owner_->getDefaultHeaderTimeFormat (twelvehour, show_seconds);
+ default:
+ twelvehour = true;
+ break;
}
- gchar* joinDateAndTimeFormatStrings (const char * date_string, const char * time_string) const
+ return m_owner->getDefaultHeaderTimeFormat(twelvehour, show_seconds);
+}
+
+gchar* joinDateAndTimeFormatStrings(const char* date_string,
+ const char* time_string) const
+{
+ gchar * str;
+
+ if (date_string && time_string)
+ {
+ /* TRANSLATORS: This is a format string passed to strftime to
+ * combine the date and the time. The value of "%s\u2003%s"
+ * will result in a string like this in US English 12-hour time:
+ * 'Fri Jul 16 11:50 AM'. The space in between date and time is
+ * a Unicode en space (E28082 in UTF-8 hex). */
+ str = g_strdup_printf("%s\u2003%s", date_string, time_string);
+ }
+ else if (date_string)
+ {
+ str = g_strdup(date_string);
+ }
+ else // time_string
{
- gchar * str;
-
- if (date_string && time_string)
- {
- /* TRANSLATORS: This is a format string passed to strftime to combine the
- * date and the time. The value of "%s\u2003%s" will result in a
- * string like this in US English 12-hour time: 'Fri Jul 16 11:50 AM'.
- * The space in between date and time is a Unicode en space
- * (E28082 in UTF-8 hex). */
- str = g_strdup_printf ("%s\u2003%s", date_string, time_string);
- }
- else if (date_string)
- {
- str = g_strdup (date_string);
- }
- else // time_string
- {
- str = g_strdup (time_string);
- }
-
- return str;
+ str = g_strdup(time_string);
}
+ return str;
+}
+
private:
- DesktopFormatter * const owner_;
- std::shared_ptr<Clock> clock_;
- GSettings * settings_;
+DesktopFormatter * const m_owner;
+std::shared_ptr<Clock> m_clock;
+GSettings * m_settings;
};
/***
****
***/
-DesktopFormatter::DesktopFormatter (const std::shared_ptr<Clock>& clock):
+DesktopFormatter::DesktopFormatter(const std::shared_ptr<Clock>& clock):
Formatter(clock),
p(new Impl(this, clock))
{