File indexing completed on 2024-04-21 03:55:19

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2001, 2002, 2003 Carsten Pfeiffer <pfeiffer@kde.org>
0004     SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KFILEPLACEEDITDIALOG_H
0010 #define KFILEPLACEEDITDIALOG_H
0011 
0012 #include "kiofilewidgets_export.h"
0013 
0014 #include <KIconLoader>
0015 #include <QDialog>
0016 #include <QUrl>
0017 
0018 class QCheckBox;
0019 class QDialogButtonBox;
0020 class QLineEdit;
0021 class KIconButton;
0022 class KUrlRequester;
0023 
0024 /**
0025  * @class KFilePlaceEditDialog kfileplaceeditdialog.h <KFilePlaceEditDialog>
0026  *
0027  * A dialog that allows editing entries of a KFilePlacesModel.
0028  * The dialog offers to configure a given url, label and icon.
0029  * See the class-method getInformation() for easy usage.
0030  *
0031  * @author Carsten Pfeiffer <pfeiffer@kde.org>
0032  * @since 5.53
0033  */
0034 class KIOFILEWIDGETS_EXPORT KFilePlaceEditDialog : public QDialog
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     /**
0040      * A convenience method to show the dialog and retrieve all the
0041      * properties via the given parameters. The parameters are used to
0042      * initialize the dialog and then return the user-configured values.
0043      *
0044      * @p allowGlobal if you set this to true, the dialog will have a checkbox
0045      *                for the user to decide if he wants the entry to be
0046      *                available globally or just for the current application.
0047      * @p url the url of the item
0048      * @p label a short, translated description of the item
0049      * @p icon an icon for the item
0050      * @p appLocal tells whether the item should be local for this application
0051      *             or be available globally
0052      * @p iconSize determines the size of the icon that is shown/selectable
0053      * @p parent the parent-widget for the dialog
0054      *
0055      * If you leave the icon empty, the default icon for the given url will be
0056      * used (KMimeType::pixmapForUrl()).
0057      */
0058     static bool
0059     getInformation(bool allowGlobal, QUrl &url, QString &label, QString &icon, bool isAddingNewPlace, bool &appLocal, int iconSize, QWidget *parent = nullptr);
0060 
0061     /**
0062      * Constructs a KFilePlaceEditDialog.
0063      *
0064      * @p allowGlobal if you set this to true, the dialog will have a checkbox
0065      *                for the user to decide if he wants the entry to be
0066      *                available globally or just for the current application.
0067      * @p url the url of the item
0068      * @p label a short, translated description of the item
0069      * @p icon an icon for the item
0070      * @p appLocal tells whether the item should be local for this application
0071      *             or be available globally
0072      * @p iconSize determines the size of the icon that is shown/selectable
0073      * @p parent the parent-widget for the dialog
0074      *
0075      * If you leave the icon empty, the default icon for the given url will be
0076      * used (KMimeType::pixmapForUrl()).
0077      */
0078     KFilePlaceEditDialog(bool allowGlobal,
0079                          const QUrl &url,
0080                          const QString &label,
0081                          const QString &icon,
0082                          bool isAddingNewPlace,
0083                          bool appLocal = true,
0084                          int iconSize = KIconLoader::SizeMedium,
0085                          QWidget *parent = nullptr);
0086     /**
0087      * Destroys the dialog.
0088      */
0089     ~KFilePlaceEditDialog() override;
0090 
0091     /**
0092      * @returns the configured url
0093      */
0094     QUrl url() const;
0095 
0096     /**
0097      * @returns the configured label
0098      */
0099     QString label() const;
0100 
0101     /**
0102      * @returns the configured icon
0103      */
0104     QString icon() const;
0105 
0106     /**
0107      * @returns whether the item should be local to the application or global.
0108      * If allowGlobal was set to false in the constructor, this will always
0109      * return true.
0110      */
0111     bool applicationLocal() const;
0112 
0113 public Q_SLOTS:
0114     void urlChanged(const QString &);
0115 
0116 private:
0117     /**
0118      * The KUrlRequester used for editing the url
0119      */
0120     KUrlRequester *m_urlEdit;
0121     /**
0122      * The QLineEdit used for editing the label
0123      */
0124     QLineEdit *m_labelEdit;
0125     /**
0126      * The KIconButton to configure the icon
0127      */
0128     KIconButton *m_iconButton;
0129     /**
0130      * The QCheckBox to modify the local/global setting
0131      */
0132     QCheckBox *m_appLocal;
0133 
0134     QDialogButtonBox *m_buttonBox;
0135 };
0136 
0137 #endif // KFILEPLACEEDITDIALOG_H