akregator/src

feeditem.cpp

00001 /*
00002     This file is part of Akregator.
00003 
00004     Copyright (C) 2004 Frank Osterfeld <frank.osterfeld at kdemail.net>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include "actionmanager.h"
00026 #include "feed.h"
00027 #include "feeditem.h"
00028 
00029 #include <qpopupmenu.h>
00030 #include <kaction.h>
00031 #include <kdebug.h>
00032 #include <kiconloader.h>
00033 #include <qstring.h>
00034 
00035 namespace Akregator {
00036 
00037 FeedItem::FeedItem(FolderItem* parent, Feed* node) : TreeNodeItem(parent, node)
00038 {
00039     initialize(node);
00040 }
00041 
00042 FeedItem::FeedItem(KListView* parent, Feed* node) : TreeNodeItem(parent, node)
00043 {
00044     initialize(node);
00045 }
00046 
00047 FeedItem::FeedItem(KListView* parent, TreeNodeItem* after, Feed* node) : TreeNodeItem(parent, after, node)
00048 {
00049     initialize(node);
00050 }
00051 
00052 
00053 FeedItem::FeedItem(FolderItem* parent, TreeNodeItem* after, Feed* node) : TreeNodeItem(parent, after, node)
00054 {
00055     initialize(node);
00056 }
00057 
00058 FeedItem::~FeedItem()
00059 {
00060 }
00061 
00062 Feed* FeedItem::node() 
00063 { 
00064     return static_cast<Feed*> (m_node); 
00065 }
00066 
00067 void FeedItem::nodeChanged()
00068 {
00069     if ( node()->fetchErrorOccurred() )
00070         setPixmap(0, errorPixmap());
00071     else
00072     {
00073         if (!node()->favicon().isNull())
00074              setPixmap(0, node()->favicon());
00075         else
00076         {
00077             setPixmap( 0, defaultPixmap() );
00078             node()->loadFavicon();
00079         }
00080     }
00081     
00082     TreeNodeItem::nodeChanged();
00083 }
00084 
00085 QPixmap FeedItem::errorPixmap()
00086 {
00087     return KGlobal::iconLoader()->loadIcon("error", KIcon::Small);
00088 }
00089 
00090 QPixmap FeedItem::defaultPixmap()
00091 {
00092     return KGlobal::iconLoader()->loadIcon("txt", KIcon::Small);
00093 }
00094 
00095 void FeedItem::initialize(Feed* node)
00096 {
00097     setExpandable(false);
00098     if (node)
00099     {
00100         setText(0, node->title());
00101         if (!node->favicon().isNull())
00102             setPixmap( 0, node->favicon() );
00103         else
00104         {
00105             setPixmap( 0, defaultPixmap() );
00106             node->loadFavicon();
00107         }
00108     }
00109 }
00110 
00111 void FeedItem::showContextMenu(const QPoint& p)
00112 {
00113     QWidget* w = ActionManager::getInstance()->container("feeds_popup");
00114     if (w)
00115         static_cast<QPopupMenu *>(w)->exec(p);
00116 }
00117 
00118 } // namespace Akregator
00119 
KDE Home | KDE Accessibility Home | Description of Access Keys