File: stdactions.cpp

package info (click to toggle)
cantata 3.4.0.ds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,428 kB
  • sloc: cpp: 109,584; perl: 1,366; xml: 722; python: 139; lex: 110; sh: 105; yacc: 78; makefile: 8
file content (157 lines) | stat: -rw-r--r-- 8,504 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Cantata
 *
 * Copyright (c) 2011-2022 Craig Drummond <craig.p.drummond@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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "stdactions.h"
#include "models/playlistsmodel.h"
#include "support/action.h"
#include "support/actioncollection.h"
#include "widgets/icons.h"
#ifdef ENABLE_DEVICES_SUPPORT
#include "models/devicesmodel.h"
#endif
#include "support/globalstatic.h"
#include "support/icon.h"
#include "support/utils.h"
#include "widgets/icons.h"
#include "widgets/mirrormenu.h"
#include <QCoreApplication>

GLOBAL_STATIC(StdActions, instance)

static QMenu* priorityMenu(bool isSet, Action* parent)
{
	QString prefix(isSet ? "set" : "addwith");
	Action* prioHighestAction = ActionCollection::get()->createAction(prefix + "priohighest", QObject::tr("Highest Priority (255)"));
	Action* prioHighAction = ActionCollection::get()->createAction(prefix + "priohigh", QObject::tr("High Priority (200)"));
	Action* prioMediumAction = ActionCollection::get()->createAction(prefix + "priomedium", QObject::tr("Medium Priority (125)"));
	Action* prioLowAction = ActionCollection::get()->createAction(prefix + "priolow", QObject::tr("Low Priority (50)"));
	Action* prioDefaultAction = ActionCollection::get()->createAction(prefix + "priodefault", QObject::tr("Default Priority (0)"));
	Action* prioCustomAction = ActionCollection::get()->createAction(prefix + "priocustom", QObject::tr("Custom Priority..."));

	prioHighestAction->setSettingsText(parent);
	prioHighAction->setSettingsText(parent);
	prioMediumAction->setSettingsText(parent);
	prioLowAction->setSettingsText(parent);
	prioDefaultAction->setSettingsText(parent);
	prioCustomAction->setSettingsText(parent);

	prioHighAction->setData(200);
	prioMediumAction->setData(125);
	prioLowAction->setData(50);
	prioDefaultAction->setData(0);
	prioCustomAction->setData(-1);

	prioHighestAction->setData(255);
	prioHighAction->setData(200);
	prioMediumAction->setData(125);
	prioLowAction->setData(50);
	prioDefaultAction->setData(0);
	prioCustomAction->setData(-1);

	QMenu* prioMenu = new QMenu();
	prioMenu->addAction(prioHighestAction);
	prioMenu->addAction(prioHighAction);
	prioMenu->addAction(prioMediumAction);
	prioMenu->addAction(prioLowAction);
	prioMenu->addAction(prioDefaultAction);
	prioMenu->addAction(prioCustomAction);
	return prioMenu;
}

