[pan2] + ability to specifiy custom filename extension for cache files (default: eml) + fixes to build
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2] + ability to specifiy custom filename extension for cache files (default: eml) + fixes to build
- Date: Tue, 17 Jan 2012 18:20:16 +0000 (UTC)
commit e6709223c4abd728ef8ef75419fd779c6467b00b
Author: Heinrich MÃller <henmull src gnome org>
Date: Tue Jan 17 19:19:33 2012 +0100
+ ability to specifiy custom filename extension for cache files (default: eml)
+ fixes to build
pan/data-impl/article-filter.cc | 8 ++-
pan/data-impl/data-impl.cc | 4 +-
pan/data-impl/data-impl.h | 2 +-
pan/data/article-cache.cc | 183 ++++++++++++++++++++-------------------
pan/data/article-cache.h | 11 ++-
pan/data/cert-store.cc | 7 +-
pan/gui/gui.cc | 9 ++
pan/gui/pan.cc | 2 +-
pan/gui/prefs-ui.cc | 30 ++++++-
pan/tasks/socket-impl-main.cc | 10 ++-
pan/tasks/socket-impl-openssl.h | 9 ++-
pan/usenet-utils/ssl-utils.h | 1 -
12 files changed, 170 insertions(+), 106 deletions(-)
---
diff --git a/pan/data-impl/article-filter.cc b/pan/data-impl/article-filter.cc
index 6f6ffce..9a25dbb 100644
--- a/pan/data-impl/article-filter.cc
+++ b/pan/data-impl/article-filter.cc
@@ -23,7 +23,13 @@
#include <pan/general/macros.h>
#include <pan/data/data.h>
#include <gmime/gmime.h>
-#include <glib/gprintf.h>
+
+//#include <glib/gprintf.h>
+extern "C"
+{
+ #include <glib.h>
+}
+
#include "article-filter.h"
using namespace pan;
diff --git a/pan/data-impl/data-impl.cc b/pan/data-impl/data-impl.cc
index f290035..a047305 100644
--- a/pan/data-impl/data-impl.cc
+++ b/pan/data-impl/data-impl.cc
@@ -67,9 +67,9 @@ namespace
}
-DataImpl :: DataImpl (bool unit_test, int cache_megs, DataIO * io):
+DataImpl :: DataImpl (const StringView& cache_ext, bool unit_test, int cache_megs, DataIO * io):
ProfilesImpl (*io),
- _cache (get_cache_path(), cache_megs),
+ _cache (get_cache_path(), cache_ext, cache_megs),
_encode_cache (get_encode_cache_path(), cache_megs),
_certstore(*this),
_unit_test (unit_test),
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index d8afba7..edb4b13 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -74,7 +74,7 @@ namespace pan
**/
public:
- DataImpl (bool unit_test=false, int cache_megs=10, DataIO * source=new DataIO());
+ DataImpl (const StringView& cache_ext, bool unit_test=false, int cache_megs=10, DataIO * source=new DataIO());
virtual ~DataImpl ();
virtual void save_state ();
diff --git a/pan/data/article-cache.cc b/pan/data/article-cache.cc
index 487983a..ffb8df4 100644
--- a/pan/data/article-cache.cc
+++ b/pan/data/article-cache.cc
@@ -43,104 +43,105 @@ extern "C"
#include "article-cache.h"
using namespace pan;
+/**
+* Message-IDs are transformed via message_id_to_filename()
+* to play nicely with some filesystems, so to extract the Message-ID
+* from a filename we need to reverse the transform.
+*
+* @return string length, or 0 on failure
+*/
+
+int
+ArticleCache :: filename_to_message_id (char * buf, int len, const char * basename)
+{
+ const char * in;
+ char * out;
+ char * pch;
+ char tmp_basename[PATH_MAX];
+
+ // sanity clause
+ pan_return_val_if_fail (basename && *basename, 0);
+ pan_return_val_if_fail (buf!=NULL, 0);
+ pan_return_val_if_fail (len>0, 0);
+
+ // remove the trailing ".msg" or similar
+ g_strlcpy (tmp_basename, basename, sizeof(tmp_basename));
+// if ((pch = g_strrstr (tmp_basename, msg_extension.c_str())))
+// *pch = '\0';
+ if ((pch = g_strrstr (tmp_basename, ".")))
+ *pch = '\0';
+ g_strstrip (tmp_basename);
+
+ std::cerr<<"debug "<<tmp_basename<<"\n";
+
+ // transform
+ out = buf;
+ *out++ = '<';
+ for (in=tmp_basename; *in; ++in) {
+ if (in[0]!='%' || !g_ascii_isxdigit(in[1]) || !g_ascii_isxdigit(in[2]))
+ *out++ = *in;
+ else {
+ char buf[3];
+ buf[0] = *++in;
+ buf[1] = *++in;
+ buf[2] = '\0';
+ *out++ = (char) strtoul (buf, NULL, 16);
+ }
+ }
+ *out++ = '>';
+ *out = '\0';
-/*****
-******
-*****/
+ return out - buf;
+}
-namespace
+/**
+* Some characters in message-ids don't work well in filenames,
+* so we transform them to a safer name.
+*/
+char*
+ArticleCache :: message_id_to_filename (char * buf, int len, const StringView& mid) const
{
- /**
- * Some characters in message-ids don't work well in filenames,
- * so we transform them to a safer name.
- */
- char*
- message_id_to_filename (char * buf, int len, const StringView& mid)
- {
- // sanity clause
- pan_return_val_if_fail (!mid.empty(), 0);
- pan_return_val_if_fail (buf!=0, NULL);
- pan_return_val_if_fail (len>0, NULL);
-
- // some characters in message-ids are illegal on older Windows boxes,
- // so we transform those illegal characters using URL encoding
- char * out = buf;
- for (const char *in=mid.begin(), *end=mid.end(); in!=end; ++in) {
- switch (*in) {
- case '%': /* this is the escape character */
- case '"': case '*': case '/': case ':': case '?': case '|':
- case '\\': /* these are illegal on vfat, fat32 */
- g_snprintf (out, len-(out-buf), "%%%02x", (int)*in);
- out += 3;
- break;
- case '<': case '>': /* these are illegal too, but rather than encoding
- them, follow the convention of omitting them */
- break;
- default:
- *out++ = *in;
- }
- }
-
- g_snprintf (out, len-(out-buf), ".msg");
- return buf;
- }
+ // sanity clause
+ pan_return_val_if_fail (!mid.empty(), 0);
+ pan_return_val_if_fail (buf!=0, NULL);
+ pan_return_val_if_fail (len>0, NULL);
+
+ // some characters in message-ids are illegal on older Windows boxes,
+ // so we transform those illegal characters using URL encoding
+ char * out = buf;
+ for (const char *in=mid.begin(), *end=mid.end(); in!=end; ++in) {
+ switch (*in) {
+ case '%': /* this is the escape character */
+ case '"': case '*': case '/': case ':': case '?': case '|':
+ case '\\': /* these are illegal on vfat, fat32 */
+ g_snprintf (out, len-(out-buf), "%%%02x", (int)*in);
+ out += 3;
+ break;
+ case '<': case '>': /* these are illegal too, but rather than encoding
+ them, follow the convention of omitting them */
+ break;
+ default:
+ *out++ = *in;
+ }
+ }
- /**
- * Message-IDs are transformed via message_id_to_filename()
- * to play nicely with some filesystems, so to extract the Message-ID
- * from a filename we need to reverse the transform.
- *
- * @return string length, or 0 on failure
- */
- int
- filename_to_message_id (char * buf, int len, const char * basename)
- {
- const char * in;
- char * out;
- char * pch;
- char tmp_basename[PATH_MAX];
-
- // sanity clause
- pan_return_val_if_fail (basename && *basename, 0);
- pan_return_val_if_fail (buf!=NULL, 0);
- pan_return_val_if_fail (len>0, 0);
-
- // remove the trailing ".msg"
- g_strlcpy (tmp_basename, basename, sizeof(tmp_basename));
- if ((pch = g_strrstr (tmp_basename, ".msg")))
- *pch = '\0';
- g_strstrip (tmp_basename);
-
- // transform
- out = buf;
- *out++ = '<';
- for (in=tmp_basename; *in; ++in) {
- if (in[0]!='%' || !g_ascii_isxdigit(in[1]) || !g_ascii_isxdigit(in[2]))
- *out++ = *in;
- else {
- char buf[3];
- buf[0] = *++in;
- buf[1] = *++in;
- buf[2] = '\0';
- *out++ = (char) strtoul (buf, NULL, 16);
- }
- }
- *out++ = '>';
- *out = '\0';
+ // add the filename extension
+ char* tmp = new char[msg_extension.length()+1];
+ g_snprintf (tmp, sizeof(tmp), ".%s", msg_extension.c_str());
+ g_snprintf (out, len-(out-buf), tmp);
- return out - buf;
- }
-};
+ delete tmp;
-/*****
-******
-*****/
+ return buf;
+}
-ArticleCache :: ArticleCache (const StringView& path, size_t max_megs):
+ArticleCache :: ArticleCache (const StringView& path, const StringView& extension, size_t max_megs):
+ msg_extension(extension),
_path (path.str, path.len),
_max_megs (max_megs),
_current_bytes (0ul)
{
+
GError * err = NULL;
GDir * dir = g_dir_open (_path.c_str(), 0, &err);
if (err != NULL)
diff --git a/pan/data/article-cache.h b/pan/data/article-cache.h
index 74d604c..a82c971 100644
--- a/pan/data/article-cache.h
+++ b/pan/data/article-cache.h
@@ -38,6 +38,7 @@ extern "C"
namespace pan
{
+
class Article;
class StringView;
@@ -60,7 +61,7 @@ namespace pan
{
public:
- ArticleCache (const StringView& path, size_t max_megs=10);
+ ArticleCache (const StringView& path, const StringView& extension, size_t max_megs=10);
~ArticleCache ();
typedef std::vector<Quark> mid_sequence_t;
@@ -92,11 +93,15 @@ namespace pan
public:
void set_max_megs (size_t value) { _max_megs = value; }
+ void set_msg_extension (const std::string& s) { msg_extension = s; }
+ const std::string& get_msg_extension () const { return msg_extension; }
private:
std::map<Quark,int> _locks;
+ std::string msg_extension;
+
struct MsgInfo {
Quark _message_id;
size_t _size;
@@ -130,6 +135,10 @@ namespace pan
char* get_filename (char* buf, int buflen, const Quark& mid) const;
GMimeStream* get_message_file_stream (const Quark& mid) const;
GMimeStream* get_message_mem_stream (const Quark& mid) const;
+
+ int filename_to_message_id (char * buf, int len, const char * basename);
+ char* message_id_to_filename (char * buf, int len, const StringView& mid) const;
+
};
}
diff --git a/pan/data/cert-store.cc b/pan/data/cert-store.cc
index f632c4c..4cc3d47 100644
--- a/pan/data/cert-store.cc
+++ b/pan/data/cert-store.cc
@@ -21,8 +21,10 @@
*/
#include <string>
-#include <glib/giochannel.h>
-#include <glib/gstring.h>
+
+//#include <glib/giochannel.h>
+//#include <glib/gstring.h>
+
#include <pan/tasks/socket.h>
#include <config.h>
#include <map>
@@ -34,6 +36,7 @@
extern "C" {
#include <glib/gi18n.h>
+ #include <glib.h>
}
#include <pan/general/debug.h>
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index c07eae8..701d061 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -2249,6 +2249,15 @@ GUI :: on_prefs_string_changed (const StringView& key, const StringView& value)
if (key == "default-save-attachments-path")
prev_path.assign (value.str, value.len);
+
+ if (key == "cache-file-extension")
+ {
+ _prefs.save();
+ StringView tmp(value);
+ // default to "eml" if value is empty to conform with article-cache
+ if (tmp.empty()) tmp ="eml";
+ _data.get_cache().set_msg_extension(tmp);
+ }
}
#ifdef HAVE_GNUTLS
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index e7820f8..dc07cec 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -911,7 +911,7 @@ main (int argc, char *argv[])
// instantiate the backend...
const int cache_megs = prefs.get_int ("cache-size-megs", 10);
- DataImpl data (false, cache_megs);
+ DataImpl data (prefs.get_string("cache-file-extension","msg"), false, cache_megs);
ArticleCache& cache (data.get_cache ());
EncodeCache& encode_cache (data.get_encode_cache());
CertStore& certstore (data.get_certstore());
diff --git a/pan/gui/prefs-ui.cc b/pan/gui/prefs-ui.cc
index b28ab29..bd5792a 100644
--- a/pan/gui/prefs-ui.cc
+++ b/pan/gui/prefs-ui.cc
@@ -60,6 +60,14 @@ namespace
static_cast<Prefs*>(prefs_gpointer)->set_flag (key, gtk_toggle_button_get_active(toggle));
}
+ void entry_changed_cb (GtkEntry * e, gpointer prefs_gpointer)
+ {
+ const char * key = (const char*) g_object_get_data (G_OBJECT(e), PREFS_KEY);
+ const char * val = gtk_entry_get_text (GTK_ENTRY(e));
+ if (key && val)
+ static_cast<Prefs*>(prefs_gpointer)->set_string (key, val);
+ }
+
void set_string_from_radio_cb (GtkToggleButton * toggle, gpointer prefs_gpointer)
{
const char * key = (const char*) g_object_get_data (G_OBJECT(toggle), PREFS_KEY);
@@ -77,6 +85,16 @@ namespace
return t;
}
+ GtkWidget* new_entry (const char* key, const char* fallback, Prefs& prefs)
+ {
+ GtkWidget * t = gtk_entry_new();
+ g_object_set_data_full (G_OBJECT(t), PREFS_KEY, g_strdup(key), g_free);
+ gtk_entry_set_text (GTK_ENTRY(t), prefs.get_string (key, fallback).c_str());
+ g_signal_connect (t, "changed", G_CALLBACK(entry_changed_cb), &prefs);
+ return t;
+ }
+
+
GtkWidget* new_layout_radio (GtkWidget* prev, const guint8* line, const char* value, std::string& cur, Prefs& prefs)
{
GtkWidget * r = prev==0
@@ -340,7 +358,7 @@ void
PrefsDialog :: on_prefs_string_changed (const StringView& key, const StringView& value)
{
- if (key.strcmp("default-charset") == 0)
+ if (key == "default-charset")
{
_prefs.save();
update_default_charset_label(value);
@@ -555,7 +573,9 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
HIG :: workarea_add_wide_control (t, &row, w);
w = new_check_button (_("E_xpand all threads when entering group"), "expand-threads-when-entering-group", false, prefs);
HIG :: workarea_add_wide_control (t, &row, w);
+
HIG::workarea_add_section_divider (t, &row);
+
HIG :: workarea_add_section_title (t, &row, _("Articles"));
HIG :: workarea_add_section_spacer (t, row, 5);
w = new_check_button (_("Space selects next article rather than next unread"), "space-selects-next-article", true, prefs);
@@ -566,6 +586,10 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
HIG :: workarea_add_wide_control (t, &row, w);
w = new_check_button (_("Smooth scrolling"), "smooth-scrolling", true, prefs);
HIG :: workarea_add_wide_control (t, &row, w);
+
+ HIG::workarea_add_section_divider (t, &row);
+
+ HIG :: workarea_add_section_title (t, &row, _("Article Cache"));
w = new_check_button (_("Clear article cache on shutdown"), "clear-article-cache-on-shutdown", false, prefs);
HIG :: workarea_add_wide_control (t, &row, w);
w = new_spin_button ("cache-size-megs", 10, 1024*16, prefs);
@@ -573,7 +597,9 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
gtk_misc_set_alignment (GTK_MISC(l), 0.0, 0.5);
gtk_label_set_mnemonic_widget(GTK_LABEL(l), w);
HIG::workarea_add_row (t, &row, w, l);
- HIG::workarea_add_section_divider (t, &row);
+ w = new_entry ("cache-file-extension", "msg", prefs);
+ HIG :: workarea_add_row (t, &row, w, gtk_label_new(_("File extension for Cached Articles")));
+
HIG :: workarea_finish (t, &row);
gtk_notebook_append_page (GTK_NOTEBOOK(notebook), t, gtk_label_new_with_mnemonic(_("_Behavior")));
diff --git a/pan/tasks/socket-impl-main.cc b/pan/tasks/socket-impl-main.cc
index 4e4bd1f..3ec7bcd 100644
--- a/pan/tasks/socket-impl-main.cc
+++ b/pan/tasks/socket-impl-main.cc
@@ -27,8 +27,14 @@
***/
#include <string>
-#include <glib/giochannel.h>
-#include <glib/gstring.h>
+//#include <glib/giochannel.h>
+//#include <glib/gstring.h>
+
+extern "C"
+{
+ #include <glib.h>
+}
+
#include <pan/tasks/socket.h>
#include <config.h>
diff --git a/pan/tasks/socket-impl-openssl.h b/pan/tasks/socket-impl-openssl.h
index ff1da0d..32e195d 100644
--- a/pan/tasks/socket-impl-openssl.h
+++ b/pan/tasks/socket-impl-openssl.h
@@ -25,8 +25,13 @@
#define __SocketSSL_h__
#include <string>
-#include <glib/giochannel.h>
-#include <glib/gstring.h>
+//#include <glib/giochannel.h>
+//#include <glib/gstring.h>
+extern "C"
+{
+ #include <glib.h>
+}
+
#include <pan/general/debug.h>
#include <pan/general/quark.h>
#include <pan/tasks/socket.h>
diff --git a/pan/usenet-utils/ssl-utils.h b/pan/usenet-utils/ssl-utils.h
index 885de1e..d815568 100644
--- a/pan/usenet-utils/ssl-utils.h
+++ b/pan/usenet-utils/ssl-utils.h
@@ -41,7 +41,6 @@
#include <pan/tasks/socket.h>
#include <pan/general/e-util.h>
#include <gnutls/gnutls.h>
-#include <gnutls/openssl.h>
#include <gnutls/x509.h>
#include <map>
#include <sstream>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]