summaryrefslogtreecommitdiffstats
path: root/kradio3/plugins/gui-quickbar
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-22 18:23:26 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-22 18:23:26 +0000
commitae364d9bed0589bf1a22cd5f530c563462379e3e (patch)
treee32727e2664e7ce68d0d30270afa040320ae35a1 /kradio3/plugins/gui-quickbar
downloadtderadio-ae364d9bed0589bf1a22cd5f530c563462379e3e.tar.gz
tderadio-ae364d9bed0589bf1a22cd5f530c563462379e3e.zip
Added old KDE3 version of kradio
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kradio@1094417 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kradio3/plugins/gui-quickbar')
-rw-r--r--kradio3/plugins/gui-quickbar/Makefile.am18
-rw-r--r--kradio3/plugins/gui-quickbar/buttonflowlayout.cpp232
-rw-r--r--kradio3/plugins/gui-quickbar/buttonflowlayout.h60
-rw-r--r--kradio3/plugins/gui-quickbar/po/Makefile.am2
-rw-r--r--kradio3/plugins/gui-quickbar/po/de.po53
-rw-r--r--kradio3/plugins/gui-quickbar/po/ru.po55
-rw-r--r--kradio3/plugins/gui-quickbar/quickbar-configuration.cpp35
-rw-r--r--kradio3/plugins/gui-quickbar/quickbar-configuration.h36
-rw-r--r--kradio3/plugins/gui-quickbar/quickbar.cpp424
-rw-r--r--kradio3/plugins/gui-quickbar/quickbar.h138
10 files changed, 1053 insertions, 0 deletions
diff --git a/kradio3/plugins/gui-quickbar/Makefile.am b/kradio3/plugins/gui-quickbar/Makefile.am
new file mode 100644
index 0000000..09c58ee
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/Makefile.am
@@ -0,0 +1,18 @@
+SUBDIRS = po .
+
+INCLUDES = -I$(top_builddir)/kradio3/src $(all_includes)
+METASOURCES = AUTO
+
+libkradio_LTLIBRARIES = libquickbar.la
+libquickbar_la_SOURCES = buttonflowlayout.cpp quickbar.cpp \
+ quickbar-configuration.cpp
+libquickbar_la_LDFLAGS = -module -avoid-version $(KDE_RPATH) $(all_libraries)
+
+noinst_HEADERS = buttonflowlayout.h quickbar-configuration.h quickbar.h
+
+#messages: rc.cpp
+# $(XGETTEXT) *.cpp *.h -o po/kradio-gui-quickbar.pot
+
+messages: rc.cpp
+ $(EXTRACTRC) *.rc *.ui >> rc.cpp
+ $(XGETTEXT) rc.cpp *.h *.cpp -o po/kradio-gui-quickbar.pot
diff --git a/kradio3/plugins/gui-quickbar/buttonflowlayout.cpp b/kradio3/plugins/gui-quickbar/buttonflowlayout.cpp
new file mode 100644
index 0000000..40d7da4
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/buttonflowlayout.cpp
@@ -0,0 +1,232 @@
+/****************************************************************************
+** $Id: buttonflowlayout.cpp 272 2005-05-18 08:12:51Z emw $
+**
+** Implementing your own layout: flow example
+**
+** Copyright (C) 1996 by Trolltech AS. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+/**
+ Modified 2002 by Klas Kalass ([email protected]) for kradio
+ */
+
+#include <kdebug.h>
+
+#include "buttonflowlayout.h"
+
+/*********************************************/
+/* Iterator */
+class ButtonFlowLayoutIterator :public QGLayoutIterator
+{
+public:
+ ButtonFlowLayoutIterator( QPtrList<QLayoutItem> *l ) :idx(0), list(l) {}
+ uint count() const;
+ QLayoutItem *current();
+ QLayoutItem *next();
+ QLayoutItem *takeCurrent();
+
+private:
+ int idx;
+ QPtrList<QLayoutItem> *list;
+
+};
+
+uint ButtonFlowLayoutIterator::count() const
+{
+ return list->count();
+}
+
+QLayoutItem *ButtonFlowLayoutIterator::current()
+{
+ return idx < int(count()) ? list->at(idx) : 0;
+}
+
+QLayoutItem *ButtonFlowLayoutIterator::next()
+{
+ idx++; return current();
+}
+
+QLayoutItem *ButtonFlowLayoutIterator::takeCurrent()
+{
+ return idx < int(count()) ? list->take( idx ) : 0;
+}
+
+/**************************************************************/
+
+ButtonFlowLayout::ButtonFlowLayout( QWidget *parent, int margin, int spacing,
+ const char *name )
+ : QLayout( parent, margin, spacing, name ),
+ cached_width(0)
+{
+}
+
+ButtonFlowLayout::ButtonFlowLayout( QLayout* parentLayout, int spacing, const char *name )
+ : QLayout( parentLayout, spacing, name ),
+ cached_width(0)
+{
+}
+
+ButtonFlowLayout::ButtonFlowLayout( int spacing, const char *name )
+ : QLayout( spacing, name ),
+ cached_width(0)
+{
+}
+
+ButtonFlowLayout::~ButtonFlowLayout()
+{
+ deleteAllItems();
+}
+
+
+int ButtonFlowLayout::heightForWidth( int w ) const
+{
+ if ( cached_width != w ) {
+ //Not all C++ compilers support "mutable" yet:
+ ButtonFlowLayout * mthis = (ButtonFlowLayout*)this;
+ int h = mthis->doLayout( QRect(0,0,w,0), TRUE );
+ mthis->cached_hfw = h;
+ mthis->cached_width = w;
+ return h;
+ }
+ return cached_hfw;
+}
+
+void ButtonFlowLayout::addItem( QLayoutItem *item)
+{
+ list.append( item );
+}
+
+bool ButtonFlowLayout::hasHeightForWidth() const
+{
+ return TRUE;
+}
+
+QSize ButtonFlowLayout::sizeHint() const
+{
+ return minimumSize();
+}
+
+QSizePolicy::ExpandData ButtonFlowLayout::expanding() const
+{
+ return QSizePolicy::NoDirection;
+}
+
+QLayoutIterator ButtonFlowLayout::iterator()
+{
+ return QLayoutIterator( new ButtonFlowLayoutIterator( &list ) );
+}
+
+void ButtonFlowLayout::setGeometry( const QRect &r )
+{
+ QLayout::setGeometry( r );
+ doLayout( r );
+}
+
+int ButtonFlowLayout::doLayout( const QRect &r, bool testonly )
+{
+/* kdDebug() << "buttonflowlayout::doLayout ("
+ << r.x() << "," << r.y() << ","
+ << r.width() << "," << r.height() << ", " << testonly << ")\n";
+*/
+ float x = r.x();
+ float y = r.y();
+ int h = 0; //height of this line so far.
+ float buttonWidth = 0;
+ int buttonHeight = 0;
+ int linecount = 0;
+ int totalWidth = r.width();
+ int totalHeight = r.height();
+
+ QPtrListIterator<QLayoutItem> it(list);
+ QLayoutItem *o;
+
+ // get the width of the biggest Button
+
+ it.toFirst();
+ while ( (o=it.current()) != 0 ) {
+ ++it;
+ buttonWidth = QMAX( buttonWidth, o->sizeHint().width() );
+ buttonHeight = QMAX( buttonHeight, o->sizeHint().height() );
+ }
+
+ // calculate the optimal width
+ unsigned int columns = (totalWidth + spacing()) /
+ ((int)buttonWidth + spacing());
+ if (columns > it.count() ) columns = it.count();
+ if (columns == 0) columns = 1; // avoid division by zero
+
+
+ int rows = (it.count() - 1) / columns + 1;
+ float deltaH = (float)(totalHeight - rows * buttonHeight - (rows - 1) * spacing())
+ / (float)(rows + 1) ;
+ if (deltaH < 0) deltaH = 0;
+
+ y += deltaH;
+
+ buttonWidth = (float)(totalWidth - spacing()*(columns-1)) / (float)columns;
+
+/* fprintf (stderr, "cols = %i col-width = %f\n"
+ "rows = %i row-height = %i\n"
+ "w = %i h = %i\n",
+ columns, buttonWidth,
+ rows, buttonHeight,
+ totalWidth, totalHeight
+ );
+*/
+ // calculate the positions and sizes
+ it.toFirst();
+ while ( (o = it.current()) != 0 ) {
+
+// fprintf (stderr, "x = %i y = %i\n", x, (int)y);
+ ++it;
+ int btnRight = (int)rint(x + buttonWidth) - 1,
+ btnLeft = (int)rint(x);
+
+ if ( btnRight > r.right() && h > 0 ) {
+ x = r.x();
+ btnRight = (int)rint(x + buttonWidth) - 1;
+ btnLeft = (int)rint(x);
+
+ y += h + spacing() + deltaH;
+ h = 0;
+ linecount++;
+ }
+ if (!testonly)
+ o->setGeometry( QRect( QPoint( btnLeft, (int)rint(y) ),
+ QSize( btnRight - btnLeft + 1,
+ buttonHeight) )
+ );
+
+ x += buttonWidth + spacing();
+ h = QMAX( h, buttonHeight );
+ }
+
+ int ret = (int)rint(y + h + deltaH) - r.y();
+
+// kdDebug() << "ButtonFlowLayout::doLayout() = " << ret << endl;
+ return ret;
+}
+
+
+QSize ButtonFlowLayout::minimumSize() const
+{
+ return minimumSize(geometry().size());
+}
+
+
+QSize ButtonFlowLayout::minimumSize(const QSize &r) const
+{
+ QSize s(0, 0);
+
+ for (QPtrListIterator<QLayoutItem> it(list); it.current(); ++it) {
+ QLayoutItem *o = it.current();
+ s = s.expandedTo( o->sizeHint()); //minimumSize() );
+ }
+
+ s.setHeight(heightForWidth(r.width()));
+
+ return s;
+}
diff --git a/kradio3/plugins/gui-quickbar/buttonflowlayout.h b/kradio3/plugins/gui-quickbar/buttonflowlayout.h
new file mode 100644
index 0000000..337a850
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/buttonflowlayout.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+** $Id: buttonflowlayout.h 471 2006-11-11 17:04:51Z emw $
+**
+** Definition of simple flow layout for custom layout example
+**
+** Created : 979899
+**
+** Copyright (C) 1997 by Trolltech AS. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+/**
+ Modified 2002 by Klas Kalass ([email protected]) for kradio
+ */
+#ifndef BUTTONFLOWLAYOUT_H
+#define BUTTONFLOWLAYOUT_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "../../src/include/utils.h"
+
+#include <qlayout.h>
+#include <qptrlist.h>
+
+class ButtonFlowLayout : public QLayout
+{
+public:
+ ButtonFlowLayout( QWidget *parent, int margin = 0, int spacing=-1,
+ const char *name=0 );
+
+ ButtonFlowLayout( QLayout* parentLayout, int spacing=-1, const char *name=0 );
+
+ ButtonFlowLayout( int spacing=-1, const char *name=0 );
+
+ ~ButtonFlowLayout();
+
+ void addItem( QLayoutItem *item);
+ bool hasHeightForWidth() const;
+ int heightForWidth( int ) const;
+ QSize sizeHint() const;
+ QSize minimumSize() const;
+ QSize minimumSize(const QSize &r) const; // minimumSize is dependent from width
+ QLayoutIterator iterator();
+ QSizePolicy::ExpandData expanding() const;
+
+protected:
+ void setGeometry( const QRect& );
+
+private:
+ int doLayout( const QRect&, bool testonly = FALSE );
+ QPtrList<QLayoutItem> list;
+ int cached_width;
+ int cached_hfw;
+};
+
+#endif
diff --git a/kradio3/plugins/gui-quickbar/po/Makefile.am b/kradio3/plugins/gui-quickbar/po/Makefile.am
new file mode 100644
index 0000000..fbee5b4
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/po/Makefile.am
@@ -0,0 +1,2 @@
+PACKAGE = kradio-gui-quickbar
+POFILES = AUTO
diff --git a/kradio3/plugins/gui-quickbar/po/de.po b/kradio3/plugins/gui-quickbar/po/de.po
new file mode 100644
index 0000000..9ac8533
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/po/de.po
@@ -0,0 +1,53 @@
+# translation of de.po to
+# translation of kradio-gui-quickbar.po to
+# This file is put in the public domain.
+#
+# Ernst Martin Witte <[email protected]>, 2006.
+msgid ""
+msgstr ""
+"Project-Id-Version: de\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2006-11-10 23:20+0100\n"
+"PO-Revision-Date: 2006-11-06 00:32+0100\n"
+"Last-Translator: Ernst Martin Witte <[email protected]>\n"
+"Language-Team: <[email protected]>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: KBabel 1.11.4\n"
+
+#: _translatorinfo.cpp:1
+msgid ""
+"_: NAME OF TRANSLATORS\n"
+"Your names"
+msgstr "Ernst Martin Witte "
+
+#: _translatorinfo.cpp:3
+msgid ""
+"_: EMAIL OF TRANSLATORS\n"
+"Your emails"
+
+#: quickbar.cpp:42
+msgid "Radio Station Quick Selection Toolbar"
+msgstr "Senderkurzwahlfenster"
+
+#: quickbar.cpp:48
+msgid "Quickbar Plugin"
+msgstr "Schnellauswahlfenster"
+
+#: quickbar.cpp:139
+msgid "Quickbar"
+msgstr "Kurzwahlfenster"
+
+#: quickbar.cpp:140
+msgid "Quickbar Configuration"
+msgstr "Konfiguration des Kurzwahlfensters"
+
+#: quickbar.cpp:404
+msgid "contentsDragEnterEvent accepted"
+msgstr "contentsDragEnterEvent angenommen"
+
+#: quickbar.cpp:406
+msgid "contentsDragEnterEvent rejected"
+msgstr "contentsDragEnterEvent abgelehnt"
diff --git a/kradio3/plugins/gui-quickbar/po/ru.po b/kradio3/plugins/gui-quickbar/po/ru.po
new file mode 100644
index 0000000..7742fde
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/po/ru.po
@@ -0,0 +1,55 @@
+# translation of ru.po to
+# translation of kradio-gui-quickbar.po to
+# This file is put in the public domain.
+# Алексей Кузнецов <[email protected]>, 2006.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: ru\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2006-11-11 02:11+0100\n"
+"PO-Revision-Date: 2006-11-08 12:00+0300\n"
+"Last-Translator: Алексей Кузнецов <[email protected]>\n"
+"Language-Team: <[email protected]>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: KBabel 1.10\n"
+
+#: _translatorinfo.cpp:1
+msgid ""
+"_: NAME OF TRANSLATORS\n"
+"Your names"
+msgstr "Алексей Кузнецов"
+
+#: _translatorinfo.cpp:3
+msgid ""
+"_: EMAIL OF TRANSLATORS\n"
+"Your emails"
+
+#: quickbar.cpp:42
+msgid "Radio Station Quick Selection Toolbar"
+msgstr "Панель быстрого выбора радиостанций"
+
+#: quickbar.cpp:48
+msgid "Quickbar Plugin"
+msgstr "Панель быстрого доступа"
+
+#: quickbar.cpp:139
+msgid "Quickbar"
+msgstr ""
+"Панель\n"
+" радиостанций"
+
+#: quickbar.cpp:140
+msgid "Quickbar Configuration"
+msgstr "Настройка панели быстрого доступа"
+
+#: quickbar.cpp:404
+msgid "contentsDragEnterEvent accepted"
+msgstr "contentsDragEnterEvent accepted"
+
+#: quickbar.cpp:406
+msgid "contentsDragEnterEvent rejected"
+msgstr "contentsDragEnterEvent rejected"
diff --git a/kradio3/plugins/gui-quickbar/quickbar-configuration.cpp b/kradio3/plugins/gui-quickbar/quickbar-configuration.cpp
new file mode 100644
index 0000000..bb8b0f6
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/quickbar-configuration.cpp
@@ -0,0 +1,35 @@
+/***************************************************************************
+ quickbar-configuration.cpp - description
+ -------------------
+ begin : Son Aug 3 2003
+ copyright : (C) 2003 by Martin Witte
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include "quickbar-configuration.h"
+
+using namespace std;
+
+QuickbarConfiguration::QuickbarConfiguration (QWidget *parent)
+ : StationSelector(parent)
+{
+}
+
+
+QuickbarConfiguration::~QuickbarConfiguration ()
+{
+}
+
+
+
+
+#include "quickbar-configuration.moc"
diff --git a/kradio3/plugins/gui-quickbar/quickbar-configuration.h b/kradio3/plugins/gui-quickbar/quickbar-configuration.h
new file mode 100644
index 0000000..e2e1c08
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/quickbar-configuration.h
@@ -0,0 +1,36 @@
+/***************************************************************************
+ quickbar-configuration.h - description
+ -------------------
+ begin : Son Aug 3 2003
+ copyright : (C) 2003 by Martin Witte
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef KRADIO_QUICKBAR_CONFIGURATION_H
+#define KRADIO_QUICKBAR_CONFIGURATION_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "../../src/include/stationselector.h"
+
+class QuickbarConfiguration : public StationSelector
+{
+Q_OBJECT
+public :
+ QuickbarConfiguration (QWidget *parent);
+ ~QuickbarConfiguration ();
+
+};
+
+#endif
diff --git a/kradio3/plugins/gui-quickbar/quickbar.cpp b/kradio3/plugins/gui-quickbar/quickbar.cpp
new file mode 100644
index 0000000..628a1bf
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/quickbar.cpp
@@ -0,0 +1,424 @@
+/***************************************************************************
+ quickbar.cpp - description
+ -------------------
+ begin : Mon Feb 11 2002
+ copyright : (C) 2002 by Martin Witte / Frank Schwanz
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include <qtooltip.h>
+#include <qnamespace.h>
+#include <qhbuttongroup.h>
+#include <qvbuttongroup.h>
+
+#include <ktoolbarbutton.h>
+#include <kwin.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kconfig.h>
+#include <kaboutdata.h>
+
+#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
+
+PLUGIN_LIBRARY_FUNCTIONS(QuickBar, "kradio-gui-quickbar", i18n("Radio Station Quick Selection Toolbar"));
+
+/////////////////////////////////////////////////////////////////////////////
+
+QuickBar::QuickBar(const QString &name)
+ : QWidget(NULL, name.ascii()),
+ 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
+
+bool QuickBar::setStationSelection(const QStringList &sl)
+{
+ if (m_stationIDs != sl) {
+ m_stationIDs = sl;
+ rebuildGUI();
+ notifyStationSelectionChanged(m_stationIDs);
+ }
+ return true;
+}
+
+// PluginBase methods
+
+
+void QuickBar::restoreState (KConfig *config)
+{
+ config->setGroup(QString("quickBar-") + name());
+
+ WidgetPluginBase::restoreState(config, false);
+
+ int nStations = config->readNumEntry("nStations", 0);
+ m_stationIDs.clear();
+ for (int i = 1; i <= nStations; ++i) {
+ QString s = config->readEntry(QString("stationID-") + QString().setNum(i), QString::null);
+ if (s.length())
+ m_stationIDs += s;
+ }
+
+ rebuildGUI();
+ notifyStationSelectionChanged(m_stationIDs);
+}
+
+
+void QuickBar::saveState (KConfig *config) const
+{
+ config->setGroup(QString("quickBar-") + name());
+
+ WidgetPluginBase::saveState(config);
+
+ config->writeEntry("nStations", m_stationIDs.size());
+ int i = 1;
+ QStringList::const_iterator end = m_stationIDs.end();
+ for (QStringList::const_iterator it = m_stationIDs.begin(); it != end; ++it, ++i) {
+ config->writeEntry(QString("stationID-") + QString().setNum(i), *it);
+ }
+}
+
+
+ConfigPageInfo QuickBar::createConfigurationPage()
+{
+ QuickbarConfiguration *conf = new QuickbarConfiguration(NULL);
+ connectI (conf);
+ return ConfigPageInfo(
+ conf,
+ i18n("Quickbar"),
+ i18n("Quickbar Configuration"),
+ "view_icon"
+ );
+}
+
+
+AboutPageInfo QuickBar::createAboutPage()
+{
+/* KAboutData aboutData("kradio",
+ NULL,
+ NULL,
+ I18N_NOOP("Quickback for KRadio"),
+ KAboutData::License_GPL,
+ "(c) 2002-2005 Martin Witte, Klas Kalass",
+ 0,
+ "http://sourceforge.net/projects/kradio",
+ 0);
+ aboutData.addAuthor("Martin Witte", "", "[email protected]");
+ aboutData.addAuthor("Klas Kalass", "", "[email protected]");
+
+ return AboutPageInfo(
+ new KRadioAboutWidget(aboutData, KRadioAboutWidget::AbtTabbed),
+ 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)
+{
+ // ouch, but we are still using QStringList :(
+ if (queryIsPowerOn() && id == getButtonID(queryCurrentStation())) {
+ sendPowerOff();
+ } else {
+
+ int k = 0;
+ QStringList::iterator end = m_stationIDs.end();
+ for (QStringList::iterator it = m_stationIDs.begin(); it != end; ++it, ++k) {
+ 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
+{
+ QString stationID = rs.stationID();
+ int k = 0;
+ QStringList::const_iterator end = m_stationIDs.end();
+ for (QStringList::const_iterator it = m_stationIDs.begin(); it != end; ++it, ++k) {
+ 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 {
+ for (QToolButton *b = m_buttons.first(); b; b = m_buttons.next()) {
+ b->setOn(false);
+ }
+ }
+ autoSetCaption();
+}
+
+
+
+// KDE/Qt gui
+
+
+void QuickBar::rebuildGUI()
+{
+ if (m_layout) delete m_layout;
+ if (m_buttonGroup) delete m_buttonGroup;
+
+ for (QPtrListIterator<QToolButton> it(m_buttons); it.current(); ++it)
+ delete it.current();
+ m_buttons.clear();
+
+ m_layout = new ButtonFlowLayout(this);
+ m_layout->setMargin(1);
+ m_layout->setSpacing(2);
+
+ m_buttonGroup = new QButtonGroup(this);
+ QObject::connect (m_buttonGroup, SIGNAL(clicked(int)), this, SLOT(buttonClicked(int)));
+ // we use buttonGroup to enable automatic toggle/untoggle
+ m_buttonGroup->setExclusive(true);
+ m_buttonGroup->setFrameStyle(QFrame::NoFrame);
+ m_buttonGroup->show();
+
+ int buttonID = 0;
+ const RawStationList &stations = queryStations().all();
+
+ QStringList::iterator end = m_stationIDs.end();
+ for (QStringList::iterator it = m_stationIDs.begin(); it != end; ++it, ++buttonID) {
+
+ const RadioStation &rs = stations.stationWithID(*it);
+ if (! rs.isValid()) continue;
+
+ QToolButton *b = new QToolButton(this);
+ m_buttons.append(b);
+ b->setToggleButton(true);
+ if (rs.iconName().length())
+ b->setIconSet(QPixmap(rs.iconName()));
+ else
+ b->setText(m_showShortName ? rs.shortName() : rs.name());
+
+ b->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
+
+ QToolTip::add(b, rs.longName());
+ if (isVisible()) b->show();
+
+
+ m_buttonGroup->insert(b, buttonID);
+ m_layout->add(b);
+ }
+
+ // activate correct button
+ activateCurrentButton();
+
+ // calculate geometry
+ if (m_layout) {
+ QRect r = geometry();
+ 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();
+ QWidget::show();
+}
+
+
+void QuickBar::showOnOrgDesktop()
+{
+ WidgetPluginBase::pShowOnOrgDesktop();
+ //QWidget::show();
+}
+
+
+void QuickBar::hide()
+{
+ WidgetPluginBase::pHide();
+ QWidget::hide();
+}
+
+void QuickBar::showEvent(QShowEvent *e)
+{
+ QWidget::showEvent(e);
+ WidgetPluginBase::pShowEvent(e);
+}
+
+void QuickBar::hideEvent(QHideEvent *e)
+{
+ QWidget::hideEvent(e);
+ WidgetPluginBase::pHideEvent(e);
+}
+
+
+void QuickBar::setGeometry (int x, int y, int w, int h)
+{
+ if (m_layout) {
+ QSize marginSize(m_layout->margin()*2, m_layout->margin()*2);
+ setMinimumSize(m_layout->minimumSize(QSize(w, h) - marginSize) + marginSize);
+ }
+ QWidget::setGeometry (x, y, w, h);
+}
+
+
+void QuickBar::setGeometry (const QRect &r)
+{
+ setGeometry (r.x(), r.y(), r.width(), r.height());
+}
+
+
+void QuickBar::resizeEvent (QResizeEvent *e)
+{
+ // minimumSize might change because of the flow layout
+ if (m_layout) {
+ QSize marginSize(m_layout->margin()*2, m_layout->margin()*2);
+ setMinimumSize(m_layout->minimumSize(e->size() - marginSize) + marginSize);
+ }
+
+ QWidget::resizeEvent (e);
+}
+
+
+void QuickBar::autoSetCaption()
+{
+ const RadioStation &rs = queryCurrentStation();
+ setCaption((queryIsPowerOn() && rs.isValid()) ? rs.longName() : QString("KRadio"));
+}
+
+void QuickBar::dragEnterEvent(QDragEnterEvent* event)
+{
+ bool a = StationDragObject::canDecode(event);
+ if (a)
+ IErrorLogClient::staticLogDebug(i18n("contentsDragEnterEvent accepted"));
+ else
+ IErrorLogClient::staticLogDebug(i18n("contentsDragEnterEvent rejected"));
+ event->accept(a);
+}
+
+void QuickBar::dropEvent(QDropEvent* event)
+{
+ QStringList list;
+
+ if ( StationDragObject::decode(event, list) ) {
+ QStringList l = getStationSelection();
+ for (QValueListConstIterator<QString> it = list.begin(); it != list.end(); ++it)
+ if (!l.contains(*it))
+ l.append(*it);
+ setStationSelection(l);
+ }
+}
+
+
+#include "quickbar.moc"
diff --git a/kradio3/plugins/gui-quickbar/quickbar.h b/kradio3/plugins/gui-quickbar/quickbar.h
new file mode 100644
index 0000000..7bf5193
--- /dev/null
+++ b/kradio3/plugins/gui-quickbar/quickbar.h
@@ -0,0 +1,138 @@
+/***************************************************************************
+ quickbar.h - description
+ -------------------
+ begin : Mon Feb 11 2002
+ copyright : (C) 2002 by Martin Witte / Klas Kalass
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef KRADIO_QUICKBAR_H
+#define KRADIO_QUICKBAR_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qwidget.h>
+
+#include "../../src/include/radio_interfaces.h"
+#include "../../src/include/widgetplugins.h"
+#include "../../src/include/stationselection_interfaces.h"
+
+class ButtonFlowLayout;
+class QButtonGroup;
+class KConfig;
+class QToolButton;
+
+/**
+ *@author Martin Witte / Klas Kalass
+ */
+
+class QuickBar : public QWidget,
+ public WidgetPluginBase,
+ public IRadioClient,
+ public IStationSelection
+{
+Q_OBJECT
+public:
+ QuickBar(const QString &name = QString::null);
+ ~QuickBar();
+
+ virtual QString pluginClassName() const { return "QuickBar"; }
+
+ const QString &name() const { return PluginBase::name(); }
+ QString &name() { return PluginBase::name(); }
+
+ virtual bool connectI(Interface *i);
+ virtual bool disconnectI(Interface *i);
+
+ // IStationSelection
+
+RECEIVERS:
+ bool setStationSelection(const QStringList &sl);
+
+ANSWERS:
+ const QStringList & getStationSelection () const { return m_stationIDs; }
+
+
+ // PluginBase
+
+public:
+ virtual void saveState (KConfig *) const;
+ virtual void restoreState (KConfig *);
+
+ virtual ConfigPageInfo createConfigurationPage();
+ virtual AboutPageInfo createAboutPage();
+
+ // IRadioClient
+
+RECEIVERS:
+ bool noticePowerChanged(bool on);
+ bool noticeStationChanged (const RadioStation &, int idx);
+ bool noticeStationsChanged(const StationList &sl);
+ bool noticePresetFileChanged(const QString &/*f*/) { return false; }
+
+ bool noticeCurrentSoundStreamIDChanged(SoundStreamID /*id*/) { return false; }
+
+ // button/station Management
+
+
+protected slots:
+
+ void buttonClicked(int id);
+
+protected:
+
+ int getButtonID(const RadioStation &rs) const;
+ void activateCurrentButton();
+ void activateButton(const RadioStation &);
+
+ void autoSetCaption();
+
+
+ void dragEnterEvent(QDragEnterEvent* event);
+ void dropEvent(QDropEvent* event);
+
+ // KDE/QT
+
+public slots:
+
+ void toggleShown() { WidgetPluginBase::pToggleShown(); }
+ void show();
+ void hide();
+ void showOnOrgDesktop();
+ void setGeometry (const QRect &r);
+ void setGeometry (int x, int y, int w, int h);
+
+protected:
+ void rebuildGUI();
+ void showEvent(QShowEvent *);
+ void hideEvent(QHideEvent *);
+ void resizeEvent(QResizeEvent *);
+
+ const QWidget *getWidget() const { return this; }
+ QWidget *getWidget() { return this; }
+
+protected :
+
+ ButtonFlowLayout *m_layout;
+ QButtonGroup *m_buttonGroup;
+
+ QPtrList<QToolButton> m_buttons;
+
+ // config
+ bool m_showShortName;
+ QStringList m_stationIDs;
+
+ bool m_ignoreNoticeActivation;
+};
+#endif