From 203f213d30e59d7919ddd5ea10acb8b09149cefb Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 27 Jan 2011 02:12:08 +0000 Subject: [PATCH 01/16] Re-generated Makefiles --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 003e863..81d34b8 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ dist: $(PACKAGE)-$(VERSION)/project.conf $(RM) -- $(PACKAGE)-$(VERSION) -install: $(TARGETS) +install: @for i in $(SUBDIRS); do (cd $$i && $(MAKE) install) || exit; done uninstall: -- 2.20.1 From 89189c5d58c470da19368ef3abbf56945cf993c4 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 18 Feb 2011 23:37:48 +0000 Subject: [PATCH 02/16] Nicer error dialogs --- src/progress.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/progress.c b/src/progress.c index 99ba9c7..8df6bbd 100644 --- a/src/progress.c +++ b/src/progress.c @@ -232,8 +232,12 @@ static int _error_do(Progress * progress, char const * message, dialog = gtk_message_dialog_new((progress != NULL) ? GTK_WINDOW(progress->window) : NULL, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s: %s", message, - error); + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, +#if GTK_CHECK_VERSION(2, 6, 0) + "%s", "Error"); + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), +#endif + "%s: %s", message, error); gtk_window_set_title(GTK_WINDOW(dialog), "Error"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); -- 2.20.1 From 5acaab1e9484fadab5b0a1d14962e045819f7eea Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 15 Apr 2011 23:27:13 +0000 Subject: [PATCH 03/16] Do not let the cancel button resize --- src/progress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/progress.c b/src/progress.c index 8df6bbd..e583b5b 100644 --- a/src/progress.c +++ b/src/progress.c @@ -186,12 +186,13 @@ static int _progress(Prefs * prefs, char * argv[]) p.progress = gtk_progress_bar_new(); p.pulse = 0; gtk_box_pack_start(GTK_BOX(vbox), p.progress, TRUE, TRUE, 4); + /* cancel */ hbox = gtk_hbox_new(FALSE, 0); widget = gtk_button_new_from_stock(GTK_STOCK_CANCEL); g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK( _progress_cancel), NULL); gtk_box_pack_end(GTK_BOX(hbox), widget, FALSE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); gtk_container_add(GTK_CONTAINER(p.window), vbox); gtk_container_set_border_width(GTK_CONTAINER(p.window), 4); gtk_widget_show_all(p.window); -- 2.20.1 From ab8415c62faf6bde4f19a2ac550c473572702d76 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 15 Apr 2011 23:27:54 +0000 Subject: [PATCH 04/16] Migrated to Gtk+ 3.0 --- src/Makefile | 4 ++-- src/progress.c | 1 + src/project.conf | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Makefile b/src/Makefile index 967d193..bde11a2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,9 +5,9 @@ BINDIR = $(PREFIX)/bin CC = cc CPPFLAGSF= CPPFLAGS= -CFLAGSF = -W `pkg-config gtk+-2.0 --cflags` +CFLAGSF = -W `pkg-config gtk+-3.0 --cflags` CFLAGS = -Wall -g -O2 -pedantic -LDFLAGSF= `pkg-config gtk+-2.0 --libs` +LDFLAGSF= `pkg-config gtk+-3.0 --libs` RM = rm -f LN = ln -f MKDIR = mkdir -p diff --git a/src/progress.c b/src/progress.c index e583b5b..78a92e3 100644 --- a/src/progress.c +++ b/src/progress.c @@ -132,6 +132,7 @@ static int _progress(Prefs * prefs, char * argv[]) /* graphical interface */ p.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(p.window), 300, 100); + gtk_window_set_has_resize_grip(GTK_WINDOW(p.window), FALSE); gtk_window_set_title(GTK_WINDOW(p.window), prefs->title != NULL ? prefs->title : "Progress"); g_signal_connect_swapped(G_OBJECT(p.window), "delete-event", G_CALLBACK( diff --git a/src/project.conf b/src/project.conf index ae0c575..3d23f37 100644 --- a/src/project.conf +++ b/src/project.conf @@ -1,7 +1,7 @@ targets=fontsel,progress -cflags_force=-W `pkg-config gtk+-2.0 --cflags` +cflags_force=-W `pkg-config gtk+-3.0 --cflags` cflags=-Wall -g -O2 -pedantic -ldflags_force=`pkg-config gtk+-2.0 --libs` +ldflags_force=`pkg-config gtk+-3.0 --libs` dist=Makefile [fontsel] -- 2.20.1 From 6d66260cb93a3ae0c4223259297491b694223a3b Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 16 Apr 2011 19:20:56 +0000 Subject: [PATCH 05/16] Fixed build with Gtk+ < 3.0 --- src/progress.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/progress.c b/src/progress.c index 78a92e3..2b86df1 100644 --- a/src/progress.c +++ b/src/progress.c @@ -132,7 +132,9 @@ static int _progress(Prefs * prefs, char * argv[]) /* graphical interface */ p.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(p.window), 300, 100); +#if GTK_CHECK_VERSION(3, 0, 0) gtk_window_set_has_resize_grip(GTK_WINDOW(p.window), FALSE); +#endif gtk_window_set_title(GTK_WINDOW(p.window), prefs->title != NULL ? prefs->title : "Progress"); g_signal_connect_swapped(G_OBJECT(p.window), "delete-event", G_CALLBACK( -- 2.20.1 From 17ed0630a20b9edffb4e67de6647f60bfe12b4b1 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 29 Jul 2011 00:28:45 +0000 Subject: [PATCH 06/16] Removed useless self-mention of .cvsignore in .cvsignore files --- src/.cvsignore | 1 - 1 file changed, 1 deletion(-) diff --git a/src/.cvsignore b/src/.cvsignore index da15729..6bffeda 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -1,3 +1,2 @@ -.cvsignore fontsel progress -- 2.20.1 From edbe72161b45573f2126e84447bec868aaa89c82 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 16 Sep 2011 10:19:40 +0000 Subject: [PATCH 07/16] Re-generated Makefiles --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index bde11a2..1e76fe9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ TARGETS = fontsel progress PREFIX = /usr/local -DESTDIR = +DESTDIR = BINDIR = $(PREFIX)/bin CC = cc CPPFLAGSF= -- 2.20.1 From 99741697ff812eb0a38abcad63e63fd4a9d14333 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 16 Sep 2011 11:36:26 +0000 Subject: [PATCH 08/16] Re-generated Makefiles --- Makefile | 6 +++--- src/Makefile | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 81d34b8..a164105 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ PACKAGE = Accessories VERSION = 0.0.1 SUBDIRS = src -RM = rm -f -LN = ln -f -TAR = tar -czvf +RM ?= rm -f +LN ?= ln -f +TAR ?= tar -czvf all: subdirs diff --git a/src/Makefile b/src/Makefile index 1e76fe9..abb7ffe 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,15 +3,15 @@ PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin CC = cc -CPPFLAGSF= -CPPFLAGS= +CPPFLAGSF?= +CPPFLAGS?= CFLAGSF = -W `pkg-config gtk+-3.0 --cflags` CFLAGS = -Wall -g -O2 -pedantic LDFLAGSF= `pkg-config gtk+-3.0 --libs` -RM = rm -f -LN = ln -f -MKDIR = mkdir -p -INSTALL = install +RM ?= rm -f +LN ?= ln -f +MKDIR ?= mkdir -p +INSTALL ?= install all: $(TARGETS) -- 2.20.1 From beaddf6b30e3cd54eb48a8a5f7861200efc391e0 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 16 Sep 2011 11:54:13 +0000 Subject: [PATCH 09/16] Re-generated Makefiles --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index abb7ffe..a47044a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ TARGETS = fontsel progress PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin -CC = cc +CC ?= cc CPPFLAGSF?= CPPFLAGS?= CFLAGSF = -W `pkg-config gtk+-3.0 --cflags` -- 2.20.1 From 1824ef86a916cc7b72d169da59424160b10296a9 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 27 Nov 2011 20:27:45 +0000 Subject: [PATCH 10/16] Reporting more errors --- src/progress.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/progress.c b/src/progress.c index 2b86df1..1af72a1 100644 --- a/src/progress.c +++ b/src/progress.c @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /* TODO: - * - fix when EOF occurs on the output side */ + * - report errors when relevant upon EOF when outputting */ @@ -50,6 +50,7 @@ typedef struct _Progress struct timeval tv; /* start time */ int fd; /* read descriptor */ int eof; /* end of file */ + int ret; int fds[2]; /* for the pipe */ pid_t pid; /* child's pid */ size_t cnt; /* bytes written */ @@ -202,7 +203,7 @@ static int _progress(Prefs * prefs, char * argv[]) gtk_main(); close(p.fd); close(p.fds[1]); - return 0; + return p.ret; } static int _error_do(Progress * progress, char const * message, @@ -227,6 +228,7 @@ static int _error_do(Progress * progress, char const * message, { GtkWidget * dialog; + progress->ret = ret; if(ret < 0) { fputs("progress: ", stderr); @@ -365,7 +367,7 @@ static gboolean _channel_in(Progress * p, GIOChannel * source) p->bufsiz - p->buf_cnt, &read, &error); if(status == G_IO_STATUS_ERROR) { - _progress_error(p, p->prefs->filename, 0); + _progress_gerror(p, p->prefs->filename, error, 1); g_io_channel_close(source); gtk_main_quit(); return FALSE; @@ -398,13 +400,14 @@ static gboolean _channel_out(Progress * p, GIOChannel * source) &error); if(status == G_IO_STATUS_ERROR) { - _progress_gerror(p, p->prefs->filename, error, 0); + _progress_gerror(p, p->prefs->filename, error, 1); gtk_main_quit(); return FALSE; } else if(status == G_IO_STATUS_EOF) { p->eof = 1; /* reached end of output file */ + _progress_error(p, p->prefs->filename, 1); g_io_channel_close(source); } else if(p->buf_cnt == p->bufsiz) @@ -566,5 +569,5 @@ int main(int argc, char * argv[]) } if(argc - optind < 1) return _usage(); - return _progress(&prefs, &argv[optind]) == 0 ? 0 : 2; + return (_progress(&prefs, &argv[optind]) == 0) ? 0 : 2; } -- 2.20.1 From 6c29c375667da15ded99efc3f159145da0234618 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Tue, 20 Dec 2011 09:26:12 +0000 Subject: [PATCH 11/16] Added the "compare" string comparison tool --- Makefile | 1 + src/.cvsignore | 1 + src/Makefile | 17 +++++- src/compare.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++ src/project.conf | 7 ++- 5 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 src/compare.c diff --git a/Makefile b/Makefile index a164105..5c3a688 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ dist: $(RM) -r -- $(PACKAGE)-$(VERSION) $(LN) -s -- . $(PACKAGE)-$(VERSION) @$(TAR) $(PACKAGE)-$(VERSION).tar.gz -- \ + $(PACKAGE)-$(VERSION)/src/compare.c \ $(PACKAGE)-$(VERSION)/src/fontsel.c \ $(PACKAGE)-$(VERSION)/src/progress.c \ $(PACKAGE)-$(VERSION)/src/Makefile \ diff --git a/src/.cvsignore b/src/.cvsignore index 6bffeda..86f02d5 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -1,2 +1,3 @@ +compare fontsel progress diff --git a/src/Makefile b/src/Makefile index a47044a..b5a5edf 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -TARGETS = fontsel progress +TARGETS = compare fontsel progress PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -16,6 +16,13 @@ INSTALL ?= install all: $(TARGETS) +compare_OBJS = compare.o +compare_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +compare_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +compare: $(compare_OBJS) + $(CC) -o compare $(compare_OBJS) $(compare_LDFLAGS) + fontsel_OBJS = fontsel.o fontsel_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) fontsel_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) @@ -30,6 +37,9 @@ progress_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) progress: $(progress_OBJS) $(CC) -o progress $(progress_OBJS) $(progress_LDFLAGS) +compare.o: compare.c + $(CC) $(compare_CFLAGS) -c compare.c + fontsel.o: fontsel.c $(CC) $(fontsel_CFLAGS) -c fontsel.c @@ -37,18 +47,21 @@ progress.o: progress.c $(CC) $(progress_CFLAGS) -c progress.c clean: - $(RM) -- $(fontsel_OBJS) $(progress_OBJS) + $(RM) -- $(compare_OBJS) $(fontsel_OBJS) $(progress_OBJS) distclean: clean $(RM) -- $(TARGETS) install: $(TARGETS) + $(MKDIR) $(DESTDIR)$(BINDIR) + $(INSTALL) -m 0755 -- compare $(DESTDIR)$(BINDIR)/compare $(MKDIR) $(DESTDIR)$(BINDIR) $(INSTALL) -m 0755 -- fontsel $(DESTDIR)$(BINDIR)/fontsel $(MKDIR) $(DESTDIR)$(BINDIR) $(INSTALL) -m 0755 -- progress $(DESTDIR)$(BINDIR)/progress uninstall: + $(RM) -- $(DESTDIR)$(BINDIR)/compare $(RM) -- $(DESTDIR)$(BINDIR)/fontsel $(RM) -- $(DESTDIR)$(BINDIR)/progress diff --git a/src/compare.c b/src/compare.c new file mode 100644 index 0000000..348acf7 --- /dev/null +++ b/src/compare.c @@ -0,0 +1,154 @@ +/* $Id$ */ +/* Copyright (c) 2011 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Accessories */ +/* 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, version 3 of the License. + * + * 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, see . */ + + + +#include +#include +#include + + +/* Compare */ +/* private */ +/* types */ +typedef struct _Compare +{ + GtkWidget * entry1; + GtkWidget * entry2; + GtkWidget * label; +} Compare; + + +/* prototypes */ +static int _compare(char const * string1, char const * string2); + +static int _usage(void); + +/* callbacks */ +static void _compare_on_changed(gpointer data); +static void _compare_on_close(gpointer data); +static gboolean _compare_on_closex(gpointer data); + + +/* functions */ +/* compare */ +static int _compare(char const * string1, char const * string2) +{ + Compare compare; + GtkWidget * window; + GtkWidget * vbox; + GtkWidget * bbox; + GtkWidget * widget; + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(window), 4); + gtk_window_set_title(GTK_WINDOW(window), "Compare strings"); + g_signal_connect_swapped(G_OBJECT(window), "delete-event", G_CALLBACK( + _compare_on_closex), window); + vbox = gtk_vbox_new(FALSE, 4); + compare.entry1 = gtk_entry_new(); + if(string1 != NULL) + gtk_entry_set_text(GTK_ENTRY(compare.entry1), string1); + g_signal_connect_swapped(compare.entry1, "changed", G_CALLBACK( + _compare_on_changed), &compare); + gtk_box_pack_start(GTK_BOX(vbox), compare.entry1, FALSE, TRUE, 0); + compare.entry2 = gtk_entry_new(); + if(string2 != NULL) + gtk_entry_set_text(GTK_ENTRY(compare.entry2), string2); + g_signal_connect_swapped(compare.entry2, "changed", G_CALLBACK( + _compare_on_changed), &compare); + gtk_box_pack_start(GTK_BOX(vbox), compare.entry2, FALSE, TRUE, 0); + compare.label = gtk_label_new(" "); + gtk_misc_set_alignment(GTK_MISC(compare.label), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(vbox), compare.label, FALSE, TRUE, 0); + bbox = gtk_hbutton_box_new(); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + widget = gtk_button_new_from_stock(GTK_STOCK_CLOSE); + g_signal_connect_swapped(widget, "clicked", G_CALLBACK( + _compare_on_close), window); + gtk_container_add(GTK_CONTAINER(bbox), widget); + gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); + gtk_container_add(GTK_CONTAINER(window), vbox); + gtk_widget_show_all(window); + gtk_main(); + return 0; +} + + +/* usage */ +static int _usage(void) +{ + fputs("Usage: compare [string1 [string2]]\n", stderr); + return 1; +} + + +/* callbacks */ +/* compare_on_changed */ +static void _compare_on_changed(gpointer data) +{ + Compare * compare = data; + char const * string1; + char const * string2; + + string1 = gtk_entry_get_text(GTK_ENTRY(compare->entry1)); + string2 = gtk_entry_get_text(GTK_ENTRY(compare->entry2)); + if(strcmp(string1, string2) == 0) + gtk_label_set_text(GTK_LABEL(compare->label), + "The strings MATCH"); + else + gtk_label_set_text(GTK_LABEL(compare->label), + "The strings do NOT match"); +} + + +/* compare_on_close */ +static void _compare_on_close(gpointer data) +{ + GtkWidget * widget = data; + + gtk_widget_hide(widget); + gtk_main_quit(); +} + + +/* compare_on_closex */ +static gboolean _compare_on_closex(gpointer data) +{ + GtkWidget * widget = data; + + _compare_on_close(widget); + return FALSE; +} + + +/* main */ +int main(int argc, char * argv[]) +{ + int o; + char const * string1; + char const * string2 = NULL; + + gtk_init(&argc, &argv); + while((o = getopt(argc, argv, "")) != -1) + switch(o) + { + default: + return _usage(); + } + if((string1 = argv[optind]) != NULL) + string2 = argv[optind + 1]; + return (_compare(string1, string2) == 0) ? 0 : 2; +} diff --git a/src/project.conf b/src/project.conf index 3d23f37..f672666 100644 --- a/src/project.conf +++ b/src/project.conf @@ -1,9 +1,14 @@ -targets=fontsel,progress +targets=compare,fontsel,progress cflags_force=-W `pkg-config gtk+-3.0 --cflags` cflags=-Wall -g -O2 -pedantic ldflags_force=`pkg-config gtk+-3.0 --libs` dist=Makefile +[compare] +type=binary +sources=compare.c +install=$(BINDIR) + [fontsel] type=binary sources=fontsel.c -- 2.20.1 From c6f04147a08f8326d0740768f982a89dcd7e1fff Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Tue, 20 Dec 2011 09:59:54 +0000 Subject: [PATCH 12/16] About to release Accessories 0.0.2 --- Makefile | 2 +- project.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5c3a688..5d59806 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PACKAGE = Accessories -VERSION = 0.0.1 +VERSION = 0.0.2 SUBDIRS = src RM ?= rm -f LN ?= ln -f diff --git a/project.conf b/project.conf index e63c158..6af3255 100644 --- a/project.conf +++ b/project.conf @@ -1,5 +1,5 @@ package=Accessories -version=0.0.1 +version=0.0.2 subdirs=src dist=Makefile,COPYING -- 2.20.1 From 7cd2aeec2f5f9371a458614e30d22b63338167a6 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 6 Oct 2012 01:18:41 +0000 Subject: [PATCH 13/16] Implemented an embedded mode --- src/progress.c | 67 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/src/progress.c b/src/progress.c index 1af72a1..c132183 100644 --- a/src/progress.c +++ b/src/progress.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2011 Pierre Pronchery */ +/* Copyright (c) 2007-2012 Pierre Pronchery */ /* This file is part of DeforaOS Desktop Accessories */ /* 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 @@ -38,7 +38,8 @@ typedef struct _Prefs char * title; size_t length; } Prefs; -#define PREFS_z 0x1 +#define PREFS_x 0x1 +#define PREFS_z 0x2 /* progress */ @@ -81,6 +82,7 @@ static gboolean _progress_closex(gpointer data); static void _progress_cancel(void); static gboolean _progress_channel(GIOChannel * source, GIOCondition condition, gpointer data); +static void _progress_embedded(gpointer data); static gboolean _progress_idle_in(gpointer data); static gboolean _progress_idle_out(gpointer data); static gboolean _progress_timeout(gpointer data); @@ -96,6 +98,7 @@ static int _progress(Prefs * prefs, char * argv[]) GtkWidget * widget; PangoFontDescription * bold; char * q; + unsigned long id; memset(&p, 0, sizeof(p)); p.prefs = prefs; @@ -131,15 +134,24 @@ static int _progress(Prefs * prefs, char * argv[]) g_io_channel_set_encoding(p.out_channel, NULL, NULL); p.out_id = 0; /* graphical interface */ - p.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size(GTK_WINDOW(p.window), 300, 100); + if((prefs->flags & PREFS_x) == 0) + { + p.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_default_size(GTK_WINDOW(p.window), 300, 100); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_window_set_has_resize_grip(GTK_WINDOW(p.window), FALSE); + gtk_window_set_has_resize_grip(GTK_WINDOW(p.window), FALSE); #endif - gtk_window_set_title(GTK_WINDOW(p.window), prefs->title != NULL - ? prefs->title : "Progress"); - g_signal_connect_swapped(G_OBJECT(p.window), "delete-event", G_CALLBACK( - _progress_closex), p.window); + gtk_window_set_title(GTK_WINDOW(p.window), prefs->title != NULL + ? prefs->title : "Progress"); + g_signal_connect_swapped(p.window, "delete-event", G_CALLBACK( + _progress_closex), p.window); + } + else + { + p.window = gtk_plug_new(0); + g_signal_connect_swapped(p.window, "embedded", G_CALLBACK( + _progress_embedded), &p); + } vbox = gtk_vbox_new(FALSE, 0); hbox = gtk_hbox_new(FALSE, 0); left = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); @@ -199,7 +211,17 @@ static int _progress(Prefs * prefs, char * argv[]) gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); gtk_container_add(GTK_CONTAINER(p.window), vbox); gtk_container_set_border_width(GTK_CONTAINER(p.window), 4); - gtk_widget_show_all(p.window); + gtk_widget_show_all(vbox); + if((prefs->flags & PREFS_x) == 0) + /* show the window */ + gtk_widget_show(p.window); + else + { + /* print the window ID and force a flush */ + id = gtk_plug_get_id(GTK_PLUG(p.window)); + printf("%lu\n", id); + fclose(stdout); + } gtk_main(); close(p.fd); close(p.fds[1]); @@ -250,6 +272,13 @@ static int _error_do(Progress * progress, char const * message, return ret; } +static void _progress_embedded(gpointer data) +{ + Progress * p = data; + + gtk_widget_show(p->window); +} + static gboolean _progress_idle_in(gpointer data) { Progress * p = data; @@ -368,14 +397,14 @@ static gboolean _channel_in(Progress * p, GIOChannel * source) if(status == G_IO_STATUS_ERROR) { _progress_gerror(p, p->prefs->filename, error, 1); - g_io_channel_close(source); + g_io_channel_shutdown(source, TRUE, NULL); gtk_main_quit(); return FALSE; } else if(status == G_IO_STATUS_EOF) { p->eof = 1; /* reached end of input file */ - g_io_channel_close(source); + g_io_channel_shutdown(source, TRUE, NULL); } else if(p->buf_cnt + read != p->bufsiz) g_idle_add(_progress_idle_in, p); /* continue to read */ @@ -408,7 +437,7 @@ static gboolean _channel_out(Progress * p, GIOChannel * source) { p->eof = 1; /* reached end of output file */ _progress_error(p, p->prefs->filename, 1); - g_io_channel_close(source); + g_io_channel_shutdown(source, TRUE, NULL); } else if(p->buf_cnt == p->bufsiz) g_idle_add(_progress_idle_in, p); /* read again */ @@ -420,7 +449,7 @@ static gboolean _channel_out(Progress * p, GIOChannel * source) g_idle_add(_progress_idle_out, p); /* continue to write */ else if(p->eof == 1) /* reached end of output */ { - g_io_channel_close(p->out_channel); + g_io_channel_shutdown(p->out_channel, TRUE, NULL); gtk_main_quit(); } return FALSE; @@ -524,9 +553,10 @@ static void _timeout_progress(Progress * progress) /* usage */ static int _usage(void) { - fputs("Usage: progress [-z][-b buffer size][-f file][-l length]" + fputs("Usage: progress [-x][-z][-b buffer size][-f file][-l length]" "[-p prefix]\n" -" [-t title] cmd [args...]\n", stderr); +" [-t title] cmd [args...]\n" +" -x Start in embedded mode\n", stderr); return 1; } @@ -541,7 +571,7 @@ int main(int argc, char * argv[]) memset(&prefs, 0, sizeof(prefs)); prefs.bufsiz = 65536; gtk_init(&argc, &argv); - while((o = getopt(argc, argv, "b:f:l:t:z")) != -1) + while((o = getopt(argc, argv, "b:f:l:t:xz")) != -1) switch(o) { case 'b': @@ -561,6 +591,9 @@ int main(int argc, char * argv[]) case 't': prefs.title = optarg; break; + case 'x': + prefs.flags |= PREFS_x; + break; case 'z': prefs.flags |= PREFS_z; break; -- 2.20.1 From 9ed2b1197eb6b0336878fe95c6a58092ee1d93c6 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 6 Oct 2012 01:20:47 +0000 Subject: [PATCH 14/16] Fixed build with Gtk+ 3.0 --- src/progress.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/progress.c b/src/progress.c index c132183..5c6f334 100644 --- a/src/progress.c +++ b/src/progress.c @@ -27,6 +27,9 @@ #include #include #include +#if GTK_CHECK_VERSION(3, 0, 0) +# include +#endif /* types */ -- 2.20.1 From 52641f340ba35ba9d8102603a2fce60d8711058b Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 7 Oct 2012 23:31:01 +0000 Subject: [PATCH 15/16] Also display the remaining time --- src/progress.c | 98 +++++++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/src/progress.c b/src/progress.c index 5c6f334..33a1e84 100644 --- a/src/progress.c +++ b/src/progress.c @@ -69,7 +69,7 @@ typedef struct _Progress /* widgets */ GtkWidget * window; GtkWidget * done; - GtkWidget * speed; + GtkWidget * remaining; GtkWidget * progress; int pulse; /* tells when to pulse */ } Progress; @@ -188,18 +188,18 @@ static int _progress(Prefs * prefs, char * argv[]) gtk_size_group_add_widget(right, p.done); gtk_box_pack_start(GTK_BOX(hbox), p.done, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 4); - /* speed */ + /* remaining */ hbox = gtk_hbox_new(FALSE, 0); - widget = gtk_label_new("Speed: "); + widget = gtk_label_new("Remaining: "); gtk_widget_modify_font(widget, bold); gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.0); gtk_size_group_add_widget(left, widget); gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0); - p.speed = gtk_label_new("0.0 kB/s"); + p.remaining = gtk_label_new(""); g_timeout_add(250, _progress_timeout, &p); - gtk_misc_set_alignment(GTK_MISC(p.speed), 0.0, 0.0); - gtk_size_group_add_widget(right, p.speed); - gtk_box_pack_start(GTK_BOX(hbox), p.speed, TRUE, TRUE, 0); + gtk_misc_set_alignment(GTK_MISC(p.remaining), 0.0, 0.0); + gtk_size_group_add_widget(right, p.remaining); + gtk_box_pack_start(GTK_BOX(hbox), p.remaining, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 4); /* progress */ p.progress = gtk_progress_bar_new(); @@ -480,47 +480,37 @@ static void _out_rate(Progress * p) /* progress_timeout */ -static void _timeout_done(Progress * progress); -static void _timeout_speed(Progress * progress); +static void _timeout_done(Progress * progress, guint64 * rate); static void _timeout_progress(Progress * progress); +static void _timeout_remaining(Progress * progress, guint64 rate); static gboolean _progress_timeout(gpointer data) { Progress * progress = data; + guint64 rate = 0; - _timeout_done(progress); - _timeout_speed(progress); + _timeout_done(progress, &rate); + _timeout_remaining(progress, rate); _timeout_progress(progress); return TRUE; } -static void _timeout_done(Progress * progress) +static void _timeout_done(Progress * progress, guint64 * rate) { double cnt = progress->cnt / 1024; double total = progress->prefs->length / 1024; - char buf[32]; - char const * unit = "kB"; + char buf[48]; + char const * dunit = "kB"; + struct timeval tv; + double r; + char const * sunit = "kB"; if(progress->prefs->length > 1048576 || progress->cnt > 1048576) { cnt /= 1024; total /= 1024; - unit = "MB"; + dunit = "MB"; } - if(progress->prefs->length == 0) - snprintf(buf, sizeof(buf), "%.1f %s", cnt, unit); - else - snprintf(buf, sizeof(buf), "%.1f of %.1f %s", cnt, total, unit); - gtk_label_set_text(GTK_LABEL(progress->done), buf); -} - -static void _timeout_speed(Progress * progress) -{ - struct timeval tv; - double rate; - char buf[16]; - char const * unit = "kB"; - if(gettimeofday(&tv, NULL) != 0) { _progress_error(progress, "gettimeofday", FALSE); @@ -533,15 +523,21 @@ static void _timeout_speed(Progress * progress) tv.tv_sec--; tv.tv_usec += 1000000; } - rate = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); - unit = "kB"; - if((rate = progress->cnt / rate) > 1024) + r = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); + sunit = "kB"; + *rate = (progress->cnt * 1024) / r; + if((r = progress->cnt / r) > 1024) { - rate /= 1024; - unit = "MB"; + r /= 1024; + sunit = "MB"; } - snprintf(buf, sizeof(buf), "%.1f %s/s", rate, unit); - gtk_label_set_text(GTK_LABEL(progress->speed), buf); + if(progress->prefs->length == 0) + snprintf(buf, sizeof(buf), "%.1f %s (%.1f %s/s)", cnt, dunit, + r, sunit); + else + snprintf(buf, sizeof(buf), "%.1f of %.1f %s (%.1f %s/s)", cnt, + total, dunit, r, sunit); + gtk_label_set_text(GTK_LABEL(progress->done), buf); } static void _timeout_progress(Progress * progress) @@ -552,6 +548,36 @@ static void _timeout_progress(Progress * progress) progress->pulse = 0; } +static void _timeout_remaining(Progress * progress, guint64 rate) +{ + char buf[32]; + guint64 remaining; + struct tm tm; + + if(progress->prefs->length == 0 || rate == 0) + { + gtk_label_set_text(GTK_LABEL(progress->remaining), "Unknown"); + return; + } + remaining = (progress->prefs->length - progress->cnt) / rate; + memset(&tm, 0, sizeof(tm)); + tm.tm_sec = remaining; + /* minutes */ + if(tm.tm_sec > 60) + { + tm.tm_min = tm.tm_sec / 60; + tm.tm_sec = tm.tm_sec - (tm.tm_min * 60); + } + /* hours */ + if(tm.tm_min > 60) + { + tm.tm_hour = tm.tm_min / 60; + tm.tm_min = tm.tm_min - (tm.tm_hour * 60); + } + strftime(buf, sizeof(buf), "%H:%M:%S", &tm); + gtk_label_set_text(GTK_LABEL(progress->remaining), buf); +} + /* usage */ static int _usage(void) -- 2.20.1 From eb62c3340654967797699d73077c1a6367726b15 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 14 Oct 2012 16:53:17 +0000 Subject: [PATCH 16/16] Releasing DeforaOS Accessories 0.0.3 --- Makefile | 2 +- project.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5d59806..b4d96fd 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PACKAGE = Accessories -VERSION = 0.0.2 +VERSION = 0.0.3 SUBDIRS = src RM ?= rm -f LN ?= ln -f diff --git a/project.conf b/project.conf index 6af3255..36030d6 100644 --- a/project.conf +++ b/project.conf @@ -1,5 +1,5 @@ package=Accessories -version=0.0.2 +version=0.0.3 subdirs=src dist=Makefile,COPYING -- 2.20.1