void CHelperItemSet::InitPaihangTree(const char* worldid) { if(m_worldIdList.size()>0 ) { //for(int i=0;i<(int)m_worldIdList.size();i++) //{ // if(strcmp(((String)m_worldIdList[i]).c_str(),worldid)==0) return; //} } m_worldIdList.push_back(String(worldid)); int ArryLenth=3; char *Anchors[]={"top50level.html","top50money.html","top50xinfa.html"}; wchar_t *Names[]={L"高手排行(TOP50)", L"富豪排行(TOP50)", L"心法排行(TOP50)"}; if(!m_rootItemPaihang) return; char *PathStart="http://tl.sohu.com/tlbbrank"; char szPath[MAX_PATH]; char szAnchor[MAX_PATH]; for(int i=0;i<ArryLenth;i++) { memset(szAnchor, 0, MAX_PATH); memset(szPath, 0, MAX_PATH); strcpy(szPath, PathStart); strcat(szPath, "/"); strcat(szPath,worldid); strcat(szPath,"/"); strcat(szPath,Anchors[i]); WString itemName(Names[i]); strcpy(szAnchor,Anchors[i]); strcat(szAnchor,worldid); String itemAnchor(szAnchor); String itemUrl(szPath); itemUrl=CheckUrl(itemUrl); CHelperItem item(itemName, itemAnchor,itemUrl ); m_rootItemPaihang->AddChildItem(item); } }
QString ThumbnailModel::imagePath(const QModelIndex &index) const { QUrl url = itemUrl(index); return url.isValid() ? thumbnailPath(url) : QString(); }
void SavedListsEngine::run() { QThread::setTerminationEnabled(true); m_stop = false; if (m_updateSourceInfo || m_removeSourceInfo) { NepomukListEngine::run(); return; } QList<MediaItem> mediaList; if (m_mediaListProperties.engineArg().isEmpty() && !m_mediaListProperties.engineFilter().isEmpty()) { MediaListProperties mediaListProperties = m_mediaListProperties; mediaListProperties.lri = m_mediaListProperties.engineFilter(); kDebug() << mediaListProperties.lri; emit loadOtherEngine(mediaListProperties, m_requestSignature, m_subRequestSignature); m_requestSignature = QString(); m_subRequestSignature = QString(); return; } if (!m_mediaListProperties.engineArg().isEmpty()) { QString workingDir; QFile file(KStandardDirs::locateLocal("data", QString("bangarang/%1").arg(m_mediaListProperties.engineArg()), false)); if (file.exists()) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { emit results(m_requestSignature, mediaList, m_mediaListProperties, true, m_subRequestSignature); return; } } else { KUrl url(m_mediaListProperties.engineArg()); workingDir = url.directory(KUrl::AppendTrailingSlash); file.setFileName(url.path()); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { emit results(m_requestSignature, mediaList, m_mediaListProperties, true, m_subRequestSignature); return; } } //Make sure it's a valid M3U fileref QTextStream in(&file); bool valid = false; bool isM3U = false; bool isPLS = false; if (!in.atEnd()) { QString line = in.readLine(); if (line.trimmed() == "#EXTM3U") { valid = true; isM3U = true; } else if (line.trimmed() == "[playlist]") { valid = true; isPLS = true; } } //Create a MediaItem for each entry if (valid) { while (!in.atEnd()) { if (m_stop) { return; } QString line = in.readLine(); QString title; QString url; int duration = 0; //Read playlist entry to get title and url if ((isM3U) && line.startsWith("#EXTINF:")) { line = line.replace("#EXTINF:",""); QStringList durTitle = line.split(","); if (durTitle.count() == 1) { //No title title = durTitle.at(0); } else { duration = durTitle.at(0).toInt(); title = durTitle.at(1); } url = in.readLine().trimmed(); } else if ((isPLS) && line.startsWith("File")) { url = line.mid(line.indexOf("=") + 1).trimmed(); if (!in.atEnd()) { line = in.readLine(); title = line.mid(line.indexOf("=") + 1).trimmed(); } if (!in.atEnd()) { line = in.readLine(); duration = line.mid(line.indexOf("=") + 1).trimmed().toInt(); } } //Create a basic mediaItem for each entry MediaItem mediaItem; KUrl itemUrl(workingDir, url); if (!url.isEmpty()) { if (!title.isEmpty()) { mediaItem.title = title; } else { mediaItem.title = itemUrl.fileName(); } mediaItem.fields["title"] = mediaItem.title; mediaItem.url = itemUrl.prettyUrl(); mediaItem.fields["url"] = mediaItem.url; if (Utilities::isVideo(mediaItem.url)) { mediaItem.type = "Video"; mediaItem.artwork = KIcon("video-x-generic"); mediaItem.fields["videoType"] = "Video Clip"; } else { mediaItem.type = "Audio"; mediaItem.artwork = KIcon("audio-x-generic"); mediaItem.fields["audioType"] = "Audio Clip"; } if ((duration > 0) && (mediaItem.fields["duration"].toInt() <= 0)) { mediaItem.duration = Utilities::durationString(duration); mediaItem.fields["duration"] = duration; } else if (duration == -1) { mediaItem.duration = QString(); mediaItem.fields["audioType"] = "Audio Stream"; } mediaList << mediaItem; } } } } m_mediaListProperties.summary = i18np("1 item", "%1 items", mediaList.count()); emit results(m_requestSignature, mediaList, m_mediaListProperties, true, m_subRequestSignature); //Get more detailed mediaItem info for (int i = 0; i < mediaList.count(); i++) { if (m_stop) { return; } MediaItem detailedMediaItem = Utilities::mediaItemFromUrl(KUrl(mediaList.at(i).url)); emit updateMediaItem(detailedMediaItem); } //Check if MediaItems in mediaList exist QList<MediaItem> mediaItems = Utilities::mediaItemsDontExist(mediaList); if (mediaItems.count() > 0) { emit updateMediaItems(mediaItems); } m_requestSignature = QString(); m_subRequestSignature = QString(); }
/************************************************************************* SAX2 Handler methods *************************************************************************/ void CHelperItemSet_xmlHandler::elementStart(const String& element, const CHelperXMLAttributes& attributes) { // handle an ItemSet element. if (element == HelperItemSetElement) { // do nothing... } // handle an item element else if(element == ItemElement) { // get name of item. String itemName(attributes.getValueAsString(ItemNameAttribute)); // get anchor for new item String itemAnchor(attributes.getValueAsString(ItemAnchorAttribute)); // get url for new item String itemUrl(attributes.getValueAsString(ItemUrlAttribute)); // url convert(MFC) if(!itemUrl.empty()) { DWORD dwServiceType; CString strServer, strObject; INTERNET_PORT nPort; String strFullURL; AfxParseURL(itemUrl.c_str(), dwServiceType, strServer, strObject, nPort); if(AFX_INET_SERVICE_UNK == dwServiceType) { //local file itemUrl = CHelperSystem::GetMe()->GetWorkDictory() + itemUrl; } else { itemUrl = itemUrl; } } // create new item CHelperItem item(itemName, itemAnchor, itemUrl); // add this item to the current parent (if any) if (!m_stack.empty()) { m_stack.push_back(m_stack.back()->AddChildItem(item)); } else { throw std::exception("HelperItemSet::xmlHandler::startElement item hiberarchy error!"); } } else { char szException[MAX_PATH]; _snprintf(szException, MAX_PATH, "HelperItemSet::xmlHandler::startElement - Unexpected data was found while parsing the Imageset file: '%s' is unknown.", element.c_str()); throw std::exception(szException); } }
QUrl ThumbnailModel::imageUrl(const QModelIndex &index) const { return itemUrl(index); }