File indexing completed on 2024-05-12 16:40:57
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003-2014 Jarosław Staniek <staniek@kde.org> 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 KEXISTARTUPFILEHANDLER_H 0021 #define KEXISTARTUPFILEHANDLER_H 0022 0023 #include "kexiextwidgets_export.h" 0024 #include <KexiFileFilters.h> 0025 0026 #include <QObject> 0027 0028 class QUrl; 0029 class KFileDialog; 0030 class KUrlRequester; 0031 class KexiContextMessage; 0032 0033 //! @short Handler for use with file Kexi-specific opening/saving widgets/dialogs 0034 /*! Make sure this object is destroyed before the handled file dialog 0035 or URL requester, otherwise recent dirs information will not be updated. 0036 Alternativelly you can call saveRecentDir(). */ 0037 class KEXIEXTWIDGETS_EXPORT KexiStartupFileHandler : public QObject 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 /* removed in KEXI3 0043 KexiStartupFileHandler( 0044 const QUrl &startDirOrVariable, Mode mode, KFileDialog *dialog);*/ 0045 0046 //! @todo KEXI3 add equivalent of kfiledialog:/// for startDirOrVariable 0047 KexiStartupFileHandler( 0048 const QUrl &startDirOrVariable, KexiFileFilters::Mode mode, KUrlRequester *requester); 0049 0050 virtual ~KexiStartupFileHandler(); 0051 0052 /*! Helper. Displays "This file already exists. Do you want to overwrite it?" 0053 message. 0054 @return true if @a filePath file does not exists or user has agreed on overwriting, 0055 false in user do not want to overwrite. Blocks until user 'answers' 0056 by to signal askForOverwriting(const KexiContextMessage&) 0057 by triggering 'yes' or 'no' action. */ 0058 bool askForOverwriting(const QString& filePath); 0059 0060 //! @return mode for the handler. 0061 KexiFileFilters::Mode mode() const; 0062 0063 //! Sets mode for the handler. 0064 void setMode(KexiFileFilters::Mode mode); 0065 0066 QStringList additionalMimeTypes() const; 0067 0068 //! Sets additional mime types, e.g. "text/x-csv" 0069 void setAdditionalMimeTypes(const QStringList &mimeTypes); 0070 0071 QStringList excludedMimeTypes() const; 0072 0073 //! Excludes mime types 0074 void setExcludedMimeTypes(const QStringList &mimeTypes); 0075 0076 //removed in KEXI3 void setLocationText(const QString& fn); 0077 0078 //! Sets default extension which will be added after accepting 0079 //! if user didn't provided one. This method is usable when there is 0080 //! more than one filter so there is no rule what extension should be selected 0081 //! (by default first one is selected). 0082 void setDefaultExtension(const QString& ext); 0083 0084 /*! \return true if the current URL meets requies constraints 0085 (i.e. exists or doesn't exist); 0086 shows appropriate message box if needed. */ 0087 bool checkSelectedUrl(); 0088 0089 /*! If true, user will be asked to accept overwriting existing file. 0090 This is true by default. */ 0091 void setConfirmOverwrites(bool set); 0092 0093 0094 //! Updates the requested URL based on specified name. Performs any necessary character conversions. 0095 void updateUrl(const QString &name); 0096 Q_SIGNALS: 0097 void askForOverwriting(const KexiContextMessage& message); 0098 0099 protected Q_SLOTS: 0100 void slotAccepted(); 0101 void saveRecentDir(); 0102 0103 void messageWidgetActionYesTriggered(); 0104 void messageWidgetActionNoTriggered(); 0105 0106 private: 0107 void init(const QUrl &startDirOrVariable, KexiFileFilters::Mode mode); 0108 void updateFilters(); 0109 0110 class Private; 0111 Private * const d; 0112 }; 0113 0114 #endif