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

📄 filelistview.cpp

📁 手机文件浏览器 Here are the sources to SMan v1.2c 1.2 is a major jump from v1.1. You will see this from the
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "filelistview.h"
#include "sman.h"
#include <SMan.rsg>

/*************************************************************
*
* File browser view.
*
**************************************************************/

CSMan2FileListView::CSMan2FileListView(CConfig *cData) : CViewBase(cData)
{
}

TBool CSMan2FileListView::ViewScreenModeCompatible(TInt aScreenMode)
{
	return (aScreenMode == 0);
}

TVwsViewIdAndMessage CSMan2FileListView::ViewScreenDeviceChangedL()
{
	return TVwsViewIdAndMessage(TVwsViewId(KUidSMan2App, KUidFlipclosedView));
}

void CSMan2FileListView::ViewDeactivated()
{
	activateCount--;
	if (activateCount <= 0)
	{
		MakeVisible(EFalse);
		static_cast<CEikAppUi*>(iEikonEnv->AppUi())->RemoveFromStack(this);
	}
}

void CSMan2FileListView::ViewActivatedL(const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
{
	doViewActivated();
}

TVwsViewId CSMan2FileListView::ViewId() const
{
	return TVwsViewId(KUidSMan2App, KUidFileView);
}

CSMan2FileListView::~CSMan2FileListView()
{
	for (int i = 0; i < KMaxDrives; i++)
		if (driveOldPath[i] != NULL)
			delete driveOldPath[i];
	delete crcCalculator;
	delete blueBeam;
	delete clipBoard;
	delete fileList;
	if (currentPathScroller->IsActive())
		currentPathScroller->Cancel();
	delete currentPathScroller;
}

TKeyResponse CSMan2FileListView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
	if (aType == EEventKey)
	{
		if (aKeyEvent.iCode == EQuartzKeyConfirm)
		{
			TPointerEvent fakeEvent;

			// This modifier is almost impossible to get in real life (and definitely impossible on the P800 due to lack of keyboard).
			// We use this modifier to tell the pointer handler that this is a fake event. 			
			fakeEvent.iModifiers = EAllModifiers;
			fakeEvent.iPosition = cFileListBox->View()->ItemPos(cFileListBox->CurrentItemIndex());
			fakeEvent.iPosition.iX = cFileListBox->View()->ItemDrawer()->MarkColumn() + 1;	// Force x coordinate to the right.
			fakeEvent.iType = TPointerEvent::EButton1Down;
			// Note, this event must never be passed to the default pointer event handler!!
			// In this case, we're sure it will never happen because our overridden handler
			// will consume it.
			HandlePointerEventL(fakeEvent);
			return EKeyWasConsumed;
		}
		else if (aKeyEvent.iCode == EQuartzKeyTwoWayDown)
		{
			cFileListBox->View()->MoveCursorL(CListBoxView::ECursorNextItem, CListBoxView::ENoSelection);
			cFileListBox->UpdateScrollBarsL();
			updateFileDateTime();
			return EKeyWasConsumed;
		}
		else if (aKeyEvent.iCode == EQuartzKeyTwoWayUp)
		{
			cFileListBox->View()->MoveCursorL(CListBoxView::ECursorPreviousItem, CListBoxView::ENoSelection);
			cFileListBox->UpdateScrollBarsL();
			updateFileDateTime();
			return EKeyWasConsumed;
		}
	}
	return cFileListBox->OfferKeyEventL(aKeyEvent, aType);
}

void CSMan2FileListView::getFileAttrib(TDes *attribText, TInt index)
{
	if ((*fileList)[index].IsReadOnly())
		attribText->Append(_L("R"));
	else
		attribText->Append(_L("-"));
		
	if ((*fileList)[index].IsSystem())
		attribText->Append(_L("S"));
	else
		attribText->Append(_L("-"));

	if ((*fileList)[index].IsHidden())
		attribText->Append(_L("H"));
	else
		attribText->Append(_L("-"));
		
	if ((*fileList)[index].IsArchive())
		attribText->Append(_L("A"));
	else
		attribText->Append(_L("-"));
}

