summaryrefslogtreecommitdiffstats
path: root/src/library/scanner/libraryscannerdlg.cpp
blob: 08568b2ad22bbe85e4d7c8a2c7f4b9575450e1c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***************************************************************************
                          LibraryScannerDlg.cpp  -  shows library scanning
                                                       progress
                             -------------------
    begin                : 11/27/2007
    copyright            : (C) 2007 Albert Santoni and Adam Davison
    email                : gamegod \a\t users.sf.net
***************************************************************************/

/***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/

#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QtDebug>

#include "library/scanner/libraryscannerdlg.h"

LibraryScannerDlg::LibraryScannerDlg(QWidget* parent, Qt::WindowFlags f)
        : QWidget(parent, f),
          m_bCancelled(false) {
    setWindowIcon(QIcon(":/images/mixxx_icon.svg"));

    QVBoxLayout* pLayout = new QVBoxLayout(this);

    setWindowTitle(tr("Library Scanner"));
    QLabel* pLabel = new QLabel(tr("It's taking Mixxx a minute to scan your music library, please wait..."),this);
    pLayout->addWidget(pLabel);

    QPushButton* pCancel = new QPushButton(tr("Cancel"), this);
    connect(pCancel,
            &QPushButton::clicked,
            this,
            &LibraryScannerDlg::slotCancel);
    pLayout->addWidget(pCancel);

    QLabel* pCurrent = new QLabel(this);
    pCurrent->setAlignment(Qt::AlignTop);
    pCurrent->setMaximumWidth(600);
    pCurrent->setFixedHeight(this->fontMetrics().height());
    pCurrent->setWordWrap(true);
    connect(this, &LibraryScannerDlg::progress, pCurrent, &QLabel::setText);
    pLayout->addWidget(pCurrent);
    setLayout(pLayout);
}

LibraryScannerDlg::~LibraryScannerDlg() {
}

void LibraryScannerDlg::slotUpdate(QString path) {
    //qDebug() << "LibraryScannerDlg slotUpdate" << m_timer.elapsed().formatMillisWithUnit() << path;
    if (!m_bCancelled && m_timer.elapsed() > mixxx::Duration::fromSeconds(2)) {
       setVisible(true);
    }

    if (isVisible()) {
        QString status = tr("Scanning: ") + path;
        emit(progress(status));
    }
}

void LibraryScannerDlg::slotUpdateCover(QString path) {
    //qDebug() << "LibraryScannerDlg slotUpdate" << m_timer.elapsed() << path;
    if (!m_bCancelled && m_timer.elapsed() > mixxx::Duration::fromSeconds(2)) {
       setVisible(true);
    }

    if (isVisible()) {
        QString status = QString("%1: %2")
                .arg(tr("Scanning cover art (safe to cancel)"))
                .arg(path);
        emit(progress(status));
    }
}

void LibraryScannerDlg::slotCancel() {
    qDebug() << "Cancelling library scan...";
    m_bCancelled = true;
    emit(scanCancelled());
    hide();
}

void LibraryScannerDlg::slotScanStarted() {
    m_bCancelled = false;
    m_timer.start();
}

void LibraryScannerDlg::slotScanFinished() {
    // Raise this flag to prevent any latent slotUpdates() from showing the
    // dialog again.
    m_bCancelled = true;

    hide();
}