|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to manage the list of hosts not to be cached. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, Qt |
|
11 from PyQt4.QtGui import QDialog, QStringListModel, QSortFilterProxyModel, \ |
|
12 QInputDialog, QLineEdit |
|
13 |
|
14 from .Ui_NoCacheHostsDialog import Ui_NoCacheHostsDialog |
|
15 |
|
16 import Preferences |
|
17 |
|
18 |
|
19 class NoCacheHostsDialog(QDialog, Ui_NoCacheHostsDialog): |
|
20 """ |
|
21 Class implementing a dialog to manage the list of hosts not to be cached. |
|
22 """ |
|
23 def __init__(self, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param parent reference to the parent widget (QWidget) |
|
28 """ |
|
29 super().__init__(parent) |
|
30 self.setupUi(self) |
|
31 |
|
32 self.__model = QStringListModel(Preferences.getHelp("NoCacheHosts"), self) |
|
33 self.__model.sort(0) |
|
34 self.__proxyModel = QSortFilterProxyModel(self) |
|
35 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive) |
|
36 self.__proxyModel.setSourceModel(self.__model) |
|
37 self.noCacheList.setModel(self.__proxyModel) |
|
38 |
|
39 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString) |
|
40 |
|
41 self.removeButton.clicked[()].connect(self.noCacheList.removeSelected) |
|
42 self.removeAllButton.clicked[()].connect(self.noCacheList.removeAll) |
|
43 |
|
44 @pyqtSlot() |
|
45 def on_addButton_clicked(self): |
|
46 """ |
|
47 Private slot to add an entry to the list. |
|
48 """ |
|
49 host, ok = QInputDialog.getText( |
|
50 self, |
|
51 self.trUtf8("Not Cached Hosts"), |
|
52 self.trUtf8("Enter host name to add to the list:"), |
|
53 QLineEdit.Normal) |
|
54 if ok and host != "" and host not in self.__model.stringList(): |
|
55 self.__model.insertRow(self.__model.rowCount()) |
|
56 self.__model.setData( |
|
57 self.__model.index(self.__model.rowCount() - 1), host) |
|
58 self.__model.sort(0) |
|
59 |
|
60 def accept(self): |
|
61 """ |
|
62 Public method to accept the dialog data. |
|
63 """ |
|
64 Preferences.setHelp("NoCacheHosts", self.__model.stringList()) |
|
65 |
|
66 super().accept() |