コード例 #1
0
void
CDownloadFileManager::start_download() {
  if (m_network_reply != NULL) return;
  m_network_reply = CRestWorker::Instance()->download_gorjun_file(m_file_id);
  connect(m_network_reply, SIGNAL(downloadProgress(qint64,qint64)),
          this, SLOT(download_progress(qint64,qint64)));
  connect(m_network_reply, SIGNAL(readyRead()),
          this, SLOT(network_reply_ready_read()));
  connect(m_network_reply, SIGNAL(finished()),
          this, SLOT(reply_finished()));
}
コード例 #2
0
/* outgoingData is always 0 for Get and Head requests */
QNetworkReply*
network_manager::createRequest(Operation op, const QNetworkRequest& req, QIODevice* outgoingData)
{
  DBG_PRINTF(5, "createRequest for %s", req.url().toString().toLocal8Bit().constData());
  if (op!=GetOperation) {
    // only GET is currently supported, see if HEAD should be
    return empty_network_reply(op, req);
  }
  const QUrl& url = req.url();
  // the request refers to attached contents
  if (req.url().scheme() == "cid") {
    // refers to a MIME part that should be attached
    if (m_pmsg) {
      attachment* a = m_pmsg->attachments().get_by_content_id(req.url().path());
      if (a!=NULL) {
	attachment_network_reply* reply = a->network_reply(req, this);
	connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
		this, SLOT(download_error(QNetworkReply::NetworkError)));
	connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
		this, SLOT(download_progress(qint64,qint64)));
	connect(reply, SIGNAL(finished()), this, SLOT(download_finished()));
	return reply;
      }
      
    }
    return empty_network_reply(op, req);
  }
  else if (url.scheme()=="manitou" && (url.authority()=="xface" || url.authority()=="face")) {
    if (url.hasQueryItem("id") && url.hasQueryItem("o")) {
      QString headers = m_pmsg->get_headers();
      bool id_ok, o_ok;
      uint id = url.queryItemValue("id").toUInt(&id_ok);
      int offset = url.queryItemValue("o").toInt(&o_ok);
      if (id_ok && o_ok && id == m_pmsg->get_id()) {
	int lf_pos = headers.indexOf('\n', offset);
	QString ascii_line;
	if (lf_pos>0) {
	  ascii_line = headers.mid(offset, lf_pos-offset);
	}
	else {
	  ascii_line = headers.mid(offset);
	}
	ascii_line.replace(" ", "");
	int type = url.authority()=="face" ? 1:2;
	return new internal_img_network_reply(req, ascii_line, type, this);
      }
    }
    return empty_network_reply(op, req);
  }
  else if (req.url().scheme()=="style") { // internal scheme for styling contents
    return new internal_style_network_reply(req, m_body_style, this);
  }
  // the request refers to external contents
  if (m_ext_download_permitted) {
    //        qDebug() << "op accepted for " << req.url().toString();
    return QNetworkAccessManager::createRequest(op, req, outgoingData);
  }
  else {
    if (!m_ext_download_permission_asked) {
      // let know that contents were skipped so that the user can be
      // presented with the choice to fetch them or not
      emit external_contents_requested();
      m_ext_download_permission_asked=true;
    }
    return empty_network_reply(op, req);
  }
}