picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / pkg / YQPkgLangList.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgLangList.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
24 #include <qregexp.h>
25
26 #include "YQi18n.h"
27 #include "utf8.h"
28 #include "YQPkgLangList.h"
29
30 using std::set;
31
32
33 YQPkgLangList::YQPkgLangList( QWidget * parent )
34     : YQPkgObjList( parent )
35 {
36     y2debug( "Creating language list" );
37
38     int numCol = 0;
39     addColumn( ""               );      _statusCol      = numCol++;
40
41     // Translators: Table column heading for language ISO code like "de_DE", "en_US"
42     // Please keep this short to avoid stretching the column too wide!
43     addColumn( _( "Code"        ) );    _nameCol        = numCol++;
44
45     // Full (human readable) language / country name like "German (Austria)"
46     addColumn( _( "Language" ) );       _summaryCol     = numCol++;
47     setAllColumnsShowFocus( true );
48
49     connect( this,      SIGNAL( selectionChanged        ( Q3ListViewItem * ) ),
50              this,      SLOT  ( filter()                                    ) );
51
52     fillList();
53     selectSomething();
54
55     y2debug( "Creating language list done" );
56 }
57
58
59 YQPkgLangList::~YQPkgLangList()
60 {
61     // NOP
62 }
63
64
65 void
66 YQPkgLangList::fillList()
67 {
68     clear();
69     y2debug( "Filling language list" );
70
71
72     for ( ZyppPoolIterator it = zyppLangBegin();
73           it != zyppLangEnd();
74           ++it )
75     {
76         ZyppLang zyppLang = tryCastToZyppLang( (*it)->theObj() );
77
78         if ( zyppLang )
79             addLangItem( *it, zyppLang );
80         else
81             y2error( "Found non-Language selectable" );
82     }
83
84     y2debug( "Language list filled" );
85 }
86
87
88 void
89 YQPkgLangList::filterIfVisible()
90 {
91     if ( isVisible() )
92         filter();
93 }
94
95
96 void
97 YQPkgLangList::filter()
98 {
99     emit filterStart();
100
101     if ( selection() )
102     {
103         ZyppLang lang = selection()->zyppLang();
104
105         if ( lang )
106         {
107             string currentLang = lang->name();
108
109             //
110             // Iterate over all selectables in pool
111             //
112
113             for ( ZyppPoolIterator it = zyppPkgBegin();
114                   it != zyppPkgEnd();
115                   ++it )
116             {
117                 ZyppObj zyppObj = (*it)->theObj();
118
119                 if ( zyppObj )
120                 {
121                     //
122                     // Iterate over all "freshens" dependencies of this object
123                     //
124
125                     zypp::CapSet freshens = zyppObj->dep( zypp::Dep::FRESHENS );
126
127                     for ( zypp::CapSet::const_iterator cap_it = freshens.begin();
128                           cap_it != freshens.end();
129                           ++cap_it )
130                     {
131                         if ( (*cap_it).index() == currentLang ) // obj freshens this language
132                         {
133                             ZyppPkg pkg = tryCastToZyppPkg( zyppObj );
134
135                             if ( pkg )
136                             {
137                                 y2debug( "Found pkg %s for lang %s",
138                                          pkg->name().c_str(), currentLang.c_str() );
139
140                                 emit filterMatch( *it, pkg );
141                             }
142                             else
143                             {
144                                 y2warning( "Found non-pkg obj %s for lang %s",
145                                            pkg->name().c_str(), currentLang.c_str() );
146                             }
147                         }
148                     }
149                 }
150             }
151         }
152     }
153
154     emit filterFinished();
155 }
156
157
158 void
159 YQPkgLangList::addLangItem( ZyppSel     selectable,
160                             ZyppLang    zyppLang )
161 {
162     if ( ! selectable )
163     {
164         y2error( "NULL ZyppSel!" );
165         return;
166     }
167
168     new YQPkgLangListItem( this, selectable, zyppLang );
169 }
170
171
172 YQPkgLangListItem *
173 YQPkgLangList::selection() const
174 {
175     Q3ListViewItem * item = selectedItem();
176
177     if ( ! item )
178         return 0;
179
180     return dynamic_cast<YQPkgLangListItem *> (item);
181 }
182
183
184
185
186
187
188 YQPkgLangListItem::YQPkgLangListItem( YQPkgLangList *   langList,
189                                       ZyppSel           selectable,
190                                       ZyppLang          lang            )
191     : YQPkgObjListItem( langList, selectable, lang )
192     , _langList( langList )
193     , _zyppLang( lang )
194 {
195 }
196
197
198
199 YQPkgLangListItem::~YQPkgLangListItem()
200 {
201     // NOP
202 }
203
204
205 void
206 YQPkgLangListItem::applyChanges()
207 {
208     solveResolvableCollections();
209 }
210
211
212
213
214 #include "YQPkgLangList.moc"