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

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • libs
  • kasten
  • core
  • system
documentmanager.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Kasten Framework, made within the KDE community.
3 
4  Copyright 2006-2007,2009,2011 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "documentmanager.h"
24 
25 // lib
26 #include <abstractdocument.h>
27 // KDE
28 #include <KUrl>
29 // Qt
30 #include <QtCore/QMutableListIterator>
31 #include <QtCore/QStringList>
32 
33 // temporary
34 #include "documentcreatemanager.h"
35 #include "documentsyncmanager.h"
36 #include "modelcodecmanager.h"
37 
38 
39 namespace Kasten2
40 {
41 
42 static int lastDocumentId = 0;
43 
44 
45 DocumentManager::DocumentManager()
46  : mCreateManager( new DocumentCreateManager(this) ),
47  mSyncManager( new DocumentSyncManager(this) ),
48  mCodecManager( new ModelCodecManager(this) )
49 {
50 }
51 
52 QList<AbstractDocument*> DocumentManager::documents() const { return mList; }
53 bool DocumentManager::isEmpty() const { return mList.isEmpty(); }
54 
55 void DocumentManager::addDocument( AbstractDocument* document )
56 {
57  // TODO: check for double insert
58  document->setId( QString::number(++lastDocumentId) );
59  mList.append( document );
60  // TODO: only emit if document was not included before
61  QList<AbstractDocument*> addedDocuments;
62  addedDocuments.append( document );
63  emit added( addedDocuments );
64 }
65 
66 void DocumentManager::closeDocument( AbstractDocument* document )
67 {
68  QMutableListIterator<AbstractDocument*> iterator( mList );
69 
70  if( iterator.findNext(document) )
71  {
72  // TODO: first check if unsaved and ask, only then close
73 
74  iterator.remove();
75 
76  QList<AbstractDocument*> closedDocuments;
77  closedDocuments.append( document );
78  emit closing( closedDocuments );
79 
80  delete document;
81  }
82 }
83 
84 void DocumentManager::closeDocuments( const QList<AbstractDocument*>& documents )
85 {
86  // TODO: optimize
87  foreach( AbstractDocument* document, documents )
88  mList.removeOne( document );
89 
90  emit closing( documents );
91 
92  foreach( AbstractDocument* document, documents )
93  delete document;
94 }
95 
96 void DocumentManager::closeAll()
97 {
98  // TODO: is it better for remove the document from the list before emitting closing(document)?
99  // TODO: or better emit close(documentList)? who would use this?
100  QList<AbstractDocument*> closedDocuments = mList;
101  mList.clear();
102 
103  emit closing( closedDocuments );
104 
105  foreach( AbstractDocument* document, closedDocuments )
106  delete document;
107 }
108 
109 void DocumentManager::closeAllOther( AbstractDocument* keptDocument )
110 {
111  // TODO: is it better for remove the document from the list before emitting closing(document)?
112  // TODO: or better emit close(documentList)? who would use this?
113  QList<AbstractDocument*> closedDocuments = mList;
114  closedDocuments.removeOne( keptDocument );
115 
116  mList.clear();
117  mList.append( keptDocument );
118 
119  emit closing( closedDocuments );
120 
121  foreach( AbstractDocument* document, closedDocuments )
122  {
123  delete document;
124  }
125 }
126 
127 bool DocumentManager::canClose( AbstractDocument* document )
128 {
129  return mSyncManager->canClose( document );
130 }
131 
132 bool DocumentManager::canClose( const QList<AbstractDocument*>& documents )
133 {
134  bool canClose = true;
135 
136  foreach( AbstractDocument* document, documents )
137  {
138  if( ! mSyncManager->canClose(document) )
139  {
140  canClose = false;
141  break;
142  }
143  }
144 
145  return canClose;
146 }
147 
148 bool DocumentManager::canCloseAll()
149 {
150  bool canCloseAll = true;
151 
152  foreach( AbstractDocument* document, mList )
153  {
154  if( !mSyncManager->canClose(document) )
155  {
156  canCloseAll = false;
157  break;
158  }
159  }
160 
161  return canCloseAll;
162 }
163 
164 bool DocumentManager::canCloseAllOther( AbstractDocument* keptDocument )
165 {
166  bool canCloseAll = true;
167 
168  foreach( AbstractDocument* document, mList )
169  {
170  if( ( document != keptDocument ) &&
171  ! mSyncManager->canClose(document) )
172  {
173  canCloseAll = false;
174  break;
175  }
176  }
177 
178  return canCloseAll;
179 }
180 
181 void DocumentManager::requestFocus( AbstractDocument* document )
182 {
183  emit focusRequested( document );
184 }
185 
186 DocumentManager::~DocumentManager()
187 {
188  // TODO: emit signal here, too?
189  qDeleteAll( mList );
190 
191  delete mCreateManager;
192  delete mSyncManager;
193  delete mCodecManager;
194 } //TODO: destroy all documents?
195 
196 }
abstractdocument.h
documentsyncmanager.h
modelcodecmanager.h
Kasten2::DocumentManager::addDocument
void addDocument(AbstractDocument *document)
Definition: documentmanager.cpp:55
documentmanager.h
Kasten2::DocumentManager::canClose
bool canClose(AbstractDocument *document)
Definition: documentmanager.cpp:127
Kasten2::lastDocumentId
static int lastDocumentId
Definition: documentmanager.cpp:42
Kasten2::DocumentManager::documents
QList< AbstractDocument * > documents() const
Definition: documentmanager.cpp:52
Kasten2::DocumentManager::closeAll
void closeAll()
Definition: documentmanager.cpp:96
Kasten2::AbstractDocument::setId
void setId(const QString &id)
Definition: abstractdocument.cpp:47
Kasten2::DocumentManager::canCloseAll
bool canCloseAll()
Definition: documentmanager.cpp:148
Kasten2::DocumentManager::canCloseAllOther
bool canCloseAllOther(AbstractDocument *document)
Definition: documentmanager.cpp:164
Kasten2::DocumentManager::closeAllOther
void closeAllOther(AbstractDocument *document)
Definition: documentmanager.cpp:109
Kasten2::DocumentManager::isEmpty
bool isEmpty() const
Definition: documentmanager.cpp:53
Kasten2::DocumentManager::focusRequested
void focusRequested(Kasten2::AbstractDocument *document)
Kasten2::DocumentManager::closeDocuments
void closeDocuments(const QList< AbstractDocument * > &documents)
Definition: documentmanager.cpp:84
Kasten2::DocumentCreateManager
Definition: documentcreatemanager.h:41
Kasten2::DocumentManager::closing
void closing(const QList< Kasten2::AbstractDocument * > &documents)
documents are about to be closed, cannot be stopped
Kasten2::DocumentManager::added
void added(const QList< Kasten2::AbstractDocument * > &documents)
Kasten2::DocumentManager::requestFocus
void requestFocus(AbstractDocument *document)
Definition: documentmanager.cpp:181
Kasten2::AbstractDocument
Definition: abstractdocument.h:43
documentcreatemanager.h
Kasten2::DocumentManager::DocumentManager
DocumentManager()
Definition: documentmanager.cpp:45
Kasten2::DocumentManager::closeDocument
void closeDocument(AbstractDocument *document)
Definition: documentmanager.cpp:66
Kasten2::DocumentManager::~DocumentManager
virtual ~DocumentManager()
Definition: documentmanager.cpp:186
Kasten2::DocumentSyncManager::canClose
bool canClose(AbstractDocument *document)
Definition: documentsyncmanager.cpp:221
Kasten2::DocumentSyncManager
Definition: documentsyncmanager.h:45
Kasten2::ModelCodecManager
Definition: modelcodecmanager.h:48
QList
Definition: bookmarkable.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

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