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" 50 : QY2ListView( parent )
52 yuiDebug() <<
"Creating service list" << endl;
60 setHeaderLabels( headers );
61 header()->setSectionResizeMode( _nameCol, QHeaderView::Stretch );
63 setSelectionMode( QAbstractItemView::ExtendedSelection );
65 connect(
this, SIGNAL( itemSelectionChanged() ),
67 setIconSize(QSize(32,32));
69 setSortingEnabled(
true );
70 sortByColumn( nameCol(), Qt::AscendingOrder );
73 yuiDebug() <<
"Creating service list done" << endl;
85 yuiDebug() <<
"Filling service list" << endl;
87 std::set<std::string> added_services;
88 zypp::RepoManager repo_manager;
90 std::for_each(ZyppRepositoriesBegin(), ZyppRepositoriesEnd(), [&](
const zypp::Repository& repo) {
91 const std::string &service_name(repo.info().service());
92 if (!service_name.empty())
94 bool found = std::any_of(added_services.begin(), added_services.end(), [&](
const std::string& name) {
95 return service_name == name;
101 added_services.insert(service_name);
106 yuiDebug() <<
"Service list filled" << endl;
121 yuiMilestone() <<
"Collecting packages in selected services..." << endl;
128 QTreeWidgetItem * item;
129 QList<QTreeWidgetItem *> items = selectedItems();
130 QListIterator<QTreeWidgetItem *> it(items);
132 while ( it.hasNext() )
139 yuiMilestone() <<
"Selected service: " << serviceItem->
zyppService() << endl;
141 zypp::PoolQuery query;
142 std::for_each(ZyppRepositoriesBegin(), ZyppRepositoriesEnd(), [&](
const zypp::Repository& repo) {
143 if (serviceItem->
zyppService() == repo.info().service())
145 yuiMilestone() <<
"Adding repo filter: " << repo.info().alias() << endl;
146 query.addRepo( repo.info().alias() );
149 query.addKind(zypp::ResKind::package);
151 std::for_each(query.selectableBegin(), query.selectableEnd(), [&](
const zypp::ui::Selectable::Ptr &selectable) {
152 emit
filterMatch( selectable, tryCastToZyppPkg( selectable->theObj() ) );
157 yuiDebug() <<
"Packages sent to package list. Elapsed time: " 158 << stopWatch.elapsed() / 1000.0 <<
" sec" 174 QTreeWidgetItem * item = currentItem();
179 ZyppService service,
const zypp::RepoManager &mgr )
180 : QY2ListViewItem( parentList )
181 , _serviceList( parentList )
182 , _zyppService( service )
185 zypp::ServiceInfo srvinfo = mgr.getService(service);
186 _zyppServiceName = srvinfo.name();
187 QString service_name(fromUTF8(_zyppServiceName));
189 if ( nameCol() >= 0 && !service.empty() )
191 setText( nameCol(), service_name);
194 QString infoToolTip(
"<p><b>" + service_name.toHtmlEscaped() +
"</b></p>");
197 infoToolTip +=
"<p><b>" + _(
"URL: ") +
"</b>" + fromUTF8(srvinfo.url().asString()).toHtmlEscaped() +
"</p>";
203 infoToolTip += (
"<p><b>" + _(
"Product: ") +
"</b>" 204 + fromUTF8(product->summary()).toHtmlEscaped() +
"</p>");
208 infoToolTip +=
"<p><b>" + _(
"Repositories:") +
"</b><ul>";
209 std::for_each(ZyppRepositoriesBegin(), ZyppRepositoriesEnd(), [&](
const zypp::Repository& repo) {
210 if (service == repo.info().service())
211 infoToolTip +=
"<li>" + fromUTF8(repo.name()).toHtmlEscaped() +
"</li>";
213 infoToolTip +=
"</ul></p>";
215 setToolTip( nameCol(), infoToolTip);
218 QString iconName =
"yast-update";
220 if ( QIcon::hasThemeIcon(iconName) )
222 setIcon( 0, QIcon::fromTheme(iconName) );
225 setIcon( 0, QIcon( iconPath.sprintf(
"/usr/share/icons/hicolor/48x48/apps/%s.png", iconName.toUtf8().data()) ));
238 return item.resolvable()->repoInfo().service() ==
zyppService;
243 YQPkgServiceListItem::operator< (
const QTreeWidgetItem & other )
const 251 #include "YQPkgServiceList.moc" 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...