Exemplo n.º 1
0
  void Popup::render(Wt::WFlags<Wt::RenderFlag> flags) {
    Wt::WApplication * app = Wt::WApplication::instance();
    Wt::WString initFunction = app->javaScriptClass() + ".init_popup_" + id();

    Wt::WStringStream stream;
    stream
      << "{" << initFunction.toUTF8() << " = function() {"
      << "  var self = " << jsRef() << ";"
      << "  if (!self) {"
      << "    setTimeout(" << initFunction.toUTF8() << ", 0);"
      << "  }";

    stream
      << "  self.popup = new mapboxgl.Popup( {"
      << "    closeButton: " << ToScript(closeButton_).toUTF8() << ", "
      << "    closeOnClick: " << ToScript(closeOnClick_).toUTF8() << ", "
      << "    anchor: " << ToScript(anchor_).toUTF8()
      << "  });";

    for (unsigned int i = 0; i < additions_.size(); i++) {
      stream << additions_[i].toUTF8();
    }
    additions_.clear();

    stream
      << "  setTimeout(function(){ delete " << initFunction.toUTF8() << ";}, 0)};\n"
      << "}\n"
      << initFunction.toUTF8() << "();\n";

    app->doJavaScript(stream.str());
  }
Exemplo n.º 2
0
void MainWindow::sayHi() {
    Wt::WString name = _nameInput->valueText();
    if (name.empty())
        _nameOutput->setText("");
    else
        _nameOutput->setText("Hi there " + name);
}
Exemplo n.º 3
0
Wt::WContainerWidget * ThermometerPlugin::getSummary() {
	Wt::WContainerWidget *summaryContainer_ = new Wt::WContainerWidget();
	Wt::WString str = "Found {1} Probes";
	str.arg((int) addresses_.size());
	summaryContainer_->addWidget(new Wt::WText(str));
	return summaryContainer_;
}
Exemplo n.º 4
0
 void set_query() {
     dbo::Transaction t(tApp->session());
     ULP::Q q;
     if (only_blocked_) {
         q = tApp->session().query<UserPtr>(
                 "select U from thechess_message_filter F "
                 "left join thechess_user U on F.bad_id = U.id");
         q.where("F.good_id = ?").bind(tApp->user());
     } else {
         q = tApp->session().find<User>();
     }
     if (not_removed_) {
         q.where("rights != ?").bind(NONE);
         q.where("vacation_until is null");
         q.where("last_online > ?").bind(now() - 10 * WEEK);
     }
     if (only_online_) {
         q.where("last_online >= ?");
         q.bind(now() - Options::instance()->away_timeout());
     }
     if (!name_like_.empty()) {
         q.where("(username like ? or id = ?)");
         q.bind("%" + name_like_ + "%");
         q.bind(Wt::Wc::str2int(name_like_.toUTF8()));
     }
     q.orderBy("games_stat_elo desc");
     setQuery(q, /* keep_columns */ true);
 }
