summaryrefslogtreecommitdiff
path: root/core
authorzecke <zecke>2004-09-26 13:42:38 (UTC)
committer zecke <zecke>2004-09-26 13:42:38 (UTC)
commit77441b90e9b5a4a23b080e7ac53a512abe96f8a9 (patch) (unidiff)
tree1e2d8eef39f651561f817042fe4319e86156b7a0 /core
parent358c159e5d4f28eedfbd8e539e4420324c565eba (diff)
downloadopie-77441b90e9b5a4a23b080e7ac53a512abe96f8a9.zip
opie-77441b90e9b5a4a23b080e7ac53a512abe96f8a9.tar.gz
opie-77441b90e9b5a4a23b080e7ac53a512abe96f8a9.tar.bz2
Fix the indentation...
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/tools/quicklauncher/main.cpp227
1 files changed, 115 insertions, 112 deletions
diff --git a/core/tools/quicklauncher/main.cpp b/core/tools/quicklauncher/main.cpp
index b1befce..fb2ca44 100644
--- a/core/tools/quicklauncher/main.cpp
+++ b/core/tools/quicklauncher/main.cpp
@@ -68,7 +68,7 @@ void setproctitle (const char *fmt,...) {
68 va_list ap; 68 va_list ap;
69 69
70 if (!argv0) 70 if (!argv0)
71 return; 71 return;
72 72
73 va_start(ap, fmt); 73 va_start(ap, fmt);
74 (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap); 74 (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap);
@@ -76,9 +76,10 @@ void setproctitle (const char *fmt,...) {
76 76
77 i = strlen (buf); 77 i = strlen (buf);
78 if (i > argv_lth - 2) { 78 if (i > argv_lth - 2) {
79 i = argv_lth - 2; 79 i = argv_lth - 2;
80 buf[i] = '\0'; 80 buf[i] = '\0';
81 } 81 }
82
82 memset(argv0[0], '\0', argv_lth); /* clear the memory area */ 83 memset(argv0[0], '\0', argv_lth); /* clear the memory area */
83 (void) strcpy (argv0[0], buf); 84 (void) strcpy (argv0[0], buf);
84 85
@@ -93,81 +94,84 @@ class QuickLauncher : public QObject
93public: 94public:
94 QuickLauncher() : QObject() 95 QuickLauncher() : QObject()
95 { 96 {
96 QCString ch("QPE/QuickLauncher-"); 97 QCString ch("QPE/QuickLauncher-");
97 ch += QString::number(getpid()); 98 ch += QString::number(getpid());
98 qlChannel = new QCopChannel( ch, this); 99 qlChannel = new QCopChannel( ch, this);
99 connect( qlChannel, SIGNAL(received(const QCString&,const QByteArray&)), 100 connect( qlChannel, SIGNAL(received(const QCString&,const QByteArray&)),
100 this, SLOT(message(const QCString&,const QByteArray&)) ); 101 this, SLOT(message(const QCString&,const QByteArray&)) );
101 } 102 }
102 103
103 static void exec( int /*argc*/, char **argv ) 104 static void exec( int /*argc*/, char **argv )
104 { 105 {
105 QString appName = argv[0]; 106 QString appName = argv[0];
106 int sep = appName.findRev( '/' ); 107 int sep = appName.findRev( '/' );
107 if ( sep > 0 ) 108 if ( sep > 0 )
108 appName = appName.mid( sep+1 ); 109 appName = appName.mid( sep+1 );
110
111 appIface = 0;
112 if ( loader->queryInterface(appName, IID_QtopiaApplication, (QUnknownInterface**)&appIface) == QS_OK ) {
113 mainWindow = appIface->createMainWindow( appName );
114 }
109 115
110 appIface = 0; 116 if ( mainWindow ) {
111 if ( loader->queryInterface(appName, IID_QtopiaApplication, (QUnknownInterface**)&appIface) == QS_OK ) { 117 if ( mainWindow->metaObject()->slotNames().contains("setDocument(const QString&)") ) {
112 mainWindow = appIface->createMainWindow( appName ); 118 app->showMainDocumentWidget( mainWindow );
113 } 119 } else {
114 if ( mainWindow ) { 120 app->showMainWidget( mainWindow );
115 if ( mainWindow->metaObject()->slotNames().contains("setDocument(const QString&)") ) { 121 }
116 app->showMainDocumentWidget( mainWindow );
117 } else { 122 } else {
118 app->showMainWidget( mainWindow ); 123 owarn << "Could not create application main window" << oendl;
124 exit(-1);
119 } 125 }
120 } else {
121 owarn << "Could not create application main window" << oendl;
122 exit(-1);
123 }
124 } 126 }
125 127
126private slots: 128private slots:
127 void message(const QCString &msg, const QByteArray & data) 129 void message(const QCString &msg, const QByteArray & data)
128 { 130 {
129 QStrList argList;
130
131 if ( msg == "execute(QStrList)" ) {
132 delete qlChannel;
133 QDataStream stream( data, IO_ReadOnly );
134 QStrList argList;
135 stream >> argList;
136 odebug << "QuickLauncher execute: " << argList.at(0) << oendl;
137 doQuickLaunch( argList );
138 delete this;
139 } else if ( msg == "execute(QString)" ) {
140 delete qlChannel;
141 QDataStream stream( data, IO_ReadOnly );
142 QString arg;
143 stream >> arg;
144 odebug << "QuickLauncher execute: " << arg << oendl;
145 QStrList argList; 131 QStrList argList;
146 argList.append( arg.utf8() ); 132
147 doQuickLaunch( argList ); 133 if ( msg == "execute(QStrList)" ) {
148 delete this; 134 delete qlChannel;
149 } 135 QDataStream stream( data, IO_ReadOnly );
136 QStrList argList;
137 stream >> argList;
138 odebug << "QuickLauncher execute: " << argList.at(0) << oendl;
139 doQuickLaunch( argList );
140 delete this;
141 } else if ( msg == "execute(QString)" ) {
142 delete qlChannel;
143 QDataStream stream( data, IO_ReadOnly );
144 QString arg;
145 stream >> arg;
146 odebug << "QuickLauncher execute: " << arg << oendl;
147 QStrList argList;
148 argList.append( arg.utf8() );
149 doQuickLaunch( argList );
150 delete this;
151 }
150 } 152 }
151 153
152private: 154private:
153 void doQuickLaunch( QStrList &argList ) 155 void doQuickLaunch( QStrList &argList )
154 { 156 {
155 static int myargc = argList.count(); 157 static int myargc = argList.count();
156 static char **myargv = new char *[myargc + 1]; 158 static char **myargv = new char *[myargc + 1];
157 for ( int j = 0; j < myargc; j++ ) { 159
158 myargv[j] = new char [strlen(argList.at(j))+1]; 160 for ( int j = 0; j < myargc; j++ ) {
159 strcpy( myargv[j], argList.at(j) ); 161 myargv[j] = new char [strlen(argList.at(j))+1];
160 } 162 strcpy( myargv[j], argList.at(j) );
161 myargv[myargc] = NULL; 163 }
164
165 myargv[myargc] = NULL;
162#ifdef _OS_LINUX_ 166#ifdef _OS_LINUX_
163 // Change name of process 167 // Change name of process
164 setproctitle(myargv[0]); 168 setproctitle(myargv[0]);
165#endif 169#endif
166 170
167 connect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); 171 connect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit()));
168 app->exit_loop(); 172 app->exit_loop();
169 app->initApp( myargc, myargv ); 173 app->initApp( myargc, myargv );
170 exec( myargc, myargv ); 174 exec( myargc, myargv );
171 } 175 }
172 176
173private: 177private:
@@ -184,78 +188,77 @@ int main( int argc, char** argv )
184 188
185 QCString arg0 = argv[0]; 189 QCString arg0 = argv[0];
186 int sep = arg0.findRev( '/' ); 190 int sep = arg0.findRev( '/' );
191
187 if ( sep > 0 ) 192 if ( sep > 0 )
188 arg0 = arg0.mid( sep+1 ); 193 arg0 = arg0.mid( sep+1 );
194
189 if ( arg0 != "quicklauncher" ) { 195 if ( arg0 != "quicklauncher" ) {
190 odebug << "QuickLauncher invoked as: " << arg0.data() << oendl; 196 odebug << "QuickLauncher invoked as: " << arg0.data() << oendl;
191 QuickLauncher::exec( argc, argv ); 197 QuickLauncher::exec( argc, argv );
192 } else { 198 } else {
193#ifdef _OS_LINUX_ 199#ifdef _OS_LINUX_
194 // Setup to change proc title 200 // Setup to change proc title
195 int i; 201 int i;
196 char **envp = environ; 202 char **envp = environ;
197 /* Move the environment so we can reuse the memory. 203 /* Move the environment so we can reuse the memory.
198 * (Code borrowed from sendmail.) */ 204 * (Code borrowed from sendmail.) */
199 for (i = 0; envp[i] != NULL; i++) 205 for (i = 0; envp[i] != NULL; i++)
200 continue; 206 continue;
201 environ = (char **) malloc(sizeof(char *) * (i + 1)); 207 environ = (char **) malloc(sizeof(char *) * (i + 1));
202 if (environ == NULL) 208 if (environ == NULL)
203 return -1; 209 return -1;
204 for (i = 0; envp[i] != NULL; i++) 210 for (i = 0; envp[i] != NULL; i++)
205 if ((environ[i] = strdup(envp[i])) == NULL) 211 if ((environ[i] = strdup(envp[i])) == NULL)
206 return -1; 212 return -1;
207 environ[i] = NULL; 213 environ[i] = NULL;
208 214
209 argv0 = argv; 215 argv0 = argv;
210 if (i > 0) 216 if (i > 0)
211 argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0]; 217 argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0];
212 else 218 else
213 argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0]; 219 argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0];
214#endif 220#endif
215 (void)new QuickLauncher(); 221 (void)new QuickLauncher();
216 odebug << "QuickLauncher running" << oendl; 222 odebug << "QuickLauncher running" << oendl;
217 // Pre-load default fonts 223 // Pre-load default fonts
218 QFontMetrics fm( QApplication::font() ); 224 QFontMetrics fm( QApplication::font() );
219 fm.ascent(); // causes font load. 225 fm.ascent(); // causes font load.
220 QFont f( QApplication::font() ); 226 QFont f( QApplication::font() );
221 f.setWeight( QFont::Bold ); 227 f.setWeight( QFont::Bold );
222 QFontMetrics fmb( f ); 228 QFontMetrics fmb( f );
223 fmb.ascent(); // causes font load. 229 fmb.ascent(); // causes font load.
224 230
225 // Each of the following force internal structures/internal 231 // Each of the following force internal structures/internal
226 // initialization to be performed. This may mean allocating 232 // initialization to be performed. This may mean allocating
227 // memory that is not needed by all applications. 233 // memory that is not needed by all applications.
228#if 0 234 Resource::loadIconSet("new"); // do internal init
229 TimeZone::current().isValid(); // popuplate timezone cache
230 TimeString::currentDateFormat(); // create internal structures
231 TimeString::currentAMPM();
232#endif
233 Resource::loadIconSet("new"); // do internal init
234 235
235 /* make sure libopie gets lined in */ 236 /* make sure libopie gets lined in */
236 { 237 {
237 Opie::Ui::OWait item; 238 Opie::Ui::OWait item;
238 } 239 }
239 240
240 // Create a widget to force initialization of title bar images, etc. 241 // Create a widget to force initialization of title bar images, etc.
241 QObject::disconnect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); 242 QObject::disconnect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit()));
242 QWidget *w = new QWidget(0,0,Qt::WDestructiveClose|Qt::WStyle_ContextHelp|Qt::WStyle_Tool); 243 QWidget *w = new QWidget(0,0,Qt::WDestructiveClose|Qt::WStyle_ContextHelp|Qt::WStyle_Tool);
243 w->setGeometry( -100, -100, 10, 10 ); 244 w->setGeometry( -100, -100, 10, 10 );
244 w->show(); 245 w->show();
245 QTimer::singleShot( 0, w, SLOT(close()) ); 246 QTimer::singleShot( 0, w, SLOT(close()) );
246 247
247 app->enter_loop(); 248 app->enter_loop();
248 } 249 }
249 250
250 int rv = app->exec(); 251 int rv = app->exec();
251 252
252 if ( mainWindow ) 253 if ( mainWindow )
253 delete (QWidget*)mainWindow; 254 delete (QWidget*)mainWindow;
254
255 delete app; 255 delete app;
256
256 if ( appIface ) 257 if ( appIface )
257 loader->releaseInterface( appIface ); 258 loader->releaseInterface( appIface );
258 delete loader; 259 delete loader;
260
261
259 // Neither QLibrary nor my Dropin is a QObject and they don't depend 262 // Neither QLibrary nor my Dropin is a QObject and they don't depend
260 // on a qApp so we destroy QWidget::destroyMapper() without 263 // on a qApp so we destroy QWidget::destroyMapper() without
261 // crashing the app 264 // crashing the app
@@ -264,10 +267,10 @@ int main( int argc, char** argv )
264 // in the apps and on destructing these objects are not available 267 // in the apps and on destructing these objects are not available
265 // anymore. In future fix up the apps but for now 268 // anymore. In future fix up the apps but for now
266 // we just skip deletion and hope things go well -zecke 269 // we just skip deletion and hope things go well -zecke
267// delete app; 270 // delete app;
268 // hack instead -zecke 271 // hack instead -zecke
269// delete app->pidChannel; 272 // delete app->pidChannel;
270// app->pidChannel = 0; 273 // app->pidChannel = 0;
271 274
272 return rv; 275 return rv;
273} 276}