~ubuntu-branches/ubuntu/vivid/kdesdk/vivid

« back to all changes in this revision

Viewing changes to okteta/kasten/controllers/view/viewprofiles/viewprofilescontroller.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-14 15:11:09 UTC
  • mfrom: (0.4.22)
  • Revision ID: package-import@ubuntu.com-20120614151109-t9h5vc8qga2sz5yo
Tags: 4:4.8.90-0ubuntu1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of the Okteta Kasten module, made within the KDE community.
3
 
 
4
 
    Copyright 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 "viewprofilescontroller.h"
24
 
 
25
 
// controller
26
 
#include "viewprofileeditdialog.h"
27
 
// Okteta Gui Kasten
28
 
#include <bytearrayviewprofilemanager.h>
29
 
#include <bytearrayviewprofilesynchronizer.h>
30
 
#include <bytearrayview.h>
31
 
// KDE
32
 
#include <KXMLGUIClient>
33
 
#include <KLocale>
34
 
#include <KAction>
35
 
 
36
 
 
37
 
namespace Kasten2
38
 
{
39
 
 
40
 
ViewProfilesController::ViewProfilesController( KXMLGUIClient* guiClient,
41
 
                                                ByteArrayViewProfileManager* viewProfileManager,
42
 
                                                QWidget* parentWidget )
43
 
  : mGuiClient( guiClient )
44
 
  , mViewProfileManager( viewProfileManager )
45
 
  , mParentWidget( parentWidget )
46
 
  , mByteArrayView( 0 )
47
 
  , mByteArrayViewProfileSynchronizer( 0 )
48
 
{
49
 
    mViewProfilesActionGroup = new QActionGroup( this );
50
 
    mViewProfilesActionGroup->setExclusive( true );
51
 
    connect( mViewProfilesActionGroup, SIGNAL(triggered(QAction*)),
52
 
             SLOT(onViewProfileTriggered(QAction*)) );
53
 
 
54
 
    connect( mViewProfileManager, SIGNAL(viewProfilesChanged(QList<Kasten2::ByteArrayViewProfile>)),
55
 
             SLOT(onViewProfilesChanged()) );
56
 
    connect( mViewProfileManager, SIGNAL(viewProfilesRemoved(QList<Kasten2::ByteArrayViewProfile::Id>)),
57
 
             SLOT(onViewProfilesChanged()) );
58
 
 
59
 
    onViewProfilesChanged();
60
 
 
61
 
    setTargetModel( 0 );
62
 
}
63
 
 
64
 
void ViewProfilesController::setTargetModel( AbstractModel* model )
65
 
{
66
 
    if( mByteArrayViewProfileSynchronizer )
67
 
        mByteArrayViewProfileSynchronizer->disconnect( this );
68
 
 
69
 
    mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0;
70
 
    mByteArrayViewProfileSynchronizer = mByteArrayView ? mByteArrayView->synchronizer() : 0;
71
 
 
72
 
    const bool hasSynchronizer = ( mByteArrayViewProfileSynchronizer != 0 );
73
 
    if( hasSynchronizer )
74
 
    {
75
 
        onViewProfileChanged( mByteArrayViewProfileSynchronizer->viewProfileId() );
76
 
 
77
 
        connect( mByteArrayViewProfileSynchronizer, SIGNAL(viewProfileChanged(Kasten2::ByteArrayViewProfile::Id)),
78
 
                 SLOT(onViewProfileChanged(Kasten2::ByteArrayViewProfile::Id)) );
79
 
    }
80
 
 
81
 
    mViewProfilesActionGroup->setEnabled( hasSynchronizer );
82
 
}
83
 
 
84
 
void ViewProfilesController::onViewProfileChanged( const Kasten2::ByteArrayViewProfile::Id& viewProfileId )
85
 
{
86
 
    const QList<QAction*> actions = mViewProfilesActionGroup->actions();
87
 
 
88
 
    foreach( QAction* action, actions )
89
 
    {
90
 
        if( action->data().toString() == viewProfileId )
91
 
        {
92
 
            action->setChecked( true );
93
 
            break;
94
 
        }
95
 
    }
96
 
}
97
 
 
98
 
void ViewProfilesController::onViewProfilesChanged()
99
 
{
100
 
    mGuiClient->unplugActionList( QLatin1String("view_profile_list") );
101
 
 
102
 
    qDeleteAll( mViewProfilesActionGroup->actions() );
103
 
 
104
 
    const QList<ByteArrayViewProfile> viewProfiles = mViewProfileManager->viewProfiles();
105
 
    const ByteArrayViewProfile::Id currentViewProfileId = mByteArrayViewProfileSynchronizer ?
106
 
        mByteArrayViewProfileSynchronizer->viewProfileId() :
107
 
        ByteArrayViewProfile::Id();
108
 
 
109
 
    foreach( const ByteArrayViewProfile& viewProfile, viewProfiles )
110
 
    {
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 );
118
 
 
119
 
        mViewProfilesActionGroup->addAction( action );
120
 
    }
121
 
 
122
 
    mGuiClient->plugActionList( QLatin1String("view_profile_list"), mViewProfilesActionGroup->actions() );
123
 
}
124
 
 
125
 
void ViewProfilesController::onViewProfileTriggered( QAction* action )
126
 
{
127
 
    if( mByteArrayViewProfileSynchronizer )
128
 
        mByteArrayViewProfileSynchronizer->setViewProfileId( action->data().toString() );
129
 
}
130
 
 
131
 
}