1 | /* This file is part of the KDE project |
2 | Copyright (C) 2000 - 2008 David Faure <faure@kde.org> |
3 | Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org> |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License or ( at |
8 | your option ) version 3 or, at the discretion of KDE e.V. ( which shall |
9 | act as a proxy as in section 14 of the GPLv3 ), any later version. |
10 | |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; see the file COPYING. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #ifndef FILETYPESVIEW_H |
23 | #define FILETYPESVIEW_H |
24 | |
25 | #include <QtCore/QList> |
26 | #include <QtCore/QMap> |
27 | #include <QLabel> |
28 | #include <QStackedWidget> |
29 | |
30 | #include <KSharedConfig> |
31 | #include <KCModule> |
32 | |
33 | #include "typeslistitem.h" |
34 | |
35 | class QLabel; |
36 | class QTreeWidget; |
37 | class QTreeWidgetItem; |
38 | class KPushButton; |
39 | class KLineEdit; |
40 | class FileTypeDetails; |
41 | class FileGroupDetails; |
42 | class QStackedWidget; |
43 | |
44 | class FileTypesView : public KCModule |
45 | { |
46 | Q_OBJECT |
47 | public: |
48 | FileTypesView(QWidget *parent, const QVariantList &args); |
49 | ~FileTypesView(); |
50 | |
51 | void load(); |
52 | void save(); |
53 | void defaults(); |
54 | |
55 | protected Q_SLOTS: |
56 | void addType(); |
57 | void removeType(); |
58 | void updateDisplay(QTreeWidgetItem *); |
59 | void slotDoubleClicked(QTreeWidgetItem *); |
60 | void slotFilter(const QString &patternFilter); |
61 | void setDirty(bool state); |
62 | |
63 | void slotDatabaseChanged(const QStringList& changedResources); |
64 | void slotEmbedMajor(const QString &major, bool &embed); |
65 | |
66 | private: |
67 | void readFileTypes(); |
68 | void updateRemoveButton(TypesListItem* item); |
69 | |
70 | private: |
71 | QTreeWidget *typesLV; |
72 | KPushButton *m_removeTypeB; |
73 | |
74 | QStackedWidget * m_widgetStack; |
75 | FileTypeDetails * m_details; |
76 | FileGroupDetails * m_groupDetails; |
77 | QLabel * m_emptyWidget; |
78 | |
79 | KLineEdit *patternFilterLE; |
80 | QStringList removedList; |
81 | bool m_dirty; |
82 | bool m_removeButtonSaysRevert; |
83 | QMap<QString,TypesListItem*> m_majorMap; // groups |
84 | QList<TypesListItem *> m_itemList; |
85 | |
86 | KSharedConfig::Ptr m_fileTypesConfig; |
87 | }; |
88 | |
89 | |
90 | // helper class for loading the icon on request instead of preloading lots of probably |
91 | // unused icons which takes quite a lot of time |
92 | class TypesListTreeWidget : public QTreeWidget |
93 | { |
94 | Q_OBJECT |
95 | public: |
96 | TypesListTreeWidget(QWidget *parent) |
97 | : QTreeWidget(parent) { |
98 | } |
99 | |
100 | protected: |
101 | void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { |
102 | static_cast<TypesListItem *>(itemFromIndex(index))->loadIcon(); |
103 | |
104 | QTreeWidget::drawRow(painter, option, index); |
105 | } |
106 | }; |
107 | |
108 | #endif |
109 | |