From ea4406b4779306f4d0c65f0619cd8241bbdcef7b Mon Sep 17 00:00:00 2001
From: tpearson
Date: Wed, 10 Feb 2010 20:23:29 +0000
Subject: Added abandoned version of kio-apt
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kio-apt@1088432 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
---
src/parsers/show.cpp | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 194 insertions(+)
create mode 100644 src/parsers/show.cpp
(limited to 'src/parsers/show.cpp')
diff --git a/src/parsers/show.cpp b/src/parsers/show.cpp
new file mode 100644
index 0000000..0a1c503
--- /dev/null
+++ b/src/parsers/show.cpp
@@ -0,0 +1,194 @@
+/***************************************************************************
+ * Copyright (C) 2003 by Sylvain Joyeux *
+ * sylvain.joyeux@m4x.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 "parsers.h"
+#include "../apt.h"
+
+#include
+#include
+
+static const QString
+ html_attribute_begin("%1 | \n\t\n\t\t"),
+ html_attribute_classed(" |
%2 | \n\t\n\t\t"),
+ html_attribute_end("\n\t | \n
\n");
+
+// Converts the special chars in orig into its HTML equivalents
+static QString text2html(const QString& orig)
+{ QString ret(orig);
+ ret = ret.replace("<(?!a href)", "<");
+ //ret = ret.replace( QRegExp("\n"), "
\n");
+ return ret;
+}
+
+static void close_indent(int indent, QString& buffer)
+{
+ if (buffer.isEmpty()) return;
+ if (indent)
+ buffer += "\n\t\t";
+}
+static void close_item(int indent, QString& buffer)
+{
+ if (buffer.isEmpty()) return;
+ close_indent(indent, buffer);
+ buffer += html_attribute_end;
+}
+
+static void close_table(const QString& version, int indent, QString& buffer)
+{
+ if (buffer.isEmpty()) return;
+ close_item(indent, buffer);
+ buffer = version + "\n";
+}
+
+static QString version_header_link(const KURL& url, const QString& name)
+{ return QString("\t" + name + "\n"); }
+
+namespace Parsers
+{
+
+Show::Show(const QString& package, const QString& installed_version, bool act)
+ : m_package(package), m_installed(installed_version), m_act(false)
+{
+ m_act = act;
+}
+
+void Show::operator() (AptProtocol* slave, const QString& tag, const QString& value)
+{
+ // Since we want to show the version first, we should wait for it
+ // before sending anything
+ static QString version;
+ static QString buffer;
+ static QString attribute;
+ static int indent;
+ static bool multiline = false;
+ static bool first_line = false, new_paragraph = true;
+
+ if (tag == "begin" || tag == "package" || tag == "end")
+ {
+ if (multiline && !new_paragraph)
+ buffer += "
";
+
+ if (tag == "begin")
+ m_result_count = 0;
+ else
+ {
+ m_result_count += (tag == "package");
+
+ close_table(version, indent, buffer);
+ if (!buffer.isEmpty()) *slave << buffer;
+ }
+
+ // init the state variables for the next package
+ buffer = "";
+ indent = 0;
+ first_line = false;
+ new_paragraph = true;
+ }
+ else if (tag == "field")
+ {
+ if (multiline && !new_paragraph)
+ buffer += "";
+
+ attribute = value;
+ if (value == "Depends" || value == "Description")
+ {
+ close_item(indent, buffer);
+ buffer +=
+ html_attribute_begin.arg(value)
+ + " ";
+
+ close_item(indent, buffer);
+ buffer += html_attribute_begin.arg(" ");
+ }
+ else if (value != "Version" && value != "Package")
+ {
+ close_item(indent, buffer);
+ buffer += html_attribute_begin.arg(value);
+ }
+
+ if (value == "Description")
+ {
+ multiline = true;
+ new_paragraph = true;
+ first_line = true;
+ }
+ else
+ {
+ multiline = false;
+ }
+ }
+ else if (tag == "indent")
+ {
+ close_indent(indent, buffer);
+
+ int new_indent = value.toInt();
+ if (new_indent)
+ buffer += "\n\t";
+ indent = new_indent;
+ }
+ else if (tag == "data" && attribute == "Version")
+ {
+ KURL action ("apt:/get");
+
+ QString item_id = mangle_version(value);
+ if (value == m_installed)
+ {
+ action.setQuery("remove");
+ version = QString("