Messagelib

messagecore/src/helpers/nodehelper.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
3  SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]>
4  SPDX-FileCopyrightText: 2010 Leo Franchi <[email protected]>
5 
6  SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 
9 #include "nodehelper.h"
10 
11 #include <KMime/Content>
12 #include <KMime/KMimeMessage>
13 
15 {
16  if (!node) {
17  return nullptr;
18  }
19 
20  KMime::Content *next = nullptr;
21  KMime::Content *parent = node->parent();
22  if (parent) {
23  const auto contents = parent->contents();
24  const int index = contents.indexOf(const_cast<KMime::Content *>(node)) + 1;
25  if (index < contents.size()) { // next on the same level
26  next = contents.at(index);
27  }
28  }
29 
30  return next;
31 }
32 
34 {
35  if (allowChildren) {
36  if (KMime::Content *child = firstChild(node)) {
37  return child;
38  }
39  }
40 
41  if (KMime::Content *sibling = nextSibling(node)) {
42  return sibling;
43  }
44 
45  for (KMime::Content *parent = node->parent(); parent; parent = parent->parent()) {
46  if (KMime::Content *sibling = nextSibling(parent)) {
47  return sibling;
48  }
49  }
50 
51  return nullptr;
52 }
53 
55 {
56  if (!node) {
57  return nullptr;
58  }
59 
60  KMime::Content *child = nullptr;
61  if (!node->contents().isEmpty()) {
62  child = node->contents().at(0);
63  }
64 
65  return child;
66 }
MESSAGECORE_EXPORT KMime::Content * next(KMime::Content *node, bool allowChildren=true)
Returns the next node (child, sibling or parent) of the given node.
QVector< Content * > contents() const
MESSAGECORE_EXPORT KMime::Content * firstChild(const KMime::Content *node)
Returns the first child node of the given node.
Content * parent() const
MESSAGECORE_EXPORT KMime::Content * nextSibling(const KMime::Content *node)
Returns the next sibling node of the given node.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:12:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.