File: InteractiveFileFinder.cpp

package info (click to toggle)
sonic-visualiser 5.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,744 kB
  • sloc: cpp: 158,888; ansic: 11,920; sh: 1,785; makefile: 517; xml: 64; perl: 31
file content (690 lines) | stat: -rw-r--r-- 22,637 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*
    Sonic Visualiser
    An audio file viewer and annotation editor.
    Centre for Digital Music, Queen Mary, University of London.
    This file copyright 2007 QMUL.
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or (at your option) any later version.  See the file
    COPYING included with this distribution for more information.
*/

#include "InteractiveFileFinder.h"
#include "data/fileio/FileSource.h"
#include "data/fileio/AudioFileReaderFactory.h"
#include "data/fileio/DataFileReaderFactory.h"
#include "rdf/RDFImporter.h"
#include "rdf/RDFExporter.h"
#include "system/System.h"

#include <QFileInfo>
#include <QMessageBox>
#include <QPushButton>
#include <QFileDialog>
#include <QInputDialog>
#include <QImageReader>
#include <QSettings>

#include <iostream>

namespace sv {

InteractiveFileFinder 
InteractiveFileFinder::m_instance;

InteractiveFileFinder::InteractiveFileFinder() :
    m_sessionExtension("sv"),
    m_lastLocatedLocation(""),
    m_parent(nullptr)
{
    FileFinder::registerFileFinder(this);
}

InteractiveFileFinder::~InteractiveFileFinder()
{
}

void
InteractiveFileFinder::setParentWidget(QWidget *parent)
{
    getInstance()->m_parent = parent;
}

void
InteractiveFileFinder::setApplicationSessionExtension(QString extension)
{
    m_sessionExtension = extension;
}

QString
InteractiveFileFinder::getOpenFileName(FileType type,
                                       QString fallbackLocation)
{
    QStringList names = getOpenFileNames(type,
                                         fallbackLocation,
                                         false);
    if (names.empty()) return "";
    else return names[0];
}

QStringList
InteractiveFileFinder::getOpenFileNames(FileType type,
                                        QString fallbackLocation)
{
    return getOpenFileNames(type,
                            fallbackLocation,
                            true);
}

QStringList
InteractiveFileFinder::getOpenFileNames(FileType type,
                                        QString fallbackLocation,
                                        bool multiple)
{
    QString settingsKeyStub;
    QString lastPath = fallbackLocation;
    
    QString title;
    if (multiple) {
        title = tr("Select one or more files");
    } else {
        title = tr("Select file");
    }
    QString filter = tr("All files (*.*)");

    QStringList names;
    
    switch (type) {

    case SessionFile:
        settingsKeyStub = "session";
        if (multiple) {
            title = tr("Select one or more session files");
        } else {
            title = tr("Select a session file");
        }
        filter = tr("%1 session files (*.%2)\nRDF files (%3)\nAll files (*.*)")
            .arg(QApplication::applicationName())
            .arg(m_sessionExtension)
            .arg(RDFImporter::getKnownExtensions());
        break;

    case AudioFile:
        settingsKeyStub = "audio";
        if (multiple) {
            title = tr("Select one or more audio files");
        } else {
            title = tr("Select an audio file");
        }
        filter = tr("Audio files (%1)\nAll files (*.*)")
            .arg(AudioFileReaderFactory::getKnownExtensions());
        break;

    case LayerFile:
        settingsKeyStub = "layer";
        filter = tr("All supported files (%1 %2)\nSonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nSpace-separated .lab files (*.lab)\nRDF files (%2)\nMIDI files (*.mid)\nText files (*.txt)\nAll files (*.*)")
            .arg(DataFileReaderFactory::getKnownExtensions())
            .arg(RDFImporter::getKnownExtensions());
        break;

    case LayerFileNoMidi:
        settingsKeyStub = "layer";
        filter = tr("All supported files (%1 %2)\nSonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nSpace-separated .lab files (*.lab)\nRDF files (%2)\nText files (*.txt)\nAll files (*.*)")
            .arg(DataFileReaderFactory::getKnownExtensions())
            .arg(RDFImporter::getKnownExtensions());
        break;

    case LayerFileNonSV:
        settingsKeyStub = "layer";
        filter = tr("All supported files (%1 %2)\nComma-separated data files (*.csv)\nSonic Visualiser Layer XML files (*.svl)\nSpace-separated .lab files (*.lab)\nRDF files (%2)\nMIDI files (*.mid)\nText files (*.txt)\nAll files (*.*)")
            .arg(DataFileReaderFactory::getKnownExtensions())
            .arg(RDFImporter::getKnownExtensions());
        break;

    case LayerFileNoMidiNonSV:
        settingsKeyStub = "layer";
        filter = tr("All supported files (%1 %2)\nComma-separated data files (*.csv)\nSonic Visualiser Layer XML files (*.svl)\nSpace-separated .lab files (*.lab)\nRDF files (%2)\nText files (*.txt)\nAll files (*.*)")
            .arg(DataFileReaderFactory::getKnownExtensions())
            .arg(RDFImporter::getKnownExtensions());
        break;

    case SessionOrAudioFile:
        settingsKeyStub = "last";
        filter = tr("All supported files (*.%1 %2 %3)\n%4 session files (*.%1)\nAudio files (%3)\nRDF files (%2)\nAll files (*.*)")
            .arg(m_sessionExtension)
            .arg(RDFImporter::getKnownExtensions())
            .arg(AudioFileReaderFactory::getKnownExtensions())
            .arg(QApplication::applicationName());
        break;

    case ImageFile:
        settingsKeyStub = "image";
        {
            QStringList fmts;
            QList<QByteArray> formats = QImageReader::supportedImageFormats();
            for (QList<QByteArray>::iterator i = formats.begin();
                 i != formats.end(); ++i) {
                fmts.push_back(QString("*.%1")
                               .arg(QString::fromLocal8Bit(*i).toLower()));
            }
            filter = tr("Image files (%1)\nAll files (*.*)").arg(fmts.join(" "));
        }
        break;

    case SVGFile:
        settingsKeyStub = "svg";
        filter = tr("Scalable Vector Graphics files (*.svg)\nAll files (*.*)");
        break;

    case CSVFile:
        settingsKeyStub = "layer";
        filter = tr("Comma-separated data files (*.csv)\nSpace-separated .lab files (*.lab)\nText files (*.txt)\nAll files (*.*)");
        break;

    case AnyFile:
        settingsKeyStub = "last";
        filter = tr("All supported files (*.%1 %2 %3 %4)\n%5 session files (*.%1)\nAudio files (%2)\nLayer files (%3)\nRDF files (%4)\nAll files (*.*)")
            .arg(m_sessionExtension)
            .arg(AudioFileReaderFactory::getKnownExtensions())
            .arg(DataFileReaderFactory::getKnownExtensions())
            .arg(RDFImporter::getKnownExtensions())
            .arg(QApplication::applicationName());
        break;
    };

    if (lastPath == "") {
        std::string home;
        if (getEnvUtf8("HOME", home)) {
            lastPath = QString::fromStdString(home);
        } else {
            lastPath = ".";
        }
    } else if (QFileInfo(lastPath).isDir()) {
        lastPath = QFileInfo(lastPath).canonicalFilePath();
    } else {
        lastPath = QFileInfo(lastPath).canonicalPath();
    }

    QSettings settings;
    settings.beginGroup("FileFinder");
    lastPath = settings.value(settingsKeyStub + "path", lastPath).toString();

    // Use our own QFileDialog just for symmetry with getSaveFileName below

    QFileDialog dialog(m_parent);
    dialog.setNameFilters(filter.split('\n'));
    dialog.setWindowTitle(title);
    dialog.setDirectory(lastPath);

    dialog.setAcceptMode(QFileDialog::AcceptOpen);

    if (multiple) {
        dialog.setFileMode(QFileDialog::ExistingFiles);
    } else {
        dialog.setFileMode(QFileDialog::ExistingFile);
    }

    QString testPath = "";
    QString pathToRemember = "";
    
    if (dialog.exec()) {
        names = dialog.selectedFiles();
        
        if (!multiple && !names.empty()) {
            testPath = *names.begin();
            QFileInfo fi(testPath);
        
            if (!fi.exists()) {
                QMessageBox::critical(nullptr, tr("File does not exist"),
                                      tr("<b>File not found</b><p>File \"%1\" does not exist").arg(testPath));
            
            } else if (!fi.isReadable()) {
            
                QMessageBox::critical(nullptr, tr("File is not readable"),
                                      tr("<b>File is not readable</b><p>File \"%1\" can not be read").arg(testPath));
            
            } else if (fi.isDir()) {
            
                QMessageBox::critical(nullptr, tr("Directory selected"),
                                      tr("<b>Directory selected</b><p>File \"%1\" is a directory").arg(testPath));

            } else if (!fi.isFile()) {
            
                QMessageBox::critical(nullptr, tr("Non-file selected"),
                                      tr("<b>Not a file</b><p>Path \"%1\" is not a file").arg(testPath));
            
            } else if (fi.size() == 0) {
            
                QMessageBox::critical(nullptr, tr("File is empty"),
                                      tr("<b>File is empty</b><p>File \"%1\" is empty").arg(testPath));

            } else {
                pathToRemember = testPath;
            }
        }
    }

    if (pathToRemember != "") {
        settings.setValue(settingsKeyStub + "path",
                          QFileInfo(pathToRemember)
                          .absoluteDir()
                          .canonicalPath());
    }
    
    return names;
}

QString
InteractiveFileFinder::getSaveFileName(FileType type, 
                                       QString fallbackLocation)
{
    QString settingsKeyStub;
    QString lastPath = fallbackLocation;
    
    QString title = tr("Select file");
    QString filter = tr("All files (*.*)");

    switch (type) {

    case SessionFile:
        settingsKeyStub = "savesession";
        title = tr("Select a session file");
        filter = tr("%1 session files (*.%2)\nAll files (*.*)")
            .arg(QApplication::applicationName())
            .arg(m_sessionExtension);
        break;

    case AudioFile:
        settingsKeyStub = "saveaudio";
        title = "Select an audio file";
        title = tr("Select a file to export to");
        filter = tr("WAV audio files (*.wav)\nAll files (*.*)");
        break;

    case LayerFile:
        settingsKeyStub = "savelayer";
        title = tr("Select a file to export to");
        filter = tr("Sonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nRDF/Turtle files (%1)\nMIDI files (*.mid)\nText files (*.txt)\nAll files (*.*)")
            .arg(RDFExporter::getSupportedExtensions());
        break;

    case LayerFileNoMidi:
        settingsKeyStub = "savelayer";
        title = tr("Select a file to export to");
        filter = tr("Sonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nRDF/Turtle files (%1)\nText files (*.txt)\nAll files (*.*)")
            .arg(RDFExporter::getSupportedExtensions());
        break;

    case LayerFileNonSV:
        settingsKeyStub = "savelayer";
        title = tr("Select a file to export to");
        filter = tr("Comma-separated data files (*.csv)\nSonic Visualiser Layer XML files (*.svl)\nRDF/Turtle files (%1)\nMIDI files (*.mid)\nText files (*.txt)\nAll files (*.*)")
            .arg(RDFExporter::getSupportedExtensions());
        break;

    case LayerFileNoMidiNonSV:
        settingsKeyStub = "savelayer";
        title = tr("Select a file to export to");
        filter = tr("Comma-separated data files (*.csv)\nSonic Visualiser Layer XML files (*.svl)\nRDF/Turtle files (%1)\nText files (*.txt)\nAll files (*.*)")
            .arg(RDFExporter::getSupportedExtensions());
        break;

    case SessionOrAudioFile:
        SVCERR << "ERROR: Internal error: InteractiveFileFinder::getSaveFileName: SessionOrAudioFile cannot be used here" << endl;
        abort();

    case ImageFile:
        settingsKeyStub = "saveimage";
        title = tr("Select a file to export to");
        filter = tr("Portable Network Graphics files (*.png)\nAll files (*.*)");
        break;

    case SVGFile:
        settingsKeyStub = "savesvg";
        title = tr("Select a file to export to");
        filter = tr("Scalable Vector Graphics files (*.svg)\nAll files (*.*)");
        break;

    case CSVFile:
        settingsKeyStub = "savelayer";
        title = tr("Select a file to export to");
        filter = tr("Comma-separated data files (*.csv)\nText files (*.txt)\nAll files (*.*)");
        break;

    case AnyFile:
        SVCERR << "ERROR: Internal error: InteractiveFileFinder::getSaveFileName: AnyFile cannot be used here" << endl;
        abort();
    };

    if (lastPath == "") {
        std::string home;
        if (getEnvUtf8("HOME", home)) {
            lastPath = QString::fromStdString(home);
        } else {
            lastPath = ".";
        }
    } else if (QFileInfo(lastPath).isDir()) {
        lastPath = QFileInfo(lastPath).canonicalPath();
    } else {
        lastPath = QFileInfo(lastPath).absoluteDir().canonicalPath();
    }

    QSettings settings;
    settings.beginGroup("FileFinder");
    lastPath = settings.value(settingsKeyStub + "path", lastPath).toString();

    QString path = "";

    // Use our own QFileDialog instead of static functions, as we may
    // need to adjust the file extension based on the selected filter

    QFileDialog dialog(m_parent);

    QStringList filters = filter.split('\n');

    dialog.setNameFilters(filters);
    dialog.setWindowTitle(title);
    dialog.setDirectory(lastPath);
    dialog.setAcceptMode(QFileDialog::AcceptSave);
    dialog.setFileMode(QFileDialog::AnyFile);
    dialog.setOption(QFileDialog::DontConfirmOverwrite, true); // we'll do that
    
    QString defaultSuffix;
    if (type == SessionFile) {
        defaultSuffix = m_sessionExtension;
    } else if (type == AudioFile) {
        defaultSuffix = "wav";
    } else if (type == ImageFile) {
        defaultSuffix = "png";
    } else if (type == SVGFile) {
        defaultSuffix = "svg";
    } else if (type == CSVFile) {
        defaultSuffix = "csv";
    }

    defaultSuffix = 
        settings.value(settingsKeyStub + "suffix", defaultSuffix).toString();

    dialog.setDefaultSuffix(defaultSuffix);

    foreach (QString f, filters) {
        if (f.contains("." + defaultSuffix)) {
            dialog.selectNameFilter(f);
        }
    }

    bool good = false;

    while (!good) {

        path = "";
        
        if (!dialog.exec()) break;
        
        QStringList files = dialog.selectedFiles();
        if (files.empty()) break;
        path = *files.begin();
        
        QFileInfo fi(path);

        SVCERR << "type = " << type << ", suffix = " << fi.suffix() << endl;
        
        if ((type == LayerFile || type == LayerFileNoMidi || 
             type == LayerFileNonSV || type == LayerFileNoMidiNonSV)
            && fi.suffix() == "") {
            QString expectedExtension;
            QString selectedFilter = dialog.selectedNameFilter();
            if (selectedFilter.contains(".svl")) {
                expectedExtension = "svl";
            } else if (selectedFilter.contains(".txt")) {
                expectedExtension = "txt";
            } else if (selectedFilter.contains(".csv")) {
                expectedExtension = "csv";
            } else if (selectedFilter.contains(".mid")) {
                expectedExtension = "mid";
            } else if (selectedFilter.contains(".ttl")) {
                expectedExtension = "ttl";
            }
            SVCERR << "expected extension = " << expectedExtension << endl;
            if (expectedExtension != "") {
                path = QString("%1.%2").arg(path).arg(expectedExtension);
                fi = QFileInfo(path);
            }
        }
        
        if (fi.isDir()) {
            QMessageBox::critical(nullptr, tr("Directory selected"),
                                  tr("<b>Directory selected</b><p>File \"%1\" is a directory").arg(path));
            continue;
        }
        
        if (fi.exists()) {
            if (QMessageBox::question(nullptr, tr("File exists"),
                                      tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
                                      QMessageBox::Ok,
                                      QMessageBox::Cancel) != QMessageBox::Ok) {
                continue;
            }
        }
        
        good = true;
    }
        
    if (path != "") {
        settings.setValue(settingsKeyStub + "path",
                          QFileInfo(path).absoluteDir().canonicalPath());
        settings.setValue(settingsKeyStub + "suffix",
                          QFileInfo(path).suffix());
    }
    
    return path;
}

void
InteractiveFileFinder::registerLastOpenedFilePath(FileType type, QString path)
{
    QString settingsKeyStub;

    switch (type) {
    case SessionFile:
        settingsKeyStub = "session";
        break;

    case AudioFile:
        settingsKeyStub = "audio";
        break;

    case LayerFile:
        settingsKeyStub = "layer";
        break;

    case LayerFileNoMidi:
        settingsKeyStub = "layer";
        break;

    case LayerFileNonSV:
        settingsKeyStub = "layer";
        break;

    case LayerFileNoMidiNonSV:
        settingsKeyStub = "layer";
        break;

    case SessionOrAudioFile:
        settingsKeyStub = "last";
        break;

    case ImageFile:
        settingsKeyStub = "image";
        break;

    case SVGFile:
        settingsKeyStub = "svg";
        break;

    case CSVFile:
        settingsKeyStub = "layer";
        break;

    case AnyFile:
        settingsKeyStub = "last";
        break;
    }

    if (path != "") {
        QSettings settings;
        settings.beginGroup("FileFinder");
        path = QFileInfo(path).absoluteDir().canonicalPath();
        QString suffix = QFileInfo(path).suffix();
        settings.setValue(settingsKeyStub + "path", path);
        settings.setValue(settingsKeyStub + "suffix", suffix);
        settings.setValue("lastpath", path);
    }
}
    
QString
InteractiveFileFinder::find(FileType type, QString location, QString lastKnownLocation)
{
    if (FileSource::canHandleScheme(location)) {
        if (FileSource(location).isAvailable()) {
            SVDEBUG << "InteractiveFileFinder::find: ok, it's available... returning" << endl;
            return location;
        }
    }

    if (QFileInfo(location).exists()) return location;

    QString foundAt = "";

    if ((foundAt = findRelative(location, lastKnownLocation)) != "") {
        return foundAt;
    }

    if ((foundAt = findRelative(location, m_lastLocatedLocation)) != "") {
        return foundAt;
    }

    return locateInteractive(type, location);
}

QString
InteractiveFileFinder::findRelative(QString location, QString relativeTo)
{
    if (relativeTo == "") return "";

    SVDEBUG << "Looking for \"" << location << "\" next to \""
              << relativeTo << "\"..." << endl;

    QString fileName;
    QString resolved;

    if (FileSource::isRemote(location)) {
        fileName = QUrl(location).path().section('/', -1, -1,
                                                 QString::SectionSkipEmpty);
    } else {
        if (QUrl(location).scheme() == "file") {
            location = QUrl(location).toLocalFile();
        }
        fileName = QFileInfo(location).fileName();
    }

    if (FileSource::isRemote(relativeTo)) {
        resolved = QUrl(relativeTo).resolved(fileName).toString();
        if (!FileSource(resolved).isAvailable()) resolved = "";
        SVCERR << "resolved: " << resolved << endl;
    } else {
        if (QUrl(relativeTo).scheme() == "file") {
            relativeTo = QUrl(relativeTo).toLocalFile();
        }
        resolved = QFileInfo(relativeTo).dir().filePath(fileName);
        if (!QFileInfo(resolved).exists() ||
            !QFileInfo(resolved).isFile() ||
            !QFileInfo(resolved).isReadable()) {
            resolved = "";
        }
    }
            
    return resolved;
}

QString
InteractiveFileFinder::locateInteractive(FileType type, QString thing)
{
    QString question;
    if (type == AudioFile) {
        question = tr("<b>File not found</b><p>Audio file \"%1\" could not be opened.\nDo you want to locate it?");
    } else {
        question = tr("<b>File not found</b><p>File \"%1\" could not be opened.\nDo you want to locate it?");
    }

    QString path = "";
    bool done = false;

    while (!done) {

        QMessageBox mb(QMessageBox::Question,
                       tr("Failed to open file"),
                       question.arg(thing),
                       QMessageBox::NoButton,
                       nullptr);

        auto locateButton =
            mb.addButton(tr("Locate file..."), QMessageBox::ActionRole);
        auto urlButton =
            mb.addButton(tr("Use URL..."), QMessageBox::ActionRole);
        auto nopeButton =
            mb.addButton(tr("Cancel"), QMessageBox::RejectRole);

        mb.setDefaultButton(locateButton);
        mb.setEscapeButton(nopeButton);

        mb.exec();

        auto clicked = mb.clickedButton();
        
        if (clicked == locateButton) {

            if (QFileInfo(thing).dir().exists()) {
                path = QFileInfo(thing).dir().canonicalPath();
            }
            
            path = getOpenFileName(type, path);
            done = (path != "");

        } else if (clicked == urlButton) {

            bool ok = false;
            path = QInputDialog::getText
                (nullptr, tr("Use URL"),
                 tr("Please enter the URL to use for this file:"),
                 QLineEdit::Normal, "", &ok);

            if (ok && path != "") {
                if (FileSource(path).isAvailable()) {
                    done = true;
                } else {
                    QMessageBox::critical
                        (nullptr, tr("Failed to open location"),
                         tr("<b>Failed to open location</b><p>URL \"%1\" could not be opened").arg(path));
                    path = "";
                }
            }

        } else { // Cancel, either via button or clicked == nullptr meaning Esc

            path = "";
            done = true;
        }
    }

    if (path != "") m_lastLocatedLocation = path;
    return path;
}


} // end namespace sv