• 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
  • document
  • modified
modifiedbarcontroller.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 2009-2010,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 "modifiedbarcontroller.h"
24 
25 // Kasten ui
26 #include <statusbar.h>
27 // Kasten core
28 #include <abstractmodelsynchronizer.h>
29 #include <abstractdocument.h>
30 // KDE
31 #include <KLocale>
32 #include <KIcon>
33 // Qt
34 #include <QtGui/QLabel>
35 
36 
37 namespace Kasten2
38 {
39 static const int modifiedPixmapWidth = 16;
40 
41 
42 ModifiedBarController::ModifiedBarController( StatusBar* statusBar )
43  : mDocument( 0 )
44  , mSynchronizer( 0 )
45 {
46  // TODO: depend an statusbar height
47  const QSize modifiedPixmapSize = QSize(modifiedPixmapWidth, modifiedPixmapWidth);
48 
49  mLocalStateLabel = new QLabel( statusBar );
50  mLocalStateLabel->setAlignment( Qt::AlignCenter );
51  mLocalStateLabel->setFixedSize( modifiedPixmapSize );
52  statusBar->addWidget( mLocalStateLabel );
53 
54  mRemoteStateLabel = new QLabel( statusBar );
55  mRemoteStateLabel->setAlignment( Qt::AlignCenter );
56  mRemoteStateLabel->setFixedSize( modifiedPixmapSize );
57  statusBar->addWidget( mRemoteStateLabel );
58 
59  setTargetModel( 0 );
60 }
61 
62 
63 void ModifiedBarController::setTargetModel( AbstractModel* model )
64 {
65  AbstractDocument* newDocument = model ? model->findBaseModel<AbstractDocument*>() : 0;
66 
67  if( mDocument == newDocument )
68  return;
69 
70  if( mDocument ) mDocument->disconnect( this );
71 
72  mDocument = newDocument;
73 
74  if( mDocument )
75  {
76  connect( mDocument, SIGNAL(synchronizerChanged(Kasten2::AbstractModelSynchronizer*)),
77  SLOT(onSynchronizerChanged(Kasten2::AbstractModelSynchronizer*)) );
78  }
79 
80  mLocalStateLabel->setEnabled( mDocument );
81  mRemoteStateLabel->setEnabled( mDocument );
82 
83  onSynchronizerChanged( mDocument ? mDocument->synchronizer() : 0 );
84 }
85 
86 
87 void ModifiedBarController::onContentFlagsChanged( ContentFlags contentFlags )
88 {
89  const bool hasChanges = (contentFlags & ContentHasUnstoredChanges);
90  onLocalSyncStateChanged( hasChanges ? LocalHasChanges : LocalInSync );
91 }
92 
93 void ModifiedBarController::onLocalSyncStateChanged( LocalSyncState localSyncState )
94 {
95  const bool isModified = (localSyncState == LocalHasChanges );
96 
97  // TODO: depend an statusbar height
98  const QPixmap pixmap = isModified ?
99  KIcon( QLatin1String("document-save") ).pixmap(modifiedPixmapWidth) :
100  QPixmap();
101  mLocalStateLabel->setPixmap( pixmap );
102 
103  mLocalStateLabel->setToolTip( isModified ?
104  i18nc( "@tooltip the document is modified", "Modified." ) :
105  i18nc( "@tooltip the document is not modified", "Not modified." ) );
106 
107 }
108 
109 void ModifiedBarController::onRemoteSyncStateChanged( RemoteSyncState remoteSyncState )
110 {
111  const char* const iconName =
112  ( mSynchronizer == 0 ) ? "document-new" :
113  ( remoteSyncState == RemoteHasChanges ) ? "document-save" :
114  ( remoteSyncState == RemoteDeleted ) ? "edit-delete" :
115  ( remoteSyncState == RemoteUnknown ) ? "flag-yellow" :
116  ( remoteSyncState == RemoteUnreachable ) ? "network-disconnect" :
117  /* else */ 0;
118 
119  // TODO: depend an statusbar height
120  const QPixmap pixmap = iconName ?
121  KIcon( QLatin1String(iconName) ).pixmap(modifiedPixmapWidth) :
122  QPixmap();
123  mRemoteStateLabel->setPixmap( pixmap );
124 
125  // TODO: tooltips
126 }
127 
128 void ModifiedBarController::onSynchronizerChanged( AbstractModelSynchronizer* newSynchronizer )
129 {
130  if( mSynchronizer ) mSynchronizer->disconnect( this );
131 
132  AbstractModelSynchronizer* oldSynchronizer = mSynchronizer;
133  mSynchronizer = newSynchronizer;
134 
135  LocalSyncState localState;
136  RemoteSyncState remoteState;
137  if( mSynchronizer )
138  {
139  if( ! oldSynchronizer )
140  mDocument->disconnect( this, SLOT(onContentFlagsChanged(Kasten2::ContentFlags)) );
141 
142  localState = mSynchronizer->localSyncState();
143  remoteState = mSynchronizer->remoteSyncState();
144 
145  connect( mSynchronizer, SIGNAL(localSyncStateChanged(Kasten2::LocalSyncState)),
146  SLOT(onLocalSyncStateChanged(Kasten2::LocalSyncState)) );
147  connect( mSynchronizer, SIGNAL(remoteSyncStateChanged(Kasten2::RemoteSyncState)),
148  SLOT(onRemoteSyncStateChanged(Kasten2::RemoteSyncState)) );
149  connect( mSynchronizer, SIGNAL(destroyed(QObject*)),
150  SLOT(onSynchronizerDeleted(QObject*)) );
151  }
152  else if( mDocument )
153  {
154  const bool hasChanges = (mDocument->contentFlags() & ContentHasUnstoredChanges);
155  localState = ( hasChanges ? LocalHasChanges : LocalInSync );
156  // TODO: onRemoteSyncStateChanged(...) checks for mSynchronizer and ignores this
157  remoteState = RemoteInSync;
158 
159  connect( mDocument, SIGNAL(contentFlagsChanged(Kasten2::ContentFlags)),
160  SLOT(onContentFlagsChanged(Kasten2::ContentFlags)) );
161  }
162  else
163  {
164  localState = LocalInSync;
165  // TODO: onRemoteSyncStateChanged(...) checks for mSynchronizer and ignores this
166  remoteState = RemoteInSync;
167  }
168 
169  onLocalSyncStateChanged( localState );
170  onRemoteSyncStateChanged( remoteState );
171 }
172 
173 void ModifiedBarController::onSynchronizerDeleted( QObject* synchronizer )
174 {
175  if( synchronizer != mSynchronizer )
176  return;
177 
178  mSynchronizer = 0;
179 
180  // switch to document state
181  connect( mDocument, SIGNAL(contentFlagsChanged(Kasten2::ContentFlags)),
182  SLOT(onContentFlagsChanged(Kasten2::ContentFlags)) );
183 
184  onContentFlagsChanged( mDocument->contentFlags() );
185  // TODO: onRemoteSyncStateChanged(...) checks for mSynchronizer and ignores the parameter
186  onRemoteSyncStateChanged( RemoteInSync );
187 }
188 
189 }
Kasten2::RemoteUnreachable
unknown, e.g. because connection not available/lost
Definition: kastencore.h:47
Kasten2::LocalSyncState
LocalSyncState
Definition: kastencore.h:33
abstractdocument.h
modifiedbarcontroller.h
Kasten2::ModifiedBarController::ModifiedBarController
ModifiedBarController(StatusBar *statusBar)
Definition: modifiedbarcontroller.cpp:42
Kasten2::StatusBar
Definition: statusbar.h:40
Kasten2::ContentHasUnstoredChanges
Definition: kastencore.h:53
QObject
statusbar.h
Kasten2::ModifiedBarController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: modifiedbarcontroller.cpp:63
Kasten2::RemoteDeleted
Definition: kastencore.h:43
Kasten2::RemoteSyncState
RemoteSyncState
Definition: kastencore.h:39
Kasten2::LocalInSync
Definition: kastencore.h:35
Kasten2::AbstractModelSynchronizer::localSyncState
virtual LocalSyncState localSyncState() const =0
Kasten2::modifiedPixmapWidth
static const int modifiedPixmapWidth
Definition: modifiedbarcontroller.cpp:39
Kasten2::AbstractModelSynchronizer::remoteSyncState
virtual RemoteSyncState remoteSyncState() const =0
abstractmodelsynchronizer.h
Kasten2::RemoteUnknown
Definition: kastencore.h:45
Kasten2::RemoteInSync
Definition: kastencore.h:41
Kasten2::AbstractDocument::contentFlags
virtual ContentFlags contentFlags() const =0
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::AbstractDocument
Definition: abstractdocument.h:43
Kasten2::RemoteHasChanges
Definition: kastencore.h:42
Kasten2::StatusBar::addWidget
void addWidget(QWidget *widget)
Definition: statusbar.cpp:47
Kasten2::AbstractModelSynchronizer
possible actions:
Definition: abstractmodelsynchronizer.h:61
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::AbstractDocument::synchronizer
AbstractModelSynchronizer * synchronizer() const
Definition: abstractdocument.cpp:40
Kasten2::LocalHasChanges
Definition: kastencore.h:36
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