elisaapplication.cpp 22.8 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
36
37
#include <KXmlGui/KAboutApplicationDialog>
#include <KXmlGui/KHelpMenu>
#include <KXmlGui/KBugReport>
#include <KXmlGui/KShortcutsDialog>
#endif

#include <KCoreAddons/KAboutData>

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

54
55
#include <memory>

56
57
58
59
60
class ElisaApplicationPrivate
{
public:

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

68
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
69
    KActionCollection mCollection;
70
#endif
71

72
    DataTypes::EntryDataList mArguments;
73

74
75
76
77
    std::unique_ptr<MusicListenersManager> mMusicManager;

    std::unique_ptr<MediaPlayList> mMediaPlayList;

78
79
    std::unique_ptr<MediaPlayListProxyModel> mMediaPlayListProxyModel;

Alexander Stippich's avatar
Alexander Stippich committed
80
81
    std::unique_ptr<AudioWrapper> mAudioWrapper;

Alexander Stippich's avatar
Alexander Stippich committed
82
83
    std::unique_ptr<ManageAudioPlayer> mAudioControl;

84
85
86
87
    std::unique_ptr<ManageMediaPlayerControl> mPlayerControl;

    std::unique_ptr<ManageHeaderBar> mManageHeaderBar;

88
    QQmlEngine *mEngine = nullptr;
89

90
91
    QFileSystemWatcher mConfigFileWatcher;

92
93
94
};

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

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

104
105
106
107
108
    connect(Elisa::ElisaConfiguration::self(), &Elisa::ElisaConfiguration::configChanged,
            this, &ElisaApplication::configChanged);

    connect(&d->mConfigFileWatcher, &QFileSystemWatcher::fileChanged,
            this, &ElisaApplication::configChanged);
109
110
111

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

114
115
116
ElisaApplication::~ElisaApplication()
= default;

117
void ElisaApplication::setupActions(const QString &actionName)
118
119
{
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
Laurent Montel's avatar
Laurent Montel committed
120
    if (actionName == QLatin1String("file_quit")) {
121
122
123
        auto quitAction = KStandardAction::quit(QCoreApplication::instance(), &QCoreApplication::quit, &d->mCollection);
        d->mCollection.addAction(actionName, quitAction);
    }
124

Laurent Montel's avatar
Laurent Montel committed
125
    if (actionName == QLatin1String("help_contents") && KAuthorized::authorizeAction(actionName)) {
126
127
        auto handBookAction = KStandardAction::helpContents(this, &ElisaApplication::appHelpActivated, &d->mCollection);
        d->mCollection.addAction(handBookAction->objectName(), handBookAction);
128
129
    }

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

Laurent Montel's avatar
Laurent Montel committed
135
    if (actionName == QLatin1String("help_about_app") && KAuthorized::authorizeAction(actionName)) {
136
137
        auto aboutAppAction = KStandardAction::aboutApp(this, &ElisaApplication::aboutApplication, this);
        d->mCollection.addAction(aboutAppAction->objectName(), aboutAppAction);
138
139
    }

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

Laurent Montel's avatar
Laurent Montel committed
145
    if (actionName == QLatin1String("options_configure_keybinding") && KAuthorized::authorizeAction(actionName)) {
146
147
148
149
        auto keyBindingsAction = KStandardAction::keyBindings(this, &ElisaApplication::configureShortcuts, this);
        d->mCollection.addAction(keyBindingsAction->objectName(), keyBindingsAction);
    }

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

Laurent Montel's avatar
Laurent Montel committed
155
    if (actionName == QLatin1String("toggle_playlist") && KAuthorized::authorizeAction(actionName)) {
Diego Gangl's avatar
Diego Gangl committed
156
157
158
159
160
        auto togglePlaylistAction = d->mCollection.addAction(actionName, this, &ElisaApplication::togglePlaylist);
        togglePlaylistAction->setShortcut(QKeySequence(Qt::Key_F9));
        togglePlaylistAction->setText(QStringLiteral("Toggle Playlist"));
    }

Laurent Montel's avatar
Laurent Montel committed
161
    if (actionName == QLatin1String("Seek") && KAuthorized::authorizeAction(actionName)) {
162
            auto seekAction = d->mCollection.addAction(actionName, this, &ElisaApplication::seek);
163
            d->mCollection.setDefaultShortcut(seekAction, QKeySequence(Qt::SHIFT + Qt::Key_Right));
164
165
    }

Laurent Montel's avatar
Laurent Montel committed
166
    if (actionName == QLatin1String("Scrub") && KAuthorized::authorizeAction(actionName)) {
167
            auto scrubAction = d->mCollection.addAction(actionName, this, &ElisaApplication::scrub);
168
            d->mCollection.setDefaultShortcut(scrubAction, QKeySequence(Qt::SHIFT + Qt::Key_Left));
169
170
    }

171
172
173
174
175
176
177
178
179
180
181
182
    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
183
    if (actionName == QLatin1String("Play-Pause") && KAuthorized::authorizeAction(actionName)) {
184
            auto playPauseAction = d->mCollection.addAction(actionName, this, &ElisaApplication::playPause);
185
            d->mCollection.setDefaultShortcut(playPauseAction, QKeySequence(Qt::Key_Space));
186
187
    }

Laurent Montel's avatar
Laurent Montel committed
188
    if (actionName == QLatin1String("edit_find") && KAuthorized::authorizeAction(actionName)) {
189
190
191
192
        auto findAction = KStandardAction::find(this, &ElisaApplication::find, this);
        d->mCollection.addAction(findAction->objectName(), findAction);
    }

193
    d->mCollection.readSettings();
194
195
196
#endif
}

