mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteapp/src/MVSSaveAsDialog.cpp
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // MVSSavaAeDialog.cpp
       
    15 // Part of the MVS Application for TechView
       
    16 //
       
    17 
       
    18 #include "MVSSaveAsDialog.h"
       
    19 #include "MVSApp.hrh"
       
    20 #include <techview/eikcfdlg.h>
       
    21 #include <techview/eikon.hrh>
       
    22 #include <techview/eikfbrow.h>
       
    23 #include <techview/eikedwin.h>
       
    24 #include <eikenv.h>
       
    25 #include <coeutils.h>
       
    26 #include <f32file.h>
       
    27 #include <techview/eikfsel.h>
       
    28 #include <apparc.h>
       
    29 #include <eikproc.h>
       
    30 #include <techview/eikinfo.h>
       
    31 #include <eikfutil.h>
       
    32 #include <eikappui.h>
       
    33 #include <eikapp.h>
       
    34 #include <eikpanic.h>
       
    35 #include <techview/eikinfo.h>
       
    36 #include <uiklafgt/eikcore.rsg>
       
    37 #include <eikfile.rsg>
       
    38 
       
    39 _LIT(KAnyFile,"*");
       
    40 const TInt KShortErrorMessageLength = 64;
       
    41 const TInt KMaxDisplayedFullNameLen	= 35;
       
    42 
       
    43 TInt CMVSSaveAsDialog::SetupDialogLD(TDes& aFileName, TBool* aReplace)
       
    44 	{
       
    45     CMVSSaveAsDialog* dialog = new(ELeave) CMVSSaveAsDialog(aFileName, aReplace);
       
    46     TInt val = dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS);
       
    47     return val;
       
    48     }
       
    49 
       
    50 CMVSSaveAsDialog::CMVSSaveAsDialog(TDes& aFilename, TBool* aReplace):CEikFileSaveAsDialog(&aFilename),iFilename(aFilename)
       
    51     {
       
    52     iReplace = aReplace;
       
    53     }
       
    54 
       
    55 TBool CMVSSaveAsDialog::OkToExitL(TInt aButtonId)
       
    56 
       
    57     {
       
    58 	if (aButtonId==EEikBidBrowse)
       
    59 		{
       
    60 		HandleBrowseButtonL();
       
    61 		return EFalse;
       
    62 		}
       
    63 	else
       
    64 		{
       
    65 		CEikFileNameEditor* fileNameEditor=(CEikFileNameEditor*)(Control(EEikCidFileNameEd));
       
    66 		TFileName* fullName=new(ELeave) TFileName;
       
    67 		CleanupStack::PushL(fullName);
       
    68 		fileNameEditor->GetFullNameL(*fullName);
       
    69 		TUint attributes=0;
       
    70 		if (!ConeUtils::FileExists(*fullName))
       
    71 			{
       
    72 			ConeUtils::EnsurePathExistsL(*fullName);	
       
    73 			}
       
    74 		else
       
    75 			{
       
    76 			TBuf<32> infoDialogTitle;
       
    77 			iEikonEnv->ReadResource(infoDialogTitle,R_EIK_TBUF_DIALOG_TITLE_CONFIRM_FILE_REPLACE);
       
    78 			TBuf<KShortErrorMessageLength> formatStr;
       
    79 			User::LeaveIfError(iEikonEnv->FsSession().Att(*fullName,attributes));
       
    80 			if (attributes&KEntryAttReadOnly)
       
    81 				{
       
    82 				iEikonEnv->LeaveWithInfoMsg(R_EIK_TBUF_CANNOT_REPLACE_READONLY_FILE);
       
    83 				}		
       
    84 			else
       
    85 				{
       
    86 				iEikonEnv->ReadResource(formatStr,R_EIK_TBUF_FILE_REPLACE_CONFIRM1);
       
    87 				}
       
    88 			TBuf<KMaxDisplayedFullNameLen> abbrevName;
       
    89 			User::LeaveIfError(EikFileUtils::Parse(*fullName));
       
    90 			TParsePtr parse(*fullName);
       
    91 			EikFileUtils::AbbreviateFileName(parse.NameAndExt(),abbrevName);
       
    92 			TBuf<KShortErrorMessageLength + KMaxDisplayedFullNameLen> textMsg;
       
    93 			textMsg.Format(formatStr,&abbrevName);
       
    94 			CEikDialog* infoDialog=new(ELeave) CEikInfoDialog(infoDialogTitle,textMsg,CEikInfoDialog::EIgnoreEnter);
       
    95 			*iReplace = infoDialog->ExecuteLD(R_EIK_DIALOG_SINGLE_FILE_REPLACE);
       
    96 			}
       
    97 		// check disk is present in selected drive
       
    98 		TParsePtrC parse(*fullName);
       
    99 		TPtrC drv=parse.Drive();
       
   100 		TBuf<4> root(drv);
       
   101 		root.Append(TChar(KPathDelimiter));
       
   102 		root.Append(KAnyFile);
       
   103 		RDir dir;
       
   104 		const TInt ret=dir.Open(iEikonEnv->FsSession(),root,EFileRead|EFileShareAny);
       
   105 		if (ret==KErrNotReady)
       
   106 			{
       
   107 			iEikonEnv->LeaveWithInfoMsg(R_EIK_TBUF_DISK_NOT_PRESENT);
       
   108 			}
       
   109 		if (ret==KErrNone)
       
   110 			{
       
   111 			dir.Close();
       
   112 			}
       
   113 		//
       
   114 		iFilename=*fullName;
       
   115 		CleanupStack::PopAndDestroy(); // fullName
       
   116 		return ETrue;
       
   117 		}
       
   118     }