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