void MTCompose::on_serverButton_clicked() { // Select from servers in local wallet filtered by both Nyms. // DlgChooser theChooser(this); mapIDName & the_map = theChooser.m_map; // ----------------------------------------------- mapIDName map_recipientServers; // If server ID is explicitly set, then we may know about a server that the contact // record DOESN'T know about. Therefore we only do this block if the server ID ISN'T // set (where we filter it based on the known servers for a given Nym.) // if (m_serverId.isEmpty() && !m_recipientNymId.isEmpty()) { if (MTContactHandler::getInstance()->GetServers(map_recipientServers, m_recipientNymId)) { the_map = map_recipientServers; // ------------------------------ if (DBHandler::getInstance()->runQuery("SELECT `server` FROM `default_server` WHERE `default_id`='1' LIMIT 0,1")) { QString default_server_id = DBHandler::getInstance()->queryString("SELECT `server` FROM `default_server` WHERE `default_id`='1' LIMIT 0,1", 0, 0); if (!default_server_id.isEmpty()) { mapIDName::iterator it_server = the_map.find(default_server_id); if (it_server != the_map.end()) theChooser.SetPreSelected(default_server_id); } } } } // ----------------------------------------------- if (the_map.size() < 1) { const int32_t server_count = OTAPI_Wrap::It()->GetServerCount(); // ----------------------------------------------- for (int32_t ii = 0; ii < server_count; ++ii) { //Get OT Server ID // QString OT_server_id = QString::fromStdString(OTAPI_Wrap::It()->GetServer_ID(ii)); QString OT_server_name(""); // ----------------------------------------------- if (!OT_server_id.isEmpty()) { if (!m_serverId.isEmpty() && (OT_server_id == m_serverId)) theChooser.SetPreSelected(m_serverId); // ----------------------------------------------- OT_server_name = QString::fromStdString(OTAPI_Wrap::It()->GetServer_Name(OT_server_id.toStdString())); // ----------------------------------------------- the_map.insert(OT_server_id, OT_server_name); } } } // ----------------------------------------------- theChooser.setWindowTitle("Select an OT Server"); // ----------------------------------------------- if (theChooser.exec() == QDialog::Accepted) { qDebug() << QString("SELECT was clicked for ServerID: %1").arg(theChooser.m_qstrCurrentID); if (!theChooser.m_qstrCurrentID.isEmpty()) { m_serverId = theChooser.m_qstrCurrentID; // ----------------------------------------- if (theChooser.m_qstrCurrentName.isEmpty()) ui->serverButton->setText(tr("(This server has a blank name)")); else ui->serverButton->setText(theChooser.m_qstrCurrentName); // ----------------------------------------- return; } } else { qDebug() << "CANCEL was clicked"; } // ----------------------------------------------- m_serverId = QString(""); ui->serverButton->setText(tr("<Click to choose an OT Server>")); }
// Top level... // (For servers and nyms.) // void DlgMarkets::RefreshRecords() { ui->comboBoxServer->blockSignals(true); ui->comboBoxNym ->blockSignals(true); // ---------------------------- m_mapServers.clear(); m_mapNyms .clear(); // ---------------------------- ClearOfferMap(); ClearMarketMap(); // ---------------------------- ui->comboBoxServer->clear(); ui->comboBoxNym ->clear(); // ---------------------------- int nDefaultServerIndex = 0; int nDefaultNymIndex = 0; // ---------------------------- bool bFoundServerDefault = false; // ---------------------------- QString qstrAllID = tr("all"); QString qstrAllName = tr("All Servers"); m_mapServers.insert(qstrAllID, qstrAllName); ui->comboBoxServer->insertItem(0, qstrAllName); // ---------------------------- if (!m_serverId.isEmpty() && (m_serverId == qstrAllID)) { bFoundServerDefault = true; nDefaultServerIndex = 0; } // ---------------------------- const int32_t server_count = OTAPI_Wrap::GetServerCount(); // ----------------------------------------------- for (int32_t ii = 0; ii < server_count; ++ii) { //Get OT Server ID // QString OT_server_id = QString::fromStdString(OTAPI_Wrap::GetServer_ID(ii)); QString OT_server_name(""); // ----------------------------------------------- if (!OT_server_id.isEmpty()) { if (!m_serverId.isEmpty() && (OT_server_id == m_serverId)) { bFoundServerDefault = true; nDefaultServerIndex = ii+1; // the +1 is because of "all" in the 0 position. (Servers only.) } // ----------------------------------------------- OT_server_name = QString::fromStdString(OTAPI_Wrap::GetServer_Name(OT_server_id.toStdString())); // ----------------------------------------------- m_mapServers.insert(OT_server_id, OT_server_name); ui->comboBoxServer->insertItem(ii+1, OT_server_name); } } // ----------------------------------------------- // ----------------------------------------------- bool bFoundNymDefault = false; const int32_t nym_count = OTAPI_Wrap::GetNymCount(); // ----------------------------------------------- for (int32_t ii = 0; ii < nym_count; ++ii) { //Get OT Nym ID QString OT_nym_id = QString::fromStdString(OTAPI_Wrap::GetNym_ID(ii)); QString OT_nym_name(""); // ----------------------------------------------- if (!OT_nym_id.isEmpty()) { if (!m_nymId.isEmpty() && (OT_nym_id == m_nymId)) { bFoundNymDefault = true; nDefaultNymIndex = ii; } // ----------------------------------------------- MTNameLookupQT theLookup; OT_nym_name = QString::fromStdString(theLookup.GetNymName(OT_nym_id.toStdString())); // ----------------------------------------------- m_mapNyms.insert(OT_nym_id, OT_nym_name); ui->comboBoxNym->insertItem(ii, OT_nym_name); } } // ----------------------------------------------- // ----------------------------------------------- if (m_mapNyms.size() > 0) { SetCurrentNymIDBasedOnIndex(nDefaultNymIndex); ui->comboBoxNym->setCurrentIndex(nDefaultNymIndex); } else SetCurrentNymIDBasedOnIndex(-1); // ----------------------------------------------- if (m_mapServers.size() > 0) { SetCurrentServerIDBasedOnIndex(nDefaultServerIndex); ui->comboBoxServer->setCurrentIndex(nDefaultServerIndex); } else SetCurrentServerIDBasedOnIndex(-1); // ----------------------------------------------- ui->comboBoxServer->blockSignals(false); ui->comboBoxNym ->blockSignals(false); // ----------------------------------------------- emit needToLoadOrRetrieveMarkets(); }