summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-06-25 15:28:21 (UTC)
committer mickeyl <mickeyl>2005-06-25 15:28:21 (UTC)
commit3d434ac35915afe7f7035468ca18656264a91c52 (patch) (side-by-side diff)
treef71edcbb83d4566f098da4de68f77a2f6058062f
parent3ec008c17167a17f89cc096779113c6b8369b257 (diff)
downloadopie-3d434ac35915afe7f7035468ca18656264a91c52.zip
opie-3d434ac35915afe7f7035468ca18656264a91c52.tar.gz
opie-3d434ac35915afe7f7035468ca18656264a91c52.tar.bz2
fix enable/disable logic for menu entries in popup
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/configdialog.cpp10
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp22
2 files changed, 18 insertions, 14 deletions
diff --git a/noncore/applets/pcmcia/configdialog.cpp b/noncore/applets/pcmcia/configdialog.cpp
index f94edde..3b1b40c 100644
--- a/noncore/applets/pcmcia/configdialog.cpp
+++ b/noncore/applets/pcmcia/configdialog.cpp
@@ -26,57 +26,57 @@
Boston, MA 02111-1307, USA.
*/
#include "configdialog.h"
/* OPIE */
#include <opie2/oconfig.h>
#include <opie2/odebug.h>
#include <opie2/opcmciasystem.h>
using namespace Opie::Core;
/* QT */
#include <qcombobox.h>
#include <qdir.h>
#include <qfile.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qtextstream.h>
ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
:ConfigDialogBase( parent, "pcmcia config dialog", true )
{
gbDetails->setTitle( QString( "Details for card in socket #%1" ).arg( card->number() ) );
- txtCardName->setText( card->productIdentity().join( " " ) );
+ txtCardName->setText( card->productIdentity() );
txtManfid->setText( card->manufacturerIdentity() );
txtFunction->setText( card->function() );
QString insertAction = preferredAction( card, "insert" );
QString resumeAction = preferredAction( card, "resume" );
- odebug << "pcmcia: preferred insertion action for card '" << card->name() << "' seems to be '" << insertAction << "'" << oendl;
- odebug << "pcmcia: preferred resume action for card '" << card->name() << "' seems to be '" << resumeAction << "'" << oendl;
+ odebug << "pcmcia: preferred insertion action for card '" << card->productIdentity() << "' seems to be '" << insertAction << "'" << oendl;
+ odebug << "pcmcia: preferred resume action for card '" << card->productIdentity() << "' seems to be '" << resumeAction << "'" << oendl;
if ( !insertAction.isEmpty() )
{
for ( int i; i < cbInsertAction->count(); ++i )
if ( cbInsertAction->text( i ) == insertAction ) cbInsertAction->setCurrentItem( i );
}
if ( !resumeAction.isEmpty() )
{
for ( int i; i < cbResumeAction->count(); ++i )
if ( cbResumeAction->text( i ) == resumeAction ) cbResumeAction->setCurrentItem( i );
}
if ( !card->isUnsupported() )
{
odebug << "pcmcia: card is recognized - hiding bindings" << oendl;
textInfo->hide();
textBindTo->hide();
cbBindTo->hide();
return;
}
else
{
odebug << "card is unsupported yet - showing possible bindings" << oendl;
@@ -111,69 +111,69 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
}
else
{
owarn << "couldn't open '" << conffile.name() << "' for reading" << oendl;
continue;
}
}
for ( StringMap::Iterator it = bindEntries.begin(); it != bindEntries.end(); ++it )
{
odebug << "found binding '" << it.key() << "' defined in '" << it.data().latin1() << "'" << oendl;
cbBindTo->insertItem( it.key() );
}
}
ConfigDialog::~ConfigDialog()
{
}
void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& value )
{
OConfig cfg( "PCMCIA" );
cfg.setGroup( "Global" );
int nCards = cfg.readNumEntry( "nCards", 0 );
- QString cardName = card->productIdentity().join( " " ).stripWhiteSpace();
+ QString cardName = card->productIdentity();
QString action;
for ( int i = 0; i < nCards; ++i )
{
QString cardSection = QString( "Card_%1" ).arg( i );
cfg.setGroup( cardSection );
QString name = cfg.readEntry( "name" );
odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
if ( cardName == name )
{
cfg.writeEntry( key, value );
break;
}
}
}
QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue )
{
OConfig cfg( "PCMCIA" );
cfg.setGroup( "Global" );
int nCards = cfg.readNumEntry( "nCards", 0 );
- QString cardName = card->productIdentity().join( " " ).stripWhiteSpace();
+ QString cardName = card->productIdentity();
QString value;
for ( int i = 0; i < nCards; ++i )
{
QString cardSection = QString( "Card_%1" ).arg( i );
cfg.setGroup( cardSection );
QString name = cfg.readEntry( "name" );
odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
if ( cardName == name )
{
value = cfg.readEntry( key, defaultValue );
break;
}
}
return value;
}
QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type )
{
return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" );
}
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index af23f58..c6386cb 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -55,49 +55,49 @@ using namespace Opie::Ui;
#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 ), popupMenu( 0 )
{
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( "pcmcia/pcmcia", Opie::Core::OResource::SmallIcon );
+ pm = Opie::Core::OResource::loadPixmap( "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();
while ( it.current() )
{
if ( !it.current()->isEmpty() )
{
@@ -142,147 +142,151 @@ enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE };
static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur" };
void PcmciaManager::mousePressEvent( QMouseEvent* )
{
QPopupMenu* menu = new QPopupMenu( this );
QStringList cmd;
bool execute = true;
OPcmciaSystem* sys = OPcmciaSystem::instance();
sys->synchronize();
OPcmciaSystem::CardIterator it = sys->iterator();
if ( !sys->count() ) return;
int i = 0;
while ( it.current() )
{
QPopupMenu* submenu = new QPopupMenu( menu );
submenu->insertItem( "&Eject", EJECT+i*100 );
submenu->insertItem( "&Insert", INSERT+i*100 );
submenu->insertItem( "&Suspend", SUSPEND+i*100 );
submenu->insertItem( "&Resume", RESUME+i*100 );
submenu->insertItem( "Rese&t", RESET+i*100 );
submenu->insertItem( "&Configure", CONFIGURE+i*100 );
- submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() );
- submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() );
- submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && it.current()->isSuspended() );
- submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() );
- submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring );
+ bool isSuspended = it.current()->isSuspended();
+ bool isEmpty = it.current()->isEmpty();
+
+ submenu->setItemEnabled( EJECT+i*100, !isEmpty );
+ submenu->setItemEnabled( INSERT+i*100, isEmpty );
+ submenu->setItemEnabled( SUSPEND+i*100, !isEmpty && !isSuspended );
+ submenu->setItemEnabled( RESUME+i*100, !isEmpty && isSuspended );
+ submenu->setItemEnabled( RESET+i*100, !isEmpty && !isSuspended );
+ submenu->setItemEnabled( CONFIGURE+i*100, !isEmpty && !configuring );
connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) );
menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 );
++it;
}
QPoint p = mapToGlobal( QPoint( 0, 0 ) );
QSize s = menu->sizeHint();
int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 );
qDebug( "pcmcia: menu result = %d", opt );
delete menu;
}
void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
{
odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl;
if ( msg != "stabChanged()" ) return;
/* check if a previously unknown card has been inserted */
OPcmciaSystem::instance()->synchronize();
if ( !OPcmciaSystem::instance()->cardCount() ) return;
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( " " ).stripWhiteSpace();
+ QString cardName = theCard->productIdentity();
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;
executeAction( theCard, "insert" );
break;
}
}
if ( !newCard ) ++it; else break;
}
}
if ( newCard )
{
odebug << "pcmcia: unconfigured card detected" << oendl;
- QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace();
+ QString newCardName = theCard->productIdentity();
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( conf );
if ( confFile.open( IO_ReadWrite | IO_Append ) )
{
QString entryCard = QString( "card \"%1\"" ).arg( newCardName );
QString entryVersion( " version " );
- for ( QStringList::Iterator it = theCard->productIdentity().begin(); it != theCard->productIdentity().end(); ++it )
+ for ( QStringList::Iterator it = theCard->productIdentityVector().begin(); it != theCard->productIdentityVector().end(); ++it )
{
entryVersion += QString( "\"%1\", " ).arg( *it );
}
QString entryBind = QString( " bind %1" ).arg( driver );
QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind );
odebug << "pcmcia: writing entry...:" << entry << oendl;
confFile.writeBlock( (const char*) entry, entry.length() );
Global::statusMessage( "restarting pcmcia services..." );
::system( "/etc/init.d/pcmcia restart" );
}
else
{
owarn << "pcmcia: couldn't write binding to '" << conf << "' ( " << strerror( errno ) << " )." << oendl;
}
}
else
{
odebug << "pcmcia: card has not been configured this time. leaving as unknown card" << oendl;
}
}
else
{
odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl;