author | eilers <eilers> | 2002-11-01 14:50:14 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-11-01 14:50:14 (UTC) |
commit | 3fbba334274ca53bd26cd79ccd4662e529c61f40 (patch) (unidiff) | |
tree | 3fa1ccd82237757dc97a7c9b652ea43b8a16023a | |
parent | 6e4730b8485d3481d554dc8c079722ee1236f375 (diff) | |
download | opie-3fbba334274ca53bd26cd79ccd4662e529c61f40.zip opie-3fbba334274ca53bd26cd79ccd4662e529c61f40.tar.gz opie-3fbba334274ca53bd26cd79ccd4662e529c61f40.tar.bz2 |
Complete redesign of internal structure. Now, there exist a cetral view
class which manages the current implemented views table and card...
-rw-r--r-- | core/pim/addressbook/abview.cpp | 331 | ||||
-rw-r--r-- | core/pim/addressbook/abview.h | 81 |
2 files changed, 412 insertions, 0 deletions
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp new file mode 100644 index 0000000..d35e392 --- a/dev/null +++ b/core/pim/addressbook/abview.cpp | |||
@@ -0,0 +1,331 @@ | |||
1 | #include "abview.h" | ||
2 | |||
3 | // Is defined in LibQPE | ||
4 | extern QString categoryFileName(); | ||
5 | |||
6 | #include <qlayout.h> | ||
7 | |||
8 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered, const QStringList& slOrderedFields ): | ||
9 | QWidget(parent), | ||
10 | mCat(0), | ||
11 | m_inSearch( false ), | ||
12 | m_curr_category( 0 ), | ||
13 | m_curr_View( TableView ), | ||
14 | m_prev_View( TableView ), | ||
15 | m_curr_Contact ( 0 ), | ||
16 | m_contactdb ( "addressbook", 0l, 0l, false ), // Handle syncing myself.. ! | ||
17 | m_viewStack( 0l ), | ||
18 | m_abTable( 0l ), | ||
19 | m_orderedFields( ordered ), | ||
20 | m_slOrderedFields( slOrderedFields ) | ||
21 | { | ||
22 | mCat.load( categoryFileName() ); | ||
23 | |||
24 | // Create Layout and put WidgetStack into it. | ||
25 | QVBoxLayout *vb = new QVBoxLayout( this ); | ||
26 | m_viewStack = new QWidgetStack( this ); | ||
27 | vb->addWidget( m_viewStack ); | ||
28 | |||
29 | // Creat TableView | ||
30 | QVBox* tableBox = new QVBox( m_viewStack ); | ||
31 | m_abTable = new AbTable( &m_orderedFields, tableBox, "table" ); | ||
32 | m_abTable->setCurrentCell( 0, 0 ); | ||
33 | m_abTable->setFocus(); | ||
34 | |||
35 | // Add TableView to WidgetStack and raise it | ||
36 | m_viewStack -> addWidget( tableBox , TableView ); | ||
37 | |||
38 | // Create CardView and add it to WidgetStack | ||
39 | QVBox* cardBox = new QVBox( m_viewStack ); | ||
40 | m_ablabel = new AbLabel( cardBox, "CardView"); | ||
41 | m_viewStack -> addWidget( cardBox , CardView ); | ||
42 | |||
43 | // Connect views to me | ||
44 | connect ( m_abTable, SIGNAL( signalSwitch( void ) ), | ||
45 | this, SLOT( slotSwitch( void ) ) ); | ||
46 | connect ( m_ablabel, SIGNAL( signalOkPressed( void ) ), | ||
47 | this, SLOT( slotSwitch( void ) ) ); | ||
48 | |||
49 | load(); | ||
50 | } | ||
51 | |||
52 | void AbView::setView( Views view ) | ||
53 | { | ||
54 | qWarning("AbView::setView( Views view )"); | ||
55 | m_curr_View = view; | ||
56 | load(); | ||
57 | } | ||
58 | |||
59 | void AbView::addEntry( const OContact &newContact ) | ||
60 | { | ||
61 | qWarning("abview:AddContact"); | ||
62 | m_contactdb.add ( newContact ); | ||
63 | load(); | ||
64 | |||
65 | } | ||
66 | void AbView::removeEntry( const int UID ) | ||
67 | { | ||
68 | qWarning("abview:RemoveContact"); | ||
69 | m_contactdb.remove( UID ); | ||
70 | load(); | ||
71 | } | ||
72 | |||
73 | void AbView::replaceEntry( const OContact &contact ) | ||
74 | { | ||
75 | qWarning("abview:ReplaceContact"); | ||
76 | m_contactdb.replace( contact ); | ||
77 | load(); | ||
78 | |||
79 | } | ||
80 | |||
81 | OContact AbView::currentEntry() | ||
82 | { | ||
83 | switch ( (int) m_curr_View ) { | ||
84 | case TableView: | ||
85 | return ( m_abTable -> currentEntry() ); | ||
86 | break; | ||
87 | case CardView: | ||
88 | return ( m_ablabel -> currentEntry() ); | ||
89 | break; | ||
90 | } | ||
91 | return OContact(); | ||
92 | } | ||
93 | |||
94 | bool AbView::save() | ||
95 | { | ||
96 | qWarning("abView:Save data"); | ||
97 | |||
98 | return m_contactdb.save(); | ||
99 | } | ||
100 | |||
101 | // :SX Add: Just load for specific Category | ||
102 | void AbView::load() | ||
103 | { | ||
104 | qWarning("abView:Load data"); | ||
105 | |||
106 | m_list = m_contactdb.allRecords(); | ||
107 | clearForCategory(); | ||
108 | m_curr_Contact = 0; | ||
109 | |||
110 | qWarning ("Number of contacts: %d", m_list.count()); | ||
111 | |||
112 | updateView(); | ||
113 | |||
114 | } | ||
115 | |||
116 | void AbView::reload() | ||
117 | { | ||
118 | m_contactdb.reload(); | ||
119 | load(); | ||
120 | } | ||
121 | |||
122 | void AbView::clear() | ||
123 | { | ||
124 | // :SX | ||
125 | } | ||
126 | |||
127 | void AbView::setShowByCategory( Views view, const QString& cat ) | ||
128 | { | ||
129 | qWarning("AbView::setShowCategory( Views view, const QString& cat )"); | ||
130 | m_curr_View = view; | ||
131 | |||
132 | emit signalClearLetterPicker(); | ||
133 | |||
134 | if ( !cat.isNull() ) | ||
135 | m_curr_category = mCat.id("Contacts", cat ); | ||
136 | else | ||
137 | m_curr_category = -1; // Set to all | ||
138 | |||
139 | qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); | ||
140 | |||
141 | load(); | ||
142 | |||
143 | } | ||
144 | void AbView::setShowByLetter( char c ) | ||
145 | { | ||
146 | qWarning("void AbView::setShowByLetter( %c )", c ); | ||
147 | OContact query; | ||
148 | if ( c == 0 ){ | ||
149 | load(); | ||
150 | return; | ||
151 | }else{ | ||
152 | query.setLastName( QString("%1*").arg(c) ); | ||
153 | m_list = m_contactdb.queryByExample( query, OContactAccess::WildCards ); | ||
154 | clearForCategory(); | ||
155 | m_curr_Contact = 0; | ||
156 | } | ||
157 | updateView(); | ||
158 | } | ||
159 | |||
160 | QString AbView::showCategory() const | ||
161 | { | ||
162 | return mCat.label( "Contacts", m_curr_category ); | ||
163 | } | ||
164 | |||
165 | void AbView::showContact( const OContact& cnt ) | ||
166 | { | ||
167 | qWarning ("void AbView::showContact( const OContact& cnt )"); | ||
168 | // :SX | ||
169 | } | ||
170 | |||
171 | QStringList AbView::categories() | ||
172 | { | ||
173 | mCat.load( categoryFileName() ); | ||
174 | QStringList categoryList = mCat.labels( "Contacts" ); | ||
175 | return categoryList; | ||
176 | } | ||
177 | |||
178 | // BEGIN: Slots | ||
179 | void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, | ||
180 | bool , QString cat = QString::null ) | ||
181 | { | ||
182 | qWarning( "void AbView::slotDoFind" ); | ||
183 | // Use the current Category if nothing else selected | ||
184 | |||
185 | int category = 0; | ||
186 | |||
187 | if ( cat.isEmpty() ) | ||
188 | category = m_curr_category; | ||
189 | else{ | ||
190 | category = mCat.id("Contacts", cat ); | ||
191 | } | ||
192 | |||
193 | qWarning ("Find in Category %d", category); | ||
194 | |||
195 | QRegExp r( str ); | ||
196 | r.setCaseSensitive( caseSensitive ); | ||
197 | r.setWildcard( !useRegExp ); | ||
198 | |||
199 | // Get all matching entries out of the database | ||
200 | m_list = m_contactdb.matchRegexp( r ); | ||
201 | |||
202 | qWarning( "found: %d", m_list.count() ); | ||
203 | if ( m_list.count() == 0 ){ | ||
204 | emit signalNotFound(); | ||
205 | return; | ||
206 | } | ||
207 | |||
208 | // Now remove all contacts with wrong category (if any selected) | ||
209 | // This algorithm is a litte bit ineffective, but | ||
210 | // we will not have a lot of matching entries.. | ||
211 | clearForCategory(); | ||
212 | |||
213 | // Now show all found entries | ||
214 | updateView(); | ||
215 | } | ||
216 | |||
217 | void AbView::offSearch() | ||
218 | { | ||
219 | m_inSearch = false; | ||
220 | |||
221 | load(); | ||
222 | } | ||
223 | |||
224 | void AbView::slotSwitch(){ | ||
225 | qWarning("AbView::slotSwitch()"); | ||
226 | |||
227 | m_prev_View = m_curr_View; | ||
228 | switch ( (int) m_curr_View ){ | ||
229 | case TableView: | ||
230 | qWarning("Switching to CardView"); | ||
231 | m_curr_View = CardView; | ||
232 | break; | ||
233 | case CardView: | ||
234 | qWarning("Switching to TableView"); | ||
235 | m_curr_View = TableView; | ||
236 | break; | ||
237 | } | ||
238 | updateView(); | ||
239 | |||
240 | } | ||
241 | |||
242 | // END: Slots | ||
243 | |||
244 | void AbView::clearForCategory() | ||
245 | { | ||
246 | OContactAccess::List::Iterator it; | ||
247 | // Now remove all contacts with wrong category if any category selected | ||
248 | // This algorithm is a litte bit ineffective | ||
249 | if ( m_curr_category != -1 ){ | ||
250 | for ( it = m_list.begin(); it != m_list.end(); ++it ){ | ||
251 | if ( !contactCompare( *it, m_curr_category ) ){ | ||
252 | qWarning("Removing %d", (*it).uid()); | ||
253 | m_list.remove( (*it).uid() ); | ||
254 | it = m_list.begin(); | ||
255 | } | ||
256 | } | ||
257 | } | ||
258 | } | ||
259 | |||
260 | bool AbView::contactCompare( const OContact &cnt, int category ) | ||
261 | { | ||
262 | qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); | ||
263 | |||
264 | bool returnMe; | ||
265 | QArray<int> cats; | ||
266 | cats = cnt.categories(); | ||
267 | |||
268 | qWarning ("Number of categories: %d", cats.count() ); | ||
269 | |||
270 | returnMe = false; | ||
271 | if ( cats.count() == 0 ) | ||
272 | returnMe = true; | ||
273 | else { | ||
274 | int i; | ||
275 | for ( i = 0; i < int(cats.count()); i++ ) { | ||
276 | qWarning("Comparing %d with %d",cats[i],category ); | ||
277 | if ( cats[i] == category ) { | ||
278 | returnMe = true; | ||
279 | break; | ||
280 | } | ||
281 | } | ||
282 | } | ||
283 | qWarning ("Return: %d", returnMe); | ||
284 | return returnMe; | ||
285 | } | ||
286 | |||
287 | void AbView::updateView() | ||
288 | { | ||
289 | qWarning("AbView::updateView()"); | ||
290 | |||
291 | if ( m_viewStack -> visibleWidget() ){ | ||
292 | m_viewStack -> visibleWidget() -> clearFocus(); | ||
293 | } | ||
294 | |||
295 | // If we switching the view, we have to store some information | ||
296 | if ( m_prev_View != m_curr_View ){ | ||
297 | switch ( (int) m_prev_View ) { | ||
298 | case TableView: | ||
299 | m_curr_Contact = m_abTable -> currentEntry_UID(); | ||
300 | break; | ||
301 | case CardView: | ||
302 | m_curr_Contact = m_ablabel -> currentEntry_UID(); | ||
303 | break; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | m_prev_View = m_curr_View; | ||
308 | |||
309 | // Switch to new View | ||
310 | switch ( (int) m_curr_View ) { | ||
311 | case TableView: | ||
312 | m_abTable -> setContacts( m_list ); | ||
313 | if ( m_curr_Contact != 0 ) | ||
314 | m_abTable -> selectContact ( m_curr_Contact ); | ||
315 | m_abTable -> setFocus(); | ||
316 | emit signalViewSwitched ( (int) m_curr_View ); | ||
317 | break; | ||
318 | case CardView: | ||
319 | m_ablabel -> setContacts( m_list ); | ||
320 | if ( m_curr_Contact != 0 ) | ||
321 | m_ablabel -> selectContact( m_curr_Contact ); | ||
322 | m_ablabel -> setFocus(); | ||
323 | emit signalViewSwitched ( (int) m_curr_View ); | ||
324 | break; | ||
325 | } | ||
326 | |||
327 | // Raise the current View | ||
328 | m_viewStack -> raiseWidget( m_curr_View ); | ||
329 | } | ||
330 | |||
331 | |||
diff --git a/core/pim/addressbook/abview.h b/core/pim/addressbook/abview.h new file mode 100644 index 0000000..4d35338 --- a/dev/null +++ b/core/pim/addressbook/abview.h | |||
@@ -0,0 +1,81 @@ | |||
1 | #ifndef _ABVIEW_H_ | ||
2 | #define _ABVIEW_H_ | ||
3 | |||
4 | #include <qwidget.h> | ||
5 | #include <qwidgetstack.h> | ||
6 | |||
7 | #include <qpe/categories.h> | ||
8 | #include <opie/ocontact.h> | ||
9 | #include <opie/ocontactaccess.h> | ||
10 | |||
11 | #include "contacteditor.h" | ||
12 | #include "abtable.h" | ||
13 | #include "ablabel.h" | ||
14 | |||
15 | class AbView: public QWidget | ||
16 | { | ||
17 | Q_OBJECT | ||
18 | |||
19 | public: | ||
20 | enum Views{ TableView=0, CardView, PhoneBook, CompanyBook, EmailBook }; | ||
21 | |||
22 | AbView( QWidget* parent, const QValueList<int>& ordered, const QStringList& slOrderedFields ); | ||
23 | |||
24 | bool save(); | ||
25 | void load(); | ||
26 | void reload(); | ||
27 | void clear(); | ||
28 | |||
29 | void setView( Views view ); | ||
30 | void showContact( const OContact& cnt ); | ||
31 | void setShowByCategory( Views view, const QString& cat ); | ||
32 | void setShowByLetter( char c ); | ||
33 | // Add Entry and put to current | ||
34 | void addEntry( const OContact &newContact ); | ||
35 | void removeEntry( const int UID ); | ||
36 | void replaceEntry( const OContact &contact ); | ||
37 | OContact currentEntry(); | ||
38 | |||
39 | void inSearch() { m_inSearch = true; } | ||
40 | void offSearch(); | ||
41 | |||
42 | QString showCategory() const; | ||
43 | QStringList categories(); | ||
44 | |||
45 | signals: | ||
46 | void signalNotFound(); | ||
47 | void signalClearLetterPicker(); | ||
48 | void signalViewSwitched ( int ); | ||
49 | |||
50 | public slots: | ||
51 | void slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, | ||
52 | bool backwards, QString category = QString::null ); | ||
53 | void slotSwitch(); | ||
54 | |||
55 | private: | ||
56 | void updateView(); | ||
57 | void clearForCategory(); | ||
58 | bool contactCompare( const OContact &cnt, int category ); | ||
59 | void parseName( const QString& name, QString *first, QString *middle, | ||
60 | QString * last ); | ||
61 | |||
62 | Categories mCat; | ||
63 | bool m_inSearch; | ||
64 | int m_curr_category; | ||
65 | Views m_curr_View; | ||
66 | Views m_prev_View; | ||
67 | int m_curr_Contact; | ||
68 | |||
69 | OContactAccess m_contactdb; | ||
70 | OContactAccess::List m_list; | ||
71 | |||
72 | QWidgetStack* m_viewStack; | ||
73 | AbTable* m_abTable; | ||
74 | AbLabel* m_ablabel; | ||
75 | |||
76 | QValueList<int> m_orderedFields; | ||
77 | QStringList m_slOrderedFields; | ||
78 | }; | ||
79 | |||
80 | |||
81 | #endif | ||