• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

krdc

  • sources
  • kde-4.12
  • kdenetwork
  • krdc
  • nx
nxhostpreferences.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2008 David Gross <gdavid.devel@gmail.com>
4 **
5 ** This file is part of KDE.
6 **
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.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
21 **
22 ****************************************************************************/
23 
24 #include "nxhostpreferences.h"
25 
26 #include "settings.h"
27 
28 #include <KDebug>
29 #include <kfiledialog.h>
30 
31 #include <QDesktopWidget>
32 #include <QFile>
33 #include <QByteArray>
34 #include <QTextEdit>
35 
36 static const QStringList keymaps = (QStringList()
37  << "ar"
38  << "cs"
39  << "da"
40  << "de"
41  << "de-ch"
42  << "en-dv"
43  << "en-gb"
44  << "en-us"
45  << "es"
46  << "et"
47  << "fi"
48  << "fo"
49  << "fr"
50  << "fr-be"
51  << "fr-ca"
52  << "fr-ch"
53  << "he"
54  << "hr"
55  << "hu"
56  << "is"
57  << "it"
58  << "ja"
59  << "ko"
60  << "lt"
61  << "lv"
62  << "mk"
63  << "nl"
64  << "nl-be"
65  << "no"
66  << "pl"
67  << "pt"
68  << "pt-br"
69  << "ru"
70  << "sl"
71  << "sv"
72  << "th"
73  << "tr"
74 );
75 
76 static const int defaultKeymap = 7; // en-us
77 
78 inline int keymap2int(const QString &keymap)
79 {
80  const int index = keymaps.lastIndexOf(keymap);
81  return (index == -1) ? defaultKeymap : index;
82 }
83 
84 inline QString int2keymap(int layout)
85 {
86  if (layout >= 0 && layout < keymaps.count())
87  return keymaps.at(layout);
88  else
89  return keymaps.at(defaultKeymap);
90 }
91 
92 static const QStringList desktopTypes = (QStringList()
93  << "unix-kde"
94  << "unix-gnome"
95  << "unix-cde"
96  << "unix-xdm"
97 );
98 
99 static const int defaultDesktopType = 0;
100 
101 inline int desktopType2int(const QString &desktopType)
102 {
103  const int index = desktopTypes.lastIndexOf(desktopType);
104  return (index == -1) ? defaultDesktopType : index;
105 }
106 
107 inline QString int2desktopType(int index)
108 {
109  if (index >= 0 && index < desktopTypes.count())
110  return desktopTypes.at(index);
111  else
112  return desktopTypes.at(defaultDesktopType);
113 }
114 
115 NxHostPreferences::NxHostPreferences(KConfigGroup configGroup, QObject *parent)
116  : HostPreferences(configGroup, parent)
117 {
118 }
119 
120 NxHostPreferences::~NxHostPreferences()
121 {
122 }
123 
124 QWidget* NxHostPreferences::createProtocolSpecificConfigPage()
125 {
126  nxPage = new QWidget();
127  nxUi.setupUi(nxPage);
128 
129  nxUi.kcfg_NxHeight->setValue(height());
130  nxUi.kcfg_NxWidth->setValue(width());
131  nxUi.kcfg_NxDesktopType->setCurrentIndex(desktopType2int(desktopType()));
132  nxUi.kcfg_NxKeyboardLayout->setCurrentIndex(keymap2int(keyboardLayout()));
133 
134  if (privateKey() == "default") {
135  nxUi.checkboxDefaultPrivateKey->setChecked(true);
136  nxUi.groupboxPrivateKey->setEnabled(false);
137  setDefaultPrivateKey(Qt::Checked);
138  } else {
139  nxUi.checkboxDefaultPrivateKey->setChecked(false);
140  nxUi.groupboxPrivateKey->setEnabled(true);
141  setDefaultPrivateKey(Qt::Unchecked);
142  }
143 
144  connect(nxUi.resolutionComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateWidthHeight(int)));
145  connect(nxUi.checkboxDefaultPrivateKey, SIGNAL(stateChanged(int)), SLOT(setDefaultPrivateKey(int)));
146  connect(nxUi.buttonImportPrivateKey, SIGNAL(pressed()), SLOT(chooseKeyFile()));
147  connect(nxUi.kcfg_NxPrivateKey, SIGNAL(textChanged()), SLOT(updatePrivateKey()));
148 
149  const QString resolutionString = QString::number(width()) + 'x' + QString::number(height());
150  const int resolutionIndex = nxUi.resolutionComboBox->findText(resolutionString, Qt::MatchContains);
151  nxUi.resolutionComboBox->setCurrentIndex((resolutionIndex == -1) ? 5 : resolutionIndex);
152 
153  return nxPage;
154 }
155 
156 void NxHostPreferences::updateWidthHeight(int index)
157 {
158  switch (index) {
159  case 0:
160  nxUi.kcfg_NxHeight->setValue(480);
161  nxUi.kcfg_NxWidth->setValue(640);
162  break;
163  case 1:
164  nxUi.kcfg_NxHeight->setValue(600);
165  nxUi.kcfg_NxWidth->setValue(800);
166  break;
167  case 2:
168  nxUi.kcfg_NxHeight->setValue(768);
169  nxUi.kcfg_NxWidth->setValue(1024);
170  break;
171  case 3:
172  nxUi.kcfg_NxHeight->setValue(1024);
173  nxUi.kcfg_NxWidth->setValue(1280);
174  break;
175  case 4:
176  nxUi.kcfg_NxHeight->setValue(1200);
177  nxUi.kcfg_NxWidth->setValue(1600);
178  break;
179  case 5: {
180  QDesktopWidget *desktop = QApplication::desktop();
181  int currentScreen = desktop->screenNumber(nxUi.kcfg_NxHeight);
182  nxUi.kcfg_NxHeight->setValue(desktop->screenGeometry(currentScreen).height());
183  nxUi.kcfg_NxWidth->setValue(desktop->screenGeometry(currentScreen).width());
184  break;
185  }
186  case 6:
187  default:
188  break;
189  }
190 
191  bool enabled = (index == 6) ? true : false;
192 
193  nxUi.kcfg_NxHeight->setEnabled(enabled);
194  nxUi.kcfg_NxWidth->setEnabled(enabled);
195  nxUi.heightLabel->setEnabled(enabled);
196  nxUi.widthLabel->setEnabled(enabled);
197 }
198 
199 void NxHostPreferences::setDefaultPrivateKey(int state)
200 {
201  if (state == Qt::Checked) {
202  setPrivateKey("default");
203  nxUi.groupboxPrivateKey->setEnabled(false);
204  } else if (state == Qt::Unchecked) {
205  setPrivateKey("");
206  nxUi.groupboxPrivateKey->setEnabled(true);
207  }
208 }
209 
210 void NxHostPreferences::updatePrivateKey()
211 {
212  m_privateKey = nxUi.kcfg_NxPrivateKey->toPlainText();
213 }
214 
215 void NxHostPreferences::chooseKeyFile()
216 {
217  const QString fileName = KFileDialog::getOpenFileName(KUrl(QDir::homePath()),
218  "*.key|" + i18n("Key Files (*.key)"),
219  nxPage, i18n("Open DSA Key File"));
220 
221  QFile file(fileName);
222  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
223  return;
224 
225  QByteArray key;
226  while (!file.atEnd())
227  key += file.readLine();
228 
229  nxUi.kcfg_NxPrivateKey->setPlainText(QString(key));
230  setPrivateKey(QString(key));
231 }
232 
233 void NxHostPreferences::acceptConfig()
234 {
235  HostPreferences::acceptConfig();
236 
237  setHeight(nxUi.kcfg_NxHeight->value());
238  setWidth(nxUi.kcfg_NxWidth->value());
239  setDesktopType(int2desktopType(nxUi.kcfg_NxDesktopType->currentIndex()));
240  setKeyboardLayout(int2keymap(nxUi.kcfg_NxKeyboardLayout->currentIndex()));
241 }
242 
243 void NxHostPreferences::setHeight(int height)
244 {
245  if (height >= 0)
246  m_configGroup.writeEntry("height", height);
247 }
248 
249 int NxHostPreferences::height()
250 {
251  return m_configGroup.readEntry("height", Settings::nxHeight());
252 }
253 
254 void NxHostPreferences::setWidth(int width)
255 {
256  if (width >= 0)
257  m_configGroup.writeEntry("width", width);
258 }
259 
260 int NxHostPreferences::width()
261 {
262  return m_configGroup.readEntry("width", Settings::nxWidth());
263 }
264 
265 void NxHostPreferences::setDesktopType(const QString &desktopType)
266 {
267  if (!desktopType.isNull())
268  m_configGroup.writeEntry("desktopType", desktopType2int(desktopType));
269 }
270 
271 QString NxHostPreferences::desktopType() const
272 {
273  return int2desktopType(m_configGroup.readEntry("desktopType", Settings::nxDesktopType()));
274 }
275 
276 void NxHostPreferences::setKeyboardLayout(const QString &keyboardLayout)
277 {
278  if (!keyboardLayout.isNull())
279  m_configGroup.writeEntry("keyboardLayout", keymap2int(keyboardLayout));
280 }
281 
282 QString NxHostPreferences::keyboardLayout() const
283 {
284  return int2keymap(m_configGroup.readEntry("keyboardLayout", Settings::nxKeyboardLayout()));
285 }
286 
287 void NxHostPreferences::setPrivateKey(const QString &privateKey)
288 {
289  if (!privateKey.isNull())
290  m_configGroup.writeEntry("privateKey", privateKey);
291 }
292 
293 QString NxHostPreferences::privateKey() const
294 {
295  return m_configGroup.readEntry("privateKey", Settings::nxPrivateKey());
296 }
297 
298 #include "nxhostpreferences.moc"
HostPreferences::m_configGroup
KConfigGroup m_configGroup
Definition: hostpreferences.h:101
Settings::nxPrivateKey
static QString nxPrivateKey()
Get NxPrivateKey.
Definition: settings.h:752
NxHostPreferences::setWidth
void setWidth(int width)
Definition: nxhostpreferences.cpp:254
Settings::nxKeyboardLayout
static int nxKeyboardLayout()
Get NxKeyboardLayout.
Definition: settings.h:733
QWidget
defaultKeymap
static const int defaultKeymap
Definition: nxhostpreferences.cpp:76
defaultDesktopType
static const int defaultDesktopType
Definition: nxhostpreferences.cpp:99
NxHostPreferences::privateKey
QString privateKey() const
Definition: nxhostpreferences.cpp:293
Settings::nxDesktopType
static int nxDesktopType()
Get NxDesktopType.
Definition: settings.h:714
QObject
NxHostPreferences::setKeyboardLayout
void setKeyboardLayout(const QString &keyboardLayout)
Definition: nxhostpreferences.cpp:276
NxHostPreferences::setHeight
void setHeight(int height)
Definition: nxhostpreferences.cpp:243
NxHostPreferences::keyboardLayout
QString keyboardLayout() const
Definition: nxhostpreferences.cpp:282
NxHostPreferences::width
int width()
Definition: nxhostpreferences.cpp:260
NxHostPreferences::~NxHostPreferences
~NxHostPreferences()
Definition: nxhostpreferences.cpp:120
int2keymap
QString int2keymap(int layout)
Definition: nxhostpreferences.cpp:84
NxHostPreferences::setDesktopType
void setDesktopType(const QString &desktopType)
Definition: nxhostpreferences.cpp:265
desktopTypes
static const QStringList desktopTypes
Definition: nxhostpreferences.cpp:92
NxHostPreferences::height
int height()
Definition: nxhostpreferences.cpp:249
Settings::nxHeight
static int nxHeight()
Get NxHeight.
Definition: settings.h:695
NxHostPreferences::desktopType
QString desktopType() const
Definition: nxhostpreferences.cpp:271
Settings::nxWidth
static int nxWidth()
Get NxWidth.
Definition: settings.h:676
HostPreferences
Definition: hostpreferences.h:42
settings.h
HostPreferences::acceptConfig
virtual void acceptConfig()
Called when the user validates the config dialog.
Definition: hostpreferences.cpp:56
keymaps
static const QStringList keymaps
Definition: nxhostpreferences.cpp:36
NxHostPreferences::acceptConfig
void acceptConfig()
Called when the user validates the config dialog.
Definition: nxhostpreferences.cpp:233
keymap2int
int keymap2int(const QString &keymap)
Definition: nxhostpreferences.cpp:78
desktopType2int
int desktopType2int(const QString &desktopType)
Definition: nxhostpreferences.cpp:101
int2desktopType
QString int2desktopType(int index)
Definition: nxhostpreferences.cpp:107
NxHostPreferences::createProtocolSpecificConfigPage
QWidget * createProtocolSpecificConfigPage()
Definition: nxhostpreferences.cpp:124
NxHostPreferences::NxHostPreferences
NxHostPreferences(KConfigGroup configGroup, QObject *parent=0)
Definition: nxhostpreferences.cpp:115
nxhostpreferences.h
NxHostPreferences::setPrivateKey
void setPrivateKey(const QString &privateKey)
Definition: nxhostpreferences.cpp:287
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krdc

Skip menu "krdc"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal