?? playlistwindow.cpp
字號:
/*************************************************************************** begin : Fre Nov 15 2002 copyright : (C) Mark Kretschmann <markey@web.de> : (C) Max Howell <max.howell@methylblue.com> : (C) G??bor Lehel <illissius@gmail.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. * * * ***************************************************************************/#include "config.h" //HAVE_LIBVISUAL definition#include "actionclasses.h" //see toolbar construction#include "amarok.h"#include "amarokconfig.h"#include "browserbar.h"#include "clicklineedit.h" //m_lineEdit#include "collectionbrowser.h"#include "contextbrowser.h"#include "debug.h"#include "mediadevicemanager.h"#include "editfilterdialog.h"#include "enginecontroller.h" //for actions in ctor#include "filebrowser.h"#include "k3bexporter.h"#include "lastfm.h" //check credentials when adding lastfm streams#include "mediabrowser.h"#include "dynamicmode.h"#include "playlist.h"#include "playlistbrowser.h"#include "playlistwindow.h"#include "scriptmanager.h"#include "statistics.h"#include "statusbar.h"#include "threadmanager.h"#include "magnatunebrowser/magnatunebrowser.h"#include <qevent.h> //eventFilter()#include <qfont.h>#include <qheader.h>#include <qlayout.h>#include <qlabel.h> //search filter label#include <qpainter.h> //dynamic title#include <qpen.h>#include <qsizepolicy.h> //qspaceritem in dynamic bar#include <qtimer.h> //search filter timer#include <qtooltip.h> //QToolTip::add()#include <qvbox.h> //contains the playlist#include <kaction.h> //m_actionCollection#include <kapplication.h> //kapp#include <kfiledialog.h> //savePlaylist(), openPlaylist()#include <kglobal.h>#include <khtml_part.h> //Welcome Tab#include <kiconloader.h> //ClearFilter button#include <kinputdialog.h> //slotAddStream()#include <klocale.h>#include <kmenubar.h>#include <kmessagebox.h> //savePlaylist()#include <kpopupmenu.h>#include <kpushbutton.h>#include <kstandarddirs.h> //Welcome Tab, locate welcome.html#include <ktoolbar.h>#include <ktoolbarbutton.h> //createGUI()#include <kxmlguibuilder.h> //XMLGUI#include <kxmlguifactory.h> //XMLGUI#include <fixx11h.h>///////////////////////////////////////////////////////////////////////////////////////////// CLASS Amarok::ToolBar//////////////////////////////////////////////////////////////////////////////////////////namespace Amarok{ class ToolBar : public KToolBar { public: ToolBar( QWidget *parent, const char *name ) : KToolBar( parent, name ) {} protected: virtual void contextMenuEvent( QContextMenuEvent *e ) { Amarok::Menu::instance()->popup( e->globalPos() ); } virtual void wheelEvent( QWheelEvent *e ) { EngineController::instance()->increaseVolume( e->delta() / Amarok::VOLUME_SENSITIVITY ); } };}PlaylistWindow *PlaylistWindow::s_instance = 0;PlaylistWindow::PlaylistWindow() : QWidget( 0, "PlaylistWindow", Qt::WGroupLeader ) , KXMLGUIClient() , m_lastBrowser( 0 ){ s_instance = this; // Sets caption and icon correctly (needed e.g. for GNOME) kapp->setTopWidget( this ); KActionCollection* const ac = actionCollection(); const EngineController* const ec = EngineController::instance(); ac->setAutoConnectShortcuts( false ); ac->setWidget( this ); new K3bExporter(); KStdAction::configureToolbars( kapp, SLOT( slotConfigToolBars() ), ac ); KStdAction::keyBindings( kapp, SLOT( slotConfigShortcuts() ), ac ); KStdAction::keyBindings( kapp, SLOT( slotConfigGlobalShortcuts() ), ac, "options_configure_globals" ); KStdAction::preferences( kapp, SLOT( slotConfigAmarok() ), ac ); ac->action("options_configure_globals")->setIcon( Amarok::icon( "configure" ) ); ac->action(KStdAction::name(KStdAction::KeyBindings))->setIcon( Amarok::icon( "configure" ) ); ac->action(KStdAction::name(KStdAction::ConfigureToolbars))->setIcon( Amarok::icon( "configure" ) ); ac->action(KStdAction::name(KStdAction::Preferences))->setIcon( Amarok::icon( "configure" ) ); KStdAction::quit( kapp, SLOT( quit() ), ac ); KStdAction::open( this, SLOT(slotAddLocation()), ac, "playlist_add" )->setText( i18n("&Add Media...") ); ac->action( "playlist_add" )->setIcon( Amarok::icon( "files" ) ); KStdAction::open( this, SLOT(slotAddStream()), ac, "stream_add" )->setText( i18n("&Add Stream...") ); ac->action( "stream_add" )->setIcon( Amarok::icon( "files" ) ); KStdAction::save( this, SLOT(savePlaylist()), ac, "playlist_save" )->setText( i18n("&Save Playlist As...") ); ac->action( "playlist_save" )->setIcon( Amarok::icon( "save" ) ); //FIXME: after string freeze rename to "Burn Current Playlist"? new KAction( i18n("Burn to CD"), Amarok::icon( "burn" ), 0, this, SLOT(slotBurnPlaylist()), ac, "playlist_burn" ); actionCollection()->action("playlist_burn")->setEnabled( K3bExporter::isAvailable() ); new KAction( i18n("Play Media..."), Amarok::icon( "files" ), 0, this, SLOT(slotPlayMedia()), ac, "playlist_playmedia" ); new KAction( i18n("Play Audio CD"), Amarok::icon( "album" ), 0, this, SLOT(playAudioCD()), ac, "play_audiocd" ); KAction *playPause = new KAction( i18n( "&Play/Pause" ), Amarok::icon( "play" ), Key_Space, ec, SLOT( playPause() ), ac, "play_pause" ); new KAction( i18n("Script Manager"), Amarok::icon( "scripts" ), 0, this, SLOT(showScriptSelector()), ac, "script_manager" ); new KAction( i18n("Queue Manager"), Amarok::icon( "queue" ), 0, this, SLOT(showQueueManager()), ac, "queue_manager" ); KAction *seekForward = new KAction( i18n( "&Seek Forward" ), Amarok::icon( "fastforward" ), Key_Right, ec, SLOT( seekForward() ), ac, "seek_forward" ); KAction *seekBackward = new KAction( i18n( "&Seek Backward" ), Amarok::icon( "rewind" ), Key_Left, ec, SLOT( seekBackward() ), ac, "seek_backward" ); new KAction( i18n("Statistics"), Amarok::icon( "info" ), 0, this, SLOT(showStatistics()), ac, "statistics" ); new KAction( i18n("Update Collection"), Amarok::icon( "refresh" ), 0, CollectionDB::instance(), SLOT( scanModifiedDirs() ), actionCollection(), "update_collection" ); m_lastfmTags << "Alternative" << "Ambient" << "Chill Out" << "Classical" << "Dance" << "Electronica" << "Favorites" << "Heavy Metal" << "Hip Hop" << "Indie Rock" << "Industrial" << "Japanese" << "Pop" << "Psytrance" << "Rap" << "Rock" << "Soundtrack" << "Techno" << "Trance"; KPopupMenu* playTagRadioMenu = new KPopupMenu( this ); int id = 0; foreach( m_lastfmTags ) { playTagRadioMenu->insertItem( *it, this, SLOT( playLastfmGlobaltag( int ) ), 0, id ); ++id; } KPopupMenu* addTagRadioMenu = new KPopupMenu( this ); id = 0; foreach( m_lastfmTags ) { addTagRadioMenu->insertItem( *it, this, SLOT( addLastfmGlobaltag( int ) ), 0, id ); ++id; } KActionMenu* playLastfm = new KActionMenu( i18n( "Play las&t.fm Stream" ), Amarok::icon( "audioscrobbler" ), ac, "lastfm_play" ); QPopupMenu* playLastfmMenu = playLastfm->popupMenu(); playLastfmMenu->insertItem( i18n( "Personal Radio" ), this, SLOT( playLastfmPersonal() ) ); playLastfmMenu->insertItem( i18n( "Neighbor Radio" ), this, SLOT( playLastfmNeighbor() ) ); playLastfmMenu->insertItem( i18n( "Custom Station" ), this, SLOT( playLastfmCustom() ) ); playLastfmMenu->insertItem( i18n( "Global Tag Radio" ), playTagRadioMenu ); KActionMenu* addLastfm = new KActionMenu( i18n( "Add las&t.fm Stream" ), Amarok::icon( "audioscrobbler" ), ac, "lastfm_add" ); QPopupMenu* addLastfmMenu = addLastfm->popupMenu(); addLastfmMenu->insertItem( i18n( "Personal Radio" ), this, SLOT( addLastfmPersonal() ) ); addLastfmMenu->insertItem( i18n( "Neighbor Radio" ), this, SLOT( addLastfmNeighbor() ) ); addLastfmMenu->insertItem( i18n( "Custom Station" ), this, SLOT( addLastfmCustom() ) ); addLastfmMenu->insertItem( i18n( "Global Tag Radio" ), addTagRadioMenu ); ac->action( "options_configure_globals" )->setText( i18n( "Configure &Global Shortcuts..." ) ); new KAction( i18n( "Previous Track" ), Amarok::icon( "back" ), 0, ec, SLOT( previous() ), ac, "prev" ); new KAction( i18n( "Play" ), Amarok::icon( "play" ), 0, ec, SLOT( play() ), ac, "play" ); new KAction( i18n( "Pause" ), Amarok::icon( "pause" ), 0, ec, SLOT( pause() ), ac, "pause" ); new KAction( i18n( "Next Track" ), Amarok::icon( "next" ), 0, ec, SLOT( next() ), ac, "next" ); KAction *toggleFocus = new KAction( i18n( "Toggle Focus" ), "reload", CTRL+Key_Tab, this, SLOT( slotToggleFocus() ), ac, "toggle_focus" ); { // KAction idiocy -- shortcuts don't work until they've been plugged into a menu KPopupMenu asdf; playPause->plug( &asdf ); seekForward->plug( &asdf ); seekBackward->plug( &asdf ); toggleFocus->plug( &asdf ); playPause->unplug( &asdf ); seekForward->unplug( &asdf ); seekBackward->unplug( &asdf ); toggleFocus->unplug( &asdf ); } new Amarok::MenuAction( ac ); new Amarok::StopAction( ac ); new Amarok::PlayPauseAction( ac ); new Amarok::AnalyzerAction( ac ); new Amarok::RepeatAction( ac ); new Amarok::RandomAction( ac ); new Amarok::FavorAction( ac ); new Amarok::VolumeAction( ac ); if( K3bExporter::isAvailable() ) new Amarok::BurnMenuAction( ac ); if( AmarokConfig::playlistWindowSize().isValid() ) { // if first ever run, use sizeHint(), and let // KWin place us otherwise use the stored values resize( AmarokConfig::playlistWindowSize() ); move( AmarokConfig::playlistWindowPos() ); }}PlaylistWindow::~PlaylistWindow(){ AmarokConfig::setPlaylistWindowPos( pos() ); //TODO de XT? AmarokConfig::setPlaylistWindowSize( size() ); //TODO de XT?}///////// public interface/** * This function will initialize the playlist window. */void PlaylistWindow::init(){ DEBUG_BLOCK //this function is necessary because Amarok::actionCollection() returns our actionCollection //via the App::m_pPlaylistWindow pointer since App::m_pPlaylistWindow is not defined until //the above ctor returns it causes a crash unless we do the initialisation in 2 stages. m_browsers = new BrowserBar( this ); //<Dynamic Mode Status Bar /> DynamicBar *dynamicBar = new DynamicBar( m_browsers->container()); QFrame *playlist; { //<Search LineEdit> KToolBar *bar = new KToolBar( m_browsers->container(), "NotMainToolBar" ); bar->setIconSize( 22, false ); //looks more sensible bar->setFlat( true ); //removes the ugly frame bar->setMovingEnabled( false ); //removes the ugly frame playlist = new Playlist( m_browsers->container() ); actionCollection()->action( "playlist_clear")->plug( bar ); actionCollection()->action( "playlist_save")->plug( bar ); bar->addSeparator(); actionCollection()->action( "playlist_undo")->plug( bar ); actionCollection()->action( "playlist_redo")->plug( bar ); bar->boxLayout()->addStretch(); QWidget *button = new KToolBarButton( "locationbar_erase", 1, bar ); QLabel *filter_label = new QLabel( i18n("S&earch:") + ' ', bar ); m_lineEdit = new ClickLineEdit( i18n( "Playlist Search" ), bar ); filter_label->setBuddy( m_lineEdit ); bar->setStretchableWidget( m_lineEdit ); KPushButton *filterButton = new KPushButton("...", bar, "filter"); filterButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ); m_lineEdit->setFrame( QFrame::Sunken ); m_lineEdit->installEventFilter( this ); //we intercept keyEvents connect( button, SIGNAL(clicked()), m_lineEdit, SLOT(clear()) ); connect( m_lineEdit, SIGNAL(textChanged( const QString& )), playlist, SLOT(setFilterSlot( const QString& )) ); connect( filterButton, SIGNAL( clicked() ), SLOT( slotEditFilter() ) ); QToolTip::add( button, i18n( "Clear search field" ) ); QString filtertip = i18n( "Enter space-separated terms to search in the playlist.\n\n" "Advanced, Google-esque syntax is also available;\n" "see the handbook (The Playlist section of chapter 4) for details." ); QToolTip::add( m_lineEdit, filtertip ); QToolTip::add( filterButton, i18n( "Click to edit playlist filter" ) ); } //</Search LineEdit> dynamicBar->init(); m_toolbar = new Amarok::ToolBar( m_browsers->container(), "mainToolBar" );#ifndef Q_WS_MAC m_toolbar->setShown( AmarokConfig::showToolbar() );#endif QWidget *statusbar = new Amarok::StatusBar( this ); KAction* repeatAction = Amarok::actionCollection()->action( "repeat" ); connect( repeatAction, SIGNAL( activated( int ) ), playlist, SLOT( slotRepeatTrackToggled( int ) ) ); m_menubar = new KMenuBar( this );
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -