| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2002-2009 Mark Kretschmann <kretschmann@kde.org> * |
| 3 |
* Copyright (c) 2002 Max Howell <max.howell@methylblue.com> * |
| 4 |
* * |
| 5 |
* This program is free software; you can redistribute it and/or modify it under * |
| 6 |
* the terms of the GNU General Public License as published by the Free Software * |
| 7 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 8 |
* version. * |
| 9 |
* * |
| 10 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 11 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 12 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 13 |
* * |
| 14 |
* You should have received a copy of the GNU General Public License along with * |
| 15 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 16 |
****************************************************************************************/ |
| 17 |
|
| 18 |
#ifndef MAINWINDOW_H |
| 19 |
#define MAINWINDOW_H |
| 20 |
|
| 21 |
#include <config-amarok.h> |
| 22 |
|
| 23 |
#include "amarok_export.h" |
| 24 |
#include "core/meta/Meta.h" |
| 25 |
#include "core/engine/EngineObserver.h" |
| 26 |
#include "browsers/BrowserDock.h" |
| 27 |
|
| 28 |
#include <KMainWindow> |
| 29 |
#include <KVBox> |
| 30 |
|
| 31 |
#include <QPointer> |
| 32 |
|
| 33 |
class CollectionWidget; |
| 34 |
class SlimToolbar; |
| 35 |
class MainToolbar; |
| 36 |
class MainWindow; |
| 37 |
#ifdef DEBUG_BUILD_TYPE |
| 38 |
class NetworkAccessViewer; |
| 39 |
#endif // DEBUG_BUILD_TYPE |
| 40 |
class PlaylistFileProvider; |
| 41 |
|
| 42 |
namespace PlaylistBrowserNS { class PlaylistBrowser; } |
| 43 |
namespace Playlist { class Dock; } |
| 44 |
class ContextDock; |
| 45 |
|
| 46 |
|
| 47 |
class KMenu; |
| 48 |
class QMenuBar; |
| 49 |
class QSplitter; |
| 50 |
class QTimer; |
| 51 |
|
| 52 |
namespace The { |
| 53 |
AMAROK_EXPORT MainWindow* mainWindow(); |
| 54 |
} |
| 55 |
|
| 56 |
//This should only change if docks or toolbars are added or removed |
| 57 |
#define LAYOUT_VERSION 3 |
| 58 |
|
| 59 |
/** |
| 60 |
* @class MainWindow |
| 61 |
* @short The MainWindow widget class. |
| 62 |
* |
| 63 |
* This is the main window widget. |
| 64 |
*/ |
| 65 |
class AMAROK_EXPORT MainWindow : public KMainWindow, public Engine::EngineObserver, public Meta::Observer |
| 66 |
{ |
| 67 |
friend MainWindow* The::mainWindow(); |
| 68 |
|
| 69 |
Q_OBJECT |
| 70 |
|
| 71 |
public: |
| 72 |
MainWindow(); |
| 73 |
~MainWindow(); |
| 74 |
|
| 75 |
//allows us to switch browsers from within other browsers etc |
| 76 |
void showBrowser( const QString& name ); |
| 77 |
void addBrowser( const QString &name, QWidget *widget, const QString &text, const QString &icon ); |
| 78 |
|
| 79 |
//takes into account minimized, multiple desktops, etc. |
| 80 |
bool isReallyShown() const; |
| 81 |
|
| 82 |
void activate(); |
| 83 |
|
| 84 |
BrowserDock *browserDock() const { return m_browserDock; } |
| 85 |
QPointer<KMenu> ToolsMenu() const { return m_toolsMenu; } |
| 86 |
QPointer<KMenu> SettingsMenu() const { return m_settingsMenu; } |
| 87 |
Playlist::Dock * playlistDock() const { return m_playlistDock; } |
| 88 |
void deleteBrowsers(); |
| 89 |
|
| 90 |
/* Reimplemented from QMainWindow to allow only one active toolbar at any time */ |
| 91 |
virtual QMenu* createPopupMenu(); |
| 92 |
|
| 93 |
QString activeBrowserName(); |
| 94 |
|
| 95 |
CollectionWidget * collectionBrowser(); |
| 96 |
PlaylistBrowserNS::PlaylistBrowser * playlistBrowser(); |
| 97 |
|
| 98 |
//will return the size of the rect defined top, right and left by the main toolbar and bottom by the context view. |
| 99 |
QSize backgroundSize() const; |
| 100 |
|
| 101 |
QRect contextRectGlobal() const; |
| 102 |
QPoint globalBackgroundOffset(); |
| 103 |
|
| 104 |
bool isLayoutLocked() const; |
| 105 |
|
| 106 |
/** |
| 107 |
* If an audiocd collection is present. Stop current playback, clear playlist, |
| 108 |
* add cd to playlist and start playback |
| 109 |
*/ |
| 110 |
bool playAudioCd(); |
| 111 |
|
| 112 |
bool isWaitingForCd() const; |
| 113 |
|
| 114 |
signals: |
| 115 |
void loveTrack( Meta::TrackPtr track ); |
| 116 |
void banTrack(); |
| 117 |
void skipTrack(); |
| 118 |
void switchQueueStateShortcut(); |
| 119 |
|
| 120 |
public slots: |
| 121 |
void showHide(); |
| 122 |
void slotFullScreen(); |
| 123 |
void slotLoveTrack(); |
| 124 |
void showNotificationPopup(); |
| 125 |
|
| 126 |
void setLayoutLocked( bool locked ); |
| 127 |
|
| 128 |
void showAbout(); |
| 129 |
void showReportBug(); |
| 130 |
|
| 131 |
protected: |
| 132 |
//Reimplemented from EngineObserver |
| 133 |
virtual void engineStateChanged( Phonon::State state, Phonon::State oldState = Phonon::StoppedState ); |
| 134 |
virtual void engineNewTrackPlaying(); |
| 135 |
|
| 136 |
//Reimplemented from Meta::Observer |
| 137 |
using Observer::metadataChanged; |
| 138 |
virtual void metadataChanged( Meta::TrackPtr track ); |
| 139 |
|
| 140 |
private slots: |
| 141 |
void exportPlaylist() const; |
| 142 |
void slotShowActiveTrack() const; |
| 143 |
void slotShowBookmarkManager() const; |
| 144 |
void slotShowEqualizer() const; |
| 145 |
void slotShowCoverManager() const; |
| 146 |
void slotPlayMedia(); |
| 147 |
void slotAddLocation( bool directPlay = false ); |
| 148 |
void slotAddStream(); |
| 149 |
void slotJumpTo(); |
| 150 |
void showScriptSelector(); |
| 151 |
#ifdef DEBUG_BUILD_TYPE |
| 152 |
void showNetworkRequestViewer(); |
| 153 |
#endif // DEBUG_BUILD_TYPE |
| 154 |
|
| 155 |
/** |
| 156 |
* Save state and position of dock widgets. |
| 157 |
*/ |
| 158 |
void saveLayout(); |
| 159 |
|
| 160 |
/** |
| 161 |
* Try to restore saved layout, if this fails, try to use the default layout. |
| 162 |
*/ |
| 163 |
void restoreLayout(); |
| 164 |
|
| 165 |
protected: |
| 166 |
bool eventFilter(QObject *, QEvent *); |
| 167 |
virtual void closeEvent( QCloseEvent* ); |
| 168 |
virtual void showEvent( QShowEvent* event ); |
| 169 |
virtual void keyPressEvent( QKeyEvent* ); |
| 170 |
virtual void resizeEvent ( QResizeEvent * event ); |
| 171 |
virtual void paletteChange( const QPalette & oldPalette ); |
| 172 |
virtual bool queryExit(); |
| 173 |
|
| 174 |
private slots: |
| 175 |
void setRating1() { setRating( 1 ); } |
| 176 |
void setRating2() { setRating( 2 ); } |
| 177 |
void setRating3() { setRating( 3 ); } |
| 178 |
void setRating4() { setRating( 4 ); } |
| 179 |
void setRating5() { setRating( 5 ); } |
| 180 |
|
| 181 |
private: |
| 182 |
void init(); |
| 183 |
void setRating( int n ); |
| 184 |
void showBrowser( const int index ); |
| 185 |
|
| 186 |
CollectionWidget * m_collectionBrowser; |
| 187 |
PlaylistBrowserNS::PlaylistBrowser * m_playlistBrowser; |
| 188 |
|
| 189 |
QPointer<QMenuBar> m_menubar; |
| 190 |
QPointer<KMenu> m_toolsMenu; |
| 191 |
QPointer<KMenu> m_settingsMenu; |
| 192 |
QPointer<BrowserDock> m_browserDock; |
| 193 |
QStringList m_browserNames; |
| 194 |
QPointer<KMenu> m_searchMenu; |
| 195 |
//QPointer<KVBox> m_statusbarArea; |
| 196 |
|
| 197 |
QPointer<QTimer> m_timer; //search filter timer |
| 198 |
QPointer<QSplitter> m_splitter; |
| 199 |
#ifdef DEBUG_BUILD_TYPE |
| 200 |
QPointer<NetworkAccessViewer> m_networkViewer; |
| 201 |
#endif // DEBUG_BUILD_TYPE |
| 202 |
|
| 203 |
QByteArray m_splitterState; |
| 204 |
|
| 205 |
Meta::TrackPtr m_currentTrack; |
| 206 |
|
| 207 |
ContextDock * m_contextDock; |
| 208 |
Playlist::Dock * m_playlistDock; |
| 209 |
|
| 210 |
QPointer<SlimToolbar> m_slimToolbar; |
| 211 |
QPointer<MainToolbar> m_mainToolbar; |
| 212 |
|
| 213 |
void createActions(); |
| 214 |
void createMenus(); |
| 215 |
int m_lastBrowser; |
| 216 |
int m_searchField; |
| 217 |
|
| 218 |
static QPointer<MainWindow> s_instance; |
| 219 |
|
| 220 |
bool m_layoutLocked; |
| 221 |
bool m_layoutEverRestored; |
| 222 |
|
| 223 |
bool m_waitingForCd; |
| 224 |
|
| 225 |
// Layout hack ----------------- |
| 226 |
typedef struct Ratio { |
| 227 |
float x,y; |
| 228 |
} Ratio; |
| 229 |
Ratio m_browserRatio; |
| 230 |
Ratio m_contextRatio; |
| 231 |
Ratio m_playlistRatio; |
| 232 |
QRect m_dockingRect; |
| 233 |
bool m_mouseDown; |
| 234 |
bool m_LH_initialized; |
| 235 |
QTimer * m_saveLayoutChangesTimer; |
| 236 |
|
| 237 |
bool LH_isIrrelevant( const QDockWidget *dock ); |
| 238 |
QTabBar *LH_dockingTabbar(); |
| 239 |
void LH_extend( QRect &target, const QDockWidget *dock ); |
| 240 |
QSize LH_desiredSize( QDockWidget *dock, const QRect &area, float rx, float ry, int splitter ); |
| 241 |
bool LH_fuzzyMatch( const QSize &sz1, const QSize &sz2 ); |
| 242 |
bool LH_isConstrained( const QDockWidget *dock ); |
| 243 |
|
| 244 |
private slots: |
| 245 |
void updateDockRatio(); |
| 246 |
void updateDockRatio(QDockWidget*); |
| 247 |
void initLayoutHack(); |
| 248 |
// ------------------------------ |
| 249 |
}; |
| 250 |
|
| 251 |
|
| 252 |
#endif //AMAROK_PLAYLISTWINDOW_H |