-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsourcepage.cpp
152 lines (135 loc) · 4.45 KB
/
sourcepage.cpp
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "sourcepage.h"
#include "ui_sourcepage.h"
#include "alarmwizard.h"
#include "../../controlpanel/musiccontrol.h"
#include <QtCore/QDebug>
SourcePage::SourcePage(QWidget *parent, QStringList source) :
QWizardPage(parent),
_ui(new Ui::SourcePage),
_source(source)
{
_ui->setupUi(this);
_plugin = NULL;
_source.append("");
connect(_ui->sourceList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectSource(QListWidgetItem*)));
}
SourcePage::~SourcePage()
{
delete _ui;
}
void SourcePage::initializePage()
{
if ( _source.size() == 1 )
{
_ui->sourceList->clear();
_ui->sourceList->addItems(Msg::MusicControl::getInstance().getAudioPlugins());
//load source from wizard, if available
if ( !((AlarmWizard*) wizard())->getSource().isEmpty() )
{
QString src = ((AlarmWizard*) wizard())->getSource();
int index = src.indexOf("/");
src.remove(index, src.length());
QList<QListWidgetItem*> items = _ui->sourceList->findItems(src, Qt::MatchExactly);
if ( items.size() != 1 )
return;
_ui->sourceList->clearSelection();
//items.first()->setSelected(true);
_ui->sourceList->setCurrentItem(items.first());
selectSource(items.first());
}
} else {
Msg::AudioPlugin* plugin = getPlugin();
_ui->sourceList->addItems(plugin->getSourceList());
//load source from wizard, if available
if ( !((AlarmWizard*) wizard())->getSource().isEmpty() )
{
QString src = ((AlarmWizard*) wizard())->getSource();
int index = src.indexOf("/");
src.remove(0, index + 1);
QList<QListWidgetItem*> items = _ui->sourceList->findItems(src, Qt::MatchExactly);
if ( items.size() != 1 )
return;
_ui->sourceList->clearSelection();
items.first()->setSelected(true);
selectSource(items.first());
}
}
if ( _ui->sourceList->selectedItems().size() == 0 )
{
_ui->sourceList->setCurrentItem(_ui->sourceList->itemAt(1,1));
selectSource(_ui->sourceList->selectedItems().first());
}
}
void SourcePage::selectSource(QListWidgetItem *item)
{
if ( item )
{
qDebug() << item->text();
QString src;
//_source << item->text();
_source.last() = item->text();
/*if ( _source.isEmpty() )
src = QString("%1/%2").arg(_source, item->text());
else
src = item->text();
//((AlarmWizard*)this->wizard())->setNewSource(src);
qDebug() << src;
_source = src;*/
getPlugin();
emit completeChanged();
}
}
bool SourcePage::isComplete() const
{
return _ui->sourceList->selectedItems().size() > 0;
}
int SourcePage::nextId() const
{
qDebug() << "pre nextId";
if ( _source.size() == 0 )
return ((AlarmWizard*)this->wizard())->getNextPage();
if ( _plugin != NULL && _plugin->isFinal(getPath()) )
{
((AlarmWizard*) wizard())->setSource(_source.join("/"));
return AlarmWizard::SNOOZEPAGE;
}
else
{
SourcePage* next_page = new SourcePage(NULL, _source);
((AlarmWizard*) this->wizard())->addPage(next_page);
return ((AlarmWizard*)this->wizard())->getNextPage();
}
}
Msg::AudioPlugin* SourcePage::getPlugin()
{
/*int index = _source.indexOf("/");
qDebug() << "Index:" << index;
QString sourcePlugin = _source;
if ( index > 0 )
sourcePlugin.remove(index, sourcePlugin.length());
qDebug() << "Plugin:" << sourcePlugin;
if ( _plugin == NULL || _plugin->getName().compare(sourcePlugin.toStdString()) != 0 )
_plugin = Msg::MusicControl::getInstance().getAudioPlugin(sourcePlugin);
return _plugin;*/
if ( _plugin == NULL || _plugin->getName().compare(_source.first().toStdString()) != 0 )
_plugin = Msg::MusicControl::getInstance().getAudioPlugin(_source.first());
return _plugin;
}
QString SourcePage::getPath() const
{
/*int index = _source.indexOf("/");
qDebug() << "Index:" << index;
if ( index < 0 )
return "";
QString pluginSource = _source;
pluginSource.remove(0, index + 1);
qDebug() << "Path:" << pluginSource;
return pluginSource;*/
if ( _source.size() > 1 )
{
QStringList sources = _source;
sources.removeFirst();
return sources.join("/");
}
return "";
}