File indexing completed on 2024-04-28 04:01:26
0001 /* 0002 * Copyright 1999 by Martin R. Jones <mjones@kde.org> 0003 * Copyright 2010 by Stefan Böhmann <kde@hilefoks.org> 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program; if not, write to the Free Software 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 #include "queueitem.h" 0020 0021 0022 QueueItem::QueueItem(ItemType type, const QString &text, int time) 0023 : m_type( type ), 0024 m_text( text ), 0025 m_time( time ) 0026 { 0027 // if the time field was not given, calculate one based on the type 0028 // and length of the item 0029 int effectiveLength = 0; 0030 int nesting = 0; 0031 0032 // discard html code from the length count 0033 for(int i = 0; i < m_text.length(); ++i) { 0034 if( m_text[i] == QLatin1Char( '<' ) ) { 0035 nesting++; 0036 } 0037 else if( m_text[i] == QLatin1Char( '>' ) ) { 0038 nesting--; 0039 } 0040 else if( !nesting ) { 0041 effectiveLength++; 0042 } 0043 } 0044 0045 if( nesting ) { // malformed html 0046 effectiveLength = m_text.length(); 0047 } 0048 0049 if( m_time == -1 ) { 0050 switch( m_type ) { 0051 case Talk: // shorter times 0052 m_time = 1500 + 45 * effectiveLength; 0053 break; 0054 case Tip: // longer times 0055 m_time = 4000 + 30 * effectiveLength; 0056 break; 0057 } 0058 } 0059 } 0060 0061 0062 QueueItem::ItemType QueueItem::type() 0063 { 0064 return m_type; 0065 } 0066 0067 0068 QString QueueItem::text() 0069 { 0070 return m_text; 0071 } 0072 0073 0074 int QueueItem::time() 0075 { 0076 return m_time; 0077 } 0078 0079 0080 void QueueItem::setTime(int newTime) 0081 { 0082 if( m_time > 0 ) { 0083 m_time = newTime; 0084 } 0085 } 0086 0087 0088 // kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; replace-tabs on; space-indent on; 0089 // vim:set spell et sw=4 ts=4 nowrap cino=l1,cs,U1: