author | zecke <zecke> | 2004-11-03 23:02:13 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-11-03 23:02:13 (UTC) |
commit | a6adcd3869b9c9c7548290ea686bc4e78ed62fc3 (patch) (unidiff) | |
tree | 0916443be21889c567de40b90de27d34f793484d | |
parent | 07900eb7986f63e56072b1fb8fe5dbf846c8519d (diff) | |
download | opie-a6adcd3869b9c9c7548290ea686bc4e78ed62fc3.zip opie-a6adcd3869b9c9c7548290ea686bc4e78ed62fc3.tar.gz opie-a6adcd3869b9c9c7548290ea686bc4e78ed62fc3.tar.bz2 |
-Create a QPE/System channel (sysMessage:QCopChannel from QPEApplication
can't be used)
-'Forward' receiving of messages to the 'systemMessageSignal'
-rw-r--r-- | libopie2/opiecore/oapplication.cpp | 7 | ||||
-rw-r--r-- | libopie2/opiecore/oapplication.h | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/libopie2/opiecore/oapplication.cpp b/libopie2/opiecore/oapplication.cpp index 0ce61d8..0164957 100644 --- a/libopie2/opiecore/oapplication.cpp +++ b/libopie2/opiecore/oapplication.cpp | |||
@@ -1,142 +1,149 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <opie2/oapplication.h> | 30 | #include <opie2/oapplication.h> |
31 | #include <opie2/oconfig.h> | 31 | #include <opie2/oconfig.h> |
32 | #include <opie2/odebug.h> | 32 | #include <opie2/odebug.h> |
33 | 33 | ||
34 | #include <qcopchannel_qws.h> | ||
35 | |||
36 | |||
34 | #include <signal.h> | 37 | #include <signal.h> |
35 | #include <stdio.h> | 38 | #include <stdio.h> |
36 | 39 | ||
37 | using namespace Opie::Core; | 40 | using namespace Opie::Core; |
38 | 41 | ||
39 | 42 | ||
40 | OApplication* OApplication::_instance = 0; | 43 | OApplication* OApplication::_instance = 0; |
41 | 44 | ||
42 | /************************************************************************************************** | 45 | /************************************************************************************************** |
43 | * OApplicationPrivate | 46 | * OApplicationPrivate |
44 | **************************************************************************************************/ | 47 | **************************************************************************************************/ |
45 | 48 | ||
46 | namespace Opie { | 49 | namespace Opie { |
47 | namespace Core { | 50 | namespace Core { |
48 | namespace Internal { | 51 | namespace Internal { |
49 | class OApplicationPrivate | 52 | class OApplicationPrivate |
50 | { | 53 | { |
51 | public: | 54 | public: |
52 | OApplicationPrivate() {}; | 55 | OApplicationPrivate() {}; |
53 | ~OApplicationPrivate() {}; | 56 | ~OApplicationPrivate() {}; |
54 | }; | 57 | }; |
55 | } | 58 | } |
56 | 59 | ||
57 | /************************************************************************************************** | 60 | /************************************************************************************************** |
58 | * OApplication | 61 | * OApplication |
59 | **************************************************************************************************/ | 62 | **************************************************************************************************/ |
60 | OApplication::OApplication( int& argc, char** argv, Type type ) | 63 | OApplication::OApplication( int& argc, char** argv, Type type ) |
61 | :QPEApplication( argc, argv, type ), | 64 | :QPEApplication( argc, argv, type ), |
62 | _appname( QString::null ), | 65 | _appname( QString::null ), |
63 | _config( 0 ) | 66 | _config( 0 ) |
64 | { | 67 | { |
65 | init(); | 68 | init(); |
66 | } | 69 | } |
67 | 70 | ||
68 | OApplication::OApplication( int& argc, char** argv, const QCString& rAppName ) | 71 | OApplication::OApplication( int& argc, char** argv, const QCString& rAppName ) |
69 | :QPEApplication( argc, argv ), | 72 | :QPEApplication( argc, argv ), |
70 | _appname( rAppName ), | 73 | _appname( rAppName ), |
71 | _config( 0 ) | 74 | _config( 0 ) |
72 | { | 75 | { |
73 | init(); | 76 | init(); |
74 | } | 77 | } |
75 | 78 | ||
76 | 79 | ||
77 | OApplication::~OApplication() | 80 | OApplication::~OApplication() |
78 | { | 81 | { |
79 | delete d; | 82 | delete d; |
80 | if ( _config ) | 83 | if ( _config ) |
81 | delete _config; | 84 | delete _config; |
82 | OApplication::_instance = 0; | 85 | OApplication::_instance = 0; |
83 | // after deconstruction of the one-and-only application object, | 86 | // after deconstruction of the one-and-only application object, |
84 | // the construction of another object is allowed | 87 | // the construction of another object is allowed |
85 | } | 88 | } |
86 | 89 | ||
87 | 90 | ||
88 | OConfig* OApplication::config() | 91 | OConfig* OApplication::config() |
89 | { | 92 | { |
90 | if ( !_config ) | 93 | if ( !_config ) |
91 | { | 94 | { |
92 | _config = new OConfig( _appname ); | 95 | _config = new OConfig( _appname ); |
93 | } | 96 | } |
94 | return _config; | 97 | return _config; |
95 | } | 98 | } |
96 | 99 | ||
97 | 100 | ||
98 | void OApplication::init() | 101 | void OApplication::init() |
99 | { | 102 | { |
100 | d = new Internal::OApplicationPrivate(); | 103 | d = new Internal::OApplicationPrivate(); |
101 | if ( !OApplication::_instance ) | 104 | if ( !OApplication::_instance ) |
102 | { | 105 | { |
103 | OApplication::_instance = this; | 106 | OApplication::_instance = this; |
107 | |||
108 | QCopChannel *chan = new QCopChannel("QPE/System", this, "OApplication System Channel"); | ||
109 | connect(chan,SIGNAL(received(const QCString&,const QByteArray&)), | ||
110 | this,SIGNAL(systemMessageSignal(const QCString&,const QByteArray&))); | ||
104 | 111 | ||
105 | /* register SIGSEGV handler to give programs an option | 112 | /* register SIGSEGV handler to give programs an option |
106 | * to exit gracefully, e.g. save or close devices or files. | 113 | * to exit gracefully, e.g. save or close devices or files. |
107 | struct sigaction sa; | 114 | struct sigaction sa; |
108 | sa.sa_handler = ( void (*)(int) ) &segv_handler; | 115 | sa.sa_handler = ( void (*)(int) ) &segv_handler; |
109 | sa.sa_flags = SA_SIGINFO | SA_RESTART; | 116 | sa.sa_flags = SA_SIGINFO | SA_RESTART; |
110 | sigemptyset(&sa.sa_mask); | 117 | sigemptyset(&sa.sa_mask); |
111 | sigaction(SIGSEGV, &sa, NULL); | 118 | sigaction(SIGSEGV, &sa, NULL); |
112 | */ | 119 | */ |
113 | } | 120 | } |
114 | else | 121 | else |
115 | { | 122 | { |
116 | ofatal << "OApplication: Can't create more than one OApplication object. Aborting." << oendl; | 123 | ofatal << "OApplication: Can't create more than one OApplication object. Aborting." << oendl; |
117 | //FIXME exit gracefully ? | 124 | //FIXME exit gracefully ? |
118 | ::exit( -1 ); | 125 | ::exit( -1 ); |
119 | } | 126 | } |
120 | } | 127 | } |
121 | 128 | ||
122 | 129 | ||
123 | void OApplication::showMainWidget( QWidget* widget, bool nomax ) | 130 | void OApplication::showMainWidget( QWidget* widget, bool nomax ) |
124 | { | 131 | { |
125 | QPEApplication::showMainWidget( widget, nomax ); | 132 | QPEApplication::showMainWidget( widget, nomax ); |
126 | widget->setCaption( _appname ); | 133 | widget->setCaption( _appname ); |
127 | } | 134 | } |
128 | 135 | ||
129 | 136 | ||
130 | void OApplication::setTitle( const QString& title ) const | 137 | void OApplication::setTitle( const QString& title ) const |
131 | { | 138 | { |
132 | if ( mainWidget() ) | 139 | if ( mainWidget() ) |
133 | { | 140 | { |
134 | if ( !title.isNull() ) | 141 | if ( !title.isNull() ) |
135 | mainWidget()->setCaption( QString(_appname) + QString( " - " ) + title ); | 142 | mainWidget()->setCaption( QString(_appname) + QString( " - " ) + title ); |
136 | else | 143 | else |
137 | mainWidget()->setCaption( _appname ); | 144 | mainWidget()->setCaption( _appname ); |
138 | } | 145 | } |
139 | } | 146 | } |
140 | 147 | ||
141 | } | 148 | } |
142 | } | 149 | } |
diff --git a/libopie2/opiecore/oapplication.h b/libopie2/opiecore/oapplication.h index d34e6b1..709d73a 100644 --- a/libopie2/opiecore/oapplication.h +++ b/libopie2/opiecore/oapplication.h | |||
@@ -1,117 +1,128 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef OAPPLICATION_H | 30 | #ifndef OAPPLICATION_H |
31 | #define OAPPLICATION_H | 31 | #define OAPPLICATION_H |
32 | 32 | ||
33 | #define oApp Opie::Core::OApplication::oApplication() | 33 | #define oApp Opie::Core::OApplication::oApplication() |
34 | 34 | ||
35 | 35 | ||
36 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
37 | 37 | ||
38 | namespace Opie { | 38 | namespace Opie { |
39 | namespace Core { | 39 | namespace Core { |
40 | namespace Internal { | 40 | namespace Internal { |
41 | class OApplicationPrivate; | 41 | class OApplicationPrivate; |
42 | } // private class | 42 | } // private class |
43 | 43 | ||
44 | class OConfig; | 44 | class OConfig; |
45 | 45 | ||
46 | 46 | ||
47 | class OApplication : public QPEApplication | 47 | class OApplication : public QPEApplication |
48 | { | 48 | { |
49 | Q_OBJECT | 49 | Q_OBJECT |
50 | 50 | ||
51 | public: | 51 | public: |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Constructor. Compatible to QPEApplication | 54 | * Constructor. Compatible to QPEApplication |
55 | */ | 55 | */ |
56 | OApplication( int& argc, char** argv, Type type=GuiClient); | 56 | OApplication( int& argc, char** argv, Type type=GuiClient); |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Constructor. Parses command-line arguments and sets the window caption. | 59 | * Constructor. Parses command-line arguments and sets the window caption. |
60 | * | 60 | * |
61 | * @param rAppName application name. Will be used for finding the | 61 | * @param rAppName application name. Will be used for finding the |
62 | * associated message, icon and configuration files | 62 | * associated message, icon and configuration files |
63 | * | 63 | * |
64 | */ | 64 | */ |
65 | OApplication( int& argc, char** argv, const QCString& rAppName ); | 65 | OApplication( int& argc, char** argv, const QCString& rAppName ); |
66 | /** | 66 | /** |
67 | * Destructor. Destroys the application object and its children. | 67 | * Destructor. Destroys the application object and its children. |
68 | */ | 68 | */ |
69 | virtual ~OApplication(); | 69 | virtual ~OApplication(); |
70 | /** | 70 | /** |
71 | * @returns the process-wide application object | 71 | * @returns the process-wide application object |
72 | * | 72 | * |
73 | * This is similar to the global @ref QApplication pointer qApp. It | 73 | * This is similar to the global @ref QApplication pointer qApp. It |
74 | * allows access to the single global OApplication object, since | 74 | * allows access to the single global OApplication object, since |
75 | * more than one cannot be created in the same application. It | 75 | * more than one cannot be created in the same application. It |
76 | * saves you the trouble of having to pass the pointer explicitly | 76 | * saves you the trouble of having to pass the pointer explicitly |
77 | * to every function that may require it. | 77 | * to every function that may require it. |
78 | */ | 78 | */ |
79 | static OApplication* oApplication() { return _instance; }; | 79 | static OApplication* oApplication() { return _instance; }; |
80 | /** | 80 | /** |
81 | * Returns the application name as given during creation. | 81 | * Returns the application name as given during creation. |
82 | * | 82 | * |
83 | * @returns a reference to the application name | 83 | * @returns a reference to the application name |
84 | */ | 84 | */ |
85 | const QCString& appName() const { return _appname; }; | 85 | const QCString& appName() const { return _appname; }; |
86 | /** | 86 | /** |
87 | * @returns the application session config object. | 87 | * @returns the application session config object. |
88 | * | 88 | * |
89 | * @see OConfig | 89 | * @see OConfig |
90 | */ | 90 | */ |
91 | OConfig* config(); | 91 | OConfig* config(); |
92 | /** | 92 | /** |
93 | * Shows the main @a widget and sets the name of the application as window caption. | 93 | * Shows the main @a widget and sets the name of the application as window caption. |
94 | */ | 94 | */ |
95 | virtual void showMainWidget( QWidget* widget, bool nomax = false ); | 95 | virtual void showMainWidget( QWidget* widget, bool nomax = false ); |
96 | /** | 96 | /** |
97 | * Set the application title. The application title will be concatenated | 97 | * Set the application title. The application title will be concatenated |
98 | * to the application name given in the constructor. | 98 | * to the application name given in the constructor. |
99 | * | 99 | * |
100 | * @param title the title. If not given, resets caption to appname | 100 | * @param title the title. If not given, resets caption to appname |
101 | */ | 101 | */ |
102 | virtual void setTitle( const QString& title = QString::null ) const; | 102 | virtual void setTitle( const QString& title = QString::null ) const; |
103 | 103 | ||
104 | signals: | ||
105 | |||
106 | /** | ||
107 | * Emit signals when messages are received on QPE/System | ||
108 | * QCOP Channel. | ||
109 | * | ||
110 | * @param msg The QCOP Message | ||
111 | * @param data The QCOP Data | ||
112 | */ | ||
113 | void systemMessageSignal(const QCString& msg, const QByteArray& data); | ||
114 | |||
104 | protected: | 115 | protected: |
105 | void init(); | 116 | void init(); |
106 | 117 | ||
107 | private: | 118 | private: |
108 | const QCString _appname; | 119 | const QCString _appname; |
109 | static OApplication* _instance; | 120 | static OApplication* _instance; |
110 | OConfig* _config; | 121 | OConfig* _config; |
111 | Internal::OApplicationPrivate* d; | 122 | Internal::OApplicationPrivate* d; |
112 | }; | 123 | }; |
113 | 124 | ||
114 | } // Core | 125 | } // Core |
115 | } // Opie | 126 | } // Opie |
116 | 127 | ||
117 | #endif // OAPPLICATION_H | 128 | #endif // OAPPLICATION_H |