Example #1
0
QStringList getSectionEnums(QString &section)
{
    QStringList result;
    QRegularExpressionMatchIterator currMatchIter = BL_ENUMERATED.globalMatch(section);

    while (currMatchIter.hasNext() )
    {
        result.append(currMatchIter.next().captured(1).remove(QRegularExpression("\\s") ).split(",") );

        #ifdef DEBUG
            qDebug() << "\n~~~~~~\n";
        #endif

        int resIter;
        for (resIter = 0; resIter < result.size()-1; ++resIter)
        {
            section.remove(result.at(resIter) );

            #ifdef DEBUG
                qDebug() << result.at(resIter).toLatin1().constData() << "\n";
            #endif
        }

        #ifdef DEBUG
            qDebug() << result.last().toLatin1().constData() << "\n";
        #endif
    }

    return result;
}   /* getSectionEnums */
Example #2
0
void WebUploader::GetArenaCards(QString &html)
{
    //Ejemplo html
    //<li><a href='#deck' data-toggle='tab'>Cards: List & Info</a></li>

    if(html.contains("<li><a href='#deck' data-toggle='tab'>Cards: List & Info</a></li>"))
    {
        deckInWeb = true;
        emit newWebDeckCardList();
        qDebug() << "WebUploader: "<< "Inicio leer deck.";

        //Ejemplo html carta
        //<li id='374' class='list-group-item' data-name='1' data-cost='3' data-total='1' data-remaining='1' data-any='1'>
        //<span style='display: inline-block;'>(3) <a href='http://www.hearthpwn.com/cards/428' onClick='return false;'>Acolyte of Pain</a>
        //</span> (<span id='remaining-374' style='font-weight:bold;'>1</span> copy)</li>
        QRegularExpression re(
            "<li id='\\d+' class='list-group-item' data-name='\\d+' data-cost='\\d+' data-total='(\\d+)' data-remaining='\\d+' data-any='\\d+'>"
            "<span style='display: inline-block;'>.*<a href=.*onClick=.*>(.+)</a> "
            "</span>.*</li>");
        QRegularExpressionMatchIterator reIterator = re.globalMatch(html);

        while (reIterator.hasNext())
        {
            QRegularExpressionMatch match = reIterator.next();
            emit newDeckCard(codeFromName(match.captured(2)), match.captured(1).toInt());
        }
        qDebug() << "WebUploader: "<< "Final leer deck.";
        emit sendLog(tr("Web: Active deck read."));
    }
}
Example #3
0
void IccClient::on_receiveText(const QString &data)
{
    emit onData(data);
    //Examples below:
    //(32 CHENNAIBOND {IM} 1 {wanted to play Rxd8})aics%
    //(32 knightrunner {} 1 {Sir H!})

    //use a raw string literal so we dont have to double escape for the regex
    //QString regex = R"x(\((\d+) (.+)\)|([^]+))x";
    QString regex = "\\((\\d+) (.+?)\\)|([^]+)";
    qDebug() << regex;

    QRegularExpression rx(regex);
    QRegularExpressionMatchIterator i  = rx.globalMatch(data);

    while (i.hasNext()) {
        QRegularExpressionMatch match = i.next();
        if (!match.captured(1).isEmpty())
        {
            parseDatagram(match.captured(1).toInt(), match.captured(0));
            emit onDatagram(match.captured(1).toInt(), match.captured(0));
        }else{ //matched 3
            emit onNonDatagram(match.captured(3));
        }
    }
}
Example #4
0
QStringList getLocalDefs(QString block, ConstRegExp REG_OUTER, const uint outerCapGroup,
                         ConstRegExp REG_INNER, const uint innerCapGroup,
                         ConstRegExp REMOVE_REG)
{
    QStringList result;
    QString params, currParam;

    #ifdef DEBUG
        qDebug() << "\n~~~~~~\n";
    #endif

    QRegularExpressionMatchIterator currMatchIter = REG_OUTER.globalMatch(block);
    if (!currMatchIter.hasNext() )
        return result;       // empty result if not found

    params = currMatchIter.next().captured(outerCapGroup);

    currMatchIter = REG_INNER.globalMatch(params);
    while (currMatchIter.hasNext() )
    {
        currParam = currMatchIter.next().captured(innerCapGroup).remove(REMOVE_REG).remove(WHITE_SPACES);

        if (!currParam.isEmpty() )
            result.append(currParam.split(",") );
    }

    #ifdef DEBUG
        for (int resIter = 0; resIter < result.size(); ++resIter)
            qDebug() << result.at(resIter).toLatin1().constData() << "\n";
    #endif

    return result;
}   /* getLocalDefs */
Example #5
0
QStringList getLocalDefs(QString block, ConstRegExp OUTER_REG, const uint outerCapGroup,
                         ConstRegExp INNER_REG, const uint innerCapGroup,
                         ConstRegExp REMOVE_REG = ConstRegExp() )
{
    QStringList result;
    QString params, currParam;

    QRegularExpressionMatchIterator currMatchIter = OUTER_REG.globalMatch(block);
    while (currMatchIter.hasNext() )
    {
        params = currMatchIter.next().captured(outerCapGroup);

        QRegularExpressionMatchIterator currPartIter = INNER_REG.globalMatch(params);
        while (currPartIter .hasNext() )
        {
            currParam = currPartIter .next().captured(innerCapGroup).remove(REMOVE_REG).remove(RX_WHITE_SPACES);

            if (!currParam.isEmpty() )
                result.append(currParam.split(",") );
        }
    }

    return result;

}   /* getLocalDefs */
Example #6
0
QString Properties::GetSummary(const QString& key, const QVariant& v) {
  QString ret;
  QMap<QString, QString>::const_iterator it = summary.find(key);
  if (it != summary.end()) {
    ret = *it;
    QRegularExpression re("(\\{.*?\\})");
    QRegularExpressionMatchIterator matches = re.globalMatch(*it);
    while (matches.hasNext()) {
      QRegularExpressionMatch m = matches.next();
      QString pattern = m.captured(0);
      QString evaluated =
          EvaluateSubExpression(pattern.mid(1, pattern.size() - 2), v);
      // if a lookup fails, then don't return anything
      if (evaluated.size() == 0) {
        ret = "";
        break;
      }
      ret.replace(pattern, evaluated);
    }
  } else if ((QMetaType::Type)v.type() == QMetaType::QVariantList) {
    ret = QString("(%1 items)").arg(v.toList().size());
  } else if ((QMetaType::Type)v.type() == QMetaType::QVariantMap) {
    ret = GetSummary("", v);
  }
  return ret;
}
Example #7
0
SteamConfig::Element::Element(QList<QString> *lines) {
  QString line;
  QRegularExpression re("\"([^\"]*)\"");
  QRegularExpressionMatchIterator i;
  while (lines->length() > 0) {
    line = lines->front();
    lines->pop_front();
    i = re.globalMatch(line);
    if (i.hasNext())
      break;
  }
  if (!lines->length())  // corrupt
    return;
  QRegularExpressionMatch match = i.next();
  name = match.captured(1).toLower();
  if (i.hasNext()) {  // value is a string
    match = i.next();
    value = match.captured(1);
    value.replace("\\\\", "\\");
  }
  line = lines->front();
  if (line.contains("{")) {
    lines->pop_front();
    while (true) {
      line = lines->front();
      if (line.contains("}")) {  // empty
        lines->pop_front();
        return;
      }
      Element e(lines);
      children[e.name] = e;
    }
  }
}
/**
 * @brief Returns a map of parsed markdown urls with their link texts as key
 *
 * @param text
 * @return parsed urls
 */