Exemplo n.º 5
0
void CreatePostWidget::submitMessage()
{
    Wt::WString text = _messageTextArea->text();
    if(text == ""){
        // can use setEmptyText instead of this
        enterDefaultText();
    }else{
        PostMsg msg;
        uint32_t token;

        RsGxsId author = _idChooser->getSelectedId();
        if(author.isNull()){
            return;
        }
        msg.mMeta.mAuthorId = author;

        RsGxsGroupId targetWall = _wallChooser->getSelectedWallId();
        if(targetWall.isNull()){
            return;
        }
        // this is a trick:
        // use the group id to signal the wall the post should appear on
        msg.mMeta.mGroupId = targetWall;

        // todo: circle
        msg.mPostText = text.toUTF8();
        rsWall->createPost(token, msg);
    }
}
Exemplo n.º 6
0
void AbstractRPM::consoleAddData(const Wt::WString &computerName, const Wt::WString &data)
{
	Wt::WString date = Wt::WDate::currentServerDate().toString("yyyy/MM/dd");
	Wt::WString time = Wt::WTime::currentServerTime().toString("hh:mm:ss");
	std::string user = currentUser();
	Wt::WString header = date + "-" + time;
	if (!user.empty())
		header += ": " + user;
	Wt::WString entry = header + ": " + data + "\n";

	computerStateLock.lock();
	Wt::WString logs = entry + _computerLogs[computerName];
	logs = logs.toUTF8().substr(0, 1000);	/* limit to 1k */
	_computerLogs[computerName] = logs;
	computerStateLock.unlock();

	viewsLock.lock();
	std::map< std::string, View* >::iterator it;
	for (it = views.begin(); it != views.end(); ++it) {
		server->post((*it).first, boost::bind(&View::consoleDataAdded,
						      (*it).second, computerName,
						      entry));
	}
	viewsLock.unlock();
}
Exemplo n.º 7
0
void ComputerView::consoleDataAdded(const Wt::WString &data)
{
	Wt::WString logs = data + _logs_edit->valueText();
	logs = logs.toUTF8().substr(0, 1000);	/* limit to 1k */
	_logs_edit->setValueText(logs);

	app->triggerUpdate();
}
Exemplo n.º 8
0
Wt::Auth::User RDAUserDatabase::findWithIdentity (const std::string &provider,
						  const Wt::WString &identity)
  const
{
	std::string i;
  /*
   * David: find the 'id' for a user with name _identity_, leave it
   * empty if no user with this name exists
   */

	if(SEC_USERS_FILENO==(-1))
	{
    		return Wt::Auth::User();
	}
	ZERNRD(SEC_USERS_FILENO);
	i=identity.toUTF8();
	USERLOGIN=stralloc(i.c_str());
	FINDFLDSETSTRING(SEC_USERS_FILENO,"USER IDENTIFICATION",USERLOGIN);
	if(EQLNRD(SEC_USERS_FILENO,1)) 
	{
		KEYNRD(SEC_USERS_FILENO,1);
    		return Wt::Auth::User();
	} else {
    		return Wt::Auth::User(i, *this);
	}
}
Exemplo n.º 9
0
Wt::WString TopicWidget::reindent(const Wt::WString& text)
{
  std::vector<std::string> lines;
  std::string s = text.toUTF8();
  boost::split(lines, s, boost::is_any_of("\n"));

  std::string result;
  int indent = -1;
  int newlines = 0;
  for (unsigned i = 0; i < lines.size(); ++i) {
    const std::string& line = lines[i];

    if (line.empty()) {
      ++newlines;
    } else {
      if (indent == -1) {
        indent = countSpaces(line);
      } else {
        for (int j = 0; j < newlines; ++j)
          result += '\n';
      }

      newlines = 0;

      if (!result.empty())
        result += '\n';

      result += skipSpaces(line, indent);
    }
  }
  return Wt::WString::fromUTF8(result);
}
Exemplo n.º 10
0
void FormBaseModel::setValid(Field field, const Wt::WString& message)
{
  setValidation(field,
		WValidator::Result(WValidator::Valid,
				   message.empty() ? 
				   WString::tr("Wt.Auth.valid") : message));
}
Exemplo n.º 11
0
 void Popup::doDelayedJavaScript(const Wt::WString & jscode) {
   if (isRendered()) {
     doJavaScript(jscode.toUTF8());
   }
   else {
     additions_.push_back(jscode);
   }
 }
Exemplo n.º 12
0
/* ****************************************************************************
 * asciidoc
 */
WString asciidoc(const Wt::WString& src)
{
    std::string srcFileName = tempFileName();
    std::string htmlFileName = tempFileName();

    {
        std::ofstream srcFile(srcFileName.c_str(), std::ios::out);
        std::string ssrc = src.toUTF8();
        srcFile.write(ssrc.c_str(), (std::streamsize)ssrc.length());
        srcFile.close();
    }

#if defined(ASCIIDOC_EXECUTABLE)
#define xstr(s) str(s)
#define str(s) #s
    std::string cmd = xstr(ASCIIDOC_EXECUTABLE);
#else
    std::string cmd = "asciidoc";
#endif
    std::string command = cmd + " -o " + htmlFileName + " -s " + srcFileName;

#ifndef WIN32
  /*
   * So, asciidoc apparently sends a SIGINT which is caught by its parent process..
   * So we have to temporarily ignore it.
   */
    struct sigaction newAction, oldAction;
    newAction.sa_handler = SIG_IGN;
    newAction.sa_flags = 0;
    sigemptyset(&newAction.sa_mask);
    sigaction(SIGINT, &newAction, &oldAction);
#endif
    bool ok = system(command.c_str()) == 0;
#ifndef WIN32
    sigaction(SIGINT, &oldAction, 0);
#endif

    WString result;

    if (ok)
    {
        result = WString::fromUTF8(readFileToString(htmlFileName));
    }
    else
    {
        result = WString::fromUTF8("<i>Could not execute asciidoc</i>");
    }
    unlink(srcFileName.c_str());
    unlink(htmlFileName.c_str());

    return result;
}
Exemplo n.º 13
0
		Result validate(const Wt::WString& input) const
		{
			auto res = Wt::WValidator::validate(input);
			if (res.state() != Wt::ValidationState::Valid)
				return res;

			auto password = Config::instance().getString("upload-password", "");

			if (input.toUTF8() == password)
				return Result(Wt::ValidationState::Valid);

			return Result(Wt::ValidationState::Invalid, Wt::WString::tr("msg-bad-password"));
		}
