summaryrefslogtreecommitdiff
path: root/src/generic/apt/pkg_changelog.h
blob: cf4ffa5553a2dfabd780e991aa41359eda0b385c (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// pkg_changelog.h    -*-c++-*-
//
//  Copyright 2000, 2005, 2008-2009 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 PKG_CHANGELOG_H
#define PKG_CHANGELOG_H

#include <map>
#include <string>

#include <generic/util/post_thunk.h>
#include <generic/util/temp.h>

#include <apt-pkg/pkgcache.h>

#include <sigc++/signal.h>
#include <sigc++/slot.h>

#include <boost/shared_ptr.hpp>

/** \brief Routines to download a Debian changelog for a given package.
 *
 *  \file pkg_changelog.h
 */

class download_manager;

namespace aptitude
{
  class download_callbacks;
  class download_request;

  namespace apt
  {
    /** \brief Carries information about which changelog is to be
     *  downloaded.
     */
    class changelog_info
    {
      const std::string source_package;
      const std::string source_version;
      const std::vector<std::string> uri_list;
      const std::string display_name;

    public:
      /** \brief This constructor is public for make_shared; it should
       *  never be invoked directly.  Use the static create() methods
       *  instead.
       */
      changelog_info(const std::string &_source_package,
		     const std::string &_source_version,
                     const std::vector<std::string> &_uri_list,
		     const std::string &_display_name)
	: source_package(_source_package),
	  source_version(_source_version),
          uri_list(_uri_list),
	  display_name(_display_name)
      {
      }

      static boost::shared_ptr<changelog_info>
      create(const std::string &source_package,
	     const std::string &source_version,
             const std::vector<std::string> &uri_list,
	     const std::string &display_name);

      static boost::shared_ptr<changelog_info>
      guess(const std::string &source_package,
	    const std::string &source_version,
            const std::string &section,
	    const std::string &display_name);

      /** \brief Create a changelog_info structure that describes the
       *  changelog of the given package version.
       *
       *  \return the new object, or an invalid pointer if the
       *  changelog can't be downloaded.
       */
      static boost::shared_ptr<changelog_info>
      create(const pkgCache::VerIterator &ver);

      /** \brief Retrieve the name of the changelog's source package. */
      const std::string &get_source_package() const { return source_package; }
      /** \brief Retrieve the name of the changelog's source version. */
      const std::string &get_source_version() const { return source_version; }
      /** \brief Retrieve the list of URIs to try, in order. */
      const std::vector<std::string> &get_uri_list() const { return uri_list; }
      /** \brief Retrieve the display name of the changelog's package.
       *
       *  This is the name that should be displayed to the user when,
       *  for instance, the changelog is being downloaded.  The name
       *  of the binary package that was selected is a good choice
       *  here.
       */
      const std::string &get_display_name() const { return display_name; }
    };

    /** \brief Start downloading a changelog.
     *
     *  \param info       The changelog that is to be fetched.
     *  \param callbacks  The callbacks to invoke for download events.
     *  \param post_thunk How to post thunks to the foreground thread.
     */
    boost::shared_ptr<download_request>
    get_changelog(const boost::shared_ptr<changelog_info> &info,
		  const boost::shared_ptr<download_callbacks> &callbacks,
		  post_thunk_f post_thunk);

    /** \brief Convenience code to download a version's changelog.
     *
     *  The given slots are invoked in the main thread via post_thunk
     *  when the download completes.
     *
     *  \note The slots are handled safely as long as it is safe to
     *  copy them in the thread that invokes get_changelog().  No
     *  special treatment is necessary.
     */
    boost::shared_ptr<download_request>
    get_changelog(const pkgCache::VerIterator &ver,
		  post_thunk_f post_thunk,
		  const sigc::slot<void, temp::name> &success,
		  const sigc::slot<void, std::string> &failure);
  }
}

#endif