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