File indexing completed on 2024-02-18 04:58:19

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2007 by Lukas Appelhans <l.appelhans@gmx.de>
0004    Copyright (C) 2008 by Javier Goday <jgoday@gmail.com>
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 */
0011 #ifndef TRANSFERHISTORYSTORE_H
0012 #define TRANSFERHISTORYSTORE_H
0013 
0014 #include "kget_export.h"
0015 
0016 #include <QDateTime>
0017 #include <QList>
0018 #include <QMetaType>
0019 #include <QObject>
0020 
0021 class Transfer;
0022 
0023 class KGET_EXPORT TransferHistoryItem : public QObject
0024 {
0025 public:
0026     TransferHistoryItem();
0027     TransferHistoryItem(const Transfer &transfer);
0028     TransferHistoryItem(const TransferHistoryItem &);
0029 
0030     bool isExpired(qint64 expiryAge);
0031 
0032     void setDest(const QString &dest);
0033     void setSource(const QString &source);
0034     void setState(int state);
0035     void setSize(int size);
0036     void setDateTime(const QDateTime &time);
0037 
0038     QString dest() const;
0039     QString source() const;
0040     int state() const;
0041     int size() const;
0042     QDateTime dateTime() const;
0043 
0044     TransferHistoryItem &operator=(const TransferHistoryItem &);
0045     bool operator==(const TransferHistoryItem &) const;
0046 
0047 private:
0048     QString m_dest;
0049     QString m_source;
0050     int m_state;
0051     int m_size;
0052     QDateTime m_dateTime;
0053 };
0054 
0055 class KGET_EXPORT TransferHistoryStore : public QObject
0056 {
0057     Q_OBJECT
0058 public:
0059     enum Backend {
0060         Xml = 0,
0061         SQLite = 1,
0062     };
0063 
0064     enum Time {
0065         Day = 0,
0066         Hour = 1,
0067         Minute = 2,
0068         Second = 3,
0069     };
0070 
0071     TransferHistoryStore();
0072     ~TransferHistoryStore() override;
0073 
0074     QList<TransferHistoryItem> items() const;
0075 
0076     qint64 expiryAge() const;
0077 
0078     static TransferHistoryStore *getStore();
0079     static qint64 getSettingsExpiryAge();
0080 
0081     void settingsChanged();
0082 
0083 public Q_SLOTS:
0084     virtual void load()
0085     {
0086     }
0087     virtual void clear()
0088     {
0089     }
0090     virtual void saveItem(const TransferHistoryItem &item)
0091     {
0092         Q_UNUSED(item)
0093     }
0094     virtual void saveItems(const QList<TransferHistoryItem> &items)
0095     {
0096         foreach (const TransferHistoryItem &item, items) {
0097             saveItem(item);
0098         }
0099     }
0100     virtual void deleteItem(const TransferHistoryItem &item)
0101     {
0102         Q_UNUSED(item)
0103     }
0104 
0105 Q_SIGNALS:
0106     void elementLoaded(int number, int total, const TransferHistoryItem &item);
0107     void loadFinished();
0108     void saveFinished();
0109     void deleteFinished();
0110 
0111 protected:
0112     void deleteExpiredItems();
0113     void updateExpiryAge(qint64 expiry);
0114 
0115     QList<TransferHistoryItem> m_items;
0116     qint64 m_expiryAge;
0117 };
0118 
0119 Q_DECLARE_METATYPE(TransferHistoryItem)
0120 
0121 #endif