Example #1
0
void LinTORManager::collectItems()
{
  // Marshall the current item:
  QJson::Parser parser;
  bool ok;
  QVariantMap result = parser.parse(torItemReply->readAll(), &ok).toMap();
  torItemReply->deleteLater();
  torItemReply = 0;

  if (!ok)
  {
    qWarning() << "Failed to parse The Old Reader item contents";
    return;
  }

  // Try to pull the usable bits out of the item contents:
  QList<QVariant> itemsVariants = result["items"].toList();

  QList<QVariant>::const_iterator index = itemsVariants.constBegin();
  QList<QVariant>::const_iterator end = itemsVariants.constEnd();

  while (index != end)
  {
    QVariantMap itemMap = (*index).toMap();

    LinTORItem item;

    item.setTitle(itemMap["title"].toString());

    QList<QVariant> canonicalList = itemMap["canonical"].toList();

    // For now, just pull the first item out of the list:
    if (!canonicalList.isEmpty())
    {
      QVariantMap canonicalMap = canonicalList.first().toMap();
      item.setSourceUrl(canonicalMap["href"].toString());
    }

    QList<QVariant> enclosureList = itemMap["enclosure"].toList();

    // For now, just pull the first item out of the list:
    if (!enclosureList.isEmpty())
    {
      QVariantMap enclosureMap = enclosureList.first().toMap();

      item.setEnclosureUrl(enclosureMap["href"].toString());
      item.setEnclosureType(enclosureMap["type"].toString());
    }

    QVariantMap summaryMap = itemMap["summary"].toMap();

    item.setSummary(summaryMap["content"].toString());

    torItems[itemMap["id"].toString()] = item;

    ++index;
  }

  emit itemsReady();
}
void CalendarSelectionPage::createContent(void)
{
	createCommonContent(m_model,
			    _getCreator,
			    tr("Fetching calendar items"),
			    tr("Select calendar entry"),
			    true,
			    false);

	connect(m_list, SIGNAL(itemClicked(const QModelIndex &)),
		this, SLOT(calendarItemSelected(const QModelIndex &)));

	connect(m_model, SIGNAL(ready()), this, SLOT(itemsReady()));
	if (m_model->fetch() == true) {
		setBusy();
	} else {
		m_list->setLabel(tr("Cannot retrieve calendar entries"));
	}
}
Example #3
0
void LinTORManager::parseItemIDs()
{
  QJson::Parser parser;
  bool ok;
  QVariantMap result = parser.parse(itemIDsReply->readAll(), &ok).toMap();
  itemIDsReply->deleteLater();
  itemIDsReply = 0;

  if (!ok)
  {
    qWarning() << "Failed to parse The Old Reader id list";
    return;
  }


  QList<QVariant> itemRefsVariants = result["itemRefs"].toList();

  torItems.clear();

  if (itemRefsVariants.isEmpty())
  {
    // Return an empty list:
    emit itemsReady();
    return;
  }

  QString itemRequestString =
    "https://theoldreader.com/reader/api/0/stream/items/contents?output=json";

  QList<QVariant>::const_iterator currentID = itemRefsVariants.constBegin();
  QList<QVariant>::const_iterator endOfIDs = itemRefsVariants.constEnd();

  while (currentID != endOfIDs)
  {
    QVariantMap itemIDMap = (*currentID).toMap();
    itemRequestString += "&i=";
    itemRequestString += itemIDMap["id"].toString();
    ++currentID;
  }

  if (torItemReply)
  {
    // Stop any existing request:
    torItemReply->abort();
    torItemReply = 0;
  }

  QUrl qurl(itemRequestString);

  QNetworkRequest itemRequest(qurl);

  itemRequest.setRawHeader(
    "Authorization", authHeaderString.toAscii());

  torItemReply = qnam->get(itemRequest);

  connect(
    torItemReply,
    SIGNAL(finished()),
    this,
    SLOT(collectItems()));
}