elisaapplication.cpp 23.6 KB
Newer Older
1
/*
Matthieu Gallien's avatar
Matthieu Gallien committed
2 3 4 5
   SPDX-FileCopyrightText: 2017 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
   SPDX-FileCopyrightText: 2012 (c) Aleix Pol Gonzalez <aleixpol@blue-systems.com>

   SPDX-License-Identifier: LGPL-3.0-or-later
6 7 8
 */

#include "elisaapplication.h"
9 10

#include "musiclistenersmanager.h"
11

12
#include "mediaplaylist.h"
13
#include "mediaplaylistproxymodel.h"
Alexander Stippich's avatar
Alexander Stippich committed
14
#include "audiowrapper.h"
Alexander Stippich's avatar
Alexander Stippich committed
15
#include "manageaudioplayer.h"
16 17
#include "managemediaplayercontrol.h"
#include "manageheaderbar.h"
18
#include "databaseinterface.h"
19

20
#include "elisa_settings.h"
21
#include <KConfigCore/KAuthorized>
22
#include <KLocalizedString>
23 24 25

#if defined KF5ConfigWidgets_FOUND && KF5ConfigWidgets_FOUND
#include <KConfigWidgets/KStandardAction>
26
#endif
27

28
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
29
#include <KXmlGui/KActionCollection>
30 31 32 33 34 35
#include <KXmlGui/KAboutApplicationDialog>
#include <KXmlGui/KHelpMenu>
#include <KXmlGui/KBugReport>
#include <KXmlGui/KShortcutsDialog>
#endif

36
#include <KColorSchemeManager>
37
#include <KCoreAddons/KAboutData>
38
#include <KIO/OpenFileManagerWindowJob>
39

40 41
#include <QQmlEngine>
#include <QQmlComponent>
42
#include <QGuiApplication>
43 44 45 46 47 48
#include <QDesktopServices>
#include <QDialog>
#include <QPointer>
#include <QIcon>
#include <QAction>
#include <QUrl>
49 50
#include <QFileInfo>
#include <QDir>
51
#include <QFileSystemWatcher>
52
#include <QKeyEvent>
53
#include <QDebug>
54
#include <QFileSystemWatcher>
55

56 57
#include <memory>

58 59 60 61 62
class ElisaApplicationPrivate
{
public:

    explicit ElisaApplicationPrivate(QObject *parent)
63
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
64 65
        : mCollection(parent)
    #endif
66
    {
67
        Q_UNUSED(parent)
68 69
    }

70
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
71
    KActionCollection mCollection;
72
#endif
73

74
    DataTypes::EntryDataList mArguments;
75

76 77 78 79
    std::unique_ptr<MusicListenersManager> mMusicManager;

    std::unique_ptr<MediaPlayList> mMediaPlayList;

80 81
    std::unique_ptr<MediaPlayListProxyModel> mMediaPlayListProxyModel;

Alexander Stippich's avatar
Alexander Stippich committed
82 83
    std::unique_ptr<AudioWrapper> mAudioWrapper;

Alexander Stippich's avatar
Alexander Stippich committed
84 85
    std::unique_ptr<ManageAudioPlayer> mAudioControl;

86 87 88 89
    std::unique_ptr<ManageMediaPlayerControl> mPlayerControl;

    std::unique_ptr<ManageHeaderBar> mManageHeaderBar;

90
    QQmlEngine *mEngine = nullptr;
91

92 93
    QFileSystemWatcher mConfigFileWatcher;

94
    KColorSchemeManager *mSchemes;
95 96 97
};

