Warning, file /office/calligra/libs/main/KoFilterManager_p.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
0003                  2000, 2001 Werner Trobin <trobin@kde.org>
0004    Copyright (C) 2004 Nicolas Goutte <goutte@kde.org>
0005    Copyright (C) 2009 Thomas Zander <zander@kde.org>
0006 
0007 This library is free software; you can redistribute it and/or
0008 modify it under the terms of the GNU Library General Public
0009 License as published by the Free Software Foundation; either
0010 version 2 of the License, or (at your option) any later version.
0011 
0012 This library is distributed in the hope that it will be useful,
0013 but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015 Library General Public License for more details.
0016 
0017 You should have received a copy of the GNU Library General Public License
0018 along with this library; see the file COPYING.LIB.  If not, write to
0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020 Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #include "KoFilterManager_p.h"
0024 
0025 #include <QVBoxLayout>
0026 #include <QListWidget>
0027 #include <QListWidgetItem>
0028 #include <QMimeDatabase>
0029 
0030 #include <klocalizedstring.h>
0031 #include <ksqueezedtextlabel.h>
0032 
0033 #include <unistd.h>
0034 
0035 KoFilterChooser::KoFilterChooser(QWidget *parent, const QStringList &mimeTypes, const QString &/*nativeFormat*/, const QUrl &url)
0036         : KoDialog(parent),
0037         m_mimeTypes(mimeTypes)
0038 {
0039     setObjectName("kofilterchooser");
0040     setInitialSize(QSize(300, 350));
0041     setButtons(KoDialog::Ok|KoDialog::Cancel);
0042     setDefaultButton(KoDialog::Ok);
0043     setCaption(i18n("Choose Filter"));
0044     setModal(true);
0045 
0046     QWidget *page = new QWidget(this);
0047     setMainWidget(page);
0048 
0049     QVBoxLayout *layout = new QVBoxLayout(page);
0050     if (url.isValid()) {
0051         KSqueezedTextLabel *l = new KSqueezedTextLabel(url.path(), page);
0052         layout->addWidget(l);
0053     }
0054     m_filterList = new QListWidget(page);
0055     layout->addWidget(m_filterList);
0056     page->setLayout(layout);
0057 
0058     Q_ASSERT(!m_mimeTypes.isEmpty());
0059     QMimeDatabase db;
0060     for (QStringList::ConstIterator it = m_mimeTypes.constBegin();
0061             it != m_mimeTypes.constEnd();
0062             ++it) {
0063 
0064         QMimeType mime = db.mimeTypeForName(*it);
0065         const QString name = mime.isValid() ? mime.comment() : *it;
0066         if (! name.isEmpty()) {
0067             QListWidgetItem *item = new QListWidgetItem(name, m_filterList);
0068             item->setData(32, *it);
0069         }
0070     }
0071 
0072     m_filterList->sortItems();
0073 
0074     if (m_filterList->currentRow() == -1)
0075         m_filterList->setCurrentRow(0);
0076 
0077     m_filterList->setFocus();
0078 
0079     connect(m_filterList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(accept()));
0080     resize(QSize(520, 400));//.expandedTo(minimumSizeHint()));
0081 }
0082 
0083 KoFilterChooser::~KoFilterChooser()
0084 {
0085 }
0086 
0087 QString KoFilterChooser::filterSelected()
0088 {
0089     QListWidgetItem *item = m_filterList->currentItem();
0090     return item->data(32).toString();
0091 }