akregator/src

feeditem.cpp
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2004 Frank Osterfeld <frank.osterfeld at kdemail.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include "actionmanager.h"
26 #include "feed.h"
27 #include "feeditem.h"
28 
29 #include <tqpopupmenu.h>
30 #include <tdeaction.h>
31 #include <kdebug.h>
32 #include <kiconloader.h>
33 #include <tqstring.h>
34 
35 namespace Akregator {
36 
37 FeedItem::FeedItem(FolderItem* parent, Feed* node) : TreeNodeItem(parent, node)
38 {
39  initialize(node);
40 }
41 
42 FeedItem::FeedItem(TDEListView* parent, Feed* node) : TreeNodeItem(parent, node)
43 {
44  initialize(node);
45 }
46 
47 FeedItem::FeedItem(TDEListView* parent, TreeNodeItem* after, Feed* node) : TreeNodeItem(parent, after, node)
48 {
49  initialize(node);
50 }
51 
52 
53 FeedItem::FeedItem(FolderItem* parent, TreeNodeItem* after, Feed* node) : TreeNodeItem(parent, after, node)
54 {
55  initialize(node);
56 }
57 
58 FeedItem::~FeedItem()
59 {
60 }
61 
62 Feed* FeedItem::node()
63 {
64  return static_cast<Feed*> (m_node);
65 }
66 
67 void FeedItem::nodeChanged()
68 {
69  if ( node()->fetchErrorOccurred() )
70  setPixmap(0, errorPixmap());
71  else
72  {
73  if (!node()->favicon().isNull())
74  setPixmap(0, node()->favicon());
75  else
76  {
77  setPixmap( 0, defaultPixmap() );
78  node()->loadFavicon();
79  }
80  }
81 
82  TreeNodeItem::nodeChanged();
83 }
84 
85 TQPixmap FeedItem::errorPixmap()
86 {
87  return TDEGlobal::iconLoader()->loadIcon("error", TDEIcon::Small);
88 }
89 
90 TQPixmap FeedItem::defaultPixmap()
91 {
92  return TDEGlobal::iconLoader()->loadIcon("text-plain", TDEIcon::Small);
93 }
94 
95 void FeedItem::initialize(Feed* node)
96 {
97  setExpandable(false);
98  if (node)
99  {
100  setText(0, node->title());
101  if (!node->favicon().isNull())
102  setPixmap( 0, node->favicon() );
103  else
104  {
105  setPixmap( 0, defaultPixmap() );
106  node->loadFavicon();
107  }
108  }
109 }
110 
111 void FeedItem::showContextMenu(const TQPoint& p)
112 {
113  TQWidget* w = ActionManager::getInstance()->container("feeds_popup");
114  if (w)
115  static_cast<TQPopupMenu *>(w)->exec(p);
116 }
117 
118 } // namespace Akregator
119