ElisaApplication::ElisaApplication(QObject *parent) : QObject(parent), d(std::make_unique<ElisaApplicationPrivate>(this))
98
{
99 100 101 102 103 104
    auto configurationFileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
    configurationFileName += QStringLiteral("/elisarc");
    Elisa::ElisaConfiguration::instance(configurationFileName);
    Elisa::ElisaConfiguration::self()->load();
    Elisa::ElisaConfiguration::self()->save();

105 106
    d->mSchemes = new KColorSchemeManager(this);

107 108
    d->mConfigFileWatcher.addPath(Elisa::ElisaConfiguration::self()->config()->name());

109 110 111 112 113
    connect(Elisa::ElisaConfiguration::self(), &Elisa::ElisaConfiguration::configChanged,
            this, &ElisaApplication::configChanged);

    connect(&d->mConfigFileWatcher, &QFileSystemWatcher::fileChanged,
            this, &ElisaApplication::configChanged);
114 115 116

    connect(static_cast<QGuiApplication*>(QCoreApplication::instance()), &QGuiApplication::commitDataRequest,
            this, &ElisaApplication::commitDataRequest);
117 118
}

119 120 121
ElisaApplication::~ElisaApplication()
= default;

122 123 124 125 126 127 128 129 130 131
QAbstractItemModel *ElisaApplication::colorSchemesModel()
{
    return d->mSchemes->model();
}

void ElisaApplication::activateColorScheme(const QString &name)
{
    d->mSchemes->activateScheme(d->mSchemes->indexForScheme(name));
}