StdActions::StdActions()
{
	QColor col = Utils::monoIconColor();
	Q_UNUSED(col)
	prevTrackAction = ActionCollection::get()->createAction("prevtrack", QObject::tr("Previous Track"), Icons::self()->toolbarPrevIcon);
	nextTrackAction = ActionCollection::get()->createAction("nexttrack", QObject::tr("Next Track"), Icons::self()->toolbarNextIcon);
	playPauseTrackAction = ActionCollection::get()->createAction("playpausetrack", QObject::tr("Play/Pause"), Icons::self()->toolbarPlayIcon);
	stopPlaybackAction = ActionCollection::get()->createAction("stopplayback", QObject::tr("Stop"), Icons::self()->toolbarStopIcon);
	stopAfterCurrentTrackAction = ActionCollection::get()->createAction("stopaftercurrenttrack", QObject::tr("Stop After Current Track"), Icons::self()->toolbarStopIcon);
	stopAfterTrackAction = ActionCollection::get()->createAction("stopaftertrack", QObject::tr("Stop After Track"), Icons::self()->toolbarStopIcon);
	increaseVolumeAction = ActionCollection::get()->createAction("increasevolume", QObject::tr("Increase Volume"));
	decreaseVolumeAction = ActionCollection::get()->createAction("decreasevolume", QObject::tr("Decrease Volume"));
	savePlayQueueAction = ActionCollection::get()->createAction("saveplayqueue", QObject::tr("Save As"), Icons::self()->savePlayQueueIcon);
	appendToPlayQueueAction = ActionCollection::get()->createAction("appendtoplayqueue", QObject::tr("Append"), Icons::self()->appendToPlayQueueIcon);
	appendToPlayQueueAction->setSettingsText(QObject::tr("Append To Play Queue"));
	appendToPlayQueueAndPlayAction = ActionCollection::get()->createAction("appendtoplayqueueandplay", QObject::tr("Append And Play"));
	addToPlayQueueAndPlayAction = ActionCollection::get()->createAction("addtoplayqueueandplay", QObject::tr("Add And Play"));
	appendToPlayQueueAndPlayAction->setSettingsText(QObject::tr("Append To Play Queue And Play"));
	insertAfterCurrentAction = ActionCollection::get()->createAction("insertintoplayqueue", QObject::tr("Insert After Current"));
	addRandomAlbumToPlayQueueAction = ActionCollection::get()->createAction("addrandomalbumtoplayqueue", QObject::tr("Append Random Album"));
	replacePlayQueueAction = ActionCollection::get()->createAction("replaceplayqueue", QObject::tr("Play Now (And Replace Play Queue)"), Icons::self()->replacePlayQueueIcon);
	savePlayQueueAction->setShortcut(Qt::ControlModifier | Qt::Key_S);
	appendToPlayQueueAction->setShortcut(Qt::ControlModifier | Qt::Key_P);
	replacePlayQueueAction->setShortcut(Qt::ControlModifier | Qt::Key_R);

	addWithPriorityAction = new Action(QObject::tr("Add With Priority"), nullptr);
	setPriorityAction = new Action(QObject::tr("Set Priority"), nullptr);
	setPriorityAction->setMenu(priorityMenu(true, setPriorityAction));
	addWithPriorityAction->setMenu(priorityMenu(false, addWithPriorityAction));

	addToStoredPlaylistAction = ActionCollection::get()->createAction("addtoplaylist", QObject::tr("Add To Playlist"), Icons::self()->playlistListIcon);
#ifdef TagLib_FOUND
	organiseFilesAction = ActionCollection::get()->createAction("orgfiles", QObject::tr("Organize Files"), Icon::fa(fa::fa_regular, fa::fa_folder_open));
	editTagsAction = ActionCollection::get()->createAction("edittags", QObject::tr("Edit Track Information"));
#endif
#ifdef ENABLE_REPLAYGAIN_SUPPORT
	replaygainAction = ActionCollection::get()->createAction("replaygain", QObject::tr("ReplayGain"), Icon::fa(fa::fa_solid, fa::fa_chart_column));
#endif
#ifdef ENABLE_DEVICES_SUPPORT
	copyToDeviceAction = ActionCollection::get()->createAction("copytodevice", QObject::tr("Copy Songs To Device"), Icon::fa(fa::fa_solid, fa::fa_mobile_screen));
	copyToDeviceAction->setMenu(DevicesModel::self()->menu());
	deleteSongsAction = ActionCollection::get()->createAction("deletesongs", QObject::tr("Delete Songs"), Icons::self()->trashIcon);
#endif
	setCoverAction = ActionCollection::get()->createAction("setimage", QObject::tr("Set Image"));
	removeAction = ActionCollection::get()->createAction("remove", QObject::tr("Remove"), Icons::self()->removeIcon);
	searchAction = ActionCollection::get()->createAction("search", QObject::tr("Find"), Icons::self()->searchIcon);
	searchAction->setShortcut(Qt::ControlModifier | Qt::Key_F);

	addToStoredPlaylistAction->setMenu(PlaylistsModel::self()->menu());

	QMenu* addMenu = new QMenu();
	addToPlayQueueMenuAction = new Action(QObject::tr("Add To Play Queue"), nullptr);
	addMenu->addAction(appendToPlayQueueAction);
	addMenu->addAction(appendToPlayQueueAndPlayAction);
	addMenu->addAction(addToPlayQueueAndPlayAction);
	addMenu->addAction(addWithPriorityAction);
	addMenu->addAction(insertAfterCurrentAction);
	addMenu->addAction(addRandomAlbumToPlayQueueAction);
	addToPlayQueueMenuAction->setMenu(addMenu);
	addRandomAlbumToPlayQueueAction->setVisible(false);

	zoomInAction = ActionCollection::get()->createAction("zoomIn", QObject::tr("Zoom In"));
	zoomInAction->setShortcut(Qt::ControlModifier | Qt::Key_Plus);
	zoomOutAction = ActionCollection::get()->createAction("zoomOut", QObject::tr("Zoom Out"));
	zoomOutAction->setShortcut(Qt::ControlModifier | Qt::Key_Minus);
}

void StdActions::enableAddToPlayQueue(bool en)
{
	appendToPlayQueueAction->setEnabled(en);
	appendToPlayQueueAndPlayAction->setEnabled(en);
	addToPlayQueueAndPlayAction->setEnabled(en);
	insertAfterCurrentAction->setEnabled(en);
	replacePlayQueueAction->setEnabled(en);
	addToStoredPlaylistAction->setEnabled(en);
	addToPlayQueueMenuAction->setEnabled(en);
}