• 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
  • parts
  • kpart
part.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta KPart module, made within the KDE community.
3 
4  Copyright 2003,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 "part.h"
24 
25 // part
26 #include "partfactory.h"
27 #include "browserextension.h"
28 // Okteta Kasten
29 #include <bytearraydocument.h>
30 #include <bytearrayview.h>
31 #include <bytearrayviewprofilesynchronizer.h>
32 #include <bytearrayviewprofilemanager.h>
33 #include <filesystem/bytearrayrawfilesynchronizerfactory.h>
34 #include <overwriteonly/overwriteonlycontroller.h>
35 #include <overwritemode/overwritemodecontroller.h>
36 #include <gotooffset/gotooffsetcontroller.h>
37 #include <selectrange/selectrangecontroller.h>
38 #include <search/searchcontroller.h>
39 #include <replace/replacecontroller.h>
40 #include <bookmarks/bookmarkscontroller.h>
41 #include <print/printcontroller.h>
42 #include <viewconfig/viewconfigcontroller.h>
43 #include <viewmode/viewmodecontroller.h>
44 #include <viewstatus/viewstatuscontroller.h>
45 #include <viewprofiles/viewprofilecontroller.h>
46 // Kasten
47 #include <jobmanager.h>
48 #include <abstractloadjob.h>
49 #include <abstractsyncwithremotejob.h>
50 #include <document/readonly/readonlycontroller.h>
51 // #include <document/readonly/readonlybarcontroller.h>
52 // #include <io/synchronize/synchronizecontroller.h>
53 #include <io/clipboard/clipboardcontroller.h>
54 #include <io/insert/insertcontroller.h>
55 #include <io/copyas/copyascontroller.h>
56 #include <io/export/exportcontroller.h>
57 #include <view/version/versioncontroller.h>
58 #include <view/zoom/zoomcontroller.h>
59 #include <view/zoom/zoombarcontroller.h>
60 #include <view/select/selectcontroller.h>
61 // KDE
62 #include <KActionCollection>
63 // Qt
64 #include <QtGui/QWidget>
65 #include <QtGui/QLayout>
66 #include <QtCore/QList>
67 
68 
69 static const char* const UIFileName[] =
70 {
71  "oktetapartreadonlyui.rc",
72  "oktetapartbrowserui.rc",
73  "oktetapartreadwriteui.rc"
74 };
75 
76 
77 OktetaPart::OktetaPart( QObject* parent,
78  const KComponentData& componentData,
79  Modus modus,
80  Kasten2::ByteArrayViewProfileManager* viewProfileManager )
81  : KParts::ReadWritePart( parent )
82  , mModus( modus )
83  , mViewProfileManager( viewProfileManager )
84 {
85  setComponentData( componentData );
86 
87  QWidget* widget = new QWidget();
88  mLayout = new QVBoxLayout( widget );
89  mLayout->setMargin( 0 );
90 
91  setWidget( widget );
92 
93  setXMLFile( QLatin1String(UIFileName[modus]) );
94 
95  if( modus == ReadWriteModus )
96  mControllers.append( new Kasten2::VersionController(this) );
97  if( modus == ReadWriteModus )
98  mControllers.append( new Kasten2::ReadOnlyController(this) );
99  // TODO: save_as
100 // mControllers.append( new ExportController(mProgram->viewManager(),mProgram->documentManager(),this) );
101  mControllers.append( new Kasten2::ZoomController(this) );
102  mControllers.append( new Kasten2::SelectController(this) );
103  if( modus != BrowserViewModus )
104  mControllers.append( new Kasten2::ClipboardController(this) );
105 // if( modus != BrowserViewModus )
106 // mControllers.append( new Kasten2::InsertController(mProgram->viewManager(),mProgram->documentManager(),this) );
107 // mControllers.append( new Kasten2::CopyAsController(mProgram->viewManager(),mProgram->documentManager(),this) );
108  if( modus == ReadWriteModus )
109  mControllers.append( new Kasten2::OverwriteModeController(this) );
110  mControllers.append( new Kasten2::SearchController(this,widget) );
111  if( modus == ReadWriteModus )
112  mControllers.append( new Kasten2::ReplaceController(this,widget) );
113 // mControllers.append( new Kasten2::GotoOffsetController(mGroupedViews,this) );
114 // mControllers.append( new Kasten2::SelectRangeController(mGroupedViews,this) );
115 // mControllers.append( new Kasten2::BookmarksController(this) );
116  mPrintController = new Kasten2::PrintController( this );
117  mControllers.append( mPrintController );
118  mControllers.append( new Kasten2::ViewConfigController(this) );
119  mControllers.append( new Kasten2::ViewModeController(this) );
120  mControllers.append( new Kasten2::ViewProfileController(mViewProfileManager, widget, this) );
121 
122 // Kasten2::StatusBar* bottomBar = static_cast<Kasten2::StatusBar*>( statusBar() );
123 // mControllers.append( new ViewStatusController(bottomBar) );
124 // mControllers.append( new ReadOnlyBarController(bottomBar) );
125 // mControllers.append( new ZoomBarController(bottomBar) );
126 
127 // addTool( new DocumentInfoToolView(new DocumentInfoTool(mProgram->documentManager()->syncManager())) );
128 // addTool( new ChecksumToolView(new ChecksumTool()) );
129 // addTool( new FilterToolView(new FilterTool()) );
130 // addTool( new StringsExtractToolView(new StringsExtractTool()) );
131 // addTool( new ByteTableToolView(new ByteTableTool()) );
132 // addTool( new InfoToolView(new InfoTool()) );
133 // addTool( new PODDecoderToolView(new PODDecoderTool()) );
134 // addTool( new BookmarksToolView(new BookmarksTool()) );
135 
136  // TODO: BrowserExtension might rely on existing objects (session snap while loadJob),
137  // so this hack just creates some dummies
138  mDocument = new Kasten2::ByteArrayDocument( QString() );
139  Kasten2::ByteArrayViewProfileSynchronizer* viewProfileSynchronizer =
140  new Kasten2::ByteArrayViewProfileSynchronizer( viewProfileManager );
141  mByteArrayView = new Kasten2::ByteArrayView( mDocument, viewProfileSynchronizer );
142 
143  if( modus == BrowserViewModus )
144  new OktetaBrowserExtension( this );
145 }
146 
147 Kasten2::PrintController* OktetaPart::printController() const { return mPrintController; }
148 
149 
150 void OktetaPart::setReadWrite( bool readWrite )
151 {
152  mDocument->setReadOnly( ! readWrite );
153 
154  KParts::ReadWritePart::setReadWrite( readWrite ); // TODO: call to super needed?
155 }
156 
157 bool OktetaPart::openFile()
158 {
159  Kasten2::ByteArrayRawFileSynchronizerFactory* synchronizerFactory = new Kasten2::ByteArrayRawFileSynchronizerFactory();
160  Kasten2::AbstractModelSynchronizer* synchronizer = synchronizerFactory->createSynchronizer();
161 
162  Kasten2::AbstractLoadJob* loadJob = synchronizer->startLoad( localFilePath() );
163  connect( loadJob, SIGNAL(documentLoaded(Kasten2::AbstractDocument*)),
164  SLOT(onDocumentLoaded(Kasten2::AbstractDocument*)) );
165  Kasten2::JobManager::executeJob( loadJob );
166 
167  delete synchronizerFactory;
168 
169  return true;
170 }
171 
172 bool OktetaPart::saveFile()
173 {
174  Kasten2::AbstractModelSynchronizer* synchronizer = mDocument->synchronizer();
175 
176  Kasten2::AbstractSyncWithRemoteJob *syncJob =
177  synchronizer->startSyncWithRemote( localFilePath(), Kasten2::AbstractModelSynchronizer::ReplaceRemote );
178  const bool syncSucceeded = Kasten2::JobManager::executeJob( syncJob );
179 
180  return syncSucceeded;
181 }
182 
183 
184 void OktetaPart::onDocumentLoaded( Kasten2::AbstractDocument* document )
185 {
186  if( document )
187  {
188  delete mByteArrayView;
189  delete mDocument;
190 
191  mDocument = static_cast<Kasten2::ByteArrayDocument*>( document );
192  mDocument->setReadOnly( mModus != ReadWriteModus );
193  connect( mDocument->synchronizer(), SIGNAL(localSyncStateChanged(Kasten2::LocalSyncState)),
194  SLOT(onModified(Kasten2::LocalSyncState)) );
195 
196  Kasten2::ByteArrayViewProfileSynchronizer* viewProfileSynchronizer =
197  new Kasten2::ByteArrayViewProfileSynchronizer( mViewProfileManager );
198  viewProfileSynchronizer->setViewProfileId( mViewProfileManager->defaultViewProfileId() );
199 
200  mByteArrayView = new Kasten2::ByteArrayView( mDocument, viewProfileSynchronizer );
201  connect( mByteArrayView, SIGNAL(hasSelectedDataChanged(bool)), SIGNAL(hasSelectedDataChanged(bool)) );
202 
203  QWidget* displayWidget = mByteArrayView->widget();
204  mLayout->addWidget( displayWidget );
205  mLayout->parentWidget()->setFocusProxy( displayWidget );
206 
207  foreach( Kasten2::AbstractXmlGuiController* controller, mControllers )
208  controller->setTargetModel( mByteArrayView );
209 
210  setModified( false );
211  }
212 }
213 
214 
215 void OktetaPart::onModified( Kasten2::LocalSyncState state )
216 {
217  const bool isModified = ( state != Kasten2::LocalInSync );
218  setModified( isModified );
219 }
220 
221 OktetaPart::~OktetaPart()
222 {
223  qDeleteAll( mControllers );
224  delete mByteArrayView;
225  delete mDocument;
226 }
clipboardcontroller.h
replacecontroller.h
searchcontroller.h
Kasten2::LocalSyncState
LocalSyncState
Definition: kastencore.h:33
Kasten2::ByteArrayRawFileSynchronizerFactory
Definition: bytearrayrawfilesynchronizerfactory.h:35
abstractloadjob.h
OktetaPart::~OktetaPart
virtual ~OktetaPart()
Definition: part.cpp:221
OktetaPart::onDocumentLoaded
void onDocumentLoaded(Kasten2::AbstractDocument *document)
Definition: part.cpp:184
Kasten2::ViewConfigController
Definition: viewconfigcontroller.h:43
gotooffsetcontroller.h
Kasten2::ByteArrayView::widget
virtual QWidget * widget() const
Definition: bytearrayview.cpp:147
abstractsyncwithremotejob.h
QWidget
jobmanager.h
overwriteonlycontroller.h
readonlycontroller.h
Kasten2::AbstractModelSynchronizer::startSyncWithRemote
virtual AbstractSyncWithRemoteJob * startSyncWithRemote(const KUrl &url, AbstractModelSynchronizer::ConnectOption option)=0
changes the
Kasten2::SearchController
Definition: searchcontroller.h:47
bytearrayviewprofilemanager.h
Kasten2::AbstractLoadJob
Definition: abstractloadjob.h:40
QObject
exportcontroller.h
Kasten2::ZoomController
Definition: zoomcontroller.h:43
selectrangecontroller.h
viewstatuscontroller.h
printcontroller.h
Kasten2::LocalInSync
Definition: kastencore.h:35
Kasten2::ByteArrayViewProfileManager::defaultViewProfileId
ByteArrayViewProfile::Id defaultViewProfileId() const
Definition: bytearrayviewprofilemanager.cpp:205
Kasten2::ByteArrayDocument::setReadOnly
virtual void setReadOnly(bool isReadOnly)
default does nothing
Definition: bytearraydocument.cpp:69
OktetaPart::printController
Kasten2::PrintController * printController() const
Definition: part.cpp:147
OktetaPart::saveFile
virtual bool saveFile()
Definition: part.cpp:172
overwritemodecontroller.h
viewprofilecontroller.h
insertcontroller.h
OktetaPart::onModified
void onModified(Kasten2::LocalSyncState state)
Definition: part.cpp:215
partfactory.h
selectcontroller.h
OktetaPart::BrowserViewModus
Definition: part.h:50
bookmarkscontroller.h
Kasten2::ClipboardController
Definition: clipboardcontroller.h:44
Kasten2::SelectController
Definition: selectcontroller.h:43
zoombarcontroller.h
Kasten2::VersionController
Definition: versioncontroller.h:44
Kasten2::ViewModeController
Definition: viewmodecontroller.h:41
OktetaPart::OktetaBrowserExtension
friend class OktetaBrowserExtension
Definition: part.h:47
OktetaPart::ReadWriteModus
Definition: part.h:50
OktetaPart::openFile
virtual bool openFile()
Definition: part.cpp:157
OktetaPart::hasSelectedDataChanged
void hasSelectedDataChanged(bool hasSelectedData)
viewconfigcontroller.h
Kasten2::ViewProfileController
Definition: viewprofilecontroller.h:47
bytearrayviewprofilesynchronizer.h
viewmodecontroller.h
Kasten2::ByteArrayViewProfileSynchronizer
Definition: bytearrayviewprofilesynchronizer.h:41
Kasten2::OverwriteModeController
Definition: overwritemodecontroller.h:40
versioncontroller.h
Kasten2::AbstractDocument
Definition: abstractdocument.h:43
zoomcontroller.h
Kasten2::ReplaceController
Definition: replacecontroller.h:48
Kasten2::ByteArrayViewProfileManager
Definition: bytearrayviewprofilemanager.h:65
UIFileName
static const char *const UIFileName[]
Definition: part.cpp:69
Kasten2::AbstractModelSynchronizer::startLoad
virtual AbstractLoadJob * startLoad(const KUrl &url)=0
Kasten2::PrintController
Definition: printcontroller.h:41
Kasten2::JobManager::executeJob
static bool executeJob(KJob *job)
Definition: jobmanager.cpp:35
Kasten2::AbstractController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: abstractcontroller.cpp:29
copyascontroller.h
Kasten2::AbstractModelSynchronizer
possible actions:
Definition: abstractmodelsynchronizer.h:61
bytearrayrawfilesynchronizerfactory.h
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::AbstractModelSynchronizer::ReplaceRemote
Definition: abstractmodelsynchronizer.h:69
browserextension.h
OktetaPart::OktetaPart
OktetaPart(QObject *parent, const KComponentData &componentData, Modus modus, Kasten2::ByteArrayViewProfileManager *viewProfileManager)
Definition: part.cpp:77
bytearraydocument.h
Kasten2::AbstractSyncWithRemoteJob
Definition: abstractsyncwithremotejob.h:38
Kasten2::AbstractDocument::synchronizer
AbstractModelSynchronizer * synchronizer() const
Definition: abstractdocument.cpp:40
OktetaPart::setReadWrite
virtual void setReadWrite(bool readWrite=true)
Definition: part.cpp:150
OktetaPart::Modus
Modus
Definition: part.h:50
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
Kasten2::ReadOnlyController
Definition: readonlycontroller.h:41
Kasten2::ByteArrayRawFileSynchronizerFactory::createSynchronizer
virtual AbstractModelSynchronizer * createSynchronizer() const
Definition: bytearrayrawfilesynchronizerfactory.cpp:45
part.h
Kasten2::AbstractXmlGuiController
Definition: abstractxmlguicontroller.h:32
bytearrayview.h
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