libyui-qt-pkg  2.45.13.1
YQPkgLangList.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgLangList.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 
43 #define YUILogComponent "qt-pkg"
44 #include "YUILog.h"
45 #include <qregexp.h>
46 
47 #include <QHeaderView>
48 #include "YQi18n.h"
49 #include "utf8.h"
50 #include "YQPkgLangList.h"
51 
52 #include "zypp/sat/LocaleSupport.h"
53 
54 using std::set;
55 using std::endl;
56 
57 
58 YQPkgLangList::YQPkgLangList( QWidget * parent )
59  : YQPkgObjList( parent )
60 //FIXME "base class works with zypp::Resolvable, but zypp::Locale isn't one any longer!"
61 {
62  yuiDebug() << "Creating language list" << endl;
63 
64  int numCol = 0;
65  QStringList headers;
66  headers << ""; _statusCol = numCol++;
67 
68  // Translators: Table column heading for language ISO code like "de_DE", "en_US"
69  // Please keep this short to avoid stretching the column too wide!
70  headers << _( "Code" ); _nameCol = numCol++;
71 
72  // Full (human readable) language / country name like "German (Austria)"
73  headers << _( "Language"); _summaryCol = numCol++;
74  setAllColumnsShowFocus( true );
75  setHeaderLabels(headers);
76  header()->setSectionResizeMode( _nameCol, QHeaderView::ResizeToContents );
77  header()->setSectionResizeMode( _summaryCol, QHeaderView::Stretch );
78 
79 
80  setSortingEnabled( true );
81  header()->setSortIndicatorShown( true );
82  header()->setSectionsClickable( true );
83 
84  sortByColumn( nameCol(), Qt::AscendingOrder );
85 
86  connect( this, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
87  this, SLOT ( filter() ) );
88 
89  fillList();
90  selectSomething();
91  resizeColumnToContents(_statusCol);
92 
93  yuiDebug() << "Creating language list done" << endl;
94 }
95 
96 
98 {
99  // NOP
100 }
101 
102 
103 void
105 {
106  clear();
107  yuiDebug() << "Filling language list" << endl;
108 
109  zypp::LocaleSet locales = zypp::getZYpp()->pool().getAvailableLocales();
110 
111  for ( zypp::LocaleSet::const_iterator it = locales.begin();
112  it != locales.end();
113  ++it )
114  {
115  addLangItem( *it );
116  }
117 
118  yuiDebug() << "Language list filled" << endl;
119 }
120 
121 
122 void
124 {
125  if ( isVisible() )
126  filter();
127 }
128 
129 
130 void
132 {
133  emit filterStart();
134 
135  if ( selection() )
136  {
137  int total = 0;
138  int installed = 0;
139 
140  zypp::Locale lang = selection()->zyppLang();
141 
142  zypp::sat::LocaleSupport myLocale( lang );
143  for_( it, myLocale.selectableBegin(), myLocale.selectableEnd() )
144  {
145  ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
146  if ( zyppPkg )
147  {
148  if ( (*it)->installedSize() > 0 )
149  ++installed;
150  ++total;
151 
152  emit filterMatch( *it, zyppPkg );
153  }
154  }
155  //selection()->setInstalledPackages(installed);
156  //selection()->setTotalPackages(total);
157 
158  //selection()->setText( _summaryCol, QString().sprintf("%s (%d/%d)", zyppPattern->summary().c_str(), installed, total));
159 
160  }
161  emit filterFinished();
162 }
163 
164 void
165 YQPkgLangList::addLangItem( const zypp::Locale &zyppLang )
166 {
167  new YQPkgLangListItem( this, zyppLang );
168 }
169 
170 
173 {
174  QTreeWidgetItem * item = currentItem();
175 
176  if ( ! item )
177  return 0;
178 
179  return dynamic_cast<YQPkgLangListItem *> (item);
180 }
181 
182 
183 void
185 {
186 #if 0
187  YQPkgLangListItem *litem;
188  if ( !item)
189  litem = dynamic_cast<YQPkgLangListItem *> ( currentItem() );
190  else
191  litem = dynamic_cast<YQPkgLangListItem *> ( item );
192 #endif
193 
194  actionSetCurrentInstall->setEnabled( true );
195  actionSetCurrentDontInstall->setEnabled( true );
196  actionSetCurrentTaboo->setEnabled( true );
197  actionSetCurrentProtected->setEnabled( false );
198 
199  actionSetCurrentKeepInstalled->setEnabled( false );
200  actionSetCurrentDelete->setEnabled( false );
201  actionSetCurrentUpdate->setEnabled( false );
202 }
203 
204 
206  const zypp::Locale & lang )
207  : YQPkgObjListItem( langList )
208  , _zyppLang( lang )
209 {
210  init();
211 }
212 
213 
214 
216 {
217  // NOP
218 }
219 
220 
221 void
223 {
225 }
226 
227 
228 void
230 {
231 //FIXME this is utterly broken - see bug #370233
232  // DO NOT CALL PARENT CLASS
233  _debugIsBroken = false;
234  _debugIsSatisfied = false;
235  _candidateIsNewer = false;
236  _installedIsNewer = false;
237 
238  if ( nameCol() >= 0 ) setText( nameCol(), _zyppLang.code() );
239  if ( summaryCol() >= 0 ) setText( summaryCol(), _zyppLang.name() );
240 
241  setStatusIcon();
242 }
243 
244 
245 ZyppStatus
247 {
248  if ( zypp::getZYpp()->pool().isRequestedLocale( _zyppLang ) )
249  return S_Install;
250  else
251  return S_NoInst;
252 }
253 
254 void
255 YQPkgLangListItem::setStatus( ZyppStatus newStatus, bool sendSignals )
256 {
257  ZyppStatus oldStatus = status();
258 
259  switch ( newStatus )
260  {
261  case S_Install:
262  if ( ! zypp::getZYpp()->pool().isRequestedLocale( _zyppLang ) )
263  {
264  zypp::getZYpp()->pool().addRequestedLocale( _zyppLang );
265  }
266  break;
267  case S_NoInst:
268  if ( zypp::getZYpp()->pool().isRequestedLocale( _zyppLang ) )
269  {
270  zypp::getZYpp()->pool().eraseRequestedLocale( _zyppLang );
271  }
272  break;
273  default:
274  return;
275  }
276 
277  if ( oldStatus != newStatus )
278  {
279  applyChanges();
280 
281  if ( sendSignals )
282  {
283  _pkgObjList->updateItemStates();
284  _pkgObjList->sendUpdatePackages();
285  }
286  }
287 
288  setStatusIcon();
289  _pkgObjList->sendStatusChanged();
290 }
291 
292 bool
294 {
295  return zypp::getZYpp()->pool().isRequestedLocale( _zyppLang );
296 }
297 
298 
299 void
301 {
302  if ( zypp::getZYpp()->pool().isRequestedLocale( _zyppLang ) )
303  {
304  zypp::getZYpp()->pool().eraseRequestedLocale( _zyppLang );
305  }
306  else
307  {
308  zypp::getZYpp()->pool().addRequestedLocale( _zyppLang );
309  }
310  setStatusIcon();
311  _pkgObjList->sendStatusChanged();
312 }
313 
314 bool YQPkgLangListItem::operator<( const QTreeWidgetItem & otherListViewItem ) const
315 {
316  const YQPkgLangListItem * other = dynamic_cast<const YQPkgLangListItem *> (&otherListViewItem);
317  int col = treeWidget()->sortColumn();
318 
319  if ( other )
320  {
321  if ( col == nameCol() )
322  {
323  return ( strcoll( this->zyppLang().code().c_str(), other->zyppLang().code().c_str() ) < 0 );
324  }
325  if ( col == summaryCol() )
326  {
327  return ( strcoll( this->zyppLang().name().c_str(), other->zyppLang().name().c_str() ) < 0 );
328  }
329  }
330 
331  return QY2ListViewItem::operator<( otherListViewItem );
332 }
333 #include "YQPkgLangList.moc"
Abstract base class to display a list of zypp::ResObjects.
Definition: YQPkgObjList.h:68
void setText(int column, const string text)
Set a column text via STL string.
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
virtual ZyppStatus status() const
override this two as we don&#39;t have a real selectable and the status depends on the language ...
virtual void cycleStatus()
Cycle the package status to the next valid value.
virtual ~YQPkgLangListItem()
Destructor.
void filter()
Filter according to the view&#39;s rules and current selection.
virtual void clear()
Reimplemented from QY2ListView: Emit currentItemChanged() signal after clearing the list...
void sendStatusChanged()
Emit a statusChanged() signal for the specified zypp::ResObject.
Definition: YQPkgObjList.h:248
void fillList()
Fill the language list.
virtual void updateActions(YQPkgObjListItem *item=0)
update from base class to not access selectables
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter.
YQPkgLangList(QWidget *parent)
Constructor.
virtual bool bySelection() const
Returns &#39;true&#39; if this selectable&#39;s status is set by a selection (rather than by the user or by the d...
virtual void setStatus(ZyppStatus newStatus, bool sendSignals=true)
Set the (binary RPM) package status.
void currentItemChanged(ZyppSel selectable)
Emitted when a zypp::ui::Selectable is selected.
void filterFinished()
Emitted when filtering is finished.
YQPkgLangListItem * selection() const
Returns the currently selected item or 0 if there is none.
void addLangItem(const zypp::Locale &lang)
Add a selection to the list.
Display a list of zypp::Selection objects.
Definition: YQPkgLangList.h:52
void sendUpdatePackages()
Emit an updatePackages() signal.
Definition: YQPkgObjList.h:237
YQPkgLangListItem(YQPkgLangList *pkgSelList, const zypp::Locale &lang)
Constructor.
void solveResolvableCollections()
Do a "small" solver run for all "resolvable collections", i.e., for selections, patterns, languages, patches.
void filterStart()
Emitted when the filtering starts.
virtual ~YQPkgLangList()
Destructor.
virtual void setStatusIcon()
Set a status icon according to the package&#39;s status.
zypp::Locale zyppLang() const
Returns the original object within the package manager backend.
virtual void applyChanges()
Propagate status changes in this list to other lists: Have the solver transact all languages...
virtual void init()
overloaded
virtual bool operator<(const QTreeWidgetItem &other) const
Sorting function.