1
// vim: set tabstop=4 shiftwidth=4 noexpandtab
3
Gwenview - A simple image viewer for KDE
4
Copyright 2000-2004 Aur�lien G�teau
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include <kdeversion.h>
27
#include <kfilefiltercombo.h>
30
#include <kurlcombobox.h>
33
#include "gvimagesavedialog.moc"
36
static int findFormatInFilterList(const QStringList& filters, const QString& format) {
38
for(QStringList::const_iterator it=filters.begin(); it!=filters.end(); ++it,++pos) {
39
QStringList list=QStringList::split("|",*it);
40
if ( list[1].startsWith(format) ) return pos;
46
GVImageSaveDialog::GVImageSaveDialog(KURL& url, const QCString& imageFormat, QWidget* parent)
47
: KFileDialog(url.path(),QString::null,parent,"gvimagesavedialog",true)
49
, mImageFormat(imageFormat)
51
setOperationMode(KFileDialog::Saving);
53
// FIXME: Ugly code to define the filter combo label.
54
KMimeType::List types;
55
setFilterMimeType(i18n("Format:"),types,KMimeType::mimeType(""));
59
// Create our filter list
60
QStringList mimeTypes=KImageIO::mimeTypes();
61
for(QStringList::const_iterator it=mimeTypes.begin(); it!=mimeTypes.end(); ++it) {
62
QString format=KImageIO::typeForMime(*it);
64
// Create the pattern part of the filter string
65
KMimeType::Ptr mt=KMimeType::mimeType(*it);
67
for (QStringList::const_iterator patIt=mt->patterns().begin();patIt!=mt->patterns().end();++patIt) {
68
QString pattern=(*patIt).lower();
69
if (!patterns.contains(pattern)) patterns.append(pattern);
71
if (patterns.isEmpty()) {
72
patterns.append( QString("*.%1").arg(format.lower()) );
74
QString patternString=patterns.join(" ");
76
// Create the filter string
77
QString filter=QString("%1|%2 - %3 (%4)").arg(patternString).arg(format).arg(mt->comment()).arg(patternString);
80
filters.append(filter);
84
setFilter(filters.join("\n"));
86
// Select the default image format
87
int pos=findFormatInFilterList(filters,mImageFormat);
89
pos=findFormatInFilterList(filters,"PNG");
93
filterWidget->setCurrentItem(pos);
95
// Tweak the filter widget
96
filterWidget->setEditable(false);
98
connect(filterWidget,SIGNAL(activated(const QString&)),
99
this,SLOT(updateImageFormat(const QString&)) );
101
// Call slotFilterChanged() to get the list filtered by the filter we
102
// selected. If we don't use a single shot, it leads to a crash :-/
103
QTimer::singleShot(0,this,SLOT(slotFilterChanged()));
107
void GVImageSaveDialog::accept() {
108
KFileDialog::accept();
113
void GVImageSaveDialog::updateImageFormat(const QString& text) {
114
QStringList list=QStringList::split(" ",text);
115
mImageFormat=list[0].local8Bit();
117
QString name=locationEdit->currentText();
118
QString suffix=KImageIO::suffix(mImageFormat);
119
int dotPos=name.findRev('.');
121
name=name.left(dotPos);
123
name.append('.').append(suffix);
124
locationEdit->setCurrentText(name);