• 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
  • kasten
  • gui
  • io
bytearrayviewprofilesynchronizer.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2012 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 "bytearrayviewprofilesynchronizer.h"
24 
25 // library
26 #include <bytearrayviewprofilemanager.h>
27 #include <bytearrayview.h>
28 
29 #include <KDebug>
30 namespace Kasten2
31 {
32 
33 ByteArrayViewProfileSynchronizer::ByteArrayViewProfileSynchronizer( ByteArrayViewProfileManager* viewProfileManager )
34  : QObject()
35  , mView( 0 )
36  , mViewProfileId()
37  , mDirtyFlags( 0 )
38  , mUpdatingView( false )
39  , mViewProfileManager( viewProfileManager )
40 {
41 }
42 
43 LocalSyncState
44 ByteArrayViewProfileSynchronizer::localSyncState() const
45 {
46  return ( mDirtyFlags == 0 ) ? LocalInSync : LocalHasChanges;
47 }
48 
49 void
50 ByteArrayViewProfileSynchronizer::setView( ByteArrayView* view )
51 {
52  if( mView && ! mViewProfileId.isEmpty() ) mView->disconnect( this );
53 
54  mView = view;
55 
56  // TODO: drop all changes and set view to profile if set
57  mDirtyFlags = 0;
58 
59  if( mView && ! mViewProfileId.isEmpty() )
60  {
61  const ByteArrayViewProfile viewProfile = mViewProfileManager->viewProfile( mViewProfileId );
62  updateView( viewProfile );
63  connectViewSignals();
64  }
65 }
66 
67 void ByteArrayViewProfileSynchronizer::setViewProfileId( const ByteArrayViewProfile::Id& viewProfileId )
68 {
69  if( mViewProfileId == viewProfileId )
70  return;
71 
72  const bool isListeningBefore = ( ! mViewProfileId.isEmpty() );
73 
74  mViewProfileId = viewProfileId;
75 
76  // TODO: drop all changes and set view to profile if set
77  mDirtyFlags = 0;
78  if( ! viewProfileId.isEmpty() )
79  {
80  const ByteArrayViewProfile viewProfile = mViewProfileManager->viewProfile( viewProfileId );
81  updateView( viewProfile );
82  }
83 
84  const bool isListeningAfter = ( ! mViewProfileId.isEmpty() );
85 
86  if( isListeningAfter)
87  {
88  if( ! isListeningBefore )
89  {
90  connect( mViewProfileManager, SIGNAL(viewProfilesChanged(QList<Kasten2::ByteArrayViewProfile>)),
91  SLOT(onViewProfilesChanged(QList<Kasten2::ByteArrayViewProfile>)) );
92  connect( mViewProfileManager, SIGNAL(viewProfilesRemoved(QList<Kasten2::ByteArrayViewProfile::Id>)),
93  SLOT(onViewProfilesRemoved(QList<Kasten2::ByteArrayViewProfile::Id>)) );
94  if( mView )
95  connectViewSignals();
96  }
97  }
98  else
99  {
100  if ( isListeningBefore )
101  {
102  mViewProfileManager->disconnect( this );
103  if( mView ) mView->disconnect( this );
104  }
105  }
106 
107  if( mView )
108  emit localSyncStateChanged( LocalInSync );
109 }
110 
111 void
112 ByteArrayViewProfileSynchronizer::syncToRemote()
113 {
114  if( (mView == 0) || (mViewProfileId.isEmpty()) )
115  return;
116 
117  ByteArrayViewProfile viewProfile = mViewProfileManager->viewProfile( mViewProfileId );
118  updateViewProfile( viewProfile );
119 
120  mDirtyFlags = 0;
121 
122  QList<ByteArrayViewProfile> viewProfiles;
123  viewProfiles << viewProfile;
124  mViewProfileManager->saveViewProfiles( viewProfiles );
125 
126  if( mView )
127  emit localSyncStateChanged( LocalInSync );
128 }
129 
130 void
131 ByteArrayViewProfileSynchronizer::syncFromRemote()
132 {
133  if( (mView == 0) || (mViewProfileId.isEmpty()) )
134  return;
135 
136  const ByteArrayViewProfile viewProfile = mViewProfileManager->viewProfile( mViewProfileId );
137  // TODO: this is a lazy hack, simply sets all of the profile, even if not needed. Improve that.
138  mDirtyFlags = 0;
139  updateView( viewProfile );
140 
141  if( mView )
142  emit localSyncStateChanged( LocalInSync );
143 }
144 
145 
146 void
147 ByteArrayViewProfileSynchronizer::onViewProfilesChanged( const QList<ByteArrayViewProfile>& viewProfiles )
148 {
149  if( mView == 0 )
150  return;
151 
152  foreach( const ByteArrayViewProfile& viewProfile, viewProfiles )
153  {
154  if( viewProfile.id() == mViewProfileId )
155  {
156  updateView( viewProfile );
157  break;
158  }
159  }
160 }
161 
162 void ByteArrayViewProfileSynchronizer::updateView( const ByteArrayViewProfile& viewProfile )
163 {
164  if( ! mView )
165  return;
166 
167  mUpdatingView = true;
168 
169  if( (mDirtyFlags&ShowsNonprintingChanged) == 0 )
170  mView->setShowsNonprinting( viewProfile.showsNonprinting() );
171 
172  if( (mDirtyFlags&OffsetCodingChanged) == 0 )
173  mView->setOffsetCoding( viewProfile.offsetCoding() );
174 
175  if( (mDirtyFlags&ValueCodingChanged) == 0 )
176  mView->setValueCoding( viewProfile.valueCoding() );
177 
178  if( (mDirtyFlags&CharCodecChanged) == 0 )
179  mView->setCharCoding( viewProfile.charCodingName() );
180 
181  if( (mDirtyFlags&SubstituteCharChanged) == 0 )
182  mView->setSubstituteChar( viewProfile.substituteChar() );
183 
184  if( (mDirtyFlags&UndefinedCharChanged) == 0 )
185  mView->setUndefinedChar( viewProfile.undefinedChar() );
186 
187  if( (mDirtyFlags&VisibleByteArrayCodingsChanged) == 0 )
188  mView->setVisibleByteArrayCodings( viewProfile.visibleByteArrayCodings() );
189 
190  if( (mDirtyFlags&OffsetColumnVisibleChanged) == 0 )
191  mView->toggleOffsetColumn( viewProfile.offsetColumnVisible() );
192 
193  if( (mDirtyFlags&NoOfBytesPerLineChanged) == 0 )
194  mView->setNoOfBytesPerLine( viewProfile.noOfBytesPerLine() );
195 
196  if( (mDirtyFlags&NoOfGroupedBytesChanged) == 0 )
197  mView->setNoOfGroupedBytes( viewProfile.noOfGroupedBytes() );
198 
199  if( (mDirtyFlags&LayoutStyleChanged) == 0 )
200  mView->setLayoutStyle( viewProfile.layoutStyle() );
201 
202  if( (mDirtyFlags&ViewModusChanged) == 0 )
203  mView->setViewModus( viewProfile.viewModus() );
204 
205  mUpdatingView = false;
206 }
207 
208 void ByteArrayViewProfileSynchronizer::updateViewProfile( ByteArrayViewProfile& viewProfile )
209 {
210  if( ! mView )
211  return;
212 
213  if( (mDirtyFlags&ShowsNonprintingChanged) )
214  viewProfile.setShowsNonprinting( mView->showsNonprinting() );
215 
216  if( (mDirtyFlags&OffsetCodingChanged) )
217  viewProfile.setOffsetCoding( mView->offsetCoding() );
218 
219  if( (mDirtyFlags&ValueCodingChanged) )
220  viewProfile.setValueCoding( mView->valueCoding() );
221 
222  if( (mDirtyFlags&CharCodecChanged) )
223  viewProfile.setCharCoding( mView->charCodingName() );
224 
225  if( (mDirtyFlags&SubstituteCharChanged) )
226  viewProfile.setSubstituteChar( mView->substituteChar() );
227 
228  if( (mDirtyFlags&UndefinedCharChanged) )
229  viewProfile.setUndefinedChar( mView->undefinedChar() );
230 
231  if( (mDirtyFlags&VisibleByteArrayCodingsChanged) )
232  viewProfile.setVisibleByteArrayCodings( mView->visibleByteArrayCodings() );
233 
234  if( (mDirtyFlags&OffsetColumnVisibleChanged) )
235  viewProfile.setOffsetColumnVisible( mView->offsetColumnVisible() );
236 
237  if( (mDirtyFlags&NoOfBytesPerLineChanged) )
238  viewProfile.setNoOfBytesPerLine( mView->noOfBytesPerLine() );
239 
240  if( (mDirtyFlags&NoOfGroupedBytesChanged) )
241  viewProfile.setNoOfGroupedBytes( mView->noOfGroupedBytes() );
242 
243  if( (mDirtyFlags&LayoutStyleChanged) )
244  viewProfile.setLayoutStyle( mView->layoutStyle() );
245 
246  if( (mDirtyFlags&ViewModusChanged) )
247  viewProfile.setViewModus( mView->viewModus() );
248 }
249 
250 void ByteArrayViewProfileSynchronizer::connectViewSignals()
251 {
252  connect( mView, SIGNAL(showsNonprintingChanged(bool)),
253  SLOT(onShowsNonprintingChanged()) );
254  connect( mView, SIGNAL(offsetCodingChanged(int)),
255  SLOT(onOffsetCodingChanged()) );
256  connect( mView, SIGNAL(valueCodingChanged(int)),
257  SLOT(onValueCodingChanged()) );
258  connect( mView, SIGNAL(charCodecChanged(QString)),
259  SLOT(onCharCodecChanged()) );
260  connect( mView, SIGNAL(substituteCharChanged(QChar)),
261  SLOT(onSubstituteCharChanged()) );
262  connect( mView, SIGNAL(undefinedCharChanged(QChar)),
263  SLOT(onUndefinedCharChanged()) );
264  connect( mView, SIGNAL(visibleByteArrayCodingsChanged(int)),
265  SLOT(onVisibleByteArrayCodingsChanged()) );
266  connect( mView, SIGNAL(offsetColumnVisibleChanged(bool)),
267  SLOT(onOffsetColumnVisibleChanged()) );
268  connect( mView, SIGNAL(noOfBytesPerLineChanged(int)),
269  SLOT(onNoOfBytesPerLineChanged()) );
270  connect( mView, SIGNAL(noOfGroupedBytesChanged(int)),
271  SLOT(onNoOfGroupedBytesChanged()) );
272  connect( mView, SIGNAL(layoutStyleChanged(int)),
273  SLOT(onLayoutStyleChanged()) );
274  connect( mView, SIGNAL(viewModusChanged(int)),
275  SLOT(onViewModusChanged()) );
276 }
277 
278 void ByteArrayViewProfileSynchronizer::onViewProfilesRemoved( const QList<ByteArrayViewProfile::Id>& viewProfileIds )
279 {
280  if( mView == 0 )
281  return;
282 
283  foreach( const ByteArrayViewProfile::Id& viewProfileId, viewProfileIds )
284  {
285  if( viewProfileId == mViewProfileId )
286  {
287  // TODO: really forget binding to that profile completely? cannot reappear?
288  setViewProfileId( ByteArrayViewProfile::Id() );
289  break;
290  }
291  }
292 }
293 
294 void
295 ByteArrayViewProfileSynchronizer::setDirtyFlag( int dirtyFlag )
296 {
297  if( mUpdatingView )
298  return;
299 
300  const bool isCleanBefore = ( mDirtyFlags == 0 );
301 
302  mDirtyFlags |= dirtyFlag;
303 
304  if( isCleanBefore )
305  emit localSyncStateChanged( LocalHasChanges );
306 }
307 
308 void ByteArrayViewProfileSynchronizer::onShowsNonprintingChanged()
309 {
310  setDirtyFlag( ShowsNonprintingChanged );
311 }
312 void ByteArrayViewProfileSynchronizer::onOffsetCodingChanged()
313 {
314  setDirtyFlag( OffsetCodingChanged );
315 }
316 void ByteArrayViewProfileSynchronizer::onValueCodingChanged()
317 {
318  setDirtyFlag( ValueCodingChanged );
319 }
320 void ByteArrayViewProfileSynchronizer::onCharCodecChanged()
321 {
322  setDirtyFlag( CharCodecChanged );
323 }
324 void ByteArrayViewProfileSynchronizer::onSubstituteCharChanged()
325 {
326  setDirtyFlag( SubstituteCharChanged );
327 }
328 void ByteArrayViewProfileSynchronizer::onUndefinedCharChanged()
329 {
330  setDirtyFlag( UndefinedCharChanged );
331 }
332 void ByteArrayViewProfileSynchronizer::onVisibleByteArrayCodingsChanged()
333 {
334  setDirtyFlag( VisibleByteArrayCodingsChanged );
335 }
336 void ByteArrayViewProfileSynchronizer::onOffsetColumnVisibleChanged()
337 {
338  setDirtyFlag( OffsetColumnVisibleChanged );
339 }
340 void ByteArrayViewProfileSynchronizer::onNoOfBytesPerLineChanged()
341 {
342  setDirtyFlag( NoOfBytesPerLineChanged );
343 }
344 void ByteArrayViewProfileSynchronizer::onNoOfGroupedBytesChanged()
345 {
346  setDirtyFlag( NoOfGroupedBytesChanged );
347 }
348 void ByteArrayViewProfileSynchronizer::onLayoutStyleChanged()
349 {
350  setDirtyFlag( LayoutStyleChanged );
351 }
352 void ByteArrayViewProfileSynchronizer::onViewModusChanged()
353 {
354  setDirtyFlag( ViewModusChanged );
355 }
356 
357 }
Kasten2::ByteArrayView::showsNonprinting
bool showsNonprinting() const
Definition: bytearrayview.cpp:286
Kasten2::ByteArrayViewProfile::id
Id id() const
Definition: bytearrayviewprofile.cpp:108
Kasten2::ByteArrayViewProfileSynchronizer::ByteArrayViewProfileSynchronizer
ByteArrayViewProfileSynchronizer(ByteArrayViewProfileManager *viewProfileManager)
Definition: bytearrayviewprofilesynchronizer.cpp:33
Kasten2::LocalSyncState
LocalSyncState
Definition: kastencore.h:33
Kasten2::ByteArrayView::viewModus
int viewModus() const
Definition: bytearrayview.cpp:409
Kasten2::ByteArrayView::valueCoding
int valueCoding() const
Definition: bytearrayview.cpp:250
Kasten2::ByteArrayViewProfile::Id
QString Id
Definition: bytearrayviewprofile.h:42
Kasten2::ByteArrayView::setSubstituteChar
void setSubstituteChar(QChar substituteChar)
Definition: bytearrayview.cpp:358
Kasten2::ByteArrayView::charCodingName
QString charCodingName() const
Definition: bytearrayview.cpp:255
Kasten2::ByteArrayView::noOfBytesPerLine
int noOfBytesPerLine() const
Definition: bytearrayview.cpp:244
Kasten2::ByteArrayView::setViewModus
void setViewModus(int viewModus)
Definition: bytearrayview.cpp:405
Kasten2::ByteArrayViewProfileSynchronizer::syncFromRemote
void syncFromRemote()
Definition: bytearrayviewprofilesynchronizer.cpp:131
Kasten2::ByteArrayView::setValueCoding
void setValueCoding(int valueCoding)
Definition: bytearrayview.cpp:260
Kasten2::ByteArrayViewProfile
Definition: bytearrayviewprofile.h:39
bytearrayviewprofilemanager.h
Kasten2::ByteArrayViewProfileManager::saveViewProfiles
void saveViewProfiles(QList< ByteArrayViewProfile > &viewProfiles)
Definition: bytearrayviewprofilemanager.cpp:236
Kasten2::ByteArrayView::setCharCoding
void setCharCoding(const QString &charCodingName)
Definition: bytearrayview.cpp:265
QObject
Kasten2::ByteArrayView::visibleByteArrayCodings
int visibleByteArrayCodings() const
Definition: bytearrayview.cpp:306
Kasten2::ByteArrayViewProfileSynchronizer::viewProfileId
ByteArrayViewProfile::Id viewProfileId() const
Definition: bytearrayviewprofilesynchronizer.h:118
Kasten2::ByteArrayView::setLayoutStyle
void setLayoutStyle(int layoutStyle)
Definition: bytearrayview.cpp:336
Kasten2::LocalInSync
Definition: kastencore.h:35
Kasten2::ByteArrayViewProfileSynchronizer::view
ByteArrayView * view() const
Definition: bytearrayviewprofilesynchronizer.h:117
Kasten2::ByteArrayView::setShowsNonprinting
void setShowsNonprinting(bool showsNonprinting=true)
Definition: bytearrayview.cpp:316
Kasten2::ByteArrayView::setNoOfGroupedBytes
void setNoOfGroupedBytes(int noOfGroupedBytes)
Definition: bytearrayview.cpp:321
Kasten2::ByteArrayViewProfileSynchronizer::setViewProfileId
void setViewProfileId(const ByteArrayViewProfile::Id &viewProfileId)
Definition: bytearrayviewprofilesynchronizer.cpp:67
Kasten2::ByteArrayViewProfileSynchronizer::localSyncState
LocalSyncState localSyncState() const
Definition: bytearrayviewprofilesynchronizer.cpp:44
Kasten2::ByteArrayViewProfileSynchronizer::setView
void setView(ByteArrayView *view)
Definition: bytearrayviewprofilesynchronizer.cpp:50
Kasten2::ByteArrayView::setVisibleByteArrayCodings
void setVisibleByteArrayCodings(int columns)
Definition: bytearrayview.cpp:346
Kasten2::ByteArrayView::setNoOfBytesPerLine
void setNoOfBytesPerLine(int noOfBytesPerLine)
Definition: bytearrayview.cpp:341
Kasten2::ByteArrayView::noOfGroupedBytes
int noOfGroupedBytes() const
Definition: bytearrayview.cpp:382
Kasten2::ByteArrayView::setUndefinedChar
void setUndefinedChar(QChar undefinedChar)
Definition: bytearrayview.cpp:363
Kasten2::ByteArrayViewProfileSynchronizer::syncToRemote
void syncToRemote()
Definition: bytearrayviewprofilesynchronizer.cpp:112
Kasten2::ByteArrayView::undefinedChar
QChar undefinedChar() const
Definition: bytearrayview.cpp:373
Kasten2::ByteArrayViewProfileSynchronizer::localSyncStateChanged
void localSyncStateChanged(Kasten2::LocalSyncState newState)
bytearrayviewprofilesynchronizer.h
Kasten2::viewProfileIds
static QList< ByteArrayViewProfile::Id > viewProfileIds(const QList< ByteArrayViewProfile > &viewProfiles)
Definition: bytearrayviewprofilemanager.cpp:58
Kasten2::ByteArrayView::substituteChar
QChar substituteChar() const
Definition: bytearrayview.cpp:369
Kasten2::ByteArrayViewProfileManager
Definition: bytearrayviewprofilemanager.h:65
Kasten2::ByteArrayView::offsetColumnVisible
bool offsetColumnVisible() const
Definition: bytearrayview.cpp:291
Kasten2::ByteArrayView::setOffsetCoding
void setOffsetCoding(int offsetCoding)
Definition: bytearrayview.cpp:331
Kasten2::ByteArrayView::offsetCoding
int offsetCoding() const
Definition: bytearrayview.cpp:296
Kasten2::LocalHasChanges
Definition: kastencore.h:36
Kasten2::ByteArrayView::layoutStyle
int layoutStyle() const
Definition: bytearrayview.cpp:301
Kasten2::ByteArrayView::toggleOffsetColumn
void toggleOffsetColumn(bool visible)
Definition: bytearrayview.cpp:326
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
QList< Kasten2::ByteArrayViewProfile >
Kasten2::ByteArrayViewProfileManager::viewProfile
ByteArrayViewProfile viewProfile(const ByteArrayViewProfile::Id &id) const
Definition: bytearrayviewprofilemanager.cpp:188
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: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