Diffstat (limited to 'kaddressbook/kaddressbookview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/kaddressbookview.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/kaddressbook/kaddressbookview.cpp b/kaddressbook/kaddressbookview.cpp index 424d52a..09859c2 100644 --- a/kaddressbook/kaddressbookview.cpp +++ b/kaddressbook/kaddressbookview.cpp | |||
@@ -1,170 +1,186 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program 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 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef KAB_EMBEDDED | 24 | #ifndef KAB_EMBEDDED |
25 | #include <qapplication.h> | 25 | #include <qapplication.h> |
26 | 26 | ||
27 | #include <kabc/distributionlistdialog.h> | 27 | #include <kabc/distributionlistdialog.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <klocale.h> | 29 | #include <klocale.h> |
30 | 30 | ||
31 | #include "viewmanager.h" | 31 | #include "viewmanager.h" |
32 | 32 | ||
33 | #endif //KAB_EMBEDDED | 33 | #endif //KAB_EMBEDDED |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | 35 | ||
36 | #include <kabc/distributionlistdialog.h> | 36 | #include <kabc/distributionlistdialog.h> |
37 | #include <kabc/addressbook.h> | 37 | #include <kabc/addressbook.h> |
38 | #include <kdebug.h> | 38 | #include <kdebug.h> |
39 | 39 | ||
40 | #include "kaddressbookview.h" | 40 | #include "kaddressbookview.h" |
41 | 41 | ||
42 | KAddressBookView::KAddressBookView( KABC::AddressBook *ab, QWidget *parent, | 42 | KAddressBookView::KAddressBookView( KABC::AddressBook *ab, QWidget *parent, |
43 | const char *name ) | 43 | const char *name ) |
44 | : QWidget( parent, name ), mAddressBook( ab ), mFieldList() | 44 | : QWidget( parent, name ), mAddressBook( ab ), mFieldList() |
45 | { | 45 | { |
46 | 46 | ||
47 | initGUI(); | 47 | initGUI(); |
48 | } | 48 | } |
49 | 49 | ||
50 | KAddressBookView::~KAddressBookView() | 50 | KAddressBookView::~KAddressBookView() |
51 | { | 51 | { |
52 | kdDebug(5720) << "KAddressBookView::~KAddressBookView: destroying - " | 52 | |
53 | << name() << endl; | ||
54 | } | 53 | } |
55 | 54 | ||
55 | QRegExp KAddressBookView::getRegExp( const QString s ) | ||
56 | { | ||
57 | QRegExp re; | ||
58 | |||
59 | if ( s.length() == 3 && s.mid(1,1) == "-" ) { | ||
60 | QString pattern = "^[" + s.lower() +"]"; | ||
61 | re.setCaseSensitive(false); | ||
62 | re.setPattern( pattern ); | ||
63 | } else { | ||
64 | QString pattern = s.lower()+"*"; | ||
65 | re.setWildcard(true); // most people understand these better. | ||
66 | re.setCaseSensitive(false); | ||
67 | re.setPattern( pattern ); | ||
68 | } | ||
69 | return re; | ||
70 | } | ||
71 | |||
56 | void KAddressBookView::readConfig( KConfig *config ) | 72 | void KAddressBookView::readConfig( KConfig *config ) |
57 | { | 73 | { |
58 | mFieldList = KABC::Field::restoreFields( config, "KABCFields" ); | 74 | mFieldList = KABC::Field::restoreFields( config, "KABCFields" ); |
59 | 75 | ||
60 | if ( mFieldList.isEmpty() ) | 76 | if ( mFieldList.isEmpty() ) |
61 | mFieldList = KABC::Field::defaultFields(); | 77 | mFieldList = KABC::Field::defaultFields(); |
62 | 78 | ||
63 | mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 ); | 79 | mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 ); |
64 | mDefaultFilterName = config->readEntry( "DefaultFilterName", QString::null ); | 80 | mDefaultFilterName = config->readEntry( "DefaultFilterName", QString::null ); |
65 | } | 81 | } |
66 | 82 | ||
67 | void KAddressBookView::writeConfig( KConfig* ) | 83 | void KAddressBookView::writeConfig( KConfig* ) |
68 | { | 84 | { |
69 | // Most of writing the config is handled by the ConfigureViewDialog | 85 | // Most of writing the config is handled by the ConfigureViewDialog |
70 | } | 86 | } |
71 | 87 | ||
72 | QString KAddressBookView::selectedEmails() | 88 | QString KAddressBookView::selectedEmails() |
73 | { | 89 | { |
74 | bool first = true; | 90 | bool first = true; |
75 | QString emailAddrs; | 91 | QString emailAddrs; |
76 | QStringList uidList = selectedUids(); | 92 | QStringList uidList = selectedUids(); |
77 | KABC::Addressee addr; | 93 | KABC::Addressee addr; |
78 | QString email; | 94 | QString email; |
79 | 95 | ||
80 | QStringList::Iterator it; | 96 | QStringList::Iterator it; |
81 | for ( it = uidList.begin(); it != uidList.end(); ++it ) { | 97 | for ( it = uidList.begin(); it != uidList.end(); ++it ) { |
82 | addr = mAddressBook->findByUid( *it ); | 98 | addr = mAddressBook->findByUid( *it ); |
83 | 99 | ||
84 | if ( !addr.isEmpty() ) { | 100 | if ( !addr.isEmpty() ) { |
85 | QString m = QString::null; | 101 | QString m = QString::null; |
86 | 102 | ||
87 | if ( addr.emails().count() > 1 ) | 103 | if ( addr.emails().count() > 1 ) |
88 | m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this ); | 104 | m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this ); |
89 | 105 | ||
90 | email = addr.fullEmail( m ); | 106 | email = addr.fullEmail( m ); |
91 | 107 | ||
92 | if ( !first ) | 108 | if ( !first ) |
93 | emailAddrs += ", "; | 109 | emailAddrs += ", "; |
94 | else | 110 | else |
95 | first = false; | 111 | first = false; |
96 | 112 | ||
97 | emailAddrs += email; | 113 | emailAddrs += email; |
98 | } | 114 | } |
99 | } | 115 | } |
100 | 116 | ||
101 | return emailAddrs; | 117 | return emailAddrs; |
102 | } | 118 | } |
103 | 119 | ||
104 | KABC::Addressee::List KAddressBookView::addressees() | 120 | KABC::Addressee::List KAddressBookView::addressees() |
105 | { | 121 | { |
106 | KABC::Addressee::List addresseeList; | 122 | KABC::Addressee::List addresseeList; |
107 | 123 | ||
108 | KABC::AddressBook::Iterator it; | 124 | KABC::AddressBook::Iterator it; |
109 | for (it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 125 | for (it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
110 | if ( mFilter.filterAddressee( *it ) ) | 126 | if ( mFilter.filterAddressee( *it ) ) |
111 | addresseeList.append( *it ); | 127 | addresseeList.append( *it ); |
112 | } | 128 | } |
113 | 129 | ||
114 | return addresseeList; | 130 | return addresseeList; |
115 | } | 131 | } |
116 | 132 | ||
117 | void KAddressBookView::initGUI() | 133 | void KAddressBookView::initGUI() |
118 | { | 134 | { |
119 | // Create the layout | 135 | // Create the layout |
120 | QVBoxLayout *layout = new QVBoxLayout( this ); | 136 | QVBoxLayout *layout = new QVBoxLayout( this ); |
121 | 137 | ||
122 | // Add the view widget | 138 | // Add the view widget |
123 | mViewWidget = new QWidget( this ); | 139 | mViewWidget = new QWidget( this ); |
124 | layout->addWidget( mViewWidget ); | 140 | layout->addWidget( mViewWidget ); |
125 | } | 141 | } |
126 | 142 | ||
127 | KABC::Field::List KAddressBookView::fields() const | 143 | KABC::Field::List KAddressBookView::fields() const |
128 | { | 144 | { |
129 | return mFieldList; | 145 | return mFieldList; |
130 | } | 146 | } |
131 | KABC::Field::List KAddressBookView::allFields() const | 147 | KABC::Field::List KAddressBookView::allFields() const |
132 | { | 148 | { |
133 | return KABC::Field::allFields(); | 149 | return KABC::Field::allFields(); |
134 | } | 150 | } |
135 | 151 | ||
136 | void KAddressBookView::setFilter( const Filter &filter ) | 152 | void KAddressBookView::setFilter( const Filter &filter ) |
137 | { | 153 | { |
138 | mFilter = filter; | 154 | mFilter = filter; |
139 | } | 155 | } |
140 | 156 | ||
141 | KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const | 157 | KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const |
142 | { | 158 | { |
143 | return mDefaultFilterType; | 159 | return mDefaultFilterType; |
144 | } | 160 | } |
145 | 161 | ||
146 | const QString &KAddressBookView::defaultFilterName() const | 162 | const QString &KAddressBookView::defaultFilterName() const |
147 | { | 163 | { |
148 | return mDefaultFilterName; | 164 | return mDefaultFilterName; |
149 | } | 165 | } |
150 | 166 | ||
151 | KABC::AddressBook *KAddressBookView::addressBook() const | 167 | KABC::AddressBook *KAddressBookView::addressBook() const |
152 | { | 168 | { |
153 | return mAddressBook; | 169 | return mAddressBook; |
154 | } | 170 | } |
155 | 171 | ||
156 | QWidget *KAddressBookView::viewWidget() | 172 | QWidget *KAddressBookView::viewWidget() |
157 | { | 173 | { |
158 | return mViewWidget; | 174 | return mViewWidget; |
159 | } | 175 | } |
160 | 176 | ||
161 | ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab, | 177 | ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab, |
162 | QWidget *parent, | 178 | QWidget *parent, |
163 | const char *name ) | 179 | const char *name ) |
164 | { | 180 | { |
165 | return new ViewConfigureWidget( ab, parent, name ); | 181 | return new ViewConfigureWidget( ab, parent, name ); |
166 | } | 182 | } |
167 | 183 | ||
168 | #ifndef KAB_EMBEDDED | 184 | #ifndef KAB_EMBEDDED |
169 | #include "kaddressbookview.moc" | 185 | #include "kaddressbookview.moc" |
170 | #endif //KAB_EMBEDDED | 186 | #endif //KAB_EMBEDDED |