예제 #1
0
/*!
  \brief Determines if something has changed.

  We do that by comparing every value against what is stored in the storage.

  \return \arg \c true  Yes, something has changed.
          \arg \c false No, nothing changed.
*/
bool
Settings::changed() const
{
  if( apiKey() != Storage::loadString( QL( "apiKey" ) ) )
    return true;

  if( useSystemProxy() != Storage::loadBool( QL( "useSystemProxy" ) ) )
    return true;

  if( useSystemProxy() )
    return false;

  if( proxyHost() != Storage::loadString( QL( "proxyHost" ) ) )
    return true;

  if( proxyPort() != Storage::loadUShort( QL( "proxyPort" ) ) )
    return true;

  if( proxyLogin() != Storage::loadString( QL( "proxyLogin" ) ) )
    return true;

  if( proxyPassword() != Storage::loadString( QL( "proxyPassword" ) ) )
    return true;

  return false;
}
예제 #2
0
void ApiInfo::createInstance()
      {
      if (_instance)
            return;

      QFile f(apiInfoLocation());
      QByteArray clientId;
      if (f.open(QIODevice::ReadOnly)) {
            const QByteArray saveData = f.readAll();
            const QJsonDocument d(QJsonDocument::fromBinaryData(saveData));
            QJsonObject saveObject = d.object();
            clientId = saveObject["clientId"].toString().toLatin1();
            f.close();
            }
      else {
            clientId = genClientId();
            // Save the generated ID
            if (f.open(QIODevice::WriteOnly)) {
                  QJsonObject saveObject;
                  saveObject["clientId"] = QString(clientId);
                  QJsonDocument saveDoc(saveObject);
                  f.write(saveDoc.toBinaryData());
                  f.close();
                  }
            }

      QByteArray apiKey("0b19809bab331d70fb9983a0b9866290");
      _instance = new ApiInfo(clientId, apiKey);
      }
