-rw-r--r-- | core/tools/quicklauncher/main.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/core/tools/quicklauncher/main.cpp b/core/tools/quicklauncher/main.cpp index 5f0d80b..fbed5a1 100644 --- a/core/tools/quicklauncher/main.cpp +++ b/core/tools/quicklauncher/main.cpp | |||
@@ -56,132 +56,135 @@ | |||
56 | 56 | ||
57 | 57 | ||
58 | using QuickPrivate::PluginLoader; | 58 | using QuickPrivate::PluginLoader; |
59 | 59 | ||
60 | static QPEApplication *app = 0; | 60 | static QPEApplication *app = 0; |
61 | static PluginLoader *loader = 0; | 61 | static PluginLoader *loader = 0; |
62 | static ApplicationInterface *appIface = 0; | 62 | static ApplicationInterface *appIface = 0; |
63 | static QGuardedPtr<QWidget> mainWindow; | 63 | static QGuardedPtr<QWidget> mainWindow; |
64 | 64 | ||
65 | #ifdef _OS_LINUX_ | 65 | #ifdef _OS_LINUX_ |
66 | static char **argv0 = 0; | 66 | static char **argv0 = 0; |
67 | static int argv_lth; | 67 | static int argv_lth; |
68 | extern char **environ; | 68 | extern char **environ; |
69 | #ifndef SPT_BUFSIZE | 69 | #ifndef SPT_BUFSIZE |
70 | #define SPT_BUFSIZE 2048 | 70 | #define SPT_BUFSIZE 2048 |
71 | #endif | 71 | #endif |
72 | #include <stdarg.h> | 72 | #include <stdarg.h> |
73 | void setproctitle (const char *fmt,...) { | 73 | void setproctitle (const char *fmt,...) { |
74 | int i; | 74 | int i; |
75 | char buf[SPT_BUFSIZE]; | 75 | char buf[SPT_BUFSIZE]; |
76 | va_list ap; | 76 | va_list ap; |
77 | 77 | ||
78 | if (!argv0) | 78 | if (!argv0) |
79 | return; | 79 | return; |
80 | 80 | ||
81 | va_start(ap, fmt); | 81 | va_start(ap, fmt); |
82 | (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap); | 82 | (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap); |
83 | va_end(ap); | 83 | va_end(ap); |
84 | 84 | ||
85 | i = strlen (buf); | 85 | i = strlen (buf); |
86 | if (i > argv_lth - 2) { | 86 | if (i > argv_lth - 2) { |
87 | i = argv_lth - 2; | 87 | i = argv_lth - 2; |
88 | buf[i] = '\0'; | 88 | buf[i] = '\0'; |
89 | } | 89 | } |
90 | 90 | ||
91 | memset(argv0[0], '\0', argv_lth); /* clear the memory area */ | 91 | memset(argv0[0], '\0', argv_lth); /* clear the memory area */ |
92 | (void) strcpy (argv0[0], buf); | 92 | (void) strcpy (argv0[0], buf); |
93 | 93 | ||
94 | argv0[1] = NULL; | 94 | argv0[1] = NULL; |
95 | } | 95 | } |
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | 98 | ||
99 | class QuickLauncher : public QObject | 99 | class QuickLauncher : public QObject |
100 | { | 100 | { |
101 | Q_OBJECT | 101 | Q_OBJECT |
102 | public: | 102 | public: |
103 | QuickLauncher() : QObject() | 103 | QuickLauncher() : QObject() |
104 | { | 104 | { |
105 | QCString ch("QPE/QuickLauncher-"); | 105 | QCString ch("QPE/QuickLauncher-"); |
106 | ch += QString::number(getpid()); | 106 | ch += QString::number(getpid()); |
107 | qlChannel = new QCopChannel( ch, this); | 107 | qlChannel = new QCopChannel( ch, this); |
108 | connect( qlChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 108 | connect( qlChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
109 | this, SLOT(message(const QCString&,const QByteArray&)) ); | 109 | this, SLOT(message(const QCString&,const QByteArray&)) ); |
110 | } | 110 | } |
111 | 111 | ||
112 | static void exec( int /*argc*/, char **argv ) | 112 | static void exec( int /*argc*/, char **argv ) |
113 | { | 113 | { |
114 | QString appName = argv[0]; | 114 | QString appName = argv[0]; |
115 | int sep = appName.findRev( '/' ); | 115 | int sep = appName.findRev( '/' ); |
116 | if ( sep > 0 ) | 116 | if ( sep > 0 ) |
117 | appName = appName.mid( sep+1 ); | 117 | appName = appName.mid( sep+1 ); |
118 | 118 | ||
119 | appIface = 0; | 119 | appIface = 0; |
120 | if ( loader->queryInterface(appName, IID_QtopiaApplication, (QUnknownInterface**)&appIface) == QS_OK ) { | 120 | if ( loader->queryInterface(appName, IID_QtopiaApplication, (QUnknownInterface**)&appIface) != QS_OK ) { |
121 | mainWindow = appIface->createMainWindow( appName ); | 121 | owarn << "Plugin does not support QuickLauncher interface" << oendl; |
122 | exit(-1); | ||
122 | } | 123 | } |
123 | 124 | ||
125 | mainWindow = appIface->createMainWindow( appName ); | ||
126 | |||
124 | if ( mainWindow ) { | 127 | if ( mainWindow ) { |
125 | if ( mainWindow->metaObject()->slotNames().contains("setDocument(const QString&)") ) { | 128 | if ( mainWindow->metaObject()->slotNames().contains("setDocument(const QString&)") ) { |
126 | app->showMainDocumentWidget( mainWindow ); | 129 | app->showMainDocumentWidget( mainWindow ); |
127 | } else { | 130 | } else { |
128 | app->showMainWidget( mainWindow ); | 131 | app->showMainWidget( mainWindow ); |
129 | } | 132 | } |
130 | } else { | 133 | } else { |
131 | owarn << "Could not create application main window" << oendl; | 134 | owarn << "Could not create application main window" << oendl; |
132 | exit(-1); | 135 | exit(-1); |
133 | } | 136 | } |
134 | } | 137 | } |
135 | 138 | ||
136 | private slots: | 139 | private slots: |
137 | void message(const QCString &msg, const QByteArray & data) | 140 | void message(const QCString &msg, const QByteArray & data) |
138 | { | 141 | { |
139 | QStrList argList; | 142 | QStrList argList; |
140 | 143 | ||
141 | if ( msg == "execute(QStrList)" ) { | 144 | if ( msg == "execute(QStrList)" ) { |
142 | delete qlChannel; | 145 | delete qlChannel; |
143 | QDataStream stream( data, IO_ReadOnly ); | 146 | QDataStream stream( data, IO_ReadOnly ); |
144 | QStrList argList; | 147 | QStrList argList; |
145 | stream >> argList; | 148 | stream >> argList; |
146 | odebug << "QuickLauncher execute: " << argList.at(0) << oendl; | 149 | odebug << "QuickLauncher execute: " << argList.at(0) << oendl; |
147 | doQuickLaunch( argList ); | 150 | doQuickLaunch( argList ); |
148 | delete this; | 151 | delete this; |
149 | } else if ( msg == "execute(QString)" ) { | 152 | } else if ( msg == "execute(QString)" ) { |
150 | delete qlChannel; | 153 | delete qlChannel; |
151 | QDataStream stream( data, IO_ReadOnly ); | 154 | QDataStream stream( data, IO_ReadOnly ); |
152 | QString arg; | 155 | QString arg; |
153 | stream >> arg; | 156 | stream >> arg; |
154 | odebug << "QuickLauncher execute: " << arg << oendl; | 157 | odebug << "QuickLauncher execute: " << arg << oendl; |
155 | QStrList argList; | 158 | QStrList argList; |
156 | argList.append( arg.utf8() ); | 159 | argList.append( arg.utf8() ); |
157 | doQuickLaunch( argList ); | 160 | doQuickLaunch( argList ); |
158 | delete this; | 161 | delete this; |
159 | } | 162 | } |
160 | } | 163 | } |
161 | 164 | ||
162 | private: | 165 | private: |
163 | void doQuickLaunch( QStrList &argList ) | 166 | void doQuickLaunch( QStrList &argList ) |
164 | { | 167 | { |
165 | static int myargc = argList.count(); | 168 | static int myargc = argList.count(); |
166 | static char **myargv = new char *[myargc + 1]; | 169 | static char **myargv = new char *[myargc + 1]; |
167 | 170 | ||
168 | for ( int j = 0; j < myargc; j++ ) { | 171 | for ( int j = 0; j < myargc; j++ ) { |
169 | myargv[j] = new char [strlen(argList.at(j))+1]; | 172 | myargv[j] = new char [strlen(argList.at(j))+1]; |
170 | strcpy( myargv[j], argList.at(j) ); | 173 | strcpy( myargv[j], argList.at(j) ); |
171 | } | 174 | } |
172 | 175 | ||
173 | myargv[myargc] = NULL; | 176 | myargv[myargc] = NULL; |
174 | #ifdef _OS_LINUX_ | 177 | #ifdef _OS_LINUX_ |
175 | // Change name of process | 178 | // Change name of process |
176 | setproctitle(myargv[0]); | 179 | setproctitle(myargv[0]); |
177 | prctl( PR_SET_NAME, (unsigned long)myargv[0], 0, 0, 0 ); | 180 | prctl( PR_SET_NAME, (unsigned long)myargv[0], 0, 0, 0 ); |
178 | #endif | 181 | #endif |
179 | 182 | ||
180 | connect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); | 183 | connect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); |
181 | app->exit_loop(); | 184 | app->exit_loop(); |
182 | app->initApp( myargc, myargv ); | 185 | app->initApp( myargc, myargv ); |
183 | exec( myargc, myargv ); | 186 | exec( myargc, myargv ); |
184 | } | 187 | } |
185 | 188 | ||
186 | private: | 189 | private: |
187 | QCopChannel *qlChannel; | 190 | QCopChannel *qlChannel; |