-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplaylistWidget.cpp
87 lines (73 loc) · 2.45 KB
/
playlistWidget.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
#include "playlistWidget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDir>
#include <QDebug>
PlaylistWidget::PlaylistWidget(DataBase* db,QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f)
{
database = db;
QVBoxLayout* layoutMaster = new QVBoxLayout(this);
QHBoxLayout* layoutButton = new QHBoxLayout();
playlistTable = new QListWidget(this);
buttonLaden = new QPushButton("Laden", this);
buttonLoeschen = new QPushButton("Loeschen", this);
layoutButton->addWidget(buttonLaden);
layoutButton->addWidget(buttonLoeschen);
layoutMaster->addWidget(playlistTable);
layoutMaster->addLayout(layoutButton);
/* QDir dir(QDir::homePath() + "/.config/qmdb/Playlists");
QFileInfoList infoList = dir.entryInfoList();
QFileInfo fileInfo;
QListWidgetItem* item;
foreach(fileInfo, infoList)
{
if(fileInfo.isFile())
{
item = new QListWidgetItem(fileInfo.fileName(), playlistTable);
item->setFlags(item->flags() | Qt::ItemIsEditable);
}
}*/
connect(playlistTable, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
connect(playlistTable, SIGNAL(currentTextChanged(QString)), this, SLOT(currentTextChanged(QString)));
connect(buttonLaden, SIGNAL(clicked()), this, SLOT(ladenClicked()));
connect(buttonLoeschen, SIGNAL(clicked()), this, SLOT(loeschenClicked()));
}
void PlaylistWidget::currentTextChanged(QString ct)
{
currentText = ct;
qDebug("-- start currentTextChanged --");
qDebug() << "current Text " << currentText;
}
void PlaylistWidget::insertItem(QString text)
{
currentText = QString("");
QListWidgetItem* item = new QListWidgetItem(text, playlistTable);
item->setFlags(item->flags() | Qt::ItemIsEditable);
}
void PlaylistWidget::itemChanged(QListWidgetItem * item)
{
if(currentText == QString(""))
return;
QString newText = item->text();
database->renamePlaylist(currentText, newText);
playlistTable->clear();
QStringList playlisten = database->getPlaylist();
foreach(QString playlist, playlisten)
{
insertItem(playlist);
}
}
void PlaylistWidget::ladenClicked()
{
ladePlaylist(playlistTable->currentItem()->text());
}
void PlaylistWidget::loeschenClicked()
{
database->deletePlaylist(playlistTable->currentItem()->text());
playlistTable->clear();
QStringList playlisten = database->getPlaylist();
foreach(QString playlist, playlisten)
{
insertItem(playlist);
}
}