diff options
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/changelog_parse.cc | 4 | ||||
-rw-r--r-- | src/cmdline/cmdline_show.cc | 2 | ||||
-rw-r--r-- | src/desc_render.cc | 162 | ||||
-rw-r--r-- | src/desc_render.h | 67 | ||||
-rw-r--r-- | src/generic/apt/Makefile.am | 2 | ||||
-rw-r--r-- | src/generic/apt/desc_parse.cc (renamed from src/desc_parse.cc) | 132 | ||||
-rw-r--r-- | src/generic/apt/desc_parse.h (renamed from src/desc_parse.h) | 31 | ||||
-rw-r--r-- | src/pkg_info_screen.cc | 2 | ||||
-rw-r--r-- | src/pkg_view.cc | 2 |
10 files changed, 240 insertions, 168 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8ad0d9fc..9a182483 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,8 +14,8 @@ LDADD=@LIBINTL@ cmdline/libcmdline.a mine/libcmine.a \ aptitude_SOURCES= \ aptitude.h \ main.cc \ - desc_parse.cc \ - desc_parse.h \ + desc_render.cc \ + desc_render.h \ apt_config_treeitems.cc \ apt_config_treeitems.h \ apt_config_widgets.cc \ diff --git a/src/changelog_parse.cc b/src/changelog_parse.cc index e90ca93d..43c997a9 100644 --- a/src/changelog_parse.cc +++ b/src/changelog_parse.cc @@ -1,6 +1,6 @@ // changelog_parse.cc // -// Copyright (C) 2005 Daniel Burrows +// Copyright (C) 2005, 2008 Daniel Burrows // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -22,7 +22,7 @@ #include "changelog_parse.h" -#include "desc_parse.h" +#include "desc_render.h" #include <apt-pkg/fileutl.h> #include <apt-pkg/pkgsystem.h> diff --git a/src/cmdline/cmdline_show.cc b/src/cmdline/cmdline_show.cc index 3fcbe130..297463ed 100644 --- a/src/cmdline/cmdline_show.cc +++ b/src/cmdline/cmdline_show.cc @@ -5,7 +5,7 @@ #include "cmdline_show.h" #include <aptitude.h> -#include <desc_parse.h> +#include <desc_render.h> #include "cmdline_common.h" #include "cmdline_util.h" diff --git a/src/desc_render.cc b/src/desc_render.cc new file mode 100644 index 00000000..0b0b0ef9 --- /dev/null +++ b/src/desc_render.cc @@ -0,0 +1,162 @@ +// desc_parse.cc +// +// Copyright 2004-2008 Daniel Burrows +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. +// +// Parses a description into a cw::fragment. + +#include "desc_render.h" + +#include "aptitude.h" +#include "ui.h" + +#include <generic/apt/apt.h> +#include <generic/apt/config_signal.h> +#include <generic/apt/tags.h> + +#include <cwidget/fragment.h> +#include <cwidget/generic/util/transcode.h> +#include <cwidget/config/colors.h> + +using namespace std; + +namespace cw = cwidget; + +namespace aptitude +{ + namespace + { + cw::fragment *make_desc_fragment(const std::vector<description_element_ref> &elements, + int level) + { + std::vector<cw::fragment *> fragments; + + for(std::vector<description_element_ref>::const_iterator it = elements.begin(); + it != elements.end(); ++it) + { + const description_element_ref &elt(*it); + + switch(elt->get_type()) + { + case description_element::blank_line: + fragments.push_back(cw::newline_fragment()); + break; + case description_element::paragraph: + fragments.push_back(wrapbox(cw::text_fragment(elt->get_string()))); + break; + case description_element::literal: + fragments.push_back(cw::hardwrapbox(cw::text_fragment(elt->get_string()))); + break; + case description_element::bullet_list: + { + wstring bullet; + bullet.push_back(L"*+-"[level%3]); + + cw::fragment *item_contents(make_desc_fragment(elt->get_elements(), + level + 1)); + + fragments.push_back(cw::style_fragment(cw::text_fragment(bullet), + cw::get_style("Bullet"))); + fragments.push_back(cw::indentbox(1, + (level + 1) * 2, + item_contents)); + } + break; + } + } + + return cw::sequence_fragment(fragments); + } + } + + cw::fragment *make_desc_fragment(const std::vector<description_element_ref> &elements) + { + return make_desc_fragment(elements, 0); + } +} + +cw::fragment *make_desc_fragment(const wstring &desc) +{ + std::vector<aptitude::description_element_ref> elements; + aptitude::parse_desc(desc, elements); + + return aptitude::make_desc_fragment(elements); +} + + +cw::fragment *make_tags_fragment(const pkgCache::PkgIterator &pkg) +{ + if(pkg.end()) + return NULL; + +#ifdef HAVE_EPT + typedef ept::debtags::Tag tag; + using aptitude::apt::get_tags; +#endif + +#ifdef HAVE_EPT + const set<tag> realS(get_tags(pkg)); + const set<tag> * const s(&realS); +#else + const set<tag> * const s(get_tags(pkg)); +#endif + + vector<cw::fragment *> rval; + if(s != NULL && !s->empty()) + { + vector<cw::fragment *> tags; + for(set<tag>::const_iterator i = s->begin(); i != s->end(); ++i) + { +#ifdef HAVE_EPT + std::string name(i->fullname()); +#else + const std::string name(i->str()); +#endif + + tags.push_back(cw::text_fragment(name, cw::style_attrs_on(A_BOLD))); + } + + wstring tagstitle = W_("Tags"); + + rval.push_back(cw::fragf("%ls: %F", + tagstitle.c_str(), + indentbox(0, wcswidth(tagstitle.c_str(), tagstitle.size())+2, + wrapbox(cw::join_fragments(tags, L", "))))); + } + + typedef aptitudeDepCache::user_tag user_tag; + const set<user_tag> &user_tags((*apt_cache_file)->get_ext_state(pkg).user_tags); + if(!user_tags.empty()) + { + vector<cw::fragment *> tags; + for(set<user_tag>::const_iterator it = user_tags.begin(); + it != user_tags.end(); ++it) + { + tags.push_back(cw::text_fragment((*apt_cache_file)->deref_user_tag(*it), + cw::style_attrs_on(A_BOLD))); + } + + wstring title = W_("User Tags"); + rval.push_back(dropbox(cw::fragf("%ls: ", title.c_str()), + wrapbox(cw::join_fragments(tags, L", ")))); + } + + if(!rval.empty()) + return cw::join_fragments(rval, L"\n"); + else + return NULL; +} diff --git a/src/desc_render.h b/src/desc_render.h new file mode 100644 index 00000000..5f8ab3f1 --- /dev/null +++ b/src/desc_render.h @@ -0,0 +1,67 @@ +// desc_render.h -*-c++-*- +// +// Copyright 2004-2005, 2008 Daniel Burrows +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef DESC_RENDER_H +#define DESC_RENDER_H + +#include <string> +#include <vector> + +#include <apt-pkg/pkgcache.h> + +#include <cwidget/generic/util/ref_ptr.h> + +#include <generic/apt/desc_parse.h> + +/** \file desc_render.h + */ + +namespace cwidget +{ + class fragment; +} + +namespace aptitude +{ + /** \brief Render a list of elements as a cwidget fragment. + * + * \param elements the list of description elements to be rendered. + */ + cwidget::fragment *make_desc_fragment(const std::vector<description_element_ref> &elements); +} + +/** Parses the given description string according to the standard + * formatting rules. + * + * \param desc a Description tag to parse + * \return a cwidget::fragment representing that description + * + * This just invokes aptitude::parse_desc() and aptitude::make_desc_fragment(). + */ +cwidget::fragment *make_desc_fragment(const std::wstring &desc); + +/** \return a cwidget::fragment listing the tags of the given package, or \b + * NULL if there are no tags. + * + * The global cache, apt_cache_file, should be available when you + * call this routine. + */ +cwidget::fragment *make_tags_fragment(const pkgCache::PkgIterator &pkg); + +#endif diff --git a/src/generic/apt/Makefile.am b/src/generic/apt/Makefile.am index 78a6348a..d3eaa71b 100644 --- a/src/generic/apt/Makefile.am +++ b/src/generic/apt/Makefile.am @@ -27,6 +27,8 @@ libgeneric_apt_a_SOURCES = \ apt_undo_group.h \ config_signal.cc \ config_signal.h \ + desc_parse.cc \ + desc_parse.h \ download_manager.cc \ download_manager.h \ download_install_manager.cc \ diff --git a/src/desc_parse.cc b/src/generic/apt/desc_parse.cc index 0a288b04..62610e4a 100644 --- a/src/desc_parse.cc +++ b/src/generic/apt/desc_parse.cc @@ -22,15 +22,9 @@ #include "desc_parse.h" #include "aptitude.h" -#include "ui.h" -#include <generic/apt/apt.h> -#include <generic/apt/config_signal.h> -#include <generic/apt/tags.h> - -#include <cwidget/fragment.h> -#include <cwidget/generic/util/transcode.h> -#include <cwidget/config/colors.h> +#include "apt.h" // For aptcfg. +#include "config_signal.h" // For aptcfg. using namespace std; @@ -247,56 +241,6 @@ static void make_level_fragment(const wstring &desc, namespace aptitude { - namespace - { - cw::fragment *make_desc_fragment(const std::vector<description_element_ref> &elements, - int level) - { - std::vector<cw::fragment *> fragments; - - for(std::vector<description_element_ref>::const_iterator it = elements.begin(); - it != elements.end(); ++it) - { - const description_element_ref &elt(*it); - - switch(elt->get_type()) - { - case description_element::blank_line: - fragments.push_back(cw::newline_fragment()); - break; - case description_element::paragraph: - fragments.push_back(wrapbox(cw::text_fragment(elt->get_string()))); - break; - case description_element::literal: - fragments.push_back(cw::hardwrapbox(cw::text_fragment(elt->get_string()))); - break; - case description_element::bullet_list: - { - wstring bullet; - bullet.push_back(L"*+-"[level%3]); - - cw::fragment *item_contents(make_desc_fragment(elt->get_elements(), - level + 1)); - - fragments.push_back(cw::style_fragment(cw::text_fragment(bullet), - cw::get_style("Bullet"))); - fragments.push_back(cw::indentbox(1, - (level + 1) * 2, - item_contents)); - } - break; - } - } - - return cw::sequence_fragment(fragments); - } - } - - cw::fragment *make_desc_fragment(const std::vector<description_element_ref> &elements) - { - return make_desc_fragment(elements, 0); - } - void parse_desc(const std::wstring &desc, std::vector<description_element_ref> &output) { @@ -322,75 +266,3 @@ namespace aptitude output); } } - -cw::fragment *make_desc_fragment(const wstring &desc) -{ - std::vector<aptitude::description_element_ref> elements; - aptitude::parse_desc(desc, elements); - - return aptitude::make_desc_fragment(elements); -} - - -cw::fragment *make_tags_fragment(const pkgCache::PkgIterator &pkg) -{ - if(pkg.end()) - return NULL; - -#ifdef HAVE_EPT - typedef ept::debtags::Tag tag; - using aptitude::apt::get_tags; -#endif - -#ifdef HAVE_EPT - const set<tag> realS(get_tags(pkg)); - const set<tag> * const s(&realS); -#else - const set<tag> * const s(get_tags(pkg)); -#endif - - vector<cw::fragment *> rval; - if(s != NULL && !s->empty()) - { - vector<cw::fragment *> tags; - for(set<tag>::const_iterator i = s->begin(); i != s->end(); ++i) - { -#ifdef HAVE_EPT - std::string name(i->fullname()); -#else - const std::string name(i->str()); -#endif - - tags.push_back(cw::text_fragment(name, cw::style_attrs_on(A_BOLD))); - } - - wstring tagstitle = W_("Tags"); - - rval.push_back(cw::fragf("%ls: %F", - tagstitle.c_str(), - indentbox(0, wcswidth(tagstitle.c_str(), tagstitle.size())+2, - wrapbox(cw::join_fragments(tags, L", "))))); - } - - typedef aptitudeDepCache::user_tag user_tag; - const set<user_tag> &user_tags((*apt_cache_file)->get_ext_state(pkg).user_tags); - if(!user_tags.empty()) - { - vector<cw::fragment *> tags; - for(set<user_tag>::const_iterator it = user_tags.begin(); - it != user_tags.end(); ++it) - { - tags.push_back(cw::text_fragment((*apt_cache_file)->deref_user_tag(*it), - cw::style_attrs_on(A_BOLD))); - } - - wstring title = W_("User Tags"); - rval.push_back(dropbox(cw::fragf("%ls: ", title.c_str()), - wrapbox(cw::join_fragments(tags, L", ")))); - } - - if(!rval.empty()) - return cw::join_fragments(rval, L"\n"); - else - return NULL; -} diff --git a/src/desc_parse.h b/src/generic/apt/desc_parse.h index b8274d8a..19a0a0d0 100644 --- a/src/desc_parse.h +++ b/src/generic/apt/desc_parse.h @@ -23,18 +23,11 @@ #include <string> #include <vector> -#include <apt-pkg/pkgcache.h> - #include <cwidget/generic/util/ref_ptr.h> /** \file desc_parse.h */ -namespace cwidget -{ - class fragment; -} - namespace aptitude { /** \brief Represents a single piece of syntactic structure in a @@ -170,12 +163,6 @@ namespace aptitude }; typedef cwidget::util::ref_ptr<description_element> description_element_ref; - /** \brief Render a list of elements as a cwidget fragment. - * - * \param elements the list of description elements to be rendered. - */ - cwidget::fragment *make_desc_fragment(const std::vector<description_element_ref> &elements); - /** \brief Parse a description-style string. * * \param desc the raw text of the description. The short @@ -189,22 +176,4 @@ namespace aptitude std::vector<description_element_ref> &output); } -/** Parses the given description string according to the standard - * formatting rules. - * - * \param desc a Description tag to parse - * \return a cwidget::fragment representing that description - * - * This just invokes aptitude::parse_desc() and aptitude::make_desc_fragment(). - */ -cwidget::fragment *make_desc_fragment(const std::wstring &desc); - -/** \return a cwidget::fragment listing the tags of the given package, or \b - * NULL if there are no tags. - * - * The global cache, apt_cache_file, should be available when you - * call this routine. - */ -cwidget::fragment *make_tags_fragment(const pkgCache::PkgIterator &pkg); - #endif diff --git a/src/pkg_info_screen.cc b/src/pkg_info_screen.cc index 503864ec..507ead31 100644 --- a/src/pkg_info_screen.cc +++ b/src/pkg_info_screen.cc @@ -30,7 +30,7 @@ #include <cwidget/widgets/layout_item.h> #include "dep_item.h" -#include "desc_parse.h" +#include "desc_render.h" #include "pkg_item_with_subtree.h" #include "pkg_subtree.h" #include "pkg_ver_item.h" diff --git a/src/pkg_view.cc b/src/pkg_view.cc index 7edfe74d..cf2ce32e 100644 --- a/src/pkg_view.cc +++ b/src/pkg_view.cc @@ -21,7 +21,7 @@ #include "aptitude.h" -#include "desc_parse.h" +#include "desc_render.h" #include "edit_pkg_hier.h" #include "menu_redirect.h" #include "pkg_columnizer.h" |