• 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
modelcodecmanager.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 2007-2009 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 "modelcodecmanager.h"
24 
25 // lib
26 #include "modelencoderfilesystemexporter.h"
27 #include "abstractmodelstreamencoder.h"
28 // #include "abstractmodelstreamdecoder.h"
29 #include "abstractmodeldatagenerator.h"
30 #include "abstractoverwritedialog.h"
31 #include "jobmanager.h"
32 #include "documentmanager.h"
33 #include "abstractexportjob.h"
34 // KDE
35 #include <KIO/NetAccess>
36 #include <KFileDialog>
37 #include <KPushButton>
38 #include <KLocale>
39 
40 
41 namespace Kasten2
42 {
43 
44 ModelCodecManager::ModelCodecManager( DocumentManager* manager )
45  : mManager( manager ),
46  mOverwriteDialog( 0 )
47 {
48 }
49 
50 QList<AbstractModelStreamEncoder*>
51 ModelCodecManager::encoderList( AbstractModel* model, const AbstractModelSelection* selection ) const
52 {
53 Q_UNUSED( selection )
54  return model ? mEncoderList : QList<AbstractModelStreamEncoder*>();
55 }
56 
57 QList<AbstractModelStreamDecoder*>
58 ModelCodecManager::decoderList() const { return mDecoderList; }
59 
60 QList<AbstractModelDataGenerator*>
61 ModelCodecManager::generatorList() const { return mGeneratorList; }
62 
63 QList<AbstractModelExporter*>
64 ModelCodecManager::exporterList( AbstractModel* model, const AbstractModelSelection* selection ) const
65 {
66 Q_UNUSED( selection )
67  return model ? mExporterList : QList<AbstractModelExporter*>();
68 }
69 
70 void ModelCodecManager::setOverwriteDialog( AbstractOverwriteDialog* overwriteDialog )
71 {
72  mOverwriteDialog = overwriteDialog;
73 }
74 
75 void ModelCodecManager::setEncoders( const QList<AbstractModelStreamEncoder*>& encoderList )
76 {
77  mEncoderList = encoderList;
78 
79  qDeleteAll( mExporterList );
80  mExporterList.clear();
81 
82  foreach( AbstractModelStreamEncoder* encoder, mEncoderList )
83  mExporterList << new ModelEncoderFileSystemExporter( encoder );
84 }
85 
86 void ModelCodecManager::setDecoders( const QList<AbstractModelStreamDecoder*>& decoderList )
87 {
88  mDecoderList = decoderList;
89 }
90 
91 void ModelCodecManager::setGenerators( const QList<AbstractModelDataGenerator*>& generatorList )
92 {
93  mGeneratorList = generatorList;
94 }
95 
96 void ModelCodecManager::encodeToStream( AbstractModelStreamEncoder* encoder,
97  AbstractModel* model, const AbstractModelSelection* selection )
98 {
99  Q_UNUSED( selection )
100  Q_UNUSED( model )
101  Q_UNUSED( encoder )
102 // AbstractDocument* model = mFactory->create();
103 // mManager->addDocument( model );
104 }
105 
106 
107 void ModelCodecManager::exportDocument( AbstractModelExporter* exporter,
108  AbstractModel* model, const AbstractModelSelection* selection )
109 {
110  bool exportDone = false;
111 
112  const QString dialogTitle =
113  i18nc( "@title:window", "Export" );
114  do
115  {
116  KFileDialog exportFileDialog( /*mWorkingUrl.url()*/KUrl(), QString(), /*mWidget*/0 );
117 
118  exportFileDialog.setOperationMode( KFileDialog::Saving );
119  exportFileDialog.setMode( KFile::File );
120  const QStringList mimeTypes = QStringList() << exporter->remoteMimeType();
121  exportFileDialog.setMimeFilter( mimeTypes );
122  exportFileDialog.setCaption( dialogTitle );
123  const KGuiItem exportGuiItem( i18nc("@action:button",
124  "&Export"),
125  QLatin1String("document-export"),
126  i18nc("@info:tooltip",
127  "Export the data into the file with the entered name.") );
128  exportFileDialog.okButton()->setGuiItem( exportGuiItem );
129 
130  exportFileDialog.exec();
131 
132  const KUrl exportUrl = exportFileDialog.selectedUrl();
133 
134  if( !exportUrl.isEmpty() )
135  {
136  const bool isUrlInUse = KIO::NetAccess::exists( exportUrl, KIO::NetAccess::DestinationSide, /*mWidget*/0 );
137 
138  if( isUrlInUse )
139  {
140  // TODO: care for case that file from url is already loaded by (only?) this program
141 // const bool otherFileLoaded = mManager->documentByUrl( exportUrl );
142  // TODO: replace "file" with synchronizer->storageTypeName() or such
143  // TODO: offer "Synchronize" as alternative, if supported, see below
144  const Answer answer =
145  mOverwriteDialog ? mOverwriteDialog->queryOverwrite( exportUrl, dialogTitle ) : Cancel;
146  if( answer == Cancel )
147  break;
148  if( answer == PreviousQuestion )
149  continue;
150  }
151 
152  AbstractExportJob* exportJob = exporter->startExport( model, selection, exportUrl );
153  exportDone = JobManager::executeJob( exportJob );
154 
155 // if( exportDone )
156 // emit urlUsed( exportUrl );
157  }
158  else
159  break;
160  }
161  while( !exportDone );
162 }
163 
164 ModelCodecManager::~ModelCodecManager()
165 {
166  qDeleteAll( mExporterList );
167  qDeleteAll( mEncoderList );
168 // qDeleteAll( mDecoderList );
169  qDeleteAll( mGeneratorList );
170 }
171 
172 }
Kasten2::ModelCodecManager::setDecoders
void setDecoders(const QList< AbstractModelStreamDecoder * > &decoderList)
Definition: modelcodecmanager.cpp:86
modelcodecmanager.h
documentmanager.h
Kasten2::ModelCodecManager::exporterList
QList< AbstractModelExporter * > exporterList(AbstractModel *model, const AbstractModelSelection *selection) const
Definition: modelcodecmanager.cpp:64
Kasten2::ModelCodecManager::decoderList
QList< AbstractModelStreamDecoder * > decoderList() const
Definition: modelcodecmanager.cpp:58
jobmanager.h
modelencoderfilesystemexporter.h
Kasten2::AbstractOverwriteDialog::queryOverwrite
virtual Answer queryOverwrite(const KUrl &url, const QString &title) const =0
Kasten2::PreviousQuestion
Definition: kastencore.h:65
Kasten2::ModelCodecManager::generatorList
QList< AbstractModelDataGenerator * > generatorList() const
Definition: modelcodecmanager.cpp:61
Kasten2::AbstractExportJob
Definition: abstractexportjob.h:40
abstractmodelstreamencoder.h
abstractoverwritedialog.h
abstractmodeldatagenerator.h
Kasten2::ModelCodecManager::encoderList
QList< AbstractModelStreamEncoder * > encoderList(AbstractModel *model, const AbstractModelSelection *selection) const
Definition: modelcodecmanager.cpp:51
Kasten2::ModelCodecManager::encodeToStream
void encodeToStream(AbstractModelStreamEncoder *encoder, AbstractModel *model, const AbstractModelSelection *selection)
Definition: modelcodecmanager.cpp:96
Kasten2::AbstractModelExporter::remoteMimeType
QString remoteMimeType() const
Definition: abstractmodelexporter.cpp:47
Kasten2::ModelCodecManager::exportDocument
void exportDocument(AbstractModelExporter *exporter, AbstractModel *model, const AbstractModelSelection *selection)
Definition: modelcodecmanager.cpp:107
Kasten2::Answer
Answer
Definition: kastencore.h:58
Kasten2::AbstractModelSelection
Definition: abstractmodelselection.h:35
Kasten2::Cancel
Definition: kastencore.h:60
abstractexportjob.h
Kasten2::ModelCodecManager::setOverwriteDialog
void setOverwriteDialog(AbstractOverwriteDialog *overwriteDialog)
Definition: modelcodecmanager.cpp:70
Kasten2::JobManager::executeJob
static bool executeJob(KJob *job)
Definition: jobmanager.cpp:35
Kasten2::AbstractModelStreamEncoder
Definition: abstractmodelstreamencoder.h:50
Kasten2::ModelCodecManager::ModelCodecManager
ModelCodecManager(DocumentManager *manager)
Definition: modelcodecmanager.cpp:44
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::ModelCodecManager::~ModelCodecManager
virtual ~ModelCodecManager()
Definition: modelcodecmanager.cpp:164
Kasten2::ModelCodecManager::setGenerators
void setGenerators(const QList< AbstractModelDataGenerator * > &generatorList)
Definition: modelcodecmanager.cpp:91
Kasten2::DocumentManager
Definition: documentmanager.h:44
Kasten2::AbstractOverwriteDialog
Definition: abstractoverwritedialog.h:37
Kasten2::AbstractModelExporter
Definition: abstractmodelexporter.h:45
Kasten2::AbstractModelExporter::startExport
virtual AbstractExportJob * startExport(AbstractModel *model, const AbstractModelSelection *selection, const KUrl &url)=0
QList
Definition: bookmarkable.h:29
Kasten2::ModelEncoderFileSystemExporter
Definition: modelencoderfilesystemexporter.h:38
Kasten2::ModelCodecManager::setEncoders
void setEncoders(const QList< AbstractModelStreamEncoder * > &encoderList)
Definition: modelcodecmanager.cpp:75
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