1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "uiinterface.h"
24
UIInterface::UIInterface(QObject* parent)
29
void UIInterface::RegisterActionLocation(const QString& id, QMenu* menu, QAction* before) {
30
if (locations_.contains(id)) {
31
qDebug() << __PRETTY_FUNCTION__
32
<< "A location with ID" << id << "was already registered";
36
locations_[id] = Location(menu, before);
38
connect(menu, SIGNAL(destroyed()), SLOT(MenuDestroyed()));
40
connect(before, SIGNAL(destroyed()), SLOT(MenuActionDestroyed()));
43
// Add any actions that were waiting
44
foreach (const IdAndAction& id_action, pending_actions_) {
45
if (id_action.first == id) {
46
DoAddAction(id_action.first, id_action.second);
47
pending_actions_.removeAll(id_action);
52
void UIInterface::AddAction(const QString& id, QAction* action) {
53
if (locations_.contains(id)) {
54
DoAddAction(id, action);
56
// Maybe that part of the UI hasn't been lazy created yet
57
pending_actions_ << IdAndAction(id, action);
58
connect(action, SIGNAL(destroyed()), SLOT(ActionDestroyed()));
62
void UIInterface::DoAddAction(const QString& id, QAction* action) {
63
const Location& location = locations_[id];
66
location.menu_->insertAction(location.before_, action);
70
void UIInterface::MenuDestroyed() {
71
QMenu* menu = qobject_cast<QMenu*>(sender());
72
foreach (const QString& id, locations_.keys()) {
73
if (locations_[id].menu_ == menu) {
74
locations_.remove(id);
79
void UIInterface::MenuActionDestroyed() {
80
QAction* action = qobject_cast<QAction*>(sender());
81
foreach (const QString& id, locations_.keys()) {
82
if (locations_[id].before_ == action) {
83
locations_.remove(id);
88
void UIInterface::ActionDestroyed() {
89
QAction* action = qobject_cast<QAction*>(sender());
90
foreach (const IdAndAction& id_action, pending_actions_) {
91
if (id_action.second == action) {
92
pending_actions_.removeAll(id_action);