27 #include "feediconmanager.h"
29 #include <dcopclient.h>
30 #include <tdeapplication.h>
32 #include <kstandarddirs.h>
33 #include <kstaticdeleter.h>
38 #include <tqvaluelist.h>
42 class FeedIconManager::FeedIconManagerPrivate
45 TQValueList<Feed*> registeredFeeds;
49 FeedIconManager *FeedIconManager::m_instance = 0;
51 static KStaticDeleter<FeedIconManager> feediconmanagersd;
53 FeedIconManager* FeedIconManager::self()
56 m_instance = feediconmanagersd.setObject(m_instance,
new FeedIconManager);
60 void FeedIconManager::fetchIcon(Feed* feed)
62 if (!d->registeredFeeds.contains(feed))
64 d->registeredFeeds.append(feed);
65 connect(feed, TQ_SIGNAL(signalDestroyed(TreeNode*)),
this, TQ_SLOT(slotFeedDestroyed(TreeNode*)));
67 TQString iconURL = getIconURL(KURL(feed->xmlUrl()));
68 d->urlDict.insert(iconURL, feed);
72 FeedIconManager::FeedIconManager(TQObject * parent,
const char *name)
73 : TQObject(parent, name), DCOPObject(
"FeedIconManager"), d(new FeedIconManagerPrivate)
75 connectDCOPSignal(
"kded",
76 "favicons",
"iconChanged(bool, TQString, TQString)",
77 "slotIconChanged(bool, TQString, TQString)",
false);
81 FeedIconManager::~FeedIconManager()
87 void FeedIconManager::loadIcon(
const TQString & url)
91 TQString iconFile = iconLocation(u);
93 if (iconFile.isNull())
96 TQDataStream ds(data, IO_WriteOnly);
98 kapp->dcopClient()->send(
"kded",
"favicons",
"downloadHostIcon(KURL)",
102 slotIconChanged(
false, url, iconFile);
106 TQString FeedIconManager::getIconURL(
const KURL& url)
108 return "http://" +url.host() +
"/";
111 TQString FeedIconManager::iconLocation(
const KURL & url)
const
113 TQByteArray data, reply;
115 TQDataStream ds(data, IO_WriteOnly);
119 kapp->dcopClient()->call(
"kded",
"favicons",
"iconForURL(KURL)", data,
122 if (replyType ==
"TQString") {
123 TQDataStream replyStream(reply, IO_ReadOnly);
125 replyStream >> result;
132 void FeedIconManager::slotFeedDestroyed(TreeNode* node)
134 Feed* feed =
dynamic_cast<Feed*
>(node);
136 while (d->registeredFeeds.contains(feed))
137 d->registeredFeeds.remove(d->registeredFeeds.find(feed));
140 void FeedIconManager::slotIconChanged(
bool ,
const TQString& hostOrURL,
141 const TQString& iconName)
143 TQString iconFile = TDEGlobal::dirs()->findResource(
"cache",
146 TQPixmap p = TQPixmap(iconFile);
149 while (( f = d->urlDict.take(hostOrURL) ))
150 if (d->registeredFeeds.contains(f))
153 emit signalIconChanged(hostOrURL, iconFile);
157 #include "feediconmanager.moc"