akregator/src

treenode.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 "folder.h"
00026 #include "treenode.h"
00027 
00028 #include <qstring.h>
00029 #include <qvaluelist.h>
00030 
00031 #include <kdebug.h>
00032 
00033 namespace Akregator {
00034 
00035 class TreeNode::TreeNodePrivate
00036 {
00037     public:
00038     
00039     bool doNotify;
00040     bool nodeChangeOccurred;
00041     bool articleChangeOccurred;
00042     QString title;
00043     Folder* parent;
00044     uint id;
00045     bool signalDestroyedEmitted;
00046 };
00047 
00048 TreeNode::TreeNode()
00049     : QObject(0, 0), d(new TreeNodePrivate)
00050 {
00051     d->doNotify = true;
00052     d->nodeChangeOccurred = false;
00053     d->articleChangeOccurred = false;
00054     d->title = "";
00055     d->parent = 0;
00056     d->id = 0;
00057     d->signalDestroyedEmitted = false;
00058     
00059 }
00060 
00061 void TreeNode::emitSignalDestroyed()
00062 {
00063     if (!d->signalDestroyedEmitted)
00064     {
00065         emit signalDestroyed(this);
00066         d->signalDestroyedEmitted = true;
00067     } 
00068 }
00069 
00070 TreeNode::~TreeNode()
00071 {
00072 
00073     delete d;
00074     d = 0;
00075 }
00076 
00077 const QString& TreeNode::title() const
00078 {
00079     return d->title;
00080 }
00081 
00082 void TreeNode::setTitle(const QString& title)
00083 {
00084 
00085     if (d->title != title)
00086     {
00087         d->title = title;
00088         nodeModified();
00089     }
00090 }
00091 
00092 TreeNode* TreeNode::nextSibling() const
00093 {
00094     if (!d->parent)
00095         return 0;
00096     QValueList<TreeNode*> children = d->parent->children();
00097     TreeNode* me = (TreeNode*)this;
00098         
00099     int idx = children.findIndex(me);
00100     
00101     return idx+1 < children.size() ? *(children.at(idx+1)) : 0L;
00102 }
00103 
00104 TreeNode* TreeNode::prevSibling() const
00105 {
00106     if (!d->parent)
00107         return 0;
00108     QValueList<TreeNode*> children = d->parent->children();
00109     TreeNode* me = (TreeNode*)this;
00110     
00111     int idx = children.findIndex(me);
00112     return idx > 0 ? *(d->parent->children().at(idx-1)) : 0L;
00113 }
00114 
00115 Folder* TreeNode::parent() const
00116 {
00117     return d->parent;
00118 }
00119 
00120 void TreeNode::setParent(Folder* parent)
00121 {
00122     d->parent = parent;
00123 }
00124 
00125 void TreeNode::setNotificationMode(bool doNotify, bool notifyOccurredChanges)
00126 {
00127     if (doNotify && !d->doNotify) // turned on
00128     {
00129         d->doNotify = true;
00130         if (d->nodeChangeOccurred && notifyOccurredChanges)
00131             emit signalChanged(this);
00132         if (d->articleChangeOccurred && notifyOccurredChanges)
00133             doArticleNotification();
00134         d->nodeChangeOccurred = false;
00135         d->articleChangeOccurred = false;
00136     }
00137     if (!doNotify && d->doNotify) //turned off
00138     {
00139         d->nodeChangeOccurred = false;
00140         d->articleChangeOccurred = false;
00141         d->doNotify = false;
00142     }
00143 }
00144 
00145 uint TreeNode::id() const
00146 {
00147     return d->id;
00148 }
00149 
00150 void TreeNode::setId(uint id)
00151 {
00152     d->id = id;
00153 }
00154 
00155 void TreeNode::nodeModified()
00156 {
00157     if (d->doNotify)
00158         emit signalChanged(this);
00159     else
00160         d->nodeChangeOccurred = true;
00161 }
00162 
00163 void TreeNode::articlesModified()
00164 {
00165     if (d->doNotify)
00166         doArticleNotification();
00167     else
00168         d->articleChangeOccurred = true;
00169 }
00170 
00171 void TreeNode::doArticleNotification()
00172 {
00173 }
00174 
00175 } // namespace Akregator
00176 
00177 #include "treenode.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys