summaryrefslogtreecommitdiff
authorzecke <zecke>2005-06-27 17:50:15 (UTC)
committer zecke <zecke>2005-06-27 17:50:15 (UTC)
commit0c99f2087c4d5a1cab6c2bd1083d6db3f2a4cae8 (patch) (unidiff)
treeab7169403134f8171a454e053f2e34c6fd30eede
parentcc4771f193215827036689291d9d3d74d2cbef3f (diff)
downloadopie-0c99f2087c4d5a1cab6c2bd1083d6db3f2a4cae8.zip
opie-0c99f2087c4d5a1cab6c2bd1083d6db3f2a4cae8.tar.gz
opie-0c99f2087c4d5a1cab6c2bd1083d6db3f2a4cae8.tar.bz2
Sort by Anniversary and Birthday
Patch courtsey Marcin Juszkiewicz
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/today/plugins/addressbook/addresspluginwidget.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/pim/today/plugins/addressbook/addresspluginwidget.cpp b/core/pim/today/plugins/addressbook/addresspluginwidget.cpp
index 5662af2..75bf474 100644
--- a/core/pim/today/plugins/addressbook/addresspluginwidget.cpp
+++ b/core/pim/today/plugins/addressbook/addresspluginwidget.cpp
@@ -1,215 +1,225 @@
1/* 1/*
2 * addresspluginwidget.cpp 2 * addresspluginwidget.cpp
3 * 3 *
4 * copyright : (c) 2003 by Stefan Eilers 4 * copyright : (c) 2003 by Stefan Eilers
5 * email : eilers.stefan@epost.de 5 * email : eilers.stefan@epost.de
6 * 6 *
7 * This implementation was derived from the todolist plugin implementation 7 * This implementation was derived from the todolist plugin implementation
8 * 8 *
9 */ 9 */
10/*************************************************************************** 10/***************************************************************************
11 * * 11 * *
12 * This program is free software; you can redistribute it and/or modify * 12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by * 13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or * 14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. * 15 * (at your option) any later version. *
16 * * 16 * *
17 ***************************************************************************/ 17 ***************************************************************************/
18 18
19#include "addresspluginwidget.h" 19#include "addresspluginwidget.h"
20 20
21#include <opie2/odebug.h> 21#include <opie2/odebug.h>
22#include <opie2/opimcontact.h> 22#include <opie2/opimcontact.h>
23 23
24#include <qpe/config.h> 24#include <qpe/config.h>
25 25
26AddressBookPluginWidget::AddressBookPluginWidget( QWidget *parent, const char* name ) 26AddressBookPluginWidget::AddressBookPluginWidget( QWidget *parent, const char* name )
27 : QWidget( parent, name ) { 27 : QWidget( parent, name ) {
28 28
29 addressLabel = 0l; 29 addressLabel = 0l;
30 m_contactdb = 0l; 30 m_contactdb = 0l;
31 layoutTodo = 0l; 31 layoutTodo = 0l;
32 32
33 m_contactdb = new Opie::OPimContactAccess("addressplugin"); 33 m_contactdb = new Opie::OPimContactAccess("addressplugin");
34 34
35 connect( m_contactdb, SIGNAL( signalChanged(const Opie::OPimContactAccess*) ), 35 connect( m_contactdb, SIGNAL( signalChanged(const Opie::OPimContactAccess*) ),
36 this, SLOT( refresh(const Opie::OPimContactAccess*) ) ); 36 this, SLOT( refresh(const Opie::OPimContactAccess*) ) );
37 37
38 38
39 readConfig(); 39 readConfig();
40 getAddress(); 40 getAddress();
41} 41}
42 42
43AddressBookPluginWidget::~AddressBookPluginWidget() { 43AddressBookPluginWidget::~AddressBookPluginWidget() {
44 delete m_contactdb; 44 delete m_contactdb;
45} 45}
46 46
47void AddressBookPluginWidget::refresh( const Opie::OPimContactAccess* ) 47void AddressBookPluginWidget::refresh( const Opie::OPimContactAccess* )
48{ 48{
49 owarn << " AddressBookPluginWidget::Database was changed externally ! " << oendl; 49 owarn << " AddressBookPluginWidget::Database was changed externally ! " << oendl;
50 m_contactdb->reload(); 50 m_contactdb->reload();
51 getAddress(); 51 getAddress();
52} 52}
53 53
54void AddressBookPluginWidget::reinitialize() { 54void AddressBookPluginWidget::reinitialize() {
55 readConfig(); 55 readConfig();
56 getAddress(); 56 getAddress();
57} 57}
58 58
59void AddressBookPluginWidget::readConfig() { 59void AddressBookPluginWidget::readConfig() {
60 Config cfg( "todayaddressplugin" ); 60 Config cfg( "todayaddressplugin" );
61 cfg.setGroup( "config" ); 61 cfg.setGroup( "config" );
62 m_maxLinesTask = cfg.readNumEntry( "maxlinestask", 5 ); 62 m_maxLinesTask = cfg.readNumEntry( "maxlinestask", 5 );
63 m_maxCharClip = cfg.readNumEntry( "maxcharclip", 38 ); 63 m_maxCharClip = cfg.readNumEntry( "maxcharclip", 38 );
64 m_daysLookAhead = cfg.readNumEntry( "dayslookahead", 14 ); 64 m_daysLookAhead = cfg.readNumEntry( "dayslookahead", 14 );
65 m_urgentDays = cfg.readNumEntry( "urgentdays", 7 ); 65 m_urgentDays = cfg.readNumEntry( "urgentdays", 7 );
66 m_entryColor = cfg.readEntry("entrycolor", Qt::black.name() ); 66 m_entryColor = cfg.readEntry("entrycolor", Qt::black.name() );
67 m_headlineColor = cfg.readEntry( "headlinecolor", Qt::black.name() ); 67 m_headlineColor = cfg.readEntry( "headlinecolor", Qt::black.name() );
68 m_urgentColor = cfg.readEntry( "urgentcolor", Qt::red.name() ); 68 m_urgentColor = cfg.readEntry( "urgentcolor", Qt::red.name() );
69 m_showBirthdays = cfg.readBoolEntry( "showBirthdays", true ); 69 m_showBirthdays = cfg.readBoolEntry( "showBirthdays", true );
70 m_showAnniversaries = cfg.readBoolEntry( "showAnniversaries", true ); 70 m_showAnniversaries = cfg.readBoolEntry( "showAnniversaries", true );
71} 71}
72 72
73 73
74/** 74/**
75 * Get the addresss 75 * Get the addresss
76 */ 76 */
77void AddressBookPluginWidget::getAddress() { 77void AddressBookPluginWidget::getAddress() {
78 78
79 if ( ! layoutTodo ){ 79 if ( ! layoutTodo ){
80 layoutTodo = new QVBoxLayout( this ); 80 layoutTodo = new QVBoxLayout( this );
81 } 81 }
82 82
83 if ( ! addressLabel ) { 83 if ( ! addressLabel ) {
84 addressLabel = new Opie::Ui::OClickableLabel( this ); 84 addressLabel = new Opie::Ui::OClickableLabel( this );
85 connect( addressLabel, SIGNAL( clicked() ), this, SLOT( startAddressBook() ) ); 85 connect( addressLabel, SIGNAL( clicked() ), this, SLOT( startAddressBook() ) );
86 layoutTodo->addWidget( addressLabel ); 86 layoutTodo->addWidget( addressLabel );
87 } 87 }
88 88
89 QString output; 89 QString output;
90 90
91 // Check whether the database provide the search option.. 91 // Check whether the database provide the search option..
92 if ( !m_contactdb->hasQuerySettings( Opie::OPimContactAccess::DateDiff ) ){ 92 if ( !m_contactdb->hasQuerySettings( Opie::OPimContactAccess::DateDiff ) ){
93 // Libopie seems to be old.. 93 // Libopie seems to be old..
94 output = QObject::tr( "Database does not provide this search query ! Please upgrade libOpie !<br>" ); 94 output = QObject::tr( "Database does not provide this search query ! Please upgrade libOpie !<br>" );
95 addressLabel->setText( output ); 95 addressLabel->setText( output );
96 return; 96 return;
97 } 97 }
98 98
99 // Define the query for birthdays and start search.. 99 // Define the query for birthdays and start search..
100 QDate lookAheadDate = QDate::currentDate().addDays( m_daysLookAhead ); 100 QDate lookAheadDate = QDate::currentDate().addDays( m_daysLookAhead );
101 int ammount = 0; 101 int ammount = 0;
102 if ( m_showBirthdays ){ 102 if ( m_showBirthdays ){
103 owarn << "Searching from now (" << QDate::currentDate().toString() << ") until " 103 owarn << "Searching from now (" << QDate::currentDate().toString() << ") until "
104 << lookAheadDate.toString() << " ! " << oendl; 104 << lookAheadDate.toString() << " ! " << oendl;
105 105
106 if ( m_contactdb->hasQuerySettings( Opie::OPimContactAccess::DateDiff ) ){ 106 if ( m_contactdb->hasQuerySettings( Opie::OPimContactAccess::DateDiff ) ){
107 107
108 108
109 Opie::OPimContact querybirthdays; 109 Opie::OPimContact querybirthdays;
110 querybirthdays.setBirthday( lookAheadDate ); 110 querybirthdays.setBirthday( lookAheadDate );
111 111
112 m_list = m_contactdb->queryByExample( querybirthdays, 112 m_list = m_contactdb->queryByExample( querybirthdays,
113 Opie::OPimContactAccess::DateDiff ); 113 Opie::OPimContactAccess::DateDiff );
114 if ( m_list.count() > 0 ){ 114 if ( m_list.count() > 0 ){
115 output = "<font color=" + m_headlineColor + ">" 115 output = "<font color=" + m_headlineColor + ">"
116 + QObject::tr( "Next birthdays in <b> %1 </b> days:" ) 116 + QObject::tr( "Next birthdays in <b> %1 </b> days:" )
117 .arg( m_daysLookAhead ) 117 .arg( m_daysLookAhead )
118 + "</font> <br>"; 118 + "</font> <br>";
119
120 // Sort filtered results
121 m_list = m_contactdb->sorted( m_list, true, Opie::OPimContactAccess::SortBirthday,
122 Opie::OPimContactAccess::FilterOff, NULL );
123
119 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) { 124 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
120 if ( ammount++ < m_maxLinesTask ){ 125 if ( ammount++ < m_maxLinesTask ){
121 // Now we want to calculate how many days 126 // Now we want to calculate how many days
122 //until birthday. We have to set 127 //until birthday. We have to set
123 // the correct year to calculate the day diff... 128 // the correct year to calculate the day diff...
124 QDate destdate = (*m_it).birthday(); 129 QDate destdate = (*m_it).birthday();
125 destdate.setYMD( QDate::currentDate().year(), 130 destdate.setYMD( QDate::currentDate().year(),
126 destdate.month(), destdate.day() ); 131 destdate.month(), destdate.day() );
127 if ( QDate::currentDate().daysTo(destdate) < 0 ) 132 if ( QDate::currentDate().daysTo(destdate) < 0 )
128 destdate.setYMD( QDate::currentDate().year()+1, 133 destdate.setYMD( QDate::currentDate().year()+1,
129 destdate.month(), destdate.day() ); 134 destdate.month(), destdate.day() );
130 135
131 136
132 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays ) 137 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays )
133 output += "<font color=" + m_urgentColor + "><b>-" 138 output += "<font color=" + m_urgentColor + "><b>-"
134 + (*m_it).fullName() 139 + (*m_it).fullName()
135 + " (" 140 + " ("
136 + QString::number(QDate::currentDate() 141 + QString::number(QDate::currentDate()
137 .daysTo(destdate)) 142 .daysTo(destdate))
138 + " Days) </b></font><br>"; 143 + " Days) </b></font><br>";
139 144
140 else 145 else
141 output += "<font color=" + m_entryColor + "><b>-" 146 output += "<font color=" + m_entryColor + "><b>-"
142 + (*m_it).fullName() 147 + (*m_it).fullName()
143 + " (" 148 + " ("
144 + QString::number(QDate::currentDate() 149 + QString::number(QDate::currentDate()
145 .daysTo(destdate)) 150 .daysTo(destdate))
146 + " Days) </b></font><br>"; 151 + " Days) </b></font><br>";
147 } 152 }
148 } 153 }
149 } else { 154 } else {
150 output = "<font color=" + m_headlineColor + ">" 155 output = "<font color=" + m_headlineColor + ">"
151 + QObject::tr( "No birthdays in <b> %1 </b> days!" ) 156 + QObject::tr( "No birthdays in <b> %1 </b> days!" )
152 .arg( m_daysLookAhead ) 157 .arg( m_daysLookAhead )
153 + "</font> <br>"; 158 + "</font> <br>";
154 } 159 }
155 } 160 }
156 } 161 }
157 162
158 if ( m_showAnniversaries ){ 163 if ( m_showAnniversaries ){
159 // Define the query for anniversaries and start search.. 164 // Define the query for anniversaries and start search..
160 Opie::OPimContact queryanniversaries; 165 Opie::OPimContact queryanniversaries;
161 queryanniversaries.setAnniversary( lookAheadDate ); 166 queryanniversaries.setAnniversary( lookAheadDate );
162 167
163 m_list = m_contactdb->queryByExample( queryanniversaries, Opie::OPimContactAccess::DateDiff ); 168 m_list = m_contactdb->queryByExample( queryanniversaries, Opie::OPimContactAccess::DateDiff );
164 169
165 ammount = 0; 170 ammount = 0;
166 if ( m_list.count() > 0 ){ 171 if ( m_list.count() > 0 ){
167 output += "<font color=" + m_headlineColor + ">" 172 output += "<font color=" + m_headlineColor + ">"
168 + QObject::tr( "Next anniversaries in <b> %1 </b> days:" ) 173 + QObject::tr( "Next anniversaries in <b> %1 </b> days:" )
169 .arg( m_daysLookAhead ) 174 .arg( m_daysLookAhead )
170 + "</font> <br>"; 175 + "</font> <br>";
176
177 // Sort filtered results
178 m_list = m_contactdb->sorted( m_list, true, Opie::OPimContactAccess::SortAnniversary,
179 Opie::OPimContactAccess::FilterOff, NULL );
180
171 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) { 181 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
172 if ( ammount++ < m_maxLinesTask ){ 182 if ( ammount++ < m_maxLinesTask ){
173 // Now we want to calculate how many days until anniversary. 183 // Now we want to calculate how many days until anniversary.
174 // We have to set the correct year to calculate the day diff... 184 // We have to set the correct year to calculate the day diff...
175 QDate destdate = (*m_it).anniversary(); 185 QDate destdate = (*m_it).anniversary();
176 destdate.setYMD( QDate::currentDate().year(), destdate.month(), 186 destdate.setYMD( QDate::currentDate().year(), destdate.month(),
177 destdate.day() ); 187 destdate.day() );
178 if ( QDate::currentDate().daysTo(destdate) < 0 ) 188 if ( QDate::currentDate().daysTo(destdate) < 0 )
179 destdate.setYMD( QDate::currentDate().year()+1, 189 destdate.setYMD( QDate::currentDate().year()+1,
180 destdate.month(), destdate.day() ); 190 destdate.month(), destdate.day() );
181 191
182 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays ) 192 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays )
183 output += "<font color=" + m_urgentColor + "><b>-" 193 output += "<font color=" + m_urgentColor + "><b>-"
184 + (*m_it).fullName() 194 + (*m_it).fullName()
185 + " (" 195 + " ("
186 + QString::number(QDate::currentDate() 196 + QString::number(QDate::currentDate()
187 .daysTo( destdate ) ) 197 .daysTo( destdate ) )
188 + " Days) </b></font><br>"; 198 + " Days) </b></font><br>";
189 else 199 else
190 output += "<font color=" + m_entryColor + "><b>-" 200 output += "<font color=" + m_entryColor + "><b>-"
191 + (*m_it).fullName() 201 + (*m_it).fullName()
192 + " (" 202 + " ("
193 + QString::number(QDate::currentDate() 203 + QString::number(QDate::currentDate()
194 .daysTo( destdate ) ) 204 .daysTo( destdate ) )
195 + " Days) </b></font><br>"; 205 + " Days) </b></font><br>";
196 } 206 }
197 } 207 }
198 } else { 208 } else {
199 output += "<font color=" + m_headlineColor + ">" 209 output += "<font color=" + m_headlineColor + ">"
200 + QObject::tr( "No anniversaries in <b> %1 </b> days!" ) 210 + QObject::tr( "No anniversaries in <b> %1 </b> days!" )
201 .arg( m_daysLookAhead ) 211 .arg( m_daysLookAhead )
202 + "</font> <br>"; 212 + "</font> <br>";
203 } 213 }
204 } 214 }
205 215
206 addressLabel->setText( output ); 216 addressLabel->setText( output );
207} 217}
208 218
209/** 219/**
210 * start the todolist 220 * start the todolist
211 */ 221 */
212void AddressBookPluginWidget::startAddressBook() { 222void AddressBookPluginWidget::startAddressBook() {
213 QCopEnvelope e( "QPE/System", "execute(QString)" ); 223 QCopEnvelope e( "QPE/System", "execute(QString)" );
214 e << QString( "addressbook" ); 224 e << QString( "addressbook" );
215} 225}