summaryrefslogtreecommitdiffstats
path: root/noatun-plugins/dub/dub/dub.h
blob: 75519bfc516df2ee249b061a8f63e4a9f6ce23a4 (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
/***************************************************************************
                          dub.h  -  description
                             -------------------
    begin                : Tue Oct 23 01:44:51 EEST 2001
    copyright            : (C) 2001 by Eray Ozkural (exa)
    email                : erayo@cs.bilkent.edu.tr
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef Dub_Interface
#define Dub_Interface

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// KDE includes
#include <tdeapplication.h>
#include <tdemainwindow.h>
#include <kurl.h>
#include <noatun/plugin.h>
#include <noatun/playlist.h>

// sys includes
#include <vector>
#include <list>

// forward decl
class KFileItem;
class KDirLister;
class DubPlaylist;

// application specific includes
#include "dubapp.h"
#include "dubconfigmodule.h"

// dub specific application code
class Dub : public DubApp
{
  Q_OBJECT
  

public:

  Dub(DubPlaylist* plist);

public slots:
  /** A file selected */
  void fileSelected(const KFileItem*);
  void mediaHomeSelected(const TQString& url);

  signals:
void setMediaHome(KURL);
  // xemacs rules

public:

  /** playlist object to interface noatun
   */
  DubPlaylist& playlist;
  /** noatun configuration object
   */
  DubConfigModule& dubconfig;

  KFileItem* getActiveFile() { return activeFile; }
  /** find root */
  KFileItem* queryRoot();
  /** First file in the sequence */
  const KFileItem* queryFirstFile();
  /** Select next file in order */
  void selectNextFile();
  /** Select previous file in order */
  void selectPreviousFile();

public:

  /*  The chosen file */
  KFileItem* activeFile;

private:

  void configure_sequencing();

  // expansion slot :P
  struct Sequencer {
    Sequencer(Dub* d) : dub(*d) {}
    virtual KFileItem* first() = 0;
    virtual void next() = 0;
    virtual void prev() = 0;
    Dub& dub;
    void set_file(KFileItem** file, KFileItem* val);
  };
  Sequencer* sequencer;

  // possible sequencers are linear/oneDir, linear/recursive,
  // shuffle/oneDir, shuffle/recursive, repeat, single

  // linear sequencing subsystem
  struct Linear_Seq : public Sequencer {
    Linear_Seq(Dub* d) : Sequencer(d) {}
    KFileItem* first(TQPtrList<KFileItem> & items);
    KFileItem* last(TQPtrList<KFileItem> & items);
    KFileItem* next(TQPtrList<KFileItem> & items, KFileItem** active_file);
    KFileItem* prev(TQPtrList<KFileItem> & items, KFileItem** active_file);
    bool find(TQPtrList<KFileItem> & items, KFileItem* a_file);
  };

  // sequencer that traverses current directory in view order
  struct Linear_OneDir : public Linear_Seq {
    Linear_OneDir(Dub* d) : Linear_Seq(d), first_file(0) {}
    virtual ~Linear_OneDir() {}
    KFileItem* first();
    void next();
    void prev();
    KFileItem* first_file;
  };
  Linear_OneDir linear_onedir;

  // directory node for recursive play
  struct Dir_Node
  {
    Dir_Node(TQString dir, bool forward = true);
    TQString dir;
    TQStringList subdirs;
    TQStringList::iterator current_subdir;
    TQPtrList<KFileItem> file_items;
    KFileItem* current_file;
    void init_traversal(bool forward);
    bool past_begin;		// stupid iterators
  };

  // recursive play sequencing subsystem
  struct Recursive_Seq {
    Recursive_Seq();
    void init(const KURL & root);
    TQString canonical_path(TQString dir);
    bool check_dir(TQString dir);
    Dir_Node* top_dir() { return play_stack.getLast(); }
    Dir_Node* bottom_dir() { return play_stack.getFirst(); }
    bool push_dir(TQString dir, bool forward = true);
    bool pop_dir();
    bool advance(bool forward = true);
    void pop_preorder(bool forward = true);
    void next_preorder();
    void prev_preorder();
    void print_stack();

    TQString recursion_root;
    TQPtrList<Dir_Node> play_stack;
  };

  // sequencer to make a preorder walk of the directory tree
  struct Linear_Recursive
    : public Sequencer, public Recursive_Seq {
    Linear_Recursive(Dub* d);
    virtual ~Linear_Recursive() {};
    KFileItem* first();
    void next();
    void prev();
  };
  Linear_Recursive linear_recursive;

  // shuffle/onedir sequencer
  struct Shuffle_OneDir
    : public Sequencer {
    Shuffle_OneDir(Dub* d) : Sequencer(d) {
      items.setAutoDelete(true);
    }
    virtual ~Shuffle_OneDir() {};
    void init(const TQString& dir);
    KFileItem* first();
    void next();
    void prev();
    void init();

    int play_index;
    std::vector<int> play_order;
    KURL shuffle_dir;
    TQPtrList<KFileItem> items;
  };
  Shuffle_OneDir shuffle_onedir;

  // shuffle/recursive sequencer
  struct Shuffle_Recursive
    : public Sequencer, public Recursive_Seq {
    Shuffle_Recursive(Dub* d) : Sequencer(d) {}
    virtual ~Shuffle_Recursive() {}
    KFileItem* random_file();
    KFileItem* first();
    void next();
    void prev();

    TQString shuffle_root;
  };
  Shuffle_Recursive shuffle_recursive;

};

#endif // DUB_H