9
from PyQt4.QtGui import (
21
from PyQt4.QtCore import Qt
23
from encuentro import platform
25
logger = logging.getLogger('encuentro.preferences')
28
"http://registro.educ.ar/cuentas/registro/index?servicio=conectate"
33
class GeneralPreferences(QWidget):
34
"""The general preferences input."""
35
def __init__(self, config_data):
36
super(GeneralPreferences, self).__init__()
37
grid = QGridLayout(self)
41
u"<b>Ingresá el directorio donde descargar los videos...</b>")
42
l.setTextFormat(Qt.RichText)
43
grid.addWidget(l, 0, 0, 1, 2)
45
grid.addWidget(QLabel(u"Descargar en:"), 1, 0, 2, 1)
46
prv = config_data.get('downloaddir', '')
47
self.downloaddir_entry = QLineEdit(prv)
48
grid.addWidget(self.downloaddir_entry, 1, 1, 2, 2)
49
# FIXME: the text entry is too separated of the "descarga en" subtitle,
50
# it should automatically use more of the width
52
self.autoreload_checkbox = QCheckBox(
53
u"Recargar automáticamente la lista de episodios al iniciar")
54
prv = config_data.get('autorefresh', False)
55
self.autoreload_checkbox.setChecked(prv)
56
grid.addWidget(self.autoreload_checkbox, 2, 0, 3, 2)
58
self.shownotifs_checkbox = QCheckBox(
59
u"Mostrar una notificación cuando termina cada descarga")
60
prv = config_data.get('notification', True)
61
self.shownotifs_checkbox.setChecked(prv)
62
grid.addWidget(self.shownotifs_checkbox, 3, 0, 4, 2)
65
"""Return the config for this tab."""
67
d['downloaddir'] = self.downloaddir_entry.text()
68
d['autorefresh'] = self.autoreload_checkbox.isChecked()
69
d['notification'] = self.shownotifs_checkbox.isChecked()
73
class ConectatePreferences(QWidget):
74
"""The preferences for Conectate backend."""
75
def __init__(self, config_data):
76
super(ConectatePreferences, self).__init__()
77
grid = QGridLayout(self)
80
l = QLabel(u"<b>Ingresá tus datos del portal Conectate:</b>")
81
l.setTextFormat(Qt.RichText)
82
grid.addWidget(l, 0, 0, 1, 2)
84
grid.addWidget(QLabel(u"Usuario:"), 1, 0, 2, 1)
85
prv = config_data.get('user', '')
86
self.user_entry = QLineEdit(prv)
87
grid.addWidget(self.user_entry, 1, 1, 2, 2)
88
# FIXME: the text entry is too separated of the "descarga en" subtitle,
89
# it should automatically use more of the width
91
grid.addWidget(QLabel(u"Contraseña:"), 2, 0, 3, 1)
92
prv = config_data.get('password', '')
93
self.password_entry = QLineEdit(prv)
94
grid.addWidget(self.password_entry, 2, 1, 3, 2)
95
# FIXME: the text entry is too separated of the "descarga en" subtitle,
96
# it should automatically use more of the width
98
l = QLabel(u'Si no tenés estos datos, <a href="%s">registrate aquí'
99
u'</a>' % (URL_CONECTATE,))
100
# FIXME: make this link to automaticall open the browser with it
101
l.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
102
l.setTextFormat(Qt.RichText)
103
l.setOpenExternalLinks(True)
104
grid.addWidget(l, 3, 0, 4, 3)
106
def get_config(self):
107
"""Return the config for this tab."""
109
d['user'] = self.user_entry.text()
110
d['password'] = self.password_entry.text()
114
class PreferencesDialog(QDialog):
115
"""The dialog for preferences."""
117
super(PreferencesDialog, self).__init__()
118
vbox = QVBoxLayout(self)
119
self._config_file = os.path.join(platform.config_dir, 'encuentro.conf')
120
if os.path.exists(self._config_file):
121
with open(self._config_file, 'rb') as fh:
122
self.config_data = pickle.load(fh)
124
self.config_data = {}
126
tabbed = QTabWidget()
127
self.gp = GeneralPreferences(self.config_data)
128
tabbed.addTab(self.gp, u"General")
129
self.cp = ConectatePreferences(self.config_data)
130
tabbed.addTab(self.cp, u"Conectate")
131
vbox.addWidget(tabbed)
133
bbox = QDialogButtonBox(QDialogButtonBox.Ok)
134
bbox.accepted.connect(self.accept)
137
def save_config(self):
138
"""Save all config."""
141
new_cfg.update(self.gp.get_config())
142
new_cfg.update(self.cp.get_config())
145
logger.info("Updating preferences config: %s", new_cfg)
146
with open(self._config_file, 'wb') as fh:
147
pickle.dump(new_cfg, fh)
150
if __name__ == '__main__':
152
project_basedir = os.path.abspath(os.path.dirname(os.path.dirname(
153
os.path.realpath(sys.argv[0]))))
154
sys.path.insert(0, project_basedir)
156
from PyQt4.QtGui import QApplication
157
app = QApplication(sys.argv)
159
frame = PreferencesDialog()