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 "korganizeriface_stub.h"
00041
00042 #include "core.h"
00043 #include "plugin.h"
00044 #include "korganizerplugin.h"
00045
00046 #include "korganizer/stdcalendar.h"
00047
00048 #include "summarywidget.h"
00049
00050 SummaryWidget::SummaryWidget( KOrganizerPlugin *plugin, QWidget *parent,
00051 const char *name )
00052 : Kontact::Summary( parent, name ), mPlugin( plugin ), mCalendar( 0 )
00053 {
00054 QVBoxLayout *mainLayout = new QVBoxLayout( this, 3, 3 );
00055
00056 QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_date",
00057 KIcon::Desktop, KIcon::SizeMedium );
00058 QWidget *header = createHeader( this, icon, i18n( "Appointments" ) );
00059 mainLayout->addWidget( header );
00060
00061 mLayout = new QGridLayout( mainLayout, 7, 5, 3 );
00062 mLayout->setRowStretch( 6, 1 );
00063
00064 mCalendar = KOrg::StdCalendar::self();
00065 mCalendar->load();
00066
00067 connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( updateView() ) );
00068 connect( mPlugin->core(), SIGNAL( dayChanged( const QDate& ) ),
00069 SLOT( updateView() ) );
00070
00071 updateView();
00072 }
00073
00074 SummaryWidget::~SummaryWidget()
00075 {
00076 }
00077
00078 void SummaryWidget::updateView()
00079 {
00080 mLabels.setAutoDelete( true );
00081 mLabels.clear();
00082 mLabels.setAutoDelete( false );
00083
00084 KIconLoader loader( "korganizer" );
00085
00086 KConfig config( "kcmkorgsummaryrc" );
00087
00088 config.setGroup( "Calendar" );
00089 int days = config.readNumEntry( "DaysToShow", 1 );
00090
00091 QLabel *label = 0;
00092 int counter = 0;
00093 QPixmap pm = loader.loadIcon( "appointment", KIcon::Small );
00094
00095 QDate dt;
00096 for ( dt=QDate::currentDate();
00097 dt<=QDate::currentDate().addDays( days - 1 );
00098 dt=dt.addDays(1) ) {
00099 KCal::Event::List events = mCalendar->events( dt,
00100 KCal::EventSortStartDate,
00101 KCal::SortDirectionAscending );
00102 KCal::Event *ev;
00103 KCal::Event::List::ConstIterator it;
00104 for ( it=events.begin(); it!=events.end(); ++it ) {
00105 ev = *it;
00106
00107
00108 int span=1; int dayof=1;
00109 if ( ev->isMultiDay() ) {
00110 QDate d = ev->dtStart().date();
00111 if ( d < QDate::currentDate() ) {
00112 d = QDate::currentDate();
00113 }
00114 while ( d < ev->dtEnd().date() ) {
00115 if ( d < dt ) {
00116 dayof++;
00117 }
00118 span++;
00119 d=d.addDays( 1 );
00120 }
00121 }
00122
00123
00124
00125 if ( ev->isMultiDay() && ev->doesFloat() && dayof != 1 )break;
00126
00127
00128 label = new QLabel( this );
00129 label->setPixmap( pm );
00130 label->setMaximumWidth( label->minimumSizeHint().width() );
00131 label->setAlignment( AlignVCenter );
00132 mLayout->addWidget( label, counter, 0 );
00133 mLabels.append( label );
00134
00135
00136 bool makeBold = false;
00137 QString datestr;
00138
00139
00140 QDate sD = QDate::QDate( dt.year(), dt.month(), dt.day() );
00141 if ( ( sD.month() == QDate::currentDate().month() ) &&
00142 ( sD.day() == QDate::currentDate().day() ) ) {
00143 datestr = i18n( "Today" );
00144 makeBold = true;
00145 } else if ( ( sD.month() == QDate::currentDate().addDays( 1 ).month() ) &&
00146 ( sD.day() == QDate::currentDate().addDays( 1 ).day() ) ) {
00147 datestr = i18n( "Tomorrow" );
00148 } else {
00149 datestr = KGlobal::locale()->formatDate( sD );
00150 }
00151
00152
00153
00154 if ( ev->isMultiDay() && ev->doesFloat() && dayof == 1 && span > 1 ) {
00155 QString endstr = KGlobal::locale()->formatDate( sD.addDays( span-1 ) );
00156 datestr += " -\n " + endstr;
00157 }
00158
00159 label = new QLabel( datestr, this );
00160 label->setAlignment( AlignLeft | AlignVCenter );
00161 if ( makeBold ) {
00162 QFont font = label->font();
00163 font.setBold( true );
00164 label->setFont( font );
00165 }
00166 mLayout->addWidget( label, counter, 1 );
00167 mLabels.append( label );
00168
00169
00170 QString newtext = ev->summary();
00171 if ( ev->isMultiDay() && !ev->doesFloat() ) {
00172 newtext.append( QString(" (%1/%2)").arg( dayof ).arg( span ) );
00173 }
00174
00175 KURLLabel *urlLabel = new KURLLabel( ev->uid(), newtext, this );
00176 urlLabel->installEventFilter( this );
00177 urlLabel->setAlignment( urlLabel->alignment() | Qt::WordBreak );
00178 mLayout->addWidget( urlLabel, counter, 2 );
00179 mLabels.append( urlLabel );
00180
00181 if ( !ev->description().isEmpty() ) {
00182 QToolTip::add( urlLabel, ev->description() );
00183 }
00184
00185
00186 if ( !ev->doesFloat() ) {
00187 QTime sST = ev->dtStart().time();
00188 QTime sET = ev->dtEnd().time();
00189 if ( ev->isMultiDay() ) {
00190 if ( ev->dtStart().date() < dt ) {
00191 sST = QTime::QTime( 0, 0 );
00192 }
00193 if ( ev->dtEnd().date() > dt ) {
00194 sET = QTime::QTime( 23, 59 );
00195 }
00196 }
00197 datestr = i18n( "Time from - to", "%1 - %2" )
00198 .arg( KGlobal::locale()->formatTime( sST ) )
00199 .arg( KGlobal::locale()->formatTime( sET ) );
00200 label = new QLabel( datestr, this );
00201 label->setAlignment( AlignLeft | AlignVCenter );
00202 mLayout->addWidget( label, counter, 3 );
00203 mLabels.append( label );
00204 }
00205
00206 connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
00207 this, SLOT( selectEvent( const QString& ) ) );
00208
00209 counter++;
00210 }
00211 }
00212
00213 if ( !counter ) {
00214 QLabel *noEvents = new QLabel(
00215 i18n( "No appointments pending within the next day",
00216 "No appointments pending within the next %n days",
00217 days ), this, "nothing to see" );
00218 noEvents->setAlignment( AlignHCenter | AlignVCenter );
00219 mLayout->addWidget( noEvents, 0, 2 );
00220 mLabels.append( noEvents );
00221 }
00222
00223 for ( label = mLabels.first(); label; label = mLabels.next() )
00224 label->show();
00225 }
00226
00227 void SummaryWidget::selectEvent( const QString &uid )
00228 {
00229 mPlugin->core()->selectPlugin( "kontact_korganizerplugin" );
00230 KOrganizerIface_stub iface( "korganizer", "KOrganizerIface" );
00231 iface.editIncidence( uid );
00232 }
00233
00234 bool SummaryWidget::eventFilter( QObject *obj, QEvent* e )
00235 {
00236 if ( obj->inherits( "KURLLabel" ) ) {
00237 KURLLabel* label = static_cast<KURLLabel*>( obj );
00238 if ( e->type() == QEvent::Enter )
00239 emit message( i18n( "Edit Appointment: \"%1\"" ).arg( label->text() ) );
00240 if ( e->type() == QEvent::Leave )
00241 emit message( QString::null );
00242 }
00243
00244 return Kontact::Summary::eventFilter( obj, e );
00245 }
00246
00247 QStringList SummaryWidget::configModules() const
00248 {
00249 return QStringList( "kcmkorgsummary.desktop" );
00250 }
00251
00252 #include "summarywidget.moc"