Exemplo n.º 1
0
void Application::path_changed_handler_() {
    dbo::Transaction t(session());
    std::string section = internalPathNextPart("/");
    if (section == "fact") {
        std::string fact_str = internalPathNextPart("/fact/");
        if (fact_str == "random") {
            facts_->set_random_fact();
        } else if (fact_str == "prev") {
            facts_->set_prev_fact();
        } else if (fact_str == "next") {
            facts_->set_next_fact();
        } else {
            try {
                int fact_id = boost::lexical_cast<int>(fact_str);
                FactPtr fact = session().load<Fact>(fact_id);
                facts_->set_fact(fact);
            } catch (...)
            { }
        }
    }
    if (section == "admin") {
        facts_->try_admin_enter();
    }
    t.commit();
}
Exemplo n.º 2
0
int Application::comment_index(const FactPtr& fact) const {
    std::string comment_base = fact_path(fact) + "comment/";
    if (!internalPathMatches(comment_base)) {
        return -1;
    }
    try {
        std::string comment_str = internalPathNextPart(comment_base);
        return boost::lexical_cast<int>(comment_str);
    } catch (...) {
        return -1;
    }
}
Exemplo n.º 3
0
Arquivo: Home.C Projeto: GuLinux/wt
void Home::setLanguageFromPath()
{
  std::string langPath = internalPathNextPart("/");

  if (langPath.empty())
    langPath = '/';
  else
    langPath = '/' + langPath + '/';

  int newLanguage = 0;

  for (unsigned i = 0; i < languages.size(); ++i) {
    if (languages[i].path_ == langPath) {
      newLanguage = i;
      break;
    }
  }

  if (newLanguage != language_)
    setLanguage(newLanguage);
}
Exemplo n.º 4
0
Arquivo: Home.C Projeto: GuLinux/wt
void Home::setup()
{
  /*
   * This function switches between the two major components of the homepage,
   * depending on the internal path:
   * /src -> source viewer
   * /... -> homepage
   *
   * FIXME: we should take into account language /cn/src ...
   */
  std::string base = internalPathNextPart("/");

  if (base == SRC_INTERNAL_PATH) {
    if (!sourceViewer_) {
      delete homePage_;
      homePage_ = 0;

      root()->clear();

      sourceViewer_ = sourceViewer("/" + SRC_INTERNAL_PATH + "/");
      WVBoxLayout *layout = new WVBoxLayout();
      layout->setContentsMargins(0, 0, 0, 0);
      layout->addWidget(sourceViewer_);
      root()->setLayout(layout);
    }
  } else {
    if (!homePage_) {
      delete sourceViewer_;
      sourceViewer_ = 0;

      root()->clear();

      createHome();
      root()->addWidget(homePage_);

      setLanguageFromPath();
    }
  }
}
Exemplo n.º 5
0
std::string Application::ip_from_path() const {
    if (internalPathMatches("/admin/ip/")) {
        return internalPathNextPart("/admin/ip/");
    }
    return "";
}