Child: [1d3ef3] (diff)

Download this file

sortprefs.cpp    97 lines (82 with data), 2.8 kB

 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
#include "sortprefs.h"
#include <map>
#include <string>
#include "HelperStructs/Helper.h"
#include "HelperStructs/CSettingsStorage.h"
#include "upadapt/upputils.h"
using namespace std;
static map<string, string> allSortCrits;
static map<string, string> allSortCritsRev;
void SortprefsW::loadValues()
{
qDebug() << "SortprefsW::loadValues()";
if (allSortCrits.empty()) {
allSortCrits["Track Number"] = "upnp:originalTrackNumber";
allSortCrits["Track Title"] = "dc:title";
allSortCrits["Date"] = "dc:date";
allSortCrits["Artist"] = "upnp:artist";
allSortCrits["Album Title"] = "upnp:album";
allSortCrits["URI"] = "uri";
for (map<string, string>::iterator it = allSortCrits.begin();
it != allSortCrits.end(); it++) {
allSortCritsRev[it->second] = it->first;
}
}
QStringList qcrits = CSettingsStorage::getInstance()->getSortCrits();
vector<string> crits;
if (qcrits.size() == 0) {
qcrits.push_back("upnp:artist");
qcrits.push_back("upnp:album");
qcrits.push_back("upnp:originalTrackNumber");
qcrits.push_back("dc:title");
qcrits.push_back("dc:date");
qcrits.push_back("uri");
}
for (int i = 0; i < qcrits.size(); i++) {
string nm = allSortCritsRev[qs2utf8s(qcrits[i])];
if (nm == "") {
// Bummer. Limp along and hope for the best
nm = qs2utf8s(qcrits[i]);
}
crits.push_back(nm);
}
critsLW->clear();
for (unsigned int i = 0; i < crits.size(); ++i)
critsLW->addItem(new QListWidgetItem(crits[i].c_str()));
int sortkind = CSettingsStorage::getInstance()->getSortKind();
switch (sortkind) {
case CSettingsStorage::SK_NOSORT:
default:
noSortRB->setChecked(true);
break;
case CSettingsStorage::SK_MINIMFNORDER:
minimfnRB->setChecked(true);
break;
case CSettingsStorage::SK_CUSTOM:
sortRB->setChecked(true);
break;
}
}
void SortprefsW::storeValues()
{
qDebug() << "SortprefsW::storeValues()";
int sortkind = CSettingsStorage::SK_NOSORT;
if (minimfnRB->isChecked()) {
sortkind = CSettingsStorage::SK_MINIMFNORDER;
} else if (sortRB->isChecked()) {
sortkind = CSettingsStorage::SK_CUSTOM;
}
CSettingsStorage::getInstance()->setSortKind(sortkind);
QStringList qcrits;
for (int i = 0; i < critsLW->count(); i++) {
QString val =
critsLW->item(i)->data(Qt::DisplayRole).toString();
//qDebug() << "Sort nm: " << val;
val = u8s2qs(allSortCrits[qs2utf8s(val)]);
if (val != "") {
qcrits += val;
//qDebug() << "Sort crit: " << val;
}
}
CSettingsStorage::getInstance()->setSortCrits(qcrits);
}