~ubuntu-branches/ubuntu/maverick/aptitude/maverick

« back to all changes in this revision

Viewing changes to .pc/03_branding/src/gtk/previewtab.cc

  • Committer: Steve Langasek
  • Date: 2010-07-09 18:00:47 UTC
  • Revision ID: steve.langasek@canonical.com-20100709180047-qq1g7874npwmi1mm
Drop build-dependency on google-mock/libgtest-dev and disable the test
suite at build time; google-mock hasn't built in Ubuntu and is in
universe.  This should probably be revisited once google-mock is
buildable in Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// previewtab.cc
 
2
//
 
3
//  Copyright 1999-2009 Daniel Burrows
 
4
//  Copyright 2008 Obey Arthur Liu
 
5
//
 
6
//  This program is free software; you can redistribute it and/or modify
 
7
//  it under the terms of the GNU General Public License as published by
 
8
//  the Free Software Foundation; either version 2 of the License, or
 
9
//  (at your option) any later version.
 
10
//
 
11
//  This program is distributed in the hope that it will be useful,
 
12
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
//  GNU General Public License for more details.
 
15
//
 
16
//  You should have received a copy of the GNU General Public License
 
17
//  along with this program; see the file COPYING.  If not, write to
 
18
//  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
19
//  Boston, MA 02111-1307, USA.
 
20
 
 
21
#include "previewtab.h"
 
22
#include "aptitude.h"
 
23
 
 
24
#undef OK
 
25
#include <gtkmm.h>
 
26
 
 
27
#include <apt-pkg/strutl.h>
 
28
 
 
29
#include <generic/util/util.h>
 
30
 
 
31
#include <gtk/hyperlink.h>
 
32
#include <gtk/gui.h>
 
33
#include <gtk/info.h>
 
34
#include <gtk/packageinformation.h>
 
35
#include <gtk/packagestab.h> // For PackageSearchEntry.
 
36
#include <gtk/pkgview.h>
 
37
#include <gtk/progress.h>
 
38
#include <gtk/notify.h>
 
39
 
 
40
namespace gui
 
