Skip to content

Commit a9878b1

Browse files
committed
Qt: prefer libretro-common file APIs and drop Qt5/Qt6 ladders
Reduces Qt-specific surface and silences three pre-existing -Wdeprecated-declarations warnings. All changes preserve behaviour on Qt 5.2 and up (RetroArch's minimum, per qb/config.libs.sh). * MainWindow::MainWindow: Drop dead 'QDir playlistDir(path_dir_playlist)' and the path_dir_playlist local that only existed to construct it. Both unused since the constructor split. -Wunused-variable did not flag the QDir because of its non-trivial constructor. * MainWindow::setCustomThemeFile: Replace QFile open / readAll / close with filestream_read_file plus filestream_exists. Same five error paths preserved (blank path, missing file, open failure, empty file, success). * MainWindow::onFileBrowserTreeContextMenuRequested: Replace the QDir / dir.exists() existence check with path_is_directory(). Removes a Qt5/Qt6 ifdef ladder ('dir = string' on Qt5 vs 'dir.setPath(string)' on Qt6) and silences the QDir::operator=(QString) deprecation warning. The QDir::toNativeSeparators(...) display path stays - that side is fine on both Qt 5 and Qt 6. * LoadCoreWindow::onCoreEnterPressed: Replace 'QByteArray::append(QString)' (Qt 5) / 'QByteArray::append(QString::toStdString())' (Qt 6) ladder with 'path.toUtf8().constData()' inline. The temporary QByteArray's lifetime extends through the loadCore() call so this is safe. Silences the QByteArray::append(QString) deprecation warning. * MainWindow::onPlaylistWidgetContextMenuRequested: Replace 'm_listWidget->isItemHidden(item)' (deprecated since Qt 4.8) with 'item->isHidden()' (available since Qt 4.x). Removes a Qt5/Qt6 ifdef ladder. Silences the QListWidget::isItemHidden() deprecation warning. Tested under Qt 5.15 with -Wdeprecated-declarations enabled; all four object files (ui_qt, ui_qt_widgets, moc_ui_qt, moc_ui_qt_widgets) now build with zero warnings. No behaviour change.
1 parent 334f787 commit a9878b1

2 files changed

Lines changed: 33 additions & 59 deletions

File tree

ui/drivers/ui_qt.cpp

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,9 +1540,7 @@ MainWindow::MainWindow(QWidget *parent) :
15401540
,m_itemsCountLabel(new QLabel(this))
15411541
{
15421542
settings_t *settings = config_get_ptr();
1543-
const char *path_dir_playlist = settings->paths.directory_playlist;
15441543
const char *path_dir_assets = settings->paths.directory_assets;
1545-
QDir playlistDir(path_dir_playlist);
15461544
QString configDir = QFileInfo(path_get(RARCH_PATH_CONFIG)).dir().absolutePath();
15471545

15481546
qRegisterMetaType<QPointer<ThumbnailWidget> >("ThumbnailWidget");
@@ -2202,6 +2200,11 @@ const QString& MainWindow::customThemeString() const
22022200

22032201
bool MainWindow::setCustomThemeFile(QString filePath)
22042202
{
2203+
QByteArray pathArray;
2204+
const char *path_data;
2205+
void *buf = NULL;
2206+
int64_t len = 0;
2207+
22052208
if (filePath.isEmpty())
22062209
{
22072210
QMessageBox::critical(this,
@@ -2210,45 +2213,37 @@ bool MainWindow::setCustomThemeFile(QString filePath)
22102213
return false;
22112214
}
22122215

2213-
QFile file(filePath);
2216+
pathArray = filePath.toUtf8();
2217+
path_data = pathArray.constData();
22142218

2215-
if (file.exists())
2219+
if (!filestream_exists(path_data))
22162220
{
2217-
bool opened = file.open(QIODevice::ReadOnly);
2218-
2219-
if (!opened)
2220-
{
2221-
QMessageBox::critical(this,
2222-
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME),
2223-
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_READ_OPEN_FAILED));
2224-
return false;
2225-
}
2226-
2227-
{
2228-
QByteArray fileArray = file.readAll();
2229-
QString fileStr = QString::fromUtf8(fileArray);
2230-
2231-
file.close();
2232-
2233-
if (fileStr.isEmpty())
2234-
{
2235-
QMessageBox::critical(this,
2236-
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME),
2237-
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_IS_EMPTY));
2238-
return false;
2239-
}
2221+
QMessageBox::critical(this,
2222+
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME),
2223+
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_DOES_NOT_EXIST));
2224+
return false;
2225+
}
22402226

