diff options
author | Lars Kotthoff <larsko@uwyo.edu> | 2018-10-13 20:38:54 -0600 |
---|---|---|
committer | Lars Kotthoff <larsko@uwyo.edu> | 2018-10-13 20:38:54 -0600 |
commit | 501384f6f1719dbbf94f2dfdf1a67bd0006ba2de (patch) | |
tree | ee50e4e21b40bebcf94c2fd3577ae8b63998df83 | |
parent | cda29352783efb9be76e76a24ac6d2406697fe4b (diff) |
first attempt at a general read plugin
-rw-r--r-- | src/message_thread.cc | 38 | ||||
-rw-r--r-- | src/plugin/astroid_activatable.c | 106 | ||||
-rw-r--r-- | src/plugin/astroid_activatable.h | 3 | ||||
-rw-r--r-- | src/plugin/manager.cc | 14 | ||||
-rw-r--r-- | src/plugin/manager.hh | 1 |
5 files changed, 105 insertions, 57 deletions
diff --git a/src/message_thread.cc b/src/message_thread.cc index c1a968d..589b830 100644 --- a/src/message_thread.cc +++ b/src/message_thread.cc @@ -16,6 +16,9 @@ # include "utils/ustring_utils.hh" # include "utils/vector_utils.hh" # include "actions/action_manager.hh" +# ifndef DISABLE_PLUGINS + # include "plugin/manager.hh" +# endif using namespace std; using namespace boost::filesystem; @@ -170,30 +173,35 @@ namespace Astroid { return; } else { - GError *err = NULL; (void) (err); // not used in GMime 2. - GMimeStream * stream = g_mime_stream_file_open (fname.c_str(), "r", &err); - g_mime_stream_file_set_owner (GMIME_STREAM_FILE(stream), TRUE); + GMimeStream * stream = NULL; +# ifndef DISABLE_PLUGINS + stream = astroid->plugin_manager->astroid_extension->process (fname.c_str()); +# endif if (stream == NULL) { - LOG (error) << "failed to open file: " << fname << " (unspecified error)"; + GError *err = NULL; (void) (err); // not used in GMime 2. + stream = g_mime_stream_file_open (fname.c_str(), "r", &err); + g_mime_stream_file_set_owner (GMIME_STREAM_FILE(stream), TRUE); + if (stream == NULL) { + LOG (error) << "failed to open file: " << fname << " (unspecified error)"; - has_file = false; - missing_content = true; + has_file = false; + missing_content = true; - if (in_notmuch) { - LOG (warn) << "loading cache for missing file from notmuch"; - load_notmuch_cache (); - } else { - LOG (error) << "tried to open disk file, but failed, message is not in database either."; - string error_s = "failed to open file: " + fname; - throw message_error (error_s.c_str()); + if (in_notmuch) { + LOG (warn) << "loading cache for missing file from notmuch"; + load_notmuch_cache (); + } else { + LOG (error) << "tried to open disk file, but failed, message is not in database either."; + string error_s = "failed to open file: " + fname; + throw message_error (error_s.c_str()); + } + return; } - return; } GMimeParser * parser = g_mime_parser_new_with_stream (stream); GMimeMessage * _message = g_mime_parser_construct_message (parser, g_mime_parser_options_get_default ()); load_message (_message); - g_object_unref (_message); // is reffed in load_message g_object_unref (stream); // reffed from parser g_object_unref (parser); // reffed from message diff --git a/src/plugin/astroid_activatable.c b/src/plugin/astroid_activatable.c index 60ff420..eaa9d15 100644 --- a/src/plugin/astroid_activatable.c +++ b/src/plugin/astroid_activatable.c @@ -14,19 +14,19 @@ G_DEFINE_INTERFACE (AstroidActivatable, astroid_activatable, G_TYPE_OBJECT) void astroid_activatable_default_init (AstroidActivatableInterface *iface) { - static gboolean initialized = FALSE; + static gboolean initialized = FALSE; (void)(iface); /* unused */ - if (!initialized) { - /** - * AstroidActivatable:window: - * - * The window property contains the gtr window for this - * #AstroidActivatable instance. - */ + if (!initialized) { + /** + * AstroidActivatable:window: + * + * The window property contains the gtr window for this + * #AstroidActivatable instance. + */ /* - g_object_interface_install_property (iface, + g_object_interface_install_property (iface, g_param_spec_object ("shell", "Shell", "The Liferea shell", @@ -36,8 +36,8 @@ astroid_activatable_default_init (AstroidActivatableInterface *iface) G_PARAM_STATIC_STRINGS)); */ - initialized = TRUE; - } + initialized = TRUE; + } } /** @@ -49,13 +49,13 @@ astroid_activatable_default_init (AstroidActivatableInterface *iface) void astroid_activatable_activate (AstroidActivatable * activatable) { - AstroidActivatableInterface *iface; + AstroidActivatableInterface *iface; - g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable)); + g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable)); - iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); - if (iface->activate) - iface->activate (activatable); + iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); + if (iface->activate) + iface->activate (activatable); } /** @@ -67,13 +67,13 @@ astroid_activatable_activate (AstroidActivatable * activatable) void astroid_activatable_deactivate (AstroidActivatable * activatable) { - AstroidActivatableInterface *iface; + AstroidActivatableInterface *iface; - g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable)); + g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable)); - iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); - if (iface->deactivate) - iface->deactivate (activatable); + iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); + if (iface->deactivate) + iface->deactivate (activatable); } /** @@ -86,13 +86,13 @@ astroid_activatable_deactivate (AstroidActivatable * activatable) void astroid_activatable_update_state (AstroidActivatable * activatable) { - AstroidActivatableInterface *iface; + AstroidActivatableInterface *iface; - g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable)); + g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable)); - iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); - if (iface->update_state) - iface->update_state (activatable); + iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); + if (iface->update_state) + iface->update_state (activatable); } /** @@ -104,13 +104,13 @@ astroid_activatable_update_state (AstroidActivatable * activatable) const char * astroid_activatable_get_user_agent (AstroidActivatable * activatable) { - AstroidActivatableInterface *iface; + AstroidActivatableInterface *iface; - if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL; + if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL; - iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); - if (iface->get_user_agent) - return iface->get_user_agent (activatable); + iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); + if (iface->get_user_agent) + return iface->get_user_agent (activatable); return NULL; } @@ -124,20 +124,20 @@ astroid_activatable_get_user_agent (AstroidActivatable * activatable) const char * astroid_activatable_generate_mid (AstroidActivatable * activatable) { - AstroidActivatableInterface *iface; + AstroidActivatableInterface *iface; - if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL; + if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL; - iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); - if (iface->generate_mid) - return iface->generate_mid (activatable); + iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); + if (iface->generate_mid) + return iface->generate_mid (activatable); return NULL; } /** * astroid_activatable_get_tag_colors: - * @activatable: A #AstroidThreadViewActivatable. + * @activatable: A #AstroidActivatable. * @tag : A #utf8. * @bg : A #utf8. * @@ -146,13 +146,35 @@ astroid_activatable_generate_mid (AstroidActivatable * activatable) GList * astroid_activatable_get_tag_colors (AstroidActivatable * activatable, const char * tag, const char * bg) { - AstroidActivatableInterface *iface; + AstroidActivatableInterface *iface; + + if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL; + + iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); + if (iface->get_tag_colors) + return iface->get_tag_colors (activatable, tag, bg); + + return NULL; +} + +/** + * astroid_activatable_process: + * @activatable: A #AstroidActivatable. + * @fname: The file name of the message. + * + * Returns: Stream of the processed raw message. + */ +GMimeStream * +astroid_activatable_process (AstroidActivatable * activatable, const char * fname) +{ + AstroidActivatableInterface *iface; - if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL; + if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL; - iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); - if (iface->get_tag_colors) - return iface->get_tag_colors (activatable, tag, bg); + iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable); + if (iface->process) { + return iface->process (activatable, fname); + } return NULL; } diff --git a/src/plugin/astroid_activatable.h b/src/plugin/astroid_activatable.h index 65749c4..f175f81 100644 --- a/src/plugin/astroid_activatable.h +++ b/src/plugin/astroid_activatable.h @@ -1,6 +1,7 @@ # pragma once # include <glib-object.h> +# include <gmime/gmime.h> G_BEGIN_DECLS @@ -27,6 +28,7 @@ struct _AstroidActivatableInterface const char * (*get_user_agent) (AstroidActivatable * activatable); const char * (*generate_mid) (AstroidActivatable * activatable); GList * (*get_tag_colors) (AstroidActivatable * activatable, const char * tag, const char * bg); + GMimeStream * (*process) (AstroidActivatable * activatable, const char * fname); }; @@ -41,6 +43,7 @@ void astroid_activatable_update_state (AstroidActivatable *activatable); const char * astroid_activatable_get_user_agent (AstroidActivatable * activatable); const char * astroid_activatable_generate_mid (AstroidActivatable * activatable); GList * astroid_activatable_get_tag_colors (AstroidActivatable * activatable, const char * tag, const char * bg); +GMimeStream * astroid_activatable_process (AstroidActivatable * activatable, const char * fname); G_END_DECLS diff --git a/src/plugin/manager.cc b/src/plugin/manager.cc index 51be111..b8e47db 100644 --- a/src/plugin/manager.cc +++ b/src/plugin/manager.cc @@ -241,6 +241,20 @@ namespace Astroid { return clrs; } + GMimeStream * PluginManager::AstroidExtension::process ( + const char * fname) { + if (!active || astroid->plugin_manager->disabled) return NULL; + + for (PeasPluginInfo * p : astroid->plugin_manager->astroid_plugins) { + PeasExtension * pe = peas_extension_set_get_extension (extensions, p); + + GMimeStream * ret = astroid_activatable_process (ASTROID_ACTIVATABLE(pe), fname); + if(ret != NULL) return ret; + } + + return NULL; + } + /* ******************** * ThreadIndexExtension * ********************/ diff --git a/src/plugin/manager.hh b/src/plugin/manager.hh index fa0a5c0..1858614 100644 --- a/src/plugin/manager.hh +++ b/src/plugin/manager.hh @@ -45,6 +45,7 @@ namespace Astroid { bool get_user_agent (ustring &); bool generate_mid (ustring &); std::pair<ustring, ustring> get_tag_colors (ustring tag, ustring bg); + GMimeStream * process (const char * fname); }; AstroidExtension * astroid_extension; // set up from Astroid |