25 #include "dragobjects.h"
28 #include <tqcstring.h>
34 ArticleDrag::ArticleDrag(
const TQValueList<Article>& articles, TQWidget* dragSource,
const char* name)
35 : KURLDrag(articleURLs(articles), dragSource, name), m_items(articlesToDragItems(articles))
38 bool ArticleDrag::canDecode(
const TQMimeSource* e)
40 return e->provides(
"akregator/articles");
43 bool ArticleDrag::decode(
const TQMimeSource* e, TQValueList<ArticleDragItem>& articles)
46 TQByteArray array = e->encodedData(
"akregator/articles");
48 TQDataStream stream(array, IO_ReadOnly);
50 while (!stream.atEnd())
61 const char* ArticleDrag::format(
int i)
const
64 return "text/uri-list";
66 return "akregator/articles";
71 TQByteArray ArticleDrag::encodedData(
const char* mime)
const
73 TQCString mimetype(mime);
74 if (mimetype ==
"akregator/articles")
77 TQDataStream stream(ba, IO_WriteOnly);
79 TQValueList<ArticleDragItem>::ConstIterator end = m_items.end();
80 for (TQValueList<ArticleDragItem>::ConstIterator it = m_items.begin(); it != end; ++it)
82 stream << (*it).feedURL;
89 return KURLDrag::encodedData(mime);
93 TQValueList<ArticleDragItem> ArticleDrag::articlesToDragItems(
const TQValueList<Article>& articles)
95 TQValueList<ArticleDragItem> items;
97 TQValueList<Article>::ConstIterator end(articles.end());
99 for (TQValueList<Article>::ConstIterator it = articles.begin(); it != end; ++it)
102 i.feedURL = (*it).feed() ? (*it).feed()->xmlUrl() :
"";
103 i.guid = (*it).guid();
110 KURL::List ArticleDrag::articleURLs(
const TQValueList<Article>& articles)
113 TQValueList<Article>::ConstIterator end(articles.end());
114 for (TQValueList<Article>::ConstIterator it = articles.begin(); it != end; ++it)
115 urls.append((*it).link());