source: trunk/tools/designer/app/main.cpp@ 198

Last change on this file since 198 was 197, checked in by rudi, 14 years ago

Added QtDesigner

File size: 6.1 KB
Line 
1/**********************************************************************
2** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
3**
4** This file is part of Qt Designer.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
21**
22** Contact info@trolltech.com if any conditions of this licensing are
23** not clear to you.
24**
25**********************************************************************/
26
27#include "qplatformdefs.h"
28
29// SCO OpenServer redefines raise -> kill
30#if defined(raise)
31# undef raise
32#endif
33
34#include "mainwindow.h"
35#include "formwindow.h"
36
37#include "designerapp.h"
38
39#include <qtextstream.h>
40#include <qobjectlist.h>
41#include <qsettings.h>
42#include <qsplashscreen.h>
43#include <qdir.h>
44
45#include <stdlib.h>
46#include <signal.h>
47
48// SCO OpenServer redefines raise -> kill
49#if defined(raise)
50# undef raise
51#endif
52
53#if defined(Q_WS_WIN)
54#include <qt_windows.h>
55#include <process.h>
56#endif
57
58#if defined(Q_WS_PM)
59#include <qt_os2.h>
60#include <unistd.h>
61#endif
62
63#if defined(Q_OS_UNIX)
64#if defined(Q_C_CALLBACKS)
65extern "C" {
66#endif
67
68static void signalHandler( QT_SIGNAL_ARGS )
69{
70 QFile f( QDir::homeDirPath() + "/.designerargs" );
71 f.open( IO_ReadOnly );
72 QString args;
73 f.readLine( args, f.size() );
74 QStringList lst = QStringList::split( " ", args );
75 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
76 QString arg = (*it).stripWhiteSpace();
77 if ( arg[0] != '-' ) {
78 QObjectList* l = MainWindow::self->queryList( "FormWindow" );
79 FormWindow* fw = (FormWindow*) l->first();
80#if 0 // ### what's this dead code for?
81 FormWindow* totop;
82#endif
83 bool haveit = FALSE;
84 while ( fw ) {
85 haveit = haveit || fw->fileName() == arg;
86#if 0 // ### what's this dead code for?
87 if ( haveit )
88 totop = fw;
89#endif
90 fw = (FormWindow*) l->next();
91 }
92 if ( !haveit )
93 MainWindow::self->openFormWindow( arg );
94 }
95 }
96 MainWindow::self->raise();
97 MainWindow::self->setActiveWindow();
98}
99
100#if defined(Q_C_CALLBACKS)
101}
102#endif
103
104#endif
105
106#if defined(Q_C_CALLBACKS)
107extern "C" {
108#endif
109
110static void exitHandler( QT_SIGNAL_ARGS )
111{
112 QDir d( QDir::homeDirPath() );
113 d.remove( ".designerpid" );
114 exit( -1 );
115}
116
117#if defined(Q_C_CALLBACKS)
118}
119#endif
120
121int main( int argc, char *argv[] )
122{
123 QApplication::setColorSpec( QApplication::ManyColor );
124
125 DesignerApplication a( argc, argv );
126
127 DesignerApplication::setOverrideCursor( Qt::WaitCursor );
128
129 bool creatPid = FALSE;
130 if ( a.argc() > 1 ) {
131 QString arg1 = a.argv()[ 1 ];
132 if ( arg1 == "-client" ) {
133 QFile pf( QDir::homeDirPath() + "/.designerpid" );
134 if ( pf.exists() && pf.open( IO_ReadOnly ) ) {
135 QString pidStr;
136 pf.readLine( pidStr, pf.size() );
137 QFile f( QDir::homeDirPath() + "/.designerargs" );
138 f.open( IO_WriteOnly );
139 QTextStream ts( &f );
140 for ( int i = 1; i < a.argc(); ++i )
141 ts << a.argv()[ i ] << " ";
142 ts << endl;
143 f.close();
144#if defined(Q_OS_UNIX)
145 if ( kill( pidStr.toInt(), SIGUSR1 ) == -1 )
146 creatPid = TRUE;
147 else
148 return 0;
149#elif defined(Q_OS_WIN32)
150 if ( !GetProcessVersion( pidStr.toUInt() ) ) {
151 creatPid = TRUE;
152 } else {
153 if ( a.winVersion() & Qt::WV_NT_based )
154 SendMessage( HWND_BROADCAST, RegisterWindowMessage((TCHAR*)"QT_DESIGNER_OPEN_FILE"), 0, 0 );
155 else
156 SendMessage( HWND_BROADCAST, RegisterWindowMessageA("QT_DESIGNER_OPEN_FILE"), 0, 0 );
157 return 0;
158 }
159#endif
160 } else {
161 creatPid = TRUE;
162 }
163 } else if(arg1 == "-debug_stderr") {
164 extern bool debugToStderr; //outputwindow.cpp
165 debugToStderr = TRUE;
166 }
167 }
168
169 if ( creatPid ) {
170 QFile pf( QDir::homeDirPath() + "/.designerpid" );
171 pf.open( IO_WriteOnly );
172 QTextStream ts( &pf );
173#if defined(Q_OS_UNIX)
174 signal( SIGUSR1, signalHandler );
175#endif
176 ts << getpid() << endl;
177
178 pf.close();
179 signal( SIGABRT, exitHandler );
180 signal( SIGFPE, exitHandler );
181 signal( SIGILL, exitHandler );
182 signal( SIGINT, exitHandler );
183 signal( SIGSEGV, exitHandler );
184 signal( SIGTERM, exitHandler );
185 }
186
187 extern void qInitImages_designercore();
188 qInitImages_designercore();
189
190 QSettings config;
191 QString keybase = DesignerApplication::settingsKey();
192 config.insertSearchPath( QSettings::Windows, "/Trolltech" );
193 QStringList pluginPaths = config.readListEntry( keybase + "PluginPaths" );
194 if (pluginPaths.count())
195 QApplication::setLibraryPaths(pluginPaths);
196
197 QSplashScreen *splash = a.showSplash();
198
199 MainWindow *mw = new MainWindow( creatPid );
200 a.setMainWidget( mw );
201#if defined(QT_NON_COMMERCIAL)
202 mw->setCaption( "Qt Designer by Trolltech for non-commercial use" );
203#else
204 mw->setCaption( "Qt Designer by Trolltech" );
205#endif
206 if ( config.readBoolEntry( keybase + "Geometries/MainwindowMaximized", FALSE ) ) {
207 int x = config.readNumEntry( keybase + "Geometries/MainwindowX", 0 );
208 int y = config.readNumEntry( keybase + "Geometries/MainwindowY", 0 );
209 mw->move( x, y );
210 mw->showMaximized();
211 } else {
212 mw->show();
213 }
214 if ( splash )
215 splash->finish( mw );
216 delete splash;
217
218 QApplication::restoreOverrideCursor();
219 for ( int i = 1; i < a.argc(); ++i ) {
220 QString arg = a.argv()[ i ];
221 if ( arg[0] != '-' )
222 mw->fileOpen( "", "", arg );
223 }
224
225 return a.exec();
226}
Note: See TracBrowser for help on using the repository browser.