Exemplo n.º 1
0
inline bool isNetWorkPath(QString strUrl)
{
	QUrl qUrl(strUrl);
	if (qUrl.isValid())
	{
		if (1 != strUrl.indexOf(':'))
			if (0 == strUrl.indexOf(QString("http://")) || 0 == strUrl.indexOf(QString("https://")))
				return true;
	}
	return false;
}
Exemplo n.º 2
0
IAdaptable* HelpEditorInputFactory::CreateElement(const SmartPointer<IMemento>& memento)
{
    QString url;
    if (!memento->GetString(TAG_PATH, url))
    {
        return nullptr;
    }

    QUrl qUrl(url);
    if (qUrl.isValid())
    {
        return new HelpEditorInput(qUrl);
    }
    return nullptr;
}
Exemplo n.º 3
0
void ChatView::checkWord(QTextCursor &cursor, QString &message)
{
    // extract the first word
    QString rest;
    QString fullWordUpToSpaceOrEnd = extractNextWord(message, rest);

    // check urls
    if (fullWordUpToSpaceOrEnd.startsWith("http://", Qt::CaseInsensitive) ||
        fullWordUpToSpaceOrEnd.startsWith("https://", Qt::CaseInsensitive) ||
        fullWordUpToSpaceOrEnd.startsWith("www.", Qt::CaseInsensitive))
    {
        QUrl qUrl(fullWordUpToSpaceOrEnd);
        if (qUrl.isValid())
        {
            appendUrlTag(cursor, fullWordUpToSpaceOrEnd);
            cursor.insertText(rest, defaultFormat);
            return;
        }
    }

    // check word mentions
    foreach (QString word, highlightedWords)
    {
        if (fullWordUpToSpaceOrEnd.compare(word, Qt::CaseInsensitive) == 0)
        {
            // You have received a valid mention of custom word!!
            highlightFormat.setBackground(QBrush(getCustomHighlightColor()));
            highlightFormat.setForeground(settingsCache->getChatHighlightForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
            cursor.insertText(fullWordUpToSpaceOrEnd, highlightFormat);
            cursor.insertText(rest, defaultFormat);
            QApplication::alert(this);
            return;
        }
    }

    // not a special word; just print it
    cursor.insertText(fullWordUpToSpaceOrEnd + rest, defaultFormat);
}
Exemplo n.º 4
0
  void CHttpThread::sendHttp(const CProtocol& protocol)
  {
    //LOG_PROTOCOL(protocol);
    QByteArray postData;
    // konwertuj protokol do postaci binarnej tablicy QByteArray
    if (!convertToBinary(postData, protocol)){
      // nieprawidlowy format protokolu
      LOG_ERROR("Sending protocol error. idPackage:", protocol.getIdPackage());
      DConnectionResult res(new CConnectionResult(protocol, EConnectionStatus::OUTPUT_PROTOCOL_FORMAT_ERROR));
      resultsQueue.push(res);
    }
    else
    {
      //convertToProtocolDebug(postData);

      uint16_t crc = NUtil::CCryptography::crc16(postData.constData(), postData.size());
      postData.replace(postData.size() - sizeof(crc), sizeof(crc), reinterpret_cast<char*>(&crc), sizeof(crc));

      // tworzy tymczasowa petle komunikatow
      QEventLoop eventLoop;

      // dla sygnalu QNetworkAccessManager::finished wywolaj QEventLoop::quit
      QNetworkAccessManager mgr;
      QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));

      // HTTP
      const std::string url = NEngine::CConfigurationFactory::getInstance()->getServerUrl();
      QUrl qUrl(url.c_str());
      QNetworkRequest req(qUrl);
      // typ MIME
      req.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
      // wyslij post'a
      std::shared_ptr<QNetworkReply> reply(mgr.post(req, postData));
      eventLoop.exec(); // czekaj QEventLoop::quit (czyli QNetworkAccessManager::finished)

      if (reply->error() == QNetworkReply::NoError) {
        //success
        LOG_DEBUG("Protocol has been sent successfully. idPackage:", protocol.getIdPackage());

        CByteWrapper wrapper(reply->readAll());
        // wyslanie potwierdzenia zmiany konfiguracji - jesli zmiana odbyla sie bez problemow nie zwraca danych
        if (wrapper.getSize() > 0)
        {
          if (!wrapper.isCRCValid())
          {
            LOG_ERROR("Received protocol error - CRC. idPackage:", protocol.getIdPackage());
            DConnectionResult res(new CConnectionResult(protocol, EConnectionStatus::CRC_ERROR));
            resultsQueue.push(res);

          }
          else
          {

            std::shared_ptr<CProtocol> responseProtocol =
                convertToProtocol(wrapper);
            // przekonwertuj do struktury
            if (!responseProtocol)
            {
              // blad struktury protokolu
              LOG_ERROR("Received protocol error. idPackage:", protocol.getIdPackage());
              DConnectionResult res(new CConnectionResult(protocol, EConnectionStatus::INPUT_PROTOCOL_FORMAT_ERROR));
              resultsQueue.push(res);
            }
            else
            {
              LOG_DEBUG("Protocol has been received successfully. idPackage:", responseProtocol->getIdPackage());
              DConnectionResult res(new CConnectionResult(protocol, responseProtocol, EConnectionStatus::NONE));
              resultsQueue.push(res);
            }
          }
        }

      }
      else {

        LOG_ERROR("Protocol sending error. idPackage:",
                  protocol.getIdPackage(), ". Error: ", reply->errorString().toStdString());
        DConnectionResult res(new CConnectionResult(protocol, EConnectionStatus::CONNECTION_ERROR));
        resultsQueue.push(res);
      }
    }
  }