summaryrefslogtreecommitdiffabout
path: root/kabc/addresseedialog.cpp
authorzautrix <zautrix>2005-03-29 17:05:50 (UTC)
committer zautrix <zautrix>2005-03-29 17:05:50 (UTC)
commita7c827aa0e555206b60dec3bc07f7afab4352883 (patch) (unidiff)
tree56dbda15314f27ffabd143d09ea036b092444198 /kabc/addresseedialog.cpp
parent3116f249fc6ccd0e067213e826d3d924f6986972 (diff)
downloadkdepimpi-a7c827aa0e555206b60dec3bc07f7afab4352883.zip
kdepimpi-a7c827aa0e555206b60dec3bc07f7afab4352883.tar.gz
kdepimpi-a7c827aa0e555206b60dec3bc07f7afab4352883.tar.bz2
fixes
Diffstat (limited to 'kabc/addresseedialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addresseedialog.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp
index b3429e3..648e780 100644
--- a/kabc/addresseedialog.cpp
+++ b/kabc/addresseedialog.cpp
@@ -1,235 +1,237 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qpushbutton.h> 22#include <qpushbutton.h>
23#include <qgroupbox.h> 23#include <qgroupbox.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qvbox.h> 26#include <qvbox.h>
27#include <qlabel.h> 27#include <qlabel.h>
28 28
29#include <klocale.h> 29#include <klocale.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include <kglobalsettings.h> 31#include <kglobalsettings.h>
32 32
33#include "stdaddressbook.h" 33#include "stdaddressbook.h"
34 34
35#include "addresseedialog.h" 35#include "addresseedialog.h"
36#include "KDGanttMinimizeSplitter.h" 36#include "KDGanttMinimizeSplitter.h"
37//#include "addresseedialog.moc" 37//#include "addresseedialog.moc"
38 38
39using namespace KABC; 39using namespace KABC;
40 40
41AddresseeItem::AddresseeItem( QListView *parent, const Addressee &addressee ) : 41AddresseeItem::AddresseeItem( QListView *parent, const Addressee &addressee ) :
42 QListViewItem( parent ), 42 QListViewItem( parent ),
43 mAddressee( addressee ) 43 mAddressee( addressee )
44{ 44{
45 QString name = addressee.familyName()+", "+ addressee.givenName(); 45 QString name = addressee.familyName()+", "+ addressee.givenName();
46 if ( name.length() == 2 ) 46 if ( name.length() == 2 )
47 name = addressee.organization(); 47 name = addressee.organization();
48 setText( Name,name); 48 setText( Name,name);
49 setText( Email, addressee.preferredEmail() ); 49 setText( Email, addressee.preferredEmail() );
50} 50}
51 51
52QString AddresseeItem::key( int column, bool ) const 52QString AddresseeItem::key( int column, bool ) const
53{ 53{
54 54
55 if (column == Email) { 55 if (column == Email) {
56 QString value = text(Email); 56 QString value = text(Email);
57 int val = value.findRev("@"); 57 int val = value.findRev("@");
58 return value.mid( val) + value.left( val ); 58 return value.mid( val) + value.left( val );
59 } 59 }
60 return text(column).lower(); 60 return text(column).lower();
61} 61}
62 62
63AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) : 63AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) :
64 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"), 64 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"),
65 Ok|Cancel, No, parent ), mMultiple( multiple ) 65 Ok|Cancel, No, parent ), mMultiple( multiple )
66{ 66{
67 qDebug("NEW AddresseeDialog ");
67 QWidget *topWidget = plainPage(); 68 QWidget *topWidget = plainPage();
68 69
69 QBoxLayout *topLayout = new QHBoxLayout( topWidget ); 70 QBoxLayout *topLayout = new QHBoxLayout( topWidget );
70 71
71 72
72 KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget); 73 KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget);
73 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 74 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
74 75
75 topLayout->addWidget(mMiniSplitter ); 76 topLayout->addWidget(mMiniSplitter );
76 77
77 QWidget *listWidget = new QWidget( mMiniSplitter ); 78 QWidget *listWidget = new QWidget( mMiniSplitter );
78 79
79 QBoxLayout *listLayout = new QVBoxLayout (listWidget) ; 80 QBoxLayout *listLayout = new QVBoxLayout (listWidget) ;
80 //topLayout->addLayout( listLayout ); 81 //topLayout->addLayout( listLayout );
81 82
82 mAddresseeList = new KListView( listWidget ); 83 mAddresseeList = new KListView( listWidget );
83 mAddresseeList->addColumn( i18n("Name") ); 84 mAddresseeList->addColumn( i18n("Name") );
84 mAddresseeList->addColumn( i18n("Email") ); 85 mAddresseeList->addColumn( i18n("Email") );
85 mAddresseeList->setAllColumnsShowFocus( true ); 86 mAddresseeList->setAllColumnsShowFocus( true );
86 mAddresseeList->setFullWidth( true ); 87 mAddresseeList->setFullWidth( true );
87 listLayout->addWidget( mAddresseeList ); 88 listLayout->addWidget( mAddresseeList );
88 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ), 89 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ),
89 SLOT( slotOk() ) ); 90 SLOT( slotOk() ) );
90 91
91 mAddresseeEdit = new QLineEdit( listWidget ); 92 mAddresseeEdit = new QLineEdit( listWidget );
92 connect( mAddresseeEdit, SIGNAL( returnPressed() ), 93 connect( mAddresseeEdit, SIGNAL( returnPressed() ),
93 SLOT( loadAddressBook() ) ); 94 SLOT( loadAddressBook() ) );
94 mAddresseeEdit->setFocus(); 95 mAddresseeEdit->setFocus();
95 96
96 listLayout->addWidget( mAddresseeEdit ); 97 listLayout->addWidget( mAddresseeEdit );
97 98
98 if ( mMultiple ) { 99 if ( mMultiple ) {
99 //QBoxLayout *selectedLayout = new QVBoxLayout; 100 //QBoxLayout *selectedLayout = new QVBoxLayout;
100 //topLayout->addLayout( selectedLayout ); 101 //topLayout->addLayout( selectedLayout );
101 //topLayout->setSpacing( spacingHint() ); 102 //topLayout->setSpacing( spacingHint() );
102 103
103 QVBox *selectedGroup = new QVBox( mMiniSplitter ); 104 QVBox *selectedGroup = new QVBox( mMiniSplitter );
104 new QLabel ( i18n("Selected:"), selectedGroup ); 105 new QLabel ( i18n("Selected:"), selectedGroup );
105 //selectedLayout->addWidget( selectedGroup ); 106 //selectedLayout->addWidget( selectedGroup );
106 107
107 mSelectedList = new KListView( selectedGroup ); 108 mSelectedList = new KListView( selectedGroup );
108 mSelectedList->addColumn( i18n("Name") ); 109 mSelectedList->addColumn( i18n("Name") );
109 mSelectedList->addColumn( i18n("Email") ); 110 mSelectedList->addColumn( i18n("Email") );
110 mSelectedList->setAllColumnsShowFocus( true ); 111 mSelectedList->setAllColumnsShowFocus( true );
111 mSelectedList->setFullWidth( true ); 112 mSelectedList->setFullWidth( true );
112 connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ), 113 connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ),
113 SLOT( removeSelected() ) ); 114 SLOT( removeSelected() ) );
114 115
115 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup ); 116 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup );
116 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) ); 117 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) );
117 118
118 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ), 119 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ),
119 SLOT( addSelected( QListViewItem * ) ) ); 120 SLOT( addSelected( QListViewItem * ) ) );
120 connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ), 121 connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ),
121 SLOT( selectNextItem( QListViewItem * ) ) ); 122 SLOT( selectNextItem( QListViewItem * ) ) );
122 123
123 } 124 }
124 125
125 mAddressBook = StdAddressBook::self( true ); 126 mAddressBook = StdAddressBook::self( true );
126 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), 127 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ),
127 SLOT( addressBookChanged() ) ); 128 SLOT( addressBookChanged() ) );
128 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ), 129 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ),
129 SLOT( addressBookChanged() ) ); 130 SLOT( addressBookChanged() ) );
130 131
131 loadAddressBook(); 132 loadAddressBook();
132 QValueList<int> splitterSize; 133 QValueList<int> splitterSize;
133 splitterSize.append( ( width() / 5 ) * 3 ); 134 splitterSize.append( ( width() / 5 ) * 3 );
134 splitterSize.append( ( width() / 5 ) *2 ); 135 splitterSize.append( ( width() / 5 ) *2 );
135 mMiniSplitter->setSizes( splitterSize ); 136 mMiniSplitter->setSizes( splitterSize );
136} 137}
137 138
138AddresseeDialog::~AddresseeDialog() 139AddresseeDialog::~AddresseeDialog()
139{ 140{
141 qDebug("DELETE AddresseeDialog ");
140} 142}
141 143
142void AddresseeDialog::loadAddressBook() 144void AddresseeDialog::loadAddressBook()
143{ 145{
144 mAddresseeList->clear(); 146 mAddresseeList->clear();
145 mItemDict.clear(); 147 mItemDict.clear();
146 if ( mAddresseeEdit->text().isEmpty() ) { 148 if ( mAddresseeEdit->text().isEmpty() ) {
147 AddressBook::Iterator it; 149 AddressBook::Iterator it;
148 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 150 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
149 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 151 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
150 continue; 152 continue;
151 new AddresseeItem( mAddresseeList, (*it) ); 153 new AddresseeItem( mAddresseeList, (*it) );
152 } 154 }
153 return; 155 return;
154 } 156 }
155 //mAddresseeEdit->completionObject()->clear(); 157 //mAddresseeEdit->completionObject()->clear();
156 QRegExp re; 158 QRegExp re;
157 re.setWildcard(true); // most people understand these better. 159 re.setWildcard(true); // most people understand these better.
158 re.setCaseSensitive(false); 160 re.setCaseSensitive(false);
159 re.setPattern( "*"+ mAddresseeEdit->text() + "*"); 161 re.setPattern( "*"+ mAddresseeEdit->text() + "*");
160 162
161 AddressBook::Iterator it; 163 AddressBook::Iterator it;
162 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 164 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
163 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 165 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
164 continue; 166 continue;
165 QString name = (*it).familyName()+", "+ (*it).givenName(); 167 QString name = (*it).familyName()+", "+ (*it).givenName();
166 if ( name.length() == 2 ) 168 if ( name.length() == 2 )
167 name = (*it).realName(); 169 name = (*it).realName();
168 name += (*it).preferredEmail(); 170 name += (*it).preferredEmail();
169#if QT_VERSION >= 0x030000 171#if QT_VERSION >= 0x030000
170 if (re.search(name) != -1) 172 if (re.search(name) != -1)
171#else 173#else
172 if (re.match(name) != -1) 174 if (re.match(name) != -1)
173#endif 175#endif
174 AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) ); 176 AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) );
175 } 177 }
176} 178}
177 179
178void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item ) 180void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item )
179{ 181{
180 if ( str.isEmpty() ) return; 182 if ( str.isEmpty() ) return;
181 183
182 mItemDict.insert( str, item ); 184 mItemDict.insert( str, item );
183 //mAddresseeEdit->completionObject()->addItem( str ); 185 //mAddresseeEdit->completionObject()->addItem( str );
184} 186}
185 187
186void AddresseeDialog::selectItem( const QString &str ) 188void AddresseeDialog::selectItem( const QString &str )
187{ 189{
188 if ( str.isEmpty() ) return; 190 if ( str.isEmpty() ) return;
189 191
190 QListViewItem *item = mItemDict.find( str ); 192 QListViewItem *item = mItemDict.find( str );
191 if ( item ) { 193 if ( item ) {
192 mAddresseeList->blockSignals( true ); 194 mAddresseeList->blockSignals( true );
193 mAddresseeList->setSelected( item, true ); 195 mAddresseeList->setSelected( item, true );
194 mAddresseeList->ensureItemVisible( item ); 196 mAddresseeList->ensureItemVisible( item );
195 mAddresseeList->blockSignals( false ); 197 mAddresseeList->blockSignals( false );
196 } 198 }
197} 199}
198 200
199void AddresseeDialog::updateEdit( QListViewItem *item ) 201void AddresseeDialog::updateEdit( QListViewItem *item )
200{ 202{
201 mAddresseeEdit->setText( item->text( 0 ) ); 203 mAddresseeEdit->setText( item->text( 0 ) );
202 mAddresseeEdit->setSelection( 0, item->text( 0 ).length() ); 204 mAddresseeEdit->setSelection( 0, item->text( 0 ).length() );
203} 205}
204 206
205void AddresseeDialog::selectNextItem( QListViewItem *item ) 207void AddresseeDialog::selectNextItem( QListViewItem *item )
206{ 208{
207 addSelected( item ); 209 addSelected( item );
208 QListViewItem *next = item->nextSibling(); 210 QListViewItem *next = item->nextSibling();
209 if ( next ) { 211 if ( next ) {
210 next->setSelected( true ); 212 next->setSelected( true );
211 item->setSelected( false ); 213 item->setSelected( false );
212 mAddresseeList->setCurrentItem( next ); 214 mAddresseeList->setCurrentItem( next );
213 } 215 }
214} 216}
215void AddresseeDialog::addSelected( QListViewItem *item ) 217void AddresseeDialog::addSelected( QListViewItem *item )
216{ 218{
217 AddresseeItem *addrItem = (AddresseeItem *)( item ); 219 AddresseeItem *addrItem = (AddresseeItem *)( item );
218 if ( !addrItem ) return; 220 if ( !addrItem ) return;
219 221
220 Addressee a = addrItem->addressee(); 222 Addressee a = addrItem->addressee();
221 223
222 QListViewItem *selectedItem = mSelectedDict.find( a.uid() ); 224 QListViewItem *selectedItem = mSelectedDict.find( a.uid() );
223 if ( !selectedItem ) { 225 if ( !selectedItem ) {
224 selectedItem = new AddresseeItem( mSelectedList, a ); 226 selectedItem = new AddresseeItem( mSelectedList, a );
225 mSelectedDict.insert( a.uid(), selectedItem ); 227 mSelectedDict.insert( a.uid(), selectedItem );
226 } 228 }
227 229
228} 230}
229 231
230void AddresseeDialog::removeSelected() 232void AddresseeDialog::removeSelected()
231{ 233{
232 QListViewItem *item = mSelectedList->selectedItem(); 234 QListViewItem *item = mSelectedList->selectedItem();
233 AddresseeItem *addrItem = (AddresseeItem *)( item ); 235 AddresseeItem *addrItem = (AddresseeItem *)( item );
234 if ( !addrItem ) return; 236 if ( !addrItem ) return;
235 QListViewItem *next = item->nextSibling(); 237 QListViewItem *next = item->nextSibling();