evolution-data-server r9012 - trunk/camel



Author: fejj
Date: Sat Jun 21 02:27:36 2008
New Revision: 9012
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9012&view=rev

Log:
2008-06-20  Jeffrey Stedfast  <fejj novell com>

	* camel-mime-filter-progress.[c,h]: New progress-reporting stream
	filter.



Added:
   trunk/camel/camel-mime-filter-progress.c
   trunk/camel/camel-mime-filter-progress.h
Modified:
   trunk/camel/ChangeLog
   trunk/camel/Makefile.am

Modified: trunk/camel/Makefile.am
==============================================================================
--- trunk/camel/Makefile.am	(original)
+++ trunk/camel/Makefile.am	Sat Jun 21 02:27:36 2008
@@ -180,6 +180,7 @@
 	camel-mime-filter-index.c		\
 	camel-mime-filter-linewrap.c		\
 	camel-mime-filter-pgp.c			\
+	camel-mime-filter-progress.c		\
 	camel-mime-filter-save.c		\
 	camel-mime-filter-tohtml.c		\
 	camel-mime-filter-windows.c		\
@@ -252,6 +253,7 @@
 	camel-mime-filter-index.h		\
 	camel-mime-filter-linewrap.h		\
 	camel-mime-filter-pgp.h			\
+	camel-mime-filter-progress.h		\
 	camel-mime-filter-save.h		\
 	camel-mime-filter-tohtml.h		\
 	camel-mime-filter-windows.h		\

Added: trunk/camel/camel-mime-filter-progress.c
==============================================================================
--- (empty file)
+++ trunk/camel/camel-mime-filter-progress.c	Sat Jun 21 02:27:36 2008
@@ -0,0 +1,147 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ *  Authors: Jeffrey Stedfast <fejj ximian com>
+ *
+ *  Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser 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.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+#include <camel/camel-operation.h>
+
+#include "camel-mime-filter-progress.h"
+
+#define d(x)
+#define w(x)
+
+static void camel_mime_filter_progress_class_init (CamelMimeFilterProgressClass *klass);
+static void camel_mime_filter_progress_init       (CamelObject *o);
+static void camel_mime_filter_progress_finalize   (CamelObject *o);
+
+static CamelMimeFilterClass *parent_class = NULL;
+
+CamelType
+camel_mime_filter_progress_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+	
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (),
+					    "CamelMimeFilterProgress",
+					    sizeof (CamelMimeFilterProgress),
+					    sizeof (CamelMimeFilterProgressClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_progress_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_progress_init,
+					    (CamelObjectFinalizeFunc) camel_mime_filter_progress_finalize);
+	}
+	
+	return type;
+}
+
+static void
+camel_mime_filter_progress_finalize (CamelObject *o)
+{
+	;
+}
+
+static void
+camel_mime_filter_progress_init (CamelObject *o)
+{
+	CamelMimeFilterProgress *progress = (CamelMimeFilterProgress *) o;
+	
+	progress->count = 0;
+}
+
+static void
+filter_filter (CamelMimeFilter *filter, char *in, size_t len, size_t prespace,
+	       char **out, size_t *outlen, size_t *outprespace)
+{
+	CamelMimeFilterProgress *progress = (CamelMimeFilterProgress *) filter;
+	CamelOperation *operation;
+	double percent;
+	
+	progress->count += len;
+	
+	if ((operation = camel_operation_registered ())) {
+		if (progress->count < progress->total)
+			percent = ((double) progress->count * 100.0) / ((double) progress->total);
+		else
+			percent = 100.0;
+		
+		camel_operation_progress (operation, (int) percent);
+	}
+	
+	*outprespace = prespace;
+	*outlen = len;
+	*out = in;
+}
+
+static void 
+filter_complete (CamelMimeFilter *filter, char *in, size_t len, size_t prespace,
+		 char **out, size_t *outlen, size_t *outprespace)
+{
+	filter_filter (filter, in, len, prespace, out, outlen, outprespace);
+}
+
+static void
+filter_reset (CamelMimeFilter *filter)
+{
+	CamelMimeFilterProgress *progress = (CamelMimeFilterProgress *) filter;
+	
+	progress->count = 0;
+}
+
+static void
+camel_mime_filter_progress_class_init (CamelMimeFilterProgressClass *klass)
+{
+	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	
+	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+	
+	filter_class->reset = filter_reset;
+	filter_class->filter = filter_filter;
+	filter_class->complete = filter_complete;
+}
+
+
+/**
+ * camel_mime_filter_progress_new:
+ * @total: total number of bytes to report progress on
+ *
+ * Create a new #CamelMimeFilterProgress object that will report
+ * streaming progress.
+ *
+ * Returns a new #CamelMimeFilter object
+ **/
+CamelMimeFilter *
+camel_mime_filter_progress_new (guint32 total)
+{
+	CamelMimeFilter *filter;
+	
+	filter = (CamelMimeFilter *) camel_object_new (camel_mime_filter_progress_get_type ());
+	((CamelMimeFilterProgress *) filter)->total = total;
+	
+	return filter;
+}

Added: trunk/camel/camel-mime-filter-progress.h
==============================================================================
--- (empty file)
+++ trunk/camel/camel-mime-filter-progress.h	Sat Jun 21 02:27:36 2008
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ *  Authors: Jeffrey Stedfast <fejj ximian com>
+ *
+ *  Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser 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 __CAMEL_MIME_FILTER_PROGRESS_H__
+#define __CAMEL_MIME_FILTER_PROGRESS_H__
+
+#include <camel/camel-mime-filter.h>
+
+#define CAMEL_MIME_FILTER_PROGRESS(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_progress_get_type (), CamelMimeFilterProgress)
+#define CAMEL_MIME_FILTER_PROGRESS_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_progress_get_type (), CamelMimeFilterProgressClass)
+#define CAMEL_IS_MIME_FILTER_PROGRESS(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_progress_get_type ())
+
+G_BEGIN_DECLS
+
+typedef struct _CamelMimeFilterProgressClass CamelMimeFilterProgressClass;
+typedef struct _CamelMimeFilterProgress CamelMimeFilterProgress;
+
+struct _CamelMimeFilterProgress {
+	CamelMimeFilter parent;
+	
+	guint32 total;
+	guint32 count;
+};
+
+struct _CamelMimeFilterProgressClass {
+	CamelMimeFilterClass parent_class;
+	
+};
+
+
+CamelType camel_mime_filter_progress_get_type (void);
+
+CamelMimeFilter *camel_mime_filter_progress_new (guint32 total);
+
+G_END_DECLS
+
+#endif /* __CAMEL_MIME_FILTER_PROGRESS_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]