Esempio n. 1
0
static NewsFeed *
news_format_rss_read (NewsFormat    *format,
                      GInputStream  *stream,
                      GError       **error)
{
   NewsFormatRssPrivate *priv;
   NewsFormatRss *rss = (NewsFormatRss *)format;
   GomAdapter *adapter;
   NewsSource *source;
   XmlReader *reader;
   NewsFeed *feed;
   gchar *source_id;

   ENTRY;

   g_return_val_if_fail(NEWS_IS_FORMAT_RSS(rss), NULL);

   priv = rss->priv;

   if (!(source = news_format_get_source(format))) {
      g_assert_not_reached();
      RETURN(NULL);
   }

   if (!(adapter = news_format_get_adapter(format))) {
      g_assert_not_reached();
      RETURN(NULL);
   }

   reader = xml_reader_new();
   if (!xml_reader_load_from_stream(reader, stream, error)) {
      g_object_unref(reader);
      RETURN(NULL);
   }

   g_signal_connect(reader, "error",
                    G_CALLBACK(news_format_rss_on_error),
                    format);

   g_object_get(source, "id", &source_id, NULL);
   feed = g_object_new(NEWS_TYPE_FEED,
                       "adapter", adapter,
                       "is-new", TRUE,
                       "source-id", source_id,
                       NULL);
   if (!news_format_rss_read_from_xml(rss, reader, feed, error)) {
      g_clear_object(&feed);
   } else if (priv->error) {
      g_clear_object(&feed);
      if (error) {
         *error = g_error_copy(priv->error);
      }
   }

   g_free(source_id);
   g_object_unref(reader);

   RETURN(feed);
}
Esempio n. 2
0
gboolean
xml_reader_load_from_file (XmlReader     *reader,
                           GFile         *file,
                           GCancellable  *cancellable,
                           GError       **error)
{
  GFileInputStream *stream;
  gboolean ret;

  g_return_val_if_fail (XML_IS_READER (reader), FALSE);
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);

  if (!(stream = g_file_read (file, cancellable, error)))
    return FALSE;

  ret = xml_reader_load_from_stream (reader, G_INPUT_STREAM (stream), error);

  g_clear_object (&stream);

  return ret;
}