Exemplo n.º 14
0
Wt::Json::Value saveFragments(MyTreeTableNode *root)
{ 
	Wt::Json::Value retVal = Wt::Json::Value(Wt::Json::ArrayType);
	Wt::Json::Array& ret = retVal; 
	Wt::WString name;
	name = root->text;	
	std::string str = name.toUTF8();
	str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); //This removes whitespace
	if(str.length()<1)
	{
		name = Wt::WString("New Node");
	}
	if(root->childNodes().size()>0)
	{
		ret.push_back(Wt::Json::Value(Wt::WString("group")));
		ret.push_back(Wt::Json::Value(name));
		Wt::Json::Value out_children_value = Wt::Json::Value(Wt::Json::ArrayType);	
		Wt::Json::Array& out_children = out_children_value; 
		for(auto mynode:root->childNodes()) //I wonder, what order do we get these in?
		{
			out_children.push_back(saveFragments(dynamic_cast<MyTreeTableNode*>(mynode)));
		}

		ret.push_back(out_children_value);

	}
	else //TODO add room for annotations
	{
		ret.push_back(Wt::Json::Value(Wt::WString("fragment")));
		ret.push_back(Wt::Json::Value(name));
		long long start = root->startWidget->time();
		long long stop = root->stopWidget->time();
		//this->log("info")<< "Saving fragment "<<std::to_string(start) << "  "<<std::to_string(stop);
		ret.push_back(Wt::Json::Value(start));
		ret.push_back(Wt::Json::Value(stop));
	}
