qtewin.cpp.org
来自「远程桌面登陆软件 用rdesktop 但不基于Xwindows 可基于(nano」· ORG 代码 · 共 2,378 行 · 第 1/5 页
ORG
2,378 行
/* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. User interface services - QT Emb System Copyright (C) Jay Sorg 2004-2005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*///#define SHARP#ifdef SHARP#include <qpe/qpeapplication.h>#else#include <qapplication.h>#endif#include <qcursor.h>#include <qmainwindow.h>#include <qwidget.h>#include <qpainter.h>#include <qimage.h>#include <qsocketnotifier.h>#include <qscrollview.h>#include <qmessagebox.h>#include <qpushbutton.h>#include <qlineedit.h>#include <qcombobox.h>#include <qlabel.h>#include <qfile.h>#include <qcheckbox.h>#include <qpopupmenu.h>#include <stdlib.h>#include <stdarg.h> // va_list va_start va_end#include <unistd.h> // gethostname#include <pwd.h> // getpwuid#include "../rdesktop.h"#include "qtewin.h"#define QT_OPTIextern int g_tcp_port_rdp;int g_encryption = 1;int g_bitmap_cache = 1;int g_bitmap_cache_persist_enable = 0;int g_bitmap_cache_precache = 1;int g_use_rdp5 = 1;int g_desktop_save = 1;int g_bitmap_compression = 1;int g_polygon_ellipse_orders = 0;int g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;int g_console_session = 0;int g_keylayout = 0x409; /* Defaults to US keyboard layout */int g_keyboard_type = 0x4; /* Defaults to US keyboard layout */int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */int g_width = 640;int g_height = 480;int g_server_bpp = 8;char g_hostname[16] = "";char g_username[100] = "";#ifdef WITH_RDPSNDextern int g_dsp_busy;extern int g_dsp_fd;int g_rdpsnd = 0;static QSocketNotifier * g_SoundNotifier = 0;#endif/* types */struct QColorMap{ uint32 RGBColors[256]; uint32 NumColors;};struct bitmap{ int w; int h; uint8 * data;};static int g_client_width = 640;static int g_client_height = 480;static uint32 g_flags = RDP_LOGON_NORMAL;static char g_server[64] = "";static char g_domain[16] = "";static char g_password[16] = "";static char g_shell[128] = "";static char g_directory[32] = "";static int g_fullscreen = 0;static int g_global_sock = 0;static int g_deactivated = 0;static uint32 g_ext_disc_reason = 0;static QSocketNotifier * g_SocketNotifier = 0;#ifdef SHARPstatic QPEApplication * g_App = 0;#elsestatic QApplication * g_App = 0;#endifstatic QMyMainWindow * g_MW = 0;static QMyScrollView * g_SV = 0;static struct QColorMap * g_CM = 0;static uint8 * g_BS = 0; /* the screen data */static int g_clipx = 0;static int g_clipy = 0;static int g_clipcx = 0;static int g_clipcy = 0;/* Session Directory redirection */BOOL g_redirect = False;char g_redirect_server[64];char g_redirect_domain[16];char g_redirect_password[64];char g_redirect_username[64];char g_redirect_cookie[128];uint32 g_redirect_flags = 0;#define BPP ((g_server_bpp + 7) / 8)#define GETPIXEL8(d, x, y, w) (*(((uint8*)d) + ((y) * (w) + (x))))#define GETPIXEL16(d, x, y, w) (*(((uint16*)d) + ((y) * (w) + (x))))#define GETPIXEL32(d, x, y, w) (*(((uint32*)d) + ((y) * (w) + (x))))#define SETPIXEL8(d, x, y, w, v) *(((uint8*)d) + ((y) * (w) + (x))) = v#define SETPIXEL16(d, x, y, w, v) *(((uint16*)d) + ((y) * (w) + (x))) = v#define SETPIXEL32(d, x, y, w, v) *(((uint32*)d) + ((y) * (w) + (x))) = v/******************************************************************************/void CleanString(QString * Item){ int i; i = Item->length() - 1; while (i >= 0) { if (Item->at(i) == 10 || Item->at(i) == 13) { Item->remove(i, 1); } i--; }}/******************************************************************************/QMyDialog::QMyDialog(QWidget * parent) : QDialog(parent, "Settings", true){ int i, j; char * home; char Text[256]; QString Line; QString ItemName; QString ItemValue; // resize dialog resize(230, 270); // main list box ListBox = new QListBox(this); ListBox->move(10, 10); ListBox->resize(200, 100); connect(ListBox, SIGNAL(selectionChanged()), this, SLOT(ListBoxChanged())); connect(ListBox, SIGNAL(selected(int)), this, SLOT(ListBoxSelected(int))); // server Label1 = new QLabel(this); Label1->setText("Server Desc"); Label1->move(10, 120); Label1->resize(100, 20); ServerNameEdit = new QLineEdit(this); ServerNameEdit->move(75, 120); ServerNameEdit->resize(100, 20); // username Label2 = new QLabel(this); Label2->setText("User Name"); Label2->move(10, 150); Label2->resize(100, 20); UserNameEdit = new QLineEdit(this); UserNameEdit->move(75, 150); UserNameEdit->resize(100, 20); // ip Label3 = new QLabel(this); Label3->setText("Server IP"); Label3->move(10, 180); Label3->resize(100, 20); IPEdit = new QLineEdit(this); IPEdit->move(75, 180); IPEdit->resize(100, 20); // width and height WidthHeightBox = new QComboBox(this); WidthHeightBox->move(10, 210); WidthHeightBox->resize(100, 20); WidthHeightBox->insertItem("240x320"); WidthHeightBox->insertItem("640x480"); WidthHeightBox->insertItem("800x600"); connect(WidthHeightBox, SIGNAL(activated(int)), this, SLOT(ComboChanged(int))); WidthHeightBox->setCurrentItem(1); WidthEdit = new QLineEdit(this); WidthEdit->move(110, 210); WidthEdit->resize(30, 20); WidthEdit->setText("800"); HeightEdit = new QLineEdit(this); HeightEdit->move(140, 210); HeightEdit->resize(30, 20); HeightEdit->setText("600"); // add to list button AddButton = new QPushButton(this); AddButton->move(180, 120); AddButton->resize(50, 20); AddButton->setText("Add"); connect(AddButton, SIGNAL(clicked()), this, SLOT(AddClicked())); // change list item button EditButton = new QPushButton(this); EditButton->move(180, 140); EditButton->resize(50, 20); EditButton->setText("Edit"); connect(EditButton, SIGNAL(clicked()), this, SLOT(EditClicked())); // save to file button SaveButton = new QPushButton(this); SaveButton->move(180, 160); SaveButton->resize(50, 20); SaveButton->setText("Save"); connect(SaveButton, SIGNAL(clicked()), this, SLOT(SaveClicked())); // remove an item button RemoveButton = new QPushButton(this); RemoveButton->move(180, 180); RemoveButton->resize(50, 20); RemoveButton->setText("Remove"); connect(RemoveButton, SIGNAL(clicked()), this, SLOT(RemoveClicked())); // full screen check box FullScreenCheckBox = new QCheckBox(this, "Full Screen"); FullScreenCheckBox->setText("Full Screen"); FullScreenCheckBox->move(10, 230); // ok button OKButton = new QPushButton(this); OKButton->setText("OK"); OKButton->move(100, 240); OKButton->resize(50, 20); connect(OKButton, SIGNAL(clicked()), this, SLOT(OKClicked())); // cancel button CancelButton = new QPushButton(this); CancelButton->setText("Cancel"); CancelButton->move(160, 240); CancelButton->resize(50, 20); connect(CancelButton, SIGNAL(clicked()), this, SLOT(CancelClicked())); for (i = 0; i < 10; i++) { ConnectionList[i] = new QMyConnectionItem; ConnectionList[i]->ServerName = ""; ConnectionList[i]->UserName = ""; ConnectionList[i]->ServerIP = ""; ConnectionList[i]->Width = 0; ConnectionList[i]->Height = 0; ConnectionList[i]->FullScreen = 0; } home = getenv("HOME"); if (home != NULL) { sprintf(Text, "%s/rdesktop.ini", home); QFile * File = new QFile(Text); if (File->open(IO_ReadOnly)) { i = -1; while (!File->atEnd()) { File->readLine(Line, 255); j = Line.find("="); if (j > 0) { ItemName = Line.mid(0, j); CleanString(&ItemName); ItemValue = Line.mid(j + 1); CleanString(&ItemValue); if (ItemName == "Server") { i++; ConnectionList[i]->ServerName = ItemValue; ListBox->insertItem(ItemValue); } else if (ItemName == "UserName") ConnectionList[i]->UserName = ItemValue; else if (ItemName == "Width") ConnectionList[i]->Width = ItemValue.toInt(); else if (ItemName == "Height") ConnectionList[i]->Height = ItemValue.toInt(); else if (ItemName == "IP") ConnectionList[i]->ServerIP = ItemValue; else if (ItemName == "FullScreen") ConnectionList[i]->FullScreen = (ItemValue != "0"); } } } delete File; }}/******************************************************************************/QMyDialog::~QMyDialog(){ QMyConnectionItem * Item; int i; for (i = 0; i < 10; i++) { Item = ConnectionList[i]; delete Item; }}/******************************************************************************/void QMyDialog::ComboChanged(int index){ if (index == 0) { WidthEdit->setText("240"); HeightEdit->setText("320"); } if (index == 1) { WidthEdit->setText("640"); HeightEdit->setText("480"); } else if (index == 2) { WidthEdit->setText("800"); HeightEdit->setText("600"); }}/******************************************************************************/void QMyDialog::OKClicked(){ ServerName = ServerNameEdit->text(); UserName = UserNameEdit->text(); Width = WidthEdit->text().toInt(); Height = HeightEdit->text().toInt(); ServerIP = IPEdit->text(); FullScreen = FullScreenCheckBox->isChecked(); done(1);}/******************************************************************************/void QMyDialog::CancelClicked(){ done(0);}/******************************************************************************/void QMyDialog::AddClicked(){ int i; QMyConnectionItem * Item; i = ListBox->count(); if (i < 10) { ListBox->insertItem(ServerNameEdit->text()); Item = ConnectionList[i]; Item->ServerName = ServerNameEdit->text(); Item->UserName = UserNameEdit->text(); Item->Width = WidthEdit->text().toInt(); Item->Height = HeightEdit->text().toInt(); Item->ServerIP = IPEdit->text(); Item->FullScreen = FullScreenCheckBox->isChecked(); }}/******************************************************************************/void QMyDialog::EditClicked(){ int i; QMyConnectionItem * Item; i = ListBox->currentItem(); if (i >= 0) { Item = ConnectionList[i]; Item->ServerName = ServerNameEdit->text(); Item->UserName = UserNameEdit->text(); Item->Width = WidthEdit->text().toInt(); Item->Height = HeightEdit->text().toInt(); Item->ServerIP = IPEdit->text(); Item->FullScreen = FullScreenCheckBox->isChecked(); ListBox->changeItem(ServerNameEdit->text(), i); }}/******************************************************************************/void WriteString(QFile* File, QString* Line){ File->writeBlock((const char*)(*Line), Line->length());}/******************************************************************************/void QMyDialog::SaveClicked(){ int i, j; QMyConnectionItem * Item; QString Line; char * home; char Text[256]; QFile* File; home = getenv("HOME"); if (home != NULL) { sprintf(Text, "%s/rdesktop.ini", home); File = new QFile(Text); if (File->open(IO_Truncate | IO_ReadWrite)) { i = ListBox->count(); for (j = 0; j < i; j++) { Item = ConnectionList[j]; Line = "Server="; Line += Item->ServerName; Line += (char)10; WriteString(File, &Line); Line = "UserName="; Line += Item->UserName; Line += (char)10; WriteString(File, &Line); Line = "Width="; sprintf(Text, "%d", Item->Width); Line += Text; Line += (char)10; WriteString(File, &Line); Line = "Height="; sprintf(Text, "%d", Item->Height); Line += Text; Line += (char)10; WriteString(File, &Line); Line = "IP="; Line += Item->ServerIP; Line += (char)10; WriteString(File, &Line); Line = "FullScreen="; if (Item->FullScreen) Line += "1"; else Line += "0"; Line += (char)10; WriteString(File, &Line); } } File->flush(); File->close(); delete File; }}/******************************************************************************/void QMyDialog::RemoveClicked(){ int i, j, c; QMyConnectionItem * Item1; QMyConnectionItem * Item2; i = ListBox->currentItem(); if (i >= 0) { c = ListBox->count(); for (j = i; j < c - 1; j++) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?