void CSMan2FileListView::updateFileDateTime(void)
{
	TTime fileDateTime;
	TBuf<7> attrib;
	
	attrib.Copy(_L(""));
	textFileDateTime = _L("");
	if (fileList->Count() > 0)
	{
		// Compensate for ".." entry. fileList does not have this entry while cFileListBox
		// does!
		if (currentPath.Length() > 3)
		{
			if ((cFileListBox->CurrentItemIndex() > 0) && (cFileListBox->CurrentItemIndex() <= fileList->Count()))
			{
				fileDateTime = (*fileList)[cFileListBox->CurrentItemIndex() - 1].iModified;
				fileDateTime.FormatL(textFileDateTime, _L("%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"));
				getFileAttrib(&attrib, cFileListBox->CurrentItemIndex() - 1);
			}
		}
		else
		{
			if (cFileListBox->CurrentItemIndex() <= fileList->Count() - 1)
			{
				fileDateTime = (*fileList)[cFileListBox->CurrentItemIndex()].iModified;
				fileDateTime.FormatL(textFileDateTime, _L("%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"));
				getFileAttrib(&attrib, cFileListBox->CurrentItemIndex());
			}
		}
	}
	attrib.Append(_L("  ")); 
	textFileDateTime.Insert(0, attrib);
	labelFileDateTime->SetTextL(textFileDateTime);
	labelFileDateTime->DrawNow();
}

void CSMan2FileListView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
	TBool consumed = EFalse;
	TInt theItem;
	TBool pointValid = cFileListBox->View()->XYPosToItemIndex(aPointerEvent.iPosition, theItem);
	TPtrC tempText, selectedType, selectedName;

	if ((cFileListBox->Model()->ItemTextArray()->MdcaCount() > 0) && (pointValid) && (!cFileListBox->DrawableWindow()->IsFaded()))
	{
		tempText.Set(cFileListBox->Model()->ItemTextArray()->MdcaPoint(theItem));
		TextUtils::ColumnText(selectedType, 1, &tempText);
		TextUtils::ColumnText(selectedName, 0, &tempText);

		if (aPointerEvent.iType == TPointerEvent::EDrag)
		{
			if ((pointValid) && (oldItem != theItem) && (aPointerEvent.iPosition.iX <= cFileListBox->View()->ItemDrawer()->MarkColumn()))
			{
				consumed = ETrue;
				if ((selectedType.Compare(_L("<drv>")) != 0) && (selectedName.Compare(_L("..")) != 0))
				{
					cFileListBox->View()->VerticalMoveToItemL(theItem, CListBoxView::EDisjointSelection);
					cFileListBox->UpdateScrollBarsL();
				}
				oldItem = theItem;
			}
		}
		else if (aPointerEvent.iType == TPointerEvent::EButton1Down)
		{
			consumed = ETrue;
			oldItem = theItem;
			if (aPointerEvent.iPosition.iX > cFileListBox->View()->ItemDrawer()->MarkColumn())
			{
				// Change folder
				tempText.Set(cFileListBox->Model()->ItemTextArray()->MdcaPoint(theItem));
				
				// Check if user selected directory
				if ((selectedType.Compare(_L("<dir>")) == 0) || (selectedType.Compare(_L("<drv>")) == 0))
				{
					// Did user click on the filename?
					if (aPointerEvent.iPosition.iX < (((CColumnListBoxItemDrawer*)cFileListBox->ItemDrawer())->ColumnData()->ColumnWidthPixel(0) + cFileListBox->View()->ItemDrawer()->MarkColumn()))
					{
						cFileListBox->ClearSelection();
						// Highlight the item very briefly
						cFileListBox->SetCurrentItemIndexAndDraw(theItem);
						cFileListBox->SetFocus(ETrue, EDrawNow);
						User::After(5000);
						cFileListBox->Reset();
						
						//TextUtils::ColumnText(selectedDir, 0, &tempText);
						if (selectedName.Compare(_L("..")) == 0)
						{
							// One level up
							currentPath.SetLength(currentPath.Length() - 1); // remove slash
							currentPath.SetLength(currentPath.LocateReverse(TChar('\\')));
						}
						else
						{
							if (selectedName.Right(1) != _L(":"))
								currentPath.Append(selectedName);
							else
							{
								TInt driveIndex = (selectedName.Left(1))[0] - 65;
								if (driveOldPath[driveIndex] != NULL)
									currentPath.Copy(*driveOldPath[driveIndex]);
								else
									currentPath.Copy(selectedName);
								if (currentPath.Right(1).Compare(_L("\\")) == 0)
									currentPath.SetLength(currentPath.Length() - 1);
							}
						}
						currentPath.Append(_L("\\"));
						fillListBox(currentPath);
					}
					else
					// No, user clicked on file size column... then highlight only
					{
						cFileListBox->View()->VerticalMoveToItemL(theItem, CListBoxView::ENoSelection);
						cFileListBox->UpdateScrollBarsL();
						updateFileDateTime();
					}
				}
				else
				{
					// Did user click on the filename?
					if (aPointerEvent.iPosition.iX < (((CColumnListBoxItemDrawer*)cFileListBox->ItemDrawer())->ColumnData()->ColumnWidthPixel(0) + cFileListBox->View()->ItemDrawer()->MarkColumn()))
					{
						// Is this a fake pointer event generated by our key handler? If not, process it
						// like an open command else do nothing
						if (aPointerEvent.iModifiers == EAllModifiers)
							cFileListBox->View()->VerticalMoveToItemL(theItem, CListBoxView::EDisjointSelection);
						else
							cFileListBox->View()->VerticalMoveToItemL(theItem, CListBoxView::ENoSelection);
						cFileListBox->UpdateScrollBarsL();
						updateFileDateTime();
						
						if ((aPointerEvent.iModifiers != EAllModifiers) && ((configData->autoOpenFile) || (configData->autoRunApp)))
							static_cast<CSMan2AppUi*>(CEikonEnv::Static()->AppUi())->doProcessCommand(cmdFileManOpen);
					}
					else
					// No, user clicked on file size column... then highlight only
					{
						cFileListBox->View()->VerticalMoveToItemL(theItem, CListBoxView::ENoSelection);
						cFileListBox->UpdateScrollBarsL();
						updateFileDateTime();
					}
				}					
			}
			else
			{
				tempText.Set(cFileListBox->Model()->ItemTextArray()->MdcaPoint(theItem));
				
				// Only allow the user to select if it is not a drive or ".."
				if ((selectedType.Compare(_L("<drv>")) != 0) && (selectedName.Compare(_L("..")) != 0))
				{
					cFileListBox->View()->VerticalMoveToItemL(theItem, CListBoxView::EDisjointSelection);
					cFileListBox->UpdateScrollBarsL();
					updateFileDateTime();
				}
				else
					iEikonEnv->InfoMsg(R_TBUF_FILEMAN_WRONGSELECT);
			}
		}
	}
	// Prevent user from clicking on the label buttons we use as display for
	// folder path and file date time
	if (aPointerEvent.iPosition.iY < cFileListBox->Position().iY)
		consumed = ETrue;

	if (!consumed)
		CCoeControl::HandlePointerEventL(aPointerEvent);
}

