Changeset View
Changeset View
Standalone View
Standalone View
kwrite/kwriteapplication.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> | ||||
3 | Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> | ||||
4 | Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> | ||||
5 | | ||||
6 | This library is free software; you can redistribute it and/or | ||||
7 | modify it under the terms of the GNU Library General Public | ||||
8 | License version 2 as published by the Free Software Foundation. | ||||
9 | | ||||
10 | This library 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 GNU | ||||
13 | Library General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU Library General Public License | ||||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "kwriteapplication.h" | ||||
22 | #include "kwrite.h" | ||||
23 | | ||||
24 | #include <QApplication> | ||||
25 | #include <KConfigGui> | ||||
26 | | ||||
27 | KWriteApplication::KWriteApplication::KWriteApplication() | ||||
28 | { | ||||
29 | m_application = new KTextEditor::Application(this); | ||||
30 | KTextEditor::Editor::instance()->setApplication(m_application); | ||||
31 | } | ||||
32 | | ||||
33 | KWriteApplication::~KWriteApplication() | ||||
34 | { | ||||
35 | delete m_application; | ||||
36 | } | ||||
37 | | ||||
38 | KWrite * KWriteApplication::newWindow(KTextEditor::Document* doc) | ||||
39 | { | ||||
40 | KWrite *k = new KWrite(doc, this); | ||||
41 | m_windows.append(k); | ||||
42 | return k; | ||||
43 | } | ||||
44 | | ||||
45 | void KWriteApplication::restore() | ||||
46 | { | ||||
47 | KConfig *config = KConfigGui::sessionConfig(); | ||||
48 | | ||||
49 | if (!config) { | ||||
50 | return; | ||||
51 | } | ||||
52 | | ||||
53 | int docs, windows; | ||||
54 | QString buf; | ||||
55 | KTextEditor::Document *doc; | ||||
56 | KWrite *t; | ||||
57 | | ||||
58 | KConfigGroup numberConfig(config, "Number"); | ||||
59 | docs = numberConfig.readEntry("NumberOfDocuments", 0); | ||||
60 | windows = numberConfig.readEntry("NumberOfWindows", 0); | ||||
61 | | ||||
62 | for (int z = 1; z <= docs; z++) { | ||||
63 | buf = QStringLiteral("Document %1").arg(z); | ||||
64 | KConfigGroup cg(config, buf); | ||||
65 | doc = KTextEditor::Editor::instance()->createDocument(nullptr); | ||||
66 | doc->readSessionConfig(cg); | ||||
67 | addDocument(doc); | ||||
68 | } | ||||
69 | | ||||
70 | for (int z = 1; z <= windows; z++) { | ||||
71 | buf = QStringLiteral("Window %1").arg(z); | ||||
72 | KConfigGroup cg(config, buf); | ||||
73 | t = newWindow(m_documents.at(cg.readEntry("DocumentNumber", 0) - 1)); | ||||
74 | t->restore(config, z); | ||||
75 | } | ||||
76 | } | ||||
77 | | ||||
78 | bool KWriteApplication::quit() | ||||
79 | { | ||||
80 | QList<KWrite *>::iterator i; | ||||
meven: Unused I believe. | |||||
81 | foreach(KWrite *w, m_windows) { | ||||
Avoid foreach, you can use for future proofing : for (KWrite *w: qAsConst(m_windows)) { Reference: meven: Avoid foreach, you can use for future proofing :
```
for (KWrite *w: qAsConst(m_windows)) {… | |||||
82 | if (!w->close()) { | ||||
83 | return false; | ||||
84 | } | ||||
85 | m_windows.removeAll(w); | ||||
anthonyfieroni: don't removed in same loop, just call clear afterwards. | |||||
86 | delete w; | ||||
87 | } | ||||
88 | QApplication::quit(); | ||||
89 | return true; | ||||
90 | } |
Unused I believe.