| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 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 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 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 | ** 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 have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include "qvfb.h" | 
|---|
| 43 |  | 
|---|
| 44 | #include <QApplication> | 
|---|
| 45 | #include <QRegExp> | 
|---|
| 46 | #include <QLibraryInfo> | 
|---|
| 47 | #include <QLocale> | 
|---|
| 48 | #include <QTranslator> | 
|---|
| 49 | #include <stdlib.h> | 
|---|
| 50 | #include <stdio.h> | 
|---|
| 51 | #include <signal.h> | 
|---|
| 52 | #ifdef Q_WS_X11 | 
|---|
| 53 | #include <QX11Info> | 
|---|
| 54 | #endif | 
|---|
| 55 |  | 
|---|
| 56 | QT_BEGIN_NAMESPACE | 
|---|
| 57 |  | 
|---|
| 58 | void fn_quit_qvfb(int) | 
|---|
| 59 | { | 
|---|
| 60 | // pretend that we have quit normally | 
|---|
| 61 | qApp->quit(); | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 |  | 
|---|
| 65 | void usage( const char *app ) | 
|---|
| 66 | { | 
|---|
| 67 | printf( "Usage: %s [-width width] [-height height] [-depth depth] [-zoom zoom]" | 
|---|
| 68 | "[-mmap] [-nocursor] [-qwsdisplay :id] [-x11display :id] [-skin skindirectory]\n" | 
|---|
| 69 | "Supported depths: 1, 4, 8, 12, 15, 16, 18, 24, 32\n", app ); | 
|---|
| 70 | } | 
|---|
| 71 | int qvfb_protocol = 0; | 
|---|
| 72 |  | 
|---|
| 73 | int runQVfb( int argc, char *argv[] ) | 
|---|
| 74 | { | 
|---|
| 75 | Q_INIT_RESOURCE(qvfb); | 
|---|
| 76 |  | 
|---|
| 77 | QApplication app( argc, argv ); | 
|---|
| 78 |  | 
|---|
| 79 | QTranslator translator; | 
|---|
| 80 | QTranslator qtTranslator; | 
|---|
| 81 | QString sysLocale = QLocale::system().name(); | 
|---|
| 82 | QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); | 
|---|
| 83 | if (translator.load(QLatin1String("qvfb_") + sysLocale, resourceDir) | 
|---|
| 84 | && qtTranslator.load(QLatin1String("qt_") + sysLocale, resourceDir)) { | 
|---|
| 85 | app.installTranslator(&translator); | 
|---|
| 86 | app.installTranslator(&qtTranslator); | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | int width = 0; | 
|---|
| 90 | int height = 0; | 
|---|
| 91 | int depth = -32; // default, but overridable by skin | 
|---|
| 92 | bool depthSet = false; | 
|---|
| 93 | int rotation = 0; | 
|---|
| 94 | bool cursor = true; | 
|---|
| 95 | QVFb::DisplayType displayType = QVFb::QWS; | 
|---|
| 96 | double zoom = 1.0; | 
|---|
| 97 | QString displaySpec( ":0" ); | 
|---|
| 98 | QString skin; | 
|---|
| 99 |  | 
|---|
| 100 | for ( int i = 1; i < argc; i++ ){ | 
|---|
| 101 | QString arg = argv[i]; | 
|---|
| 102 | if ( arg == "-width" ) { | 
|---|
| 103 | width = atoi( argv[++i] ); | 
|---|
| 104 | } else if ( arg == "-height" ) { | 
|---|
| 105 | height = atoi( argv[++i] ); | 
|---|
| 106 | } else if ( arg == "-skin" ) { | 
|---|
| 107 | skin = argv[++i]; | 
|---|
| 108 | } else if ( arg == "-depth" ) { | 
|---|
| 109 | depth = atoi( argv[++i] ); | 
|---|
| 110 | depthSet = true; | 
|---|
| 111 | } else if ( arg == "-nocursor" ) { | 
|---|
| 112 | cursor = false; | 
|---|
| 113 | } else if ( arg == "-mmap" ) { | 
|---|
| 114 | qvfb_protocol = 1; | 
|---|
| 115 | } else if ( arg == "-zoom" ) { | 
|---|
| 116 | zoom = atof( argv[++i] ); | 
|---|
| 117 | } else if ( arg == "-qwsdisplay" ) { | 
|---|
| 118 | displaySpec = argv[++i]; | 
|---|
| 119 | displayType = QVFb::QWS; | 
|---|
| 120 | #ifdef Q_WS_X11 | 
|---|
| 121 | } else if ( arg == "-x11display" ) { | 
|---|
| 122 | displaySpec = argv[++i]; | 
|---|
| 123 | displayType = QVFb::X11; | 
|---|
| 124 |  | 
|---|
| 125 | // Usually only the default X11 depth will work with Xnest, | 
|---|
| 126 | // so override the default of 32 with the actual X11 depth. | 
|---|
| 127 | if (!depthSet) | 
|---|
| 128 | depth = -QX11Info::appDepth(); // default, but overridable by skin | 
|---|
| 129 | #endif | 
|---|
| 130 | } else { | 
|---|
| 131 | printf( "Unknown parameter %s\n", arg.toLatin1().constData() ); | 
|---|
| 132 | usage( argv[0] ); | 
|---|
| 133 | exit(1); | 
|---|
| 134 | } | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | int displayId = 0; | 
|---|
| 138 | QRegExp r( ":[0-9]+" ); | 
|---|
| 139 | int m = r.indexIn( displaySpec, 0 ); | 
|---|
| 140 | int len = r.matchedLength(); | 
|---|
| 141 | if ( m >= 0 ) { | 
|---|
| 142 | displayId = displaySpec.mid( m+1, len-1 ).toInt(); | 
|---|
| 143 | } | 
|---|
| 144 | QRegExp rotRegExp( "Rot[0-9]+" ); | 
|---|
| 145 | m = rotRegExp.indexIn( displaySpec, 0 ); | 
|---|
| 146 | len = rotRegExp.matchedLength(); | 
|---|
| 147 | if ( m >= 0 ) { | 
|---|
| 148 | rotation = displaySpec.mid( m+3, len-3 ).toInt(); | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | signal(SIGINT, fn_quit_qvfb); | 
|---|
| 152 | signal(SIGTERM, fn_quit_qvfb); | 
|---|
| 153 |  | 
|---|
| 154 | QVFb mw( displayId, width, height, depth, rotation, skin, displayType ); | 
|---|
| 155 | mw.setZoom(zoom); | 
|---|
| 156 | //app.setMainWidget( &mw ); | 
|---|
| 157 | mw.enableCursor(cursor); | 
|---|
| 158 | mw.show(); | 
|---|
| 159 |  | 
|---|
| 160 | return app.exec(); | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 | QT_END_NAMESPACE | 
|---|
| 164 |  | 
|---|
| 165 | int main( int argc, char *argv[] ) | 
|---|
| 166 | { | 
|---|
| 167 | return QT_PREPEND_NAMESPACE(runQVfb)(argc, argv); | 
|---|
| 168 | } | 
|---|