|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Network configuration page. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import QVariant, pyqtSlot |
|
13 from PyQt4.QtGui import QFileDialog |
|
14 |
|
15 from E4Gui.E4Completers import E4DirCompleter |
|
16 |
|
17 from ConfigurationPageBase import ConfigurationPageBase |
|
18 from Ui_NetworkPage import Ui_NetworkPage |
|
19 |
|
20 import Preferences |
|
21 import Utilities |
|
22 |
|
23 class NetworkPage(ConfigurationPageBase, Ui_NetworkPage): |
|
24 """ |
|
25 Class implementing the Network configuration page. |
|
26 """ |
|
27 def __init__(self): |
|
28 """ |
|
29 Constructor |
|
30 """ |
|
31 ConfigurationPageBase.__init__(self) |
|
32 self.setupUi(self) |
|
33 self.setObjectName("NetworkPage") |
|
34 |
|
35 self.downloadDirCompleter = E4DirCompleter(self.downloadDirEdit) |
|
36 |
|
37 self.proxyTypeCombo.addItem(self.trUtf8("Transparent HTTP"), QVariant(0)) |
|
38 self.proxyTypeCombo.addItem(self.trUtf8("Caching HTTP"), QVariant(1)) |
|
39 self.proxyTypeCombo.addItem(self.trUtf8("Socks5"), QVariant(2)) |
|
40 |
|
41 # set initial values |
|
42 self.downloadDirEdit.setText(Preferences.getUI("DownloadPath")) |
|
43 self.requestFilenameCheckBox.setChecked( |
|
44 Preferences.getUI("RequestDownloadFilename")) |
|
45 |
|
46 self.proxyGroup.setChecked(\ |
|
47 Preferences.getUI("UseProxy")) |
|
48 self.proxyTypeCombo.setCurrentIndex(self.proxyTypeCombo.findData(\ |
|
49 QVariant(Preferences.getUI("ProxyType")))) |
|
50 self.proxyHostEdit.setText(\ |
|
51 Preferences.getUI("ProxyHost")) |
|
52 self.proxyUserEdit.setText(\ |
|
53 Preferences.getUI("ProxyUser")) |
|
54 self.proxyPasswordEdit.setText(\ |
|
55 Preferences.getUI("ProxyPassword")) |
|
56 self.proxyPortSpin.setValue(\ |
|
57 Preferences.getUI("ProxyPort")) |
|
58 |
|
59 def save(self): |
|
60 """ |
|
61 Public slot to save the Application configuration. |
|
62 """ |
|
63 Preferences.setUI("DownloadPath", |
|
64 self.downloadDirEdit.text()) |
|
65 Preferences.setUI("RequestDownloadFilename", |
|
66 int(self.requestFilenameCheckBox.isChecked())) |
|
67 |
|
68 Preferences.setUI("UseProxy", |
|
69 int(self.proxyGroup.isChecked())) |
|
70 Preferences.setUI("ProxyType", |
|
71 self.proxyTypeCombo.itemData(self.proxyTypeCombo.currentIndex()).toInt()[0]) |
|
72 Preferences.setUI("ProxyHost", |
|
73 self.proxyHostEdit.text()) |
|
74 Preferences.setUI("ProxyUser", |
|
75 self.proxyUserEdit.text()) |
|
76 Preferences.setUI("ProxyPassword", |
|
77 self.proxyPasswordEdit.text()) |
|
78 Preferences.setUI("ProxyPort", |
|
79 self.proxyPortSpin.value()) |
|
80 |
|
81 @pyqtSlot() |
|
82 def on_downloadDirButton_clicked(self): |
|
83 """ |
|
84 Private slot to handle the directory selection via dialog. |
|
85 """ |
|
86 directory = QFileDialog.getExistingDirectory(\ |
|
87 self, |
|
88 self.trUtf8("Select download directory"), |
|
89 self.downloadDirEdit.text(), |
|
90 QFileDialog.Options(QFileDialog.ShowDirsOnly)) |
|
91 |
|
92 if directory: |
|
93 dn = Utilities.toNativeSeparators(directory) |
|
94 while dn.endswith(os.sep): |
|
95 dn = dn[:-1] |
|
96 self.downloadDirEdit.setText(dn) |
|
97 |
|
98 def create(dlg): |
|
99 """ |
|
100 Module function to create the configuration page. |
|
101 |
|
102 @param dlg reference to the configuration dialog |
|
103 """ |
|
104 page = NetworkPage() |
|
105 return page |