summaryrefslogtreecommitdiffstats
path: root/krdc/rdp/rdphostpref.cpp
blob: a818640364e16900a6bbec331670ac51dc0ae9b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
     rdphostpref.cpp, handles preferences for RDP hosts
     Copyright (C) 2003 Arend van Beelen jr.

     This program is free software; you can redistribute it and/or modify it under the terms of the
     GNU General Public License as published by the Free Software Foundation; either version 2 of
     the License, or (at your option) any later version.

     This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
     without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
     the GNU General Public License for more details.

     You should have received a copy of the GNU General Public License along with this program; if
     not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
     MA 02111-1307 USA

     For any questions, comments or whatever, you may mail me at: arend@auton.nl
*/

#include "rdphostpref.h"
#include <kconfig.h>
#include <klocale.h>

const QString RdpHostPref::RdpType = "RDP";

RdpHostPref::RdpHostPref(KConfig *conf, const QString &host, const QString &type) :
	HostPref(conf, host, type),
	m_width(0),
	m_height(0),
	m_colorDepth(24),
	m_layout("en-us"),
	m_askOnConnect(true),
	m_useKWallet(true)
{
}

RdpHostPref::~RdpHostPref()
{
}

void RdpHostPref::save()
{
	if ( !m_host.isEmpty() && !m_type.isEmpty() )
	{
		m_config->setGroup("PerHostSettings");
		QString p = prefix();
		m_config->writeEntry(p+"exists", true);
		m_config->writeEntry(p+"width", m_width);
		m_config->writeEntry(p+"height", m_height);
		m_config->writeEntry(p+"colorDepth", m_colorDepth);
		m_config->writeEntry(p+"layout", m_layout);
		m_config->writeEntry(p+"askOnConnect", m_askOnConnect);
		m_config->writeEntry(p+"useKWallet", m_useKWallet);
	}
	else
	{
		m_config->setGroup( "RdpDefaultSettings" );
		m_config->writeEntry( "rdpWidth", m_width );
		m_config->writeEntry( "rdpHeight", m_height );
		m_config->writeEntry( "rdpColorDepth", m_colorDepth);
		m_config->writeEntry( "rdpKeyboardLayout", m_layout );
		m_config->writeEntry( "rdpShowHostPreferences", m_askOnConnect );
		m_config->writeEntry( "rdpUseKWallet", m_useKWallet );
	}
}

void RdpHostPref::load()
{
	if ( !m_host.isEmpty() && !m_type.isEmpty() )
	{
		m_config->setGroup("PerHostSettings");
		QString p = prefix();
		m_width = m_config->readNumEntry(p+"width", 0);
		m_height = m_config->readNumEntry(p+"height", 0);
		m_colorDepth = m_config->readNumEntry(p+"colorDepth", 24);
		m_layout = m_config->readEntry(p+"layout", "en-us");
		m_askOnConnect = m_config->readBoolEntry(p+"askOnConnect", true);
		m_useKWallet = m_config->readBoolEntry(p+"useKWallet", true);
	}
	else
	{
		setDefaults();
	}
}

void RdpHostPref::remove()
{
	m_config->setGroup("PerHostSettings");
	QString p = prefix();
	m_config->deleteEntry(p+"exists");
	m_config->deleteEntry(p+"width");
	m_config->deleteEntry(p+"height");
	m_config->deleteEntry(p+"colorDepth");
	m_config->deleteEntry(p+"layout");
	m_config->deleteEntry(p+"askOnConnect");
	m_config->deleteEntry(p+"useKWallet");
}

void RdpHostPref::setDefaults()
{
	m_config->setGroup("RdpDefaultSettings");
	m_width = m_config->readNumEntry("rdpWidth", 0);
	m_height = m_config->readNumEntry("rdpHeight", 0);
	m_colorDepth = m_config->readNumEntry("rdpColorDepth", 24);
	m_layout = m_config->readEntry("rdpKeyboardLayout", "en-us");
	m_askOnConnect = m_config->readBoolEntry("rdpShowHostPreferences", true);
	m_useKWallet = m_config->readBoolEntry("rdpUseKWallet", true);
}

QString RdpHostPref::prefDescription() const
{
	return i18n("Show Preferences: %1, Resolution: %2x%3, Color Depth: %4, Keymap: %5, KWallet: %6")
	  .arg(m_askOnConnect ? i18n("yes") : i18n("no")).arg(m_width).arg(m_height)
	  .arg(m_colorDepth).arg(m_layout).arg(m_useKWallet ? i18n("yes") : i18n("no"));
}

void RdpHostPref::setWidth(int w)
{
	m_width = w;
	save();
}

int RdpHostPref::width() const
{
	return m_width;
}

void RdpHostPref::setHeight(int h)
{
	m_height = h;
	save();
}

int RdpHostPref::height() const
{
	return m_height;
}

void RdpHostPref::setColorDepth(int d)
{
	m_colorDepth = d;
	save();
}

int RdpHostPref::colorDepth() const
{
	return m_colorDepth;
}


void RdpHostPref::setLayout(const QString &l)
{
	m_layout = l;
	save();
}

QString RdpHostPref::layout() const
{
	return m_layout;
}

void RdpHostPref::setAskOnConnect(bool ask)
{
	m_askOnConnect = ask;
	save();
}

bool RdpHostPref::askOnConnect() const
{
	return m_askOnConnect;
}

void RdpHostPref::setUseKWallet(bool use) {
	m_useKWallet = use;
	save();
}

bool RdpHostPref::useKWallet() const {
	return m_useKWallet;
}