elisaapplication.cpp 23 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
        auto togglePlaylistAction = d->mCollection.addAction(actionName, this, &ElisaApplication::togglePlaylist);
        togglePlaylistAction->setShortcut(QKeySequence(Qt::Key_F9));
158
        togglePlaylistAction->setText(i18n("Toggle Playlist"));
Diego Gangl's avatar
Diego Gangl committed
159
160
    }

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
            seekAction->setText(i18n("Seek forward 10 seconds"));
164
            d->mCollection.setDefaultShortcut(seekAction, QKeySequence(Qt::SHIFT + Qt::Key_Right));
165
166
    }

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

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

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

196
    d->mCollection.readSettings();
197
198
199
#endif
}

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

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

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

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

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

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

234
235
            realArguments.push_back({{{DataTypes::ElementTypeRole, ElisaUtils::Track},
                                      {DataTypes::ResourceRole, QUrl::fromUserInput(oneArgument)}}, {}, {}});
236
237
238
239
240
        }

        Q_EMIT enqueue(checkFileListAndMakeAbsolute(realArguments, workingDirectory),
                       ElisaUtils::PlayListEnqueueMode::AppendPlayList,
                       ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay);
241
    }
242
243
244
245
246
247
248
}

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

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
280
281
282
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);
283
    dlg.addCollection(&d->mCollection);
284
    dlg.configure();
285
286
287
#endif
}

288
289
void ElisaApplication::configureElisa()
{
290
291
292
293
    if (!d->mEngine)
    {
        return;
    }
294

295
296
297
298
    QQmlComponent configurationDialogComponent(d->mEngine,
                                               QUrl(QStringLiteral("qrc:/qml/ElisaConfigurationDialog.qml")));

    configurationDialogComponent.create();
299
300
}

301
302
void ElisaApplication::goBack() {}

303
304
void ElisaApplication::find() {}

Diego Gangl's avatar
Diego Gangl committed
305
306
void ElisaApplication::togglePlaylist() {}

307
308
309
310
void ElisaApplication::seek() {}

void ElisaApplication::scrub() {}

311
312
313
314
void ElisaApplication::nextTrack() {}

void ElisaApplication::previousTrack() {}

315
316
void ElisaApplication::playPause() {}

317
318
319
320
321
322
323
324
325
326
void ElisaApplication::configChanged()
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

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

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

    Q_EMIT showProgressOnTaskBarChanged();
327
    Q_EMIT showSystemTrayIconChanged();
328
    Q_EMIT embeddedViewChanged();
329
330
}

331
DataTypes::EntryDataList ElisaApplication::checkFileListAndMakeAbsolute(const DataTypes::EntryDataList &filesList,
332
                                                                         const QString &workingDirectory) const
333
{
334
    auto filesToOpen = DataTypes::EntryDataList{};
335
336

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

344
            if (newFile.isRelative()) {
345
346
                if (trackUrl.scheme().isEmpty()) {
                    newFile.setFile(workingDirectory, trackUrl.toString());
347
                } else {
348
                    newFile.setFile(workingDirectory, trackUrl.toLocalFile());
349
350
                }
            }
351

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

    return filesToOpen;
}

365
void ElisaApplication::initialize()
366
367
368
{
    initializeModels();
    initializePlayer();
369
370

    Q_EMIT initializationDone();
371
372
}

373
void ElisaApplication::setQmlEngine(QQmlEngine *engine)
374
375
376
377
{
    d->mEngine = engine;
}

378
void ElisaApplication::initializeModels()
379
380
381
{
    d->mMusicManager = std::make_unique<MusicListenersManager>();
    Q_EMIT musicManagerChanged();
382

383
    d->mMediaPlayList = std::make_unique<MediaPlayList>();
384
    d->mMusicManager->subscribeForTracks(d->mMediaPlayList.get());
385
386
    Q_EMIT mediaPlayListChanged();

387
388
389
390
    d->mMediaPlayListProxyModel = std::make_unique<MediaPlayListProxyModel>();
    d->mMediaPlayListProxyModel->setPlayListModel(d->mMediaPlayList.get());
    Q_EMIT mediaPlayListProxyModelChanged();

391
392
    d->mMusicManager->setElisaApplication(this);

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

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

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

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

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

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

449
450
451
    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);
452

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

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

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

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

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

    return resultAction;
488
489
490
491
492
493
494
495
496
497
498
499
#else
    Q_UNUSED(name);

    return new QAction();
#endif
}

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

500
501
502
503
504
505
506
507
508
509
510
void ElisaApplication::installKeyEventFilter(QObject *object)
{
    if(!object) {
        return;
    }

    object->installEventFilter(this);
}

bool ElisaApplication::eventFilter(QObject *object, QEvent *event)
{
511
    Q_UNUSED(object)
512
513
514
515
516
517
518
519
520
521

    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;
}

522
const DataTypes::EntryDataList &ElisaApplication::arguments() const
523
524
525
526
{
    return d->mArguments;
}

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

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

537
538
539
540
541
542
MediaPlayListProxyModel *ElisaApplication::mediaPlayListProxyModel() const
{
    return d->mMediaPlayListProxyModel.get();
}


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

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

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

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

563
564
565
566
567
568
569
bool ElisaApplication::showProgressOnTaskBar() const
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

    return currentConfiguration->showProgressOnTaskBar();
}

570
571
572
573
574
575
576
bool ElisaApplication::showSystemTrayIcon() const
{
    auto currentConfiguration = Elisa::ElisaConfiguration::self();

    return currentConfiguration->showSystemTrayIcon();
}

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

600
#include "moc_elisaapplication.cpp"