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

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

Strip spaces around :: in C++ code (Qt client)

  • Property svn:keywords set to Date Rev Author Id
File size: 3.5 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 14377 2014-12-12 23:05:10Z mikedld $
8 */
9
10#include <QCheckBox>
11#include <QDialogButtonBox>
12#include <QLabel>
13#include <QLineEdit>
14#include <QRadioButton>
15#include <QSpinBox>
16#include <QVBoxLayout>
17
18#include "hig.h"
19#include "prefs.h"
20#include "session.h"
21#include "session-dialog.h"
22
23/***
24****
25***/
26
27void
28SessionDialog::onAccepted ()
29{
30  myPrefs.set (Prefs::SESSION_IS_REMOTE, myRemoteRadioButton->isChecked ());
31  myPrefs.set (Prefs::SESSION_REMOTE_HOST, myHostLineEdit->text ());
32  myPrefs.set (Prefs::SESSION_REMOTE_PORT, myPortSpinBox->value ());
33  myPrefs.set (Prefs::SESSION_REMOTE_AUTH, myAuthCheckBox->isChecked ());
34  myPrefs.set (Prefs::SESSION_REMOTE_USERNAME, myUsernameLineEdit->text ());
35  myPrefs.set (Prefs::SESSION_REMOTE_PASSWORD, myPasswordLineEdit->text ());
36  mySession.restart ();
37  hide ();
38}
39
40void
41SessionDialog::resensitize ()
42{
43  const bool isRemote = myRemoteRadioButton->isChecked();
44  const bool useAuth = myAuthCheckBox->isChecked();
45
46  foreach (QWidget * w, myRemoteWidgets)
47    w->setEnabled (isRemote);
48
49  foreach (QWidget * w, myAuthWidgets)
50    w->setEnabled (isRemote && useAuth);
51}
52
53/***
54****
55***/
56
57SessionDialog::SessionDialog (Session& session, Prefs& prefs, QWidget * parent):
58  QDialog (parent),
59  mySession (session),
60  myPrefs (prefs)
61{
62  QWidget * l;
63  QSpinBox * sb;
64  QCheckBox * cb;
65  QLineEdit * le;
66  QRadioButton * rb;
67
68  setWindowTitle (tr ("Change Session"));
69  QVBoxLayout * top = new QVBoxLayout (this);
70  top->setSpacing (HIG::PAD);
71
72  HIG * hig = new HIG;
73  hig->setContentsMargins (0, 0, 0, 0);
74  hig->addSectionTitle (tr ("Source"));
75  rb = new QRadioButton (tr ("Start &Local Session"));
76  rb->setChecked (!prefs.get<bool>(Prefs::SESSION_IS_REMOTE));
77  connect (rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
78  hig->addWideControl (rb);
79  rb = myRemoteRadioButton = new QRadioButton (tr ("Connect to &Remote Session"));
80  rb->setChecked (prefs.get<bool>(Prefs::SESSION_IS_REMOTE));
81  connect (rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
82  hig->addWideControl (rb);
83  le = myHostLineEdit = new QLineEdit ();
84  le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_HOST));
85  l = hig->addRow (tr ("&Host:"), le);
86  myRemoteWidgets << l << le;
87  sb = myPortSpinBox = new QSpinBox;
88  sb->setRange (1, 65535);
89  sb->setValue (prefs.get<int>(Prefs::SESSION_REMOTE_PORT));
90  l = hig->addRow (tr ("&Port:"), sb);
91  myRemoteWidgets << l << sb;
92  cb = myAuthCheckBox = new QCheckBox (tr ("&Authentication required"));
93  cb->setChecked (prefs.get<bool>(Prefs::SESSION_REMOTE_AUTH));
94  connect (cb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
95  myRemoteWidgets << cb;
96  hig->addWideControl (cb);
97  le = myUsernameLineEdit = new QLineEdit ();
98  le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME));
99  l = hig->addRow (tr ("&Username:"), le);
100  myAuthWidgets << l << le;
101  le = myPasswordLineEdit = new QLineEdit ();
102  le->setEchoMode (QLineEdit::Password);
103  le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD));
104  l = hig->addRow (tr ("Pass&word:"), le);
105  myAuthWidgets << l << le;
106  hig->finish ();
107  top->addWidget (hig, 1);
108  resensitize ();
109
110  QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
111  connect (buttons, SIGNAL(rejected()), this, SLOT(hide()));
112  connect (buttons, SIGNAL(accepted()), this, SLOT(onAccepted()));
113  top->addWidget (buttons, 0);
114}
Note: See TracBrowser for help on using the repository browser.