|
From: <ow...@us...> - 2008-01-23 20:59:14
|
Revision: 1023
http://ipcop.svn.sourceforge.net/ipcop/?rev=1023&view=rev
Author: owes
Date: 2008-01-23 12:59:19 -0800 (Wed, 23 Jan 2008)
Log Message:
-----------
Add functions for statuswindow and command with progressbar.
Modified Paths:
--------------
ipcop/trunk/src/installer/common.h
ipcop/trunk/src/installer/helper_newt.c
Modified: ipcop/trunk/src/installer/common.h
===================================================================
--- ipcop/trunk/src/installer/common.h 2008-01-23 20:47:02 UTC (rev 1022)
+++ ipcop/trunk/src/installer/common.h 2008-01-23 20:59:19 UTC (rev 1023)
@@ -35,10 +35,12 @@
*/
int mysystem(char *command);
int mysystemhidden(char *command);
+int mysystem_progress(char *command, void *form, int left, int top, int width, int lines, int offset);
/*
Implemented in helper_newt.c
*/
void statuswindow(int width, int height, char *title, char *text, ...);
+void *statuswindow_progress(int width, int height, char *title, char *text, ...);
/*
Gets IPCop version number, platform and 'slogan'.
*/
Modified: ipcop/trunk/src/installer/helper_newt.c
===================================================================
--- ipcop/trunk/src/installer/helper_newt.c 2008-01-23 20:47:02 UTC (rev 1022)
+++ ipcop/trunk/src/installer/helper_newt.c 2008-01-23 20:59:19 UTC (rev 1023)
@@ -16,8 +16,9 @@
#include "common.h"
-void
-statuswindow(int width, int height, char *title, char *text, ...)
+newtComponent f_progress;
+
+void statuswindow(int width, int height, char *title, char *text, ...)
{
newtComponent t, f;
char *buf = NULL;
@@ -52,3 +53,84 @@
newtRefresh();
newtFormDestroy(f);
}
+
+
+/*
+ Create and show newt Window, but return form component instead of destroying,
+ makes easy to add for example scale component.
+*/
+void *statuswindow_progress(int width, int height, char *title, char *text, ...)
+{
+ newtComponent t;
+ char *buf = NULL;
+ int size = 0;
+ int i = 0;
+ va_list args;
+
+ va_start(args, text);
+
+ do
+ {
+ size += 1000;
+ if (buf)
+ free(buf);
+ buf = malloc(size);
+ i = vsnprintf(buf, size, text, args);
+ } while (i == size);
+
+ va_end(args);
+
+ newtCenteredWindow(width, height, title);
+
+ t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
+ newtTextboxSetText(t, buf);
+ f_progress = newtForm(NULL, NULL, 0);
+
+ free(buf);
+
+ newtFormAddComponent(f_progress, t);
+
+ newtDrawForm(f_progress);
+ newtRefresh();
+
+ return &f_progress;
+}
+
+
+/* newtScale mechanism borrowed from redhat installer */
+int mysystem_progress(char *command, void *form, int left, int top, int width, int lines, int offset)
+{
+ int progress = offset;
+ newtComponent *f = (newtComponent *)form;
+ newtComponent s;
+ FILE *p;
+ char buffer[STRING_SIZE];
+
+ s = newtScale(left, top, width, lines);
+ newtScaleSet(s, progress);
+
+ newtFormAddComponent(*f, s);
+
+ newtDrawForm(*f);
+ newtRefresh();
+
+ if ( flog != NULL )
+ {
+ fprintf(flog, "Running command: %s\n", command);
+ }
+
+ if ( !(p = popen(command, "r")) )
+ {
+ return 1;
+ }
+
+ setvbuf(p, NULL, _IOLBF, 255);
+
+ while ( fgets(buffer, STRING_SIZE, p) )
+ {
+ newtScaleSet(s, ++progress);
+ newtRefresh();
+ }
+
+ return pclose(p);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|