author | mickeyl <mickeyl> | 2003-09-16 12:31:09 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-09-16 12:31:09 (UTC) |
commit | 81171716bb686e709f27fbbc0931740aa9d9462a (patch) (unidiff) | |
tree | a989e70496240fad7f3a87a72ee3c1a530be26eb | |
parent | 7338604c783a51c456fdf8d534f8da62e4383e03 (diff) | |
download | opie-81171716bb686e709f27fbbc0931740aa9d9462a.zip opie-81171716bb686e709f27fbbc0931740aa9d9462a.tar.gz opie-81171716bb686e709f27fbbc0931740aa9d9462a.tar.bz2 |
virtual terminal applet says: "Hello"
-rw-r--r-- | core/applets/vtapplet/.cvsignore | 1 | ||||
-rw-r--r-- | core/applets/vtapplet/config.in | 4 | ||||
-rw-r--r-- | core/applets/vtapplet/vt.cpp | 143 | ||||
-rw-r--r-- | core/applets/vtapplet/vt.h | 53 | ||||
-rw-r--r-- | core/applets/vtapplet/vtapplet.pro | 13 | ||||
-rw-r--r-- | packages | 1 |
6 files changed, 215 insertions, 0 deletions
diff --git a/core/applets/vtapplet/.cvsignore b/core/applets/vtapplet/.cvsignore new file mode 100644 index 0000000..c55c0bc --- a/dev/null +++ b/core/applets/vtapplet/.cvsignore | |||
@@ -0,0 +1 @@ | |||
Makefile* | |||
diff --git a/core/applets/vtapplet/config.in b/core/applets/vtapplet/config.in new file mode 100644 index 0000000..85692a5 --- a/dev/null +++ b/core/applets/vtapplet/config.in | |||
@@ -0,0 +1,4 @@ | |||
1 | config VTAPPLET | ||
2 | boolean "VT (switch to another virtual terminal)" | ||
3 | default "y" | ||
4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE | ||
diff --git a/core/applets/vtapplet/vt.cpp b/core/applets/vtapplet/vt.cpp new file mode 100644 index 0000000..6200447 --- a/dev/null +++ b/core/applets/vtapplet/vt.cpp | |||
@@ -0,0 +1,143 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. | ||
3 | ** | ||
4 | ** Contact me @ mickeyl@handhelds.org | ||
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 <qpe/resource.h> | ||
17 | #include <qpe/qcopenvelope_qws.h> | ||
18 | |||
19 | #include <qapplication.h> | ||
20 | #include <qiconset.h> | ||
21 | #include <qpopupmenu.h> | ||
22 | |||
23 | #include <fcntl.h> | ||
24 | #include <unistd.h> | ||
25 | #include <sys/types.h> | ||
26 | #include <sys/stat.h> | ||
27 | #include <sys/ioctl.h> | ||
28 | #include <linux/vt.h> | ||
29 | |||
30 | #include "vt.h" | ||
31 | |||
32 | class VTPopupMenu : public QPopupMenu | ||
33 | { | ||
34 | public: | ||
35 | VTPopupMenu( QWidget * parent=0, const char * name=0 ) : QPopupMenu( parent, name ) {}; | ||
36 | |||
37 | virtual void activated() { qDebug( "VTPopupMenu::activated()" ); } | ||
38 | }; | ||
39 | |||
40 | VTApplet::VTApplet ( ) | ||
41 | : QObject ( 0, "VTApplet" ), ref ( 0 ) | ||
42 | { | ||
43 | } | ||
44 | |||
45 | VTApplet::~VTApplet ( ) | ||
46 | { | ||
47 | } | ||
48 | |||
49 | int VTApplet::position ( ) const | ||
50 | { | ||
51 | return 2; | ||
52 | } | ||
53 | |||
54 | QString VTApplet::name ( ) const | ||
55 | { | ||
56 | return tr( "VT shortcut" ); | ||
57 | } | ||
58 | |||
59 | QString VTApplet::text ( ) const | ||
60 | { | ||
61 | return tr( "Terminal" ); | ||
62 | } | ||
63 | |||
64 | /* | ||
65 | QString VTApplet::tr( const char* s ) const | ||
66 | { | ||
67 | return qApp->translate( "VTApplet", s, 0 ); | ||
68 | } | ||
69 | |||
70 | QString VTApplet::tr( const char* s, const char* p ) const | ||
71 | { | ||
72 | return qApp->translate( "VTApplet", s, p ); | ||
73 | } | ||
74 | */ | ||
75 | |||
76 | QIconSet VTApplet::icon ( ) const | ||
77 | { | ||
78 | QPixmap pix; | ||
79 | QImage img = Resource::loadImage ( "terminal" ); | ||
80 | |||
81 | if ( !img. isNull ( )) | ||
82 | pix. convertFromImage ( img. smoothScale ( 14, 14 )); | ||
83 | return pix; | ||
84 | } | ||
85 | |||
86 | QPopupMenu *VTApplet::popup ( QWidget* parent ) const | ||
87 | { | ||
88 | qDebug( "VTApplet::popup" ); | ||
89 | |||
90 | struct vt_stat vtstat; | ||
91 | int fd = ::open("/dev/tty0", O_RDWR); | ||
92 | if ( fd == -1 ) return 0; | ||
93 | if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0; | ||
94 | |||
95 | submenu = new VTPopupMenu( parent ); | ||
96 | submenu->setCheckable( true ); | ||
97 | for ( int i = 1; i < 10; ++i ) | ||
98 | { | ||
99 | int id = submenu->insertItem( QString::number( i ), 500+i ); | ||
100 | submenu->setItemChecked( id, id-500 == vtstat.v_active ); | ||
101 | } | ||
102 | ::close( fd ); | ||
103 | |||
104 | connect( submenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) ); | ||
105 | |||
106 | return submenu; | ||
107 | } | ||
108 | |||
109 | |||
110 | void VTApplet::changeVT( int index ) | ||
111 | { | ||
112 | qDebug( "VTApplet::changeVT( %d )", index-500 ); | ||
113 | int fd = ::open("/dev/tty0", O_RDWR); | ||
114 | if ( fd == -1 ) return; | ||
115 | ioctl( fd, VT_ACTIVATE, index-500 ); | ||
116 | } | ||
117 | |||
118 | |||
119 | void VTApplet::activated() | ||
120 | { | ||
121 | qDebug( "VTApplet::activated()" ); | ||
122 | } | ||
123 | |||
124 | |||
125 | QRESULT VTApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) | ||
126 | { | ||
127 | *iface = 0; | ||
128 | if ( uuid == IID_QUnknown ) | ||
129 | *iface = this; | ||
130 | else if ( uuid == IID_MenuApplet ) | ||
131 | *iface = this; | ||
132 | |||
133 | if ( *iface ) | ||
134 | (*iface)-> addRef ( ); | ||
135 | return QS_OK; | ||
136 | } | ||
137 | |||
138 | Q_EXPORT_INTERFACE( ) | ||
139 | { | ||
140 | Q_CREATE_INSTANCE( VTApplet ) | ||
141 | } | ||
142 | |||
143 | |||
diff --git a/core/applets/vtapplet/vt.h b/core/applets/vtapplet/vt.h new file mode 100644 index 0000000..2df9791 --- a/dev/null +++ b/core/applets/vtapplet/vt.h | |||
@@ -0,0 +1,53 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. | ||
3 | ** | ||
4 | ** Contact me @ mickeyl@handhelds.org | ||
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 | #ifndef __OPIE_VTAPPLET_H__ | ||
16 | #define __OPIE_VTAPPLET_H__ | ||
17 | |||
18 | #include <qpe/menuappletinterface.h> | ||
19 | #include <qobject.h> | ||
20 | |||
21 | class VTApplet : public QObject, public MenuAppletInterface | ||
22 | { | ||
23 | |||
24 | Q_OBJECT | ||
25 | |||
26 | public: | ||
27 | VTApplet ( ); | ||
28 | virtual ~VTApplet ( ); | ||
29 | |||
30 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | ||
31 | Q_REFCOUNT | ||
32 | |||
33 | virtual int position() const; | ||
34 | |||
35 | virtual QString name ( ) const; | ||
36 | virtual QIconSet icon ( ) const; | ||
37 | virtual QString text ( ) const; | ||
38 | //virtual QString tr( const char* ) const; | ||
39 | //virtual QString tr( const char*, const char* ) const; | ||
40 | virtual QPopupMenu *popup ( QWidget *parent ) const; | ||
41 | |||
42 | virtual void activated (); | ||
43 | |||
44 | public slots: | ||
45 | virtual void changeVT( int index ); | ||
46 | |||
47 | private: | ||
48 | ulong ref; | ||
49 | }; | ||
50 | |||
51 | static QPopupMenu* submenu; | ||
52 | |||
53 | #endif | ||
diff --git a/core/applets/vtapplet/vtapplet.pro b/core/applets/vtapplet/vtapplet.pro new file mode 100644 index 0000000..3899e75 --- a/dev/null +++ b/core/applets/vtapplet/vtapplet.pro | |||
@@ -0,0 +1,13 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += qt warn_on release | ||
3 | HEADERS = vt.h | ||
4 | SOURCES = vt.cpp | ||
5 | TARGET = vtapplet | ||
6 | DESTDIR = $(OPIEDIR)/plugins/applets | ||
7 | INCLUDEPATH += $(OPIEDIR)/include | ||
8 | DEPENDPATH += $(OPIEDIR)/include | ||
9 | LIBS += -lqpe | ||
10 | VERSION = 1.0.0 | ||
11 | |||
12 | include ( $(OPIEDIR)/include.pro ) | ||
13 | target.path = $$prefix/plugins/applets | ||
@@ -168,2 +168,3 @@ CONFIG_VMEMO core/applets/vmemo vmemo.pro | |||
168 | CONFIG_VOLUMEAPPLET core/applets/volumeappletvolumeapplet.pro | 168 | CONFIG_VOLUMEAPPLET core/applets/volumeappletvolumeapplet.pro |
169 | CONFIG_VTAPPLET core/applets/vtappletvtapplet.pro | ||
169 | CONFIG_WAVPLUGIN core/multimedia/opieplayer/wavpluginwavplugin.pro | 170 | CONFIG_WAVPLUGIN core/multimedia/opieplayer/wavpluginwavplugin.pro |