annotate src/startupdialog.cpp @ 571:012ba1b83328

Show cancel button with progress bar only when running an operation that it makes sense to cancel (we don't really want people cancelling e.g. initial folder scan because it would leave things in an inconsistent state)
author Chris Cannam
date Thu, 01 Mar 2012 22:53:54 +0000
parents 533519ebc0cb
children ae67ea0af696
rev   line source
Chris@64 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@64 2
Chris@64 3 /*
Chris@64 4 EasyMercurial
Chris@64 5
Chris@64 6 Based on HgExplorer by Jari Korhonen
Chris@64 7 Copyright (c) 2010 Jari Korhonen
Chris@560 8 Copyright (c) 2012 Chris Cannam
Chris@560 9 Copyright (c) 2012 Queen Mary, University of London
Chris@64 10
Chris@64 11 This program is free software; you can redistribute it and/or
Chris@64 12 modify it under the terms of the GNU General Public License as
Chris@64 13 published by the Free Software Foundation; either version 2 of the
Chris@64 14 License, or (at your option) any later version. See the file
Chris@64 15 COPYING included with this distribution for more information.
Chris@64 16 */
Chris@64 17
Chris@64 18 #include "startupdialog.h"
Chris@64 19 #include "common.h"
Chris@64 20
Chris@64 21 #include <QGridLayout>
Chris@64 22 #include <QDialogButtonBox>
Chris@64 23 #include <QSettings>
Chris@64 24
Chris@64 25 StartupDialog::StartupDialog(QWidget *parent) :
Chris@64 26 QDialog(parent)
Chris@64 27 {
Chris@64 28 setModal(true);
Chris@64 29 setWindowTitle(tr("About me"));
Chris@64 30
Chris@64 31 QSettings settings;
Chris@64 32 settings.beginGroup("User Information");
Chris@64 33 m_name = settings.value("name", getUserRealName()).toString();
Chris@64 34 m_email = settings.value("email").toString();
Chris@64 35
Chris@64 36 QGridLayout *layout = new QGridLayout;
Chris@64 37 int row = 0;
Chris@64 38
Chris@72 39 layout->addWidget(new QLabel(tr("<qt><big>Welcome to EasyMercurial!</qt></big><br>How would you like to be identified in commit messages?")),
Chris@64 40 row++, 0, 1, 2);
Chris@64 41
Chris@64 42 layout->addWidget(new QLabel(tr("Name:")), row, 0);
Chris@64 43
Chris@64 44 m_nameEdit = new QLineEdit();
Chris@64 45 m_nameEdit->setText(m_name);
Chris@64 46 connect(m_nameEdit, SIGNAL(textChanged(const QString &)),
Chris@64 47 this, SLOT(realNameChanged(const QString &)));
Chris@64 48 layout->addWidget(m_nameEdit, row++, 1);
Chris@64 49
Chris@64 50 layout->addWidget(new QLabel(tr("Email address:")), row, 0);
Chris@64 51
Chris@64 52 m_emailEdit = new QLineEdit();
Chris@64 53 m_emailEdit->setText(m_email);
Chris@64 54 connect(m_emailEdit, SIGNAL(textChanged(const QString &)),
Chris@64 55 this, SLOT(emailChanged(const QString &)));
Chris@64 56 layout->addWidget(m_emailEdit, row++, 1);
Chris@64 57
Chris@64 58 layout->addWidget(new QLabel(tr("<br>You will appear as:")), row, 0, Qt::AlignBottom);
Chris@64 59 m_example = new QLabel();
Chris@64 60 layout->addWidget(m_example, row++, 1, Qt::AlignBottom);
Chris@64 61
Chris@64 62 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok);
Chris@64 63 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
Chris@64 64 layout->addWidget(bbox, row++, 0, 1, 2);
Chris@64 65 m_ok = bbox->button(QDialogButtonBox::Ok);
Chris@64 66 m_ok->setEnabled(false);
Chris@64 67
Chris@64 68 setLayout(layout);
Chris@64 69
Chris@64 70 m_ok->setEnabled(m_name != "");
Chris@64 71 updateExample();
Chris@64 72 }
Chris@64 73
Chris@64 74 void
Chris@64 75 StartupDialog::realNameChanged(const QString &s)
Chris@64 76 {
Chris@64 77 m_name = s.trimmed();
Chris@64 78 m_ok->setEnabled(m_name != "");
Chris@64 79 updateExample();
Chris@64 80 }
Chris@64 81
Chris@64 82 void
Chris@64 83 StartupDialog::emailChanged(const QString &s)
Chris@64 84 {
Chris@64 85 m_email = s.trimmed();
Chris@64 86 updateExample();
Chris@64 87 }
Chris@64 88
Chris@64 89 void
Chris@64 90 StartupDialog::accept()
Chris@64 91 {
Chris@64 92 QSettings settings;
Chris@64 93 settings.beginGroup("User Information");
Chris@64 94 settings.setValue("name", m_name);
Chris@64 95 settings.setValue("email", m_email);
Chris@64 96 QDialog::accept();
Chris@64 97 }
Chris@64 98
Chris@64 99 void
Chris@64 100 StartupDialog::updateExample()
Chris@64 101 {
Chris@64 102 QString identifier;
Chris@64 103
Chris@64 104 if (m_email != "") {
Chris@64 105 identifier = QString("%1 <%2>").arg(m_name).arg(m_email);
Chris@64 106 } else {
Chris@64 107 identifier = m_name;
Chris@64 108 }
Chris@64 109
Chris@64 110 m_example->setText(identifier);
Chris@64 111 }
Chris@64 112
Chris@64 113