N9profile
[n9profile] / timedprofildialog.cpp
1 #include "timedprofildialog.h"
2 #include "ui_timedprofildialog.h"
3 #include <QMaemo5ValueButton>
4 #include <QMaemo5ListPickSelector>
5 #include <QMaemo5InformationBox>
6 #include <QMaemo5TimePickSelector>
7 #include <QtCore/QStringList>
8
9 #include <QtGui/QStandardItemModel>
10 #include <QLabel>
11 #include <QtCore/QDebug> //Debug pro informace
12 TimedProfilDialog::TimedProfilDialog(QStringList list,QWidget *parent) :
13         QDialog(parent),
14         ui(new Ui::TimedprofilDialog)
15 {
16     ui->setupUi(this);
17
18     createNewMaemoButtons(list);
19     createNewLabels();
20 }
21
22 /** createNewMaemoButtons()
23 create maemo buttons
24 */
25 void TimedProfilDialog::createNewMaemoButtons(QStringList list)
26 {
27     QStandardItemModel *testmodel = new QStandardItemModel(this);
28     for (int i = 0; i < list.size(); ++i)
29         testmodel->appendRow(new QStandardItem(list.at(i)));
30
31     v1 = new QMaemo5ValueButton(tr("Name of profile"), this);
32     v1->setValueLayout(QMaemo5ValueButton::ValueBesideText);
33     list_pick = new QMaemo5ListPickSelector();
34     list_pick->setModel(testmodel);
35     v1->setPickSelector(list_pick);
36     ui->gridLayout->addWidget(v1,0,1);
37
38     v2 = new QMaemo5ValueButton(tr("Time"),this);
39     v2->setValueLayout(QMaemo5ValueButton::ValueBesideText);
40     time_pick = new QMaemo5TimePickSelector();
41     time_pick->setCurrentTime(QTime(0,0));//0 hours, 0 min
42     v2->setPickSelector(time_pick);
43     ui->gridLayout->addWidget(v2,1,1);
44 }
45
46 /** createNewLabels()
47 create new labels
48 */
49 void TimedProfilDialog::createNewLabels()
50 {
51     QLabel * label_name = new QLabel(this);
52     label_name->setObjectName(QString::fromUtf8("label_name"));
53     QFont font;
54     font.setPointSize(17);
55     label_name->setFont(font);
56     label_name->setText(tr("Name of profile"));
57     ui->gridLayout->addWidget(label_name, 0, 0);
58     QLabel *label_time = new QLabel(this);
59     label_time->setObjectName(QString::fromUtf8("label_time"));
60     label_time->setFont(font);
61     label_time->setText(tr("Select time"));
62     ui->gridLayout->addWidget(label_time, 1, 0);
63 }
64
65
66 TimedProfilDialog::~TimedProfilDialog()
67 {
68     delete ui;
69 }
70
71 /** accept()
72 Slot for signal when user click on save button.
73 Check is everyting is OK
74 */
75 void TimedProfilDialog::accept()
76 {
77     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " Profile is:" << list_pick->currentValueText();
78     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " Time is : " <<  time_pick->currentValueText();
79     time_for_set = time_pick->currentTime();
80
81     name_of_profile = list_pick->currentValueText();
82     if(name_of_profile.isEmpty())
83     {
84         QMaemo5InformationBox::information(this, tr("Select profile"), QMaemo5InformationBox::DefaultTimeout);
85         return;
86     }
87
88     QTime nula_cas(0,0);
89     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Hours: " << time_for_set.hour() << "min " << time_for_set.minute();
90     qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "sec to" << nula_cas.secsTo(time_for_set);
91     done(QDialog::Accepted);
92 }
93
94 /** GetTime()
95 Return time from time picker
96 */
97 QTime TimedProfilDialog::GetTime()
98 {
99     return time_for_set;
100 }
101
102 /** GetName()
103 Return name from list picker
104 */
105 QString TimedProfilDialog::GetName()
106 {
107     return name_of_profile;
108 }
109
110 void TimedProfilDialog::changeEvent(QEvent *e)
111 {
112     QDialog::changeEvent(e);
113     switch (e->type()) {
114     case QEvent::LanguageChange:
115         ui->retranslateUi(this);
116         break;
117     default:
118         break;
119     }
120 }