summaryrefslogtreecommitdiff
authordwmw2 <dwmw2>2002-04-01 21:41:04 (UTC)
committer dwmw2 <dwmw2>2002-04-01 21:41:04 (UTC)
commit22183e22f3d1776c6c73219bd1a07ddf6bb8d670 (patch) (unidiff)
tree82712ae6199ba31dbf826d2ded63e866a05373e6
parent5c8abf28f5c839d1af9565b58b9f01aa54378eab (diff)
downloadopie-22183e22f3d1776c6c73219bd1a07ddf6bb8d670.zip
opie-22183e22f3d1776c6c73219bd1a07ddf6bb8d670.tar.gz
opie-22183e22f3d1776c6c73219bd1a07ddf6bb8d670.tar.bz2
Import basic applet to allow switching IrDA on and off.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/irdaapplet/.cvsignore3
-rw-r--r--core/applets/irdaapplet/irda.cpp159
-rw-r--r--core/applets/irdaapplet/irda.h57
-rw-r--r--core/applets/irdaapplet/irdaapplet.pro11
-rw-r--r--core/applets/irdaapplet/irdaappletimpl.cpp64
-rw-r--r--core/applets/irdaapplet/irdaappletimpl.h44
-rw-r--r--core/applets/irdaapplet/opie-irdaapplet.control9
-rw-r--r--pics/irdaapplet/irdaoff.pngbin0 -> 272 bytes
-rw-r--r--pics/irdaapplet/irdaon.pngbin0 -> 258 bytes
9 files changed, 347 insertions, 0 deletions
diff --git a/core/applets/irdaapplet/.cvsignore b/core/applets/irdaapplet/.cvsignore
new file mode 100644
index 0000000..2c33e73
--- a/dev/null
+++ b/core/applets/irdaapplet/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile*
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp
new file mode 100644
index 0000000..2eff2a9
--- a/dev/null
+++ b/core/applets/irdaapplet/irda.cpp
@@ -0,0 +1,159 @@
1/**********************************************************************
2** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org>
3** Heavily based on volumeapplet, (C) 2002 L.J. Potter ljp@llornkcor.com
4** All rights reserved.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14**********************************************************************/
15
16#include "irda.h"
17#include <qapplication.h>
18#include <stdlib.h>
19
20
21#include <qpe/resource.h>
22#include <qpe/qpeapplication.h>
23#include <qpe/timestring.h>
24#include <qpe/resource.h>
25#include <qpe/config.h>
26#include <qpe/applnk.h>
27#include <qpe/config.h>
28
29#include <qdir.h>
30#include <qfileinfo.h>
31#include <qpoint.h>
32#include <qpushbutton.h>
33#include <qpainter.h>
34#include <qcombobox.h>
35#include <qspinbox.h>
36#include <qslider.h>
37#include <qlayout.h>
38#include <qframe.h>
39#include <qpixmap.h>
40#include <qstring.h>
41#include <qfile.h>
42#include <qtimer.h>
43#include <qpopupmenu.h>
44
45#include <net/if.h>
46#include <netinet/in.h>
47#include <sys/types.h>
48#include <sys/socket.h>
49#include <sys/ioctl.h>
50
51
52//===========================================================================
53
54IrdaApplet::IrdaApplet( QWidget *parent, const char *name )
55 : QWidget( parent, name )
56{
57 setFixedHeight( 18 );
58 setFixedWidth( 14 );
59 sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
60 irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" );
61 irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" );
62 startTimer(5000);
63 timerEvent(NULL);
64}
65
66IrdaApplet::~IrdaApplet()
67{
68 close(sockfd);
69}
70
71int IrdaApplet::checkIrdaStatus()
72{
73 struct ifreq ifr;
74
75 strcpy(ifr.ifr_name, "irda0");
76
77 if (ioctl(sockfd, SIOCGIFFLAGS, &ifr))
78 return -1;
79
80 return (ifr.ifr_flags & IFF_UP)?1:0;
81}
82
83int IrdaApplet::setIrdaStatus(int c)
84{
85 struct ifreq ifr;
86
87 strcpy(ifr.ifr_name, "irda0");
88
89 if (ioctl(sockfd, SIOCGIFFLAGS, &ifr))
90 return -1;
91
92 if (c)
93 ifr.ifr_flags |= IFF_UP;
94 else
95 ifr.ifr_flags &= ~IFF_UP;
96
97 if (ioctl(sockfd, SIOCSIFFLAGS, &ifr))
98 return -1;
99
100 return 0;
101}
102
103void IrdaApplet::mousePressEvent( QMouseEvent *)
104{
105 QPopupMenu *menu = new QPopupMenu();
106 QString cmd;
107 int ret=0;
108
109 /* Refresh active state */
110 timerEvent(NULL);
111
112 //menu->insertItem( tr("More..."), 2 );
113 if (irdaactive)
114 menu->insertItem( tr("Disable IrDA"), 0 );
115 else
116 menu->insertItem( tr("Enable IrDA"), 1 );
117
118 QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) );
119 ret = menu->exec(p, 1);
120
121 qDebug("ret was %d\n", ret);
122
123 switch(ret) {
124 case 0:
125 setIrdaStatus(0);
126 timerEvent(NULL);
127 break;
128 case 1:
129 setIrdaStatus(1);
130 timerEvent(NULL);
131 break;
132 case 2:
133 qDebug("FIXME: Bring up pretty menu...\n");
134 // With 'discovery' button to enable/disable,
135 // and table of currently-detected devices.
136 }
137
138}
139
140void IrdaApplet::timerEvent( QTimerEvent * )
141{
142 int oldactive = irdaactive;
143
144 irdaactive = checkIrdaStatus();
145 if (irdaactive != oldactive)
146 paintEvent(NULL);
147
148}
149
150void IrdaApplet::paintEvent( QPaintEvent* )
151{
152 QPainter p(this);
153 qDebug("paint irda pixmap");
154
155 if (irdaactive > 0)
156 p.drawPixmap( 0, 1, irdaOnPixmap );
157 else
158 p.drawPixmap( 0, 1, irdaOffPixmap );
159}
diff --git a/core/applets/irdaapplet/irda.h b/core/applets/irdaapplet/irda.h
new file mode 100644
index 0000000..d762ff3
--- a/dev/null
+++ b/core/applets/irdaapplet/irda.h
@@ -0,0 +1,57 @@
1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com
3** All rights reserved.
4**
5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file.
9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12**
13**********************************************************************/
14
15#ifndef __SCREENSHOT_APPLET_H__
16#define __SCREENSHOT_APPLET_H__
17
18
19
20#include <qwidget.h>
21#include <qframe.h>
22#include <qpixmap.h>
23#include <qguardedptr.h>
24#include <qtimer.h>
25
26
27class IrdaApplet : public QWidget
28{
29 Q_OBJECT
30public:
31 IrdaApplet( QWidget *parent = 0, const char *name=0 );
32 ~IrdaApplet();
33
34protected:
35 void timerEvent(QTimerEvent *te );
36
37public slots:
38private:
39 void mousePressEvent( QMouseEvent * );
40 void paintEvent( QPaintEvent* );
41 int checkIrdaStatus();
42 int setIrdaStatus(int);
43 int sockfd;
44
45private:
46 QPixmap irdaOnPixmap;
47 QPixmap irdaOffPixmap;
48 int irdaactive;
49
50private slots:
51
52
53};
54
55
56#endif // __SCREENSHOT_APPLET_H__
57
diff --git a/core/applets/irdaapplet/irdaapplet.pro b/core/applets/irdaapplet/irdaapplet.pro
new file mode 100644
index 0000000..c8f3fdc
--- a/dev/null
+++ b/core/applets/irdaapplet/irdaapplet.pro
@@ -0,0 +1,11 @@
1TEMPLATE = lib
2CONFIG += qt warn_on release
3HEADERS = irda.h irdaappletimpl.h
4SOURCES = irda.cpp irdaappletimpl.cpp
5TARGET = irdaapplet
6DESTDIR = ../../plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += ../$(OPIEDIR)/include
9LIBS += -lqpe
10VERSION = 1.0.0
11
diff --git a/core/applets/irdaapplet/irdaappletimpl.cpp b/core/applets/irdaapplet/irdaappletimpl.cpp
new file mode 100644
index 0000000..02443db
--- a/dev/null
+++ b/core/applets/irdaapplet/irdaappletimpl.cpp
@@ -0,0 +1,64 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "irda.h"
21#include "irdaappletimpl.h"
22
23
24IrdaAppletImpl::IrdaAppletImpl()
25 : irda(0), ref(0)
26{
27}
28
29IrdaAppletImpl::~IrdaAppletImpl()
30{
31 delete irda;
32}
33
34QWidget *IrdaAppletImpl::applet( QWidget *parent )
35{
36 if ( !irda )
37 irda = new IrdaApplet( parent );
38 return irda;
39}
40
41int IrdaAppletImpl::position() const
42{
43 return 6;
44}
45
46QRESULT IrdaAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
47{
48 *iface = 0;
49 if ( uuid == IID_QUnknown )
50 *iface = this;
51 else if ( uuid == IID_TaskbarApplet )
52 *iface = this;
53
54 if ( *iface )
55 (*iface)->addRef();
56 return QS_OK;
57}
58
59Q_EXPORT_INTERFACE()
60{
61 Q_CREATE_INSTANCE( IrdaAppletImpl )
62}
63
64
diff --git a/core/applets/irdaapplet/irdaappletimpl.h b/core/applets/irdaapplet/irdaappletimpl.h
new file mode 100644
index 0000000..abedb07
--- a/dev/null
+++ b/core/applets/irdaapplet/irdaappletimpl.h
@@ -0,0 +1,44 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef SCREENSHOTAPPLETIMPL_H
21#define SCREENSHOTAPPLETIMPL_H
22
23#include <qpe/taskbarappletinterface.h>
24
25class IrdaApplet;
26
27class IrdaAppletImpl : public TaskbarAppletInterface
28{
29public:
30 IrdaAppletImpl();
31 virtual ~IrdaAppletImpl();
32
33 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
34 Q_REFCOUNT
35
36 virtual QWidget *applet( QWidget *parent );
37 virtual int position() const;
38
39private:
40 IrdaApplet *irda;
41 ulong ref;
42};
43
44#endif
diff --git a/core/applets/irdaapplet/opie-irdaapplet.control b/core/applets/irdaapplet/opie-irdaapplet.control
new file mode 100644
index 0000000..d730554
--- a/dev/null
+++ b/core/applets/irdaapplet/opie-irdaapplet.control
@@ -0,0 +1,9 @@
1Files: plugins/applets/libirdaapplet.so* pics/irdaapplet/*
2Priority: optional
3Section: opie/system
4Maintainer: David Woodhouse <dwmw2@infradead.org>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION.1
7Depends: opie-base ($QPE_VERSION)
8Description: Irda Applet
9 An IrDA taskbar applet for the Opie environment
diff --git a/pics/irdaapplet/irdaoff.png b/pics/irdaapplet/irdaoff.png
new file mode 100644
index 0000000..4e6c731
--- a/dev/null
+++ b/pics/irdaapplet/irdaoff.png
Binary files differ
diff --git a/pics/irdaapplet/irdaon.png b/pics/irdaapplet/irdaon.png
new file mode 100644
index 0000000..53fc7e9
--- a/dev/null
+++ b/pics/irdaapplet/irdaon.png
Binary files differ