예제 #3
0
void Connection::save(QVariantMap& m) const
{
    m["title"] = title();
    m["apiUrl"] = apiUrl();
    m["userEmail"] = userEmail();
    m["apiKey"] = apiKey();
}
예제 #4
0
void Pastebin::submitPaste(const QString& pasteContent, const QString& pasteTitle, const QString& format, const QString& expiration, const PasteListing::Visibility visibility) {
    qDebug() << "submitPaste()";

    QNetworkRequest request(buildUrl("http://pastebin.com/api/api_post.php"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, URLENCODED_CONTENT_TYPE);

    QUrl params;
    params.addQueryItem("api_dev_key", PASTEBIN_DEV_KEY);
    params.addQueryItem("api_user_key", apiKey());
    params.addQueryItem("api_option", "paste");
    params.addQueryItem("api_paste_code", pasteContent);
    params.addQueryItem("api_paste_private", QString("%1").arg(static_cast<int>(visibility)));
    if(!pasteTitle.isEmpty()) {
        params.addQueryItem("api_paste_name", pasteTitle);
    }
    if(!expiration.isEmpty()) {
        params.addQueryItem("api_paste_expire_date", expiration);
    }
    if(!format.isEmpty()) {
        params.addQueryItem("api_paste_format", format);
    }

    QNetworkReply *reply = accessManager_.post(request, params.encodedQuery());
    connect(reply, SIGNAL(finished()), this, SLOT(onSubmitPasteFinished()));
}
예제 #5
0
void Pastebin::requestHistory() {
    QNetworkRequest request(buildUrl("http://pastebin.com/api/api_post.php"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, URLENCODED_CONTENT_TYPE);

    QUrl params;
    params.addQueryItem("api_dev_key", PASTEBIN_DEV_KEY);
    params.addQueryItem("api_user_key", apiKey());
    params.addQueryItem("api_option", "list");

    QNetworkReply *reply = accessManager_.post(request, params.encodedQuery());
    connect(reply, SIGNAL(finished()), this, SLOT(onHistoryFinished()));
}
예제 #6
0
//! ----  slot_parse_fanart_info ------------------------------------------------
void CHTBackdrops::parseInfo(QByteArray bytes)
{
  CLog::log(LOG_INFO, "PROVIDER", "Parsing info", "HTBackDrops");

  /*-------------------------------------------------*/
  /* Get id from sender reply                        */
  /* ------------------------------------------------*/
  QObject* reply = qobject_cast<QObject*>(sender());

  if (!reply || !_listRequests.contains(reply))   return;
  const int id = _listRequests.take(reply);

  /*-------------------------------------------------*/
  /* Parse info                                      */
  /* ------------------------------------------------*/
  QXmlStreamReader xml(bytes);
  bool imageFound = false;

  //! Xml reading loop
  while(!xml.atEnd() && !xml.hasError())
  {
    QXmlStreamReader::TokenType token = xml.readNext();
    //! search Xml start element

    if(token == QXmlStreamReader::StartElement)
    {
      //! search Xml Image element (size = medium, large, extralarge)
      if(xml.name() == "id")
      {
        //! we have to check if image is already stored
        bool imageAlreadyPresent = false;

        // Laureon: Removed image existance check this isn`t supposed to be here...
        // image has to be stored
        if (!imageAlreadyPresent) {
          QString imageUrl = xml.readElementText();
          if (!imageUrl.isEmpty())
          {
            QUrl url = "http://htbackdrops.org/api/"+apiKey()+"/download/"+imageUrl.toUtf8()+"/fullsize";
            QObject *reply = CNetworkAccess::instance()->get(url);
            _listRequests[reply] = id;

            connect(reply, SIGNAL(data(QByteArray)), this, SLOT(receivedInfo(QByteArray)));
            connect(reply, SIGNAL(error(QNetworkReply*)), this, SLOT(stopSearch()));
            imageFound = true;
            break;
          }
        }
      } // end Xml image element
/* ============================================================================
 *  PUBLIC Slots
 */
void THGoogleDetectLanguage::detectLanguage (const QString& query) {
    if (!query.isEmpty())
        d->query = query;

    QUrl url("http://ajax.googleapis.com/ajax/services/language/detect");
    url.addQueryItem("q", query);
    url.addQueryItem("v", "1.0");

    if (hasHostLanguage())
        url.addQueryItem("hl", hostLanguage());

    if (hasApiKey())
        url.addQueryItem("key", apiKey());

    get(url);
}
/* ============================================================================
 *  PUBLIC Slots
 */
void THGoogleTranslator::translate (const QString& query) {
    if (!query.isEmpty())
        d->query = query;

    QUrl url("http://ajax.googleapis.com/ajax/services/language/translate");
    url.addQueryItem("q", query);
    url.addQueryItem("v", "1.0");
    url.addQueryItem("langpair", d->srcLang + '|' + d->dstLang);

    if (hasHostLanguage())
        url.addQueryItem("hl", hostLanguage());

    if (hasApiKey())
        url.addQueryItem("key", apiKey());

    get(url);
}
예제 #9
0
void Pastebin::requestDeletePaste(const QString& pasteKey)
{
    qDebug().nospace() << "requestDeletePaste(" << pasteKey << ")";

    QNetworkRequest request(buildUrl("http://pastebin.com/api/api_post.php"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, URLENCODED_CONTENT_TYPE);
    request.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User + 1), pasteKey);

    QUrl params;
    params.addQueryItem("api_dev_key", PASTEBIN_DEV_KEY);
    params.addQueryItem("api_user_key", apiKey());
    params.addQueryItem("api_paste_key", pasteKey);
    params.addQueryItem("api_option", "delete");

    QNetworkReply *reply = accessManager_.post(request, params.encodedQuery());
    connect(reply, SIGNAL(finished()), this, SLOT(onDeletePasteFinished()));
}
예제 #10
0
//! ----  slot_send_fanart_info_request -----------------------------------------
void CPlexusArtist::requestInfo(int id)
{
  //REMOVE ACENTOS E CARACTERES ESPECIAIS
  QString artistName = artist();
  artistName = artistName.normalized(QString::NormalizationForm_D);
  artistName = artistName.replace(QRegExp("[^a-zA-Z0-9\\s]"), "");
  //FIM REMOVE ACENTOS E CARACTERES ESPECIAIS

  CLog::log(LOG_INFO, "PROVIDER", "Requesting info for: '"+artistName+"'", "PlexusArtist");

  QUrlQuery url("http://plexusdynamics.com/admin/api/getartist.php?");
  url.addQueryItem("key", apiKey());
  url.addQueryItem("artist", artistName);

  QObject *reply = CNetworkAccess::instance()->get(url.query());
  _listRequests[reply] = id;

  CLog::log(LOG_DEBUG, "PROVIDER", "Connecting Signals", "PlexusArtist");
  connect(reply, SIGNAL(data(QByteArray)), this, SLOT(parseInfo(QByteArray)));
  connect(reply, SIGNAL(error(QNetworkReply*)), this, SLOT(stopSearch()));
}
예제 #11
0
//! ----  slot_send_fanart_info_request -----------------------------------------
void CHTBackdrops::requestInfo(int id)
{
  //REMOVE ACENTOS E CARACTERES ESPECIAIS
  QString artistName = artist();
  artistName = artistName.normalized(QString::NormalizationForm_D);
  artistName = artistName.replace(QRegExp("[^a-zA-Z0-9\\s]"), "");
  //FIM REMOVE ACENTOS E CARACTERES ESPECIAIS

  CLog::log(LOG_INFO, "PROVIDER", "Requesting info for: '"+artistName+"'", "HTBackDrops");

  QUrlQuery url("http://htbackdrops.org/api/"+apiKey()+"/searchXML/?");
  url.addQueryItem("default_operator", "and");
  url.addQueryItem("keywords", artistName);

  QObject *reply = CNetworkAccess::instance()->get(url.query());
  _listRequests[reply] = id;

  CLog::log(LOG_DEBUG, "PROVIDER", "Connecting Signals", "HTBackDrops");
  connect(reply, SIGNAL(data(QByteArray)), this, SLOT(parseInfo(QByteArray)));
  connect(reply, SIGNAL(error(QNetworkReply*)), this, SLOT(stopSearch()));
}
예제 #12
0
///
/// Returns a copy of the settings with a new API key.
///
Settings Settings::withApiKey(const std::string &apiKey) const {
	auto copy = *this;
	copy.apiKey(apiKey);
	return copy;
}
예제 #13
0
void Connection::updateValidFlag()
{
    setValid(!apiUrl().isEmpty() && !apiKey().isEmpty());
}
예제 #14
0
void Pastebin::onUserDetailsFinished() {
    QNetworkReply *networkReply = qobject_cast<QNetworkReply *>(sender());
    QVariant statusCode = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    qDebug() << "User details request complete:" << statusCode.toInt();

    if(networkReply->error() == QNetworkReply::NoError) {
        const QString response = networkReply->readAll();

        if(response.startsWith("Bad API request")) {
            qWarning() << "Error fetching user details:" << response;
            emit userDetailsError(response);
        }
        else {
            QXmlStreamReader reader;
            reader.addData("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
            reader.addData("<response>");
            reader.addData(response);
            reader.addData("</response>");

            bool success = false;

            PasteUserData pasteUser;
            while(!reader.atEnd()) {
                QXmlStreamReader::TokenType token = reader.readNext();
                if(token == QXmlStreamReader::StartDocument) {
                    qDebug() << "StartDocument";
                    continue;
                }
                else if(token == QXmlStreamReader::StartElement) {
                    if(reader.name() == "user") {
                        parseUserDetails(reader, &pasteUser);
                        success = true;
                    }
                }
                else if(token == QXmlStreamReader::EndDocument) {
                    qDebug() << "EndDocument";
                    continue;
                }
            }

            qDebug() << "Parsed user details";

            if(!success || reader.hasError()) {
                qWarning() << "Parse error:" << reader.errorString();
                emit userDetailsError(QString::null);
            } else {
                AppSettings *appSettings = AppSettings::instance();
                appSettings->setUsername(pasteUser.username);
                appSettings->setAvatarUrl(pasteUser.avatarUrl);
                appSettings->setWebsite(pasteUser.website);
                appSettings->setEmail(pasteUser.email);
                appSettings->setLocation(pasteUser.location);
                appSettings->setAccountType(pasteUser.accountType);
                appSettings->setPasteFormatShort(pasteUser.pasteFormatShort);
                appSettings->setPasteExpiration(pasteUser.pasteExpiration);
                appSettings->setPasteVisibility(pasteUser.pasteVisibility);
                appSettings->setApiKey(apiKey());
                emit userDetailsUpdated();

                requestUserAvatar();
            }
        }
    }
    else {
        qWarning() << "Error in user details response:" << networkReply->errorString();
        emit userDetailsError(QString::null);
    }
}