summaryrefslogtreecommitdiffstats
path: root/amarok/src/moodbar.h
blob: 8b3d2ef52725a6afe56e63235de863e9d4b88510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/***************************************************************************
                       moodbar.h  -  description
                          -------------------
 begin                : 6th Nov 2005
 copyright            : (C) 2006 by Joseph Rabinoff
 copyright            : (C) 2005 by Gav Wood
 email                : bobqwatson@yahoo.com
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

// Aug 5 2006 (Joe Rabinoff): Rewrote everything.  This file bears 
// no resemblance to Gav's original code.

// See moodbar.cpp for usage and implementation notes.

#ifndef MOODBAR_H
#define MOODBAR_H

#include <tqobject.h>
#include <tqvaluevector.h>
#include <tqcolor.h>
#include <tqpixmap.h>
#include <tqmutex.h>
#include <tqvaluelist.h>

#include <kurl.h>


class MetaBundle;

class Moodbar : public TQObject
{
  Q_OBJECT
  
  
public:
  typedef TQValueVector<TQColor> ColorList;

  typedef enum
  {
      Unloaded,   // Haven't tried to load yet
      CantLoad,   // For some reason we'll never be able to load
      JobQueued,  // An analysis job is pending 
      JobRunning, // An analysis job is running
      JobFailed,  // Our job has returned and failed
      Loaded      // Can draw()
  } State;

  // These are the state changes we emit in jobEvent
  enum
  {
      JobStateRunning,
      JobStateSucceeded,
      JobStateFailed
  };
  
  // Construct an empty, small-footprint instance
  Moodbar( MetaBundle *mb ); 
  // This is for de-queueing jobs
  ~Moodbar( void );
  
  Moodbar& operator=( const Moodbar &mood );
  void reset( void );
  void detach( void );
  
  bool dataExists( void );
  bool canHaveMood( void );
  void load( void );
  TQPixmap draw( int width, int height );

  int hueSort( void ) const
  { return m_hueSort; }
  State state( void ) const
  { return m_state; }
  
  // Where are we storing the .mood file?
  static TQString moodFilename( const KURL &url );
  static TQString moodFilename( const KURL &url, bool withMusic );
  static bool copyFile( const TQString &srcPath, const TQString &dstPath );

  static bool executableExists( void );
  
public slots:
  void slotJobEvent( KURL url, int newState );
  
signals:
  void jobEvent( int newState );
  
private:
  // Undefined!  We can't construct unless we know what
  // *our* parent bundle is.
  Moodbar( const Moodbar& );

  bool readFile( void );
  
  MetaBundle    *m_bundle;      // Parent bundle
  ColorList      m_data;        // .mood file contents
  TQPixmap        m_pixmap;      // Cached from the last time draw() was called
  KURL           m_url;         // Keep a copy of this, mainly for dtor
  mutable TQMutex m_mutex;       // Locks the whole object
  int            m_hueSort;     // For PlaylistItem sorting
  State          m_state;
};


class TDEProcess;

// For internal use only (well, mostly)
class MoodServer : public TQObject
{
  Q_OBJECT
  

public:
  static MoodServer *instance( void );
  
  bool queueJob( MetaBundle *bundle );
  void deQueueJob( KURL url );

  bool moodbarBroken( void ) const
  { return m_moodbarBroken; }

signals:
  void jobEvent( KURL url, int newState );
  
private slots:
  void slotJobCompleted( TDEProcess *proc );
  void slotNewJob( void );
  void slotMoodbarPrefs( bool show, bool moodier, int alter, bool withMusic );

public slots:
  // Moodbar file organization slots
  void slotFileDeleted( const TQString &absPath );
  void slotFileMoved( const TQString &srcPath, const TQString &dstPath );

private:

  class ProcData
  {
  public:
    ProcData( KURL url, TQString infile, TQString outfile )
      : m_url( url ), m_infile( infile ), m_outfile( outfile )
      , m_refcount( 1 )
    {}
    ProcData( void ) : m_refcount( 0 ) {}

    KURL    m_url;
    TQString m_infile;
    TQString m_outfile; 
    // Keep track of how many Moodbars are waiting on this URL
    int     m_refcount;  
  };

  typedef enum
  {
    Crash       = -1,
    Success     = 0,
    NoPlugin    = 1,
    NoFile      = 2,
    CommandLine = 3
  } ReturnStatus;

  MoodServer( void );
  void setMoodbarBroken( void );
  void clearJobs( void );

  TQValueList<ProcData> m_jobQueue;
  bool m_moodbarBroken;
  TDEProcess *m_currentProcess;
  ProcData m_currentData;
  mutable TQMutex m_mutex;
};


#endif // MOODBAR_H