Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AM/PM time format option #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions data/alarm-clock.schemas.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
</locale>
</schema>

<schema>
<key>/schemas/apps/alarm-clock/time_format_12h</key>
<applyto>/apps/alarm-clock/time_format_12h</applyto>
<owner>alarm-clock</owner>
<type>bool</type>
<default>false</default>
<locale name="C">
<short>Use AM/PM format for alarms</short>
<long>Whether to use 12 hour (am/pm) or 24 hour format when
setting alarm times.</long>
</locale>
</schema>

<!--
Alarm specific:
-->
Expand Down Expand Up @@ -162,5 +175,3 @@
-->
</schemalist>
</gconfschemafile>


98 changes: 75 additions & 23 deletions data/alarm-clock.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">99</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="upper">59</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment3">
<property name="upper">59</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment4">
<property name="upper">23</property>
<property name="upper">24</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
<property name="page_increment">2</property>
</object>
<object class="GtkAdjustment" id="adjustment5">
<property name="lower">1</property>
Expand All @@ -19,12 +30,10 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAction" id="delete-action">
<property name="label" translatable="yes">Delete alarm</property>
<property name="short_label" translatable="yes">Delete</property>
<property name="tooltip" translatable="yes">Delete the selected alarm</property>
<property name="stock_id">gtk-delete</property>
<signal name="activate" handler="alarm_action_delete" swapped="no"/>
<object class="GtkToggleAction" id="autostart-action">
<property name="label" translatable="yes">Start automatically at login</property>
<property name="short_label" translatable="yes">Start automatically at login</property>
<signal name="activate" handler="alarm_action_toggle_autostart" swapped="no"/>
</object>
<object class="GtkAction" id="edit-action">
<property name="label" translatable="yes">Edit alarm</property>
Expand All @@ -40,6 +49,11 @@
<property name="stock_id">gtk-yes</property>
<signal name="activate" handler="alarm_action_enabled" swapped="no"/>
</object>
<object class="GtkToggleAction" id="hour-format-action">
<property name="label" translatable="yes">Use AM/PM format for alarm times</property>
<property name="short_label" translatable="yes">Use AM/PM format for alarm times</property>
<signal name="activate" handler="alarm_action_toggle_time_format_12h" swapped="no"/>
</object>
<object class="GtkAction" id="new-action">
<property name="label" translatable="yes">New alarm</property>
<property name="short_label" translatable="yes">New</property>
Expand Down Expand Up @@ -143,16 +157,6 @@ Kamal Mostafa &lt;[email protected]&gt;</property>
</object>
</child>
</object>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">99</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="upper">59</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="alarm-list-window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Alarms</property>
Expand Down Expand Up @@ -595,6 +599,21 @@ Kamal Mostafa &lt;[email protected]&gt;</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="am-pm-button">
<property name="label" translatable="yes">AM</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="am_pm_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
Expand Down Expand Up @@ -821,7 +840,7 @@ Kamal Mostafa &lt;[email protected]&gt;</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="repeat_all_button">
<property name="label" translatable="yes">Every day</property>
<property name="label" translatable="yes">Every Day</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
Expand Down Expand Up @@ -1150,10 +1169,26 @@ Kamal Mostafa &lt;[email protected]&gt;</property>
</columns>
<signal name="rows-reordered" handler="alarm_list_window_rows_reordered" swapped="no"/>
</object>
<object class="GtkToggleAction" id="autostart-action">
<property name="label" translatable="yes">Start automatically at login</property>
<property name="short_label" translatable="yes">Start automatically at login</property>
<signal name="activate" handler="alarm_action_toggle_autostart" swapped="no"/>
<object class="GtkListStore" id="am-pm-list">
<columns>
<!-- column-name value -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">AM</col>
</row>
<row>
<col id="0" translatable="yes">PM</col>
</row>
</data>
</object>
<object class="GtkAction" id="delete-action">
<property name="label" translatable="yes">Delete alarm</property>
<property name="short_label" translatable="yes">Delete</property>
<property name="tooltip" translatable="yes">Delete the selected alarm</property>
<property name="stock_id">gtk-delete</property>
<signal name="activate" handler="alarm_action_delete" swapped="no"/>
</object>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
Expand Down Expand Up @@ -1261,6 +1296,22 @@ Kamal Mostafa &lt;[email protected]&gt;</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="hour-format-check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Use 12 hour format
instead of 24 hour</property>
<property name="related_action">hour-format-action</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down Expand Up @@ -1297,6 +1348,7 @@ Kamal Mostafa &lt;[email protected]&gt;</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="show-label-check">
<property name="label" translatable="yes">Show countdown label</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
Expand Down
25 changes: 22 additions & 3 deletions src/alarm-actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "alarm-actions.h"
#include "alarm-applet.h"
#include "alarm-list-window.h"
#include "alarm-settings.h"

#define GET_ACTION(name) GTK_ACTION (gtk_builder_get_object (builder, (name)))