void CSMan2FileListView::fillListBox(TPath thePath)
{
	RFs fileServer;
	TPath temp;
	TBuf<20> fileSize;
	CDesCArray *iArray;
	TInt i;
	
	temp.Copy(thePath);
	temp.Append(_L("*"));
	fileServer.Connect();
	cFileListBox->ClearSelection();
	iArray = ((CDesCArray *) cFileListBox->Model()->ItemTextArray());
	iArray->Reset();
	cFileListBox->HandleItemRemovalL();
	currentPath.SetLength(0);
	if (fileList)
		delete fileList;
		
	TInt attribs = KEntryAttMaskSupported;
	if (!configData->showHiddenFiles)
		attribs ^= KEntryAttHidden;
		
	if (fileServer.GetDir(temp, attribs, ESortByName | EDirsFirst, fileList) == KErrNone)
	{		
		TFileName tempText;
		
		// Navigation upwards. Only allow if thePath is not a root folder
		if (thePath.Length() > 3)
		{
			tempText.Copy(_L(".."));
			tempText.Append(KColumnListSeparator);
			tempText.Append(_L("<dir>"));
			iArray->AppendL(tempText);
		}
		currentPath.Append(thePath);
		for (i = 0; i < fileList->Count(); i++)
		{
			tempText = (*fileList)[i].iName;
			tempText.Append(KColumnListSeparator);
			
			// Dir check
			if ((*fileList)[i].IsDir())
				tempText.Append(_L("<dir>"));
			else
			{
				if (((*fileList)[i].iSize) < 1024)
				{
					fileSize.Num((*fileList)[i].iSize);
					fileSize.Append(_L("b"));
				}
				else
				{
					fileSize.Num((*fileList)[i].iSize / 1024);
					fileSize.Append(_L("k"));
				}
				tempText.Append(fileSize);
			}
			iArray->AppendL(tempText);
		}
		
		// Add drive letters
		TVolumeInfo volInfo;
		
		for (i = 0; i < KMaxDrives; i++)
		{
			if (iEikonEnv->FsSession().Volume(volInfo, EDriveA + i) == KErrNone)
			{
				tempText.Format(_L("%c:"), 0x41 + i);
				tempText.Append(KColumnListSeparator);
				tempText.Append(_L("<drv>"));
				iArray->AppendL(tempText);	
			}
			else
			{
				if (driveOldPath[i] != NULL)
					delete driveOldPath[i];
			}
		}
		TBuf<1> driveLetter;
		driveLetter.Copy(currentPath.Left(1));
		TInt driveIndex = driveLetter[0] - 65;	// 65 = 'A'
		if (driveOldPath[driveIndex] == NULL)
			driveOldPath[driveIndex] = HBufC::NewL(KMaxPath);
		driveOldPath[driveIndex]->Des().Copy(currentPath);
	}
	else
	{
		iEikonEnv->InfoMsg(R_TBUF_FILEMAN_ERRREADFOLDER);
		labelFileDateTime->SetTextL(_L(""));
		labelFileDateTime->DrawNow();
	}
	cFileListBox->HandleItemAdditionL();
	if (iArray->MdcaCount() > 0)
	{
		cFileListBox->SetCurrentItemIndexAndDraw(0);
		cFileListBox->SetFocus(ETrue, EDrawNow);
		updateFileDateTime();
	}
	fileServer.Close();
	labelCurrentFolder->SetTextL(currentPath);
	labelCurrentFolder->DrawNow();
}

