• 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
  • synchronize
synchronizecontroller.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 "synchronizecontroller.h"
24 
25 // Kasten core
26 #include <documentsyncmanager.h>
27 #include <abstractmodelfilesystemsynchronizer.h>
28 // KDE
29 #include <KUrl>
30 #include <KActionCollection>
31 #include <KAction>
32 #include <KStandardAction>
33 #include <KXMLGUIClient>
34 #include <KLocale>
35 
36 
37 namespace Kasten2
38 {
39 
40 SynchronizeController::SynchronizeController( DocumentSyncManager* syncManager, KXMLGUIClient* guiClient )
41  : mSyncManager( syncManager ),
42  mDocument( 0 ),
43  mSynchronizer( 0 )
44 {
45  KActionCollection* actionCollection = guiClient->actionCollection();
46 
47  mSaveAction = KStandardAction::save( this, SLOT(save()), actionCollection );
48 
49  mReloadAction = actionCollection->addAction( QLatin1String("file_reload"),
50  this, SLOT(reload()) );
51  mReloadAction->setText( i18nc("@title:menu","Reloa&d") );
52  mReloadAction->setIcon( KIcon( QLatin1String("view-refresh") ) );
53  mReloadAction->setShortcuts( KStandardShortcut::reload() );
54 
55  setTargetModel( 0 );
56 }
57 
58 void SynchronizeController::setTargetModel( AbstractModel* model )
59 {
60  if( mDocument ) mDocument->disconnect( this );
61 
62  mDocument = model ? model->findBaseModel<AbstractDocument*>() : 0;
63 
64  if( mDocument )
65  {
66  connect( mDocument, SIGNAL(synchronizerChanged(Kasten2::AbstractModelSynchronizer*)),
67  SLOT(onSynchronizerChanged(Kasten2::AbstractModelSynchronizer*)) );
68  }
69  onSynchronizerChanged( mDocument ? mDocument->synchronizer() : 0 );
70 }
71 
72 void SynchronizeController::save()
73 {
74  mSyncManager->save( mDocument );
75 }
76 
77 void SynchronizeController::reload()
78 {
79  mSyncManager->reload( mDocument );
80 }
81 
82 void SynchronizeController::onSynchronizerChanged( AbstractModelSynchronizer* newSynchronizer )
83 {
84  if( mSynchronizer ) mSynchronizer->disconnect( this );
85 
86  mSynchronizer = qobject_cast<AbstractModelFileSystemSynchronizer*>( newSynchronizer );
87  // TODO: Storable interface should be used by Synchronizer
88  // synchronizer should report about possible activities
89  // TODO: check for access rights, may not write
90  bool canSync = false;
91  if( mSynchronizer )
92  {
93  const LocalSyncState localSyncState = mSynchronizer->localSyncState();
94  const RemoteSyncState remoteSyncState = mSynchronizer->remoteSyncState();
95  canSync = ( localSyncState == LocalHasChanges )
96  || ( remoteSyncState == RemoteHasChanges )
97  || ( remoteSyncState == RemoteUnknown );
98 
99  connect( mSynchronizer, SIGNAL(localSyncStateChanged(Kasten2::LocalSyncState)),
100  SLOT(onSyncStateChanged()) );
101  connect( mSynchronizer, SIGNAL(remoteSyncStateChanged(Kasten2::RemoteSyncState)),
102  SLOT(onSyncStateChanged()) );
103  connect( mSynchronizer, SIGNAL(destroyed(QObject*)),
104  SLOT(onSynchronizerDeleted(QObject*)) );
105  }
106 
107  mSaveAction->setEnabled( canSync );
108  mReloadAction->setEnabled( canSync );
109 }
110 
111 void SynchronizeController::onSynchronizerDeleted( QObject* synchronizer )
112 {
113  if( synchronizer != mSynchronizer )
114  return;
115 
116  mSynchronizer = 0;
117 
118  mSaveAction->setEnabled( false );
119  mReloadAction->setEnabled( false );
120 }
121 
122 void SynchronizeController::onSyncStateChanged()
123 {
124  const LocalSyncState localSyncState = mSynchronizer->localSyncState();
125  const RemoteSyncState remoteSyncState = mSynchronizer->remoteSyncState();
126  const bool canSync = ( localSyncState == LocalHasChanges )
127  || ( remoteSyncState == RemoteHasChanges )
128  || ( remoteSyncState == RemoteUnknown );
129 
130  mSaveAction->setEnabled( canSync );
131  mReloadAction->setEnabled( canSync );
132 }
133 
134 }
Kasten2::LocalSyncState
LocalSyncState
Definition: kastencore.h:33
documentsyncmanager.h
Kasten2::AbstractModelFileSystemSynchronizer::remoteSyncState
virtual RemoteSyncState remoteSyncState() const
Definition: abstractmodelfilesystemsynchronizer.cpp:43
abstractmodelfilesystemsynchronizer.h
QObject
synchronizecontroller.h
Kasten2::SynchronizeController::SynchronizeController
SynchronizeController(DocumentSyncManager *syncManager, KXMLGUIClient *guiClient)
Definition: synchronizecontroller.cpp:40
Kasten2::RemoteSyncState
RemoteSyncState
Definition: kastencore.h:39
Kasten2::AbstractModelSynchronizer::localSyncState
virtual LocalSyncState localSyncState() const =0
Kasten2::RemoteUnknown
Definition: kastencore.h:45
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::DocumentSyncManager::save
void save(AbstractDocument *document)
Definition: documentsyncmanager.cpp:284
Kasten2::AbstractDocument
Definition: abstractdocument.h:43
Kasten2::RemoteHasChanges
Definition: kastencore.h:42
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
Kasten2::DocumentSyncManager
Definition: documentsyncmanager.h:45
Kasten2::SynchronizeController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: synchronizecontroller.cpp:58
Kasten2::DocumentSyncManager::reload
void reload(AbstractDocument *document)
Definition: documentsyncmanager.cpp:265
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 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