summaryrefslogtreecommitdiffstats
path: root/src/configgeneralpage.cpp
blob: 337b0990e8b2093ca8333b9c0f35568e0496c848 (plain)
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

#include "configgeneralpage.h"

#include "config.h"

#include <klocale.h>
#include <kcombobox.h>
#include <knuminput.h>
#include <kiconloader.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kfiledialog.h>

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqcheckbox.h>
#include <tqtooltip.h>
#include <tqdir.h>
#include <tqregexp.h>

// ### soundkonverter 0.4: add an option to use vfat save names when the output device is vfat

ConfigGeneralPage::ConfigGeneralPage( Config* _config, TQWidget *tqparent, const char *name )
    : ConfigPageBase( tqparent, name )
{
    config = _config;

    // create an icon loader object for loading icons
    KIconLoader* iconLoader = new KIconLoader();

    TQVBoxLayout* box = new TQVBoxLayout( tqparent, 0, 6 );

    TQHBoxLayout* startTabBox = new TQHBoxLayout( box, 6 );
    TQLabel* lStartTab = new TQLabel( i18n("Start in Mode")+":", tqparent, "lStartTab" );
    startTabBox->addWidget( lStartTab );
    cStartTab = new KComboBox( tqparent, "cStartTab" );
    cStartTab->insertItem( i18n("Last used") );
    cStartTab->insertItem( i18n("Simple") );
    cStartTab->insertItem( i18n("Detailed") );
    cStartTab->setCurrentItem( config->data.general.startTab );
    startTabBox->addWidget( cStartTab );
    connect( cStartTab, TQT_SIGNAL(activated(int)),
               this, TQT_SLOT(cfgChanged())
             );

    box->addSpacing( 5 );

    TQHBoxLayout* defaultProfileBox = new TQHBoxLayout( box, 6 );
    TQLabel* lDefaultProfile = new TQLabel( i18n("Default profile")+":", tqparent, "lDefaultProfile" );
    defaultProfileBox->addWidget( lDefaultProfile );
    cDefaultProfile = new KComboBox( tqparent, "cDefaultProfile" );
    sDefaultProfile += i18n("Very low");
    sDefaultProfile += i18n("Low");
    sDefaultProfile += i18n("Medium");
    sDefaultProfile += i18n("High");
    sDefaultProfile += i18n("Very high");
    sDefaultProfile += i18n("Lossless");
    sDefaultProfile += i18n("Hybrid");
    sDefaultProfile += config->getAllProfiles();
    sDefaultProfile.remove( i18n("Last used") );
    sDefaultProfile.remove( "Last used" );
    sDefaultProfile.prepend( i18n("Last used") );
    cDefaultProfile->insertStringList( sDefaultProfile );
    cDefaultProfile->setCurrentItem( profileIndex(config->data.general.defaultProfile) );
    defaultProfileBox->addWidget( cDefaultProfile );
    connect( cDefaultProfile, TQT_SIGNAL(activated(int)),
               this, TQT_SLOT(profileChanged())
             );
    connect( cDefaultProfile, TQT_SIGNAL(activated(int)),
               this, TQT_SLOT(cfgChanged())
             );
    TQLabel* lDefaultFormat = new TQLabel( i18n("Default format")+":", tqparent, "lDefaultFormat" );
    defaultProfileBox->addWidget( lDefaultFormat );
    cDefaultFormat = new KComboBox( tqparent, "cDefaultFormat" );
    defaultProfileBox->addWidget( cDefaultFormat );
    connect( cDefaultFormat, TQT_SIGNAL(activated(int)),
               this, TQT_SLOT(cfgChanged())
             );
    profileChanged();

    box->addSpacing( 5 );

/*    TQHBoxLayout* defaultDirBox = new TQHBoxLayout( box, 6 );
    TQLabel* lDefaultDir = new TQLabel( i18n("Default output directory")+":", tqparent, "lDefaultDir" );
    defaultDirBox->addWidget( lDefaultDir );
    lDir = new KLineEdit( tqparent, "lDir" );
    lDir->setText( config->data.general.defaultOutputDirectory );
    TQToolTip::add( lDir, i18n("<p>The following strings are space holders, that will be replaced by the information in the meta data:</p><p>%a - Artist<br>%b - Album<br>%c - Comment<br>%d - Disc number<br>%g - Genre<br>%n - Track number<br>%p - Composer<br>%t - Title<br>%y - Year<br>%f - Original file name<p>") );
    defaultDirBox->addWidget( lDir );
    connect( lDir, TQT_SIGNAL(textChanged(const TQString&)),
               this, TQT_SLOT(cfgChanged())
             );*/
    /*pDirInfo = new KPushButton( iconLoader->loadIcon("messagebox_info",KIcon::Small), "", tqparent, "pDirInfo" );
    TQToolTip::add( pDirInfo, i18n("Information about the wildcards.") );
    defaultDirBox->addWidget( pDirInfo );
    connect( pDirInfo, TQT_SIGNAL(clicked()),
               this, TQT_SLOT(dirInfo())
             );*/
//     pDirSelect = new KPushButton( iconLoader->loadIcon("folder",KIcon::Small), "", tqparent, "pDirSelect" );
//     TQToolTip::add( pDirSelect, i18n("Choose an output directory") );
//     defaultDirBox->addWidget( pDirSelect );
//     connect( pDirSelect, TQT_SIGNAL(clicked()),
//                this, TQT_SLOT(selectDir())
//              );

    TQHBoxLayout* priorityBox = new TQHBoxLayout( box, 6 );
    TQLabel* lPriority = new TQLabel( i18n("Process priority of the backends")+":", tqparent, "lPriority" );
    priorityBox->addWidget( lPriority );
    cPriority = new KComboBox( tqparent, "cPriority" );
    sPriority += i18n("Normal");
    sPriority += i18n("Low");
    cPriority->insertStringList( sPriority );
    cPriority->setCurrentItem( config->data.general.priority / 10 ); // NOTE that just works for 'normal' and 'low'
    priorityBox->addWidget( cPriority );
    connect( cPriority, TQT_SIGNAL(activated(int)),
               this, TQT_SLOT(cfgChanged())
             );

    box->addSpacing( 5 );

    TQHBoxLayout* useVFATNamesBox = new TQHBoxLayout( box, 6 );
    cUseVFATNames = new TQCheckBox( i18n("Use FAT compatible output file names"), tqparent, "cUseVFATNames" );
    TQToolTip::add( cUseVFATNames, i18n("Replaces some special characters like \'?\' by \'_\'.") );
    cUseVFATNames->setChecked( config->data.general.useVFATNames );
    useVFATNamesBox->addWidget( cUseVFATNames );
    connect( cUseVFATNames, TQT_SIGNAL(toggled(bool)),
               this, TQT_SLOT(cfgChanged())
             );

    box->addSpacing( 5 );

    TQHBoxLayout* conflictHandlingBox = new TQHBoxLayout( box, 6 );
    TQLabel* lConflictHandling = new TQLabel( i18n("Conflict handling")+":", tqparent, "lConflictHandling" );
    conflictHandlingBox->addWidget( lConflictHandling );
    cConflictHandling = new KComboBox( tqparent, "cConflictHandling" );
    TQToolTip::add( cConflictHandling, i18n("Do that if the output file already exists") );
    sConflictHandling += i18n("Generate new file name");
    sConflictHandling += i18n("Skip file");
    cConflictHandling->insertStringList( sConflictHandling );
    cConflictHandling->setCurrentItem( config->data.general.conflictHandling );
    conflictHandlingBox->addWidget( cConflictHandling );
    connect( cConflictHandling, TQT_SIGNAL(activated(int)),
             this, TQT_SLOT(cfgChanged())
           );

    box->addSpacing( 5 );

    TQHBoxLayout* numFilesBox = new TQHBoxLayout( box, 6 );
    TQLabel* lNumFiles = new TQLabel( i18n("Number of files to convert at once")+":", tqparent, "lNumFiles" );
    numFilesBox->addWidget( lNumFiles );
    iNumFiles = new KIntSpinBox( 1, 100, 1, config->data.general.numFiles, 10, tqparent, "iNumFiles" );
    numFilesBox->addWidget( iNumFiles );
    connect( iNumFiles, TQT_SIGNAL(valueChanged(int)),
               this, TQT_SLOT(cfgChanged())
             );

    box->addSpacing( 5 );

    TQHBoxLayout* updateDelayBox = new TQHBoxLayout( box, 6 );
    TQLabel* lUpdateDelay = new TQLabel( i18n("tqStatus update delay (time in msec.)")+":", tqparent, "lUpdateDelay" );
    updateDelayBox->addWidget( lUpdateDelay );
    iUpdateDelay = new KIntSpinBox( 100, 5000, 100, config->data.general.updateDelay, 10, tqparent, "iUpdateDelay" );
    TQToolTip::add( iUpdateDelay, i18n("Update the progress bar in this interval (time in milliseconds)") );
    updateDelayBox->addWidget( iUpdateDelay );
    connect( iUpdateDelay, TQT_SIGNAL(valueChanged(int)),
               this, TQT_SLOT(cfgChanged())
             );

    box->addSpacing( 5 );

    TQHBoxLayout* askForNewOptionsBox = new TQHBoxLayout( box, 6 );
    cAskForNewOptions = new TQCheckBox( i18n("Ask for new options, when adding files from external program"), tqparent, "cAskForNewOptions" );
    TQToolTip::add( cAskForNewOptions, i18n("If you open a file with soundKonverter and soundKonverter is already running,\nyou can either be asked to define new converting options\nor the current settings from the soundKonverter main window are used.") );
    cAskForNewOptions->setChecked( config->data.general.askForNewOptions );
    askForNewOptionsBox->addWidget( cAskForNewOptions );
    connect( cAskForNewOptions, TQT_SIGNAL(toggled(bool)),
               this, TQT_SLOT(cfgChanged())
             );

    box->addSpacing( 5 );

    TQHBoxLayout* executeUserScriptBox = new TQHBoxLayout( box, 6 );
    cExecuteUserScript = new TQCheckBox( i18n("Execute user script (for advanced users)"), tqparent, "cAskForNewOptions" );
    TQToolTip::add( cExecuteUserScript, i18n("Executes a script after every finished conversion. Have a look at $KDEDIR/soundkonverter/userscript.sh") );
    cExecuteUserScript->setChecked( config->data.general.executeUserScript );
    executeUserScriptBox->addWidget( cExecuteUserScript );
    connect( cExecuteUserScript, TQT_SIGNAL(toggled(bool)),
             this, TQT_SLOT(cfgChanged())
           );

    box->addStretch();

    // delete the icon loader object
    delete iconLoader;
}

