diff --git a/intl/msg_hash_ja.h b/intl/msg_hash_ja.h index 4309fcb8b3..69ece6caf1 100644 --- a/intl/msg_hash_ja.h +++ b/intl/msg_hash_ja.h @@ -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, + "ファイル削除に失敗しました。") diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index f9a0321199..295f349e00 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -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.") diff --git a/msg_hash.h b/msg_hash.h index 985bff2205..2cafb7af5a 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -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), diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index 0b8d94b9ea..03f13d1617 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #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 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 associateMenu; QScopedPointer hiddenPlaylistsMenu; QScopedPointer hideAction; + QScopedPointer newPlaylistAction; + QScopedPointer deletePlaylistAction; QPointer 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 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); diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index 3912428a2c..1b1ebb5865 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -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 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;