1616
1717#include < QAKQuick/quickactioncontext.h>
1818
19- #include < audio/AudioExporterConfig.h>
20- #include < audio/internal/AudioExporterPresets.h>
2119#include < coreplugin/ProjectDocumentContext.h>
2220#include < coreplugin/ProjectWindowInterface.h>
2321
22+ #include < audio/AudioExporter.h>
23+ #include < audio/AudioExporterConfig.h>
24+ #include < audio/internal/AudioExporterPresets.h>
25+
2426namespace Audio ::Internal {
2527 namespace {
2628 QString documentsDirectory () {
@@ -38,6 +40,14 @@ namespace Audio::Internal {
3840 }
3941 return documentsDirectory ();
4042 }
43+
44+ void applyFileType (AudioExporterConfig &config, int index) {
45+ const QFileInfo fileInfo (config.fileName ());
46+ config.setFileType (static_cast <AudioExporterConfig::FileType>(index));
47+ config.setFormatOption (0 );
48+ config.setFileName (fileInfo.completeBaseName () + QStringLiteral (" ." ) +
49+ AudioExporterConfig::extensionOfType (static_cast <AudioExporterConfig::FileType>(index)));
50+ }
4151 }
4252
4353 ExportAudioAddOn::ExportAudioAddOn (QObject *parent) : WindowInterfaceAddOn(parent) {
@@ -76,12 +86,20 @@ namespace Audio::Internal {
7686 if (!windowInterface || !windowInterface->window ())
7787 return ;
7888
89+ AudioExporter exporter (windowInterface, this );
90+
91+ connect (AudioExporterPresets::instance (), &AudioExporterPresets::currentConfigChanged, &exporter, [&exporter] {
92+ exporter.setConfig (AudioExporterPresets::instance ()->currentConfig ());
93+ });
94+ exporter.setConfig (AudioExporterPresets::instance ()->currentConfig ());
95+
7996 QQmlComponent component (Core::RuntimeInterface::qmlEngine (), " DiffScope.Audio" , " AudioExportDialog" );
8097 if (component.isError ()) {
8198 qFatal () << component.errorString ();
8299 }
83100 std::unique_ptr<QWindow> dialog (qobject_cast<QWindow *>(component.createWithInitialProperties ({
84- {" addOn" , QVariant::fromValue (this )}
101+ {" addOn" , QVariant::fromValue (this )},
102+ {" exporter" , QVariant::fromValue (&exporter)},
85103 })));
86104 if (!dialog) {
87105 qFatal () << component.errorString ();
@@ -112,7 +130,7 @@ namespace Audio::Internal {
112130 const auto path = QFileDialog::getSaveFileName (
113131 nullptr ,
114132 {},
115- QDir (projectDirectory (windowInterface)).absoluteFilePath (config.fileName ()),
133+ QDir (projectDirectory (windowInterface)).absoluteFilePath (config.fileDirectory ()),
116134 filters.join (QStringLiteral (" ;;" )),
117135 &selectedFilter
118136 );
@@ -126,7 +144,7 @@ namespace Audio::Internal {
126144 : QStringLiteral (" _${trackIndex}_${trackName}." );
127145 config.setFileName (fileInfo.completeBaseName () + templateSuffix + fileInfo.suffix ());
128146 config.setFileDirectory (fileInfo.dir ().canonicalPath ());
129- config. setFileType ( static_cast <AudioExporterConfig::FileType>( filters.indexOf (selectedFilter) ));
147+ applyFileType (config, filters.indexOf (selectedFilter));
130148 presets->setCurrentConfig (config);
131149 }
132150
@@ -153,6 +171,13 @@ namespace Audio::Internal {
153171 presets->setCurrentConfig (config);
154172 }
155173
174+ void ExportAudioAddOn::setFileType (int index) {
175+ auto presets = AudioExporterPresets::instance ();
176+ auto config = presets->currentConfig ();
177+ applyFileType (config, index);
178+ presets->setCurrentConfig (config);
179+ }
180+
156181}
157182
158183#include " moc_ExportAudioAddOn.cpp"
0 commit comments