Changeset View
Changeset View
Standalone View
Standalone View
src/backends/R/rexpression.cpp
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 95 | { | |||
---|---|---|---|---|---|
97 | QMimeDatabase db; | 97 | QMimeDatabase db; | ||
98 | 98 | | |||
99 | type=db.mimeTypeForUrl(QUrl(file)); | 99 | type=db.mimeTypeForUrl(QUrl(file)); | ||
100 | qDebug()<<"MimeType: "<<type.name(); | 100 | qDebug()<<"MimeType: "<<type.name(); | ||
101 | if(type.inherits(QLatin1String("application/postscript"))) | 101 | if(type.inherits(QLatin1String("application/postscript"))) | ||
102 | { | 102 | { | ||
103 | qDebug()<<"its PostScript"; | 103 | qDebug()<<"its PostScript"; | ||
104 | setResult(new Cantor::EpsResult(QUrl::fromLocalFile(file))); | 104 | setResult(new Cantor::EpsResult(QUrl::fromLocalFile(file))); | ||
105 | } else if(type.inherits(QLatin1String("text/plain"))) | 105 | } | ||
106 | else if(type.inherits(QLatin1String("text/plain")) | ||||
107 | || type.inherits(QLatin1String("application/x-extension-html"))) | ||||
106 | { | 108 | { | ||
107 | //Htmls are also plain texts, combining this in one | 109 | //Htmls are also plain texts, combining this in one | ||
108 | if(type.inherits(QLatin1String("text/html"))) | 110 | const bool isHtml = type.inherits(QLatin1String("text/html")) | ||
111 | || type.inherits(QLatin1String("application/x-extension-html")); | ||||
112 | if(isHtml) | ||||
109 | qDebug()<<"its a HTML document"; | 113 | qDebug()<<"its a HTML document"; | ||
110 | else | 114 | else | ||
111 | qDebug()<<"its plain text"; | 115 | qDebug()<<"its plain text"; | ||
112 | 116 | | |||
113 | QFile f(file); | 117 | QFile f(file); | ||
114 | if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) | 118 | if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) | ||
115 | { | 119 | { | ||
116 | setResult(new Cantor::TextResult(i18n("Error opening file %1", file))); | 120 | setResult(new Cantor::TextResult(i18n("Error opening file %1", file))); | ||
117 | setErrorMessage(i18n("Error opening file %1", file)); | 121 | setErrorMessage(i18n("Error opening file %1", file)); | ||
118 | setStatus(Cantor::Expression::Error); | 122 | setStatus(Cantor::Expression::Error); | ||
119 | } | 123 | } | ||
120 | QString content=QTextStream(&f).readAll(); | 124 | QString content=QTextStream(&f).readAll(); | ||
121 | if (!type.inherits(QLatin1String("text/html"))) | 125 | if (!isHtml) | ||
122 | { | 126 | { | ||
123 | //Escape whitespace | 127 | //Escape whitespace | ||
124 | content.replace( QLatin1Char(' '), QLatin1String(" ")); | 128 | content.replace( QLatin1Char(' '), QLatin1String(" ")); | ||
125 | //replace appearing backspaces, as they mess the whole output up | 129 | //replace appearing backspaces, as they mess the whole output up | ||
126 | content.remove(QRegExp(QLatin1String(".\b"))); | 130 | content.remove(QRegExp(QLatin1String(".\b"))); | ||
127 | //Replace < and > with their html code, so they won't be confused as html tags | 131 | //Replace < and > with their html code, so they won't be confused as html tags | ||
128 | content.replace( QLatin1Char('<') , QLatin1String("<")); | 132 | content.replace( QLatin1Char('<') , QLatin1String("<")); | ||
129 | content.replace( QLatin1Char('>') , QLatin1String(">")); | 133 | content.replace( QLatin1Char('>') , QLatin1String(">")); | ||
Show All 22 Lines |