Expand Down Expand Up @@ -65,6 +66,7 @@ alarm_applet_actions_init (AlarmApplet *applet)

applet->action_toggle_autostart = GTK_TOGGLE_ACTION (GET_ACTION ("autostart-action"));
applet->action_toggle_show_label = GTK_TOGGLE_ACTION (GET_ACTION ("show-label-action"));
applet->action_toggle_time_format_12h = GTK_TOGGLE_ACTION (GET_ACTION ("hour-format-action"));

gtk_action_group_add_action (applet->actions_global, applet->action_new);
gtk_action_group_add_action (applet->actions_global, applet->action_stop_all);
Expand All @@ -73,6 +75,7 @@ alarm_applet_actions_init (AlarmApplet *applet)
GTK_ACTION (applet->action_toggle_list_win), "Escape");
gtk_action_group_add_action (applet->actions_global, GTK_ACTION (applet->action_toggle_autostart));
gtk_action_group_add_action (applet->actions_global, GTK_ACTION (applet->action_toggle_show_label));
gtk_action_group_add_action (applet->actions_global, GTK_ACTION (applet->action_toggle_time_format_12h));

gtk_action_connect_accelerator (GTK_ACTION (applet->action_toggle_list_win));

Expand Down Expand Up @@ -364,12 +367,28 @@ alarm_action_toggle_show_label (GtkAction *action, gpointer data)
}
}

/*
* Toggle time format (24-hour vs 12-hour)
*/
void
alarm_action_toggle_time_format_12h (GtkAction *action, gpointer data)
{
AlarmApplet *applet = (AlarmApplet *)data;
gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
gboolean time_format_state = prefs_time_format_12h_get(applet);
AlarmSettingsDialog *settings_dialog = applet->settings_dialog;

g_debug ("AlarmAction: toggle time_format_12h to %d", active);

if (active != time_format_state) {
g_debug ("AlarmAction: set time_format_12h to %d!", active);
prefs_time_format_12h_set (applet, active);




// update the time display format if a settings dialog is open for an alarm
if (settings_dialog->alarm != NULL)
alarm_settings_update_time_format (settings_dialog);
}
}

/**
* Update actions to a consistent state
Expand Down
3 changes: 3 additions & 0 deletions src/alarm-actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ alarm_action_toggle_autostart (GtkAction *action, gpointer data);
void
alarm_action_toggle_show_label (GtkAction *action, gpointer data);

void
alarm_action_toggle_time_format_12h (GtkAction *action, gpointer data);

#endif // ALARM_ACTIONS_H
1 change: 1 addition & 0 deletions src/alarm-applet.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ struct _AlarmApplet {
GtkToggleAction *action_toggle_list_win;
GtkToggleAction *action_toggle_autostart;
GtkToggleAction *action_toggle_show_label;
GtkToggleAction *action_toggle_time_format_12h;
};

void alarm_applet_sounds_load (AlarmApplet *applet);
Expand Down
9 changes: 8 additions & 1 deletion src/alarm-list-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "alarm-list-window.h"
#include "alarm-settings.h"
#include "alarm-actions.h"
#include "prefs.h"

gboolean
alarm_list_window_delete_event (GtkWidget *window, GdkEvent *event, gpointer data);
Expand Down Expand Up @@ -251,9 +252,15 @@ alarm_list_window_update_row (AlarmListWindow *list_window, GtkTreeIter *iter)
tm = alarm_get_time (a);
}

gboolean time_format_12h = prefs_time_format_12h_get (list_window->applet);

if (a->type == ALARM_TYPE_CLOCK) {
type_col = ALARM_ICON;
strftime(tmp, sizeof(tmp), TIME_COL_CLOCK_FORMAT, tm);
// show 12 hour format if enabled and not counting down
if (time_format_12h && !a->active)
strftime(tmp, sizeof(tmp), TIME_COL_CLOCK_FORMAT_12HR, tm);
else
strftime(tmp, sizeof(tmp), TIME_COL_CLOCK_FORMAT, tm);
} else {
type_col = TIMER_ICON;
strftime(tmp, sizeof(tmp), TIME_COL_TIMER_FORMAT, tm);
Expand Down
1 change: 1 addition & 0 deletions src/alarm-list-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct _AlarmListWindow {

//#define TIME_COL_FORMAT "<span font='Bold 11'>%H:%M:%S</span>"
// TODO: Does fixing the font size give a11y problems?
#define TIME_COL_CLOCK_FORMAT_12HR "<span font='Bold 11'> %I:%M</span><span font='Bold 7'>:%S</span><span font='Bold 8'> %p</span>"
#define TIME_COL_CLOCK_FORMAT "<span font='Bold 11'> %H:%M</span><span font='Bold 7'>:%S</span>"
#define TIME_COL_TIMER_FORMAT "<span font='Bold 11'>-%H:%M</span><span font='Bold 7'>:%S</span>"
#define TIME_COL_REPEAT_FORMAT "\n <sup>%s</sup>"
Expand Down
Loading