• 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
nxview.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 "nxview.h"
25 #include "settings.h"
26 
27 #include <nxcl/nxdata.h>
28 
29 #include <KInputDialog>
30 #include <KMessageBox>
31 #include <KPasswordDialog>
32 
33 #include <QEvent>
34 #include <QMetaType>
35 
36 NxView::NxView(QWidget *parent, const KUrl &url, KConfigGroup configGroup)
37  : RemoteView(parent),
38  m_quitFlag(false),
39  m_container(NULL),
40  m_hostPreferences(NULL)
41 {
42  m_url = url;
43  m_host = url.host();
44  m_port = url.port();
45 
46  if (m_port <= 0 || m_port >= 65536)
47  m_port = TCP_PORT_NX;
48 
49  m_container = new QX11EmbedContainer(this);
50  m_container->installEventFilter(this);
51 
52  qRegisterMetaType<QList<nxcl::NXResumeData> >("QList<nxcl::NXResumeData>");
53 
54  m_clientThread.setCallbacks(&m_callbacks);
55 
56  connect(&m_clientThread, SIGNAL(hasXid(int)), this, SLOT(hasXid(int)));
57  connect(&m_callbacks, SIGNAL(progress(int,QString)), this, SLOT(handleProgress(int,QString)));
58  connect(&m_callbacks, SIGNAL(suspendedSessions(QList<nxcl::NXResumeData>)), this, SLOT(handleSuspendedSessions(QList<nxcl::NXResumeData>)));
59  connect(&m_callbacks, SIGNAL(noSessions()), this, SLOT(handleNoSessions()));
60  connect(&m_callbacks, SIGNAL(atCapacity()), this, SLOT(handleAtCapacity()));
61  connect(&m_resumeSessions, SIGNAL(newSession()), this, SLOT(handleNewSession()));
62  connect(&m_resumeSessions, SIGNAL(resumeSession(QString)), this, SLOT(handleResumeSession(QString)));
63 
64  m_hostPreferences = new NxHostPreferences(configGroup, this);
65 }
66 
67 NxView::~NxView()
68 {
69 }
70 
71 // filter out key and mouse events to the container if we are view only
72 //FIXME: X11 events are passed to the app before getting caught in the Qt event processing
73 bool NxView::eventFilter(QObject *obj, QEvent *event)
74 {
75  if (m_viewOnly) {
76  if (event->type() == QEvent::KeyPress ||
77  event->type() == QEvent::KeyRelease ||
78  event->type() == QEvent::MouseButtonDblClick ||
79  event->type() == QEvent::MouseButtonPress ||
80  event->type() == QEvent::MouseButtonRelease ||
81  event->type() == QEvent::MouseMove)
82  return true;
83  }
84 
85  return RemoteView::eventFilter(obj, event);
86 }
87 
88 void NxView::startQuitting()
89 {
90  kDebug(5013) << "about to quit";
91 
92  const bool connected = status() == RemoteView::Connected;
93  setStatus(Disconnecting);
94  m_quitFlag = true;
95 
96  if (connected)
97  m_clientThread.stop();
98  else
99  m_clientThread.quit();
100 
101  m_clientThread.wait(500);
102  setStatus(Disconnected);
103  m_container->discardClient();
104 }
105 
106 bool NxView::isQuitting()
107 {
108  return m_quitFlag;
109 }
110 
111 bool NxView::start()
112 {
113  m_clientThread.setResolution(m_hostPreferences->width(), m_hostPreferences->height());
114  m_clientThread.setDesktopType(m_hostPreferences->desktopType());
115  m_clientThread.setKeyboardLayout(m_hostPreferences->keyboardLayout());
116  m_clientThread.setPrivateKey(m_hostPreferences->privateKey());
117 
118  m_container->show();
119 
120  if (m_hostPreferences->walletSupport()) {
121  if (m_url.userName().isEmpty()) {
122  QString userName;
123  bool ok = false;
124 
125  userName = KInputDialog::getText(i18n("Enter Username"),
126  i18n("Please enter the username you would like to use for login."),
127  QString(), &ok, this);
128 
129  if (ok)
130  m_url.setUserName(userName);
131  }
132 
133  if (!m_url.userName().isEmpty()) {
134  QString walletPassword = readWalletPassword();
135 
136  if (!walletPassword.isNull())
137  m_url.setPassword(walletPassword);
138  else {
139  KPasswordDialog dialog(this);
140  dialog.setPrompt(i18n("Access to the system requires a password."));
141  if (dialog.exec() == KPasswordDialog::Accepted) {
142  m_url.setPassword(dialog.password());
143 
144  if (m_hostPreferences->walletSupport())
145  saveWalletPassword(dialog.password());
146  }
147  }
148  }
149  }
150 
151  m_clientThread.setHost(m_host);
152  m_clientThread.setPort(m_port);
153  m_clientThread.setUserName(m_url.userName());
154  m_clientThread.setPassword(m_url.password());
155  m_clientThread.setResolution(m_hostPreferences->width(), m_hostPreferences->height());
156 
157  setStatus(Connecting);
158  m_clientThread.start();
159 
160  connect(m_container, SIGNAL(clientIsEmbedded()), SLOT(connectionOpened()));
161  connect(m_container, SIGNAL(clientClosed()), SLOT(connectionClosed()));
162 
163  return true;
164 }
165 
166 HostPreferences* NxView::hostPreferences()
167 {
168  return m_hostPreferences;
169 }
170 
171 QSize NxView::framebufferSize()
172 {
173  return m_container->minimumSizeHint();
174 }
175 
176 QSize NxView::sizeHint() const
177 {
178  return maximumSize();
179 }
180 
181 
182 void NxView::switchFullscreen(bool on)
183 {
184  setGrabAllKeys(on);
185 }
186 
187 void NxView::setGrabAllKeys(bool grabAllKeys)
188 {
189  m_grabAllKeys = grabAllKeys;
190 
191  if (grabAllKeys) {
192  m_keyboardIsGrabbed = true;
193  m_container->grabKeyboard();
194  } else if (m_keyboardIsGrabbed)
195  m_container->releaseKeyboard();
196 }
197 
198 void NxView::hasXid(int xid)
199 {
200  m_container->embedClient(xid);
201 }
202 
203 void NxView::handleProgress(int id, QString msg)
204 {
205  Q_UNUSED(msg);
206  switch (id) {
207  case NXCL_AUTH_FAILED:
208  KMessageBox::error(this, i18n("The authentication key is invalid."), i18n("Invalid authentication key"));
209  break;
210  case NXCL_LOGIN_FAILED:
211  KMessageBox::error(this, i18n("The username or password that you have entered is invalid."), i18n("Invalid username or password"));
212  break;
213  case NXCL_HOST_KEY_VERIFAILED:
214  KMessageBox::error(this, i18n("The host key verification has failed."), i18n("Host key verification failed"));
215  break;
216  case NXCL_PROCESS_ERROR:
217  KMessageBox::error(this, i18n("An error has occurred during the connection to the NX server."), i18n("Process error"));
218  break;
219  default:
220  break;
221  }
222 }
223 
224 void NxView::handleSuspendedSessions(QList<nxcl::NXResumeData> sessions)
225 {
226  if (!m_resumeSessions.empty())
227  m_resumeSessions.clear();
228 
229  m_resumeSessions.addSessions(sessions);
230  m_resumeSessions.show();
231 }
232 
233 void NxView::handleNoSessions()
234 {
235  m_clientThread.setSuspended(false);
236  m_clientThread.startSession();
237 }
238 
239 void NxView::handleAtCapacity()
240 {
241  KMessageBox::error(this, i18n("This NX server is running at capacity."), i18n("Server at capacity"));
242 }
243 
244 void NxView::handleNewSession()
245 {
246  m_clientThread.setSuspended(false);
247  m_clientThread.startSession();
248 }
249 
250 void NxView::handleResumeSession(QString id)
251 {
252  m_clientThread.setId(id);
253  m_clientThread.setSuspended(true);
254  m_clientThread.startSession();
255 }
256 
257 void NxView::connectionOpened()
258 {
259  kDebug(5013) << "Connection opened";
260  QSize size(m_hostPreferences->width(), m_hostPreferences->height());
261  kDebug(5013) << "Size hint: " << size.width() << size.height();
262  setStatus(Connected);
263  setFixedSize(size);
264  resize(size);
265  m_container->setFixedSize(size);
266  emit framebufferSizeChanged(size.width(), size.height());
267  emit connected();
268  setFocus();
269 }
270 
271 void NxView::connectionClosed()
272 {
273  emit disconnected();
274  setStatus(Disconnected);
275  m_quitFlag = true;
276 }
277 
278 #include "nxview.moc"
NxHostPreferences
Definition: nxhostpreferences.h:30
nxview.h
NxClientThread::setPrivateKey
void setPrivateKey(const QString &privateKey)
Definition: nxclientthread.cpp:128
NxView::start
virtual bool start()
Initialize the view (for example by showing configuration dialogs to the user) and start connecting...
Definition: nxview.cpp:111
RemoteView::m_grabAllKeys
bool m_grabAllKeys
Definition: remoteview.h:401
NxView::sizeHint
QSize sizeHint() const
Definition: nxview.cpp:176
NxClientThread::setResolution
void setResolution(int width, int height)
Definition: nxclientthread.cpp:108
NxView::handleSuspendedSessions
void handleSuspendedSessions(QList< nxcl::NXResumeData > sessions)
Definition: nxview.cpp:224
NxView::isQuitting
virtual bool isQuitting()
Checks whether the view is currently quitting.
Definition: nxview.cpp:106
NxClientThread::setId
void setId(const QString &id)
Definition: nxclientthread.cpp:141
NxClientThread::setCallbacks
void setCallbacks(NxCallbacks *callbacks)
Definition: nxclientthread.cpp:76
TCP_PORT_NX
#define TCP_PORT_NX
Definition: nxview.h:35
NxView::handleNewSession
void handleNewSession()
Definition: nxview.cpp:244
NxView::handleResumeSession
void handleResumeSession(QString id)
Definition: nxview.cpp:250
QWidget
NxView::setGrabAllKeys
virtual void setGrabAllKeys(bool grabAllKeys)
Enables/disables grabbing all possible keys.
Definition: nxview.cpp:187
NxClientThread::setDesktopType
void setDesktopType(const QString &desktopType)
Definition: nxclientthread.cpp:114
NxClientThread::startSession
void startSession()
Definition: nxclientthread.cpp:195
RemoteView::readWalletPassword
QString readWalletPassword(bool fromUserNameOnly=false)
Definition: remoteview.cpp:199
NxHostPreferences::privateKey
QString privateKey() const
Definition: nxhostpreferences.cpp:293
NxView::eventFilter
bool eventFilter(QObject *obj, QEvent *event)
Definition: nxview.cpp:73
QObject
NxClientThread::setKeyboardLayout
void setKeyboardLayout(const QString &keyboardLayout)
Definition: nxclientthread.cpp:121
RemoteView::connected
void connected()
Emitted when the view connected successfully.
NxView::startQuitting
virtual void startQuitting()
Initiate the disconnection.
Definition: nxview.cpp:88
NxView::hostPreferences
HostPreferences * hostPreferences()
Returns the current host preferences of this view.
Definition: nxview.cpp:166
RemoteView::m_port
int m_port
Definition: remoteview.h:399
NxResumeSessions::clear
void clear()
Definition: nxresumesessions.cpp:67
RemoteView::m_host
QString m_host
Definition: remoteview.h:398
RemoteView::grabAllKeys
virtual bool grabAllKeys()
Checks whether grabbing all possible keys is enabled.
Definition: remoteview.cpp:143
RemoteView
Generic widget that displays a remote framebuffer.
Definition: remoteview.h:59
RemoteView::disconnected
void disconnected()
Emitted when the view disconnected without error.
NxResumeSessions::empty
bool empty() const
Definition: nxresumesessions.cpp:62
RemoteView::Disconnecting
Definition: remoteview.h:113
NxView::handleNoSessions
void handleNoSessions()
Definition: nxview.cpp:233
NxView::hasXid
void hasXid(int xid)
Definition: nxview.cpp:198
NxView::switchFullscreen
void switchFullscreen(bool on)
Definition: nxview.cpp:182
NxClientThread::setSuspended
void setSuspended(bool suspended)
Definition: nxclientthread.cpp:135
RemoteView::framebufferSizeChanged
void framebufferSizeChanged(int w, int h)
Emitted when the size of the remote screen changes.
NxView::connectionClosed
void connectionClosed()
Definition: nxview.cpp:271
NxView::connectionOpened
void connectionOpened()
Definition: nxview.cpp:257
NxHostPreferences::keyboardLayout
QString keyboardLayout() const
Definition: nxhostpreferences.cpp:282
RemoteView::m_keyboardIsGrabbed
bool m_keyboardIsGrabbed
Definition: remoteview.h:403
NxHostPreferences::width
int width()
Definition: nxhostpreferences.cpp:260
RemoteView::Connecting
Definition: remoteview.h:109
NxResumeSessions::addSessions
void addSessions(QList< nxcl::NXResumeData > sessions)
Definition: nxresumesessions.cpp:72
RemoteView::url
KUrl url()
Definition: remoteview.cpp:193
NxView::handleProgress
void handleProgress(int id, QString msg)
Definition: nxview.cpp:203
RemoteView::saveWalletPassword
void saveWalletPassword(const QString &password, bool fromUserNameOnly=false)
Definition: remoteview.cpp:235
NxClientThread::setPassword
void setPassword(const QString &password)
Definition: nxclientthread.cpp:101
NxClientThread::setHost
void setHost(const QString &host)
Definition: nxclientthread.cpp:81
NxHostPreferences::height
int height()
Definition: nxhostpreferences.cpp:249
NxHostPreferences::desktopType
QString desktopType() const
Definition: nxhostpreferences.cpp:271
NxClientThread::stop
void stop()
Definition: nxclientthread.cpp:148
HostPreferences
Definition: hostpreferences.h:42
NxView::NxView
NxView(QWidget *parent=0, const KUrl &url=KUrl(), KConfigGroup configGroup=KConfigGroup())
Definition: nxview.cpp:36
settings.h
NxView::handleAtCapacity
void handleAtCapacity()
Definition: nxview.cpp:239
RemoteView::m_viewOnly
bool m_viewOnly
Definition: remoteview.h:400
RemoteView::setStatus
virtual void setStatus(RemoteStatus s)
Set the status of the connection.
Definition: remoteview.cpp:62
NxResumeSessions::show
void show()
Definition: nxresumesessions.cpp:88
RemoteView::m_url
KUrl m_url
Definition: remoteview.h:404
RemoteView::status
RemoteStatus status()
Returns the current status of the connection.
Definition: remoteview.cpp:57
NxClientThread::setPort
void setPort(int port)
Definition: nxclientthread.cpp:88
NxView::~NxView
virtual ~NxView()
Definition: nxview.cpp:67
NxView::framebufferSize
virtual QSize framebufferSize()
Returns the resolution of the remote framebuffer.
Definition: nxview.cpp:171
NxClientThread::setUserName
void setUserName(const QString &userName)
Definition: nxclientthread.cpp:94
RemoteView::Disconnected
Definition: remoteview.h:114
HostPreferences::walletSupport
bool walletSupport()
Definition: hostpreferences.cpp:82
RemoteView::Connected
Definition: remoteview.h:112
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