diff options
author | Unia <jthidskes@live.nl> | 2013-04-08 20:13:27 +0200 |
---|---|---|
committer | Unia <jthidskes@live.nl> | 2013-04-08 20:13:27 +0200 |
commit | 69160392add9a35020d45fbaceae0bf8b1d2aae4 (patch) | |
tree | 6089f649978b2d3299256014181e47c0ae0afbec | |
parent | 919411efcf5933d84339f0e55e793900d205e27e (diff) |
lots of improvements
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | gstopwatch.c | 110 |
2 files changed, 44 insertions, 78 deletions
@@ -3,10 +3,6 @@ Gstopwatch **A simple stopwatch, written in GTK3.** -Okay, so apparently there are absolutely zero good stopwatches around for X11! -I spent my time searching but couldn't find one simple enough for me. This -stopwatch will start counting, stop counting and reset. - Installation ------------ @@ -27,10 +23,12 @@ For any bug or request [fill an issue][bug] on [GitHub][ghp]. ToDo ---- -* Add hundreds/tenths of seconds? -* Add about dialog back in? * Add a timer function too, in GtkNotebook? -* Add split in laps: difference between lap 1 and lap 2 +* 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 License ------- diff --git a/gstopwatch.c b/gstopwatch.c index 346b738..29b2148 100644 --- a/gstopwatch.c +++ b/gstopwatch.c @@ -8,33 +8,30 @@ enum { enum { N_LAP, + SPLIT, TIME, N_COLUMNS }; -gchar output[100]; GTimer *timer; -gint state = STOPPED, lap = 0; +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; GtkListStore *liststore; GtkTreeSelection *selection; GtkTreeIter selection_iter, iter; -gboolean update_progress_bar (void) { - gint hours, minutes, seconds; +gboolean stopwatch (void) { gchar *markup; gulong gulong; - /*gdouble hseconds;*/ - /*hseconds = g_timer_elapsed (timer, &gulong); - hseconds = */ seconds = g_timer_elapsed (timer, &gulong); hours = seconds / 3600; seconds -= 3600 * hours; minutes = seconds / 60; seconds -= 60 * minutes; - /*sprintf(output, "%02d:%02d:%02d:%.2f", hours, minutes, seconds, hseconds);*/ - sprintf(output, "%02d:%02d:%02d", hours, minutes, seconds); + sprintf(output, "%02d:%02d:%.2f", hours, minutes, seconds); gtk_label_set_text(GTK_LABEL(timer_display), output); markup = g_markup_printf_escaped("<span font=\"48\" weight=\"heavy\"><tt>%s</tt></span>", output); @@ -44,38 +41,37 @@ gboolean update_progress_bar (void) { } void add_lap (void) { - GtkTreePath *path; - + /*gchar split[100];*/ lap++; - gtk_list_store_append(liststore, &iter); - gtk_list_store_set(liststore, &iter, N_LAP, lap, TIME, output, -1); - gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)), &iter); - if(selection) { - if(gtk_tree_selection_get_selected(selection, NULL, &iter) ) { - path = gtk_tree_model_get_path(gtk_tree_view_get_model(GTK_TREE_VIEW(tree)), &iter); - gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(tree), path, NULL, FALSE, 0, 0); - gtk_tree_path_free(path); - } + /*split_seconds = seconds - prev_seconds; + prev_seconds = seconds; + if(split_seconds > 60) { + split_minutes = split_seconds / 60; + prev_minutes = minutes; } + sprintf(split, "%02d:%.2f", split_minutes, split_seconds);*/ + gtk_list_store_append(GTK_LIST_STORE(liststore), &iter); + gtk_list_store_set(GTK_LIST_STORE(liststore), &iter, N_LAP, lap, /*SPLIT, split, */TIME, output, -1); + gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)), &iter); } void on_timer_button_clicked (void) { if(state == STOPPED) { - g_timer_start(timer); gtk_button_set_label(GTK_BUTTON(button_timer), "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) { - g_timer_continue(timer); gtk_button_set_label(GTK_BUTTON(button_timer), "Stop"); gtk_button_set_label(GTK_BUTTON(button_funcs), "Lap"); + g_timer_continue(timer); state = STARTED; } else if(state == STARTED) { - g_timer_stop(timer); gtk_button_set_label(GTK_BUTTON(button_timer), "Continue"); gtk_widget_set_sensitive(GTK_WIDGET(button_funcs), TRUE); gtk_button_set_label(GTK_BUTTON(button_funcs), "Reset"); + g_timer_stop(timer); state = PAUSED; } } @@ -94,47 +90,8 @@ void on_funcs_button_clicked (void) { } } -/*void about_dialog_close (GtkWidget *about_dialog) { - gtk_widget_destroy(GTK_WIDGET(about_dialog)); -} - -void about_dialog_open (void) { - GtkWidget *about_dialog; - gchar *license_trans; - - const gchar *authors[] = {"Jente", "Calvin Morrison", NULL}; - const gchar *license[] = { - N_("Gstopwatch is free software: you can redistribute it and/or modify " - "it under the terms of the GNU General Public License as published by " - "the Free Software Foundation, either version 3 of the License, or " - "(at your option) any later version."), - N_("Gstopwatch is distributed in the hope that it will be useful " - "but WITHOUT ANY WARRANTY; without even the implied warranty of " - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " - "GNU General Public License for more details."), - N_("You should have received a copy of the GNU General Public License " - "along with this program. If not, see <http://www.gnu.org/licenses/>.") - }; - license_trans = g_strjoin ("\n\n", _(license[0]), _(license[1]), _(license[2]), NULL); - - about_dialog = gtk_about_dialog_new(); - gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG (about_dialog), "Gstopwatch"); - gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG (about_dialog), "A simple stopwatch, written in GTK3"), - gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG (about_dialog), "Copyright \xc2\xa9 2013 Jente"); - gtk_about_dialog_set_license(GTK_ABOUT_DIALOG (about_dialog), license_trans); - gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG (about_dialog), TRUE); - gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG (about_dialog), authors); - gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG (about_dialog), "GitHub repository"); - gtk_about_dialog_set_website(GTK_ABOUT_DIALOG (about_dialog), "https://github.com/Unia/gstopwatch"); - gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG (about_dialog), "clocks"); - - g_signal_connect (GTK_DIALOG(about_dialog), "response", G_CALLBACK(about_dialog_close), NULL); - - gtk_widget_show (about_dialog); -}*/ - int main (int argc, char *argv[]) { - GtkWidget *window, *vbox, *hbox; + GtkWidget *window, *vbox, *hbox, *scroll; GtkTreeViewColumn *column; GtkCellRenderer *renderer; @@ -142,40 +99,52 @@ int main (int argc, char *argv[]) { vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); - timer_display = gtk_label_new(""); button_timer = 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); tree = gtk_tree_view_new(); - liststore = gtk_list_store_new(N_COLUMNS, G_TYPE_INT, G_TYPE_STRING); + 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); gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(liststore)); 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_sort_column_id(column, N_LAP); + 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_sort_column_id(column, TIME); + 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), tree, TRUE, TRUE, 5); - /*gtk_box_pack_start(GTK_BOX(hbox), button_about, TRUE, TRUE, 5);*/ + gtk_container_add(GTK_CONTAINER(scroll), tree); + gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 5); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW(window), "Gstopwatch"); @@ -186,9 +155,8 @@ int main (int argc, char *argv[]) { timer = g_timer_new(); g_timer_stop(timer); - g_timeout_add_full(G_PRIORITY_HIGH, 50, (GSourceFunc) update_progress_bar, NULL, NULL); + 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_about, "clicked", G_CALLBACK(about_dialog_open), NULL);*/ g_signal_connect(button_timer, "clicked", G_CALLBACK(on_timer_button_clicked), NULL); g_signal_connect(button_funcs, "clicked", G_CALLBACK(on_funcs_button_clicked), NULL); |