konsolekalendar.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdlib.h>
00019 #include <iostream>
00020
00021 #include <qdatetime.h>
00022
00023 #include <kdebug.h>
00024 #include <klocale.h>
00025
00026 #include "calendarlocal.h"
00027 #include "calendar.h"
00028 #include "event.h"
00029
00030 #include "konsolekalendar.h"
00031
00032 using namespace KCal;
00033 using namespace std;
00034
00035 KonsoleKalendar::KonsoleKalendar(KalendarVariables &variables)
00036 {
00037 m_variables = variables;
00038 m_Calendar = new CalendarLocal;
00039 }
00040
00041 KonsoleKalendar::~KonsoleKalendar()
00042 {
00043 }
00044
00045 void KonsoleKalendar::showInstance()
00046 {
00047 if( !m_Calendar->load( m_variables.getCalendarFile() ) ) {
00048 kdDebug() << "Can't open file: " << m_variables.getCalendarFile() << endl;
00049 } else {
00050 if( m_variables.isNext() ) {
00051 showNext();
00052 }
00053
00054 if( m_variables.isDate() && m_variables.isStartDate() == false ) {
00055 showDate( m_variables.getDate() );
00056 }
00057
00058 if( m_variables.isStartDate() ) {
00059 if(m_variables.isVerbose()){
00060 kdDebug() << "konsolecalendar.cpp::showInstance(int argc, char *argv[]) | Start date set" << endl;
00061 }
00062
00063 QDate start = m_variables.getStartDate( );
00064 QDate end;
00065 bool loop = false;
00066
00067 if( m_variables.isEndDate() ) {
00068 end = m_variables.getEndDate( );
00069 } else {
00070 end = start.addDays(30);
00071 }
00072
00073 while( !loop ) {
00074 if(m_variables.isVerbose()) {
00075 kdDebug() << "konsolecalendar.cpp::showInstance(int argc, char *argv[]) | " << start.toString().local8Bit() << endl;
00076 kdDebug() << "konsolecalendar.cpp::showInstance(int argc, char *argv[]) | days to end " << start.daysTo( end ) << endl;
00077 }
00078
00079 showDate( start );
00080
00081 if( !start.daysTo( end ) ) {
00082 loop = true;
00083 }
00084
00085 start = start.addDays(1);
00086 }
00087 }
00088 }
00089
00090 delete m_Calendar;
00091 }
00092
00093
00094 void KonsoleKalendar::showDate( QDate date )
00095 {
00096 Event *singleEvent;
00097
00098 QList<Event> eventList(m_Calendar->events( date, TRUE));
00099 QString tempString;
00100 QDate current = QDate::currentDate();
00101
00102 if( eventList.count() ) {
00103 int len = 100;
00104 tempString = date.toString();
00105 len -= tempString.length();
00106
00107 cout << endl << tempString.local8Bit() << "\n";
00108
00109 for( len = len; len < 100; len ++) {
00110 cout << "-";
00111 }
00112
00113 cout << endl;
00114
00115 for ( singleEvent = eventList.first(); singleEvent != 0; singleEvent =
00116 eventList.next() ) {
00117 if( m_variables.isAll() ) {
00118 printEventTime(singleEvent);
00119
00120 cout << "\t" << singleEvent->summary().local8Bit() << endl;
00121 } else {
00122 if(current.daysTo( date ) == 0) {
00123 if( m_variables.isVerbose() ) {
00124 cout << i18n("Today: ") << isHappened(singleEvent) << endl;
00125 }
00126
00127 if( isHappened(singleEvent) == false) {
00128 printEventTime( singleEvent );
00129 cout << "\t" << singleEvent->summary().local8Bit() << endl;
00130 }
00131 } else {
00132 if( m_variables.isVerbose() ){
00133 cout << i18n("Not today: ") << isHappened(singleEvent) << endl;
00134 }
00135
00136 printEventTime( singleEvent );
00137 cout << "\t" << singleEvent->summary().local8Bit() << endl;
00138 }
00139 }
00140 }
00141 }
00142 }
00143
00144
00145 void KonsoleKalendar::showNext()
00146 {
00147 int date = 0;
00148 bool loop = false;
00149
00150
00151 Event *singleEvent;
00152 QDate qdate;
00153 QString tempString;
00154 int len = 50;
00155
00156 while(!loop) {
00157 QList<Event> eventList(m_Calendar->events(m_variables.getDate(), TRUE));
00158
00159 if( eventList.count() ) {
00160 len = 80;
00161 tempString = m_variables.getDate().toString();
00162 len -= tempString.length();
00163
00164 cout << endl << tempString << " ";
00165
00166 for( len = len; len < 80; len ++) {
00167 cout << "-";
00168 }
00169
00170 cout << endl;
00171
00172 for ( singleEvent = eventList.first(); singleEvent != 0; singleEvent = eventList.next() ){
00173 printEventTime(singleEvent);
00174 cout << endl;
00175 cout << "\t\t" << singleEvent->summary().local8Bit() << endl;
00176
00177 if (!singleEvent->doesFloat()) {
00178 loop = true;
00179 break;
00180 }
00181 }
00182 loop = true;
00183 }
00184
00185 date ++;
00186 if(date >= 30) {
00187 loop = true;
00188 }
00189
00190 qdate = m_variables.getDate();
00191 qdate = qdate.addDays(1);
00192 m_variables.setDate(qdate);
00193 }
00194 }
00195
00196
00197 bool KonsoleKalendar::isHappened( Event *event )
00198 {
00199 int minute, hour;
00200
00201 QString sHour, sMinute;
00202 QString temp;
00203 QString temp2;
00204 QTime time( QTime::currentTime() );
00205
00206 temp = event->dtStartStr().remove(0, (event->dtStartStr().find(' ', 0, false) + 1) );
00207 temp2 = temp;
00208
00209 sHour = temp.remove( (temp.find(':', 0, false) ), ( temp.length() - temp.find(':', 0, false) ));
00210
00211 sMinute = temp2.remove( 0, ( temp2.find(':', 0, false) + 1 ));
00212
00213 if( m_variables.isVerbose() ) {
00214 cout << i18n("hours: ") << sHour << i18n(" minutes: ") << sMinute << endl;
00215 }
00216
00217 hour = sHour.toInt();
00218 minute = sMinute.toInt();
00219
00220 if( m_variables.isVerbose() ) {
00221 cout << i18n("hours: ") << hour << i18n(" minutes: ") << minute << endl;
00222 }
00223
00224 if( hour >= time.hour() && minute >= time.minute()) {
00225 if( m_variables.isVerbose() ) {
00226 cout << i18n("This is valid!");
00227 }
00228 return false;
00229 }
00230
00231 return true;
00232 }
00233
00234
00236 void KonsoleKalendar::printEventTime(Event *event)
00237 {
00238 if (!event->doesFloat()) {
00239
00240
00241
00242
00243 cout << event->dtStartStr().remove(0, (event->dtStartStr().find(' ', 0, false) + 1) );
00244 cout << " - ";
00245 cout << event->dtEndStr().remove(0, (event->dtEndStr().find(' ', 0, false) + 1) );
00246 }
00247 }
This file is part of the documentation for kdelibs Version 3.1.4.