author | zecke <zecke> | 2004-02-05 16:44:20 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-05 16:44:20 (UTC) |
commit | 4c4ed7176231558d01aeca2eb705fc6810ec7766 (patch) (unidiff) | |
tree | d923fd4ca70d6db917a0e154a5a642a444cab87e | |
parent | ef8ece225a663f0ff1262989085fc214500beebe (diff) | |
download | opie-4c4ed7176231558d01aeca2eb705fc6810ec7766.zip opie-4c4ed7176231558d01aeca2eb705fc6810ec7766.tar.gz opie-4c4ed7176231558d01aeca2eb705fc6810ec7766.tar.bz2 |
Stuff can be broken if you really want it... or because only root can open /dev/console...
Anyway have a mutable QPopupMenu in the class and remove unsigned long ref
as we don't need it
-rw-r--r-- | core/applets/vtapplet/vt.cpp | 18 | ||||
-rw-r--r-- | core/applets/vtapplet/vt.h | 4 |
2 files changed, 10 insertions, 12 deletions
diff --git a/core/applets/vtapplet/vt.cpp b/core/applets/vtapplet/vt.cpp index cdd3c97..881eb41 100644 --- a/core/applets/vtapplet/vt.cpp +++ b/core/applets/vtapplet/vt.cpp | |||
@@ -1,164 +1,164 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** Contact me @ mickeyl@handhelds.org | 4 | ** Contact me @ mickeyl@handhelds.org |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include <qpe/resource.h> | 16 | #include <qpe/resource.h> |
17 | #include <qpe/qcopenvelope_qws.h> | 17 | #include <qpe/qcopenvelope_qws.h> |
18 | 18 | ||
19 | #include <qapplication.h> | 19 | #include <qapplication.h> |
20 | #include <qiconset.h> | 20 | #include <qiconset.h> |
21 | #include <qpopupmenu.h> | 21 | #include <qpopupmenu.h> |
22 | 22 | ||
23 | #include <fcntl.h> | 23 | #include <fcntl.h> |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | #include <sys/types.h> | 25 | #include <sys/types.h> |
26 | #include <sys/stat.h> | 26 | #include <sys/stat.h> |
27 | #include <sys/ioctl.h> | 27 | #include <sys/ioctl.h> |
28 | #include <linux/vt.h> | 28 | #include <linux/vt.h> |
29 | 29 | ||
30 | #include "vt.h" | 30 | #include "vt.h" |
31 | 31 | ||
32 | VTApplet::VTApplet ( ) | 32 | VTApplet::VTApplet ( ) |
33 | : QObject ( 0, "VTApplet" ), ref ( 0 ) | 33 | : QObject ( 0, "VTApplet" ) |
34 | { | 34 | { |
35 | } | 35 | } |
36 | 36 | ||
37 | VTApplet::~VTApplet ( ) | 37 | VTApplet::~VTApplet ( ) |
38 | { | 38 | { |
39 | } | 39 | } |
40 | 40 | ||
41 | int VTApplet::position ( ) const | 41 | int VTApplet::position ( ) const |
42 | { | 42 | { |
43 | return 2; | 43 | return 2; |
44 | } | 44 | } |
45 | 45 | ||
46 | QString VTApplet::name ( ) const | 46 | QString VTApplet::name ( ) const |
47 | { | 47 | { |
48 | return tr( "VT shortcut" ); | 48 | return tr( "VT shortcut" ); |
49 | } | 49 | } |
50 | 50 | ||
51 | QString VTApplet::text ( ) const | 51 | QString VTApplet::text ( ) const |
52 | { | 52 | { |
53 | return tr( "Terminal" ); | 53 | return tr( "Terminal" ); |
54 | } | 54 | } |
55 | 55 | ||
56 | /* | 56 | /* |
57 | QString VTApplet::tr( const char* s ) const | 57 | QString VTApplet::tr( const char* s ) const |
58 | { | 58 | { |
59 | return qApp->translate( "VTApplet", s, 0 ); | 59 | return qApp->translate( "VTApplet", s, 0 ); |
60 | } | 60 | } |
61 | 61 | ||
62 | QString VTApplet::tr( const char* s, const char* p ) const | 62 | QString VTApplet::tr( const char* s, const char* p ) const |
63 | { | 63 | { |
64 | return qApp->translate( "VTApplet", s, p ); | 64 | return qApp->translate( "VTApplet", s, p ); |
65 | } | 65 | } |
66 | */ | 66 | */ |
67 | 67 | ||
68 | QIconSet VTApplet::icon ( ) const | 68 | QIconSet VTApplet::icon ( ) const |
69 | { | 69 | { |
70 | QPixmap pix; | 70 | QPixmap pix; |
71 | QImage img = Resource::loadImage ( "terminal" ); | 71 | QImage img = Resource::loadImage ( "terminal" ); |
72 | 72 | ||
73 | if ( !img. isNull ( )) | 73 | if ( !img. isNull ( )) |
74 | pix. convertFromImage ( img. smoothScale ( 14, 14 )); | 74 | pix. convertFromImage ( img. smoothScale ( 14, 14 )); |
75 | return pix; | 75 | return pix; |
76 | } | 76 | } |
77 | 77 | ||
78 | QPopupMenu *VTApplet::popup ( QWidget* parent ) const | 78 | QPopupMenu *VTApplet::popup ( QWidget* parent ) const |
79 | { | 79 | { |
80 | qDebug( "VTApplet::popup" ); | 80 | qDebug( "VTApplet::popup" ); |
81 | 81 | ||
82 | struct vt_stat vtstat; | 82 | struct vt_stat vtstat; |
83 | int fd = ::open( "/dev/tty0", O_RDWR ); | 83 | int fd = ::open( "/dev/tty0", O_RDWR ); |
84 | if ( fd == -1 ) return 0; | 84 | if ( fd == -1 ) return 0; |
85 | if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0; | 85 | if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0; |
86 | 86 | ||
87 | submenu = new QPopupMenu( parent ); | 87 | m_subMenu = new QPopupMenu( parent ); |
88 | submenu->setCheckable( true ); | 88 | m_subMenu->setCheckable( true ); |
89 | for ( int i = 1; i < 10; ++i ) | 89 | for ( int i = 1; i < 10; ++i ) |
90 | { | 90 | { |
91 | int id = submenu->insertItem( QString::number( i ), 500+i ); | 91 | int id = m_subMenu->insertItem( QString::number( i ), 500+i ); |
92 | submenu->setItemChecked( id, id-500 == vtstat.v_active ); | 92 | m_subMenu->setItemChecked( id, id-500 == vtstat.v_active ); |
93 | } | 93 | } |
94 | ::close( fd ); | 94 | ::close( fd ); |
95 | 95 | ||
96 | connect( submenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) ); | 96 | connect( m_subMenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) ); |
97 | connect( submenu, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) ); | 97 | connect( m_subMenu, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) ); |
98 | 98 | ||
99 | return submenu; | 99 | return m_subMenu; |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | void VTApplet::changeVT( int index ) | 103 | void VTApplet::changeVT( int index ) |
104 | { | 104 | { |
105 | //qDebug( "VTApplet::changeVT( %d )", index-500 ); | 105 | //qDebug( "VTApplet::changeVT( %d )", index-500 ); |
106 | 106 | ||
107 | int fd = ::open("/dev/tty0", O_RDWR); | 107 | int fd = ::open("/dev/tty0", O_RDWR); |
108 | if ( fd == -1 ) return; | 108 | if ( fd == -1 ) return; |
109 | ioctl( fd, VT_ACTIVATE, index-500 ); | 109 | ioctl( fd, VT_ACTIVATE, index-500 ); |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | void VTApplet::updateMenu() | 113 | void VTApplet::updateMenu() |
114 | { | 114 | { |
115 | //qDebug( "VTApplet::updateMenu()" ); | 115 | //qDebug( "VTApplet::updateMenu()" ); |
116 | 116 | ||
117 | int fd = ::open( "/dev/console", O_RDONLY ); | 117 | int fd = ::open( "/dev/console", O_RDONLY ); |
118 | if ( fd == -1 ) return; | 118 | if ( fd == -1 ) return; |
119 | 119 | ||
120 | for ( int i = 1; i < 10; ++i ) | 120 | for ( int i = 1; i < 10; ++i ) |
121 | { | 121 | { |
122 | int result = ioctl( fd, VT_DISALLOCATE, i ); | 122 | int result = ioctl( fd, VT_DISALLOCATE, i ); |
123 | 123 | ||
124 | /* | 124 | /* |
125 | if ( result == -1 ) | 125 | if ( result == -1 ) |
126 | qDebug( "VT %d disallocated == free", i ); | 126 | qDebug( "VT %d disallocated == free", i ); |
127 | else | 127 | else |
128 | qDebug( "VT %d _not_ disallocated == busy", i ); | 128 | qDebug( "VT %d _not_ disallocated == busy", i ); |
129 | */ | 129 | */ |
130 | 130 | ||
131 | submenu->setItemEnabled( 500+i, result == -1 ); | 131 | m_subMenu->setItemEnabled( 500+i, result == -1 ); |
132 | } | 132 | } |
133 | 133 | ||
134 | ::close( fd ); | 134 | ::close( fd ); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | void VTApplet::activated() | 138 | void VTApplet::activated() |
139 | { | 139 | { |
140 | qDebug( "VTApplet::activated()" ); | 140 | qDebug( "VTApplet::activated()" ); |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | QRESULT VTApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) | 144 | QRESULT VTApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) |
145 | { | 145 | { |
146 | *iface = 0; | 146 | *iface = 0; |
147 | if ( uuid == IID_QUnknown ) | 147 | if ( uuid == IID_QUnknown ) |
148 | *iface = this; | 148 | *iface = this; |
149 | else if ( uuid == IID_MenuApplet ) | 149 | else if ( uuid == IID_MenuApplet ) |
150 | *iface = this; | 150 | *iface = this; |
151 | else | 151 | else |
152 | return QS_FALSE; | 152 | return QS_FALSE; |
153 | 153 | ||
154 | if ( *iface ) | 154 | if ( *iface ) |
155 | (*iface)-> addRef ( ); | 155 | (*iface)-> addRef ( ); |
156 | return QS_OK; | 156 | return QS_OK; |
157 | } | 157 | } |
158 | 158 | ||
159 | Q_EXPORT_INTERFACE( ) | 159 | Q_EXPORT_INTERFACE( ) |
160 | { | 160 | { |
161 | Q_CREATE_INSTANCE( VTApplet ) | 161 | Q_CREATE_INSTANCE( VTApplet ) |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
diff --git a/core/applets/vtapplet/vt.h b/core/applets/vtapplet/vt.h index 6bdb9e0..4c92ddd 100644 --- a/core/applets/vtapplet/vt.h +++ b/core/applets/vtapplet/vt.h | |||
@@ -1,54 +1,52 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** Contact me @ mickeyl@handhelds.org | 4 | ** Contact me @ mickeyl@handhelds.org |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | #ifndef __OPIE_VTAPPLET_H__ | 15 | #ifndef __OPIE_VTAPPLET_H__ |
16 | #define __OPIE_VTAPPLET_H__ | 16 | #define __OPIE_VTAPPLET_H__ |
17 | 17 | ||
18 | #include <qpe/menuappletinterface.h> | 18 | #include <qpe/menuappletinterface.h> |
19 | #include <qobject.h> | 19 | #include <qobject.h> |
20 | 20 | ||
21 | class VTApplet : public QObject, public MenuAppletInterface | 21 | class VTApplet : public QObject, public MenuAppletInterface |
22 | { | 22 | { |
23 | 23 | ||
24 | Q_OBJECT | 24 | Q_OBJECT |
25 | 25 | ||
26 | public: | 26 | public: |
27 | VTApplet ( ); | 27 | VTApplet ( ); |
28 | virtual ~VTApplet ( ); | 28 | virtual ~VTApplet ( ); |
29 | 29 | ||
30 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | 30 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); |
31 | Q_REFCOUNT | 31 | Q_REFCOUNT |
32 | 32 | ||
33 | virtual int position() const; | 33 | virtual int position() const; |
34 | 34 | ||
35 | virtual QString name ( ) const; | 35 | virtual QString name ( ) const; |
36 | virtual QIconSet icon ( ) const; | 36 | virtual QIconSet icon ( ) const; |
37 | virtual QString text ( ) const; | 37 | virtual QString text ( ) const; |
38 | //virtual QString tr( const char* ) const; | 38 | //virtual QString tr( const char* ) const; |
39 | //virtual QString tr( const char*, const char* ) const; | 39 | //virtual QString tr( const char*, const char* ) const; |
40 | virtual QPopupMenu *popup ( QWidget *parent ) const; | 40 | virtual QPopupMenu *popup ( QWidget *parent ) const; |
41 | 41 | ||
42 | virtual void activated (); | 42 | virtual void activated (); |
43 | 43 | ||
44 | public slots: | 44 | public slots: |
45 | virtual void changeVT( int index ); | 45 | virtual void changeVT( int index ); |
46 | virtual void updateMenu(); | 46 | virtual void updateMenu(); |
47 | |||
48 | private: | 47 | private: |
49 | ulong ref; | 48 | mutable QPopupMenu* m_subMenu; |
50 | }; | 49 | }; |
51 | 50 | ||
52 | static QPopupMenu* submenu; | ||
53 | 51 | ||
54 | #endif | 52 | #endif |