void lua_player::run_require_slot(std::string file)
{
  try
  {
    QUrl url = player::create_url(file + ".lua", lua_path);

    activate_frame(file, url.toString ().toStdString ());

    QObject::connect(current_activation_frame (), SIGNAL(execution_finished ())
                     , this, SLOT(require_finished ()));

    assert(pending_download_file == 0);
    pending_download_file = new player::url_file(url, this);

    if(!pending_download_file->local())
    {
      QObject::connect(this, SIGNAL(download_lua_signal ()), this
                       , SLOT(download_require ()), Qt::QueuedConnection);
      QObject::connect(pending_download_file, SIGNAL(download_finished_signal()), this
                       , SLOT(download_lua()));
      QObject::connect(pending_download_file, SIGNAL(error_signal(std::string)), this
                       , SLOT(download_error(std::string)));
    }
    else
    {
      QObject::connect(this, SIGNAL(download_lua_signal ()), this
                       , SLOT(download_require ()), Qt::QueuedConnection);
      Q_EMIT download_lua_signal();
    }
  }
  catch(std::exception const& e)
  {
    std::string error = "Error loading file ";
    error += lua_path;
    error += '/';
    error += path;
    error += " with error: ";
    error += e.what();
    ncl_window->error_occurred(error);
  }
}
void lua_player::run_global_scope()
{
  QObject::disconnect(this, SIGNAL (started ()));

  luaL_openlibs(L);

  luabind::open(L);

  luabind::module(L, "ghtv")
  [
   luabind::class_<lua_player>("lua_player")
  ];

  init_sandbox();
  init_canvas();
  init_event();

  start_time = boost::posix_time::microsec_clock::universal_time();

  QObject::connect(this, SIGNAL(resume_current_frame_signal (int)), this
                   , SLOT(resume_current_frame (int)), Qt::QueuedConnection);
  QObject::connect(this, SIGNAL(run_require_signal (std::string)), this
                   , SLOT(run_require_slot (std::string)), Qt::QueuedConnection);

  try
  {
    main_file_url = player::create_url(path, root_path);
    lua_path = main_file_url.path ().toStdString ();

    {
      std::string::reverse_iterator
        iterator = std::find(lua_path.rbegin(), lua_path.rend(), '/')
        , iterator_backslash = std::find(lua_path.rbegin(), lua_path.rend(), '\\');
      iterator = (std::min)(iterator, iterator_backslash);
      if(iterator != lua_path.rend())
        lua_path.erase(boost::prior(iterator.base()), lua_path.end());
      else
      {
        std::string error_msg = "Couldn't create a absolute path from the path for the NCL file: ";
        error_msg += lua_path;
        ncl_window->error_occurred(error_msg);
        return;
      }
    }

    activate_frame(path, main_file_url.toString ().toStdString ());

    QObject::connect(current_activation_frame (), SIGNAL(execution_finished ())
                     , this, SLOT(global_scope_finished ()));
    QObject::connect(this, SIGNAL(signal_all_execution_finished ())
                     , this, SLOT(try_unqueue_events ()), Qt::QueuedConnection);
    QObject::connect(this, SIGNAL(signal_try_unqueue_event ())
                     , this, SLOT(try_unqueue_event ()), Qt::QueuedConnection);

    assert(pending_download_file == 0);
    pending_download_file = new player::url_file(main_file_url, this);
    if(!pending_download_file->local())
    {
      QObject::connect(this, SIGNAL(download_lua_signal ()), this
                       , SLOT(download_global ()), Qt::QueuedConnection);
      QObject::connect(pending_download_file, SIGNAL(download_finished_signal()), this
                       , SLOT(download_lua()));
      QObject::connect(pending_download_file, SIGNAL(error_signal(std::string)), this
                       , SLOT(download_error(std::string)));
    }
    else
    {
      QObject::connect(this, SIGNAL(download_lua_signal ()), this
                       , SLOT(download_global ()), Qt::QueuedConnection);
      Q_EMIT download_lua_signal();
    }
  }
  catch(std::exception const& e)
  {
    std::string error = "Error loading file ";
    error += root_path;
    error += '/';
    error += path;
    error += " with error: ";
    error += e.what();
    ncl_window->error_occurred(error);
  }
}
Exemplo n.º 3
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);
  }
}