File indexing completed on 2024-05-12 04:52:16

0001 /*
0002  * dvbrecording.h
0003  *
0004  * Copyright (C) 2009-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 DVBRECORDING_H
0022 #define DVBRECORDING_H
0023 
0024 #include <QDateTime>
0025 #include <QTextStream>
0026 #include "dvbchannel.h"
0027 
0028 class DvbManager;
0029 class DvbRecordingFile;
0030 class DvbEpgEntry;
0031 
0032 class DvbRecording : public SharedData, public SqlKey
0033 {
0034 
0035 public:
0036     DvbRecording() : repeat(0), status(Inactive) { disabled = false; }
0037     ~DvbRecording() { }
0038 
0039     // checks that all variables are ok and updates 'end'
0040     // 'sqlKey' and 'status' are ignored
0041     bool validate();
0042 
0043 
0044     enum Status {
0045         Inactive,
0046         Recording,
0047         Error
0048     };
0049 
0050     QString name;
0051     QString filename;
0052     QString subheading;
0053     QString details;
0054     DvbSharedChannel channel;
0055     QDateTime begin; // UTC
0056     QDateTime end; // UTC, read-only
0057     QTime duration;
0058     QDateTime beginEPG; // What EPG claims to be the beginning of the program, local time
0059     QDateTime endEPG;
0060     QTime durationEPG;
0061     int repeat; // (1 << 0) (monday) | (1 << 1) (tuesday) | ... | (1 << 6) (sunday)
0062     int priority;
0063     bool disabled;
0064     Status status; // read-only
0065 };
0066 
0067 typedef ExplicitlySharedDataPointer<const DvbRecording> DvbSharedRecording;
0068 Q_DECLARE_TYPEINFO(DvbSharedRecording, Q_MOVABLE_TYPE);
0069 
0070 class DvbRecordingModel : public QObject, private SqlInterface
0071 {
0072     Q_OBJECT
0073 public:
0074     DvbRecordingModel(DvbManager *manager_, QObject *parent);
0075     ~DvbRecordingModel();
0076 
0077     bool hasRecordings() const;
0078     void setEmptyAction(QString emptyAction);
0079     QString getEmptyAction();
0080     bool hasActiveRecordings() const;
0081     DvbSharedRecording findRecordingByKey(const SqlKey &sqlKey) const;
0082     QMap<SqlKey, DvbSharedRecording> getRecordings() const;
0083     QList<DvbSharedRecording> getUnwantedRecordings() const;
0084     DvbSharedRecording addRecording(DvbRecording &recording, bool checkForRecursion=false);
0085     void updateRecording(DvbSharedRecording recording, DvbRecording &modifiedRecording);
0086     void removeRecording(DvbSharedRecording recording);
0087     void addToUnwantedRecordings(DvbSharedRecording recording);
0088     void findNewRecordings();
0089     void removeDuplicates();
0090     void executeActionAfterRecording(DvbRecording recording);
0091     DvbRecording getCurrentRecording();
0092     void setCurrentRecording(DvbRecording _currentRecording);
0093     void disableLessImportant(DvbSharedRecording &recording1, DvbSharedRecording &recording2);
0094     bool areInConflict(DvbSharedRecording recording1, DvbSharedRecording recording2);
0095     bool isInConflictWithAll(DvbSharedRecording rec, QList<DvbSharedRecording> recList);
0096     int getNumberOfLeastImportants(QList<DvbSharedRecording> recList);
0097     DvbSharedRecording getLeastImportant(QList<DvbSharedRecording> recList);
0098     void disableLeastImportants(QList<DvbSharedRecording> recList);
0099     void disableConflicts();
0100     int getSecondsUntilNextRecording() const;
0101     bool isScanWhenIdle() const;
0102     bool shouldWeScanChannels() const;
0103     void scanChannels();
0104 
0105 signals:
0106     void recordingAdded(const DvbSharedRecording &recording);
0107     // updating doesn't change the recording pointer (modifies existing content)
0108     void recordingAboutToBeUpdated(const DvbSharedRecording &recording);
0109     void recordingUpdated(const DvbSharedRecording &recording);
0110     void recordingRemoved(const DvbSharedRecording &recording);
0111 
0112 private:
0113     void timerEvent(QTimerEvent *event) override;
0114 
0115     void bindToSqlQuery(SqlKey sqlKey, QSqlQuery &query, int index) const override;
0116     bool insertFromSqlQuery(SqlKey sqlKey, const QSqlQuery &query, int index) override;
0117     bool updateStatus(DvbRecording &recording);
0118     bool existsSimilarRecording(DvbEpgEntry recording);
0119 
0120     DvbManager *manager;
0121     QMap<SqlKey, DvbSharedRecording> recordings;
0122     QList<DvbSharedRecording> unwantedRecordings;
0123     QMap<SqlKey, QExplicitlySharedDataPointer<DvbRecordingFile> > recordingFiles;
0124     bool hasPendingOperation;
0125     DvbRecording currentRecording;
0126 };
0127 
0128 void delay(int seconds);
0129 
0130 #endif /* DVBRECORDING_H */