• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/App

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • App
  • Ui
JournalEditorWidget.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #include "JournalEditorWidget.h"
21 #include <Project.h>
22 #include "ui_JournalEditorWidget.h"
23 
24 #include <KUrl>
25 #include <KSaveFile>
26 #include <KDebug>
27 
28 #include <QTextStream>
29 #include <QFile>
30 
31 
32 JournalEditorWidget::JournalEditorWidget(QWidget* parent)
33  : QWidget(parent)
34  , _currentProject(0)
35 {
36  ui = new Ui::JournalEditorWidget;
37  ui->setupUi(this);
38 
39  connect(ui->editor, SIGNAL(textChanged()), this, SLOT(setModified()));
40 }
41 
42 void JournalEditorWidget::openJournal(Project *project)
43 {
44  _currentProject = project;
45  if (!project) {
46  kError() << "No project specified! Cannot set journal widget.";
47  return;
48  }
49  if (project->journalFile().isEmpty()) {
50  kDebug() << "Skipping loading of journal file, project does not contain any, yet.";
51  ui->editor->setHtml(QString());
52  } else {
53  QFile fileHandle(project->journalFile().toLocalFile());
54  if (!fileHandle.open(QIODevice::ReadOnly | QIODevice::Text)) {
55  kError() << "Could not open file"
56  << project->journalFile().toLocalFile()
57  << " in read mode: "
58  << fileHandle.errorString();
59  return;
60  }
61  QTextStream stream(&fileHandle);
62  stream.setCodec("UTF-8");
63  ui->editor->setHtml(stream.readAll());
64  }
65  // explicitly set journal to be unmodified, since setting of text to editor caused modifed
66  // value to be true
67  _modified = false;
68 }
69 
70 void JournalEditorWidget::saveJournal()
71 {
72  Q_ASSERT(_currentProject);
73  if (!_currentProject) {
74  kError() << "Associated project is not set: cannot save journal file and hence aborting saving.";
75  kDebug() << "Journal must be created with JournalEditorWidget::openJournal(...).";
76  return;
77  }
78 
79  KSaveFile saveFile(_currentProject->journalFile().toLocalFile());
80  saveFile.open();
81 
82  QTextStream stream(&saveFile);
83  stream.setCodec("UTF-8");
84  stream << ui->editor->toHtml();
85  stream.flush();
86  if (!saveFile.finalize()) {
87  kError() << "Error while writing journal file, aborting write. Journal file was not changed.";
88  }
89  _modified = false;
90 }
91 
92 void JournalEditorWidget::setModified()
93 {
94  _modified = true;
95 }
96 
97 bool JournalEditorWidget::isModified() const
98 {
99  return _modified;
100 }
QTextStream::setCodec
void setCodec(QTextCodec *codec)
QWidget
QIODevice::errorString
QString errorString() const
JournalEditorWidget.h
JournalEditorWidget::JournalEditorWidget
JournalEditorWidget(QWidget *parent)
Default constructor.
Definition: JournalEditorWidget.cpp:32
QFile
QTextStream
JournalEditorWidget::saveJournal
void saveJournal()
Writes current journal content to file as specified by its project.
Definition: JournalEditorWidget.cpp:70
QString
JournalEditorWidget::openJournal
void openJournal(Project *project)
Loads journal from specified project project.
Definition: JournalEditorWidget.cpp:42
JournalEditorWidget::isModified
bool isModified() const
Definition: JournalEditorWidget.cpp:97
QTextStream::flush
void flush()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QTextStream::readAll
QString readAll()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/App

Skip menu "rocs/App"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal