26 #include <QtCore/QEvent>
27 #include <QtGui/QLineEdit>
29 class KFileFilterCombo::Private
34 hasAllSupportedFiles(false),
40 void _k_slotFilterChanged();
47 bool hasAllSupportedFiles;
58 :
KComboBox(true, parent), d( new Private(this) )
61 setInsertPolicy(QComboBox::NoInsert);
62 connect(
this, SIGNAL(activated(
int)),
this, SIGNAL(
filterChanged()));
64 connect(
this, SIGNAL(
filterChanged()), SLOT(_k_slotFilterChanged()));
65 d->m_allTypes =
false;
77 d->hasAllSupportedFiles =
false;
79 if (!filter.isEmpty()) {
81 int index = tmp.indexOf(
'\n');
83 d->m_filters.append(tmp.left(index));
84 tmp = tmp.mid(index + 1);
85 index = tmp.indexOf(
'\n');
87 d->m_filters.append(tmp);
90 d->m_filters.append( d->defaultFilter );
92 QStringList::ConstIterator it;
93 QStringList::ConstIterator
end(d->m_filters.constEnd());
94 for (it = d->m_filters.constBegin(); it !=
end; ++it) {
95 int tab = (*it).indexOf(
'|');
96 addItem((tab < 0) ? *it :
100 d->lastFilter = currentText();
101 d->isMimeFilter =
false;
107 if (f == itemText(currentIndex())) {
108 f = d->m_filters.value(currentIndex());
109 if ( d->isMimeFilter || (currentIndex() == 0 && d->hasAllSupportedFiles) ) {
114 int tab = f.indexOf(
'|');
123 return d->m_allTypes;
133 setCurrentIndex(d->m_filters.indexOf(filter));
141 d->m_filters.clear();
142 QString delim = QLatin1String(
", ");
143 d->hasAllSupportedFiles =
false;
144 bool hasAllFilesFilter =
false;
146 d->m_allTypes = defaultType.isEmpty() && (types.count() > 1);
149 for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
159 if ( type->name().startsWith( QLatin1String(
"all/" ) ) ) {
160 hasAllFilesFilter =
true;
164 if ( d->m_allTypes && it != types.begin() ) {
165 allComments += delim;
169 d->m_filters.append( type->name() );
172 allTypes += type->name();
173 allComments += type->comment();
175 addItem( type->comment() );
176 if ( type->name() == defaultType )
177 setCurrentIndex( count() - 1 );
183 insertItem(0, allComments);
185 insertItem(0,
i18n(
"All Supported Files"));
186 d->hasAllSupportedFiles =
true;
188 setCurrentIndex( 0 );
190 d->m_filters.prepend( allTypes );
193 if ( hasAllFilesFilter ) {
194 addItem(
i18n(
"All Files"));
195 d->m_filters.append( QLatin1String(
"all/allfiles") );
198 d->lastFilter = currentText();
199 d->isMimeFilter =
true;
202 void KFileFilterCombo::Private::_k_slotFilterChanged()
204 lastFilter = parent->currentText();
209 if ( o == lineEdit() && e->type() == QEvent::FocusOut ) {
210 if ( currentText() != d->lastFilter )
219 d->defaultFilter = filter;
224 return d->defaultFilter;
229 return d->isMimeFilter;
232 #include "kfilefiltercombo.moc"