void CContextOSX::GetPathName(tchar* pszPathName)
{
	IFile::GetSystemDirectory(IFile::SystemDirApplications, pszPathName);

	std::string sPathName((const char*)pszPathName);

	tchar pszName[64];
	mpCallback->GetName(pszName);
	std::string sName((const char*)pszName);
	
	sPathName += sName;
	sPathName += ".kspi";

    strcpy((char*)pszPathName, sPathName.c_str());
}
std::string CKS_Import_File_Browser::GetSelectedFile()
{
	tint32 iIndex = miLatestSelectedFile; //mpListBox->GetValue();
	if (iIndex < 0) {
		return "";
	}

	std::list<SItemInfo>::const_iterator it = mItems.begin();
	while (iIndex) {
		iIndex--;
		it++;
	}
	SItemInfo Info = *it;
	if (Info.bDir == true) {
		return "";
	}
	else {
		std::string sPathName(msPath);
		sPathName += Info.sName;
		return sPathName;
	}
}
Exemple #3
0
void CBrowser::BrowseFolder(SItem* pFolder)
{
	// Clear current list
	std::list<SItem*>::iterator it = pFolder->SubItems.begin();
	for (; it != pFolder->SubItems.end(); it++) {
		SItem* pItem = *it;
		delete pItem;
	}
	pFolder->SubItems.clear();

	tint32 iItemCount = giBrowserMaxItemsPerFolder;
	IBrowser::SItem* pItems = new IBrowser::SItem[iItemCount];

	std::string sPathName(pFolder->sPathName);
	if (sPathName != std::string("")) {
#ifdef WIN32
		sPathName += std::string("\\");
#endif
#ifdef _Mac
		sPathName += std::string(":");
#endif
	}
	mpCallback->Browse((tchar*)(sPathName.c_str()), pItems, iItemCount);

	// Convert to internal structure
	tint32 iItem;
	for (iItem = 0; iItem < iItemCount; iItem++) {
		CBrowser::SItem* pItemInternal = new CBrowser::SItem();

		strcpy((char*)(pItemInternal->pszName), (char*)(pItems[iItem].pszName));
		pItemInternal->bFolder = pItems[iItem].bFolder;

		pItemInternal->sNameModified = std::string((char*)(pItemInternal->pszName));
		pItemInternal->sPathName = pFolder->sPathName;
#ifdef WIN32
		pItemInternal->sPathName += std::string("\\");
#endif
#ifdef _Mac
		pItemInternal->sPathName += std::string(":");
#endif
		pItemInternal->sPathName += std::string((char*)(pItemInternal->pszName));
		pItemInternal->bFolderIsOpen = false;

		pFolder->SubItems.push_back(pItemInternal);
	}

	delete[] pItems;

	// Get number of lines
	tint32 iLineCount = 0;
	GetItemCount(mItemRoot.SubItems, iLineCount);

	// We now know the amount of lines, and can set the size
	SSize SizeNew(GetSize());
	SizeNew.iCY = miMarginTop + (iLineCount * miSpaceBetweenItems);
	if (SizeNew.iCY < mSizeMin.iCY) {
		SizeNew.iCY = mSizeMin.iCY;
	}
	if (SizeNew != GetSize()) {
		SetSize(SizeNew);

		SScrollPos ScrollPos;
		mpScrollPane->GetScrollPos(ScrollPos);
		ScrollPos.AreaSize = SizeNew;
		mpScrollBar->SetScrollPos(ScrollPos, false);
	}
}
Exemple #4
0
void CBrowser::UpdateFolder(SItem* pFolder)
{
	SItem* pFolderTmp = new SItem;

	tint32 iItemCount = giBrowserMaxItemsPerFolder;
	IBrowser::SItem* pItems = new IBrowser::SItem[iItemCount];

	std::string sPathName(pFolder->sPathName);
	if (sPathName != std::string("")) {
#ifdef WIN32
		sPathName += std::string("\\");
#endif
#ifdef _Mac
		sPathName += std::string(":");
#endif
	}
	mpCallback->Browse((tchar*)(sPathName.c_str()), pItems, iItemCount);

	// Convert to internal structure
	tint32 iItem;
	for (iItem = 0; iItem < iItemCount; iItem++) {
		CBrowser::SItem* pItemInternal = new CBrowser::SItem();

		strcpy((char*)(pItemInternal->pszName), (char*)(pItems[iItem].pszName));
		pItemInternal->bFolder = pItems[iItem].bFolder;

		pItemInternal->sNameModified = std::string((char*)(pItemInternal->pszName));
		pItemInternal->sPathName = pFolder->sPathName;
#ifdef WIN32
		pItemInternal->sPathName += std::string("\\");
#endif
#ifdef _Mac
		pItemInternal->sPathName += std::string(":");
#endif
		pItemInternal->sPathName += std::string((char*)(pItemInternal->pszName));
		pItemInternal->bFolderIsOpen = false;

		pFolderTmp->SubItems.push_back(pItemInternal);

		if (pItemInternal->bFolder) {
			// Check if folder previously was open
		}
	}

	delete[] pItems;

	// Go through the old items, deleting the ones missing, and updating the sub folders
	// These are the items we wish to delete from list. We'll do it in the end, so we don't mess up the iterator
	std::list<SItem*> DeleteList;
	tint32 iNrOfItems = pFolder->SubItems.size();
	std::list<SItem*>::iterator it = pFolder->SubItems.begin();
	for (iItem = 0; iItem < iNrOfItems; iItem++, it++) {
		SItem* pItem = *it;
		std::string sName = std::string((char*)pItem->pszName);

		// See if we can find this item in the new list
		std::list<SItem*>::iterator it2 = pFolderTmp->SubItems.begin();
		bool bFoundIt = false;
		for (; it2 != pFolderTmp->SubItems.end(); it2++) {
			SItem* pItemNew = *it2;
			std::string sNameNew = std::string((char*)pItemNew->pszName);
			if (sNameNew.compare(sName) == 0) {
				// The names match
				bFoundIt = true;
				// Update the new list
				delete pItemNew;
				pFolderTmp->SubItems.erase(it2);
				break;
			}
		}
		if (bFoundIt) {
			if (pItem->bFolder) {
				if (pItem->bFolderIsOpen) {
					UpdateFolder(pItem);
				}
			}
		}
		else {
			// We didn't find it, so put it in list of items to delete
			DeleteList.push_back(pItem);
		}
	}

	// Delete the items, which needs to be deleted
	it = DeleteList.begin();
	for (; it != DeleteList.end(); it++) {
		SItem* pItem = *it;
		delete pItem;
		pFolder->SubItems.remove(pItem);
	}

	// All remaining items in the new list needs to be put in the old list
	it = pFolderTmp->SubItems.begin();
	for (; it != pFolderTmp->SubItems.end(); it++) {
		SItem* pItem = *it;
		pFolder->SubItems.push_back(pItem);
	}
	// Clear the new list, since we don't want the items to be deleted (they've been transfered to the old list)
	pFolderTmp->SubItems.clear();

	delete pFolderTmp;
}
void CKS_Import_File_Browser::SetPath(const std::string& sPath)
{
	CAutoDelete<ge::IWaitCursor> pWaitCursor(ge::IWaitCursor::Create());

	std::string sEnum;
	mItems.clear();

	tbool bWasOldMyComputer = (strcmp(msPath.c_str(), ":") == 0);
	tbool bIsNewMyComputer = (strcmp(sPath.c_str(), ":") == 0);

	msPath = sPath;

	if (bIsNewMyComputer) {
		// List "My Computer" - a.k.a. disk volumes
		tchar pszEnumVolumes[1024];
		if (IFile::GetDriveNames(pszEnumVolumes, sizeof(pszEnumVolumes), '@', true)) {
			std::list<std::string> listVolumes;
			PszEnumString2List(pszEnumVolumes, '@', listVolumes);
			std::list<std::string>::iterator itVolumes = listVolumes.begin();
			for ( ; itVolumes != listVolumes.end(); itVolumes++) {
				SItemInfo Info;
				Info.sName = *itVolumes;
				Info.bDir = true;
				mItems.push_back(Info);
			}
			sEnum = pszEnumVolumes;
		}
	}
	else if (bWasOldMyComputer) {
#ifdef _WIN32
		// For windows we must use only the drive letter part of the path
		tint32 iPosSpace = msPath.find_first_of(' ');
		if (iPosSpace > -1) {
			msPath.erase(iPosSpace);
			msPath += ":\\";
		}
#endif // _WIN32
	}

	CAutoDelete<IFileSearch> pSearch(IFileSearch::Create());
	std::string sSearchPathName(msPath);
	sSearchPathName += "*";
	pSearch->Init2(sSearchPathName.c_str());

	tbool bFirst = true;
	tchar pszName[1024];
	tbool bDir;
	while (pSearch->GetNext(pszName, bDir)) {
		std::string sName;
		tbool bFirstOld = bFirst;
		if (bFirst == false) {
			sName = "@";
		}
		bFirst = false;

		tbool bOK = false;
		sName += std::string(pszName);
		if (bDir) {
			sName += " (dir)";
			bOK = true;
		}
		else {
			std::string sPathName(msPath);
			sPathName += std::string(pszName);
			CAutoDelete<IFile> pFile(IFile::Create());
			if (pFile->Open(sPathName.c_str(), IFile::FileRead)) {
				ac::IDecoder* pDec = ac::IDecoder::Create(pFile);
				if (pDec) {
					bOK = true;
					pDec->Destroy();
				}
			}
		}

		if (bOK) {
			sEnum += sName;

			SItemInfo Info;
			Info.sName = std::string(pszName);
			Info.bDir = bDir;
			mItems.push_back(Info);
		}
		else {
			bFirst = bFirstOld;
		}
	}

	mpListBox->SetText(sEnum.c_str(), '@');

	tint32 iTextHeight = mItems.size() * 14;

	ge::SSize SizeScroll(200 - giScrollBarSize, iTextHeight);
	ge::SScrollPos ScrollPos;
	mpScrollPane->GetScrollPos(ScrollPos);
	ScrollPos.AreaSize = SizeScroll;
	if (ScrollPos.AreaSize.iCY < ScrollPos.VisibleRect.iCY) {
		ScrollPos.AreaSize.iCY = ScrollPos.VisibleRect.iCY;
	}
	mpScrollPane->SetScrollPos(ScrollPos);

	ge::SSize SizeListBox(SizeScroll - ge::SSize(4, 0));
	mpListBox->SetSize(SizeListBox);
} // SetPath
void CKS_Import_File_Browser::EventValueChange(ge::IControl* pControl, tint32 iValueNew)
{
	GetParmMan()->ControlUpdate(miPaneID, pControl->GetID(), iValueNew);

	switch(pControl->GetID()) {
		case giCtrl_File_List:
			{
				tbool bIsDoubleClick = (iValueNew == -2);
				if (iValueNew >= -1) {
					miLatestGenuineIndex = iValueNew;
				}

				tint32 iIndex = miLatestGenuineIndex; //pControl->GetValue();
				std::list<SItemInfo>::const_iterator it = mItems.begin();
				while (iIndex > 0) {
					iIndex--;
					it++;
				}
				SItemInfo Info = *it;
				if (Info.bDir == true) {
					mpImportGUI->PreviewStop();
					miLatestSelectedFile = -1;

					std::string sPath(msPath);
					sPath += Info.sName;
					sPath += ":";
					if (bIsDoubleClick) {
						mpImportGUI->BrowseToDir(sPath);
					}
				}
				else {
					tbool bSameFile = (miLatestGenuineIndex == miLatestSelectedFile);

					if (bSameFile) {
						// Same file
						if (bIsDoubleClick) {
							// Add file to import list
							std::string sPathName(msPath);
							sPathName += Info.sName;
							mpImportGUI->AddFile(sPathName);
						}
					}
					else {
						// New file - read its info

						// First we need to stop previewing (may crash on read info if we don't)
						mpImportGUI->PreviewStop();

						// Get info
						miLatestSelectedFile = miLatestGenuineIndex;
						std::string sPathName(msPath);
						sPathName += Info.sName;
						CAutoDelete<IFile> pFile(IFile::Create());
						if (pFile->Open(sPathName.c_str(), IFile::FileRead)) {
							ac::IDecoder* pdec = ac::IDecoder::Create(pFile);
							if (pdec) {
								// Attempt to test file - if it fails ignore it
								pdec->TestFile(pFile);
								// Now we have tried to decipher file - we pretend it succeeded
								CAutoDelete<ac::IDecoder> pDecoder(pdec);
								ac::EAudioCodec Codec = pDecoder->GetAudioCodec();
								if (Codec == ac::geAudioCodecWave) {
									mpImportGUI->SetType(0);
									ac::EQuality eQ = ac::geQualityUnknown;
									tint32 iBitDepth = pdec->miLastInputBitWidth;
									if (iBitDepth == 16)
										eQ = ac::geQualityLossless16;
									else if (iBitDepth == 24)
										eQ = ac::geQualityLossless24;
									tint32 iSampleRate = pdec->miOutputSampleFreq;
									tint32 iChannels = pdec->miOutputChannels;
									mpImportGUI->SetInfo(eQ, iSampleRate, iChannels);
								}
								else if (Codec == geAudioCodecVorbis) {
									mpImportGUI->SetType(1);
									tint32 iSampleRate = pdec->miOutputSampleFreq;
									tint32 iChannels = pdec->miOutputChannels;
									mpImportGUI->SetInfo(pdec->meLowestInputQuality, iSampleRate, iChannels);
								}
								else {
									mpImportGUI->SetType(2);
									tint32 iSampleRate = pdec->miOutputSampleFreq;
									tint32 iChannels = pdec->miOutputChannels;
									mpImportGUI->SetInfo(pdec->meLowestInputQuality, iSampleRate, iChannels);
								}
							}
						}
					}
				}
			}
			break;
	}
} // EventValueChange