Skip to content

Commit

Permalink
Add tray (fixes #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba160 committed Jun 15, 2024
1 parent ff30f93 commit 0aba96a
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 9 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ if (USE_WIDGETS)
widgets/plugins/QueueManager.cpp widgets/plugins/QueueManager.h
widgets/DBActionMenu.h widgets/DBActionMenu.cpp
widgets/ActionHandlers.cpp widgets/ActionHandlers.h
widgets/PluginConfParser.h widgets/PluginConfParser.cpp
widgets/TrayIcon.h widgets/TrayIcon.cpp
)
endif()

Expand All @@ -77,8 +79,8 @@ set(SOURCES
WidgetLibraryModel.cpp
QtGui.cpp)
qt_add_resources(SOURCES Images.qrc)
add_library(ddb_gui_qt5 SHARED ${SOURCES}
widgets/PluginConfParser.h widgets/PluginConfParser.cpp)
add_library(ddb_gui_qt5 SHARED ${SOURCES})



# fix for Qt Creator to find qml files
Expand Down
12 changes: 10 additions & 2 deletions dbapi/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Actions::Actions(QObject *parent)
//default_actions = new ActionsDefault(this, Api);

QList<DBAction::ActionLocations> filter_flags = { DBAction::ACTION_LOC_HOTKEY, DBAction::ACTION_LOC_TRACK_CONTEXT,
DBAction::ACTION_LOC_PLAYLIST_CONTEXT, DBAction::ACTION_LOC_MENUBAR };
DBAction::ACTION_LOC_PLAYLIST_CONTEXT, DBAction::ACTION_LOC_MENUBAR, DBAction::ACTION_LOC_TRAY };

