summaryrefslogtreecommitdiffstats
path: root/src/k3baudioplayer.h
blob: 1e32602d71771e82a248c9ab97feab285ede172c (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* 
 *
 * $Id: k3baudioplayer.h 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * 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.
 * See the file "COPYING" for the exact licensing terms.
 */


#ifndef K3BAUDIOPLAYER_H
#define K3BAUDIOPLAYER_H

#include <klistview.h>

#include <config.h>

#ifdef WITH_ARTS
#include <arts/kmedia2.h>
#include <arts/kartsdispatcher.h>
#endif

class TQTimer;
class TQLabel;
class TQToolButton;
class TQSlider;
class TQPainter;
class TQColorGroup;
class TQDropEvent;
class TQDragObject;
class KAction;
class KActionMenu;


/**
 * Special ListViewItem for the K3bAudioPlayer playlist
 * @author Sebastian Trueg
 */
class K3bPlayListViewItem : public KListViewItem
{
 public:
  K3bPlayListViewItem( const TQString&, TQListView* parent );
  K3bPlayListViewItem( const TQString&, TQListView* parent, TQListViewItem* after );
  ~K3bPlayListViewItem();

  /** @returns the filename for the first column and the 
   *           length in format 00:00.00 for the second column
   */
  virtual TQString text( int c ) const;

  void setLength( unsigned long l ) { m_length = l; }
  unsigned long length() const { return m_length; }
  const TQString& filename() const { return m_filename; }

  /**
   * reimplemented from TQListViewItem
   * takes the m_bActive flag into account.
   */
  virtual void paintCell( TQPainter*, const TQColorGroup&, int, int, int );

  void setActive( bool a ) { m_bActive = a; }

 protected:
  /** path to the associated file */
  TQString m_filename;

  /** length in frames (1/75 second) */
  unsigned long m_length;

  bool m_bActive;
};



/**
 * Playlistview just needed to accept 
 * url drags
 */ 
class K3bPlayListView : public KListView
{
Q_OBJECT
  TQ_OBJECT

 public:
  K3bPlayListView( TQWidget* parent = 0, const char* name = 0 );
  ~K3bPlayListView();

 protected:
  bool acceptDrag( TQDropEvent* e ) const;
  TQDragObject* dragObject();
};




/**
 * @author Sebastian Trueg
 */
class K3bAudioPlayer : public TQWidget
{
Q_OBJECT
  TQ_OBJECT

 public: 
  K3bAudioPlayer( TQWidget* parent = 0, const char* name = 0 );
  ~K3bAudioPlayer();

  bool supportsMimetype( const TQString& mimetype );

  /**
   * length of current playing in seconds
   */
  long length();

  /**
   * current position in seconds
   */
  long position();

  /**
   * EMPTY - no file loaded
   */
  enum player_state { PLAYING, PAUSED, STOPPED, EMPTY };

  int state();

 signals:
  void started( const TQString& filename );
  void started();
  void stopped();
  void paused();
  void ended();

 public slots:
  void playFile( const TQString& filename );
  void playFiles( const TQStringList& files );
  void enqueueFile( const TQString& filename );
  void enqueueFiles( const TQStringList& files );

  /** clears the playlist */
  void clear();
  void play();
  void forward();
  void back();
  void stop();
  void pause();
  void seek( long pos );
  void seek( int pos );

/*  protected: */
/*   void dragEnterEvent( TQDragEnterEvent* e ); */
/*   void dropEvent( TQDropEvent* e ); */

 private slots:
  void slotCheckEnd();
  void slotUpdateDisplay();
  void slotUpdateCurrentTime( int time );
  void slotUpdateLength( long time );
  void slotUpdateFilename();
  void slotPlayItem( TQListViewItem* item );
  void slotDropped( TQDropEvent* e, TQListViewItem* after );

  /**
   * set the actual item. Will set m_currentItem and 
   * handle highlighting of the current item
   */
  void setCurrentItem( TQListViewItem* item );
  void slotRemoveSelected();
  void slotShowContextMenu( KListView*, TQListViewItem* item, const TQPoint& p );

 private:
#ifdef WITH_ARTS
  Arts::PlayObject m_playObject;
  KArtsDispatcher m_dispatcher;
#endif
  TQString m_filename;

  TQLabel* m_labelFilename;
  TQLabel* m_labelCurrentTime;
  TQLabel* m_labelOverallTime;
  
  TQToolButton* m_buttonPlay;
  TQToolButton* m_buttonPause;
  TQToolButton* m_buttonStop;
  TQToolButton* m_buttonForward;
  TQToolButton* m_buttonBack;
  
  K3bPlayListView* m_viewPlayList;
  
  TQSlider* m_seekSlider;
  
  TQTimer* m_updateTimer;

  K3bPlayListViewItem* m_currentItem;

  bool m_bLengthReady;

  KAction* m_actionRemove;
  KAction* m_actionClear;
  KActionMenu* m_contextMenu;
};


#endif