ConfigGeneralPage::~ConfigGeneralPage()
{}

void ConfigGeneralPage::resetDefaults()
{
    cStartTab->setCurrentItem( 0 );
    cDefaultProfile->setCurrentItem( 0 );
    cDefaultFormat->setCurrentItem( 0 );
//     lDir->setText( TQDir::homeDirPath() + "/soundKonverter/%b/%d - %n - %a - %t" );
    cPriority->setCurrentItem( 1 );
    cUseVFATNames->setChecked( true );
    cConflictHandling->setCurrentItem( 0 );
    iNumFiles->setValue( 3 );
    iUpdateDelay->setValue( 500 );
    cAskForNewOptions->setChecked( true );
    cExecuteUserScript->setChecked( false );

    cfgChanged();
}

void ConfigGeneralPage::saveSettings()
{
    config->data.general.startTab = cStartTab->currentItem();
    config->data.general.defaultProfile = cDefaultProfile->currentText();
    config->data.general.defaultFormat = cDefaultFormat->currentText();
//     config->data.general.defaultOutputDirectory = lDir->text();
    config->data.general.priority = cPriority->currentItem() * 10; // NOTE that just works for 'normal' and 'low'
    config->data.general.useVFATNames = cUseVFATNames->isChecked();
    config->data.general.conflictHandling = cConflictHandling->currentItem();
    config->data.general.numFiles = iNumFiles->value();
    config->data.general.updateDelay = iUpdateDelay->value();
    config->data.general.askForNewOptions = cAskForNewOptions->isChecked();
    config->data.general.executeUserScript = cExecuteUserScript->isChecked();
}

