1 /*************************************************************************** -*- c++ -*-
2 moodbar.h - description
5 copyright : (C) 2006 by Joseph Rabinoff
6 copyright : (C) 2005 by Gav Wood
7 email : bobqwatson@yahoo.com
8 ***************************************************************************/
10 /***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
17 ***************************************************************************/
19 // Aug 5 2006 (Joe Rabinoff): Rewrote everything. This file bears
20 // no resemblance to Gav's original code.
22 // See moodbar.cpp for usage and implementation notes.
29 #include <q3valuelist.h>
30 #include <q3valuevector.h>
36 #include "amarok_export.h"
40 class AMAROK_EXPORT Moodbar
: public QObject
45 typedef Q3ValueVector
<QColor
> ColorList
;
49 Unloaded
, // Haven't tried to load yet
50 CantLoad
, // For some reason we'll never be able to load
51 JobQueued
, // An analysis job is pending
52 JobRunning
, // An analysis job is running
53 JobFailed
, // Our job has returned and failed
57 // These are the state changes we emit in jobEvent
65 // Construct an empty, small-footprint instance
66 Moodbar( MetaBundle
*mb
);
67 // This is for de-queueing jobs
70 Moodbar
& operator=( const Moodbar
&mood
);
73 bool dataExists( void );
74 bool canHaveMood( void );
76 QPixmap
draw( int width
, int height
);
78 int hueSort( void ) const
80 State
state( void ) const
83 // Where are we storing the .mood file?
84 static QString
moodFilename( const KUrl
&url
);
85 static QString
moodFilename( const KUrl
&url
, bool withMusic
);
86 static bool copyFile( const QString
&srcPath
, const QString
&dstPath
);
88 static bool executableExists( void );
91 void slotJobEvent( KUrl url
, int newState
);
94 void jobEvent( int newState
);
97 // Undefined! We can't construct unless we know what
98 // *our* parent bundle is.
99 Moodbar( const Moodbar
& );
101 bool readFile( void );
103 MetaBundle
*m_bundle
; // Parent bundle
104 ColorList m_data
; // .mood file contents
105 QPixmap m_pixmap
; // Cached from the last time draw() was called
106 KUrl m_url
; // Keep a copy of this, mainly for dtor
107 mutable QMutex m_mutex
; // Locks the whole object
108 int m_hueSort
; // For PlaylistItem sorting
115 // For internal use only (well, mostly)
116 class MoodServer
: public QObject
121 static MoodServer
*instance( void );
123 bool queueJob( MetaBundle
*bundle
);
124 void deQueueJob( KUrl url
);
126 bool moodbarBroken( void ) const
127 { return m_moodbarBroken
; }
130 void jobEvent( KUrl url
, int newState
);
133 void slotJobCompleted( int );
134 void slotNewJob( void );
135 void slotMoodbarPrefs( bool show
, bool moodier
, int alter
, bool withMusic
);
138 // Moodbar file organization slots
139 void slotFileDeleted( const QString
&absPath
);
140 void slotFileMoved( const QString
&srcPath
, const QString
&dstPath
);
147 ProcData( KUrl url
, QString infile
, QString outfile
)
148 : m_url( url
), m_infile( infile
), m_outfile( outfile
)
156 // Keep track of how many Moodbars are waiting on this URL
170 void setMoodbarBroken( void );
171 void clearJobs( void );
173 Q3ValueList
<ProcData
> m_jobQueue
;
174 bool m_moodbarBroken
;
175 Process
*m_currentProcess
;
176 ProcData m_currentData
;
177 mutable QMutex m_mutex
;