summaryrefslogtreecommitdiffstats
path: root/src/dlgdevelopertools.cpp
blob: 413e1a83491f11abaf962f10b726f6471cfc7392 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "dlgdevelopertools.h"

#include "control/control.h"
#include "util/cmdlineargs.h"
#include "util/statsmanager.h"

DlgDeveloperTools::DlgDeveloperTools(QWidget* pParent,
                                     ConfigObject<ConfigValue>* pConfig)
        : QDialog(pParent) {
    Q_UNUSED(pConfig);
    setupUi(this);

    QList<QSharedPointer<ControlDoublePrivate> > controlsList;
    ControlDoublePrivate::getControls(&controlsList);
    QHash<ConfigKey, ConfigKey> controlAliases =
            ControlDoublePrivate::getControlAliases();

    for (QList<QSharedPointer<ControlDoublePrivate> >::const_iterator it = controlsList.begin();
            it != controlsList.end(); ++it) {
        const QSharedPointer<ControlDoublePrivate>& pControl = *it;
        if (pControl) {
            m_controlModel.addControl(pControl->getKey(), pControl->name(),
                                      pControl->description());

            ConfigKey aliasKey = controlAliases[pControl->getKey()];
            if (!aliasKey.isNull()) {
                m_controlModel.addControl(aliasKey, pControl->name(),
                                          "Alias for " + pControl->getKey().group + pControl->getKey().item);
            }
        }
    }

    m_controlProxyModel.setSourceModel(&m_controlModel);
    m_controlProxyModel.setFilterCaseSensitivity(Qt::CaseInsensitive);
    m_controlProxyModel.setFilterKeyColumn(ControlModel::CONTROL_COLUMN_FILTER);
    controlsTable->setModel(&m_controlProxyModel);
    controlsTable->hideColumn(ControlModel::CONTROL_COLUMN_TITLE);
    controlsTable->hideColumn(ControlModel::CONTROL_COLUMN_DESCRIPTION);
    controlsTable->hideColumn(ControlModel::CONTROL_COLUMN_FILTER);

    StatsManager* pManager = StatsManager::instance();
    if (pManager) {
        connect(pManager, SIGNAL(statUpdated(const Stat&)),
                &m_statModel, SLOT(statUpdated(const Stat&)));
        pManager->emitAllStats();
    }

    m_statProxyModel.setSourceModel(&m_statModel);
    statsTable->setModel(&m_statProxyModel);

    QString logFileName = QDir(CmdlineArgs::Instance().getSettingsPath()).filePath("mixxx.log");
    m_logFile.setFileName(logFileName);
    if (!m_logFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qDebug() << "ERROR: Could not open log file";
    }

    // Connect search box signals to the library
    connect(controlSearch, SIGNAL(search(const QString&)),
            this, SLOT(slotControlSearch(const QString&)));
    connect(controlSearch, SIGNAL(searchCleared()),
            this, SLOT(slotControlSearchClear()));

    // Set up the log search box
    connect(logSearch, SIGNAL(returnPressed()),
            this, SLOT(slotLogSearch()));
    connect(logSearchButton, SIGNAL(clicked()),
            this, SLOT(slotLogSearch()));

    m_logCursor = logTextView->textCursor();

    // Update at 2FPS.
    startTimer(500);

    // Delete this dialog when its closed. We don't want any persistence.
    setAttribute(Qt::WA_DeleteOnClose);
}

DlgDeveloperTools::~DlgDeveloperTools() {
}

void DlgDeveloperTools::timerEvent(QTimerEvent* pEvent) {
    Q_UNUSED(pEvent);
    if (m_logFile.isOpen()) {
        QStringList newLines;

        while (true) {
            QByteArray line = m_logFile.readLine();
            if (line.isEmpty()) {
                break;
            }
            newLines.append(QString::fromLocal8Bit(line));
        }

        if (!newLines.isEmpty()) {
            logTextView->append(newLines.join(""));
        }
    }

    // To save on CPU, only update the models when they are visible.
    if (toolTabWidget->currentWidget() == controlsTab) {
        //m_controlModel.updateDirtyRows();
        controlsTable->update();
    } else if (toolTabWidget->currentWidget() == statsTab) {
        StatsManager* pManager = StatsManager::instance();
        if (pManager) {
            pManager->updateStats();
        }
    }
}

void DlgDeveloperTools::slotControlSearch(const QString& search) {
    m_controlProxyModel.setFilterFixedString(search);
}

void DlgDeveloperTools::slotControlSearchClear() {
    m_controlProxyModel.setFilterFixedString(QString());
}

void DlgDeveloperTools::slotLogSearch() {
    QString textToFind = logSearch->text();
    m_logCursor = logTextView->document()->find(textToFind, m_logCursor);
    logTextView->setTextCursor(m_logCursor);
}