kleopatra
adduseriddialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <config-kleopatra.h>
00034
00035 #include "adduseriddialog.h"
00036
00037 #include "ui_adduseriddialog.h"
00038
00039 #include <utils/validation.h>
00040
00041 #include <QString>
00042 #include <QStringList>
00043 #include <QPushButton>
00044
00045 #include <cassert>
00046
00047 using namespace Kleo;
00048 using namespace Kleo::Dialogs;
00049
00050 class AddUserIDDialog::Private {
00051 friend class ::Kleo::Dialogs::AddUserIDDialog;
00052 AddUserIDDialog * const q;
00053 public:
00054 explicit Private( AddUserIDDialog * qq )
00055 : q( qq ),
00056 ui( q )
00057 {
00058
00059 }
00060
00061 private:
00062 void slotUserIDChanged();
00063
00064 private:
00065 struct UI : public Ui_AddUserIDDialog {
00066 explicit UI( AddUserIDDialog * qq )
00067 : Ui_AddUserIDDialog()
00068 {
00069 setupUi( qq );
00070
00071 nameLE->setValidator( Validation::pgpName( nameLE ) );
00072 emailLE->setValidator( Validation::email( emailLE ) );
00073 commentLE->setValidator( Validation::pgpComment( commentLE ) );
00074 }
00075
00076 QPushButton * okPB() const {
00077 return buttonBox->button( QDialogButtonBox::Ok );
00078 }
00079 } ui;
00080 };
00081
00082 AddUserIDDialog::AddUserIDDialog( QWidget * p, Qt::WindowFlags f )
00083 : QDialog( p, f ), d( new Private( this ) )
00084 {
00085
00086 }
00087
00088 AddUserIDDialog::~AddUserIDDialog() {}
00089
00090
00091 void AddUserIDDialog::setName( const QString & name ) {
00092 d->ui.nameLE->setText( name );
00093 }
00094
00095 QString AddUserIDDialog::name() const {
00096 return d->ui.nameLE->text().trimmed();
00097 }
00098
00099 void AddUserIDDialog::setEmail( const QString & email ) {
00100 d->ui.emailLE->setText( email );
00101 }
00102
00103 QString AddUserIDDialog::email() const {
00104 return d->ui.emailLE->text().trimmed();
00105 }
00106
00107 void AddUserIDDialog::setComment( const QString & comment ) {
00108 d->ui.commentLE->setText( comment );
00109 }
00110
00111 QString AddUserIDDialog::comment() const {
00112 return d->ui.commentLE->text().trimmed();
00113 }
00114
00115
00116 void AddUserIDDialog::Private::slotUserIDChanged() {
00117
00118 bool ok = false;
00119 QString error;
00120
00121 if ( !ui.nameLE->hasAcceptableInput() )
00122 error = i18nc("@info", "<interface>Real name</interface> must be at least 5 characters long.");
00123 else if ( !ui.emailLE->hasAcceptableInput() )
00124 error = i18nc("@info", "<interface>EMail address</interface> is invalid.");
00125 else if ( !ui.commentLE->hasAcceptableInput() )
00126 error = i18nc("@info", "<interface>Comment</interface> contains invalid characters.");
00127 else
00128 ok = true;
00129
00130 ui.okPB()->setEnabled( ok );
00131 ui.errorLB->setText( error );
00132
00133 const QString name = q->name();
00134 const QString email = q->email();
00135 const QString comment = q->comment();
00136
00137 QStringList parts;
00138 if ( !name.isEmpty() )
00139 parts.push_back( name );
00140 if ( !comment.isEmpty() )
00141 parts.push_back( QLatin1Char( '(' ) + comment + QLatin1Char( ')' ) );
00142 if ( !email.isEmpty() )
00143 parts.push_back( QLatin1Char( '<' ) + email + QLatin1Char( '>' ) );
00144
00145 ui.resultLB->setText( parts.join( QLatin1String( " " ) ) );
00146 }
00147
00148 #include "moc_adduseriddialog.cpp"