Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vt.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
00003 **
00004 ** This file may be distributed and/or modified under the terms of the
00005 ** GNU General Public License version 2 as published by the Free Software
00006 ** Foundation and appearing in the file LICENSE.GPL included in the
00007 ** packaging of this file.
00008 **
00009 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00010 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00011 **
00012 **********************************************************************/
00013 
00014 #include "vt.h"
00015 
00016 /* OPIE */
00017 #include <opie2/odebug.h>
00018 #include <opie2/oresource.h>
00019 
00020 #include <qpe/applnk.h>
00021 
00022 using namespace Opie::Core;
00023 
00024 /* QT */
00025 #include <qpopupmenu.h>
00026 
00027 /* STD */
00028 #include <fcntl.h>
00029 #include <unistd.h>
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <sys/ioctl.h>
00033 #include <linux/vt.h>
00034 
00035 VTApplet::VTApplet()
00036          :QObject( 0, "VTApplet" ), m_ourVT( 0 )
00037 {
00038 }
00039 
00040 VTApplet::~VTApplet()
00041 {
00042 }
00043 
00044 int VTApplet::position() const
00045 {
00046     return 2;
00047 }
00048 
00049 QString VTApplet::name() const
00050 {
00051     return tr( "VT shortcut" );
00052 }
00053 
00054 QString VTApplet::text() const
00055 {
00056     return tr( "Terminal" );
00057 }
00058 
00059 /*
00060 QString VTApplet::tr( const char* s ) const
00061 {
00062     return qApp->translate( "VTApplet", s, 0 );
00063 }
00064 
00065 QString VTApplet::tr( const char* s, const char* p ) const
00066 {
00067     return qApp->translate( "VTApplet", s, p );
00068 }
00069 */
00070 
00071 QIconSet VTApplet::icon() const
00072 {
00073     QPixmap pix = Opie::Core::OResource::loadPixmap( "terminal", Opie::Core::OResource::SmallIcon );
00074     return pix;
00075 }
00076 
00077 QPopupMenu *VTApplet::popup( QWidget* parent ) const
00078 {
00079     odebug << "VTApplet::popup" << oendl;
00080 
00081     struct vt_stat vtstat;
00082 #ifdef QT_QWS_DEVFS
00083     int fd = ::open( "/dev/vc/0", O_RDWR );
00084 #else
00085     int fd = ::open( "/dev/tty0", O_RDWR );
00086 #endif
00087     if ( fd == -1 ) return 0;
00088     if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0;
00089 
00090     m_subMenu = new QPopupMenu( parent );
00091     m_subMenu->setCheckable( true );
00092     for ( int i = 1; i < 10; ++i )
00093     {
00094         int id = m_subMenu->insertItem( QString::number( i ), 500+i );
00095         m_subMenu->setItemChecked( id, id-500 == vtstat.v_active );
00096     }
00097     ::close( fd );
00098 
00099     m_ourVT = vtstat.v_active;
00100 
00101     connect( m_subMenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) );
00102     connect( m_subMenu, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) );
00103 
00104     return m_subMenu;
00105 }
00106 
00107 
00108 void VTApplet::changeVT( int index )
00109 {
00110     //odebug << "VTApplet::changeVT( " << index-500 << " )" << oendl;
00111 
00112 #ifdef QT_QWS_DEVFS
00113     int fd = ::open("/dev/vc/0", O_RDWR);
00114 #else
00115     int fd = ::open("/dev/tty0", O_RDWR);
00116 #endif
00117     if ( fd == -1 ) return;
00118     ioctl( fd, VT_ACTIVATE, index-500 );
00119     if ( m_ourVT )
00120     {
00121         odebug << "VTApplet::waiting for user to return to VT " << m_ourVT << oendl;
00122         ioctl( fd, VT_WAITACTIVE, m_ourVT );
00123     }
00124 }
00125 
00126 
00127 void VTApplet::updateMenu()
00128 {
00129     //odebug << "VTApplet::updateMenu()" << oendl;
00130 
00131     int fd = ::open( "/dev/console", O_RDONLY );
00132     if ( fd == -1 ) return;
00133 
00134     for ( int i = 1; i < 10; ++i )
00135     {
00136         int result = ioctl( fd, VT_DISALLOCATE, i );
00137 
00138         /*
00139         if ( result == -1 )
00140             odebug << "VT " << i << " disallocated == free" << oendl;
00141         else
00142             odebug << "VT " << i << " _not_ disallocated == busy" << oendl;
00143         */
00144 
00145         m_subMenu->setItemEnabled( 500+i, result == -1 );
00146     }
00147 
00148     ::close( fd );
00149 }
00150 
00151 
00152 void VTApplet::activated()
00153 {
00154     odebug << "VTApplet::activated()" << oendl;
00155 }
00156 
00157 
00158 QRESULT VTApplet::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
00159 {
00160     *iface = 0;
00161     if ( uuid == IID_QUnknown )
00162         *iface = this;
00163     else if ( uuid == IID_MenuApplet )
00164         *iface = this;
00165     else
00166         return QS_FALSE;
00167 
00168     if ( *iface )
00169         (*iface)-> addRef ( );
00170     return QS_OK;
00171 }
00172 
00173 Q_EXPORT_INTERFACE( )
00174 {
00175     Q_CREATE_INSTANCE( VTApplet )
00176 }
00177 
00178 

Generated on Sat Nov 5 16:15:25 2005 for OPIE by  doxygen 1.4.2