for (int i = 0 ; i < 4; i++) {
for (int i = 0 ; i < 5; i++) {
//m_prototypes.insert(i, new ActionsModel(this, i, getDefaultConfig(filter_flags[i])));
registerPrototype(static_cast<uint32_t>(filter_flags[i]), DBAction::ACTION_ARG_ALL, getDefaultConfig(filter_flags[i]));
//m_prototypes.insert(i, new ActionsModel(this, i));
Expand All @@ -33,6 +33,9 @@ void Actions::registerActionOwner(ActionOwner *owner) {
// unregister action owner

uint32_t Actions::registerPrototype(uint32_t location_filter, uint32_t accepts_filter, QString config) {
if (location_filter == DBAction::ACTION_LOC_TRAY) {
location_filter = DBAction::ACTION_LOC_CUSTOM;
}
m_prototypes.insert(prototype_counter, new ActionsModel(this, location_filter, config));
return prototype_counter++;
}
Expand Down Expand Up @@ -138,6 +141,11 @@ QString Actions::getDefaultConfig(DBAction::ActionLocations location) {
case DBAction::ACTION_LOC_TRACK_CONTEXT:
return "[{\"action\":\"add_to_front_of_playback_queue\",\"properties\":{\"extract\":true}},{\"action\":\"add_to_playback_queue\",\"properties\":{\"extract\":true}},{\"action\":\"remove_from_playback_queue\",\"properties\":{\"extract\":true,\"separator_after\":true}},{\"action\":\"q_cut\"},{\"action\":\"q_copy\"},{\"action\":\"q_paste\",\"properties\":{\"separator_after\":true}},{\"action\":\"q_track_properties\",\"properties\":{\"last\":true}}]";
break;
case DBAction::ACTION_LOC_TRAY:
return "[{\"action\":\"stop\",\"properties\":{\"extract\":true}},{\"action\":\"play\",\"properties\":{\"extract\":true}},{\"action\":\"pause\",\"properties\":{\"extract\":true}},{\"action\":\"prev\",\"properties\":{\"extract\":true}},{\"action\":\"next\",\"properties\":{\"extract\":true}},{\"action\":\"playback_random\",\"properties\":{\"extract\":true}},{\"action\":\"q_about\", \"properties\": {\"extract\": true}},{\"action\":\"q_quit\", \"properties\":{\"separator_before\": true, \"extract\":true}}]";
break;
default:
break;
}
return {};
}
Expand Down
11 changes: 8 additions & 3 deletions dbapi/Actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ class DBAction : public QObject {
};
Q_ENUM(ActionAccepts);
enum ActionLocations {
ACTION_LOC_CUSTOM = 0, // only add actions from prototype
ACTION_LOC_HOTKEY = 1 << 0,
ACTION_LOC_TRACK_CONTEXT = 1 << 1, // item(s) context
ACTION_LOC_PLAYLIST_CONTEXT = 1 << 2,
ACTION_LOC_MENUBAR = 1 << 3,
ACTION_LOC_TRAY = 1 << 4,
ACTION_LOC_ALL = (ACTION_LOC_HOTKEY | ACTION_LOC_TRACK_CONTEXT |
ACTION_LOC_PLAYLIST_CONTEXT | ACTION_LOC_MENUBAR)
ACTION_LOC_PLAYLIST_CONTEXT | ACTION_LOC_MENUBAR |
ACTION_LOC_TRAY)

};
Q_ENUM(ActionLocations);
Expand Down Expand Up @@ -104,8 +107,8 @@ public slots:
protected:


const int filter_flags[4] = { DBAction::ACTION_LOC_HOTKEY, DBAction::ACTION_LOC_TRACK_CONTEXT,
DBAction::ACTION_LOC_PLAYLIST_CONTEXT, DBAction::ACTION_LOC_MENUBAR };
const int filter_flags[5] = { DBAction::ACTION_LOC_HOTKEY, DBAction::ACTION_LOC_TRACK_CONTEXT,
DBAction::ACTION_LOC_PLAYLIST_CONTEXT, DBAction::ACTION_LOC_MENUBAR, DBAction::ACTION_LOC_TRAY };

void rebuildMenu(DBAction::ActionLocations);

Expand All @@ -125,6 +128,8 @@ public slots:
return 2;
case DBAction::ACTION_LOC_MENUBAR:
return 3;
case DBAction::ACTION_LOC_TRAY:
return 4;
default:
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion dbapi/models/ActionsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void ActionsModel::rebuildActionTree() {
// first round of adding from prototype
for (QString &action_id : order) {
DBAction *action = actions->getAction(action_id);
if (action && action->locations & location_filter) {
DBAction::ActionLocations location_filter_custom = location_filter == DBAction::ACTION_LOC_CUSTOM ? DBAction::ACTION_LOC_ALL : (DBAction::ActionLocations)location_filter;
if (action && action->locations & location_filter_custom) {
QStringList order_path;
if (order_extract.contains(action_id)) {
tree->insertChild(action->title, action->action_id);
Expand Down
2 changes: 1 addition & 1 deletion widgets/ActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ ActionHandlers::ActionHandlers(QWidget *parent, DBApi *Api) : QObject(parent) {
}

// design mode
if (action = api->actions.getAction("q_design_mode")) {
if ((action = api->actions.getAction("q_design_mode"))) {
connect(action, &DBAction::actionApplied, Api, [parent, Api]() {
PluginManager* pm = Api->property("ddbw_pluginmanager").value<PluginManager*>();
bool state_new = !Api->conf.get("MainWindow", "widgets_locked", false).toBool();
Expand Down
8 changes: 8 additions & 0 deletions widgets/DBActionMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ QMenu* buildTrackContextMenu(QWidget *parent, DBApi *Api, PlayItemIterator pit)
buildMenuIter(menu, Api, array, pit);
return menu;
}

QMenu* buildTrayContextMenu(QWidget *parent, DBApi *Api) {
PlayItemIterator pit = PlayItemIterator();
QMenu *menu = new QMenu(parent);
QJsonArray array = Api->actions.parsePrototype(4, pit);
buildMenuIter(menu, Api, array, pit);
return menu;
}
1 change: 1 addition & 0 deletions widgets/DBActionMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@

QMenuBar* buildMenuBar(QWidget *parent, DBApi *Api);
QMenu* buildTrackContextMenu(QWidget *parent, DBApi *Api, PlayItemIterator pit);
QMenu* buildTrayContextMenu(QWidget *parent, DBApi *Api);

#endif // DBACTIONMENU_H
3 changes: 3 additions & 0 deletions widgets/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ MainWindow::MainWindow(QWidget *parent, DBApi *Api)
DBAction* action = api->actions.getAction("q_design_mode");
action->properties_const.insert("checked", widgets_locked);
emit action->actionPropertiesChanged();

tray = new TrayIcon(this, api);
}

MainWindow::~MainWindow() {
Expand All @@ -94,6 +96,7 @@ MainWindow::~MainWindow() {
void MainWindow::closeEvent(QCloseEvent *event) {
api->conf.set("MainWindow", "geometry", saveGeometry());
api->conf.set("MainWindow", "state", saveState());
delete tray;
QMainWindow::closeEvent(event);
}

Expand Down
2 changes: 2 additions & 0 deletions widgets/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "PluginManager.h"
#include "ActionHandlers.h"
#include "TrayIcon.h"

class MainWindow : public QMainWindow
{
Expand All @@ -22,6 +23,7 @@ class MainWindow : public QMainWindow
protected:
PluginManager plugins;
ActionHandlers action_handlers;
TrayIcon *tray;
signals:

};
Expand Down

0 comments on commit 0aba96a

Please sign in to comment.