⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btobjectexchangeappui.cpp

📁 This C++ code example provides a method for transferring objects or chunks of data from one device
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            aMenuPane->SetItemDimmed( EBTObjectExchangeStartServer, ETrue );
            aMenuPane->SetItemDimmed( EBTObjectExchangeStopServer, EFalse );
            aMenuPane->SetItemDimmed( EBTObjectExchangeConnect, ETrue );
            aMenuPane->SetItemDimmed( EBTObjectExchangeSendMessage, ETrue );
            aMenuPane->SetItemDimmed( EBTObjectExchangeDisconnect, ETrue );
            }
        else if ( iClient->IsConnected() )
            {
            aMenuPane->SetItemDimmed( EBTObjectExchangeStartServer, ETrue );
            aMenuPane->SetItemDimmed( EBTObjectExchangeStopServer, ETrue );
            aMenuPane->SetItemDimmed( EBTObjectExchangeConnect, ETrue );
            aMenuPane->SetItemDimmed( EBTObjectExchangeSendMessage, 
                iClient->IsBusy() );
            aMenuPane->SetItemDimmed( EBTObjectExchangeDisconnect, 
                iClient->IsBusy() );
            }
        
        // Display the Send menu item (if there are possible bearers)

        // Show only the bearers which support attachments
        TSendingCapabilities capabilities(0,0, TSendingCapabilities::ESupportsAttachments );
        
        
        #ifdef __SERIES60_3X__
            //In 3rd edition the menu item is not created in the rss
            TInt position = 0;
            //so find a desired command
            aMenuPane->ItemAndPos( EBTObjectExchangeClearList, position );
            //and add the Send menu item next to it
            iSendUi->AddSendMenuItemL(*aMenuPane, position-1, ESendViaSendUi, capabilities );
            
            //this could be used if the menu item was introduced in the rss
            //aMenuPane->ItemAndPos( ESendViaSendUi, position );
            //iSendUi->AddSendMenuItemL(*aMenuPane, position, ESendViaSendUi, capabilities );
        #else
            //In 1st and 2nd edition we have the Send menu item with its cascade
            //menu in the rss
            TInt position = 0;
            aMenuPane->ItemAndPos( ESendViaSendUi, position );
            iSendUi->DisplaySendMenuItemL (*aMenuPane, position, capabilities );
            aMenuPane->DeleteMenuItem(ESendViaSendUi);      
        #endif
        }
    #ifndef __SERIES60_3X__ //this is not needed in 3rd ed.
    
    else if ( aResourceId == R_BTOBEX_SENDUI_MENU) // Show the SendUI cascade menu
            {
            iSendUi->DisplaySendCascadeMenuL(*aMenuPane, NULL);
            }
    #endif

    }

TBool CBTObjectExchangeAppUi::AskFileL(TFileName& aFileName)
    {
    // Select memory
    CAknMemorySelectionDialog* memSelectionDialog = 
        CAknMemorySelectionDialog::NewL(ECFDDialogTypeNormal, EFalse);
    CleanupStack::PushL(memSelectionDialog);
    CAknMemorySelectionDialog::TMemory mem(CAknMemorySelectionDialog::EPhoneMemory);

    TInt ret = memSelectionDialog->ExecuteL(mem);
    CleanupStack::PopAndDestroy(memSelectionDialog);
    if (!ret) 
        {        
        return EFalse;
        }
    //Select file from the chosen memory
    CAknFileSelectionDialog* fileSelectionDialog = NULL; 
    if (mem == CAknMemorySelectionDialog::EMemoryCard)
        {  
        fileSelectionDialog = CAknFileSelectionDialog::NewL(ECFDDialogTypeNormal,R_FILE_SELECTION_DIALOG_E );
        }
    else
        {  
        fileSelectionDialog= CAknFileSelectionDialog::NewL(ECFDDialogTypeNormal,R_FILE_SELECTION_DIALOG_C );
        } 

    TBool result = fileSelectionDialog->ExecuteL(aFileName);
    delete fileSelectionDialog;
    return result;
    }
    
void CBTObjectExchangeAppUi::ShowMessageL( const TDesC& aMsg )
   {
   CAknInformationNote* informationNote;
   informationNote = new ( ELeave ) CAknInformationNote;
   informationNote->ExecuteLD( aMsg);
   }    

