50
47
class GeneralPreferences(QWidget):
51
48
"""The general preferences input."""
52
def __init__(self, config_data):
53
50
super(GeneralPreferences, self).__init__()
54
51
grid = QGridLayout(self)
55
52
grid.setSpacing(20)
53
grid.setColumnStretch(1, 10)
58
56
u"<b>Ingresá el directorio donde descargar los videos...</b>")
60
58
grid.addWidget(l, 0, 0, 1, 2)
62
60
grid.addWidget(QLabel(u"Descargar en:"), 1, 0, 2, 1)
63
prv = config_data.get('downloaddir', '')
61
prv = config.get('downloaddir', '')
64
62
self.downloaddir_entry = QLineEdit(prv)
65
63
grid.addWidget(self.downloaddir_entry, 1, 1, 2, 2)
66
# FIXME: the text entry is too separated of the "descarga en" subtitle,
67
# it should automatically use more of the width
69
65
self.autoreload_checkbox = QCheckBox(
70
66
u"Recargar automáticamente la lista de episodios al iniciar")
71
prv = config_data.get('autorefresh', False)
67
prv = config.get('autorefresh', False)
72
68
self.autoreload_checkbox.setChecked(prv)
73
69
grid.addWidget(self.autoreload_checkbox, 2, 0, 3, 2)
75
71
self.shownotifs_checkbox = QCheckBox(
76
72
u"Mostrar una notificación cuando termina cada descarga")
77
prv = config_data.get('notification', True)
73
prv = config.get('notification', True)
78
74
self.shownotifs_checkbox.setChecked(prv)
79
75
grid.addWidget(self.shownotifs_checkbox, 3, 0, 4, 2)
90
86
class ConectatePreferences(QWidget):
91
87
"""The preferences for Conectate backend."""
92
def __init__(self, config_data):
93
89
super(ConectatePreferences, self).__init__()
94
90
grid = QGridLayout(self)
95
91
grid.setSpacing(20)
92
grid.setColumnStretch(1, 10)
97
94
l = QLabel(u"<b>Ingresá tus datos del portal Conectate:</b>")
98
95
l.setTextFormat(Qt.RichText)
99
96
grid.addWidget(l, 0, 0, 1, 2)
101
98
grid.addWidget(QLabel(u"Usuario:"), 1, 0, 2, 1)
102
prv = config_data.get('user', '')
99
prv = config.get('user', '')
103
100
self.user_entry = QLineEdit(prv)
104
101
grid.addWidget(self.user_entry, 1, 1, 2, 2)
105
# FIXME: the text entry is too separated of the "descarga en" subtitle,
106
# it should automatically use more of the width
108
103
grid.addWidget(QLabel(u"Contraseña:"), 2, 0, 3, 1)
109
prv = config_data.get('password', '')
104
prv = config.get('password', '')
110
105
self.password_entry = QLineEdit(prv)
111
106
grid.addWidget(self.password_entry, 2, 1, 3, 2)
112
# FIXME: the text entry is too separated of the "descarga en" subtitle,
113
# it should automatically use more of the width
115
108
l = QLabel(u'Si no tenés estos datos, <a href="%s">registrate aquí'
116
109
u'</a>' % (URL_CONECTATE,))
117
# FIXME: make this link to automaticall open the browser with it
118
110
l.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
119
111
l.setTextFormat(Qt.RichText)
120
112
l.setOpenExternalLinks(True)
133
125
def __init__(self):
134
126
super(PreferencesDialog, self).__init__()
135
127
vbox = QVBoxLayout(self)
136
self._config_file = os.path.join(platform.config_dir, 'encuentro.conf')
137
if os.path.exists(self._config_file):
138
with open(self._config_file, 'rb') as fh:
139
self.config_data = pickle.load(fh)
141
self.config_data = {}
143
129
tabbed = QTabWidget()
144
self.gp = GeneralPreferences(self.config_data)
130
self.gp = GeneralPreferences()
145
131
tabbed.addTab(self.gp, u"General")
146
self.cp = ConectatePreferences(self.config_data)
132
self.cp = ConectatePreferences()
147
133
tabbed.addTab(self.cp, u"Conectate")
148
134
vbox.addWidget(tabbed)
150
136
bbox = QDialogButtonBox(QDialogButtonBox.Ok)
151
137
bbox.accepted.connect(self.accept)
138
bbox.accepted.connect(self._save)
152
139
vbox.addWidget(bbox)
154
def save_config(self):
155
"""Save all config."""
141
def closeEvent(self, event):
142
"""Save and close."""
144
super(PreferencesDialog, self).closeEvent(event)
156
148
# get it from tabs
158
new_cfg.update(self.gp.get_config())
159
new_cfg.update(self.cp.get_config())
162
logger.info("Updating preferences config: %s", new_cfg)
163
with open(self._config_file, 'wb') as fh:
164
pickle.dump(new_cfg, fh)
149
config.update(self.gp.get_config())
150
config.update(self.cp.get_config())
167
154
if __name__ == '__main__':