Exemplo n.º 1
0
void BaiduMusic::searchReplyFinished()
{

    QString url = searchReply->request().url().toString();

    int keywordBegin = url.indexOf("key=") + 4;
    int keywordEnd = url.indexOf("&start=");

    int pageBeginPos = url.indexOf("start=") + 6;
    int pageEndPos = url.indexOf("&size=");

    //当前页
    int currentPage = url.mid(pageBeginPos,pageEndPos-pageBeginPos).toInt()/PAGESIZE + 1;

    //关键字
    QString keyword = url.mid(keywordBegin,keywordEnd-keywordBegin);
    if(searchReply->error()){
		
		//如果出错,pageCount为-1;
        emit searchComplete(currentPage,1,keyword,"{error:"+searchReply->errorString()+"}");
        return;
    }

    //TODO:未搜索到内容的判断

    QString html = searchReply->readAll();
    QStringList songList;
    QRegularExpression re("<li data-songitem = '(.+?)'");
    QRegularExpressionMatchIterator i = re.globalMatch(html);

    while (i.hasNext()) {
        QRegularExpressionMatch match = i.next();
        QString songData = match.captured(1);
        //&quot; 替换为 " ;删除<em>和</em>
        songData = songData.replace("&quot;","\"").replace("&lt;em&gt;","").replace("&lt;\\/em&gt;","");
        songList << songData;
    }

    //构造json数组
    QString songArray = "[" + songList.join(",") + "]";
    QString result = unifyResult(songArray);
    //匹配总页数
    QRegularExpression pageCountRe("\">(\\d+)</a>\\s*<a class=\"page-navigator-next\"");
    QRegularExpressionMatch match = pageCountRe.match(html);

    //页面总数
    int pageCount = match.captured(1).toInt();

    //如果没有 pageCount,则 pageCount 设为 1;
    pageCount = pageCount>0 ? pageCount : 1;

    emit searchComplete(currentPage,pageCount,keyword,result);
}
Exemplo n.º 2
0
void GameUI::searchStart(void)
{
    MythGenericTree *parent = m_gameUITree->GetCurrentNode()->getParent();

    if (parent != NULL)
    {
        QStringList childList;
        QList<MythGenericTree*>::iterator it;
        QList<MythGenericTree*> *children = parent->getAllChildren();

        for (it = children->begin(); it != children->end(); ++it)
        {
            MythGenericTree *child = *it;
            childList << child->GetText();
        }

        MythScreenStack *popupStack =
            GetMythMainWindow()->GetStack("popup stack");
        MythUISearchDialog *searchDialog = new MythUISearchDialog(popupStack,
            tr("Game Search"), childList, true, "");

        if (searchDialog->Create())
        {
            connect(searchDialog, SIGNAL(haveResult(QString)),
                    SLOT(searchComplete(QString)));

            popupStack->AddScreen(searchDialog);
        }
        else
            delete searchDialog;
    }
}
Exemplo n.º 3
0
void KNMusicTreeViewBase::searchText(QString text)
{
    //Backup the search text.
    m_seachText=text;
    //Set to proxy model's filter.
    if(m_proxyModel!=nullptr)
    {
        //Do search.
        m_proxyModel->setFilterFixedString(m_seachText);
        if(currentIndex().isValid())
        {
            scrollTo(model()->index(currentIndex().row(),
                                    0),
                     QAbstractItemView::PositionAtCenter);
        }
        //Emit search signal.
        emit searchComplete();
    }
}
Exemplo n.º 4
0
void SpotWorker::emitSearchCompleteSignal(sp_search *search)
{
    emit searchComplete(search);
}