add check for role to data()
[amarok.git] / src / moodbar.h
blobe7c185bb13ab77356d0de68f12eee332a9de022b
1 /*************************************************************************** -*- c++ -*-
2 moodbar.h - description
3 -------------------
4 begin : 6th Nov 2005
5 copyright : (C) 2006 by Joseph Rabinoff
6 copyright : (C) 2005 by Gav Wood
7 email : bobqwatson@yahoo.com
8 ***************************************************************************/
10 /***************************************************************************
11 * *
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. *
16 * *
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.
24 #ifndef MOODBAR_H
25 #define MOODBAR_H
27 #include <KUrl>
29 #include <q3valuelist.h>
30 #include <q3valuevector.h>
31 #include <QColor>
32 #include <QMutex>
33 #include <QObject>
34 #include <QPixmap>
37 class MetaBundle;
39 class Moodbar : public QObject
41 Q_OBJECT
43 public:
44 typedef Q3ValueVector<QColor> ColorList;
46 typedef enum
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
53 Loaded // Can draw()
54 } State;
56 // These are the state changes we emit in jobEvent
57 enum
59 JobStateRunning,
60 JobStateSucceeded,
61 JobStateFailed
64 // Construct an empty, small-footprint instance
65 Moodbar( MetaBundle *mb );
66 // This is for de-queueing jobs
67 ~Moodbar( void );
69 Moodbar& operator=( const Moodbar &mood );
70 void reset( void );
72 bool dataExists( void );
73 bool canHaveMood( void );
74 void load( void );
75 QPixmap draw( int width, int height );
77 int hueSort( void ) const
78 { return m_hueSort; }
79 State state( void ) const
80 { return m_state; }
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 );
89 public slots:
90 void slotJobEvent( KUrl url, int newState );
92 signals:
93 void jobEvent( int newState );
95 private:
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
108 State m_state;
112 class K3Process;
114 // For internal use only (well, mostly)
115 class MoodServer : public QObject
117 Q_OBJECT
119 public:
120 static MoodServer *instance( void );
122 bool queueJob( MetaBundle *bundle );
123 void deQueueJob( KUrl url );
125 bool moodbarBroken( void ) const
126 { return m_moodbarBroken; }
128 signals:
129 void jobEvent( KUrl url, int newState );
131 private slots:
132 void slotJobCompleted( K3Process *proc );
133 void slotNewJob( void );
134 void slotMoodbarPrefs( bool show, bool moodier, int alter, bool withMusic );
136 public slots:
137 // Moodbar file organization slots
138 void slotFileDeleted( const QString &absPath );
139 void slotFileMoved( const QString &srcPath, const QString &dstPath );
141 private:
143 class ProcData
145 public:
146 ProcData( KUrl url, QString infile, QString outfile )
147 : m_url( url ), m_infile( infile ), m_outfile( outfile )
148 , m_refcount( 1 )
150 ProcData( void ) {}
152 KUrl m_url;
153 QString m_infile;
154 QString m_outfile;
155 // Keep track of how many Moodbars are waiting on this URL
156 int m_refcount;
159 typedef enum
161 Crash = -1,
162 Success = 0,
163 NoPlugin = 1,
164 NoFile = 2,
165 CommandLine = 3
166 } ReturnStatus;
168 MoodServer( void );
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;
180 #endif // MOODBAR_H