File indexing completed on 2024-04-28 16:44:26

0001 /*  This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2000-2008 David Faure <faure@kde.org>
0003     SPDX-FileCopyrightText: 2008 Urs Wolfer <uwolfer @ kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #ifndef FILETYPESVIEW_H
0009 #define FILETYPESVIEW_H
0010 
0011 #include <QLabel>
0012 #include <QList>
0013 #include <QMap>
0014 #include <QStackedWidget>
0015 
0016 #include <KCModule>
0017 #include <KSharedConfig>
0018 
0019 #include "typeslistitem.h"
0020 
0021 class QTreeWidget;
0022 class QTreeWidgetItem;
0023 class QPushButton;
0024 class KLineEdit;
0025 class FileTypeDetails;
0026 class FileGroupDetails;
0027 
0028 class FileTypesView : public KCModule
0029 {
0030     Q_OBJECT
0031 public:
0032     FileTypesView(QWidget *parent, const QVariantList &args);
0033     ~FileTypesView() override;
0034 
0035     void load() override;
0036     void save() override;
0037     void defaults() override;
0038 
0039 protected Q_SLOTS:
0040     void addType();
0041     void removeType();
0042     void updateDisplay(QTreeWidgetItem *);
0043     void slotDoubleClicked(QTreeWidgetItem *);
0044     void slotFilter(const QString &patternFilter);
0045     void setDirty(bool state);
0046 
0047     void slotDatabaseChanged();
0048     void slotEmbedMajor(const QString &major, bool &embed);
0049 
0050 private:
0051     void readFileTypes();
0052     void updateRemoveButton(TypesListItem *item);
0053 
0054 private:
0055     QTreeWidget *typesLV;
0056     QPushButton *m_removeTypeB;
0057 
0058     QStackedWidget *m_widgetStack;
0059     FileTypeDetails *m_details;
0060     FileGroupDetails *m_groupDetails;
0061     QLabel *m_emptyWidget;
0062 
0063     KLineEdit *patternFilterLE;
0064     QStringList removedList;
0065     bool m_dirty;
0066     bool m_removeButtonSaysRevert;
0067     QMap<QString, TypesListItem *> m_majorMap; // groups
0068     QList<TypesListItem *> m_itemList;
0069 
0070     KSharedConfig::Ptr m_fileTypesConfig;
0071 };
0072 
0073 // helper class for loading the icon on request instead of preloading lots of probably
0074 // unused icons which takes quite a lot of time
0075 class TypesListTreeWidget : public QTreeWidget
0076 {
0077     Q_OBJECT
0078 public:
0079     explicit TypesListTreeWidget(QWidget *parent)
0080         : QTreeWidget(parent)
0081     {
0082     }
0083 
0084 protected:
0085     void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
0086     {
0087         static_cast<TypesListItem *>(itemFromIndex(index))->loadIcon();
0088 
0089         QTreeWidget::drawRow(painter, option, index);
0090     }
0091 };
0092 
0093 #endif