Logo Search packages:      
Sourcecode: webissues version File versions  Download package

viewmanager.cpp

/**************************************************************************
* This file is part of the WebIssues program
* Copyright (C) 2006 Michał Męciński
* Copyright (C) 2007 WebIssues Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
**************************************************************************/

#include "viewmanager.h"

#include <QApplication>

#include "views/view.h"
#include "views/issueview.h"
#include "views/viewfactory.h"
#include "viewerwindow.h"

using namespace WebIssues;

00023 ViewManager* WebIssues::viewManager = NULL;

00025 ViewManager::ViewManager()
{
}

00029 ViewManager::~ViewManager()
{
    QList<ViewerWindow*> windows = m_views.values();

    for ( uint i = 0; i < windows.count(); i++ ) {
        ViewerWindow* window = windows.at( i );
        delete window;
    }
}

00039 void ViewManager::openTypesView()
{
    openView( "WebIssues::TypesView", 0 );
}

00044 void ViewManager::openUsersView()
{
    openView( "WebIssues::UsersView", 0 );
}

00049 void ViewManager::openFolderView( int folderId )
{
    openView( "WebIssues::FolderView", folderId );
}

00054 void ViewManager::openIssueView( int issueId, int itemId )
{
    IssueView* view = (IssueView*)openView( "WebIssues::IssueView", issueId );
    if ( itemId != 0 )
        view->gotoItem( itemId );
}

00061 void ViewManager::openMembersView( int projectId )
{
    openView( "WebIssues::MembersView", projectId );
}

00066 void ViewManager::openCommentView( int issueId )
{
    openView( "WebIssues::CommentView", issueId );
}

00071 bool ViewManager::queryCloseViews()
{
    QList<View*> views = m_views.keys();

    for ( uint i = 0; i < views.count(); i++ ) {
        View* view = views.at( i );
        if ( !view->queryClose() )
            return false;
    }

    return true;
}

00084 void ViewManager::postViewEvent( const char* className, ViewEvent::Action action, int id )
{
    QList<View*> views = m_views.keys();

    for ( uint i = 0; i < views.count(); i++ ) {
        View* view = views.at( i );
        if ( !className || view->inherits( className ) ) {
            ViewEvent* viewEvent = new ViewEvent( action, id );
            QApplication::postEvent( view, viewEvent );
        }
    }
}

00097 void ViewManager::activateView( View* view )
{
    ViewerWindow* window = m_views.value( view, NULL );
    if ( !window )
        return;

    window->raise();
    window->activateWindow();
}

00107 void ViewManager::closeView( View* view )
{
    ViewerWindow* window = m_views.value( view, NULL );
    if ( !window )
        return;

    window->deleteLater();
}

View* ViewManager::openView( const char* className, int id )
{
    View* view = findView( className, id );
    if ( view ) {
        activateView( view );
        return view;
    }
    return createView( className, id );
}

View* ViewManager::findView( const char* className, int id )
{
    QList<View*> views = m_views.keys();

    for ( uint i = 0; i < views.count(); i++ ) {
        View* view = views.at( i );
        if ( view->inherits( className ) ) {
            if ( id == 0 || view->id() == id )
                return view;
        }
    }
    return NULL;
}

View* ViewManager::createView( const char* className, int id )
{
    ViewerWindow* window = new ViewerWindow();
    View* view = ViewFactory::createView( className, window, window );

    m_views.insert( view, window );
    connect( view, SIGNAL( destroyed( QObject* ) ), this, SLOT( viewDestroyed( QObject* ) ) );

    view->setId( id );
    window->setView( view );

    view->initialUpdate();
    window->show();

    return view;
}

void ViewManager::viewDestroyed( QObject* view )
{
    m_views.remove( (View*)view );
}

#include "viewmanager.moc"

Generated by  Doxygen 1.6.0   Back to index