132
void ElisaApplication::setupActions(const QString &actionName)
133 134
{
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
Laurent Montel's avatar
Laurent Montel committed
135
    if (actionName == QLatin1String("file_quit")) {
136 137 138
        auto quitAction = KStandardAction::quit(QCoreApplication::instance(), &QCoreApplication::quit, &d->mCollection);
        d->mCollection.addAction(actionName, quitAction);
    }
139

Laurent Montel's avatar
Laurent Montel committed
140
    if (actionName == QLatin1String("help_contents") && KAuthorized::authorizeAction(actionName)) {
141 142
        auto handBookAction = KStandardAction::helpContents(this, &ElisaApplication::appHelpActivated, &d->mCollection);
        d->mCollection.addAction(handBookAction->objectName(), handBookAction);
143 144
    }

Laurent Montel's avatar
Laurent Montel committed
145
    if (actionName == QLatin1String("help_report_bug") && KAuthorized::authorizeAction(actionName) && !KAboutData::applicationData().bugAddress().isEmpty()) {
146 147
        auto reportBugAction = KStandardAction::reportBug(this, &ElisaApplication::reportBug, &d->mCollection);
        d->mCollection.addAction(reportBugAction->objectName(), reportBugAction);
148 149
    }

Laurent Montel's avatar
Laurent Montel committed
150
    if (actionName == QLatin1String("help_about_app") && KAuthorized::authorizeAction(actionName)) {
151 152
        auto aboutAppAction = KStandardAction::aboutApp(this, &ElisaApplication::aboutApplication, this);
        d->mCollection.addAction(aboutAppAction->objectName(), aboutAppAction);
153 154
    }

Laurent Montel's avatar
Laurent Montel committed
155
    if (actionName == QLatin1String("options_configure") && KAuthorized::authorizeAction(actionName)) {
156 157
        auto preferencesAction = KStandardAction::preferences(this, &ElisaApplication::configureElisa, this);
        d->mCollection.addAction(preferencesAction->objectName(), preferencesAction);
158 159
    }

Laurent Montel's avatar
Laurent Montel committed
160
    if (actionName == QLatin1String("options_configure_keybinding") && KAuthorized::authorizeAction(actionName)) {
161 162 163 164
        auto keyBindingsAction = KStandardAction::keyBindings(this, &ElisaApplication::configureShortcuts, this);
        d->mCollection.addAction(keyBindingsAction->objectName(), keyBindingsAction);
    }

Laurent Montel's avatar
Laurent Montel committed
165
    if (actionName == QLatin1String("go_back") && KAuthorized::authorizeAction(actionName)) {
166 167
        auto goBackAction = KStandardAction::back(this, &ElisaApplication::goBack, this);
        d->mCollection.addAction(goBackAction->objectName(), goBackAction);
168
    }
169

Laurent Montel's avatar
Laurent Montel committed
170
    if (actionName == QLatin1String("toggle_playlist") && KAuthorized::authorizeAction(actionName)) {
Diego Gangl's avatar
Diego Gangl committed
171 172
        auto togglePlaylistAction = d->mCollection.addAction(actionName, this, &ElisaApplication::togglePlaylist);
        togglePlaylistAction->setShortcut(QKeySequence(Qt::Key_F9));
173
        togglePlaylistAction->setText(i18n("Toggle Playlist"));
Diego Gangl's avatar
Diego Gangl committed
174 175
    }

Laurent Montel's avatar
Laurent Montel committed
176
    if (actionName == QLatin1String("Seek") && KAuthorized::authorizeAction(actionName)) {
177
            auto seekAction = d->mCollection.addAction(actionName, this, &ElisaApplication::seek);
178
            seekAction->setText(i18n("Seek forward 10 seconds"));
179
            d->mCollection.setDefaultShortcut(seekAction, QKeySequence(Qt::SHIFT + Qt::Key_Right));
180 181
    }

Laurent Montel's avatar
Laurent Montel committed
182
    if (actionName == QLatin1String("Scrub") && KAuthorized::authorizeAction(actionName)) {
183
            auto scrubAction = d->mCollection.addAction(actionName, this, &ElisaApplication::scrub);
184
            scrubAction->setText(i18n("Scrub backwards 10 seconds"));
185
            d->mCollection.setDefaultShortcut(scrubAction, QKeySequence(Qt::SHIFT + Qt::Key_Left));
186 187
    }

188 189 190 191 192 193 194 195 196 197 198 199
    if (actionName == QLatin1String("NextTrack") && KAuthorized::authorizeAction(actionName)) {
            auto nextTrackAction = d->mCollection.addAction(actionName, this, &ElisaApplication::nextTrack);
            nextTrackAction->setText(i18n("Go to next track"));
            d->mCollection.setDefaultShortcut(nextTrackAction, QKeySequence(Qt::CTRL + Qt::Key_Left));
    }

    if (actionName == QLatin1String("PreviousTrack") && KAuthorized::authorizeAction(actionName)) {
            auto previousTrackAction = d->mCollection.addAction(actionName, this, &ElisaApplication::previousTrack);
            previousTrackAction->setText(i18n("Go to previous track"));
            d->mCollection.setDefaultShortcut(previousTrackAction, QKeySequence(Qt::CTRL + Qt::Key_Right));
    }

Laurent Montel's avatar
Laurent Montel committed
200
    if (actionName == QLatin1String("Play-Pause") && KAuthorized::authorizeAction(actionName)) {
201
            auto playPauseAction = d->mCollection.addAction(actionName, this, &ElisaApplication::playPause);
202
            playPauseAction->setText(i18n("Play/pause"));
203
            d->mCollection.setDefaultShortcut(playPauseAction, QKeySequence(Qt::Key_Space));
204 205
    }

Laurent Montel's avatar
Laurent Montel committed
206
    if (actionName == QLatin1String("edit_find") && KAuthorized::authorizeAction(actionName)) {
207 208 209 210
        auto findAction = KStandardAction::find(this, &ElisaApplication::find, this);
        d->mCollection.addAction(findAction->objectName(), findAction);
    }

211
    d->mCollection.readSettings();
212 213 214
#endif
}

215
void ElisaApplication::setArguments(const DataTypes::EntryDataList &newArguments)
216 217 218 219 220 221 222
{
    if (d->mArguments == newArguments) {
        return;
    }

    d->mArguments = checkFileListAndMakeAbsolute(newArguments, QDir::currentPath());
    Q_EMIT argumentsChanged();
223 224

    if (!d->mArguments.isEmpty()) {
225
        Q_EMIT enqueue(d->mArguments,
226 227
                       ElisaUtils::PlayListEnqueueMode::AppendPlayList,
                       ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay);
228
    }
229 230 231 232 233 234 235 236 237 238
}

