1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/* This file is part of the KDE project
Copyright (C) 2013 - 2014 Yue Liu <yue.liu@mail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOFILEDIALOG_H
#define KOFILEDIALOG_H
#include "kowidgets_export.h"
#include <QFileDialog>
#include <QString>
#include <QUrl>
#include <QStringList>
#include <QList>
/**
* Wrapper around QFileDialog providing native file dialogs
* on KDE/Gnome/Windows/OSX/etc.
*/
class KOWIDGETS_EXPORT KoFileDialog : public QObject
{
Q_OBJECT
public:
enum DialogType {
OpenFile,
OpenFiles,
OpenDirectory,
ImportFile,
ImportFiles,
ImportDirectory,
SaveFile
};
/**
* @brief constructor
* @param parent The parent of the file dialog
* @param dialogType usage of the file dialog
* @param dialogName the name for the file dialog. This will be used to open
* the filedialog in the last open location, instead the specified directory.
*
* @return The name of the entry user selected in the file dialog
*
*/
KoFileDialog(QWidget *parent,
KoFileDialog::DialogType type,
const QString &dialogName);
~KoFileDialog();
void setCaption(const QString &caption);
/**
* @brief setDefaultDir set the default directory to defaultDir
*
* @param defaultDir a path to a file or directory
*/
void setDefaultDir(const QString &defaultDir, bool override = false);
/**
* @brief setOverrideDir override both the default dir and the saved dir found by dialogName
* @param overrideDir a path to a file or directory
*/
void setOverrideDir(const QString &overrideDir);
/**
* @brief setImageFilters sets the name filters for the file dialog to all
* image formats Qt's QImageReader supports.
*/
void setImageFilters();
void setNameFilter(const QString &filter);
/**
* @brief setNameFilters set a list of description/extension pairs.
*
* These are not registered mimetypes. In contrast with Qt's filedialog namefilters,
* you can only have _one_ pair per line. I.e.
*
* Gif Image (*gif)
* Tiff Image (*tif)
*
* And NOT Images (*gif *tif)
*
* @param filterList
* @param defaultFilter
*/
void setNameFilters(const QStringList &filterList,
QString defaultFilter = QString());
void setMimeTypeFilters(const QStringList &filterList,
QString defaultFilter = QString());
void setHideNameFilterDetailsOption();
QStringList nameFilters() const;
QStringList urls();
QString url();
/**
* @brief selectedNameFilter returns the name filter the user selected, either
* directory or by clicking on it.
* @return
*/
QString selectedNameFilter() const;
QString selectedMimeType() const;
private Q_SLOTS:
void filterSelected(const QString &filter);
private:
/**
* @brief splitNameFilter take a single line of a QDialog name filter and split it
* into several lines. This is needed because a single line name filter can contain
* more than one mimetype, making it impossible to figure out the correct extension.
*
* The methods takes care of some duplicated extensions, like jpeg and jpg.
* @param nameFilter the namefilter to be split
* @param mimeList a pointer to the list with mimes that shouldn't be added.
* @return a stringlist of all name filters.
*/
static QStringList splitNameFilter(const QString &nameFilter, QStringList *mimeList);
void createFileDialog();
QString getUsedDir(const QString &dialogName);
void saveUsedDir(const QString &fileName, const QString &dialogName);
const QStringList getFilterStringListFromMime(const QStringList &mimeList,
bool withAllSupportedEntry = false);
class Private;
Private * const d;
};
#endif /* KOFILEDIALOG_H */
|