~ubuntu-branches/ubuntu/vivid/aptitude/vivid

« back to all changes in this revision

Viewing changes to src/gtk/controllers/search_input.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-06-22 12:32:56 UTC
  • mfrom: (1.8.6 sid)
  • Revision ID: james.westby@ubuntu.com-20110622123256-8aox9w9ch3x72dci
Tags: 0.6.4-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/05aptitude: never autoremove kernels
  - drop aptitude-doc to Suggests
  - 03_branding.dpatch: ubuntu branding
  - 04_changelog.dpatch: take changelogs from changelogs.ubuntu.com
  - 09_ubuntu_fortify_source.dpatch: Suppress a number of warnings (turned
    into errors by -Werror) triggered by Ubuntu's default of
    -D_FORTIFY_SOURCE=2.
  - 11_ubuntu_uses_sudo.dpatch: fix status line of 'Become root' menu entry
    to not refer to su.
  - 12_point_manpage_to_doc_package.dpatch: point Finnish manpage to the
    correct place for further info
  - 14_html2text_preferred.dpatch: switch back to html2text in favor of
    elinks, since html2text is in main and elinks isn't.
* dropped 01_intltool_update.dpatch
* updated 15_ftbfs_new_apt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/** \file search_input.cc */    // -*-c++-*-
2
 
 
3
 
//  Copyright 1999-2010 Daniel Burrows
4
 
//  Copyright 2008-2009 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 "search_input.h"
22
 
 
23
 
#include <aptitude.h>
24
 
 
25
 
#include <generic/apt/matching/parse.h>
26
 
#include <generic/apt/matching/pattern.h>
27
 
 
28
 
#include <gtk/views/search_input.h>
29
 
 
30
 
#include <boost/format.hpp>
31
 
#include <boost/make_shared.hpp>
32
 
 
33
 
namespace gui
34
 
{
35
 
  namespace controllers
36
 
  {
37
 
    namespace
38
 
    {
39
 
      class search_input_impl : public search_input
40
 
      {
41
 
        boost::shared_ptr<views::search_input> view;
42
 
 
43
 
        // Parse the current entry and emit the activated() signal if
44
 
        // it's valid (otherwise show the error).
45
 
        void do_search();
46
 
 
47
 
        // Invoked when the search entry's text changes.
48
 
        void search_input_changed();
49
 
 
50
 
        /** \brief A signal emitted when the user searches for a package. */
51
 
        sigc::signal<void, Glib::ustring, cwidget::util::ref_ptr<aptitude::matching::pattern> > signal_activated;
52
 
 
53
 
      public:
54
 
        // Only public for make_shared.
55
 
        search_input_impl(const boost::shared_ptr<views::search_input> &_view);
56
 
 
57
 
        /** \brief Create a new search_input_impl.
58
 
         *
59
 
         *  \param view   The view to manage.
60
 
         *
61
 
         *  \return A reference-counting wrapper around the new package
62
 
         *  search entry.
63
 
         */
64
 
        static boost::shared_ptr<search_input_impl>
65
 
        create(const boost::shared_ptr<views::search_input> &view);
66
 
 
67
 
        Glib::ustring get_text() const;
68
 
 
69
 
        /** \brief Set the text of the view and emit a search
70
 
         *  immediately.
71
 
         */
72
 
        void enter_text(const Glib::ustring &text);
73
 
 
74
 
        sigc::connection
75
 
        connect_activated(const sigc::slot<void, Glib::ustring, cwidget::util::ref_ptr<aptitude::matching::pattern> > &slot);
76
 
      };
77
 
 
78
 
      search_input_impl::search_input_impl(const boost::shared_ptr<views::search_input> &_view)
79
 
        : view(_view)
80
 
      {
81
 
      }
82
 
 
83
 
      boost::shared_ptr<search_input_impl>
84
 
      search_input_impl::create(const boost::shared_ptr<views::search_input> &
85
 
                                view)
86
 
      {
87
 
        return boost::make_shared<search_input_impl>(view);
88
 
      }
89
 
 
90
 
      void search_input_impl::do_search()
91
 
      {
92
 
        Glib::ustring search_term_u(view->get_search_text());
93
 
        std::string search_term(search_term_u);
94
 
        cwidget::util::ref_ptr<aptitude::matching::pattern> p;
95
 
        try
96
 
          {
97
 
            p = aptitude::matching::parse_with_errors(search_term);
98
 
          }
99
 
        catch(aptitude::matching::MatchingException &ex)
100
 
          {
101
 
            std::string msg = (boost::format("%s: %s")
102
 
                               % _("Parse error")
103
 
                               % ex.errmsg()).str();
104
 
            view->set_error_message(msg);
105
 
            return;
106
 
          }
107
 
 
108
 
        view->set_error_message("");
109
 
        signal_activated(search_term_u, p);
110
 
      }
111
 
 
112
 
      void search_input_impl::search_input_changed()
113
 
      {
114
 
        const Glib::ustring limit(view->get_search_text());
115
 
        bool valid;
116
 
        try
117
 
          {
118
 
            aptitude::matching::parse_with_errors(limit);
119
 
            valid = true;
120
 
          }
121
 
        catch(aptitude::matching::MatchingException &)
122
 
          {
123
 
            valid = false;
124
 
          }
125
 
 
126
 
        view->set_input_validity(valid);
127
 
      }
128
 
 
129
 
      void search_input_impl::enter_text(const Glib::ustring &text)
130
 
      {
131
 
        view->set_search_text(text);
132
 
        do_search();
133
 
      }
134
 
 
135
 
      sigc::connection
136
 
      search_input_impl::connect_activated(const sigc::slot<void, Glib::ustring, cwidget::util::ref_ptr<aptitude::matching::pattern> > &slot)
137
 
      {
138
 
        return signal_activated.connect(slot);
139
 
      }
140
 
    }
141
 
 
142
 
    search_input::~search_input()
143
 
    {
144
 
    }
145
 
 
146
 
    boost::shared_ptr<search_input>
147
 
    create_search_input(const boost::shared_ptr<views::search_input> &view)
148
 
    {
149
 
      return search_input_impl::create(view);
150
 
    }
151
 
  }
152
 
}