41
{
 
42
  PreviewView::Generator::Generator(const EntityColumns *_entity_columns)
 
43
  {
 
44
    entity_columns = _entity_columns;
 
45
    store = Gtk::TreeStore::create(*entity_columns);
 
46
  }
 
47
 
 
48
  PreviewView::Generator *PreviewView::Generator::create(const EntityColumns *entity_columns)
 
49
  {
 
50
    return new Generator(entity_columns);
 
51
  }
 
52
 
 
53
  void PreviewView::Generator::add(const pkgCache::PkgIterator &pkg)
 
54
  {
 
55
    int group = find_pkg_state(pkg, *apt_cache_file);
 
56
    if(group != pkg_unchanged)
 
57
      {
 
58
        const std::map<int, Gtk::TreeModel::iterator>::const_iterator found =
 
59
          state_trees.find(group);
 
60
 
 
61
        Gtk::TreeModel::iterator tree;
 
62
        if(found == state_trees.end())
 
63
          {
 
64
            tree = store->append();
 
65
            Gtk::TreeModel::Row tree_row = *tree;
 
66
            (new HeaderEntity(_(child_names[group])))->fill_row(entity_columns, tree_row);
 
67
            state_trees[group] = tree;
 
68
          }
 
69
        else
 
70
          tree = found->second;
 
71
 
 
72
        Gtk::TreeModel::iterator iter = store->append(tree->children());
 
73
        Gtk::TreeModel::Row row = *iter;
 
74
 
 
75
        PkgEntity *entity = new PkgEntity(pkg);
 
76
        entity->fill_row(entity_columns, row);
 
77
      }
 
78
  }
 
79
 
 
80
  void PreviewView::Generator::finish()
 
81
  {
 
82
    store->set_sort_column(entity_columns->Name, Gtk::SORT_ASCENDING);
 
83
    // FIXME: Hack while finding a nonblocking thread join.
 
84
    finished = true;
 
85
  }
 
86
 
 
87
  Glib::RefPtr<Gtk::TreeModel> PreviewView::Generator::get_model()
 
88
  {
 
89
    return store;
 
90
  }
 
91
 
 
92
 
 
93
  // \todo This is proof-of-concept only; the child_names list should
 
94
  // be in common code.
 
95
  const char * const PreviewView::Generator::child_names[num_pkg_action_states]=
 
96
    {
 
97
      N_("Packages with unsatisfied dependencies\n The dependency requirements of these packages will be unmet after the install is complete.\n .\n The presence of this tree probably indicates that something is broken, either on your system or in the Debian archive."),
 
98
      N_("Packages being removed because they are no longer used\n These packages are being deleted because they were automatically installed to fulfill dependencies, and the planned action will result in no installed package declaring an 'important' dependency on them.\n"),
 
99
      N_("Packages being automatically held in their current state\n These packages could be upgraded, but they have been kept in their current state to avoid breaking dependencies."),
 
100
      N_("Packages being automatically installed to satisfy dependencies\n These packages are being installed because they are required by another package you have chosen for installation."),
 
101
      N_("Packages being deleted due to unsatisfied dependencies\n These packages are being deleted because one or more of their dependencies is no longer available, or because another package conflicts with them."),
 
102
      N_("Packages to be downgraded\n An older version of these packages than is currently installed will be installed."),
 
103
      N_("Packages being held back\n These packages could be upgraded, but you have asked for them to be held at their current version."),
 
104
      N_("Packages to be reinstalled\n These packages will be reinstalled."),
 
105
      N_("Packages to be installed\n These packages have been manually selected for installation on your computer."),
 
106
      N_("Packages to be removed\n These packages have been manually selected for removal."),
 
107
      N_("Packages to be upgraded\n These packages will be upgraded to a newer version."),
 
108
      N_("Packages that are partially installed\n These packages are not fully installed and configured; an attempt will be made to complete their installation."),
 
109
    };
 
110
 
 
111
  PreviewView::PreviewView(const Glib::RefPtr<Gnome::Glade::Xml> &refGlade,
 
112
                           const Glib::ustring &gladename,
 
113
                           const Glib::ustring &limit,
 
114
                           const sigc::slot<cwidget::util::ref_ptr<refcounted_progress> > &build_progress_k)
 
115
    : PkgViewBase(sigc::ptr_fun(&Generator::create),
 
116
                  refGlade,
 
117
                  gladename,
 
118
                  _("Preview"),
 
119
                  limit,
 
120
                  build_progress_k)
 
121
  {
 
122
  }
 
123
 
 
124
  PreviewTab::PreviewTab(const Glib::ustring &label) :
 
125
    Tab(Preview, label, Gnome::Glade::Xml::create(glade_main_file, "main_packages_hpaned"), "main_packages_hpaned")
 
126
  {
 
127
    Gtk::Entry *pLimitEntry;
 
128
    Gtk::Button *pLimitButton;
 
129
    Gtk::Label *pLimitErrors;
 
130
 
 
131
    get_xml()->get_widget("main_packages_textview", pPackagesTextView);
 
132
    get_xml()->get_widget("main_notebook_packages_limit_entry", pLimitEntry);
 
133
    get_xml()->get_widget("main_notebook_packages_limit_errors", pLimitErrors);
 
134
    get_xml()->get_widget("main_notebook_packages_limit_button", pLimitButton);
 
135
 
 
136
    pSearchEntry = PackageSearchEntry::create(pLimitEntry,
 
137
                                              pLimitErrors,
 
138
                                              pLimitButton);
 
139
    pSearchEntry->activated.connect(sigc::mem_fun(*this, &PreviewTab::limit_changed));
 
140
 
 
141
    using cwidget::util::ref_ptr;
 
142
    pPkgView = ref_ptr<PreviewView>(new PreviewView(get_xml(), "main_packages_treeview", "",
 
143
                                                    sigc::bind(sigc::ptr_fun(&gtkEntryOpProgress::create),
 
144
                                                               sigc::ref(*pLimitEntry))));
 
145
 
 
146
    pPkgView->get_treeview()->signal_selection.connect(sigc::mem_fun(*this, &PreviewTab::activated_package_handler));
 
147
 
 
148
    // Start out with no limit.
 
149
    limit_changed(aptitude::matching::pattern::make_true());
 
150
 
 
151
    pPkgView->get_treeview()->expand_all();
 
152
 
 
153
    get_widget()->show();
 
154
 
 
155
  }
 
156
 
 
157
  // TODO: Should be moved into PackagesView for use with PackagesView::signal_on_package_selection.
 
158
  void PreviewTab::activated_package_handler()
 
159
  {
 
160
    Gtk::TreeModel::Path path;
 
161
    Gtk::TreeViewColumn * focus_column;
 
162
    pPkgView->get_treeview()->get_cursor(path, focus_column);
 
163
    if (pPkgView->get_treeview()->get_selection()->is_selected(path))
 
164
    {
 
165
      Gtk::TreeModel::iterator iter = pPkgView->get_model()->get_iter(path);
 
166
      cwidget::util::ref_ptr<Entity> ent = (*iter)[pPkgView->get_columns()->EntObject];
 
167
      display_desc(ent);
 
168
    }
 
169
    else
 
170
    {
 
171
      pPackagesTextView->get_buffer()->set_text("");
 
172
    }
 
173
  }
 
174
 
 
175
  void PreviewTab::limit_changed(const cwidget::util::ref_ptr<aptitude::matching::pattern> &limit)
 
176
  {
 
177
    pPkgView->set_limit(limit);
 
178
    pPkgView->get_treeview()->expand_all();
 
179
    set_label(_("Preview: ") + pSearchEntry->get_text());
 
180
  }
 
181
 
 
182
  void PreviewTab::display_desc(const cwidget::util::ref_ptr<Entity> &ent)
 
183
  {
 
184
    cwidget::util::ref_ptr<PkgEntity> pkg_ent = ent.dyn_downcast<PkgEntity>();
 
185
 
 
186
    pkgCache::PkgIterator pkg;
 
187
    pkgCache::VerIterator ver;
 
188
 
 
189
    if(pkg_ent.valid())
 
190
      {
 
191
        pkg = pkg_ent->get_pkg();
 
192
        ver = pkg_ent->get_ver();
 
193
      }
 
194
 
 
195
    Glib::RefPtr<Gtk::TextBuffer> textBuffer = Gtk::TextBuffer::create();
 
196
 
 
197
    if(!pkg_ent.valid() || pkg.end())
 
198
      {
 
199
        textBuffer->set_text("");
 
200
      }
 
201
    else
 
202
      {
 
203
        PackageInformation info(pkg, ver);
 
204
 
 
205
        Glib::RefPtr<Gtk::TextBuffer::Tag> nameTag = textBuffer->create_tag();
 
206
        nameTag->property_size() = 20 * Pango::SCALE;
 
207
 
 
208
        Glib::RefPtr<Gtk::TextBuffer::Tag> fieldNameTag = textBuffer->create_tag();
 
209
        fieldNameTag->property_weight() = 2 * Pango::SCALE;
 
210
 
 
211
        textBuffer->insert_with_tag(textBuffer->end(),
 
212
                                    info.Name(),
 
213
                                    nameTag);
 
214
        textBuffer->insert(textBuffer->end(), " ");
 
215
        add_hyperlink(textBuffer, textBuffer->end(), _("(more info...)"),
 
216
                      sigc::bind(sigc::ptr_fun(&InfoTab::show_tab),
 
217
                                 pkg, ver));
 
218
        textBuffer->insert(textBuffer->end(), "\n");
 
219
        textBuffer->insert(textBuffer->end(), info.ShortDescription());
 
220
        textBuffer->insert(textBuffer->end(), "\n");
 
221
 
 
222
        // TODO: insert a horizontal rule here (how?)
 
223
 
 
224
        textBuffer->insert(textBuffer->end(), "\n");
 
225
 
 
226
        if (ver)
 
227
          {
 
228
            //pkgRecords::Parser &rec=apt_package_records->Lookup(ver.FileList());
 
229
 
 
230
            textBuffer->insert_with_tag(textBuffer->end(), _("Version: "), fieldNameTag);
 
231
            textBuffer->insert(textBuffer->end(), info.Version());
 
232
 
 
233
            textBuffer->insert(textBuffer->end(), "\n");
 
234
            textBuffer->insert(textBuffer->end(), "\n");
 
235
 
 
236
            std::wstring longdesc = get_long_description(ver, apt_package_records);
 
237
 
 
238
            textBuffer->insert_with_tag(textBuffer->end(), _("Description: "), fieldNameTag);
 
239
 
 
240
            textBuffer->insert(textBuffer->end(), info.LongDescription());
 
241
          }
 
242
        else
 
243
          {
 
244
          }
 
245
      }
 
246
 
 
247
    pPackagesTextView->set_buffer(textBuffer);
 
248
  }
 
249
 
 
250
}