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