61 |
61 |
62 def __init__(self, parent=None): |
62 def __init__(self, parent=None): |
63 """ |
63 """ |
64 Constructor |
64 Constructor |
65 |
65 |
66 @param parent reference to the parent object (QObject) |
66 @param parent reference to the parent object |
|
67 @type QObject |
67 """ |
68 """ |
68 super().__init__(parent) |
69 super().__init__(parent) |
69 |
70 |
70 self.__saveTimer = AutoSaver(self, self.save) |
71 self.__saveTimer = AutoSaver(self, self.save) |
71 self.entryAdded.connect(self.__saveTimer.changeOccurred) |
72 self.entryAdded.connect(self.__saveTimer.changeOccurred) |
227 |
230 |
228 def addBookmark(self, parent, node, row=-1): |
231 def addBookmark(self, parent, node, row=-1): |
229 """ |
232 """ |
230 Public method to add a bookmark. |
233 Public method to add a bookmark. |
231 |
234 |
232 @param parent reference to the node to add to (BookmarkNode) |
235 @param parent reference to the node to add to |
233 @param node reference to the node to add (BookmarkNode) |
236 @type BookmarkNode |
234 @param row row number (integer) |
237 @param node reference to the node to add |
|
238 @type BookmarkNode |
|
239 @param row row number |
|
240 @type int |
235 """ |
241 """ |
236 if not self.__loaded: |
242 if not self.__loaded: |
237 return |
243 return |
238 |
244 |
239 self.setTimestamp(node, BookmarkNode.TsAdded, QDateTime.currentDateTime()) |
245 self.setTimestamp(node, BookmarkNode.TsAdded, QDateTime.currentDateTime()) |
257 |
264 |
258 def setTitle(self, node, newTitle): |
265 def setTitle(self, node, newTitle): |
259 """ |
266 """ |
260 Public method to set the title of a bookmark. |
267 Public method to set the title of a bookmark. |
261 |
268 |
262 @param node reference to the node to be changed (BookmarkNode) |
269 @param node reference to the node to be changed |
263 @param newTitle title to be set (string) |
270 @type BookmarkNode |
|
271 @param newTitle title to be set |
|
272 @type str |
264 """ |
273 """ |
265 if not self.__loaded: |
274 if not self.__loaded: |
266 return |
275 return |
267 |
276 |
268 command = ChangeBookmarkCommand(self, node, newTitle, True) |
277 command = ChangeBookmarkCommand(self, node, newTitle, True) |
270 |
279 |
271 def setUrl(self, node, newUrl): |
280 def setUrl(self, node, newUrl): |
272 """ |
281 """ |
273 Public method to set the URL of a bookmark. |
282 Public method to set the URL of a bookmark. |
274 |
283 |
275 @param node reference to the node to be changed (BookmarkNode) |
284 @param node reference to the node to be changed |
276 @param newUrl URL to be set (string) |
285 @type BookmarkNode |
|
286 @param newUrl URL to be set |
|
287 @type str |
277 """ |
288 """ |
278 if not self.__loaded: |
289 if not self.__loaded: |
279 return |
290 return |
280 |
291 |
281 command = ChangeBookmarkCommand(self, node, newUrl, False) |
292 command = ChangeBookmarkCommand(self, node, newUrl, False) |
290 |
301 |
291 def setTimestamp(self, node, timestampType, timestamp): |
302 def setTimestamp(self, node, timestampType, timestamp): |
292 """ |
303 """ |
293 Public method to set the URL of a bookmark. |
304 Public method to set the URL of a bookmark. |
294 |
305 |
295 @param node reference to the node to be changed (BookmarkNode) |
306 @param node reference to the node to be changed |
|
307 @type BookmarkNode |
296 @param timestampType type of the timestamp to set |
308 @param timestampType type of the timestamp to set |
297 (BookmarkNode.TsAdded, BookmarkNode.TsModified, |
309 (BookmarkNode.TsAdded, BookmarkNode.TsModified, |
298 BookmarkNode.TsVisited) |
310 BookmarkNode.TsVisited) |
299 @param timestamp timestamp to set (QDateTime) |
311 @type int |
|
312 @param timestamp timestamp to set |
|
313 @type QDateTime |
300 """ |
314 """ |
301 if not self.__loaded: |
315 if not self.__loaded: |
302 return |
316 return |
303 |
317 |
304 if timestampType == BookmarkNode.TsAdded: |
318 if timestampType == BookmarkNode.TsAdded: |
324 |
339 |
325 def setVisitCount(self, node, count): |
340 def setVisitCount(self, node, count): |
326 """ |
341 """ |
327 Public method to set the visit count of a bookmark. |
342 Public method to set the visit count of a bookmark. |
328 |
343 |
329 @param node reference to the node to be changed (BookmarkNode) |
344 @param node reference to the node to be changed |
330 @param count visit count to be set (int or str) |
345 @type BookmarkNode |
|
346 @param count visit count to be set |
|
347 @type int or str |
331 """ |
348 """ |
332 with contextlib.suppress(ValueError): |
349 with contextlib.suppress(ValueError): |
333 node.visitCount = int(count) |
350 node.visitCount = int(count) |
334 self.__saveTimer.changeOccurred() |
351 self.__saveTimer.changeOccurred() |
335 |
352 |
336 def bookmarks(self): |
353 def bookmarks(self): |
337 """ |
354 """ |
338 Public method to get a reference to the root bookmark node. |
355 Public method to get a reference to the root bookmark node. |
339 |
356 |
340 @return reference to the root bookmark node (BookmarkNode) |
357 @return reference to the root bookmark node |
|
358 @rtype BookmarkNode |
341 """ |
359 """ |
342 if not self.__loaded: |
360 if not self.__loaded: |
343 self.load() |
361 self.load() |
344 |
362 |
345 return self.__bookmarkRootNode |
363 return self.__bookmarkRootNode |
346 |
364 |
347 def menu(self): |
365 def menu(self): |
348 """ |
366 """ |
349 Public method to get a reference to the bookmarks menu node. |
367 Public method to get a reference to the bookmarks menu node. |
350 |
368 |
351 @return reference to the bookmarks menu node (BookmarkNode) |
369 @return reference to the bookmarks menu node |
|
370 @rtype BookmarkNode |
352 """ |
371 """ |
353 if not self.__loaded: |
372 if not self.__loaded: |
354 self.load() |
373 self.load() |
355 |
374 |
356 return self.__menu |
375 return self.__menu |
357 |
376 |
358 def toolbar(self): |
377 def toolbar(self): |
359 """ |
378 """ |
360 Public method to get a reference to the bookmarks toolbar node. |
379 Public method to get a reference to the bookmarks toolbar node. |
361 |
380 |
362 @return reference to the bookmarks toolbar node (BookmarkNode) |
381 @return reference to the bookmarks toolbar node |
|
382 @rtype BookmarkNode |
363 """ |
383 """ |
364 if not self.__loaded: |
384 if not self.__loaded: |
365 self.load() |
385 self.load() |
366 |
386 |
367 return self.__toolbar |
387 return self.__toolbar |
368 |
388 |
369 def bookmarksModel(self): |
389 def bookmarksModel(self): |
370 """ |
390 """ |
371 Public method to get a reference to the bookmarks model. |
391 Public method to get a reference to the bookmarks model. |
372 |
392 |
373 @return reference to the bookmarks model (BookmarksModel) |
393 @return reference to the bookmarks model |
|
394 @rtype BookmarksModel |
374 """ |
395 """ |
375 from .BookmarksModel import BookmarksModel |
396 from .BookmarksModel import BookmarksModel |
376 |
397 |
377 if self.__bookmarksModel is None: |
398 if self.__bookmarksModel is None: |
378 self.__bookmarksModel = BookmarksModel(self, self) |
399 self.__bookmarksModel = BookmarksModel(self, self) |
430 |
451 |
431 def faviconChanged(self, url): |
452 def faviconChanged(self, url): |
432 """ |
453 """ |
433 Public slot to update the icon image for an URL. |
454 Public slot to update the icon image for an URL. |
434 |
455 |
435 @param url URL of the icon to update (QUrl or string) |
456 @param url URL of the icon to update |
|
457 @type QUrl or str |
436 """ |
458 """ |
437 if isinstance(url, QUrl): |
459 if isinstance(url, QUrl): |
438 url = url.toString() |
460 url = url.toString() |
439 nodes = self.bookmarksForUrl(url) |
461 nodes = self.bookmarksForUrl(url) |
440 for node in nodes: |
462 for node in nodes: |
442 |
464 |
443 def bookmarkForUrl(self, url, start=StartRoot): |
465 def bookmarkForUrl(self, url, start=StartRoot): |
444 """ |
466 """ |
445 Public method to get a bookmark node for a given URL. |
467 Public method to get a bookmark node for a given URL. |
446 |
468 |
447 @param url URL of the bookmark to search for (QUrl or string) |
469 @param url URL of the bookmark to search for |
|
470 @type QUrl or str |
448 @param start indicator for the start of the search |
471 @param start indicator for the start of the search |
449 (StartRoot, StartMenu, StartToolBar) |
472 (StartRoot, StartMenu, StartToolBar) |
450 @return bookmark node for the given url (BookmarkNode) |
473 @type int |
|
474 @return bookmark node for the given url |
|
475 @rtype BookmarkNode |
451 """ |
476 """ |
452 if start == StartMenu: |
477 if start == StartMenu: |
453 startNode = self.__menu |
478 startNode = self.__menu |
454 elif start == StartToolBar: |
479 elif start == StartToolBar: |
455 startNode = self.__toolbar |
480 startNode = self.__toolbar |
465 |
490 |
466 def __searchBookmark(self, url, startNode): |
491 def __searchBookmark(self, url, startNode): |
467 """ |
492 """ |
468 Private method get a bookmark node for a given URL. |
493 Private method get a bookmark node for a given URL. |
469 |
494 |
470 @param url URL of the bookmark to search for (string) |
495 @param url URL of the bookmark to search for |
|
496 @type str |
471 @param startNode reference to the node to start searching |
497 @param startNode reference to the node to start searching |
472 (BookmarkNode) |
498 @type BookmarkNode |
473 @return bookmark node for the given url (BookmarkNode) |
499 @return bookmark node for the given url |
|
500 @rtype BookmarkNode |
474 """ |
501 """ |
475 bm = None |
502 bm = None |
476 for node in startNode.children(): |
503 for node in startNode.children(): |
477 if node.type() == BookmarkNode.Folder: |
504 if node.type() == BookmarkNode.Folder: |
478 bm = self.__searchBookmark(url, node) |
505 bm = self.__searchBookmark(url, node) |
484 |
511 |
485 def bookmarksForUrl(self, url, start=StartRoot): |
512 def bookmarksForUrl(self, url, start=StartRoot): |
486 """ |
513 """ |
487 Public method to get a list of bookmark nodes for a given URL. |
514 Public method to get a list of bookmark nodes for a given URL. |
488 |
515 |
489 @param url URL of the bookmarks to search for (QUrl or string) |
516 @param url URL of the bookmarks to search for |
|
517 @type QUrl or str |
490 @param start indicator for the start of the search |
518 @param start indicator for the start of the search |
491 (StartRoot, StartMenu, StartToolBar) |
519 (StartRoot, StartMenu, StartToolBar) |
492 @return list of bookmark nodes for the given url (list of BookmarkNode) |
520 @type int |
|
521 @return list of bookmark nodes for the given url |
|
522 @rtype list of BookmarkNode |
493 """ |
523 """ |
494 if start == StartMenu: |
524 if start == StartMenu: |
495 startNode = self.__menu |
525 startNode = self.__menu |
496 elif start == StartToolBar: |
526 elif start == StartToolBar: |
497 startNode = self.__toolbar |
527 startNode = self.__toolbar |
507 |
537 |
508 def __searchBookmarks(self, url, startNode): |
538 def __searchBookmarks(self, url, startNode): |
509 """ |
539 """ |
510 Private method get a list of bookmark nodes for a given URL. |
540 Private method get a list of bookmark nodes for a given URL. |
511 |
541 |
512 @param url URL of the bookmarks to search for (string) |
542 @param url URL of the bookmarks to search for |
|
543 @type str |
513 @param startNode reference to the node to start searching |
544 @param startNode reference to the node to start searching |
514 (BookmarkNode) |
545 @type BookmarkNode |
515 @return list of bookmark nodes for the given url (list of BookmarkNode) |
546 @return list of bookmark nodes for the given url |
|
547 @rtype list of BookmarkNode |
516 """ |
548 """ |
517 bm = [] |
549 bm = [] |
518 for node in startNode.children(): |
550 for node in startNode.children(): |
519 if node.type() == BookmarkNode.Folder: |
551 if node.type() == BookmarkNode.Folder: |
520 bm.extend(self.__searchBookmarks(url, node)) |
552 bm.extend(self.__searchBookmarks(url, node)) |
531 def __init__(self, bookmarksManager, parent, row): |
563 def __init__(self, bookmarksManager, parent, row): |
532 """ |
564 """ |
533 Constructor |
565 Constructor |
534 |
566 |
535 @param bookmarksManager reference to the bookmarks manager |
567 @param bookmarksManager reference to the bookmarks manager |
536 (BookmarksManager) |
568 @type BookmarksManager |
537 @param parent reference to the parent node (BookmarkNode) |
569 @param parent reference to the parent node |
538 @param row row number of bookmark (integer) |
570 @type BookmarkNode |
|
571 @param row row number of bookmark |
|
572 @type int |
539 """ |
573 """ |
540 super().__init__( |
574 super().__init__( |
541 QCoreApplication.translate("BookmarksManager", "Remove Bookmark") |
575 QCoreApplication.translate("BookmarksManager", "Remove Bookmark") |
542 ) |
576 ) |
543 |
577 |
572 def __init__(self, bookmarksManager, parent, node, row): |
606 def __init__(self, bookmarksManager, parent, node, row): |
573 """ |
607 """ |
574 Constructor |
608 Constructor |
575 |
609 |
576 @param bookmarksManager reference to the bookmarks manager |
610 @param bookmarksManager reference to the bookmarks manager |
577 (BookmarksManager) |
611 @type BookmarksManager |
578 @param parent reference to the parent node (BookmarkNode) |
612 @param parent reference to the parent node |
579 @param node reference to the node to be inserted (BookmarkNode) |
613 @type BookmarkNode |
580 @param row row number of bookmark (integer) |
614 @param node reference to the node to be inserted |
|
615 @type BookmarkNode |
|
616 @param row row number of bookmark |
|
617 @type int |
581 """ |
618 """ |
582 RemoveBookmarksCommand.__init__(self, bookmarksManager, parent, row) |
619 RemoveBookmarksCommand.__init__(self, bookmarksManager, parent, row) |
583 self.setText(QCoreApplication.translate("BookmarksManager", "Insert Bookmark")) |
620 self.setText(QCoreApplication.translate("BookmarksManager", "Insert Bookmark")) |
584 self._node = node |
621 self._node = node |
585 |
622 |
604 def __init__(self, bookmarksManager, node, newValue, title): |
641 def __init__(self, bookmarksManager, node, newValue, title): |
605 """ |
642 """ |
606 Constructor |
643 Constructor |
607 |
644 |
608 @param bookmarksManager reference to the bookmarks manager |
645 @param bookmarksManager reference to the bookmarks manager |
609 (BookmarksManager) |
646 @type BookmarksManager |
610 @param node reference to the node to be changed (BookmarkNode) |
647 @param node reference to the node to be changed |
611 @param newValue new value to be set (string) |
648 @type BookmarkNode |
|
649 @param newValue new value to be set |
|
650 @type str |
612 @param title flag indicating a change of the title (True) or |
651 @param title flag indicating a change of the title (True) or |
613 the URL (False) (boolean) |
652 the URL (False) |
|
653 @type bool |
614 """ |
654 """ |
615 super().__init__() |
655 super().__init__() |
616 |
656 |
617 self._bookmarksManager = bookmarksManager |
657 self._bookmarksManager = bookmarksManager |
618 self._title = title |
658 self._title = title |