summaryrefslogtreecommitdiffstats
path: root/src/parsers/list.cpp
blob: 3010b86180b724b3f218bda327970918cd26d2bb (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
/***************************************************************************
 *   Copyright (C) 2003 by Sylvain Joyeux                                  *
 *   [email protected]                                                *
 *                                                                         *
 *   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 "parsers.h"
#include "../apt.h"

#include <tdeio/slavebase.h>
#include <tdelocale.h>
#include <tqregexp.h>
#include <kurl.h>

namespace Parsers
{
  List::List(bool links)
    : m_links(links) {}

  /** Parses the tokens sent by PackageManager::list */
  void List::operator() (AptProtocol* slave, const TQString& tag, const TQString& value )
  {
    static TQRegExp rx_manpage("/man/.*\\.\\d[^/]*$");

    static TQStringList files;

    if (tag == "begin")
    {
      m_result_count = 0;
    }
    else if (tag == "error")
    {
      *slave << "<div class=\"error\">" + value + "</div>";
    }
    else if (tag == "file" && value != "/.")
    {
      if (m_links)
      {
        KURL url;
        if (rx_manpage.search(value) >= 0)
          url.setProtocol("man");
        else
          url.setProtocol("file");

        url.setPath(value);

        files += "<a href=\"" + url.htmlURL() + "\">" + value + "</a>";
      }
      else
      {
        files += value;
      }

      ++m_result_count;
    }
    else if (tag == "end")
    {
      files.sort();
      *slave <<
      	"<div class=\"filelist\">\n" + files.join("\n<br>") + "\n</div>\n"
        "<div class=\"footer\">" + i18n("%1 files in the package").arg(result_count()) + "</div>\n";
      files.clear();
    }
  }
}