[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdevplatform/shell
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2009-11-15 15:42:21
Message-ID: 1258299741.021384.30574.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1049633 by apaku:

Make sessions more accessible.

Move the configure-sessions to a new toplevel menu and allow to
switch the session via an action list.

 M  +1 -0      CMakeLists.txt  
 A             kdevsessionui.rc  
 M  +5 -0      mainwindow.cpp  
 M  +0 -6      mainwindow_actions.cpp  
 M  +0 -6      mainwindow_p.cpp  
 M  +0 -1      mainwindow_p.h  
 M  +82 -16    sessioncontroller.cpp  
 M  +6 -1      sessioncontroller.h  


--- trunk/KDE/kdevplatform/shell/CMakeLists.txt #1049632:1049633
@@ -135,6 +135,7 @@
 install(TARGETS kdevplatformshell EXPORT KDevPlatformTargets \
${INSTALL_TARGETS_DEFAULT_ARGS} )  
 install( FILES debugger/kdevdebuggershellui.rc DESTINATION \
${DATA_INSTALL_DIR}/kdevdebugger ) +install( FILES kdevsessionui.rc DESTINATION \
${DATA_INSTALL_DIR}/kdevsession )  
 if(NOT WIN32)
    macro_optional_add_subdirectory(kross)
--- trunk/KDE/kdevplatform/shell/mainwindow.cpp #1049632:1049633
@@ -48,6 +48,7 @@
 #include "documentcontroller.h"
 #include "debugcontroller.h"
 #include "workingsetcontroller.h"
+#include "sessioncontroller.h"
 
 namespace KDevelop
 {
@@ -209,6 +210,10 @@
         d->addPlugin(plugin);
     
     guiFactory()->addClient(Core::self()->debugControllerInternal());
+    guiFactory()->addClient(Core::self()->sessionController());
+    // Needed to re-plug the actions from the sessioncontroller as xmlguiclients \
don't +    // seem to remember which actions where plugged in.
+    Core::self()->sessionController()->plugActions();
     d->setupGui();
 }
 
--- trunk/KDE/kdevplatform/shell/mainwindow_actions.cpp #1049632:1049633
@@ -159,12 +159,6 @@
     s_quitRequested = false;
 }
 
