summaryrefslogtreecommitdiffstats
path: root/krdc/vnc/vnchostpref.cpp
blob: 3fedb308304bae276d9a7fe27c043214fc87bd3a (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
/***************************************************************************
                      vnchostprefs.cpp  -  vnc host preferences
                             -------------------
    begin                : Fri May 09 22:32 CET 2003
    copyright            : (C) 2003 by Tim Jansen
    email                : tim@tjansen.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "vnchostpref.h"
#include <tdeconfig.h>
#include <tdelocale.h>

const TQString VncHostPref::VncType = "VNC";

VncHostPref::VncHostPref(TDEConfig *conf, const TQString &host, const TQString &type) :
	HostPref(conf, host, type),
	m_quality(0),
	m_askOnConnect(true),
	m_useTDEWallet(true) {
}

VncHostPref::~VncHostPref() {
}

void VncHostPref::save() {
	if ( !m_host.isEmpty() && !m_type.isEmpty() )
	{
		m_config->setGroup("PerHostSettings");
		TQString p = prefix();
		m_config->writeEntry(p+"exists", true);
		m_config->writeEntry(p+"quality", m_quality);
		m_config->writeEntry(p+"askOnConnect", m_askOnConnect);
		m_config->writeEntry(p+"useTDEWallet", m_useTDEWallet);
	}
	else
	{
		m_config->setGroup( "VncDefaultSettings" );
		m_config->writeEntry( "vncQuality", m_quality );
		m_config->writeEntry( "vncShowHostPreferences", m_askOnConnect );
		m_config->writeEntry( "vncUseTDEWallet", m_useTDEWallet );
	}
}

void VncHostPref::load() {
	if ( !m_host.isEmpty() && !m_type.isEmpty() )
	{
		m_config->setGroup("PerHostSettings");
		TQString p = prefix();
		m_quality = m_config->readNumEntry(p+"quality", 0);
		m_askOnConnect = m_config->readBoolEntry(p+"askOnConnect", true);
		m_useTDEWallet = m_config->readBoolEntry(p+"useTDEWallet", true);
	}
	else
	{
		setDefaults();
	}
}

void VncHostPref::remove() {
	m_config->setGroup("PerHostSettings");
	TQString p = prefix();
	m_config->deleteEntry(p+"exists");
	m_config->deleteEntry(p+"quality");
	m_config->deleteEntry(p+"askOnConnect");
}

void VncHostPref::setDefaults() {
	m_config->setGroup("VncDefaultSettings");
	m_quality = m_config->readNumEntry("vncQuality", 0);
	m_askOnConnect = m_config->readBoolEntry("vncShowHostPreferences", true);
	m_useTDEWallet = m_config->readBoolEntry("vncUseTDEWallet", true);
}

TQString VncHostPref::prefDescription() const {
	TQString q;
	switch(m_quality) {
	case 0:
		q = i18n("High");
		break;
	case 1:
		q = i18n("Medium");
		break;
	case 2:
		q = i18n("Low");
		break;
	default:
		Q_ASSERT(true);
	}
	return i18n("Show Preferences: %1, Quality: %2, TDEWallet: %3")
	  .arg(m_askOnConnect ? i18n("yes") : i18n("no")).arg(q).arg(m_useTDEWallet ? i18n("yes") : i18n("no"));
}

void VncHostPref::setQuality(int q) {
	m_quality = q;
	save();
}

int VncHostPref::quality() const {
	return m_quality;
}

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

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

void VncHostPref::setUseTDEWallet(bool use) {
	m_useTDEWallet = use;
	save();
}

bool VncHostPref::useTDEWallet() const {
	return m_useTDEWallet;
}