summaryrefslogtreecommitdiff
path: root/core/applets/vtapplet
authormickeyl <mickeyl>2003-09-22 12:06:07 (UTC)
committer mickeyl <mickeyl>2003-09-22 12:06:07 (UTC)
commitfd500184450e37c239e573adf1c12a6ff62b65f6 (patch) (unidiff)
tree2ce7fad7a9af7d17d1ab9495b1e32d353c5f08b0 /core/applets/vtapplet
parentbef84fa57fcb1ea5815ea55be7ac12b1a9df0c24 (diff)
downloadopie-fd500184450e37c239e573adf1c12a6ff62b65f6.zip
opie-fd500184450e37c239e573adf1c12a6ff62b65f6.tar.gz
opie-fd500184450e37c239e573adf1c12a6ff62b65f6.tar.bz2
FEATURE: vtapplet now indicates which virtual terminals are occupied
Diffstat (limited to 'core/applets/vtapplet') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vtapplet/vt.cpp41
-rw-r--r--core/applets/vtapplet/vt.h1
2 files changed, 31 insertions, 11 deletions
diff --git a/core/applets/vtapplet/vt.cpp b/core/applets/vtapplet/vt.cpp
index 6200447..4cc2d60 100644
--- a/core/applets/vtapplet/vt.cpp
+++ b/core/applets/vtapplet/vt.cpp
@@ -8,56 +8,48 @@
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
32class 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
40VTApplet::VTApplet ( ) 32VTApplet::VTApplet ( )
41 : QObject ( 0, "VTApplet" ), ref ( 0 ) 33 : QObject ( 0, "VTApplet" ), ref ( 0 )
42{ 34{
43} 35}
44 36
45VTApplet::~VTApplet ( ) 37VTApplet::~VTApplet ( )
46{ 38{
47} 39}
48 40
49int VTApplet::position ( ) const 41int VTApplet::position ( ) const
50{ 42{
51 return 2; 43 return 2;
52} 44}
53 45
54QString VTApplet::name ( ) const 46QString VTApplet::name ( ) const
55{ 47{
56 return tr( "VT shortcut" ); 48 return tr( "VT shortcut" );
57} 49}
58 50
59QString VTApplet::text ( ) const 51QString VTApplet::text ( ) const
60{ 52{
61 return tr( "Terminal" ); 53 return tr( "Terminal" );
62} 54}
63 55
@@ -67,76 +59,103 @@ QString VTApplet::tr( const char* s ) const
67 return qApp->translate( "VTApplet", s, 0 ); 59 return qApp->translate( "VTApplet", s, 0 );
68} 60}
69 61
70QString VTApplet::tr( const char* s, const char* p ) const 62QString VTApplet::tr( const char* s, const char* p ) const
71{ 63{
72 return qApp->translate( "VTApplet", s, p ); 64 return qApp->translate( "VTApplet", s, p );
73} 65}
74*/ 66*/
75 67
76QIconSet VTApplet::icon ( ) const 68QIconSet VTApplet::icon ( ) const
77{ 69{
78 QPixmap pix; 70 QPixmap pix;
79 QImage img = Resource::loadImage ( "terminal" ); 71 QImage img = Resource::loadImage ( "terminal" );
80 72
81 if ( !img. isNull ( )) 73 if ( !img. isNull ( ))
82 pix. convertFromImage ( img. smoothScale ( 14, 14 )); 74 pix. convertFromImage ( img. smoothScale ( 14, 14 ));
83 return pix; 75 return pix;
84} 76}
85 77
86QPopupMenu *VTApplet::popup ( QWidget* parent ) const 78QPopupMenu *VTApplet::popup ( QWidget* parent ) const
87{ 79{
88 qDebug( "VTApplet::popup" ); 80 qDebug( "VTApplet::popup" );
89 81
90 struct vt_stat vtstat; 82 struct vt_stat vtstat;
91 int fd = ::open("/dev/tty0", O_RDWR); 83 int fd = ::open( "/dev/tty0", O_RDWR );
92 if ( fd == -1 ) return 0; 84 if ( fd == -1 ) return 0;
93 if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0; 85 if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0;
94 86
95 submenu = new VTPopupMenu( parent ); 87 submenu = new QPopupMenu( parent );
96 submenu->setCheckable( true ); 88 submenu->setCheckable( true );
97 for ( int i = 1; i < 10; ++i ) 89 for ( int i = 1; i < 10; ++i )
98 { 90 {
99 int id = submenu->insertItem( QString::number( i ), 500+i ); 91 int id = submenu->insertItem( QString::number( i ), 500+i );
100 submenu->setItemChecked( id, id-500 == vtstat.v_active ); 92 submenu->setItemChecked( id, id-500 == vtstat.v_active );
101 } 93 }
102 ::close( fd ); 94 ::close( fd );
103 95
104 connect( submenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) ); 96 connect( submenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) );
97 connect( submenu, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) );
105 98
106 return submenu; 99 return submenu;
107} 100}
108 101
109 102
110void VTApplet::changeVT( int index ) 103void VTApplet::changeVT( int index )
111{ 104{
112 qDebug( "VTApplet::changeVT( %d )", index-500 ); 105 //qDebug( "VTApplet::changeVT( %d )", index-500 );
106
113 int fd = ::open("/dev/tty0", O_RDWR); 107 int fd = ::open("/dev/tty0", O_RDWR);
114 if ( fd == -1 ) return; 108 if ( fd == -1 ) return;
115 ioctl( fd, VT_ACTIVATE, index-500 ); 109 ioctl( fd, VT_ACTIVATE, index-500 );
116} 110}
117 111
118 112
113void VTApplet::updateMenu()
114{
115 //qDebug( "VTApplet::updateMenu()" );
116
117 int fd = ::open( "/dev/console", O_RDONLY );
118 if ( fd == -1 ) return;
119
120 for ( int i = 1; i < 10; ++i )
121 {
122 int result = ioctl( fd, VT_DISALLOCATE, i );
123
124 /*
125 if ( result == -1 )
126 qDebug( "VT %d disallocated == free", i );
127 else
128 qDebug( "VT %d _not_ disallocated == busy", i );
129 */
130
131 submenu->setItemEnabled( 500+i, result == -1 );
132 }
133
134 ::close( fd );
135}
136
137
119void VTApplet::activated() 138void VTApplet::activated()
120{ 139{
121 qDebug( "VTApplet::activated()" ); 140 qDebug( "VTApplet::activated()" );
122} 141}
123 142
124 143
125QRESULT VTApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) 144QRESULT VTApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface )
126{ 145{
127 *iface = 0; 146 *iface = 0;
128 if ( uuid == IID_QUnknown ) 147 if ( uuid == IID_QUnknown )
129 *iface = this; 148 *iface = this;
130 else if ( uuid == IID_MenuApplet ) 149 else if ( uuid == IID_MenuApplet )
131 *iface = this; 150 *iface = this;
132 151
133 if ( *iface ) 152 if ( *iface )
134 (*iface)-> addRef ( ); 153 (*iface)-> addRef ( );
135 return QS_OK; 154 return QS_OK;
136} 155}
137 156
138Q_EXPORT_INTERFACE( ) 157Q_EXPORT_INTERFACE( )
139{ 158{
140 Q_CREATE_INSTANCE( VTApplet ) 159 Q_CREATE_INSTANCE( VTApplet )
141} 160}
142 161
diff --git a/core/applets/vtapplet/vt.h b/core/applets/vtapplet/vt.h
index 2df9791..6bdb9e0 100644
--- a/core/applets/vtapplet/vt.h
+++ b/core/applets/vtapplet/vt.h
@@ -22,32 +22,33 @@ class VTApplet : public QObject, public MenuAppletInterface
22{ 22{
23 23
24 Q_OBJECT 24 Q_OBJECT
25 25
26public: 26public:
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
44public slots: 44public slots:
45 virtual void changeVT( int index ); 45 virtual void changeVT( int index );
46 virtual void updateMenu();
46 47
47private: 48private:
48 ulong ref; 49 ulong ref;
49}; 50};
50 51
51static QPopupMenu* submenu; 52static QPopupMenu* submenu;
52 53
53#endif 54#endif