|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to select the action to be performed on the |
|
8 bookmark. |
|
9 """ |
|
10 |
|
11 from __future__ import unicode_literals |
|
12 |
|
13 from PyQt5.QtCore import pyqtSlot |
|
14 from PyQt5.QtWidgets import QDialog |
|
15 |
|
16 from .Ui_BookmarkActionSelectionDialog import Ui_BookmarkActionSelectionDialog |
|
17 |
|
18 import UI.PixmapCache |
|
19 |
|
20 |
|
21 class BookmarkActionSelectionDialog(QDialog, Ui_BookmarkActionSelectionDialog): |
|
22 """ |
|
23 Class implementing a dialog to select the action to be performed on |
|
24 the bookmark. |
|
25 """ |
|
26 Undefined = -1 |
|
27 AddBookmark = 0 |
|
28 EditBookmark = 1 |
|
29 AddSpeeddial = 2 |
|
30 RemoveSpeeddial = 3 |
|
31 |
|
32 def __init__(self, url, parent=None): |
|
33 """ |
|
34 Constructor |
|
35 |
|
36 @param url URL to be worked on (QUrl) |
|
37 @param parent reference to the parent widget (QWidget) |
|
38 """ |
|
39 super(BookmarkActionSelectionDialog, self).__init__(parent) |
|
40 self.setupUi(self) |
|
41 |
|
42 self.__action = self.Undefined |
|
43 |
|
44 self.icon.setPixmap(UI.PixmapCache.getPixmap("bookmark32.png")) |
|
45 |
|
46 import WebBrowser.WebBrowserWindow |
|
47 |
|
48 if WebBrowser.WebBrowserWindow.WebBrowserWindow.bookmarksManager()\ |
|
49 .bookmarkForUrl(url) is None: |
|
50 self.__bmAction = self.AddBookmark |
|
51 self.bookmarkPushButton.setText(self.tr("Add Bookmark")) |
|
52 else: |
|
53 self.__bmAction = self.EditBookmark |
|
54 self.bookmarkPushButton.setText(self.tr("Edit Bookmark")) |
|
55 |
|
56 # TODO: SpeedDial |
|
57 self.speeddialPushButton.setText("Future Speed Dial Entry") |
|
58 ## if WebBrowser.WebBrowserWindow.WebBrowserWindow.speedDial().pageForUrl(url).url: |
|
59 ## self.__sdAction = self.RemoveSpeeddial |
|
60 ## self.speeddialPushButton.setText( |
|
61 ## self.tr("Remove from Speed Dial")) |
|
62 ## else: |
|
63 ## self.__sdAction = self.AddSpeeddial |
|
64 ## self.speeddialPushButton.setText(self.tr("Add to Speed Dial")) |
|
65 |
|
66 msh = self.minimumSizeHint() |
|
67 self.resize(max(self.width(), msh.width()), msh.height()) |
|
68 |
|
69 @pyqtSlot() |
|
70 def on_bookmarkPushButton_clicked(self): |
|
71 """ |
|
72 Private slot handling selection of a bookmark action. |
|
73 """ |
|
74 self.__action = self.__bmAction |
|
75 self.accept() |
|
76 |
|
77 @pyqtSlot() |
|
78 def on_speeddialPushButton_clicked(self): |
|
79 """ |
|
80 Private slot handling selection of a speed dial action. |
|
81 """ |
|
82 self.__action = self.__sdAction |
|
83 self.accept() |
|
84 |
|
85 def getAction(self): |
|
86 """ |
|
87 Public method to get the selected action. |
|
88 |
|
89 @return reference to the associated action |
|
90 """ |
|
91 return self.__action |