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

view.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 "view.h"

#include "commands/commandmanager.h"
#include "data/datamanager.h"
#include "data/updatebatch.h"
#include "xmlui/builder.h"
#include "viewevent.h"

using namespace WebIssues;

00022 View::View( QObject* parent ) : QObject( parent ),
    m_mainWidget( NULL ),
    m_id( 0 ),
    m_access( UnknownAccess ),
    m_enabled( false ),
    m_updating( false )
{
    dataManager->addObserver( this );
}

00032 View::~View()
{
    if ( dataManager )
        dataManager->removeObserver( this );

    delete m_mainWidget;
}

00040 void View::setMainWidget( QWidget* widget )
{
    m_mainWidget = widget;
}

00045 void View::setViewerSizeHint( const QSize& size )
{
    m_sizeHint = size;
}

00050 void View::setAccess( Access access, bool initial )
{
    if ( initial || m_access != access ) {
        m_access = access;

        if ( ( initial || !m_enabled ) && ( access == NormalAccess || access == AdminAccess ) ) {
            m_enabled = true;
            enableView();
            emit enabledChanged( true );
            emit showInfo( tr( "OK" ) );
        } else if ( ( initial || m_enabled ) && ( access == UnknownAccess || access == NoAccess ) ) {
            m_enabled = false;
            emit enabledChanged( false );
            emit showSummary( QPixmap(), QString() );
            disableView();
        }

        if ( access == NormalAccess || access == AdminAccess ) {
            updateAccess( access );
            if ( builder() )
                builder()->rebuildAll();
        }

        if ( access == UnknownAccess )
            emit showWarning( tr( "Please wait until the data is updated" ) );
        else if ( access == NoAccess )
            emit showWarning( tr( "You don't have permissions to access this view" ) );
    }
}

00080 void View::enableView()
{
}

00084 void View::disableView()
{
}

00088 void View::updateAccess( Access access )
{
}

00092 void View::updateEvent( UpdateEvent* e )
{
}

00096 void View::viewEvent( ViewEvent* e )
{
}

00100 bool View::queryClose()
{
    return true;
}

void View::setCaption( const QString& text )
{
    m_caption = text;
    emit captionChanged( text );
}

void View::customEvent( QEvent* e )
{
    if ( e->type() == UpdateEvent::Type )
        updateEvent( (UpdateEvent*)e );
    else if ( e->type() == ViewEvent::Type )
        viewEvent( (ViewEvent*)e );
}

00119 void View::initialUpdate()
{
}

00123 void View::executeUpdate( UpdateBatch* batch )
{
    showBusy( tr( "Updating the view..." ) );

    connect( batch, SIGNAL( completed( bool ) ), this, SLOT( updateCompleted( bool ) ) );

    commandManager->execute( batch );

    m_updating = true;
}

void View::updateCompleted( bool successful )
{
    if ( successful )
        showInfo( tr( "Update successful" ) );
    else
        showWarning( commandManager->errorMessage( tr( "Update failed" ) ) );

    m_updating = false;
}

#include "view.moc"

Generated by  Doxygen 1.6.0   Back to index