197
void ElisaApplication::setArguments(const DataTypes::EntryDataList &newArguments)
198
199
200
201
202
203
204
{
    if (d->mArguments == newArguments) {
        return;
    }

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

    if (!d->mArguments.isEmpty()) {
207
        Q_EMIT enqueue(d->mArguments,
208
209
                       ElisaUtils::PlayListEnqueueMode::AppendPlayList,
                       ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay);
210
    }
211
212
213
214
215
216
217
218
219
220
}

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

void ElisaApplication::activateRequested(const QStringList &arguments, const QString &workingDirectory)
{
221
    if (arguments.size() > 1) {
222
        auto realArguments = DataTypes::EntryDataList{};
223
224
225
226
227
228
229
230

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

231
232
            realArguments.push_back({{{DataTypes::ElementTypeRole, ElisaUtils::Track},
                                      {DataTypes::ResourceRole, QUrl::fromUserInput(oneArgument)}}, {}, {}});
233
234
235
236
237
        }

        Q_EMIT enqueue(checkFileListAndMakeAbsolute(realArguments, workingDirectory),
                       ElisaUtils::PlayListEnqueueMode::AppendPlayList,
                       ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay);
238
    }
239
240
241
242
243
244
245
}

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

246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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
    KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, nullptr);
    dlg.setModal(true);
280
    dlg.addCollection(&d->mCollection);
281
    dlg.configure();
282
283
284
#endif
}

285
286
void ElisaApplication::configureElisa()
{
287
288
289
290
    if (!d->mEngine)
    {
        return;
    }
291

292
293
294
295
    QQmlComponent configurationDialogComponent(d->mEngine,
                                               QUrl(QStringLiteral("qrc:/qml/ElisaConfigurationDialog.qml")));

    configurationDialogComponent.create();
296
297
}

298
299
void ElisaApplication::goBack() {}

300
301
void ElisaApplication::find() {}

Diego Gangl's avatar
Diego Gangl committed
302
303
void ElisaApplication::togglePlaylist() {}

304
305
306
307
void ElisaApplication::seek() {}

void ElisaApplication::scrub() {}

308
309
310
311
void ElisaApplication::nextTrack() {}

void ElisaApplication::previousTrack() {}

312
313
void ElisaApplication::playPause() {}

314
315
316
317
318
319
320
321
322
323
void ElisaApplication::configChanged()
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

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

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

    Q_EMIT showProgressOnTaskBarChanged();
324
    Q_EMIT showSystemTrayIconChanged();
325
    Q_EMIT embeddedViewChanged();
