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

opietoothapplet.cpp

Go to the documentation of this file.
00001 /*
00002                =.            This file is part of the OPIE Project
00003              .=l.            Copyright (c)  2002 Maximilian Reiss <max.reiss@gmx.de>
00004            .>+-=
00005  _;:,     .>    :=|.         This library is free software; you can
00006 .> <,   >  .   <=          redistribute it and/or  modify it under
00007 :=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00008 .="- .-=="i,     .._         License as published by the Free Software
00009  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00010      ._= =}       :          or (at your option) any later version.
00011     .%+i>       _;_.
00012     .i_,=:_.      -<s.       This library is distributed in the hope that
00013      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00014     : ..    .:,     . . .    without even the implied warranty of
00015     =_        +     =;=|    MERCHANTABILITY or FITNESS FOR A
00016   _.=:.       :    :=>:     PARTICULAR PURPOSE. See the GNU
00017 ..}^=.=       =       ;      Library General Public License for more
00018 ++=   -.     .     .:       details.
00019  :     =  ...= . :.=-
00020  -.   .:....=;==+<;          You should have received a copy of the GNU
00021   -_. . .   )=.  =           Library General Public License along with
00022     --        :-=           this library; see the file COPYING.LIB.
00023                              If not, write to the Free Software Foundation,
00024                              Inc., 59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 
00030 #include <qapplication.h>
00031 
00032 #include <qpe/qcopenvelope_qws.h>
00033 #include <qpe/config.h>
00034 
00035 #include <qpoint.h>
00036 #include <qpainter.h>
00037 #include <qlayout.h>
00038 #include <qframe.h>
00039 #include <qpixmap.h>
00040 #include <qstring.h>
00041 #include <qpopupmenu.h>
00042 
00043 #include <OTGateway.h>
00044 #include <OTIcons.h>
00045 #include <opietoothapplet.h>
00046 
00047 namespace Opietooth2 {
00048 
00049 //
00050 //
00051 // Panel
00052 //
00053 //
00054 
00055 MessagePanel::MessagePanel( const QString & Msg,
00056                             QWidget* parent, const char*  name ):
00057                             QLabel( parent, name, WType_Popup ){
00058 
00059         QLabel * L = new QLabel( Msg, this );
00060         L->setAlignment( Qt::WordBreak | Qt::AlignCenter );
00061 
00062         QVBoxLayout * VL = new QVBoxLayout( this );
00063         VL->addWidget( this );
00064         VL->setMargin( 3 );
00065 
00066         setFrameStyle( WinPanel|Raised );
00067         setAlignment( AlignCenter );
00068 
00069         resize(150,100);
00070 
00071         moves = 0;
00072 }
00073 
00074 void MessagePanel::mouseReleaseEvent( QMouseEvent * e){
00075 
00076         if  (rect().contains( e->pos() ) || moves > 5)
00077             close();
00078 }
00079 
00080 void MessagePanel::closeEvent( QCloseEvent *e ){
00081 
00082         e->accept();
00083 
00084         moves = 0;
00085 
00086         if (!popupParent)
00087             return;
00088 
00089         /* 
00090            remember that we (as a popup) might recieve the mouse 
00091            release event instead of the popupParent. This is due to 
00092            the fact that the popupParent popped us up in its 
00093            mousePressEvent handler. To avoid the button remaining in 
00094            pressed state we simply send a faked mouse button release 
00095            event to it.
00096         */
00097 
00098         QMouseEvent me( QEvent::MouseButtonRelease, 
00099                         QPoint(0,0), 
00100                         QPoint(0,0), 
00101                         QMouseEvent::LeftButton, 
00102                         QMouseEvent::NoButton);
00103         QApplication::sendEvent( popupParent, &me );
00104 }
00105 
00106 void MessagePanel::popup( QWidget* parent) {
00107 
00108         popupParent = parent;
00109 
00110         if (popupParent)
00111             move( popupParent->mapToGlobal( 
00112                     popupParent->rect().bottomLeft() ) 
00113                 );
00114         show();
00115 }
00116 
00117 
00118 //
00119 //
00120 // Applet code
00121 //
00122 //
00123 
00124 Opietooth2Applet::Opietooth2Applet( QWidget *parent, const char *name ) : QWidget( parent, name ) {
00125         OTIcons Ic;
00126         setFixedHeight( 18 );
00127         setFixedWidth( 14 );
00128         
00129         OT = OTGateway::getOTGateway();
00130 
00131         OnP = Ic.loadPixmap( "bluezon" );
00132         OffP = Ic.loadPixmap( "bluezoff" );
00133 
00134         // sent when bluetooth on device is enabled/disabled
00135         connect( OT,
00136                  SIGNAL( deviceEnabled( bool ) ),
00137                  this,
00138                  SLOT( SLOT_StateChange( bool ) ) );
00139 
00140         // sent when error
00141         connect( OT,
00142                  SIGNAL( error( const QString & ) ),
00143                  this,
00144                  SLOT( SLOT_Error( const QString & ) ) );
00145 }
00146 
00147 Opietooth2Applet::~Opietooth2Applet() {
00148         OTGateway::releaseOTGateway();
00149 }
00150 
00151 void Opietooth2Applet::mousePressEvent( QMouseEvent *) {
00152 
00153         QPopupMenu *menu = new QPopupMenu();
00154         // QPopupMenu *signal = new QPopupMenu();
00155         int ret=0;
00156 
00157         /* Refresh active state */
00158         menu->insertItem( ( (OT->isEnabled()) ?
00159                               tr("Disable") :
00160                               tr("Enable")
00161                           ),
00162                           1 );
00163         menu->insertItem( tr("Launch manager"), 2 );
00164 
00165         //menu->insertItem( tr("Signal strength"), signal,  5);
00166         //menu->insertSeparator(8);
00167 
00168         /*
00169         menu->insertItem( ( (DiscoveryActive) ?
00170                               tr("Disable discovery") :
00171                               tr("Enable discovery")
00172                           ),
00173                           3 );
00174         */
00175 
00176         QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) );
00177 
00178         ret = menu->exec(p, 0);
00179 
00180         switch(ret) {
00181           case 1:
00182             // toggle enabling of BT
00183             OT->SLOT_SetEnabled( ! OT->isEnabled() );
00184             break;
00185           case 2:
00186             // start bluetoothmanager
00187             launchManager();
00188             break;
00189           //case 3:
00190            // DiscoveryActive = 1 - DiscoveryActive;
00191            // setDiscoveryStatus( DiscoveryActive );
00192            // break;
00193            // case 7:
00194            //  With table of currently-detected devices.
00195         }
00196         // delete signal;
00197         delete menu;
00198 }
00199 
00200 
00201 void Opietooth2Applet::SLOT_Error( const QString & S ) {
00202         MessagePanel * MP = new MessagePanel( S );
00203 
00204         QPoint p = mapToGlobal( 
00205               QPoint(1, - MP->sizeHint().height()-1) );
00206         MP->move( p );
00207 
00208         MP->popup( 0 );
00209         delete MP;
00210 }
00211 
00215 void Opietooth2Applet::launchManager() {
00216         QCopEnvelope e("QPE/System", "execute(QString)");
00217         e << QString("networksettings2-opietooth");
00218 }
00219 
00220 void Opietooth2Applet::SLOT_StateChange( bool ) {
00221         // changed
00222 
00223         // trigger painting
00224         update();
00225 }
00226 
00231 void Opietooth2Applet::paintEvent( QPaintEvent* ) {
00232         QPainter p(this);
00233 
00234         p.drawPixmap( 0, 1, (( OT->isEnabled() ) ? OnP : OffP) );
00235 }
00236 
00237 //
00238 // end of namespace
00239 //
00240 
00241 };

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