1 /****************************************************************************************
2  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
3  *                                                                                      *
4  * This program is free software; you can redistribute it and/or modify it under        *
5  * the terms of the GNU General Public License as published by the Free Software        *
6  * Foundation; either version 2 of the License, or (at your option) any later           *
7  * version.                                                                             *
8  *                                                                                      *
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12  *                                                                                      *
13  * You should have received a copy of the GNU General Public License along with         *
14  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15  ****************************************************************************************/
16 
17 #ifndef COMPOUNDPROGRESSBAR_H
18 #define COMPOUNDPROGRESSBAR_H
19 
20 #include "statusbar/ProgressBar.h"
21 #include "statusbar/PopupWidget.h"
22 
23 #include <QList>
24 #include <QMap>
25 #include <QMouseEvent>
26 #include <QMutex>
27 
28 /**
29  * A progress bar that wraps a number of simple progress bars and displays their
30  * overall progress. Also features an expanded mode that allows the user to view
31  * and canceled individual operations
32  */
33 class AMAROK_EXPORT CompoundProgressBar : public ProgressBar
34 {
35     Q_OBJECT
36 public:
37     explicit CompoundProgressBar( QWidget *parent );
38 
39     ~CompoundProgressBar() override;
40 
41     void addProgressBar( ProgressBar *progressBar, QObject *owner );
42 
43     void incrementProgress( const QObject *owner );
44     void setProgressTotalSteps( const QObject *owner, int value );
45     void setProgressStatus( const QObject *owner, const QString &text );
46     void setProgress( const QObject *owner, int steps );
47 
48     /* reimplemented from QWidget to open/close the details widget */
49     void mousePressEvent( QMouseEvent *event ) override;
50 
51 public Q_SLOTS:
52     void endProgressOperation( QObject *owner );
53     void slotIncrementProgress();
54 
55 Q_SIGNALS:
56     void allDone();
57 
58 protected Q_SLOTS:
59     void cancelAll();
60     void toggleDetails();
61 
62     void childPercentageChanged( );
63     void childBarCancelled( ProgressBar *progressBar );
64     void childBarComplete( ProgressBar *progressBar );
65 
66     void slotObjectDestroyed( QObject *object );
67 
68 private:
69     void showDetails();
70     void hideDetails();
71 
72     void childBarFinished( ProgressBar *bar );
73 
74     int calcCompoundPercentage();
75 
76     QMap< const QObject *, ProgressBar *> m_progressMap;
77     PopupWidget *m_progressDetailsWidget;
78     QMutex m_mutex; // protecting m_progressMap consistency
79 };
80 
81 #endif
82