Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

oapplication.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
00004               =.
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #include <opie2/oapplication.h>
00031 #include <opie2/oconfig.h>
00032 #include <opie2/odebug.h>
00033 
00034 #include <signal.h>
00035 #include <stdio.h>
00036 
00037 using namespace Opie::Core;
00038 
00039 
00040 OApplication* OApplication::_instance = 0;
00041 
00042 /**************************************************************************************************
00043  * OApplicationPrivate
00044  **************************************************************************************************/
00045 
00046 namespace Opie {
00047 namespace Core {
00048 namespace Internal {
00049 class OApplicationPrivate
00050 {
00051   public:
00052     OApplicationPrivate() {};
00053     ~OApplicationPrivate() {};
00054 };
00055 }
00056 
00057 /**************************************************************************************************
00058  * OApplication
00059  **************************************************************************************************/
00060 OApplication::OApplication( int& argc, char** argv, Type type )
00061              :QPEApplication( argc, argv, type ),
00062              _appname( QString::null ),
00063              _config( 0 )
00064 {
00065     init();
00066 }       
00067 
00068 OApplication::OApplication( int& argc, char** argv, const QCString& rAppName )
00069              :QPEApplication( argc, argv ),
00070              _appname( rAppName ),
00071              _config( 0 )
00072 {
00073     init();
00074 }
00075 
00076 
00077 OApplication::~OApplication()
00078 {
00079     delete d;
00080     if ( _config )
00081         delete _config;
00082     OApplication::_instance = 0;
00083     // after deconstruction of the one-and-only application object,
00084     // the construction of another object is allowed
00085 }
00086 
00087 
00088 OConfig* OApplication::config()
00089 {
00090     if ( !_config )
00091     {
00092         _config = new OConfig( _appname );
00093     }
00094     return _config;
00095 }
00096 
00097 
00098 void OApplication::init()
00099 {
00100     d = new Internal::OApplicationPrivate();
00101     if ( !OApplication::_instance )
00102     {
00103         OApplication::_instance = this;
00104 
00105         /* register SIGSEGV handler to give programs an option
00106          * to exit gracefully, e.g. save or close devices or files.
00107         struct sigaction sa;
00108         sa.sa_handler = ( void (*)(int) ) &segv_handler;
00109         sa.sa_flags = SA_SIGINFO | SA_RESTART;
00110         sigemptyset(&sa.sa_mask);
00111         sigaction(SIGSEGV, &sa, NULL);
00112         */
00113     }
00114     else
00115     {
00116         ofatal << "OApplication: Can't create more than one OApplication object. Aborting." << oendl;
00117         //FIXME exit gracefully ?
00118         ::exit( -1 );
00119     }
00120 }
00121 
00122 
00123 void OApplication::showMainWidget( QWidget* widget, bool nomax )
00124 {
00125     QPEApplication::showMainWidget( widget, nomax );
00126     widget->setCaption( _appname );
00127 }
00128 
00129 
00130 void OApplication::setTitle( const QString& title ) const
00131 {
00132     if ( mainWidget() )
00133     {
00134         if ( !title.isNull() )
00135             mainWidget()->setCaption( QString(_appname) + QString( " - " ) + title );
00136         else
00137             mainWidget()->setCaption( _appname );
00138     }
00139 }
00140 
00141 }
00142 }

Generated on Sat Nov 5 16:16:07 2005 for OPIE by  doxygen 1.4.2