1 /* This file is part of KDevelop
2 Copyright 2008 Anreas Pakulat <apaku@gmx.de>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "sessioncontroller.h"
22 #include <QtCore/QHash>
29 class SessionControllerPrivate
32 QHash
<QString
,Session
*> availableSessions
;
33 ISession
* activeSession
;
36 SessionController::SessionController( QObject
*parent
)
37 : QObject( parent
), d(new SessionControllerPrivate
)
41 SessionController::~SessionController()
45 void SessionController::cleanup()
47 qDeleteAll(d
->availableSessions
);
50 void SessionController::initialize()
55 ISession
* SessionController::activeSession() const
57 return d
->activeSession
;
60 void SessionController::loadSession( const QString
& name
)
62 Q_ASSERT( d
->availableSessions
.contains( name
) );
63 d
->activeSession
= d
->availableSessions
[name
];
66 QList
<QString
> SessionController::sessions() const
68 return d
->availableSessions
.keys();
71 void SessionController::createSession( const QString
& name
)
73 Q_ASSERT( !d
->availableSessions
.contains( name
) );
74 Session
* s
= new Session( name
);
75 d
->availableSessions
.insert(name
, s
);
78 void SessionController::deleteSession( const QString
& name
)
80 Q_ASSERT( d
->availableSessions
.contains( name
) );
81 Session
* s
= d
->availableSessions
[ name
];
83 emit
sessionDeleted( name
);
84 if( s
== d
->activeSession
) {
87 d
->availableSessions
.remove(name
);
91 void SessionController::loadDefaultSession()
94 if( d
->availableSessions
.count() == 0 )
97 createSession( name
);
100 name
= sessions().at(0);
106 #include "sessioncontroller.moc"