QMap<QString, QString> QMarkdownTextEdit::parseMarkdownUrlsFromText( QString text )
{
    QMap<QString, QString> urlMap;

    // match urls like this: [this url](http://mylink)
    QRegularExpression re("(\\[.*?\\]\\((.+?://.+?)\\))");
    QRegularExpressionMatchIterator i = re.globalMatch( text );
    while ( i.hasNext() )
    {
        QRegularExpressionMatch match = i.next();
        QString linkText = match.captured(1);
        QString url = match.captured(2);
        urlMap[linkText] = url;
    }

    // match urls like this: <http://mylink>
    re = QRegularExpression("(<(.+?://.+?)>)");
    i = re.globalMatch( text );
    while ( i.hasNext() )
    {
        QRegularExpressionMatch match = i.next();
        QString linkText = match.captured(1);
        QString url = match.captured(2);
        urlMap[linkText] = url;
    }

    return urlMap;
}
static void createProposal(QFutureInterface<QStringList> &future, const QString &text,
                           const QString &wordUnderCursor)
{
    const QRegularExpression wordRE("([a-zA-Z_][a-zA-Z0-9_]{2,})");

    QSet<QString> words;
    QRegularExpressionMatchIterator it = wordRE.globalMatch(text);
    int wordUnderCursorFound = 0;
    while (it.hasNext()) {
        if (future.isCanceled())
            return;
        QRegularExpressionMatch match = it.next();
        const QString &word = match.captured();
        if (word == wordUnderCursor) {
            // Only add the word under cursor if it
            // already appears elsewhere in the text
            if (++wordUnderCursorFound < 2)
                continue;
        }

        if (!words.contains(word))
            words.insert(word);
    }

    future.reportResult(words.toList());
}
Example #10
0
bool QuickFindPattern::isLineMatchingBackward(
        const QString& line, int column ) const
{
    int pos = 0;

    if ( ! active_ )
        return false;

    QRegularExpressionMatchIterator matches = regexp_.globalMatch(line);
    QRegularExpressionMatch lastMatch;
    while ( matches.hasNext() ) {
        QRegularExpressionMatch nextMatch = matches.peekNext();
        if ( column >= 0 && nextMatch.capturedEnd() >= column ) {
            break;
        }

        lastMatch = matches.next();
    }

    if ( lastMatch.hasMatch() ) {
        lastMatchStart_ = lastMatch.capturedStart();
        lastMatchEnd_ = lastMatch.capturedEnd() - 1;
        return true;
    }
    else {
        return false;
    }
}
Example #11
0
void FetchThread::process(QString phost)
{

    QUdpSocket *udpSocket ;
    udpSocket= new QUdpSocket(0);
    udpSocket->bind(QHostAddress::LocalHost, 9999);
    udpSocket->waitForConnected(250);



    QTcpSocket socket;
    socket.connectToHost("localhost", 4949);
    socket.waitForConnected(500);

    while (socket.waitForReadyRead(250));
    QString t_hello = socket.readAll();
    qDebug() << "READ: " << t_hello;

    socket.write(QString("list\n").toStdString().c_str() );
    while (socket.waitForReadyRead(250));
    QString buf1 = socket.readAll();

    qDebug() << "READ: " << buf1;
    QStringList list_probe = buf1.split(QRegExp("\\s+"));

    for (int z=0; z< list_probe.size(); z++)
    {
        QString probe=list_probe.at(z);
        QString cmd = QString("fetch ").append(probe).append("\n");
        qDebug() << "cmd : " << cmd;
        socket.write(cmd.toStdString().c_str() );


        while (socket.waitForReadyRead(250));
        QString buf2 = socket.readAll();
        qDebug() << "Rep fetch :" << buf2 << "\n";

        QRegularExpression re("(\\w+).(\\w+) ([0-9.]+)\\n");
        QRegularExpressionMatchIterator i = re.globalMatch(buf2);
        re.setPatternOptions(QRegularExpression::MultilineOption);

        while (i.hasNext()) {
            QRegularExpressionMatch match = i.next();
            QString s_metric = match.captured(1);
            QString s_value = match.captured(3);
            QString s_mtr = "monit2influxdb,metric="+probe + "_" + s_metric + ",host=" + phost+ " value=" + s_value + " " + QString::number(1000000* QDateTime::currentMSecsSinceEpoch());
            qDebug() << "metric:  " << s_mtr.toLower();

            udpSocket->writeDatagram(s_mtr.toStdString().c_str(), QHostAddress::LocalHost, 9999);




        }

        udpSocket->close();


    }
}
Example #12
0
/**
 * Builds a string list of a search string
 */