return retVal;
}
Exemplo n.º 15
0
void PopupChatWidget::goOnline()
{
  if (!online_) {
    online_ = true;

    int tries = 1;
    Wt::WString name = name_;
    if (name.empty())
      name = server().suggestGuest();

    while (!startChat(name)) {
      if (name_.empty())
	name = server().suggestGuest();
      else
	name = name_ + boost::lexical_cast<std::string>(++tries);
    }

    name_ = name;
  }

  missedMessages_ = 0;
  bar_->removeStyleClass("alert");
}
Exemplo n.º 16
0
void PopupChatWidget::setName(const Wt::WString& name)
{
  if (name.empty())
    return;

  if (online_) {
    int tries = 1;
    Wt::WString n = name;
    while (!server().changeName(name_, n))
      n = name + boost::lexical_cast<std::string>(++tries);

    name_ = n;
  } else
    name_ = name;
}
Exemplo n.º 17
0
Wt::WContainerWidget*
Application::instantiateMainTabs() {
    Wt::WContainerWidget *mainTabContainer = new Wt::WContainerWidget;
    Wt::WVBoxLayout *vbox = new Wt::WVBoxLayout;
    mainTabContainer->setLayout(vbox);

    wMainTabs_ = new Wt::WTabWidget;
    wMainTabs_->currentChanged().connect(boost::bind(&Application::changeTab2, this, _1));
    vbox->addWidget(wMainTabs_, 1 /*stretch*/);

    for (size_t i=0; i<NMainTabs; ++i) {
        Wt::WString tabName;
        Wt::WContainerWidget *tabContent = NULL;
        switch ((MainTab)i) {
        case PartitionerTab: {
            tabName = "Partitioner";
            tabContent = wPartitioner_ = new WPartitioner(ctx_);
            wPartitioner_->specimenParsed().connect(boost::bind(&Application::handleSpecimenParsed, this, _1));
            wPartitioner_->specimenLoaded().connect(boost::bind(&Application::handleSpecimenLoaded, this, _1));
            wPartitioner_->specimenPartitioned().connect(boost::bind(&Application::handleSpecimenPartitioned, this, _1));
            break;
        }
        case MemoryMapTab: {
            tabName = "Memory Map";
            tabContent = wMemoryMap_ = new WMemoryMap;
            wMemoryMap_->mapChanged().connect(boost::bind(&Application::memoryMapChanged, this));
            wMemoryMap_->allowDownloads(ctx_.settings.allowDownloads);
            break;
        }
        case FunctionListTab: {
            tabName = "Functions";
            tabContent = wFunctionList_ = new WFunctionList(ctx_);
            wFunctionList_->functionChanged().connect(boost::bind(&Application::changeFunction, this, _1));
            wFunctionList_->functionRowDoubleClicked()
            .connect(boost::bind(&Application::changeFunctionDoubleClick, this, _1));
            break;
        }
        case FunctionSummaryTab: {
            tabName = "Summary";
            tabContent = wFunctionSummary_ = new WFunctionSummary(ctx_);
            break;
        }
        case FunctionCfgTab: {
            tabName = "CFG";
            tabContent = wFunctionCfg_ = new WFunctionCfg(ctx_);
            wFunctionCfg_->functionChanged().connect(boost::bind(&Application::changeFunction, this, _1));
            wFunctionCfg_->functionClicked().connect(boost::bind(&Application::changeFunction, this, _1));
            wFunctionCfg_->addressClicked().connect(boost::bind(&Application::showHexDumpAtAddress, this, _1));
            wFunctionCfg_->basicBlockClicked().connect(boost::bind(&Application::changeBasicBlock, this, _1));
            break;
        }
        case AssemblyTab: {
            tabName = "Assembly";
            tabContent = wAssembly_ = new WAssemblyListing(ctx_);
            break;
        }
        case HexDumpTab: {
            tabName = "Hexdump";
            tabContent = wHexDump_ = new WHexDump;
            wHexDump_->byteClicked().connect(boost::bind(&Application::updateAddressCrossReferences, this, _1));
            break;
        }
        case MagicTab: {
            tabName = "Magic";
            tabContent = wMagic_ = new WMagic;
            break;
        }
        case StringsTab: {
            tabName = "Strings";
            tabContent = wStrings_ = new WStrings;
            wStrings_->stringClicked().connect(boost::bind(&Application::updateStringCrossReferences, this, _1));
            break;
        }
        case StatusTab: {
            tabName = "Status";
            tabContent = wStatus_ = new WStatus(ctx_);
            break;
        }
        default:
            ASSERT_not_reachable("invalid main tab");
        }
        ASSERT_not_null(tabContent);
        ASSERT_forbid(tabName.empty());
        wMainTabs_->addTab(tabContent, tabName);
    }
    return mainTabContainer;
}
Exemplo n.º 18
0
sb2->addItem("Green peppers");
sb2->addItem("Ham");
sb2->addItem("Pepperoni");
sb2->addItem("Red peppers");
sb2->addItem("Turkey");
sb2->setSelectionMode(Wt::ExtendedSelection);
std::set<int> selection;    // By default select the items with index 1 and 4.
selection.insert(1);        // Index 1 corresponds to the 2nd item.
selection.insert(4);        // Index 4 corresponds to the 5th item.
sb2->setSelectedIndexes(selection);
sb2->setMargin(10, Wt::Right);

Wt::WText *out = new Wt::WText(container);

sb2->activated().connect(std::bind([=] () {
      Wt::WString selected;

      std::set<int> selection = sb2->selectedIndexes();
      for (std::set<int>::iterator it = selection.begin();
	   it != selection.end(); ++it) {
	if (!selected.empty())
          selected += ", ";

	selected += sb2->itemText(*it);
      }

      out->setText(Wt::WString::fromUTF8("You choose {1}.").arg(selected));
}));

SAMPLE_END(return container)
Exemplo n.º 19
0
void
WHexValueEdit::setError(const Wt::WString &mesg) {
    wError_->setText(mesg);
    wError_->setHidden(mesg.empty());
    wSave_->setEnabled(mesg.empty());
}