• 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
nxclientthread.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 "nxclientthread.h"
25 #include "nxcallbacks.h"
26 
27 #include <kglobal.h>
28 #include <kstandarddirs.h>
29 
30 #include <QDesktopWidget>
31 #include <QApplication>
32 #include <QFile>
33 
34 NxClientThread::NxClientThread(QObject *parent)
35  : QThread(parent),
36  m_host(std::string()),
37  m_port(0),
38  m_privateKey(std::string()),
39  m_xid(0),
40  m_stopped(false)
41 {
42  m_client.setSessionData(&m_data);
43 
44  QDesktopWidget *desktop = QApplication::desktop();
45  int currentScreen = desktop->screenNumber();
46  QRect rect = desktop->screenGeometry(currentScreen);
47  m_client.setResolution(rect.width(), rect.height());
48  m_client.setDepth(24);
49  m_client.setRender(true);
50 
51  m_data.sessionName = "krdcSession";
52  m_data.cache = 8;
53  m_data.images = 32;
54  m_data.linkType = "adsl";
55  m_data.render = true;
56  m_data.backingstore = "when_requested";
57  m_data.imageCompressionMethod = 2;
58  m_data.keyboard = "defkeymap";
59  m_data.media = false;
60  m_data.agentServer = "";
61  m_data.agentUser = "";
62  m_data.agentPass = "";
63  m_data.cups = 0;
64  m_data.suspended = false;
65  m_data.fullscreen = false;
66  m_data.encryption = true;
67  m_data.terminate = false;
68 }
69 
70 NxClientThread::~NxClientThread()
71 {
72  stop();
73  wait(500);
74 }
75 
76 void NxClientThread::setCallbacks(NxCallbacks *callbacks)
77 {
78  m_client.setExternalCallbacks(callbacks);
79 }
80 
81 void NxClientThread::setHost(const QString &host)
82 {
83  QMutexLocker locker(&m_mutex);
84  QByteArray tmp = host.toAscii();
85  m_host = tmp.data();
86 }
87 
88 void NxClientThread::setPort(int port)
89 {
90  QMutexLocker locker(&m_mutex);
91  m_port = port;
92 }
93 
94 void NxClientThread::setUserName(const QString &userName)
95 {
96  QMutexLocker locker(&m_mutex);
97  std::string userNameStr = std::string(userName.toAscii().data());
98  m_client.setUsername(userNameStr);
99 }
100 
101 void NxClientThread::setPassword(const QString &password)
102 {
103  QMutexLocker locker(&m_mutex);
104  std::string passwordStr = std::string(password.toAscii());
105  m_client.setPassword(passwordStr);
106 }
107 
108 void NxClientThread::setResolution(int width, int height)
109 {
110  QMutexLocker locker(&m_mutex);
111  m_data.geometry = width + 'x' + height + "+0+0";
112 }
113 
114 void NxClientThread::setDesktopType(const QString &desktopType)
115 {
116  QMutexLocker locker(&m_mutex);
117  QByteArray tmp = desktopType.toAscii();
118  m_data.sessionType = tmp.data();
119 }
120 
121 void NxClientThread::setKeyboardLayout(const QString &keyboardLayout)
122 {
123  QMutexLocker locker(&m_mutex);
124  QByteArray tmp = keyboardLayout.toAscii();
125  m_data.kbtype = tmp.data();
126 }
127 
128 void NxClientThread::setPrivateKey(const QString &privateKey)
129 {
130  QMutexLocker locker(&m_mutex);
131  QByteArray tmp = privateKey.toAscii();
132  m_privateKey = tmp.data();
133 }
134 
135 void NxClientThread::setSuspended(bool suspended)
136 {
137  QMutexLocker locker(&m_mutex);
138  m_data.suspended = suspended;
139 }
140 
141 void NxClientThread::setId(const QString &id)
142 {
143  QMutexLocker locker(&m_mutex);
144  QByteArray tmp = id.toAscii();
145  m_data.id = tmp.data();
146 }
147 
148 void NxClientThread::stop()
149 {
150  QMutexLocker locker(&m_mutex);
151  m_stopped = true;
152 }
153 
154 void NxClientThread::run()
155 {
156  if (m_privateKey.compare("default") == 0) {
157  const QString keyfilename = QString("default.dsa.key");
158  const QString keyfilepath = KGlobal::dirs()->findResource("appdata", keyfilename);
159 
160  QFile file(keyfilepath);
161  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
162  return;
163 
164  QByteArray key;
165  while (!file.atEnd())
166  key += file.readLine();
167 
168  m_client.invokeNXSSH("supplied", m_host, true, key.data(), m_port);
169  } else
170  m_client.invokeNXSSH("supplied", m_host, true, m_privateKey, m_port);
171 
172  nxcl::notQProcess* p;
173  while (!m_client.getIsFinished() && !m_stopped) {
174  if (!m_client.getReadyForProxy()) {
175  p = m_client.getNXSSHProcess();
176  p->probeProcess();
177  } else {
178  p = m_client.getNXSSHProcess();
179  p->probeProcess();
180  p = m_client.getNXProxyProcess();
181  p->probeProcess();
182  }
183 
184  if (!this->m_xid) {
185  this->m_xid = m_client.getXID();
186 
187  if (this->m_xid)
188  emit hasXid(this->m_xid);
189  }
190 
191  usleep(1000);
192  }
193 }
194 
195 void NxClientThread::startSession()
196 {
197  m_client.runSession();
198 }
199 
200 #include "moc_nxclientthread.cpp"
NxClientThread::setPrivateKey
void setPrivateKey(const QString &privateKey)
Definition: nxclientthread.cpp:128
NxClientThread::setResolution
void setResolution(int width, int height)
Definition: nxclientthread.cpp:108
NxClientThread::setId
void setId(const QString &id)
Definition: nxclientthread.cpp:141
NxClientThread::setCallbacks
void setCallbacks(NxCallbacks *callbacks)
Definition: nxclientthread.cpp:76
NxClientThread::setDesktopType
void setDesktopType(const QString &desktopType)
Definition: nxclientthread.cpp:114
NxClientThread::startSession
void startSession()
Definition: nxclientthread.cpp:195
QObject
NxClientThread::setKeyboardLayout
void setKeyboardLayout(const QString &keyboardLayout)
Definition: nxclientthread.cpp:121
nxclientthread.h
NxClientThread::setSuspended
void setSuspended(bool suspended)
Definition: nxclientthread.cpp:135
NxClientThread::setPassword
void setPassword(const QString &password)
Definition: nxclientthread.cpp:101
NxClientThread::setHost
void setHost(const QString &host)
Definition: nxclientthread.cpp:81
NxClientThread::stop
void stop()
Definition: nxclientthread.cpp:148
NxClientThread::run
void run()
Definition: nxclientthread.cpp:154
NxClientThread::setPort
void setPort(int port)
Definition: nxclientthread.cpp:88
NxClientThread::NxClientThread
NxClientThread(QObject *parent=0)
Definition: nxclientthread.cpp:34
NxCallbacks
Definition: nxcallbacks.h:35
NxClientThread::hasXid
void hasXid(int xid)
Emitted when the X Window ID of the main NX window is received.
NxClientThread::setUserName
void setUserName(const QString &userName)
Definition: nxclientthread.cpp:94
QThread
NxClientThread::~NxClientThread
~NxClientThread()
Definition: nxclientthread.cpp:70
nxcallbacks.h
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