Warning, file /office/calligra/libs/widgetutils/KoFileDialog.h 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) 2013 - 2014 Yue Liu <yue.liu@mail.com>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KOFILEDIALOG_H
0021 #define KOFILEDIALOG_H
0022 
0023 #include "kowidgetutils_export.h"
0024 
0025 #include <QFileDialog>
0026 #include <QString>
0027 #include <QUrl>
0028 #include <QStringList>
0029 #include <QList>
0030 
0031 
0032 /**
0033  * Wrapper around QFileDialog providing native file dialogs
0034  * on KDE/Gnome/Windows/OSX/etc.
0035  */
0036 class KOWIDGETUTILS_EXPORT KoFileDialog : public QObject
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     enum DialogType {
0042         OpenFile,
0043         OpenFiles,
0044         OpenDirectory,
0045         ImportFile,
0046         ImportFiles,
0047         ImportDirectory,
0048         SaveFile
0049     };
0050 
0051     /**
0052      * @brief constructor
0053      * @param parent The parent of the file dialog
0054      * @param dialogType usage of the file dialog
0055      * @param dialogName the name for the file dialog. This will be used to open
0056      * the filedialog in the last open location, instead the specified directory.
0057      *
0058      * @return The name of the entry user selected in the file dialog
0059      *
0060      */
0061     KoFileDialog(QWidget *parent,
0062                  KoFileDialog::DialogType type,
0063                  const QString &dialogName);
0064 
0065     ~KoFileDialog() override;
0066 
0067     void setCaption(const QString &caption);
0068 
0069     /**
0070      * @brief setDefaultDir set the default directory to defaultDir
0071      *
0072      * @param defaultDir a path to a file or directory
0073      */
0074     void setDefaultDir(const QString &defaultDir, bool override = false);
0075 
0076     /**
0077      * @brief setOverrideDir override both the default dir and the saved dir found by dialogName
0078      * @param overrideDir a path to a file or directory
0079      */
0080     void setOverrideDir(const QString &overrideDir);
0081 
0082     /**
0083      * @brief setImageFilters sets the name filters for the file dialog to all
0084      * image formats Qt's QImageReader supports.
0085      */
0086     void setImageFilters();
0087 
0088     void setNameFilter(const QString &filter);
0089 
0090     /**
0091      * @brief setNameFilters set a list of description/extension pairs.
0092      *
0093      * These are not registered mimetypes. In contrast with Qt's filedialog namefilters,
0094      * you can only have _one_ pair per line. I.e.
0095      *
0096      * Gif Image (*gif)
0097      * Tiff Image (*tif)
0098      *
0099      * And NOT Images (*gif *tif)
0100      *
0101      * @param filterList
0102      * @param defaultFilter
0103      */
0104     void setNameFilters(const QStringList &filterList,
0105                         QString defaultFilter = QString());
0106     void setMimeTypeFilters(const QStringList &filterList,
0107                             QString defaultFilter = QString());
0108     void setHideNameFilterDetailsOption();
0109 
0110     QStringList nameFilters() const;
0111 
0112     QStringList filenames();
0113     QString filename();
0114 
0115     /**
0116      * @brief selectedNameFilter returns the name filter the user selected, either
0117      *    directory or by clicking on it.
0118      * @return
0119      */
0120     QString selectedNameFilter() const;
0121 
0122     QString selectedMimeType() const;
0123 
0124 private Q_SLOTS:
0125 
0126     void filterSelected(const QString &filter);
0127 
0128 private:
0129     /**
0130      * @brief splitNameFilter take a single line of a QDialog name filter and split it
0131      *   into several lines. This is needed because a single line name filter can contain
0132      *   more than one mimetype, making it impossible to figure out the correct extension.
0133      *
0134      *   The methods takes care of some duplicated extensions, like jpeg and jpg.
0135      * @param nameFilter the namefilter to be split
0136      * @param mimeList a pointer to the list with mimes that shouldn't be added.
0137      * @return a stringlist of all name filters.
0138      */
0139     static QStringList splitNameFilter(const QString &nameFilter, QStringList *mimeList);
0140 
0141     void createFileDialog();
0142 
0143     QString getUsedDir(const QString &dialogName);
0144     void saveUsedDir(const QString &fileName, const QString &dialogName);
0145 
0146     const QStringList getFilterStringListFromMime(const QStringList &mimeList,
0147                                                   bool withAllSupportedEntry = false);
0148 
0149 
0150 
0151     class Private;
0152     Private * const d;
0153 };
0154 
0155 #endif /* KOFILEDIALOG_H */