[multimedia/amarok] /: Small fixes to silence some compilation warnings

Tuomas Nurmi <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 323912f6d328a0a5b933c7e6ec3bd16117379633 by Tuomas Nurmi.
Committed on 29/07/2026 at 15:22.
Pushed by nurmi into branch 'master'.

Small fixes to silence some compilation warnings

Basic handling for some theoretical QFile::open false return values, some
QReadLocker and QWriteLocker changes to silence some warnings during
compilation of tests, etc.

M  +6    -1    src/configdialog/dialogs/ScriptsConfig.cpp
M  +4    -1    src/core-impl/collections/ipodcollection/IpodCollection.cpp
M  +7    -2    src/importers/amarok/AmarokEmbeddedSqlConnection.cpp
M  +4    -2    src/scripting/scriptconsole/ScriptConsole.cpp
M  +4    -3    src/scripting/scriptmanager/ScriptItem.cpp
M  +10   -2    src/services/lastfm/biases/WeeklyTopBias.cpp
M  +1    -1    src/widgets/BookmarkTriangle.cpp
M  +3    -3    tests/CollectionTestImpl.h
M  +2    -1    tests/core-impl/collections/db/sql/TestSqlScanManager.cpp
M  +2    -1    utilities/collectionscanner/CollectionScanner.cpp

https://invent.kde.org/multimedia/amarok/-/commit/323912f6d328a0a5b933c7e6ec3bd16117379633

diff --git a/src/configdialog/dialogs/ScriptsConfig.cpp b/src/configdialog/dialogs/ScriptsConfig.cpp
index d624b73d6c..4454fa25ca 100644
--- a/src/configdialog/dialogs/ScriptsConfig.cpp
+++ b/src/configdialog/dialogs/ScriptsConfig.cpp
@@ -171,7 +171,12 @@ ScriptsConfig::installLocalScript()
     }
 
     QTemporaryFile tempFile;
-    tempFile.open();
+    if( !tempFile.open() )
+    {
+        debug() << "Couldn't open temporary file for script processing";
+        KMessageBox::error( this, i18n( "Error" ) );
+        return;
+    }
     QIODevice *device = metadataFile->createDevice();
     tempFile.write( device->readAll() );
     delete device;
diff --git a/src/core-impl/collections/ipodcollection/IpodCollection.cpp b/src/core-impl/collections/ipodcollection/IpodCollection.cpp
index e4002d7177..f35e8ca676 100644
--- a/src/core-impl/collections/ipodcollection/IpodCollection.cpp
+++ b/src/core-impl/collections/ipodcollection/IpodCollection.cpp
@@ -539,7 +539,10 @@ IpodCollection::slotStartWriteDatabaseTimer()
         m_preventUnmountTempFile = new QTemporaryFile();
         QString name( QStringLiteral("/.itunes_database_dirty_in_amarok_prevent_unmounting") );
         m_preventUnmountTempFile->setFileTemplate( m_mountPoint + name );
-        m_preventUnmountTempFile->open();
+        if( !m_preventUnmountTempFile->open() )
+        {
+            debug() << "failed to open unmount preventer file on iPod, hopefully everything goes ok";
+        }
     }
 }
 
diff --git a/src/importers/amarok/AmarokEmbeddedSqlConnection.cpp b/src/importers/amarok/AmarokEmbeddedSqlConnection.cpp
index f87c52975c..9645f14d52 100644
--- a/src/importers/amarok/AmarokEmbeddedSqlConnection.cpp
+++ b/src/importers/amarok/AmarokEmbeddedSqlConnection.cpp
@@ -63,8 +63,13 @@ AmarokEmbeddedSqlConnection::connection()
 
     QTemporaryFile pidFile( QDir::temp().filePath( QStringLiteral("amarok_importer-XXXXXX.pid") ) );
     QTemporaryFile socket( QDir::temp().filePath( QStringLiteral("amarok_importer-XXXXXX.socket") ) );
-    pidFile.open();
-    socket.open();
+    bool pidOpen = pidFile.open();
+    bool socketOpen = socket.open();
+    if( !pidOpen || !socketOpen )
+    {
+        warning() << "Failed to create temporary files for AmarokEmbeddedSqlConnection";
+        return QSqlDatabase();
+    }
 
     // Get random port in range 3307 - 65535
     const int port = ( QRandomGenerator::global()->generate() % ( 65536 - 3307 ) ) + 3307;
