/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * 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, or (at your option) * any later version. * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" /* * Represents a line in a subtitle script. */ /* * Initializes an empty line. */ kryEvent::kryEvent() : kryObject(kryEvent::SIGNAL_COUNT) { this->m_start = 0; this->m_end = 0; this->m_type = kryEvent::EVENT_DIALOG; this->m_type_sub = EVENT_BLANK; this->m_text = NULL; } /* * Destroys the line */ kryEvent::~kryEvent() { if(this->m_text) kry_free(this->m_text); } /* * Returns the start time of this event. */ unsigned long kryEvent::GetStart() { return this->m_start; } unsigned long kryEvent::GetStartStatic(kryEvent *event) { return event->GetStart(); } /* * Returns the end time of this event. */ unsigned long kryEvent::GetEnd() { return this->m_end; } unsigned long kryEvent::GetEndStatic(kryEvent *event) { return event->GetEnd(); } /* * Sets the time of the event. */ void kryEvent::SetTime(unsigned long start, unsigned long end) { if(start < 0 || end < 0) { g_warning("attempt to set a negative time on the event"); return; } if(start != this->GetStart() || end != this->GetEnd()) { this->InvokeSignal(kryEvent::SIGNAL_BEFORE_TIME_CHANGED, NULL); this->m_start = start; this->m_end = end; this->InvokeSignal(kryEvent::SIGNAL_AFTER_TIME_CHANGED, NULL); } } void kryEvent::SetStartStatic(kryEvent *event, int time) { event->m_start = time; } void kryEvent::SetStart(int time) { this->m_start = time; } void kryEvent::SetEndStatic(kryEvent *event, int time) { event->m_end = time; } void kryEvent::SetEnd(int time) { this->m_end = time; } /* * Set the type of the event. */ void kryEvent::SetType(enum event_type type) { this->m_type = type; } void kryEvent::SetTypeStatic(kryEvent *event, enum event_type type) { event->SetType(type); } /* * Returns the type of the event. */ enum kryEvent::event_type kryEvent::GetType() { return this->m_type; } enum kryEvent::event_type kryEvent::GetTypeStatic(kryEvent *event) { return event->GetType(); } /* * Sets the sub type of the event. */ void kryEvent::SetTypeSub(enum event_type type) { this->m_type_sub = type; } /* * Returns a textual representation of the given event type. * The result must be freed. */ char *kryEvent::GetTypeString(enum event_type type) { if(type == EVENT_DIALOG) return kry_strdup("Dialogue"); else if(type == EVENT_COMMENT_DIALOG) return kry_strdup("Comment"); else if(type == EVENT_BLANK) return kry_strdup("Blank"); else return kry_strdup("Error"); } /* * Returns a textual representation of teh type of this event. */ char *kryEvent::GetTypeString() { return GetTypeString(this->GetType()); } char *kryEvent::GetTypeSubString() { return GetTypeString(this->GetTypeSub()); } /* * Returns the sub type of the event. */ enum kryEvent::event_type kryEvent::GetTypeSub() { return this->m_type_sub; } /* * Set the text of the event. */ void kryEvent::SetText(char *text) { if(!text) { g_warning("Attempt to set NULL text."); return; } if(this->m_text) kry_free(this->m_text); this->m_text = kry_strdup(text); } void kryEvent::SetTextStatic(kryEvent *event, char *text) { event->SetText(text); } /* * Get the text of the event. */ char *kryEvent::GetText() { return this->m_text; } char *kryEvent::GetTextStatic(kryEvent *event) { return event->GetText(); } /* * Returns the index (in the script) of this event. */ int kryEvent::GetIndex() { return this->m_index; } /* * Sets the index (in the script) of this event. */ void kryEvent::SetIndex(int index) { this->m_index = index; } /* * Makes a copy of the event list. * NOTE: The copy does not have any signals connected. */ kryEvent *kryEvent::Copy() { kryEvent *new_event = new kryEvent(); if(new_event->m_text) kry_free(new_event->m_text); *new_event = *this; new_event->m_text = NULL; new_event->SetText(this->GetText()); return new_event; } gboolean kryEvent::IsDetailed() { return FALSE; }