juk.h 6.11 KB
Newer Older
1 2 3 4 5
/***************************************************************************
                          juk.h  -  description
                             -------------------
    begin                : Mon Feb  4 23:40:41 EST 2002
    copyright            : (C) 2002 by Scott Wheeler
6
    email                : wheeler@kde.org
7
***************************************************************************/
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

/***************************************************************************
 *                                                                         *
 *   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 JUK_H
#define JUK_H

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

#include <kaction.h>
26
#include <kglobalaccel.h>
27 28
#include <kstdaction.h>
#include <kmainwindow.h>
29
#include <kmenubar.h>
30
#include <kpopupmenu.h>
31

32
#include <qlabel.h>
33 34

#include "player.h"
35
#include "playlistsplitter.h"
36
#include "jukIface.h"
37 38 39

class QTimer;
class QListViewItem;
40

41
class SliderAction;
42
class StatusLabel;
43
class SystemTray;
44

45
class JuK : public KMainWindow, virtual public JuKIface
46
{
47
    Q_OBJECT
48

49
public:
50
    JuK(QWidget* parent = 0, const char *name = 0);
51
    virtual ~JuK();
52

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
public slots:
    void play();
    void pause();
    void stop();
    void back();
    void back(int howMany);
    void slotPopulateBackMenu();
    void forward();
    void seekBack();
    void seekForward();

    void playPause();

    void volumeUp();
    void volumeDown();
    void volumeMute();

70
signals:
71 72
    void signalEdit();
    void signalNewSong(const QString& songTitle);
73

74 75
private:
    void setupLayout();
76
    void setupActions();
77 78 79 80 81 82 83 84
    /**
     * Solves the problem of the splitter needing to use some of the actions from
     * this class and as such them needing to be created before the
     * PlaylistSplitter, but also needing to connect to the playlist splitter.
     *
     * @see createSplitterAction();
     */
    void setupSplitterConnections();
85
    void setupPlayer();
86
    void setupSystemTray();
87
    void setupGlobalAccels();
88

89
    void processArgs();
90

91 92
    void keyPressEvent(QKeyEvent *);

93
    /**
94 95
     * readSettings() is separate from readConfig() in that it contains settings
     * that need to be read before the GUI is setup.
96 97
     */
    void readSettings();
98
    void readConfig();
99
    void saveConfig();
100

101
    virtual bool queryExit();
102 103
    virtual bool queryClose();

104
    QString playingString() const;
105 106 107 108 109 110 111 112 113 114 115 116 117 118

    int currentTime() const { return m_player->currentTime(); }
    int totalTime() const { return m_player->totalTime(); }

    /**
     * Set the volume.  100 is the maximum.
     */
    void setVolume(float volume);

    /**
     * Set the position in the currently playing track (in seconds).
     */
    void setTime(int time) { m_player->seek(time); }

119 120 121 122 123 124 125
    void updatePlaylistInfo();

    /**
     * This is the main method to play stuff.  Everything else is just a wrapper
     * around this.
     */
    void play(const QString &file);
126

127
    void openFile(const QString &file);
128
    void openFile(const QStringList &files);
129

130 131 132 133 134 135 136 137
    /**
     * Because we want to be able to reuse these actions in the main GUI classes,
     * which are created by the PlaylistSplitter, it is useful to create them
     * before creating the splitter.  This however creates a problem in that we
     * also need to connect them to the splitter.  This method builds creates
     * actions and builds a list of connections that can be set up after the
     * splitter is created.
     */
138 139
    KAction *createSplitterAction(const QString &text,
				  const char *slot,
140 141 142 143
				  const char *name,
				  const QString &pix = QString::null,
				  const KShortcut &shortcut = KShortcut());

144
private slots:
145
    void slotPlaylistChanged();
146

147 148 149
    // file menu
    void slotQuit() { m_shuttingDown = true; kapp->quit(); }

150
    // settings menu
151 152
    void slotToggleSystemTray(bool enabled);
    void slotSetOutput(int output);
153
    void slotEditKeys();
154
    void slotConfigureTagGuesser();
155
    void slotConfigureFileRenamer();
156

157 158 159 160
    // additional player slots
    void slotTrackPositionSliderClicked();
    void slotTrackPositionSliderReleased();
    void slotTrackPositionSliderUpdate(int position);
161 162

    /**
163 164
     * This method is called by the slider to set the volume of the player.  Its
     * value is relative to the maxValue() of the volume slider.
165
     */
166
    void slotSetVolume(int volume);
167

168
    /**
169 170
     * This method is called to check our progress in the playing file.  It uses
     * m_playTimer to know when to call itself again.
171
     */
172
    void slotPollPlay();
173
    void slotPlaySelectedFile();
174
    void startPlayingPlaylist();
175
    void slotToggleMenuBar() { menuBar()->isVisible() ? menuBar()->hide() : menuBar()->show(); }
176 177
    void slotGuessTagInfoFromFile();
    void slotGuessTagInfoFromInternet();
178

179 180
private:
    // layout objects
181 182 183
    PlaylistSplitter *m_splitter;
    StatusLabel *m_statusLabel;
    SystemTray *m_systemTray;
184

185 186 187
    typedef QPair<KAction *, const char *> SplitterConnection;
    QValueList<SplitterConnection> m_splitterConnections;

188
    // actions
189
    KToggleAction *m_showSearchAction;
190
    KToggleAction *m_showEditorAction;
191
    KToggleAction *m_showHistoryAction;
192 193 194
    SliderAction *m_sliderAction;
    KToggleAction *m_randomPlayAction;
    KToggleAction *m_toggleSystemTrayAction;
195
    KToggleAction *m_toggleDockOnCloseAction;
196
    KToggleAction *m_togglePopupsAction;
197
    KToggleAction *m_toggleSplashAction;
198
    KSelectAction *m_outputSelectAction;
199
    KActionMenu *m_guessMenu;
200

201
    KToolBarPopupAction *m_backAction;
202
    KToggleAction *m_loopPlaylistAction;
203 204 205

    QTimer *m_playTimer;
    Player *m_player;
206
    KGlobalAccel *m_accel;
207 208 209

    bool m_trackPositionDragging;
    bool m_noSeek;
210
    bool m_startDocked;
211
    bool m_showSplash;
212
    bool m_shuttingDown;
Scott Wheeler's avatar
Scott Wheeler committed
213
    bool m_muted;
214

215
    static const int m_pollInterval = 800;
216 217 218
};

#endif