void CSMan2FileListView::ConstructL(const TRect& aRect)
{
	CreateWindowL();
	SetExtent(aRect.iTl, aRect.Size());

	for (int i = 0; i < KMaxDrives; i++)
		driveOldPath[i] = NULL;

	crcCalculator = new (ELeave) CCRCCalculator;

	blueBeam = new (ELeave) CBlueBeam(configData);
	blueBeam->logBuffer = &beamLog;
	fileList = NULL;

	clipBoard = new (ELeave) CArrayFixSeg<TFileName>(1);
	
	// Initialize current folder label
	labelCurrentFolder = new (ELeave) CEikTextButton;
	labelCurrentFolder->SetTextL(currentPath);
	labelCurrentFolder->SetContainerWindowL(*this);
	labelCurrentFolder->SetExtent(TPoint(0, 0), TSize(Size().iWidth, 22));
	labelCurrentFolder->SetBorder(TGulBorder::EDeepSunken);
	//labelCurrentFolder->Label()->SetEmphasis(CEikLabel::EFullEmphasis);
	controlsArray->AppendL(labelCurrentFolder);
		
	// Initialize file date time
	labelFileDateTime = new (ELeave) CEikTextButton;
	textFileDateTime.Copy(_L(""));
	labelFileDateTime->SetTextL(textFileDateTime);
	labelFileDateTime->SetContainerWindowL(*this);
	labelFileDateTime->SetExtent(TPoint(0, labelCurrentFolder->Size().iHeight), TSize(Size().iWidth, labelCurrentFolder->Size().iHeight));
	labelFileDateTime->SetBorder(TGulBorder::ESingleDotted);
	labelCurrentFolder->Label()->SetEmphasis(CEikLabel::ENoEmphasis);
	controlsArray->AppendL(labelFileDateTime);

	// Initialize listbox
	cFileListBox = new(ELeave) CEikColumnListBox;
	cFileListBox->ConstructL(this, CEikColumnListBox::EMultipleSelection);
	CColumnListBoxData* listBoxColumns = ((CColumnListBoxItemDrawer*)cFileListBox->ItemDrawer())->ColumnData();
	listBoxColumns->SetColumnWidthPixelL(0, int(Size().iWidth * 0.58));
	listBoxColumns->SetColumnWidthPixelL(1, int(Size().iWidth * 0.30));
	listBoxColumns->SetColumnAlignmentL(0, CGraphicsContext::ELeft);
	listBoxColumns->SetColumnAlignmentL(1, CGraphicsContext::ERight);
	cFileListBox->CreateScrollBarFrameL();
	cFileListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto);
	cFileListBox->SetExtent(TPoint(0, labelCurrentFolder->Size().iHeight + labelFileDateTime->Size().iHeight), TSize(Size().iWidth, 
		Size().iHeight - labelCurrentFolder->Size().iHeight - labelFileDateTime->Size().iHeight - EQikToolbarHeight + 4 - 10));

⌨️ 快捷键说明

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