summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addresseedialog.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp
index 3e7b72c..9197850 100644
--- a/kabc/addresseedialog.cpp
+++ b/kabc/addresseedialog.cpp
@@ -1,202 +1,205 @@
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 setText( Name,addressee.realName()); 45 setText( Name,addressee.realName());
46 setText( Email, addressee.preferredEmail() ); 46 setText( Email, addressee.preferredEmail() );
47 setText( Category, addressee.categories().join(";") ); 47 setText( Category, addressee.categories().join(";") );
48} 48}
49 49
50QString AddresseeItem::key( int column, bool ) const 50QString AddresseeItem::key( int column, bool ) const
51{ 51{
52 52
53 if (column == Email) { 53 if (column == Email) {
54 QString value = text(Email); 54 QString value = text(Email);
55 int val = value.findRev("@"); 55 int val = value.findRev("@");
56 return value.mid( val) + value.left( val ); 56 return value.mid( val) + value.left( val );
57 } 57 }
58 return text(column).lower(); 58 return text(column).lower();
59} 59}
60 60
61AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) : 61AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) :
62 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"), 62 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"),
63 Ok|Cancel, No, parent ), mMultiple( multiple ) 63 Ok|Cancel, No, parent ), mMultiple( multiple )
64{ 64{
65 qDebug("NEW AddresseeDialog "); 65 qDebug("NEW AddresseeDialog ");
66 QWidget *topWidget = plainPage(); 66 QWidget *topWidget = plainPage();
67 67
68 QBoxLayout *topLayout = new QHBoxLayout( topWidget ); 68 QBoxLayout *topLayout = new QHBoxLayout( topWidget );
69 69
70 70
71 KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget); 71 KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget);
72 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 72 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
73 73
74 topLayout->addWidget(mMiniSplitter ); 74 topLayout->addWidget(mMiniSplitter );
75 75
76 QWidget *listWidget = new QWidget( mMiniSplitter ); 76 QWidget *listWidget = new QWidget( mMiniSplitter );
77 77
78 QBoxLayout *listLayout = new QVBoxLayout (listWidget) ; 78 QVBoxLayout *listLayout = new QVBoxLayout (listWidget) ;
79 //topLayout->addLayout( listLayout ); 79 //topLayout->addLayout( listLayout );
80 80
81 mAddresseeList = new KListView( listWidget ); 81 mAddresseeList = new KListView( listWidget );
82 mAddresseeList->addColumn( i18n("Name") ); 82 mAddresseeList->addColumn( i18n("Name") );
83 mAddresseeList->addColumn( i18n("Email") ); 83 mAddresseeList->addColumn( i18n("Email") );
84 mAddresseeList->addColumn( i18n("Category") ); 84 mAddresseeList->addColumn( i18n("Category") );
85 mAddresseeList->setAllColumnsShowFocus( true ); 85 mAddresseeList->setAllColumnsShowFocus( true );
86 mAddresseeList->setFullWidth( true ); 86 mAddresseeList->setFullWidth( true );
87 listLayout->addWidget( mAddresseeList ); 87 listLayout->addWidget( mAddresseeList );
88 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ), 88 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ),
89 SLOT( slotOk() ) ); 89 SLOT( slotOk() ) );
90 90
91 QHBox* searchBox = new QHBox ( listWidget ); 91 //QHBox* searchBox = new QHBox ( listWidget );
92 mAddresseeEdit = new QLineEdit( searchBox ); 92 mAddresseeEdit = new QLineEdit( listWidget );
93 connect( mAddresseeEdit, SIGNAL( returnPressed() ), 93 connect( mAddresseeEdit, SIGNAL( returnPressed() ),
94 SLOT( loadAddressBook() ) ); 94 SLOT( loadAddressBook() ) );
95 mAddresseeEdit->setFocus(); 95 mAddresseeEdit->setFocus();
96 QPushButton *searchButton = new QPushButton( i18n("Search!"), searchBox ); 96 QPushButton *searchButton = new QPushButton( i18n("Search!"), listWidget );
97 connect ( searchButton, SIGNAL( clicked() ), SLOT( loadAddressBook() ) ); 97 connect ( searchButton, SIGNAL( clicked() ), SLOT( loadAddressBook() ) );
98 98
99 listLayout->addWidget( searchBox ); 99 QHBoxLayout *searchLayout = new QHBoxLayout (listLayout) ;
100 searchLayout->addWidget( mAddresseeEdit );
101 searchLayout->addWidget( searchButton );
102 //listLayout->addWidget( searchBox );
100 103
101 if ( mMultiple ) { 104 if ( mMultiple ) {
102 //QBoxLayout *selectedLayout = new QVBoxLayout; 105 //QBoxLayout *selectedLayout = new QVBoxLayout;
103 //topLayout->addLayout( selectedLayout ); 106 //topLayout->addLayout( selectedLayout );
104 //topLayout->setSpacing( spacingHint() ); 107 //topLayout->setSpacing( spacingHint() );
105 108
106 QVBox *selectedGroup = new QVBox( mMiniSplitter ); 109 QVBox *selectedGroup = new QVBox( mMiniSplitter );
107 new QLabel ( i18n("Selected:"), selectedGroup ); 110 new QLabel ( i18n("Selected:"), selectedGroup );
108 //selectedLayout->addWidget( selectedGroup ); 111 //selectedLayout->addWidget( selectedGroup );
109 112
110 mSelectedList = new KListView( selectedGroup ); 113 mSelectedList = new KListView( selectedGroup );
111 mSelectedList->addColumn( i18n("Name") ); 114 mSelectedList->addColumn( i18n("Name") );
112 mSelectedList->addColumn( i18n("Email") ); 115 mSelectedList->addColumn( i18n("Email") );
113 mSelectedList->setAllColumnsShowFocus( true ); 116 mSelectedList->setAllColumnsShowFocus( true );
114 mSelectedList->setFullWidth( true ); 117 mSelectedList->setFullWidth( true );
115 //connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ), 118 //connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ),
116 // SLOT( removeSelected() ) ); 119 // SLOT( removeSelected() ) );
117 connect( mSelectedList, SIGNAL( clicked( QListViewItem * ) ), 120 connect( mSelectedList, SIGNAL( clicked( QListViewItem * ) ),
118 SLOT( removeSelected() ) ); 121 SLOT( removeSelected() ) );
119 connect( mSelectedList, SIGNAL( returnPressed( QListViewItem *) ), 122 connect( mSelectedList, SIGNAL( returnPressed( QListViewItem *) ),
120 SLOT( removeSelected() ) ); 123 SLOT( removeSelected() ) );
121 124
122#if 0 125#if 0
123 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup ); 126 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup );
124 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) ); 127 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) );
125 128
126#endif 129#endif
127 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ), 130 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ),
128 SLOT( addSelected( QListViewItem * ) ) ); 131 SLOT( addSelected( QListViewItem * ) ) );
129 connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ), 132 connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ),
130 SLOT( selectNextItem( QListViewItem * ) ) ); 133 SLOT( selectNextItem( QListViewItem * ) ) );
131 134
132 } 135 }
133 136
134 mAddressBook = StdAddressBook::self( true ); 137 mAddressBook = StdAddressBook::self( true );
135 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), 138 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ),
136 SLOT( addressBookChanged() ) ); 139 SLOT( addressBookChanged() ) );
137#if 0 140#if 0
138 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ), 141 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ),
139 SLOT( addressBookChanged() ) ); 142 SLOT( addressBookChanged() ) );
140#endif 143#endif
141 loadAddressBook(); 144 loadAddressBook();
142 QValueList<int> splitterSize; 145 QValueList<int> splitterSize;
143 splitterSize.append( ( width() / 5 ) * 3 ); 146 splitterSize.append( ( width() / 5 ) * 3 );
144 splitterSize.append( ( width() / 5 ) *2 ); 147 splitterSize.append( ( width() / 5 ) *2 );
145 mMiniSplitter->setSizes( splitterSize ); 148 mMiniSplitter->setSizes( splitterSize );
146} 149}
147 150
148AddresseeDialog::~AddresseeDialog() 151AddresseeDialog::~AddresseeDialog()
149{ 152{
150 qDebug("DELETE AddresseeDialog "); 153 qDebug("DELETE AddresseeDialog ");
151} 154}
152 155
153void AddresseeDialog::loadAddressBook() 156void AddresseeDialog::loadAddressBook()
154{ 157{
155 mAddresseeList->clear(); 158 mAddresseeList->clear();
156 mItemDict.clear(); 159 mItemDict.clear();
157 if ( mAddresseeEdit->text().isEmpty() ) { 160 if ( mAddresseeEdit->text().isEmpty() ) {
158 AddressBook::Iterator it; 161 AddressBook::Iterator it;
159 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 162 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
160 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 163 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
161 continue; 164 continue;
162 new AddresseeItem( mAddresseeList, (*it) ); 165 new AddresseeItem( mAddresseeList, (*it) );
163 } 166 }
164 return; 167 return;
165 } 168 }
166 //mAddresseeEdit->completionObject()->clear(); 169 //mAddresseeEdit->completionObject()->clear();
167 QRegExp re; 170 QRegExp re;
168 re.setWildcard(true); // most people understand these better. 171 re.setWildcard(true); // most people understand these better.
169 re.setCaseSensitive(false); 172 re.setCaseSensitive(false);
170 re.setPattern( "*"+ mAddresseeEdit->text() + "*"); 173 re.setPattern( "*"+ mAddresseeEdit->text() + "*");
171 174
172 AddressBook::Iterator it; 175 AddressBook::Iterator it;
173 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 176 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
174 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 177 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
175 continue; 178 continue;
176 QString name = (*it).realName(); 179 QString name = (*it).realName();
177 name += (*it).preferredEmail(); 180 name += (*it).preferredEmail();
178 name += (*it).categories().join(";"); 181 name += (*it).categories().join(";");
179#if QT_VERSION >= 0x030000 182#if QT_VERSION >= 0x030000
180 if (re.search(name) != -1) 183 if (re.search(name) != -1)
181#else 184#else
182 if (re.match(name) != -1) 185 if (re.match(name) != -1)
183#endif 186#endif
184 AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) ); 187 AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) );
185 } 188 }
186} 189}
187 190
188void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item ) 191void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item )
189{ 192{
190 if ( str.isEmpty() ) return; 193 if ( str.isEmpty() ) return;
191 194
192 mItemDict.insert( str, item ); 195 mItemDict.insert( str, item );
193 //mAddresseeEdit->completionObject()->addItem( str ); 196 //mAddresseeEdit->completionObject()->addItem( str );
194} 197}
195 198
196void AddresseeDialog::selectItem( const QString &str ) 199void AddresseeDialog::selectItem( const QString &str )
197{ 200{
198 if ( str.isEmpty() ) return; 201 if ( str.isEmpty() ) return;
199 202
200 QListViewItem *item = mItemDict.find( str ); 203 QListViewItem *item = mItemDict.find( str );
201 if ( item ) { 204 if ( item ) {
202 mAddresseeList->blockSignals( true ); 205 mAddresseeList->blockSignals( true );