Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
TimeManager
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
linux-tools
TimeManager
Commits
5748a635
Commit
5748a635
authored
Aug 08, 2019
by
Carit Zhu
🎱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish the first verion by using gtk2 library
parent
8de92bee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
105 deletions
+124
-105
main.c
main.c
+124
-105
No files found.
main.c
View file @
5748a635
...
...
@@ -11,11 +11,11 @@
#define DEBUG
/* G
Objec
ts */
static
G
Objec
t
*
entry_date
;
static
G
Objec
t
*
entry_hour
;
static
G
Objec
t
*
entry_minute
;
static
G
Objec
t
*
entry_second
;
/* G
tkWidge
ts */
static
G
tkWidge
t
*
entry_date
;
static
G
tkWidge
t
*
entry_hour
;
static
G
tkWidge
t
*
entry_minute
;
static
G
tkWidge
t
*
entry_second
;
/* Time info buffer */
static
time_t
time_now
;
...
...
@@ -164,18 +164,23 @@ static void combo_handler(GObject *combo, gpointer user_data) {
}
}
static
void
timezone_init
(
Gtk
Builder
*
builder
)
{
G
Objec
t
*
combo_timezone
;
static
void
timezone_init
(
Gtk
Widget
*
window_vbox
)
{
G
tkWidge
t
*
combo_timezone
;
GtkListStore
*
store
=
NULL
;
GtkTreeIter
iter
;
GtkTreeIter
active_iter
;
GtkCellRenderer
*
cell
=
NULL
;
combo_timezone
=
gtk_builder_get_object
(
builder
,
"combobox-timezone"
);
if
(
combo_timezone
==
NULL
)
{
g_print
(
"[ERROR] can not get combobox timezone object
\n
"
);
return
;
}
/* Timezone */
GtkWidget
*
timezone_hbox
=
gtk_hbox_new
(
TRUE
,
2
);
GtkWidget
*
label_timezone
=
gtk_label_new
(
"TimeZone:"
);
gtk_box_pack_start
(
GTK_BOX
(
timezone_hbox
),
label_timezone
,
FALSE
,
FALSE
,
3
);
combo_timezone
=
gtk_combo_box_new
();
gtk_box_pack_start
(
GTK_BOX
(
timezone_hbox
),
combo_timezone
,
FALSE
,
FALSE
,
3
);
gtk_box_pack_start
(
GTK_BOX
(
window_vbox
),
GTK_WIDGET
(
timezone_hbox
),
FALSE
,
FALSE
,
5
);
FILE
*
fp
=
popen
(
"timedatectl list-timezones"
,
"r"
);
...
...
@@ -267,83 +272,85 @@ static void date_init(GtkEntry *entry_date, GtkEntry *entry_hour, GtkEntry *entr
gtk_entry_set_text
(
entry_second
,
active_sec
);
}
static
int
gobjects_init
(
GtkBuilder
*
builder
,
GtkWidget
*
dialog
)
{
GObject
*
combo_hour
;
GObject
*
combo_minute
;
GObject
*
combo_second
;
GObject
*
button_ok
;
GObject
*
button_cancel
;
static
int
date_widget_init
(
GtkWidget
*
window_vbox
)
{
GtkWidget
*
combo_hour
;
GtkWidget
*
combo_minute
;
GtkWidget
*
combo_second
;
gchar
text
[
3
]
=
{
0
};
entry_date
=
gtk_builder_get_object
(
builder
,
"entry-date"
);
/* Date */
GtkWidget
*
date_hbox
=
gtk_hbox_new
(
TRUE
,
2
);
GtkWidget
*
label_date
=
gtk_label_new
(
"Date:"
);
gtk_box_pack_start
(
GTK_BOX
(
date_hbox
),
label_date
,
FALSE
,
FALSE
,
3
);
entry_date
=
gtk_entry_new
();
if
(
entry_date
==
NULL
)
{
g_print
(
"[ERROR] c
an not get entry date object
\n
"
);
g_print
(
"[ERROR] c
reate entry date object failed.
\n
"
);
return
-
1
;
}
gtk_box_pack_start
(
GTK_BOX
(
date_hbox
),
entry_date
,
FALSE
,
FALSE
,
3
);
entry_hour
=
gtk_builder_get_object
(
builder
,
"comboboxtext-entry-hour"
);
if
(
entry_hour
==
NULL
)
{
g_print
(
"[ERROR] can not get entry hour object
\n
"
);
return
-
1
;
}
gtk_box_pack_start
(
GTK_BOX
(
window_vbox
),
GTK_WIDGET
(
date_hbox
),
FALSE
,
FALSE
,
5
);
entry_minute
=
gtk_builder_get_object
(
builder
,
"comboboxtext-entry-minute"
);
if
(
entry_minute
==
NULL
)
{
g_print
(
"[ERROR] can not get entry minute object
\n
"
);
return
-
1
;
}
/* Time */
GtkWidget
*
hour_hbox
=
gtk_hbox_new
(
TRUE
,
2
);
GtkWidget
*
minute_hbox
=
gtk_hbox_new
(
TRUE
,
2
);
GtkWidget
*
second_hbox
=
gtk_hbox_new
(
TRUE
,
2
);
entry_second
=
gtk_builder_get_object
(
builder
,
"comboboxtext-entry-second"
);
if
(
entry_second
==
NULL
)
{
g_print
(
"[ERROR] can not get entry second object
\n
"
);
return
-
1
;
}
GtkWidget
*
label_time
=
gtk_label_new
(
"Time:"
);
gtk_box_pack_start
(
GTK_BOX
(
hour_hbox
),
label_time
,
FALSE
,
FALSE
,
3
);
combo_hour
=
gtk_builder_get_object
(
builder
,
"comboboxtext-hour"
);
if
(
combo_hour
==
NULL
)
{
g_print
(
"[ERROR] can not get combo box hour object
\n
"
);
return
-
1
;
}
/* Hour */
GtkWidget
*
label_hour
=
gtk_label_new
(
"H:"
);
gtk_box_pack_start
(
GTK_BOX
(
hour_hbox
),
label_hour
,
FALSE
,
FALSE
,
3
);
combo_hour
=
gtk_combo_box_text_new_with_entry
();
/* Add hour combo box context */
for
(
int
i
=
0
;
i
<
24
;
i
++
)
{
sprintf
(
text
,
"%d"
,
i
);
gtk_combo_box_text_append
(
GTK_COMBO_BOX_TEXT
(
combo_hour
),
text
,
text
);
gtk_combo_box_text_append
_text
(
GTK_COMBO_BOX_TEXT
(
combo_hour
)
,
text
);
}
entry_hour
=
(
GTK_BIN
(
combo_hour
)
->
child
);
gtk_box_pack_start
(
GTK_BOX
(
hour_hbox
),
combo_hour
,
FALSE
,
FALSE
,
3
);
combo_minute
=
gtk_builder_get_object
(
builder
,
"comboboxtext-minute"
);
if
(
combo_minute
==
NULL
)
{
g_print
(
"[ERROR] can not get combo box minute object
\n
"
);
return
-
1
;
}
gtk_box_pack_start
(
GTK_BOX
(
window_vbox
),
GTK_WIDGET
(
hour_hbox
),
FALSE
,
FALSE
,
5
);
/* Minute */
GtkWidget
*
label_blank1
=
gtk_label_new
(
""
);
gtk_box_pack_start
(
GTK_BOX
(
minute_hbox
),
label_blank1
,
FALSE
,
FALSE
,
3
);
GtkWidget
*
label_minute
=
gtk_label_new
(
"M:"
);
gtk_box_pack_start
(
GTK_BOX
(
minute_hbox
),
label_minute
,
FALSE
,
FALSE
,
3
);
combo_minute
=
gtk_combo_box_text_new_with_entry
();
/* Add minute combo box context */
for
(
int
i
=
0
;
i
<
60
;
i
++
)
{
sprintf
(
text
,
"%d"
,
i
);
gtk_combo_box_text_append
(
GTK_COMBO_BOX_TEXT
(
combo_minute
),
text
,
text
);
gtk_combo_box_text_append
_text
(
GTK_COMBO_BOX_TEXT
(
combo_minute
)
,
text
);
}
entry_minute
=
(
GTK_BIN
(
combo_minute
)
->
child
);
gtk_box_pack_start
(
GTK_BOX
(
minute_hbox
),
combo_minute
,
FALSE
,
FALSE
,
3
);
combo_second
=
gtk_builder_get_object
(
builder
,
"comboboxtext-second"
);
if
(
combo_second
==
NULL
)
{
g_print
(
"[ERROR] can not get combo box second object
\n
"
);
return
-
1
;
}
gtk_box_pack_start
(
GTK_BOX
(
window_vbox
),
GTK_WIDGET
(
minute_hbox
),
FALSE
,
FALSE
,
5
);
/* Second */
GtkWidget
*
label_blank2
=
gtk_label_new
(
""
);
gtk_box_pack_start
(
GTK_BOX
(
second_hbox
),
label_blank2
,
FALSE
,
FALSE
,
3
);
GtkWidget
*
label_second
=
gtk_label_new
(
"S:"
);
gtk_box_pack_start
(
GTK_BOX
(
second_hbox
),
label_second
,
FALSE
,
FALSE
,
3
);
combo_second
=
gtk_combo_box_text_new_with_entry
();
/* Add second combo box context */
for
(
int
i
=
0
;
i
<
60
;
i
++
)
{
sprintf
(
text
,
"%d"
,
i
);
gtk_combo_box_text_append
(
GTK_COMBO_BOX_TEXT
(
combo_second
),
text
,
text
);
gtk_combo_box_text_append
_text
(
GTK_COMBO_BOX_TEXT
(
combo_second
)
,
text
);
}
entry_second
=
(
GTK_BIN
(
combo_second
)
->
child
);
gtk_box_pack_start
(
GTK_BOX
(
second_hbox
),
combo_second
,
FALSE
,
FALSE
,
3
);
button_ok
=
gtk_builder_get_object
(
builder
,
"button-ok"
);
if
(
button_ok
==
NULL
)
{
g_print
(
"[ERROR] can not get button ok object
\n
"
);
return
-
1
;
}
button_cancel
=
gtk_builder_get_object
(
builder
,
"button-cancel"
);
if
(
button_cancel
==
NULL
)
{
g_print
(
"[ERROR] can not get button cancel object
\n
"
);
return
-
1
;
}
gtk_box_pack_start
(
GTK_BOX
(
window_vbox
),
GTK_WIDGET
(
second_hbox
),
FALSE
,
FALSE
,
5
);
date_init
(
GTK_ENTRY
(
entry_date
),
GTK_ENTRY
(
entry_hour
),
GTK_ENTRY
(
entry_minute
),
GTK_ENTRY
(
entry_second
));
...
...
@@ -353,60 +360,72 @@ static int gobjects_init(GtkBuilder *builder, GtkWidget *dialog) {
// gtk_combo_box_set_active_id(GTK_COMBO_BOX(combo_second), active_sec);
// gtk_combo_box_set_active(GTK_COMBO_BOX(combo_hour), tm_now->tm_hour);
// g_signal_connect(entry_date, GTK_EVENT_ACTIVATE, G_CALLBACK(date_activate), "date");
g_signal_connect
(
combo_hour
,
GTK_EVENT_CHANGED
,
G_CALLBACK
(
combo_handler
),
"hour"
);
g_signal_connect
(
button_ok
,
GTK_EVENT_CLICKED
,
G_CALLBACK
(
button_handler
),
"ok"
);
g_signal_connect
(
button_cancel
,
GTK_EVENT_CLICKED
,
G_CALLBACK
(
button_handler
),
"cancel"
);
return
0
;
}
// void close_window(GtkWidget *dialog, GtkWidget *window){
// gint result = gtk_dialog_get_response_for_widget(GTK_DIALOG(dialog), window);
// g_print("[DEBUG] result is %d\n", result);
// /* Close window without exit program*/
// //gtk_main_quit();
// gtk_widget_destroy (GTK_WIDGET (dialog));
// gtk_widget_destroy (GTK_WIDGET (window));
// }
int
main
(
int
argc
,
char
**
argv
)
{
GtkBuilder
*
builder
=
gtk_builder_new
();
GtkWidget
*
dialog
;
char
ui_path
[
64
]
=
"timemanager.ui"
;
if
(
argc
>=
3
&&
(
argc
%
2
!=
0
))
{
for
(
int
i
=
1
;
i
<
argc
;
i
+=
2
)
{
if
(
!
strcmp
(
argv
[
i
],
"--ui"
))
{
strncpy
(
ui_path
,
argv
[
i
+
1
],
63
);
}
}
}
#ifdef DEBUG
g_print
(
"[DEBUG] ui path is %s
\n
"
,
ui_path
);
#endif
GtkWidget
*
window
;
gtk_init
(
&
argc
,
&
argv
);
if
(
!
gtk_builder_add_from_file
(
builder
,
ui_path
,
NULL
))
{
g_print
(
"[ERROR] can not load glade file
\n
"
);
return
-
1
;
}
window
=
gtk_window_new
(
GTK_WINDOW_TOPLEVEL
);
dialog
=
GTK_WIDGET
(
gtk_builder_get_object
(
builder
,
"dialog-date_time"
));
if
(
dialog
==
NULL
)
{
g_print
(
"[ERROR] can not get dialog object
\n
"
);
return
-
1
;
}
gtk_window_set_title
(
GTK_WINDOW
(
dialog
),
"Date & Time"
);
gtk_window_set_default_size
(
GTK_WINDOW
(
dialog
),
320
,
240
);
gtk_window_set_title
(
GTK_WINDOW
(
window
),
"Date & Time"
);
gtk_window_set_position
(
GTK_WINDOW
(
window
),
GTK_WIN_POS_CENTER
);
gtk_window_set_default_size
(
GTK_WINDOW
(
window
),
480
,
240
);
gtk_builder_connect_signals
(
builder
,
NULL
);
g_signal_connect
(
dialog
,
GTK_EVENT_DESTROY
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
/* Create vbox for whole style(vertical) */
GtkWidget
*
window_vbox
=
gtk_vbox_new
(
TRUE
,
2
);
gobjects_init
(
builder
,
dialog
);
/* Date */
date_widget_init
(
window_vbox
);
/* Timezone */
get_time_date_status
();
timezone_init
(
builder
);
timezone_init
(
window_vbox
);
/* OK and Cancel */
GtkWidget
*
button_hbox
=
gtk_hbox_new
(
TRUE
,
2
);
GtkWidget
*
button_ok
=
gtk_button_new_with_label
(
"Ok"
);
GtkWidget
*
button_cancel
=
gtk_button_new_with_label
(
"Cancel"
);
gtk_box_pack_start
(
GTK_BOX
(
button_hbox
),
button_ok
,
TRUE
,
TRUE
,
50
);
gtk_box_pack_start
(
GTK_BOX
(
button_hbox
),
button_cancel
,
TRUE
,
TRUE
,
50
);
gtk_box_pack_start
(
GTK_BOX
(
window_vbox
),
GTK_WIDGET
(
button_hbox
),
FALSE
,
FALSE
,
5
);
g_object_unref
(
G_OBJECT
(
builder
));
gtk_widget_show_all
(
dialog
);
g_signal_connect
(
button_ok
,
GTK_EVENT_CLICKED
,
G_CALLBACK
(
button_handler
),
"ok"
);
g_signal_connect
(
button_cancel
,
GTK_EVENT_CLICKED
,
G_CALLBACK
(
button_handler
),
"cancel"
);
/* Add to container */
gtk_container_add
(
GTK_CONTAINER
(
window
),
window_vbox
);
g_signal_connect
(
window
,
GTK_EVENT_DESTROY
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
gtk_widget_show_all
(
window
);
gtk_main
();
// gint result = gtk_dialog_run (GTK_DIALOG (dialog));
// switch (result) {
// case GTK_RESPONSE_REJECT:
// break;
// case GTK_RESPONSE_OK:
// //
// break;
// default:
// break;
// }
// gtk_widget_destroy (GTK_WIDGET (dialog));
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment