Project

General

Profile

libaudqt-progress-bar.patch

Thomas Lange, April 21, 2020 21:25

View differences:

src/libaudqt/infopopup-qt.cc
18 18
 */
19 19

  
20 20
#include <libaudcore/audstrings.h>
21
#include <libaudcore/drct.h>
21 22
#include <libaudcore/hook.h>
22 23
#include <libaudcore/i18n.h>
23 24
#include <libaudcore/playlist.h>
25
#include <libaudcore/runtime.h>
24 26
#include <libaudcore/tuple.h>
25 27

  
26 28
#include "libaudqt-internal.h"
......
31 33
#include <QLabel>
32 34
#include <QPainter>
33 35
#include <QPointer>
36
#include <QProgressBar>
34 37

  
35 38
namespace audqt
36 39
{
......
43 46
private:
44 47
    void add_field(int row, const char * field, const char * value);
45 48
    void add_fields(const Tuple & tuple);
49
    void add_progress_bar();
50
    void update_progress();
46 51
    void art_ready(const char * filename);
47 52
    void finish_loading();
48 53

  
......
56 61

  
57 62
    QHBoxLayout m_hbox;
58 63
    QGridLayout m_grid;
64
    QProgressBar m_progress;
59 65
    bool m_queued = false;
60 66
};
61 67

  
......
75 81
    m_hbox.addLayout(&m_grid);
76 82

  
77 83
    add_fields(tuple);
84
    add_progress_bar();
85

  
86
    update_progress();
78 87
    finish_loading();
79 88
}
80 89

  
......
124 133
    m_grid.addWidget(label, row, 1, Qt::AlignLeft | Qt::AlignTop);
125 134
}
126 135

  
136
void InfoPopup::add_progress_bar()
137
{
138
    m_grid.addWidget(&m_progress, m_grid.rowCount(), 0, 1, m_grid.columnCount(),
139
                     Qt::AlignLeft | Qt::AlignTop);
140

  
141
    auto timer = new Timer<InfoPopup>(TimerRate::Hz4, this,
142
                                      &InfoPopup::update_progress);
143
    connect(this, &QObject::destroyed, [timer]() { delete timer; });
144
    timer->start();
145
}
146

  
147
void InfoPopup::update_progress()
148
{
149
    String filename;
150
    int length = 0, time = 0;
151

  
152
    if (aud_drct_get_playing())
153
    {
154
        filename = aud_drct_get_filename();
155
        length = aud_drct_get_length();
156
        time = aud_drct_get_time();
157
    }
158

  
159
    if (aud_get_bool("filepopup_showprogressbar") && filename &&
160
        m_filename && !strcmp(filename, m_filename) && length > 0)
161
    {
162
        m_progress.setRange(0, length);
163
        m_progress.setValue(time);
164
        m_progress.setFormat(QString(str_format_time(time)));
165
        m_progress.show();
166
    }
167
    else
168
        m_progress.hide();
169
}
170

  
127 171
void InfoPopup::art_ready(const char * filename)
128 172
{
129 173
    if (m_queued && strcmp(filename, m_filename) == 0)