326
327
}

328
DataTypes::EntryDataList ElisaApplication::checkFileListAndMakeAbsolute(const DataTypes::EntryDataList &filesList,
329
                                                                         const QString &workingDirectory) const
330
{
331
    auto filesToOpen = DataTypes::EntryDataList{};
332
333

    for (const auto &oneFile : filesList) {
334
335
336
337
338
        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());
339
            }
340

341
            if (newFile.isRelative()) {
342
343
                if (trackUrl.scheme().isEmpty()) {
                    newFile.setFile(workingDirectory, trackUrl.toString());
344
                } else {
345
                    newFile.setFile(workingDirectory, trackUrl.toLocalFile());
346
347
                }
            }
348

349
            if (newFile.exists()) {
350
351
352
                auto trackData = std::get<0>(oneFile);
                trackData[DataTypes::ResourceRole] = QUrl::fromLocalFile(newFile.canonicalFilePath());
                filesToOpen.push_back({trackData, std::get<1>(oneFile), {}});
353
354
            }
        } else {
355
            filesToOpen.push_back(oneFile);
356
357
358
359
360
361
        }
    }

    return filesToOpen;
}

362
void ElisaApplication::initialize()
363
364
365
{
    initializeModels();
    initializePlayer();
366
367

    Q_EMIT initializationDone();
368
369
}

370
void ElisaApplication::setQmlEngine(QQmlEngine *engine)
371
372
373
374
{
    d->mEngine = engine;
}

375
void ElisaApplication::initializeModels()
376
377
378
{
    d->mMusicManager = std::make_unique<MusicListenersManager>();
    Q_EMIT musicManagerChanged();
379

380
    d->mMediaPlayList = std::make_unique<MediaPlayList>();
381
    d->mMusicManager->subscribeForTracks(d->mMediaPlayList.get());
382
383
    Q_EMIT mediaPlayListChanged();

384
385
386
387
    d->mMediaPlayListProxyModel = std::make_unique<MediaPlayListProxyModel>();
    d->mMediaPlayListProxyModel->setPlayListModel(d->mMediaPlayList.get());
    Q_EMIT mediaPlayListProxyModelChanged();

388
389
    d->mMusicManager->setElisaApplication(this);

390
    QObject::connect(this, &ElisaApplication::enqueue,
391
392
393
                     d->mMediaPlayListProxyModel.get(), static_cast<void (MediaPlayListProxyModel::*)(const DataTypes::EntryDataList&,
                                                                                            ElisaUtils::PlayListEnqueueMode,
                                                                                            ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayListProxyModel::enqueue));
394
395
396
397
398
399
400
401
402
403
404
405
406
}

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
407
408
409
410
411
    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);
412
    d->mAudioControl->setPlayListModel(d->mMediaPlayListProxyModel.get());
Alexander Stippich's avatar
Alexander Stippich committed
413
414
415
416
417

    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);
418
419
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::saveUndoPositionInAudioWrapper, d->mAudioWrapper.get(), &AudioWrapper::saveUndoPosition);
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::restoreUndoPositionInAudioWrapper, d->mAudioWrapper.get(), &AudioWrapper::restoreUndoPosition);
420
421
422
423

    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
424
425
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::sourceInError, d->mMusicManager.get(), &MusicListenersManager::playBackError);
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerSourceChanged, d->mAudioWrapper.get(), &AudioWrapper::setSource);
426
427
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::startedPlayingTrack,
                     d->mMusicManager->viewDatabase(), &DatabaseInterface::trackHasStartedPlaying);
428
    QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::updateData, d->mMediaPlayList.get(), &MediaPlayList::setData);
Alexander Stippich's avatar
Alexander Stippich committed
429

430
431
432
433
434
    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);
435
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::seek, d->mAudioWrapper.get(), &AudioWrapper::seek);
436

437
438
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playbackStateChanged,
                     d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPlaybackState);
Alexander Stippich's avatar
Alexander Stippich committed
439
440
441
442
443
    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
444
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::currentPlayingForRadiosChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentPlayingForRadios);
Alexander Stippich's avatar
Alexander Stippich committed
445

