author | mickeyl <mickeyl> | 2005-06-21 14:11:55 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-06-21 14:11:55 (UTC) |
commit | ae85d18a1f8a63323ad47631724516f3aa355a75 (patch) (side-by-side diff) | |
tree | 9238ab79beabca8f035714f3e339513c06685d2a | |
parent | 65ea54f43ee7dcbd95ffb474c8dfbb8b076d43e5 (diff) | |
download | opie-ae85d18a1f8a63323ad47631724516f3aa355a75.zip opie-ae85d18a1f8a63323ad47631724516f3aa355a75.tar.gz opie-ae85d18a1f8a63323ad47631724516f3aa355a75.tar.bz2 |
- prepare methods to execute the preferred actions on insertion and suspend
- intercept QPE/System channel to listen for 'resumeFromSuspend()'
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.cpp | 35 | ||||
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.h | 5 |
2 files changed, 39 insertions, 1 deletions
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp index 186dfea..0787c3c 100644 --- a/noncore/applets/pcmcia/pcmcia.cpp +++ b/noncore/applets/pcmcia/pcmcia.cpp @@ -49,71 +49,94 @@ using namespace Opie::Ui; #include <qcopchannel_qws.h> #include <qpainter.h> #include <qfile.h> #include <qtextstream.h> #include <qmessagebox.h> #include <qsound.h> #include <qtimer.h> /* STD */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <fcntl.h> #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) #include <sys/vfs.h> #include <mntent.h> #endif PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) { QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); connect( pcmciaChannel, SIGNAL( received(const QCString&,const QByteArray&) ), this, SLOT( cardMessage(const QCString&,const QByteArray&) ) ); setFocusPolicy( NoFocus ); setFixedWidth ( AppLnk::smallIconSize() ); setFixedHeight ( AppLnk::smallIconSize() ); pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); configuring = false; + + QCopChannel *channel = new QCopChannel( "QPE/System", this ); + connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), + this, SLOT(handleSystemChannel(const QCString&,const QByteArray&)) ); } PcmciaManager::~PcmciaManager() { } +void PcmciaManager::handleSystemChannel( const QCString&msg, const QByteArray& ) +{ + if ( msg == "returnFromSuspend()" ) + { + if ( !OPcmciaSystem::instance()->cardCount() ) return; + OPcmciaSystem* sys = OPcmciaSystem::instance(); + OPcmciaSystem::CardIterator it = sys->iterator(); + OPcmciaSocket* theCard = 0; + + while ( it.current() ) + { + if ( it.current()->isEmpty() ) + { + executeResumeAction( theCard ); + } + ++it; + } + } +} void PcmciaManager::popUp( QString message, QString icon ) { if ( !popupMenu ) { popupMenu = new QPopupMenu( this ); } popupMenu->clear(); if ( icon.isEmpty() ) { popupMenu->insertItem( message, 0 ); } else { popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), message, 0 ); } QPoint p = mapToGlobal( QPoint( 0, 0 ) ); QSize s = popupMenu->sizeHint(); popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); } void PcmciaManager::popupTimeout() { popupMenu->hide(); } enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE }; void PcmciaManager::mousePressEvent( QMouseEvent* ) @@ -168,64 +191,66 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) OConfig cfg( "PCMCIA" ); cfg.setGroup( "Global" ); int nCards = cfg.readNumEntry( "nCards", 0 ); OPcmciaSystem* sys = OPcmciaSystem::instance(); OPcmciaSystem::CardIterator it = sys->iterator(); bool newCard = true; OPcmciaSocket* theCard = 0; while ( it.current() && newCard ) { if ( it.current()->isEmpty() ) { odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl; ++it; continue; } else { theCard = it.current(); QString cardName = theCard->productIdentity().join( " " ); for ( int i = 0; i < nCards; ++i ) { QString cardSection = QString( "Card_%1" ).arg( i ); cfg.setGroup( cardSection ); QString name = cfg.readEntry( "name" ); odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl; if ( cardName == name ) { newCard = false; + odebug << "pcmcia: we have seen this card before" << oendl; + executeInsertAction( theCard ); break; } } if ( !newCard ) ++it; else break; } } if ( newCard ) { odebug << "pcmcia: unconfigured card detected" << oendl; QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace(); int result = QMessageBox::information( qApp->desktop(), tr( "PCMCIA/CF Subsystem" ), tr( "<qt>You have inserted the card<br/><b>%1</b><br/>This card is not yet configured. Do you want to configure it now?</qt>" ).arg( newCardName ), tr( "Yes" ), tr( "No" ), 0, 0, 1 ); odebug << "pcmcia: result = " << result << oendl; if ( result == 0 ) { QString insertAction; QString resumeAction; QString driver; QString conf; bool configured = configure( theCard, insertAction, resumeAction, driver, conf ); if ( configured ) { odebug << "pcmcia: card has been configured. writing out to database" << oendl; cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); cfg.writeEntry( "name", newCardName ); cfg.writeEntry( "insertAction", insertAction ); cfg.writeEntry( "resumeAction", resumeAction ); cfg.setGroup( "Global" ); cfg.writeEntry( "nCards", nCards+1 ); cfg.write(); QFile confFile( QString( "/etc/pcmcia/%1" ).arg( conf ) ); @@ -315,35 +340,45 @@ void PcmciaManager::userCardAction( int action ) case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); break; case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); break; case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); break; case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); break; case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); break; default: odebug << "pcmcia: not yet implemented" << oendl; } if ( !success ) { owarn << "pcmcia: couldn't perform user action (" << strerror( errno ) << ")" << oendl; } } bool PcmciaManager::configure( OPcmciaSocket* card, QString& insertAction, QString& resumeAction, QString& driver, QString& conf ) { configuring = true; ConfigDialog dialog( card, qApp->desktop() ); int configresult = QPEApplication::execDialog( &dialog, false ); configuring = false; odebug << "pcmcia: configresult = " << configresult << oendl; if ( configresult ) { insertAction = dialog.cbInsertAction->currentText(); resumeAction = dialog.cbResumeAction->currentText(); driver = dialog.cbBindTo->currentText(); conf = dialog.bindEntries[driver]; } return configresult; } +void PcmciaManager::executeInsertAction( Opie::Core::OPcmciaSocket* card ) +{ + odebug << "pcmcia: execute insert action" << oendl; +} + +void PcmciaManager::executeResumeAction( Opie::Core::OPcmciaSocket* card ) +{ + odebug << "pcmcia: execute resume action" << oendl; +} + EXPORT_OPIE_APPLET_v1( PcmciaManager ) diff --git a/noncore/applets/pcmcia/pcmcia.h b/noncore/applets/pcmcia/pcmcia.h index 94203d3..6567cd7 100644 --- a/noncore/applets/pcmcia/pcmcia.h +++ b/noncore/applets/pcmcia/pcmcia.h @@ -16,55 +16,58 @@ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef PCMCIA_H #define PCMCIA_H #include <qwidget.h> #include <qpixmap.h> #include <qpopupmenu.h> namespace Opie { namespace Core { class OPcmciaSocket; } }; class PcmciaManager : public QWidget { Q_OBJECT public: PcmciaManager( QWidget *parent = 0 ); ~PcmciaManager(); static int position(); private slots: - void cardMessage( const QCString& msg, const QByteArray& ); + void handleSystemChannel( const QCString&, const QByteArray& ); + void cardMessage( const QCString&, const QByteArray& ); void userCardAction( int action ); void popupTimeout(); protected: void paintEvent( QPaintEvent* ); void mousePressEvent( QMouseEvent * ); private: bool configure( Opie::Core::OPcmciaSocket*, QString&, QString&, QString&, QString& ); void execCommand( const QStringList &command ); + void executeInsertAction( Opie::Core::OPcmciaSocket* ); + void executeResumeAction( Opie::Core::OPcmciaSocket* ); void popUp(QString message, QString icon = QString::null ); private: bool configuring; int commandOrig; QPixmap pm; QPopupMenu *popupMenu; }; #endif |