source: trunk/qt/session-dialog.cc @ 14393

Last change on this file since 14393 was 14393, checked in by mikedld, 8 years ago

Rework session dialog in Qt client to load from .ui

  • Property svn:keywords set to Date Rev Author Id
File size: 2.4 KB
Line 
1/*
2 * This file Copyright (C) 2009-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU Public License v2 or v3 licenses,
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: session-dialog.cc 14393 2014-12-21 23:46:31Z mikedld $
8 */
9
10#include "prefs.h"
11#include "session.h"
12#include "session-dialog.h"
13
14/***
15****
16***/
17
18void
19SessionDialog::onAccepted ()
20{
21  myPrefs.set (Prefs::SESSION_IS_REMOTE, ui.remoteSessionRadio->isChecked ());
22  myPrefs.set (Prefs::SESSION_REMOTE_HOST, ui.hostEdit->text ());
23  myPrefs.set (Prefs::SESSION_REMOTE_PORT, ui.portSpin->value ());
24  myPrefs.set (Prefs::SESSION_REMOTE_AUTH, ui.authCheck->isChecked ());
25  myPrefs.set (Prefs::SESSION_REMOTE_USERNAME, ui.usernameEdit->text ());
26  myPrefs.set (Prefs::SESSION_REMOTE_PASSWORD, ui.passwordEdit->text ());
27  mySession.restart ();
28  hide ();
29}
30
31void
32SessionDialog::resensitize ()
33{
34  const bool isRemote = ui.remoteSessionRadio->isChecked ();
35  const bool useAuth = ui.authCheck->isChecked ();
36
37  foreach (QWidget * w, myRemoteWidgets)
38    w->setEnabled (isRemote);
39
40  foreach (QWidget * w, myAuthWidgets)
41    w->setEnabled (isRemote && useAuth);
42}
43
44/***
45****
46***/
47
48SessionDialog::SessionDialog (Session& session, Prefs& prefs, QWidget * parent):
49  QDialog (parent),
50  mySession (session),
51  myPrefs (prefs)
52{
53  ui.setupUi (this);
54
55  ui.localSessionRadio->setChecked (!prefs.get<bool> (Prefs::SESSION_IS_REMOTE));
56  connect (ui.localSessionRadio, SIGNAL (toggled (bool)), this, SLOT (resensitize ()));
57
58  ui.remoteSessionRadio->setChecked (prefs.get<bool> (Prefs::SESSION_IS_REMOTE));
59  connect (ui.remoteSessionRadio, SIGNAL (toggled (bool)), this, SLOT (resensitize ()));
60
61  ui.hostEdit->setText (prefs.get<QString> (Prefs::SESSION_REMOTE_HOST));
62  myRemoteWidgets << ui.hostLabel << ui.hostEdit;
63
64  ui.portSpin->setValue (prefs.get<int> (Prefs::SESSION_REMOTE_PORT));
65  myRemoteWidgets << ui.portLabel << ui.portSpin;
66
67  ui.authCheck->setChecked (prefs.get<bool> (Prefs::SESSION_REMOTE_AUTH));
68  connect (ui.authCheck, SIGNAL (toggled (bool)), this, SLOT (resensitize ()));
69  myRemoteWidgets << ui.authCheck;
70
71  ui.usernameEdit->setText (prefs.get<QString> (Prefs::SESSION_REMOTE_USERNAME));
72  myAuthWidgets << ui.usernameLabel << ui.usernameEdit;
73
74  ui.passwordEdit->setText (prefs.get<QString> (Prefs::SESSION_REMOTE_PASSWORD));
75  myAuthWidgets << ui.passwordLabel << ui.passwordEdit;
76
77  resensitize ();
78
79  connect (ui.dialogButtons, SIGNAL (rejected ()), this, SLOT (hide ()));
80  connect (ui.dialogButtons, SIGNAL (accepted ()), this, SLOT (onAccepted ()));
81}
Note: See TracBrowser for help on using the repository browser.