- renamed icons to ASCII-only names cause build failed
[buliscores] / src / match.cpp
1 #include "match.h"
2
3 Match::Match(QString hometeam, QString awayteam, QDateTime date, QObject *parent) :
4     QObject(parent)
5 {
6     m_date = date;
7     m_lastevent = QDateTime::currentDateTime();
8
9     m_homeTeam = hometeam;
10     m_awayTeam = awayteam;
11     m_homeScore = -1;
12     m_awayScore = -1;
13
14     m_homeEmblem = getEmblemByName(hometeam);
15     m_awayEmblem = getEmblemByName(awayteam);
16 }
17
18
19 // TODO write team class that allows more attributes
20 // and aliases for team names
21 QIcon Match::getEmblemByName(QString team)
22 {
23     QIcon i;
24
25     if (team == "Hannover 96") {
26         i = QIcon(":/Icons/Hannover.png");
27     } else if (team == "FC St. Pauli") {
28         i = QIcon(":/Icons/St.Pauli.png");
29     } else if (team == "Hamburger SV") {
30         i = QIcon(":/Icons/Hamburg.png");
31     } else if (team == "1. FC Kaiserslautern") {
32         i = QIcon(":/Icons/Kaiserslautern.png");
33     } else if (team == "1. FSV Mainz 05") {
34         i = QIcon(":/Icons/Mainz.png");
35     } else if (team == "1899 Hoffenheim") {
36         i = QIcon(":/Icons/Hoffenheim.png");
37     } else if (team == "Borussia M'gladbach") {
38         i = QIcon(":/Icons/Moenchengladbach.png");
39     } else if (team == "VfL Wolfsburg") {
40         i = QIcon(":/Icons/Wolfsburg.png");
41     } else if (team == "SC Freiburg") {
42         i = QIcon(":/Icons/Freiburg.png");
43     } else if (team == "1. FC Köln") {
44         i = QIcon(":/Icons/Koeln.png");
45     } else if (team == "1. FC Nürnberg") {
46         i = QIcon(":/Icons/Nuernberg.png");
47     } else if (team == "FC Schalke 04") {
48         i = QIcon(":/Icons/Schalke.png");
49     } else if (team == "VfB Stuttgart") {
50         i = QIcon(":/Icons/Stuttgart.png");
51     } else if (team == "Eintracht Frankfurt") {
52         i = QIcon(":/Icons/Frankfurt.png");
53     } else if (team == "Bayer Leverkusen") {
54         i = QIcon(":/Icons/Leverkusen.png");
55     } else if (team == "Werder Bremen") {
56         i = QIcon(":/Icons/Bremen.png");
57     } else if (team == "Borussia Dortmund") {
58         i = QIcon(":/Icons/Dortmund.png");
59     } else if (team == "Bayern München") {
60         i = QIcon(":/Icons/Bayern.png");
61     } else {
62         i = QIcon();
63     }
64
65     return i;
66 }
67
68 void Match::setScore(int home, int away, bool notifyWatchers)
69 {
70     bool changed = false;
71     int oldhomescore = m_homeScore;
72     int oldawayscore = m_awayScore;
73
74     if (m_homeScore != home) {
75         m_homeScore = home;
76         changed = true;
77     }
78
79     if (m_awayScore != away) {
80         m_awayScore = away;
81         changed = true;
82     }
83
84     if (changed) {
85         m_lastevent = QDateTime::currentDateTime();
86         if(notifyWatchers) {
87             emit scoreChanged(oldhomescore, oldawayscore,
88                               home, away);
89         }
90     }
91 }
92
93 void Match::setState(MatchState state, bool notifyWatchers) {
94     if (m_state != state) {
95         m_state = state;
96         m_lastevent = QDateTime::currentDateTime();
97         if (notifyWatchers) {
98             emit stateChanged(state);
99         }
100     }
101 }