Esempio n. 1
0
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);
}
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();

}
Esempio n. 4
0
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();
}