📄 qtwin.cpp
字号:
{
int i, x, y, dx, dy;
if (npoints > 0)
{
x = points[0].x;
y = points[0].y;
for (i = 1; i < npoints; i++)
{
dx = points[i].x;
dy = points[i].y;
ui_line(opcode, x, y, x + dx, y + dy, pen);
x = x + dx;
y = y + dy;
}
}
}
/*****************************************************************************/
void ui_ellipse(uint8 opcode, uint8 fillmode,
int x, int y, int cx, int cy,
BRUSH * brush, int bgcolour, int fgcolour)
{
}
/*****************************************************************************/
void generate_random(uint8 * random)
{
QFile File("/dev/random");
File.open(IO_ReadOnly);
if (File.readBlock((char*)random, 32) == 32)
{
return;
}
warning("no /dev/random\n");
memcpy(random, "12345678901234567890123456789012", 32);
}
/*****************************************************************************/
void save_licence(uint8 * data, int length)
{
char * home, * path, * tmppath;
int fd;
home = getenv("HOME");
if (home == NULL)
{
return;
}
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) +
sizeof("/.rdesktop/licence."));
sprintf(path, "%s/.rdesktop", home);
if ((mkdir(path, 0700) == -1) && errno != EEXIST)
{
perror(path);
return;
}
/* write licence to licence.hostname.new, then atomically rename to
licence.hostname */
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
strcpy(tmppath, path);
strcat(tmppath, ".new");
fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (fd == -1)
{
perror(tmppath);
return;
}
if (write(fd, data, length) != length)
{
perror(tmppath);
unlink(tmppath);
}
else if (rename(tmppath, path) == -1)
{
perror(path);
unlink(tmppath);
}
close(fd);
xfree(tmppath);
xfree(path);
}
/*****************************************************************************/
int load_licence(uint8 ** data)
{
char * home, * path;
struct stat st;
int fd, length;
home = getenv("HOME");
if (home == NULL)
{
return -1;
}
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) +
sizeof("/.rdesktop/licence."));
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
fd = open(path, O_RDONLY);
if (fd == -1)
{
return -1;
}
if (fstat(fd, &st))
{
return -1;
}
*data = (uint8 *) xmalloc(st.st_size);
length = read(fd, *data, st.st_size);
close(fd);
xfree(path);
return length;
}
/*****************************************************************************/
void* xrealloc(void * in_val, int size)
{
return realloc(in_val, size);
}
/*****************************************************************************/
void* xmalloc(int size)
{
return malloc(size);
}
/*****************************************************************************/
void xfree(void * in_val)
{
if (in_val != NULL)
{
free(in_val);
}
}
/*****************************************************************************/
char * xstrdup(const char * s)
{
char * mem = strdup(s);
if (mem == NULL)
{
perror("strdup");
exit(1);
}
return mem;
}
/*****************************************************************************/
void warning(char * format, ...)
{
va_list ap;
fprintf(stderr, "WARNING: ");
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
}
/*****************************************************************************/
void unimpl(char * format, ...)
{
va_list ap;
fprintf(stderr, "NOT IMPLEMENTED: ");
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
}
/*****************************************************************************/
void error(char * format, ...)
{
va_list ap;
fprintf(stderr, "ERROR: ");
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
}
/*****************************************************************************/
void out_params(void)
{
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");
fprintf(stderr, "QT uiport by Jay Sorg\n");
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
fprintf(stderr, "Usage: qtrdesktop [options] server\n");
fprintf(stderr, " -g WxH: desktop geometry\n");
fprintf(stderr, " -4: use RDP version 4\n");
fprintf(stderr, " -5: use RDP version 5 (default)\n");
fprintf(stderr, " -t 3389: tcp port)\n");
fprintf(stderr, " -a 8|16|24: connection colour depth\n");
fprintf(stderr, " -T title: window title\n");
fprintf(stderr, " -P: use persistent bitmap caching\n");
fprintf(stderr, " -0: attach to console\n");
fprintf(stderr, " -z: enable rdp compression\n");
fprintf(stderr, " -r sound: enable sound\n");
fprintf(stderr, "\n");
}
/*****************************************************************************/
/* produce a hex dump */
void hexdump(uint8 * p, uint32 len)
{
uint8 * line = p;
int i, thisline;
uint32 offset = 0;
while (offset < len)
{
printf("%04x ", offset);
thisline = len - offset;
if (thisline > 16)
{
thisline = 16;
}
for (i = 0; i < thisline; i++)
{
printf("%02x ", line[i]);
}
for (; i < 16; i++)
{
printf(" ");
}
for (i = 0; i < thisline; i++)
{
printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
}
printf("\n");
offset += thisline;
line += thisline;
}
}
/*****************************************************************************/
int rd_pstcache_mkdir(void)
{
char * home;
char bmpcache_dir[256];
home = getenv("HOME");
if (home == NULL)
{
return False;
}
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
{
perror(bmpcache_dir);
return False;
}
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
{
perror(bmpcache_dir);
return False;
}
return True;
}
/*****************************************************************************/
int rd_open_file(char * filename)
{
char * home;
char fn[256];
int fd;
home = getenv("HOME");
if (home == NULL)
{
return -1;
}
sprintf(fn, "%s/.rdesktop/%s", home, filename);
fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd == -1)
{
perror(fn);
}
return fd;
}
/*****************************************************************************/
void rd_close_file(int fd)
{
close(fd);
}
/*****************************************************************************/
int rd_read_file(int fd, void * ptr, int len)
{
return read(fd, ptr, len);
}
/*****************************************************************************/
int rd_write_file(int fd, void * ptr, int len)
{
return write(fd, ptr, len);
}
/*****************************************************************************/
int rd_lseek_file(int fd, int offset)
{
return lseek(fd, offset, SEEK_SET);
}
/*****************************************************************************/
int rd_lock_file(int fd, int start, int len)
{
struct flock lock;
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = start;
lock.l_len = len;
if (fcntl(fd, F_SETLK, &lock) == -1)
{
return False;
}
return True;
}
/*****************************************************************************/
void get_username_and_hostname(void)
{
char fullhostname[64];
char * p;
struct passwd * pw;
STRNCPY(g_username, "unknown", sizeof(g_username));
STRNCPY(g_hostname, "unknown", sizeof(g_hostname));
pw = getpwuid(getuid());
if (pw != NULL && pw->pw_name != NULL)
{
STRNCPY(g_username, pw->pw_name, sizeof(g_username));
}
if (gethostname(fullhostname, sizeof(fullhostname)) != -1)
{
p = strchr(fullhostname, '.');
if (p != NULL)
{
*p = 0;
}
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
}
}
/*****************************************************************************/
int parse_parameters(int in_argc, char ** in_argv)
{
int i;
char * p;
if (in_argc <= 1)
{
out_params();
return 0;
}
g_argc = in_argc;
g_argv = in_argv;
for (i = 1; i < in_argc; i++)
{
strcpy(g_servername, in_argv[i]);
if (strcmp(in_argv[i], "-g") == 0)
{
g_width = strtol(in_argv[i + 1], &p, 10);
if (g_width <= 0)
{
error("invalid geometry\n");
return 0;
}
if (*p == 'x')
{
g_height = strtol(p + 1, NULL, 10);
}
if (g_height <= 0)
{
error("invalid geometry\n");
return 0;
}
g_width = (g_width + 3) & ~3;
}
else if (strcmp(in_argv[i], "-T") == 0)
{
strcpy(g_title, in_argv[i + 1]);
}
else if (strcmp(in_argv[i], "-4") == 0)
{
g_use_rdp5 = 0;
}
else if (strcmp(in_argv[i], "-5") == 0)
{
g_use_rdp5 = 1;
}
else if (strcmp(in_argv[i], "-a") == 0)
{
g_server_depth = strtol(in_argv[i + 1], &p, 10);
if (g_server_depth != 8 && g_server_depth != 15 &&
g_server_depth != 16 && g_server_depth != 24)
{
error("invalid bpp\n");
return 0;
}
}
else if (strcmp(in_argv[i], "-t") == 0)
{
g_tcp_port_rdp = strtol(in_argv[i + 1], &p, 10);
}
else if (strcmp(in_argv[i], "-P") == 0)
{
g_bitmap_cache_persist_enable = 1;
}
else if (strcmp(in_argv[i], "-0") == 0)
{
g_console_session = 1;
}
else if (strcmp(in_argv[i], "-z") == 0)
{
g_flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2);
}
else if (strcmp(in_argv[i], "-r") == 0)
{
if (strcmp(in_argv[i + 1], "sound") == 0)
{
#ifdef WITH_RDPSND
g_rdpsnd = 1;
#endif
}
}
}
return 1;
}
/*****************************************************************************/
int main(int in_argc, char** in_argv)
{
get_username_and_hostname();
if (!parse_parameters(in_argc, in_argv))
{
return 0;
}
if (!ui_init())
{
return 1;
}
if (!ui_create_window())
{
return 1;
}
ui_main_loop();
ui_destroy_window();
ui_deinit();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -