File indexing completed on 2024-04-21 04:41:01

0001 /* This file is part of the KDE project
0002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
0003    Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
0004    Copyright (C) 2016-2018 Jarosław Staniek <staniek@kde.org>
0005    Copyright (C) 2018 Dmitry Baryshev <dmitrymq@gmail.com>
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 #ifndef KPROPERTYURLEDITORPRIVATE_H
0024 #define KPROPERTYURLEDITORPRIVATE_H
0025 
0026 #include <QObject>
0027 #include <QString>
0028 #include <QUrl>
0029 #include <QVariant>
0030 
0031 class KPropertyGenericSelectionEditor;
0032 class KProperty;
0033 
0034 class QEvent;
0035 class QLineEdit;
0036 class QLocale;
0037 
0038 /*!
0039  *  A private implementation of KPropertyUrlEditor and KPropertyComposedUrlEditor
0040  *
0041  *  @warning This file is not a part of public API and must not be used by clients
0042  */
0043 class KPropertyUrlEditorPrivate : public QObject
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048     KPropertyUrlEditorPrivate(KPropertyGenericSelectionEditor *editor, const KProperty &property);
0049 
0050     //! Save a new value as a variant. Additionally allow saving regular URLs
0051     //! if the underlying type is KPropertyComposedUrl
0052     void setValue(const QVariant &newValue);
0053 
0054     //! Update the line edit after setting a new value
0055     void updateLineEdit(const QString &textToDisplay);
0056 
0057     //! @return @c true is @a url is valid for the property options
0058     //! @param[in,out] url - the URL to check and update
0059     bool checkAndUpdate(QUrl *url) const;
0060 
0061     //! Get a new URL value either from a custom or the built-in dialog
0062     QUrl getUrl();
0063 
0064     //! Process an input event from the editor
0065     void processEvent(QObject *o, QEvent *event);
0066 
0067 private:
0068     //! @return @c true if @a event is a key press event for Enter or Return key
0069     bool enterPressed(QEvent *event) const;
0070 
0071     QString fixUp(const QString &path, bool isRelative) const;
0072 
0073 Q_SIGNALS:
0074     void commitData();
0075 
0076 public:
0077     QVariant value;
0078     bool isComposedUrl;
0079     QString savedText;
0080     QLineEdit *lineEdit;
0081     QByteArray fileMode;
0082     bool confirmOverwrites;
0083     QByteArray propertyName;
0084 
0085 private:
0086     KPropertyGenericSelectionEditor *const m_editor;
0087 };
0088 
0089 #endif