-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathddedockmpdplugin.cpp
202 lines (168 loc) · 6.07 KB
/
ddedockmpdplugin.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* Author: Linus Boyle <[email protected]>
*
* 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 3 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. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ddedockmpdplugin.h"
#include "ddedockmpdwidget.h"
#include "tipswidget.h"
#include "mpdinterface.h"
#include <QDebug>
#include <QMessageBox>
#include "playlistwidget.h"
#define WIDGET_KEY QString("dde-dock-mpd")
DDEDockMPDPlugin::DDEDockMPDPlugin(QObject *parent)
:QObject(parent),
m_setting(new QSettings("deepin","dde-dock-mpd",this))
{
}
const QString DDEDockMPDPlugin::pluginName() const {
return QStringLiteral("MPDController");
}
const QString DDEDockMPDPlugin::pluginDisplayName() const {
return QStringLiteral("MPD");
}
void DDEDockMPDPlugin::init(PluginProxyInterface *proxyInter) {
m_proxyInter = proxyInter;
m_widget = new DDEDockMPDWidget();
m_tipwidget = new TipsWidget();
m_playlist = new PlaylistWidget();
QTranslator* translator = new QTranslator();
if(translator->load(":/qm/dde-dock-mpd_" + QLocale::system().name()))
qApp->installTranslator(translator);
else {
qDebug()<<"load translation failed for " <<QLocale::system().name();
translator->deleteLater();
}
if(m_widget->isEnabled() && displayMode() == Dock::DisplayMode::Efficient
&& positionValid() )
proxyInter->itemAdded(this,WIDGET_KEY);
}
QWidget *DDEDockMPDPlugin::itemWidget(const QString &itemKey)
{
Q_UNUSED(itemKey);
return m_widget;
}
QWidget *DDEDockMPDPlugin::itemTipsWidget(const QString &itemKey){
Q_UNUSED(itemKey);
return m_tipwidget;
}
QWidget *DDEDockMPDPlugin::itemPopupApplet(const QString &itemKey){
Q_UNUSED(itemKey);
return m_playlist;
}
bool DDEDockMPDPlugin::pluginIsDisable(){
return !m_widget->isEnabled();
}
void DDEDockMPDPlugin::pluginStateSwitched(){
m_widget->setEnabled(!m_widget->isEnabled());
if(m_widget->isEnabled() && displayMode() == Dock::DisplayMode::Efficient && positionValid()){
m_proxyInter->itemAdded(this,WIDGET_KEY);
m_widget->show();
} else if(displayMode() == Dock::DisplayMode::Efficient && positionValid()){
m_proxyInter->itemRemoved(this,WIDGET_KEY);
m_widget->hide();
}
}
const QString DDEDockMPDPlugin::itemContextMenu(const QString &itemKey){
Q_UNUSED(itemKey);
QList<QVariant> items;
items.reserve(2);
QMap<QString, QVariant> mode;
mode["itemId"] = "repeatMode";
if(MPDInterface::instance()->getRepeatMode()){
mode["itemText"] = tr("Stop Loop");
} else {
mode["itemText"]= tr("Loop Playlist");
}
mode["isActive"] = true;
items.push_back(mode);
QMap<QString,QVariant> about;
about["itemId"] = "about";
about["itemText"] = tr("About");
about["isActive"] = true;
items.push_back(about);
QMap<QString, QVariant> menu;
menu["items"] = items;
menu["checkableMenu"] = false;
menu["singleCheck"] = false;
return QJsonDocument::fromVariant(menu).toJson();
}
void DDEDockMPDPlugin::invokedMenuItem(const QString &itemkey, const QString &menuId, const bool checked){
Q_UNUSED(itemkey);
Q_UNUSED(checked);
if(menuId == "repeatMode")
MPDInterface::instance()->switchRepeatMode();
else if (menuId == "about"){
QMessageBox aboutMessage(QMessageBox::NoIcon,tr("MPD Control Plugin"),tr("This Plugin is intended for "
"getting information of and controlling MPD"
"from dde-dock\nAuthor:Linus Boyle<[email protected]>\n"
"Licensed under GPLv3,you can find the source code on Github"));
aboutMessage.setIconPixmap(QPixmap(":/icon/mpd.svg").scaled(48,48,Qt::KeepAspectRatio));
aboutMessage.exec();
}
}
void DDEDockMPDPlugin::displayModeChanged(const Dock::DisplayMode displaymode) {
switch (displaymode) {
case Dock::DisplayMode::Fashion:
if(!this->pluginIsDisable() && positionValid())
m_proxyInter->itemRemoved(this,WIDGET_KEY);
break;
case Dock::DisplayMode::Efficient:
if(!this->pluginIsDisable() && positionValid())
m_proxyInter->itemAdded(this,WIDGET_KEY);
break;
default:
break;
}
}
void DDEDockMPDPlugin::positionChanged(const Dock::Position position) {
switch (position) {
case Dock::Position::Bottom:
case Dock::Position::Top:
if(!this->pluginIsDisable() && displayMode() == Dock::DisplayMode::Efficient){
m_proxyInter->itemAdded(this,WIDGET_KEY);
}
break;
case Dock::Position::Left:
case Dock::Position::Right:
if(!this->pluginIsDisable() && displayMode() == Dock::DisplayMode::Efficient){
m_proxyInter->itemRemoved(this,WIDGET_KEY);
}
break;
default:
break;
}
}
int DDEDockMPDPlugin::itemSortKey(const QString &itemKey) {
Q_UNUSED(itemKey);
return m_setting->value("position",0).toInt();
}
void DDEDockMPDPlugin::setSortKey(const QString &itemKey, const int order) {
Q_UNUSED(itemKey);
m_setting->setValue("position",order);
}
bool DDEDockMPDPlugin::positionValid(){
switch (position()) {
case Dock::Position::Bottom:
case Dock::Position::Top:
return true;
case Dock::Position::Left:
case Dock::Position::Right:
return false;
default:
Q_UNREACHABLE();
break;
}
}