void ElisaApplication::activateActionRequested(const QString &actionName, const QVariant &parameter)
{
    Q_UNUSED(actionName)
    Q_UNUSED(parameter)
}

void ElisaApplication::activateRequested(const QStringList &arguments, const QString &workingDirectory)
{
239
    if (arguments.size() > 1) {
240
        auto realArguments = DataTypes::EntryDataList{};
241 242 243 244 245 246 247 248

        bool isFirst = true;
        for (const auto &oneArgument : arguments) {
            if (isFirst) {
                isFirst = false;
                continue;
            }

249 250
            realArguments.push_back({{{DataTypes::ElementTypeRole, ElisaUtils::Track},
                                      {DataTypes::ResourceRole, QUrl::fromUserInput(oneArgument)}}, {}, {}});
251 252 253 254 255
        }

        Q_EMIT enqueue(checkFileListAndMakeAbsolute(realArguments, workingDirectory),
                       ElisaUtils::PlayListEnqueueMode::AppendPlayList,
                       ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay);
256
    }
257 258 259 260 261 262 263
}

void ElisaApplication::openRequested(const QList<QUrl> &uris)
{
    Q_UNUSED(uris)
}

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
void ElisaApplication::appHelpActivated()
{
    QDesktopServices::openUrl(QUrl(QStringLiteral("help:/")));
}

void ElisaApplication::aboutApplication()
{
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
    static QPointer<QDialog> dialog;
    if (!dialog) {
        dialog = new KAboutApplicationDialog(KAboutData::applicationData(), nullptr);
        dialog->setAttribute(Qt::WA_DeleteOnClose);
    }
    dialog->show();
#endif
}

void ElisaApplication::reportBug()
{
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
    static QPointer<QDialog> dialog;
    if (!dialog) {
        dialog = new KBugReport(KAboutData::applicationData(), nullptr);
        dialog->setAttribute(Qt::WA_DeleteOnClose);
    }
    dialog->show();
#endif
}

void ElisaApplication::configureShortcuts()
{
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
296
    KShortcutsDialog dlg(KShortcutsEditor::ApplicationAction, KShortcutsEditor::LetterShortcutsAllowed, nullptr);
297
    dlg.setModal(true);
298
    dlg.addCollection(&d->mCollection);
299
    dlg.configure();
300 301 302
#endif
}

303 304
void ElisaApplication::configureElisa()
{
305 306 307 308
    if (!d->mEngine)
    {
        return;
    }
309

310 311 312 313
    QQmlComponent configurationDialogComponent(d->mEngine,
                                               QUrl(QStringLiteral("qrc:/qml/ElisaConfigurationDialog.qml")));

    configurationDialogComponent.create();
314 315
}

316 317
void ElisaApplication::goBack() {}

318 319
void ElisaApplication::find() {}

Diego Gangl's avatar
Diego Gangl committed
320 321
void ElisaApplication::togglePlaylist() {}

322 323 324 325
void ElisaApplication::seek() {}

void ElisaApplication::scrub() {}

326 327 328 329
void ElisaApplication::nextTrack() {}

void ElisaApplication::previousTrack() {}

330 331
void ElisaApplication::playPause() {}

332 333 334 335 336 337 338 339 340 341
void ElisaApplication::configChanged()
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

    d->mConfigFileWatcher.addPath(currentConfiguration->config()->name());

    currentConfiguration->load();
    currentConfiguration->read();

    Q_EMIT showProgressOnTaskBarChanged();
342
    Q_EMIT showSystemTrayIconChanged();
343
    Q_EMIT embeddedViewChanged();
344 345
}

346
DataTypes::EntryDataList ElisaApplication::checkFileListAndMakeAbsolute(const DataTypes::EntryDataList &filesList,
347
                                                                         const QString &workingDirectory) const
