You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdebluez/src/tdebluez/mediacontrol.cpp

182 lines
5.6 KiB

/*
*
* MediaControl for tdebluez
*
* Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com>
*
*
* This file is part of tdebluez.
*
* tdebluez 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.
*
* tdebluez 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 kbluetooth; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <kdebug.h>
#include <tqpushbutton.h>
#include <tqslider.h>
#include <kiconloader.h>
#include "mediacontrol.h"
MediaControl::MediaControl(TQString path, TQT_DBusConnection *conn) :
MediaCtlDlg()
{
pixStart = TDEGlobal::iconLoader()->loadIcon("media-playback-start", TDEIcon::Small, 22);
pixPause = TDEGlobal::iconLoader()->loadIcon("media-playback-pause", TDEIcon::Small, 22);
tQPushButtonPlay->setPixmap(pixStart);
tQPushButtonSeekForward->setPixmap(TDEGlobal::iconLoader()->loadIcon("media-seek-forward", TDEIcon::Small, 22));
tQPushButtonSeekBackward->setPixmap(TDEGlobal::iconLoader()->loadIcon("media-seek-backward", TDEIcon::Small, 22));
tQPushButtonForward->setPixmap(TDEGlobal::iconLoader()->loadIcon("media-skip-forward", TDEIcon::Small, 22));
tQPushButtonBackward->setPixmap(TDEGlobal::iconLoader()->loadIcon("media-skip-backward", TDEIcon::Small, 22));
tQPushButtonStop->setPixmap(TDEGlobal::iconLoader()->loadIcon("media-playback-stop", TDEIcon::Small, 22));
tQVolumeSlider->setTracking(false);
tQVolumeSlider->setRange(0, 100);
volume = 50;
tQVolumeSlider->setValue(volume);
mPath = path;
mediaCtlProxy = new org::bluez::MediaControl1Proxy("org.bluez", path);
mediaCtlProxy->setConnection((*(conn)));
connect((TQObject*) tQPushButtonPlay, SIGNAL(clicked()), this, TQT_SLOT(slotPlay()));
connect((TQObject*) tQPushButtonPlay, SIGNAL(toggled(bool)), this, TQT_SLOT(slotPlayToggled(bool)));
connect((TQObject*) tQPushButtonSeekForward, SIGNAL(clicked()), this, TQT_SLOT(slotFastForward()));
connect((TQObject*) tQPushButtonSeekBackward, SIGNAL(clicked()), this, TQT_SLOT(slotRewind()));
connect((TQObject*) tQPushButtonForward, SIGNAL(clicked()), this, TQT_SLOT(slotNext()));
connect((TQObject*) tQPushButtonBackward, SIGNAL(clicked()), this, TQT_SLOT(slotPrevious()));
connect((TQObject*) tQPushButtonStop, SIGNAL(clicked()), this, TQT_SLOT(slotStop()));
// tQProgressSlider
connect((TQObject*) tQVolumeSlider, SIGNAL(valueChanged(int)), this, TQT_SLOT(slotVolumeValueChanged(int)));
// tQPushButtonRepeat
show();
}
MediaControl::~MediaControl()
{
if (mediaCtlProxy)
delete mediaCtlProxy;
}
//void MediaControl::closeMediaControl()
//{
//
//}
void MediaControl::slotPlay()
{
kdDebug() << k_funcinfo << endl;
TQT_DBusError error;
mediaCtlProxy->Play(error);
if (error.isValid())
tqDebug("Media Play failed: %s", error.message().local8Bit().data());
}
void MediaControl::slotPlayToggled(bool state)
{
kdDebug() << k_funcinfo << endl;
if (state)
{
tQPushButtonPlay->setPixmap(pixPause);
}
else
{
slotPause();
tQPushButtonPlay->setPixmap(pixStart);
}
}
void MediaControl::slotStop()
{
kdDebug() << k_funcinfo << endl;
TQT_DBusError error;
if (mediaCtlProxy->Stop(error))
{
if (tQPushButtonPlay->isOn())
tQPushButtonPlay->toggle();
}
if (error.isValid())
tqDebug("Media Stop failed: %s", error.message().local8Bit().data());
}
void MediaControl::slotPause()
{
kdDebug() << k_funcinfo << endl;
TQT_DBusError error;
mediaCtlProxy->Pause(error);
if (error.isValid())
tqDebug("Media Pause failed: %s", error.message().local8Bit().data());
}
void MediaControl::slotNext()
{
kdDebug() << k_funcinfo << endl;
TQT_DBusError error;
mediaCtlProxy->Next(error);
if (error.isValid())
tqDebug("Media Next failed: %s", error.message().local8Bit().data());
}
void MediaControl::slotPrevious()
{
kdDebug() << k_funcinfo << endl;
TQT_DBusError error;
mediaCtlProxy->Previous(error);
if (error.isValid())
tqDebug("Media Previous failed: %s", error.message().local8Bit().data());
}
void MediaControl::slotFastForward()
{
kdDebug() << k_funcinfo << endl;
TQT_DBusError error;
mediaCtlProxy->FastForward(error);
if (error.isValid())
tqDebug("Media FastForward failed: %s", error.message().local8Bit().data());
}
void MediaControl::slotRewind()
{
kdDebug() << k_funcinfo << endl;
TQT_DBusError error;
mediaCtlProxy->Rewind(error);
if (error.isValid())
tqDebug("Media Rewind failed: %s", error.message().local8Bit().data());
}
void MediaControl::slotVolumeValueChanged(int val)
{
kdDebug() << k_funcinfo << endl;
TQT_DBusError error;
if (val > volume)
{
TQT_DBusError error;
mediaCtlProxy->VolumeUp(error);
if (error.isValid())
tqDebug("Media VolumeUp getPowered failed: %s", error.message().local8Bit().data());
}
if (val < volume)
{
mediaCtlProxy->VolumeDown(error);
if (error.isValid())
tqDebug("Media VolumeDown getPowered failed: %s", error.message().local8Bit().data());
}
volume = val;
}
#include "mediacontrol.moc"