From c69aadceb8d1afc9ea16c2e8be2ae6aebc1f10ae Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 25 Nov 2013 21:56:20 +0000 Subject: [PATCH] extracted ui code to create a new task --- src/Makefile.am | 3 ++- src/Makefile.in | 7 ++++-- src/main.c | 43 +---------------------------------- src/ui.c | 9 ++++++++ src/ui.h | 1 + src/ui_newtask_diag.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/ui_newtask_diag.h | 25 ++++++++++++++++++++ 7 files changed, 106 insertions(+), 45 deletions(-) create mode 100644 src/ui_newtask_diag.c create mode 100644 src/ui_newtask_diag.h diff --git a/src/Makefile.am b/src/Makefile.am index 84f2093..e8dae2f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,7 +17,8 @@ ptask_SOURCES = main.c \ pstr.c pstr.h \ ptime.c ptime.h \ tw.c tw.h \ - ui.c ui.h + ui.c ui.h \ + ui_newtask_diag.c ui_newtask_diag.h dist_man_MANS = ptask.1 diff --git a/src/Makefile.in b/src/Makefile.in index ccfd917..3b3042d 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -66,7 +66,8 @@ CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" PROGRAMS = $(bin_PROGRAMS) am_ptask_OBJECTS = main.$(OBJEXT) log.$(OBJEXT) note.$(OBJEXT) \ - pstr.$(OBJEXT) ptime.$(OBJEXT) tw.$(OBJEXT) ui.$(OBJEXT) + pstr.$(OBJEXT) ptime.$(OBJEXT) tw.$(OBJEXT) ui.$(OBJEXT) \ + ui_newtask_diag.$(OBJEXT) ptask_OBJECTS = $(am_ptask_OBJECTS) ptask_LDADD = $(LDADD) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) @@ -294,7 +295,8 @@ ptask_SOURCES = main.c \ pstr.c pstr.h \ ptime.c ptime.h \ tw.c tw.h \ - ui.c ui.h + ui.c ui.h \ + ui_newtask_diag.c ui_newtask_diag.h dist_man_MANS = ptask.1 gsettings_SCHEMAS = ptask.gschema.xml @@ -390,6 +392,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tw.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui_newtask_diag.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/src/main.c b/src/main.c index 29204e9..2171895 100644 --- a/src/main.c +++ b/src/main.c @@ -148,7 +148,7 @@ static void clear_task_panel() gtk_widget_set_sensitive(GTK_WIDGET(w_priority), 0); } -static void refresh() +void refresh() { GtkWidget *dialog; GtkTreeModel *model; @@ -293,47 +293,6 @@ int refresh_clicked_cbk(GtkButton *btn, gpointer data) return FALSE; } -int newtask_clicked_cbk(GtkButton *btn, gpointer data) -{ - gint result; - static GtkDialog *diag; - GtkBuilder *builder; - GtkEntry *entry; - const char *ctxt; - - log_debug("newtask_clicked_cbk"); - - builder = gtk_builder_new(); - gtk_builder_add_from_file - (builder, - PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade", - NULL); - diag = GTK_DIALOG(gtk_builder_get_object(builder, "diag_tasknew")); - gtk_builder_connect_signals(builder, NULL); - - result = gtk_dialog_run(diag); - - if (result == GTK_RESPONSE_ACCEPT) { - log_debug("ok"); - entry = GTK_ENTRY(gtk_builder_get_object - (builder, "diag_tasknew_description")); - ctxt = gtk_entry_get_text(entry); - - log_debug("%s", ctxt); - - tw_add(ctxt); - refresh(); - } else { - log_debug("cancel"); - } - - g_object_unref(G_OBJECT(builder)); - - gtk_widget_destroy(GTK_WIDGET(diag)); - - return FALSE; -} - static int status_changed_cbk(GtkComboBox *w, gpointer data) { log_debug("status_changed_cbk"); diff --git a/src/ui.c b/src/ui.c index 83e9876..eda9ecc 100644 --- a/src/ui.c +++ b/src/ui.c @@ -19,9 +19,18 @@ #include #include +#include static GtkTreeView *w_treeview; +int newtask_clicked_cbk(GtkButton *btn, gpointer data) +{ + ui_newtask(); + + return FALSE; +} + + static void save_settings(GtkWindow *window, GSettings *settings) { int w, h, x, y, sort_col_id; diff --git a/src/ui.h b/src/ui.h index 27aebce..54914e3 100644 --- a/src/ui.h +++ b/src/ui.h @@ -23,5 +23,6 @@ #include GtkWindow *create_window(GtkBuilder *, GSettings *); +void refresh(); #endif diff --git a/src/ui_newtask_diag.c b/src/ui_newtask_diag.c new file mode 100644 index 0000000..96d0291 --- /dev/null +++ b/src/ui_newtask_diag.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2012-2013 jeanfi@gmail.com + * + * This program 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 2 of the + * License, or (at your option) any later version. + * + * This program 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include + +#include +#include +#include + +void ui_newtask() +{ + gint result; + static GtkDialog *diag; + GtkBuilder *builder; + GtkEntry *entry; + const char *ctxt; + + log_debug("newtask_clicked_cbk"); + + builder = gtk_builder_new(); + gtk_builder_add_from_file + (builder, + PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade", + NULL); + diag = GTK_DIALOG(gtk_builder_get_object(builder, "diag_tasknew")); + gtk_builder_connect_signals(builder, NULL); + + result = gtk_dialog_run(diag); + + if (result == GTK_RESPONSE_ACCEPT) { + log_debug("ok"); + entry = GTK_ENTRY(gtk_builder_get_object + (builder, "diag_tasknew_description")); + ctxt = gtk_entry_get_text(entry); + + log_debug("%s", ctxt); + + tw_add(ctxt); + refresh(); + } else { + log_debug("cancel"); + } + + g_object_unref(G_OBJECT(builder)); + + gtk_widget_destroy(GTK_WIDGET(diag)); +} diff --git a/src/ui_newtask_diag.h b/src/ui_newtask_diag.h new file mode 100644 index 0000000..d9e5e26 --- /dev/null +++ b/src/ui_newtask_diag.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012-2013 jeanfi@gmail.com + * + * This program 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 2 of the + * License, or (at your option) any later version. + * + * This program 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef _PTASK_UI_NEWTASK_DIAG_H_ +#define _PTASK_UI_NEWTASK_DIAG_H_ + +void ui_newtask(); + +#endif -- 2.7.4