|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the tools applications of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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 |
|
53 QT_BEGIN_NAMESPACE |
|
54 |
|
55 void fn_quit_qvfb(int) |
|
56 { |
|
57 // pretend that we have quit normally |
|
58 qApp->quit(); |
|
59 } |
|
60 |
|
61 |
|
62 void 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 } |
|
68 int qvfb_protocol = 0; |
|
69 |
|
70 int 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 |
|
141 QVFb mw( displayId, width, height, depth, rotation, skin, displayType ); |
|
142 mw.setZoom(zoom); |
|
143 //app.setMainWidget( &mw ); |
|
144 mw.enableCursor(cursor); |
|
145 mw.show(); |
|
146 |
|
147 return app.exec(); |
|
148 } |
|
149 |
|
150 QT_END_NAMESPACE |
|
151 |
|
152 int main( int argc, char *argv[] ) |
|
153 { |
|
154 return QT_PREPEND_NAMESPACE(runQVfb)(argc, argv); |
|
155 } |