• 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
  • core
hostpreferences.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2007 - 2010 Urs Wolfer <uwolfer @ kde.org>
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 "hostpreferences.h"
25 
26 #include "settings.h"
27 
28 #include <KDebug>
29 #include <KLocale>
30 #include <KStandardDirs>
31 #include <KTitleWidget>
32 
33 #include <QCheckBox>
34 #include <QFile>
35 #include <QVBoxLayout>
36 
37 HostPreferences::HostPreferences(KConfigGroup configGroup, QObject *parent)
38  : QObject(parent),
39  m_configGroup(configGroup),
40  m_connected(false),
41  showAgainCheckBox(0),
42  walletSupportCheckBox(0)
43 {
44  m_hostConfigured = m_configGroup.hasKey("showConfigAgain");
45 }
46 
47 HostPreferences::~HostPreferences()
48 {
49 }
50 
51 KConfigGroup HostPreferences::configGroup()
52 {
53  return m_configGroup;
54 }
55 
56 void HostPreferences::acceptConfig()
57 {
58  setShowConfigAgain(showAgainCheckBox->isChecked());
59  setWalletSupport(walletSupportCheckBox->isChecked());
60 }
61 
62 bool HostPreferences::hostConfigured()
63 {
64  return m_hostConfigured;
65 }
66 
67 void HostPreferences::setShowConfigAgain(bool show)
68 {
69  m_configGroup.writeEntry("showConfigAgain", show);
70 }
71 
72 bool HostPreferences::showConfigAgain()
73 {
74  return m_configGroup.readEntry("showConfigAgain", true);
75 }
76 
77 void HostPreferences::setWalletSupport(bool walletSupport)
78 {
79  m_configGroup.writeEntry("walletSupport", walletSupport);
80 }
81 
82 bool HostPreferences::walletSupport()
83 {
84  return m_configGroup.readEntry("walletSupport", true);
85 }
86 
87 void HostPreferences::setHeight(int height)
88 {
89  if (height >= 0)
90  m_configGroup.writeEntry("height", height);
91 }
92 
93 int HostPreferences::height()
94 {
95  return m_configGroup.readEntry("height", Settings::height());
96 }
97 
98 void HostPreferences::setWidth(int width)
99 {
100  if (width >= 0)
101  m_configGroup.writeEntry("width", width);
102 }
103 
104 int HostPreferences::width()
105 {
106  return m_configGroup.readEntry("width", Settings::width());
107 }
108 
109 bool HostPreferences::fullscreenScale()
110 {
111  return m_configGroup.readEntry("fullscreenScale", false);
112 }
113 
114 void HostPreferences::setFullscreenScale(bool scale)
115 {
116  m_configGroup.writeEntry("fullscreenScale", scale);
117 }
118 
119 bool HostPreferences::windowedScale()
120 {
121  return m_configGroup.readEntry("windowedScale", false);
122 }
123 
124 void HostPreferences::setWindowedScale(bool scale)
125 {
126  m_configGroup.writeEntry("windowedScale", scale);
127 }
128 
129 bool HostPreferences::grabAllKeys()
130 {
131  return m_configGroup.readEntry("grabAllKeys", false);
132 }
133 
134 void HostPreferences::setGrabAllKeys(bool grab)
135 {
136  m_configGroup.writeEntry("grabAllKeys", grab);
137 }
138 
139 bool HostPreferences::showLocalCursor()
140 {
141  return m_configGroup.readEntry("showLocalCursor", false);
142 }
143 
144 void HostPreferences::setShowLocalCursor(bool show)
145 {
146  m_configGroup.writeEntry("showLocalCursor", show);
147 }
148 
149 bool HostPreferences::viewOnly()
150 {
151  return m_configGroup.readEntry("viewOnly", false);
152 }
153 
154 void HostPreferences::setViewOnly(bool view)
155 {
156  m_configGroup.writeEntry("viewOnly", view);
157 }
158 
159 bool HostPreferences::showDialogIfNeeded(QWidget *parent)
160 {
161  if (hostConfigured()) {
162  if (showConfigAgain()) {
163  kDebug(5010) << "Show config dialog again";
164  return showDialog(parent);
165  } else
166  return true; // no changes, no need to save
167  } else {
168  kDebug(5010) << "No config found, create new";
169  if (Settings::showPreferencesForNewConnections())
170  return showDialog(parent);
171  else
172  return true;
173  }
174 }
175 
176 
177 bool HostPreferences::showDialog(QWidget *parent)
178 {
179  // Prepare dialog
180  KDialog *dialog = new KDialog(parent);
181  dialog->setCaption(i18n("Host Configuration"));
182 
183  QWidget *mainWidget = dialog->mainWidget();
184  QVBoxLayout *layout = new QVBoxLayout(mainWidget);
185 
186  KTitleWidget *titleWidget = new KTitleWidget(dialog);
187  titleWidget->setText(i18n("Host Configuration"));
188  if (m_connected) {
189  titleWidget->setComment(QString("<i>%1</i>").arg(
190  i18n("Note that settings might only apply when you connect next time to this host.")));
191  }
192  titleWidget->setPixmap(KIcon("krdc"));
193  layout->addWidget(titleWidget);
194 
195  QWidget* widget = createProtocolSpecificConfigPage();
196 
197  if (widget) {
198  if (widget->layout())
199  widget->layout()->setMargin(0);
200 
201  layout->addWidget(widget);
202  }
203 
204  showAgainCheckBox = new QCheckBox(mainWidget);
205  showAgainCheckBox->setText(i18n("Show this dialog again for this host"));
206  showAgainCheckBox->setChecked(showConfigAgain());
207 
208  walletSupportCheckBox = new QCheckBox(mainWidget);
209  walletSupportCheckBox->setText(i18n("Remember password (KWallet)"));
210  walletSupportCheckBox->setChecked(walletSupport());
211 
212  layout->addWidget(showAgainCheckBox);
213  layout->addWidget(walletSupportCheckBox);
214  layout->addStretch(1);
215 
216  // WORKAROUND: it seems that KDialog does not set the minimum size properly in some cases.
217  // see for example issue #244539. also it looks like KTitleWidget returns a too small size hint when a comment is shown.
218  QSize minimumSize = dialog->sizeHint();
219  if (m_connected) {
220  minimumSize += QSize(0, 50);
221  }
222  dialog->setMinimumSize(minimumSize);
223 
224  // Show dialog
225  if (dialog->exec() == KDialog::Accepted) {
226  kDebug(5010) << "HostPreferences config dialog accepted";
227  acceptConfig();
228  return true;
229  } else {
230  return false;
231  }
232 }
233 
234 void HostPreferences::setShownWhileConnected(bool connected)
235 {
236  m_connected = connected;
237 }
238 
239 #include "hostpreferences.moc"
HostPreferences::setShownWhileConnected
void setShownWhileConnected(bool connected)
If connected is true, a message is shown that settings might only apply after a reconnect.
Definition: hostpreferences.cpp:234
HostPreferences::m_configGroup
KConfigGroup m_configGroup
Definition: hostpreferences.h:101
HostPreferences::HostPreferences
HostPreferences(KConfigGroup configGroup, QObject *parent)
Definition: hostpreferences.cpp:37
HostPreferences::windowedScale
bool windowedScale()
Whether scaling is enabled when session is not full screen.
Definition: hostpreferences.cpp:119
Settings::showPreferencesForNewConnections
static bool showPreferencesForNewConnections()
Get ShowPreferencesForNewConnections.
Definition: settings.h:106
HostPreferences::setWindowedScale
void setWindowedScale(bool scale)
Definition: hostpreferences.cpp:124
hostpreferences.h
HostPreferences::showDialog
bool showDialog(QWidget *parent)
Show the configuration dialog.
Definition: hostpreferences.cpp:177
HostPreferences::hostConfigured
bool hostConfigured()
Definition: hostpreferences.cpp:62
QWidget
HostPreferences::grabAllKeys
bool grabAllKeys()
Definition: hostpreferences.cpp:129
KDialog
QObject
HostPreferences::fullscreenScale
bool fullscreenScale()
Whether scaling is enabled when session is full screen.
Definition: hostpreferences.cpp:109
Settings::height
static int height()
Get Height.
Definition: settings.h:467
HostPreferences::~HostPreferences
~HostPreferences()
Definition: hostpreferences.cpp:47
HostPreferences::setShowLocalCursor
void setShowLocalCursor(bool show)
Definition: hostpreferences.cpp:144
HostPreferences::setGrabAllKeys
void setGrabAllKeys(bool grab)
Definition: hostpreferences.cpp:134
HostPreferences::configGroup
KConfigGroup configGroup()
Definition: hostpreferences.cpp:51
HostPreferences::setWidth
void setWidth(int width)
Definition: hostpreferences.cpp:98
HostPreferences::height
int height()
Saved height.
Definition: hostpreferences.cpp:93
Settings::width
static int width()
Get Width.
Definition: settings.h:448
HostPreferences::showConfigAgain
bool showConfigAgain()
Definition: hostpreferences.cpp:72
settings.h
HostPreferences::setFullscreenScale
void setFullscreenScale(bool scale)
Definition: hostpreferences.cpp:114
HostPreferences::createProtocolSpecificConfigPage
virtual QWidget * createProtocolSpecificConfigPage()=0
HostPreferences::acceptConfig
virtual void acceptConfig()
Called when the user validates the config dialog.
Definition: hostpreferences.cpp:56
HostPreferences::setViewOnly
void setViewOnly(bool view)
Definition: hostpreferences.cpp:154
HostPreferences::viewOnly
bool viewOnly()
Definition: hostpreferences.cpp:149
HostPreferences::width
int width()
Saved width.
Definition: hostpreferences.cpp:104
HostPreferences::setHeight
void setHeight(int height)
Definition: hostpreferences.cpp:87
HostPreferences::showDialogIfNeeded
bool showDialogIfNeeded(QWidget *parent)
Show the configuration dialog if needed, ie.
Definition: hostpreferences.cpp:159
HostPreferences::walletSupport
bool walletSupport()
Definition: hostpreferences.cpp:82
HostPreferences::showLocalCursor
bool showLocalCursor()
Definition: hostpreferences.cpp:139
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