README
[n9profile] / event.cpp
1 #include "event.h"
2 #include <QtCore/QDebug> //Debug pro informace
3 #include <QtCore/QSettings>
4 #include <QtCore/QTimer>
5
6 /** Constructor.
7   Set pointers to NULL and create timer
8 */
9 Event::Event(QObject *parent) :
10         QObject(parent)
11 {
12     is_now = false;
13     is_old= false;
14     timer = new QTimer(this);
15     timer->setSingleShot(true);//A single-shot timer fires only once
16     connect(timer,SIGNAL(timeout()),this,SLOT(TimerTimeout()));
17 }
18
19 /** GetSummary()
20 Returns the summary of event
21 \returns  summary text
22 */
23 QString Event::GetSummary()
24 {
25     return summary;
26 }
27
28 /** GetId()
29 Returns id of event
30 \returns id
31 */
32 QString Event::GetId()
33 {
34     return Id_event;
35 }
36
37 /** isNow()
38 Returns if profile is now
39 \returns bool is event now
40 */
41 bool Event::isNow()
42 {
43     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Is profil now? " << is_now;
44     return is_now;
45 }
46
47 /** isOld()
48 Returns if profile is old
49 \returns bool is event old
50 */
51 bool Event::isOld()
52 {
53     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Is profil old? " << is_old;
54     return is_old;
55 }
56
57 /** SetTime
58    Set time and data of event
59    \param I id of event
60    \param des desctription
61    \param sum summary
62    \param SDate start date
63    \param EDate end date
64  */
65 void Event::SetTime(QString I, QString des ,QString sum, QDateTime SDate,QDateTime EDate)
66 {
67     Id_event = I;
68     description = des;
69     summary = sum;
70     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Setting date time events name" << sum ;
71     start_Date = SDate;
72     end_Date = EDate;
73     timerSet();
74 }
75
76 /** timerSet
77    Check event start end end
78  */
79 void Event::timerSet()
80 {
81     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "timer will be now set for event " << description ;
82
83     if(start_Date >  QDateTime::currentDateTime()){ //id start date in future
84         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "date in future" ;
85         timer->start(QDateTime::currentDateTime().secsTo(start_Date) * 1000 ); // wait to event start
86         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "sec to event start" << QDateTime::currentDateTime().secsTo(start_Date) ;
87     } else if(( end_Date <=  QDateTime::currentDateTime()) ) { //is end date in past
88         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "event is old" ;
89         is_old = true;
90     } else if((start_Date <=  QDateTime::currentDateTime()) && ( end_Date >=  QDateTime::currentDateTime()) ) { //is now ?
91         is_now = true;
92         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "event is now" ;
93         timer->start(QDateTime::currentDateTime().secsTo(end_Date) * 1000);
94         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "sec to event end" << QDateTime::currentDateTime().secsTo(end_Date) ;
95         emit s_event_change(this); //emit signal
96     }
97 }
98
99 /** TimerTimeout
100    slot for timer
101  */
102 void Event::TimerTimeout()
103 {
104     if((is_now == false) && (is_old == false )){//not not and not old
105         is_now = true;
106         timer->start(start_Date.secsTo(end_Date) * 1000);//timer to end of event
107         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "sec to event end" << start_Date.secsTo(end_Date) ;
108         emit s_event_change(this); //emit signal
109     } else if((is_now == true) && (is_old == false)) {
110         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " end of event " ;
111         is_now = false;
112         is_old = true;
113         emit s_event_change(this);//emit signal
114     }
115 }