|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the bookmark node. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import QDateTime |
|
11 |
|
12 |
|
13 class BookmarkNode: |
|
14 """ |
|
15 Class implementing the bookmark node type. |
|
16 """ |
|
17 # possible bookmark node types |
|
18 Root = 0 |
|
19 Folder = 1 |
|
20 Bookmark = 2 |
|
21 Separator = 3 |
|
22 |
|
23 # possible timestamp types |
|
24 TsAdded = 0 |
|
25 TsModified = 1 |
|
26 TsVisited = 2 |
|
27 |
|
28 def __init__(self, type_=Root, parent=None): |
|
29 """ |
|
30 Constructor |
|
31 |
|
32 @param type_ type of the bookmark node (BookmarkNode.Type) |
|
33 @param parent reference to the parent node (BookmarkNode) |
|
34 """ |
|
35 self.url = "" |
|
36 self.title = "" |
|
37 self.desc = "" |
|
38 self.expanded = False |
|
39 self.added = QDateTime() |
|
40 self.modified = QDateTime() |
|
41 self.visited = QDateTime() |
|
42 self.visitCount = 0 |
|
43 |
|
44 self._children = [] |
|
45 self._parent = parent |
|
46 self._type = type_ |
|
47 |
|
48 if parent is not None: |
|
49 parent.add(self) |
|
50 |
|
51 def type(self): |
|
52 """ |
|
53 Public method to get the bookmark's type. |
|
54 |
|
55 @return bookmark type (BookmarkNode.Type) |
|
56 """ |
|
57 return self._type |
|
58 |
|
59 def setType(self, type_): |
|
60 """ |
|
61 Public method to set the bookmark's type. |
|
62 |
|
63 @param type_ type of the bookmark node (BookmarkNode.Type) |
|
64 """ |
|
65 self._type = type_ |
|
66 |
|
67 def children(self): |
|
68 """ |
|
69 Public method to get the list of child nodes. |
|
70 |
|
71 @return list of all child nodes (list of BookmarkNode) |
|
72 """ |
|
73 return self._children[:] |
|
74 |
|
75 def parent(self): |
|
76 """ |
|
77 Public method to get a reference to the parent node. |
|
78 |
|
79 @return reference to the parent node (BookmarkNode) |
|
80 """ |
|
81 return self._parent |
|
82 |
|
83 def add(self, child, offset=-1): |
|
84 """ |
|
85 Public method to add/insert a child node. |
|
86 |
|
87 @param child reference to the node to add (BookmarkNode) |
|
88 @param offset position where to insert child (integer, -1 = append) |
|
89 """ |
|
90 if child._type == BookmarkNode.Root: |
|
91 return |
|
92 |
|
93 if child._parent is not None: |
|
94 child._parent.remove(child) |
|
95 |
|
96 child._parent = self |
|
97 if offset == -1: |
|
98 self._children.append(child) |
|
99 else: |
|
100 self._children.insert(offset, child) |
|
101 |
|
102 def remove(self, child): |
|
103 """ |
|
104 Public method to remove a child node. |
|
105 |
|
106 @param child reference to the child node (BookmarkNode) |
|
107 """ |
|
108 child._parent = None |
|
109 if child in self._children: |
|
110 self._children.remove(child) |