int ConfigGeneralPage::profileIndex( const TQString &string )
{
    return sDefaultProfile.findIndex( string );
}

int ConfigGeneralPage::formatIndex( const TQString &string )
{
    return sDefaultFormat.findIndex( string );
}

// void ConfigGeneralPage::selectDir()
// {
//     TQString startDir = lDir->text();
//     int i = startDir.find( TQRegExp("%[aAbBcCdDgGnNpPtTyY]{1,1}") );
//     if( i != -1 ) {
//         i = startDir.findRev( "/", i );
//         startDir = startDir.left( i );
//     }
// 
//     TQString directory = KFileDialog::getExistingDirectory( startDir, 0, i18n("Choose an output directory") );
//     if( !directory.isEmpty() ) {
//         TQString dir = lDir->text();
//         i = dir.find( TQRegExp("%[aAbBcCdDgGnNpPtTyY]{1,1}") );
//         if( i != -1 ) {
//             i = dir.findRev( "/", i );
//             lDir->setText( directory + dir.mid(i) );
//         }
//         else {
//             lDir->setText( directory );
//         }
//     }
// }

void ConfigGeneralPage::profileChanged()
{
    TQString last;

    if( cDefaultProfile->currentText() == i18n("Last used") ) {
        last = cDefaultFormat->currentText();
        if( last.isEmpty() ) last = config->data.general.defaultFormat;
        cDefaultFormat->clear();
        sDefaultFormat = i18n("Last used");
        cDefaultFormat->insertStringList( sDefaultFormat );
        cDefaultFormat->setCurrentItem( formatIndex(last) );
        return;
    }

    ConversionOptions options = config->getProfile( cDefaultProfile->currentText() );
    if( !options.encodingOptions.sFormat.isEmpty() ) {
        last = cDefaultFormat->currentText();
        cDefaultFormat->clear();
        sDefaultFormat = options.encodingOptions.sFormat;
        cDefaultFormat->insertStringList( sDefaultFormat );
        cDefaultFormat->setCurrentItem( formatIndex(last) );
        return;
    }

    if( cDefaultProfile->currentText() == i18n("Very low") ||
      cDefaultProfile->currentText() == i18n("Low") ||
      cDefaultProfile->currentText() == i18n("Medium") ||
      cDefaultProfile->currentText() == i18n("High") ||
      cDefaultProfile->currentText() == i18n("Very high") ) {
        last = cDefaultFormat->currentText();
        if( last.isEmpty() ) last = config->data.general.defaultFormat;
        cDefaultFormat->clear();
        sDefaultFormat = i18n("Last used");
        sDefaultFormat += config->allLossyEncodableFormats();
        cDefaultFormat->insertStringList( sDefaultFormat );
        cDefaultFormat->setCurrentItem( formatIndex(last) );
    }
    else if( cDefaultProfile->currentText() == i18n("Lossless") ) {
        last = cDefaultFormat->currentText();
        if( last.isEmpty() ) last = config->data.general.defaultFormat;
        cDefaultFormat->clear();
        sDefaultFormat = i18n("Last used");
        sDefaultFormat += config->allLosslessEncodableFormats();
        sDefaultFormat += "wav";
        cDefaultFormat->insertStringList( sDefaultFormat );
        cDefaultFormat->setCurrentItem( formatIndex(last) );
    }
    else if( cDefaultProfile->currentText() == i18n("Hybrid") ) {
        last = cDefaultFormat->currentText();
        if( last.isEmpty() ) last = config->data.general.defaultFormat;
        cDefaultFormat->clear();
        sDefaultFormat = i18n("Last used");
        sDefaultFormat += config->allHybridEncodableFormats();
        cDefaultFormat->insertStringList( sDefaultFormat );
        cDefaultFormat->setCurrentItem( formatIndex(last) );
    }
}