N9profile
[n9profile] / timeprofile.cpp
1 #include <QtCore/QDebug> //Debug pro informace
2 #include <QtCore/QSettings>
3 #include <QtCore/QTimer>
4 #include "timeprofile.h"
5 #include "timedprofildialog.h"
6 #include <QtCore/QStringList>
7 #include <QtCore/QTime>
8 /** TimeProfile()
9 create new labels
10 */
11 TimeProfile::TimeProfile(QWidget *parent,QSettings *set) :
12         QWidget(parent)
13 {
14     settings = set;
15     timer = new QTimer(this);
16     timer->setSingleShot(true);//A single-shot timer fires only once
17     connect(timer,SIGNAL(timeout()),this,SLOT(TimerTimeout()));
18 }
19
20 /** SetTimer()
21 create new labels
22 */
23 void TimeProfile::SetTimer(QStringList  list_of_profiles_n)
24 {
25     TimedProfilDialog dialog(list_of_profiles_n, this);
26     int result = dialog.exec();
27     if(result)
28     {
29         QTime nula_cas(0,0);
30         // dialog.GetTime().msec()
31         //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "time:" << dialog.GetTime() ;
32         //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "different:" << nula_cas.msecsTo(dialog.GetTime());
33         if(dialog.GetTime() == nula_cas){
34             timer->stop();
35             profile = QString("");
36             emit  s_set_timed_profile(QString(""));//send empty string
37             return;
38         }
39         timer->start(nula_cas.msecsTo(dialog.GetTime()));
40         profile = dialog.GetName();
41         emit s_set_timed_profile(profile);
42     }
43 }
44
45 /** TimerTimeout()
46 timer timeout slot
47 */
48 void TimeProfile::TimerTimeout()
49 {
50     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "timer  timeout" ;
51     profile = QString("");
52     emit  s_set_timed_profile(QString(""));//send empty string
53 }
54
55 /** ChangeInProfles()
56 When profiles change , find profile
57 if not exist stop this profile
58 */
59 void TimeProfile::ChangeInProfles(QStringList list_profiles)
60 {
61     if(!list_profiles.contains(profile))
62     {
63         timer->stop();
64         emit  s_set_timed_profile(QString(""));//send empty string
65     }
66 }
67