From 0cc88d6a62fc8eff0b93fc6c287fc1b054ced094 Mon Sep 17 00:00:00 2001 From: rbuj Date: Wed, 19 Jun 2019 18:58:45 +0200 Subject: time-admin: Add time-admin.ui --- capplets/time-admin/src/Makefile.am | 10 +- capplets/time-admin/src/main.c | 296 ++++------------- .../time-admin/src/org.mate.mcc.ta.gresource.xml | 22 ++ capplets/time-admin/src/time-admin.ui | 365 +++++++++++++++++++++ capplets/time-admin/src/time-share.c | 61 ++-- capplets/time-admin/src/time-share.h | 7 +- capplets/time-admin/src/time-tool.c | 4 - capplets/time-admin/src/time-zone.c | 118 ++++--- 8 files changed, 571 insertions(+), 312 deletions(-) create mode 100644 capplets/time-admin/src/org.mate.mcc.ta.gresource.xml create mode 100644 capplets/time-admin/src/time-admin.ui (limited to 'capplets/time-admin/src') diff --git a/capplets/time-admin/src/Makefile.am b/capplets/time-admin/src/Makefile.am index 59332519..95b930d8 100644 --- a/capplets/time-admin/src/Makefile.am +++ b/capplets/time-admin/src/Makefile.am @@ -2,21 +2,25 @@ cappletname = time-admin bin_PROGRAMS = mate-time-admin +BUILT_SOURCES = mate-time-admin-resources.h mate-time-admin-resources.c +nodist_mate_time_admin_SOURCES = $(BUILT_SOURCES) mate_time_admin_SOURCES = \ main.c time-map.c time-share.c time-tool.c time-zone.c \ time-map.h time-share.h time-tool.h time-zone.h +mate-time-admin-resources.h mate-time-admin-resources.c: org.mate.mcc.ta.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir $(srcdir) $(srcdir)/org.mate.mcc.ta.gresource.xml) + $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate --c-name time_admin $< + mate_time_admin_LDADD = $(MATECC_CAPPLETS_LIBS) mate_time_admin_LDFLAGS = -export-dynamic AM_CPPFLAGS = \ $(MATECC_CAPPLETS_CFLAGS) \ - -DMATELOCALEDIR="\"$(datadir)/locale\""\ -DTIMPZONEDIR="\"$(datadir)/mate-time-admin/map/\"" -CLEANFILES = $(MATECC_CAPPLETS_CLEANFILES) +CLEANFILES = $(MATECC_CAPPLETS_CLEANFILES) $(BUILT_SOURCES) -EXTRA_DIST = time-zones.h +EXTRA_DIST = time-admin.ui time-zones.h org.mate.mcc.ta.gresource.xml -include $(top_srcdir)/git.mk diff --git a/capplets/time-admin/src/main.c b/capplets/time-admin/src/main.c index 721f0157..bbb960d9 100644 --- a/capplets/time-admin/src/main.c +++ b/capplets/time-admin/src/main.c @@ -25,6 +25,17 @@ #define LOCKFILE "/tmp/time-admin.pid" #define TIME_ADMIN_PERMISSION "org.freedesktop.timedate1.set-time" +static char *translate(const char *value) +{ + g_autofree gchar *zone_translated = NULL; + char *name; + + zone_translated = g_strdup (_(value)); + name = g_strdup_printf (C_("timezone loc", "%s"),zone_translated); + + return name; +} + static gboolean CheckClockHealth(gpointer data) { TimeAdmin *ta = (TimeAdmin *)data; @@ -33,6 +44,7 @@ static gboolean CheckClockHealth(gpointer data) return FALSE; } + static void update_apply_timeout(TimeAdmin *ta) { Update_Clock_Stop(ta); @@ -43,6 +55,7 @@ static void update_apply_timeout(TimeAdmin *ta) } ta->ApplyId = g_timeout_add (10000, (GSourceFunc)CheckClockHealth,ta); } + static void ChangeTimeValue(GtkSpinButton *spin_button, gpointer data) { @@ -62,25 +75,22 @@ static gboolean on_window_quit (GtkWidget *widget, QuitApp(ta); return TRUE; } + static void CloseWindow (GtkButton *button,gpointer data) { TimeAdmin *ta = (TimeAdmin *)data; QuitApp(ta); } + static void UpdatePermission(TimeAdmin *ta) { gboolean is_authorized; is_authorized = g_permission_get_allowed (G_PERMISSION (ta->Permission)); - - gtk_widget_set_sensitive(ta->HourSpin, is_authorized); - gtk_widget_set_sensitive(ta->MinuteSpin, is_authorized); - gtk_widget_set_sensitive(ta->SecondSpin, is_authorized); gtk_widget_set_sensitive(ta->TimeZoneButton, is_authorized); - gtk_widget_set_sensitive(ta->Calendar, is_authorized); - gtk_widget_set_sensitive(ta->SaveButton, is_authorized); gtk_widget_set_sensitive(ta->NtpSyncSwitch, is_authorized); + gtk_widget_set_sensitive(ta->SaveButton, is_authorized); } static void on_permission_changed (GPermission *permission, @@ -93,32 +103,58 @@ static void on_permission_changed (GPermission *permission, static void InitMainWindow(TimeAdmin *ta) { - GtkWidget *Window; - GError *error = NULL; - - Window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - ta->MainWindow = WindowLogin = Window; - gtk_window_set_deletable(GTK_WINDOW(Window),FALSE); - gtk_window_set_resizable(GTK_WINDOW(Window),FALSE); - gtk_window_set_hide_titlebar_when_maximized(GTK_WINDOW(Window),TRUE); - gtk_window_set_position(GTK_WINDOW(Window), GTK_WIN_POS_CENTER); - gtk_window_set_title(GTK_WINDOW(Window),_("Time and Date Manager")); - gtk_container_set_border_width(GTK_CONTAINER(Window),10); - gtk_widget_set_size_request(Window, 300, 360); - g_signal_connect(G_OBJECT(Window), - "delete-event", - G_CALLBACK(on_window_quit), - ta); - gtk_window_set_icon_name (GTK_WINDOW(Window), "preferences-system-time"); - ta->Permission = polkit_permission_new_sync (TIME_ADMIN_PERMISSION, - NULL, - NULL, - &error); + GError *error = NULL; + GtkBuilder *builder; + + builder = gtk_builder_new_from_resource ("/org/mate/mcc/ta/time-admin.ui"); + gtk_builder_add_callback_symbols (builder, + "on_window_quit", G_CALLBACK (on_window_quit), + "on_button1_clicked", G_CALLBACK (RunTimeZoneDialog), + "on_button2_clicked", G_CALLBACK (SaveModifyTime), + "on_button3_clicked", G_CALLBACK (CloseWindow), + "on_spin1_changed", G_CALLBACK (ChangeTimeValue), + "on_spin2_changed", G_CALLBACK (ChangeTimeValue), + "on_spin3_changed", G_CALLBACK (ChangeTimeValue), + "on_switch1_state_set", G_CALLBACK (ChangeNtpSync), + NULL); + gtk_builder_connect_signals (builder, ta); + ta->MainWindow = GTK_WIDGET (gtk_builder_get_object (builder, "window1")); + ta->HourSpin = GTK_WIDGET (gtk_builder_get_object (builder, "spin1")); + ta->MinuteSpin = GTK_WIDGET (gtk_builder_get_object (builder, "spin2")); + ta->SecondSpin = GTK_WIDGET (gtk_builder_get_object (builder, "spin3")); + ta->TimeZoneButton = GTK_WIDGET (gtk_builder_get_object (builder, "button1")); + ta->TimeZoneEntry = GTK_WIDGET (gtk_builder_get_object (builder, "entry1")); + ta->NtpSyncSwitch = GTK_WIDGET (gtk_builder_get_object (builder, "switch1")); + ta->Calendar = GTK_WIDGET (gtk_builder_get_object (builder, "calendar1")); + ta->SaveButton = GTK_WIDGET (gtk_builder_get_object (builder, "button2")); + ta->ButtonLock = GTK_WIDGET (gtk_builder_get_object (builder, "button4")); + g_object_unref (builder); + + /* Make sure that every window gets an icon */ + gtk_window_set_default_icon_name ("preferences-system-time"); + + ta->Permission = polkit_permission_new_sync (TIME_ADMIN_PERMISSION, NULL, NULL, &error); if (ta->Permission == NULL) { g_warning ("Failed to acquire %s: %s", TIME_ADMIN_PERMISSION, error->message); g_error_free (error); } + gtk_lock_button_set_permission(GTK_LOCK_BUTTON (ta->ButtonLock),ta->Permission); + g_signal_connect(ta->Permission, "notify", G_CALLBACK (on_permission_changed), ta); + + struct tm *LocalTime = GetCurrentTime(); + ta->UpdateTimeId = 0; + ta->ApplyId = 0; + Update_Clock_Start(ta); + SetupTimezoneDialog(ta); + const char *TimeZone = GetTimeZone(ta); + char *ZoneName = translate(TimeZone); + gtk_entry_set_text (GTK_ENTRY (ta->TimeZoneEntry), ZoneName); + g_free (ZoneName); + ta->NtpState = GetNtpState(ta); + gtk_switch_set_state (GTK_SWITCH(ta->NtpSyncSwitch), ta->NtpState); + gtk_calendar_mark_day (GTK_CALENDAR(ta->Calendar), LocalTime->tm_mday); + ta->OldDay = LocalTime->tm_mday; } static int RecordPid(void) @@ -127,6 +163,7 @@ static int RecordPid(void) int fd; int Length = 0; char WriteBuf[30] = { 0 }; + fd = open(LOCKFILE,O_WRONLY|O_CREAT|O_TRUNC,0777); if(fd < 0) { @@ -146,6 +183,7 @@ static int RecordPid(void) return 0; } + /****************************************************************************** * Function: ProcessRuning * @@ -194,200 +232,8 @@ static gboolean ProcessRuning(void) ERROREXIT: close(fd); return TRUE; - } -static char *translate(const char *value) -{ - g_autofree gchar *zone_translated = NULL; - char *name; - zone_translated = g_strdup (_(value)); - name = g_strdup_printf (C_("timezone loc", "%s"),zone_translated); - - return name; -} -static GtkWidget * TimeZoneAndNtp(TimeAdmin *ta) -{ - GtkWidget *table; - GtkWidget *TimeZoneLabel; - GtkWidget *NtpSyncLabel; - const char *TimeZone; - gboolean NtpState; - char *ZoneName; - - table = gtk_grid_new(); - gtk_grid_set_column_homogeneous(GTK_GRID(table),TRUE); - - TimeZoneLabel = gtk_label_new (_("Time Zone:")); - gtk_widget_set_halign(TimeZoneLabel,GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(table) ,TimeZoneLabel, 0 , 0 , 1 , 1); - - SetupTimezoneDialog(ta); - TimeZone = GetTimeZone(ta); - ZoneName = translate(TimeZone); - ta->TimeZoneButton = gtk_button_new_with_label(ZoneName); - g_signal_connect (ta->TimeZoneButton, - "clicked", - G_CALLBACK (RunTimeZoneDialog), - ta); - - gtk_grid_attach(GTK_GRID(table) ,ta->TimeZoneButton,1 , 0 , 3 , 1); - - NtpSyncLabel = gtk_label_new (_("Ntp Sync:")); - gtk_widget_set_halign(NtpSyncLabel,GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(table) ,NtpSyncLabel, 0 , 1 , 1 , 1); - - ta->NtpSyncSwitch = gtk_switch_new(); - NtpState = GetNtpState(ta); - ta->NtpState = NtpState; - gtk_switch_set_state (GTK_SWITCH(ta->NtpSyncSwitch), - NtpState); - gtk_grid_attach(GTK_GRID(table) ,ta->NtpSyncSwitch, 1 , 1 , 1 , 1); - g_signal_connect (G_OBJECT(ta->NtpSyncSwitch), - "state-set", - G_CALLBACK (ChangeNtpSync), - ta); - - gtk_grid_set_row_spacing(GTK_GRID(table), 6); - gtk_grid_set_column_spacing(GTK_GRID(table), 12); - - return table; - -} - -static GtkWidget *GetSpinButton(int Initial,int Maximum,TimeAdmin *ta) -{ - GtkWidget *SpinButton; - GtkAdjustment *Adjustment; - - Adjustment = gtk_adjustment_new (Initial, 0, Maximum, 1, 0, 0); - SpinButton = gtk_spin_button_new (Adjustment, 1, 0); - gtk_widget_set_sensitive(SpinButton,!ta->NtpState); - gtk_widget_set_halign(SpinButton,GTK_ALIGN_START); - gtk_spin_button_set_wrap(GTK_SPIN_BUTTON (SpinButton), TRUE); - gtk_spin_button_set_numeric(GTK_SPIN_BUTTON (SpinButton),TRUE); - gtk_widget_set_hexpand (SpinButton,TRUE); - g_signal_connect (SpinButton, - "changed", - G_CALLBACK (ChangeTimeValue), - ta); - - SetTooltip(SpinButton,!ta->NtpState); - return SpinButton; -} -static GtkWidget *SetClock(TimeAdmin *ta) -{ - GtkWidget *table; - GtkWidget *TimeLabel; - struct tm *LocalTime; - - table = gtk_grid_new(); - gtk_grid_set_column_homogeneous(GTK_GRID(table),TRUE); - - TimeLabel = gtk_label_new (_("Set Time")); - gtk_widget_set_halign(TimeLabel,GTK_ALIGN_CENTER); - gtk_widget_set_valign(TimeLabel,GTK_ALIGN_START); - gtk_widget_set_hexpand(TimeLabel,FALSE); - gtk_grid_attach(GTK_GRID(table) ,TimeLabel, 1 , 0 , 1 , 1); - - LocalTime = GetCurrentTime(); - ta->UpdateTimeId = 0; - ta->ApplyId = 0; - - ta->HourSpin = GetSpinButton(LocalTime->tm_hour,23,ta); - gtk_grid_attach(GTK_GRID(table) ,ta->HourSpin, 0 , 1 , 1 , 1); - - ta->MinuteSpin = GetSpinButton(LocalTime->tm_min,59,ta); - gtk_grid_attach(GTK_GRID(table) ,ta->MinuteSpin, 1 , 1 , 1 , 1); - - ta->SecondSpin = GetSpinButton (LocalTime->tm_sec,59,ta); - gtk_grid_attach(GTK_GRID(table) ,ta->SecondSpin, 2 , 1 , 1 , 1); - - Update_Clock_Start(ta); - - gtk_grid_set_row_spacing(GTK_GRID(table), 6); - gtk_grid_set_column_spacing(GTK_GRID(table), 12); - - return table; -} - -static GtkWidget *SetDate(TimeAdmin *ta) -{ - GtkWidget *table, *image, *DateLabel; - struct tm *LocalTime; - - table = gtk_grid_new(); - gtk_grid_set_column_homogeneous (GTK_GRID(table), TRUE); - - DateLabel = gtk_label_new (_("Set Date")); - gtk_grid_attach(GTK_GRID(table) ,DateLabel, 1 , 0 , 2 , 2); - - LocalTime = GetCurrentTime (); - ta->Calendar = gtk_calendar_new (); - gtk_widget_set_sensitive (ta->Calendar, !ta->NtpState); - SetTooltip (ta->Calendar, !ta->NtpState); - gtk_calendar_mark_day (GTK_CALENDAR(ta->Calendar), LocalTime->tm_mday); - ta->OldDay = LocalTime->tm_mday; - gtk_grid_attach (GTK_GRID(table), ta->Calendar, 0, 2, 4, 3); - - ta->CloseButton = gtk_button_new_with_label (_("_Close")); - image = gtk_image_new_from_icon_name ("gtk-close", GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (ta->CloseButton), image); - gtk_button_set_use_underline (GTK_BUTTON(ta->CloseButton), TRUE); - gtk_style_context_add_class (gtk_widget_get_style_context (ta->CloseButton), "text-button"); - gtk_grid_attach (GTK_GRID(table), ta->CloseButton, 3, 5, 1, 1); - g_signal_connect (ta->CloseButton, - "clicked", - G_CALLBACK (CloseWindow), - ta); - - if (ta->Permission) - { - ta->ButtonLock = gtk_lock_button_new (ta->Permission); - gtk_lock_button_set_permission (GTK_LOCK_BUTTON (ta->ButtonLock),ta->Permission); - gtk_grid_attach (GTK_GRID(table), ta->ButtonLock, 0, 5, 1, 1); - g_signal_connect (ta->Permission, - "notify", - G_CALLBACK (on_permission_changed), - ta); - } - - ta->SaveButton = gtk_button_new_with_label (_("_Save")); - image = gtk_image_new_from_icon_name ("gtk-save", GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (ta->SaveButton), image); - gtk_button_set_use_underline (GTK_BUTTON(ta->SaveButton), TRUE); - gtk_style_context_add_class (gtk_widget_get_style_context (ta->SaveButton), "text-button"); - gtk_widget_set_sensitive (ta->SaveButton, !ta->NtpState); - gtk_grid_attach (GTK_GRID(table), ta->SaveButton, 2, 5, 1, 1); - g_signal_connect (ta->SaveButton, - "clicked", - G_CALLBACK (SaveModifyTime), - ta); - - gtk_grid_set_row_spacing (GTK_GRID(table), 6); - gtk_grid_set_column_spacing (GTK_GRID(table), 12); - - return table; -} - -static void CreateClockInterface(TimeAdmin *ta) -{ - GtkWidget *Vbox; - GtkWidget *Vbox1; - GtkWidget *Vbox2; - GtkWidget *Vbox3; - - Vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add(GTK_CONTAINER(ta->MainWindow), Vbox); - - Vbox1 = TimeZoneAndNtp(ta); - gtk_box_pack_start(GTK_BOX(Vbox),Vbox1,TRUE,TRUE,8); - - Vbox2 = SetClock(ta); - gtk_box_pack_start(GTK_BOX(Vbox),Vbox2,TRUE,TRUE,8); - Vbox3 = SetDate(ta); - gtk_box_pack_start(GTK_BOX(Vbox),Vbox3,TRUE,TRUE,8); -} static gboolean InitDbusProxy(TimeAdmin *ta) { GError *error = NULL; @@ -424,18 +270,16 @@ int main(int argc, char **argv) capplet_init (NULL, &argc, &argv); - /* Create the main window */ - InitMainWindow(&ta); - /* Check whether the process has been started */ if(ProcessRuning() == TRUE) exit(0); if(InitDbusProxy(&ta) == FALSE) - { exit(0); - } - CreateClockInterface(&ta); - UpdatePermission(&ta); + + /* Create the main window */ + InitMainWindow(&ta); + + UpdatePermission(&ta); gtk_widget_show_all(ta.MainWindow); gtk_main(); diff --git a/capplets/time-admin/src/org.mate.mcc.ta.gresource.xml b/capplets/time-admin/src/org.mate.mcc.ta.gresource.xml new file mode 100644 index 00000000..44a6c03b --- /dev/null +++ b/capplets/time-admin/src/org.mate.mcc.ta.gresource.xml @@ -0,0 +1,22 @@ + + + + + time-admin.ui + + diff --git a/capplets/time-admin/src/time-admin.ui b/capplets/time-admin/src/time-admin.ui new file mode 100644 index 00000000..7539d2cc --- /dev/null +++ b/capplets/time-admin/src/time-admin.ui @@ -0,0 +1,365 @@ + + + + + + 23 + 1 + 10 + + + 59 + 1 + 10 + + + 59 + 1 + 10 + + + False + Time and Date Manager + False + center + preferences-system-time + + + + + + + True + False + vertical + + + True + False + 12 + 12 + 12 + 6 + 0 + none + + + True + False + 6 + 6 + 12 + + + True + False + 6 + 12 + + + True + False + end + NTP sync + + + 0 + 0 + + + + + True + True + start + + + + 1 + 0 + + + + + True + False + end + Time zone + + + 0 + 1 + + + + + True + False + 6 + + + True + False + False + True + False + 25 + False + + + False + True + 0 + + + + + gtk-edit + True + True + True + True + True + + + + False + True + 1 + + + + + 1 + 1 + + + + + + + + + True + False + Preferences + + + + + + + + False + True + 0 + + + + + True + False + 12 + 12 + 6 + 6 + 0 + none + + + True + False + 6 + 6 + 12 + + + True + False + 6 + 6 + 12 + True + + + True + + True + 2 + False + digits + adjustament1 + + + + False + True + 0 + + + + + True + + True + 2 + False + digits + adjustament2 + + + + False + True + 1 + + + + + True + + True + 2 + False + 1 + digits + adjustament3 + + + + False + True + 2 + + + + + + + + + True + False + Time + + + + + + + + False + True + 1 + + + + + True + False + 12 + 12 + 6 + 0 + none + + + True + False + 6 + 6 + 6 + 12 + + + True + + True + 2019 + 5 + 20 + + + + + + + True + False + Date + + + + + + + + False + True + 2 + + + + + True + False + end + 18 + 18 + 18 + 18 + 12 + end + + + True + True + 18 + + + True + True + 0 + + + + + gtk-save + True + True + True + True + + + + True + True + 1 + + + + + gtk-close + True + True + True + True + + + + True + True + 2 + + + + + False + True + 3 + + + + + + diff --git a/capplets/time-admin/src/time-share.c b/capplets/time-admin/src/time-share.c index 379134e3..b5038779 100644 --- a/capplets/time-admin/src/time-share.c +++ b/capplets/time-admin/src/time-share.c @@ -22,18 +22,20 @@ #include /****************************************************************************** -* Function: MessageReport -* -* Explain: Prompt information dialog -* -* Input: @Title Message title -* @Msg Message content -* @nType Message type -* Output: -* -* Author: zhuyaliang 25/05/2018 -******************************************************************************/ -int MessageReport(const char *Title,const char *Msg,int nType) + * Function: MessageReport + * + * Explain: Prompt information dialog + * + * Input: @Title Message title + * @Msg Message content + * @nType Message type + * Output: + * + * Author: zhuyaliang 25/05/2018 + ******************************************************************************/ +int MessageReport(const char *Title, + const char *Msg, + int nType) { GtkWidget *dialog = NULL; int nRet; @@ -42,49 +44,49 @@ int MessageReport(const char *Title,const char *Msg,int nType) { case ERROR: { - dialog = gtk_message_dialog_new(GTK_WINDOW(WindowLogin), - GTK_DIALOG_DESTROY_WITH_PARENT, + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - "%s",Title); + "%s", Title); break; } case WARING: { - dialog = gtk_message_dialog_new(GTK_WINDOW(WindowLogin), - GTK_DIALOG_DESTROY_WITH_PARENT, + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, - "%s",Title); + "%s", Title); break; } case INFOR: { - dialog = gtk_message_dialog_new(GTK_WINDOW(WindowLogin), - GTK_DIALOG_DESTROY_WITH_PARENT, + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, - "%s",Title); + "%s", Title); break; } case QUESTION: { - dialog = gtk_message_dialog_new(GTK_WINDOW(WindowLogin), - GTK_DIALOG_DESTROY_WITH_PARENT, + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, - "%s",Title); + "%s", Title); gtk_dialog_add_button (GTK_DIALOG (dialog),("_Return"), GTK_RESPONSE_ACCEPT); break; } case QUESTIONNORMAL: { - dialog = gtk_message_dialog_new(GTK_WINDOW(WindowLogin), - GTK_DIALOG_DESTROY_WITH_PARENT, + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, - "%s",Title); + "%s", Title); break; } default : @@ -102,13 +104,10 @@ int MessageReport(const char *Title,const char *Msg,int nType) void QuitApp(TimeAdmin *ta) { if(ta->UpdateTimeId > 0) - { g_source_remove (ta->UpdateTimeId); - } + if(ta->ApplyId > 0) - { g_source_remove(ta->ApplyId); - } gtk_main_quit(); } diff --git a/capplets/time-admin/src/time-share.h b/capplets/time-admin/src/time-share.h index 1a842e1c..346944be 100644 --- a/capplets/time-admin/src/time-share.h +++ b/capplets/time-admin/src/time-share.h @@ -40,8 +40,7 @@ #define QUESTIONNORMAL 5 -GtkWidget *WindowLogin; -int TimeoutFlag; +int TimeoutFlag; typedef struct { GtkWidget *MainWindow; @@ -49,9 +48,9 @@ typedef struct GtkWidget *MinuteSpin; GtkWidget *SecondSpin; GtkWidget *TimeZoneButton; + GtkWidget *TimeZoneEntry; GtkWidget *NtpSyncSwitch; GtkWidget *Calendar; - GtkWidget *CloseButton; GtkWidget *SaveButton; int UpdateTimeId; int ApplyId; @@ -67,7 +66,7 @@ typedef struct GtkWidget *map; GtkListStore *CityListStore; GtkTreeModelSort *CityModelSort; - GtkWidget *ButtonLock; + GtkWidget *ButtonLock; GPermission *Permission; }TimeAdmin; diff --git a/capplets/time-admin/src/time-tool.c b/capplets/time-admin/src/time-tool.c index 0029f3bb..a5e13f03 100644 --- a/capplets/time-admin/src/time-tool.c +++ b/capplets/time-admin/src/time-tool.c @@ -191,13 +191,9 @@ static void ChangeSpinBttonState(TimeAdmin *ta,gboolean State) { gtk_widget_set_sensitive(ta->SaveButton,!State); SetTooltip(ta->SaveButton,!ta->NtpState); - gtk_widget_set_sensitive(ta->HourSpin, !State); SetTooltip(ta->HourSpin,!ta->NtpState); - gtk_widget_set_sensitive(ta->MinuteSpin,!State); SetTooltip(ta->MinuteSpin,!ta->NtpState); - gtk_widget_set_sensitive(ta->SecondSpin,!State); SetTooltip(ta->SecondSpin,!ta->NtpState); - gtk_widget_set_sensitive(ta->Calendar, !State); SetTooltip(ta->Calendar,!ta->NtpState); } diff --git a/capplets/time-admin/src/time-zone.c b/capplets/time-admin/src/time-zone.c index e6106f1b..713314cf 100644 --- a/capplets/time-admin/src/time-zone.c +++ b/capplets/time-admin/src/time-zone.c @@ -41,17 +41,21 @@ #include - #define DEFAULT_TZ "Europe/London" #define BACKFILE "/usr/share/mate-time-admin/map/backward" + static void LocationChanged(TimezoneMap *map, - TzLocation *location,TimeAdmin *ta); + TzLocation *location, + TimeAdmin *ta); + enum { CITY_COL_CITY_HUMAN_READABLE, CITY_COL_ZONE, CITY_NUM_COLS }; -static gchar *tz_data_file_get (void) + +static gchar* +tz_data_file_get (void) { gchar *file; @@ -60,25 +64,31 @@ static gchar *tz_data_file_get (void) return file; } -static float convert_pos (gchar *pos, int digits) +static float +convert_pos (gchar *pos, int digits) { - gchar whole[10]; - gchar *fraction; + gchar whole[10], *fraction; gint i; float t1, t2; - if (!pos || strlen(pos) < 4 || digits > 9) return 0.0; + if (!pos || strlen(pos) < 4 || digits > 9) + return 0.0; + + for (i = 0; i < digits + 1; i++) + whole[i] = pos[i]; - for (i = 0; i < digits + 1; i++) whole[i] = pos[i]; whole[i] = '\0'; fraction = pos + digits + 1; t1 = g_strtod (whole, NULL); t2 = g_strtod (fraction, NULL); - if (t1 >= 0.0) return t1 + t2/pow (10.0, strlen(fraction)); - else return t1 - t2/pow (10.0, strlen(fraction)); + if (t1 >= 0.0) + return t1 + t2/pow (10.0, strlen(fraction)); + else + return t1 - t2/pow (10.0, strlen(fraction)); } + static int compare_country_names (const void *a, const void *b) { const TzLocation *tza = * (TzLocation **) a; @@ -174,14 +184,16 @@ TzDB *tz_load_db (void) gchar *p; TzLocation *loc; - if (*buf == '#') continue; + if (*buf == '#') + continue; g_strchomp(buf); tmpstrarr = g_strsplit(buf,"\t", 6); latstr = g_strdup (tmpstrarr[1]); p = latstr + 1; - while (*p != '-' && *p != '+') p++; + while (*p != '-' && *p != '+') + p++; lngstr = g_strdup (p); *p = '\0'; @@ -195,7 +207,8 @@ TzDB *tz_load_db (void) if (tmpstrarr[3] && *tmpstrarr[3] == '-' && tmpstrarr[4]) loc->comment = g_strdup (tmpstrarr[4]); - if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) { + if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) + { TzLocation *locgrp; locgrp = g_new0 (TzLocation, 1); locgrp->country = g_strdup (tmpstrarr[0]); @@ -224,7 +237,8 @@ TzDB *tz_load_db (void) return tz_db; } -static GtkWidget *GetTimeZoneMap(TimeAdmin *ta) +static GtkWidget* +GetTimeZoneMap(TimeAdmin *ta) { GtkWidget *map; g_autoptr(GtkEntryCompletion) completion = NULL; @@ -240,7 +254,6 @@ static GtkWidget *GetTimeZoneMap(TimeAdmin *ta) gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (ta->CityListStore)); gtk_entry_completion_set_text_column (completion, CITY_COL_CITY_HUMAN_READABLE); - return map; } static char * @@ -305,13 +318,14 @@ update_timezone (TimezoneMap *map) g_date_time_unref(date); } -static void LocationChanged(TimezoneMap *map, - TzLocation *location, - TimeAdmin *ta) +static void +LocationChanged(TimezoneMap *map, + TzLocation *location, + TimeAdmin *ta) { - update_timezone (map); } + static void get_initial_timezone (TimeAdmin *ta) { @@ -327,8 +341,10 @@ get_initial_timezone (TimeAdmin *ta) } update_timezone (TIMEZONEMAP(ta->map)); } -static void LoadCities (TzLocation *loc, - GtkListStore *CityStore) + +static void +LoadCities (TzLocation *loc, + GtkListStore *CityStore) { g_autofree gchar *human_readable = NULL; @@ -340,20 +356,22 @@ static void LoadCities (TzLocation *loc, human_readable, CITY_COL_ZONE, loc->zone, - -1); + -1); } -static void CreateCityList(TimeAdmin *ta) +static void +CreateCityList(TimeAdmin *ta) { TzDB *db; ta->CityListStore = gtk_list_store_new (CITY_NUM_COLS,G_TYPE_STRING,G_TYPE_STRING); - db = tz_load_db (); g_ptr_array_foreach (db->locations, (GFunc) LoadCities, ta->CityListStore); TimeZoneDateBaseFree(db); } -static GtkWidget *CreateZoneFrame(TimeAdmin *ta) + +static GtkWidget* +CreateZoneFrame(TimeAdmin *ta) { GtkWidget *TimeZoneFrame; @@ -363,19 +381,26 @@ static GtkWidget *CreateZoneFrame(TimeAdmin *ta) return TimeZoneFrame; } -static GtkWidget *CreateZoneScrolled(TimeAdmin *ta) + +static GtkWidget* +CreateZoneScrolled(TimeAdmin *ta) { GtkWidget *Scrolled; + Scrolled = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (Scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (Scrolled), GTK_SHADOW_IN); return Scrolled; } -static void CreateZoneEntry(TimeAdmin *ta) + +static void +CreateZoneEntry(TimeAdmin *ta) { GtkWidget *hbox; @@ -390,13 +415,13 @@ static void CreateZoneEntry(TimeAdmin *ta) gtk_search_bar_set_show_close_button (GTK_SEARCH_BAR (ta->SearchBar),FALSE); gtk_container_add (GTK_CONTAINER (ta->SearchBar), hbox); gtk_search_bar_set_search_mode(GTK_SEARCH_BAR(ta->SearchBar),TRUE); - } -static gboolean CityChanged(GtkEntryCompletion *completion, - GtkTreeModel *model, - GtkTreeIter *iter, - TimeAdmin *self) +static gboolean +CityChanged(GtkEntryCompletion *completion, + GtkTreeModel *model, + GtkTreeIter *iter, + TimeAdmin *self) { GtkWidget *entry; g_autofree gchar *zone = NULL; @@ -413,22 +438,22 @@ static gboolean CityChanged(GtkEntryCompletion *completion, return TRUE; } -static void ChoooseTimezoneDone (GtkWidget *widget, - TimeAdmin *ta) + +static void +ChoooseTimezoneDone (GtkWidget *widget, + TimeAdmin *ta) { TimezoneMap *map; - g_autofree gchar *ZoneCity = NULL; map = TIMEZONEMAP(ta->map); SetTimeZone(ta->proxy,map->location->zone); - - ZoneCity = translated_city_name(map->location); - gtk_button_set_label((GTK_BUTTON(ta->TimeZoneButton)),ZoneCity); + gtk_entry_set_text (GTK_ENTRY (ta->TimeZoneEntry), _(map->location->zone)); gtk_widget_hide_on_delete(GTK_WIDGET(ta->dialog)); } -static void ChoooseTimezoneClose(GtkWidget *widget, - TimeAdmin *ta) +static void +ChoooseTimezoneClose(GtkWidget *widget, + TimeAdmin *ta) { gtk_widget_hide_on_delete(GTK_WIDGET(ta->dialog)); } @@ -443,8 +468,6 @@ void SetupTimezoneDialog(TimeAdmin *ta) NULL, NULL); gtk_window_set_default_size (GTK_WINDOW (ta->dialog), 730, 520); - gtk_window_set_icon_name (GTK_WINDOW(ta->dialog), "preferences-system-time"); - ta->TZclose = gtk_button_new_with_mnemonic (_("_Close")); image = gtk_image_new_from_icon_name ("window-close", GTK_ICON_SIZE_BUTTON); @@ -498,6 +521,7 @@ void SetupTimezoneDialog(TimeAdmin *ta) TRUE, TRUE, 8); } + void tz_info_free (TzInfo *tzinfo) { g_return_if_fail (tzinfo != NULL); @@ -506,6 +530,7 @@ void tz_info_free (TzInfo *tzinfo) if (tzinfo->tzname_daylight) g_free (tzinfo->tzname_daylight); g_free (tzinfo); } + struct { const char *orig; const char *dest; @@ -533,9 +558,10 @@ struct { { "MST", "America/Denver" }, /* Other name for the mountain tz */ { "MST7MDT", "America/Denver" }, /* ditto */ }; + static gboolean compare_timezones (const char *a, - const char *b) + const char *b) { if (g_str_equal (a, b)) return TRUE; @@ -639,6 +665,7 @@ TzInfo *tz_info_from_location (TzLocation *loc) return tzinfo; } + glong tz_location_get_utc_offset (TzLocation *loc) { TzInfo *tz_info; @@ -650,6 +677,7 @@ glong tz_location_get_utc_offset (TzLocation *loc) return offset; } + void RunTimeZoneDialog (GtkButton *button, gpointer data) { @@ -657,15 +685,16 @@ void RunTimeZoneDialog (GtkButton *button, gtk_widget_show_all(GTK_WIDGET(ta->dialog)); } + static void tz_location_free (TzLocation *loc, gpointer data) { g_free (loc->country); g_free (loc->zone); g_free (loc->comment); - g_free (loc); } + void TimeZoneDateBaseFree (TzDB *db) { g_ptr_array_foreach (db->locations, (GFunc) tz_location_free, NULL); @@ -673,6 +702,7 @@ void TimeZoneDateBaseFree (TzDB *db) g_hash_table_destroy (db->backward); g_free (db); } + GPtrArray *tz_get_locations (TzDB *db) { return db->locations; -- cgit v1.2.1