Mudlet  0
Mudclient
dlgNotepad.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008-2009 by Heiko Koehn - KoehnHeiko@googlemail.com *
3  * Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
4  * Copyright (C) 2017-2018 by Stephen Lyons - slysven@virginmedia.com *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
21 
22 
23 #include "dlgNotepad.h"
24 
25 #include "mudlet.h"
26 
27 #include "pre_guard.h"
28 #include <QDir>
29 #include "post_guard.h"
30 
32 : mpHost(pH)
33 {
34  setupUi(this);
35 
36  if (mpHost) {
37  restore();
38  }
39 }
40 
42 {
43  // Safety step, just in case:
44  if (mpHost && mpHost->mpNotePad) {
45  save();
46  mpHost->mpNotePad = nullptr;
47  }
48 }
49 
51 {
52  QString directoryFile = mudlet::getMudletPath(mudlet::profileHomePath, mpHost->getName());
53  QString fileName = mudlet::getMudletPath(mudlet::profileDataItemPath, mpHost->getName(), QStringLiteral("notes.txt"));
54  QDir dirFile;
55  if (!dirFile.exists(directoryFile)) {
56  dirFile.mkpath(directoryFile);
57  }
58  QFile file;
59  file.setFileName(fileName);
60  file.open(QIODevice::WriteOnly);
61  QTextStream fileStream;
62  fileStream.setDevice(&file);
63  fileStream << notesEdit->toPlainText();
64  file.close();
65 }
66 
68 {
69  QString fileName = mudlet::getMudletPath(mudlet::profileDataItemPath, mpHost->getName(), QStringLiteral("notes.txt"));
70  QFile file;
71  file.setFileName(fileName);
72  file.open(QIODevice::ReadOnly);
73  QTextStream fileStream;
74  fileStream.setDevice(&file);
75  QString txt = fileStream.readAll();
76  notesEdit->setPlainText(txt);
77  file.close();
78 }
void restore()
Definition: dlgNotepad.cpp:67
Definition: Host.h:62
dlgNotepad(Host *)
Definition: dlgNotepad.cpp:31
static QString getMudletPath(mudletPathType, const QString &extra1=QString(), const QString &extra2=QString())
Definition: mudlet.cpp:3829
void save()
Definition: dlgNotepad.cpp:50
QPointer< Host > mpHost
Definition: dlgNotepad.h:47