Preferences/ConfigurationPages/NetworkPage.py

changeset 0
de9c2efb9d02
child 7
c679fb30c8f3
diff -r 000000000000 -r de9c2efb9d02 Preferences/ConfigurationPages/NetworkPage.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Preferences/ConfigurationPages/NetworkPage.py	Mon Dec 28 16:03:33 2009 +0000
@@ -0,0 +1,105 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the Network configuration page.
+"""
+
+import os
+
+from PyQt4.QtCore import QVariant, pyqtSlot
+from PyQt4.QtGui import QFileDialog
+
+from E4Gui.E4Completers import E4DirCompleter
+
+from ConfigurationPageBase import ConfigurationPageBase
+from Ui_NetworkPage import Ui_NetworkPage
+
+import Preferences
+import Utilities
+
+class NetworkPage(ConfigurationPageBase, Ui_NetworkPage):
+    """
+    Class implementing the Network configuration page.
+    """
+    def __init__(self):
+        """
+        Constructor
+        """
+        ConfigurationPageBase.__init__(self)
+        self.setupUi(self)
+        self.setObjectName("NetworkPage")
+        
+        self.downloadDirCompleter = E4DirCompleter(self.downloadDirEdit)
+        
+        self.proxyTypeCombo.addItem(self.trUtf8("Transparent HTTP"), QVariant(0))
+        self.proxyTypeCombo.addItem(self.trUtf8("Caching HTTP"), QVariant(1))
+        self.proxyTypeCombo.addItem(self.trUtf8("Socks5"), QVariant(2))
+        
+        # set initial values
+        self.downloadDirEdit.setText(Preferences.getUI("DownloadPath"))
+        self.requestFilenameCheckBox.setChecked(
+            Preferences.getUI("RequestDownloadFilename"))
+        
+        self.proxyGroup.setChecked(\
+            Preferences.getUI("UseProxy"))
+        self.proxyTypeCombo.setCurrentIndex(self.proxyTypeCombo.findData(\
+            QVariant(Preferences.getUI("ProxyType"))))
+        self.proxyHostEdit.setText(\
+            Preferences.getUI("ProxyHost"))
+        self.proxyUserEdit.setText(\
+            Preferences.getUI("ProxyUser"))
+        self.proxyPasswordEdit.setText(\
+            Preferences.getUI("ProxyPassword"))
+        self.proxyPortSpin.setValue(\
+            Preferences.getUI("ProxyPort"))
+        
+    def save(self):
+        """
+        Public slot to save the Application configuration.
+        """
+        Preferences.setUI("DownloadPath", 
+            self.downloadDirEdit.text())
+        Preferences.setUI("RequestDownloadFilename", 
+            int(self.requestFilenameCheckBox.isChecked()))
+        
+        Preferences.setUI("UseProxy",
+            int(self.proxyGroup.isChecked()))
+        Preferences.setUI("ProxyType", 
+            self.proxyTypeCombo.itemData(self.proxyTypeCombo.currentIndex()).toInt()[0])
+        Preferences.setUI("ProxyHost",
+            self.proxyHostEdit.text())
+        Preferences.setUI("ProxyUser",
+            self.proxyUserEdit.text())
+        Preferences.setUI("ProxyPassword",
+            self.proxyPasswordEdit.text())
+        Preferences.setUI("ProxyPort",
+            self.proxyPortSpin.value())
+    
+    @pyqtSlot()
+    def on_downloadDirButton_clicked(self):
+        """
+        Private slot to handle the directory selection via dialog.
+        """
+        directory = QFileDialog.getExistingDirectory(\
+            self,
+            self.trUtf8("Select download directory"),
+            self.downloadDirEdit.text(),
+            QFileDialog.Options(QFileDialog.ShowDirsOnly))
+            
+        if directory:
+            dn = Utilities.toNativeSeparators(directory)
+            while dn.endswith(os.sep):
+                dn = dn[:-1]
+            self.downloadDirEdit.setText(dn)
+    
+def create(dlg):
+    """
+    Module function to create the configuration page.
+    
+    @param dlg reference to the configuration dialog
+    """
+    page = NetworkPage()
+    return page

eric ide

mercurial