summaryrefslogtreecommitdiffstats
path: root/amarok/src/mediadevice/generic/genericmediadeviceconfigdialog.ui.h
blob: 43a0660380d95a243ea9d2abee5a6fcce0f627ff (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
324
/*
  (c) 2006 Roel Meeuws <r.j.meeuws+amarok@gmail.com>

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


/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** TQt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/


/// Configuration Dialog Extension slots

void
GenericMediaDeviceConfigDialog::addSupportedButtonClicked( int id )
{
    TQPopupMenu *unsupported = m_addSupportedButton->popup();
    TQComboBox *convert     = m_convertComboBox;
    TQListBox  *supported   = m_supportedListBox;

    TQString text = unsupported->text( id );
    if( text.startsWith( "&" ) )
        supported->insertItem( text.right( text.length() - 1 ) );
    else
        supported->insertItem( text );

    TQString temp = convert->currentText();
    convert->insertItem( unsupported->text( id ) );

    unsupported->removeItem( id );

    supported->sort();
    convert->listBox()->sort();

    convert->setCurrentText( temp );
}


void
GenericMediaDeviceConfigDialog::removeSupportedButtonClicked()
{
    TQStringList unsupported;

    TQComboBox *convert     = m_convertComboBox;
    TQListBox  *supported   = m_supportedListBox;

    for( uint i = 0; i < m_addSupportedButton->popup()->count(); i++ )
    {
        int id = m_addSupportedButton->popup()->idAt( i );
        unsupported.append( m_addSupportedButton->popup()->text( id ) );
    }

    for( uint i = 0; i < supported->count() ; /* nothing */)
    {
        TQListBoxItem *item = supported->item( i );

        if( item->isSelected() )
        {
            TQString temp;

            unsupported.append( item->text() );

            temp = convert->currentText();

            convert->setCurrentText( item->text() );
            convert->removeItem( convert->currentItem() );

            if( temp == item->text() )
                convert->setCurrentItem( 0 );
            else
                convert->setCurrentText( temp );

            item = 0;
            supported->removeItem( i );

            continue;
        }

        i++;
    }

    // at least support mp3 format.
    if( supported->count() <= 0 )
    {
        supported->insertItem( "mp3" );
        convert->insertItem( "mp3" );
        convert->setCurrentItem( 0 );
        unsupported.remove( "mp3" );
    }

    unsupported.sort();
    m_addSupportedButton->popup()->clear();
    for( TQStringList::Iterator it = unsupported.begin(); it != unsupported.end(); it++ )
    {
        m_addSupportedButton->popup()->insertItem( *it );
    }
}


void
GenericMediaDeviceConfigDialog::supportedListBoxDoubleClicked( TQListBoxItem* item )
{
    m_convertComboBox->setCurrentText( item->text() );
}




void
GenericMediaDeviceConfigDialog::updateConfigDialogLists( const TQStringList & supportedFileTypes )
{
    TQStringList allTypes;
    allTypes << "mp3" << "ogg" << "wma" << "mp4" << "aac" << "m4a" << "ac3";
    allTypes << "wav" << "flac" << "asf" << "asx" << "mpg" << "mp4v" << "mpeg";
    allTypes << "aa" << "3gp" << "mp2" << "ape" << "mpc";

    TQStringList unsupported;
    TQComboBox *convert      = m_convertComboBox;
    TQListBox  *supported    = m_supportedListBox;

    for( TQStringList::Iterator it = allTypes.begin(); it != allTypes.end(); it++ )
    {
        if( supportedFileTypes.contains( *it ) )
        {
            supported->insertItem( *it );
            convert->insertItem( *it );
        }
        else
        {
            unsupported.append( *it );
        }
    }

    supported->sort();
    unsupported.sort();

    m_addSupportedButton->popup()->clear();

    for( TQStringList::Iterator it = unsupported.begin(); it != unsupported.end(); it++ )
    {
        m_addSupportedButton->popup()->insertItem( *it );
    }
    convert->listBox()->sort();
    convert->setCurrentText( supportedFileTypes.first() );
}

TQString
GenericMediaDeviceConfigDialog::buildDestination( const TQString &format, const MetaBundle &mb )
{
    bool isCompilation = mb.compilation() > 0;
    TQMap<TQString, TQString> args;
    TQString artist = mb.artist();
    TQString albumartist = artist;
    if( isCompilation )
        albumartist = i18n( "Various Artists" );
    args["theartist"] = cleanPath( artist );
    args["thealbumartist"] = cleanPath( albumartist );
    if( m_ignoreTheCheck->isChecked() && artist.startsWith( "The " ) )
        CollectionView::instance()->manipulateThe( artist, true );
    artist = cleanPath( artist );
    if( m_ignoreTheCheck->isChecked() && albumartist.startsWith( "The " ) )
        CollectionView::instance()->manipulateThe( albumartist, true );

    albumartist = cleanPath( albumartist );
    for( int i = 0; i < MetaBundle::NUM_COLUMNS; i++ )
    {
        if( i == MetaBundle::Score || i == MetaBundle::PlayCount || i == MetaBundle::LastPlayed )
            continue;
        args[mb.exactColumnName( i ).lower()] = cleanPath( mb.prettyText( i ) );
    }
    args["artist"] = artist;
    args["albumartist"] = albumartist;
    args["initial"] = albumartist.mid( 0, 1 ).upper();
    args["filetype"] = mb.url().path().section( ".", -1 ).lower();
    TQString track;
    if ( mb.track() )
        track.sprintf( "%02d", mb.track() );
    args["track"] = track;

    Amarok::QStringx formatx( format );
    TQString result = m_device->mountPoint().append( formatx.namedOptArgs( args ) );
    TQString tail = result.mid( m_device->mountPoint().length() );
    if( !tail.startsWith( "/" ) )
        tail.prepend( "/" );

   return m_device->mountPoint() + tail.replace( TQRegExp( "/\\.*" ), "/" );
}

