Adaptations for StationScheduleModel class
[quandoparte] / application / stationschedulemodel.cpp
1 /*
2
3 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING.  If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20 */
21
22 #include "stationschedulemodel.h"
23
24 #include "dataprovider.h"
25
26 #include <QDebug>
27
28 StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent) :
29     QStringListModel(parent),
30     m_name(name)
31
32 {
33     DataProvider *provider = DataProvider::instance();
34
35     connect(provider, SIGNAL(stationScheduleReady(QByteArray,QUrl)),
36             this, SLOT(parse(QByteArray,QUrl)));
37 }
38
39 QString & StationScheduleModel::name()
40 {
41     return m_name;
42 }
43
44 void StationScheduleModel::setName(const QString &name)
45 {
46     if (name != m_name) {
47         m_name = name;
48         emit nameChanged();
49     }
50 }
51
52 void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUrl)
53 {
54     Q_UNUSED(baseUrl);
55     qDebug() << "--- start of query result --- cut here ------";
56     qDebug() << QString::fromUtf8(htmlReply.constData());
57     qDebug() << "--- end of query result ----- cut here ------";
58 }
59
60 void StationScheduleModel::fetch(const QString &name)
61 {
62     DataProvider *provider = DataProvider::instance();
63
64     provider->fetchStationSchedule(name);
65     setName(name);
66 }