27 #include <QStandardPaths> 42 : mResourceFile(resourcefile)
61 return settings.value(
"app/startupsound",
true).toBool();
78 LOGSTATUS <<
"Setting enabled =" << (enabled ?
"true" :
"false");
79 settings.setValue(
"app/startupsound",enabled);
99 LOGMESSAGE <<
"Startup sound is disabled in the settings";
105 if (mResourceFile.size()==0)
return;
106 int lastPoint = mResourceFile.lastIndexOf(
".");
107 const QString extension =
108 mResourceFile.right(mResourceFile.size()-lastPoint-1);
109 if (extension.size() != 3)
111 LOGWARNING <<
"Could not identify extension of resource file" 112 << mResourceFile <<
":" << extension;
119 const QString localpath =
120 QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
122 if (not directory.mkpath(localpath))
124 LOGWARNING <<
"Cannot create local path" << localpath;
129 const QString filename =
"startupsound." + extension;
130 QFile localfile (localpath +
"/" + filename);
131 if (localfile.exists())
133 if (localfile.size() != QResource(mResourceFile).size())
137 QFile::copy(mResourceFile, localfile.fileName());
140 else QFile::copy(mResourceFile, localfile.fileName());
141 if (not localfile.exists())
LOGWARNING<<
"Startupsound could not be copied.";
142 LOGSTATUS << mResourceFile <<
"was copied to" << localfile.fileName();
144 mPlayer.setMedia(QUrl::fromLocalFile(localfile.fileName()));
145 mPlayer.setVolume(static_cast<int>(100*volume));
147 if (
mPlayer.error() != QMediaPlayer::NoError)
149 LOGSTATUS <<
"Leaving Startupsound::play()";
QMediaPlayer mPlayer
Pointer to the player.
QString mResourceFile
Resource file object.
void play(double volume)
Play startup sound.
void enable(bool enabled)
Public slot: Enable / disable startup sound.
StartupSound(const QString &resourcefile)
Constructor.
bool isEnabled()
StartupSound::isEnabled.