aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnia <jthidskes@live.nl>2013-04-08 20:55:40 +0200
committerUnia <jthidskes@live.nl>2013-04-08 20:55:40 +0200
commit5b472a23ff91fc7385ce6704fcdfcc48f76b872f (patch)
treef6ebaad3613fd7f3543e382554a061226825e456
parent7a0637f2ea56fca8d5963ff2607fd62146336edb (diff)
started implementing tabs and countdown timer
-rw-r--r--README.md1
-rw-r--r--gstopwatch.c49
2 files changed, 28 insertions, 22 deletions
diff --git a/README.md b/README.md
index 7eae229..a3ccd7a 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,6 @@ ToDo
* Add a timer function too, in GtkNotebook?
* Fix split
-* Centralize list stores
* Button background colors
* This doesn't work in some themes, so for now we won't implement this. See:
https://bugzilla.gnome.org/show_bug.cgi?id=656461
diff --git a/gstopwatch.c b/gstopwatch.c
index 3ae0c62..8970515 100644
--- a/gstopwatch.c
+++ b/gstopwatch.c
@@ -36,7 +36,7 @@ GTimer *timer;
gchar output[100];
gint state = STOPPED, lap = 0, hours, minutes; /*split_hours, split_minutes, prev_hours, prev_minutes;*/
gdouble seconds; /*split_seconds, prev_seconds;*/
-GtkWidget *timer_display, *button_timer, *button_funcs, *tree;
+GtkWidget *timer_display, *button_stopwatch, *button_funcs, *tree;
GtkListStore *liststore;
GtkTreeSelection *selection;
GtkTreeIter selection_iter, iter;
@@ -76,18 +76,18 @@ void add_lap (void) {
void on_timer_button_clicked (void) {
if(state == STOPPED) {
- gtk_button_set_label(GTK_BUTTON(button_timer), "Stop");
+ gtk_button_set_label(GTK_BUTTON(button_stopwatch), "Stop");
gtk_widget_set_sensitive(GTK_WIDGET(button_funcs), TRUE);
gtk_button_set_label(GTK_BUTTON(button_funcs), "Lap");
g_timer_start(timer);
state = STARTED;
} else if(state == PAUSED) {
- gtk_button_set_label(GTK_BUTTON(button_timer), "Stop");
+ gtk_button_set_label(GTK_BUTTON(button_stopwatch), "Stop");
gtk_button_set_label(GTK_BUTTON(button_funcs), "Lap");
g_timer_continue(timer);
state = STARTED;
} else if(state == STARTED) {
- gtk_button_set_label(GTK_BUTTON(button_timer), "Continue");
+ gtk_button_set_label(GTK_BUTTON(button_stopwatch), "Continue");
gtk_widget_set_sensitive(GTK_WIDGET(button_funcs), TRUE);
gtk_button_set_label(GTK_BUTTON(button_funcs), "Reset");
g_timer_stop(timer);
@@ -103,28 +103,36 @@ void on_funcs_button_clicked (void) {
g_timer_stop(timer);
gtk_widget_set_sensitive(GTK_WIDGET(button_funcs), FALSE);
gtk_button_set_label(GTK_BUTTON(button_funcs), "Reset");
- gtk_button_set_label(GTK_BUTTON(button_timer), "Start");
+ gtk_button_set_label(GTK_BUTTON(button_stopwatch), "Start");
gtk_list_store_clear(GTK_LIST_STORE(liststore));
state = STOPPED;
}
}
int main (int argc, char *argv[]) {
- GtkWidget *window, *vbox, *hbox, *scroll;
+ GtkWidget *window, *notebook, *label_stopwatch, *vbox_stopwatch, *hbox_stopwatch, *scroll, *label_timer, *vbox_timer, *button_timer;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
gtk_init(&argc, &argv);
- vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
- hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
+ notebook = gtk_notebook_new();
+ gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), TRUE);
+
+ vbox_stopwatch = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
+ hbox_stopwatch = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
+ label_stopwatch = gtk_label_new("Stopwatch");
timer_display = gtk_label_new("");
- button_timer = gtk_button_new_with_label("Start");
+ button_stopwatch = gtk_button_new_with_label("Start");
button_funcs = gtk_button_new_with_label("Reset");
gtk_widget_set_sensitive(button_funcs, FALSE);
scroll = gtk_scrolled_window_new (NULL, NULL);
g_object_set (scroll, "shadow-type", GTK_SHADOW_IN, NULL);
+ vbox_timer = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
+ label_timer = gtk_label_new("Timer");
+ button_timer = gtk_button_new_with_label("Start");
+
tree = gtk_tree_view_new();
liststore = gtk_list_store_new(N_COLUMNS, G_TYPE_INT, /*G_TYPE_STRING, */G_TYPE_STRING);
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
@@ -132,43 +140,42 @@ int main (int argc, char *argv[]) {
column = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(column, "Lap");
- gtk_tree_view_column_set_expand(column, TRUE);
- gtk_tree_view_column_set_alignment(column, 0.5);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(column, renderer, TRUE);
gtk_tree_view_column_set_attributes(column, renderer, "text", N_LAP, NULL);
gtk_tree_view_column_set_expand(column, TRUE);
- gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
/*renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("Split", renderer, "text", SPLIT, NULL);
gtk_tree_view_column_set_expand(column, TRUE);
- gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);*/
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("Time", renderer, "text", TIME, NULL);
gtk_tree_view_column_set_expand(column, TRUE);
- gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
- gtk_box_pack_start(GTK_BOX(vbox), timer_display, FALSE, TRUE, 5);
- gtk_box_pack_start(GTK_BOX(hbox), button_timer, TRUE, TRUE, 5);
- gtk_box_pack_start(GTK_BOX(hbox), button_funcs, TRUE, TRUE, 5);
- gtk_container_add(GTK_CONTAINER(vbox), hbox);
+ gtk_box_pack_start(GTK_BOX(vbox_stopwatch), timer_display, FALSE, TRUE, 5);
+ gtk_box_pack_start(GTK_BOX(hbox_stopwatch), button_stopwatch, TRUE, TRUE, 5);
+ gtk_box_pack_start(GTK_BOX(hbox_stopwatch), button_funcs, TRUE, TRUE, 5);
+ gtk_container_add(GTK_CONTAINER(vbox_stopwatch), hbox_stopwatch);
gtk_container_add(GTK_CONTAINER(scroll), tree);
- gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 5);
+ gtk_box_pack_start(GTK_BOX(vbox_stopwatch), scroll, TRUE, TRUE, 5);
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_stopwatch, label_stopwatch);
+
+ gtk_box_pack_start(GTK_BOX(vbox_timer), button_timer, TRUE, TRUE, 5);
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_timer, label_timer);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW(window), "Gstopwatch");
gtk_window_set_default_icon_name("clocks");
- gtk_container_add(GTK_CONTAINER(window), vbox);
+ gtk_container_add(GTK_CONTAINER(window), notebook);
gtk_widget_show_all(window);
timer = g_timer_new();
@@ -176,7 +183,7 @@ int main (int argc, char *argv[]) {
g_timeout_add_full(G_PRIORITY_HIGH, 50, (GSourceFunc) stopwatch, NULL, NULL);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
- g_signal_connect(button_timer, "clicked", G_CALLBACK(on_timer_button_clicked), NULL);
+ g_signal_connect(button_stopwatch, "clicked", G_CALLBACK(on_timer_button_clicked), NULL);
g_signal_connect(button_funcs, "clicked", G_CALLBACK(on_funcs_button_clicked), NULL);
gtk_main();