examples/SFExamples/Files/FileSharingCreator/src/FileSharingCreatorAppUi.cpp

00001 /*
00002  * Copyright (c) 2002-2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */ 
00029 
00030 // INCLUDES
00031 #include <f32file.h>
00032 #include <eikapp.h>
00033 #include <FileSharingCreator.rsg>
00034 
00035 #include "FileSharingCreatorAppUi.h"
00036 #include "FileSharingCreatorMainView.h"
00037 #include "FileSharingCreator.hrh"
00038 
00039 // CONSTANTS
00040 _LIT(KDataFileName,   "filesharing.txt");
00041 _LIT(KClientFileName, "FileSharingClient.exe");
00042 
00043 const TInt KFileServerSlot = 1;
00044 const TInt KFileHandleSlot = 2;
00045 
00046 // MEMBER FUNCTIONS
00047 
00048 // --------------------------------------------------------------------------
00049 // Constructor
00050 // --------------------------------------------------------------------------
00051 void CFileSharingCreatorAppUi::ConstructL()
00052         {
00053         BaseConstructL(EAknEnableSkin);
00054         
00055         iMainView = CFileSharingCreatorMainView::NewL(ClientRect());
00056         }
00057         
00058 // --------------------------------------------------------------------------
00059 // Destructor
00060 // --------------------------------------------------------------------------
00061 CFileSharingCreatorAppUi::~CFileSharingCreatorAppUi()
00062     {
00063     if (iMainView)
00064         {
00065         delete iMainView;
00066         iMainView = NULL;
00067         }
00068     }
00069 
00070 // --------------------------------------------------------------------------
00071 // Handles user command.
00072 // --------------------------------------------------------------------------
00073 void CFileSharingCreatorAppUi::HandleCommandL(TInt aCommand)
00074         {
00075         switch ( aCommand )
00076                 {
00077                 // For S60, we need to handle this event, which is normally
00078                 // an event from the right soft key.
00079                 case EAknSoftkeyExit:
00080                 case EEikCmdExit:
00081                         {
00082                         Exit();
00083                         break;
00084                         }
00085                 
00086                 case EFileSharingCreatorTransferToProcess:
00087                         {
00088                         DoTransferFileL();
00089                         
00090                         iEikonEnv->InfoWinL(
00091                                 R_FILESHARINGCREATOR_CAPTION,
00092                                 R_FILESHARINGCREATOR_TRANSFERRED);
00093                         break;
00094                         }
00095                 
00096                 default:
00097                         // Do nothing
00098                         break;
00099                 }
00100         }
00101 
00102         
00103 
00104 // --------------------------------------------------------------------------
00105 // Handles screen resolution/size changes.
00106 // --------------------------------------------------------------------------
00107 void CFileSharingCreatorAppUi::HandleResourceChangeL(TInt aType)
00108         {
00109         CAknAppUi::HandleResourceChangeL(aType);
00110         iMainView->SetRect(ClientRect());
00111         }
00112 
00113 
00114 
00115 void CFileSharingCreatorAppUi::DoTransferFileL()
00116         {
00117         // Connect to the file server session and share it.
00118         RFs fs;
00119         User::LeaveIfError(fs.Connect());
00120         CleanupClosePushL(fs);
00121         User::LeaveIfError(fs.ShareProtected());
00122         
00123         // Get the file name that is located in the private folder.
00124         RBuf privatePath;
00125         privatePath.Create(KMaxFileName);
00126         fs.PrivatePath(privatePath);
00127         TParsePtrC parseAppPath(Application()->AppFullName());
00128         TParse parse;
00129         parse.Set(parseAppPath.Drive(), &privatePath, &KDataFileName);
00130         
00131         // Open the file to be shared.
00132         RFile file;
00133         User::LeaveIfError(file.Open(fs, parse.FullName(), EFileRead));
00134         CleanupClosePushL(file);
00135         
00136         // Create the process that will use the file.
00137         RProcess process;
00138         User::LeaveIfError(process.Create(KClientFileName, KNullDesC));
00139         CleanupClosePushL(process);
00140         
00141         // Transfer to process storing the RFs handle into
00142         // environment slot KFileServerSlot and
00143         // the RFile handle into slot KFileHandleSlot.
00144         User::LeaveIfError(file.TransferToProcess(
00145                         process, KFileServerSlot, KFileHandleSlot));
00146         
00147         // Resume the process, which means start it.
00148         process.Resume();
00149         
00150         // Cleanup the resources.
00151         CleanupStack::PopAndDestroy(3, &fs); // close p, file, and fs
00152         }
00153 
00154 // End of File

Generated by  doxygen 1.6.2