File indexing completed on 2024-05-12 16:40:54
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003-2018 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 KEXIFILEWIDGET_H 0021 #define KEXIFILEWIDGET_H 0022 0023 #include <config-kexi.h> 0024 0025 #ifdef KEXI_USE_KFILEWIDGET 0026 0027 #include "KexiFileWidgetInterface.h" 0028 #include <KFileWidget> 0029 0030 //! @short Widget for opening/saving files supported by Kexi 0031 /*! For simplicity, initially the widget has hidden the preview pane. */ 0032 class KEXIEXTWIDGETS_EXPORT KexiFileWidget : public KFileWidget, public KexiFileWidgetInterface 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 //! @todo KEXI3 add equivalent of kfiledialog:/// for startDirOrVariable 0038 KexiFileWidget(const QUrl &startDirOrVariable, KexiFileFilters::Mode mode, 0039 const QString &fileName, QWidget *parent = nullptr); 0040 0041 KexiFileWidget(const QUrl &startDirOrVariable, KexiFileFilters::Mode mode, 0042 QWidget *parent = nullptr); 0043 0044 ~KexiFileWidget() override; 0045 0046 using KFileWidget::setMode; 0047 0048 /** 0049 * Returns the full path of the selected file in the local filesystem. 0050 * (Local files only) 0051 */ 0052 QString selectedFile() const override; 0053 0054 /** 0055 * Returns the full path of the highlighted file in the local filesystem. 0056 * (Local files only) 0057 */ 0058 QString highlightedFile() const override; 0059 0060 /** 0061 * @return the currently shown directory. 0062 */ 0063 QString currentDir() const override; 0064 0065 public Q_SLOTS: 0066 void setMode(KexiFileFilters::Mode mode); 0067 0068 //! Just sets locationWidget()->setCurrentText(text) 0069 //void setLocationText(const QString& text) override; 0070 0071 /** 0072 * Sets the file name to preselect to @p name 0073 * 0074 * This takes absolute URLs and relative file names. 0075 */ 0076 void setSelectedFile(const QString &name) override; 0077 0078 //! Typing a file that doesn't exist closes the file dialog, we have to 0079 //! handle this case better here. 0080 virtual void accept(); 0081 0082 /** 0083 * Sets whether the line edit draws itself with a frame. 0084 */ 0085 void setWidgetFrame(bool set) override; 0086 0087 Q_SIGNALS: 0088 void fileHighlighted(const QString &name); 0089 void fileSelected(const QString &name); 0090 void rejected(); 0091 0092 protected Q_SLOTS: 0093 virtual void reject(); 0094 void slotFileHighlighted(const QUrl& url); 0095 void slotFileSelected(const QUrl& url); 0096 0097 protected: 0098 virtual void showEvent(QShowEvent *event) override; 0099 0100 virtual void focusInEvent(QFocusEvent *event) override; 0101 0102 /** 0103 * Updates filters in the widget based on current filter selection. 0104 */ 0105 void updateFilters() override; 0106 0107 void applyEnteredFileName() override; 0108 0109 QStringList currentFilters() const override; 0110 0111 private: 0112 class Private; 0113 Private * const d; 0114 }; 0115 0116 #endif // KEXI_USE_KFILEWIDGET 0117 #endif // KEXIFILEWIDGET_H