kopia lustrzana https://gitlab.com/Zwarf/picplanner
time-picker: Prefer g_auto* macros
g_autofree will automatically free variables when they go out of scope. g_autoptr will do the same, but using the appropriate freefunc for the given type, e.g. GDateTime -> g_date_time_unref() or GObject -> g_object_unref(). This automatic cleanup reduces the risk of memory leaks and allows getting rid of some lines of code.main
rodzic
933089cf6f
commit
3255001a90
|
@ -53,10 +53,9 @@ void
|
||||||
time_picker_set_time_zone (TimePicker *time_picker,
|
time_picker_set_time_zone (TimePicker *time_picker,
|
||||||
double time_zone)
|
double time_zone)
|
||||||
{
|
{
|
||||||
char *char_time_zone;
|
g_autofree char *char_time_zone = NULL;
|
||||||
char_time_zone = g_strdup_printf ("UTC %s%.1f", time_zone>=0 ? "+" : "", time_zone);
|
char_time_zone = g_strdup_printf ("UTC %s%.1f", time_zone>=0 ? "+" : "", time_zone);
|
||||||
gtk_label_set_text (GTK_LABEL (time_picker->label_time_zone), char_time_zone);
|
gtk_label_set_text (GTK_LABEL (time_picker->label_time_zone), char_time_zone);
|
||||||
g_free (char_time_zone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,7 +134,7 @@ static gboolean
|
||||||
time_spin_button_text (GtkSpinButton *self)
|
time_spin_button_text (GtkSpinButton *self)
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
char *button_text;
|
g_autofree char *button_text = NULL;
|
||||||
GtkAdjustment *adjustment;
|
GtkAdjustment *adjustment;
|
||||||
|
|
||||||
adjustment = gtk_spin_button_get_adjustment (self);
|
adjustment = gtk_spin_button_get_adjustment (self);
|
||||||
|
@ -143,7 +142,6 @@ time_spin_button_text (GtkSpinButton *self)
|
||||||
button_text = g_strdup_printf ("%02d", value);
|
button_text = g_strdup_printf ("%02d", value);
|
||||||
gtk_editable_set_text (GTK_EDITABLE (self),
|
gtk_editable_set_text (GTK_EDITABLE (self),
|
||||||
button_text);
|
button_text);
|
||||||
g_free (button_text);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -156,9 +154,9 @@ static void
|
||||||
day_selected (GtkCalendar *self,
|
day_selected (GtkCalendar *self,
|
||||||
TimePicker *time_picker)
|
TimePicker *time_picker)
|
||||||
{
|
{
|
||||||
GDateTime *date_selected;
|
g_autoptr (GDateTime) date_selected = NULL;
|
||||||
GtkPopover *popover;
|
GtkPopover *popover;
|
||||||
char *button_text;
|
g_autofree char *button_text = NULL;
|
||||||
|
|
||||||
(void) self;
|
(void) self;
|
||||||
date_selected = gtk_calendar_get_date (GTK_CALENDAR (time_picker->calendar));
|
date_selected = gtk_calendar_get_date (GTK_CALENDAR (time_picker->calendar));
|
||||||
|
@ -181,9 +179,6 @@ day_selected (GtkCalendar *self,
|
||||||
popover = GTK_POPOVER(time_picker->calendar_popover);
|
popover = GTK_POPOVER(time_picker->calendar_popover);
|
||||||
gtk_popover_popdown (popover);
|
gtk_popover_popdown (popover);
|
||||||
|
|
||||||
g_free (button_text);
|
|
||||||
g_date_time_unref (date_selected);
|
|
||||||
|
|
||||||
input_changed (GTK_WIDGET (self), time_picker);
|
input_changed (GTK_WIDGET (self), time_picker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue