README
[n9profile] / calendar.cpp
1 #include "calendar.h"
2 #include <QtCore/QDateTime>
3 #include <QtCore/QVector>
4 #include <QtCore/QDebug> //Debug pro informace
5 #include "event.h"
6 /**
7  */
8 Calendar::Calendar(QObject *parent) :
9         QObject(parent)
10 {
11 }
12
13 /** AddEvent
14    Add event into calendar
15    \param id of event
16    \param des desctription
17    \param sum summary
18    \param SDate start date
19    \param EDate end date
20  */
21 void Calendar::AddEvent(QString id, QString des ,QString sum, QDateTime SDate, QDateTime EDate)
22 {
23     Event *event_new;
24     if((event_new = findEvent(id)) == NULL){
25         event_new = new Event(this);
26         vector_calendars_events.append(event_new);
27         //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Create new event ";
28         connect(event_new,SIGNAL(s_event_change(Event*)),this,SLOT(EventChanged(Event*)));
29         event_new->SetTime(id, des, sum, SDate, EDate);
30     }
31 }
32 /** Delete event
33   delete event
34   \param id of event
35  */
36 void Calendar::DeleteEvent(QString id)
37 {
38     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Delete event " << id;
39     for(int i = 0; i < vector_calendars_events.size();++i)
40     {
41         if(vector_calendars_events.at(i)->GetId() == id){
42             delete vector_calendars_events.at(i);
43             vector_calendars_events.remove(i);
44             return;
45         }
46     }
47 }
48 /** Delete all old events
49  */
50 void Calendar::DeleteOldEvents()
51 {
52     ////qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "delete all old events ";
53     QMutableVectorIterator<Event *> i(vector_calendars_events);
54     while (i.hasNext()) {
55         Event *val = i.next();
56         if (val->isOld() == true) {
57             //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Event is old delete ";
58             delete val;
59             i.remove();
60         }
61     }
62 }
63
64 /** Change in event
65    Slot for change in event
66    \param ev  event
67  */
68 void Calendar::EventChanged(Event * ev)
69 {
70     if(ev->isNow()) {
71         emit s_eventStart(ev);
72     } else {
73         emit s_eventStop(ev);
74     }
75 }
76 /** FindEventsNow
77  find all event for now
78   \returns vector of events
79  */
80 QVector<Event *> Calendar::FindEventsNow()
81 {
82     QVector<Event *> vector;
83     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Search for now events ";
84     foreach(Event *evt, vector_calendars_events )
85     {
86         if(evt->isNow()){
87            qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Select event";
88             vector.append(evt);
89         }
90     }
91     return vector;
92 }
93 /** findevent
94   find event
95   \param i of event
96  */
97 Event * Calendar::findEvent(QString i)
98 {
99     foreach(Event * evt, vector_calendars_events)
100     {
101         if(evt->GetId() == i) return evt;
102     }
103     return NULL;
104 }
105 /** Setname
106   set name of calendar
107   \param n  name of cal
108  */
109 void Calendar::SetName(QString n)
110 {
111     name_of_calendar = n;
112     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " jmeno kalendare je " << n;
113 }
114 /** SetIcon
115   set icon of calendar
116   \param ico  icon of cal
117  */
118 void Calendar::SetIcon(QIcon ico)
119 {
120     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Setting icon fo cal" ;
121     icon = ico;
122 }
123 /** SetId
124   set id of calendar
125   \param i  id of cal
126  */
127 void Calendar::SetId(int i)
128 {
129     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Id_cal:" << Id_cal;
130     Id_cal = i;
131 }
132 /** GetId
133   get id of calendar
134  */
135 int Calendar::GetId()
136 {
137     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Id_cal:" << Id_cal;
138     return Id_cal;
139 }
140 /** GetIcon
141   set icon of calendar
142  */
143 QIcon Calendar::GetIcon()
144 {
145     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "return icon";
146     return icon;
147 }
148 /** GetName
149 get name of calendar
150  */
151 QString Calendar::GetName()
152 {
153     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Get name:" << name_of_calendar;
154     return name_of_calendar;
155 }