?? amarokdcophandler.cpp
字號:
/*************************************************************************** amarokdcophandler.cpp - DCOP Implementation ------------------- begin : Sat Oct 11 2003 copyright : (C) 2003 by Stanislav Karchebny (C) 2004 Christian Muehlhaeuser (C) 2005 Ian Monroe (C) 2005 Seb Ruiz (C) 2006 Alexandre Oliveira email : berkus@users.sf.net***************************************************************************//*************************************************************************** * * * 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 "amarok.h"#include "amarokconfig.h"#include "amarokdcophandler.h"#include "app.h" //transferCliArgs#include "debug.h"#include "collectiondb.h"#include "contextbrowser.h"#include "devicemanager.h"#include "enginebase.h"#include "enginecontroller.h"#include "equalizersetup.h"#include "htmlview.h"#include "mediabrowser.h"#include "mountpointmanager.h"#include "osd.h"#include "playlist.h"#include "playlistbrowser.h"#include "playlistitem.h"#include "playlistwindow.h"#include "scancontroller.h"#include "scriptmanager.h"#include "statusbar.h"#include "lastfm.h"#include <qfile.h>#include <dcopclient.h>#include <kactioncollection.h>#include <kstartupinfo.h>namespace Amarok{/////////////////////////////////////////////////////////////////////////////////////// class DcopPlayerHandler///////////////////////////////////////////////////////////////////////////////////// DcopPlayerHandler::DcopPlayerHandler() : DCOPObject( "player" ) , QObject( kapp ) { // Register with DCOP if ( !kapp->dcopClient()->isRegistered() ) { kapp->dcopClient()->registerAs( "amarok", false ); kapp->dcopClient()->setDefaultObject( objId() ); } } QString DcopPlayerHandler::version() { return APP_VERSION; } bool DcopPlayerHandler::dynamicModeStatus() { return Amarok::dynamicMode(); } bool DcopPlayerHandler::equalizerEnabled() { if(EngineController::hasEngineProperty( "HasEqualizer" )) return AmarokConfig::equalizerEnabled(); else return false; } bool DcopPlayerHandler::osdEnabled() { return AmarokConfig::osdEnabled(); } bool DcopPlayerHandler::isPlaying() { return EngineController::engine()->state() == Engine::Playing; } bool DcopPlayerHandler::randomModeStatus() { return AmarokConfig::randomMode(); } bool DcopPlayerHandler::repeatPlaylistStatus() { return Amarok::repeatPlaylist(); } bool DcopPlayerHandler::repeatTrackStatus() { return Amarok::repeatTrack(); } int DcopPlayerHandler::getVolume() { return EngineController::engine() ->volume(); } int DcopPlayerHandler::sampleRate() { return EngineController::instance()->bundle().sampleRate(); } float DcopPlayerHandler::score() { const MetaBundle &bundle = EngineController::instance()->bundle(); float score = CollectionDB::instance()->getSongPercentage( bundle.url().path() ); return score; } int DcopPlayerHandler::rating() { const MetaBundle &bundle = EngineController::instance()->bundle(); int rating = CollectionDB::instance()->getSongRating( bundle.url().path() ); return rating; } int DcopPlayerHandler::status() { // <0 - error, 0 - stopped, 1 - paused, 2 - playing switch( EngineController::engine()->state() ) { case Engine::Playing: return 2; case Engine::Paused: return 1; case Engine::Empty: case Engine::Idle: return 0; } return -1; } int DcopPlayerHandler::trackCurrentTime() { return EngineController::instance()->trackPosition() / 1000; } int DcopPlayerHandler::trackCurrentTimeMs() { return EngineController::instance()->trackPosition(); } int DcopPlayerHandler::trackPlayCounter() { const MetaBundle &bundle = EngineController::instance()->bundle(); int count = CollectionDB::instance()->getPlayCount( bundle.url().path() ); return count; } int DcopPlayerHandler::trackTotalTime() { return EngineController::instance()->bundle().length(); } QStringList DcopPlayerHandler::labels() { const MetaBundle &bundle = EngineController::instance()->bundle(); return CollectionDB::instance()->getLabels( bundle.url().path(), CollectionDB::typeUser ); } QString DcopPlayerHandler::album() { return EngineController::instance()->bundle().album(); } QString DcopPlayerHandler::artist() { return EngineController::instance()->bundle().artist(); } QString DcopPlayerHandler::bitrate() { return EngineController::instance()->bundle().prettyBitrate(); } QString DcopPlayerHandler::comment() { return EngineController::instance()->bundle().comment(); } QString DcopPlayerHandler::coverImage() { const MetaBundle &bundle = EngineController::instance()->bundle(); QString image = CollectionDB::instance()->albumImage( bundle, 0 ); return image; } QString DcopPlayerHandler::currentTime() { return MetaBundle::prettyLength( EngineController::instance()->trackPosition() / 1000 ,true ); } QString DcopPlayerHandler::encodedURL() { return EngineController::instance()->bundle().url().url(); } QString DcopPlayerHandler::engine() { return AmarokConfig::soundSystem(); } QString DcopPlayerHandler::genre() { return EngineController::instance()->bundle().genre(); } QString DcopPlayerHandler::lyrics() { return CollectionDB::instance()->getLyrics( EngineController::instance()->bundle().url().path() ); } QString DcopPlayerHandler::lyricsByPath( QString path ) { return CollectionDB::instance()->getLyrics( path ); } QString DcopPlayerHandler::lastfmStation() { return LastFm::Controller::stationDescription(); //return QString::null if not playing } QString DcopPlayerHandler::nowPlaying() { return EngineController::instance()->bundle().prettyTitle(); } QString DcopPlayerHandler::path() { return EngineController::instance()->bundle().url().path(); } QString DcopPlayerHandler::setContextStyle(const QString& msg) { AmarokConfig::setContextBrowserStyleSheet( msg ); ContextBrowser::instance()->reloadStyleSheet(); if ( QFile::exists( Amarok::saveLocation( "themes/" + msg + '/' ) + "stylesheet.css" ) ) return "Context browser theme '"+msg+"' applied."; else return "No such theme '"+msg+"' exists, default theme applied."; } QString DcopPlayerHandler::title() { return EngineController::instance()->bundle().title(); } QString DcopPlayerHandler::totalTime() { return EngineController::instance()->bundle().prettyLength(); } QString DcopPlayerHandler::track() { if ( EngineController::instance()->bundle().track() != 0 ) return QString::number( EngineController::instance()->bundle().track() ); else return QString(); } QString DcopPlayerHandler::type() { if (EngineController::instance()->bundle().url().protocol() == "lastfm") return QString("LastFm Stream"); else return EngineController::instance()->bundle().type(); } QString DcopPlayerHandler::year() { return QString::number( EngineController::instance()->bundle().year() ); } void DcopPlayerHandler::configEqualizer() { if(EngineController::hasEngineProperty( "HasEqualizer" )) EqualizerSetup::instance()->show(); EqualizerSetup::instance()->raise(); } void DcopPlayerHandler::enableOSD(bool enable) { Amarok::OSD::instance()->setEnabled( enable ); AmarokConfig::setOsdEnabled( enable ); } void DcopPlayerHandler::enableRandomMode( bool enable ) { static_cast<KSelectAction*>(Amarok::actionCollection()->action( "random_mode" )) ->setCurrentItem( enable ? AmarokConfig::EnumRandomMode::Tracks : AmarokConfig::EnumRandomMode::Off ); } void DcopPlayerHandler::enableRepeatPlaylist( bool enable ) { static_cast<KSelectAction*>( Amarok::actionCollection()->action( "repeat" ) ) ->setCurrentItem( enable ? AmarokConfig::EnumRepeat::Playlist : AmarokConfig::EnumRepeat::Off ); } void DcopPlayerHandler::enableRepeatTrack( bool enable) { static_cast<KSelectAction*>( Amarok::actionCollection()->action( "repeat" ) ) ->setCurrentItem( enable ? AmarokConfig::EnumRepeat::Track : AmarokConfig::EnumRepeat::Off ); } void DcopPlayerHandler::mediaDeviceMount() { if ( MediaBrowser::instance()->currentDevice() ) MediaBrowser::instance()->currentDevice()->connectDevice(); } void DcopPlayerHandler::mediaDeviceUmount() { if ( MediaBrowser::instance()->currentDevice() ) MediaBrowser::instance()->currentDevice()->disconnectDevice(); } void DcopPlayerHandler::mute() { EngineController::instance()->mute(); } void DcopPlayerHandler::next() { EngineController::instance() ->next(); } void DcopPlayerHandler::pause() { EngineController::instance()->pause(); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -