src/ldconfig.cc

changeset 609
a8dc74a809c6
parent 606
3dd6f343ec06
equal deleted inserted replaced
608:487db37f0bb3 609:a8dc74a809c6
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <QFile>
19 #include "document.h" 20 #include "document.h"
20 #include "ldconfig.h" 21 #include "ldconfig.h"
21 #include "gui.h" 22 #include "gui.h"
22 #include "misc.h" 23 #include "misc.h"
23 #include "colors.h" 24 #include "colors.h"
39 40
40 // ============================================================================= 41 // =============================================================================
41 // ----------------------------------------------------------------------------- 42 // -----------------------------------------------------------------------------
42 void parseLDConfig() 43 void parseLDConfig()
43 { 44 {
44 File* f = openLDrawFile ("LDConfig.ldr", false); 45 QFile* fp = openLDrawFile ("LDConfig.ldr", false);
45 46
46 if (!f) 47 if (!fp)
47 { 48 {
48 critical (fmt (QObject::tr ("Unable to open LDConfig.ldr for parsing: %1"), 49 critical (QObject::tr ("Unable to open LDConfig.ldr for parsing."));
49 strerror (errno)));
50 return; 50 return;
51 } 51 }
52 52
53 // Read in the lines 53 // Read in the lines
54 for (QString line : *f) 54 while (fp->atEnd() == false)
55 { 55 {
56 if (line.length() == 0 || line[0] != '0') 56 QString line = QString::fromUtf8 (fp->readLine());
57
58 if (line.isEmpty() || line[0] != '0')
57 continue; // empty or illogical 59 continue; // empty or illogical
58 60
59 line.remove ('\r'); 61 line.remove ('\r');
60 line.remove ('\n'); 62 line.remove ('\n');
61 63
109 col->faceColor.setAlpha (alpha); 111 col->faceColor.setAlpha (alpha);
110 col->index = code; 112 col->index = code;
111 setColor (code, col); 113 setColor (code, col);
112 } 114 }
113 115
114 delete f; 116 fp->close();
117 fp->deleteLater();
115 } 118 }
116 119
117 // ============================================================================= 120 // =============================================================================
118 // ----------------------------------------------------------------------------- 121 // -----------------------------------------------------------------------------
119 LDConfigParser::LDConfigParser (QString inText, char sep) 122 LDConfigParser::LDConfigParser (QString inText, char sep)

mercurial