]> Shamusworld >> Repos - architektonas/blobdiff - src/base/rs_fileio.cpp
Fixed thumbnail rendering in LibraryWidget and DXF detection.
[architektonas] / src / base / rs_fileio.cpp
index 8e59307019c80e92b37e1b658faeb4a47878d425..dc29997524d716cf30ba82a81cc1fbca75d60f66 100644 (file)
@@ -12,6 +12,7 @@
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  05/28/2010  Added this text. :-)
+// JLH  09/07/2010  Fixed file detection algorithm.
 //
 
 #include "rs_fileio.h"
@@ -33,7 +34,7 @@ RS_FileIO::RS_FileIO()
  */
 /*static*/ RS_FileIO * RS_FileIO::instance()
 {
-       if (uniqueInstance == NULL)
+       if (!uniqueInstance)
                uniqueInstance = new RS_FileIO();
 
        return uniqueInstance;
@@ -60,7 +61,6 @@ QList<RS_FilterInterface *> RS_FileIO::getFilterList()
  */
 RS_FilterInterface * RS_FileIO::getImportFilter(RS2::FormatType t)
 {
-//     for(RS_FilterInterface * f=filterList.first(); f!=NULL; f=filterList.next())
        for(int i=0; i<filterList.size(); i++)
        {
                RS_FilterInterface * f = filterList[i];
@@ -77,7 +77,6 @@ RS_FilterInterface * RS_FileIO::getImportFilter(RS2::FormatType t)
  */
 RS_FilterInterface * RS_FileIO::getExportFilter(RS2::FormatType t)
 {
-//     for(RS_FilterInterface * f=filterList.first(); f!=NULL; f=filterList.next())
        for(int i=0; i<filterList.size(); i++)
        {
                RS_FilterInterface * f = filterList[i];
@@ -100,43 +99,18 @@ RS_FilterInterface * RS_FileIO::getExportFilter(RS2::FormatType t)
  */
 bool RS_FileIO::fileImport(Drawing & graphic, const QString & file, RS2::FormatType type)
 {
-       RS_DEBUG->print("Trying to import file '%s'...", file.toLatin1().data());
+       RS_DEBUG->print("Trying to import file '%s'...", file.toAscii().data());
 
        RS_FilterInterface * filter = NULL;
-       RS2::FormatType t;
-
-       if (type == RS2::FormatUnknown)
-               t = detectFormat(file);
-       else
-               t = type;
-
+       RS2::FormatType t = (type == RS2::FormatUnknown ? detectFormat(file) : type);
        filter = getImportFilter(t);
 
-       /*
-       switch (t) {
-       case RS2::FormatCXF:
-        filter = new RS_FilterCXF(graphic);
-               break;
-
-       case RS2::FormatDXF1:
-        filter = new RS_FilterDXF1(graphic);
-               break;
-
-       case RS2::FormatDXF:
-        filter = new RS_FilterDXF(graphic);
-               break;
-
-       default:
-               break;
-    }
-       */
-
     if (filter)
         return filter->fileImport(graphic, file, t);
        else
        {
                RS_DEBUG->print(RS_Debug::D_WARNING, "RS_FileIO::fileImport: failed to import file: %s",
-                       file.toLatin1().data());
+                       file.toAscii().data());
        }
 
        return false;
@@ -151,13 +125,10 @@ bool RS_FileIO::fileImport(Drawing & graphic, const QString & file, RS2::FormatT
 bool RS_FileIO::fileExport(Drawing & graphic, const QString & file, RS2::FormatType type)
 {
        RS_DEBUG->print("RS_FileIO::fileExport");
-       //RS_DEBUG->print("Trying to export file '%s'...", file.latin1());
 
        if (type == RS2::FormatUnknown)
        {
-               QString extension;
-//             extension = QFileInfo(file).extension(false).toLower();
-               extension = QFileInfo(file).suffix().toLower();
+               QString extension = QFileInfo(file).suffix().toLower();
 
                if (extension == "dxf")
                        type = RS2::FormatDXF;
@@ -167,7 +138,7 @@ bool RS_FileIO::fileExport(Drawing & graphic, const QString & file, RS2::FormatT
 
        RS_FilterInterface * filter = getExportFilter(type);
 
-       if (filter != NULL)
+       if (filter)
                return filter->fileExport(graphic, file, type);
 
        RS_DEBUG->print("RS_FileIO::fileExport: no filter found");
@@ -181,10 +152,8 @@ bool RS_FileIO::fileExport(Drawing & graphic, const QString & file, RS2::FormatT
 RS2::FormatType RS_FileIO::detectFormat(const QString & file)
 {
        RS2::FormatType type = RS2::FormatUnknown;
-       QFileInfo f(file);
-
-//     QString ext = f.extension(false).toLower();
-       QString ext = f.suffix().toLower();
+       QFileInfo info(file);
+       QString ext = info.suffix().toLower();
 
        if (ext == "cxf")
        {
@@ -199,21 +168,23 @@ RS2::FormatType RS_FileIO::detectFormat(const QString & file)
                {
                        // Error opening file:
                        RS_DEBUG->print(RS_Debug::D_WARNING,
-                               "RS_FileIO::detectFormat: Cannot open file: %s", file.toLatin1().data());
+                               "RS_FileIO::detectFormat: Cannot open file: %s", file.toAscii().data());
                        type = RS2::FormatUnknown;
                }
                else
                {
                        RS_DEBUG->print("RS_FileIO::detectFormat: Successfully opened DXF file: %s",
-                               file.toLatin1().data());
+                               file.toAscii().data());
 
                        QTextStream ts(&f);
-                       QString line;
                        int c = 0;
 
-                       while (!f.atEnd() && ++c < 100)
+//I think this is wrong... We're mixing classes here...
+//AND THAT WAS THE PROBLEM!!!
+//                     while (!f.atEnd() && ++c < 100)
+                       while (!ts.atEnd() && ++c < 100)
                        {
-                               line = ts.readLine();
+                               QString line = ts.readLine();
 
                                if (line == "$ACADVER")
                                        type = RS2::FormatDXF;