Example #1
0
void ProfileWizard::createProfile(int result)
{
  if (_profile_edit->isComplete() )
  {
    bts::profile_config conf;
    conf.firstname  = _profile_edit->ui.first_name->text().toUtf8().constData();
    conf.firstname  = fc::trim( conf.firstname );
    conf.middlename = _profile_edit->ui.middle_name->text().toUtf8().constData();
    conf.middlename = fc::trim( conf.middlename );
    conf.lastname   = _profile_edit->ui.last_name->text().toUtf8().constData();
    conf.lastname   = fc::trim( conf.lastname );
    conf.brainkey   = _profile_edit->ui.brainkey->text().toUtf8().constData();
    conf.brainkey   = fc::trim( conf.brainkey );

    std::string                      password = _profile_edit->ui.local_password1->text().toUtf8().constData();

    std::string profile_name         = conf.firstname + " " + conf.lastname;
    auto                             app = bts::application::instance();
    fc::thread* main_thread = &fc::thread::current();
    QProgressBar* progress = new QProgressBar();
    progress->setWindowTitle( "Creating Profile" );
    progress->setMaximum(1000);
    progress->resize( 640, 20 );
    progress->show();
    auto                             profile = app->create_profile(profile_name, conf, password, 
                                               [=]( double p )
                                               {
                                                  main_thread->async( [=](){ 
                                                                      progress->setValue( 1000*p );
                                                                      qApp->sendPostedEvents();
                                                                      qApp->processEvents();
                                                                      if( p >= 1.0 ) progress->deleteLater();
                                                                      } ).wait();
                                               }
                                               );
    assert(profile != nullptr);

    //store myself as contact
  /*
    std::string dac_id_string = _nym_page->_profile_nym_ui.keyhotee_id->text().toStdString();
    bts::addressbook::wallet_contact myself;
    myself.wallet_index = 0;
    myself.first_name = conf.firstname;
    myself.last_name = conf.lastname;
    myself.set_dac_id(dac_id_string);
    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(myself);

    //store myself as identity
    bts::addressbook::wallet_identity new_identity;
    static_cast<bts::addressbook::contact&>(new_identity) = myself;
    profile->store_identity(new_identity);

    bts::application::instance()->add_receive_key(priv_key);
    */

    _mainApp.displayMainWindow();
  }
}
void ProgressListDelegate::updateItemWidgets(const QList<QWidget*> widgets,
        const QStyleOptionViewItem &option,
        const QPersistentModelIndex &index) const
{
    if (!index.isValid()) {
        return;
    }

    QPushButton *pauseResumeButton = static_cast<QPushButton*>(widgets[0]);

    QPushButton *cancelButton = static_cast<QPushButton*>(widgets[1]);
    cancelButton->setToolTip(i18n("Cancel"));

    QProgressBar *progressBar = static_cast<QProgressBar*>(widgets[2]);
    QPushButton *clearButton = static_cast<QPushButton*>(widgets[3]);

    int percent = d->getPercent(index);

    cancelButton->setVisible(percent < 100);
    pauseResumeButton->setVisible(percent < 100);
    clearButton->setVisible(percent > 99);

    KJob::Capabilities capabilities = (KJob::Capabilities) index.model()->data(index, JobView::Capabilities).toInt();
    cancelButton->setEnabled(capabilities & KJob::Killable);
    pauseResumeButton->setEnabled(capabilities & KJob::Suspendable);


    JobView::JobState state = (JobView::JobState) index.model()->data(index, JobView::State).toInt();
    switch (state) {
    case JobView::Running:
        pauseResumeButton->setToolTip(i18n("Pause"));
        pauseResumeButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-pause")));
        break;
    case JobView::Suspended:
        pauseResumeButton->setToolTip(i18n("Resume"));
        pauseResumeButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start")));
        break;
    default:
        Q_ASSERT(0);
        break;
    }

    QSize progressBarButtonSizeHint;



    if (percent < 100) {
        QSize cancelButtonSizeHint = cancelButton->sizeHint();

        cancelButton->move(option.rect.width() - d->separatorPixels - cancelButtonSizeHint.width(),
                           option.rect.height() - d->separatorPixels - cancelButtonSizeHint.height());

        QSize pauseResumeButtonSizeHint = pauseResumeButton->sizeHint();


        pauseResumeButton->move(option.rect.width() - d->separatorPixels * 2 - pauseResumeButtonSizeHint.width() - cancelButtonSizeHint.width(),
                                option.rect.height() - d->separatorPixels - pauseResumeButtonSizeHint.height());

        progressBarButtonSizeHint = pauseResumeButtonSizeHint;
    } else {
        progressBarButtonSizeHint = clearButton->sizeHint();
        clearButton->resize(progressBarButtonSizeHint);

        clearButton->move(option.rect.width() - d->separatorPixels - progressBarButtonSizeHint.width(),
                          option.rect.height() - d->separatorPixels - progressBarButtonSizeHint.height());
    }
    progressBar->setValue(percent);

    QFontMetrics fm(QApplication::font());
    QSize progressBarSizeHint = progressBar->sizeHint();

    progressBar->resize(QSize(option.rect.width() - d->getCurrentLeftMargin(fm.height()) - d->rightMargin, progressBarSizeHint.height()));

    progressBar->move(d->getCurrentLeftMargin(fm.height()),
                      option.rect.height() - d->separatorPixels * 2 - progressBarButtonSizeHint.height() - progressBarSizeHint.height());
}