libyui-qt-pkg  2.47.5
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  }
156  emit filterFinished();
157 }
158 
159 void
160 YQPkgLangList::addLangItem( const zypp::Locale &zyppLang )
161 {
162  new YQPkgLangListItem( this, zyppLang );
163 }
164 
165 
168 {
169  QTreeWidgetItem * item = currentItem();
170 
171  if ( ! item )
172  return 0;
173 
174  return dynamic_cast<YQPkgLangListItem *> (item);
175 }
176 
177 
178 void
180 {
181 #if 0
182  YQPkgLangListItem *litem;
183  if ( !item)
184  litem = dynamic_cast<YQPkgLangListItem *> ( currentItem() );
185  else
186  litem = dynamic_cast<YQPkgLangListItem *> ( item );
187 #endif
188 
189  actionSetCurrentInstall->setEnabled( true );
190  actionSetCurrentDontInstall->setEnabled( true );
191  actionSetCurrentTaboo->setEnabled( true );
192  actionSetCurrentProtected->setEnabled( false );
193 
194  actionSetCurrentKeepInstalled->setEnabled( false );
195  actionSetCurrentDelete->setEnabled( false );
196  actionSetCurrentUpdate->setEnabled( false );
197 }
198 
199 
201  const zypp::Locale & lang )
202  : YQPkgObjListItem( langList )
203  , _zyppLang( lang )
204 {
205  init();
206 }
207 
208 
209 
211 {
212  // NOP
213 }
214 
215 
216 void
218 {
220 }
221 
222 
223 void
225 {
226 //FIXME this is utterly broken - see bug #370233
227  // DO NOT CALL PARENT CLASS
228  _debugIsBroken = false;
229  _debugIsSatisfied = false;
230  _candidateIsNewer = false;
231  _installedIsNewer = false;
232 
233  if ( nameCol() >= 0 ) setText( nameCol(), _zyppLang.code() );
234  if ( summaryCol() >= 0 ) setText( summaryCol(), _zyppLang.name() );
235 
236  setStatusIcon();
237 }
238 
239 
240 ZyppStatus
242 {
243  if ( zypp::getZYpp()->pool().isRequestedLocale( _zyppLang ) )
244  return S_Install;
245  else
246  return S_NoInst;
247 }
248 
249 void
250 YQPkgLangListItem::setStatus( ZyppStatus newStatus, bool sendSignals )
251 {
252  ZyppStatus oldStatus = status();
253 
254  switch ( newStatus )
255  {
256  case S_Install:
257  if ( ! zypp::getZYpp()->pool().isRequestedLocale( _zyppLang ) )
258  {
259  zypp::getZYpp()->pool().addRequestedLocale( _zyppLang );
260  }
261  break;
262  case S_NoInst:
263  if ( zypp::getZYpp()->pool().isRequestedLocale( _zyppLang ) )
264  {
265  zypp::getZYpp()->pool().eraseRequestedLocale( _zyppLang );
266  }
267  break;
268  default:
269  return;
270  }
271 
272  if ( oldStatus != newStatus )
273  {
274  applyChanges();
275 
276  if ( sendSignals )
277  {
278  _pkgObjList->updateItemStates();
279  _pkgObjList->sendUpdatePackages();
280  }
281  }
282 
283  setStatusIcon();
284  _pkgObjList->sendStatusChanged();
285 }
286 
287 bool
289 {
290  return zypp::getZYpp()->pool().isRequestedLocale( _zyppLang );
291 }
292 
293 
294 void
296 {
297  if ( zypp::getZYpp()->pool().isRequestedLocale( _zyppLang ) )
298  {
299  zypp::getZYpp()->pool().eraseRequestedLocale( _zyppLang );
300  }
301  else
302  {
303  zypp::getZYpp()->pool().addRequestedLocale( _zyppLang );
304  }
305  setStatusIcon();
306  _pkgObjList->sendStatusChanged();
307 }
308 
309 bool YQPkgLangListItem::operator<( const QTreeWidgetItem & otherListViewItem ) const
310 {
311  const YQPkgLangListItem * other = dynamic_cast<const YQPkgLangListItem *> (&otherListViewItem);
312  int col = treeWidget()->sortColumn();
313 
314  if ( other )
315  {
316  if ( col == nameCol() )
317  {
318  return ( strcoll( this->zyppLang().code().c_str(), other->zyppLang().code().c_str() ) < 0 );
319  }
320  if ( col == summaryCol() )
321  {
322  return ( strcoll( this->zyppLang().name().c_str(), other->zyppLang().name().c_str() ) < 0 );
323  }
324  }
325 
326  return QY2ListViewItem::operator<( otherListViewItem );
327 }
Abstract base class to display a list of zypp::ResObjects.
Definition: YQPkgObjList.h:66
void setText(int column, const string text)
Set a column text via STL string.
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...
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
virtual void cycleStatus()
Cycle the package status to the next valid value.
virtual bool operator<(const QTreeWidgetItem &other) const
Sorting function.
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...
zypp::Locale zyppLang() const
Returns the original object within the package manager backend.
void sendStatusChanged()
Emit a statusChanged() signal for the specified zypp::ResObject.
Definition: YQPkgObjList.h:241
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.
YQPkgLangListItem * selection() const
Returns the currently selected item or 0 if there is none.
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 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.
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:230
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.
virtual void applyChanges()
Propagate status changes in this list to other lists: Have the solver transact all languages...
virtual void init()
overloaded