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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <richard.bown@ferventsoftware.com>
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
Bown to claim authorship of this work have been asserted.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
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. See the file
COPYING included with this distribution for more information.
*/
#include "PlayList.h"
#include "PlayListView.h"
#include "PlayListViewItem.h"
#include "document/ConfigGroups.h"
#include <tqlayout.h>
#include <tdelocale.h>
#include <tdeconfig.h>
#include <tdefiledialog.h>
#include <tdeglobal.h>
#include <kurl.h>
#include <tqframe.h>
#include <tqpushbutton.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqstrlist.h>
#include <tqvbox.h>
#include <tqwidget.h>
#include <tqdragobject.h>
namespace Rosegarden
{
PlayList::PlayList(TQWidget *parent, const char *name)
: TQVBox(parent, name),
m_listView(new PlayListView(this)),
m_buttonBar(new TQFrame(this)),
m_barLayout(new TQHBoxLayout(m_buttonBar)),
m_playButton(0),
m_moveUpButton(0),
m_moveDownButton(0),
m_deleteButton(0),
m_clearButton(0)
{
m_openButton = new TQPushButton(m_buttonBar);
m_playButton = new TQPushButton(m_buttonBar);
m_moveUpButton = new TQPushButton(m_buttonBar);
m_moveDownButton = new TQPushButton(m_buttonBar);
m_deleteButton = new TQPushButton(m_buttonBar);
m_clearButton = new TQPushButton(m_buttonBar);
m_barLayout->addWidget(m_openButton);
m_barLayout->addWidget(m_playButton);
m_barLayout->addWidget(m_moveUpButton);
m_barLayout->addWidget(m_moveDownButton);
m_barLayout->addWidget(m_deleteButton);
m_barLayout->addWidget(m_clearButton);
m_barLayout->addStretch();
m_openButton ->setText(i18n("Add..."));
m_playButton ->setText(i18n("Play"));
m_moveUpButton ->setText(i18n("Move Up"));
m_moveDownButton->setText(i18n("Move Down"));
m_deleteButton ->setText(i18n("Delete"));
m_clearButton ->setText(i18n("Clear"));
connect(m_openButton, TQT_SIGNAL(clicked()),
TQT_SLOT(slotOpenFiles()));
connect(m_playButton, TQT_SIGNAL(clicked()),
TQT_SLOT(slotPlay()));
connect(m_deleteButton, TQT_SIGNAL(clicked()),
TQT_SLOT(slotDeleteCurrent()));
connect(m_clearButton, TQT_SIGNAL(clicked()),
TQT_SLOT(slotClear()));
connect(m_moveUpButton, TQT_SIGNAL(clicked()),
TQT_SLOT(slotMoveUp()));
connect(m_moveDownButton, TQT_SIGNAL(clicked()),
TQT_SLOT(slotMoveDown()));
connect(m_listView, TQT_SIGNAL(currentChanged(TQListViewItem*)),
TQT_SLOT(slotCurrentItemChanged(TQListViewItem*)));
connect(m_listView, TQT_SIGNAL(dropped(TQDropEvent*, TQListViewItem*)),
TQT_SLOT(slotDropped(TQDropEvent*, TQListViewItem*)));
restore();
enableButtons(0);
}
PlayList::~PlayList()
{
save();
}
void PlayList::slotOpenFiles()
{
KURL::List kurlList =
KFileDialog::getOpenURLs(":ROSEGARDEN",
"audio/x-rosegarden audio/x-midi audio/x-rosegarden21",
this,
i18n("Select one or more Rosegarden files"));
KURL::List::iterator it;
for (it = kurlList.begin(); it != kurlList.end(); ++it) {
new PlayListViewItem(m_listView, *it);
}
enableButtons(m_listView->currentItem());
}
void
PlayList::slotDropped(TQDropEvent *event, TQListViewItem* after)
{
TQStrList uri;
// see if we can decode a URI.. if not, just ignore it
if (TQUriDrag::decode(event, uri)) {
// okay, we have a URI.. process it
// weed out non-rg files
//
for (TQString url = uri.first(); !url.isNull(); url = uri.next()) {
if (url.right(3).lower() == ".rg")
new PlayListViewItem(m_listView, after, KURL(url));
}
}
enableButtons(m_listView->currentItem());
}
void PlayList::slotPlay()
{
PlayListViewItem *currentItem = dynamic_cast<PlayListViewItem*>(m_listView->currentItem());
if (currentItem)
emit play(currentItem->getURL().url());
}
void PlayList::slotMoveUp()
{
TQListViewItem *currentItem = m_listView->currentItem();
TQListViewItem *previousItem = m_listView->previousSibling(currentItem);
if (previousItem)
previousItem->moveItem(currentItem);
enableButtons(currentItem);
}
void PlayList::slotMoveDown()
{
TQListViewItem *currentItem = m_listView->currentItem();
TQListViewItem *nextItem = currentItem->nextSibling();
if (nextItem)
currentItem->moveItem(nextItem);
enableButtons(currentItem);
}
void PlayList::slotClear()
{
m_listView->clear();
enableButtons(0);
}
void PlayList::slotDeleteCurrent()
{
TQListViewItem* currentItem = m_listView->currentItem();
if (currentItem)
delete currentItem;
}
void PlayList::slotCurrentItemChanged(TQListViewItem* currentItem)
{
enableButtons(currentItem);
}
void PlayList::enableButtons(TQListViewItem* currentItem)
{
bool enable = (currentItem != 0);
m_playButton->setEnabled(enable);
m_deleteButton->setEnabled(enable);
if (currentItem) {
m_moveUpButton->setEnabled(currentItem != m_listView->firstChild());
m_moveDownButton->setEnabled(currentItem != m_listView->lastItem());
} else {
m_moveUpButton->setEnabled(false);
m_moveDownButton->setEnabled(false);
}
m_clearButton->setEnabled(m_listView->childCount() > 0);
}
void PlayList::save()
{
TQStringList urlList;
PlayListViewItem* item = dynamic_cast<PlayListViewItem*>(getListView()->firstChild());
while (item) {
urlList << item->getURL().url();
item = dynamic_cast<PlayListViewItem*>(item->nextSibling());
}
TDEConfig *kc = TDEGlobal::config();
TDEConfigGroupSaver cs(kc, PlayListConfigGroup);
kc->writeEntry("Playlist Files", urlList);
getListView()->saveLayout(kc, PlayListConfigGroup);
}
void PlayList::restore()
{
TDEConfig *kc = TDEGlobal::config();
getListView()->restoreLayout(kc, PlayListConfigGroup);
TDEConfigGroupSaver cs(kc, PlayListConfigGroup);
TQStringList urlList = kc->readListEntry("Playlist Files");
for (TQStringList::Iterator it = urlList.begin();
it != urlList.end(); ++it) {
new PlayListViewItem(getListView(), KURL(*it));
}
}
}
#include "PlayList.moc"
|