File indexing completed on 2024-04-21 04:57:05

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
0004    Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
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 
0012 #ifndef TRANSFERGROUPHANDLER_H
0013 #define TRANSFERGROUPHANDLER_H
0014 
0015 #include <QVariant>
0016 
0017 #include "handler.h"
0018 #include "kget.h"
0019 #include "kget_export.h"
0020 #include "transfergroup.h"
0021 
0022 class QAction;
0023 
0024 class QObjectInterface;
0025 class TransferHandler;
0026 class Scheduler;
0027 
0028 class KGET_EXPORT TransferGroupHandler : public Handler
0029 {
0030     Q_OBJECT
0031     friend class GenericObserver;
0032     friend class TransferGroup;
0033     friend class TransferTreeModel;
0034     friend class KGet;
0035 
0036 public:
0037     typedef TransferGroup::ChangesFlags ChangesFlags;
0038 
0039     TransferGroupHandler(Scheduler *scheduler, TransferGroup *parent);
0040 
0041     ~TransferGroupHandler() override;
0042 
0043     JobQueue::Status status() const
0044     {
0045         return m_group->status();
0046     }
0047 
0048     /**
0049      * Moves a list of transfers belonging to this group to a new position,
0050      * after the transfer named "after". All the transfers must belong to
0051      * this group
0052      *
0053      * @param transfers The transfers to be be moved
0054      * @param after The transfer after which the given transfers should be moved
0055      */
0056     void move(QList<TransferHandler *> transfers, TransferHandler *after);
0057 
0058     /**
0059      * Sets the maximum number of jobs belonging to this queue that
0060      * should executed simultaneously by the scheduler
0061      *
0062      * @param n The maximum number of jobs
0063      */
0064     void setMaxSimultaneousJobs(int n);
0065 
0066     /**
0067      * @returns the Job in the queue at the given index i
0068      */
0069     TransferHandler *operator[](int i);
0070 
0071     /**
0072      * @returns the number of Transfers owned by this object
0073      */
0074     int size()
0075     {
0076         return m_group->size();
0077     }
0078 
0079     /**Set the group name
0080      * @param name group name
0081      */
0082     void setName(const QString &name);
0083 
0084     /**
0085      * @return the group name
0086      */
0087     const QString &name()
0088     {
0089         return m_group->name();
0090     }
0091 
0092     /**
0093      * @return the sum of the sizes of the transfers belonging to
0094      * this group
0095      */
0096     int totalSize() const
0097     {
0098         return m_group->totalSize();
0099     }
0100 
0101     /**
0102      * @return the sum of the downloaded sizes of the transfers
0103      * belonging to this group
0104      */
0105     int downloadedSize() const
0106     {
0107         return m_group->downloadedSize();
0108     }
0109 
0110     /**
0111      * @return the sum of the uploaded sizes of the transfers
0112      * belonging to this group
0113      */
0114     int uploadedSize() const
0115     {
0116         return m_group->uploadedSize();
0117     }
0118 
0119     /**
0120      * @return the progress percentage
0121      */
0122     int percent() const
0123     {
0124         return m_group->percent();
0125     }
0126 
0127     /**
0128      * @return the sum of the download speeds of the running transfers
0129      * belonging this group
0130      */
0131     int downloadSpeed() const
0132     {
0133         return m_group->downloadSpeed();
0134     }
0135 
0136     /**
0137      * @return the sum of the upload speeds of the running transfers
0138      * belonging this group
0139      */
0140     int uploadSpeed() const
0141     {
0142         return m_group->uploadSpeed();
0143     }
0144 
0145     /**
0146      * @return the changes flags which are currently set on the transfer
0147      */
0148     ChangesFlags changesFlags();
0149 
0150     /**
0151      * Set a default Folder for the group
0152      * @param folder the new default folder
0153      */
0154     void setDefaultFolder(QString folder)
0155     {
0156         m_group->setDefaultFolder(folder);
0157     }
0158 
0159     /**
0160      * @return the groups default folder
0161      */
0162     QString defaultFolder()
0163     {
0164         return m_group->defaultFolder();
0165     }
0166 
0167     /**
0168      * Sets the regular expression of the group
0169      * @param regexp the regular expression
0170      */
0171     void setRegExp(const QRegularExpression &regexp)
0172     {
0173         m_group->setRegExp(regexp);
0174     }
0175 
0176     /**
0177      * @returns the regular expression of the group
0178      */
0179     QRegularExpression regExp()
0180     {
0181         return m_group->regExp();
0182     }
0183 
0184     /**
0185      * Set a Download-Limit for the group
0186      * @param dlLimit the new download-limit
0187      * @param limit the type of the new download-limit
0188      * @note if limit is 0, no download-limit is set
0189      */
0190     void setDownloadLimit(int dlLimit, Transfer::SpeedLimit limit)
0191     {
0192         m_group->setDownloadLimit(dlLimit, limit);
0193     }
0194 
0195     /**
0196      * @return the group's Download-Limit
0197      */
0198     int downloadLimit(Transfer::SpeedLimit limit)
0199     {
0200         return m_group->downloadLimit(limit);
0201     }
0202 
0203     /**
0204      * Set a Upload-Limit for the group
0205      * @param ulLimit the new upload-limit
0206      * @param limit the type of the new upload-limit
0207      * @note this will not be displayed in the GUI
0208      */
0209     void setUploadLimit(int ulLimit, Transfer::SpeedLimit limit)
0210     {
0211         m_group->setUploadLimit(ulLimit, limit);
0212     }
0213 
0214     /**
0215      * @return the group's Upload-Limit
0216      */
0217     int uploadLimit(Transfer::SpeedLimit limit)
0218     {
0219         return m_group->uploadLimit(limit);
0220     }
0221 
0222     /**
0223      * Set the group's icon
0224      * @param name the icon's name
0225      */
0226     void setIconName(const QString &name)
0227     {
0228         m_group->setIconName(name);
0229     }
0230 
0231     /**
0232      * @returns the group's icon's name
0233      */
0234     QString iconName() const
0235     {
0236         return m_group->iconName();
0237     }
0238 
0239     /**
0240      * @returns the group's icon
0241      */
0242     QPixmap pixmap()
0243     {
0244         return m_group->pixmap();
0245     }
0246 
0247     /**
0248      * @returns the data associated to this TransferGroup item. This is
0249      * necessary to make the interview model/view work
0250      */
0251     QVariant data(int column) override;
0252 
0253     /**
0254      * @returns the number of columns associated to the group's data
0255      */
0256     int columnCount() const
0257     {
0258         return 6;
0259     }
0260 
0261     /**
0262      * @returns the index for the given transfer. If the transfer can't
0263      *          be found, it returns -1
0264      */
0265     int indexOf(TransferHandler *transfer);
0266 
0267     /**
0268      * @returns a list containing all the transfers belonging to this group.
0269      */
0270     const QList<TransferHandler *> transfers();
0271 
0272     /**
0273      * @returns a pointer to a QObjectInterface object which is a QObject
0274      * by means of which you can connect signals and slots for this
0275      * transfer group.
0276      */
0277     const QList<QAction *> &actions();
0278 
0279     /**
0280      * Calculates the whole SpeedLimits
0281      */
0282     void calculateSpeedLimits()
0283     {
0284         m_group->calculateSpeedLimits();
0285     }
0286 
0287     /**
0288      * Calculates the DownloadLimits
0289      */
0290     void calculateDownloadLimit()
0291     {
0292         m_group->calculateDownloadLimit();
0293     }
0294 
0295     /**
0296      * Calculates the DownloadLimits
0297      */
0298     void calculateUploadLimit()
0299     {
0300         m_group->calculateUploadLimit();
0301     }
0302 
0303 public Q_SLOTS:
0304     /**
0305      * These are all JobQueue-related functions
0306      */
0307     void start() override;
0308     void stop() override;
0309 
0310 Q_SIGNALS:
0311     void groupChangedEvent(TransferGroupHandler *transfer, TransferGroupHandler::ChangesFlags flags);
0312 
0313 private:
0314     /**
0315      * Sets a change flag in the ChangesFlags variable.
0316      *
0317      * @param change The TransferChange flag to be set
0318      * @param notifyModel notify the model about the change
0319      */
0320     void setGroupChange(ChangesFlags change, bool notifyModel = false);
0321 
0322     /**
0323      * Resets the changes flags
0324      */
0325     void resetChangesFlags();
0326 
0327     /**
0328      * Creates all the QActions
0329      */
0330     void createActions();
0331 
0332     TransferGroup *m_group;
0333 
0334     QList<QAction *> m_actions;
0335 
0336     ChangesFlags m_changesFlags;
0337 };
0338 
0339 #endif