diff --git a/src/scripting/scriptconsole/ScriptConsole.cpp b/src/scripting/scriptconsole/ScriptConsole.cpp
index fc975f0504..de986d0462 100644
--- a/src/scripting/scriptconsole/ScriptConsole.cpp
+++ b/src/scripting/scriptconsole/ScriptConsole.cpp
@@ -245,8 +245,10 @@ ScriptConsole::loadScripts()
             i++;
             ScriptEditorDocument *document = new ScriptEditorDocument( this, m_editor->createDocument( nullptr ) );
             QFile scriptText = QFile( scriptPath + QStringLiteral("/main.js") );
-            scriptText.open( QIODevice::ReadOnly );
-            document->setText( QString::fromUtf8( scriptText.readAll() ) );
+            if( scriptText.open( QIODevice::ReadOnly ) )
+                document->setText( QString::fromUtf8( scriptText.readAll() ) );
+            else
+                debug() << "Error loading script from " << scriptPath << QStringLiteral("/main.js");
             scriptText.close();
             scriptItem = new ScriptConsoleItem( this, dir, QStringLiteral("Generic"), scriptPath, document );
             m_scriptListDock->addScript( scriptItem );
diff --git a/src/scripting/scriptmanager/ScriptItem.cpp b/src/scripting/scriptmanager/ScriptItem.cpp
index 3485fd6071..41fcb52120 100644
--- a/src/scripting/scriptmanager/ScriptItem.cpp
+++ b/src/scripting/scriptmanager/ScriptItem.cpp
@@ -213,7 +213,8 @@ ScriptItem::start( bool silent )
     m_output.clear();
 
     QFile scriptFile( m_url.path() );
-    scriptFile.open( QIODevice::ReadOnly );
+    QString scriptContents = scriptFile.open( QIODevice::ReadOnly )
+        ? QString::fromUtf8(scriptFile.readAll()) : QStringLiteral( "Failed to read script file" );
     m_running = true;
 
     m_log << QStringLiteral( "%1 Script started" ).arg( QTime::currentTime().toString() );
@@ -226,10 +227,10 @@ ScriptItem::start( bool silent )
                 QStringLiteral("const ([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*) *="),
                 QRegularExpression::DotMatchesEverythingOption );
         m_engineResult = m_engine->evaluate(
-               QString::fromUtf8(scriptFile.readAll()).replace( removeConst, QStringLiteral("var \\1 =") ),
+               scriptContents.replace( removeConst, QStringLiteral("var \\1 =") ),
                 m_name);
     } else {
-        m_engineResult = m_engine->evaluate(QString::fromUtf8(scriptFile.readAll()), m_name);
+        m_engineResult = m_engine->evaluate( scriptContents, m_name );
     }
     m_output << m_engineResult.toString();
     debug() << "After Evaluation "<< m_name;