348
{
349
    auto filesToOpen = DataTypes::EntryDataList{};
350 351

    for (const auto &oneFile : filesList) {
352 353 354 355 356
        auto trackUrl = std::get<0>(oneFile)[DataTypes::ResourceRole].toUrl();
        if (trackUrl.scheme().isEmpty() || trackUrl.isLocalFile()) {
            auto newFile = QFileInfo(trackUrl.toLocalFile());
            if (trackUrl.scheme().isEmpty()) {
                newFile = QFileInfo(trackUrl.toString());
357
            }
358

359
            if (newFile.isRelative()) {
360 361
                if (trackUrl.scheme().isEmpty()) {
                    newFile.setFile(workingDirectory, trackUrl.toString());
362
                } else {
363
                    newFile.setFile(workingDirectory, trackUrl.toLocalFile());
364 365
                }
            }
366

367
            if (newFile.exists()) {
368 369 370
                auto trackData = std::get<0>(oneFile);
                trackData[DataTypes::ResourceRole] = QUrl::fromLocalFile(newFile.canonicalFilePath());
                filesToOpen.push_back({trackData, std::get<1>(oneFile), {}});
371 372
            }
        } else {
373
            filesToOpen.push_back(oneFile);
374 375 376 377 378 379
        }
    }

    return filesToOpen;
}

380
void ElisaApplication::initialize()
381 382 383
{
    initializeModels();
    initializePlayer();
384 385

    Q_EMIT initializationDone();
386 387
}

388
void ElisaApplication::setQmlEngine(QQmlEngine *engine)
389 390 391 392
{
    d->mEngine = engine;
}

393
void ElisaApplication::initializeModels()
394 395 396
{
    d->mMusicManager = std::make_unique<MusicListenersManager>();
    Q_EMIT musicManagerChanged();
397

398
    d->mMediaPlayList = std::make_unique<MediaPlayList>();
399
    d->mMusicManager->subscribeForTracks(d->mMediaPlayList.get());
400 401
    Q_EMIT mediaPlayListChanged();

402 403 404 405
    d->mMediaPlayListProxyModel = std::make_unique<MediaPlayListProxyModel>();
    d->mMediaPlayListProxyModel->setPlayListModel(d->mMediaPlayList.get());
    Q_EMIT mediaPlayListProxyModelChanged();

406 407
    d->mMusicManager->setElisaApplication(this);

408
    QObject::connect(this, &ElisaApplication::enqueue,
409 410 411
                     d->mMediaPlayListProxyModel.get(), static_cast<void (MediaPlayListProxyModel::*)(const DataTypes::EntryDataList&,
                                                                                            ElisaUtils::PlayListEnqueueMode,
                                                                                            ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayListProxyModel::enqueue));
412 413 414 415 416 417 418 419 420 421 422 423 424
}

void ElisaApplication::initializePlayer()
{
    d->mAudioWrapper = std::make_unique<AudioWrapper>();
    Q_EMIT audioPlayerChanged();
    d->mAudioControl = std::make_unique<ManageAudioPlayer>();
    Q_EMIT audioControlChanged();
    d->mPlayerControl = std::make_unique<ManageMediaPlayerControl>();
    Q_EMIT playerControlChanged();
    d->mManageHeaderBar = std::make_unique<ManageHeaderBar>();
    Q_EMIT manageHeaderBarChanged();

Alexander Stippich's avatar
Alexander Stippich committed
425 426 427 428 429
    d->mAudioControl->setAlbumNameRole(MediaPlayList::AlbumRole);
    d->mAudioControl->setArtistNameRole(MediaPlayList::ArtistRole);
    d->mAudioControl->setTitleRole(MediaPlayList::TitleRole);
    d->mAudioControl->setUrlRole(MediaPlayList::ResourceRole);
    d->mAudioControl->setIsPlayingRole(MediaPlayList::IsPlayingRole);
430
    d->mAudioControl->setPlayListModel(d->mMediaPlayListProxyModel.get());
Alexander Stippich's avatar
Alexander Stippich committed
431 432 433 434 435

    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerPlay, d->mAudioWrapper.get(), &AudioWrapper::play);
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerPause, d->mAudioWrapper.get(), &AudioWrapper::pause);
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerStop, d->mAudioWrapper.get(), &AudioWrapper::stop);
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::seek, d->mAudioWrapper.get(), &AudioWrapper::seek);
436 437
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::saveUndoPositionInAudioWrapper, d->mAudioWrapper.get(), &AudioWrapper::saveUndoPosition);
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::restoreUndoPositionInAudioWrapper, d->mAudioWrapper.get(), &AudioWrapper::restoreUndoPosition);
438 439 440 441

    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::skipNextTrack, d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::skipNextTrack);
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::sourceInError, d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::trackInError);

