3 Copyright (C) 2010 Christian Pulvermacher
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "mainwindow.h"
20 #include "rfb/rfbclient.h"
22 #include <QApplication>
28 const QString APPNAME("Presence VNC");
32 std::cout << "Usage: " << qPrintable(QCoreApplication::arguments().at(0)) << " [options] [URL [quality]]\n"
35 << " --help\t\t\t Print this text and exit.\n"
36 << " --listen [port]\t Listen for incoming connections on given port, or 5500 if omitted. Cannot be used with an URL.\n"
37 << " --viewonly\t\t Don't send mouse/keyboard input to remote desktop. This is only useful if you also supply a URL, or --listen.\n"
40 << " vnc://:password@server:display\n\n"
41 << " Password and display can be omitted, e.g. vnc://server is a valid URL.\n"
42 << " Optionally, you can define the quality as a second argument (1-3, where 1 is the best). Default is 2.\n";
45 int main(int argc, char *argv[])
47 QCoreApplication::setOrganizationName(APPNAME);
48 QCoreApplication::setApplicationName(APPNAME);
50 QApplication app(argc, argv);
54 int listen_port = 0; //only used if >0
55 bool view_only = false;
57 QStringList arguments = QCoreApplication::arguments();
58 for(int i = 1; i < arguments.count(); i++) {
59 if(arguments.at(i) == "--help") {
63 } else if(arguments.at(i) == "--listen") {
64 if(arguments.count() <= i+1 or arguments.at(i+1).startsWith("--")) {
65 //no argument found, use default
66 listen_port = LISTEN_PORT_OFFSET;
68 //next argument should be a port number
69 listen_port = arguments.at(i+1).toInt();
70 if(listen_port < 1 or listen_port > 65535) {
71 std::cerr << "\"" << qPrintable(arguments.at(i+1)) << "\" is not a valid port number!\n\n";
78 } else if(arguments.at(i) == "--viewonly") {
80 } else { //not a valid command line option, should be the url
81 url = arguments.at(i);
84 if(!url.startsWith("vnc://")) {
85 std::cerr << "\"" << qPrintable(url) << "\" is not a valid command line option!\n\n";
91 if(arguments.count() > i+1) { //TODO: having a --quality option would make more sense.
92 int arg = arguments.at(i+1).toInt();
93 if(1 <= arg and arg <= 3) { //check if arg is valid, might also be another option
101 if(!url.isNull() and listen_port > 0) {
102 std::cerr << "--listen cannot be used with an URL!\n";
106 MainWindow main(url, quality, listen_port, view_only);