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); } }
void Lua4RSNotify::notifyChatMessage(const ChatMessage &msg) { struct LuaEvent *e = new LuaEvent(); e->eventId = L4R_LOBBY_MESSAGERECEIVED; e->timeStamp = QDateTime::currentDateTime(); e->dataParm->setValue("strchatid", QString::fromUtf8(msg.chat_id.toStdString().c_str())); std::string msg2 = msg.msg; msg2 = stripHTMLTags(msg2); e->dataParm->setValue("strmsg", QString::fromUtf8(msg2.c_str())); RsGxsId gxsid = msg.lobby_peer_gxs_id; RsIdentityDetails gxsIdDetails; rsIdentity->getIdDetails(gxsid, gxsIdDetails); e->dataParm->setValue("strgxsid", QString::fromUtf8(gxsid.toStdString().c_str())); e->dataParm->setValue("strnick", QString::fromUtf8(gxsIdDetails.mNickname.c_str())); L4R::L4RConfig->getCore()->processEvent(e); }
bool GxsIdChooser::setChosenId(const RsGxsId &gxsId) { QString id = QString::fromStdString(gxsId.toStdString()); /* Find text of exisiting item */ int index = findData(id); if (index >= 0) { setCurrentIndex(index); return true; } return false; }
void Lua4RSNotify::notifyChatLobbyEvent (uint64_t lobby_id, uint32_t event_type, const RsGxsId& nickname, const std::string& any_string) { QVariant v = QVariant::fromValue<uint64_t>(lobby_id); struct LuaEvent *e = new LuaEvent(); e->eventId = L4R_LOBBY_EVENT; e->timeStamp = QDateTime::currentDateTime(); e->dataParm->setValue("u64lobbyId", v); e->dataParm->setValue("u32eventType", event_type); e->dataParm->setValue("strnickname", QString::fromUtf8(nickname.toStdString().c_str())); e->dataParm->setValue("stranyString", QString::fromUtf8(any_string.c_str())); L4R::L4RConfig->getCore()->processEvent(e); }
void AvatarWidget::setGxsId(const RsGxsId &id) { mId = ChatId(); mGxsId = id; setPixmap(QPixmap()); if (id.isNull()) { setEnabled(false); } refreshAvatarImage(); refreshStatus(); }
void TopJCDialog::lookupGxsId(RsGxsId gxsid){ std::vector<RsGRouter::GRouterRoutingCacheInfo> cache_infos ; RsGRouter::GRouterRoutingMatrixInfo matrix_info ; rsGRouter->getRoutingCacheInfo(cache_infos) ; rsGRouter->getRoutingMatrixInfo(matrix_info) ; ui->textBrowser->append("\n"); ui->textBrowser->append(QString("Looking up ID %1").arg(QString::fromStdString(gxsid.toStdString()))); RsPeerDetails peer_ssl_details; //print matrix std::map<GRouterKeyId,std::vector<float> >::const_iterator it; it = matrix_info.per_friend_probabilities.find(gxsid); if (it != matrix_info.per_friend_probabilities.end()){ bool is_null = true ; for(uint32_t i=0;i<matrix_info.friend_ids.size();++i) if(it->second[i] > 0.0) is_null = false ; if(!is_null) { QString ids = QString::fromStdString(it->first.toStdString())+" : " ; for(uint32_t i=0;i<matrix_info.friend_ids.size();++i){ rsPeers->getPeerDetails(matrix_info.friend_ids[i], peer_ssl_details); float friend_chance = it->second[i]; if (friend_chance>0.0){ QString friend_name = QString::fromUtf8(peer_ssl_details.name.c_str()); QString formatted_string = QString("%1 has a chance of %2").arg(friend_name, QString::number(friend_chance)); ui->textBrowser->append(formatted_string); //ui->textBrowser->append("\n"); } } if (matrix_info.friend_ids.size() == 0) ui->textBrowser->append("no friends found in routing matrix?"); }else{ ui->textBrowser->append("no route found"); } } else { ui->textBrowser->append("ID not found in matrix... booted RS recently? wait a while? Check id is correct!!"); } }
bool MakeIdDesc(const RsGxsId &id, QString &desc) { RsIdentityDetails details; if (!rsIdentity->getIdDetails(id, details)) { return false; } desc = QString::fromUtf8(details.mNickname.c_str()); if (details.mPgpLinked) { desc += " (PGP) ["; } else { desc += " (Anon) ["; } desc += QString::fromStdString(id.substr(0,5)); desc += "...]"; return true; }
int main(int argc, char **argv) { if (!DirectoryExists(certificatePath.c_str())) { std::cout << "hardcoded certificatePath " << certificatePath << " doesn't exist!" << std::endl; return 1; } if (!file_writable(storagePath.c_str())) { std::cout << "hardcoded storagePath " << storagePath << " doesn't exist or isn't writable!" << std::endl; return 1; } if (!file_writable(temporaryFriendsFile.c_str())) { std::cout << "hardcoded temporary friends file " << temporaryFriendsFile << " doesn't exist or isn't writable!" << std::endl; return 1; } // startup libretroshare RsInit::InitRsConfig(); int initResult = RsInit::InitRetroShare(argc, argv, true); if (initResult < 0) { /* Error occured */ switch (initResult) { case RS_INIT_AUTH_FAILED: std::cerr << "RsInit::InitRetroShare AuthGPG::InitAuth failed" << std::endl; break; default: /* Unexpected return code */ std::cerr << "RsInit::InitRetroShare unexpected return code " << initResult << std::endl; break; }; return 1; } RsControl::earlyInitNotificationSystem() ; NotifyTxt *notify = new NotifyTxt() ; rsNotify->registerNotifyClient(notify); RsPeerId preferredId; RsPgpId gpgId; std::string gpgName, gpgEmail, sslName; RsAccounts::GetPreferredAccountId(preferredId); if (RsAccounts::GetAccountDetails(preferredId, gpgId, gpgName, gpgEmail, sslName)) { rsAccounts->SelectPGPAccount(gpgId); } /* Key + Certificate are loaded into libretroshare */ std::string error_string ; int retVal = RsInit::LockAndLoadCertificates(false,error_string); switch(retVal) { case 0: break; case 1: std::cerr << "Error: another instance of retroshare is already using this profile" << std::endl; return 1; case 2: std::cerr << "An unexpected error occurred while locking the profile" << std::endl; return 1; case 3: std::cerr << "An error occurred while login with the profile" << std::endl; return 1; default: std::cerr << "Main: Unexpected switch value " << retVal << std::endl; return 1; } /* Start-up libretroshare server threads */ RsControl::instance() -> StartupRetroShare(); /* Disable all Turtle Routing and tunnel requests */ rsConfig->setOperatingMode(RS_OPMODE_NOTURTLE); // give the core some time to start up fully // otherwise the GXS IDs might not be setup sleep(10); // get GXS Id RsGxsId id; std::list<RsGxsId> ids; rsIdentity->getOwnIds(ids); // wait for max. 60 seconds int16_t counter = 0; if(ids.empty()) { std::cout << "no GXS ID found -> sleep 5s -> 1st check again" << std::endl; sleep(5); rsIdentity->getOwnIds(ids); } while(ids.empty() && counter++ < 12) { std::cout << "no GXS ID found -> sleep 5s -> check again" << std::endl; sleep(5); rsIdentity->getOwnIds(ids); } if(ids.empty()) { std::cerr << "Error: unabled to find any GXS ID" << std::endl; return 1; } else { // find gxs id with suitable name std::list<RsGxsId>::iterator it; RsIdentityDetails details; for(it = ids.begin(); it != ids.end(); ++it) { // slightly ugly but needed since the details might not be available on the first request // first request rsIdentity->getIdDetails(*it, details); // wait sleep(1); // second request rsIdentity->getIdDetails(*it, details); std::cout << "GXS ID: " << details.mNickname << std::endl; if(details.mNickname == name) { id = *it; std::cout << "choosing this one: " << id.toStdString() << std::endl; break; } } } //if(ids.empty()) { //// generate a new ID //std::cout << "no GXS ID found -> generating a new one" << std::endl; //if(generateGxsId(name) != 0) //// geneation failed and error was already printed -> just return //return 1; //// pick first ID that is the newly generated one //rsIdentity->getOwnIds(ids); //id = ids.front(); //} else { //if(id.isNull()) //{ //// assume that a suitable ID isn't generated yet //std::cout << "no suitable GXS ID found -> generating new one" << std::endl; //if(generateGxsId(name) != 0) //// geneation failed and error was already printed -> just return //return 1; //// pick first ID that is the newly generated one //rsIdentity->getOwnIds(ids); //id = ids.front(); //} //} // last sanity check - should not occur but you never know ... if(id.isNull()) { std::cerr << "Error: can't find/generate suitable GXS Id" << std::endl; return 1; } rsMsgs->setDefaultIdentityForChatLobby(id); // start chatserver Chatserver *chatserver = new Chatserver(id); while (true) { sleep(1); chatserver->tick(); } return 0; }