Alexander Stippich's avatar
Alexander Stippich committed
442 443
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::sourceInError, d->mMusicManager.get(), &MusicListenersManager::playBackError);
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerSourceChanged, d->mAudioWrapper.get(), &AudioWrapper::setSource);
444 445
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::startedPlayingTrack,
                     d->mMusicManager->viewDatabase(), &DatabaseInterface::trackHasStartedPlaying);
446
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::updateData, d->mMediaPlayList.get(), &MediaPlayList::setData);
Alexander Stippich's avatar
Alexander Stippich committed
447

448 449 450 451 452
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::ensurePlay, d->mAudioControl.get(), &ManageAudioPlayer::ensurePlay);
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::playListFinished, d->mAudioControl.get(), &ManageAudioPlayer::playListFinished);
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::currentTrackChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentTrack);
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::clearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::saveForUndoClearPlaylist);
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::undoClearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::restoreForUndoClearPlaylist);
453
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::seek, d->mAudioWrapper.get(), &AudioWrapper::seek);
454

455 456
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playbackStateChanged,
                     d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPlaybackState);
Alexander Stippich's avatar
Alexander Stippich committed
457 458 459 460 461
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::statusChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerStatus);
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::errorChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerError);
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::durationChanged, d->mAudioControl.get(), &ManageAudioPlayer::setAudioDuration);
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::seekableChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerIsSeekable);
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::positionChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPosition);
Jerome Guidon's avatar
Jerome Guidon committed
462
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::currentPlayingForRadiosChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentPlayingForRadios);
Alexander Stippich's avatar
Alexander Stippich committed
463

464 465 466
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::currentTrackChanged, d->mPlayerControl.get(), &ManageMediaPlayerControl::setCurrentTrack);
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::previousTrackChanged, d->mPlayerControl.get(), &ManageMediaPlayerControl::setPreviousTrack);
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::nextTrackChanged, d->mPlayerControl.get(), &ManageMediaPlayerControl::setNextTrack);
467

468
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playing, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPlaying);
469 470
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::paused, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPausedOrStopped);
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::stopped, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPausedOrStopped);
471 472 473

    d->mManageHeaderBar->setTitleRole(MediaPlayList::TitleRole);
    d->mManageHeaderBar->setAlbumRole(MediaPlayList::AlbumRole);
474
    d->mManageHeaderBar->setAlbumArtistRole(MediaPlayList::AlbumArtistRole);
475
    d->mManageHeaderBar->setArtistRole(MediaPlayList::ArtistRole);
476
    d->mManageHeaderBar->setFileNameRole(MediaPlayList::ResourceRole);
477
    d->mManageHeaderBar->setImageRole(MediaPlayList::ImageUrlRole);
478
    d->mManageHeaderBar->setDatabaseIdRole(MediaPlayList::DatabaseIdRole);
479
    d->mManageHeaderBar->setTrackTypeRole(MediaPlayList::ElementTypeRole);
480
    d->mManageHeaderBar->setAlbumIdRole(MediaPlayList::AlbumIdRole);
481
    d->mManageHeaderBar->setIsValidRole(MediaPlayList::IsValidRole);
482 483
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::currentTrackChanged, d->mManageHeaderBar.get(), &ManageHeaderBar::setCurrentTrack);
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::currentTrackDataChanged, d->mManageHeaderBar.get(), &ManageHeaderBar::updateCurrentTrackData);
484

