Commit 572e2ce0 authored by Carsten Fuhrmann's avatar Carsten Fuhrmann

show speaker only from current server,

add button to minimize to toggle current Channel/complete server,
window can now be moved from background, too,
parent 0861d949
...@@ -51,25 +51,76 @@ void ChannelTree::mouseMoveEvent(QMouseEvent * event) ...@@ -51,25 +51,76 @@ void ChannelTree::mouseMoveEvent(QMouseEvent * event)
} }
///////////////////////////////////////////////////////////////////////////////////////
Background::Background(ChannelListWidget * widget, QWidget *parent)
: QLabel(parent)
{
m_parent = widget;
QFile styleSheet("plugins\\qtTsOverlay\\background.styl");
styleSheet.open(QIODevice::ReadOnly);
setStyleSheet(styleSheet.readAll());
styleSheet.close();
}
Background::~Background()
{
}
void Background::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
doMove = true;
else if (event->button() == Qt::RightButton)
m_parent->hide();
QLabel::mousePressEvent(event);
}
void Background::mouseReleaseEvent(QMouseEvent * event)
{
doMove = false;
QLabel::mouseReleaseEvent(event);
}
void Background::mouseMoveEvent(QMouseEvent * event)
{
if (doMove)
m_parent->move(event->globalPos());
QLabel::mouseMoveEvent(event);
}
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
ChannelListWidget::ChannelListWidget(QWidget *parent) ChannelListWidget::ChannelListWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
m_state = full;
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::SplashScreen); setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::SplashScreen);
move(320, 200); move(320, 200);
m_background = new QLabel(this); m_background = new Background(this, this);
QFile styleSheet("plugins\\qtTsOverlay\\background.styl");
styleSheet.open(QIODevice::ReadOnly);
m_background->setStyleSheet(styleSheet.readAll());
styleSheet.close();
QVBoxLayout* layout = new QVBoxLayout(this); QVBoxLayout* layout = new QVBoxLayout(this);
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(0); layout->setSpacing(0);
m_button = new QPushButton(this);
m_button->setText("-");
connect(m_button, &QPushButton::pressed, this, &ChannelListWidget::buttonPressed);
QFile style("plugins\\qtTsOverlay\\button.styl");
style.open(QIODevice::ReadOnly);
m_button->setStyleSheet(style.readAll());
style.close();
layout->addWidget(m_button, 0, Qt::AlignTop | Qt::AlignRight);
m_child = new ChannelTree(this); m_child = new ChannelTree(this);
layout->addWidget(m_child); layout->addWidget(m_child);
...@@ -84,6 +135,7 @@ ChannelListWidget::~ChannelListWidget() ...@@ -84,6 +135,7 @@ ChannelListWidget::~ChannelListWidget()
delete m_child; delete m_child;
delete m_grip; delete m_grip;
delete m_background; delete m_background;
delete m_button;
} }
QTreeWidget * ChannelListWidget::getTree() QTreeWidget * ChannelListWidget::getTree()
...@@ -91,6 +143,22 @@ QTreeWidget * ChannelListWidget::getTree() ...@@ -91,6 +143,22 @@ QTreeWidget * ChannelListWidget::getTree()
return (QTreeWidget*)m_child; return (QTreeWidget*)m_child;
} }
void ChannelListWidget::buttonPressed()
{
if (m_state == full)
{
m_state = minimum;
m_button->setText("O");
}
else
{
m_state = full;
m_button->setText("-");
}
emit treeStateChanged(m_state);
}
void ChannelListWidget::resizeEvent(QResizeEvent *event) void ChannelListWidget::resizeEvent(QResizeEvent *event)
{ {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
......
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
#include <QTreeWidget> #include <QTreeWidget>
#include <QSizeGrip> #include <QSizeGrip>
#include <QLabel> #include <QLabel>
#include <QPushButton>
enum TreeState {
full,
minimum
};
class ChannelListWidget; class ChannelListWidget;
...@@ -25,7 +31,25 @@ private: ...@@ -25,7 +31,25 @@ private:
QPoint m_oldPosition; QPoint m_oldPosition;
QWidget *m_parent; QWidget *m_parent;
};
class Background : public QLabel
{
Q_OBJECT
public: public:
explicit Background(ChannelListWidget * widget, QWidget *parent = NULL);
~Background();
protected:
virtual void mousePressEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
virtual void mouseMoveEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
private:
bool doMove = false;
QPoint m_oldPosition;
QWidget *m_parent;
}; };
...@@ -38,9 +62,14 @@ public: ...@@ -38,9 +62,14 @@ public:
~ChannelListWidget(); ~ChannelListWidget();
private: private:
TreeState m_state;
ChannelTree *m_child; ChannelTree *m_child;
QSizeGrip *m_grip; QSizeGrip *m_grip;
QLabel *m_background; Background *m_background;
QPushButton* m_button;
private slots:
void buttonPressed();
protected: protected:
virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
...@@ -48,4 +77,7 @@ protected: ...@@ -48,4 +77,7 @@ protected:
public: public:
QTreeWidget* getTree(); QTreeWidget* getTree();
signals:
void treeStateChanged(TreeState state);
}; };
QPushButton {
width:10px;
height:10px;
font-size:10px;
background-color:rgba(50,50,50,0);
color:rgb(255,255,255);
border-style:solid;
border-radius:5px;
border-width:1px;
border-color:rgb(100,100,100);
padding:2px;
margin:2px;
}
QPushButton:hover {
width:10px;
height:10px;
background-color:rgba(255,255,255,100);
color:rgb(0,0,0);
border-style:solid;
border-radius:5px;
border-width:1px;
border-color:rgb(100,100,100);
padding:2px;
}
\ No newline at end of file
...@@ -20,10 +20,13 @@ enum nodeType { ...@@ -20,10 +20,13 @@ enum nodeType {
Q_DECLARE_METATYPE(nodeType); Q_DECLARE_METATYPE(nodeType);
OverlayController::OverlayController(const struct TS3Functions funcs, quint64 serverConnectionHandlerID) : QObject(), ts3(funcs) OverlayController::OverlayController(const struct TS3Functions funcs, quint64 serverConnectionHandlerID) : QObject(), m_ts3(funcs)
{ {
QDesktopWidget desktop; QDesktopWidget desktop;
m_muted = false;
m_treeState = full;
m_channelIcon.addFile("plugins\\qtTsOverlay\\channel.png"); m_channelIcon.addFile("plugins\\qtTsOverlay\\channel.png");
m_clientIcon.addFile("plugins\\qtTsOverlay\\client.png"); m_clientIcon.addFile("plugins\\qtTsOverlay\\client.png");
...@@ -46,8 +49,10 @@ OverlayController::OverlayController(const struct TS3Functions funcs, quint64 se ...@@ -46,8 +49,10 @@ OverlayController::OverlayController(const struct TS3Functions funcs, quint64 se
m_tree = new ChannelListWidget; m_tree = new ChannelListWidget;
connect(m_tree->getTree(), &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked); connect(m_tree->getTree(), &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
connect(m_tree, &ChannelListWidget::treeStateChanged, this, &OverlayController::changeTreeState);
updateChannelList(); updateChannelList();
updateClientList();
} }
OverlayController::~OverlayController() OverlayController::~OverlayController()
...@@ -90,18 +95,25 @@ void OverlayController::treeItemClicked(QTreeWidgetItem * item, int column) ...@@ -90,18 +95,25 @@ void OverlayController::treeItemClicked(QTreeWidgetItem * item, int column)
if (type == channel) if (type == channel)
{ {
anyID clientID; anyID clientID;
ts3.getClientID(m_SCHID, &clientID); m_ts3.getClientID(m_SCHID, &clientID);
quint64 id = item->data(1, Qt::UserRole).value<quint64>(); quint64 id = item->data(1, Qt::UserRole).value<quint64>();
ts3.requestClientMove(m_SCHID, clientID, id, "", NULL); m_ts3.requestClientMove(m_SCHID, clientID, id, "", NULL);
} }
else if (type == client) else if (type == client)
{ {
anyID id = item->data(1, Qt::UserRole).value<anyID>(); anyID id = item->data(1, Qt::UserRole).value<anyID>();
ts3.requestClientPoke(m_SCHID, id, "", NULL); m_ts3.requestClientPoke(m_SCHID, id, "", NULL);
} }
} }
void OverlayController::changeTreeState(TreeState state)
{
m_treeState = state;
updateChannelList();
updateClientList();
}
void OverlayController::addChatLine(QString message) void OverlayController::addChatLine(QString message)
{ {
// generate new chatline // generate new chatline
...@@ -147,6 +159,9 @@ void OverlayController::addChatLine(QString message) ...@@ -147,6 +159,9 @@ void OverlayController::addChatLine(QString message)
void OverlayController::addSpeaker(QString name) void OverlayController::addSpeaker(QString name)
{ {
if (m_muted)
return;
int labelWidth = 0; int labelWidth = 0;
QWidget* w = new QWidget; QWidget* w = new QWidget;
QLabel* newSpeaker = new QLabel(w); QLabel* newSpeaker = new QLabel(w);
...@@ -224,7 +239,7 @@ void OverlayController::updateChannelList() ...@@ -224,7 +239,7 @@ void OverlayController::updateChannelList()
{ {
// get list of all channelIDs // get list of all channelIDs
uint64* channelIDList; uint64* channelIDList;
if (ts3.getChannelList(m_SCHID, &channelIDList) != ERROR_ok) if (m_ts3.getChannelList(m_SCHID, &channelIDList) != ERROR_ok)
return; return;
// remove old stuff // remove old stuff
...@@ -240,8 +255,8 @@ void OverlayController::updateChannelList() ...@@ -240,8 +255,8 @@ void OverlayController::updateChannelList()
ChannelInfo tmp; ChannelInfo tmp;
tmp.id = channelIDList[i]; tmp.id = channelIDList[i];
tmp.name = channelID2Name(m_SCHID, channelIDList[i]); tmp.name = channelID2Name(m_SCHID, channelIDList[i]);
ts3.getChannelVariableAsInt(m_SCHID, tmp.id, CHANNEL_ORDER, &tmp.order); m_ts3.getChannelVariableAsInt(m_SCHID, tmp.id, CHANNEL_ORDER, &tmp.order);
ts3.getParentChannelOfChannel(m_SCHID, channelIDList[i], &tmp.parent); m_ts3.getParentChannelOfChannel(m_SCHID, channelIDList[i], &tmp.parent);
tmp.entry = new QTreeWidgetItem; tmp.entry = new QTreeWidgetItem;
tmp.entry->setData(0, Qt::DisplayRole, tmp.name); tmp.entry->setData(0, Qt::DisplayRole, tmp.name);
tmp.entry->setData(1, Qt::UserRole, tmp.id); tmp.entry->setData(1, Qt::UserRole, tmp.id);
...@@ -261,54 +276,80 @@ void OverlayController::updateChannelList() ...@@ -261,54 +276,80 @@ void OverlayController::updateChannelList()
i++; i++;
} }
// for every channel if (m_treeState == full)
for (auto &parent : m_channelList)
{ {
// collect all childs
QVector<ChannelInfo> childs; // for every channel
for (auto &child : m_channelList) for (auto &parent : m_channelList)
if (child.parent == parent.id) {
childs.push_back(child); // collect all childs
QVector<ChannelInfo> childs;
// add childs in correct order for (auto &child : m_channelList)
int prevID(0); if (child.parent == parent.id)
while (!childs.isEmpty()) childs.push_back(child);
// add childs in correct order
int prevID(0);
while (!childs.isEmpty())
{
int i;
for (i = 0; i < childs.size(); i++)
if (childs[i].order == prevID)
break;
prevID = childs[i].id;
parent.entry->addChild(childs.takeAt(i).entry);
}
}
// get all toplvl channels
QVector<ChannelInfo> topLvlList;
for (auto &it : m_channelList)
if (it.parent == 0)
topLvlList.push_back(it);
// add toplvl to tree in correct order
int prevID = 0;
while (!topLvlList.isEmpty())
{ {
int i; int i;
for (i = 0; i < childs.size(); i++) for (i = 0; i < topLvlList.size(); i++)
if (childs[i].order == prevID) if (topLvlList[i].order == prevID)
break; break;
prevID = childs[i].id; prevID = topLvlList[i].id;
parent.entry->addChild(childs.takeAt(i).entry); m_tree->getTree()->addTopLevelItem(topLvlList.takeAt(i).entry);
} }
} }
else if (m_treeState == minimum)
{
//TODO: different order
uint64 channel = getCurrentChannel(m_SCHID);
QTreeWidgetItem* item = NULL;
// get all toplvl channels for (auto &it : m_channelList)
QVector<ChannelInfo> topLvlList; if (it.id == channel)
for (auto &it : m_channelList) item = it.entry;
if (it.parent == 0)
topLvlList.push_back(it);
// add toplvl to tree in correct order if (item == NULL)
int prevID = 0; {
while (!topLvlList.isEmpty()) debugPrint("i was here");
{ m_ts3.freeMemory(channelIDList);
int i; return;
for (i = 0; i < topLvlList.size(); i++) }
if (topLvlList[i].order == prevID) m_tree->getTree()->addTopLevelItem(item);
break;
prevID = topLvlList[i].id;
m_tree->getTree()->addTopLevelItem(topLvlList.takeAt(i).entry);
} }
updateClientList();
m_tree->getTree()->expandAll(); m_tree->getTree()->expandAll();
m_ts3.freeMemory(channelIDList);
} }
void OverlayController::updateClientList() void OverlayController::updateClientList()
{ {
if (m_treeState == minimum)
updateChannelList();
//TODO: remove all clients //TODO: remove all clients
while (!m_clientList.isEmpty()) while (!m_clientList.isEmpty())
delete m_clientList.takeFirst(); delete m_clientList.takeFirst();
...@@ -317,7 +358,7 @@ void OverlayController::updateClientList() ...@@ -317,7 +358,7 @@ void OverlayController::updateClientList()
for (auto& it : m_channelList) for (auto& it : m_channelList)
{ {
anyID* clientIDList; anyID* clientIDList;
if (ts3.getChannelClientList(m_SCHID, it.id, &clientIDList) != ERROR_ok) if (m_ts3.getChannelClientList(m_SCHID, it.id, &clientIDList) != ERROR_ok)
continue; continue;
int i(0); int i(0);
...@@ -333,6 +374,7 @@ void OverlayController::updateClientList() ...@@ -333,6 +374,7 @@ void OverlayController::updateClientList()
it.entry->addChild(tmp); it.entry->addChild(tmp);
i++; i++;
} }
m_ts3.freeMemory(clientIDList);
} }
} }
...@@ -342,3 +384,15 @@ void OverlayController::displayChannelList() ...@@ -342,3 +384,15 @@ void OverlayController::displayChannelList()
m_tree->adjustSize(); m_tree->adjustSize();
m_tree->show(); m_tree->show();
} }
void OverlayController::mute(bool value)
{
m_muted = value;
if (m_muted)
{
m_speakerOffset = 0;
while (!m_speakers.isEmpty())
delete m_speakers.takeFirst();
}
}
...@@ -26,6 +26,7 @@ struct ChannelInfo { ...@@ -26,6 +26,7 @@ struct ChannelInfo {
int order; int order;
}; };
class QTTSOVERLAY_EXPORT OverlayController : public QObject class QTTSOVERLAY_EXPORT OverlayController : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -35,8 +36,10 @@ public: ...@@ -35,8 +36,10 @@ public:
~OverlayController(); ~OverlayController();
private: private:
const struct TS3Functions ts3; const struct TS3Functions m_ts3;
quint64 m_SCHID; quint64 m_SCHID;
bool m_muted;
TreeState m_treeState;
int m_screenWidth; int m_screenWidth;
int m_screenHeight; int m_screenHeight;
int m_speakerOffset; int m_speakerOffset;
...@@ -57,6 +60,7 @@ private: ...@@ -57,6 +60,7 @@ private:
private slots: private slots:
void treeItemClicked(QTreeWidgetItem * item, int column); void treeItemClicked(QTreeWidgetItem * item, int column);
void changeTreeState(TreeState state);
public: public:
void addChatLine(QString message); void addChatLine(QString message);
...@@ -67,4 +71,5 @@ public: ...@@ -67,4 +71,5 @@ public:
void updateChannelList(); void updateChannelList();
void updateClientList(); void updateClientList();
void displayChannelList(); void displayChannelList();
void mute(bool value);
}; };
...@@ -131,6 +131,16 @@ OverlayController* getController(uint64 serverConnectionHandlerID = 0) ...@@ -131,6 +131,16 @@ OverlayController* getController(uint64 serverConnectionHandlerID = 0)
return tmp.value(); return tmp.value();
} }
void setActiveServer(uint64 serverConnectionHanderlID)
{
// mute all server
for (auto& it : g_serverList)
it->mute(true);
// unmute the current server
getController(serverConnectionHanderlID)->mute(false);
}
/* Helper function to create a hotkey */ /* Helper function to create a hotkey */
static struct PluginHotkey* createHotkey(const char* keyword, const char* description) { static struct PluginHotkey* createHotkey(const char* keyword, const char* description) {
struct PluginHotkey* hotkey = (struct PluginHotkey*)malloc(sizeof(struct PluginHotkey)); struct PluginHotkey* hotkey = (struct PluginHotkey*)malloc(sizeof(struct PluginHotkey));
...@@ -173,7 +183,7 @@ const char* ts3plugin_name() { ...@@ -173,7 +183,7 @@ const char* ts3plugin_name() {
/* Plugin version */ /* Plugin version */
const char* ts3plugin_version() { const char* ts3plugin_version() {
return "0.2"; return "1.0";
} }
/* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */ /* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */
...@@ -359,6 +369,7 @@ void ts3plugin_onConnectStatusChangeEvent(uint64 serverConnectionHandlerID, int ...@@ -359,6 +369,7 @@ void ts3plugin_onConnectStatusChangeEvent(uint64 serverConnectionHandlerID, int
else if (newStatus == STATUS_CONNECTION_ESTABLISHED) else if (newStatus == STATUS_CONNECTION_ESTABLISHED)
{ {