-void MainWindowPrivate::configureSessions()
-{
-    SessionDialog dlg(m_mainWindow);
-    dlg.exec();
-}
-
 void MainWindowPrivate::configureNotifications()
 {
     KNotifyConfigWidget::configure(m_mainWindow);
--- trunk/KDE/kdevplatform/shell/mainwindow_p.cpp #1049632:1049633
@@ -222,12 +222,6 @@
     action->setWhatsThis( QString( "<b>%1</b><p>%2</p>" ).arg( text ).arg(
                               i18n( "Lets you customize %1.", app ) ) );
 
-    action = actionCollection()->addAction( "configure_sessions", this, SLOT( \
                configureSessions() ) );
-    action->setText( i18n("Configure Sessions...") );
-    action->setToolTip( i18n("Create/Delete/Activate Sessions") );
-    action->setWhatsThis( i18n( "<b>Configure Sessions</b><p>Shows a dialog to \
                Create/Delete Sessions and set a new active session.</p>" ) );
-
-    
     action =  KStandardAction::configureNotifications(this, \
SLOT(configureNotifications()), actionCollection());  action->setText( \
i18n("Configure Notifications...") );  action->setToolTip( i18n("Configure \
                Notifications") );
--- trunk/KDE/kdevplatform/shell/mainwindow_p.h #1049632:1049633
@@ -104,7 +104,6 @@
 
     bool applicationQuitRequested() const;
 
-    void configureSessions();
     void configureNotifications();
     void showAboutPlatform();
     void showLoadedPlugins();
--- trunk/KDE/kdevplatform/shell/sessioncontroller.cpp #1049632:1049633
@@ -21,6 +21,7 @@
 
 #include <QtCore/QHash>
 #include <QtCore/QDir>
+#include <QtCore/QSignalMapper>
 #include <QtCore/QStringList>
 
 #include <kglobal.h>
@@ -30,10 +31,12 @@
 #include <klocale.h>
 #include <kio/netaccess.h>
 #include <kparts/mainwindow.h>
+#include <kactioncollection.h>
 
 #include "session.h"
 #include "core.h"
 #include "uicontroller.h"
+#include "sessiondialog.h"
 
 namespace KDevelop
 {
@@ -44,28 +47,82 @@
 class SessionControllerPrivate
 {
 public:
+    SessionControllerPrivate( SessionController* s ) : q(s) {}
     bool knownSession( const QString& name ) const
     {
         return findSessionForName( name ) != 0;
     }
     Session* findSessionForName( const QString& name ) const
     {
-        foreach( Session* s, availableSessions )
+        foreach( Session* s, sessionActions.keys() )
         {
             if( s->name() == name )
                 return s;
         }
         return 0;
     }
+    void configureSessions()
+    {
+        SessionDialog dlg(ICore::self()->uiController()-> activeMainWindow());
+        dlg.exec();
+    }
 
-    QList<Session*> availableSessions;
+    void activateSession( Session* s )
+    {
+        Q_ASSERT( s );
+        QHash<Session*,QAction*>::iterator it = sessionActions.find(s);
+        Q_ASSERT( it != sessionActions.end() );
+        (*it)->setChecked(true);
+        KConfigGroup grp = KGlobal::config()->group( \
SessionController::cfgSessionGroup ); +        grp.writeEntry( \
SessionController::cfgActiveSessionEntry, s->name() ); +        grp.sync();
+        activeSession = s;
+    }
+
+    void loadSessionFromAction( QAction* a )
+    {
+        foreach( Session* s, sessionActions.keys() )
+        {
+            if( s->id() == QUuid( a->data().toString() ) ) {
+                activateSession( s );
+                break;
+            }
+        }
+    }
+
+    void addSession( Session* s )
+    {
+        KAction* a = new KAction( grp );
+        a->setText( s->name() );
+        a->setCheckable( true );
+        a->setData( s->id().toString() );
+        sessionActions[s] = a;
+        q->actionCollection()->addAction( "session_"+s->id().toString(), a );
+        q->unplugActionList( "available_sessions" );
+        q->plugActionList( "available_sessions", grp->actions() );
+    }
+
+    QHash<Session*, QAction*> sessionActions;
     ISession* activeSession;
+    SessionController* q;
+    QActionGroup* grp;
 };
 
 SessionController::SessionController( QObject *parent )
-        : QObject( parent ), d(new SessionControllerPrivate)
+        : QObject( parent ), d(new SessionControllerPrivate(this))
 {
     setObjectName("SessionController");
+    setComponentData(KComponentData("kdevsession"));
+    
+    setXMLFile("kdevsessionui.rc");
+
+    KAction* action = actionCollection()->addAction( "configure_sessions", this, \
SLOT( configureSessions() ) ); +    action->setText( i18n("Configure Sessions...") );
+    action->setToolTip( i18n("Create/Delete/Activate Sessions") );
+    action->setWhatsThis( i18n( "<b>Configure Sessions</b><p>Shows a dialog to \
Create/Delete Sessions and set a new active session.</p>" ) ); +
+    d->grp = new QActionGroup( this );
+    connect( d->grp, SIGNAL(triggered(QAction*)), this, \
SLOT(loadSessionFromAction(QAction*)) );  }
 
 SessionController::~SessionController()
@@ -75,7 +132,7 @@
 
 void SessionController::cleanup()
 {
-    qDeleteAll(d->availableSessions);
+    qDeleteAll(d->sessionActions);
 }
 
 void SessionController::initialize()
@@ -87,7 +144,7 @@
         if( id.isNull() )
             continue;
         // Only create sessions for directories that represent proper uuid's
-        d->availableSessions << new Session( id );
+        d->addSession( new Session( id ) );
     }
     loadDefaultSession();
 }
