~ubuntu-branches/ubuntu/lucid/amarok/lucid-backports

« back to all changes in this revision

Viewing changes to src/moodbar/MoodbarManager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2011-03-03 10:27:39 UTC
  • mfrom: (114.1.20 natty)
  • Revision ID: james.westby@ubuntu.com-20110303102739-ar67wpa6mllo59n2
Tags: 2:2.4.0-0ubuntu4~lucid1
* Source backport to lucid (LP: #728447)
  - Drop version requirement on libindicate-qt-dev build-dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
- Nikolaj
29
29
*/
30
30
 
 
31
#define DEBUG_PREFIX "MoodbarManager"
31
32
 
32
33
#include "MoodbarManager.h"
33
34
 
34
35
#include "amarokconfig.h"
35
 
#include "Debug.h"
 
36
#include "core/support/Debug.h"
 
37
#include "PaletteHandler.h"
36
38
 
37
39
#include <QFile>
38
40
#include <QFileInfo>
57
59
MoodbarManager::MoodbarManager()
58
60
    : m_cache( new KPixmapCache( "Amarok-moodbars" ) )
59
61
    , m_lastPaintMode( 0 )
60
 
{}
 
62
{
 
63
    connect( The::paletteHandler(), SIGNAL(newPalette(QPalette)), SLOT(paletteChanged(QPalette)) );
 
64
}
61
65
 
62
66
MoodbarManager::~MoodbarManager()
63
67
{}
99
103
    if( !QFile::exists( moodFilePath ) )
100
104
    {
101
105
        debug() << "no such file";
102
 
        m_hasMoodMap.insert( track, false );
103
 
        return false;
 
106
        //for fun, try without the leading '.'
 
107
 
 
108
        QFileInfo fInfo( moodFilePath );
 
109
        QString testName = fInfo.fileName(); 
 
110
        testName.remove( 0, 1 );
 
111
 
 
112
        moodFilePath.replace( fInfo.fileName(), testName );
 
113
 
 
114
        debug() << "trying : " << moodFilePath;
 
115
        if( !QFile::exists( moodFilePath ) )
 
116
        {
 
117
            debug() << "no luck removing the leading '.' either...";
 
118
            m_hasMoodMap.insert( track, false );
 
119
            return false;
 
120
        }
 
121
 
 
122
        debug() << "whoops, missing leading '.', so mood file path: " << moodFilePath;
104
123
    }
105
124
 
106
125
    //it is a local file with a matching .mood file. Good enough for now!
185
204
    if( path.isEmpty() )
186
205
        return data;
187
206
 
188
 
    debug() << "Moodbar::readFile: Trying to read " << path << endl;
 
207
    debug() << "Trying to read " << path;
189
208
 
190
209
    QFile moodFile( path );
191
210
 
193
212
        return data;
194
213
 
195
214
    int r, g, b, samples = moodFile.size() / 3;
196
 
    debug() << "Moodbar::readFile: File " << path
197
 
            << " opened. Proceeding to read contents... s=" << samples << endl;
 
215
    debug() << "File" << path << "opened. Proceeding to read contents... s=" << samples;
198
216
 
199
217
    // This would be bad.
200
218
    if( samples == 0 )
201
219
    {
202
 
        debug() << "Moodbar::readFile: File " << moodFile.fileName()
203
 
                << " is corrupted, removing." << endl;
204
 
                //TODO: notify the user somehow
 
220
        debug() << "Filex " << moodFile.fileName() << "is corrupted, removing";
 
221
        //TODO: notify the user somehow
205
222
        //moodFile.remove();
206
223
        return data;
207
224
    }
214
231
    memset( huedist, 0, sizeof( huedist ) );
215
232
 
216
233
    // Read the file, keeping track of some histograms
217
 
    for( int i = 0; i < samples; i++ )
 
234
    for( int i = 0; i < samples; ++i )
218
235
    {
219
236
 
220
237
        char rChar, gChar, bChar;
273
290
 
274
291
    const int paintStyle = AmarokConfig::moodbarPaintStyle();
275
292
 
276
 
    if( paintStyle != 0 )
277
293
    {
278
294
        MoodbarColorList modifiedData;
279
295
        // Explanation of the parameters:
294
310
 
295
311
        switch( paintStyle )
296
312
        {
297
 
          case 1: // Angry
 
313
        case 1: // Angry
298
314
            threshold  = samples / 360 * 9;
299
315
            rangeStart = 45;
300
316
            rangeDelta = -45;
302
318
            val        = 100;
303
319
            break;
304
320
 
305
 
          case 2: // Frozen
 
321
        case 2: // Frozen
306
322
            threshold  = samples / 360 * 1;
307
323
            rangeStart = 140;
308
324
            rangeDelta = 160;
310
326
            val        = 100;
311
327
            break;
312
328
 
313
 
          default: // Happy
 
329
        case 3: // Happy
314
330
            threshold  = samples / 360 * 2;
315
331
            rangeStart = 0;
316
332
            rangeDelta = 359;
317
333
            sat        = 150;
318
 
            val        = 250;
 
334
            val        = 200;
 
335
            break;
 
336
 
 
337
        default: // Default (system colours)
 
338
            threshold  = samples / 360 * 3;
 
339
            rangeStart = The::paletteHandler()->highlightColor().hsvHue();
 
340
            rangeStart = (rangeStart - 20 + 360) % 360;
 
341
            rangeDelta = 20;
 
342
            sat        = The::paletteHandler()->highlightColor().hsvSaturation();
 
343
            val        = The::paletteHandler()->highlightColor().value() / 2;
319
344
        }
320
345
 
321
346
        //debug() << "ReadMood: Applying filter t=" << threshold
386
411
        mx = i;
387
412
    m_hueSort += mx;
388
413
*/
389
 
    //debug() << "Moodbar::readFile: All done." << endl;
390
 
 
391
 
 
392
 
 
 
414
    //debug() << "All done.";
393
415
    return data;
394
416
}
395
417
 
486
508
    return moodPath.replace( fileName, '.' + fileName );
487
509
}
488
510
 
 
511
void MoodbarManager::paletteChanged( const QPalette &palette )
 
512
{
 
513
    Q_UNUSED( palette )
 
514
    const int paintStyle = AmarokConfig::moodbarPaintStyle();
 
515
    if( paintStyle == 0 ) // system default colour
 
516
    {
 
517
        m_cache->discard();
 
518
        m_moodDataMap.clear();
 
519
    }
 
520
}