/** * This method sets the PyObject form of a property. * * @param index The index of the property in pType. * @param pObj The PyObject of the property. * @return Boolean success or failure. */ bool PropertiesHelper::propSetPy( PropertyIndex index, PyObject * pObj ) { if ( pType_ == NULL || index.empty() ) return false; MF_ASSERT( index.valueAt(0) < (int) pType_->propertyCount() ); DataDescription * pDD = pType_->property( index.valueAt(0) ); if ( index.count() == 1 ) { propUsingDefault( index.valueAt( 0 ), false ); // requesting the top-level property directly, even if it's an array // (sequence), so set it directly. if (PyDict_SetItemString( pDict_, const_cast<char*>( pDD->name().c_str() ), pObj ) == -1) { //ERROR_MSG( "PropertiesHelper::propSetPy: Failed to set value\n" ); PyErr_Print(); return false; } } else { PyObjectPtr ob( propGetPy( index.valueAt(0) ), PyObjectPtr::STEAL_REFERENCE ); if ( PySequence_Check( ob.getObject() ) ) { SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() ); ArrayPropertiesHelper propArray; propArray.init( pItem(), &(dataType->getElemType()), ob.getObject() ); PropertyIndex arrayIndex = index.tail(); if ( !propArray.propSetPy( arrayIndex, pObj ) ) { //ERROR_MSG( "PropertiesHelper::propSetPy: Failed to set value in array\n" ); PyErr_Print(); return false; } } else { //ERROR_MSG( "PropertiesHelper::propSetPy: Failed to set value in array (not a sequence)\n" ); PyErr_Print(); return false; } } return true; }
bool CXmlUtil::DelAttribute(const XMLDOMElementPtr& ele, const wchar_t* name) { LocalHResult hr; XMLDOMAttributePtr node = NULL; if (ele != NULL && IsNotEmpty(name)) hr = ele->getAttributeNode(_bstr_t(name), &node); if (node != NULL) { XMLDOMElementPtr pItem(node); return SUCCEEDED(hr = ele->removeChild(pItem, NULL)); } return false; }
CProjectNewDialog::CProjectNewDialog(CWnd* pParent /*=NULL*/) : CTemplateDialog(CProjectNewDialog::IDD, pParent), m_wndBrowseButton(IDC_EDIT_PROJECTPATH, CString((LPCTSTR)STE_SELECT_PROJECT_PATH)), m_bIgnoreProjectPathChange(FALSE) { //{{AFX_DATA_INIT(CProjectNewDialog) m_strProjectName = _T(""); m_bUseBibTex = FALSE; m_bUseMakeIndex = FALSE; //}}AFX_DATA_INIT // Add template for empty project std::unique_ptr<CTemplateItem> pItem(new CEmptyProjectTemplateItem); AddTemplateItem(CString((LPCTSTR)STE_EMPTYPROJECT_CATEGORY), std::move(pItem)); //Get Project base path m_strProjectBasePath = AfxGetDefaultDirectory(true, true); if (m_strProjectBasePath.IsEmpty()) { LPITEMIDLIST lpidl; if (SHGetSpecialFolderLocation(AfxGetMainWnd()->m_hWnd, CSIDL_PERSONAL, &lpidl) == NOERROR) { SHGetPathFromIDList(lpidl, m_strProjectBasePath.GetBuffer(MAX_PATH)); m_strProjectBasePath.ReleaseBuffer(); //free memory LPMALLOC lpMalloc; SHGetMalloc(&lpMalloc); if (lpMalloc) lpMalloc->Free(lpidl); } } m_strProjectPath = m_strProjectBasePath; m_nFileFormat = CConfiguration::GetInstance()->m_nStandardFileFormat; //Set the info about the first tab to be activated m_nFirstTab = CConfiguration::GetInstance()->m_nLastTabProjectTemplateDlg; }
/** * This method returns the index of the named property. * * @param name The name of the property. * @return The index of the named property. */ PropertyIndex PropertiesHelper::propGetIdx( const std::string& name ) const { // find brackets, in case it's an array element, and if so, extract the // type name from it. uint32 bracket = name.find_first_of( '[' ); if ( bracket == std::string::npos ) bracket = name.size(); std::string typeName = name.substr( 0, bracket ); // get the property PropertyIndex result; DataDescription* pDD = pType_->findProperty( typeName ); if (pDD) { result.append( pDD->index() ); } // if no brackets, we can return as it's not an array. if ( bracket == name.size() ) return result; // find out if it's a valid python sequence PyObjectPtr ob( const_cast<PropertiesHelper*>(this)->propGetPy( result.valueAt(0) ), PyObjectPtr::STEAL_REFERENCE ); if ( PySequence_Check( ob.getObject() ) ) { // it's a sequence, so call propGetIdx in the array using the // ArrayPropertiesHelper, and append the return value to the result // PropertyIndex object. SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() ); ArrayPropertiesHelper propArray; propArray.init( pItem(), &(dataType->getElemType()), ob.getObject() ); PropertyIndex arrayResult = propArray.propGetIdx( name ); if ( !arrayResult.empty() ) { result.append( arrayResult ); } } return result; }
/** * This method returns the name of the property at the passed index. * * @param index The index of the property in pType. * @return The name of the property at the passed index in pType. */ std::string PropertiesHelper::propName( PropertyIndex index ) { if ( pType_ == NULL || index.empty() ) return ""; MF_ASSERT( index.valueAt(0) < (int) pType_->propertyCount() ); PyObjectPtr ob( propGetPy( index.valueAt(0) ), PyObjectPtr::STEAL_REFERENCE ); DataDescription* pDD = pType_->property( index.valueAt(0) ); std::string result = pDD->name(); if ( PySequence_Check( ob.getObject() ) && index.count() > 1 ) { SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() ); ArrayPropertiesHelper propArray; propArray.init( pItem(), &(dataType->getElemType()), ob.getObject() ); PropertyIndex arrayIndex = index.tail(); result = result + propArray.propName( arrayIndex ); } return result; }
void Interface_GUIWindow::remove_list_item(void* kodiBase, void* handle, void* item) { CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); CGUIAddonWindow* pAddonWindow = static_cast<CGUIAddonWindow*>(handle); if (!addon || !pAddonWindow || !item) { CLog::Log(LOGERROR, "Interface_GUIWindow::%s - invalid handler data (kodiBase='%p', handle='%p', item='%p') on addon '%s'", __FUNCTION__, addon, pAddonWindow, item, addon ? addon->ID().c_str() : "unknown"); return; } CFileItemPtr* pItem(static_cast<CFileItemPtr*>(item)); if (pItem->get() == nullptr) { CLog::Log(LOGERROR, "Interface_GUIWindow::%s - empty list item called on addon '%s'", __FUNCTION__, addon->ID().c_str()); return; } Interface_GUIGeneral::lock(); pAddonWindow->RemoveItem(pItem); Interface_GUIGeneral::unlock(); }
// ---------------------------------------------------------------------------- bool CVcfReader::xAssignVariantDel( const CVcfData& data, unsigned int index, CRef<CSeq_feat> pFeature ) // ---------------------------------------------------------------------------- { CVariation_ref::TData::TSet::TVariations& variants = pFeature->SetData().SetVariation().SetData().SetSet().SetVariations(); CRef<CVariation_ref> pVariant(new CVariation_ref); {{ //pVariant->SetData().SetNote("DEL"); pVariant->SetDeletion(); CVariation_inst& instance = pVariant->SetData().SetInstance(); CRef<CDelta_item> pItem(new CDelta_item); pItem->SetAction(CDelta_item::eAction_del_at); pItem->SetSeq().SetThis(); instance.SetDelta().push_back(pItem); }} variants.push_back(pVariant); return true; }
void f1(){ std::auto_ptr<Item> pItem(createItem()); //获得资源的同时应立即放进管理对象中 【管理对象->资源】,管理对象对资源的生死负责 //auto_ptr的析构函数会自动删除pItem }
/*---------------------------------------------------------------------- | CUPnPDirectory::GetDirectory +---------------------------------------------------------------------*/ bool CUPnPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CUPnP* upnp = CUPnP::GetInstance(); /* upnp should never be cached, it has internal cache */ items.SetCacheToDisc(CFileItemList::CACHE_NEVER); // We accept upnp://devuuid/[item_id/] NPT_String path = strPath.c_str(); if (!path.StartsWith("upnp://", true)) { return false; } if (path.Compare("upnp://", true) == 0) { upnp->StartClient(); // root -> get list of devices const NPT_Lock<PLT_DeviceDataReferenceList>& devices = upnp->m_MediaBrowser->GetMediaServers(); NPT_List<PLT_DeviceDataReference>::Iterator device = devices.GetFirstItem(); while (device) { NPT_String name = (*device)->GetFriendlyName(); NPT_String uuid = (*device)->GetUUID(); CFileItemPtr pItem(new CFileItem((const char*)name)); pItem->SetPath(CStdString((const char*) "upnp://" + uuid + "/")); pItem->m_bIsFolder = true; pItem->SetArt("thumb", (const char*)(*device)->GetIconUrl("image/png")); items.Add(pItem); ++device; } } else { if (!path.EndsWith("/")) path += "/"; // look for nextslash int next_slash = path.Find('/', 7); NPT_String uuid = (next_slash==-1)?path.SubString(7):path.SubString(7, next_slash-7); NPT_String object_id = (next_slash==-1)?"":path.SubString(next_slash+1); object_id.TrimRight("/"); if (object_id.GetLength()) { CStdString tmp = (char*) object_id; CURL::Decode(tmp); object_id = tmp; } // try to find the device with wait on startup PLT_DeviceDataReference device; if (!FindDeviceWait(upnp, uuid, device)) goto failure; // issue a browse request with object_id // if object_id is empty use "0" for root object_id = object_id.IsEmpty()?"0":object_id; // remember a count of object classes std::map<NPT_String, int> classes; // just a guess as to what types of files we want bool video = true; bool audio = true; bool image = true; m_strFileMask.TrimLeft("/"); if (!m_strFileMask.IsEmpty()) { video = m_strFileMask.Find(".wmv") >= 0; audio = m_strFileMask.Find(".wma") >= 0; image = m_strFileMask.Find(".jpg") >= 0; } // special case for Windows Media Connect and WMP11 when looking for root // We can target which root subfolder we want based on directory mask if (object_id == "0" && ((device->GetFriendlyName().Find("Windows Media Connect", 0, true) >= 0) || (device->m_ModelName == "Windows Media Player Sharing"))) { // look for a specific type to differentiate which folder we want if (audio && !video && !image) { // music object_id = "1"; } else if (!audio && video && !image) { // video object_id = "2"; } else if (!audio && !video && image) { // pictures object_id = "3"; } } #ifdef DISABLE_SPECIALCASE // same thing but special case for XBMC if (object_id == "0" && ((device->m_ModelName.Find("XBMC", 0, true) >= 0) || (device->m_ModelName.Find("Xbox Media Center", 0, true) >= 0))) { // look for a specific type to differentiate which folder we want if (audio && !video && !image) { // music object_id = "virtualpath://upnpmusic"; } else if (!audio && video && !image) { // video object_id = "virtualpath://upnpvideo"; } else if (!audio && !video && image) { // pictures object_id = "virtualpath://upnppictures"; } } #endif // if error, return now, the device could have gone away // this will make us go back to the sources list PLT_MediaObjectListReference list; NPT_Result res = upnp->m_MediaBrowser->BrowseSync(device, object_id, list); if (NPT_FAILED(res)) goto failure; // empty list is ok if (list.IsNull()) goto cleanup; PLT_MediaObjectList::Iterator entry = list->GetFirstItem(); while (entry) { // disregard items with wrong class/type if( (!video && (*entry)->m_ObjectClass.type.CompareN("object.item.videoitem", 21,true) == 0) || (!audio && (*entry)->m_ObjectClass.type.CompareN("object.item.audioitem", 21,true) == 0) || (!image && (*entry)->m_ObjectClass.type.CompareN("object.item.imageitem", 21,true) == 0) ) { ++entry; continue; } // never show empty containers in media views if((*entry)->IsContainer()) { if( (audio || video || image) && ((PLT_MediaContainer*)(*entry))->m_ChildrenCount == 0) { ++entry; continue; } } // keep count of classes classes[(*entry)->m_ObjectClass.type]++; CFileItemPtr pItem = BuildObject(*entry); if(!pItem) { ++entry; continue; } CStdString id = (char*) (*entry)->m_ObjectID; CURL::Encode(id); URIUtils::AddSlashAtEnd(id); pItem->SetPath(CStdString((const char*) "upnp://" + uuid + "/" + id.c_str())); items.Add(pItem); ++entry; } NPT_String max_string = ""; int max_count = 0; for(std::map<NPT_String, int>::iterator it = classes.begin(); it != classes.end(); it++) { if(it->second > max_count) { max_string = it->first; max_count = it->second; } } std::string content = GetContentMapping(max_string); items.SetContent(content); if (content == "unknown") { items.AddSortMethod(SORT_METHOD_UNSORTED, 571, LABEL_MASKS("%L", "%I", "%L", "")); items.AddSortMethod(SORT_METHOD_LABEL_IGNORE_FOLDERS, 551, LABEL_MASKS("%L", "%I", "%L", "")); items.AddSortMethod(SORT_METHOD_SIZE, 553, LABEL_MASKS("%L", "%I", "%L", "%I")); items.AddSortMethod(SORT_METHOD_DATE, 552, LABEL_MASKS("%L", "%J", "%L", "%J")); } } cleanup: return true; failure: return false; }
/*---------------------------------------------------------------------- | CUPnPDirectory::GetDirectory +---------------------------------------------------------------------*/ bool CUPnPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CUPnP* upnp = CUPnP::GetInstance(); /* upnp should never be cached, it has internal cache */ items.SetCacheToDisc(CFileItemList::CACHE_NEVER); // We accept upnp://devuuid/[item_id/] NPT_String path = strPath.c_str(); if (!path.StartsWith("upnp://", true)) { return false; } if (path.Compare("upnp://", true) == 0) { upnp->StartClient(); // root -> get list of devices const NPT_Lock<PLT_DeviceDataReferenceList>& devices = upnp->m_MediaBrowser->GetMediaServers(); NPT_List<PLT_DeviceDataReference>::Iterator device = devices.GetFirstItem(); while (device) { NPT_String name = (*device)->GetFriendlyName(); NPT_String uuid = (*device)->GetUUID(); CFileItemPtr pItem(new CFileItem((const char*)name)); pItem->SetPath(CStdString((const char*) "upnp://" + uuid + "/")); pItem->m_bIsFolder = true; pItem->SetThumbnailImage((const char*)(*device)->GetIconUrl("image/jpeg")); items.Add(pItem); ++device; } } else { if (!path.EndsWith("/")) path += "/"; // look for nextslash int next_slash = path.Find('/', 7); NPT_String uuid = (next_slash==-1)?path.SubString(7):path.SubString(7, next_slash-7); NPT_String object_id = (next_slash==-1)?"":path.SubString(next_slash+1); object_id.TrimRight("/"); if (object_id.GetLength()) { CStdString tmp = (char*) object_id; CURL::Decode(tmp); object_id = tmp; } // try to find the device with wait on startup PLT_DeviceDataReference device; if (!FindDeviceWait(upnp, uuid, device)) goto failure; // issue a browse request with object_id // if object_id is empty use "0" for root object_id = object_id.IsEmpty()?"0":object_id; // remember a count of object classes std::map<NPT_String, int> classes; // just a guess as to what types of files we want bool video = true; bool audio = true; bool image = true; m_strFileMask.TrimLeft("/"); if (!m_strFileMask.IsEmpty()) { video = m_strFileMask.Find(".wmv") >= 0; audio = m_strFileMask.Find(".wma") >= 0; image = m_strFileMask.Find(".jpg") >= 0; } // special case for Windows Media Connect and WMP11 when looking for root // We can target which root subfolder we want based on directory mask if (object_id == "0" && ((device->GetFriendlyName().Find("Windows Media Connect", 0, true) >= 0) || (device->m_ModelName == "Windows Media Player Sharing"))) { // look for a specific type to differentiate which folder we want if (audio && !video && !image) { // music object_id = "1"; } else if (!audio && video && !image) { // video object_id = "2"; } else if (!audio && !video && image) { // pictures object_id = "3"; } } #ifdef DISABLE_SPECIALCASE // same thing but special case for XBMC if (object_id == "0" && ((device->m_ModelName.Find("XBMC", 0, true) >= 0) || (device->m_ModelName.Find("Xbox Media Center", 0, true) >= 0))) { // look for a specific type to differentiate which folder we want if (audio && !video && !image) { // music object_id = "virtualpath://upnpmusic"; } else if (!audio && video && !image) { // video object_id = "virtualpath://upnpvideo"; } else if (!audio && !video && image) { // pictures object_id = "virtualpath://upnppictures"; } } #endif // if error, return now, the device could have gone away // this will make us go back to the sources list PLT_MediaObjectListReference list; NPT_Result res = upnp->m_MediaBrowser->BrowseSync(device, object_id, list); if (NPT_FAILED(res)) goto failure; // empty list is ok if (list.IsNull()) goto cleanup; PLT_MediaObjectList::Iterator entry = list->GetFirstItem(); while (entry) { // disregard items with wrong class/type if( (!video && (*entry)->m_ObjectClass.type.CompareN("object.item.videoitem", 21,true) == 0) || (!audio && (*entry)->m_ObjectClass.type.CompareN("object.item.audioitem", 21,true) == 0) || (!image && (*entry)->m_ObjectClass.type.CompareN("object.item.imageitem", 21,true) == 0) ) { ++entry; continue; } // never show empty containers in media views if((*entry)->IsContainer()) { if( (audio || video || image) && ((PLT_MediaContainer*)(*entry))->m_ChildrenCount == 0) { ++entry; continue; } } NPT_String ObjectClass = (*entry)->m_ObjectClass.type.ToLowercase(); // keep count of classes classes[(*entry)->m_ObjectClass.type]++; CFileItemPtr pItem(new CFileItem((const char*)(*entry)->m_Title)); pItem->SetLabelPreformated(true); pItem->m_strTitle = (const char*)(*entry)->m_Title; pItem->m_bIsFolder = (*entry)->IsContainer(); CStdString id = (char*) (*entry)->m_ObjectID; CURL::Encode(id); pItem->SetPath(CStdString((const char*) "upnp://" + uuid + "/" + id.c_str())); // if it's a container, format a string as upnp://uuid/object_id if (pItem->m_bIsFolder) { pItem->SetPath(pItem->GetPath() + "/"); // look for metadata if( ObjectClass.StartsWith("object.container.album.videoalbum") ) { pItem->SetLabelPreformated(false); CUPnP::PopulateTagFromObject(*pItem->GetVideoInfoTag(), *(*entry), NULL); } else if( ObjectClass.StartsWith("object.container.album.photoalbum")) { //CPictureInfoTag* tag = pItem->GetPictureInfoTag(); } else if( ObjectClass.StartsWith("object.container.album") ) { pItem->SetLabelPreformated(false); CUPnP::PopulateTagFromObject(*pItem->GetMusicInfoTag(), *(*entry), NULL); } } else { // set a general content type if (ObjectClass.StartsWith("object.item.videoitem")) pItem->SetMimeType("video/octet-stream"); else if(ObjectClass.StartsWith("object.item.audioitem")) pItem->SetMimeType("audio/octet-stream"); else if(ObjectClass.StartsWith("object.item.imageitem")) pItem->SetMimeType("image/octet-stream"); if ((*entry)->m_Resources.GetItemCount()) { PLT_MediaItemResource& resource = (*entry)->m_Resources[0]; // set metadata if (resource.m_Size != (NPT_LargeSize)-1) { pItem->m_dwSize = resource.m_Size; } // look for metadata if( ObjectClass.StartsWith("object.item.videoitem") ) { pItem->SetLabelPreformated(false); CUPnP::PopulateTagFromObject(*pItem->GetVideoInfoTag(), *(*entry), &resource); } else if( ObjectClass.StartsWith("object.item.audioitem") ) { pItem->SetLabelPreformated(false); CUPnP::PopulateTagFromObject(*pItem->GetMusicInfoTag(), *(*entry), &resource); } else if( ObjectClass.StartsWith("object.item.imageitem") ) { //CPictureInfoTag* tag = pItem->GetPictureInfoTag(); } } } // look for date? if((*entry)->m_Description.date.GetLength()) { SYSTEMTIME time = {}; sscanf((*entry)->m_Description.date, "%hu-%hu-%huT%hu:%hu:%hu", &time.wYear, &time.wMonth, &time.wDay, &time.wHour, &time.wMinute, &time.wSecond); pItem->m_dateTime = time; } // if there is a thumbnail available set it here if((*entry)->m_ExtraInfo.album_art_uri.GetLength()) pItem->SetThumbnailImage((const char*) (*entry)->m_ExtraInfo.album_art_uri); else if((*entry)->m_Description.icon_uri.GetLength()) pItem->SetThumbnailImage((const char*) (*entry)->m_Description.icon_uri); PLT_ProtocolInfo fanart_mask("xbmc.org", "*", "fanart", "*"); for(unsigned i = 0; i < (*entry)->m_Resources.GetItemCount(); ++i) { PLT_MediaItemResource& res = (*entry)->m_Resources[i]; if(res.m_ProtocolInfo.Match(fanart_mask)) { pItem->SetProperty("fanart_image", (const char*)res.m_Uri); break; } } items.Add(pItem); ++entry; } NPT_String max_string = ""; int max_count = 0; for(std::map<NPT_String, int>::iterator it = classes.begin(); it != classes.end(); it++) { if(it->second > max_count) { max_string = it->first; max_count = it->second; } } items.SetContent(GetContentMapping(max_string)); } cleanup: return true; failure: return false; }
bool CDAAPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CURL url(strPath); CStdString strRoot = strPath; URIUtils::AddSlashAtEnd(strRoot); CStdString host = url.GetHostName(); if (url.HasPort()) host.Format("%s:%i",url.GetHostName(),url.GetPort()); m_thisHost = g_DaapClient.GetHost(host); if (!m_thisHost) return false; // find out where we are in the folder hierarchy m_currLevel = GetCurrLevel(strRoot); CLog::Log(LOGDEBUG, "DAAPDirectory: Current Level is %i", m_currLevel); // if we have at least one database we should show it's contents if (m_thisHost->nDatabases) { CLog::Log(LOGDEBUG, "Have %i databases", m_thisHost->nDatabases); //Store the first database g_DaapClient.m_iDatabase = m_thisHost->databases[0].id; m_currentSongItems = m_thisHost->dbitems[0].items; m_currentSongItemCount = m_thisHost->dbitems[0].nItems; // Get the songs from the database if we haven't already if (!m_artisthead && (m_currLevel >= 0 && m_currLevel < 2)) { CLog::Log(LOGDEBUG, "Getting songs from the database. Have %i", m_currentSongItemCount); // Add each artist and album to an array for (int c = 0; c < m_currentSongItemCount; c++) { AddToArtistAlbum(m_currentSongItems[c].songartist, m_currentSongItems[c].songalbum); } } if (m_currLevel < 0) // root, so show playlists { for (int c = 0; c < m_thisHost->dbplaylists->nPlaylists; c++) { CStdString strFile; //size_t strLen; // we use UTF-8 internally, so no need to convert strFile = m_thisHost->dbplaylists->playlists[c].itemname; // Add item to directory list CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", strFile.c_str()); CFileItemPtr pItem(new CFileItem(strFile)); pItem->SetPath(strRoot + m_thisHost->dbplaylists->playlists[c].itemname + "/"); pItem->m_bIsFolder = true; items.Add(pItem); } } else if (m_currLevel == 0) // playlists, so show albums { // find the playlist bool bFoundMatch = false; int c; for (c = 0; c < m_thisHost->dbplaylists->nPlaylists; c++) { if (m_thisHost->dbplaylists->playlists[c].itemname == m_selectedPlaylist) { bFoundMatch = true; break; } } // if we found it show the songs contained ... if (bFoundMatch) { // if selected playlist name == d/b name then show in artist/album/song formation if (strcmp(m_thisHost->databases[0].name, m_thisHost->dbplaylists->playlists[c].itemname) == 0) { CStdString strBuffer; artistPTR *cur = m_artisthead; while (cur) { strBuffer = cur->artist; CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", strBuffer.c_str()); CFileItemPtr pItem(new CFileItem(strBuffer)); pItem->SetPath(strRoot + cur->artist + "/"); pItem->m_bIsFolder = true; items.Add(pItem); cur = cur->next; } } else { // no support for playlist items in libOpenDAAP yet? - there is now :) int j; for (j = 0; j < m_thisHost->dbplaylists->playlists[c].count; j++) { // the playlist id is the song id, these do not directly match the array // position so we've no choice but to cycle through all the songs until // we find the one we want. int i, idx; idx = -1; for (i = 0; i < m_currentSongItemCount; i ++) { if (m_currentSongItems[i].id == m_thisHost->dbplaylists->playlists[c].items[j].songid) { idx = i; break; } } if (idx > -1) { CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", m_currentSongItems[idx].itemname); CFileItemPtr pItem(new CFileItem(m_currentSongItems[idx].itemname)); CStdString path; if( m_thisHost->version_major != 3 ) { path.Format(REQUEST42, m_thisHost->host, g_DaapClient.m_iDatabase, m_currentSongItems[idx].id, m_currentSongItems[idx].songformat, m_thisHost->sessionid, m_thisHost->revision_number); } else { path.Format(REQUEST45, m_thisHost->host, g_DaapClient.m_iDatabase, m_currentSongItems[idx].id, m_currentSongItems[idx].songformat, m_thisHost->sessionid); } pItem->SetPath(path); pItem->m_bIsFolder = false; pItem->m_dwSize = m_currentSongItems[idx].songsize; pItem->GetMusicInfoTag()->SetURL(pItem->GetPath()); pItem->GetMusicInfoTag()->SetTitle(m_currentSongItems[idx].itemname); pItem->GetMusicInfoTag()->SetArtist(m_currentSongItems[idx].songartist); pItem->GetMusicInfoTag()->SetAlbum(m_currentSongItems[idx].songalbum); //pItem->m_musicInfoTag.SetTrackNumber(m_currentSongItems[idx].songtracknumber); pItem->GetMusicInfoTag()->SetTrackNumber(m_thisHost->dbplaylists->playlists[c].items[j].songid); //pItem->m_musicInfoTag.SetTrackNumber(j+1); //pItem->m_musicInfoTag.SetPartOfSet(m_currentSongItems[idx].songdiscnumber); pItem->GetMusicInfoTag()->SetDuration((int) (m_currentSongItems[idx].songtime / 1000)); pItem->GetMusicInfoTag()->SetLoaded(true); items.Add(pItem); } } } } } else if (m_currLevel == 1) // artists, so show albums { // Find the artist ... artistPTR *cur = m_artisthead; while (cur) { if (cur->artist == m_selectedArtist) break; cur = cur->next; } // if we find it, then show albums for this artist if (cur) { albumPTR *curAlbum = cur->albumhead; while (curAlbum) { CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", curAlbum->album); CFileItemPtr pItem(new CFileItem(curAlbum->album)); pItem->SetPath(strRoot + curAlbum->album + "/"); pItem->m_bIsFolder = true; items.Add(pItem); curAlbum = curAlbum->next; } } } else if (m_currLevel == 2) // albums, so show songs { int c; for (c = 0; c < m_currentSongItemCount; c++) { // mt-daapd will sometimes give us null artist and album names if (m_currentSongItems[c].songartist && m_currentSongItems[c].songalbum) { char *artist = m_currentSongItems[c].songartist; char *album = m_currentSongItems[c].songalbum; if (!strlen(artist)) artist = (char *)unknownArtistAlbum; if (!strlen(album)) album = (char *)unknownArtistAlbum; // if this song is for the current artist & album add it to the file list if (artist == m_selectedArtist && album == m_selectedAlbum) { CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", m_currentSongItems[c].itemname); CFileItemPtr pItem(new CFileItem(m_currentSongItems[c].itemname)); CStdString path; if( m_thisHost->version_major != 3 ) { path.Format(REQUEST42, m_thisHost->host, g_DaapClient.m_iDatabase, m_currentSongItems[c].id, m_currentSongItems[c].songformat, m_thisHost->sessionid, m_thisHost->revision_number); } else { path.Format(REQUEST45, m_thisHost->host, g_DaapClient.m_iDatabase, m_currentSongItems[c].id, m_currentSongItems[c].songformat, m_thisHost->sessionid); } pItem->SetPath(path); pItem->m_bIsFolder = false; pItem->m_dwSize = m_currentSongItems[c].songsize; pItem->GetMusicInfoTag()->SetURL(pItem->GetPath()); pItem->GetMusicInfoTag()->SetTitle(m_currentSongItems[c].itemname); pItem->GetMusicInfoTag()->SetArtist(m_selectedArtist); pItem->GetMusicInfoTag()->SetAlbum(m_selectedAlbum); pItem->GetMusicInfoTag()->SetTrackNumber(m_currentSongItems[c].songtracknumber); pItem->GetMusicInfoTag()->SetPartOfSet(m_currentSongItems[c].songdiscnumber); pItem->GetMusicInfoTag()->SetDuration((int) (m_currentSongItems[c].songtime / 1000)); pItem->GetMusicInfoTag()->SetLoaded(true); items.Add(pItem); } } } } } return true; }
/*---------------------------------------------------------------------- | CUPnPDirectory::GetDirectory +---------------------------------------------------------------------*/ bool CUPnPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CGUIDialogProgress* dlgProgress = NULL; CUPnP* upnp = CUPnP::GetInstance(); /* upnp should never be cached, it has internal cache */ items.SetCacheToDisc(CFileItemList::CACHE_NEVER); // start client if it hasn't been done yet bool client_started = upnp->IsClientStarted(); upnp->StartClient(); // We accept upnp://devuuid/[item_id/] NPT_String path = strPath.c_str(); if (!path.StartsWith("upnp://", true)) { return false; } if (path.Compare("upnp://", true) == 0) { // root -> get list of devices const NPT_Lock<PLT_DeviceMap>& devices = upnp->m_MediaBrowser->GetMediaServers(); const NPT_List<PLT_DeviceMapEntry*>& entries = devices.GetEntries(); NPT_List<PLT_DeviceMapEntry*>::Iterator entry = entries.GetFirstItem(); while (entry) { PLT_DeviceDataReference device = (*entry)->GetValue(); NPT_String name = device->GetFriendlyName(); NPT_String uuid = (*entry)->GetKey(); CFileItemPtr pItem(new CFileItem((const char*)name)); pItem->m_strPath = (const char*) "upnp://" + uuid + "/"; pItem->m_bIsFolder = true; pItem->SetThumbnailImage((const char*)device->GetIconUrl("image/jpeg")); items.Add(pItem); ++entry; } } else { if (!path.EndsWith("/")) path += "/"; // look for nextslash int next_slash = path.Find('/', 7); NPT_String uuid = (next_slash==-1)?path.SubString(7):path.SubString(7, next_slash-7); NPT_String object_id = (next_slash==-1)?"":path.SubString(next_slash+1); object_id.TrimRight("/"); if (object_id.GetLength()) { CStdString tmp = (char*) object_id; CUtil::UrlDecode(tmp); object_id = tmp; } // look for device in our list // (and wait for it to respond for 5 secs if we're just starting upnp client) NPT_TimeStamp watchdog; NPT_System::GetCurrentTimeStamp(watchdog); watchdog += 5.f; PLT_DeviceDataReference* device; for (;;) { const NPT_Lock<PLT_DeviceMap>& devices = upnp->m_MediaBrowser->GetMediaServers(); if (NPT_SUCCEEDED(devices.Get(uuid, device)) && device) break; // fail right away if device not found and upnp client was already running if (client_started) goto failure; // otherwise check if we've waited long enough without success NPT_TimeStamp now; NPT_System::GetCurrentTimeStamp(now); if (now > watchdog) goto failure; // sleep a bit and try again NPT_System::Sleep(NPT_TimeInterval(1, 0)); } // issue a browse request with object_id // if object_id is empty use "0" for root object_id = object_id.IsEmpty()?"0":object_id; // just a guess as to what types of files we want bool video = true; bool audio = true; bool image = true; m_strFileMask.TrimLeft("/"); if (!m_strFileMask.IsEmpty()) { video = m_strFileMask.Find(".wmv") >= 0; audio = m_strFileMask.Find(".wma") >= 0; image = m_strFileMask.Find(".jpg") >= 0; } // special case for Windows Media Connect and WMP11 when looking for root // We can target which root subfolder we want based on directory mask if (object_id == "0" && (((*device)->GetFriendlyName().Find("Windows Media Connect", 0, true) >= 0) || ((*device)->m_ModelName == "Windows Media Player Sharing"))) { // look for a specific type to differentiate which folder we want if (audio && !video && !image) { // music object_id = "1"; } else if (!audio && video && !image) { // video object_id = "2"; } else if (!audio && !video && image) { // pictures object_id = "3"; } } #ifdef DISABLE_SPECIALCASE // same thing but special case for XBMC if (object_id == "0" && (((*device)->m_ModelName.Find("XBMC", 0, true) >= 0) || ((*device)->m_ModelName.Find("Xbox Media Center", 0, true) >= 0))) { // look for a specific type to differentiate which folder we want if (audio && !video && !image) { // music object_id = "virtualpath://upnpmusic"; } else if (!audio && video && !image) { // video object_id = "virtualpath://upnpvideo"; } else if (!audio && !video && image) { // pictures object_id = "virtualpath://upnppictures"; } } #endif // bring up dialog if object is not cached if (!upnp->m_MediaBrowser->IsCached(uuid, object_id)) { dlgProgress = (CGUIDialogProgress*)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS); if (dlgProgress) { dlgProgress->ShowProgressBar(false); dlgProgress->SetCanCancel(false); dlgProgress->SetHeading(20334); dlgProgress->SetLine(0, 194); dlgProgress->SetLine(1, ""); dlgProgress->SetLine(2, ""); dlgProgress->StartModal(); } } // if error, return now, the device could have gone away // this will make us go back to the sources list PLT_MediaObjectListReference list; NPT_Result res = upnp->m_MediaBrowser->Browse(*device, object_id, list); if (NPT_FAILED(res)) goto failure; // empty list is ok if (list.IsNull()) goto cleanup; PLT_MediaObjectList::Iterator entry = list->GetFirstItem(); while (entry) { // disregard items with wrong class/type if( (!video && (*entry)->m_ObjectClass.type.CompareN("object.item.videoitem", 21,true) == 0) || (!audio && (*entry)->m_ObjectClass.type.CompareN("object.item.audioitem", 21,true) == 0) || (!image && (*entry)->m_ObjectClass.type.CompareN("object.item.imageitem", 21,true) == 0) ) { ++entry; continue; } // never show empty containers in media views if((*entry)->IsContainer()) { if( (audio || video || image) && ((PLT_MediaContainer*)(*entry))->m_ChildrenCount == 0) { ++entry; continue; } } CFileItemPtr pItem(new CFileItem((const char*)(*entry)->m_Title)); pItem->SetLabelPreformated(true); pItem->m_bIsFolder = (*entry)->IsContainer(); // if it's a container, format a string as upnp://uuid/object_id if (pItem->m_bIsFolder) { CStdString id = (char*) (*entry)->m_ObjectID; CUtil::URLEncode(id); pItem->m_strPath = (const char*) "upnp://" + uuid + "/" + id.c_str() + "/"; } else { if ((*entry)->m_Resources.GetItemCount()) { PLT_MediaItemResource& resource = (*entry)->m_Resources[0]; // look for a resource with "xbmc-get" protocol // if we can't find one, keep the first resource NPT_ContainerFind((*entry)->m_Resources, CProtocolFinder("xbmc-get"), resource); CLog::Log(LOGDEBUG, "CUPnPDirectory::GetDirectory - resource protocol info '%s'", (const char*)(resource.m_ProtocolInfo)); // if it's an item, path is the first url to the item // we hope the server made the first one reachable for us // (it could be a format we dont know how to play however) pItem->m_strPath = (const char*) resource.m_Uri; // set metadata if (resource.m_Size > 0) { pItem->m_dwSize = resource.m_Size; } // set a general content type CStdString type = (const char*)(*entry)->m_ObjectClass.type.Left(21); if (type.Equals("object.item.videoitem")) pItem->SetContentType("video/octet-stream"); else if(type.Equals("object.item.audioitem")) pItem->SetContentType("audio/octet-stream"); else if(type.Equals("object.item.imageitem")) pItem->SetContentType("image/octet-stream"); // look for content type in protocol info if (resource.m_ProtocolInfo.GetLength()) { char proto[1024]; char dummy1[1024]; char ct[1204]; char dummy2[1024]; int fields = sscanf(resource.m_ProtocolInfo, "%[^:]:%[^:]:%[^:]:%[^:]", proto, dummy1, ct, dummy2); if (fields == 4) { if (strcmp(ct, "application/octet-stream") != 0) { pItem->SetContentType(ct); } } else { CLog::Log(LOGERROR, "CUPnPDirectory::GetDirectory - invalid protocol info '%s'", (const char*)(resource.m_ProtocolInfo)); } } // look for date? if((*entry)->m_Description.date.GetLength()) { SYSTEMTIME time = {}; sscanf((*entry)->m_Description.date, "%hu-%hu-%huT%hu:%hu:%hu", &time.wYear, &time.wMonth, &time.wDay, &time.wHour, &time.wMinute, &time.wSecond); pItem->m_dateTime = time; } // look for metadata if( (*entry)->m_ObjectClass.type.CompareN("object.item.videoitem", 21,true) == 0 ) { pItem->SetLabelPreformated(false); CUPnP::PopulateTagFromObject(*pItem->GetVideoInfoTag(), *(*entry), &resource); } else if( (*entry)->m_ObjectClass.type.CompareN("object.item.audioitem", 21,true) == 0 ) { pItem->SetLabelPreformated(false); CUPnP::PopulateTagFromObject(*pItem->GetMusicInfoTag(), *(*entry), &resource); } else if( (*entry)->m_ObjectClass.type.CompareN("object.item.imageitem", 21,true) == 0 ) { //CPictureInfoTag* tag = pItem->GetPictureInfoTag(); } } } // if there is a thumbnail available set it here if((*entry)->m_ExtraInfo.album_art_uri.GetLength()) pItem->SetThumbnailImage((const char*) (*entry)->m_ExtraInfo.album_art_uri); else if((*entry)->m_Description.icon_uri.GetLength()) pItem->SetThumbnailImage((const char*) (*entry)->m_Description.icon_uri); items.Add(pItem); ++entry; } } cleanup: if (dlgProgress) dlgProgress->Close(); return true; failure: if (dlgProgress) dlgProgress->Close(); return false; }
/** * Builds a list of commands for the right click on Editor Chunk Item operation. * * @return Returns the list of commands. */ std::vector<std::string> PropertiesHelper::command() { propMap_.clear(); std::vector<std::string> links; int index = 0; for (int i=0; i < propCount(); i++) { DataDescription* pDD = pType()->property( i ); if (!pDD->editable()) continue; if ( isUserDataObjectLink(i) ) { PyObjectPtr ob( propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); std::string uniqueId = PyString_AsString( PyTuple_GetItem( ob.getObject(), 0 ) ); if ( !uniqueId.empty() ) { links.push_back( "#"+propName(i) ); links.push_back( "#"+uniqueId ); links.push_back( "Delete Link" ); propMap_[index++] = PropertyIndex( i ); links.push_back( "##" ); links.push_back( "##" ); } } else if ( isUserDataObjectLinkArray(i) ) { PyObjectPtr ob( propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() ); ArrayPropertiesHelper propArray; propArray.init( pItem(), &(dataType->getElemType()), ob.getObject()); int numProps = propArray.propCount(); if ( numProps > 0 ) { links.push_back( "#"+propName(i) ); links.push_back( "Delete All" ); propMap_[index++] = PropertyIndex( i ); links.push_back( "" ); // Iterate through the array of links for(int j = 0; j < numProps; j++) { PyObjectPtr link( propArray.propGetPy( j ), PyObjectPtr::STEAL_REFERENCE ); std::string uniqueId = PyString_AsString( PyTuple_GetItem( link.getObject(), 0 ) ); if ( !uniqueId.empty() ) { links.push_back( "#"+uniqueId ); links.push_back( "Delete Link" ); PropertyIndex pi( i ); pi.append( j ); propMap_[index++] = pi; links.push_back( "##" ); } } links.push_back( "##" ); } } } return links; }
//--------------------------------------------------------------------------- void __fastcall TMainForm::SetupData() { c4_View saveView = _data; DataGrid->Invalidate(); _data = c4_View (); c4_String title = Caption.c_str(); int w = title.Find(" - "); if (w > 0) Caption = (const char*) title.Left(w); int n = _path.GetSize(); if (n == 0) { DataGrid->ColCount = 1; DataGrid->RowCount = 1; return; } _data = _storage; c4_IntProp pItem ("item"); c4_StringProp pName ("name"); for (c4_Cursor curr = &_path[0]; curr < &_path[n]; ++curr) { int item = pItem (*curr); c4_String name (pName (*curr)); if (item >= _data.GetSize()) _data = c4_View (); _colNum = -1; // assume we'll be looking at an entire view for (int i = 0; i < _data.NumProperties(); ++i) { c4_Property prop (_data.NthProperty(i)); if (prop.Name() == name) { if (prop.Type() == 'V') _data = ((c4_ViewProp&) prop) (_data[item]); else _colNum = i; // wrong assumption, just one column break; } } char buf [10]; if (curr == &_path[0]) strcpy(buf, " - "); else if (_colNum >= 0) strcpy(buf, "."); else wsprintf(buf, "[%d].", item); Caption = Caption + buf; Caption = Caption + (const char*) name; } DataGrid->ColCount = _colNum >= 0 ? 2 : _data.NumProperties() + 1; if (DataGrid->ColCount > 1) DataGrid->FixedCols = 1; DataGrid->ColWidths[0] = 40; if (_colNum >= 0) DataGrid->ColWidths[1] = 250; if (&saveView[0] != &_data[0]) { DataGrid->RowCount = 1; // force a reset to top DataGrid->RowCount = _data.GetSize() + 1; if (DataGrid->RowCount > 1) DataGrid->FixedRows = 1; } }
void CGUIDialogSelect::Add(const CStdString& strLabel) { CFileItemPtr pItem(new CFileItem(strLabel)); m_vecListInternal->Add(pItem); }
void ResultsItemModel::addResults(const std::vector<SpectralLibraryMatch::MatchResults>& theResults, const std::map<Signature*, ColorType>& colorMap, Progress* pProgress, bool* pAbort) { if (theResults.empty()) { return; } bool findPrevious = (rowCount() > 0); // don't look for previous results if model is empty. if (pProgress != NULL) { pProgress->updateProgress("Adding Match Results to Results Window...", 0, NORMAL); } unsigned int resultCount(0); unsigned int numResults = theResults.size(); mResults.reserve(mResults.size() + numResults); for (std::vector<SpectralLibraryMatch::MatchResults>::const_iterator it = theResults.begin(); it != theResults.end(); ++it) { if (pAbort != NULL && *pAbort) { if (pProgress != NULL) { pProgress->updateProgress("Adding Match Results to Results Window canceled by user", 0, ABORT); } return; } // Get the results item if it already exists ResultsItem* pItem(NULL); bool newItem(false); if (findPrevious) { pItem = findResult(it->mTargetName, it->mAlgorithmUsed); } // Add the top-level item for the results if (pItem == NULL) { int resultsRow = static_cast<int>(mResults.size()); beginInsertRows(QModelIndex(), resultsRow, resultsRow); // Set the target name and algorithm name in the item constructor so that they will be available when // the sort model automatically sorts the top-level results items when endInsertRows() is called QString targetName = QString::fromStdString(it->mTargetName); QString algorithmName = QString::fromStdString( StringUtilities::toDisplayString<SpectralLibraryMatch::MatchAlgorithm>(it->mAlgorithmUsed)); pItem = new ResultsItem(targetName, algorithmName); newItem = true; mItemMap[getKeyString(it->mTargetName, it->mAlgorithmUsed)] = pItem; mResults.push_back(pItem); endInsertRows(); } // Get the index for the top-level results item int resultsRow = getRow(pItem); QModelIndex resultsIndex = index(resultsRow, 0); // If the results item already exists, remove any existing signature match rows if (newItem == false) { int signatureRows = pItem->rows(); if (signatureRows <= 0) { // Set the number of rows to 1 to account for the row indicating no matches are found signatureRows = 1; } beginRemoveRows(resultsIndex, 0, signatureRows - 1); pItem->clear(); endRemoveRows(); } // Add the updated signature match rows int signatureRows = it->mResults.size(); if (signatureRows <= 0) { // Set the number of rows to 1 to account for the row indicating no matches are found signatureRows = 1; } mAddingResults = true; beginInsertRows(resultsIndex, 0, signatureRows - 1); pItem->setData(*it, colorMap); endInsertRows(); mAddingResults = false; // Update the progress if (pProgress != NULL) { ++resultCount; pProgress->updateProgress("Adding Match Results to Results Window...", resultCount * 100 / numResults, NORMAL); } } if (pProgress != NULL) { pProgress->updateProgress("Finished adding Match Results to Results Window.", 100, NORMAL); } }
int CGUIDialogSelect::Add(const CStdString& strLabel) { CFileItemPtr pItem(new CFileItem(strLabel)); m_vecList->Add(pItem); return m_vecList->Size() - 1; }
bool CPrintFolder::PrintPage(CDCHandle dc, UINT nPage) { try { IW::FolderPtr pFolder = _state.Folder.GetFolder(); int nBkMode = dc.SetBkMode(TRANSPARENT); COLORREF clrTextColor = dc.SetTextColor(RGB(0,0,0)); int nImageRows = m_bPrintOnePerPage ? 1 : _sizeRowsColumns.cy; int nImageColumns = m_bPrintOnePerPage ? 1 : _sizeRowsColumns.cx; int nImagePerPage = nImageColumns * nImageRows; int nMin = nImagePerPage * nPage; int nMax = nMin + nImagePerPage; int nImage = 0; long nNormalCount = pFolder->GetItemCount(); bool bImage = false; bool bSelected = false; //bool bIsPreview = OBJ_ENHMETADC == GetObjectType(dc); for(int i = 0; i < nNormalCount; i++) { _pStatus->SetHighLevelProgress(i, nNormalCount); bImage = pFolder->IsItemImage(i); bSelected = pFolder->IsItemSelected(i); // Only process if image if (bImage && (!m_bPrintSelected || bSelected)) { if (nImage >= nMin && nImage < nMax) { int nImageThisPage = nImage - nMin; CPoint point; point.x = _rectExtents.left + (_sizeSection.cx * (nImageThisPage % nImageColumns)); point.y = _rectExtents.top + (_sizeSection.cy * (nImageThisPage / nImageColumns)); if (m_bShowHeader) { point.y += m_nHeaderHeight; } IW::FolderItemLock pItem(pFolder, i); if (!PrintImage(dc, pItem, point)) return false; } nImage++; } } dc.SetBkMode(nBkMode); dc.SetTextColor(clrTextColor); } catch(_com_error &e) { IW::CMessageBoxIndirect mb; mb.ShowException(IDS_LOW_LEVEL_ERROR_FMT, e); } return true; }