@@ -100,18 +157,13 @@
 
 void SessionController::loadSession( const QString& name )
 {
-    Session * s = d->findSessionForName( name );
-    Q_ASSERT( s );
-    KConfigGroup grp = KGlobal::config()->group( cfgSessionGroup );
-    grp.writeEntry( cfgActiveSessionEntry, name );
-    grp.sync();
-    d->activeSession = s;
+    d->activateSession( d->findSessionForName( name ) );
 }
 
 QList<QString> SessionController::sessions() const
 {
     QStringList l;
-    foreach( const Session* s, d->availableSessions )
+    foreach( const Session* s, d->sessionActions.keys() )
     {
         l << s->name();
     }
@@ -122,7 +174,7 @@
 {
     Session* s = new Session( QUuid::createUuid() );
     s->setName( name );
-    d->availableSessions << s;
+    d->addSession( s );
     return s;
 }
 
@@ -130,13 +182,21 @@
 {
     Q_ASSERT( d->knownSession( name ) );
     Session* s  = d->findSessionForName( name );
+    QHash<Session*,QAction*>::iterator it = d->sessionActions.find(s);
+    Q_ASSERT( it != d->sessionActions.end() );
+
+    unplugActionList( "available_sessions" );
+    d->grp->removeAction(*it);
+    actionCollection()->removeAction(*it);
+    plugActionList( "available_sessions", d->grp->actions() );
+    (*it)->deleteLater();
     s->deleteFromDisk();
     emit sessionDeleted( name );
     if( s == d->activeSession ) 
     {
         loadDefaultSession();
     }
-    d->availableSessions.removeOne(s);
+    d->sessionActions.remove(s);
     s->deleteLater();
 }
 
@@ -144,7 +204,7 @@
 {
     KConfigGroup grp = KGlobal::config()->group( cfgSessionGroup );
     QString name = grp.readEntry( cfgActiveSessionEntry, "default" );
-    if( d->availableSessions.count() == 0 || !sessions().contains( name ) )
+    if( d->sessionActions.count() == 0 || !sessions().contains( name ) )
     {
         createSession( name );
     }  
@@ -169,11 +229,17 @@
                              KUrl( sessionDirectory() + '/' + id.toString() ), 
                              Core::self()->uiController()->activeMainWindow() );
     Session* newSession = new Session( id );
-    d->availableSessions << newSession;
     newSession->setName( i18n( "Copy of %1", origSession->name() ) );
+    d->addSession(newSession);
     return newSession->name();
 }
 
+void SessionController::plugActions()
+{
+    unplugActionList( "available_sessions" );
+    plugActionList( "available_sessions", d->grp->actions() );
 }
+
+}
 #include "sessioncontroller.moc"
 
--- trunk/KDE/kdevplatform/shell/sessioncontroller.h #1049632:1049633
@@ -22,6 +22,7 @@
 
 #include "shellexport.h"
 #include <QtCore/QObject>
+#include <kxmlguiclient.h>
 
 namespace KDevelop
 {
@@ -30,7 +31,7 @@
 class Session;
 class ISession;
 
-class KDEVPLATFORMSHELL_EXPORT SessionController : public QObject
+class KDEVPLATFORMSHELL_EXPORT SessionController : public QObject, public \
KXMLGUIClient  {
     Q_OBJECT
 public:
@@ -51,10 +52,14 @@
     static QString sessionDirectory();
     static const QString cfgSessionGroup;
     static const QString cfgActiveSessionEntry;
+
+    void plugActions();
 Q_SIGNALS:
     void sessionLoaded( ISession* );
     void sessionDeleted( const QString& );
 private:
+    Q_PRIVATE_SLOT( d, void configureSessions() )
+    Q_PRIVATE_SLOT( d, void loadSessionFromAction( QAction* ) )
     class SessionControllerPrivate* const d;
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic