1 /*
2  *  SPDX-FileCopyrightText: 2012-2014 Andreas Cord-Landwehr <cordlandwehr@kde.org>
3  *
4  *  SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5  */
6 
7 #include "journalwidget.h"
8 #include "project/project.h"
9 #include <QSaveFile>
10 #include <QDebug>
11 #include <QTextStream>
12 #include <QFile>
13 #include <QUrl>
14 #include <KTextEditor/Document>
15 
JournalEditorWidget(QWidget * parent)16 JournalEditorWidget::JournalEditorWidget(QWidget* parent)
17     : QWidget(parent)
18     , m_currentProject(nullptr)
19     , m_modified(false)
20 {
21     ui = new Ui::JournalEditorWidget;
22     ui->setupUi(this);
23 
24     connect(ui->editor, &KRichTextWidget::textChanged,
25         this, &JournalEditorWidget::setModified);
26 }
27 
openJournal(Project * project)28 void JournalEditorWidget::openJournal(Project *project)
29 {
30     m_currentProject = project;
31     if (!project) {
32         qCritical() << "No project specified! Cannot set journal widget.";
33         return;
34     }
35     if (!project->journalDocument()) {
36         qDebug() << "Skipping loading of journal file, project does not contain any, yet.";
37         ui->editor->setHtml(QString());
38     } else {
39         ui->editor->setHtml(project->journalDocument()->text());
40     }
41     // explicitly set journal to be unmodified, since setting of text to editor caused modifed
42     // value to be true
43     m_modified = false;
44 }
45 
setModified()46 void JournalEditorWidget::setModified()
47 {
48     m_modified = true;
49 }
50 
isModified() const51 bool JournalEditorWidget::isModified() const
52 {
53     return m_modified;
54 }
55