//after the joystick is pressed the current line (item) is 
//passed here. If the line matches a file name in current
//working directory then launch it using document handler
TBool CBTObjectExchangeAppUi::HandleJoystickPressL(TDesC& aLine)
    {
    TBool fileLaunched = EFalse;
    //First figure out the CWD:
    TParsePtrC parsePtr( KTempFile );        
    TFileName filename = parsePtr.DriveAndPath();
    
    //If the CWD + aLine lenght is too long then
    //aLine can't be a filename
    if ( filename.Length() + aLine.Length() > KMaxFileName )
        return fileLaunched; //can't be a filename
    
    //Otherwise check if it's a filename
    filename.Append(aLine);    
    if( !BaflUtils::FileExists(CEikonEnv::Static()->FsSession(),  filename) )
      return fileLaunched;
    
    //If the file exists in CWD then launch it using Document Handler API
    if (!iDocHandler )
        {
        #ifdef __SERIES60_3X__
        //In 3rd ed. the process is not given as a parameter
        iDocHandler = CDocumentHandler::NewL();                  
        #else
        //In older SDKs the process is given
        iDocHandler = CDocumentHandler::NewL( CEikonEnv::Static()->Process() );                      
        #endif
        }

    //Finally try to launch the file.
    TDataType empty = TDataType();
    
    iDocHandler->OpenFileEmbeddedL(filename,empty );    
    
    fileLaunched = ETrue;
    return fileLaunched;
    }
    
//Uses the Notifier API to ask the user to turn on Bluetooth
//if it's not on already.
void CBTObjectExchangeAppUi::TurnBtOnL()
    {
    //the constant is from btnotifierapi.h which is not in all SDKs
    //so it's hard coded here
    const TUid KPowerModeSettingNotifierUid = {0x100059E2};
    //const TUid KBTPowerStateNotifierUid = {0x101F808E}; //S80 and 7710
    
    RNotifier notifier;
    User::LeaveIfError( notifier.Connect() );
    TPckgBuf<TBool> dummy(ETrue);
    TPckgBuf<TBool> reply(EFalse);
    TRequestStatus stat;
    notifier.StartNotifierAndGetResponse(stat, KPowerModeSettingNotifierUid, dummy, reply);
    User::WaitForRequest(stat);
    notifier.CancelNotifier(KPowerModeSettingNotifierUid);
    notifier.Close();
    }

void CBTObjectExchangeAppUi::HandleResourceChangeL(TInt aType)
    {
    CAknAppUi::HandleResourceChangeL(aType); //call to upper class

    // ADDED FOR SCALABLE UI SUPPORT
    // *****************************
    //if ( aType == KEikDynamicLayoutVariantSwitch )
    //hardcoded constant so it can be compiled with 1st edition
    if ( aType == 0x101F8121 )
        {
        iAppView->SetRect( ClientRect() );
        }
    }

void CBTObjectExchangeAppUi::SendFileViaSendUiL(TInt aCommand)
    {
    TFileName path;
    
    if (AskFileL(path) )
        {
        TSendingCapabilities capabs( 0, 1024, TSendingCapabilities::ESupportsAttachments ); 

        #ifdef __SERIES60_3X__   
        RFs fs;
        CleanupClosePushL(fs);
        User::LeaveIfError( fs.Connect() );
        fs.ShareProtected();
        
        TInt error( KErrNone );
        
        RFile temp;
        User::LeaveIfError( temp.Open( fs, path, EFileShareReadersOnly | EFileRead ) );
        CleanupClosePushL(temp);
                
        CMessageData* messageData = CMessageData::NewL();
        CleanupStack::PushL(messageData);
        messageData->AppendAttachmentHandleL(temp);
        
        TRAPD(err, iSendUi->ShowQueryAndSendL(messageData, capabs) );

        if( err ) //error occured during sending
            {
            iAppView->LogL(KSenduiError, err);
            }
        else
            {
            //This is shown even if the user has selected cancel during sending,
            //for example, an MMS.
            iAppView->LogL(KSenduiOk);
            }

        CleanupStack::PopAndDestroy(messageData);
        
        CleanupStack::PopAndDestroy(&temp);
        CleanupStack::PopAndDestroy(&fs);        
        
        #else //1st and 2nd edition
        const TInt KGranularity = 2;
        CDesC16ArrayFlat* array = new ( ELeave )
                CDesC16ArrayFlat( KGranularity );
    	CleanupStack::PushL( array );

        array->AppendL( path );

    	//This would show the bearer selection:
        //iSendUi->CreateAndSendMessagePopupQueryL( _L("Send UI"), capabs, NULL, array ), 
        TRAPD(err,iSendUi->CreateAndSendMessageL(aCommand, NULL, array) );
        if( err ) //error occured during sending
            {
            iAppView->LogL(KSenduiError, err);
            }
        else
            {
            //This is shown even if the user has selected cancel during sending,
            //for example, an MMS.
            iAppView->LogL(KSenduiOk);
            }
        CleanupStack::PopAndDestroy(); // array
        #endif
        }
    else
        {
        //File Selection Canceled by user
        iAppView->LogL(KCanceled);
        }
    }
// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -