00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
00091
00092
00093
00094
00095
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
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
00135 connect( OT,
00136 SIGNAL( deviceEnabled( bool ) ),
00137 this,
00138 SLOT( SLOT_StateChange( bool ) ) );
00139
00140
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
00155 int ret=0;
00156
00157
00158 menu->insertItem( ( (OT->isEnabled()) ?
00159 tr("Disable") :
00160 tr("Enable")
00161 ),
00162 1 );
00163 menu->insertItem( tr("Launch manager"), 2 );
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
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
00183 OT->SLOT_SetEnabled( ! OT->isEnabled() );
00184 break;
00185 case 2:
00186
00187 launchManager();
00188 break;
00189
00190
00191
00192
00193
00194
00195 }
00196
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
00222
00223
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
00239
00240
00241 };