screenshotdata.cpp

来自「Symbian_OS_code 初学Symbian_OS学习代码, 屏幕截图软」· C++ 代码 · 共 215 行

CPP
215
字号
/*
 * ScreenShotData.cpp
 *
 * Copyright 2005 - 2008, Antony Pranata
 * http://www.antonypranata.com
 *
 * Project: Screenshot for Symbian OS.
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

// INCLUDE FILES
#include <symbianvariant.h>

#include "ScreenShotData.h"

// MEMBER FUNCTIONS

// --------------------------------------------------------------------------
// Default constructor.
// --------------------------------------------------------------------------
CScreenShotData::CScreenShotData()
:iMode(EModeOneShot),
 iShortcut(EShortcutCamera),
 iImageFormat(EFormatJpgNormal),
 iMemoryLocation(EPhoneMemory),
 iDelay(ENoDelay),
 iStartingIndexFileName(1)
	{
	}

// --------------------------------------------------------------------------
// Destructor.
// --------------------------------------------------------------------------
CScreenShotData::~CScreenShotData()
	{
	delete iDirectory;
	delete iFileName;
	}

// --------------------------------------------------------------------------
// Returns the directory where screenshot will be saved.
// --------------------------------------------------------------------------
TPtrC CScreenShotData::Directory() const
	{
	if (iDirectory)
		{
		return iDirectory->Des();
		}
	return KDefaultDirectory();
	}

// --------------------------------------------------------------------------
// Sets the directory where screenshot will be saved.
// --------------------------------------------------------------------------
void CScreenShotData::SetDirectoryL(const TDesC& aDirectory)
	{
	delete iDirectory;
	iDirectory = 0;

	if (aDirectory.Length() > 0)
		{
		// If aDirectory is not ended with backslash, then we have
		// to add another one. Otherwise, simply copy it.
		if (aDirectory[aDirectory.Length() - 1] != '\\')
			{
			iDirectory = HBufC::NewL(aDirectory.Length() + 1);
			TPtr directoryPtr(iDirectory->Des());
			directoryPtr.Append(aDirectory);
			directoryPtr.Append('\\');
			}
		else
			{
			iDirectory = aDirectory.AllocL();
			}
		}
	}

// --------------------------------------------------------------------------
// Gets the prefix of file name.
// --------------------------------------------------------------------------
TPtrC CScreenShotData::FileName() const
	{
	if (iFileName)
		{
		return iFileName->Des();
		}
	return KDefaultFileName();
	}

// --------------------------------------------------------------------------
// Sets the prefix of file name.
// --------------------------------------------------------------------------
void CScreenShotData::SetFileNameL(const TDesC& aFileName)
	{
	delete iFileName;
	iFileName = 0;
	if (aFileName.Length() > 0)
		{
		iFileName = aFileName.AllocL();
		}
	}

void CScreenShotData::SetStartingIndexFileName(TInt aStartingIndexFileName)
	{
	iStartingIndexFileName = aStartingIndexFileName;
	}

// --------------------------------------------------------------------------
// Stores the user preferences to aStream.
// --------------------------------------------------------------------------
void CScreenShotData::ExternalizeL(RWriteStream& aStream) const
	{
	aStream.WriteInt32L(iShortcut);
	aStream.WriteInt32L(iImageFormat);
	aStream.WriteInt32L(iMemoryLocation);

	if (iFileName)
		{
		aStream.WriteInt32L(iFileName->Length());
		aStream << *iFileName;
		}
	else
		{
		TPtrC fileNamePtr(KDefaultFileName);
		aStream.WriteInt32L(fileNamePtr.Length());
		aStream << fileNamePtr;
		}

	if (iDirectory)
		{
		aStream.WriteInt32L(iDirectory->Length());
		aStream << *iDirectory;
		}
	else
		{
		TPtrC directoryPtr(KDefaultDirectory);
		aStream.WriteInt32L(directoryPtr.Length());
		aStream << directoryPtr;
		}

	aStream.WriteInt32L(iDelay);
	aStream.WriteInt32L(iStartingIndexFileName);

	// Mode has to be written at the end to maintain compatibility with version 1.0.
	aStream.WriteInt32L(iMode);
	}

// --------------------------------------------------------------------------
// Reads the user's preferences from aStream.
// --------------------------------------------------------------------------
void CScreenShotData::InternalizeL(RReadStream& aStream)
	{
	iShortcut = (TShortcut) aStream.ReadInt32L();
	if ((iShortcut >= EShortcutEnd) || (iShortcut < 0))
		{
#ifdef __S60__
		iShortcut = EShortcutCamera;
#else
		iShortcut = EShortcutCamera;
#endif
		}
		
	iImageFormat = (TImageFormat) aStream.ReadInt32L();
	if ((iImageFormat >= EFormatEnd) || (iImageFormat < 0))
		{
		iImageFormat = EFormatJpgHigh;
		}
	
	iMemoryLocation = (TMemoryLocation) aStream.ReadInt32L();
	if ((iMemoryLocation >= EMemoryEnd) || (iMemoryLocation < 0))
		{
		iMemoryLocation = EPhoneMemory;
		}

	TInt length = aStream.ReadInt32L();
	delete iFileName;
	iFileName = 0;
	iFileName = HBufC::NewL(aStream, length);

	length = aStream.ReadInt32L();
	delete iDirectory;
	iDirectory = 0;
	iDirectory = HBufC::NewL(aStream, length);

	iDelay = (TDelay) aStream.ReadInt32L();
	if ((iDelay >= EDelayEnd) || (iDelay < 0))
		{
		iDelay = ENoDelay;
		}
	
	iStartingIndexFileName = (TInt) aStream.ReadInt32L();

	// Mode is stored at the end to maintain compatibility with version 1.0.
	// We need to check iMode with 2 because we have removed 2 from this version.
	iMode = (TMode) aStream.ReadInt32L();
	if ((iMode >= EModeEnd) || (iMode < 0) || (iMode == 2))
		{
		iMode = EModeOneShot;
		}
	}

// End of File

⌨️ 快捷键说明

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