File: MP3EncoderSettings.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 (156 lines) | stat: -rw-r--r-- 6,772 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
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
/***************************************************************************
 MP3EncoderSettings.cpp  -  settings for configuring the MP3 encoer
                            -------------------
    begin                : Sun Jun 03 2012
    copyright            : (C) 2012 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 <QDir>
#include <QLatin1Char>

#include <KConfigGroup>
#include <KSharedConfig>

#include "libkwave/String.h"

#include "MP3EncoderSettings.h"

using namespace Qt::StringLiterals;

/** name of the section in the config file */
#define MP3_ENCODER_CONFIG_GROUP u"MP3_Encoder_Settings"_s

/**
 * load from config file
 * @param field receives the value
 * @param key identifier in the config section
 */
#define LOAD(field, key) field = \
    cfg.readEntry(key, field)

/**
 * save to config file
 * @param field value to save
 * @param key identifier in the config section
 */
#define SAVE(field, key) \
    cfg.writeEntry(key, sanitized(field))

/***************************************************************************/
/**
 * Makes sure that the string does only contain allowed characters,
 * avoid misuse of the command line parameters
 * @param in potentially unsafe string
 * @return string with only digits, numbers and '-', '=' and '%'
 */
static QString sanitized(const QString &in)
{
    QString out = _("");
    QString str = in.simplified();

    for (int i = 0; i < str.length(); i++) {
        QChar c = str.at(i);
        if ( c.isLetterOrNumber() || c.isSpace() ||
             (c == QLatin1Char('-')) || (c == QLatin1Char('%')) ||
             (c == QLatin1Char('=')) || (c == QLatin1Char('.')) ||
             (c == QLatin1Char('[')) || (c == QLatin1Char(']')) ||
             (c == QDir::separator()) )
        {
            out += c;
        }
    }
    return out;
}

/***************************************************************************/
void Kwave::MP3EncoderSettings::load()
{
    KConfigGroup cfg = KSharedConfig::openConfig()->group(
        MP3_ENCODER_CONFIG_GROUP);

    LOAD(m_name,                           "name_______________________");
    LOAD(m_path,                           "path_______________________");

    LOAD(m_input.m_raw_format,             "input_raw_format___________");
    LOAD(m_input.m_byte_order,             "input_byte_order___________");
    LOAD(m_input.m_signed,                 "input_signed_______________");

    LOAD(m_format.m_sample_rate,           "format_sample_rate_________");
    LOAD(m_format.m_bits_per_sample,       "format_bits_per_sample_____");
    LOAD(m_format.m_channels.m_mono,       "format_channels_mono_______");
    LOAD(m_format.m_channels.m_stereo,     "format_channels_stereo_____");

    LOAD(m_quality.m_bitrate.m_avg,        "quality_bitrate_avg________");
    LOAD(m_quality.m_bitrate.m_min,        "quality_bitrate_min________");
    LOAD(m_quality.m_bitrate.m_max,        "quality_bitrate_max________");

    LOAD(m_encoding.m_emphasis.m_none,     "encoding_emphasis_none_____");
    LOAD(m_encoding.m_emphasis.m_50_15ms,  "encoding_emphasis_50_15ms__");
    LOAD(m_encoding.m_emphasis.m_ccit_j17, "encoding_emphasis_ccit_j17_");

    LOAD(m_encoding.m_noise_shaping,       "encoding_noise_shaping_____");
    LOAD(m_encoding.m_compatibility,       "encoding_compatibility_____");

    LOAD(m_flags.m_copyright,              "flags_copyright____________");
    LOAD(m_flags.m_original,               "flags_original_____________");
    LOAD(m_flags.m_protect,                "flags_protect______________");
    LOAD(m_flags.m_prepend,                "flags_prepend______________");
    LOAD(m_flags.m_append,                 "flags_append_______________");

    LOAD(m_info.m_help,                    "info_help__________________");
    LOAD(m_info.m_version,                 "info_version_______________");
}

/***************************************************************************/
void Kwave::MP3EncoderSettings::save()
{
    KConfigGroup cfg = KSharedConfig::openConfig()->group(
        MP3_ENCODER_CONFIG_GROUP);

    SAVE(m_name,                           "name_______________________");
    SAVE(m_path,                           "path_______________________");

    SAVE(m_input.m_raw_format,             "input_raw_format___________");
    SAVE(m_input.m_byte_order,             "input_byte_order___________");
    SAVE(m_input.m_signed,                 "input_signed_______________");

    SAVE(m_format.m_sample_rate,           "format_sample_rate_________");
    SAVE(m_format.m_bits_per_sample,       "format_bits_per_sample_____");
    SAVE(m_format.m_channels.m_mono,       "format_channels_mono_______");
    SAVE(m_format.m_channels.m_stereo,     "format_channels_stereo_____");

    SAVE(m_quality.m_bitrate.m_avg,        "quality_bitrate_avg________");
    SAVE(m_quality.m_bitrate.m_min,        "quality_bitrate_min________");
    SAVE(m_quality.m_bitrate.m_max,        "quality_bitrate_max________");

    SAVE(m_encoding.m_emphasis.m_none,     "encoding_emphasis_none_____");
    SAVE(m_encoding.m_emphasis.m_50_15ms,  "encoding_emphasis_50_15ms__");
    SAVE(m_encoding.m_emphasis.m_ccit_j17, "encoding_emphasis_ccit_j17_");

    SAVE(m_encoding.m_noise_shaping,       "encoding_noise_shaping_____");
    SAVE(m_encoding.m_compatibility,       "encoding_compatibility_____");

    SAVE(m_flags.m_copyright,              "flags_copyright____________");
    SAVE(m_flags.m_original,               "flags_original_____________");
    SAVE(m_flags.m_protect,                "flags_protect______________");
    SAVE(m_flags.m_prepend,                "flags_prepend______________");
    SAVE(m_flags.m_append,                 "flags_append_______________");

    SAVE(m_info.m_help,                    "info_help__________________");
    SAVE(m_info.m_version,                 "info_version_______________");
}

/***************************************************************************/
/***************************************************************************/