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

logout.cpp

Go to the documentation of this file.
00001 #include "logout.h"
00002 
00003 #include <opie2/oresource.h>
00004 
00005 #include <qpe/applnk.h>
00006 #include <qpe/qcopenvelope_qws.h>
00007 
00008 #include <qapplication.h>
00009 #include <qmessagebox.h>
00010 
00011 #include <unistd.h>
00012 
00013 LogoutApplet::LogoutApplet ( )
00014         : QObject ( 0, "LogoutApplet" )
00015 {
00016 }
00017 
00018 LogoutApplet::~LogoutApplet ( )
00019 {
00020 }
00021 
00022 int LogoutApplet::position ( ) const
00023 {
00024     return 0;
00025 }
00026 
00027 QString LogoutApplet::name ( ) const
00028 {
00029         return tr( "Logout shortcut" );
00030 }
00031 
00032 QString LogoutApplet::text ( ) const
00033 {
00034         return tr( "Logout" );
00035 }
00036 
00037 QString LogoutApplet::tr( const char* s ) const
00038 {
00039     return qApp->translate( "LogoutApplet", s, 0 );
00040 }
00041 
00042 QString LogoutApplet::tr( const char* s, const char* p ) const
00043 {
00044     return qApp->translate( "LogoutApplet", s, p );
00045 }
00046 
00047 QIconSet LogoutApplet::icon ( ) const
00048 {
00049     QPixmap pix = Opie::Core::OResource::loadPixmap("logout", Opie::Core::OResource::SmallIcon );
00050         return pix;
00051 }
00052 
00053 QPopupMenu *LogoutApplet::popup ( QWidget * ) const
00054 {
00055         return 0;
00056 }
00057 
00058 // This is a workaround for a Qt bug
00059 // clipboard applet has to stop its poll timer, or Qt/E
00060 // will hang on quit() right before it emits aboutToQuit()
00061 
00062 class HackApplication : public QApplication {
00063 public:
00064         HackApplication ( ) : QApplication ( dummy, 0 )
00065         {
00066         }
00067 
00068         void emit_about_to_quit ( )
00069         {
00070                 emit aboutToQuit ( );
00071         }
00072 
00073         int dummy;
00074 };
00075 
00076 
00077 void LogoutApplet::activated ( )
00078 {
00079         QMessageBox mb ( tr( "Logout" ),
00080                          tr( "Do you really want to\nend this session ?" ),
00081                          QMessageBox::NoIcon,
00082                          QMessageBox::Yes | QMessageBox::Default,
00083                          QMessageBox::No | QMessageBox::Escape,
00084                          QMessageBox::NoButton );
00085 
00086         mb. setButtonText ( QMessageBox::Yes, "Yes" );
00087         mb. setButtonText ( QMessageBox::No, "No" );
00088         mb. setIconPixmap ( icon ( ). pixmap ( ));
00089 
00090         if ( mb. exec ( ) == QMessageBox::Yes ) {
00091                 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); }
00092 
00093                 qApp-> processEvents ( ); // ensure the message goes out.
00094                 sleep ( 1 );  // You have 1 second to comply.
00095 
00096                 ((HackApplication *) qApp )-> emit_about_to_quit ( );
00097                 qApp-> quit();
00098         }
00099 }
00100 
00101 
00102 QRESULT LogoutApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface )
00103 {
00104         *iface = 0;
00105         if ( uuid == IID_QUnknown )
00106                 *iface = this;
00107         else if ( uuid == IID_MenuApplet )
00108                 *iface = this;
00109         else
00110             return QS_FALSE;
00111 
00112         if ( *iface )
00113                 (*iface)-> addRef ( );
00114         return QS_OK;
00115 }
00116 
00117 Q_EXPORT_INTERFACE( )
00118 {
00119         Q_CREATE_INSTANCE( LogoutApplet )
00120 }
00121 

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