diff --git a/src/services/lastfm/biases/WeeklyTopBias.cpp b/src/services/lastfm/biases/WeeklyTopBias.cpp
index 6d6eb32cea..6f019db83c 100644
--- a/src/services/lastfm/biases/WeeklyTopBias.cpp
+++ b/src/services/lastfm/biases/WeeklyTopBias.cpp
@@ -461,7 +461,11 @@ void
 Dynamic::WeeklyTopBias::loadFromFile()
 {
     QFile file( Amarok::saveLocation() + QStringLiteral("dynamic_lastfm_topweeklyartists.xml") );
-    file.open( QIODevice::ReadOnly | QIODevice::Text );
+    if( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
+    {
+        debug() << "Failed to open " << Amarok::saveLocation() + QStringLiteral("dynamic_lastfm_topweeklyartists.xml") << " for reading";
+        return;
+    }
     QTextStream in( &file );
     while( !in.atEnd() )
     {
@@ -476,7 +480,11 @@ void
 Dynamic::WeeklyTopBias::saveDataToFile() const
 {
     QFile file( Amarok::saveLocation() + QStringLiteral("dynamic_lastfm_topweeklyartists.xml") );
-    file.open( QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text );
+    if( !file.open( QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text ) )
+    {
+        debug() << "Failed to open " << Amarok::saveLocation() + QStringLiteral("dynamic_lastfm_topweeklyartists.xml") << " for writing";
+        return;
+    }
     QTextStream out( &file );
     for( uint key : m_weeklyArtistMap.keys() )
     {
diff --git a/src/widgets/BookmarkTriangle.cpp b/src/widgets/BookmarkTriangle.cpp
index e7c104c08e..5ff8453872 100644
--- a/src/widgets/BookmarkTriangle.cpp
+++ b/src/widgets/BookmarkTriangle.cpp
@@ -99,7 +99,7 @@ void BookmarkTriangle::mousePressEvent ( QMouseEvent * event )
 void BookmarkTriangle::mouseMoveEvent ( QMouseEvent * event )
 {
     event->accept();
-    int distance_x = event->x() - m_offset.x();
+    int distance_x = event->position().x() - m_offset.x();
     QPoint pt(distance_x, 0);
     move(mapToParent( pt ));
 }
diff --git a/tests/CollectionTestImpl.h b/tests/CollectionTestImpl.h
index 3744b49c74..a5ddd63912 100644
--- a/tests/CollectionTestImpl.h
+++ b/tests/CollectionTestImpl.h
@@ -82,7 +82,7 @@ public:
 private:
     Meta::TrackPtr findTrackForUrl( const QUrl &url ) const
     {
-        QReadLocker( mc->mapLock() );
+        QReadLocker lock( mc->mapLock() );
 
         for( auto const &track : mc->trackMap().values() )
             if( track->playableUrl() == url )
@@ -116,7 +116,7 @@ private:
         {
             Q_UNUSED( configuration );
 
-            QWriteLocker( m_mc->mapLock() );
+            QWriteLocker lock( m_mc->mapLock() );
 
             for( auto const &track : sources.keys() )
             {
@@ -131,7 +131,7 @@ private:
         {
             Q_UNUSED( url );
 
-            QWriteLocker( m_mc->mapLock() );
+            QWriteLocker lock( m_mc->mapLock() );
 
             if( m_mc->trackMap().contains( track->uidUrl() ) )
                 return false;
diff --git a/tests/core-impl/collections/db/sql/TestSqlScanManager.cpp b/tests/core-impl/collections/db/sql/TestSqlScanManager.cpp
index bb1e2e8f7f..336186ccd9 100644
--- a/tests/core-impl/collections/db/sql/TestSqlScanManager.cpp
+++ b/tests/core-impl/collections/db/sql/TestSqlScanManager.cpp
@@ -1113,7 +1113,8 @@ TestSqlScanManager::testPartialUpdate()
 
     // Updating mtime for the directory triggered the bug this test was made for; do it here by creating a file within
     QFile f( m_tmpCollectionDir->path() + QStringLiteral("/Pop/Thriller/touch") );
-    f.open(QIODevice::WriteOnly);
+    if( !f.open(QIODevice::WriteOnly) )
+        qWarning() << "Failed to create a file in " << m_tmpCollectionDir->path() << QStringLiteral("/Pop/Thriller/touch");
     f.close();
     directoryWatcherSimulator.clear();
     directoryWatcherSimulator << QUrl::fromUserInput( m_tmpCollectionDir->path() + QStringLiteral("/Pop/Thriller") );
diff --git a/utilities/collectionscanner/CollectionScanner.cpp b/utilities/collectionscanner/CollectionScanner.cpp
index 59f632a893..c8d101b1dc 100644
--- a/utilities/collectionscanner/CollectionScanner.cpp
+++ b/utilities/collectionscanner/CollectionScanner.cpp
@@ -147,7 +147,8 @@ void
 CollectionScanner::Scanner::doJob() //SLOT
 {
     QFile xmlFile;
-    xmlFile.open( stdout, QIODevice::WriteOnly );
+    if( !xmlFile.open( stdout, QIODevice::WriteOnly ) )
+        qWarning() << Q_FUNC_INFO << "uh oh, failed to open stdout for writing, things probably don't work";
     QXmlStreamWriter xmlWriter( &xmlFile );
     xmlWriter.setAutoFormatting( true );
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.