Qt: add options for new/delete playlist

This commit is contained in:
Brad Parker 2018-07-26 00:38:15 -04:00
parent e9c4192e9b
commit be952a9d14
5 changed files with 91 additions and 8 deletions

View File

@ -3638,3 +3638,15 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_ALL_PLAYLISTS_GRID_MAX_COUNT
"「すべてのプレイリスト」アイコンの最大個数:")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SHOW_HIDDEN_FILES,
"隠しファイルとフォルダを表示:")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST,
"新規プレイリスト")
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_CONFIRM_DELETE_PLAYLIST,
"「%1」というプレイリストを削除しますか")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_QUESTION,
"質問")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE,
"ファイル削除に失敗しました。")

View File

@ -3796,3 +3796,15 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_ALL_PLAYLISTS_GRID_MAX_COUNT
"\"All Playlists\" max grid entries:")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SHOW_HIDDEN_FILES,
"Show hidden files and folders:")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST,
"New Playlist")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME,
"Please enter the new playlist name:")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST,
"Delete Playlist")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST,
"Are you sure you want to delete the playlist \"%1\"?")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_QUESTION,
"Question")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE,
"Could not delete file.")

View File

@ -1879,6 +1879,12 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_ICONS,
MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_LIST,
MENU_ENUM_LABEL_VALUE_QT_PROGRESS,
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_CONFIRM_DELETE_PLAYLIST,
MENU_ENUM_LABEL_VALUE_QT_QUESTION,
MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE,
MENU_LABEL(MIDI_INPUT),
MENU_LABEL(MIDI_OUTPUT),

View File

