Shape text using Pango and HarfBuzz; gives us nice ligatures and exotic scripts.
[ccbs] / bigscreen / fetch_group.cpp
1 #include "fetch_group.h"
2
3 FetchGroup::FetchGroup(unsigned tournament, unsigned round, unsigned parallel, Group *group) :
4         tournament(tournament), round(round), parallel(parallel), dest_group(group) {}
5         
6 void FetchGroup::operator() (pqxx::transaction<> &t)
7 {
8         // note: this _will_ break if any song has more than one short title!
9         pqxx::result res( t.exec("SELECT numqualifying,playmode,difficulty,position,songnumber,player,nick,song,title,COALESCE(shorttitle,title) AS shorttitle,artist,chosen,score FROM rounds NATURAL JOIN roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs NATURAL LEFT JOIN songshorttitles WHERE " 
10                 "tournament=" + pqxx::to_string(tournament) + " AND " +
11                 "round=" + pqxx::to_string(round) + " AND " +
12                 "parallel=" + pqxx::to_string(parallel) + " " +
13                 "ORDER BY position,songnumber") );
14
15         curr_group.tournament = tournament;
16         curr_group.round = round;
17         curr_group.parallel = parallel;
18         
19         // massage the data we get back into a Group object and children
20         int curr_player = -1;
21         for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
22                 curr_group.num_qualifying = i["numqualifying"].as(curr_group.num_qualifying);
23                 
24                 if (i["player"].as(curr_player) != curr_player) {
25                         Player p;
26
27                         p.id = i["player"].as(p.id);
28                         p.position = i["position"].as(p.id);
29                         p.nick = i["nick"].as(p.nick);
30                         p.total = 0;
31                         p.rank = 1;
32                         curr_group.players.push_back(p);
33                         
34                         curr_player = i["player"].as(curr_player);
35                 }
36
37                 // note: we _will_ get some duplication here (multiple identical Song
38                 // objects), but it isn't the end of the world
39                 Score sc;
40                 Song so;
41
42                 if (i["song"].is_null()) {
43                         so.id = -1;
44                 } else {
45                         so.id = i["song"].as(so.id);
46                         so.title = i["title"].as(so.title);
47                         so.artist = i["artist"].as(so.artist);
48                         so.short_title = i["shorttitle"].as(so.short_title);
49                 }
50         
51                 sc.song = so;
52                 sc.chosen = i["chosen"].as(sc.chosen);
53
54                 if (i["score"].is_null()) {
55                         sc.score = -1;
56                 } else {
57                         sc.score = i["score"].as(sc.score);
58                         curr_group.players[curr_group.players.size() - 1].total += sc.score;
59                 }
60
61                 curr_group.players[curr_group.players.size() - 1].scores.push_back(sc);
62         }
63         *dest_group = curr_group;
64 }