• 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
  • controllers
  • documentsystem
  • close
documentsystem/close/closecontroller.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-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 "closecontroller.h"
24 
25 // Kasten core
26 #include <abstractdocumentstrategy.h>
27 #include <abstractdocument.h>
28 // KDE
29 #include <KActionCollection>
30 #include <KAction>
31 #include <KStandardAction>
32 #include <KXMLGUIClient>
33 #include <KLocale>
34 #include <KIcon>
35 
36 
37 namespace Kasten2
38 {
39 
40 CloseController::CloseController( AbstractDocumentStrategy* documentStrategy,
41  KXMLGUIClient* guiClient,
42  bool supportMultiple )
43  : AbstractXmlGuiController()
44  , mDocumentStrategy( documentStrategy )
45  , mDocument( 0 )
46 {
47  KActionCollection* actionCollection = guiClient->actionCollection();
48 
49  mCloseAction = KStandardAction::close( this, SLOT(close()), actionCollection );
50  mCloseAction->setEnabled( false );
51 
52  if( supportMultiple )
53  {
54  mCloseAllAction = actionCollection->addAction( QLatin1String("file_close_all"),
55  this, SLOT(closeAll()) );
56  mCloseAllAction->setText( i18nc("@title:menu","Close All") );
57  mCloseAllAction->setIcon( KIcon( QLatin1String("window-close") ) );
58  mCloseAllAction->setEnabled( false );
59 
60  mCloseAllOtherAction = actionCollection->addAction( QLatin1String("file_close_all_other"),
61  this, SLOT(closeAllOther()) );
62  mCloseAllOtherAction->setText( i18nc("@title:menu","Close All Other") );
63  mCloseAllOtherAction->setIcon( KIcon( QLatin1String("window-close") ) );
64  mCloseAllOtherAction->setEnabled( false );
65 
66  connect( mDocumentStrategy, SIGNAL(added(QList<Kasten2::AbstractDocument*>)),
67  SLOT(onDocumentsChanged()) );
68  connect( mDocumentStrategy, SIGNAL(closing(QList<Kasten2::AbstractDocument*>)),
69  SLOT(onDocumentsChanged()) );
70  }
71 }
72 
73 void CloseController::setTargetModel( AbstractModel* model )
74 {
75  mDocument = model ? model->findBaseModel<AbstractDocument*>() : 0;
76  const bool hasDocument = ( mDocument != 0 );
77 
78  mCloseAction->setEnabled( hasDocument );
79 }
80 
81 
82 void CloseController::close()
83 {
84  if( mDocumentStrategy->canClose(mDocument) )
85  mDocumentStrategy->closeDocument( mDocument );
86 }
87 
88 void CloseController::closeAll()
89 {
90  if( mDocumentStrategy->canCloseAll() )
91  mDocumentStrategy->closeAll();
92 }
93 
94 void CloseController::closeAllOther()
95 {
96  if( mDocumentStrategy->canCloseAllOther(mDocument) )
97  mDocumentStrategy->closeAllOther( mDocument );
98 }
99 
100 void CloseController::onDocumentsChanged()
101 {
102  const QList<AbstractDocument*> documents = mDocumentStrategy->documents();
103 
104  const bool hasDocuments = ! documents.isEmpty();
105  // TODO: there could be just one, but not set for this tool?
106  const bool hasOtherDocuments = ( documents.size() > 1 );
107 
108  mCloseAllAction->setEnabled( hasDocuments );
109  mCloseAllOtherAction->setEnabled( hasOtherDocuments );
110 }
111 
112 CloseController::~CloseController()
113 {
114 }
115 
116 }
Kasten2::AbstractDocumentStrategy::closeDocument
virtual void closeDocument(AbstractDocument *document)=0
Kasten2::AbstractDocumentStrategy::canClose
virtual bool canClose(AbstractDocument *document) const =0
abstractdocument.h
Kasten2::AbstractDocumentStrategy::closeAll
virtual void closeAll()=0
Kasten2::CloseController::~CloseController
virtual ~CloseController()
Definition: documentsystem/close/closecontroller.cpp:112
abstractdocumentstrategy.h
Kasten2::AbstractDocumentStrategy
Definition: abstractdocumentstrategy.h:42
Kasten2::AbstractDocumentStrategy::canCloseAllOther
virtual bool canCloseAllOther(AbstractDocument *document) const =0
Kasten2::AbstractDocumentStrategy::canCloseAll
virtual bool canCloseAll() const =0
Kasten2::AbstractDocumentStrategy::closeAllOther
virtual void closeAllOther(AbstractDocument *document)=0
closecontroller.h
Kasten2::AbstractModel::findBaseModel
T findBaseModel() const
returns the first baseModel which is of type T, or null if none is found.
Definition: abstractmodel.h:93
Kasten2::AbstractDocumentStrategy::documents
virtual QList< AbstractDocument * > documents() const =0
Returns true if there.
Kasten2::AbstractDocument
Definition: abstractdocument.h:43
Kasten2::CloseController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: documentsystem/close/closecontroller.cpp:73
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::CloseController::CloseController
CloseController(AbstractDocumentStrategy *documentStrategy, KXMLGUIClient *guiClient, bool supportMultiple=true)
Definition: documentsystem/close/closecontroller.cpp:40
QList< Kasten2::AbstractDocument * >
Kasten2::AbstractXmlGuiController
Definition: abstractxmlguicontroller.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 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