src/mainwidget.h \
src/matchdaymodel.h \
src/scoretable.h \
- src/settingsdialog.h
+ src/settingsdialog.h \
+ src/matchdaybackend.h
SOURCES += \
src/main.cpp \
src/mainwidget.cpp \
src/matchdaymodel.cpp \
src/scoretable.cpp \
- src/settingsdialog.cpp
+ src/settingsdialog.cpp \
+ src/matchdaybackend.cpp
RESOURCES += \
resources.qrc
#include <QStringList>
#include <QDateTime>
#include <QSettings>
+#include <QApplication>
#include "backendkicker.h"
BackendKicker::BackendKicker(QObject *parent) :
- QObject(parent)
+ MatchDayBackend(parent)
{
- QSettings settings("David Solbach", "BuliScores");
- this->setLeague(settings.value("League", "1. Bundesliga").toString());
+ QSettings settings(qApp->organizationName(), qApp->applicationName());
+ this->selectLeague(settings.value("League", "1. Bundesliga").toString());
this->update();
}
return team;
}
-static int parseScore(Match* match, QString scorehtml)
+static void parseScore(Match* match, QString scorehtml)
{
- int score = -1;
QStringList tokens;
qDebug() << "parseScore in: " << scorehtml;
match->setState(Match::HalfTime);
} else {
// no color tag and no "-" -> game is finished
- match->setScore(tokens.at(1).toInt(), tokens.at(3).toInt());
+ match->setScore(tokens.at(1).toInt(), tokens.at(2).toInt());
match->setState(Match::Finished);
}
} else {
}
}
- qDebug() << "match out: " << match;
-
- return score;
+ qDebug() << "match state: " << match->state();
+ qDebug() << "match home: " << match->homeScore();
+ qDebug() << "match away: " << match->awayScore();
}
void BackendKicker::parsePage (QString htmlstr)
}
}
-void BackendKicker::setLeague(QString league)
+bool BackendKicker::selectLeague(QString league)
{
+ bool leagueIsSupported = true;
+
if (league == "1. Bundesliga") {
m_URL = "http://www.kicker.de/news/fussball/bundesliga/spieltag/1-bundesliga/2010-11/spieltag.html";
} else if (league == "2. Bundesliga") {
m_URL = "http://www.kicker.de/news/fussball/bundesliga/spieltag/2-bundesliga/2010-11/spieltag.html";
} else if (league == "tipp3 Bundesliga") {
m_URL = "http://www.kicker.de/news/fussball/intligen/oesterreich/tipp3-bundesliga/2010-11/spieltag.html";
+ } else {
+ leagueIsSupported = false;
}
// delete last data
- this->m_matchlist.clear();
- emit matchListChanged();
+ return leagueIsSupported;
}
void BackendKicker::update()
{
- //QString URL = "file:///home/david/Projects/git-buliscores/testdata/spieltag.html";
+ emit updateStarted();
+ //QString URL = "file:///home/david/Projects/git-buliscores/testdata/spieltag.html";
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(dlndFinished(QNetworkReply*)));
qDebug() << "dlnd failed: error: " << reply->error();
}
+ this->m_matchlist.clear();
+
rawdata = reply->readAll();
parsePage(rawdata);
+
emit matchListChanged();
}
#include <QObject>
#include <QNetworkReply>
-#include "match.h"
+#include "matchdaybackend.h"
-class BackendKicker : public QObject
+class BackendKicker : public MatchDayBackend
{
Q_OBJECT
private:
Match* getMatch(QString hometeam, QString awayteam, QDateTime date);
QList<Match*> matchList();
- void setLeague(QString league);
+ bool selectLeague(QString league);
signals:
void matchListChanged(void);
+ void updateStarted(void);
private slots:
void dlndFinished(QNetworkReply *reply);
QApplication app(argc, argv);
MainWidget mw;
+ app.setApplicationName("Buli Scores");
+ app.setApplicationVersion("0.1");
+ app.setOrganizationName("David Solbach");
mw.resize(400,250);
QMaemo5HomescreenAdaptor *adaptor = new QMaemo5HomescreenAdaptor(&mw);
#include <QSettings>
#include <QMouseEvent>
-
+#include <QApplication>
#include "mainwidget.h"
+#include "backendkicker.h"
#include "matchdaymodel.h"
#include "settingsdialog.h"
MainWidget::MainWidget(QWidget *parent) :
QWidget(parent),
- m_datamodel(new MatchDayModel(this)),
+ m_backend(new BackendKicker(this)),
+ m_datamodel(new MatchDayModel(this, m_backend)),
m_scoretbl(new ScoreTable(m_datamodel)),
- m_settingsdlg(new SettingsDialog(this))
+ m_settingsdlg(new SettingsDialog(this)),
+ m_settings(qApp->organizationName(), qApp->applicationName())
{
QFont f;
QPalette palette;
- f.setPixelSize(14);
- palette.setColor(QPalette::Window, QColor(100, 100, 100, 127));
-
- m_statuslbl.setAttribute(Qt::WA_TransparentForMouseEvents);
+ f.setPixelSize(40);
+ palette.setColor(QPalette::Background, QColor(0, 0, 0, 127));
+ palette.setColor(QPalette::Foreground, QColor(255, 255, 255, 127));
+ m_statuslbl.hide();
m_statuslbl.setPalette(palette);
+ m_statuslbl.setAttribute(Qt::WA_TransparentForMouseEvents);
+ m_statuslbl.setAutoFillBackground(true);
+ m_statuslbl.setBackgroundRole(QPalette::Background);
+ m_statuslbl.setAlignment(Qt::AlignCenter);
+
m_statuslbl.setFont(f);
- m_statuslbl.setText(tr("Last Update: Never"));
this->setAttribute(Qt::WA_TranslucentBackground);
-
this->setLayout(&m_layout);
m_layout.addWidget(&m_statuslbl);
m_layout.addWidget(m_scoretbl);
- this->setAutoFillBackground(true);
-
connect(m_settingsdlg, SIGNAL(accepted()),
- m_datamodel, SLOT(update()));
+ this, SLOT(update()));
+
+ connect(m_backend, SIGNAL(matchListChanged()),
+ this, SLOT(onBackendUpdateFinished()));
+
+ connect(m_backend, SIGNAL(updateStarted()),
+ this, SLOT(onBackendUpdateStarted()));
}
+// only needed for testing on desktop
void MainWidget::mousePressEvent(QMouseEvent* event)
{
- this->showSettingsDialog();
+ if (event->button() == Qt::RightButton) {
+ this->showSettingsDialog();
+ }
}
+void MainWidget::update(void)
+{
+ m_backend->selectLeague(m_settings.value("League", "1. Bundesliga").toString());
+ m_backend->update();
+}
+
+void MainWidget::onBackendUpdateStarted()
+{
+ m_statuslbl.setText(tr("Updating..."));
+ m_statuslbl.show();
+ m_scoretbl->hide();
+}
+
+void MainWidget::onBackendUpdateFinished()
+{
+ m_scoretbl->show();
+ m_statuslbl.hide();
+}
void MainWidget::showSettingsDialog()
{
#include <QVBoxLayout>
#include <QLabel>
+#include "matchdaybackend.h"
#include "scoretable.h"
#include "settingsdialog.h"
class MainWidget : public QWidget
{
Q_OBJECT
-private:
- MatchDayModel* m_datamodel;
- ScoreTable* m_scoretbl;
- SettingsDialog* m_settingsdlg;
-
- QVBoxLayout m_layout;
- QLabel m_statuslbl;
-
public:
explicit MainWidget(QWidget *parent = 0);
void mousePressEvent(QMouseEvent* event);
-signals:
-
public slots:
void showSettingsDialog();
+protected slots:
+ void onBackendUpdateStarted();
+ void onBackendUpdateFinished(void);
+
+private:
+ MatchDayBackend* m_backend;
+ MatchDayModel* m_datamodel;
+ ScoreTable* m_scoretbl;
+ SettingsDialog* m_settingsdlg;
+ QSettings m_settings;
+
+ QVBoxLayout m_layout;
+ QLabel m_statuslbl;
+
+private slots:
+ void update(void);
+
};
#endif // MAINWIDGET_H
--- /dev/null
+#include <QObject>
+
+#include "match.h"
+#include "matchdaybackend.h"
+
+
+MatchDayBackend::MatchDayBackend(QObject *parent) : QObject(parent)
+{
+
+}
+
--- /dev/null
+#ifndef MATCHDAYBACKEND_H
+#define MATCHDAYBACKEND_H
+
+#include <QObject>
+
+#include "match.h"
+
+/*
+ * Pure virtual class serving as a common interface for backends
+ * providing MatchDay Data
+ */
+class MatchDayBackend : public QObject
+{
+ Q_OBJECT
+public:
+ explicit MatchDayBackend(QObject *parent = 0);
+
+public:
+
+ virtual Match* getMatch(QString hometeam, QString awayteam, QDateTime date) = 0;
+ virtual QList<Match*> matchList() = 0;
+
+ virtual bool selectLeague(QString league) = 0;
+ virtual bool setAutomaticUpdate(bool) = 0;
+
+signals:
+ void matchListChanged(void);
+ void updateStarted(void);
+
+public slots:
+ virtual void update() = 0;
+};
+
+#endif // MATCHDAYBACKEND_H
#include <QDebug>
+#include <QBrush>
#include <QColor>
#include <QFontMetrics>
#include <QFont>
#include <QIcon>
#include <QSettings>
+#include <QApplication>
#include "matchdaymodel.h"
#include "match.h"
-MatchDayModel::MatchDayModel(QObject *parent) :
+MatchDayModel::MatchDayModel(QObject *parent, MatchDayBackend *backend) :
QAbstractTableModel(parent),
m_lastRowCount(0),
- m_settings("David Solbach", "BuliScores")
+ m_settings(qApp->organizationName(), qApp->applicationName())
{
-
- m_backend = new BackendKicker(this);
+ m_backend = backend;
connect(m_backend, SIGNAL(matchListChanged()),
this, SLOT(onMatchListChanged()));
-
}
int MatchDayModel::rowCount(const QModelIndex&) const
// DisplayRole
switch (role) {
+ case Qt::BackgroundRole:
+ return QBrush(QColor(0, 0, 0, 100));
+ break;
case Qt::DecorationRole:
switch (index.column()) {
case AwayIcon:
return s;
break;
- case Qt::BackgroundRole:
- return QColor(0, 0, 0, 120);
- break;
-
case Qt::TextAlignmentRole:
if (index.column() < 3) {
return 0x0002 | 0x0080;
m_lastRowCount = m_backend->matchList().count() - 1;
// invalidate complete data
-
qDebug() << "rowCount @ emit dataChanged: " << rowCount(QModelIndex());
emit dataChanged(index(0, 0),
index(rowCount(QModelIndex()) - 1, columnCount(QModelIndex()) - 1));
}
-
-void MatchDayModel::update(void)
-{
- this->m_backend->setLeague(m_settings.value("League", "1. Bundesliga").toString());
- this->m_backend->update();
-}
#include <QFontMetrics>
#include <QSettings>
-#include "backendkicker.h"
+#include "matchdaybackend.h"
class MatchDayModel : public QAbstractTableModel
{
};
private:
- QString m_url;
- BackendKicker* m_backend;
- int m_lastRowCount;
- QSettings m_settings;
+ QString m_url;
+ MatchDayBackend* m_backend;
+ int m_lastRowCount;
+ QSettings m_settings;
public:
- explicit MatchDayModel(QObject *parent = 0);
+ explicit MatchDayModel(QObject *parent, MatchDayBackend* backend);
int rowCount(const QModelIndex& index) const;
int columnCount(const QModelIndex& index) const;
protected slots:
void onMatchListChanged(void);
-public slots:
- void update(void);
-
};
#endif // MATCHDAYMODEL_H
ScoreTable::ScoreTable(MatchDayModel* model, QWidget *parent) :
QTableView(parent)
{
- this->setAttribute(Qt::WA_TransparentForMouseEvents);
- this->setAttribute(Qt::WA_TranslucentBackground);
+ QPalette palette;
+ this->hide();
+ // data
this->setModel(model);
+
+ // behaviour
+ this->setAttribute(Qt::WA_TransparentForMouseEvents);
this->setSelectionMode(QAbstractItemView::NoSelection);
- this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ // style
+ palette.setColor(QPalette::Background, QColor(0, 0, 0, 200));
this->verticalHeader()->hide();
this->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
this->verticalHeader()->setMinimumSectionSize(1);
-
this->horizontalHeader()->hide();
this->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
this->horizontalHeader()->setMinimumSectionSize(1);
- qDebug() << "Min VertHeaderSize: " << this->verticalHeader()->minimumSectionSize();
-
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- this->viewport()->setAutoFillBackground(true);
+ this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ this->setAttribute(Qt::WA_TranslucentBackground);
+ this->viewport()->setAttribute(Qt::WA_TranslucentBackground);
+
this->setShowGrid(false);
}
this->updateGeometry();
}
-void ScoreTable::mousePressEvent(QMouseEvent* event)
-{
- MatchDayModel* m = (MatchDayModel*)this->model();
- m->update();
-}
-
class ScoreTable : public QTableView
{
Q_OBJECT
-protected:
- void mousePressEvent(QMouseEvent*);
-
public:
explicit ScoreTable(MatchDayModel* model, QWidget *parent = 0);
QSize sizeHint() const;
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsDialog),
- settings("David Solbach", "BuliScores")
+ settings(qApp->organizationName(), qApp->applicationName())
{
QString league;