@ -29,6 +29,7 @@
#include <QMenu>
#include <QDockWidget>
#include <QList>
#include <QInputDialog>
#include <QtConcurrentRun>
#include "../ui_qt.h"
@ -977,7 +978,7 @@ void MainWindow::setCustomThemeString(QString qss)
m_customThemeString = qss;
}
bool MainWindow::showMessageBox(QString msg, MessageBoxType msgType, Qt::WindowModality modality)
bool MainWindow::showMessageBox(QString msg, MessageBoxType msgType, Qt::WindowModality modality, bool showDontAsk)
{
QPointer<QMessageBox> msgBoxPtr;
QMessageBox *msgBox = NULL;
@ -985,13 +986,16 @@ bool MainWindow::showMessageBox(QString msg, MessageBoxType msgType, Qt::WindowM
msgBoxPtr = new QMessageBox(this);
msgBox = msgBoxPtr.data();
checkBox = new QCheckBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DONT_SHOW_AGAIN), msgBox);
msgBox->setWindowModality(modality);
msgBox->setTextFormat(Qt::RichText);
/* QMessageBox::setCheckBox() is available since 5.2 */
msgBox->setCheckBox(checkBox);
if (showDontAsk)
{
checkBox = new QCheckBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DONT_SHOW_AGAIN), msgBox);
/* QMessageBox::setCheckBox() is available since 5.2 */
msgBox->setCheckBox(checkBox);
}
switch (msgType)
{
@ -1013,6 +1017,13 @@ bool MainWindow::showMessageBox(QString msg, MessageBoxType msgType, Qt::WindowM
msgBox->setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ERROR));
break;
}
case MSGBOX_TYPE_QUESTION:
{
msgBox->setIcon(QMessageBox::Question);
msgBox->setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_QUESTION));
msgBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
break;
}
default:
break;
}
@ -1023,7 +1034,10 @@ bool MainWindow::showMessageBox(QString msg, MessageBoxType msgType, Qt::WindowM
if (!msgBoxPtr)
return true;
if (checkBox->isChecked())
if (checkBox && checkBox->isChecked())
return false;
if (msgBox->result() == QMessageBox::Cancel)
return false;
return true;
@ -1036,6 +1050,8 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
QScopedPointer<QMenu> associateMenu;
QScopedPointer<QMenu> hiddenPlaylistsMenu;
QScopedPointer<QAction> hideAction;
QScopedPointer<QAction> newPlaylistAction;
QScopedPointer<QAction> deletePlaylistAction;
QPointer<QAction> selectedAction;
QPoint cursorPos = QCursor::pos();
QListWidgetItem *selectedItem = m_listWidget->itemAt(m_listWidget->viewport()->mapFromGlobal(cursorPos));
@ -1044,6 +1060,7 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
QString currentPlaylistDirPath;
QString currentPlaylistPath;
QString currentPlaylistFileName;
QFile currentPlaylistFile;
QByteArray currentPlaylistFileNameArray;
QFileInfo currentPlaylistFileInfo;
QMap<QString, const core_info_t*> coreList;
@ -1069,6 +1086,9 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
stcores = string_split(settings->arrays.playlist_cores, ";");
currentPlaylistPath = selectedItem->data(Qt::UserRole).toString();
currentPlaylistFile.setFileName(currentPlaylistPath);
currentPlaylistFileInfo = QFileInfo(currentPlaylistPath);
currentPlaylistFileName = currentPlaylistFileInfo.fileName();
currentPlaylistDirPath = currentPlaylistFileInfo.absoluteDir().absolutePath();
@ -1080,11 +1100,19 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
menu->setObjectName("menu");
hiddenPlaylistsMenu.reset(new QMenu(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_HIDDEN_PLAYLISTS), this));
hideAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_HIDE), this));
newPlaylistAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST)) + "...", this));
hiddenPlaylistsMenu->setObjectName("hiddenPlaylistsMenu");
hideAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_HIDE), this));
menu->addAction(hideAction.data());
menu->addAction(newPlaylistAction.data());
if (currentPlaylistFile.exists())
{
deletePlaylistAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST)) + "...", this));
menu->addAction(deletePlaylistAction.data());
}
for (j = 0; j < m_listWidget->count() && m_listWidget->count() > 0; j++)
{
@ -1180,6 +1208,30 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
strlcpy(settings->arrays.playlist_cores,
new_playlist_cores, sizeof(settings->arrays.playlist_cores));
}
else if (selectedAction == deletePlaylistAction.data())
{
if (currentPlaylistFile.exists())
{
if (ui_window.qtWindow->showMessageBox(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST)).arg(selectedItem->text()), MainWindow::MSGBOX_TYPE_QUESTION, Qt::ApplicationModal, false))
{
if (currentPlaylistFile.remove())
reloadPlaylists();
else
ui_window.qtWindow->showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false);
}
}
}
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));
QString newPlaylistPath = playlistDirAbsPath + "/" + name + file_path_str(FILE_PATH_LPL_EXTENSION);
QFile file(newPlaylistPath);
if (file.open(QIODevice::WriteOnly))
file.close();
reloadPlaylists();
}
else if (selectedAction == hideAction.data())
{
int row = m_listWidget->row(selectedItem);

View File

@ -261,6 +261,7 @@ public:
MSGBOX_TYPE_INFO,
MSGBOX_TYPE_WARNING,
MSGBOX_TYPE_ERROR,
MSGBOX_TYPE_QUESTION,
};
MainWindow(QWidget *parent = NULL);
@ -288,7 +289,7 @@ public:
QString getThemeString(Theme theme);
QHash<QString, QString> getSelectedCore();
void showStatusMessage(QString msg, unsigned priority, unsigned duration, bool flush);
bool showMessageBox(QString msg, MessageBoxType msgType = MSGBOX_TYPE_INFO, Qt::WindowModality modality = Qt::ApplicationModal);
bool showMessageBox(QString msg, MessageBoxType msgType = MSGBOX_TYPE_INFO, Qt::WindowModality modality = Qt::ApplicationModal, bool showDontAsk = true);
bool setCustomThemeFile(QString filePath);
void setCustomThemeString(QString qss);
const QString& customThemeString() const;