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