File indexing completed on 2024-04-28 04:57:31
0001 /*************************************************************************** 0002 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program 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 * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 0018 ***************************************************************************/ 0019 0020 #ifndef DLGCHECKSUMSEARCH_H 0021 #define DLGCHECKSUMSEARCH_H 0022 0023 #include "ui_checksumsearch.h" 0024 #include "ui_checksumsearchadddlg.h" 0025 0026 #include "checksumsearchtransferdatasource.h" 0027 0028 #include <QStyledItemDelegate> 0029 0030 #include <KCModule> 0031 #include <QDialog> 0032 0033 class QSortFilterProxyModel; 0034 class QStandardItemModel; 0035 class QStringListModel; 0036 0037 class ChecksumSearchAddDlg : public QDialog 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 ChecksumSearchAddDlg(QStringListModel *modesModel, QStringListModel *typesModel, QWidget *parent = nullptr, Qt::WindowFlags flags = {}); 0043 0044 Q_SIGNALS: 0045 /** 0046 * Emitted when the dialog gets accepted 0047 * @param change the string that should change the source url by mode 0048 * @param mode the change mode 0049 * @param type the checksum type, can be an empty string 0050 */ 0051 void addItem(const QString &change, int mode, const QString &type); 0052 0053 private Q_SLOTS: 0054 /** 0055 * Enables or disables buttons depending on if the user entered text or not, also changes 0056 * the label etc. 0057 */ 0058 void slotUpdate(); 0059 0060 void slotAccpeted(); 0061 0062 private: 0063 Ui::ChecksumSearchAddDlg ui; 0064 0065 QStringListModel *m_modesModel; 0066 QStringListModel *m_typesModel; 0067 0068 static const QUrl URL; 0069 }; 0070 0071 class ChecksumDelegate : public QStyledItemDelegate 0072 { 0073 Q_OBJECT 0074 0075 public: 0076 ChecksumDelegate(QObject *parent = nullptr); 0077 ChecksumDelegate(QStringListModel *modesModel, QStringListModel *typesModel, QObject *parent = nullptr); 0078 0079 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0080 void setEditorData(QWidget *editor, const QModelIndex &index) const override; 0081 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; 0082 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0083 0084 private: 0085 QStringListModel *m_modesModel; 0086 QStringListModel *m_typesModel; 0087 }; 0088 0089 class DlgChecksumSettingsWidget : public KCModule 0090 { 0091 Q_OBJECT 0092 0093 public: 0094 explicit DlgChecksumSettingsWidget(QObject *parent = nullptr, const KPluginMetaData &args = {}); 0095 ~DlgChecksumSettingsWidget() override; 0096 0097 public Q_SLOTS: 0098 void save() override; 0099 void load() override; 0100 0101 private Q_SLOTS: 0102 /** 0103 * Oppens the AddDlg 0104 */ 0105 void slotAdd(); 0106 0107 /** 0108 * Remove the selected indexes 0109 */ 0110 void slotRemove(); 0111 0112 /** 0113 * Enables or disables buttons depending on if the user entered text or not, also changes 0114 * the label etc. 0115 */ 0116 void slotUpdate(); 0117 0118 /** 0119 * Adds a new item defining how to proceed a search for checksums to the model 0120 * @param change the string that should change the source url by mode 0121 * @param mode the change mode, defined in verifier.h, using int instead of enum as convenience 0122 * @param type the checksum type, like e.g. "md5", empty if you do not know that 0123 * e.g. if change is "CHECKSUMS" you cannot know which checksums are present 0124 */ 0125 void slotAddItem(const QString &change, int mode, const QString &type = QString()); 0126 0127 private: 0128 Ui::ChecksumSearch ui; 0129 QStandardItemModel *m_model; 0130 QSortFilterProxyModel *m_proxy; 0131 QStringList m_modes; 0132 QStringListModel *m_modesModel; 0133 QStringListModel *m_typesModel; 0134 }; 0135 0136 #endif // DLGCHECKSUMSEARCH_H