- highlight goals updated less than 5 minutes ago
[buliscores] / src / 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
8     m_homeTeam = hometeam;
9     m_awayTeam = awayteam;
10     m_homeScore = -1;
11     m_awayScore = -1;
12
13     m_homeEmblem = getEmblemByName(hometeam);
14     m_awayEmblem = getEmblemByName(awayteam);
15 }
16
17
18 // TODO write team class that allows more attributes
19 // and aliases for team names
20 QIcon Match::getEmblemByName(QString team)
21 {
22     QIcon i;
23
24     if (team == "Hannover 96") {
25         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Hannover.png");
26     } else if (team == "FC St. Pauli") {
27         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/St.Pauli.png");
28     } else if (team == "Hamburger SV") {
29         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Hamburg.png");
30     } else if (team == "1. FC Kaiserslautern") {
31         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Kaiserslautern.png");
32     } else if (team == "1. FSV Mainz 05") {
33         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Mainz.png");
34     } else if (team == "1899 Hoffenheim") {
35         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Hoffenheim.png");
36     } else if (team == "Borussia M'gladbach") {
37         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Moenchengladbach.png");
38     } else if (team == "VfL Wolfsburg") {
39         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Wolfsburg.png");
40     } else if (team == "SC Freiburg") {
41         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Freiburg.png");
42     } else if (team == "1. FC Köln") {
43         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Koeln.png");
44     } else if (team == "1. FC Nürnberg") {
45         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Nuernberg.png");
46     } else if (team == "FC Schalke 04") {
47         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Schalke.png");
48     } else if (team == "VfB Stuttgart") {
49         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Stuttgart.png");
50     } else if (team == "Eintracht Frankfurt") {
51         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Frankfurt.png");
52     } else if (team == "Bayer Leverkusen") {
53         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Leverkusen.png");
54     } else if (team == "Werder Bremen") {
55         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Bremen.png");
56     } else if (team == "Borussia Dortmund") {
57         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Dortmund.png");
58     } else if (team == "Bayern München") {
59         i = QIcon(":/1.Bundesliga/images/teams/Bundesliga1/Bayern.png");
60
61         // 2. Bundesliga
62
63     } else if (team == "Arminia Bielefeld") {
64         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Bielefeld.png");
65     } else if (team == "SpVgg Greuther Fürth") {
66         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/GreutherFuerth.png");
67     } else if (team == "FSV Frankfurt") {
68         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Frankfurt.png");
69     } else if (team == "Hertha BSC") {
70         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/HerthaBerlin.png");
71     } else if (team == "Karlsruher SC") {
72         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Karlsruhe.png");
73     } else if (team == "Energie Cottbus") {
74         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Cottbus.png");
75     } else if (team == "Alemannia Aachen") {
76         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Aachen.png");
77     } else if (team == "Rot-Weiß Oberhausen") {
78         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Oberhausen.png");
79     } else if (team == "Fortuna Düsseldorf") {
80         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Duesseldorf.png");
81     } else if (team == "1. FC Union Berlin") {
82         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/UnionBerlin.png");
83     } else if (team == "Erzgebirge Aue") {
84         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Aue.png");
85     } else if (team == "SC Paderborn 07") {
86         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Paderborn.png");
87     } else if (team == "FC Ingolstadt 04") {
88         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Ingolstadt.png");
89     } else if (team == "1860 München") {
90         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Muenchen.png");
91     } else if (team == "VfL Bochum") {
92         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Bochum.png");
93     } else if (team == "VfL Osnabrück") {
94         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Osnabrueck.png");
95     } else if (team == "FC Augsburg") {
96         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Augsburg.png");
97     } else if (team == "MSV Duisburg") {
98         i = QIcon(":/2.Bundesliga/images/teams/Bundesliga2/Duisburg.png");
99
100         // tipp3Liga
101
102     } else if (team == "Sturm Graz") {
103         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/Graz.png");
104     } else if (team == "Austria Wien") {
105         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/AustriaWien.png");
106     } else if (team == "SV Mattersburg") {
107         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/Mattersburg.png");
108     } else if (team == "RB Salzburg") {
109         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/Salzburg.png");
110     } else if (team == "LASK Linz") {
111         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/Linz.png");
112     } else if (team == "Rapid Wien") {
113         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/RapidWien.png");
114     } else if (team == "SV Ried") {
115         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/Ried.png");
116     } else if (team == "Kapfenberger SV") {
117         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/Kapfenberg.png");
118     } else if (team == "Wacker Innsbruck") {
119         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/Innsbruck.png");
120     } else if (team == "SC Wiener Neustadt") {
121         i = QIcon(":/tipp3Liga/images/teams/tipp3Liga/WienerNeustadt.gif");
122     } else {
123
124
125         i = QIcon();
126     }
127
128     return i;
129 }
130
131 void Match::setScore(int home, int away, bool notifyWatchers)
132 {
133     bool changed = false;
134     int oldhomescore = m_homeScore;
135     int oldawayscore = m_awayScore;
136
137     if (m_homeScore != home) {
138         m_homeScore = home;
139         if (oldhomescore != -1) {
140             m_lastHomeGoal = QDateTime::currentDateTime();
141         }
142         changed = true;
143     }
144
145     if (m_awayScore != away) {
146         m_awayScore = away;
147         if (oldawayscore != -1) {
148             m_lastAwayGoal = QDateTime::currentDateTime();
149         }
150         changed = true;
151     }
152
153     if (changed && notifyWatchers) {
154         emit scoreChanged(oldhomescore, oldawayscore,
155                           home, away);
156     }
157 }
158
159 void Match::setState(MatchState state, bool notifyWatchers) {
160     if (m_state != state) {
161         m_state = state;
162         if (notifyWatchers) {
163             emit stateChanged(state);
164         }
165     }
166 }