bb24faeb1c607f5f33ecde42b3b1cc9213e89680
[presencevnc] / src / main.cpp
1 /*
2     Presence VNC
3     Copyright (C) 2010 Christian Pulvermacher
4
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.
9
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.
14
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.
18 */
19 #include "mainwindow.h"
20
21 #include <QApplication>
22 #include <QString>
23
24 #include <iostream>
25
26
27 const QString APPNAME("Presence VNC");
28
29 void printHelp() {
30         std::cout << "Usage: " << qPrintable(QCoreApplication::arguments().at(0)) << " [options] [URL [quality]]\n"
31
32                 << "\nOptions:\n"
33                 << " --help\t\t Print this text and exit.\n"
34                 << " --viewonly\t Don't send mouse/keyboard input to remote desktop. This is only useful if you also supply a URL.\n"
35
36                 << "\nURLs:\n"
37                 << " vnc://:password@server:display\n\n"
38                 << " Password and display can be omitted, e.g. vnc://server is a valid URL.\n"
39                 << " Optionally, you can define the quality as a second argument (1-3, where 1 is the best). Default is 2.\n";
40 }
41
42 int main(int argc, char *argv[])
43 {
44         QCoreApplication::setOrganizationName(APPNAME);
45         QCoreApplication::setApplicationName(APPNAME);
46
47         QApplication app(argc, argv);
48
49         QString url;
50         int quality = 2;
51         bool view_only = false;
52
53         QStringList arguments = QCoreApplication::arguments();
54         for(int i = 1; i < arguments.count(); i++) {
55                 if(arguments.at(i) == "--help") {
56                         printHelp();
57
58                         return 0;
59                 } else if(arguments.at(i) == "--viewonly") {
60                         view_only = true;
61                 } else { //not a valid command line option, should be the url
62                         url = arguments.at(i);
63
64                         //check url
65                         if(!url.startsWith("vnc://")) {
66                                 std::cerr << "\"" << qPrintable(url) << "\" is not a valid command line option!\n\n";
67                                 printHelp();
68
69                                 return 1;
70                         }
71
72                         if(arguments.count() > i+1) { //having a --quality option would make more sense.
73                                 int arg = arguments.at(i+1).toInt();
74                                 if(1 <= arg and arg <= 3) { //check if arg is valid, might also be another option
75                                         quality = arg;
76                                         i++;
77                                 }
78                         }
79                 }
80         }
81
82         MainWindow main(url, quality, view_only);
83         main.show();
84         return app.exec();
85 }