bool MainWindow::loginWithPassword(MojangAccountPtr account, const QString &errorMsg) { EditAccountDialog passDialog(errorMsg, this, EditAccountDialog::PasswordField); if (passDialog.exec() == QDialog::Accepted) { // To refresh the token, we just create an authenticate task with the given account and // the user's password. ProgressDialog progDialog(this); auto task = account->login(passDialog.password()); progDialog.exec(task.get()); if (task->successful()) return true; else { // If the authentication task failed, recurse with the task's error message. return loginWithPassword(account, task->failReason()); } } return false; }
void AccountListDialog::addAccount(const QString& errMsg) { // TODO: We can use the login dialog for this for now, but we'll have to make something better for it eventually. EditAccountDialog loginDialog(errMsg, this, EditAccountDialog::UsernameField | EditAccountDialog::PasswordField); loginDialog.exec(); if (loginDialog.result() == QDialog::Accepted) { QString username(loginDialog.username()); QString password(loginDialog.password()); MojangAccountPtr account = MojangAccountPtr(new MojangAccount(username)); ProgressDialog progDialog(this); AuthenticateTask authTask(account, password, &progDialog); if (progDialog.exec(&authTask)) { // Add the authenticated account to the accounts list. MojangAccountPtr account = authTask.getMojangAccount(); m_accounts->addAccount(account); // Grab associated player skins auto job = new NetJob("Player skins: " + account->username()); for(AccountProfile profile : account->profiles()) { auto meta = MMC->metacache()->resolveEntry("skins", profile.name() + ".png"); auto action = CacheDownload::make( QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name() + ".png"), meta); job->addNetAction(action); meta->stale = true; } job->start(); } } }
void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler) { if (!m_selectedInstance) return; // Find an account to use. std::shared_ptr<MojangAccountList> accounts = MMC->accounts(); MojangAccountPtr account = accounts->activeAccount(); if (accounts->count() <= 0) { // Tell the user they need to log in at least one account in order to play. auto reply = CustomMessageBox::selectable( this, tr("No Accounts"), tr("In order to play Minecraft, you must have at least one Mojang or Minecraft " "account logged in to MultiMC." "Would you like to open the account manager to add an account now?"), QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec(); if (reply == QMessageBox::Yes) { // Open the account manager. on_actionManageAccounts_triggered(); } } else if (account.get() == nullptr) { // If no default account is set, ask the user which one to use. AccountSelectDialog selectDialog(tr("Which account would you like to use?"), AccountSelectDialog::GlobalDefaultCheckbox, this); selectDialog.exec(); // Launch the instance with the selected account. account = selectDialog.selectedAccount(); // If the user said to use the account as default, do that. if (selectDialog.useAsGlobalDefault() && account.get() != nullptr) accounts->setActiveAccount(account->username()); } // if no account is selected, we bail if (!account.get()) return; // we try empty password first :) QString password; // we loop until the user succeeds in logging in or gives up bool tryagain = true; // the failure. the default failure. QString failReason = tr("Your account is currently not logged in. Please enter " "your password to log in again."); while (tryagain) { AuthSessionPtr session(new AuthSession()); session->wants_online = online; auto task = account->login(session, password); if (task) { // We'll need to validate the access token to make sure the account // is still logged in. ProgressDialog progDialog(this); if (online) progDialog.setSkipButton(true, tr("Play Offline")); progDialog.exec(task.get()); if (!task->successful()) { failReason = task->failReason(); } } switch (session->status) { case AuthSession::Undetermined: { QLOG_ERROR() << "Received undetermined session status during login. Bye."; tryagain = false; break; } case AuthSession::RequiresPassword: { EditAccountDialog passDialog(failReason, this, EditAccountDialog::PasswordField); if (passDialog.exec() == QDialog::Accepted) { password = passDialog.password(); } else { tryagain = false; } break; } case AuthSession::PlayableOffline: { // we ask the user for a player name bool ok = false; QString usedname = session->player_name; QString name = QInputDialog::getText(this, tr("Player name"), tr("Choose your offline mode player name."), QLineEdit::Normal, session->player_name, &ok); if (!ok) { tryagain = false; break; } if (name.length()) { usedname = name; } session->MakeOffline(usedname); // offline flavored game from here :3 } case AuthSession::PlayableOnline: { // update first if the server actually responded if (session->auth_server_online) { updateInstance(m_selectedInstance, session, profiler); } else { launchInstance(m_selectedInstance, session, profiler); } tryagain = false; } } } }
void MainWindow::doLaunch() { if (!m_selectedInstance) return; // Find an account to use. std::shared_ptr<MojangAccountList> accounts = MMC->accounts(); MojangAccountPtr account = accounts->activeAccount(); if (accounts->count() <= 0) { // Tell the user they need to log in at least one account in order to play. auto reply = CustomMessageBox::selectable( this, tr("No Accounts"), tr("In order to play Minecraft, you must have at least one Mojang or Minecraft " "account logged in to MultiMC." "Would you like to open the account manager to add an account now?"), QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec(); if (reply == QMessageBox::Yes) { // Open the account manager. on_actionManageAccounts_triggered(); } } else if (account.get() == nullptr) { // If no default account is set, ask the user which one to use. AccountSelectDialog selectDialog(tr("Which account would you like to use?"), AccountSelectDialog::GlobalDefaultCheckbox, this); selectDialog.exec(); // Launch the instance with the selected account. account = selectDialog.selectedAccount(); // If the user said to use the account as default, do that. if (selectDialog.useAsGlobalDefault() && account.get() != nullptr) accounts->setActiveAccount(account->username()); } // if no account is selected, we bail if (!account.get()) return; QString failReason = tr("Your account is currently not logged in. Please enter " "your password to log in again."); // do the login. if the account has an access token, try to refresh it first. if (account->accountStatus() != NotVerified) { // We'll need to validate the access token to make sure the account is still logged in. ProgressDialog progDialog(this); progDialog.setSkipButton(true, tr("Play Offline")); auto task = account->login(); progDialog.exec(task.get()); auto status = account->accountStatus(); if (status != NotVerified) { updateInstance(m_selectedInstance, account); } else { if (!task->successful()) { failReason = task->failReason(); } if (loginWithPassword(account, failReason)) updateInstance(m_selectedInstance, account); } // in any case, revert from online to verified. account->downgrade(); } else { if (loginWithPassword(account, failReason)) { updateInstance(m_selectedInstance, account); account->downgrade(); } // in any case, revert from online to verified. account->downgrade(); } }
void TrajVideoMaker::makeVideo(GLWidget *widget, QString workDirectory, QString videoFileName) { if (!workDirectory.endsWith('/')) workDirectory += '/'; // check widget is okay if (!widget) { QMessageBox::warning( NULL, QObject::tr( "Avogadro" ), QObject::tr( "GL widget was not correctly initialized in order to make a video" )); return; } Molecule* molecule = widget->molecule(); // check molecule is okay if (!molecule) { QMessageBox::warning( NULL, QObject::tr( "Avogadro" ), QObject::tr( "GL widget has no molecule" )); return; } double aspectRatio = getAspectRatio(widget); //start the progress dialog QProgressDialog progDialog(QObject::tr("Building video "), QObject::tr("Cancel"), 0, molecule->numConformers()*2); progDialog.setMinimumDuration(1); progDialog.setValue(0); //list of pngfiles for mencoder std::vector<QString> pngFiles; for (unsigned int i=0; i < molecule->numConformers(); i++) { QString povFileName = workDirectory + QString::number(i) + ".pov"; molecule->setConformer(i); // write the pov file // must be in own scope so object is destroyed and file is closed after // (a design flaw in POVPainterDevice?) POVPainterDevice pd( povFileName, aspectRatio, widget ); progDialog.setValue(2*i); //make the png runPovRay(workDirectory, povFileName); progDialog.setValue(2*i+1); QString pngFileName = workDirectory + QString::number(i) + ".png"; pngFiles.push_back(pngFileName); if (progDialog.wasCanceled()) { //stop making return; } } //now run mencoder runMencoder(workDirectory, videoFileName, pngFiles.begin(), pngFiles.end()); progDialog.setValue(progDialog.maximum()); //tell user if successful std::ifstream fin(QFile::encodeName(videoFileName)); if(!fin.fail()) { fin.close(); QString successMessage = "Video file " + videoFileName + " written."; QMessageBox::information( NULL, QObject::tr( "Avogadro" ), successMessage); } else { QString failedMessage = QObject::tr("Video file not written."); QMessageBox::warning( NULL, QObject::tr( "Avogadro" ), failedMessage); } }