akregator/src
dragobjects.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "dragobjects.h"
00026 #include "feed.h"
00027
00028 #include <qcstring.h>
00029
00030 namespace Akregator {
00031
00032 class Article;
00033
00034 ArticleDrag::ArticleDrag(const QValueList<Article>& articles, QWidget* dragSource, const char* name)
00035 : KURLDrag(articleURLs(articles), dragSource, name), m_items(articlesToDragItems(articles))
00036 {}
00037
00038 bool ArticleDrag::canDecode(const QMimeSource* e)
00039 {
00040 return e->provides("akregator/articles");
00041 }
00042
00043 bool ArticleDrag::decode(const QMimeSource* e, QValueList<ArticleDragItem>& articles)
00044 {
00045 articles.clear();
00046 QByteArray array = e->encodedData("akregator/articles");
00047
00048 QDataStream stream(array, IO_ReadOnly);
00049
00050 while (!stream.atEnd())
00051 {
00052 ArticleDragItem i;
00053 stream >> i.feedURL;
00054 stream >> i.guid;
00055 articles.append(i);
00056 }
00057
00058 return true;
00059 }
00060
00061 const char* ArticleDrag::format(int i) const
00062 {
00063 if (i == 0)
00064 return "text/uri-list";
00065 else if (i == 1)
00066 return "akregator/articles";
00067
00068 return 0;
00069 }
00070
00071 QByteArray ArticleDrag::encodedData(const char* mime) const
00072 {
00073 QCString mimetype(mime);
00074 if (mimetype == "akregator/articles")
00075 {
00076 QByteArray ba;
00077 QDataStream stream(ba, IO_WriteOnly);
00078
00079 QValueList<ArticleDragItem>::ConstIterator end = m_items.end();
00080 for (QValueList<ArticleDragItem>::ConstIterator it = m_items.begin(); it != end; ++it)
00081 {
00082 stream << (*it).feedURL;
00083 stream << (*it).guid;
00084 }
00085 return ba;
00086 }
00087 else
00088 {
00089 return KURLDrag::encodedData(mime);
00090 }
00091 }
00092
00093 QValueList<ArticleDragItem> ArticleDrag::articlesToDragItems(const QValueList<Article>& articles)
00094 {
00095 QValueList<ArticleDragItem> items;
00096
00097 QValueList<Article>::ConstIterator end(articles.end());
00098
00099 for (QValueList<Article>::ConstIterator it = articles.begin(); it != end; ++it)
00100 {
00101 ArticleDragItem i;
00102 i.feedURL = (*it).feed() ? (*it).feed()->xmlUrl() : "";
00103 i.guid = (*it).guid();
00104 items.append(i);
00105 }
00106
00107 return items;
00108 }
00109
00110 KURL::List ArticleDrag::articleURLs(const QValueList<Article>& articles)
00111 {
00112 KURL::List urls;
00113 QValueList<Article>::ConstIterator end(articles.end());
00114 for (QValueList<Article>::ConstIterator it = articles.begin(); it != end; ++it)
00115 urls.append((*it).link());
00116 return urls;
00117 }
00118
00119 }
|