QStringList Note::buildQueryStringList(QString searchString) {
    QStringList queryStrings;

    // check for strings in ""
    QRegularExpression re("\"([^\"]+)\"");
    QRegularExpressionMatchIterator i = re.globalMatch(searchString);
    while (i.hasNext()) {
        QRegularExpressionMatch match = i.next();
        queryStrings.append(match.captured(1));
        searchString.remove(match.captured(0));
    }

    // remove a possible remaining "
    searchString.remove("\"");
    // remove multiple spaces and spaces in front and at the end
    searchString = searchString.simplified();

    // add the remaining strings
    queryStrings.append(searchString.split(" "));

    // remove empty items, so the search will not run amok
    queryStrings.removeAll("");

    // remove duplicate query items
    queryStrings.removeDuplicates();

    return queryStrings;
}
Example #13
0
// Parse file line
void BairesWindow::parseLineFields(QString fileLine, QVector<QString> &sequence) {
    QRegularExpression re("(.*?)\\s\\|");
    QRegularExpressionMatchIterator i = re.globalMatch(fileLine); 
    while (i.hasNext()) {
        QRegularExpressionMatch match = i.next();        
        sequence.push_back(match.captured(1));        
    }
}
Example #14
0
void SyntaxHighlighter::highlightBlock(const QString &text) {
  for (std::size_t i = 0; i < _keywords.size(); i++) {
    const KeywordRule &rule = _keywords.at(i);
    QRegularExpressionMatchIterator it = rule.rulePattern.globalMatch(text);
    while (it.hasNext()) {
      QRegularExpressionMatch match = it.next();
      setFormat(
          match.capturedStart(), match.capturedLength(), rule.ruleTextFormat);
    }
  }
}
Example #15
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);
}
Example #16
0
void Template::translate(ITemplateTranslationProvider &provider)
{
	//This regex captures expressions of the form
	//<?= tr("This is a test") ?> and <?= tr("optional %1 parameters %2","bla","blu") ?>
	//The first capture group is the key (untranslated string), the second the optional list of parameters
	const QRegularExpression regexp = QRegularExpression("<\\?=\\s*tr\\(\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"((?:,\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")*)\\s*\\)\\?>");
	//This one is used to extract the parameters using global matching
	const QRegularExpression paramExp = QRegularExpression(",\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"");

	int offset = 0;
	QRegularExpressionMatch match;
	do
	{
		match = regexp.match(*this,offset);

		if(match.hasMatch())
		{
			int start = match.capturedStart(0);
			int len = match.capturedLength(0);
			QString key = match.captured(1);

			//replace escaped double and single quotes
			key.replace("\\\"","\"");
			key.replace("\\'", "'");

			QString translation = provider.getTranslation(key);

			//find out if we have optional parameters
			if(match.capturedLength(2)>0)
			{
				QString params = match.captured(2);
				//extract each optional parameter
				QRegularExpressionMatchIterator it = paramExp.globalMatch(params);
				while(it.hasNext())
				{
					QRegularExpressionMatch paramMatch = it.next();
					QString param = paramMatch.captured(1);

					//replace escaped quotes
					param.replace("\\\"","\"");
					param.replace("\\'", "'");

					//apply the param
					translation = translation.arg(param);
				}
			}

			this->replace(start,len,translation);
			offset = start+translation.length();
		}
	}while(match.hasMatch());
}
bool QGCAudioWorker::_getMillisecondString(const QString& string, QString& match, int& number) {
    static QRegularExpression re("([0-9]+ms)");
    QRegularExpressionMatchIterator i = re.globalMatch(string);
    while (i.hasNext()) {
        QRegularExpressionMatch qmatch = i.next();
        if (qmatch.hasMatch()) {
            match = qmatch.captured(0);
            number = qmatch.captured(0).replace("ms", "").toInt();
            return true;
        }
    }
    return false;
}
Example #18
0
QVariant TrimmomaticPropertyWidget::value() {
    QRegularExpressionMatchIterator capturedSteps = notQuotedSpaces.globalMatch(lineEdit->text());
    QStringList steps;
    while (capturedSteps.hasNext()) {
        const QString step = capturedSteps.next().captured();
        if (!step.isEmpty()) {
            steps << step;
        }
    }
    CHECK(!steps.isEmpty(), QVariant::Invalid);

    return steps;
}
Example #19
0
QString StringUtils::htmlEncode(
    QString text, bool urlAsLinks, bool newlineAsBr) {
  QString s;
  QHash<int,int> linksIndexes; // start of link index -> length of link
  if (urlAsLinks) {
    QRegularExpressionMatchIterator it = linkRe.globalMatch(text);
    while (it.hasNext()) {
      QRegularExpressionMatch match = it.next();
      linksIndexes.insert(match.capturedStart(0), match.capturedLength(0));
    }
  }
  for (int i = 0; i < text.length(); ) {
    if (urlAsLinks && linksIndexes.contains(i)) {
      int l = linksIndexes.value(i);
      QString html = htmlEncode(text.mid(i, l), false), href = html;
      href.replace("\"", "%22");
      s.append("<a href=\"").append(href).append("\">").append(html)
          .append("</a>");
      i += l;
    } else {
      const QChar c = text.at(i);
      switch(c.toLatin1()) {
      case '<':
        s.append("&lt;");
        break;
      case '>':
        s.append("&gt;");
        break;
      case '&':
        s.append("&amp;");
        break;
      case '"':
        s.append("&#34;");
        break;
      case '\'':
        s.append("&#39;");
        break;
      case '\n':
        if (newlineAsBr)
          s.append("<br/>\n");
        else
          s.append(c);
        break;
      default:
        s.append(c);
      }
      ++i;
    }
  }
  return s;
}
Example #20
0
    foreach (OnePartRule rule, onepartrules)
    {
        QRegularExpressionMatchIterator i = rule.pattern.globalMatch(text);

        while (i.hasNext())
        {
            QRegularExpressionMatch match = i.next();
            int length = match.capturedLength();
            if (length == 0)
                continue;
            int start = match.capturedStart();
            setFormat(start, length, rule.format);
        }
    }
Example #21
0
QStringList extractBlocks(QString &source)
{
    QStringList result;
    QRegularExpressionMatchIterator currMatchIter = CO_BLOCK.globalMatch(source);

    while (currMatchIter.hasNext() )
    {
        result.append(currMatchIter.next().captured(0).trimmed() );
    }

    source.remove(CO_BLOCK);

    return result;
}   /* extractBlocks */
Example #22
0
QStringList getEnumConsts(QString &block)
{
    QStringList result;
    QString currSection;

    QRegularExpressionMatchIterator currMatchIter = BL_VAR_TYPE_SECTION.globalMatch(block);

    while (currMatchIter.hasNext() )
    {
        currSection = currMatchIter.next().captured(0);
        result.append(getSectionEnums(currSection) );
    }

    return result;
}   /* getEnumConsts */
Example #23
0
bool WebUploader::getArenaCurrentAndGames(QNetworkReply *reply, QList<GameResult> &list, bool getCards)
{
    //Ejemplo html
    //<div class='col-md-5' id='nameDate'>
    //<h1><img src='images/32icon-dru.gif' /> Druid Arena</h1>

    QString html(reply->readAll());
    if(html.contains(QRegularExpression(
        "<div.*id='nameDate'>\n<h1>.*"
        "(Druid|Hunter|Mage|Paladin|Priest|Rogue|Shaman|Warlock|Warrior)"
        " Arena</h1>"
        ), match))
    {
        arenaCurrentHero = Utility::heroToLogNumber(match->captured(1));


        //Ejemplo html
        //<div id='gameListArea'><ul class='list-group'>
        //<a name='gameList'></a><li class='list-group-item match-list'><span class='glyphicon glyphicon-remove fail matchStatus pull-left'></span> <span class='helpText matchSupLabel'>Game 2:</span><a href='#' onClick="showGame(2771882)" data-toggle='modal' data-target='#showGame'><span class='matchLabel'>vs Mage</span> </a><span class='helpText'>(<span class='glyphicon glyphicon-plus'></span> Extra card)</span><div class='pull-right'><a onClick="showGame(2771882)" data-toggle='modal' data-target='#showGame' class='btn btn-xs btn-info'><span class='glyphicon glyphicon-paperclip'></span> Game notes</a>  <a onClick="deleteGame(2771882)" href='#' class='btn btn-xs btn-danger'><span class='glyphicon glyphicon-trash'></span></a></div></li>
        //                       <li class='list-group-item match-list'><span class='glyphicon glyphicon-ok success matchStatus pull-left'></span> <span class='helpText matchSupLabel'>Game 1:</span><a href='#' onClick="showGame(2771880)" data-toggle='modal' data-target='#showGame'><span class='matchLabel'>vs Rogue</span> </a><span class='helpText'>(<span class='glyphicon glyphicon-play-circle'></span> Played first)</span><div class='pull-right'><a onClick="showGame(2771880)" data-toggle='modal' data-target='#showGame' class='btn btn-xs btn-info'><span class='glyphicon glyphicon-paperclip'></span> Game notes</a>  <a onClick="deleteGame(2771880)" href='#' class='btn btn-xs btn-danger'><span class='glyphicon glyphicon-trash'></span></a></div></li>
        //</ul>
        //</div></div>

        QRegularExpression re(
            "<li.*>.*(fail|success).*Game (\\d+).*"
            "vs (Druid|Hunter|Mage|Paladin|Priest|Rogue|Shaman|Warlock|Warrior).*"
            "(Extra card|Played first).*</li>");
        QRegularExpressionMatchIterator reIterator = re.globalMatch(html);

        while (reIterator.hasNext())
        {
            QRegularExpressionMatch match = reIterator.next();
            list.prepend(createGameResult(match, arenaCurrentHero));
        }
        qDebug() << "WebUploader: " << "Leida arena en progreso: " << QString(match->captured(1)) <<
                    " con " << QString::number(list.count()) << " juegos";

        if(getCards)
        {
            GetArenaCards(html);
        }
        return true;
    }
    else
    {
        return false;
    }
}
Example #24
0
static QString replaceInString (const QRegularExpression &rx, QString string, T func) {
	QRegularExpressionMatchIterator it = rx.globalMatch (string);
	
	int offset = 0;
	while (it.hasNext ()) {
		QRegularExpressionMatch match = it.next ();
		QString replaceWith = func (match);
		
		int length = match.capturedLength ();
		int begin = match.capturedStart () + offset;
		string.replace (begin, length, replaceWith);
		offset += replaceWith.length () - length;
	}
	
	return string;
}
Example #25
0
bool QuickFindPattern::matchLine( const QString& line,
        QList<QuickFindMatch>& matches ) const
{
    matches.clear();

    if ( active_ ) {
        QRegularExpressionMatchIterator matchIterator = regexp_.globalMatch(line);

        while( matchIterator.hasNext() ) {
            QRegularExpressionMatch match = matchIterator.next();
            matches << QuickFindMatch ( match.capturedStart(), match.capturedLength() );
        }
    }

    return ( matches.count() > 0 );
}
Example #26
0
void MainWindow::on_Fetch_clicked()
{
    emit abortFetch();
    QString text = ui->UrlList->toPlainText();
    QRegularExpression re(QString("http://.*/"));
    QRegularExpressionMatchIterator matchi = re.globalMatch(text);

    while (matchi.hasNext()) {
        QRegularExpressionMatch match = matchi.next();
        if (match.hasMatch()) {
            Website *w = new Website;
            w->fetch(match.captured(0));
            connect(w, SIGNAL(replyContent(QString, QByteArray)), this, SLOT(getContent(QString, QByteArray)));
            connect(this, SIGNAL(abortFetch()), w, SLOT(abortFetch()));

        }
    }
}
Example #27
0
QStringList QgsFileUtils::extensionsFromFilter( const QString &filter )
{
  const QRegularExpression rx( QStringLiteral( "\\*\\.([a-zA-Z0-9]+)" ) );
  QStringList extensions;
  QRegularExpressionMatchIterator matches = rx.globalMatch( filter );

  while ( matches.hasNext() )
  {
    const QRegularExpressionMatch match = matches.next();
    if ( match.hasMatch() )
    {
      QStringList newExtensions = match.capturedTexts();
      newExtensions.pop_front(); // remove whole match
      extensions.append( newExtensions );
    }
  }
  return extensions;
}
Example #28
0
void MainWindow::getContent(QString url, QByteArray data)
{
    if (!fetched) {
        fetched = 1;
        emit abortFetch();
        qDebug() << __LINE__ << url;
        //qDebug() << url << QString(data);
        QRegularExpression re(QString("(do_openvpn.aspx.*?)'"));
        QRegularExpressionMatchIterator matchi = re.globalMatch(data);
        while (matchi.hasNext()) {
            QRegularExpressionMatch match = matchi.next();
            if (match.hasMatch()) {
                vpnList.append(new Vpn(url, match.captured(1)));
            }

        }
        rankVPN();
    }

}
Example #29
0
const QMap<QString, QString> Session::Request::getAccountBadges(const QByteArray &data) {
    QRegularExpression expr("<div class=\\\"roleLabel.+?\\\"><img src=\\\"(?<url>.+?)\\\" alt=\\\"(?<name>.+?)\\\" \\/><\\/div>");
    QRegularExpressionMatchIterator iter = expr.globalMatch(data);
    QMap<QString,QString> result;
    while (iter.hasNext()) {
        QRegularExpressionMatch match = iter.next();
        if (match.isValid() && match.hasMatch()) {
            QString url = match.captured("url");
            if (url.startsWith("/")) url.prepend("https://p7p4m6s5.ssl.hwcdn.net");
            result.insert(match.captured("name"), url);
        }
    }

    //        result.insert("Exalted", "https://p7p4m6s5.ssl.hwcdn.net/image/forum/supporter-tag/open-beta/exalted.png?v=2");
    //        result.insert("Champion", "https://p7p4m6s5.ssl.hwcdn.net/image/forum/supporter-tag/release/champion.png?v=4");
    //        result.insert("Grandmaster", "https://p7p4m6s5.ssl.hwcdn.net/image/forum/supporter-tag/release2/Grandmaster.png");
    //        result.insert("Highgate", "https://p7p4m6s5.ssl.hwcdn.net/image/forum/supporter-tag/awakening/Highgate.png");
    //        result.insert("Ascendant", "https://p7p4m6s5.ssl.hwcdn.net/image/forum/supporter-tag/ascendancy/Ascendant.png");

    return result;
}
OrphanedImagesDialog::OrphanedImagesDialog(QWidget *parent) :
        MasterDialog(parent),
    ui(new Ui::OrphanedImagesDialog) {
    ui->setupUi(this);
    ui->fileTreeWidget->installEventFilter(this);

    QDir mediaDir(NoteFolder::currentMediaPath());

    if (!mediaDir.exists()) {
        ui->progressBar->setValue(ui->progressBar->maximum());
        return;
    }

    QStringList orphanedFiles = mediaDir.entryList(
            QStringList("*"), QDir::Files, QDir::Time);
    orphanedFiles.removeDuplicates();

    QList<Note> noteList = Note::fetchAll();
    int noteListCount = noteList.count();

    ui->progressBar->setMaximum(noteListCount);
    ui->progressBar->show();

    Q_FOREACH(Note note, noteList) {
            QString text = note.getNoteText();

            // match image links like ![media-qV920](file://media/608766373.gif)
            QRegularExpression re(
                    "!\\[.*?\\]\\(file:\\/\\/media/(.+?)\\)");
            QRegularExpressionMatchIterator i = re.globalMatch(text);

            // remove all found images from the orphaned files list
            while (i.hasNext()) {
                QRegularExpressionMatch match = i.next();
                QString fileName = match.captured(1);
                orphanedFiles.removeAll(fileName);
            }

            ui->progressBar->setValue(ui->progressBar->value() + 1);
        }