Initial version
[quandoparte] / application / stationlistview.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 "stationlistview.h"
23 #include "ui_stationlistview.h"
24
25 #include "settingsdialog.h"
26 #include "stationview.h"
27
28 #include <QActionGroup>
29 #include <QDebug>
30 #include <QStringListModel>
31
32 StationListView::StationListView(QWidget *parent) :
33     QMainWindow(parent),
34     ui(new Ui::StationListView),
35     viewSelectionGroup(new QActionGroup(0)),
36     stationListModel(new QStringListModel()),
37     stationView(0)
38
39 {
40 #ifdef Q_WS_MAEMO_5
41     setAttribute(Qt::WA_Maemo5StackedWindow);
42 #endif
43     ui->setupUi(this);
44     viewSelectionGroup->addAction(ui->sortByNameAction);
45     viewSelectionGroup->addAction(ui->sortNearFirstAction);
46     viewSelectionGroup->addAction(ui->sortRecentFirstAction);
47     QStringList stationList;
48     stationList << "Genova Voltri"
49                 << "Genova Pra"
50                 << "Genova Pegli"
51                 << "Genova Sestri Ponente"
52                 << "Genova Cornigliano"
53                 << "Genova Sampierdarena"
54                 << "Genova Via di Francia"
55                 << "Genova Piazza Principe"
56                 << "Genova Brignole"
57                 << "Genova Sturla"
58                 << "Genova Quarto dei Mille"
59                 << "Genova Quinto al Mare"
60                 << "Genova Nervi";
61     stationListModel->setStringList(stationList);
62     ui->listView->setModel(stationListModel);
63     ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
64     ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
65
66     connect(ui->listView,
67             SIGNAL(activated(QModelIndex)), SLOT(showStation(QModelIndex)));
68 }
69
70 StationListView::~StationListView()
71 {
72     delete ui;
73 }
74
75 void StationListView::showSettings(void)
76 {
77     qDebug() << "Show Settings";
78     SettingsDialog *settingsDialog = new SettingsDialog(this);
79     if (settingsDialog->exec() == QDialog::Accepted) {
80         // TODO Use new settings
81     }
82
83     delete settingsDialog;
84 }
85
86 void StationListView::showStation(const QModelIndex &index)
87 {
88     qDebug() << "Show Station" << index.data();
89     emit stationSelected(index.data().toString());
90 }