2241-
setCustomThemeString(fileStr);
2242-
}
2227+
if (!filestream_read_file(path_data, &buf, &len))
2228+
{
2229+
QMessageBox::critical(this,
2230+
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME),
2231+
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_READ_OPEN_FAILED));
2232+
return false;
22432233
}
2244-
else
2234+
2235+
if (len <= 0)
22452236
{
2237+
free(buf);
22462238
QMessageBox::critical(this,
22472239
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME),
2248-
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_DOES_NOT_EXIST));
2240+
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_IS_EMPTY));
22492241
return false;
22502242
}
22512243

2244+
setCustomThemeString(QString::fromUtf8(static_cast<const char*>(buf),
2245+
static_cast<int>(len)));
2246+
free(buf);
22522247
return true;
22532248
}
22542249

@@ -2327,28 +2322,24 @@ bool MainWindow::showMessageBox(QString msg, MessageBoxType msgType,
23272322
void MainWindow::onFileBrowserTreeContextMenuRequested(const QPoint&)
23282323
{
23292324
#ifdef HAVE_LIBRETRODB
2330-
QDir dir;
2331-
QByteArray dirArray;
23322325
QPointer<QAction> action;
23332326
QList<QAction*> actions;
23342327
QScopedPointer<QAction> scanAction;
23352328
QString currentDirString = QDir::toNativeSeparators(
23362329
m_dirModel->filePath(m_dirTree->currentIndex()));
23372330
settings_t *settings = config_get_ptr();
2338-
const char *fullpath = NULL;
23392331
const char *path_dir_playlist = settings->paths.directory_playlist;
23402332
const char *path_content_db = settings->paths.path_content_database;
2333+
QByteArray dirArray;
2334+
const char *fullpath = NULL;
23412335

23422336
if (currentDirString.isEmpty())
23432337
return;
23442338

2345-
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
2346-
dir.setPath(currentDirString);
2347-
#else
2348-
dir = currentDirString;
2349-
#endif
2339+
dirArray = currentDirString.toUtf8();
2340+
fullpath = dirArray.constData();
23502341

2351-
if (!dir.exists())
2342+
if (!path_is_directory(fullpath))
23522343
return;
23532344

23542345
/* Default NULL parameter for parent wasn't added until 5.7 */
@@ -2360,9 +2351,6 @@ void MainWindow::onFileBrowserTreeContextMenuRequested(const QPoint&)
23602351
if (!(action = QMenu::exec(actions, QCursor::pos(), NULL, m_dirTree)))
23612352
return;
23622353

2363-
dirArray = currentDirString.toUtf8();
2364-
fullpath = dirArray.constData();
2365-
23662354
task_push_dbscan(
23672355
path_dir_playlist,
23682356
path_content_db,
@@ -5426,22 +5414,13 @@ void LoadCoreWindow::loadCore(const char *path)
54265414

54275415
void LoadCoreWindow::onCoreEnterPressed()
54285416
{
5429-
QByteArray pathArray;
5430-
const char *pathData = NULL;
54315417
QTableWidgetItem *selectedCoreItem =
54325418
m_table->item(m_table->currentRow(), CORE_NAME_COLUMN);
54335419
QVariantHash hash = selectedCoreItem->data(
54345420
Qt::UserRole).toHash();
54355421
QString path = hash["path"].toString();
54365422

5437-
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
5438-
pathArray.append(path.toStdString());
5439-
#else
5440-
pathArray.append(path);
5441-
#endif
5442-
pathData = pathArray.constData();
5443-
5444-
loadCore(pathData);
5423+
loadCore(path.toUtf8().constData());
54455424
}
54465425

54475426
void LoadCoreWindow::onLoadCustomCoreClicked()

ui/drivers/ui_qt_widgets.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8024,13 +8024,8 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
80248024
for (j = 0; j < m_listWidget->count(); j++)
80258025
{
80268026
QListWidgetItem *item = m_listWidget->item(j);
8027-
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
8028-
bool hidden = item->isHidden();
8029-
#else
8030-
bool hidden = m_listWidget->isItemHidden(item);
8031-
#endif
80328027

8033-
if (hidden)
8028+
if (item->isHidden())
80348029
{
80358030
QAction *action = hiddenPlaylistsMenu->addAction(item->text());
80368031
action->setProperty("row", j);

0 commit comments

Comments
 (0)