kopia lustrzana https://gitlab.com/Zwarf/picplanner
Setting the global GDateTime variable to the values given by the user input
rodzic
9e932a1871
commit
6ec2f2a2da
|
@ -16,7 +16,7 @@
|
|||
<summary>Latitude</summary>
|
||||
<description>The current latitude of the map</description>
|
||||
</key>
|
||||
<key name="zoom-level" type="i">
|
||||
<key name="zoom-level" type="d">
|
||||
<default>6</default>
|
||||
<summary>Zoom Level</summary>
|
||||
<description>The zoom level of the map</description>
|
||||
|
|
|
@ -17,9 +17,9 @@ struct _PicplannerOverview
|
|||
ShumateViewport *viewport;
|
||||
ShumateLocation *location;
|
||||
|
||||
gboolean map_move_new;
|
||||
gint map_move_count;
|
||||
guint map_move_timeout_id;
|
||||
gboolean map_move_new;
|
||||
|
||||
GDateTime *date_time;
|
||||
GSettings *settings;
|
||||
|
@ -73,46 +73,96 @@ map_moved (GtkWidget *self,
|
|||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
time_changed (GtkSpinButton *self,
|
||||
PicplannerOverview *user_data)
|
||||
/*
|
||||
* Changing the date_time variable after a user input was recognized
|
||||
*/
|
||||
static void
|
||||
change_date_time (GtkWidget *self, PicplannerOverview *overview)
|
||||
{
|
||||
(void) user_data;
|
||||
(void) self;
|
||||
int year, month, day, hour, minute;
|
||||
GDateTime *date_selected;
|
||||
|
||||
/*
|
||||
* Get year, month and day information from the calendar widget.
|
||||
*/
|
||||
date_selected = gtk_calendar_get_date (GTK_CALENDAR (overview->calendar));
|
||||
year = g_date_time_get_year (date_selected);
|
||||
month = g_date_time_get_month (date_selected);
|
||||
day = g_date_time_get_day_of_month (date_selected);
|
||||
|
||||
/*
|
||||
* Get hour and minute from the spin buttons.
|
||||
*/
|
||||
hour = gtk_spin_button_get_value (GTK_SPIN_BUTTON (overview->spin_button_hour));
|
||||
minute = gtk_spin_button_get_value (GTK_SPIN_BUTTON (overview->spin_button_minute));
|
||||
|
||||
/*
|
||||
* Save the information into the date_time variable.
|
||||
*/
|
||||
overview->date_time = g_date_time_new (g_date_time_get_timezone (overview->date_time),
|
||||
year, month, day,
|
||||
hour, minute,
|
||||
0);
|
||||
|
||||
g_print("Date: %d.%d.%d, Time: %d:%d\n", year, month, day, hour, minute);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Change the text of the GtkSpinButton to always be a two digit number.
|
||||
* E.g. don't show one o'clock AM as 1:0 but show 01:00
|
||||
*/
|
||||
static gboolean
|
||||
time_spin_button_text (GtkSpinButton *self)
|
||||
{
|
||||
int value;
|
||||
char *button_text;
|
||||
GtkAdjustment *adjustment;
|
||||
|
||||
adjustment = gtk_spin_button_get_adjustment (self);
|
||||
value = (int)gtk_adjustment_get_value (adjustment);
|
||||
value = (int) gtk_adjustment_get_value (adjustment);
|
||||
button_text = g_strdup_printf ("%02d", value);
|
||||
gtk_editable_set_text (GTK_EDITABLE (self),
|
||||
button_text);
|
||||
g_print("%s\n", button_text);
|
||||
g_free (button_text);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
day_selected (GtkCalendar *self,
|
||||
PicplannerOverview *overview)
|
||||
|
||||
/*
|
||||
* Change the text of the button which presents the calender after a date was selected.
|
||||
* Furthermore the behavior of the popup is controlled
|
||||
*/
|
||||
void
|
||||
day_selected (GtkCalendar *self, PicplannerOverview *overview)
|
||||
{
|
||||
(void) self;
|
||||
GDateTime *date_selected = gtk_calendar_get_date (GTK_CALENDAR (overview->calendar));
|
||||
GDateTime *date_selected;
|
||||
GtkPopover *popover;
|
||||
char *button_text;
|
||||
|
||||
int day = g_date_time_get_day_of_month (date_selected);
|
||||
int month = g_date_time_get_month (date_selected);
|
||||
int year = g_date_time_get_year (date_selected);
|
||||
|
||||
char *button_text = g_strdup_printf ("%d.%d.%d", day, month, year);
|
||||
date_selected = gtk_calendar_get_date (GTK_CALENDAR (overview->calendar));
|
||||
|
||||
/*
|
||||
* Set text of the button to the selected date
|
||||
*/
|
||||
button_text = g_strdup_printf ("%d.%d.%d",
|
||||
g_date_time_get_day_of_month (date_selected),
|
||||
g_date_time_get_month (date_selected),
|
||||
g_date_time_get_year (date_selected));
|
||||
gtk_menu_button_set_label (GTK_MENU_BUTTON (overview->calendar_button),
|
||||
button_text);
|
||||
|
||||
GtkPopover *popover = GTK_POPOVER(overview->calendar_popover);
|
||||
/*
|
||||
* Close Popover after the day was selected
|
||||
*/
|
||||
popover = GTK_POPOVER(overview->calendar_popover);
|
||||
gtk_popover_popdown (popover);
|
||||
|
||||
change_date_time (GTK_WIDGET (self), overview);
|
||||
}
|
||||
|
||||
|
||||
|
@ -154,6 +204,9 @@ picplanner_overview_init (PicplannerOverview *overview)
|
|||
shumate_simple_map_set_map_source (overview->map, map_source);
|
||||
overview->viewport = shumate_simple_map_get_viewport (overview->map);
|
||||
|
||||
/*
|
||||
* Make all the bindings between widget properties and g_settings.
|
||||
*/
|
||||
g_settings_bind (overview->settings, "longitude",
|
||||
overview->viewport, "longitude",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
|
@ -174,8 +227,28 @@ picplanner_overview_init (PicplannerOverview *overview)
|
|||
overview->north_entry, "value",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
|
||||
g_signal_connect (G_OBJECT (overview->north_entry), "value-changed", G_CALLBACK (map_moved), overview);
|
||||
g_signal_connect (G_OBJECT (overview->east_entry), "value-changed", G_CALLBACK (map_moved), overview);
|
||||
/*
|
||||
* Connect the signals which recognize user input.
|
||||
*/
|
||||
g_signal_connect (G_OBJECT (overview->north_entry),
|
||||
"value-changed",
|
||||
G_CALLBACK (map_moved),
|
||||
overview);
|
||||
|
||||
g_signal_connect (G_OBJECT (overview->east_entry),
|
||||
"value-changed",
|
||||
G_CALLBACK (map_moved),
|
||||
overview);
|
||||
|
||||
g_signal_connect (G_OBJECT (overview->spin_button_hour),
|
||||
"value-changed",
|
||||
G_CALLBACK (change_date_time),
|
||||
overview);
|
||||
|
||||
g_signal_connect (G_OBJECT (overview->spin_button_minute),
|
||||
"value-changed",
|
||||
G_CALLBACK (change_date_time),
|
||||
overview);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -195,8 +268,8 @@ picplanner_overview_class_init (PicplannerOverviewClass *class)
|
|||
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), PicplannerOverview, spin_button_minute);
|
||||
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), PicplannerOverview, map);
|
||||
|
||||
gtk_widget_class_bind_template_callback (class, time_changed);
|
||||
gtk_widget_class_bind_template_callback (class, day_selected);
|
||||
gtk_widget_class_bind_template_callback (class, time_spin_button_text);
|
||||
}
|
||||
|
||||
PicplannerOverview *
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
|
||||
<object class="GtkAdjustment" id="d_adjustment">
|
||||
<property name="lower">1</property>
|
||||
<property name="upper">31</property>
|
||||
<property name="step_increment">1</property>
|
||||
<property name="page_increment">10</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="h_adjustment">
|
||||
<property name="upper">23</property>
|
||||
<property name="step_increment">1</property>
|
||||
|
@ -17,12 +10,6 @@
|
|||
<property name="step_increment">1</property>
|
||||
<property name="page_increment">10</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="y_adjustment">
|
||||
<property name="lower">2000</property>
|
||||
<property name="upper">2100</property>
|
||||
<property name="step_increment">1</property>
|
||||
<property name="page_increment">10</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="north_adjustment">
|
||||
<property name="upper">85.0511287798</property>
|
||||
<property name="lower">-85.0511287798</property>
|
||||
|
@ -154,9 +141,7 @@
|
|||
<property name="adjustment">h_adjustment</property>
|
||||
<property name="numeric">false</property>
|
||||
<property name="wrap">true</property>
|
||||
<property name="value">8</property>
|
||||
<signal name="output" handler="time_changed"/>
|
||||
|
||||
<signal name="output" handler="time_spin_button_text"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -170,9 +155,9 @@
|
|||
<object class="GtkSpinButton" id="spin_button_minute">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="adjustment">m_adjustment</property>
|
||||
<property name="numeric">True</property>
|
||||
<property name="wrap">True</property>
|
||||
<signal name="output" handler="time_changed"/>
|
||||
<property name="numeric">false</property>
|
||||
<property name="wrap">true</property>
|
||||
<signal name="output" handler="time_spin_button_text"/>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue