2
This file is part of the Okteta Kasten module, made within the KDE community.
4
Copyright 2010,2012 Friedrich W. H. Kossebau <kossebau@kde.org>
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.
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.
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/>.
23
#include "viewprofilescontroller.h"
26
#include "viewprofileeditdialog.h"
28
#include <bytearrayviewprofilemanager.h>
29
#include <bytearrayviewprofilesynchronizer.h>
30
#include <bytearrayview.h>
32
#include <KXMLGUIClient>
40
ViewProfilesController::ViewProfilesController( KXMLGUIClient* guiClient,
41
ByteArrayViewProfileManager* viewProfileManager,
42
QWidget* parentWidget )
43
: mGuiClient( guiClient )
44
, mViewProfileManager( viewProfileManager )
45
, mParentWidget( parentWidget )
47
, mByteArrayViewProfileSynchronizer( 0 )
49
mViewProfilesActionGroup = new QActionGroup( this );
50
mViewProfilesActionGroup->setExclusive( true );
51
connect( mViewProfilesActionGroup, SIGNAL(triggered(QAction*)),
52
SLOT(onViewProfileTriggered(QAction*)) );
54
connect( mViewProfileManager, SIGNAL(viewProfilesChanged(QList<Kasten2::ByteArrayViewProfile>)),
55
SLOT(onViewProfilesChanged()) );
56
connect( mViewProfileManager, SIGNAL(viewProfilesRemoved(QList<Kasten2::ByteArrayViewProfile::Id>)),
57
SLOT(onViewProfilesChanged()) );
59
onViewProfilesChanged();
64
void ViewProfilesController::setTargetModel( AbstractModel* model )
66
if( mByteArrayViewProfileSynchronizer )
67
mByteArrayViewProfileSynchronizer->disconnect( this );
69
mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0;
70
mByteArrayViewProfileSynchronizer = mByteArrayView ? mByteArrayView->synchronizer() : 0;
72
const bool hasSynchronizer = ( mByteArrayViewProfileSynchronizer != 0 );
75
onViewProfileChanged( mByteArrayViewProfileSynchronizer->viewProfileId() );
77
connect( mByteArrayViewProfileSynchronizer, SIGNAL(viewProfileChanged(Kasten2::ByteArrayViewProfile::Id)),
78
SLOT(onViewProfileChanged(Kasten2::ByteArrayViewProfile::Id)) );
81
mViewProfilesActionGroup->setEnabled( hasSynchronizer );
84
void ViewProfilesController::onViewProfileChanged( const Kasten2::ByteArrayViewProfile::Id& viewProfileId )
86
const QList<QAction*> actions = mViewProfilesActionGroup->actions();
88
foreach( QAction* action, actions )
90
if( action->data().toString() == viewProfileId )
92
action->setChecked( true );
98
void ViewProfilesController::onViewProfilesChanged()
100
mGuiClient->unplugActionList( QLatin1String("view_profile_list") );
102
qDeleteAll( mViewProfilesActionGroup->actions() );
104
const QList<ByteArrayViewProfile> viewProfiles = mViewProfileManager->viewProfiles();
105
const ByteArrayViewProfile::Id currentViewProfileId = mByteArrayViewProfileSynchronizer ?
106
mByteArrayViewProfileSynchronizer->viewProfileId() :
107
ByteArrayViewProfile::Id();
109
foreach( const ByteArrayViewProfile& viewProfile, viewProfiles )
111
const QString title = viewProfile.viewProfileTitle();
112
QAction* action = new QAction( title, mViewProfilesActionGroup );
113
action->setCheckable( true );
114
const ByteArrayViewProfile::Id viewProfileId = viewProfile.id();
115
action->setData( viewProfileId );
116
if( viewProfileId == currentViewProfileId )
117
action->setChecked( true );
119
mViewProfilesActionGroup->addAction( action );
122
mGuiClient->plugActionList( QLatin1String("view_profile_list"), mViewProfilesActionGroup->actions() );
125
void ViewProfilesController::onViewProfileTriggered( QAction* action )
127
if( mByteArrayViewProfileSynchronizer )
128
mByteArrayViewProfileSynchronizer->setViewProfileId( action->data().toString() );