// Splits the string input into pieces delimited by delimiter. // if 2 delimiters are in a row, it will include the empty string between them. // added MaxStrings parameter to restrict the number of returned substrings (like perl and python) int StringUtils::SplitString(const CStdString& input, const CStdString& delimiter, CStdStringArray &results, unsigned int iMaxStrings /* = 0 */) { int iPos = -1; int newPos = -1; int sizeS2 = delimiter.GetLength(); int isize = input.GetLength(); results.clear(); vector<unsigned int> positions; newPos = input.Find (delimiter, 0); if ( newPos < 0 ) { results.push_back(input); return 1; } while ( newPos > iPos ) { positions.push_back(newPos); iPos = newPos; newPos = input.Find (delimiter, iPos + sizeS2); } // numFound is the number of delimiters which is one less // than the number of substrings unsigned int numFound = positions.size(); if (iMaxStrings > 0 && numFound >= iMaxStrings) numFound = iMaxStrings - 1; for ( unsigned int i = 0; i <= numFound; i++ ) { CStdString s; if ( i == 0 ) { if ( i == numFound ) s = input; else s = input.Mid( i, positions[i] ); } else { int offset = positions[i - 1] + sizeS2; if ( offset < isize ) { if ( i == numFound ) s = input.Mid(offset); else if ( i > 0 ) s = input.Mid( positions[i - 1] + sizeS2, positions[i] - positions[i - 1] - sizeS2 ); } } results.push_back(s); } // return the number of substrings return results.size(); }
// Splits the string input into pieces delimited by delimiter. // if 2 delimiters are in a row, it will include the empty string between them. int StringUtils::SplitString(const CStdString& input, const CStdString& delimiter, CStdStringArray &results) { int iPos = -1; int newPos = -1; int sizeS2 = delimiter.GetLength(); int isize = input.GetLength(); results.clear(); //CArray positions; vector<unsigned int> positions; newPos = input.Find (delimiter, 0); if ( newPos < 0 ) { results.push_back(input); return 1; } int numFound = 1; while ( newPos > iPos ) { numFound++; positions.push_back(newPos); iPos = newPos; newPos = input.Find (delimiter, iPos + sizeS2); } for ( unsigned int i = 0; i <= positions.size(); i++ ) { CStdString s; if ( i == 0 ) { if (i == positions.size()) s = input; else s = input.Mid( i, positions[i] ); } else { int offset = positions[i - 1] + sizeS2; if ( offset < isize ) { if ( i == positions.size() ) s = input.Mid(offset); else if ( i > 0 ) s = input.Mid( positions[i - 1] + sizeS2, positions[i] - positions[i - 1] - sizeS2 ); } } results.push_back(s); } return numFound; }
void CGUIDialogAddonInfo::OnUninstall() { if (!m_localAddon.get()) return; // ensure the addon is not a dependency of other installed addons VECADDONS addons; CStdStringArray deps; CAddonMgr::Get().GetAllAddons(addons); for (VECADDONS::iterator it = addons.begin(); it != addons.end();++it) { if ((*it)->GetDeps().find(m_localAddon->ID()) != (*it)->GetDeps().end()) deps.push_back((*it)->Name()); } if (!CAddonInstaller::Get().CheckDependencies(m_localAddon) && deps.size()) { CStdString strLine0, strLine1; StringUtils::JoinString(deps, ", ", strLine1); strLine0.Format(g_localizeStrings.Get(24046), m_localAddon->Name().c_str()); CGUIDialogOK::ShowAndGetInput(24037, strLine0, strLine1, 24047); return; } // ensure the addon isn't disabled in our database CAddonDatabase database; database.Open(); database.DisableAddon(m_localAddon->ID(), false); CJobManager::GetInstance().AddJob(new CAddonUnInstallJob(m_localAddon), &CAddonInstaller::Get()); CAddonMgr::Get().RemoveAddon(m_localAddon->ID()); Close(); }
void WatchDog::CTestPathJob::DoWork() { #ifndef WATCHDOG_DONT_TEST_PATH if (!m_jobHandler) { CLog::Log(LOGWARNING,"CTestPathJob::DoWork - Can't execute the job. [jobHandler=NULL] (testpath)"); return; } //CLog::Log(LOGDEBUG,"CTestPathJob::DoWork - Enter function. [server=%d][internet=%d] (testpath)",m_jobHandler->IsConnectedToServer(),m_jobHandler->IsConnectedToInternet()); // scan all shares CStdStringArray arr; // first copy share names from map to temp array so that we only lock the map shortly { CSingleLock lock(m_jobHandler->m_lock); for (std::map<CStdString, PathStatus>::iterator iter=m_jobHandler->m_mapPaths.begin(); iter != m_jobHandler->m_mapPaths.end(); iter++) { arr.push_back(iter->first); } } for (size_t n=0; n<arr.size() && !m_jobHandler->IsStoped(); n++) { //CLog::Log(LOGDEBUG,"CTestPathJob::DoWork - [%d/%d] - Going to test [path=%s]. [server=%d][internet=%d] (testpath)",(int)n+1,(int)arr.size(),arr[n].c_str(),m_jobHandler->IsConnectedToServer(),m_jobHandler->IsConnectedToInternet()); m_jobHandler->TestPath(arr[n]); } //CLog::Log(LOGDEBUG,"CTestPathJob::DoWork - Exit function. [server=%d][internet=%d] (testpath)",m_jobHandler->IsConnectedToServer(),m_jobHandler->IsConnectedToInternet()); #endif }
bool CGUIDialogFileBrowser::ShowAndGetFileList(const VECSOURCES &shares, const CStdString &mask, const CStdString &heading, CStdStringArray &path, bool useThumbs /* = false */, bool useFileDirectories /* = false */) { CGUIDialogFileBrowser *browser = new CGUIDialogFileBrowser(); if (!browser) return false; g_windowManager.AddUniqueInstance(browser); browser->m_useFileDirectories = useFileDirectories; browser->m_multipleSelection = true; browser->m_browsingForImages = useThumbs; browser->SetHeading(heading); browser->SetSources(shares); browser->m_browsingForFolders = 0; browser->m_rootDir.SetMask(mask); browser->m_addNetworkShareEnabled = false; browser->DoModal(); bool confirmed(browser->IsConfirmed()); if (confirmed) { if (browser->m_markedPath.size()) path = browser->m_markedPath; else path.push_back(browser->m_selectedPath); } g_windowManager.Remove(browser->GetID()); delete browser; return confirmed; }
TEST(TestStringUtils, FindBestMatch) { double refdouble, vardouble; int refint, varint; CStdStringArray strarray; refint = 3; refdouble = 0.5625f; strarray.push_back(""); strarray.push_back("a"); strarray.push_back("e"); strarray.push_back("es"); strarray.push_back("t"); varint = StringUtils::FindBestMatch("test", strarray, vardouble); EXPECT_EQ(refint, varint); EXPECT_EQ(refdouble, vardouble); }
CStdString StringUtils::Join(const vector<string> &strings, const CStdString& delimiter) { CStdStringArray strArray; for (unsigned int index = 0; index < strings.size(); index++) strArray.push_back(strings.at(index)); return JoinString(strArray, delimiter); }
// Fills the array with the region names available for this language void CLangInfo::GetRegionNames(CStdStringArray& array) { for (ITMAPREGIONS it=m_regions.begin(); it!=m_regions.end(); ++it) { CStdString strName=it->first; if (strName=="N/A") strName=g_localizeStrings.Get(416); array.push_back(strName); } }
bool CASCIIManager::readFile_using_std_stream(CStdString strFileName, CStdStringArray &aRighe /*, UV_MFC::CDlg_Progresso *pDlg*/) ///< Leggo da file. { std::wifstream myfile(strFileName); std::streampos pos_begin = std::ios::beg; std::streampos pos_curr; std::wstring line; CStdString strLine; int fileLen = 0; int nI = 0, nCont = 3500; ULONGLONG nPosition; double dPerc, dPerc1; CStdString strFase; if (myfile.is_open()) { // get length of file: myfile.seekg(0, myfile.end); fileLen = (int)myfile.tellg(); myfile.seekg(0, myfile.beg); pos_curr = myfile.tellg(); aRighe.clear(); while (getline(myfile, line)) { pos_curr = myfile.tellg(); // std::cout << line << '\n'; strLine.Format(_T("%s"), line.c_str()); aRighe.push_back(strLine); nI++; //if (pDlg && nI > nCont) //{ // nPosition = pos_curr.seekpos(); // dPerc = nPosition / (double)fileLen; // dPerc = max(0, min(1, dPerc)); // dPerc1 = pDlg->m_dPercMin + dPerc*(pDlg->m_dPercMax - pDlg->m_dPercMin); // pDlg->SetPos(dPerc1); // strFase.Format(_T("[%d/%d] Reading rows (%.1lf%%)"), pDlg->m_nFaseCurr, pDlg->m_nFaseTot, 100.0*dPerc); // pDlg->SetFase(strFase); // nI = 0; // if (!pDlg->m_bContinua) // { // myfile.close(); // return false; // } //} } myfile.close(); } return true; }
bool CDirectoryNodeTvShowsOverview::GetContent(CFileItemList& items) { CStdStringArray vecRoot; vecRoot.push_back(g_localizeStrings.Get(135)); // Genres vecRoot.push_back(g_localizeStrings.Get(369)); // Title vecRoot.push_back(g_localizeStrings.Get(562)); // Year vecRoot.push_back(g_localizeStrings.Get(344)); // Actors for (int i = 0; i < (int)vecRoot.size(); ++i) { CFileItemPtr pItem(new CFileItem(vecRoot[i])); CStdString strDir; strDir.Format("%i/", i+1); pItem->m_strPath = BuildPath() + strDir; pItem->m_bIsFolder = true; pItem->SetCanQueue(false); items.Add(pItem); } return true; }
int CGUIWindowAddonBrowser::SelectAddonID(const vector<ADDON::TYPE> &types, CStdString &addonID, bool showNone /*= false*/) { CStdStringArray addonIDs; if (!addonID.IsEmpty()) addonIDs.push_back(addonID); int retval = SelectAddonID(types, addonIDs, showNone, false); if (addonIDs.size() > 0) addonID = addonIDs.at(0); else addonID = ""; return retval; }
void CGameSettings::OnSettingAction(const CSetting* setting) { if (setting == NULL) return; const std::string& settingId = setting->GetId(); if (settingId == "gamesgeneral.manageaddons") { CStdStringArray params; params.push_back("addons://all/xbmc.gameclient"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); } }
bool CDirectoryNodeMusicVideosOverview::GetContent(CFileItemList& items) { CStdStringArray vecRoot; vecRoot.push_back(g_localizeStrings.Get(135)); // Genres vecRoot.push_back(g_localizeStrings.Get(369)); // Title vecRoot.push_back(g_localizeStrings.Get(345)); // Year vecRoot.push_back(g_localizeStrings.Get(133)); // Artists vecRoot.push_back(g_localizeStrings.Get(20348)); // Directors vecRoot.push_back(g_localizeStrings.Get(20388)); // Studios for (int i = 0; i < (int)vecRoot.size(); ++i) { CFileItem* pItem = new CFileItem(vecRoot[i]); CStdString strDir; strDir.Format("%i/", i+1); pItem->m_strPath = BuildPath() + strDir; pItem->m_bIsFolder = true; pItem->SetCanQueue(false); items.Add(pItem); } return true; }
void CAdvancedSettings::GetCustomRegexps(TiXmlElement *pRootElement, CStdStringArray& settings) { TiXmlElement *pElement = pRootElement; while (pElement) { int iAction = 0; // overwrite // for backward compatibility const char* szAppend = pElement->Attribute("append"); if ((szAppend && stricmp(szAppend, "yes") == 0)) iAction = 1; // action takes precedence if both attributes exist const char* szAction = pElement->Attribute("action"); if (szAction) { iAction = 0; // overwrite if (stricmp(szAction, "append") == 0) iAction = 1; // append else if (stricmp(szAction, "prepend") == 0) iAction = 2; // prepend } if (iAction == 0) settings.clear(); TiXmlNode* pRegExp = pElement->FirstChild("regexp"); int i = 0; while (pRegExp) { if (pRegExp->FirstChild()) { CStdString regExp = pRegExp->FirstChild()->Value(); regExp.MakeLower(); if (iAction == 2) settings.insert(settings.begin() + i++, 1, regExp); else settings.push_back(regExp); } pRegExp = pRegExp->NextSibling("regexp"); } pElement = pElement->NextSiblingElement(pRootElement->Value()); } }
bool CRetroPlayerDialogs::GameLauchDialog(const CFileItem &file, GameClientPtr &result) { CFileItem fileCopy = file; // If an explicit game client was specified, try to download that if (fileCopy.HasProperty("gameclient")) { if (InstallGameClient(fileCopy.GetProperty("gameclient").asString(), fileCopy, result)) return true; fileCopy.ClearProperty("gameclient"); // don't want this to interfere later on } // First, ask the user if they would like to install a game client or go to // the add-on manager CContextButtons choices; choices.Add(0, 24026); // Install emulator choices.Add(1, 24058); // Add-on manager int btnid = CGUIDialogContextMenu::ShowAndGetChoice(choices); if (btnid == 0) // Install emulator { return InstallGameClientDialog(fileCopy, result); } else if (btnid == 1) // Add-on manager { // Queue the file so that if a compatible game client is installed, the // user will be asked to launch the file. CGameManager::Get().SetAutoLaunch(fileCopy); CLog::Log(LOGDEBUG, "RetroPlayer: User chose to go to the add-on manager"); CStdStringArray params; params.push_back("addons://all/xbmc.gameclient"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); } else { CLog::Log(LOGDEBUG, "RetroPlayer: User canceled game client selection"); } return false; }
void CMusikSourcesCtrl::DoDrag( CMusikPropTreeItem* pItem ) { if ( !pItem ) return; COleDataSource datasrc; HGLOBAL hgDrop; DROPFILES* pDrop; CStringList lsDraggedFiles; POSITION pos; CString sFile; UINT uBuffSize = 0; TCHAR* pszBuff; FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; // get a list of filenames with the currently // selected items... CStdStringArray files; int nMode = pItem->GetPlaylistType(); // standard playlist dragged if ( nMode == MUSIK_PLAYLIST_TYPE_STANDARD ) m_Library->GetStdPlaylistFns( pItem->GetPlaylistID(), files, false ); // now playing dragged.. else if ( nMode == MUSIK_SOURCES_TYPE_NOWPLAYING ) { if ( m_Player->GetPlaylist() ) { m_Library->BeginTransaction(); for ( size_t i = 0; i < m_Player->GetPlaylist()->GetCount(); i++ ) files.push_back( m_Player->GetPlaylist()->GetField( i, MUSIK_LIBRARY_TYPE_FILENAME ) ); m_Library->EndTransaction(); } } // library playlist dragged else if ( nMode == MUSIK_SOURCES_TYPE_LIBRARY ) { CMainFrame* pMain = (CMainFrame*)m_Parent; if ( pMain->m_LibPlaylist ) { m_Library->BeginTransaction(); for ( size_t i = 0; i < pMain->m_LibPlaylist->GetCount(); i++ ) files.push_back( pMain->m_LibPlaylist->GetField( i, MUSIK_LIBRARY_TYPE_FILENAME ) ); m_Library->EndTransaction(); } } else if ( nMode == MUSIK_PLAYLIST_TYPE_DYNAMIC ) MessageBox( "This operation is not supported yet.", "Musik", MB_ICONINFORMATION | MB_OK ); if ( !files.size() ) return; // CStringList containing files for ( size_t i = 0; i < files.size(); i++ ) { lsDraggedFiles.AddTail( files.at( i ) ); uBuffSize += files.at( i ).GetLength() + 1; } files.clear(); // Add 1 extra for the final null char, and the size of the DROPFILES struct. uBuffSize = sizeof(DROPFILES) + sizeof(TCHAR) * (uBuffSize + 1); // Allocate memory from the heap for the DROPFILES struct. hgDrop = GlobalAlloc ( GHND | GMEM_SHARE, uBuffSize ); if ( !hgDrop ) return; pDrop = (DROPFILES*) GlobalLock ( hgDrop ); if ( !pDrop ) { GlobalFree ( hgDrop ); return; } // Fill in the DROPFILES struct. pDrop->pFiles = sizeof(DROPFILES); // If we're compiling for Unicode, set the Unicode flag in the struct to // indicate it contains Unicode strings. #ifdef _UNICODE pDrop->fWide = TRUE; #endif; // Copy all the filenames into memory after the end of the DROPFILES struct. pos = lsDraggedFiles.GetHeadPosition(); pszBuff = (TCHAR*) (LPBYTE(pDrop) + sizeof(DROPFILES)); while ( pos ) { lstrcpy ( pszBuff, (LPCTSTR) lsDraggedFiles.GetNext ( pos ) ); pszBuff = 1 + _tcschr ( pszBuff, '\0' ); } GlobalUnlock ( hgDrop ); // Put the data in the data source. datasrc.CacheGlobalData ( CF_HDROP, hgDrop, &etc ); // Add in our own custom data, so we know that the drag originated from our // window. CMyDropTarget::DragEnter() checks for this custom format, and // doesn't allow the drop if it's present. This is how we prevent the user // from dragging and then dropping in our own window. // The data will just be a dummy bool. HGLOBAL hgBool; hgBool = GlobalAlloc ( GHND | GMEM_SHARE, sizeof(bool) ); if ( NULL == hgBool ) { GlobalFree ( hgDrop ); return; } // Put the data in the data source. etc.cfFormat = m_DropID; datasrc.CacheGlobalData ( m_DropID, hgBool, &etc ); // Start the drag 'n' drop! DROPEFFECT dwEffect = datasrc.DoDragDrop ( DROPEFFECT_COPY | DROPEFFECT_MOVE ); // If the DnD completed OK, we remove all of the dragged items from our // list. switch ( dwEffect ) { case DROPEFFECT_COPY: case DROPEFFECT_MOVE: { // the copy completed successfully // do whatever we need to do here TRACE0( "DND from playlist completed successfully. The data has a new owner.\n" ); } break; case DROPEFFECT_NONE: { // This needs special handling, because on NT, DROPEFFECT_NONE // is returned for move operations, instead of DROPEFFECT_MOVE. // See Q182219 for the details. // So if we're on NT, we check each selected item, and if the // file no longer exists, it was moved successfully and we can // remove it from the list. if ( m_IsWinNT ) { // the copy completed successfully // on a windows nt machine. // do whatever we need to do here bool bDeletedAnything = false; if ( ! bDeletedAnything ) { // The DnD operation wasn't accepted, or was canceled, so we // should call GlobalFree() to clean up. GlobalFree ( hgDrop ); GlobalFree ( hgBool ); TRACE0( "DND had a problem. We had to manually free the data.\n" ); } } // not windows NT else { // We're on 9x, and a return of DROPEFFECT_NONE always means // that the DnD operation was aborted. We need to free the // allocated memory. GlobalFree ( hgDrop ); GlobalFree ( hgBool ); TRACE0( "DND had a problem. We had to manually free the data.\n" ); } } break; } }
void CExternalPlayer::GetCustomRegexpReplacers(TiXmlElement *pRootElement, CStdStringArray& settings) { int iAction = 0; // overwrite // for backward compatibility const char* szAppend = pRootElement->Attribute("append"); if ((szAppend && stricmp(szAppend, "yes") == 0)) iAction = 1; // action takes precedence if both attributes exist const char* szAction = pRootElement->Attribute("action"); if (szAction) { iAction = 0; // overwrite if (stricmp(szAction, "append") == 0) iAction = 1; // append else if (stricmp(szAction, "prepend") == 0) iAction = 2; // prepend } if (iAction == 0) settings.clear(); TiXmlElement* pReplacer = pRootElement->FirstChildElement("replacer"); int i = 0; while (pReplacer) { if (pReplacer->FirstChild()) { const char* szGlobal = pReplacer->Attribute("global"); const char* szStop = pReplacer->Attribute("stop"); bool bGlobal = szGlobal && stricmp(szGlobal, "true") == 0; bool bStop = szStop && stricmp(szStop, "true") == 0; CStdString strMatch; CStdString strPat; CStdString strRep; XMLUtils::GetString(pReplacer,"match",strMatch); XMLUtils::GetString(pReplacer,"pat",strPat); XMLUtils::GetString(pReplacer,"rep",strRep); if (!strPat.IsEmpty() && !strRep.IsEmpty()) { CLog::Log(LOGDEBUG," Registering replacer:"); CLog::Log(LOGDEBUG," Match:[%s] Pattern:[%s] Replacement:[%s]", strMatch.c_str(), strPat.c_str(), strRep.c_str()); CLog::Log(LOGDEBUG," Global:[%s] Stop:[%s]", bGlobal?"true":"false", bStop?"true":"false"); // keep literal commas since we use comma as a seperator strMatch.Replace(",",",,"); strPat.Replace(",",",,"); strRep.Replace(",",",,"); CStdString strReplacer = strMatch + " , " + strPat + " , " + strRep + " , " + (bGlobal ? "g" : "") + (bStop ? "s" : ""); if (iAction == 2) settings.insert(settings.begin() + i++, 1, strReplacer); else settings.push_back(strReplacer); } else { // error message about missing tag if (strPat.IsEmpty()) CLog::Log(LOGERROR," Missing <Pat> tag"); else CLog::Log(LOGERROR," Missing <Rep> tag"); } } pReplacer = pReplacer->NextSiblingElement("replacer"); } }
bool CRetroPlayerDialogs::ChooseGameClientDialog(const vector<string> &clientIds, const CFileItem &file, GameClientPtr &result) { CLog::Log(LOGDEBUG, "RetroPlayer: Multiple clients found: %s", StringUtils::Join(clientIds, ", ").c_str()); // Turn ID strings into game client pointers (std::map enables sorting by name) map<string, GameClientPtr> clients; for (vector<string>::const_iterator it = clientIds.begin(); it != clientIds.end(); ++it) { AddonPtr addon; GameClientPtr gc; if (CAddonMgr::Get().GetAddon(*it, addon, ADDON_GAMEDLL)) { gc = boost::dynamic_pointer_cast<CGameClient>(addon); if (gc) { string strName = gc->Name(); // Make lower case for sorting purposes StringUtils::ToLower(strName); clients[strName] = gc; } } } // CContextButtons doesn't support keying by string, only int, so use a // parallel array to track the string values (client name) CContextButtons choicesInt; unsigned int i = 0; vector<string> choicesStr; choicesStr.reserve(clients.size()); for (map<string, GameClientPtr>::const_iterator it = clients.begin(); it != clients.end(); ++it) { string strName = it->second->Name(); choicesInt.Add(i++, strName); // Remember, our map keys are lower case StringUtils::ToLower(strName); choicesStr.push_back(strName); } // i becomes the index of the final item (choice to go to the add-on manager) const unsigned int iAddonMgr = i; choicesInt.Add(iAddonMgr, 24025); // "Manage emulators..." int btnid = CGUIDialogContextMenu::ShowAndGetChoice(choicesInt); if (btnid < 0 || btnid > (int)iAddonMgr) { CLog::Log(LOGDEBUG, "RetroPlayer: User cancelled game client selection"); return false; } else if (btnid == (int)iAddonMgr) { // Queue the file so that if a compatible game client is installed, the // user will be asked to launch the file. CGameManager::Get().SetAutoLaunch(file); CLog::Log(LOGDEBUG, "RetroPlayer: User chose to go to the add-on manager"); CStdStringArray params; params.push_back("addons://all/xbmc.gameclient"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); return false; } else { result = clients[choicesStr[btnid]]; CLog::Log(LOGDEBUG, "RetroPlayer: Using %s", result->ID().c_str()); } return true; }
int CGUIWindowAddonBrowser::SelectAddonID(const vector<ADDON::TYPE> &types, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog) return 0; CFileItemList items; CStdString heading; int iTypes = 0; for (vector<ADDON::TYPE>::const_iterator it = types.begin(); it != types.end(); ++it) { if (*it == ADDON_UNKNOWN) continue; ADDON::VECADDONS addons; iTypes++; if (*it == ADDON_AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio",addons); else if (*it == ADDON_EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable",addons); else if (*it == ADDON_IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image",addons); else if (*it == ADDON_VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video",addons); else CAddonMgr::Get().GetAddons(*it, addons); for (ADDON::IVECADDONS it2 = addons.begin() ; it2 != addons.end() ; ++it2) { CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(*it2, "")); if (!items.Contains(item->GetPath())) items.Add(item); } if (!heading.IsEmpty()) heading += ", "; heading += TranslateType(*it, true); } if (iTypes == 0) return 0; dialog->SetHeading(heading); dialog->Reset(); dialog->SetUseDetails(true); if (multipleSelection) showNone = false; if (multipleSelection || iTypes > 1) dialog->EnableButton(true, 186); else dialog->EnableButton(true, 21452); if (showNone) { CFileItemPtr item(new CFileItem("", false)); item->SetLabel(g_localizeStrings.Get(231)); item->SetLabel2(g_localizeStrings.Get(24040)); item->SetIconImage("DefaultAddonNone.png"); item->SetSpecialSort(SortSpecialOnTop); items.Add(item); } items.Sort(SORT_METHOD_LABEL, SortOrderAscending); if (addonIDs.size() > 0) { for (CStdStringArray::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; it++) { CFileItemPtr item = items.Get(*it); if (item) item->Select(true); } } dialog->SetItems(&items); dialog->SetMultiSelection(multipleSelection); dialog->DoModal(); if (!multipleSelection && iTypes == 1 && dialog->IsButtonPressed()) { // switch to the addons browser. vector<CStdString> params; params.push_back("addons://all/"+TranslateType(types[0],false)+"/"); params.push_back("return"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); return 2; } if (!dialog->IsConfirmed()) return 0; addonIDs.clear(); const CFileItemList& list = dialog->GetSelectedItems(); for (int i = 0 ; i < list.Size() ; i++) addonIDs.push_back(list.Get(i)->GetPath()); return 1; }
TEST(TestStringUtils, JoinString) { CStdString refstr, varstr; CStdStringArray strarray; strarray.push_back("a"); strarray.push_back("b"); strarray.push_back("c"); strarray.push_back("de"); strarray.push_back(","); strarray.push_back("fg"); strarray.push_back(","); refstr = "a,b,c,de,,,fg,,"; StringUtils::JoinString(strarray, ",", varstr); EXPECT_STREQ(refstr.c_str(), varstr.c_str()); strarray.clear(); varstr.clear(); strarray.push_back("g"); strarray.push_back("h"); strarray.push_back("i"); strarray.push_back("jk,"); strarray.push_back(","); strarray.push_back("lmn,,"); strarray.push_back(","); refstr = "g,h,i,jk,,,,lmn,,,,"; varstr = StringUtils::JoinString(strarray, ","); EXPECT_STREQ(refstr.c_str(), varstr.c_str()); }
int CGUIWindowAddonBrowser::SelectAddonID(ADDON::TYPE type, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (type == ADDON_UNKNOWN || !dialog) return 0; ADDON::VECADDONS addons; if (type == ADDON_AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio",addons); else if (type == ADDON_EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable",addons); else if (type == ADDON_IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image",addons); else if (type == ADDON_VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video",addons); else CAddonMgr::Get().GetAddons(type, addons); CFileItemList items; for (ADDON::IVECADDONS i = addons.begin(); i != addons.end(); ++i) items.Add(CAddonsDirectory::FileItemFromAddon(*i, "")); dialog->SetHeading(TranslateType(type, true)); dialog->Reset(); dialog->SetUseDetails(true); if (multipleSelection) { showNone = false; dialog->EnableButton(true, 186); } else dialog->EnableButton(true, 21452); if (showNone) { CFileItemPtr item(new CFileItem("", false)); item->SetLabel(g_localizeStrings.Get(231)); item->SetLabel2(g_localizeStrings.Get(24040)); item->SetIconImage("DefaultAddonNone.png"); item->SetSpecialSort(SORT_ON_TOP); items.Add(item); } items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC); if (addonIDs.size() > 0) { for (CStdStringArray::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; it++) { CFileItemPtr item = items.Get(*it); if (item) item->Select(true); } } dialog->SetItems(&items); dialog->SetMultiSelection(multipleSelection); dialog->DoModal(); if (!multipleSelection && dialog->IsButtonPressed()) { // switch to the addons browser. vector<CStdString> params; params.push_back("addons://all/"+TranslateType(type,false)+"/"); params.push_back("return"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); return 2; } if (!multipleSelection && dialog->GetSelectedLabel() == -1) return 0; addonIDs.clear(); const CFileItemList& list = dialog->GetSelectedItems(); for (int i = 0 ; i < list.Size() ; i++) addonIDs.push_back(list.Get(i)->GetPath()); return 1; }
// Execute SQL Query for the established connection // Mostly a SELECT query, Other queries may be executed using Execute() // Returns ZERO on success UINT CSmartDBRecordSet::Open(const char* strQueryString, CSmartDB *ptrConn, LONG nRSType) { UINT i; if (ptrConn->IsLibLoaded() == FALSE) return RSOPEN_NOLIBLOADED; if (m_bIsOpen) return RSOPEN_ALREADYOPENED; if (!ptrConn->IsConnected()) return RSOPEN_NOCONNECT; CStdString strBuffer; // Temp Buffer CStdStringArray *strRSRow; // Record Set holder BOOL bTypesSaved = FALSE; // Flag used to mark if DataTypes are saved for each column char *zErrMsg = 0; sqlite3_stmt *stmtByteCode; const char *strUnused = 0; UINT nCount = 0; UINT nRecCount = 0; INT nType; strBuffer = strQueryString; SmartDBPrepare(ptrConn->db, strBuffer, strBuffer.GetLength(), &stmtByteCode, &strUnused); nCount = SmartDBColumnCount(stmtByteCode); for (i=0; i < nCount; i++) { strBuffer = SmartDBColumnName (stmtByteCode, i); // column_name strFieldsList.push_back (strBuffer); } m_nFieldsCount = strFieldsList.size(); // return, If there is no field in the table if (m_nFieldsCount == 0) return RSOPEN_INVALIDQRY; m_bIsOpen = TRUE; int nValue; double nFValue; CStdString strValue; CStdString strTemp; while (SmartDBStep (stmtByteCode) != SQLITE_DONE) // step { strRSRow = new CStdStringArray(); for (i=0; (LONG)i < m_nFieldsCount; i++) { if (!bTypesSaved) // Save Field Types in an array { nType = SmartDBColumnType (stmtByteCode, i); // column_type nFieldsType.push_back((UINT)nType); if ((LONG)i == m_nFieldsCount-1) bTypesSaved = TRUE; } switch (nFieldsType[i]) { case SQLITE_INTEGER: nValue = SmartDBColumnInt (stmtByteCode, i); strTemp.Format("%d", nValue); strRSRow->push_back(strTemp); break; case SQLITE_FLOAT: nFValue = SmartDBColumnDouble (stmtByteCode, i); strTemp.Format("%f", nFValue); strRSRow->push_back(strTemp); break; case SQLITE_TEXT: strValue = (char*)SmartDBColumnText (stmtByteCode, i); strRSRow->push_back(strValue); break; case SQLITE_BLOB: strValue = (const char*)SmartDBColumnBlob (stmtByteCode, i); strRSRow->push_back(strValue); break; case SQLITE_NULL: strRSRow->push_back(""); break; } } orsRows.push_back((void *)strRSRow); nRecCount++; } m_nRecordCount = nRecCount; m_nCurrentRecord = 0; SmartDBFinalize(stmtByteCode); return RSOPEN_SUCCESS; }
void CMusikSourcesCtrl::OnDropFiles(HDROP hDropInfo) { // set cursor back to hour glass SetCursor( LoadCursor( NULL, IDC_WAIT ) ); // see if the drag landed on an existing // playlist, if it did, we'll append CPoint pos; ::GetCursorPos( &pos ); ScreenToClient( &pos ); CMusikPropTreeItem* pItem = FindItem( pos ); // make sure the item isn't root if ( pItem != NULL && pItem->IsRootLevel() ) return; if ( pItem ) { KillFocus(); pItem->Select( TRUE ); SetFocusedItem( pItem ); } // dnd stuff size_t nNumFiles; TCHAR szNextFile [MAX_PATH]; SHFILEINFO rFileInfo; nNumFiles = DragQueryFile ( hDropInfo, -1, NULL, 0 ); CStdStringArray files; CStdString sTemp; for ( size_t i = 0; i < nNumFiles; i++ ) { if ( DragQueryFile( hDropInfo, i, szNextFile, MAX_PATH ) > 0 ) { // get the filetype. if its a directory // that was dropped, we'll want to // recurse it and add all the supported // media files... SHGetFileInfo( szNextFile, 0, &rFileInfo, sizeof( rFileInfo ), SHGFI_ATTRIBUTES ); if ( rFileInfo.dwAttributes & SFGAO_FOLDER ) { sTemp = szNextFile; sTemp += "\\*.*"; m_Dir.m_Dir = sTemp; m_Dir.m_Threaded = false; m_Dir.m_Target = &files; m_Dir.Run(); } // otherwise it was just a file... add it... else files.push_back( szNextFile ); } } DragFinish( hDropInfo ); // did we actually hit an item? if ( pItem ) { // standard playlist if ( pItem->GetPlaylistType() == MUSIK_PLAYLIST_TYPE_STANDARD ) m_Library->AppendStdPlaylist( pItem->GetPlaylistID(), files ); // hit now playing? else if ( pItem->GetPlaylistType() == MUSIK_SOURCES_TYPE_NOWPLAYING ) { m_Library->BeginTransaction(); CMusikSong song; for ( size_t i = 0; i < files.size(); i++ ) { // add song (if necessary) m_Library->AddSong( files.at( i ) ); m_Library->GetSongFromFilename( files.at( i ), song ); m_Player->GetPlaylist()->Add( song ); } m_Library->EndTransaction(); } } // else make a new playlist else { CStdString playlist_str; playlist_str.Format( _T( "New Playlist %d" ), m_StdPlaylists.size() ); m_Library->CreateStdPlaylist( playlist_str.c_str(), files ); LoadStdPlaylists(); } // didn't hit an item, a new // playlist was created, so it // was pushed to the back of the list if ( !pItem ) { pItem = m_StdPlaylists.at( m_StdPlaylists.size() - 1 ); // focus KillFocus(); pItem->Select( TRUE ); SetFocusedItem( pItem ); } if ( pItem ) SendNotify( PTN_SELCHANGE, pItem ); }