26 #include <QElapsedTimer> 27 #include <QHeaderView> 30 #define YUILogComponent "qt-pkg" 32 #include <zypp/PoolQuery.h> 33 #include <zypp/RepoManager.h> 34 #include <zypp/ServiceInfo.h> 36 #include <QTreeWidget> 37 #include "YQPkgServiceList.h" 38 #include "YQPkgFilters.h" 51 : QY2ListView( parent )
53 yuiDebug() <<
"Creating service list" << endl;
61 setHeaderLabels( headers );
62 header()->setSectionResizeMode( _nameCol, QHeaderView::Stretch );
64 setSelectionMode( QAbstractItemView::ExtendedSelection );
66 connect(
this, SIGNAL( itemSelectionChanged() ),
68 setIconSize(QSize(32,32));
70 setSortingEnabled(
true );
71 sortByColumn( nameCol(), Qt::AscendingOrder );
74 yuiDebug() <<
"Creating service list done" << endl;
86 yuiDebug() <<
"Filling service list" << endl;
88 std::set<std::string> added_services;
89 zypp::RepoManager repo_manager;
91 std::for_each(ZyppRepositoriesBegin(), ZyppRepositoriesEnd(), [&](
const zypp::Repository& repo) {
92 const std::string &service_name(repo.info().service());
93 if (!service_name.empty())
95 bool found = std::any_of(added_services.begin(), added_services.end(), [&](
const std::string& name) {
96 return service_name == name;
102 added_services.insert(service_name);
107 yuiDebug() <<
"Service list filled" << endl;
122 yuiMilestone() <<
"Collecting packages in selected services..." << endl;
123 QElapsedTimer stopWatch;
129 QTreeWidgetItem * item;
130 QList<QTreeWidgetItem *> items = selectedItems();
131 QListIterator<QTreeWidgetItem *> it(items);
133 while ( it.hasNext() )
140 yuiMilestone() <<
"Selected service: " << serviceItem->
zyppService() << endl;
142 zypp::PoolQuery query;
143 std::for_each(ZyppRepositoriesBegin(), ZyppRepositoriesEnd(), [&](
const zypp::Repository& repo) {
144 if (serviceItem->
zyppService() == repo.info().service())
146 yuiMilestone() <<
"Adding repo filter: " << repo.info().alias() << endl;
147 query.addRepo( repo.info().alias() );
150 query.addKind(zypp::ResKind::package);
152 std::for_each(query.selectableBegin(), query.selectableEnd(), [&](
const zypp::ui::Selectable::Ptr &selectable) {
153 emit
filterMatch( selectable, tryCastToZyppPkg( selectable->theObj() ) );
158 yuiDebug() <<
"Packages sent to package list. Elapsed time: " 159 << stopWatch.elapsed() / 1000.0 <<
" sec" 175 QTreeWidgetItem * item = currentItem();
180 ZyppService service,
const zypp::RepoManager &mgr )
181 : QY2ListViewItem( parentList )
182 , _serviceList( parentList )
183 , _zyppService( service )
186 zypp::ServiceInfo srvinfo = mgr.getService(service);
187 _zyppServiceName = srvinfo.name();
188 QString service_name(fromUTF8(_zyppServiceName));
190 if ( nameCol() >= 0 && !service.empty() )
192 setText( nameCol(), service_name);
195 QString infoToolTip(
"<p><b>" + service_name.toHtmlEscaped() +
"</b></p>");
198 infoToolTip +=
"<p><b>" + _(
"URL: ") +
"</b>" + fromUTF8(srvinfo.url().asString()).toHtmlEscaped() +
"</p>";
204 infoToolTip += (
"<p><b>" + _(
"Product: ") +
"</b>" 205 + fromUTF8(product->summary()).toHtmlEscaped() +
"</p>");
209 infoToolTip +=
"<p><b>" + _(
"Repositories:") +
"</b><ul>";
210 std::for_each(ZyppRepositoriesBegin(), ZyppRepositoriesEnd(), [&](
const zypp::Repository& repo) {
211 if (service == repo.info().service())
212 infoToolTip +=
"<li>" + fromUTF8(repo.name()).toHtmlEscaped() +
"</li>";
214 infoToolTip +=
"</ul></p>";
216 setToolTip( nameCol(), infoToolTip);
218 setIcon( 0, YQUI::ui()->loadIcon(
"yast-update" ) );
231 return item.resolvable()->repoInfo().service() ==
zyppService;
236 YQPkgServiceListItem::operator< (
const QTreeWidgetItem & other )
const void filterStart()
Emitted when the filtering starts.
void filter()
Filter according to the view's rules and current selection.
ZyppService zyppService() const
Returns the ZYPP service this item corresponds to (its alias)
virtual ~YQPkgServiceList()
Destructor.
std::string zyppServiceName() const
Returns the ZYPP service name this item corresponds to.
virtual ~YQPkgServiceListItem()
Destructor.
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
YQPkgServiceList(QWidget *parent)
Constructor.
void filterFinished()
Emitted when filtering is finished.
A widget to display a list of libzypp services.
static ZyppProduct singleProduct(ZyppService service)
Returns the product on a source if it has one single product or 0 if there are no or multiple product...
void fillList()
Fill the list.
static ZyppProduct singleProductFilter(std::function< bool(const zypp::PoolItem &item)> filter)
Returns the product if the filter finds a single product or null product if there are no or multiple ...
void addService(ZyppService service, const zypp::RepoManager &mgr)
Add a service to the list.
YQPkgServiceListItem * selection() const
Returns the currently selected item or 0 if there is none.
YQPkgServiceListItem(YQPkgServiceList *parentList, ZyppService service, const zypp::RepoManager &mgr)
Constructor.
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter and the candidate package comes from th...