README
[n9profile] / calendatprofile.cpp
1 #include "calendatprofile.h"
2 #include <QStringList>
3 #include <QtCore/QSettings>
4 #include <QtCore/QDebug> //Debug pro informace
5 #include <QtGui/QStandardItemModel>
6 #include <QtCore/QVector>
7 #include <QtCore/QVariant>
8 #include <QtGui/QPixmap>
9 #include <QtGui/QItemSelectionModel>
10 #include <QtCore/QDateTime>
11 #include <QtCore/QTimer>
12 #include <QtCore/QTime>
13 #include <QtDBus/QDBusConnection>
14 #include "event.h"
15 #include "calendar.h"
16 #include "calendarprofilesdialog.h"
17
18 static const char* CALENDAR_DBUS_LISTENER_SERVICE =  "com.nokia.calendar";
19 static const char* CALENDAR_DBUS_OBJECT_PATH =  "/com/nokia/calendar";
20 static const char* CALENDAR_DBUS_LISTENER_SIGNAL = "dbChange";
21
22 /** Constructor.
23 Setup ui, create multiCalendar, set QSettings pointer, create timer and model
24 */
25 CalendarProfile::CalendarProfile(QWidget *parent, QSettings *sett) :
26         QWidget(parent)
27 {
28     multiCalendar = CMulticalendar::MCInstance();
29     settings = sett;
30     timer = new QTimer(this);
31     timer->setSingleShot(true);//A single-shot timer fires only once
32     connect(timer,SIGNAL(timeout()),this,SLOT(TimerTimeout()));
33     QDBusConnection::sessionBus().connect( "", CALENDAR_DBUS_OBJECT_PATH, CALENDAR_DBUS_LISTENER_SERVICE,CALENDAR_DBUS_LISTENER_SIGNAL,this,SLOT(calendarTrack(QString)));
34     createModels();//
35 }
36
37 /** calendarTrack
38 Slot for signal when db for calendar change
39 */
40 void CalendarProfile::calendarTrack(QString str)
41 {
42     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << str ;
43     qDeleteAll(vector_of_calendars);
44     vector_of_calendars.clear();
45     profile_Currently = QString("");
46     eventCurrently = QString("");
47     emit s_calendar_profile(profile_Currently);
48     loadCalendarsAndEvents();
49 }
50
51 /**
52   V dbusus je funkce
53 dbus_message_new_signal         (       const char *     path,
54                 const char *    interface,
55                 const char *    name
56         )
57
58 Parameters:
59         path    the path to the object emitting the signal
60         interface       the interface the signal is emitted from
61         name    name of the signal
62
63 v DB na calendar je
64 static const char* CALENDAR_DBUS_LISTENER_SERVICE =  "com.nokia.calendar";
65 static const char* CALENDAR_DBUS_OBJECT_PATH =  "/com/nokia/calendar";
66 static const char* CALENDAR_DBUS_LISTENER_SIGNAL = "dbChange";
67
68     dbusMessage = dbus_message_new_signal(CALENDAR_DBUS_OBJECT_PATH,
69                       CALENDAR_DBUS_LISTENER_SERVICE,
70                       CALENDAR_DBUS_LISTENER_SIGNAL);
71
72                       v QT4
73  bool QDBusConnection::connect ( const QString & service, const QString & path, const QString & interface,
74  const QString & name, QObject  * receiver, const char * slot )
75   */
76
77
78
79 /** Destructor.
80 Destructor delete ui
81 */
82 CalendarProfile::~CalendarProfile()
83 {
84     delete multiCalendar;
85 }
86
87 /** TimerTimeout
88 slot for timer timeout
89 */
90 void CalendarProfile::TimerTimeout()
91 {
92     loadCalendarsAndEvents();
93 }
94
95 /** createModels
96 create models
97 */
98 void CalendarProfile::createModels()
99 {
100     model_of_profiles = new QStandardItemModel(this);
101     selModel_profiles = new QItemSelectionModel(model_of_profiles);
102     model_of_calendars = new QStandardItemModel(this);
103     selModel_calendars = new QItemSelectionModel(model_of_calendars);
104 }
105
106 /** Init
107 Init start calendar profile class
108 This will download first data from calendar
109 */
110 void CalendarProfile::Init()
111 {
112     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ ;
113     // setProfiles(list_of_profiles_n); //profile model
114     loadCalendarsAndEvents();
115 }
116
117 /** loadCalendarsAndEvents
118 Load calendar data
119 This will download  data from calendar
120 */
121 void CalendarProfile::loadCalendarsAndEvents()
122 {
123     int errorCode = 0;
124
125     QDateTime startofday = QDateTime::currentDateTime();
126     startofday.setTime(QTime(0,0)); // time to 0,0
127     startofday =  startofday.addDays(-1);
128     QDateTime endofday = QDateTime::currentDateTime();
129     endofday= endofday.addDays(1);
130     endofday.setTime(QTime(23,59)); // time to 23,59
131     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "zacatek" << startofday << "konec" << endofday;
132     vector< CComponent * > components;
133     QVector<CComponent *> vector_of_events;
134     vector < CCalendar  * > vector_of_cal_std = multiCalendar->getListCalFromMc();
135
136     QVector<CCalendar  *> qvector_of_cal = QVector< CCalendar  *>::fromStdVector(vector_of_cal_std); //
137     Calendar *cal;
138     if(!qvector_of_cal.empty())
139     {
140         foreach(CCalendar * ccal, qvector_of_cal ){
141             //if calendar exist return pointer else create new
142             if(( cal = findCalendar(ccal->getCalendarId())) == NULL)
143             {
144                 qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "judela se novy cal ";
145                 cal = new Calendar(this);
146                 cal->SetName(QString::fromStdString(ccal->getCalendarName()));
147                 vector_of_calendars.append(cal);
148                 connect(cal,SIGNAL(s_eventStart(Event*)),this,SLOT(event_start(Event*)));
149                 connect(cal,SIGNAL(s_eventStop(Event*)),this,SLOT(event_stop(Event*)));
150                 cal->SetIcon(createIcon(ccal->getCalendarColor()));
151             }
152             qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "ziskaj se eventy kalendar" << QString::fromStdString(ccal->getCalendarName());
153             qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "id cal " << ccal->getCalendarId();
154             qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "start datum " << startofday;
155                         qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "end datum " << endofday;
156             components = multiCalendar->getComponents(ccal->getCalendarId(),
157                                                       1, startofday.toTime_t(),
158                                                       endofday.toTime_t(), errorCode);
159                                     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "err  code " << errorCode;
160             vector_of_events = QVector<CComponent *>::fromStdVector(components);
161             if(!vector_of_events.empty()){
162                 foreach(CComponent *ccompo, vector_of_events){
163                     cal->AddEvent(QString::fromStdString(ccompo->getId()),QString::fromStdString(ccompo->getDescription()),QString::fromStdString(ccompo->getSummary()), QDateTime::fromTime_t(ccompo->getDateStart()),QDateTime::fromTime_t(ccompo->getDateEnd()));
164                     qDebug()<< "getId" << QString::fromStdString(ccompo->getId());
165                     qDebug()<< " get summary " << QString::fromStdString(ccompo->getSummary());
166                     qDebug()<< "getDescription" << QString::fromStdString(ccompo->getDescription());
167                 }
168                 cal->DeleteOldEvents();//delete old events
169             } else {
170                 qDebug()<< "Vektor s udalostma je prazdnej ?" ;
171             }
172            qDeleteAll( components);
173            components.clear();
174         }
175     }
176     multiCalendar->releaseListCalendars(vector_of_cal_std);
177     setCalendarModel();
178     timer->start(QDateTime::currentDateTime().secsTo(startofday.addDays(2)) * 1000 + 1000);//timer set for next day + 1 sec
179 }
180
181 enum CalendarColour;
182 /** createIcon
183 Create icon fro calendar
184 \param col color from maemo
185 \returns QIcon for calendar
186 */
187 QIcon CalendarProfile::createIcon(CalendarColour col)
188 {
189     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ ;
190     QPixmap pix_map = QPixmap(40,40);
191     if(col == COLOUR_DARKBLUE)
192     {
193         pix_map.fill(QColor("darkblue"));
194         return QIcon(pix_map);
195     }else if( col == COLOUR_DARKGREEN){
196         pix_map.fill(QColor("darkseagreen"));
197         return QIcon(pix_map);
198     }else if( col == COLOUR_DARKRED){
199         pix_map.fill(QColor("darkred"));
200         return QIcon(pix_map);
201     }else if( col == COLOUR_ORANGE){
202         pix_map.fill(QColor("orange"));
203         return QIcon(pix_map);
204     }else if( col == COLOUR_VIOLET){
205         pix_map.fill(QColor("violet"));
206         return QIcon(pix_map);
207     }else if( col == COLOUR_YELLOW){
208         pix_map.fill(QColor("yellow"));
209         return QIcon(pix_map);
210     }else if( col == COLOUR_WHITE){
211         pix_map.fill(QColor("white"));
212         return QIcon(pix_map);
213     }else if( col == COLOUR_BLUE){
214         pix_map.fill(QColor("blue"));
215         return QIcon(pix_map);
216     }else if( col == COLOUR_RED){
217         pix_map.fill(QColor("red"));
218         return QIcon(pix_map);
219     }else if( col == COLOUR_GREEN){
220         pix_map.fill(QColor("green"));
221         return QIcon(pix_map);
222     }
223     pix_map.fill(QColor("white"));
224     return QIcon(pix_map);
225 }
226
227 /** setCalendarModel
228 Sets calendar model
229 */
230 void CalendarProfile::setCalendarModel()
231 {
232     model_of_calendars->clear();
233     QStringList labels;
234     labels << tr("Name od calendars")  ;
235     model_of_calendars->setHorizontalHeaderLabels(labels);
236     QList<QStandardItem *>  items;
237     QStandardItem *item;
238
239     foreach(Calendar *cal, vector_of_calendars){
240         item = new QStandardItem(cal->GetIcon(),cal->GetName());
241         item->setCheckable(true);
242
243         settings->beginGroup("CalendarProfileClassCalendars");
244         if(settings->value(cal->GetName(), QVariant("0")).toString() == "2"){
245
246             item->setCheckState(Qt::Checked);
247         }
248         settings->endGroup();
249         items.append(item);
250         model_of_calendars->appendRow(items);
251         items.clear();
252     }
253 }
254
255 /** findCalendar
256 Find calendar
257 \param Id Id of calendar
258 \returns poiter to calendar
259 */
260 Calendar * CalendarProfile::findCalendar(int Id)
261 {
262     qDebug()<< "search for calendar";
263     foreach(Calendar *cal, vector_of_calendars){
264         if(cal->GetId() == Id)
265             return cal;
266     }
267     return NULL;
268 }
269
270 //===========================================================================================
271 /** setProfiles
272 Set model for profiles
273 \param list_of_profiles_n list of profiles
274 */
275 void CalendarProfile::setProfiles(QStringList list_of_profiles_n)
276 {
277     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "zavolat se a bude se nastavovat))))))))))))))))))))))))))))))))))))))))))))))))))))))" ;
278     model_of_profiles->clear();//smazu ho
279     QList<QStandardItem *>  items;
280     QStandardItem *item;
281     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ ;
282     settings->beginGroup("CalendarProfileClass");
283     foreach(QString profile, list_of_profiles_n)
284     {
285         qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "set profile" << profile ;
286         item = new QStandardItem(profile);
287         items.append(item);
288         item = new QStandardItem(settings->value(QString("%1%2").arg(profile,"words"), QVariant("")).toString());
289         items.append(item);
290         item = new QStandardItem(settings->value(QString("%1%2").arg(profile,"priority"), QVariant("0")).toString());
291         qDebug() << "novej model priorita" << settings->value(QString("%1%2").arg(profile,"priority"), QVariant("0"));
292         items.append(item);
293         model_of_profiles->appendRow(items);
294         items.clear();
295     }
296     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << settings->value("Novy2priority", 0); ;
297     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << settings->value("Novy2words", "nic") ;
298     settings->endGroup();
299
300     QStringList labels;
301     labels << tr("Name of profile") << tr("Words") << tr("Priority");
302     model_of_profiles->setHorizontalHeaderLabels(labels);
303
304     profile_Currently = QString("");
305     eventCurrently = QString("");
306     SetProfile();
307 }
308
309 /** event_start
310 Slot for events start
311 \param ev event
312 */
313 void CalendarProfile::event_start(Event * ev)
314 {
315     // int i = 0;
316     // i = getProfilePriority(evaluateEvent(ev)); //ziskam prioritu
317     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__  << "profil co zacal je spocitana priorita";
318     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__  << "profil cp ted je " << profile_Currently;
319     // if(i > getProfilePriority(profile_Currently)){
320     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__  << "start event with bigger priority";
321     SetProfile();
322     // }
323 }
324
325 /** event_stop
326 Slot for events stop
327 \param ev event
328 */
329 void CalendarProfile::event_stop(Event* ev)
330 {
331     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__  << "event_stop";
332     if(eventCurrently == ev->GetId())
333     {
334         profile_Currently = QString("");
335         eventCurrently = QString("");
336         SetProfile();
337     }
338 }
339
340 /** SetProfile
341 Set profile based on caledars, events and profiles words
342 */
343 void CalendarProfile::SetProfile()
344 {
345     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "SetProfile";
346     QVector<Event *> vector_ev;
347     QString prof = QString("");
348
349     settings->beginGroup("CalendarProfileClassCalendars");
350     foreach(Calendar* cal, vector_of_calendars)
351     {
352         if(settings->value(cal->GetName(), QVariant("0")).toString() == "2"){
353             qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Pro kalendar" << cal->GetName() << "Search for profiles";
354             qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Tak co tam ted je" << settings->value(QString("%1").arg(cal->GetId()), QVariant("0")).toString();
355
356             vector_ev += cal->FindEventsNow();
357         }
358     }
359     settings->endGroup();
360     profile_Currently = QString("");
361     eventCurrently = QString("");
362     if(vector_ev.empty()){
363         qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Found nothing";
364
365         emit s_calendar_profile(profile_Currently);
366         return;
367
368     }
369
370     QString str = evaluateEvent(vector_ev);
371
372     //
373     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Profole for now" << profile_Currently;
374     emit s_calendar_profile(profile_Currently);
375 }
376
377 /** evaluateEvent
378 Method for finding profile for event
379 \param ev event
380 */
381 QString CalendarProfile::evaluateEvent( QVector<Event *> vector_ev)
382 {
383     QString profile = QString("");
384     QStringList list_names;
385     int wordscount_old = 0;
386     int wordscount_new = 0;
387     int priority_old = 0;
388     int priority_new = 0;
389
390     foreach(Event * ev, vector_ev)//forech event
391     {
392         for(int i = 0; i < model_of_profiles->rowCount(); i++) //fing best profiel
393         {
394             list_names = model_of_profiles->item(i,1)->data(Qt::DisplayRole).toString().split(QRegExp("\\s+"),QString::SkipEmptyParts);
395             qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "list of words" <<  list_names;
396             qDebug() << "pro profil " << model_of_profiles->item(i,0)->data(Qt::DisplayRole).toString() << "jsem našel počet stjeenjch " << wordsCount(list_names,ev->GetSummary()) << "a ma proioritu " << model_of_profiles->item(i,2)->data(Qt::DisplayRole).toInt();
397
398             wordscount_new = wordsCount(list_names,ev->GetSummary());
399             if(wordscount_new == 0) continue;//pokud nenasel zadan slova pokracuje
400             priority_new = model_of_profiles->item(i,2)->data(Qt::DisplayRole).toInt();
401
402             if(priority_new > priority_old)
403             {
404                 qDebug() << "priorita je větsi nez tam byl ";
405                 qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "count is " <<  wordscount_new;
406                 wordscount_old = wordscount_new;
407                 wordscount_new = 0;
408                 profile = model_of_profiles->item(i,0)->data(Qt::DisplayRole).toString();
409                 profile_Currently = profile;
410
411                 eventCurrently = ev->GetId();
412
413                 priority_old = priority_new;
414                 qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "for profil" <<  profile;
415             } else if((priority_new == priority_old) && (wordscount_new > wordscount_old))
416             {
417                 qDebug() << "stejna prio ale vetsi pocet slov";
418                 qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "count is " <<  wordscount_new;
419                 wordscount_old = wordscount_new;
420                 wordscount_new = 0;
421                 profile = model_of_profiles->item(i,0)->data(Qt::DisplayRole).toString();
422                 priority_old = priority_new;
423                 qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "for profil" <<  profile;
424                 profile_Currently = profile;
425                 eventCurrently = ev->GetId();
426             }
427         }
428     }
429     qDebug() << "budu vracet profil co se na to hodi:" << profile;
430     return profile;
431 }
432
433 /**
434
435 void CalendarProfile::SetProfile()
436 {
437     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "SetProfile";
438     QVector<Event *> vector_ev;
439     QString prof = QString("");
440
441     settings->beginGroup("CalendarProfileClassCalendars");
442     foreach(Calendar* cal, vector_of_calendars)
443     {
444         if(settings->value(cal->GetName(), QVariant("0")).toString() == "2"){
445             qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Pro kalendar" << cal->GetName() << "Search for profiles";
446             qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Tak co tam ted je" << settings->value(QString("%1").arg(cal->GetId()), QVariant("0")).toString();
447
448             vector_ev += cal->FindEventsNow();
449         }
450     }
451     settings->endGroup();
452
453     if(vector_ev.empty()){
454         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Found nothing";
455         profile_Currently = QString("");
456         eventCurrently = QString("");
457     }
458
459     foreach(Event * ev, vector_ev)
460     {
461          qDebug() << "pro nejakej event evaluate";
462         prof = evaluateEvent(ev);
463          qDebug() << "konec evaluate";
464         if(!profile_Currently.isEmpty())
465         {
466             qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Profil uz tam ted nastavenej je a to" << profile_Currently;
467             if(getProfilePriority(profile_Currently) < getProfilePriority(prof))
468             {
469                 qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "prof je ted" << prof;
470                 profile_Currently = prof;
471
472                 eventCurrently = ev->GetId();
473             }
474         } else {
475             profile_Currently = prof;
476             eventCurrently = ev->GetId();
477         }
478
479     }
480     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Text:" << "Profole for now" << profile_Currently;
481     emit s_calendar_profile(profile_Currently);
482 }
483
484
485 QString CalendarProfile::evaluateEvent(Event * ev)
486 {
487     QString profile = QString("");
488     QStringList list_names;
489     int wordscount_old = 0;
490     int wordscount_new = 0;
491     int priority_old = 0;
492     int priority_new = 0;
493
494     for(int i = 0; i < model_of_profiles->rowCount(); i++)
495     {
496
497         list_names = model_of_profiles->item(i,1)->data(Qt::DisplayRole).toString().split(QRegExp("\\s+"),QString::SkipEmptyParts);
498         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "list of words" <<  list_names;
499         qDebug() << "pro profil " << model_of_profiles->item(i,0)->data(Qt::DisplayRole).toString() << "jsem našel počet stjeenjch " << wordsCount(list_names,ev->GetSummary()) << "a ma proioritu " << model_of_profiles->item(i,2)->data(Qt::DisplayRole).toInt();
500
501         wordscount_new = wordsCount(list_names,ev->GetSummary());
502         priority_new = model_of_profiles->item(i,2)->data(Qt::DisplayRole).toInt();
503
504         if(priority_new > priority_old)
505         {
506             qDebug() << "priorita je větsi nez tam byl ";
507             qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "count is " <<  wordscount_new;
508             wordscount_old = wordscount_new;
509             wordscount_new = 0;
510             profile = model_of_profiles->item(i,0)->data(Qt::DisplayRole).toString();
511             priority_old = priority_new;
512             qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "for profil" <<  profile;
513         } else if((priority_new == priority_old) && (wordscount_new > wordscount_old))
514         {
515             qDebug() << "stejna prio ale vetsi pocet slov";
516             qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "count is " <<  wordscount_new;
517             wordscount_old = wordscount_new;
518             wordscount_new = 0;
519             profile = model_of_profiles->item(i,0)->data(Qt::DisplayRole).toString();
520             priority_old = priority_new;
521             qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "for profil" <<  profile;
522         }
523     }
524     qDebug() << "budu vracet profil co se na to hodi:" << profile;
525     return profile;
526 }
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544 QString CalendarProfile::evaluateEvent(Event * ev)
545 {
546     QString profile = QString("");
547     QStringList list_names;
548     int ccount = 0;
549     int x = 0;
550     int prio = 0;
551     for(int i = 0; i < model_of_profiles->rowCount(); i++)
552     {
553
554         list_names = model_of_profiles->item(i,1)->data(Qt::DisplayRole).toString().split(QRegExp("\\s+"),QString::SkipEmptyParts);
555         qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "list of words" <<  list_names;
556
557
558
559         if(((x = wordsCount(list_names,ev->GetSummary())) > ccount) && (model_of_profiles->item(i,2)->data().toInt() >= prio)){
560             qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "count is " <<  x;
561             ccount = x;
562             x = 0;
563             profile = model_of_profiles->item(i,0)->data(Qt::DisplayRole).toString();
564             prio = getProfilePriority(profile);
565             qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "for profil" <<  profile;
566         }
567     }
568     return profile;
569 }
570   */
571
572
573 /** getProfilePriority
574 Priority for profile
575 \param name_of_profile name of event
576 */
577 int CalendarProfile::getProfilePriority(QString name_of_profile)
578 {
579     if(name_of_profile.isEmpty()) return 0;
580     int ro = 0;
581     ro =  model_of_profiles->findItems(name_of_profile).at(0)->row(); // najdu  na kterým je to řádku
582     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << " profil " << name_of_profile << "je na řádku" <<  ro;
583     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << " profil " << name_of_profile << " jeho prio je " <<  model_of_profiles->item(ro,2)->data(Qt::DisplayRole).toInt();
584     return model_of_profiles->item(ro,2)->data(Qt::DisplayRole).toInt(); // vratim
585 }
586
587 /** wordsCount
588 Return number of words in event summary
589 \param words list of words in profile
590 \param text text in event
591 */
592 int CalendarProfile::wordsCount(QStringList words, QString text)
593 {
594     int count = 0;
595     foreach(QString word, words)
596     {
597         if(text.contains(word,Qt::CaseInsensitive)) ++count;
598     }
599     qDebug()<< "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Pocet slov:" <<  count << "v textu" << text << "slova co se maj najit" << words;
600     return count;
601 }
602
603 //===========================================================================
604 /** ShowDialog
605 For dialog for modifi calendars and profiles
606 */
607 void CalendarProfile::ShowDialog()
608 {
609     CalendarProfilesDialog dialog(this);
610     dialog.SetViews(model_of_profiles,selModel_profiles,model_of_calendars,selModel_calendars);
611     dialog.SetSettings(settings);
612     connect(&dialog,SIGNAL(s_change_calendars()),this,SLOT(ChangeInCalendarsCheck()));
613     dialog.exec();
614     disconnect(&dialog,SIGNAL(s_change_calendars()),this,SLOT(ChangeInCalendarsCheck()));
615 }
616
617 /** ChangeInCalendarsCheck
618 Slot for chnages in calendars check
619 */
620 void CalendarProfile::ChangeInCalendarsCheck()
621 {
622     SetProfile();
623 }