diff options
Diffstat (limited to 'framework/src/domain/documenthandler.cpp')
-rw-r--r-- | framework/src/domain/documenthandler.cpp | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/framework/src/domain/documenthandler.cpp b/framework/src/domain/documenthandler.cpp index 25a83592..1a323d9f 100644 --- a/framework/src/domain/documenthandler.cpp +++ b/framework/src/domain/documenthandler.cpp | |||
@@ -256,78 +256,6 @@ void DocumentHandler::setFontSize(int size) | |||
256 | emit fontSizeChanged(); | 256 | emit fontSizeChanged(); |
257 | } | 257 | } |
258 | 258 | ||
259 | QString DocumentHandler::fileName() const | ||
260 | { | ||
261 | const QString filePath = QQmlFile::urlToLocalFileOrQrc(m_fileUrl); | ||
262 | const QString fileName = QFileInfo(filePath).fileName(); | ||
263 | if (fileName.isEmpty()) | ||
264 | return QStringLiteral("untitled.txt"); | ||
265 | return fileName; | ||
266 | } | ||
267 | |||
268 | QString DocumentHandler::fileType() const | ||
269 | { | ||
270 | return QFileInfo(fileName()).suffix(); | ||
271 | } | ||
272 | |||
273 | QUrl DocumentHandler::fileUrl() const | ||
274 | { | ||
275 | return m_fileUrl; | ||
276 | } | ||
277 | |||
278 | void DocumentHandler::load(const QUrl &fileUrl) | ||
279 | { | ||
280 | if (fileUrl == m_fileUrl) | ||
281 | return; | ||
282 | |||
283 | QQmlEngine *engine = qmlEngine(this); | ||
284 | if (!engine) { | ||
285 | qWarning() << "load() called before DocumentHandler has QQmlEngine"; | ||
286 | return; | ||
287 | } | ||
288 | |||
289 | const QUrl path = QQmlFileSelector::get(engine)->selector()->select(fileUrl); | ||
290 | const QString fileName = QQmlFile::urlToLocalFileOrQrc(path); | ||
291 | if (QFile::exists(fileName)) { | ||
292 | QFile file(fileName); | ||
293 | if (file.open(QFile::ReadOnly)) { | ||
294 | QByteArray data = file.readAll(); | ||
295 | QTextCodec *codec = QTextCodec::codecForHtml(data); | ||
296 | if (QTextDocument *doc = textDocument()) | ||
297 | doc->setModified(false); | ||
298 | |||
299 | emit loaded(codec->toUnicode(data)); | ||
300 | reset(); | ||
301 | } | ||
302 | } | ||
303 | |||
304 | m_fileUrl = fileUrl; | ||
305 | emit fileUrlChanged(); | ||
306 | } | ||
307 | |||
308 | void DocumentHandler::saveAs(const QUrl &fileUrl) | ||
309 | { | ||
310 | QTextDocument *doc = textDocument(); | ||
311 | if (!doc) | ||
312 | return; | ||
313 | |||
314 | const QString filePath = fileUrl.toLocalFile(); | ||
315 | const bool isHtml = QFileInfo(filePath).suffix().contains(QLatin1String("htm")); | ||
316 | QFile file(filePath); | ||
317 | if (!file.open(QFile::WriteOnly | QFile::Truncate | (isHtml ? QFile::NotOpen : QFile::Text))) { | ||
318 | emit error(tr("Cannot save: ") + file.errorString()); | ||
319 | return; | ||
320 | } | ||
321 | file.write((isHtml ? doc->toHtml() : doc->toPlainText()).toUtf8()); | ||
322 | file.close(); | ||
323 | |||
324 | if (fileUrl == m_fileUrl) | ||
325 | return; | ||
326 | |||
327 | m_fileUrl = fileUrl; | ||
328 | emit fileUrlChanged(); | ||
329 | } | ||
330 | |||
331 | void DocumentHandler::reset() | 259 | void DocumentHandler::reset() |
332 | { | 260 | { |
333 | emit fontFamilyChanged(); | 261 | emit fontFamilyChanged(); |