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

shutdownimpl.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "shutdownimpl.h"
00022 
00023 #include <qpe/global.h>
00024 #include <qpe/qcopenvelope_qws.h>
00025 
00026 #include <qtimer.h>
00027 #include <qprogressbar.h>
00028 #include <qpushbutton.h>
00029 #include <qbuttongroup.h>
00030 #include <qlabel.h>
00031 #include <qlayout.h>
00032 
00033 
00034 static void changeButtonColor ( QPushButton *btn, const QColor &col )
00035 {
00036         QPalette pal = btn-> palette ( );
00037 
00038         pal. setColor ( QPalette::Active, QColorGroup::Button, col );
00039         pal. setColor ( QPalette::Disabled, QColorGroup::Button, col );
00040         pal. setColor ( QPalette::Inactive, QColorGroup::Button, col );
00041 
00042         btn-> setPalette ( pal );
00043 }
00044 
00045 
00046 ShutdownImpl::ShutdownImpl( QWidget* parent, const char *name, WFlags fl )
00047                 : QWidget ( parent, name, fl )
00048 {
00049         setCaption ( tr( "Shutdown..." ) );
00050 
00051         QVBoxLayout *vbox = new QVBoxLayout ( this );
00052         vbox-> setSpacing ( 3 );
00053         vbox-> setMargin ( 6 );
00054 
00055         QButtonGroup *btngrp = new QButtonGroup ( this );
00056 
00057         btngrp-> setTitle ( tr( "Terminate" ) );
00058         btngrp-> setColumnLayout ( 0, Qt::Vertical );
00059         btngrp-> layout ( ) -> setSpacing ( 0 );
00060         btngrp-> layout ( ) -> setMargin ( 0 );
00061 
00062         QGridLayout *grid = new QGridLayout ( btngrp-> layout ( ) );
00063         grid-> setAlignment ( Qt::AlignTop );
00064         grid-> setSpacing ( 3 );
00065         grid-> setMargin ( 7 );
00066 
00067         QPushButton *quit = new QPushButton ( tr( "Terminate Opie" ), btngrp, "quit" );
00068         changeButtonColor ( quit, QColor ( 236, 236, 179 ) );
00069         btngrp-> insert ( quit, 4 );
00070         grid-> addWidget ( quit, 1, 1 );
00071 
00072         QPushButton *reboot = new QPushButton ( tr( "Reboot" ), btngrp, "reboot" );
00073         changeButtonColor ( reboot, QColor( 236, 183, 181 ) );
00074         btngrp-> insert ( reboot, 2 );
00075         grid-> addWidget( reboot, 1, 0 );
00076 
00077         QPushButton *restart = new QPushButton ( tr( "Restart Opie" ), btngrp, "restart" );
00078         changeButtonColor ( restart, QColor( 236, 236, 179 ) );
00079         btngrp-> insert ( restart, 3 );
00080         grid-> addWidget ( restart, 0, 1 );
00081 
00082         QPushButton *shutdown = new QPushButton( tr( "Shutdown" ), btngrp, "shutdown" );
00083         changeButtonColor ( shutdown, QColor( 236, 183, 181 ) );
00084         btngrp-> insert ( shutdown, 1 );
00085         grid-> addWidget ( shutdown, 0, 0 );
00086 
00087         vbox-> addWidget ( btngrp );
00088 
00089         m_info = new QLabel ( this, "info" );
00090         vbox-> addWidget ( m_info );
00091 
00092         m_progress = new QProgressBar ( this, "progressBar" );
00093         m_progress-> setFrameShape ( QProgressBar::Panel );
00094         m_progress-> setFrameShadow ( QProgressBar::Sunken );
00095         m_progress-> setTotalSteps ( 20 );
00096         m_progress-> setIndicatorFollowsStyle ( false );
00097         vbox-> addWidget ( m_progress );
00098 
00099         vbox-> addItem ( new QSpacerItem ( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
00100 
00101         QPushButton *cancel = new QPushButton ( tr( "Cancel" ), this, "cancel" );
00102         changeButtonColor ( cancel, QColor( 181, 222, 178 ) );
00103         cancel-> setDefault ( true );
00104         cancel-> setSizePolicy ( QSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding, cancel-> sizePolicy ( ). hasHeightForWidth ( ) ) );
00105         vbox-> addWidget ( cancel );
00106 
00107         m_timer = new QTimer ( this );
00108         connect ( m_timer, SIGNAL( timeout() ), this, SLOT( timeout() ) );
00109 
00110         connect ( btngrp, SIGNAL( clicked(int) ), this, SLOT( buttonClicked(int) ) );
00111         connect ( cancel, SIGNAL( clicked() ), this, SLOT( cancelClicked() ) );
00112 
00113         m_progress-> hide ( );
00114         Global::hideInputMethod ( );
00115 }
00116 
00117 void ShutdownImpl::buttonClicked ( int b )
00118 {
00119         m_counter = 0;
00120 
00121         switch ( b ) {
00122                 case 1:
00123                         m_operation = ShutdownSystem;
00124                         break;
00125                 case 2:
00126                         m_operation = RebootSystem;
00127                         break;
00128                 case 3:
00129                         m_operation = RestartDesktop;
00130                         break;
00131                 case 4:
00132                         m_operation = TerminateDesktop;
00133                         break;
00134         }
00135         m_info-> hide ( );
00136         m_progress-> show ( );
00137         m_timer-> start ( 300 );
00138         timeout ( );
00139 }
00140 
00141 void ShutdownImpl::cancelClicked ( )
00142 {
00143         m_progress-> hide ( );
00144         m_info-> show ( );
00145         if ( m_timer-> isActive ( ) )
00146                 m_timer-> stop ( );
00147         else
00148                 close ( );
00149 }
00150 
00151 void ShutdownImpl::timeout ( )
00152 {
00153         if ( ( m_counter += 2 ) > m_progress-> totalSteps ( ) ) {
00154                 m_progress-> hide ( );
00155                 m_timer-> stop ( );
00156                 emit shutdown ( m_operation );
00157         }
00158         else
00159                 m_progress-> setProgress ( m_counter );
00160 }
00161 
00162 void ShutdownImpl::hide ( )
00163 {
00164         if ( isVisible ( )) {
00165                 // hack - shutdown is a launcher dialog, but treated like a standalone app
00166                 QCopEnvelope e( "QPE/System", "closing(QString)" );
00167                 e << QString ( "shutdown" );
00168         
00169         }
00170         QWidget::hide ( );
00171 }
00172 

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