bool loadTPL(Translator &translator, QIODevice &dev, ConversionData &cd) { // Hack: Check if the template is utf8 QTextStream testStream; testStream.setDevice( &dev ); QString testContent = testStream.readAll(); if ( ( testContent.startsWith( QLatin1String("{*?template charset="), Qt::CaseInsensitive ) && ( testContent.startsWith( QLatin1String("{*?template charset=utf8?*}"), Qt::CaseInsensitive ) || testContent.startsWith( QLatin1String("{*?template charset=utf-8?*}"), Qt::CaseInsensitive ) ) ) || cd.m_assumeUtf8 ) { stream.setCodec( QTextCodec::codecForName("UTF-8") ); stream.setAutoDetectUnicode( true ); } else { stream.setCodec( QTextCodec::codecForLocale() ); stream.setAutoDetectUnicode( false ); } stream.setDevice( &dev ); stream.seek( 0 ); // we need to rewind it because the testStream has read all data on the QIODevice parse( &translator, cd.m_sourceDir.path() + QDir::separator() + cd.m_sourceFileName ); return true; }
ModList::OrderList ModList::readListFile() { OrderList itemList; if (m_list_file.isNull() || m_list_file.isEmpty()) return itemList; QFile textFile(m_list_file); if (!textFile.open(QIODevice::ReadOnly | QIODevice::Text)) return OrderList(); QTextStream textStream; textStream.setAutoDetectUnicode(true); textStream.setDevice(&textFile); while (true) { QString line = textStream.readLine(); if (line.isNull() || line.isEmpty()) break; else { OrderItem it; it.enabled = !line.endsWith(".disabled"); if (!it.enabled) { line.chop(9); } it.id = line; itemList.append(it); } } textFile.close(); return itemList; }
void HttpServer :: replyGet(QTcpSocket *socket, QString const &req) { QTextStream os (socket); os.setAutoDetectUnicode (true); QDir const dir (d->path.path() + req); auto contentFile = dir.canonicalPath(); QFileInfo const info(contentFile); if (!info.exists() || !info.isFile() || !info.isReadable()) { os << "HTTP/1.0 404 Not Found\r\n" "\r\n"; } else { auto size = QString::number(info.size()); auto lastModified = info.lastModified().toString(); auto suffix = info.suffix(); QFile file(contentFile); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { os << "HTTP/1.0 404 Not Found\r\n" "\r\n"; } os << "HTTP/1.1 200 Ok\r\n" "Date: " << QDate::currentDate().toString() << "\r\n" "Last-Modified: " << lastModified << "\r\n" "Content-Type: text/html; charset=\"UTF-8\"\r\n" "Content-Length: " << size << "\r\n" "\r\n"; QTextStream in(&file); while (!in.atEnd()) { os << in.readLine() << "\n"; } } socket->close(); if (socket->state() == QTcpSocket::UnconnectedState) { delete socket; } }
QString BtBookmarkLoader::loadXmlFromFile(QString fileName) { if (fileName.isNull()) { fileName = util::filesystem::DirectoryUtil::getUserBaseDir().absolutePath() + "/bookmarks.xml"; } QFile file(fileName); if (!file.exists()) return QString(); QString xml; if (file.open(QIODevice::ReadOnly)) { QTextStream t; t.setAutoDetectUnicode(false); t.setCodec(QTextCodec::codecForName("UTF-8")); t.setDevice(&file); xml = t.readAll(); file.close(); } return xml; }