-
Notifications
You must be signed in to change notification settings - Fork 0
/
OverviewHandler.cpp
223 lines (195 loc) · 6.02 KB
/
OverviewHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// -----------------------------------------------------------------------------
// OverviewHandler.cpp OverviewHandler.cpp
// -----------------------------------------------------------------------------
/**
* @file
* @brief This file holds the implementation of the @ref OverviewHandler class.
* @author Col. Walter E. Kurtz
* @version 2016-11-09
* @copyright GNU General Public License - Version 3.0
*/
// -----------------------------------------------------------------------------
// Includes Includes
// -----------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include "keyinfo.h"
#include "OverviewHandler.h"
// -----------------------------------------------------------------------------
// Used namespaces Used namespaces
// -----------------------------------------------------------------------------
using namespace std;
// -----------------------------------------------------------------------------
// Construction Construction
// -----------------------------------------------------------------------------
// ---------------
// OverviewHandler
// ---------------
/*
*
*/
OverviewHandler::OverviewHandler(bool detailed)
{
// set verbosity level
m_detailed = detailed;
}
// -----------------------------------------------------------------------------
// Callback handler Callback handler
// -----------------------------------------------------------------------------
// --------------
// OnBeginParsing
// --------------
/*
*
*/
void OverviewHandler::OnBeginParsing(const string& filename)
{
// update healthy flag
setHealthy();
// empty buffers
m_keys.clear();
m_values.clear();
}
// ------------
// OnEndParsing
// ------------
/*
*
*/
void OverviewHandler::OnEndParsing(bool healthy)
{
// empty buffers
m_keys.clear();
m_values.clear();
}
// ------
// OnData
// ------
/*
*
*/
void OverviewHandler::OnData(const string& key, const string& value)
{
// don't run in bad state
if ( !healthy() ) return;
// buffer tag
m_keys.push_back(key);
m_values.push_back(value);
// trigger found
if ( key == keyinfo::name(keyinfo::COMPILATIONINDEX) )
{
if (m_detailed)
{
showVerbose();
}
else
{
showBrief();
}
// empty buffers
m_keys.clear();
m_values.clear();
}
}
// -----------------------------------------------------------------------------
// Internal methods Internal methods
// -----------------------------------------------------------------------------
// --------
// getValue
// --------
/*
*
*/
string OverviewHandler::getValue(const string& key) const
{
// find related value
for(unsigned i = 0; i < m_keys.size(); i++)
{
if (m_keys[i] == key)
{
return m_values[i];
}
}
// key not found
return "";
}
// ---------
// showBrief
// ---------
/*
*
*/
void OverviewHandler::showBrief() const
{
// get album and track artist
string aa = getValue( keyinfo::name(keyinfo::ALBUMARTIST) );
string ta = getValue( keyinfo::name(keyinfo::ARTIST) );
// same artist
if (aa == ta)
{
// print one line
cout << setw(3) << right
<< getValue( keyinfo::name(keyinfo::COMPILATIONINDEX) ) << ". "
<< getValue( keyinfo::name(keyinfo::ALBUMARTIST) ) << " - "
<< getValue( keyinfo::name(keyinfo::ALBUM) ) << " - ["
<< getValue( keyinfo::name(keyinfo::TRACKNUMBER) ) << "] "
<< getValue( keyinfo::name(keyinfo::TITLE) ) << endl;
}
// different artists
else
{
// print one line
cout << setw(3) << right
<< getValue( keyinfo::name(keyinfo::COMPILATIONINDEX) ) << ". "
<< getValue( keyinfo::name(keyinfo::ALBUMARTIST) ) << " - "
<< getValue( keyinfo::name(keyinfo::ALBUM) ) << " - ["
<< getValue( keyinfo::name(keyinfo::TRACKNUMBER) ) << "] "
<< getValue( keyinfo::name(keyinfo::ARTIST) ) << " - "
<< getValue( keyinfo::name(keyinfo::TITLE) ) << endl;
}
}
// -----------
// showVerbose
// -----------
/*
*
*/
void OverviewHandler::showVerbose() const
{
// print comments in this order
vector<string> order;
order.push_back( keyinfo::name(keyinfo::IMAGE) );
order.push_back( keyinfo::name(keyinfo::COMPILATIONID) );
order.push_back( keyinfo::name(keyinfo::COMPILATIONINDEX) );
order.push_back( keyinfo::name(keyinfo::AUTHOR) );
order.push_back( keyinfo::name(keyinfo::COMPOSER) );
order.push_back( keyinfo::name(keyinfo::LYRICIST) );
order.push_back( keyinfo::name(keyinfo::OPUS) );
order.push_back( keyinfo::name(keyinfo::VERSION) );
order.push_back( keyinfo::name(keyinfo::ARRANGER) );
order.push_back( keyinfo::name(keyinfo::PERFORMER) );
order.push_back( keyinfo::name(keyinfo::CONDUCTOR) );
order.push_back( keyinfo::name(keyinfo::ENSEMBLE) );
order.push_back( keyinfo::name(keyinfo::ALBUMARTIST) );
order.push_back( keyinfo::name(keyinfo::ALBUM) );
order.push_back( keyinfo::name(keyinfo::GENRE) );
order.push_back( keyinfo::name(keyinfo::DATE) );
order.push_back( keyinfo::name(keyinfo::TRACKTOTAL) );
order.push_back( keyinfo::name(keyinfo::TRACKNUMBER) );
order.push_back( keyinfo::name(keyinfo::ARTIST) );
order.push_back( keyinfo::name(keyinfo::TITLE) );
order.push_back( keyinfo::name(keyinfo::COMMENT) );
order.push_back( keyinfo::name(keyinfo::FILENAME) );
showBrief();
// show sequence
for(unsigned n = 0; n < order.size(); n++)
{
cout << setw(21) << right
<< order[n]
<< "="
<< getValue(order[n])
<< endl;
}
// add empty line
cout << endl;
}