Beispiel #1
0
void ControllerTests::initTestCase ()
{
    QFileInfo file( m_localPath );
    if ( file.exists() ) {
        qDebug() << "test database file exists, deleting";
        QDir dir( file.absoluteDir() );
        QVERIFY( dir.remove( file.fileName() ) );
    }

    m_configuration.installationId = 1;
    m_configuration.user.setId( 1 );
    m_configuration.localStorageType = CHARM_SQLITE_BACKEND_DESCRIPTOR;
    m_configuration.localStorageDatabase = m_localPath;
    m_configuration.newDatabase = true;
    auto controller = new Controller;
    m_controller = controller;
//    connect( controller, SIGNAL(currentEvents(EventList)),
//             SLOT(slotCurrentEvents(EventList)) );
    connect( controller, SIGNAL(definedTasks(TaskList)),
             SLOT(slotDefinedTasks(TaskList)) );
    connect( controller, SIGNAL(taskAdded(Task)),
             SLOT(slotTaskAdded(Task)) );
    connect( controller, SIGNAL(taskUpdated(Task)),
             SLOT(slotTaskUpdated(Task)) );
    connect( controller, SIGNAL(taskDeleted(Task)),
             SLOT(slotTaskDeleted(Task)) );
}
Beispiel #2
0
bool Controller::setAllTasks( const TaskList& tasks )
{
    qDebug() << Q_FUNC_INFO << "replacing all tasks";
    if ( m_storage->setAllTasks( CONFIGURATION.user, tasks ) ) {
        const TaskList newTasks = m_storage->getAllTasks();
        // tell the view about the existing tasks;
        emit definedTasks( newTasks );
        return true;
    } else {
        return false;
    }
}
Beispiel #3
0
void connectControllerAndModel( Controller* controller, CharmDataModel* model )
{
    QObject::connect( controller, SIGNAL(eventAdded(Event)),
                      model, SLOT(addEvent(Event)) );
    QObject::connect( controller, SIGNAL(eventModified(Event)),
                      model, SLOT(modifyEvent(Event)) );
    QObject::connect( controller, SIGNAL(eventDeleted(Event)),
                      model, SLOT(deleteEvent(Event)) );
    QObject::connect( controller, SIGNAL(allEvents(EventList)),
                      model, SLOT(setAllEvents(EventList)) );
    QObject::connect( controller, SIGNAL(definedTasks(TaskList)),
                      model, SLOT(setAllTasks(TaskList)) );
    QObject::connect( controller, SIGNAL(taskAdded(Task)),
                      model, SLOT(addTask(Task)) );
    QObject::connect( controller, SIGNAL(taskUpdated(Task)),
                      model, SLOT(modifyTask(Task)) );
    QObject::connect( controller, SIGNAL(taskDeleted(Task)),
                      model, SLOT(deleteTask(Task)) );
}
Beispiel #4
0
void Controller::stateChanged( State previous, State next )
{
    Q_UNUSED( previous );

    switch( next ) {
    case Connected:
    {   // yes, it is that simple:
        TaskList tasks = m_storage->getAllTasks();
        // tell the view about the existing tasks;
        if ( ! Task::checkForUniqueTaskIds( tasks ) ) {
            throw CharmException( tr( "The Charm database is corrupted, it contains duplicate task ids. "
                                      "Please have it looked after by a professional." ) );
        }
        if ( ! Task::checkForTreeness( tasks ) ) {
            throw CharmException( tr( "The Charm database is corrupted, the tasks do not form a tree. "
                                      "Please have it looked after by a professional." ) );
        }
        emit definedTasks( tasks );
        EventList events = m_storage->getAllEvents();
        emit allEvents( events );
    }
    break;
    case Disconnecting:
    {
        emit readyToQuit();
        if ( m_storage ) {
// this will still leave Qt complaining about a repeated connection
//         qDebug() << "Application::enterConnectingState: closing existing storage interface";
            m_storage->disconnect();
            delete m_storage;
            m_storage = nullptr;
        }
    }
    break;
    default:
        break;
    };

    if ( m_storage ) {
        emit currentBackendStatus( m_storage->description() );
        m_storage->stateChanged( previous );
    }
}