2005-01-18 15:49:23 +01:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
|
|
|
* Copyright 2005 by Eric House (fixin@peak.org).
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <eikedwin.h>
|
|
|
|
#include <eikmfne.h>
|
|
|
|
#include <eikchlst.h>
|
|
|
|
#include <eiktxlbm.h>
|
|
|
|
|
|
|
|
#include "symgmdlg.h"
|
|
|
|
#include "symutil.h"
|
2005-01-21 08:56:00 +01:00
|
|
|
#include "symgamed.h"
|
2005-01-18 15:49:23 +01:00
|
|
|
#include "xwords.hrh"
|
|
|
|
#include "xwords.rsg"
|
2005-01-19 16:11:07 +01:00
|
|
|
#include "xwappview.h"
|
2005-01-18 15:49:23 +01:00
|
|
|
|
|
|
|
|
2005-01-19 16:11:07 +01:00
|
|
|
CXSavedGamesDlg::CXSavedGamesDlg( MPFORMAL CXWordsAppView* aOwner,
|
|
|
|
CXWGamesMgr* aGameMgr,
|
|
|
|
const TGameName* aCurName,
|
|
|
|
TGameName* result )
|
|
|
|
: iOwner(aOwner), iGameMgr(aGameMgr), iCurName(aCurName), iResultP(result)
|
2005-01-18 15:49:23 +01:00
|
|
|
{
|
|
|
|
MPASSIGN( this->mpool, mpool );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CXSavedGamesDlg::PreLayoutDynInitL()
|
|
|
|
{
|
2005-01-21 08:56:00 +01:00
|
|
|
ResetNames( -1, iCurName );
|
2005-01-18 15:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TBool
|
|
|
|
CXSavedGamesDlg::OkToExitL( TInt aKeyCode )
|
|
|
|
{
|
|
|
|
TBool canReturn = EFalse;
|
|
|
|
CEikTextListBox* box;
|
|
|
|
const CListBoxView::CSelectionIndexArray* indices;
|
|
|
|
box = static_cast<CEikTextListBox*>(Control(ESelGameChoice));
|
2005-01-21 08:56:00 +01:00
|
|
|
TInt index = box->CurrentItemIndex();
|
2005-01-23 19:02:39 +01:00
|
|
|
TDesC16 selName = (*iGameMgr->GetNames())[index];
|
2005-01-18 15:49:23 +01:00
|
|
|
|
|
|
|
XP_LOGF( "CXSavedGamesDlg::OkToExitL(%d) called", aKeyCode );
|
|
|
|
|
|
|
|
switch( aKeyCode ) {
|
|
|
|
case XW_SGAMES_OPEN_COMMAND:
|
|
|
|
indices = box->SelectionIndexes();
|
|
|
|
if ( indices->Count() > 1 ) {
|
|
|
|
XP_LOGF( "too many selected" );
|
|
|
|
} else {
|
|
|
|
/* Don't use indices: invalid when multi-select isn't on? */
|
|
|
|
// TInt index = indices->At(0);
|
|
|
|
XP_LOGF( "the %dth is selected:", index );
|
|
|
|
*iResultP = (*iGameMgr->GetNames())[index];
|
|
|
|
XP_LOGDESC16( iResultP );
|
|
|
|
canReturn = ETrue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XW_SGAMES_RENAME_COMMAND:
|
2005-01-23 19:02:39 +01:00
|
|
|
if ( 0 == selName.Compare(*iCurName) ) {
|
2005-01-21 08:56:00 +01:00
|
|
|
iOwner->UserErrorFromID( R_ALERT_NO_RENAME_OPEN_GAME );
|
|
|
|
} else {
|
|
|
|
TGameName newName;
|
2005-01-23 19:02:39 +01:00
|
|
|
if ( EditSelName( static_cast<TGameName*>(&selName), &newName ) ) {
|
2005-01-21 08:56:00 +01:00
|
|
|
ResetNames( -1, &newName );
|
|
|
|
box->DrawDeferred();
|
|
|
|
}
|
|
|
|
}
|
2005-01-18 15:49:23 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XW_SGAMES_DELETE_COMMAND: {
|
|
|
|
XP_LOGF( "delete" );
|
2005-01-23 19:02:39 +01:00
|
|
|
if ( 0 == selName.Compare(*iCurName) ) {
|
2005-01-19 16:11:07 +01:00
|
|
|
iOwner->UserErrorFromID( R_ALERT_NO_DELETE_OPEN_GAME );
|
|
|
|
} else if ( iOwner->UserQuery( (UtilQueryID)SYM_QUERY_CONFIRM_DELGAME,
|
|
|
|
NULL ) ) {
|
2005-01-18 15:49:23 +01:00
|
|
|
if ( iGameMgr->DeleteSelected( index ) ) {
|
2005-01-21 08:56:00 +01:00
|
|
|
ResetNames( index, NULL );
|
2005-01-18 15:49:23 +01:00
|
|
|
box->DrawDeferred();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EEikBidCancel:
|
|
|
|
canReturn = ETrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return canReturn;
|
|
|
|
} /* OkToExitL */
|
|
|
|
|
|
|
|
void
|
2005-01-21 08:56:00 +01:00
|
|
|
CXSavedGamesDlg::ResetNames( TInt aPrefIndex,
|
|
|
|
const TGameName* aSelName )
|
2005-01-18 15:49:23 +01:00
|
|
|
{
|
|
|
|
CDesC16Array* names = iGameMgr->GetNames();
|
2005-01-21 08:56:00 +01:00
|
|
|
TInt index = 0; /* make compiler happy */
|
|
|
|
const TGameName* seekName = NULL;
|
|
|
|
|
|
|
|
if ( aPrefIndex >= 0 ) {
|
|
|
|
index = aPrefIndex;
|
|
|
|
} else if ( aSelName != NULL ) {
|
|
|
|
seekName = aSelName;
|
|
|
|
} else {
|
|
|
|
seekName = iCurName;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( seekName != NULL && ( 0 != names->Find( *seekName, index ) ) ) {
|
2005-01-18 15:49:23 +01:00
|
|
|
XP_LOGF( "Unable to find" );
|
2005-01-21 08:56:00 +01:00
|
|
|
XP_LOGDESC16( seekName );
|
2005-01-18 15:49:23 +01:00
|
|
|
XP_ASSERT( 0 );
|
|
|
|
index = 0; /* safe default if not found */
|
|
|
|
}
|
|
|
|
|
|
|
|
CEikTextListBox* box;
|
|
|
|
box = static_cast<CEikTextListBox*>(Control(ESelGameChoice));
|
|
|
|
|
|
|
|
box->Model()->SetItemTextArray( names );
|
|
|
|
box->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
|
|
|
|
box->HandleItemAdditionL();
|
2005-01-21 08:56:00 +01:00
|
|
|
|
2005-01-18 15:49:23 +01:00
|
|
|
box->SetCurrentItemIndex( index );
|
|
|
|
} /* ResetNames */
|
|
|
|
|
2005-01-21 08:56:00 +01:00
|
|
|
TBool
|
|
|
|
CXSavedGamesDlg::EditSelName( const TGameName* aSelName, TGameName* aNewName )
|
2005-01-18 15:49:23 +01:00
|
|
|
{
|
2005-01-21 08:56:00 +01:00
|
|
|
aNewName->Copy( *aSelName );
|
|
|
|
TBool renamed = EFalse;
|
|
|
|
|
|
|
|
if ( CNameEditDlg::EditName( aNewName ) ) {
|
|
|
|
if ( iGameMgr->Exists( aNewName ) ) {
|
|
|
|
iOwner->UserErrorFromID( R_ALERT_RENAME_TARGET_EXISTS );
|
|
|
|
} else if ( !iGameMgr->IsLegalName( aNewName ) ) {
|
|
|
|
iOwner->UserErrorFromID( R_ALERT_RENAME_TARGET_BADNAME );
|
|
|
|
} else {
|
|
|
|
iGameMgr->Rename( aSelName, aNewName );
|
|
|
|
renamed = ETrue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return renamed;
|
2005-01-18 15:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ TBool
|
2005-01-19 16:11:07 +01:00
|
|
|
CXSavedGamesDlg::DoGamesPicker( MPFORMAL CXWordsAppView* aOwner,
|
|
|
|
CXWGamesMgr* aGameMgr,
|
2005-01-18 15:49:23 +01:00
|
|
|
const TGameName* aCurName, TGameName* result )
|
|
|
|
{
|
2005-01-19 16:11:07 +01:00
|
|
|
CXSavedGamesDlg* me = new CXSavedGamesDlg( MPPARM(mpool) aOwner,
|
2005-01-18 15:49:23 +01:00
|
|
|
aGameMgr, aCurName, result );
|
|
|
|
User::LeaveIfNull( me );
|
|
|
|
|
|
|
|
return me->ExecuteLD( R_XWORDS_SAVEDGAMES_DLG );
|
|
|
|
} // DoGamesPicker
|