File indexing completed on 2025-01-19 04:27:56

0001 /*
0002  * dvbchanneldialog.h
0003  *
0004  * Copyright (C) 2007-2011 Christoph Pfister <christophpfister@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License along
0017  * with this program; if not, write to the Free Software Foundation, Inc.,
0018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0019  */
0020 
0021 #ifndef DVBCHANNELDIALOG_H
0022 #define DVBCHANNELDIALOG_H
0023 
0024 #include <QTreeView>
0025 #include "../tablemodel.h"
0026 #include "dvbchannel.h"
0027 
0028 class QAction;
0029 
0030 class DvbChannelLessThan
0031 {
0032 public:
0033     DvbChannelLessThan() : sortOrder(ChannelNameAscending) { }
0034     ~DvbChannelLessThan() { }
0035 
0036     enum SortOrder
0037     {
0038         ChannelNameAscending,
0039         ChannelNameDescending,
0040         ChannelNumberAscending,
0041         ChannelNumberDescending
0042     };
0043 
0044     SortOrder getSortOrder() const
0045     {
0046         return sortOrder;
0047     }
0048 
0049     void setSortOrder(SortOrder sortOrder_)
0050     {
0051         sortOrder = sortOrder_;
0052     }
0053 
0054     bool operator()(const DvbSharedChannel &x, const DvbSharedChannel &y) const;
0055 
0056 private:
0057     SortOrder sortOrder;
0058 };
0059 
0060 class DvbChannelTableModelHelper
0061 {
0062 public:
0063     DvbChannelTableModelHelper() { }
0064     ~DvbChannelTableModelHelper() { }
0065 
0066     typedef DvbSharedChannel ItemType;
0067     typedef DvbChannelLessThan LessThanType;
0068 
0069     int columnCount() const
0070     {
0071         return 2;
0072     }
0073 
0074     bool filterAcceptsItem(const DvbSharedChannel &channel) const
0075     {
0076         // Qt::CaseSensitive == no filtering
0077         return ((filter.caseSensitivity() == Qt::CaseSensitive) ||
0078             (filter.indexIn(channel->name) >= 0));
0079     }
0080 
0081     QStringMatcher filter;
0082 
0083 private:
0084     Q_DISABLE_COPY(DvbChannelTableModelHelper)
0085 };
0086 
0087 class DvbChannelTableModel : public TableModel<DvbChannelTableModelHelper>
0088 {
0089     Q_OBJECT
0090 public:
0091     explicit DvbChannelTableModel(QObject *parent);
0092     ~DvbChannelTableModel();
0093 
0094     void setChannelModel(DvbChannelModel *channelModel_);
0095 
0096     DvbChannelModel *getChannelModel() const
0097     {
0098         return channelModel;
0099     }
0100 
0101     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0102     QVariant data(const QModelIndex &index, int role) const override;
0103     void sort(int column, Qt::SortOrder order) override;
0104 
0105     Qt::ItemFlags flags(const QModelIndex &index) const override;
0106     QMimeData *mimeData(const QModelIndexList &indexes) const override;
0107     QStringList mimeTypes() const override;
0108     Qt::DropActions supportedDropActions() const override;
0109     bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
0110         const QModelIndex &parent) override;
0111 
0112 public slots:
0113     void setFilter(const QString &filter);
0114 
0115 signals:
0116     void checkChannelDragAndDrop(bool *ok);
0117 
0118 private slots:
0119     void channelAdded(const DvbSharedChannel &channel);
0120     void channelAboutToBeUpdated(const DvbSharedChannel &channel);
0121     void channelUpdated(const DvbSharedChannel &channel);
0122     void channelRemoved(const DvbSharedChannel &channel);
0123 
0124 private:
0125     void customEvent(QEvent *event) override;
0126 
0127     DvbChannelModel *channelModel;
0128     QList<DvbSharedChannel> dndSelectedChannels;
0129     int dndInsertBeforeNumber;
0130     bool dndEventPosted;
0131 };
0132 
0133 class DvbChannelView : public QTreeView
0134 {
0135     Q_OBJECT
0136 public:
0137     explicit DvbChannelView(QWidget *parent);
0138     ~DvbChannelView();
0139 
0140     QAction *addEditAction();
0141     QAction *addRemoveAction();
0142     void setModel(DvbChannelTableModel *tableModel_);
0143 
0144 public slots:
0145     void checkChannelDragAndDrop(bool *ok);
0146     void editChannel();
0147     void removeChannel();
0148     void removeAllChannels();
0149 
0150 signals:
0151         void channelPidsUpdated(const DvbSharedChannel &channel);
0152 
0153 private slots:
0154     void channelPidsChanged(const DvbSharedChannel &channel);
0155 
0156 private:
0157     void setModel(QAbstractItemModel *) override { }
0158 
0159     DvbChannelTableModel *tableModel;
0160 };
0161 
0162 #endif /* DVBCHANNELDIALOG_H */