2 Copyright (C) 2003 Tim Jansen <tim@tjansen.de>
3 Copyright (C) 2004 Nadeem Hasan <nhasan@kde.org>
5 /***************************************************************************
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 ***************************************************************************/
14 #include "hostpreferences.h"
15 #include "vnc/vnchostpref.h"
16 #include "rdp/rdphostpref.h"
18 #include <kapplication.h>
20 #include <kstaticdeleter.h>
26 HostPreferences
*HostPreferences::m_instance
= 0;
27 static KStaticDeleter
<HostPreferences
> sd
;
29 HostPreferences
*HostPreferences::instance()
31 if ( m_instance
== 0 )
32 sd
.setObject( m_instance
, new HostPreferences() );
37 HostPref::HostPref(KConfig
*conf
, const QString
&host
, const QString
&type
) :
43 HostPref::~HostPref() {
47 QString
HostPref::host() const {
51 QString
HostPref::type() const {
55 QString
HostPref::prefix() const {
56 return prefix(m_host
, m_type
);
59 QString
HostPref::prefix(const QString
&host
, const QString
&type
) {
60 return QString("PerHost-%1-%2-").arg(type
).arg(host
);
64 HostPreferences::HostPreferences() {
65 m_config
= KGlobal::config();
68 HostPreferences::~HostPreferences() {
69 if ( m_instance
== this )
70 sd
.setObject( m_instance
, 0, false );
73 HostPrefPtr
HostPreferences::getHostPref(const QString
&host
, const QString
&type
) {
74 m_config
->setGroup("PerHostSettings");
75 if (!m_config
->readEntry(HostPref::prefix(host
, type
)+"exists",false))
78 if (type
== VncHostPref::VncType
) {
79 HostPrefPtr hp
= new VncHostPref(m_config
, host
, type
);
83 else if(type
== RdpHostPref::RdpType
) {
84 HostPrefPtr hp
= new RdpHostPref(m_config
, host
, type
);
92 HostPrefPtr
HostPreferences::createHostPref(const QString
&host
, const QString
&type
) {
93 HostPrefPtr hp
= getHostPref(host
, type
);
97 if(type
== VncHostPref::VncType
)
99 hp
= new VncHostPref(m_config
, host
, type
);
101 else if(type
== RdpHostPref::RdpType
)
103 hp
= new RdpHostPref(m_config
, host
, type
);
109 HostPrefPtr
HostPreferences::vncDefaults()
111 HostPrefPtr hp
= new VncHostPref( m_config
);
117 HostPrefPtr
HostPreferences::rdpDefaults()
119 HostPrefPtr hp
= new RdpHostPref( m_config
);
125 HostPrefPtrList
HostPreferences::getAllHostPrefs() {
127 QMap
<QString
, QString
> map
= m_config
->entryMap("PerHostSettings");
128 QStringList keys
= map
.keys();
129 QStringList::iterator it
= keys
.begin();
130 while (it
!= keys
.end()) {
132 if (key
.endsWith("-exists")) {
133 QRegExp
re("PerHost-([^-]+)-(.*)-exists");
134 if (re
.exactMatch(key
)) {
135 HostPrefPtr hp
= getHostPref(re
.cap(2), re
.cap(1));
146 void HostPreferences::removeHostPref(HostPref
*hostPref
) {
150 void HostPreferences::setShowBrowsingPanel( bool b
)
152 m_config
->setGroup( QString::null
);
153 m_config
->writeEntry( "browsingPanel", b
);
156 void HostPreferences::setServerCompletions( const QStringList
&list
)
158 m_config
->setGroup( QString::null
);
159 m_config
->writeEntry( "serverCompletions", list
);
162 void HostPreferences::setServerHistory( const QStringList
&list
)
164 m_config
->setGroup( QString::null
);
165 m_config
->writeEntry( "serverHistory", list
);
168 bool HostPreferences::showBrowsingPanel()
170 m_config
->setGroup( QString::null
);
171 return m_config
->readEntry( "browsingPanel",false );
174 QStringList
HostPreferences::serverCompletions()
176 m_config
->setGroup( QString::null
);
177 return m_config
->readEntry( "serverCompletions", QStringList() );
180 QStringList
HostPreferences::serverHistory()
182 m_config
->setGroup( QString::null
);
183 return m_config
->readEntry( "serverHistory", QStringList() );
186 void HostPreferences::sync() {