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.
425 lines
11 KiB
425 lines
11 KiB
15 years ago
|
/***************************************************************************
|
||
|
quickbar.cpp - description
|
||
|
-------------------
|
||
|
begin : Mon Feb 11 2002
|
||
|
copyright : (C) 2002 by Martin Witte / Frank Schwanz
|
||
|
email : witte@kawo1.rwth-aachen.de / schwanz@fh-brandenburg.de
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* 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 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
14 years ago
|
#include <tqtooltip.h>
|
||
|
#include <tqnamespace.h>
|
||
|
#include <tqhbuttongroup.h>
|
||
|
#include <tqvbuttongroup.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdetoolbarbutton.h>
|
||
13 years ago
|
#include <twin.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdeglobal.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
12 years ago
|
#include <tdeaboutdata.h>
|
||
15 years ago
|
|
||
|
#include "../../src/include/aboutwidget.h"
|
||
|
#include "../../src/include/station-drag-object.h"
|
||
|
#include "../../src/include/stationlist.h"
|
||
|
#include "../../src/include/radiostation.h"
|
||
|
|
||
|
#include "buttonflowlayout.h"
|
||
|
#include "quickbar-configuration.h"
|
||
|
#include "quickbar.h"
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////
|
||
|
//// plugin library functions
|
||
|
|
||
12 years ago
|
PLUGIN_LIBRARY_FUNCTIONS(QuickBar, "tderadio-gui-quickbar", i18n("Radio Station Quick Selection Toolbar"));
|
||
15 years ago
|
|
||
|
/////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
14 years ago
|
QuickBar::QuickBar(const TQString &name)
|
||
|
: TQWidget(NULL, name.ascii()),
|
||
15 years ago
|
WidgetPluginBase(name, i18n("Quickbar Plugin")),
|
||
|
m_layout(NULL),
|
||
|
m_buttonGroup(NULL),
|
||
|
m_showShortName(true),
|
||
|
m_ignoreNoticeActivation(false)
|
||
|
{
|
||
|
autoSetCaption();
|
||
|
setAcceptDrops(true);
|
||
|
}
|
||
|
|
||
|
|
||
|
QuickBar::~QuickBar()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
bool QuickBar::connectI(Interface *i)
|
||
|
{
|
||
|
bool a = IRadioClient::connectI(i);
|
||
|
bool b = IStationSelection::connectI(i);
|
||
|
bool c = PluginBase::connectI(i);
|
||
|
|
||
|
return a || b || c;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool QuickBar::disconnectI(Interface *i)
|
||
|
{
|
||
|
bool a = IRadioClient::disconnectI(i);
|
||
|
bool b = IStationSelection::disconnectI(i);
|
||
|
bool c = PluginBase::disconnectI(i);
|
||
|
|
||
|
return a || b || c;
|
||
|
}
|
||
|
|
||
|
|
||
|
// IStationSelection
|
||
|
|
||
14 years ago
|
bool QuickBar::setStationSelection(const TQStringList &sl)
|
||
15 years ago
|
{
|
||
|
if (m_stationIDs != sl) {
|
||
|
m_stationIDs = sl;
|
||
|
rebuildGUI();
|
||
|
notifyStationSelectionChanged(m_stationIDs);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// PluginBase methods
|
||
|
|
||
|
|
||
12 years ago
|
void QuickBar::restoreState (TDEConfig *config)
|
||
15 years ago
|
{
|
||
14 years ago
|
config->setGroup(TQString("quickBar-") + name());
|
||
15 years ago
|
|
||
|
WidgetPluginBase::restoreState(config, false);
|
||
|
|
||
|
int nStations = config->readNumEntry("nStations", 0);
|
||
|
m_stationIDs.clear();
|
||
|
for (int i = 1; i <= nStations; ++i) {
|
||
14 years ago
|
TQString s = config->readEntry(TQString("stationID-") + TQString().setNum(i), TQString());
|
||
15 years ago
|
if (s.length())
|
||
|
m_stationIDs += s;
|
||
|
}
|
||
|
|
||
|
rebuildGUI();
|
||
|
notifyStationSelectionChanged(m_stationIDs);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void QuickBar::saveState (TDEConfig *config) const
|
||
15 years ago
|
{
|
||
14 years ago
|
config->setGroup(TQString("quickBar-") + name());
|
||
15 years ago
|
|
||
|
WidgetPluginBase::saveState(config);
|
||
|
|
||
|
config->writeEntry("nStations", m_stationIDs.size());
|
||
|
int i = 1;
|
||
14 years ago
|
TQStringList::const_iterator end = m_stationIDs.end();
|
||
|
for (TQStringList::const_iterator it = m_stationIDs.begin(); it != end; ++it, ++i) {
|
||
|
config->writeEntry(TQString("stationID-") + TQString().setNum(i), *it);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
ConfigPageInfo QuickBar::createConfigurationPage()
|
||
|
{
|
||
|
QuickbarConfiguration *conf = new QuickbarConfiguration(NULL);
|
||
|
connectI (conf);
|
||
|
return ConfigPageInfo(
|
||
|
conf,
|
||
|
i18n("Quickbar"),
|
||
|
i18n("Quickbar Configuration"),
|
||
|
"view_icon"
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
AboutPageInfo QuickBar::createAboutPage()
|
||
|
{
|
||
12 years ago
|
/* TDEAboutData aboutData("tderadio",
|
||
15 years ago
|
NULL,
|
||
|
NULL,
|
||
12 years ago
|
I18N_NOOP("Quickback for TDERadio"),
|
||
12 years ago
|
TDEAboutData::License_GPL,
|
||
15 years ago
|
"(c) 2002-2005 Martin Witte, Klas Kalass",
|
||
|
0,
|
||
12 years ago
|
"http://sourceforge.net/projects/tderadio",
|
||
15 years ago
|
0);
|
||
|
aboutData.addAuthor("Martin Witte", "", "witte@kawo1.rwth-aachen.de");
|
||
|
aboutData.addAuthor("Klas Kalass", "", "klas.kalass@gmx.de");
|
||
|
|
||
|
return AboutPageInfo(
|
||
12 years ago
|
new TDERadioAboutWidget(aboutData, TDERadioAboutWidget::AbtTabbed),
|
||
15 years ago
|
i18n("Quickbar"),
|
||
|
i18n("Quickbar Plugin"),
|
||
|
"view_icon"
|
||
|
);*/
|
||
|
return AboutPageInfo();
|
||
|
}
|
||
|
|
||
|
|
||
|
// IRadio methods
|
||
|
|
||
|
bool QuickBar::noticePowerChanged(bool /*on*/)
|
||
|
{
|
||
|
activateCurrentButton();
|
||
|
autoSetCaption();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool QuickBar::noticeStationChanged (const RadioStation &rs, int /*idx*/)
|
||
|
{
|
||
|
if (!m_ignoreNoticeActivation)
|
||
|
activateButton(rs);
|
||
|
autoSetCaption();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool QuickBar::noticeStationsChanged(const StationList &/*sl*/)
|
||
|
{
|
||
|
// FIXME
|
||
|
// we can remove no longer existent stationIDs,
|
||
|
// but it doesn't matter if we don't care.
|
||
|
rebuildGUI();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
// button management methods
|
||
|
|
||
|
void QuickBar::buttonClicked(int id)
|
||
|
{
|
||
14 years ago
|
// ouch, but we are still using TQStringList :(
|
||
15 years ago
|
if (queryIsPowerOn() && id == getButtonID(queryCurrentStation())) {
|
||
|
sendPowerOff();
|
||
|
} else {
|
||
|
|
||
|
int k = 0;
|
||
14 years ago
|
TQStringList::iterator end = m_stationIDs.end();
|
||
|
for (TQStringList::iterator it = m_stationIDs.begin(); it != end; ++it, ++k) {
|
||
15 years ago
|
if (k == id) {
|
||
|
const RawStationList &sl = queryStations().all();
|
||
|
const RadioStation &rs = sl.stationWithID(*it);
|
||
|
bool old = m_ignoreNoticeActivation;
|
||
|
m_ignoreNoticeActivation = true;
|
||
|
sendActivateStation(rs);
|
||
|
m_ignoreNoticeActivation = old;
|
||
|
sendPowerOn();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// Problem: if we click a button twice, there will be no
|
||
|
// "station changed"-notification. Thus it would be possible to
|
||
|
// enable a button even if power is off or the radio does not
|
||
|
// accept the radiostation
|
||
|
//activateCurrentButton();
|
||
|
}
|
||
|
|
||
|
|
||
|
int QuickBar::getButtonID(const RadioStation &rs) const
|
||
|
{
|
||
14 years ago
|
TQString stationID = rs.stationID();
|
||
15 years ago
|
int k = 0;
|
||
14 years ago
|
TQStringList::const_iterator end = m_stationIDs.end();
|
||
|
for (TQStringList::const_iterator it = m_stationIDs.begin(); it != end; ++it, ++k) {
|
||
15 years ago
|
if (*it == stationID)
|
||
|
return k;
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
|
||
|
void QuickBar::activateCurrentButton()
|
||
|
{
|
||
|
activateButton(queryCurrentStation());
|
||
|
}
|
||
|
|
||
|
|
||
|
void QuickBar::activateButton(const RadioStation &rs)
|
||
|
{
|
||
|
int buttonID = getButtonID(rs);
|
||
|
bool pwr = queryIsPowerOn();
|
||
|
|
||
|
if (pwr && buttonID >= 0) {
|
||
|
m_buttonGroup->setButton(buttonID);
|
||
|
} else {
|
||
14 years ago
|
for (TQToolButton *b = m_buttons.first(); b; b = m_buttons.next()) {
|
||
15 years ago
|
b->setOn(false);
|
||
|
}
|
||
|
}
|
||
|
autoSetCaption();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
14 years ago
|
// KDE/TQt gui
|
||
15 years ago
|
|
||
|
|
||
|
void QuickBar::rebuildGUI()
|
||
|
{
|
||
|
if (m_layout) delete m_layout;
|
||
|
if (m_buttonGroup) delete m_buttonGroup;
|
||
|
|
||
14 years ago
|
for (TQPtrListIterator<TQToolButton> it(m_buttons); it.current(); ++it)
|
||
15 years ago
|
delete it.current();
|
||
|
m_buttons.clear();
|
||
|
|
||
|
m_layout = new ButtonFlowLayout(this);
|
||
|
m_layout->setMargin(1);
|
||
|
m_layout->setSpacing(2);
|
||
|
|
||
14 years ago
|
m_buttonGroup = new TQButtonGroup(this);
|
||
|
TQObject::connect (m_buttonGroup, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(buttonClicked(int)));
|
||
15 years ago
|
// we use buttonGroup to enable automatic toggle/untoggle
|
||
|
m_buttonGroup->setExclusive(true);
|
||
14 years ago
|
m_buttonGroup->setFrameStyle(TQFrame::NoFrame);
|
||
15 years ago
|
m_buttonGroup->show();
|
||
|
|
||
|
int buttonID = 0;
|
||
|
const RawStationList &stations = queryStations().all();
|
||
|
|
||
14 years ago
|
TQStringList::iterator end = m_stationIDs.end();
|
||
|
for (TQStringList::iterator it = m_stationIDs.begin(); it != end; ++it, ++buttonID) {
|
||
15 years ago
|
|
||
|
const RadioStation &rs = stations.stationWithID(*it);
|
||
|
if (! rs.isValid()) continue;
|
||
|
|
||
14 years ago
|
TQToolButton *b = new TQToolButton(this);
|
||
15 years ago
|
m_buttons.append(b);
|
||
|
b->setToggleButton(true);
|
||
|
if (rs.iconName().length())
|
||
14 years ago
|
b->setIconSet(TQPixmap(rs.iconName()));
|
||
15 years ago
|
else
|
||
|
b->setText(m_showShortName ? rs.shortName() : rs.name());
|
||
|
|
||
13 years ago
|
b->setSizePolicy(TQSizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Preferred));
|
||
15 years ago
|
|
||
14 years ago
|
TQToolTip::add(b, rs.longName());
|
||
15 years ago
|
if (isVisible()) b->show();
|
||
|
|
||
|
|
||
|
m_buttonGroup->insert(b, buttonID);
|
||
|
m_layout->add(b);
|
||
|
}
|
||
|
|
||
|
// activate correct button
|
||
|
activateCurrentButton();
|
||
|
|
||
13 years ago
|
// calculate geometry
|
||
15 years ago
|
if (m_layout) {
|
||
13 years ago
|
TQRect r = geometry();
|
||
15 years ago
|
int h = m_layout->heightForWidth( r.width());
|
||
|
|
||
|
if (h > r.height())
|
||
|
setGeometry(r.x(), r.y(), r.width(), h);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
void QuickBar::show()
|
||
|
{
|
||
|
// KWin::setType(winId(), NET::Toolbar);
|
||
|
WidgetPluginBase::pShow();
|
||
14 years ago
|
TQWidget::show();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void QuickBar::showOnOrgDesktop()
|
||
|
{
|
||
|
WidgetPluginBase::pShowOnOrgDesktop();
|
||
14 years ago
|
//TQWidget::show();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void QuickBar::hide()
|
||
|
{
|
||
|
WidgetPluginBase::pHide();
|
||
14 years ago
|
TQWidget::hide();
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void QuickBar::showEvent(TQShowEvent *e)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQWidget::showEvent(e);
|
||
15 years ago
|
WidgetPluginBase::pShowEvent(e);
|
||
|
}
|
||
|
|
||
14 years ago
|
void QuickBar::hideEvent(TQHideEvent *e)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQWidget::hideEvent(e);
|
||
15 years ago
|
WidgetPluginBase::pHideEvent(e);
|
||
|
}
|
||
|
|
||
|
|
||
|
void QuickBar::setGeometry (int x, int y, int w, int h)
|
||
|
{
|
||
|
if (m_layout) {
|
||
14 years ago
|
TQSize marginSize(m_layout->margin()*2, m_layout->margin()*2);
|
||
13 years ago
|
setMinimumSize(m_layout->minimumSize(TQSize(w, h) - marginSize) + marginSize);
|
||
15 years ago
|
}
|
||
14 years ago
|
TQWidget::setGeometry (x, y, w, h);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void QuickBar::setGeometry (const TQRect &r)
|
||
15 years ago
|
{
|
||
|
setGeometry (r.x(), r.y(), r.width(), r.height());
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void QuickBar::resizeEvent (TQResizeEvent *e)
|
||
15 years ago
|
{
|
||
13 years ago
|
// minimumSize might change because of the flow layout
|
||
15 years ago
|
if (m_layout) {
|
||
14 years ago
|
TQSize marginSize(m_layout->margin()*2, m_layout->margin()*2);
|
||
13 years ago
|
setMinimumSize(m_layout->minimumSize(e->size() - marginSize) + marginSize);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQWidget::resizeEvent (e);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void QuickBar::autoSetCaption()
|
||
|
{
|
||
|
const RadioStation &rs = queryCurrentStation();
|
||
12 years ago
|
setCaption((queryIsPowerOn() && rs.isValid()) ? rs.longName() : TQString("TDERadio"));
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void QuickBar::dragEnterEvent(TQDragEnterEvent* event)
|
||
15 years ago
|
{
|
||
|
bool a = StationDragObject::canDecode(event);
|
||
|
if (a)
|
||
|
IErrorLogClient::staticLogDebug(i18n("contentsDragEnterEvent accepted"));
|
||
|
else
|
||
|
IErrorLogClient::staticLogDebug(i18n("contentsDragEnterEvent rejected"));
|
||
|
event->accept(a);
|
||
|
}
|
||
|
|
||
14 years ago
|
void QuickBar::dropEvent(TQDropEvent* event)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQStringList list;
|
||
15 years ago
|
|
||
|
if ( StationDragObject::decode(event, list) ) {
|
||
14 years ago
|
TQStringList l = getStationSelection();
|
||
|
for (TQValueListConstIterator<TQString> it = list.begin(); it != list.end(); ++it)
|
||
14 years ago
|
if (!l.contains(*it))
|
||
15 years ago
|
l.append(*it);
|
||
|
setStationSelection(l);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "quickbar.moc"
|