mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-27 18:20:27 +00:00
Qt: add option to rename playlists
This commit is contained in:
parent
bca86728b0
commit
010fad236a
@ -3712,6 +3712,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME,
|
||||
"新しいプレイリストの名前を入力してください:")
|
||||
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST,
|
||||
"プレイリストを削除")
|
||||
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_RENAME_PLAYLIST,
|
||||
"プレイリストの名前を変更")
|
||||
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST,
|
||||
"「%1」というプレイリストを削除しますか?")
|
||||
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_QUESTION,
|
||||
|
@ -7230,6 +7230,10 @@ MSG_HASH(
|
||||
MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST,
|
||||
"Delete Playlist"
|
||||
)
|
||||
MSG_HASH(
|
||||
MENU_ENUM_LABEL_VALUE_QT_RENAME_PLAYLIST,
|
||||
"Rename Playlist"
|
||||
)
|
||||
MSG_HASH(
|
||||
MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST,
|
||||
"Are you sure you want to delete the playlist \"%1\"?"
|
||||
|
@ -1972,6 +1972,7 @@ enum msg_hash_enums
|
||||
MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST,
|
||||
MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME,
|
||||
MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST,
|
||||
MENU_ENUM_LABEL_VALUE_QT_RENAME_PLAYLIST,
|
||||
MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST,
|
||||
MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST_ITEM,
|
||||
MENU_ENUM_LABEL_VALUE_QT_QUESTION,
|
||||
|
@ -492,6 +492,7 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
|
||||
QScopedPointer<QAction> hideAction;
|
||||
QScopedPointer<QAction> newPlaylistAction;
|
||||
QScopedPointer<QAction> deletePlaylistAction;
|
||||
QScopedPointer<QAction> renamePlaylistAction;
|
||||
QScopedPointer<QAction> downloadAllThumbnailsEntireSystemAction;
|
||||
QScopedPointer<QAction> downloadAllThumbnailsThisPlaylistAction;
|
||||
QPointer<QAction> selectedAction;
|
||||
@ -551,6 +552,9 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
|
||||
{
|
||||
deletePlaylistAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST)) + "...", this));
|
||||
menu->addAction(deletePlaylistAction.data());
|
||||
|
||||
renamePlaylistAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RENAME_PLAYLIST)) + "...", this));
|
||||
menu->addAction(renamePlaylistAction.data());
|
||||
}
|
||||
|
||||
if (selectedItem)
|
||||
@ -704,6 +708,20 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (selectedItem && selectedAction == renamePlaylistAction.data())
|
||||
{
|
||||
if (currentPlaylistFile.exists())
|
||||
{
|
||||
QString oldName = selectedItem->text();
|
||||
QString name = QInputDialog::getText(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RENAME_PLAYLIST), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME), QLineEdit::Normal, oldName);
|
||||
|
||||
if (!name.isEmpty())
|
||||
{
|
||||
renamePlaylistItem(selectedItem, name);
|
||||
reloadPlaylists();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (selectedAction == newPlaylistAction.data())
|
||||
{
|
||||
QString name = QInputDialog::getText(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME));
|
||||
@ -812,13 +830,17 @@ void MainWindow::reloadPlaylists()
|
||||
currentItem = m_listWidget->currentItem();
|
||||
|
||||
if (currentItem)
|
||||
{
|
||||
currentPlaylistPath = currentItem->data(Qt::UserRole).toString();
|
||||
}
|
||||
|
||||
getPlaylistFiles();
|
||||
|
||||
/* block this signal because setData() would trigger an infinite loop */
|
||||
disconnect(m_listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onCurrentListItemDataChanged(QListWidgetItem*)));
|
||||
|
||||
m_listWidget->clear();
|
||||
m_listWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
m_listWidget->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed);
|
||||
|
||||
allPlaylistsItem = new QListWidgetItem(m_folderIcon, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ALL_PLAYLISTS));
|
||||
allPlaylistsItem->setData(Qt::UserRole, ALL_PLAYLISTS_TOKEN);
|
||||
@ -880,6 +902,7 @@ void MainWindow::reloadPlaylists()
|
||||
icon = m_folderIcon;
|
||||
|
||||
item = new QListWidgetItem(icon, fileDisplayName);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
item->setData(Qt::UserRole, playlistDir.absoluteFilePath(file));
|
||||
|
||||
m_listWidget->addItem(item);
|
||||
@ -944,6 +967,8 @@ void MainWindow::reloadPlaylists()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connect(m_listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onCurrentListItemDataChanged(QListWidgetItem*)));
|
||||
}
|
||||
|
||||
QString MainWindow::getCurrentPlaylistPath()
|
||||
|
@ -20,9 +20,7 @@
|
||||
#include <QTimer>
|
||||
#include <QLabel>
|
||||
#include <QFileSystemModel>
|
||||
#include <QListWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include <QTableWidget>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QHash>
|
||||
#include <QPushButton>
|
||||
@ -214,6 +212,26 @@ void TableWidget::keyPressEvent(QKeyEvent *event)
|
||||
QTableWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
ListWidget::ListWidget(QWidget *parent) :
|
||||
QListWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool ListWidget::isEditorOpen()
|
||||
{
|
||||
return (state() == QAbstractItemView::EditingState);
|
||||
}
|
||||
|
||||
void ListWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
|
||||
emit enterPressed();
|
||||
else if (event->key() == Qt::Key_Delete)
|
||||
emit deletePressed();
|
||||
|
||||
QListWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
CoreInfoLabel::CoreInfoLabel(QString text, QWidget *parent) :
|
||||
QLabel(text, parent)
|
||||
{
|
||||
@ -264,7 +282,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
,m_statusLabel(new QLabel(this))
|
||||
,m_dirTree(new TreeView(this))
|
||||
,m_dirModel(new QFileSystemModel(m_dirTree))
|
||||
,m_listWidget(new QListWidget(this))
|
||||
,m_listWidget(new ListWidget(this))
|
||||
,m_tableWidget(new TableWidget(this))
|
||||
,m_searchWidget(new QWidget(this))
|
||||
,m_searchLineEdit(new QLineEdit(this))
|
||||
@ -2374,7 +2392,7 @@ void MainWindow::onCurrentTableItemDataChanged(QTableWidgetItem *item)
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
/* block this signal because setData() would trigger an infinite look here */
|
||||
/* block this signal because setData() would trigger an infinite loop here */
|
||||
disconnect(m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onCurrentTableItemDataChanged(QTableWidgetItem*)));
|
||||
|
||||
hash = item->data(Qt::UserRole).value<QHash<QString, QString> >();
|
||||
@ -2390,6 +2408,78 @@ void MainWindow::onCurrentTableItemDataChanged(QTableWidgetItem *item)
|
||||
connect(m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onCurrentTableItemDataChanged(QTableWidgetItem*)));
|
||||
}
|
||||
|
||||
void MainWindow::onCurrentListItemDataChanged(QListWidgetItem *item)
|
||||
{
|
||||
renamePlaylistItem(item, item->text());
|
||||
}
|
||||
|
||||
void MainWindow::renamePlaylistItem(QListWidgetItem *item, QString newName)
|
||||
{
|
||||
QString oldPath;
|
||||
QString newPath;
|
||||
QString extension;
|
||||
QString oldName;
|
||||
QFile file;
|
||||
QFileInfo info;
|
||||
QFileInfo playlistInfo;
|
||||
QString playlistPath;
|
||||
settings_t *settings = config_get_ptr();
|
||||
QDir playlistDir(settings->paths.directory_playlist);
|
||||
bool specialPlaylist = false;
|
||||
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
playlistPath = item->data(Qt::UserRole).toString();
|
||||
playlistInfo = playlistPath;
|
||||
oldName = playlistInfo.completeBaseName();
|
||||
|
||||
/* Don't just compare strings in case there are case differences on Windows that should be ignored. */
|
||||
if (QDir(playlistInfo.absoluteDir()) != QDir(playlistDir))
|
||||
{
|
||||
/* special playlists like history etc. can't have an association */
|
||||
specialPlaylist = true;
|
||||
}
|
||||
|
||||
if (specialPlaylist)
|
||||
{
|
||||
/* special playlists shouldn't be editable already, but just in case, set the old name back and early return if they rename it */
|
||||
item->setText(oldName);
|
||||
return;
|
||||
}
|
||||
|
||||
/* block this signal because setData() would trigger an infinite loop here */
|
||||
disconnect(m_listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onCurrentListItemDataChanged(QListWidgetItem*)));
|
||||
|
||||
oldPath = item->data(Qt::UserRole).toString();
|
||||
|
||||
file.setFileName(oldPath);
|
||||
info = file;
|
||||
|
||||
extension = info.suffix();
|
||||
|
||||
newPath = info.absolutePath();
|
||||
|
||||
/* absolutePath() will always use / even on Windows */
|
||||
if (newPath.at(newPath.count() - 1) != '/')
|
||||
{
|
||||
/* add trailing slash if the path doesn't have one */
|
||||
newPath += '/';
|
||||
}
|
||||
|
||||
newPath += newName + "." + extension;
|
||||
|
||||
item->setData(Qt::UserRole, newPath);
|
||||
|
||||
if (!file.rename(newPath))
|
||||
{
|
||||
RARCH_ERR("[Qt]: Could not rename playlist.\n");
|
||||
item->setText(oldName);
|
||||
}
|
||||
|
||||
connect(m_listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onCurrentListItemDataChanged(QListWidgetItem*)));
|
||||
}
|
||||
|
||||
void MainWindow::currentItemChanged(const QHash<QString, QString> &hash)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
@ -2637,7 +2727,7 @@ void MainWindow::onBrowserStartClicked()
|
||||
m_dirTree->scrollTo(m_dirTree->currentIndex(), QAbstractItemView::PositionAtTop);
|
||||
}
|
||||
|
||||
QListWidget* MainWindow::playlistListWidget()
|
||||
ListWidget* MainWindow::playlistListWidget()
|
||||
{
|
||||
return m_listWidget;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QObject>
|
||||
#include <QMainWindow>
|
||||
#include <QTreeView>
|
||||
#include <QListWidget>
|
||||
#include <QTableWidget>
|
||||
#include <QFrame>
|
||||
#include <QWidget>
|
||||
@ -57,7 +58,6 @@ class QCloseEvent;
|
||||
class QKeyEvent;
|
||||
class QTimer;
|
||||
class QFileSystemModel;
|
||||
class QListWidget;
|
||||
class QListWidgetItem;
|
||||
class QTableWidgetItem;
|
||||
class QResizeEvent;
|
||||
@ -177,6 +177,19 @@ protected:
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
};
|
||||
|
||||
class ListWidget : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ListWidget(QWidget *parent = 0);
|
||||
bool isEditorOpen();
|
||||
signals:
|
||||
void enterPressed();
|
||||
void deletePressed();
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
};
|
||||
|
||||
class AppHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -250,7 +263,7 @@ public:
|
||||
MainWindow(QWidget *parent = NULL);
|
||||
~MainWindow();
|
||||
TreeView* dirTreeView();
|
||||
QListWidget* playlistListWidget();
|
||||
ListWidget* playlistListWidget();
|
||||
TableWidget* contentTableWidget();
|
||||
FlowLayout* contentGridLayout();
|
||||
QWidget* contentGridWidget();
|
||||
@ -361,6 +374,7 @@ private slots:
|
||||
void onCurrentListItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
|
||||
void onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
|
||||
void onCurrentTableItemDataChanged(QTableWidgetItem *item);
|
||||
void onCurrentListItemDataChanged(QListWidgetItem *item);
|
||||
void currentItemChanged(const QHash<QString, QString> &hash);
|
||||
void onSearchEnterPressed();
|
||||
void onSearchLineEditEdited(const QString &text);
|
||||
@ -437,6 +451,7 @@ private:
|
||||
int extractArchive(QString path);
|
||||
void removeUpdateTempFiles();
|
||||
bool addDirectoryFilesToList(QProgressDialog *dialog, QStringList &list, QDir &dir, QStringList &extensions);
|
||||
void renamePlaylistItem(QListWidgetItem *item, QString newName);
|
||||
QVector<QHash<QString, QString> > getPlaylistItems(QString pathString);
|
||||
|
||||
LoadCoreWindow *m_loadCoreWindow;
|
||||
@ -446,7 +461,7 @@ private:
|
||||
QLabel *m_statusLabel;
|
||||
TreeView *m_dirTree;
|
||||
QFileSystemModel *m_dirModel;
|
||||
QListWidget *m_listWidget;
|
||||
ListWidget *m_listWidget;
|
||||
TableWidget *m_tableWidget;
|
||||
QWidget *m_searchWidget;
|
||||
QLineEdit *m_searchLineEdit;
|
||||
|
Loading…
Reference in New Issue
Block a user