예제 #1
0
void MTCompose::on_fromButton_clicked()
{
    // Select from Nyms in local wallet.
    //
    DlgChooser theChooser(this);
    // -----------------------------------------------
    mapIDName & the_map = theChooser.m_map;

    bool bFoundDefault = false;
    // -----------------------------------------------
    const int32_t nym_count = OTAPI_Wrap::It()->GetNymCount();
    // -----------------------------------------------
    for (int32_t ii = 0; ii < nym_count; ++ii)
    {
        //Get OT Nym ID
        QString OT_nym_id = QString::fromStdString(OTAPI_Wrap::It()->GetNym_ID(ii));
        QString OT_nym_name("");
        // -----------------------------------------------
        if (!OT_nym_id.isEmpty())
        {
            if (!m_senderNymId.isEmpty() && (OT_nym_id == m_senderNymId))
                bFoundDefault = true;
            // -----------------------------------------------
            MTNameLookupQT theLookup;

            OT_nym_name = QString::fromStdString(theLookup.GetNymName(OT_nym_id.toStdString()));
            // -----------------------------------------------
            the_map.insert(OT_nym_id, OT_nym_name);
        }
     }
    // -----------------------------------------------
    if (bFoundDefault && !m_senderNymId.isEmpty())
        theChooser.SetPreSelected(m_senderNymId);
    // -----------------------------------------------
    theChooser.setWindowTitle(tr("Choose your Sender identity"));
    // -----------------------------------------------
    if (theChooser.exec() == QDialog::Accepted)
    {
        qDebug() << QString("SELECT was clicked for NymID: %1").arg(theChooser.m_qstrCurrentID);

        if (!theChooser.m_qstrCurrentID.isEmpty())
        {
            m_senderNymId = theChooser.m_qstrCurrentID;
            // -----------------------------------------
            if (theChooser.m_qstrCurrentName.isEmpty())
                ui->fromButton->setText(QString(""));
            else
                ui->fromButton->setText(theChooser.m_qstrCurrentName);
            // -----------------------------------------
            return;
        }
    }
    else
    {
      qDebug() << "CANCEL was clicked";
    }
    // -----------------------------------------------
    m_senderNymId = QString("");
    ui->fromButton->setText(tr("<Click to choose Sender>"));
}
예제 #2
0
void DlgEncrypt::PopulateCombo()
{
    if (ui)
    {
        ui->comboBoxNym->blockSignals(true);
        // ----------------------------
        int nDefaultNymIndex    = 0;
        bool bFoundNymDefault   = false;
        // -----------------------------------------------
        const int32_t nym_count = opentxs::OTAPI_Wrap::It()->GetNymCount();
        // -----------------------------------------------
        for (int32_t ii = 0; ii < nym_count; ++ii)
        {
            QString OT_nym_id = QString::fromStdString(opentxs::OTAPI_Wrap::It()->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);
        // -----------------------------------------------
        ui->comboBoxNym->blockSignals(false);
    }
}
예제 #3
0
void DlgDecrypt::on_pushButtonDecrypt_clicked()
{
    bool bSuccessDecrypting = false;
    bool bSuccessVerifying  = false;

    QString qstrNymWhoDecrypted;
    QString qstrNymWhoVerified;

    QString qstrText = ui->plainTextEdit->toPlainText().trimmed();
    // --------------------------------
    if (qstrText.isEmpty())
    {
        // pop up a message box warning that the input text is empty.
        //
        QMessageBox::warning(this, tr("Ciphertext is Empty"),
                             tr("Please paste something to be decrypted/verified."));
        return;
    }
    // --------------------------------
    else //qstrText not empty.
    {
        std::string str_input(qstrText.toStdString());
        opentxs::String    strInput (str_input.c_str());

        if (strInput.Exists())
        {
            if (strInput.Contains("-----BEGIN OT ARMORED ENVELOPE-----"))
            {
                opentxs::OTEnvelope theEnvelope;

                if (theEnvelope.SetFromBookendedString(strInput))
                {
                    opentxs::String strOutput;
                    // -------------------------
                    // First we'll try the default nym, if one is available.
                    //
                    QString qstrTempID = Moneychanger::It()->get_default_nym_id();

                    if (!qstrTempID.isEmpty()) // Default Nym IS available.
                    {
                        std::string  str_nym    (qstrTempID.toStdString());
                        opentxs::String     strNym     (str_nym.c_str());
                        opentxs::Identifier nym_id     (strNym);

                        if (!nym_id.IsEmpty())
                        {
                            opentxs::OTPasswordData thePWData("Recipient passphrase");

                            opentxs::Nym * pNym = opentxs::OTAPI_Wrap::OTAPI()->GetOrLoadPrivateNym(nym_id,
                                                                                   false, //bChecking=false
                                                                                   __FUNCTION__,
                                                                                   &thePWData);
                            if (NULL != pNym)
                            {
                                if (theEnvelope.Open(*pNym, strOutput) && strOutput.Exists())
                                {
                                    bSuccessDecrypting = true;
                                    qstrNymWhoDecrypted = qstrTempID;

                                    strInput  = strOutput;
                                    str_input = strInput.Get();
                                    qstrText  = QString::fromStdString(str_input);
                                }
                            }
                        }
                    }
                    // ------------
                    if (!bSuccessDecrypting) // Default nym is NOT available. Okay let's loop through all the Nyms in the wallet then, and try then all...
                    {
                        const int32_t nym_count = opentxs::OTAPI_Wrap::It()->GetNymCount();
                        // -----------------------------------------------
                        for (int32_t ii = 0; ii < nym_count; ++ii)
                        {
                            //Get OT Nym ID
                            QString OT_nym_id = QString::fromStdString(opentxs::OTAPI_Wrap::It()->GetNym_ID(ii));

                            if (!OT_nym_id.isEmpty())
                            {
                                std::string         str_nym    (OT_nym_id.toStdString());
                                opentxs::String     strNym     (str_nym.c_str());
                                opentxs::Identifier nym_id     (strNym);

                                if (!nym_id.IsEmpty())
                                {
                                    opentxs::OTPasswordData thePWData("Recipient passphrase");

                                    opentxs::Nym * pNym = opentxs::OTAPI_Wrap::OTAPI()->GetOrLoadPrivateNym(nym_id,
                                                                                           false, //bChecking=false
                                                                                           "DlgEncrypt::on_pushButtonDecrypt_clicked",
                                                                                           &thePWData);
                                    if (NULL != pNym)
                                    {
                                        // Okay there is a private key available for this Nym, so let's
                                        // try to open the envelope using it.
                                        //
                                        if (theEnvelope.Open(*pNym, strOutput) && strOutput.Exists())
                                        {
                                            bSuccessDecrypting = true;
                                            qstrNymWhoDecrypted = OT_nym_id;

                                            strInput  = strOutput;
                                            str_input = strInput.Get();
                                            qstrText  = QString::fromStdString(str_input);

                                            break;
                                        }
                                    }
                                }
                                // ------------
                            }
                        } // for
                    } // else default nym not available.
                    // -----------------------
                    if (!bSuccessDecrypting)
                    {
                        QMessageBox::warning(this, tr("Failed Decrypting"),
                                             tr("None of the identities in your wallet (including your default identity, "
                                                "if applicable) were able to open this message."));
                        return;

                    }
                    // -----------------------
                } // if (theEnvelope.SetFromBookendedString(strInput))

            } // if (strInput.Contains("-----BEGIN OT ARMORED ENVELOPE-----"))
            // --------------------------------------------
            // This call to DecodeIfArmored is what handles the: "-----BEGIN OT ARMORED ... -----"

            if (strInput.DecodeIfArmored(false)) // bEscapedIsAllowed=true by default.
            {
                std::string str_decoded(strInput.Get());
                QString qstrDecoded(QString::fromStdString(str_decoded));

                if (!qstrDecoded.isEmpty())
                    qstrText = qstrDecoded;
                // -----------------------------------
                // At this point, we know it's been decrypted, if applicable, and it's been
                // de-armored, if applicable. So now we check to see if it's a signed file.
                //
                if (strInput.Contains("-----BEGIN SIGNED FILE-----"))
                {
                    opentxs::OTSignedFile theSignedFile;

                    if (theSignedFile.LoadContractFromString(strInput))
                    {
                        opentxs::String strSignerNymID = theSignedFile.GetSignerNymID();
                        std::string str_signer_nym(strSignerNymID.Get());
                        QString qstrSignerNym(QString::fromStdString(str_signer_nym));

                        if (!str_signer_nym.empty())
                        {
                            opentxs::OTPasswordData thePWData("Sometimes need to load private part of nym in order to use its public key. (Fix that!)");
                            opentxs::Identifier id_signer_nym(strSignerNymID);
                            const opentxs::Nym * pNym = opentxs::OTAPI_Wrap::OTAPI()->GetOrLoadNym(id_signer_nym,
                                                                                   false, //bChecking=false
                                                                                   __FUNCTION__,
                                                                                   &thePWData);
                            if (NULL != pNym)
                            {
                                if (theSignedFile.VerifySignature(*pNym, &thePWData))
                                {
                                    bSuccessVerifying = true;
                                    qstrNymWhoVerified = qstrSignerNym;

                                    opentxs::String strContents = theSignedFile.GetFilePayload();

                                    if (strContents.Exists())
                                    {
                                        strInput  = strContents;
                                        str_input = strInput.Get();
                                        qstrText  = QString::fromStdString(str_input);
                                    }
                                } // signature verified
                            } // pNym exists
                        } // if str_signer_nym exists
                    } // signed file: load contract from string.
                } // "BEGIN SIGNED FILE"
            } // Decode If Armored.
            // -----------------------------------------------
            // if qstrText still contains something, pop up a dialog to display the result to the user.
            //
            if (!qstrText.isEmpty())
            {
                MTNameLookupQT theLookup;
                QString qstrNymWhoDecryptedName(""), qstrNymWhoVerifiedName("");

                if (!qstrNymWhoDecrypted.isEmpty())
                    qstrNymWhoDecryptedName = QString::fromStdString(theLookup.GetNymName(qstrNymWhoDecrypted.toStdString(), ""));
                if (!qstrNymWhoVerified.isEmpty())
                    qstrNymWhoVerifiedName = QString::fromStdString(theLookup.GetNymName(qstrNymWhoVerified.toStdString(), ""));
                // -------------------------------
                if (qstrNymWhoDecryptedName.isEmpty())
                    qstrNymWhoDecryptedName = qstrNymWhoDecrypted;
                else if (qstrNymWhoDecryptedName != qstrNymWhoDecrypted)
                    qstrNymWhoDecryptedName += QString(" (%1)").arg(qstrNymWhoDecrypted);
                // -------------------------------
                if (qstrNymWhoVerifiedName.isEmpty())
                    qstrNymWhoVerifiedName = qstrNymWhoVerified;
                else if (qstrNymWhoVerifiedName != qstrNymWhoVerified)
                    qstrNymWhoVerifiedName += QString(" (%1)").arg(qstrNymWhoVerified);
                // -------------------------------
                QString qstrType("Output:");

                if (bSuccessVerifying)
                {
                    qstrType = QString("%1: %2").arg(tr("Verified signature by Nym")).arg(qstrNymWhoVerifiedName);
                }
                // -----------
                if (bSuccessDecrypting)
                {
                    if (bSuccessVerifying)
                        qstrType = QString("%1: %2\n%3: %4").arg(tr("Decrypted using Nym")).arg(qstrNymWhoDecryptedName).arg(tr("Verified signature by Nym")).arg(qstrNymWhoVerifiedName);
                    else
                        qstrType = QString("%1: %2").arg(tr("Decrypted using Nym")).arg(qstrNymWhoDecryptedName);
                }
                // -----------
                QString qstrSubTitle(tr("Be sure to copy it somewhere before closing this dialog."));
                // -----------
                // Pop up the result dialog.
                //
                DlgExportedToPass dlgExported(this, qstrText,
                                              qstrType,
                                              qstrSubTitle, false);
                dlgExported.exec();
            } // if (!qstrText.isEmpty())
        } // if strInput
    } //qstrText not empty
}
void MTCredentials::refresh(QStringList & qstrlistNymIDs)
{
    ui->treeWidget->clear();
    // -----------------------------------
    ui->label->setVisible(false);
    ui->plainTextEdit->setVisible(false);
    // -----------------------------------
    if ((NULL != ui) && (qstrlistNymIDs.size() > 0))
    {
        m_NymIDs = qstrlistNymIDs;
        // -----------------------------------
        for (int ii = 0; ii < m_NymIDs.size(); ++ii)
        {
            QString qstrNymID = m_NymIDs.at(ii);
            // ---------------------------------------
            if (qstrNymID.isEmpty()) // should never happen.
                continue;
            // ---------------------------------------
            std::string str_nym_id = qstrNymID.toStdString();
            // ---------------------------------------
            MTNameLookupQT theLookup;

            std::string str_nym_name = theLookup.GetNymName(qstrNymID.toStdString(), "");
            QString     qstrNymName  = QString::fromStdString(str_nym_name);
            // ---------------------------------------
            // Insert Nym into Tree.
            //
            QTreeWidgetItem * topLevel = new QTreeWidgetItem;
            // ------------------------------------------
            topLevel->setText(0, qstrNymName);
            topLevel->setText(1, qstrNymID);
            // ------------------------------------------
            ui->treeWidget->addTopLevelItem(topLevel);
            ui->treeWidget->expandItem(topLevel);
            // ------------------------------------------
            // Next: any credentials under this Nym?
            //
            const int32_t nCountCredentials = opentxs::OTAPI_Wrap::It()->GetNym_MasterCredentialCount(str_nym_id);

            for (int nCred = 0; nCred < nCountCredentials; ++nCred)
            {
                std::string str_cred_id = opentxs::OTAPI_Wrap::It()->GetNym_MasterCredentialID(str_nym_id, nCred);

                if (str_cred_id.empty()) // should never happen.
                    continue;
                // ---------------------------------------
                QString qstrCredID = QString::fromStdString(str_cred_id);
                // ---------------------------------------
                // Add the credential ID to the tree.
                //
                QTreeWidgetItem * cred_item = new QTreeWidgetItem;
                // ---------------------------------------
                cred_item->setText(0, tr("Master Credential"));
                cred_item->setText(1, qstrCredID);
                cred_item->setText(2, getNamecoinStatus(str_nym_id, str_cred_id));
                // ---------------------------------------
                topLevel->addChild(cred_item);
                ui->treeWidget->expandItem(cred_item);
                // ---------------------------------------
                // If you need the credential contents later, you can use this:
                //
                // std::string opentxs::OTAPI_Wrap::It()->GetNym_CredentialContents(const std::string & NYM_ID, const std::string & CREDENTIAL_ID);
                // ---------------------------------------
                // Next: any subcredentials under this credential?
                //
                const int32_t nCountSubcred = opentxs::OTAPI_Wrap::It()->GetNym_ChildCredentialCount(str_nym_id, str_cred_id);

                for (int nSubcred = 0; nSubcred < nCountSubcred; ++nSubcred)
                {
                    std::string str_sub_cred_id = opentxs::OTAPI_Wrap::It()->GetNym_ChildCredentialID(str_nym_id, str_cred_id, nSubcred);

                    if (str_sub_cred_id.empty()) // should never happen.
                        continue;
                    // ---------------------------------------
                    QString qstrSubcredID = QString::fromStdString(str_sub_cred_id);
                    // ---------------------------------------
                    // Add the subcredential ID to the tree.
                    //
                    QTreeWidgetItem * sub_cred_item = new QTreeWidgetItem;
                    // ---------------------------------------
                    sub_cred_item->setText(0, tr("Subcredential"));
                    sub_cred_item->setText(1, qstrSubcredID);
                    // ---------------------------------------
                    cred_item->addChild(sub_cred_item);
                    // ---------------------------------------

                    // If you need the subcredential contents later, you can use this:
                    //
                    // std::string GetNym_SubCredentialContents(const std::string & NYM_ID, const std::string & MASTER_CRED_ID, const std::string & SUB_CRED_ID);
                    //
                    // Also useful:
                    // std::string opentxs::OTAPI_Wrap::It()->AddSubcredential(const std::string & NYM_ID, const std::string & MASTER_CRED_ID, const int32_t & nKeySize);
                    // bool        opentxs::OTAPI_Wrap::It()->RevokeSubcredential(const std::string & NYM_ID, const std::string & MASTER_CRED_ID, const std::string & SUB_CRED_ID);
                    //
                } // for (subcredentials.)
            } // for (credentials.)

//        QWidget     * wdg       = new QWidget;
//        QCheckBox   * pCheckbox = new QCheckBox(wdg);
//        QHBoxLayout * layout    = new QHBoxLayout(wdg);

//        layout->setContentsMargins(0,0,0,0);
//        layout->addWidget(pCheckbox);
//        layout->setAlignment( Qt::AlignCenter );
//        wdg->setLayout(layout);
//        ui->treeWidget->setCellWidget ( ii, 0, wdg);

//        ui->treeWidget->setCellWidget ( ii, 1, pLabelDenomination );
//        ui->treeWidget->setCellWidget ( ii, 2, pLabelExpires );
//        ui->treeWidget->setCellWidget ( ii, 3, pLabelSeries );
//        ui->treeWidget->setCellWidget ( ii, 4, pLabelTokenID );

//        connect(pCheckbox, SIGNAL(stateChanged(int) ), this, SLOT(checkboxClicked(int)));

        } // for (Nyms)
        // ------------------------------

    }

    // Also useful:
    //
//     int32_t     GetNym_RevokedCredCount     (const std::string & NYM_ID);
//     std::string GetNym_RevokedCredID        (const std::string & NYM_ID, const int32_t & nIndex);
//     std::string GetNym_RevokedCredContents  (const std::string & NYM_ID, const std::string & CREDENTIAL_ID);
//     bool        RevokeSubcredential         (const std::string & NYM_ID, const std::string & MASTER_CRED_ID, const std::string & SUB_CRED_ID);

}
예제 #5
0
void MTSendDlg::dialog()
{
/** Send Funds Dialog **/

    if (!already_init)
    {
        this->setWindowTitle(tr("Send Funds"));

        QString style_sheet = "QPushButton{border: none; border-style: outset; text-align:left; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa);}"
                "QPushButton:pressed {border: 1px solid black; text-align:left; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa); }"
                "QPushButton:hover {border: 1px solid black; text-align:left; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa); }";

        ui->fromButton->setStyleSheet(style_sheet);
        ui->toButton->setStyleSheet(style_sheet);

        // Here if there is pre-set data for the subject, contents, to, from, server, etc
        // then we set it here.
        //
        // -------------------------------------------
        std::string str_my_name;
        // -------------------------------------------
        if (!m_myAcctId.isEmpty()) // myAcct was provided.
        {
            MTNameLookupQT theLookup;

            str_my_name = theLookup.GetAcctName(m_myAcctId.toStdString());

            if (str_my_name.empty())
                str_my_name = m_myAcctId.toStdString();
        }
        // -------------------------------------------
        if (str_my_name.empty())
        {
            m_myAcctId = QString("");
            ui->fromButton->setText(tr("<Click to Select Account>"));
        }
        else
        {
            QString from_button_text = MTHome::FormDisplayLabelForAcctButton(m_myAcctId, QString::fromStdString(str_my_name));

            ui->fromButton->setText(from_button_text);
        }
        // -------------------------------------------


        // -------------------------------------------
        std::string str_his_name;
        // -------------------------------------------
        if (!m_hisNymId.isEmpty()) // hisNym was provided.
        {
            MTNameLookupQT theLookup;

            str_his_name = theLookup.GetNymName(m_hisNymId.toStdString());

            if (str_his_name.empty())
                str_his_name = m_hisNymId.toStdString();
        }
        // -------------------------------------------
        if (str_his_name.empty())
        {
            m_hisNymId = QString("");
            ui->toButton->setText(tr("<Click to choose Recipient>"));
        }
        else
            ui->toButton->setText(QString::fromStdString(str_his_name));
        // -------------------------------------------



        // -------------------------------------------
        if (!m_memo.isEmpty())
        {
            QString qstrTemp = m_memo;
            ui->memoEdit->setText(qstrTemp);
            // -----------------------
            this->setWindowTitle(tr("Send Funds | Memo: %1").arg(qstrTemp));
        }
        // -------------------------------------------



        // -------------------------------------------
        if (!m_amount.isEmpty())
        {
            QString qstrTemp = m_amount;
            ui->amountEdit->setText(m_amount);
        }
        // -------------------------------------------

        ui->toButton->setFocus();


        /** Flag Already Init **/
        already_init = true;
    }

}
예제 #6
0
void MTSendDlg::on_fromButton_clicked()
{
    // Select from Accounts in local wallet.
    //
    DlgChooser theChooser(this);
    theChooser.SetIsAccounts();
    // -----------------------------------------------
    mapIDName & the_map = theChooser.m_map;

    bool bFoundDefault = false;
    // -----------------------------------------------
    const int32_t acct_count = OTAPI_Wrap::GetAccountCount();
    // -----------------------------------------------
    for(int32_t ii = 0; ii < acct_count; ++ii)
    {
        //Get OT Acct ID
        QString OT_acct_id = QString::fromStdString(OTAPI_Wrap::GetAccountWallet_ID(ii));
        QString OT_acct_name("");
        // -----------------------------------------------
        if (!OT_acct_id.isEmpty())
        {
            if (!m_myAcctId.isEmpty() && (OT_acct_id == m_myAcctId))
                bFoundDefault = true;
            // -----------------------------------------------
            MTNameLookupQT theLookup;

            OT_acct_name = QString::fromStdString(theLookup.GetAcctName(OT_acct_id.toStdString()));
            // -----------------------------------------------
            the_map.insert(OT_acct_id, OT_acct_name);
        }
     }
    // -----------------------------------------------
    if (bFoundDefault && !m_myAcctId.isEmpty())
        theChooser.SetPreSelected(m_myAcctId);
    // -----------------------------------------------
    theChooser.setWindowTitle(tr("Select the Source Account"));
    // -----------------------------------------------
    if (theChooser.exec() == QDialog::Accepted)
    {
        qDebug() << QString("SELECT was clicked for AcctID: %1").arg(theChooser.m_qstrCurrentID);

        if (!theChooser.m_qstrCurrentID.isEmpty())
        {
            QString display_name("");
            QString from_button_text("");
            // -----------------------------------------
            m_myAcctId = theChooser.m_qstrCurrentID;
            // -----------------------------------------
            if (theChooser.m_qstrCurrentName.isEmpty())
                display_name = QString("");
            else
                display_name = theChooser.m_qstrCurrentName;
            // -----------------------------------------
            from_button_text = MTHome::FormDisplayLabelForAcctButton(m_myAcctId, display_name);
            // -----------------------------------------
            ui->fromButton->setText(from_button_text);
            // -----------------------------------------
            return;
        }
    }
    else
    {
      qDebug() << "CANCEL was clicked";
    }
    // -----------------------------------------------
    m_myAcctId = QString("");
    ui->fromButton->setText(tr("<Click to choose Account>"));
}
예제 #7
0
void MTCompose::dialog()
{
/** Compose Dialog **/

    if (!already_init)
    {
        connect(this,               SIGNAL(balancesChanged()),
                Moneychanger::It(), SLOT  (onBalancesChanged()));
        // ---------------------------------------
        this->setWindowTitle(tr("Compose: (no subject)"));

        QString style_sheet = "QPushButton{border: none; border-style: outset; text-align:left; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa);}"
                "QPushButton:pressed {border: 1px solid black; text-align:left; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa); }"
                "QPushButton:hover {border: 1px solid black; text-align:left; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa); }";

        ui->fromButton->setStyleSheet(style_sheet);
        ui->toButton->setStyleSheet(style_sheet);
        ui->serverButton->setStyleSheet(style_sheet);

        // Here if there is pre-set data for the subject, contents, to, from, server, etc
        // then we set it here.
        //

        // Also, need ability to pre-set server since we might be replying
        // to a mail, or messaging based on a transaction, in which case
        // the server is already known and should be used.
        //
        // Also, we need ability to juggle the server setting.
        // For example, if we have known servers for the recipient,
        // we will try to see if our default server is one of those.
        // If so, we use that. Otherwise we see if ALL servers for
        // OUR Nym contain at least one match with the recipient, and
        // use the first one found.
        // Either way, the list we use will be filtered by both Nyms,
        // the above is only for setting the initial state.
        //
        // Otherwise, if a match cannot be found, the list will contain
        // ALL known servers, with the default server selected.
        //
        // When sending to a Nym on a particular server he's NOT known to be
        // on, a warning message should be displayed first.



        // Todo.

        // -------------------------------------------
        std::string str_sender_name;
        // -------------------------------------------
        if (!m_senderNymId.isEmpty()) // senderNym was provided.
        {
            MTNameLookupQT theLookup;

            str_sender_name = theLookup.GetNymName(m_senderNymId.toStdString());

            if (str_sender_name.empty())
                str_sender_name = m_senderNymId.toStdString();
        }
        // -------------------------------------------
        if (str_sender_name.empty())
        {
            m_senderNymId = QString("");
            ui->fromButton->setText(tr("<Click to choose Sender>"));
        }
        else
            ui->fromButton->setText(QString::fromStdString(str_sender_name));
        // -------------------------------------------


        // -------------------------------------------
        std::string str_recipient_name;
        // -------------------------------------------
        if (!m_recipientNymId.isEmpty()) // recipientNym was provided.
        {
            MTNameLookupQT theLookup;

            str_recipient_name = theLookup.GetNymName(m_recipientNymId.toStdString());

            if (str_recipient_name.empty())
                str_recipient_name = m_recipientNymId.toStdString();
        }
        // -------------------------------------------
        if (str_recipient_name.empty())
        {
            m_recipientNymId = QString("");
            ui->toButton->setText(tr("<Click to choose Recipient>"));
        }
        else
            ui->toButton->setText(QString::fromStdString(str_recipient_name));
        // -------------------------------------------


        // -------------------------------------------
        std::string str_server_name;
        // -------------------------------------------
        if (!m_serverId.isEmpty()) // serverID was provided.
        {
            str_server_name = OTAPI_Wrap::It()->GetServer_Name(m_serverId.toStdString());

            if (str_server_name.empty())
                str_server_name = m_serverId.toStdString();
        }
        // -------------------------------------------
        if (str_server_name.empty())
        {
            m_serverId = QString("");
            ui->serverButton->setText(tr("<Click to choose Server>"));
        }
        else
            ui->serverButton->setText(QString::fromStdString(str_server_name));
        // -------------------------------------------




        // -------------------------------------------
        if (!m_subject.isEmpty())
        {
            QString qstrRe = tr("re:");

            QString qstrSubjectLeft = m_subject.left(qstrRe.size());

            if (qstrSubjectLeft.toLower() != qstrRe)
            {
                QString strTemp = QString("%1 %2").arg(qstrRe).arg(m_subject);
                m_subject = strTemp;
            }
            // -----------------------
            QString qstrTempSubject = m_subject;

            ui->subjectEdit->setText(qstrTempSubject);
            // -----------------------
            this->setWindowTitle(QString("%1: %2").arg(tr("Compose")).arg(qstrTempSubject));
        }
        // -------------------------------------------


        ui->contentsEdit->setFocus();


        /** Flag Already Init **/
        already_init = true;
    }

}
예제 #8
0
// 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();
}