void AdBlockSubscription::subscriptionDownloaded() {
  if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
    return;
  }

  bool error = false;
  const QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8();

  if (m_reply->error() != QNetworkReply::NoError || !response.startsWith(QByteArray("[Adblock")) || !saveDownloadedData(response)) {
    error = true;
  }

  m_reply->manager()->deleteLater();
  m_reply->deleteLater();
  m_reply = 0;

  if (error) {
    emit subscriptionError(tr("Cannot load subscription!"));

    return;
  }

  loadSubscription(AdBlockManager::instance()->disabledRules());
  emit subscriptionUpdated();
  emit subscriptionChanged();
}
Beispiel #2
0
AdBlockTreeWidget::AdBlockTreeWidget(AdBlockSubscription* subscription, QWidget* parent)
    : TreeWidget(parent)
    , m_subscription(subscription)
    , m_topItem(0)
    , m_itemChangingBlock(false)
{
    setContextMenuPolicy(Qt::CustomContextMenu);
    setDefaultItemShowMode(TreeWidget::ItemsExpanded);
    setHeaderHidden(true);
    setAlternatingRowColors(true);
    setLayoutDirection(Qt::LeftToRight);

    connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
    connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*)));
    connect(m_subscription, SIGNAL(subscriptionUpdated()), this, SLOT(subscriptionUpdated()));
    connect(m_subscription, SIGNAL(subscriptionError(QString)), this, SLOT(subscriptionError(QString)));
}