summaryrefslogtreecommitdiff
path: root/core/pim/today/plugins/addressbook/addresspluginwidget.cpp
Unidiff
Diffstat (limited to 'core/pim/today/plugins/addressbook/addresspluginwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/today/plugins/addressbook/addresspluginwidget.cpp93
1 files changed, 60 insertions, 33 deletions
diff --git a/core/pim/today/plugins/addressbook/addresspluginwidget.cpp b/core/pim/today/plugins/addressbook/addresspluginwidget.cpp
index 7d87fca..498de28 100644
--- a/core/pim/today/plugins/addressbook/addresspluginwidget.cpp
+++ b/core/pim/today/plugins/addressbook/addresspluginwidget.cpp
@@ -75,6 +75,8 @@ void AddressBookPluginWidget::readConfig() {
75 m_entryColor = cfg.readEntry("entrycolor", Qt::black.name() ); 75 m_entryColor = cfg.readEntry("entrycolor", Qt::black.name() );
76 m_headlineColor = cfg.readEntry( "headlinecolor", Qt::black.name() ); 76 m_headlineColor = cfg.readEntry( "headlinecolor", Qt::black.name() );
77 m_urgentColor = cfg.readEntry( "urgentcolor", Qt::red.name() ); 77 m_urgentColor = cfg.readEntry( "urgentcolor", Qt::red.name() );
78 m_showBirthdays = cfg.readBoolEntry( "showBirthdays", true );
79 m_showAnniversaries = cfg.readBoolEntry( "showAnniversaries", true );
78} 80}
79 81
80 82
@@ -96,51 +98,73 @@ void AddressBookPluginWidget::getAddress() {
96 QString output; 98 QString output;
97 99
98 // Check whether the database provide the search option.. 100 // Check whether the database provide the search option..
99 if ( ! m_contactdb->hasQuerySettings( OContactAccess::DateDiff ) ){ 101 // The following if-statement was replaced due to a bug in some
100 102 // implementations of libopie. The replacement should work everywhere..(eilers)
101 // Define the query for birthdays and start search.. 103 // if ( !m_contactdb->hasQuerySettings( OContactAccess::DateDiff ) ){
102 QDate lookAheadDate = QDate::currentDate().addDays( m_daysLookAhead ); 104 if ( !( m_contactdb->querySettings() & OContactAccess::DateDiff ) ){
103 qWarning("Searching from now (%s) until %s ! ", QDate::currentDate().toString().latin1(), 105 // Libopie seems to be old..
106 output = QObject::tr( "Database does not provide this search query ! Please upgrade libOpie !<br>" );
107 addressLabel->setText( output );
108 return;
109 }
110
111 // Define the query for birthdays and start search..
112 QDate lookAheadDate = QDate::currentDate().addDays( m_daysLookAhead );
113 int ammount = 0;
114 if ( m_showBirthdays ){
115 qWarning("Searching from now (%s) until %s ! ",
116 QDate::currentDate().toString().latin1(),
104 lookAheadDate.toString().latin1() ); 117 lookAheadDate.toString().latin1() );
105 OContact querybirthdays; 118 OContact querybirthdays;
106 querybirthdays.setBirthday( lookAheadDate ); 119 querybirthdays.setBirthday( lookAheadDate );
107
108 int ammount = 0;
109 120
110 m_list = m_contactdb->queryByExample( querybirthdays, OContactAccess::DateDiff ); 121
122 m_list = m_contactdb->queryByExample( querybirthdays,
123 OContactAccess::DateDiff );
111 if ( m_list.count() > 0 ){ 124 if ( m_list.count() > 0 ){
112 output = "<font color=" + m_headlineColor + ">" 125 output = "<font color=" + m_headlineColor + ">"
113 + QObject::tr( "Next birthdays in <b> %1 </b> days:" ).arg( m_daysLookAhead ) 126 + QObject::tr( "Next birthdays in <b> %1 </b> days:" )
127 .arg( m_daysLookAhead )
114 + "</font> <br>"; 128 + "</font> <br>";
115 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) { 129 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
116 if ( ammount++ < m_maxLinesTask ){ 130 if ( ammount++ < m_maxLinesTask ){
117 // Now we want to calculate how many days until birthday. We have to set 131 // Now we want to calculate how many days
132 //until birthday. We have to set
118 // the correct year to calculate the day diff... 133 // the correct year to calculate the day diff...
119 QDate destdate = (*m_it).birthday(); 134 QDate destdate = (*m_it).birthday();
120 destdate.setYMD( QDate::currentDate().year(), destdate.month(), destdate.day() ); 135 destdate.setYMD( QDate::currentDate().year(),
136 destdate.month(), destdate.day() );
121 if ( QDate::currentDate().daysTo(destdate) < 0 ) 137 if ( QDate::currentDate().daysTo(destdate) < 0 )
122 destdate.setYMD( QDate::currentDate().year()+1, destdate.month(), destdate.day() ); 138 destdate.setYMD( QDate::currentDate().year()+1,
139 destdate.month(), destdate.day() );
123 140
124 141
125 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays ) 142 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays )
126 output += "<font color=" + m_urgentColor + "><b>-" + (*m_it).fullName() 143 output += "<font color=" + m_urgentColor + "><b>-"
144 + (*m_it).fullName()
127 + " (" 145 + " ("
128 + QString::number(QDate::currentDate().daysTo(destdate)) 146 + QString::number(QDate::currentDate()
147 .daysTo(destdate))
129 + " Days) </b></font><br>"; 148 + " Days) </b></font><br>";
130 149
131 else 150 else
132 output += "<font color=" + m_entryColor + "><b>-" + (*m_it).fullName() 151 output += "<font color=" + m_entryColor + "><b>-"
152 + (*m_it).fullName()
133 + " (" 153 + " ("
134 + QString::number(QDate::currentDate().daysTo(destdate)) 154 + QString::number(QDate::currentDate()
155 .daysTo(destdate))
135 + " Days) </b></font><br>"; 156 + " Days) </b></font><br>";
136 } 157 }
137 } 158 }
138 } else { 159 } else {
139 output = "<font color=" + m_headlineColor + ">" 160 output = "<font color=" + m_headlineColor + ">"
140 + QObject::tr( "No birthdays in <b> %1 </b> days!" ).arg( m_daysLookAhead ) 161 + QObject::tr( "No birthdays in <b> %1 </b> days!" )
162 .arg( m_daysLookAhead )
141 + "</font> <br>"; 163 + "</font> <br>";
142 } 164 }
165 }
143 166
167 if ( m_showAnniversaries ){
144 // Define the query for anniversaries and start search.. 168 // Define the query for anniversaries and start search..
145 OContact queryanniversaries; 169 OContact queryanniversaries;
146 queryanniversaries.setAnniversary( lookAheadDate ); 170 queryanniversaries.setAnniversary( lookAheadDate );
@@ -150,41 +174,44 @@ void AddressBookPluginWidget::getAddress() {
150 ammount = 0; 174 ammount = 0;
151 if ( m_list.count() > 0 ){ 175 if ( m_list.count() > 0 ){
152 output += "<font color=" + m_headlineColor + ">" 176 output += "<font color=" + m_headlineColor + ">"
153 + QObject::tr( "Next anniversaries in <b> %1 </b> days:" ).arg( m_daysLookAhead ) 177 + QObject::tr( "Next anniversaries in <b> %1 </b> days:" )
178 .arg( m_daysLookAhead )
154 + "</font> <br>"; 179 + "</font> <br>";
155 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) { 180 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
156 if ( ammount++ < m_maxLinesTask ){ 181 if ( ammount++ < m_maxLinesTask ){
157 // Now we want to calculate how many days until anniversary. We have to set 182 // Now we want to calculate how many days until anniversary.
158 // the correct year to calculate the day diff... 183 // We have to set the correct year to calculate the day diff...
159 QDate destdate = (*m_it).anniversary(); 184 QDate destdate = (*m_it).anniversary();
160 destdate.setYMD( QDate::currentDate().year(), destdate.month(), destdate.day() ); 185 destdate.setYMD( QDate::currentDate().year(), destdate.month(),
186 destdate.day() );
161 if ( QDate::currentDate().daysTo(destdate) < 0 ) 187 if ( QDate::currentDate().daysTo(destdate) < 0 )
162 destdate.setYMD( QDate::currentDate().year()+1, destdate.month(), destdate.day() ); 188 destdate.setYMD( QDate::currentDate().year()+1,
189 destdate.month(), destdate.day() );
163 190
164 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays ) 191 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays )
165 output += "<font color=" + m_urgentColor + "><b>-" + (*m_it).fullName() 192 output += "<font color=" + m_urgentColor + "><b>-"
193 + (*m_it).fullName()
166 + " (" 194 + " ("
167 + QString::number(QDate::currentDate().daysTo( destdate ) ) 195 + QString::number(QDate::currentDate()
196 .daysTo( destdate ) )
168 + " Days) </b></font><br>"; 197 + " Days) </b></font><br>";
169 else 198 else
170 output += "<font color=" + m_entryColor + "><b>-" + (*m_it).fullName() 199 output += "<font color=" + m_entryColor + "><b>-"
200 + (*m_it).fullName()
171 + " (" 201 + " ("
172 + QString::number(QDate::currentDate().daysTo( destdate ) ) 202 + QString::number(QDate::currentDate()
203 .daysTo( destdate ) )
173 + " Days) </b></font><br>"; 204 + " Days) </b></font><br>";
174 } 205 }
175 } 206 }
176 } else { 207 } else {
177 output += "<font color=" + m_headlineColor + ">" 208 output += "<font color=" + m_headlineColor + ">"
178 + QObject::tr( "No anniversaries in <b> %1 </b> days!" ).arg( m_daysLookAhead ) 209 + QObject::tr( "No anniversaries in <b> %1 </b> days!" )
210 .arg( m_daysLookAhead )
179 + "</font> <br>"; 211 + "</font> <br>";
180 } 212 }
181
182
183 }else{
184 // Libopie seems to be old..
185 output = QObject::tr( "Database does not provide this search query ! Please upgrade libOpie !<br>" );
186 } 213 }
187 214
188 addressLabel->setText( output ); 215 addressLabel->setText( output );
189} 216}
190 217