~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to mobile/contacts/namepartseditwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of Akonadi Contact.
 
3
 
 
4
    Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
 
5
 
 
6
    This library is free software; you can redistribute it and/or modify it
 
7
    under the terms of the GNU Library General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or (at your
 
9
    option) any later version.
 
10
 
 
11
    This library is distributed in the hope that it will be useful, but WITHOUT
 
12
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
14
    License for more details.
 
15
 
 
16
    You should have received a copy of the GNU Library General Public License
 
17
    along with this library; see the file COPYING.LIB.  If not, write to the
 
18
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
19
    02110-1301, USA.
 
20
*/
 
21
 
 
22
 
 
23
#include "namepartseditwidget.h"
 
24
 
 
25
#include <QtGui/QFormLayout>
 
26
 
 
27
#include <kcombobox.h>
 
28
#include <klineedit.h>
 
29
#include <klocale.h>
 
30
 
 
31
NamePartsEditWidget::NamePartsEditWidget( QWidget *parent )
 
32
  : QWidget( parent)
 
33
{
 
34
  QFormLayout *layout = new QFormLayout( this );
 
35
  layout->setLabelAlignment( Qt::AlignLeft );
 
36
 
 
37
  mPrefixCombo = new KComboBox( this );
 
38
  mPrefixCombo->setDuplicatesEnabled( false );
 
39
#ifndef Q_WS_MAEMO_5
 
40
  mPrefixCombo->setEditable( true );
 
41
#endif
 
42
 
 
43
  mGivenNameEdit = new KLineEdit( this );
 
44
 
 
45
  mAdditionalNameEdit = new KLineEdit( this );
 
46
 
 
47
  mFamilyNameEdit = new KLineEdit( this );
 
48
 
 
49
  mSuffixCombo = new KComboBox( this );
 
50
  mSuffixCombo->setDuplicatesEnabled( false );
 
51
#ifndef Q_WS_MAEMO_5
 
52
  mSuffixCombo->setEditable( true );
 
53
#endif
 
54
 
 
55
  layout->addRow( i18n( "Honorific prefixes:" ), mPrefixCombo );
 
56
  layout->addRow( i18n( "Given name:" ), mGivenNameEdit );
 
57
  layout->addRow( i18n( "Additional names:" ), mAdditionalNameEdit );
 
58
  layout->addRow( i18n( "Family names:" ), mFamilyNameEdit );
 
59
  layout->addRow( i18n( "Honorific suffixes:" ), mSuffixCombo );
 
60
 
 
61
  QStringList prefixList;
 
62
  prefixList += QString();
 
63
  prefixList += i18n( "Dr." );
 
64
  prefixList += i18n( "Miss" );
 
65
  prefixList += i18n( "Mr." );
 
66
  prefixList += i18n( "Mrs." );
 
67
  prefixList += i18n( "Ms." );
 
68
  prefixList += i18n( "Prof." );
 
69
  prefixList.sort();
 
70
 
 
71
  QStringList suffixList;
 
72
  suffixList += QString();
 
73
  suffixList += i18n( "I" );
 
74
  suffixList += i18n( "II" );
 
75
  suffixList += i18n( "III" );
 
76
  suffixList += i18n( "Jr." );
 
77
  suffixList += i18n( "Sr." );
 
78
  suffixList.sort();
 
79
 
 
80
  mPrefixCombo->addItems( prefixList );
 
81
  mSuffixCombo->addItems( suffixList );
 
82
 
 
83
#ifndef Q_WS_MAEMO_5
 
84
  mPrefixCombo->lineEdit()->setFocus();
 
85
#endif
 
86
 
 
87
  connect( mSuffixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
 
88
  connect( mSuffixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
89
  connect( mPrefixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
 
90
  connect( mPrefixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
91
  connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
92
  connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
93
  connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
94
}
 
95
 
 
96
void NamePartsEditWidget::loadContact( const KABC::Addressee &contact )
 
97
{
 
98
  mContact = contact;
 
99
 
 
100
  disconnect( mSuffixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
 
101
  disconnect( mSuffixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
102
  disconnect( mPrefixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
 
103
  disconnect( mPrefixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
104
  disconnect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
105
  disconnect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
106
  disconnect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
107
 
 
108
  mPrefixCombo->setItemText( mPrefixCombo->currentIndex(), mContact.prefix() );
 
109
  mGivenNameEdit->setText( mContact.givenName() );
 
110
  mAdditionalNameEdit->setText( mContact.additionalName() );
 
111
  mFamilyNameEdit->setText( mContact.familyName() );
 
112
  mSuffixCombo->setItemText( mSuffixCombo->currentIndex(), mContact.suffix() );
 
113
 
 
114
  connect( mSuffixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
 
115
  connect( mSuffixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
116
  connect( mPrefixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
 
117
  connect( mPrefixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
118
  connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
119
  connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
120
  connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
 
121
}
 
122
 
 
123
void NamePartsEditWidget::storeContact( KABC::Addressee &contact ) const
 
124
{
 
125
  contact.setPrefix( mPrefixCombo->currentText() );
 
126
  contact.setGivenName( mGivenNameEdit->text() );
 
127
  contact.setAdditionalName( mAdditionalNameEdit->text() );
 
128
  contact.setFamilyName( mFamilyNameEdit->text() );
 
129
  contact.setSuffix( mSuffixCombo->currentText() );
 
130
}
 
131
 
 
132
void NamePartsEditWidget::inputChanged()
 
133
{
 
134
  storeContact( mContact );
 
135
  emit nameChanged( mContact );
 
136
}