akregator/src

treenode.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 "folder.h"
26 #include "treenode.h"
27 
28 #include <tqstring.h>
29 #include <tqvaluelist.h>
30 
31 #include <kdebug.h>
32 
33 namespace Akregator {
34 
35 class TreeNode::TreeNodePrivate
36 {
37  public:
38 
39  bool doNotify;
40  bool nodeChangeOccurred;
41  bool articleChangeOccurred;
42  TQString title;
43  Folder* parent;
44  uint id;
45  bool signalDestroyedEmitted;
46 };
47 
49  : TQObject(0, 0), d(new TreeNodePrivate)
50 {
51  d->doNotify = true;
52  d->nodeChangeOccurred = false;
53  d->articleChangeOccurred = false;
54  d->title = "";
55  d->parent = 0;
56  d->id = 0;
57  d->signalDestroyedEmitted = false;
58 
59 }
60 
61 void TreeNode::emitSignalDestroyed()
62 {
63  if (!d->signalDestroyedEmitted)
64  {
65  emit signalDestroyed(this);
66  d->signalDestroyedEmitted = true;
67  }
68 }
69 
71 {
72 
73  delete d;
74  d = 0;
75 }
76 
77 const TQString& TreeNode::title() const
78 {
79  return d->title;
80 }
81 
82 void TreeNode::setTitle(const TQString& title)
83 {
84 
85  if (d->title != title)
86  {
87  d->title = title;
88  nodeModified();
89  }
90 }
91 
93 {
94  if (!d->parent)
95  return 0;
96  TQValueList<TreeNode*> children = d->parent->children();
97  TreeNode* me = (TreeNode*)this;
98 
99  int idx = children.findIndex(me);
100 
101  return idx+1 < children.size() ? *(children.at(idx+1)) : 0L;
102 }
103 
105 {
106  if (!d->parent)
107  return 0;
108  TQValueList<TreeNode*> children = d->parent->children();
109  TreeNode* me = (TreeNode*)this;
110 
111  int idx = children.findIndex(me);
112  return idx > 0 ? *(d->parent->children().at(idx-1)) : 0L;
113 }
114 
116 {
117  return d->parent;
118 }
119 
121 {
122  d->parent = parent;
123 }
124 
125 void TreeNode::setNotificationMode(bool doNotify, bool notifyOccurredChanges)
126 {
127  if (doNotify && !d->doNotify) // turned on
128  {
129  d->doNotify = true;
130  if (d->nodeChangeOccurred && notifyOccurredChanges)
131  emit signalChanged(this);
132  if (d->articleChangeOccurred && notifyOccurredChanges)
134  d->nodeChangeOccurred = false;
135  d->articleChangeOccurred = false;
136  }
137  if (!doNotify && d->doNotify) //turned off
138  {
139  d->nodeChangeOccurred = false;
140  d->articleChangeOccurred = false;
141  d->doNotify = false;
142  }
143 }
144 
145 uint TreeNode::id() const
146 {
147  return d->id;
148 }
149 
150 void TreeNode::setId(uint id)
151 {
152  d->id = id;
153 }
154 
156 {
157  if (d->doNotify)
158  emit signalChanged(this);
159  else
160  d->nodeChangeOccurred = true;
161 }
162 
164 {
165  if (d->doNotify)
167  else
168  d->articleChangeOccurred = true;
169 }
170 
172 {
173 }
174 
175 } // namespace Akregator
176 
177 #include "treenode.moc"
Represents a folder (containing feeds and/or other folders)
Definition: folder.h:45
Abstract base class for all kind of elements in the feed tree, like feeds and feed groups (and search...
Definition: treenode.h:52
virtual TreeNode * nextSibling() const
Get the next sibling.
Definition: treenode.cpp:92
virtual uint id() const
returns the ID of this node.
Definition: treenode.cpp:145
virtual void setTitle(const TQString &title)
Sets the title of the node.
Definition: treenode.cpp:82
virtual TreeNode * prevSibling() const
Get the previous sibling.
Definition: treenode.cpp:104
virtual void setNotificationMode(bool doNotify, bool notifyOccurredChanges=true)
Definition: treenode.cpp:125
TreeNode()
Standard constructor.
Definition: treenode.cpp:48
virtual void doArticleNotification()
reimplement this in subclasses to do the actual notification called by articlesModified
Definition: treenode.cpp:171
virtual void articlesModified()
call this if the articles in the node were changed.
Definition: treenode.cpp:163
void signalChanged(TreeNode *)
Notification mechanism: emitted, when the node was modified and notification is enabled.
virtual ~TreeNode()
Standard destructor.
Definition: treenode.cpp:70
virtual void setId(uint id)
sets the ID
Definition: treenode.cpp:150
virtual const TQString & title() const
Get title of node.
Definition: treenode.cpp:77
virtual void setParent(Folder *parent)
Sets parent node; Don't call this directly, is done automatically by insertChild-methods in Folder.
Definition: treenode.cpp:120
virtual void nodeModified()
call this if you modified the actual node (title, unread count).
Definition: treenode.cpp:155
virtual Folder * parent() const
Returns the parent node.
Definition: treenode.cpp:115
void signalDestroyed(TreeNode *)
Emitted when this object is deleted.