5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "radiodata.h"
22 #include "radiodataconversionstate.h"
23 #include "eeprominterface.h"
26 QString
RadioData::getElementName(const QString
& prefix
, unsigned int index
, const char * name
, bool padding
)
28 QString result
= prefix
;
30 result
+= QString("%1").arg(index
, 2, 10, QChar('0'));
32 result
+= QString("%1").arg(index
);
34 QString trimmed
= QString(name
).trimmed();
35 if (trimmed
.length() > 0) {
36 result
+= ":" + QString(name
).trimmed();
42 RadioData::RadioData()
44 models
.resize(getCurrentFirmware()->getCapability(Models
));
47 void RadioData::setCurrentModel(unsigned int index
)
49 generalSettings
.currModelIndex
= index
;
50 if (index
< models
.size()) {
51 strcpy(generalSettings
.currModelFilename
, models
[index
].filename
);
55 void RadioData::fixModelFilename(unsigned int index
)
57 ModelData
& model
= models
[index
];
58 QString
filename(model
.filename
);
59 bool ok
= filename
.endsWith(".bin");
61 if (filename
.startsWith("model") && filename
.mid(5, filename
.length()-9).toInt() > 0) {
66 for (unsigned i
=0; i
<index
; i
++) {
67 if (strcmp(models
[i
].filename
, model
.filename
) == 0) {
74 sprintf(model
.filename
, "model%d.bin", index
+1);
78 void RadioData::fixModelFilenames()
80 for (unsigned int i
=0; i
<models
.size(); i
++) {
83 setCurrentModel(generalSettings
.currModelIndex
);
86 QString
RadioData::getNextModelFilename()
88 char filename
[sizeof(ModelData::filename
)];
92 sprintf(filename
, "model%d.bin", ++index
);
94 for (unsigned int i
=0; i
<models
.size(); i
++) {
95 if (strcmp(filename
, models
[i
].filename
) == 0) {
104 void RadioData::convert(RadioDataConversionState
& cstate
)
106 generalSettings
.convert(cstate
.withModelIndex(-1));
108 for (unsigned i
=0; i
<models
.size(); i
++) {
109 models
[i
].convert(cstate
.withModelIndex(i
));
112 if (categories
.size() == 0) {
113 categories
.push_back(CategoryData(qPrintable(tr("Models"))));
114 for (unsigned i
=0; i
<models
.size(); i
++) {
115 models
[i
].category
= 0;
119 if (IS_HORUS(cstate
.toType
)) {
123 // ensure proper number of model slots
124 if (getCurrentFirmware()->getCapability(Models
) && getCurrentFirmware()->getCapability(Models
) != (int)models
.size()) {
125 models
.resize(getCurrentFirmware()->getCapability(Models
));