485
    if (!d->mArguments.isEmpty()) {
486
        Q_EMIT enqueue(d->mArguments,
487 488
                       ElisaUtils::PlayListEnqueueMode::AppendPlayList,
                       ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay);
489
    }
490 491
}

492 493 494
QAction * ElisaApplication::action(const QString& name)
{
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
495 496 497 498 499 500 501 502
    auto resultAction = d->mCollection.action(name);

    if (!resultAction) {
        setupActions(name);
        resultAction = d->mCollection.action(name);
    }

    return resultAction;
503 504 505 506 507 508 509 510 511 512 513 514
#else
    Q_UNUSED(name);

    return new QAction();
#endif
}

QString ElisaApplication::iconName(const QIcon& icon)
{
    return icon.name();
}

515 516 517 518 519 520 521 522 523 524 525
void ElisaApplication::installKeyEventFilter(QObject *object)
{
    if(!object) {
        return;
    }

    object->installEventFilter(this);
}

bool ElisaApplication::eventFilter(QObject *object, QEvent *event)
{
526
    Q_UNUSED(object)
527

528
    auto *keyEvent = static_cast<QKeyEvent*>(event);
529
    auto playPauseAction = d->mCollection.action(QStringLiteral("Play-Pause"));
530 531 532 533 534 535 536
    if (keyEvent->key() == Qt::Key_Space && playPauseAction->shortcut()[0] == Qt::Key_Space) {
        return true;
    }

    return false;
}

537 538 539 540 541
void ElisaApplication::showInFolder(QUrl filePath)
{
    KIO::highlightInFileManager({filePath});
}

542
const DataTypes::EntryDataList &ElisaApplication::arguments() const
543 544 545 546
{
    return d->mArguments;
}

547 548 549 550 551 552 553 554 555 556
MusicListenersManager *ElisaApplication::musicManager() const
{
    return d->mMusicManager.get();
}

MediaPlayList *ElisaApplication::mediaPlayList() const
{
    return d->mMediaPlayList.get();
}

557 558 559 560 561 562
MediaPlayListProxyModel *ElisaApplication::mediaPlayListProxyModel() const
{
    return d->mMediaPlayListProxyModel.get();
}


Alexander Stippich's avatar
Alexander Stippich committed
563 564 565 566
AudioWrapper *ElisaApplication::audioPlayer() const
{
    return d->mAudioWrapper.get();
}
567

Alexander Stippich's avatar
Alexander Stippich committed
568 569 570 571 572
ManageAudioPlayer *ElisaApplication::audioControl() const
{
    return d->mAudioControl.get();
}

573 574 575 576 577 578 579 580 581 582
ManageMediaPlayerControl *ElisaApplication::playerControl() const
{
    return d->mPlayerControl.get();
}

ManageHeaderBar *ElisaApplication::manageHeaderBar() const
{
    return d->mManageHeaderBar.get();
}

583 584 585 586 587 588 589
bool ElisaApplication::showProgressOnTaskBar() const
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

    return currentConfiguration->showProgressOnTaskBar();
}

590 591 592 593 594 595 596
bool ElisaApplication::showSystemTrayIcon() const
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

    return currentConfiguration->showSystemTrayIcon();
}

597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
ElisaUtils::PlayListEntryType ElisaApplication::embeddedView() const
{
    ElisaUtils::PlayListEntryType result = ElisaUtils::Unknown;

    switch (Elisa::ElisaConfiguration::self()->embeddedView())
    {
    case 0:
        result = ElisaUtils::Unknown;
        break;
    case 1:
        result = ElisaUtils::Album;
        break;
    case 2:
        result = ElisaUtils::Artist;
        break;
    case 3:
        result = ElisaUtils::Genre;
        break;
    }

    return result;
}

620 621 622 623 624 625 626
int ElisaApplication::initialViewIndex() const
{
    int result = Elisa::ElisaConfiguration::initialView();

    return result;
}

627
#include "moc_elisaapplication.cpp"