~ubuntu-branches/ubuntu/maverick/transmission/maverick

« back to all changes in this revision

Viewing changes to qt/session-dialog.cc

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2009-05-22 21:57:30 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (2.1.18 sid) (1.3.8 upstream)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20090522215730-ly5kgv5aw9ig2u82
Tags: upstream-1.61
ImportĀ upstreamĀ versionĀ 1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
 
3
 *
 
4
 * This file is licensed by the GPL version 2.  Works owned by the
 
5
 * Transmission project are granted a special exemption to clause 2(b)
 
6
 * so that the bulk of its code can remain under the MIT license.
 
7
 * This exemption does not extend to derived works not owned by
 
8
 * the Transmission project.
 
9
 *
 
10
 * $Id:$
 
11
 */
 
12
 
 
13
#include <QCheckBox>
 
14
#include <QDialogButtonBox>
 
15
#include <QLabel>
 
16
#include <QLineEdit>
 
17
#include <QRadioButton>
 
18
#include <QSpinBox>
 
19
#include <QVBoxLayout>
 
20
 
 
21
#include "hig.h"
 
22
#include "prefs.h"
 
23
#include "session.h"
 
24
#include "session-dialog.h"
 
25
 
 
26
/***
 
27
****
 
28
***/
 
29
 
 
30
void
 
31
SessionDialog :: onAccepted( )
 
32
{
 
33
    myPrefs.set( Prefs::SESSION_IS_REMOTE, myRemoteRadioButton->isChecked( ) );
 
34
    myPrefs.set( Prefs::SESSION_REMOTE_HOST, myHostLineEdit->text( ) );
 
35
    myPrefs.set( Prefs::SESSION_REMOTE_PORT, myPortSpinBox->value( ) );
 
36
    myPrefs.set( Prefs::SESSION_REMOTE_AUTH, myAuthCheckBox->isChecked( ) );
 
37
    myPrefs.set( Prefs::SESSION_REMOTE_USERNAME, myUsernameLineEdit->text( ) );
 
38
    myPrefs.set( Prefs::SESSION_REMOTE_PASSWORD, myPasswordLineEdit->text( ) );
 
39
    mySession.restart( );
 
40
    hide( );
 
41
}
 
42
 
 
43
void
 
44
SessionDialog :: resensitize( )
 
45
{
 
46
    const bool isRemote = myRemoteRadioButton->isChecked();
 
47
    const bool useAuth = myAuthCheckBox->isChecked();
 
48
 
 
49
    foreach( QWidget * w, myRemoteWidgets )
 
50
        w->setEnabled( isRemote );
 
51
 
 
52
    foreach( QWidget * w, myAuthWidgets )
 
53
        w->setEnabled( isRemote && useAuth );
 
54
}
 
55
 
 
56
/***
 
57
****
 
58
***/
 
59
 
 
60
SessionDialog :: SessionDialog( Session& session, Prefs& prefs, QWidget * parent ):
 
61
    QDialog( parent ),
 
62
    mySession( session ),
 
63
    myPrefs( prefs )
 
64
{
 
65
    QWidget * l;
 
66
    QSpinBox * sb;
 
67
    QCheckBox * cb;
 
68
    QLineEdit * le;
 
69
    QRadioButton * rb;
 
70
 
 
71
    setWindowTitle( tr( "Change Session" ) );
 
72
    QVBoxLayout * top = new QVBoxLayout( this );
 
73
    top->setSpacing( HIG :: PAD );
 
74
 
 
75
    HIG * hig = new HIG;
 
76
    hig->setContentsMargins( 0, 0, 0, 0 );
 
77
    hig->addSectionTitle( tr( "Source" ) );
 
78
    rb = new QRadioButton( tr( "Start &Local Session" ) );
 
79
    rb->setChecked( !prefs.get<bool>(Prefs::SESSION_IS_REMOTE) );
 
80
    connect( rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
 
81
    hig->addWideControl( rb );
 
82
    rb = myRemoteRadioButton = new QRadioButton( tr( "Connect to &Remote Session" ) );
 
83
    rb->setChecked( prefs.get<bool>(Prefs::SESSION_IS_REMOTE) );
 
84
    connect( rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
 
85
    hig->addWideControl( rb );
 
86
    le = myHostLineEdit = new QLineEdit( );
 
87
    le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_HOST) );
 
88
    l = hig->addRow( tr( "&Host:" ), le );
 
89
    myRemoteWidgets << l << le;
 
90
    sb = myPortSpinBox = new QSpinBox;
 
91
    sb->setRange( 1, 65535 );
 
92
    sb->setValue( prefs.get<int>(Prefs::SESSION_REMOTE_PORT) );
 
93
    l = hig->addRow( tr( "&Port:" ), sb );
 
94
    myRemoteWidgets << l << sb;
 
95
    cb = myAuthCheckBox = new QCheckBox( tr( "&Authentication required" ) );
 
96
    cb->setChecked( prefs.get<bool>(Prefs::SESSION_REMOTE_AUTH) );
 
97
    connect( cb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
 
98
    myRemoteWidgets << cb;
 
99
    hig->addWideControl( cb );
 
100
    le = myUsernameLineEdit = new QLineEdit( );
 
101
    le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME) );
 
102
    l = hig->addRow( tr( "&Username:" ), le );
 
103
    myAuthWidgets << l << le;
 
104
    le = myPasswordLineEdit = new QLineEdit( );
 
105
    le->setEchoMode( QLineEdit::Password );
 
106
    le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD) );
 
107
    l = hig->addRow( tr( "Pass&word:" ), le );
 
108
    myAuthWidgets << l << le;
 
109
    hig->finish( );
 
110
    top->addWidget( hig, 1 );
 
111
    resensitize( );
 
112
 
 
113
    QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Ok );
 
114
    connect( buttons, SIGNAL(rejected()), this, SLOT(hide()));
 
115
    connect( buttons, SIGNAL(accepted()), this, SLOT(onAccepted()));
 
116
    top->addWidget( buttons, 0 );
 
117