doxygen comments
[aspt.git] / loadtab.cc
1 /*******************************************************************
2 Jan Cermak | johniez | aspt.johniez.com
3 Creative Commons 2.5 Attribution-NonCommercial-NoDerivs 2.5 license
4 http://creativecommons.org/licenses/by-nc-nd/2.5/legalcode
5 *******************************************************************/
6
7 #include "loadtab.h"
8
9 /**
10  * \brief Load Tab constructor.
11  */
12 LoadTab::LoadTab(QWidget * parent) : QWidget(parent) {
13         init();
14 }
15
16 /**
17  * \brief Load Tab destructor.
18  */
19 LoadTab::~LoadTab() {
20         delete label;
21         delete older;
22         delete mainLayout;
23 }
24
25 /**
26  * Init UI for this tab.
27  */
28 void LoadTab::init() {
29         QSettings settings("config/global.ini", QSettings::IniFormat);
30         QString num = settings.value("nextXmlId", "0").toString();
31         
32         QDate initDay(2004, 7, 5);
33         
34         older = new QComboBox();
35         
36         int j = 0;
37         for(int i=num.toInt()-1; i>=0; i--) {
38                 quickparse("data/data_"+QString().setNum(i)+".xml");            // should be stored somewhere else
39                 if(globSlot) {
40                         dataParsed[j][0] = globSlot;
41                         dataParsed[j][1] = curSlot;
42                         dataParsed[j][2] = curSeason;
43                         dataParsed[j][3] = i;
44                 }
45                 QDate cDate = initDay.addDays((dataParsed[j][0]-1)/5);
46                 QString time;
47                 switch((dataParsed[j][0]-1)%5) {
48                         case 0: time = " 4:00-10:00"; break;
49                         case 1: time = " 10:00-14:00"; break;
50                         case 2: time = " 14:00-18:00"; break;
51                         case 3: time = " 18:00-22:00"; break;
52                         case 4: time = " 22:00-4:00"; break;
53                 }
54                 older->addItem("S:" + QString().setNum(dataParsed[j][2]) + " - " + cDate.toString("d.M.yyyy") + time, "");
55                 j++;
56                 if(j>=20) break;
57         }
58         
59         mainLayout = new QVBoxLayout;
60         QString text;
61         
62         label = new QLabel(text);
63         mainLayout->addWidget(older);
64         mainLayout->addWidget(label);
65         setLayout(mainLayout);
66         connect(older, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)));
67 }
68
69 /**
70  * \brief Slot assigned to data change action.
71  */
72 void LoadTab::dataChanged() {
73         rebuildUI();
74 }
75
76 /**
77  * \brief Slot assigned to combobox index change.
78  * \param i selected index.
79  */
80 void LoadTab::indexChanged(int i) {
81         int fileNum = dataParsed[i][3];
82         parse("data/data_" + QString().setNum(fileNum) + ".xml");
83         emit loaded();
84         label->clear();
85         label->setText(tr("Loaded file: ") + "data_" + QString().setNum(fileNum) + ".xml");
86 }
87
88 /**
89  * \brief Delete UI and draw it again.
90  */
91 void LoadTab::rebuildUI() {
92         delete older;
93         delete label;
94         delete mainLayout;
95         init();
96 }