1
/** \file search_input.cc */ // -*-c++-*-
3
// Copyright 1999-2010 Daniel Burrows
4
// Copyright 2008-2009 Obey Arthur Liu
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.
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.
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.
21
#include "search_input.h"
25
#include <generic/apt/matching/parse.h>
26
#include <generic/apt/matching/pattern.h>
28
#include <gtk/views/search_input.h>
30
#include <boost/format.hpp>
31
#include <boost/make_shared.hpp>
39
class search_input_impl : public search_input
41
boost::shared_ptr<views::search_input> view;
43
// Parse the current entry and emit the activated() signal if
44
// it's valid (otherwise show the error).
47
// Invoked when the search entry's text changes.
48
void search_input_changed();
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;
54
// Only public for make_shared.
55
search_input_impl(const boost::shared_ptr<views::search_input> &_view);
57
/** \brief Create a new search_input_impl.
59
* \param view The view to manage.
61
* \return A reference-counting wrapper around the new package
64
static boost::shared_ptr<search_input_impl>
65
create(const boost::shared_ptr<views::search_input> &view);
67
Glib::ustring get_text() const;
69
/** \brief Set the text of the view and emit a search
72
void enter_text(const Glib::ustring &text);
75
connect_activated(const sigc::slot<void, Glib::ustring, cwidget::util::ref_ptr<aptitude::matching::pattern> > &slot);
78
search_input_impl::search_input_impl(const boost::shared_ptr<views::search_input> &_view)
83
boost::shared_ptr<search_input_impl>
84
search_input_impl::create(const boost::shared_ptr<views::search_input> &
87
return boost::make_shared<search_input_impl>(view);
90
void search_input_impl::do_search()
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;
97
p = aptitude::matching::parse_with_errors(search_term);
99
catch(aptitude::matching::MatchingException &ex)
101
std::string msg = (boost::format("%s: %s")
103
% ex.errmsg()).str();
104
view->set_error_message(msg);
108
view->set_error_message("");
109
signal_activated(search_term_u, p);
112
void search_input_impl::search_input_changed()
114
const Glib::ustring limit(view->get_search_text());
118
aptitude::matching::parse_with_errors(limit);
121
catch(aptitude::matching::MatchingException &)
126
view->set_input_validity(valid);
129
void search_input_impl::enter_text(const Glib::ustring &text)
131
view->set_search_text(text);
136
search_input_impl::connect_activated(const sigc::slot<void, Glib::ustring, cwidget::util::ref_ptr<aptitude::matching::pattern> > &slot)
138
return signal_activated.connect(slot);
142
search_input::~search_input()
146
boost::shared_ptr<search_input>
147
create_search_input(const boost::shared_ptr<views::search_input> &view)
149
return search_input_impl::create(view);