void RegisterNameForm::newKey() { gpm::public_key_t pub; gpm::private_key_t priv; std::string gen = generate_address( pub, priv ); get_keychain().set( encode_address(pub), gpm::key_info( pub, priv ) ); get_keychain().sync(); m_ui->key_name->insertItem( 0, gen.c_str() ); }
void NewIdentityDialog::onUserNameChanged( const QString& name ) { if( name != QString() ) { auto pro = bts::application::instance()->get_profile(); auto keys = pro->get_keychain(); auto trim_name = fc::trim(name.toUtf8().constData()); auto ident_key = keys.get_identity_key( trim_name ); auto key_addr = /*bts::*/public_key_address( ident_key.get_public_key() ); ui->publickey->setText( std::string(key_addr).c_str() ); // make sure the key is unique.. try { bts::addressbook::wallet_identity cur_ident = pro->get_identity( trim_name ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); ui->status_label->setText( tr( "Status: You have already created this identity." ) ); } catch ( fc::key_not_found_exception& e ) { ui->status_label->setText( tr( "Status: Unknown" ) ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(true); } } else { ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); } }
void NewIdentityDialog::onSave() { auto trim_name = fc::trim(ui->username->text().toUtf8().constData()); bts::addressbook::wallet_identity ident; ident.first_name = fc::trim( ui->firstname->text().toUtf8().constData() ); ident.last_name = fc::trim( ui->lastname->text().toUtf8().constData() ); ident.mining_effort = ui->register_checkbox->isChecked(); ident.wallet_ident = fc::trim( ui->username->text().toUtf8().constData() ); ident.set_dac_id( ident.wallet_ident ); auto profile = bts::application::instance()->get_profile(); profile->store_identity( ident ); std::string dac_id_string = ident.wallet_ident; bts::addressbook::wallet_contact myself; myself.wallet_index = WALLET_INVALID_INDEX; myself.first_name = ident.first_name; myself.last_name = ident.last_name; myself.set_dac_id(ident.wallet_ident); auto priv_key = profile->get_keychain().get_identity_key(myself.dac_id_string); myself.public_key = priv_key.get_public_key(); // profile->get_addressbook()->store_contact(Contact(myself)); bts::application::instance()->add_receive_key(priv_key); TKeyhoteeApplication::getInstance()->getMainWindow()->getAddressBookModel()->storeContact( Contact(myself) ); }
void NewIdentityDialog::onSave() { //store new identity in profile auto app = bts::application::instance(); auto profile = app->get_profile(); auto trim_dac_id = fc::trim(ui->username->text().toUtf8().constData()); bts::addressbook::wallet_identity ident; ident.first_name = fc::trim( ui->firstname->text().toUtf8().constData() ); ident.last_name = fc::trim( ui->lastname->text().toUtf8().constData() ); ident.mining_effort = ui->register_checkbox->isChecked(); ident.wallet_ident = trim_dac_id; ident.set_dac_id( trim_dac_id ); auto priv_key = profile->get_keychain().get_identity_key(trim_dac_id); ident.public_key = priv_key.get_public_key(); profile->store_identity( ident ); try { app->mine_name(trim_dac_id, profile->get_keychain().get_identity_key(trim_dac_id).get_public_key(), ident.mining_effort); } catch ( const fc::exception& e ) { wlog( "${e}", ("e",e.to_detail_string()) ); } //store contact for new identity bts::addressbook::wallet_contact myself; //copy common fields from new identity into contact static_cast<bts::addressbook::contact&>(myself) = ident; //fill in remaining fields for contact myself.first_name = ident.first_name; myself.last_name = ident.last_name; // profile->get_addressbook()->store_contact(Contact(myself)); TKeyhoteeApplication::getInstance()->getMainWindow()->getAddressBookModel()->storeContact( Contact(myself) ); app->add_receive_key(priv_key); }
void NewIdentityDialog::onUserNameChanged( const QString& name ) { if( name.trimmed() != QString() ) { auto pro = bts::application::instance()->get_profile(); auto keys = pro->get_keychain(); auto trim_name = fc::trim(name.toUtf8().constData()); auto ident_key = keys.get_identity_key( trim_name ); auto key_addr = /*bts::*/public_key_address( ident_key.get_public_key() ); ui->publickey->setText( std::string(key_addr).c_str() ); // make sure the key is unique.. try { bts::addressbook::wallet_identity cur_ident = pro->get_identity( trim_name ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); ui->status_label->setStyleSheet("QLabel { color : red; }"); if (cur_ident.dac_id_string == trim_name) ui->status_label->setText( tr( "Status: You have already created this identity." ) ); else ui->status_label->setText( tr( "Status: You have already created a similar id." ) ); } catch ( fc::key_not_found_exception& ) { fc::optional<bts::bitname::name_record> current_record = bts::application::instance()->lookup_name(trim_name); if(current_record) { ui->status_label->setStyleSheet("QLabel { color : red; }"); ui->status_label->setText(tr("Status: This Keyhotee ID was already registered by someone else.")); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); } else { ui->status_label->setStyleSheet("QLabel { color : black; }"); ui->status_label->setText( tr( "Status: Unknown" ) ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(true); } } catch ( fc::assert_exception& ) { ui->status_label->setStyleSheet("QLabel { color : red; }"); ui->status_label->setText(tr("Status: Invalid ID. This ID cannot be registered.")); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); } } else { ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); } }
void ContactView::sendChatMessage() { auto msg = ui->chat_input->toPlainText(); if (msg.size() != 0) { auto app = bts::application::instance(); auto profile = app->get_profile(); auto idents = profile->identities(); bts::bitchat::private_text_message text_msg(msg.toUtf8().constData() ); if (idents.size() ) { fc::ecc::private_key my_priv_key = profile->get_keychain().get_identity_key(idents[0].dac_id_string); app->send_text_message(text_msg, _current_contact.public_key, my_priv_key); appendChatMessage("me", msg); } ui->chat_input->setPlainText(QString()); } }
profile_ptr application::load_profile( const std::string& password ) { try { FC_ASSERT( my->_config ); // note: stored in temp incase open throws. auto tmp_profile = std::make_shared<profile>(); tmp_profile->open( my->_profile_dir / "default", password ); std::vector<fc::ecc::private_key> recv_keys; auto keychain = tmp_profile->get_keychain(); std::vector<identity> idents = tmp_profile->identities(); for( auto itr = idents.begin(); itr != idents.end(); ++itr ) { recv_keys.push_back( keychain.get_identity_key( itr->dac_id ) ); } my->_bitchat_client->set_receive_keys( recv_keys ); return my->_profile = tmp_profile; } FC_RETHROW_EXCEPTIONS( warn, "" ) }
fc::string register_key_on_server(const QString& keyhotee_id, const QString& key) { fc::string trimmed_keyhotee_id = keyhotee_id.trimmed().toStdString(); fc::string trimmed_key = key.trimmed().toStdString(); auto pro = bts::application::instance()->get_profile(); auto keys = pro->get_keychain(); auto ident_key = keys.get_identity_key( trimmed_keyhotee_id ); std::string key_addr = public_key_address( ident_key.get_public_key() ); fc::tcp_socket_ptr sock = std::make_shared<fc::tcp_socket>(); sock->connect_to( fc::ip::endpoint( fc::ip::address("162.243.67.4"), 3879 ) ); fc::buffered_istream_ptr isock = std::make_shared<fc::buffered_istream>(sock); fc::buffered_ostream_ptr osock = std::make_shared<fc::buffered_ostream>(sock); fc::rpc::json_connection_ptr con = std::make_shared<fc::rpc::json_connection>( isock, osock ); con->exec(); auto result = con->async_call( "register_key", trimmed_keyhotee_id, trimmed_key, key_addr ).wait(); auto points = result.get_object()["points"].as_string(); auto pub = result.get_object()["pub_key"].as_string(); return points; }
void ContactsTable::onDeleteContact() { //remove selected contacts from inbox model (and database) QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->contact_table->model()); //model->setUpdatesEnabled(false); QItemSelectionModel* selection_model = ui->contact_table->selectionModel(); QModelIndexList sortFilterIndexes = selection_model->selectedRows(); if (sortFilterIndexes.count() == 0) return; if (QMessageBox::question(this, tr("Delete Contact"), tr("Are you sure you want to delete selected contact(s)?")) == QMessageBox::Button::No) return; QModelIndexList indexes; for(const QModelIndex& sortFilterIndex : sortFilterIndexes) indexes.append(model->mapToSource(sortFilterIndex)); qSort(indexes); auto sourceModel = model->sourceModel(); auto app = bts::application::instance(); auto profile = app->get_profile(); for (int i = indexes.count() - 1; i > -1; --i) { auto contact_id = ((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).wallet_index; if(profile->isIdentityPresent(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string)) { auto priv_key = profile->get_keychain().get_identity_key(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string); app->remove_receive_key(priv_key); profile->removeIdentity(((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).dac_id_string); /// notify identity observers IdentityObservable::getInstance().notify(); } sourceModel->removeRows(indexes.at(i).row(), 1); Q_EMIT contactDeleted(contact_id); //emit signal so that ContactGui is also deleted } //model->setUpdatesEnabled(true); //TODO Remove fullname/bitname for deleted contacts from QCompleter qSort(sortFilterIndexes); selectNextRow(sortFilterIndexes.takeLast().row(), indexes.count()); }
void NewIdentityDialog::onKey( const QString& key ) { try { auto pro = bts::application::instance()->get_profile(); auto keys = pro->get_keychain(); auto trim_name = fc::trim(ui->username->text().toStdString()); auto ident_key = keys.get_identity_key( trim_name ); std::string key_addr = public_key_address( ident_key.get_public_key() ); fc::tcp_socket_ptr sock = std::make_shared<fc::tcp_socket>(); sock->connect_to( fc::ip::endpoint( fc::ip::address("162.243.67.4"), 3879 ) ); fc::buffered_istream_ptr isock = std::make_shared<fc::buffered_istream>(sock); fc::buffered_ostream_ptr osock = std::make_shared<fc::buffered_ostream>(sock); fc::rpc::json_connection_ptr con = std::make_shared<fc::rpc::json_connection>( isock, osock ); con->exec(); auto trim_key = key.trimmed(); auto result = con->async_call( "register_key", trim_name, trim_key.toStdString(), key_addr ).wait(); auto points = result.get_object()["points"].as_string(); auto pub = result.get_object()["pub_key"].as_string(); fc::usleep(fc::seconds(1)); ui->status_label->setText( ("Status: Registered with " + points + " points").c_str() ); } catch ( fc::eof_exception& ) { } catch ( fc::exception& e ) { ui->status_label->setText( ("Status: Error Registering Founder ID: " + e.to_detail_string()).c_str() ); } catch ( ... ) { ui->status_label->setText( "Status: Error Registering Founder ID" ); } }
KeyhoteeMainWindow::KeyhoteeMainWindow(const TKeyhoteeApplication& mainApp) : ATopLevelWindowsContainer(), MailProcessor(*this, bts::application::instance()->get_profile()) { ui.reset(new Ui::KeyhoteeMainWindow() ); ui->setupUi(this); setWindowIcon(QIcon(":/images/shield1024.png") ); QString title = QString("%1 (%2)").arg(mainApp.getAppName().c_str()).arg(mainApp.getLoadedProfileName().c_str()); setWindowTitle(title); connect(ui->contacts_page, &ContactsTable::contactOpened, this, &KeyhoteeMainWindow::openContactGui); connect(ui->contacts_page, &ContactsTable::contactDeleted, this, &KeyhoteeMainWindow::deleteContactGui); #ifdef Q_OS_MAC //QMacNativeToolBar* native_toolbar = QtMacExtras::setNativeToolBar(ui->toolbar, true); QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); ui->side_bar->setAttribute(Qt::WA_MacShowFocusRect, 0); QApplication::setWindowIcon(QIcon(":/images/shield1024.icns") ); #else QApplication::setWindowIcon(QIcon(":/images/shield1024.png") ); #endif setupStatusBar(); QWidget* empty = new QWidget(); empty->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); ui->toolbar->addWidget(empty); _search_edit = new QLineEdit(ui->toolbar); ui->toolbar->addWidget(_search_edit); _search_edit->setMaximumSize(QSize(150, 22) ); _search_edit->setAttribute(Qt::WA_MacShowFocusRect, 0); const char* search_style = "QLineEdit { " \ "padding-right: 20px; " \ "padding-left: 5px; " \ "background: url(:/images/search24x16.png);" \ "background-position: right;" \ "background-repeat: no-repeat;" \ "border: 1px solid gray;" \ "border-radius: 10px;}"; _search_edit->setStyleSheet(search_style); _search_edit->setPlaceholderText(tr("Search") ); QWidget* empty2 = new QWidget(); empty->resize(QSize(10, 10) ); ui->toolbar->addWidget(empty2); ui->actionEnable_Mining->setEnabled(gMiningIsPossible); ui->actionEnable_Mining->setVisible(gMiningIsPossible); ui->side_bar->setModificationsChecker (this); // ---------------------- MenuBar // File connect(ui->actionExit, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionExit_triggered); // Edit connect(ui->actionCopy, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionCopy_triggered); connect(ui->actionCut, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionCut_triggered); connect(ui->actionPaste, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionPaste_triggered); connect(ui->actionSelect_All, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionSelectAll_triggered); connect(ui->actionDelete, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionDelete_triggered); // Identity connect(ui->actionNew_identity, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionNew_identity_triggered); connect(ui->actionEnable_Mining, &QAction::toggled, this, &KeyhoteeMainWindow::enableMining_toggled); // Mail connect(ui->actionNew_Message, &QAction::triggered, this, &KeyhoteeMainWindow::newMailMessage); connect(ui->actionReply, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionReply_triggered); connect(ui->actionReply_all, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionReply_all_triggered); connect(ui->actionForward, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionForward_triggered); connect(ui->actionSave_attachement, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionSave_attachement_triggered); // Contact connect(ui->actionNew_Contact, &QAction::triggered, this, &KeyhoteeMainWindow::addContact); connect(ui->actionSet_Icon, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionset_Icon_triggered); connect(ui->actionShow_Contacts, &QAction::triggered, this, &KeyhoteeMainWindow::showContacts); // Help connect(ui->actionDiagnostic, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionDiagnostic_triggered); connect(ui->actionAbout, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionAbout_triggered); connect(ui->splitter, &QSplitter::splitterMoved, this, &KeyhoteeMainWindow::sideBarSplitterMoved); connect(ui->side_bar, &TreeWidgetCustom::itemSelectionChanged, this, &KeyhoteeMainWindow::onSidebarSelectionChanged); connect(ui->side_bar, &TreeWidgetCustom::itemDoubleClicked, this, &KeyhoteeMainWindow::onSidebarDoubleClicked); connect(ui->side_bar, &TreeWidgetCustom::itemContactRemoved, this, &KeyhoteeMainWindow::onItemContactRemoved); //connect( _search_edit, SIGNAL(textChanged(QString)), this, SLOT(searchEditChanged(QString)) ); connect(_search_edit, &QLineEdit::textChanged, this, &KeyhoteeMainWindow::searchEditChanged); auto space2 = ui->side_bar->topLevelItem(TopLevelItemIndexes::Space2); auto space3 = ui->side_bar->topLevelItem(TopLevelItemIndexes::Space3); auto space_flags = space2->flags() & (~Qt::ItemFlags(Qt::ItemIsSelectable) ); space_flags |= Qt::ItemNeverHasChildren; space2->setFlags(space_flags); space3->setFlags(space_flags); //_identities_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Identities); _mailboxes_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Mailboxes); _contacts_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Contacts); _wallets_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Wallets); _contacts_root->setExpanded(true); //_identities_root->setExpanded(true); _mailboxes_root->setExpanded(true); _inbox_root = _mailboxes_root->child(Inbox); _drafts_root = _mailboxes_root->child(Drafts); _sent_root = _mailboxes_root->child(Sent); _wallets_root->setExpanded(true); _bitcoin_root = _wallets_root->child(Bitcoin); _bitshares_root = _wallets_root->child(BitShares); _litecoin_root = _wallets_root->child(Litecoin); auto app = bts::application::instance(); app->set_application_delegate(this); auto profile = app->get_profile(); auto idents = profile->identities(); auto addressbook = profile->get_addressbook(); _addressbook_model = new AddressBookModel(this, addressbook); _inbox_model = new MailboxModel(this, profile, profile->get_inbox_db(), *_addressbook_model); _draft_model = new MailboxModel(this, profile, profile->get_draft_db(), *_addressbook_model); _pending_model = new MailboxModel(this, profile, profile->get_pending_db(), *_addressbook_model); _sent_model = new MailboxModel(this, profile, profile->get_sent_db(), *_addressbook_model); connect(_addressbook_model, &QAbstractItemModel::dataChanged, this, &KeyhoteeMainWindow::addressBookDataChanged); MailEditor::setContactCompleter(_addressbook_model->getContactCompleter() ); ui->contacts_page->setAddressBook(_addressbook_model); ui->new_contact->setAddressBook(_addressbook_model); ui->inbox_page->initial(MailProcessor, _inbox_model, Mailbox::Inbox, this); ui->draft_box_page->initial(MailProcessor, _draft_model, Mailbox::Drafts, this); ui->sent_box_page->initial(MailProcessor, _sent_model, Mailbox::Sent, this); ui->widget_stack->setCurrentWidget(ui->inbox_page); connect(ui->actionDelete, SIGNAL(triggered()), ui->inbox_page, SLOT(onDeleteMail())); connect(ui->actionShow_details, SIGNAL(toggled(bool)), ui->inbox_page, SLOT(on_actionShow_details_toggled(bool))); wlog("idents: ${idents}", ("idents", idents) ); for (size_t i = 0; i < idents.size(); ++i) { try { app->mine_name(idents[i].dac_id_string, profile->get_keychain().get_identity_key(idents[i].dac_id_string).get_public_key(), idents[i].mining_effort); } catch ( const fc::exception& e ) { wlog( "${e}", ("e",e.to_detail_string()) ); } } app->set_mining_intensity(0); ui->actionEnable_Mining->setChecked(app->get_mining_intensity() != 0); _addressbook = profile->get_addressbook(); /* auto abook = profile->get_addressbook(); auto contacts = abook->get_known_bitnames(); for( auto itr = contacts.begin(); itr != contacts.end(); ++itr ) { auto new_contact_item = new QTreeWidgetItem(_contacts_root, (QTreeWidgetItem::ItemType)ContactItem ); auto id_rec = app->lookup_name( *itr ); if( !id_rec ) { new_contact_item->setText( 0, (*itr + " [unknown]").c_str() ); } else { new_contact_item->setText( 0, (*itr + " [" + std::to_string(id_rec->repute)+"]" ).c_str() ); } } */ QString settings_file = "keyhotee_"; settings_file.append(mainApp.getLoadedProfileName().c_str()); setSettingsFile(settings_file); readSettings(); QAction* actionMenu = new QAction(tr("Keyhotee"), this); actionMenu->setCheckable(true); this->setMenuWindow(ui->menuWindow); this->registration(actionMenu); }
void NewIdentityDialog::onSave() { //store new identity in profile auto app = bts::application::instance(); auto profile = app->get_profile(); auto trimmed_dac_id = ui->username->text().trimmed(); fc::string dac_id = trimmed_dac_id.toStdString(); // make sure the key is unique.. try { bts::addressbook::wallet_identity cur_ident = profile->get_identity( dac_id ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); ui->status_label->setStyleSheet("QLabel { color : red; }"); ui->publickey->setText( "" ); if (cur_ident.dac_id_string == dac_id) ui->status_label->setText( tr( "Status: You have already created this identity." ) ); else ui->status_label->setText( tr( "Status: You have already created a similar id." ) ); return; } catch ( fc::key_not_found_exception& ) { fc::optional<bts::bitname::name_record> current_record = bts::application::instance()->lookup_name(dac_id); if(current_record) { ui->status_label->setStyleSheet("QLabel { color : red; }"); ui->status_label->setText(tr("Status: This Keyhotee ID was already registered by someone else.")); ui->publickey->setText( "" ); ui->buttonBox->button( QDialogButtonBox::Save )->setEnabled(false); return; } } bts::addressbook::wallet_identity ident; ident.first_name = fc::trim( ui->firstname->text().toUtf8().constData() ); ident.last_name = fc::trim( ui->lastname->text().toUtf8().constData() ); ident.mining_effort = ui->register_checkbox->isChecked() ? 25.0 : 0.0; ident.wallet_ident = dac_id; ident.set_dac_id( dac_id ); auto priv_key = profile->get_keychain().get_identity_key(dac_id); ident.public_key = priv_key.get_public_key(); profile->store_identity( ident ); /// notify identity observers IdentityObservable::getInstance().notify(); try { app->mine_name(dac_id, profile->get_keychain().get_identity_key(dac_id).get_public_key(), ident.mining_effort); } catch ( const fc::exception& e ) { wlog( "${e}", ("e",e.to_detail_string()) ); } //store contact for new identity bts::addressbook::wallet_contact myself; //copy common fields from new identity into contact static_cast<bts::addressbook::contact&>(myself) = ident; //fill in remaining fields for contact myself.first_name = ident.first_name; myself.last_name = ident.last_name; #ifdef ALPHA_RELEASE //just store the founder code here so we can access it over in ContactView temporarily for alpha release myself.notes = ui->founder_code->text().toStdString(); #endif TKeyhoteeApplication::getInstance()->getMainWindow()->getAddressBookModel()->storeContact( Contact(myself) ); app->add_receive_key(priv_key); //re-connect to mail server to send an updated sync_time (get past mail for identities) if history should be downloaded int days_in_past_to_fetch = ui->downloadHistory->currentData().toInt(); if (days_in_past_to_fetch != 0) { fc::time_point sync_time; if (days_in_past_to_fetch != -1) sync_time = fc::time_point::now() - fc::days(days_in_past_to_fetch); //if requested sync time further in the past than last sync time, change last_sync_time if (sync_time < profile->get_last_sync_time()) profile->set_last_sync_time(sync_time); app->connect_to_network(); } emit identityadded(); }
KeyhoteeMainWindow::KeyhoteeMainWindow() : SelfSizingMainWindow() { ui.reset( new Ui::KeyhoteeMainWindow() ); ui->setupUi(this); setWindowIcon( QIcon( ":/images/shield1024.png" ) ); if (gProfile_name != "default") { QString title =QString("%1 (%2)").arg(gApplication_name.c_str()).arg(gProfile_name.c_str()); setWindowTitle( title ); } connect( ui->contacts_page, &ContactsTable::contactOpened, this, &KeyhoteeMainWindow::openContactGui ); #ifdef Q_OS_MAC //QMacNativeToolBar* native_toolbar = QtMacExtras::setNativeToolBar(ui->toolbar, true); QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); ui->side_bar->setAttribute(Qt::WA_MacShowFocusRect, 0); QApplication::setWindowIcon( QIcon( ":/images/shield1024.icns" ) ); #else QApplication::setWindowIcon( QIcon( ":/images/shield1024.png" ) ); #endif QWidget* empty = new QWidget(); empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); ui->toolbar->addWidget(empty); _search_edit = new QLineEdit( ui->toolbar ); ui->toolbar->addWidget(_search_edit); _search_edit->setMaximumSize( QSize( 150, 22 ) ); _search_edit->setAttribute(Qt::WA_MacShowFocusRect, 0); const char* search_style = "QLineEdit { "\ "padding-right: 20px; "\ "padding-left: 5px; "\ "background: url(:/images/search24x16.png);"\ "background-position: right;"\ "background-repeat: no-repeat;"\ "border: 1px solid gray;"\ "border-radius: 10px;}"; _search_edit->setStyleSheet( search_style ); _search_edit->setPlaceholderText( tr("Search") ); QWidget* empty2 = new QWidget(); empty->resize( QSize(10,10) ); ui->toolbar->addWidget(empty2); ui->actionEnable_Mining->setEnabled(gMiningIsPossible); ui->actionEnable_Mining->setVisible(gMiningIsPossible); connect( ui->actionExit, &QAction::triggered, this, &KeyhoteeMainWindow::on_actionExit_triggered ); connect( ui->actionNew_Message, &QAction::triggered, this, &KeyhoteeMainWindow::newMailMessage ); connect( ui->actionEnable_Mining, &QAction::toggled, this, &KeyhoteeMainWindow::enableMining_toggled ); connect( ui->actionNew_Contact, &QAction::triggered, this, &KeyhoteeMainWindow::addContact ); connect( ui->actionShow_Contacts, &QAction::triggered, this, &KeyhoteeMainWindow::showContacts ); connect( ui->splitter, &QSplitter::splitterMoved, this, &KeyhoteeMainWindow::sideBarSplitterMoved ); connect( ui->side_bar, &QTreeWidget::itemSelectionChanged, this, &KeyhoteeMainWindow::onSidebarSelectionChanged ); //connect( _search_edit, SIGNAL(textChanged(QString)), this, SLOT(searchEditChanged(QString)) ); connect( _search_edit, &QLineEdit::textChanged, this, &KeyhoteeMainWindow::searchEditChanged ); auto space2 = ui->side_bar->topLevelItem(TopLevelItemIndexes::Space2); auto space3 = ui->side_bar->topLevelItem(TopLevelItemIndexes::Space3); auto space_flags = space2->flags() & (~ Qt::ItemFlags(Qt::ItemIsSelectable) ); space_flags |= Qt::ItemNeverHasChildren; space2->setFlags( space_flags ); space3->setFlags( space_flags ); //_identities_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Identities); _mailboxes_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Mailboxes); _contacts_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Contacts); _wallets_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Wallets); _contacts_root->setExpanded(true); //_identities_root->setExpanded(true); _mailboxes_root->setExpanded(true); _inbox_root = _mailboxes_root->child(Inbox); _drafts_root = _mailboxes_root->child(Drafts); _sent_root = _mailboxes_root->child(Sent); _wallets_root->setExpanded(true); auto app = bts::application::instance(); app->set_application_delegate( this ); auto profile = app->get_profile(); auto idents = profile->identities(); _inbox_model = new MailboxModel(this,profile,profile->get_inbox_db()); _draft_model = new MailboxModel(this,profile,profile->get_draft_db()); _pending_model = new MailboxModel(this,profile,profile->get_pending_db()); _sent_model = new MailboxModel(this,profile,profile->get_sent_db()); auto addressbook = profile->get_addressbook(); _addressbook_model = new AddressBookModel( this, addressbook ); connect( _addressbook_model, &QAbstractItemModel::dataChanged, this, &KeyhoteeMainWindow::addressBookDataChanged ); MailEditor::setContactCompleter( _addressbook_model->getContactCompleter() ); ui->contacts_page->setAddressBook(_addressbook_model); ui->new_contact->setAddressBook(_addressbook_model); ui->inbox_page->setModel(_inbox_model, Mailbox::Inbox); ui->draft_box_page->setModel(_draft_model, Mailbox::Drafts); ui->sent_box_page->setModel(_sent_model, Mailbox::Sent); wlog( "idents: ${idents}", ("idents",idents) ); for( size_t i = 0; i < idents.size(); ++i ) { /* auto new_ident_item = new QTreeWidgetItem(_identities_root, (QTreeWidgetItem::ItemType)IdentityItem ); auto id_rec = app->lookup_name( idents[i].bit_id ); if( !id_rec ) { new_ident_item->setText( 0, (idents[i].bit_id + " [pending]").c_str() ); } else { new_ident_item->setText( 0, (idents[i].bit_id + " [" + std::to_string(id_rec->repute)+"]" ).c_str() ); } */ app->mine_name( idents[i].dac_id, profile->get_keychain().get_identity_key( idents[i].dac_id ).get_public_key(), idents[i].mining_effort ); } app->set_mining_intensity(100); ui->actionEnable_Mining->setChecked(app->get_mining_intensity() != 0); _addressbook = profile->get_addressbook(); /* auto abook = profile->get_addressbook(); auto contacts = abook->get_known_bitnames(); for( auto itr = contacts.begin(); itr != contacts.end(); ++itr ) { auto new_contact_item = new QTreeWidgetItem(_contacts_root, (QTreeWidgetItem::ItemType)ContactItem ); auto id_rec = app->lookup_name( *itr ); if( !id_rec ) { new_contact_item->setText( 0, (*itr + " [unknown]").c_str() ); } else { new_contact_item->setText( 0, (*itr + " [" + std::to_string(id_rec->repute)+"]" ).c_str() ); } } */ QString settings_file = "keyhotee_"; settings_file.append(gProfile_name.c_str()); setSettingsFile(settings_file); readSettings(); }