Make the ServiceListDelegate use less handcoded values and more general variables...
[amarok.git] / src / moodbar.h
blob76b5442bd128cbc2ddb5a3aa4ebcafcdcf99d8dc
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>
36 #include "amarok_export.h"
38 class MetaBundle;
40 class AMAROK_EXPORT Moodbar : public QObject
42 Q_OBJECT
44 public:
45 typedef Q3ValueVector<QColor> ColorList;
47 typedef enum
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
54 Loaded // Can draw()
55 } State;
57 // These are the state changes we emit in jobEvent
58 enum
60 JobStateRunning,
61 JobStateSucceeded,
62 JobStateFailed
65 // Construct an empty, small-footprint instance
66 Moodbar( MetaBundle *mb );
67 // This is for de-queueing jobs
68 ~Moodbar( void );
70 Moodbar& operator=( const Moodbar &mood );
71 void reset( void );
73 bool dataExists( void );
74 bool canHaveMood( void );
75 void load( void );
76 QPixmap draw( int width, int height );
78 int hueSort( void ) const
79 { return m_hueSort; }
80 State state( void ) const
81 { return m_state; }
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 );
90 public slots:
91 void slotJobEvent( KUrl url, int newState );
93 signals:
94 void jobEvent( int newState );
96 private:
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
109 State m_state;
113 class K3Process;
115 // For internal use only (well, mostly)
116 class MoodServer : public QObject
118 Q_OBJECT
120 public:
121 static MoodServer *instance( void );
123 bool queueJob( MetaBundle *bundle );
124 void deQueueJob( KUrl url );
126 bool moodbarBroken( void ) const
127 { return m_moodbarBroken; }
129 signals:
130 void jobEvent( KUrl url, int newState );
132 private slots:
133 void slotJobCompleted( K3Process *proc );
134 void slotNewJob( void );
135 void slotMoodbarPrefs( bool show, bool moodier, int alter, bool withMusic );
137 public slots:
138 // Moodbar file organization slots
139 void slotFileDeleted( const QString &absPath );
140 void slotFileMoved( const QString &srcPath, const QString &dstPath );
142 private:
144 class ProcData
146 public:
147 ProcData( KUrl url, QString infile, QString outfile )
148 : m_url( url ), m_infile( infile ), m_outfile( outfile )
149 , m_refcount( 1 )
151 ProcData( void ) {}
153 KUrl m_url;
154 QString m_infile;
155 QString m_outfile;
156 // Keep track of how many Moodbars are waiting on this URL
157 int m_refcount;
160 typedef enum
162 Crash = -1,
163 Success = 0,
164 NoPlugin = 1,
165 NoFile = 2,
166 CommandLine = 3
167 } ReturnStatus;
169 MoodServer( void );
170 void setMoodbarBroken( void );
171 void clearJobs( void );
173 Q3ValueList<ProcData> m_jobQueue;
174 bool m_moodbarBroken;
175 K3Process *m_currentProcess;
176 ProcData m_currentData;
177 mutable QMutex m_mutex;
181 #endif // MOODBAR_H