TQString GenericMediaDeviceConfigDialog::cleanPath( const TQString &component )
{
    TQString result = Amarok::cleanPath( component );

    if( m_asciiCheck->isChecked() )
        result = Amarok::asciiPath( result );

    result.simplifyWhiteSpace();
    if( m_spaceCheck->isChecked() )
        result.replace( TQRegExp( "\\s" ), "_" );
    if( m_device->m_actuallyVfat || m_vfatCheck->isChecked() )
        result = Amarok::vfatPath( result );

    result.replace( "/", "-" );

    return result;
}


void
GenericMediaDeviceConfigDialog::updatePreviewLabel()
{
    m_previewLabel->setText( buildDestination( m_songLocationBox->text(), *m_previewBundle ) );
}

void
GenericMediaDeviceConfigDialog::updatePreviewLabel( const TQString& format)
{
    m_previewLabel->setText( buildDestination( format , *m_previewBundle ) );
}

void
GenericMediaDeviceConfigDialog::setDevice( GenericMediaDevice* device )
{
    m_device = device;
    m_songLocationBox->setText( m_device->m_songLocation );
    m_podcastLocationBox->setText( m_device->m_podcastLocation );

    updatePreviewLabel( m_device->m_songLocation );

    updateConfigDialogLists( m_device->m_supportedFileTypes );
    m_asciiCheck->setChecked( m_device->m_asciiTextOnly );
    m_vfatCheck->setChecked( m_device->m_vfatTextOnly );
    m_spaceCheck->setChecked( m_device->m_spacesToUnderscores );
    m_ignoreTheCheck->setChecked( m_device->m_ignoreThePrefix );
}

TQString
GenericMediaDeviceConfigDialog::buildFormatTip()
{
    TQMap<TQString, TQString> args;
    for( int i = 0; i < MetaBundle::NUM_COLUMNS; i++ )
    {
        if( i == MetaBundle::Score || i == MetaBundle::PlayCount || i == MetaBundle::LastPlayed )
            continue;
        args[MetaBundle::exactColumnName( i ).lower()] = MetaBundle::prettyColumnName( i );
    }
    args["albumartist"] = i18n( "%1 or %2" ).tqarg( "Album Artist, The" , "The Album Artist" );
    args["thealbumartist"] = "The Album Artist";
    args["theartist"] = "The Artist";
    args["artist"] = i18n( "%1 or %2" ).tqarg( "Artist, The" , "The Artist" );
    args["initial"] = i18n( "Artist's Initial" );
    args["filetype"] = i18n( "File Extension of Source" );
    args["track"] = i18n( "Track Number" );

    TQString tooltip = i18n( "<h3>Custom Format String</h3>" );
    tooltip += i18n( "You can use the following tokens:" );
    tooltip += "<ul>";
    for( TQMap<TQString, TQString>::iterator it = args.begin();
            it != args.end();
            ++it )
    {
        tooltip += TQString( "<li>%1 - %2" ).tqarg( it.data(), "%" + it.key() );
    }
    tooltip += "</ul>";

    tooltip += i18n( "If you surround sections of text that contain a token with curly-braces, "
            "that section will be hidden if the token is empty." );

    return tooltip;
}

void
GenericMediaDeviceConfigDialog::init()
{
    m_previewBundle = new MetaBundle();
    m_previewBundle->setAlbum( AtomicString( "Some Album" ) );
    m_previewBundle->setArtist( AtomicString( "The One Artist" ) );
    m_previewBundle->setBitrate( 128 );
    m_previewBundle->setComment( AtomicString( "Some Comment" ) );
    m_previewBundle->setCompilation( 0 );
    m_previewBundle->setComposer( AtomicString( "The One Composer" ) );
    m_previewBundle->setDiscNumber( 1 );
    m_previewBundle->setFileType( 2 );
    m_previewBundle->setFilesize( 1003264 );
    m_previewBundle->setGenre( AtomicString( "Some Genre" ) );
    m_previewBundle->setLength( 193 );
    m_previewBundle->setPlayCount( 2 );
    m_previewBundle->setRating( 3 );
    m_previewBundle->setSampleRate( 44100 );
    m_previewBundle->setScore( 3.f );
    m_previewBundle->setTitle( AtomicString( "Some Title" ) );
    m_previewBundle->setTrack( 7 );
    m_previewBundle->setUrl( "/some%20directory/some%20file.mp3" );
    m_previewBundle->setYear( 2006 );

    m_formatHelp->setText( TQString( "<a href='whatsthis:%1'>%2</a>" ).
            arg( Amarok::escapeHTMLAttr( buildFormatTip() ), i18n( "(Help)" ) ) );

    m_unsupportedMenu = new TQPopupMenu( m_addSupportedButton, "unsupported" );

    m_addSupportedButton->setPopup( m_unsupportedMenu );

    connect( m_unsupportedMenu, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( addSupportedButtonClicked( int ) ) );
}


void GenericMediaDeviceConfigDialog::destroy()
{
    if( m_unsupportedMenu != NULL )
        delete m_unsupportedMenu;

    m_unsupportedMenu = NULL;
}