Parent: [81cc60] (diff)

Child: [c57b0d] (diff)

Download this file

GUI_Playlist.cpp    323 lines (256 with data), 9.2 kB

  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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/* Copyright (C) 2011 Lucio Carreras
*
* This file is part of sayonara player
*
* 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 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QKeyEvent>
#include <QFileDialog>
#include <QScrollBar>
#include <QAbstractListModel>
#include <QStyleFactory>
#include <QMessageBox>
#include <QTextEdit>
#include <QAction>
#include <QMenu>
#include <QUrl>
#include <QFileInfo>
#include "HelperStructs/Helper.h"
#include "HelperStructs/PlaylistMode.h"
#include "HelperStructs/CSettingsStorage.h"
#include "HelperStructs/Style.h"
#include "HelperStructs/globals.h"
#include "GUI/playlist/GUI_Playlist.h"
#include "GUI/playlist/model/PlaylistItemModel.h"
class GUI_InfoDialog;
GUI_Playlist::GUI_Playlist(QWidget *parent, GUI_InfoDialog* dialog) :
QWidget(parent)
{
_parent = parent;
ui = new Ui::Playlist_Window();
ui->setupUi(this);
initGUI();
QAction* clear_action = new QAction(this);
clear_action->setShortcut(QKeySequence("Ctrl+."));
clear_action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(clear_action, SIGNAL(triggered()),
this->ui->btn_clear, SLOT(click()));
this->addAction(clear_action);
CSettingsStorage* settings = CSettingsStorage::getInstance();
bool small_playlist_items = settings->getShowSmallPlaylist();
ui->listView->show_big_items(!small_playlist_items);
_info_dialog = dialog;
setMode(settings->getPlaylistMode());
ui->btn_numbers->setChecked(settings->getPlaylistNumbers());
setAcceptDrops(true);
connect(ui->btn_clear, SIGNAL(clicked()),
this, SLOT(clear_playlist_slot()));
connect(ui->btn_repAll, SIGNAL(clicked()),
this, SLOT(playlist_mode_changed_slot()));
connect(ui->btn_shuffle, SIGNAL(clicked()),
this, SLOT(playlist_mode_changed_slot()));
connect(ui->btn_append, SIGNAL(clicked()),
this, SLOT(playlist_mode_changed_slot()));
connect(ui->btn_replace, SIGNAL(clicked()),
this, SLOT(playlist_mode_changed_slot()));
connect(ui->btn_playAdded, SIGNAL(clicked()),
this, SLOT(playlist_mode_changed_slot()));
connect(ui->listView,SIGNAL(sig_metadata_dropped(const MetaDataList&, int)),
this, SLOT(metadata_dropped(const MetaDataList&, int)));
connect(ui->listView, SIGNAL(sig_rows_removed(const QList<int>&, bool)),
this, SLOT(rows_removed(const QList<int>&, bool)));
connect(ui->listView, SIGNAL(sig_sort_tno()),
this, SIGNAL(sig_sort_tno()));
connect(ui->listView, SIGNAL(sig_selection_changed(MetaDataList&)),
this, SLOT(selection_changed(MetaDataList&)));
connect(ui->listView, SIGNAL(sig_selection_min_row(int)),
this, SIGNAL(selection_min_row(int)));
connect(ui->listView, SIGNAL(sig_double_clicked(int)),
this, SLOT(double_clicked(int)));
connect(ui->listView, SIGNAL(sig_no_focus()), this, SLOT(no_focus()));
connect(ui->btn_numbers, SIGNAL(toggled(bool)),
this, SLOT(btn_numbers_changed(bool)));
}
GUI_Playlist::~GUI_Playlist()
{
delete ui;
}
// This is for restoring from settings
void GUI_Playlist::setMode(Playlist_Mode mode)
{
_playlist_mode = mode;
ui->btn_repAll->setChecked(_playlist_mode.repAll);
ui->btn_shuffle->setChecked(_playlist_mode.shuffle);
ui->btn_append->setChecked(_playlist_mode.append);
ui->btn_replace->setChecked(_playlist_mode.replace);
if (_playlist_mode.replace) {
ui->btn_append->setEnabled(false);
} else {
ui->btn_append->setEnabled(true);
}
ui->btn_playAdded->setChecked(_playlist_mode.playAdded);
}
// This is for setting the modes from an openhome player. Only the
// repeat and shuffle bits
void GUI_Playlist::setPlayerMode(Playlist_Mode mode)
{
_playlist_mode.repAll = mode.repAll;
_playlist_mode.shuffle = mode.shuffle;
ui->btn_repAll->setChecked(_playlist_mode.repAll);
ui->btn_shuffle->setChecked(_playlist_mode.shuffle);
}
void GUI_Playlist::changeEvent(QEvent* e)
{
e->accept();
}
void GUI_Playlist::resizeEvent(QResizeEvent* e)
{
e->accept();
this->ui->listView->update();
this->ui->listView->reset();
}
void GUI_Playlist::focusInEvent(QFocusEvent *)
{
this->ui->listView->setFocus();
}
void GUI_Playlist::no_focus()
{
this->parentWidget()->setFocus();
emit sig_no_focus();
}
void GUI_Playlist::psl_next_group_html(QString html)
{
if (html.isEmpty()) {
this->ui->btn_clear->setToolTip(tr("Clear Playlist"));
} else {
this->ui->btn_clear->setToolTip(html);
}
}
// initialize gui
// maybe the button state (pressed/unpressed) should be loaded from db here
void GUI_Playlist::initGUI()
{
ui->btn_repAll->setIcon(QIcon(Helper::getIconPath("repAll.png")));
ui->btn_shuffle->setIcon(QIcon(Helper::getIconPath("shuffle.png")));
ui->btn_append->setIcon(QIcon(Helper::getIconPath("append.png")));
ui->btn_replace->setIcon(QIcon(Helper::getIconPath("broom.png")));
ui->btn_playAdded->setIcon(QIcon(Helper::getIconPath("dynamic.png")));
ui->btn_clear->setIcon(QIcon(Helper::getIconPath("broom.png")));
ui->btn_numbers->setIcon(QIcon(Helper::getIconPath("numbers.png")));
}
// Slot: comes from listview
void GUI_Playlist::metadata_dropped(const MetaDataList& v_md, int row)
{
emit dropped_tracks(v_md, row);
}
// SLOT: fill all tracks in v_metadata into playlist
void GUI_Playlist::fillPlaylist(MetaDataList& v_metadata, int cur_play_idx, int)
{
ui->listView->setStyleSheet(styleSheet());
ui->listView->fill(v_metadata, cur_play_idx);
_total_msecs = 0;
int actions = ENTRY_REMOVE | ENTRY_SORT_TNO;
ui->listView->set_context_menu_actions(actions);
ui->listView->set_drag_enabled(true);
foreach(MetaData md, v_metadata) {
_total_msecs += md.length_ms;
}
set_total_time_label();
}
// private SLOT: clear button pressed
void GUI_Playlist::clear_playlist_slot()
{
_total_msecs = 0;
ui->lab_totalTime->setText(tr("Playlist empty"));
ui->listView->clear();
emit clear_playlist();
}
// private SLOT: playlist item pressed (init drag & drop)
void GUI_Playlist::selection_changed(MetaDataList&)
{
// _info_dialog->setMetaData(v_md);
// this->_info_dialog->set_tag_edit_visible(true);
}
void GUI_Playlist::double_clicked(int row)
{
emit row_activated(row);
}
void GUI_Playlist::track_changed(int row)
{
ui->listView->set_current_track(row);
}
// This is connected to the UI buttons
void GUI_Playlist::playlist_mode_changed_slot()
{
this->parentWidget()->setFocus();
_playlist_mode.repAll = ui->btn_repAll->isChecked();
_playlist_mode.shuffle = ui->btn_shuffle->isChecked();
_playlist_mode.append = ui->btn_append->isChecked();
_playlist_mode.replace = ui->btn_replace->isChecked();
_playlist_mode.playAdded = ui->btn_playAdded->isChecked();
if (_playlist_mode.replace) {
ui->btn_append->setEnabled(false);
} else {
ui->btn_append->setEnabled(true);
}
emit playlist_mode_changed(_playlist_mode);
}
void GUI_Playlist::dragLeaveEvent(QDragLeaveEvent* event)
{
event->accept();
}
void GUI_Playlist::dragEnterEvent(QDragEnterEvent* event)
{
event->accept();
}
void GUI_Playlist::dragMoveEvent(QDragMoveEvent* event)
{
if (event->pos().y() < this->ui->listView->y()) {
this->ui->listView->scrollUp();
} else if (event->pos().y() >
this->ui->listView->y() + this->ui->listView->height()) {
this->ui->listView->scrollDown();
}
}
void GUI_Playlist::dropEvent(QDropEvent* event)
{
this->ui->listView->dropEventFromOutside(event);
}
void GUI_Playlist::set_total_time_label()
{
QString text = "";
ui->lab_totalTime->setContentsMargins(0, 2, 0, 2);
int n_rows = ui->listView->get_num_rows();
QString playlist_string = text + QString::number(n_rows);
if (n_rows == 1) {
playlist_string += tr(" Track - ");
} else {
playlist_string += tr(" Tracks - ");
}
playlist_string += Helper::cvtMsecs2TitleLengthString(_total_msecs, false);
ui->lab_totalTime->setText(playlist_string);
}
void GUI_Playlist::psl_show_small_playlist_items(bool small_playlist_items)
{
ui->listView->show_big_items(!small_playlist_items);
}
void GUI_Playlist::btn_numbers_changed(bool b)
{
this->parentWidget()->setFocus();
CSettingsStorage::getInstance()->setPlaylistNumbers(b);
ui->listView->reset();
}
void GUI_Playlist::rows_removed(const QList<int>& lst, bool select_next_row)
{
emit sig_rows_removed(lst, select_next_row);
}