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>
39 class Moodbar
: public QObject
44 typedef Q3ValueVector
<QColor
> ColorList
;
48 Unloaded
, // Haven't tried to load yet
49 CantLoad
, // For some reason we'll never be able to load
50 JobQueued
, // An analysis job is pending
51 JobRunning
, // An analysis job is running
52 JobFailed
, // Our job has returned and failed
56 // These are the state changes we emit in jobEvent
64 // Construct an empty, small-footprint instance
65 Moodbar( MetaBundle
*mb
);
66 // This is for de-queueing jobs
69 Moodbar
& operator=( const Moodbar
&mood
);
72 bool dataExists( void );
73 bool canHaveMood( void );
75 QPixmap
draw( int width
, int height
);
77 int hueSort( void ) const
79 State
state( void ) const
82 // Where are we storing the .mood file?
83 static QString
moodFilename( const KUrl
&url
);
84 static QString
moodFilename( const KUrl
&url
, bool withMusic
);
85 static bool copyFile( const QString
&srcPath
, const QString
&dstPath
);
87 static bool executableExists( void );
90 void slotJobEvent( KUrl url
, int newState
);
93 void jobEvent( int newState
);
96 // Undefined! We can't construct unless we know what
97 // *our* parent bundle is.
98 Moodbar( const Moodbar
& );
100 bool readFile( void );
102 MetaBundle
*m_bundle
; // Parent bundle
103 ColorList m_data
; // .mood file contents
104 QPixmap m_pixmap
; // Cached from the last time draw() was called
105 KUrl m_url
; // Keep a copy of this, mainly for dtor
106 mutable QMutex m_mutex
; // Locks the whole object
107 int m_hueSort
; // For PlaylistItem sorting
114 // For internal use only (well, mostly)
115 class MoodServer
: public QObject
120 static MoodServer
*instance( void );
122 bool queueJob( MetaBundle
*bundle
);
123 void deQueueJob( KUrl url
);
125 bool moodbarBroken( void ) const
126 { return m_moodbarBroken
; }
129 void jobEvent( KUrl url
, int newState
);
132 void slotJobCompleted( K3Process
*proc
);
133 void slotNewJob( void );
134 void slotMoodbarPrefs( bool show
, bool moodier
, int alter
, bool withMusic
);
137 // Moodbar file organization slots
138 void slotFileDeleted( const QString
&absPath
);
139 void slotFileMoved( const QString
&srcPath
, const QString
&dstPath
);
146 ProcData( KUrl url
, QString infile
, QString outfile
)
147 : m_url( url
), m_infile( infile
), m_outfile( outfile
)
155 // Keep track of how many Moodbars are waiting on this URL
169 void setMoodbarBroken( void );
170 void clearJobs( void );
172 Q3ValueList
<ProcData
> m_jobQueue
;
173 bool m_moodbarBroken
;
174 K3Process
*m_currentProcess
;
175 ProcData m_currentData
;
176 mutable QMutex m_mutex
;