[pan2/xzver_support: 22/47] forgot this



commit 37c5e7f44be73cfc3141ea54cebeedd32c2158d5
Author: Heinrich MÃller <heinrich mueller82 gmail com>
Date:   Wed May 30 23:50:29 2012 +0200

    forgot this

 pan/tasks/xzver-decoder.cc |  176 ++++++++++++++++++++++++++++++++++++++++++++
 pan/tasks/xzver-decoder.h  |  106 ++++++++++++++++++++++++++
 2 files changed, 282 insertions(+), 0 deletions(-)
---
diff --git a/pan/tasks/xzver-decoder.cc b/pan/tasks/xzver-decoder.cc
new file mode 100644
index 0000000..21567d6
--- /dev/null
+++ b/pan/tasks/xzver-decoder.cc
@@ -0,0 +1,176 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Pan - A Newsreader for Gtk+
+ * Copyright (C) 2002-2007  Charles Kerr <charles rebelbase com>
+ *
+ * This file
+ * Copyright (C) 2007 Calin Culianu <calin ajvar org>
+ * Copyright (C) 2007 Charles Kerr <charles rebelbase com>
+ *
+ * This file 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 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <config.h>
+#include <cerrno>
+#include <ostream>
+#include <fstream>
+extern "C" {
+#  define PROTOTYPES
+#  include <uulib/uudeview.h>
+#  include <glib/gi18n.h>
+};
+#include <pan/general/worker-pool.h>
+#include <pan/general/debug.h>
+#include <pan/general/file-util.h>
+#include <pan/general/macros.h>
+#include <pan/general/utf8-utils.h>
+#include "xzver-decoder.h"
+
+using namespace pan;
+
+/***
+****
+***/
+
+void
+XZVERDecoder :: enqueue (TaskXOver          * task)
+{
+  disable_progress_update ();
+
+  this->xtask = task;
+
+  mark_read = false;
+  percent = 0;
+  num_scanned_files = 0;
+  current_file.clear ();
+  log_infos.clear();
+  log_errors.clear();
+
+  // gentlemen, start your saving...
+  _worker_pool.push_work (this, task, false);
+}
+
+namespace
+{
+  char* build_cachename (char* buf, size_t len, const char* name)
+  {
+    const char * home(file::get_pan_home().c_str());
+    g_snprintf(buf,len,"%s%c%s%c%s",home, G_DIR_SEPARATOR, "encode-cache", G_DIR_SEPARATOR, name);
+    return buf;
+  }
+}
+
+// save article IN A WORKER THREAD to avoid network stalls
+void
+XZVERDecoder :: do_work()
+{
+  const int bufsz = 4096;
+  char buf[bufsz];
+
+  enable_progress_update();
+
+  char buf[4096];
+
+  int res;
+  if (((res = UUInitialize())) != UURET_OK)
+    log_errors.push_back(_("Error initializing uulib")); // log error
+  else
+  {
+    UUSetMsgCallback (this, uu_log);
+    UUSetOption (UUOPT_DESPERATE, 0, NULL); // keep incompletes; they're useful to par2
+    UUSetOption (UUOPT_IGNMODE, 1, NULL); // don't save file as executable
+    UUSetBusyCallback (this, uu_busy_poll, 500); // .5 secs busy poll?
+    UULoadFile (build_cachename(buf,sizeof(buf), "xzver_test"), 0, 1);
+    UUDecodeFile (UUGetFileListItem (0), build_cachename(buf,sizeof(buf), "xzver_decoded"));
+    UUCleanUp ();
+  }
+
+  /* raw zlib inflate */
+//  FILE * in = fopen (buf, "rb");
+//  FILE * out = fopen (build_cachename(buf,sizeof(buf), "xzver_out"), "wb");
+//  int res(Z_OK);
+//  if (in && out) res = inf (in,out);
+//
+//  /* feed to on_nntp_line */
+//  if (in) fclose(in);
+//  if (out) fclose(out);
+//  if (res==Z_OK)
+//  {
+//    std::ifstream f(buf, std::ios::in);
+//    char buf[4096];
+//    while (f.getline(buf,sizeof(buf))) on_nntp_line_process(nntp,StringView(buf));
+//  }
+
+  disable_progress_update();
+}
+
+/***
+****
+***/
+
+void
+XZVERDecoder :: uu_log (void* data, char* message, int severity)
+{
+  XZVERDecoder *self = static_cast<XZVERDecoder *>(data);
+  char * pch (g_locale_to_utf8 (message, -1, 0, 0, 0));
+
+  if (severity >= UUMSG_WARNING)
+    self->file_errors.push_back (pch ? pch : message);
+
+  if (severity >= UUMSG_ERROR)
+    self->log_errors.push_back (pch ? pch : message);
+  else if (severity >= UUMSG_NOTE)
+    self->log_infos.push_back (pch ? pch : message);
+
+  g_free (pch);
+}
+
+double
+XZVERDecoder :: get_percentage (const uuprogress& p) const
+{
+  // These should add up to 100.
+  // We can tweak these as needed.  Calin sees more time spent
+  // in COPYING, but I'm seeing it in DECODING, so I've split
+  // the difference here and given them the same weight.
+  static const double WEIGHT_SCANNING = 10;
+  static const double WEIGHT_DECODING = 45;
+  static const double WEIGHT_COPYING = 45;
+
+  double base = 0;
+
+  if (p.action != UUACT_SCANNING)
+    base += WEIGHT_SCANNING;
+  else {
+    const double percent = (100.0 + p.percent);
+    return base + (percent / (100.0/WEIGHT_SCANNING));
+  }
+
+  if (p.action != UUACT_DECODING)
+    base += WEIGHT_DECODING;
+  else {
+    const double percent = ((100.0) + p.percent);
+    return base + (percent / (100.0/WEIGHT_DECODING));
+  }
+
+  if (p.action != UUACT_COPYING)
+    base += WEIGHT_COPYING;
+  else {
+    const double percent = p.percent;
+    return base + (percent / (100.0/WEIGHT_COPYING));
+  }
+
+  return 0;
+}
+
+
diff --git a/pan/tasks/xzver-decoder.h b/pan/tasks/xzver-decoder.h
new file mode 100644
index 0000000..f4b33ca
--- /dev/null
+++ b/pan/tasks/xzver-decoder.h
@@ -0,0 +1,106 @@
+
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Pan - A Newsreader for Gtk+
+ * Copyright (C) 2002-2007 Charles Kerr <charles rebelbase com>
+ *
+ * This file
+ * Copyright (C) 2007 Calin Culianu <calin ajvar org>
+ * Copyright (C) 2007 Charles Kerr <charles rebelbase com>
+ *
+ * This file 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 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef _XZVERDecoder_H_
+#define _XZVERDecoder_H_
+
+#include <list>
+#include <string>
+#include <vector>
+#include <pan/general/locking.h>
+#include <pan/general/worker-pool.h>
+#include <pan/tasks/task-xover.h>
+#include <pan/tasks/decoder.h>
+extern "C" {
+#  define PROTOTYPES
+#  include <uulib/uudeview.h>
+};
+
+namespace pan
+{
+
+  class Decoder;
+
+  /**
+   * Decodes attachments in a worker thread.
+   *
+   * @author Calin Culianu <calin ajvar org>
+   * @author Charles Kerr <charles rebelbase com>
+   * @ingroup tasks
+   * @see Queue
+   * @see TaskArticle
+   */
+  class XZVERDecoder: public Decoder
+  {
+    public:
+
+      XZVERDecoder (WorkerPool&);
+
+      ~XZVERDecoder ();
+
+      typedef std::vector<std::string> strings_t;
+
+      void enqueue (TaskXOver        * task);
+
+//    public:
+//
+//      typedef std::list<std::string> log_t;
+//      log_t log_severe, log_errors, log_infos, file_errors;
+//      bool mark_read;
+//      Health health;
+
+    protected: // inherited from WorkerPool::Worker
+
+      void do_work();
+      TaskXOver * xtask;
+
+//    private:
+//
+//      TaskArticle * task;
+//      std::string save_path;
+//      strings_t input_files;
+//      TaskArticle::SaveMode save_mode;
+//      TaskArticle::SaveOptions options;
+//      StringView attachment_filename;
+//
+//      // These are set in the worker thread and polled in the main thread.
+//      Mutex mut;
+//      volatile double percent;
+//      std::string current_file; // the current file we are decoding, with path
+//      volatile int num_scanned_files;
+//
+//      static void uu_log(void *thiz, char *message, int severity);
+//      double get_percentage (const uuprogress& p) const;
+//      static int uu_busy_poll(void * self, uuprogress *p);
+//      /** tell our task about the decode's progress */
+//      static gboolean progress_update_timer_func(gpointer decoder);
+//
+//      WorkerPool& _worker_pool;
+//      int _gsourceid;
+//      void disable_progress_update();
+//      void enable_progress_update();
+  };
+}
+
+#endif



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