forked from abnd90/py-cloudapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preferences.py
executable file
·76 lines (65 loc) · 3.36 KB
/
preferences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
#Copyright (C)2010 Abhinandh <[email protected]>
#This Program in licensed under General Public License Ver 3
from preferencesui import Ui_Properties
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class PreferencesDialog(QDialog, Ui_Properties):
settings = {}
def __init__(self, parent=None):
super(PreferencesDialog, self).__init__(parent)
self.setupUi(self)
self.signals = self.Signals()
self.okButton.clicked.connect(self.saveSettings)
self.obj = QSettings()
self.retriveSettings()
QCoreApplication.setOrganizationName("Abhinandh")
QCoreApplication.setOrganizationDomain("abhinandh.com")
QCoreApplication.setApplicationName("Cloud App")
def showEvent(self, event):
try:
self.usernameLine.setText(self.settings['username'])
self.passwordLine.setText(self.settings['password'])
self.rememberCheckBox.setChecked(self.settings['remember_pass'])
self.fileListItems.setValue(self.settings['list_size'])
self.clipboardCheckBox.setChecked(self.settings['auto_clipboard'])
self.notificationCheckBox.setChecked(self.settings['notifications'])
self.voffsetSlider.setMaximum(qApp.desktop().height())
self.voffsetSlider.setValue(self.settings['drop_topoffset'])
except KeyError:
pass
def saveSettings(self):
self.loadSettings()
password = self.settings['password']
remember = self.settings['remember_pass']
self.obj.setValue('username',self.settings['username'])
if remember:
self.obj.setValue('password',password)
elif self.obj.contains('password'):
self.obj.remove('password')
self.obj.setValue('remember_pass',remember)
self.obj.setValue('list_size', self.settings['list_size'])
self.obj.setValue('auto_clipboard', self.settings['auto_clipboard'])
self.obj.setValue('notifications', self.settings['notifications'])
self.obj.setValue('drop_topoffset', self.settings['drop_topoffset'])
self.signals.settingsChanged.emit()
def loadSettings(self):
"""load settings from the preferences dialog"""
self.settings['username'] = str(self.usernameLine.text())
self.settings['password'] = str(self.passwordLine.text())
self.settings['remember_pass'] = self.rememberCheckBox.isChecked()
self.settings['list_size'] = self.fileListItems.value()
self.settings['auto_clipboard'] = self.clipboardCheckBox.isChecked()
self.settings['notifications'] = self.notificationCheckBox.isChecked()
self.settings['drop_topoffset'] = self.voffsetSlider.value()
def retriveSettings(self):
"""Retrive the saved settings"""
self.settings['username'] = self.obj.value('username')
self.settings['password'] = self.obj.value('password')
self.settings['remember_pass'] = bool(self.obj.value('remember_pass'))
self.settings['list_size'] = int(self.obj.value('list_size'))
self.settings['auto_clipboard'] = bool(self.obj.value('auto_clipboard'))
self.settings['notifications'] = bool(self.obj.value('notifications'))
self.settings['drop_topoffset'] = int(self.obj.value('drop_topoffset'))
class Signals(QObject):
settingsChanged = pyqtSignal()