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
00101
00102 events = KCal::Calendar::sortEvents( &events,
00103 KCal::EventSortSummary,
00104 KCal::SortDirectionAscending );
00105
00106 events = KCal::Calendar::sortEvents( &events,
00107 KCal::EventSortStartDate,
00108 KCal::SortDirectionAscending );
00109
00110 KCal::Event *ev;
00111 KCal::Event::List::ConstIterator it;
00112 for ( it=events.begin(); it!=events.end(); ++it ) {
00113 ev = *it;
00114
00115
00116 int span=1; int dayof=1;
00117 if ( ev->isMultiDay() ) {
00118 QDate d = ev->dtStart().date();
00119 if ( d < QDate::currentDate() ) {
00120 d = QDate::currentDate();
00121 }
00122 while ( d < ev->dtEnd().date() ) {
00123 if ( d < dt ) {
00124 dayof++;
00125 }
00126 span++;
00127 d=d.addDays( 1 );
00128 }
00129 }
00130
00131
00132
00133 if ( ev->isMultiDay() && ev->doesFloat() && dayof != 1 ) continue;
00134
00135
00136 label = new QLabel( this );
00137 label->setPixmap( pm );
00138 label->setMaximumWidth( label->minimumSizeHint().width() );
00139 label->setAlignment( AlignVCenter );
00140 mLayout->addWidget( label, counter, 0 );
00141 mLabels.append( label );
00142
00143
00144 bool makeBold = false;
00145 QString datestr;
00146
00147
00148 QDate sD = QDate::QDate( dt.year(), dt.month(), dt.day() );
00149 if ( ( sD.month() == QDate::currentDate().month() ) &&
00150 ( sD.day() == QDate::currentDate().day() ) ) {
00151 datestr = i18n( "Today" );
00152 makeBold = true;
00153 } else if ( ( sD.month() == QDate::currentDate().addDays( 1 ).month() ) &&
00154 ( sD.day() == QDate::currentDate().addDays( 1 ).day() ) ) {
00155 datestr = i18n( "Tomorrow" );
00156 } else {
00157 datestr = KGlobal::locale()->formatDate( sD );
00158 }
00159
00160
00161
00162 if ( ev->isMultiDay() && ev->doesFloat() && dayof == 1 && span > 1 ) {
00163 QString endstr = KGlobal::locale()->formatDate( sD.addDays( span-1 ) );
00164 datestr += " -\n " + endstr;
00165 }
00166
00167 label = new QLabel( datestr, this );
00168 label->setAlignment( AlignLeft | AlignVCenter );
00169 if ( makeBold ) {
00170 QFont font = label->font();
00171 font.setBold( true );
00172 label->setFont( font );
00173 }
00174 mLayout->addWidget( label, counter, 1 );
00175 mLabels.append( label );
00176
00177
00178 QString newtext = ev->summary();
00179 if ( ev->isMultiDay() && !ev->doesFloat() ) {
00180 newtext.append( QString(" (%1/%2)").arg( dayof ).arg( span ) );
00181 }
00182
00183 KURLLabel *urlLabel = new KURLLabel( ev->uid(), newtext, this );
00184 urlLabel->installEventFilter( this );
00185 urlLabel->setAlignment( urlLabel->alignment() | Qt::WordBreak );
00186 mLayout->addWidget( urlLabel, counter, 2 );
00187 mLabels.append( urlLabel );
00188
00189 if ( !ev->description().isEmpty() ) {
00190 QToolTip::add( urlLabel, ev->description() );
00191 }
00192
00193
00194 if ( !ev->doesFloat() ) {
00195 QTime sST = ev->dtStart().time();
00196 QTime sET = ev->dtEnd().time();
00197 if ( ev->isMultiDay() ) {
00198 if ( ev->dtStart().date() < dt ) {
00199 sST = QTime::QTime( 0, 0 );
00200 }
00201 if ( ev->dtEnd().date() > dt ) {
00202 sET = QTime::QTime( 23, 59 );
00203 }
00204 }
00205 datestr = i18n( "Time from - to", "%1 - %2" )
00206 .arg( KGlobal::locale()->formatTime( sST ) )
00207 .arg( KGlobal::locale()->formatTime( sET ) );
00208 label = new QLabel( datestr, this );
00209 label->setAlignment( AlignLeft | AlignVCenter );
00210 mLayout->addWidget( label, counter, 3 );
00211 mLabels.append( label );
00212 }
00213
00214 connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
00215 this, SLOT( selectEvent( const QString& ) ) );
00216
00217 counter++;
00218 }
00219 }
00220
00221 if ( !counter ) {
00222 QLabel *noEvents = new QLabel(
00223 i18n( "No appointments pending within the next day",
00224 "No appointments pending within the next %n days",
00225 days ), this, "nothing to see" );
00226 noEvents->setAlignment( AlignHCenter | AlignVCenter );
00227 mLayout->addWidget( noEvents, 0, 2 );
00228 mLabels.append( noEvents );
00229 }
00230
00231 for ( label = mLabels.first(); label; label = mLabels.next() )
00232 label->show();
00233 }
00234
00235 void SummaryWidget::selectEvent( const QString &uid )
00236 {
00237 mPlugin->core()->selectPlugin( "kontact_korganizerplugin" );
00238 KOrganizerIface_stub iface( "korganizer", "KOrganizerIface" );
00239 iface.editIncidence( uid );
00240 }
00241
00242 bool SummaryWidget::eventFilter( QObject *obj, QEvent* e )
00243 {
00244 if ( obj->inherits( "KURLLabel" ) ) {
00245 KURLLabel* label = static_cast<KURLLabel*>( obj );
00246 if ( e->type() == QEvent::Enter )
00247 emit message( i18n( "Edit Appointment: \"%1\"" ).arg( label->text() ) );
00248 if ( e->type() == QEvent::Leave )
00249 emit message( QString::null );
00250 }
00251
00252 return Kontact::Summary::eventFilter( obj, e );
00253 }
00254
00255 QStringList SummaryWidget::configModules() const
00256 {
00257 return QStringList( "kcmkorgsummary.desktop" );
00258 }
00259
00260 #include "summarywidget.moc"