446
447
448
    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);
449

450
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playing, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPlaying);
451
452
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::paused, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPausedOrStopped);
    QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::stopped, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPausedOrStopped);
453
454
455

    d->mManageHeaderBar->setTitleRole(MediaPlayList::TitleRole);
    d->mManageHeaderBar->setAlbumRole(MediaPlayList::AlbumRole);
456
    d->mManageHeaderBar->setAlbumArtistRole(MediaPlayList::AlbumArtistRole);
457
    d->mManageHeaderBar->setArtistRole(MediaPlayList::ArtistRole);
458
    d->mManageHeaderBar->setFileNameRole(MediaPlayList::ResourceRole);
459
    d->mManageHeaderBar->setImageRole(MediaPlayList::ImageUrlRole);
460
    d->mManageHeaderBar->setDatabaseIdRole(MediaPlayList::DatabaseIdRole);
461
    d->mManageHeaderBar->setTrackTypeRole(MediaPlayList::ElementTypeRole);
462
    d->mManageHeaderBar->setAlbumIdRole(MediaPlayList::AlbumIdRole);
463
    d->mManageHeaderBar->setIsValidRole(MediaPlayList::IsValidRole);
464
465
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::currentTrackChanged, d->mManageHeaderBar.get(), &ManageHeaderBar::setCurrentTrack);
    QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::currentTrackDataChanged, d->mManageHeaderBar.get(), &ManageHeaderBar::updateCurrentTrackData);
466

467
    if (!d->mArguments.isEmpty()) {
468
        Q_EMIT enqueue(d->mArguments,
469
470
                       ElisaUtils::PlayListEnqueueMode::AppendPlayList,
                       ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay);
471
    }
472
473
}

474
475
476
QAction * ElisaApplication::action(const QString& name)
{
#if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND
477
478
479
480
481
482
483
484
    auto resultAction = d->mCollection.action(name);

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

    return resultAction;
485
486
487
488
489
490
491
492
493
494
495
496
#else
    Q_UNUSED(name);

    return new QAction();
#endif
}

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

497
498
499
500
501
502
503
504
505
506
507
void ElisaApplication::installKeyEventFilter(QObject *object)
{
    if(!object) {
        return;
    }

    object->installEventFilter(this);
}

bool ElisaApplication::eventFilter(QObject *object, QEvent *event)
{
508
    Q_UNUSED(object)
509
510
511
512
513
514
515
516
517
518

    QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    auto playPauseAction = d->mCollection.action(tr("Play-Pause"));
    if (keyEvent->key() == Qt::Key_Space && playPauseAction->shortcut()[0] == Qt::Key_Space) {
        return true;
    }

    return false;
}

519
const DataTypes::EntryDataList &ElisaApplication::arguments() const
520
521
522
523
{
    return d->mArguments;
}

524
525
526
527
528
529
530
531
532
533
MusicListenersManager *ElisaApplication::musicManager() const
{
    return d->mMusicManager.get();
}

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

534
535
536
537
538
539
MediaPlayListProxyModel *ElisaApplication::mediaPlayListProxyModel() const
{
    return d->mMediaPlayListProxyModel.get();
}


Alexander Stippich's avatar
Alexander Stippich committed
540
541
542
543
AudioWrapper *ElisaApplication::audioPlayer() const
{
    return d->mAudioWrapper.get();
}
544

Alexander Stippich's avatar
Alexander Stippich committed
545
546
547
548
549
ManageAudioPlayer *ElisaApplication::audioControl() const
{
    return d->mAudioControl.get();
}

550
551
552
553
554
555
556
557
558
559
ManageMediaPlayerControl *ElisaApplication::playerControl() const
{
    return d->mPlayerControl.get();
}

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

560
561
562
563
564
565
566
bool ElisaApplication::showProgressOnTaskBar() const
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

    return currentConfiguration->showProgressOnTaskBar();
}

567
568
569
570
571
572
573
bool ElisaApplication::showSystemTrayIcon() const
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

    return currentConfiguration->showSystemTrayIcon();
}

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
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;
}

597
#include "moc_elisaapplication.cpp"