• 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
  • io
  • insert
insertcontroller.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 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 "insertcontroller.h"
24 
25 // lib
26 #include "insertdialog.h"
27 // Kasten gui
28 #include <modelcodecviewmanager.h>
29 #include <selecteddatawriteable.h>
30 #include <abstractmodeldatageneratorconfigeditor.h>
31 // Kasten core
32 #include <modeldatageneratethread.h>
33 #include <modelcodecmanager.h>
34 #include <abstractmodeldatagenerator.h>
35 #include <abstractmodel.h>
36 // KDE
37 #include <KXMLGUIClient>
38 #include <KXMLGUIFactory>
39 #include <KActionCollection>
40 #include <KLocale>
41 #include <KSelectAction>
42 // Qt
43 #include <QtCore/QMimeData>
44 #include <QtGui/QApplication>
45 
46 
47 #ifndef ABSTRACTMODELDATAGENERATOR_METATYPE
48 #define ABSTRACTMODELDATAGENERATOR_METATYPE
49 Q_DECLARE_METATYPE(Kasten2::AbstractModelDataGenerator*)
50 #endif
51 
52 namespace Kasten2
53 {
54 
55 InsertController::InsertController( ModelCodecViewManager* modelCodecViewManager,
56  ModelCodecManager* modelCodecManager,
57  KXMLGUIClient* guiClient )
58  : AbstractXmlGuiController(),
59  mModelCodecViewManager( modelCodecViewManager ),
60  mModelCodecManager( modelCodecManager ),
61  mModel( 0 )
62 {
63  KActionCollection* actionCollection = guiClient->actionCollection();
64 
65  mInsertSelectAction = actionCollection->add<KSelectAction>( QLatin1String("insert") ); //TODO: find better id
66  mInsertSelectAction->setText( i18nc("@title:menu","Insert") );
67 // mInsertSelectAction->setIcon( KIcon("insert-text") );
68  mInsertSelectAction->setToolBarMode( KSelectAction::MenuMode );
69  connect( mInsertSelectAction, SIGNAL(triggered(QAction*)), SLOT(onActionTriggered(QAction*)) );
70 
71  setTargetModel( 0 );
72 }
73 
74 void InsertController::setTargetModel( AbstractModel* model )
75 {
76  if( mModel ) mModel->disconnect( this );
77 
78  mModel = model ? model->findBaseModelWithInterface<If::SelectedDataWriteable*>() : 0;
79  mSelectedDataWriteableControl = mModel ? qobject_cast<If::SelectedDataWriteable*>( mModel ) : 0;
80 
81  if( mSelectedDataWriteableControl )
82  {
83  // TODO: only fill the list on menu call...
84  connect( mModel, SIGNAL(readOnlyChanged(bool)), SLOT(onReadOnlyChanged(bool)) );
85  }
86 
87  updateActions();
88 }
89 
90 
91 void InsertController::updateActions()
92 {
93  mInsertSelectAction->removeAllActions();
94 
95  // TODO: pass model to find which mimetypes it can read
96  // mSelectedDataWriteableControl->canReadData( QMimeData() ) needs already data
97  // TODO: it this depend on the current selection/focus? So it needs to be updated on every change?
98  const QList<AbstractModelDataGenerator*> generatorList =
99  mModelCodecManager->generatorList();
100  const bool hasGenerators = ( generatorList.size() > 0 );
101 
102  if( hasGenerators )
103  {
104  foreach( AbstractModelDataGenerator* generator, generatorList )
105  {
106  const QString title = generator->typeName();
107  QAction* action = new QAction( title, mInsertSelectAction );
108 
109  action->setData( QVariant::fromValue(generator) );
110  mInsertSelectAction->addAction( action );
111  }
112  }
113  else
114  {
115  QAction* noneAction = new QAction( i18nc("@item There are no generators.","Not available."), mInsertSelectAction );
116  noneAction->setEnabled( false );
117  mInsertSelectAction->addAction( noneAction );
118  }
119 
120  // TODO: need a call AbstractModelSelection::isEmpty
121  const bool isWriteable = ( mSelectedDataWriteableControl && ! mModel->isReadOnly() );
122  mInsertSelectAction->setEnabled( isWriteable );
123 }
124 
125 void InsertController::onActionTriggered( QAction *action )
126 {
127  AbstractModelDataGenerator* generator = action->data().value<AbstractModelDataGenerator* >();
128 
129  AbstractModelDataGeneratorConfigEditor* configEditor =
130  mModelCodecViewManager->createConfigEditor( generator );
131 
132  if( configEditor )
133  {
134  InsertDialog* dialog = new InsertDialog( configEditor );
135 // dialog->setData( mModel, selection ); TODO
136  if( ! dialog->exec() )
137  return;
138  }
139 
140  QApplication::setOverrideCursor( Qt::WaitCursor );
141 
142  ModelDataGenerateThread* generateThread =
143  new ModelDataGenerateThread( this, generator );
144  generateThread->start();
145  while( !generateThread->wait(100) )
146  QApplication::processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 100 );
147 
148  QMimeData* mimeData = generateThread->data();
149 
150  delete generateThread;
151 
152  mSelectedDataWriteableControl->insertData( mimeData );
153 
154  QApplication::restoreOverrideCursor();
155 }
156 
157 
158 void InsertController::onReadOnlyChanged( bool isReadOnly )
159 {
160  const bool isWriteable = ( ! isReadOnly );
161 
162  mInsertSelectAction->setEnabled( isWriteable );
163 }
164 
165 }
abstractmodel.h
modeldatageneratethread.h
modelcodecmanager.h
Kasten2::AbstractModel::findBaseModelWithInterface
AbstractModel * findBaseModelWithInterface() const
returns the first baseModel which is of type T, or null if none is found.
Definition: abstractmodel.h:109
abstractmodeldatageneratorconfigeditor.h
Kasten2::If::SelectedDataWriteable::insertData
virtual void insertData(const QMimeData *data)=0
Kasten2::ModelCodecManager::generatorList
QList< AbstractModelDataGenerator * > generatorList() const
Definition: modelcodecmanager.cpp:61
abstractmodeldatagenerator.h
selecteddatawriteable.h
Kasten2::AbstractModelDataGenerator
Definition: abstractmodeldatagenerator.h:41
insertcontroller.h
insertdialog.h
Kasten2::If::SelectedDataWriteable
Definition: selecteddatawriteable.h:43
Kasten2::AbstractModelDataGenerator::typeName
QString typeName() const
Definition: abstractmodeldatagenerator.cpp:41
Kasten2::ModelCodecViewManager::createConfigEditor
AbstractModelStreamEncoderConfigEditor * createConfigEditor(AbstractModelStreamEncoder *encoder) const
Definition: modelcodecviewmanager.cpp:67
Kasten2::InsertController::InsertController
InsertController(ModelCodecViewManager *modelCodecViewManager, ModelCodecManager *modelCodecManager, KXMLGUIClient *guiClient)
Definition: insertcontroller.cpp:55
Kasten2::ModelCodecViewManager
Definition: modelcodecviewmanager.h:50
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::AbstractModel::isReadOnly
virtual bool isReadOnly() const
default returns true
Definition: abstractmodel.cpp:39
modelcodecviewmanager.h
Kasten2::InsertController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: insertcontroller.cpp:74
Kasten2::ModelCodecManager
Definition: modelcodecmanager.h:48
QList
Definition: bookmarkable.h:29
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: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