source: trunk/tools/qvfb/main.cpp@ 372

Last change on this file since 372 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 4.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qvfb.h"
43
44#include <QApplication>
45#include <QRegExp>
46#include <stdlib.h>
47#include <stdio.h>
48#include <signal.h>
49#ifdef Q_WS_X11
50#include <QX11Info>
51#endif
52
53QT_BEGIN_NAMESPACE
54
55void fn_quit_qvfb(int)
56{
57 // pretend that we have quit normally
58 qApp->quit();
59}
60
61
62void usage( const char *app )
63{
64 printf( "Usage: %s [-width width] [-height height] [-depth depth] [-zoom zoom]"
65 "[-mmap] [-nocursor] [-qwsdisplay :id] [-x11display :id] [-skin skindirectory]\n"
66 "Supported depths: 1, 4, 8, 12, 15, 16, 18, 24, 32\n", app );
67}
68int qvfb_protocol = 0;
69
70int runQVfb( int argc, char *argv[] )
71{
72 Q_INIT_RESOURCE(qvfb);
73
74 QApplication app( argc, argv );
75
76 int width = 0;
77 int height = 0;
78 int depth = -32; // default, but overridable by skin
79 bool depthSet = false;
80 int rotation = 0;
81 bool cursor = true;
82 QVFb::DisplayType displayType = QVFb::QWS;
83 double zoom = 1.0;
84 QString displaySpec( ":0" );
85 QString skin;
86
87 for ( int i = 1; i < argc; i++ ){
88 QString arg = argv[i];
89 if ( arg == "-width" ) {
90 width = atoi( argv[++i] );
91 } else if ( arg == "-height" ) {
92 height = atoi( argv[++i] );
93 } else if ( arg == "-skin" ) {
94 skin = argv[++i];
95 } else if ( arg == "-depth" ) {
96 depth = atoi( argv[++i] );
97 depthSet = true;
98 } else if ( arg == "-nocursor" ) {
99 cursor = false;
100 } else if ( arg == "-mmap" ) {
101 qvfb_protocol = 1;
102 } else if ( arg == "-zoom" ) {
103 zoom = atof( argv[++i] );
104 } else if ( arg == "-qwsdisplay" ) {
105 displaySpec = argv[++i];
106 displayType = QVFb::QWS;
107#ifdef Q_WS_X11
108 } else if ( arg == "-x11display" ) {
109 displaySpec = argv[++i];
110 displayType = QVFb::X11;
111
112 // Usually only the default X11 depth will work with Xnest,
113 // so override the default of 32 with the actual X11 depth.
114 if (!depthSet)
115 depth = -QX11Info::appDepth(); // default, but overridable by skin
116#endif
117 } else {
118 printf( "Unknown parameter %s\n", arg.toLatin1().constData() );
119 usage( argv[0] );
120 exit(1);
121 }
122 }
123
124 int displayId = 0;
125 QRegExp r( ":[0-9]+" );
126 int m = r.indexIn( displaySpec, 0 );
127 int len = r.matchedLength();
128 if ( m >= 0 ) {
129 displayId = displaySpec.mid( m+1, len-1 ).toInt();
130 }
131 QRegExp rotRegExp( "Rot[0-9]+" );
132 m = rotRegExp.indexIn( displaySpec, 0 );
133 len = rotRegExp.matchedLength();
134 if ( m >= 0 ) {
135 rotation = displaySpec.mid( m+3, len-3 ).toInt();
136 }
137
138 signal(SIGINT, fn_quit_qvfb);
139 signal(SIGTERM, fn_quit_qvfb);
140