00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include <qlabel.h>
00025
#include <qlayout.h>
00026
00027
#include <kdialog.h>
00028
#include <kglobal.h>
00029
#include <kiconloader.h>
00030
#include <klocale.h>
00031
#include <kparts/part.h>
00032
#include <kstandarddirs.h>
00033
#include <kurllabel.h>
00034
#include <qtooltip.h>
00035
#include <libkcal/event.h>
00036
#include <libkcal/resourcecalendar.h>
00037
#include <libkcal/resourcelocal.h>
00038
#include <libkdepim/kpimprefs.h>
00039
00040
#include "core.h"
00041
#include "plugin.h"
00042
#include "korganizerplugin.h"
00043
00044
#include "korganizer/stdcalendar.h"
00045
00046
#include "summarywidget.h"
00047
00048 SummaryWidget::SummaryWidget( KOrganizerPlugin *plugin,
QWidget *parent,
00049
const char *name )
00050 : Kontact::
Summary( parent, name ), mPlugin( plugin ), mCalendar( 0 )
00051 {
00052
QVBoxLayout *mainLayout =
new QVBoxLayout(
this, 3, 3 );
00053
00054
QPixmap icon = KGlobal::iconLoader()->loadIcon(
"kontact_date",
00055 KIcon::Desktop, KIcon::SizeMedium );
00056
QWidget *header =
createHeader(
this, icon, i18n(
"Appointments" ) );
00057 mainLayout->addWidget( header );
00058
00059 mLayout =
new QGridLayout( mainLayout, 7, 5, 3 );
00060 mLayout->setRowStretch( 6, 1 );
00061
00062 mCalendar = KOrg::StdCalendar::self();
00063 mCalendar->load();
00064
00065 connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( updateView() ) );
00066 connect( mPlugin->core(), SIGNAL( dayChanged(
const QDate& ) ),
00067 SLOT( updateView() ) );
00068
00069 updateView();
00070 }
00071
00072 SummaryWidget::~SummaryWidget()
00073 {
00074 }
00075
00076
void SummaryWidget::updateView()
00077 {
00078 mLabels.setAutoDelete(
true );
00079 mLabels.clear();
00080 mLabels.setAutoDelete(
false );
00081
00082 KIconLoader loader(
"korganizer" );
00083
00084 KConfig config(
"kcmkorgsummaryrc" );
00085
00086 config.setGroup(
"Calendar" );
00087
int days = config.readNumEntry(
"DaysToShow", 1 );
00088
00089
QLabel *label = 0;
00090
int counter = 0;
00091
QPixmap pm = loader.loadIcon(
"appointment", KIcon::Small );
00092
00093
QDate dt;
00094
for ( dt=QDate::currentDate();
00095 dt<=QDate::currentDate().addDays( days - 1 );
00096 dt=dt.addDays(1) ) {
00097 KCal::Event::List events = mCalendar->events( dt,
true );
00098 KCal::Event *ev;
00099 KCal::Event::List::ConstIterator it;
00100
for ( it=events.begin(); it!=events.end(); ++it ) {
00101 ev = *it;
00102
00103
00104
int span=1;
int dayof=1;
00105
if ( ev->isMultiDay() ) {
00106
QDate d = ev->dtStart().date();
00107
while ( d < ev->dtEnd().date() ) {
00108
if ( d < dt ) {
00109 dayof++;
00110 }
00111 span++;
00112 d=d.addDays( 1 );
00113 }
00114 }
00115
00116
00117 label =
new QLabel(
this );
00118 label->setPixmap( pm );
00119 label->setMaximumSize( label->minimumSizeHint() );
00120 mLayout->addWidget( label, counter, 0 );
00121 mLabels.append( label );
00122
00123
00124
bool makeBold =
false;
00125
QString datestr;
00126
00127
00128
QDate sD = QDate::QDate( dt.year(), dt.month(), dt.day() );
00129
if ( ev->isMultiDay() ) {
00130 sD.setYMD( dt.year(), dt.month(), dt.day() );
00131 }
00132
if ( ( sD.month() == QDate::currentDate().month() ) &&
00133 ( sD.day() == QDate::currentDate().day() ) ) {
00134 datestr = i18n(
"Today" );
00135 makeBold =
true;
00136 }
else if ( ( sD.month() == QDate::currentDate().addDays( 1 ).month() ) &&
00137 ( sD.day() == QDate::currentDate().addDays( 1 ).day() ) ) {
00138 datestr = i18n(
"Tomorrow" );
00139 }
else {
00140 datestr = KGlobal::locale()->formatDate( sD );
00141 }
00142 label =
new QLabel( datestr,
this );
00143 label->setAlignment( AlignLeft | AlignVCenter );
00144
if ( makeBold ) {
00145
QFont font = label->font();
00146 font.setBold(
true );
00147 label->setFont( font );
00148 }
00149 mLayout->addWidget( label, counter, 1 );
00150 mLabels.append( label );
00151
00152
00153
QString newtext = ev->summary();
00154
if ( ev->isMultiDay() ) {
00155 newtext.append(
QString(
" (%1/%2)").arg( dayof ).arg( span ) );
00156 }
00157
00158 KURLLabel *urlLabel =
new KURLLabel( ev->uid(), newtext,
this );
00159 mLayout->addWidget( urlLabel, counter, 2 );
00160 mLabels.append( urlLabel );
00161
00162
if ( !ev->description().isEmpty() ) {
00163 QToolTip::add( urlLabel, ev->description() );
00164 }
00165
00166
00167
if ( !ev->doesFloat() ) {
00168
QTime sST = ev->dtStart().time();
00169
QTime sET = ev->dtEnd().time();
00170
if ( ev->isMultiDay() ) {
00171
if ( ev->dtStart().date() < dt ) {
00172 sST = QTime::QTime( 0, 0 );
00173 }
00174
if ( ev->dtEnd().date() > dt ) {
00175 sET = QTime::QTime( 23, 59 );
00176 }
00177 }
00178 datestr = i18n(
"Time from - to",
"%1 - %2" )
00179 .arg( KGlobal::locale()->formatTime( sST ) )
00180 .arg( KGlobal::locale()->formatTime( sET ) );
00181 label =
new QLabel( datestr,
this );
00182 label->setAlignment( AlignLeft | AlignVCenter );
00183 mLayout->addWidget( label, counter, 3 );
00184 mLabels.append( label );
00185 }
00186
00187 connect( urlLabel, SIGNAL( leftClickedURL(
const QString& ) ),
00188
this, SLOT( selectEvent(
const QString& ) ) );
00189
00190 counter++;
00191 }
00192 }
00193
00194
if ( !counter ) {
00195
QLabel *noEvents =
new QLabel( i18n(
"No appointments pending" ),
this );
00196 noEvents->setAlignment( AlignRight | AlignVCenter );
00197 mLayout->addWidget( noEvents, 0, 2 );
00198 mLabels.append( noEvents );
00199 }
00200
00201
for ( label = mLabels.first(); label; label = mLabels.next() )
00202 label->show();
00203 }
00204
00205
void SummaryWidget::selectEvent(
const QString & )
00206 {
00207 mPlugin->core()->selectPlugin(
"kontact_korganizerplugin" );
00208 mPlugin->interface()->showEventView();
00209 }
00210
00211
QStringList SummaryWidget::configModules()
const
00212
{
00213
return QStringList(
"kcmkorgsummary.desktop" );
00214 }
00215
00216
#include "summarywidget.moc"