File: FileInfoPlugin.cpp

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (127 lines) | stat: -rw-r--r-- 4,800 bytes parent folder | download
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
/***************************************************************************
     FileInfoPlugin.cpp  -  plugin for editing file properties
                             -------------------
    begin                : Fri Jul 19 2002
    copyright            : (C) 2002 by Thomas Eschenbacher
    email                : Thomas.Eschenbacher@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "config.h"

#include <errno.h>
#include <new>

#include <QPointer>

#include "libkwave/MessageBox.h"
#include "libkwave/PluginManager.h"
#include "libkwave/SignalManager.h"
#include "libkwave/String.h"

#include "FileInfoDialog.h"
#include "FileInfoPlugin.h"

KWAVE_PLUGIN(fileinfo, FileInfoPlugin)

//***************************************************************************
Kwave::FileInfoPlugin::FileInfoPlugin(QObject *parent,
                                      const QVariantList &args)
    :Kwave::Plugin(parent, args)
{
}

//***************************************************************************
Kwave::FileInfoPlugin::~FileInfoPlugin()
{
}

//***************************************************************************
QStringList *Kwave::FileInfoPlugin::setup(QStringList &)
{
    Kwave::FileInfo oldInfo(signalManager().metaData());

    // create the setup dialog
    QPointer<Kwave::FileInfoDialog> dialog =
        new(std::nothrow) Kwave::FileInfoDialog(parentWidget(), oldInfo);
    Q_ASSERT(dialog);
    if (!dialog) return nullptr;

    QStringList *list = new(std::nothrow) QStringList();
    Q_ASSERT(list);
    if (list && dialog->exec() && dialog) {
        // user has pressed "OK" -> apply the new properties
        apply(dialog->info());
    } else {
        // user pressed "Cancel"
        delete list;
        list = nullptr;
    }

    delete dialog;
    return list;
}

//***************************************************************************
void Kwave::FileInfoPlugin::apply(Kwave::FileInfo &new_info)
{
    Kwave::FileInfo old_info(signalManager().metaData());
    if (old_info == new_info) return; // nothing to do

    /* sample rate */
    if (!qFuzzyCompare(old_info.rate(), new_info.rate())) {

        // sample rate changed -> only change rate or resample ?
        double new_rate = new_info.rate();
        int res = Kwave::MessageBox::questionYesNoCancel(parentWidget(),
            i18n("You have changed the sample rate. Do you want to convert "
                 "the whole file to the new sample rate or do "
                 "you only want to set the rate information in order "
                 "to repair a damaged file? Note: changing only the sample "
                 "rate can cause \"Mickey Mouse\" effects."),
            QString(),
            i18n("&Convert"),
            i18n("&Set Rate"));
        if (res == KMessageBox::PrimaryAction) {
            // Yes -> resample

            // take over all properties except the new sample rate, this will
            // be detected and changed in the sample rate plugin
            new_info.setRate(old_info.rate());
            if (new_info != old_info) {
                signalManager().setFileInfo(new_info, true);
            } // else: nothing except sample rate changed

            // NOTE: this command could be executed asynchronously, thus
            //       we cannot change the sample rate afterwards
            emitCommand(_("plugin:execute(samplerate,%1,all)").arg(new_rate));
            return;
        } else if (res == KMessageBox::SecondaryAction) {
            // No -> only change the rate in the file info
            new_info.setRate(new_rate);
        } else {
            // canceled -> use old sample rate
            new_info.setRate(old_info.rate());
        }
    }

    // just copy all other properties
    if (new_info != old_info) {
        signalManager().setFileInfo(new_info, true);
    }
}

//***************************************************************************
#include "FileInfoPlugin.moc"
//***************************************************************************
//***************************************************************************

#include "moc_FileInfoPlugin.cpp"