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