1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
* Copyright 1999 by Martin R. Jones <mjones@kde.org>
* Copyright 2010 by Stefan Böhmann <kde@hilefoks.org>
*
* 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.
*
* 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "queueitem.h"
QueueItem::QueueItem(ItemType type, const QString &text, int time)
: m_type( type ),
m_text( text ),
m_time( time )
{
// if the time field was not given, calculate one based on the type
// and length of the item
int effectiveLength = 0;
int nesting = 0;
// discard html code from the length count
for(int i = 0; i < m_text.length(); ++i) {
if( m_text[i] == QLatin1Char( '<' ) ) {
nesting++;
}
else if( m_text[i] == QLatin1Char( '>' ) ) {
nesting--;
}
else if( !nesting ) {
effectiveLength++;
}
}
if( nesting ) { // malformed html
effectiveLength = m_text.length();
}
if( m_time == -1 ) {
switch( m_type ) {
case Talk: // shorter times
m_time = 1500 + 45 * effectiveLength;
break;
case Tip: // longer times
m_time = 4000 + 30 * effectiveLength;
break;
}
}
}
QueueItem::ItemType QueueItem::type()
{
return m_type;
}
QString QueueItem::text()
{
return m_text;
}
int QueueItem::time()
{
return m_time;
}
void QueueItem::setTime(int newTime)
{
if( m_time > 0 ) {
m_time = newTime;
}
}
// 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;
// vim:set spell et sw=4 ts=4 nowrap cino=l1,cs,U1:
|