summaryrefslogtreecommitdiffstats
path: root/quanta/messages/messageitem.cpp
blob: 7f906041a2d82fbe83a98305fdb917993a5fed1d (plain)
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
90
91
92
/***************************************************************************
                          messageoutput.cpp  -  description
                             -------------------
    begin                : Jan 12 2001
    copyright            : (C) 2001 by Dmitry Poplavsky <dima@kde.org>
                           (C) 2002-2005 Andras Mantia <amantia@kde.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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "messageitem.h"
#include <qregexp.h>
#include <klocale.h>

MessageItem::MessageItem( QListBox * listbox, const QString &text, int line, int column, const QString &fname )
  :QListBoxText(listbox,text),lineNumber(line),columnNumber(column),filename(fname)
{
}

int MessageItem::line()
{
  if ( lineNumber != -1 ) {
    return lineNumber;
  }
  else {  // try to find first number in text
    QString s = text();
    int pos = s.find( QRegExp("[0-9]"));
    if ( pos == -1 )
      return lineNumber;
    int pos2 = pos;
    while ( s[pos2].isDigit() ) pos2++;

    QString snum = s.mid(pos, pos2-pos);
    return snum.toInt();

  }
}

int MessageItem::column()
{
  if (columnNumber != -1) 
  {
    return columnNumber;
  } else
  {
    QString s = text();
    QRegExp exp("(?:\\D|^)(\\d{1,4})(?:\\D|$)");
  
    int pos = exp.search(s);
    if ( pos == -1 )
      return 0;
    pos = exp.search(s, pos + exp.cap(1).length());
    if ( pos == -1 )
      return 0;
    s = exp.cap(1);
    return s.toInt();
  }
}

QString MessageItem::fileName()
{
  if (filename.isEmpty())
  {
    QString fname;
    QString s = text();
    int pos = s.find(i18n("File: "));
    if (pos != -1)
    {
      int pos2 = s.find(i18n(", "), pos);
      if (pos2 != -1)
        fname = s.mid(pos, pos2-pos);
      else
        fname = s.mid(pos);  
      fname.remove(i18n("File: "));
    }
    return fname;
  } else
  return filename;
}

void MessageItem::addText(const QString &t)
{
   setText( text() + t );
}