project: Make time format a first-class citizen
The current code deals with 12/24h clock formats almost like a workaround of the issue. This commit adds proper support to different clock formats.
This commit is contained in:
+50
-5
@@ -24,6 +24,7 @@
|
||||
#include "css-code.h"
|
||||
#include "gcal-application.h"
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-enums.h"
|
||||
#include "gcal-log.h"
|
||||
#include "gcal-shell-search-provider.h"
|
||||
#include "gcal-weather-service.h"
|
||||
@@ -48,6 +49,9 @@ struct _GcalApplication
|
||||
gchar *uuid;
|
||||
icaltimetype *initial_date;
|
||||
|
||||
GSettings *desktop_settings;
|
||||
GcalTimeFormat time_format;
|
||||
|
||||
GcalWeatherService *weather_service;
|
||||
|
||||
GcalShellSearchProvider *search_provider;
|
||||
@@ -118,6 +122,7 @@ enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_MANAGER,
|
||||
PROP_TIME_FORMAT,
|
||||
PROP_WEATHER_SERVICE,
|
||||
N_PROPS
|
||||
};
|
||||
@@ -190,6 +195,25 @@ load_css_provider (GcalApplication *self)
|
||||
gtk_css_provider_load_from_resource (self->provider, "/org/gnome/calendar/theme/Adwaita.css");
|
||||
}
|
||||
|
||||
static void
|
||||
load_time_format (GcalApplication *self)
|
||||
{
|
||||
g_autofree gchar *clock_format = NULL;
|
||||
g_autofree gchar *enum_format = NULL;
|
||||
|
||||
clock_format = g_settings_get_string (self->desktop_settings, "clock-format");
|
||||
|
||||
if (g_strcmp0 (clock_format, "12h") == 0)
|
||||
self->time_format = GCAL_TIME_FORMAT_12H;
|
||||
else
|
||||
self->time_format = GCAL_TIME_FORMAT_24H;
|
||||
|
||||
enum_format = g_enum_to_string (GCAL_TYPE_TIME_FORMAT, self->time_format);
|
||||
g_debug ("Setting time format to %s", enum_format);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TIME_FORMAT]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GObject overrides
|
||||
@@ -202,15 +226,14 @@ gcal_application_finalize (GObject *object)
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_clear_pointer (&self->uuid, g_free);
|
||||
g_clear_pointer (&self->initial_date, g_free);
|
||||
|
||||
g_clear_object (&(self->provider));
|
||||
g_clear_pointer (&self->uuid, g_free);
|
||||
g_clear_object (&self->colors_provider);
|
||||
|
||||
g_clear_object (&self->desktop_settings);
|
||||
g_clear_object (&self->manager);
|
||||
g_clear_object (&self->weather_service);
|
||||
g_clear_object (&self->provider);
|
||||
g_clear_object (&self->search_provider);
|
||||
g_clear_object (&self->weather_service);
|
||||
|
||||
G_OBJECT_CLASS (gcal_application_parent_class)->finalize (object);
|
||||
|
||||
@@ -231,6 +254,10 @@ gcal_application_get_property (GObject *object,
|
||||
g_value_set_object (value, self->manager);
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
g_value_set_enum (value, self->time_format);
|
||||
break;
|
||||
|
||||
case PROP_WEATHER_SERVICE:
|
||||
g_value_set_object (value, self->weather_service);
|
||||
break;
|
||||
@@ -281,8 +308,11 @@ gcal_application_activate (GApplication *application)
|
||||
"manager", self->manager,
|
||||
"active-date", self->initial_date,
|
||||
"weather-service", self->weather_service,
|
||||
"time-format", self->time_format,
|
||||
NULL);
|
||||
|
||||
g_object_bind_property (self, "time-format", self->window, "time-format", G_BINDING_DEFAULT);
|
||||
|
||||
g_signal_connect (self->window, "destroy", G_CALLBACK (gtk_widget_destroyed), &self->window);
|
||||
gtk_widget_show (self->window);
|
||||
}
|
||||
@@ -455,6 +485,13 @@ gcal_application_class_init (GcalApplicationClass *klass)
|
||||
GCAL_TYPE_MANAGER,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties[PROP_TIME_FORMAT] = g_param_spec_enum ("time-format",
|
||||
"The time format of the computer",
|
||||
"The time format of the computer",
|
||||
GCAL_TYPE_TIME_FORMAT,
|
||||
GCAL_TIME_FORMAT_24H,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties[PROP_WEATHER_SERVICE] = g_param_spec_object ("weather-service",
|
||||
"The weather service object",
|
||||
"The weather service object",
|
||||
@@ -477,6 +514,14 @@ gcal_application_init (GcalApplication *self)
|
||||
|
||||
self->weather_service = gcal_weather_service_new ();
|
||||
self->search_provider = gcal_shell_search_provider_new (self->manager);
|
||||
|
||||
/* Time format */
|
||||
self->desktop_settings = g_settings_new ("org.gnome.desktop.interface");
|
||||
g_signal_connect_swapped (self->desktop_settings,
|
||||
"changed::clock-format",
|
||||
G_CALLBACK (load_time_format),
|
||||
self);
|
||||
load_time_format (self);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
+30
-5
@@ -107,7 +107,7 @@ struct _GcalEditDialog
|
||||
ESource *selected_source;
|
||||
|
||||
/* flags */
|
||||
gboolean format_24h;
|
||||
GcalTimeFormat time_format;
|
||||
gboolean event_is_new;
|
||||
gboolean recurrence_changed;
|
||||
gboolean setting_event;
|
||||
@@ -127,6 +127,7 @@ enum
|
||||
PROP_0,
|
||||
PROP_EVENT,
|
||||
PROP_MANAGER,
|
||||
PROP_TIME_FORMAT,
|
||||
PROP_WRITABLE,
|
||||
LAST_PROP
|
||||
};
|
||||
@@ -718,6 +719,10 @@ gcal_edit_dialog_get_property (GObject *object,
|
||||
g_value_set_object (value, self->manager);
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
g_value_set_enum (value, self->time_format);
|
||||
break;
|
||||
|
||||
case PROP_WRITABLE:
|
||||
g_value_set_boolean (value, self->writable);
|
||||
break;
|
||||
@@ -745,6 +750,10 @@ gcal_edit_dialog_set_property (GObject *object,
|
||||
gcal_edit_dialog_set_manager (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
gcal_edit_dialog_set_time_format (self, g_value_get_enum (value));
|
||||
break;
|
||||
|
||||
case PROP_WRITABLE:
|
||||
gcal_edit_dialog_set_writable (self, g_value_get_boolean (value));
|
||||
break;
|
||||
@@ -794,6 +803,20 @@ gcal_edit_dialog_class_init (GcalEditDialogClass *klass)
|
||||
GCAL_TYPE_MANAGER,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GcalEditDialog::time-format:
|
||||
*
|
||||
* The time format.
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_TIME_FORMAT,
|
||||
g_param_spec_enum ("time-format",
|
||||
"Manager of the dialog",
|
||||
"The manager of the dialog",
|
||||
GCAL_TYPE_TIME_FORMAT,
|
||||
GCAL_TIME_FORMAT_24H,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
* GcalEditDialog::writable:
|
||||
*
|
||||
@@ -1209,14 +1232,16 @@ gcal_edit_dialog_new (void)
|
||||
*/
|
||||
void
|
||||
gcal_edit_dialog_set_time_format (GcalEditDialog *dialog,
|
||||
gboolean use_24h_format)
|
||||
GcalTimeFormat time_format)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_EDIT_DIALOG (dialog));
|
||||
|
||||
dialog->format_24h = use_24h_format;
|
||||
dialog->time_format = time_format;
|
||||
|
||||
gcal_time_selector_set_time_format (GCAL_TIME_SELECTOR (dialog->start_time_selector), dialog->format_24h);
|
||||
gcal_time_selector_set_time_format (GCAL_TIME_SELECTOR (dialog->end_time_selector), dialog->format_24h);
|
||||
gcal_time_selector_set_time_format (GCAL_TIME_SELECTOR (dialog->start_time_selector), dialog->time_format);
|
||||
gcal_time_selector_set_time_format (GCAL_TIME_SELECTOR (dialog->end_time_selector), dialog->time_format);
|
||||
|
||||
g_object_notify (G_OBJECT (dialog), "time-format");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#ifndef __GCAL_EDIT_DIALOG_H__
|
||||
#define __GCAL_EDIT_DIALOG_H__
|
||||
|
||||
#include "gcal-enums.h"
|
||||
#include "gcal-event.h"
|
||||
#include "gcal-manager.h"
|
||||
|
||||
@@ -48,7 +49,7 @@ void gcal_edit_dialog_set_manager (GcalEditDialog *d
|
||||
GcalManager *manager);
|
||||
|
||||
void gcal_edit_dialog_set_time_format (GcalEditDialog *dialog,
|
||||
gboolean use_24h_format);
|
||||
GcalTimeFormat time_format);
|
||||
|
||||
GDateTime* gcal_edit_dialog_get_date_end (GcalEditDialog *dialog);
|
||||
|
||||
|
||||
@@ -18,6 +18,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gcal-enum-types.h"
|
||||
|
||||
/**
|
||||
* GcalTimeFormat:
|
||||
* @GCAL_TIME_FORMAT_12H: time is displayed in 12h format
|
||||
* @GCAL_TIME_FORMAT_24H: time is displayed in 24h format
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GCAL_TIME_FORMAT_12H,
|
||||
GCAL_TIME_FORMAT_24H,
|
||||
} GcalTimeFormat;
|
||||
|
||||
/**
|
||||
* GcalWindowViewType:
|
||||
|
||||
+35
-30
@@ -20,6 +20,7 @@
|
||||
#define G_LOG_DOMAIN "GcalSearchPopover"
|
||||
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-enums.h"
|
||||
#include "gcal-event.h"
|
||||
#include "gcal-search-popover.h"
|
||||
#include "gcal-utils.h"
|
||||
@@ -60,14 +61,15 @@ struct _GcalSearchPopover
|
||||
GcalManager *manager; /* weak reference */
|
||||
|
||||
/* flags */
|
||||
gboolean format_24h;
|
||||
GcalTimeFormat time_format;
|
||||
gboolean subscribed;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DATE, /* active-date inherited property */
|
||||
PROP_DATE,
|
||||
PROP_TIME_FORMAT,
|
||||
};
|
||||
|
||||
enum
|
||||
@@ -291,7 +293,8 @@ make_row_for_event (GcalSearchPopover *self,
|
||||
/* show 'all day' instead of 00:00 */
|
||||
if (!gcal_event_get_all_day (event))
|
||||
{
|
||||
text = g_date_time_format (local_datetime, self->format_24h ? "%R" : "%r");
|
||||
text = g_date_time_format (local_datetime,
|
||||
self->time_format == GCAL_TIME_FORMAT_24H ? "%R" : "%r");
|
||||
time_label = gtk_label_new (text);
|
||||
g_free (text);
|
||||
}
|
||||
@@ -579,11 +582,14 @@ gcal_search_popover_set_property (GObject *object,
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_DATE:
|
||||
{
|
||||
g_clear_pointer (&self->date, g_free);
|
||||
self->date = g_value_dup_boxed (value);
|
||||
break;
|
||||
}
|
||||
g_clear_pointer (&self->date, g_free);
|
||||
self->date = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
self->time_format = g_value_get_enum (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
@@ -603,6 +609,11 @@ gcal_search_popover_get_property (GObject *object,
|
||||
case PROP_DATE:
|
||||
g_value_set_boxed (value, self->date);
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
g_value_set_enum (value, self->time_format);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
@@ -655,11 +666,22 @@ gcal_search_popover_class_init (GcalSearchPopoverClass *klass)
|
||||
* Actually it is not used.
|
||||
*
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_DATE,
|
||||
g_param_spec_boxed ("active-date",
|
||||
"The active date",
|
||||
"The active/selected date in the view",
|
||||
ICAL_TIME_TYPE, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_DATE,
|
||||
g_param_spec_boxed ("active-date",
|
||||
"The active date",
|
||||
"The active/selected date in the view",
|
||||
ICAL_TIME_TYPE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_TIME_FORMAT,
|
||||
g_param_spec_enum ("time-format",
|
||||
"The time format",
|
||||
"The time format",
|
||||
GCAL_TYPE_TIME_FORMAT,
|
||||
GCAL_TIME_FORMAT_24H,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/* bind things for/from the template class */
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/calendar/search-popover.ui");
|
||||
@@ -707,23 +729,6 @@ gcal_search_popover_connect (GcalSearchPopover *search_popover,
|
||||
search_popover->manager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_search_popover_set_time_format:
|
||||
* @view: a #GcalSearchPopover instance.
|
||||
* @format_24h: whether is 24h or not.
|
||||
*
|
||||
* Setup time format, instead of accessing DConf
|
||||
* again.
|
||||
*
|
||||
*/
|
||||
void
|
||||
gcal_search_popover_set_time_format (GcalSearchPopover *self,
|
||||
gboolean format_24h)
|
||||
{
|
||||
self->format_24h = format_24h;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gcal_search_popover_set_search:
|
||||
* @view: a #GcalSearchPopover instance
|
||||
|
||||
@@ -30,9 +30,6 @@ G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GcalSearchPopover, gcal_search_popover, GCAL, SEARCH_POPOVER, GtkPopover)
|
||||
|
||||
void gcal_search_popover_set_time_format (GcalSearchPopover *self,
|
||||
gboolean format_24h);
|
||||
|
||||
void gcal_search_popover_search (GcalSearchPopover *self,
|
||||
const gchar *field,
|
||||
const gchar *query);
|
||||
|
||||
@@ -38,7 +38,7 @@ struct _GcalTimeSelector
|
||||
|
||||
GDateTime *time;
|
||||
|
||||
gboolean format_24h;
|
||||
GcalTimeFormat time_format;
|
||||
};
|
||||
|
||||
enum
|
||||
@@ -63,7 +63,7 @@ update_label (GcalTimeSelector *selector)
|
||||
{
|
||||
gchar *new_label;
|
||||
|
||||
if (selector->format_24h)
|
||||
if (selector->time_format == GCAL_TIME_FORMAT_24H)
|
||||
{
|
||||
new_label = g_date_time_format (selector->time, "%H:%M");
|
||||
}
|
||||
@@ -102,7 +102,7 @@ update_time (GcalTimeSelector *selector)
|
||||
hour = (gint) gtk_adjustment_get_value (selector->hour_adjustment);
|
||||
minute = (gint) gtk_adjustment_get_value (selector->minute_adjustment);
|
||||
|
||||
if (!selector->format_24h)
|
||||
if (selector->time_format == GCAL_TIME_FORMAT_12H)
|
||||
{
|
||||
hour = hour % 12;
|
||||
|
||||
@@ -188,14 +188,14 @@ gcal_time_selector_set_property (GObject *object,
|
||||
|
||||
void
|
||||
gcal_time_selector_set_time_format (GcalTimeSelector *selector,
|
||||
gboolean format_24h)
|
||||
GcalTimeFormat time_format)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_TIME_SELECTOR (selector));
|
||||
|
||||
selector->format_24h = format_24h;
|
||||
gtk_widget_set_visible (selector->period_combo, !format_24h);
|
||||
selector->time_format = time_format;
|
||||
gtk_widget_set_visible (selector->period_combo, time_format == GCAL_TIME_FORMAT_12H);
|
||||
|
||||
if (format_24h)
|
||||
if (time_format == GCAL_TIME_FORMAT_24H)
|
||||
{
|
||||
gtk_adjustment_set_lower (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->hour_spin)), 0.0);
|
||||
gtk_adjustment_set_upper (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (selector->hour_spin)), 23.0);
|
||||
@@ -312,7 +312,7 @@ gcal_time_selector_set_time (GcalTimeSelector *selector,
|
||||
hour = g_date_time_get_hour (time);
|
||||
minute = g_date_time_get_minute (time);
|
||||
|
||||
if (!selector->format_24h)
|
||||
if (selector->time_format == GCAL_TIME_FORMAT_12H)
|
||||
{
|
||||
g_signal_handlers_block_by_func (selector->period_combo, update_time, selector);
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#ifndef __GCAL_TIME_SELECTOR_H__
|
||||
#define __GCAL_TIME_SELECTOR_H__
|
||||
|
||||
#include "gcal-enums.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@@ -30,7 +32,7 @@ G_DECLARE_FINAL_TYPE (GcalTimeSelector, gcal_time_selector, GCAL, TIME_SELECTOR,
|
||||
GtkWidget* gcal_time_selector_new (void);
|
||||
|
||||
void gcal_time_selector_set_time_format (GcalTimeSelector *selector,
|
||||
gboolean format_24h);
|
||||
GcalTimeFormat time_format);
|
||||
|
||||
GDateTime* gcal_time_selector_get_time (GcalTimeSelector *selector);
|
||||
|
||||
|
||||
+34
-28
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-edit-dialog.h"
|
||||
#include "gcal-enums.h"
|
||||
#include "gcal-event-widget.h"
|
||||
#include "gcal-manager.h"
|
||||
#include "gcal-month-view.h"
|
||||
@@ -162,6 +161,8 @@ struct _GcalWindow
|
||||
gint refresh_timeout_id;
|
||||
gint open_edit_dialog_timeout_id;
|
||||
|
||||
GcalTimeFormat time_format;
|
||||
|
||||
/* weather management */
|
||||
GcalWeatherService *weather_service;
|
||||
GcalWeatherSettings *weather_settings;
|
||||
@@ -187,6 +188,7 @@ enum
|
||||
PROP_ACTIVE_VIEW,
|
||||
PROP_MANAGER,
|
||||
PROP_NEW_EVENT_MODE,
|
||||
PROP_TIME_FORMAT,
|
||||
PROP_WEATHER_SERVICE,
|
||||
N_PROPS
|
||||
};
|
||||
@@ -1339,6 +1341,14 @@ gcal_window_set_property (GObject *object,
|
||||
}
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
if (self->time_format != g_value_get_enum (value))
|
||||
{
|
||||
self->time_format = g_value_get_enum (value);
|
||||
g_object_notify_by_pspec (object, properties[PROP_TIME_FORMAT]);
|
||||
}
|
||||
break;
|
||||
|
||||
case PROP_WEATHER_SERVICE:
|
||||
if (g_set_object (&self->weather_service, g_value_get_object (value)))
|
||||
g_object_notify_by_pspec (object, properties[PROP_WEATHER_SERVICE]);
|
||||
@@ -1361,26 +1371,30 @@ gcal_window_get_property (GObject *object,
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_ACTIVE_DATE:
|
||||
g_value_set_boxed (value, self->active_date);
|
||||
break;
|
||||
|
||||
case PROP_ACTIVE_VIEW:
|
||||
g_value_set_enum (value, self->active_view);
|
||||
break;
|
||||
|
||||
case PROP_NEW_EVENT_MODE:
|
||||
g_value_set_boolean (value, self->new_event_mode);
|
||||
break;
|
||||
|
||||
case PROP_MANAGER:
|
||||
g_value_set_object (value, self->manager);
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
g_value_set_enum (value, self->time_format);
|
||||
break;
|
||||
|
||||
case PROP_WEATHER_SERVICE:
|
||||
g_value_set_object (value, self->weather_service);
|
||||
break;
|
||||
|
||||
case PROP_ACTIVE_DATE:
|
||||
g_value_set_boxed (value, self->active_date);
|
||||
break;
|
||||
|
||||
case PROP_NEW_EVENT_MODE:
|
||||
g_value_set_boolean (value, self->new_event_mode);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
}
|
||||
@@ -1460,6 +1474,13 @@ gcal_window_class_init (GcalWindowClass *klass)
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties[PROP_TIME_FORMAT] = g_param_spec_enum ("time-format",
|
||||
"The time format of the computer",
|
||||
"The time format of the computer",
|
||||
GCAL_TYPE_TIME_FORMAT,
|
||||
GCAL_TIME_FORMAT_24H,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties[PROP_WEATHER_SERVICE] = g_param_spec_object ("weather-service",
|
||||
"The weather service object",
|
||||
"The weather service object",
|
||||
@@ -1537,9 +1558,6 @@ static void
|
||||
gcal_window_init (GcalWindow *self)
|
||||
{
|
||||
GApplication *app;
|
||||
GSettings *helper_settings;
|
||||
gchar *clock_format;
|
||||
gboolean use_24h_format;
|
||||
|
||||
/* Setup actions */
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (self),
|
||||
@@ -1549,6 +1567,7 @@ gcal_window_init (GcalWindow *self)
|
||||
|
||||
app = g_application_get_default ();
|
||||
self->weather_service = gcal_application_get_weather_service (GCAL_APPLICATION (app));
|
||||
self->time_format = GCAL_TIME_FORMAT_24H;
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
@@ -1556,29 +1575,13 @@ gcal_window_init (GcalWindow *self)
|
||||
g_object_bind_property (self, "application", self->source_dialog, "application",
|
||||
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
|
||||
|
||||
helper_settings = g_settings_new ("org.gnome.desktop.interface");
|
||||
clock_format = g_settings_get_string (helper_settings, "clock-format");
|
||||
use_24h_format = (g_strcmp0 (clock_format, "24h") == 0);
|
||||
g_free (clock_format);
|
||||
g_object_unref (helper_settings);
|
||||
|
||||
self->views[GCAL_WINDOW_VIEW_WEEK] = self->week_view;
|
||||
self->views[GCAL_WINDOW_VIEW_MONTH] = self->month_view;
|
||||
self->views[GCAL_WINDOW_VIEW_YEAR] = self->year_view;
|
||||
|
||||
gcal_edit_dialog_set_time_format (GCAL_EDIT_DIALOG (self->edit_dialog), use_24h_format);
|
||||
|
||||
gcal_week_view_set_first_weekday (GCAL_WEEK_VIEW (self->views[GCAL_WINDOW_VIEW_WEEK]), get_first_weekday ());
|
||||
gcal_week_view_set_use_24h_format (GCAL_WEEK_VIEW (self->views[GCAL_WINDOW_VIEW_WEEK]), use_24h_format);
|
||||
|
||||
gcal_month_view_set_first_weekday (GCAL_MONTH_VIEW (self->views[GCAL_WINDOW_VIEW_MONTH]), get_first_weekday ());
|
||||
gcal_month_view_set_use_24h_format (GCAL_MONTH_VIEW (self->views[GCAL_WINDOW_VIEW_MONTH]), use_24h_format);
|
||||
|
||||
gcal_year_view_set_first_weekday (GCAL_YEAR_VIEW (self->views[GCAL_WINDOW_VIEW_YEAR]), get_first_weekday ());
|
||||
gcal_year_view_set_use_24h_format (GCAL_YEAR_VIEW (self->views[GCAL_WINDOW_VIEW_YEAR]), use_24h_format);
|
||||
|
||||
/* search view */
|
||||
gcal_search_popover_set_time_format (GCAL_SEARCH_POPOVER (self->search_popover), use_24h_format);
|
||||
|
||||
/* refresh timeout, first is fast */
|
||||
self->refresh_timeout_id = g_timeout_add (FAST_REFRESH_TIMEOUT, (GSourceFunc) refresh_sources, self);
|
||||
@@ -1604,6 +1607,9 @@ gcal_window_init (GcalWindow *self)
|
||||
g_object_bind_property (self, "manager", self->month_view, "manager", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "manager", self->year_view, "manager", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "manager", self->quick_add_popover, "manager", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "time-format", self->edit_dialog, "time-format", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "time-format", self->search_popover, "time-format", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "time-format", self->week_view, "time-format", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "weather-service", self->weather_settings, "weather-service", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "weather-service", self->month_view, "weather-service", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "weather-service", self->week_view, "weather-service", G_BINDING_DEFAULT);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define __GCAL_WINDOW_H__
|
||||
|
||||
#include "gcal-application.h"
|
||||
#include "gcal-enums.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
@@ -111,11 +111,6 @@ struct _GcalMonthView
|
||||
GDateTime *start_mark_cell;
|
||||
GDateTime *end_mark_cell;
|
||||
|
||||
/*
|
||||
* clock format from GNOME desktop settings
|
||||
*/
|
||||
gboolean use_24h_format;
|
||||
|
||||
/* Storage for the accumulated scrolling */
|
||||
gdouble scroll_value;
|
||||
guint update_grid_id;
|
||||
@@ -2246,16 +2241,3 @@ gcal_month_view_set_first_weekday (GcalMonthView *self,
|
||||
update_weekday_labels (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_month_view_set_use_24h_format:
|
||||
* @view:
|
||||
* @use_24h:
|
||||
*
|
||||
* Whether the view will show time using 24h or 12h format
|
||||
*/
|
||||
void
|
||||
gcal_month_view_set_use_24h_format (GcalMonthView *self,
|
||||
gboolean use_24h)
|
||||
{
|
||||
self->use_24h_format = use_24h;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ struct _GcalWeekGrid
|
||||
GdkWindow *event_window;
|
||||
|
||||
gint first_weekday;
|
||||
gboolean use_24h_format : 1;
|
||||
|
||||
icaltimetype *active_date;
|
||||
|
||||
@@ -1154,15 +1153,6 @@ gcal_week_grid_set_first_weekday (GcalWeekGrid *self,
|
||||
self->first_weekday = nr_day;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_grid_set_use_24h_format (GcalWeekGrid *self,
|
||||
gboolean use_24h_format)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_GRID (self));
|
||||
|
||||
self->use_24h_format = use_24h_format;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_grid_add_event (GcalWeekGrid *self,
|
||||
GcalEvent *event)
|
||||
|
||||
@@ -36,9 +36,6 @@ void gcal_week_grid_set_manager (GcalWeekGrid
|
||||
void gcal_week_grid_set_first_weekday (GcalWeekGrid *week_grid,
|
||||
gint nr_day);
|
||||
|
||||
void gcal_week_grid_set_use_24h_format (GcalWeekGrid *week_grid,
|
||||
gboolean use_24h_format);
|
||||
|
||||
void gcal_week_grid_add_event (GcalWeekGrid *self,
|
||||
GcalEvent *event);
|
||||
|
||||
|
||||
@@ -86,8 +86,6 @@ struct _GcalWeekHeader
|
||||
*/
|
||||
gboolean expanded;
|
||||
|
||||
gboolean use_24h_format;
|
||||
|
||||
icaltimetype *active_date;
|
||||
|
||||
gint selection_start;
|
||||
@@ -1834,15 +1832,6 @@ gcal_week_header_set_first_weekday (GcalWeekHeader *self,
|
||||
self->first_weekday = nr_day;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_header_set_use_24h_format (GcalWeekHeader *self,
|
||||
gboolean use_24h_format)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
|
||||
|
||||
self->use_24h_format = use_24h_format;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_header_add_event (GcalWeekHeader *self,
|
||||
GcalEvent *event)
|
||||
|
||||
@@ -38,9 +38,6 @@ void gcal_week_header_set_manager (GcalWeekHeader
|
||||
void gcal_week_header_set_first_weekday (GcalWeekHeader *self,
|
||||
gint nr_day);
|
||||
|
||||
void gcal_week_header_set_use_24h_format (GcalWeekHeader *self,
|
||||
gboolean use_24h_format);
|
||||
|
||||
void gcal_week_header_add_event (GcalWeekHeader *self,
|
||||
GcalEvent *event);
|
||||
|
||||
|
||||
+24
-20
@@ -19,6 +19,7 @@
|
||||
#define G_LOG_DOMAIN "GcalWeekView"
|
||||
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-enums.h"
|
||||
#include "gcal-event-widget.h"
|
||||
#include "gcal-utils.h"
|
||||
#include "gcal-view.h"
|
||||
@@ -54,10 +55,8 @@ struct _GcalWeekView
|
||||
*/
|
||||
gint first_weekday;
|
||||
|
||||
/*
|
||||
* clock format from GNOME desktop settings
|
||||
*/
|
||||
gboolean use_24h_format;
|
||||
|
||||
GcalTimeFormat time_format;
|
||||
|
||||
/* property */
|
||||
icaltimetype *date;
|
||||
@@ -80,6 +79,7 @@ enum
|
||||
PROP_0,
|
||||
PROP_DATE,
|
||||
PROP_MANAGER,
|
||||
PROP_TIME_FORMAT,
|
||||
PROP_WEATHER_SERVICE,
|
||||
NUM_PROPS
|
||||
};
|
||||
@@ -429,7 +429,7 @@ gcal_week_view_draw_hours (GcalWeekView *self,
|
||||
{
|
||||
gchar *hours;
|
||||
|
||||
if (self->use_24h_format)
|
||||
if (self->time_format == GCAL_TIME_FORMAT_24H)
|
||||
{
|
||||
hours = g_strdup_printf ("%02d:00", i);
|
||||
}
|
||||
@@ -543,6 +543,12 @@ gcal_week_view_set_property (GObject *object,
|
||||
g_object_notify (object, "manager");
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
g_debug ("BLAAA");
|
||||
self->time_format = g_value_get_enum (value);
|
||||
gtk_widget_queue_draw (self->hours_bar);
|
||||
break;
|
||||
|
||||
case PROP_WEATHER_SERVICE:
|
||||
if (g_set_object (&self->weather_service, g_value_get_object (value)))
|
||||
g_object_notify (object, "weather-service");
|
||||
@@ -575,6 +581,10 @@ gcal_week_view_get_property (GObject *object,
|
||||
g_value_set_object (value, self->manager);
|
||||
break;
|
||||
|
||||
case PROP_TIME_FORMAT:
|
||||
g_value_set_enum (value, self->time_format);
|
||||
break;
|
||||
|
||||
case PROP_WEATHER_SERVICE:
|
||||
g_value_set_object (value, self->weather_service);
|
||||
break;
|
||||
@@ -602,6 +612,15 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
|
||||
g_object_class_override_property (object_class, PROP_MANAGER, "manager");
|
||||
g_object_class_override_property (object_class, PROP_WEATHER_SERVICE, "weather-service");
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_TIME_FORMAT,
|
||||
g_param_spec_enum ("time-format",
|
||||
"Time format",
|
||||
"Time format",
|
||||
GCAL_TYPE_TIME_FORMAT,
|
||||
GCAL_TIME_FORMAT_24H,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/week-view.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, header);
|
||||
@@ -661,18 +680,3 @@ gcal_week_view_set_first_weekday (GcalWeekView *self,
|
||||
gcal_week_grid_set_first_weekday (GCAL_WEEK_GRID (self->week_grid), self->first_weekday);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_week_view_set_use_24h_format:
|
||||
* @view:
|
||||
* @use_24h:
|
||||
*
|
||||
* Whether the view will show time using 24h or 12h format
|
||||
**/
|
||||
void
|
||||
gcal_week_view_set_use_24h_format (GcalWeekView *self,
|
||||
gboolean use_24h)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_VIEW (self));
|
||||
|
||||
self->use_24h_format = use_24h;
|
||||
}
|
||||
|
||||
@@ -33,9 +33,6 @@ GtkWidget* gcal_week_view_new (void);
|
||||
void gcal_week_view_set_first_weekday (GcalWeekView *self,
|
||||
gint day_nr);
|
||||
|
||||
void gcal_week_view_set_use_24h_format (GcalWeekView *self,
|
||||
gboolean use_24h);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GCAL_WEEK_VIEW_H__ */
|
||||
|
||||
@@ -97,11 +97,6 @@ struct _GcalYearView
|
||||
/* Storage for the accumulated scrolling */
|
||||
gdouble scroll_value;
|
||||
|
||||
/**
|
||||
* clock format from GNOME desktop settings
|
||||
*/
|
||||
gboolean use_24h_format;
|
||||
|
||||
/* show week numbers from GNOME Shell settings */
|
||||
GSettings *calendar_settings;
|
||||
gboolean show_week_numbers;
|
||||
@@ -2108,10 +2103,3 @@ gcal_year_view_set_first_weekday (GcalYearView *year_view,
|
||||
{
|
||||
year_view->first_weekday = nr_day;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_year_view_set_use_24h_format (GcalYearView *year_view,
|
||||
gboolean use_24h_format)
|
||||
{
|
||||
year_view->use_24h_format = use_24h_format;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,6 @@ G_DECLARE_FINAL_TYPE (GcalYearView, gcal_year_view, GCAL, YEAR_VIEW, GtkBox)
|
||||
void gcal_year_view_set_first_weekday (GcalYearView *year_view,
|
||||
gint nr_day);
|
||||
|
||||
void gcal_year_view_set_use_24h_format (GcalYearView *year_view,
|
||||
gboolean use_24h_format);
|
||||
|
||||
void gcal_year_view_set_current_date (GcalYearView *year_view,
|
||||
icaltimetype *current_date);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user