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.
322 lines
8.6 KiB
322 lines
8.6 KiB
15 years ago
|
/***************************************************************************
|
||
|
stationselector.cpp - description
|
||
|
-------------------
|
||
|
begin : Son Aug 3 2003
|
||
|
copyright : (C) 2003 by Martin Witte
|
||
|
email : witte@kawo1.rwth-aachen.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. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
#include <kpushbutton.h>
|
||
|
#include <algorithm>
|
||
|
|
||
|
#include "include/stationlist.h"
|
||
|
#include "include/radiostation.h"
|
||
|
|
||
|
#include "include/stationselector.h"
|
||
|
#include "include/radiostation-listview.h"
|
||
|
|
||
13 years ago
|
StationSelector::StationSelector (TQWidget *parent)
|
||
|
: StationSelectorUI(parent),
|
||
15 years ago
|
m_dirty(true)
|
||
|
{
|
||
14 years ago
|
TQObject::connect(buttonToLeft, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotButtonToLeft()));
|
||
|
TQObject::connect(buttonToRight, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotButtonToRight()));
|
||
|
TQObject::connect(listAvailable, TQT_SIGNAL(sigStationsReceived(const TQStringList&)), this, TQT_SLOT(slotMoveToLeft(const TQStringList&)));
|
||
|
TQObject::connect(listSelected, TQT_SIGNAL(sigStationsReceived(const TQStringList&)), this, TQT_SLOT(slotMoveToRight(const TQStringList&)));
|
||
15 years ago
|
|
||
14 years ago
|
listSelected->setSelectionMode(TQListView::Extended);
|
||
|
listAvailable->setSelectionMode(TQListView::Extended);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
StationSelector::~StationSelector ()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
bool StationSelector::connectI(Interface *i)
|
||
|
{
|
||
|
bool a = IStationSelectionClient::connectI(i);
|
||
|
bool b = IRadioClient::connectI(i);
|
||
|
return a || b;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool StationSelector::disconnectI(Interface *i)
|
||
|
{
|
||
|
bool a = IStationSelectionClient::disconnectI(i);
|
||
|
bool b = IRadioClient::disconnectI(i);
|
||
|
return a || b;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
bool StationSelector::noticeStationSelectionChanged(const TQStringList &sl)
|
||
15 years ago
|
{
|
||
|
m_stationIDsNotDisplayed.clear();
|
||
|
m_stationIDsSelected.clear();
|
||
|
m_stationIDsAvailable.clear();
|
||
|
|
||
|
for (unsigned int i = 0; i < m_stationIDsAll.count(); ++i) {
|
||
13 years ago
|
if (sl.contains(m_stationIDsAll[i])) {
|
||
15 years ago
|
m_stationIDsSelected.append(m_stationIDsAll[i]);
|
||
|
} else {
|
||
|
m_stationIDsAvailable.append(m_stationIDsAll[i]);
|
||
|
}
|
||
|
}
|
||
|
for (unsigned int i = 0; i < sl.count(); ++i) {
|
||
13 years ago
|
if (!m_stationIDsAll.contains(sl[i]))
|
||
15 years ago
|
m_stationIDsNotDisplayed.append(sl[i]);
|
||
|
}
|
||
|
updateListViews();
|
||
|
m_dirty = false;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool StationSelector::noticeStationsChanged(const StationList &sl)
|
||
|
{
|
||
|
slotSetDirty();
|
||
|
|
||
|
listAvailable->clear();
|
||
|
listSelected->clear();
|
||
|
|
||
|
m_stationIDsAvailable.clear();
|
||
|
m_stationIDsAll.clear();
|
||
|
|
||
|
for (unsigned int i = 0; i < m_stationIDsSelected.count(); ++i)
|
||
|
m_stationIDsNotDisplayed.append(m_stationIDsSelected[i]);
|
||
|
|
||
|
m_stationIDsSelected.clear();
|
||
|
|
||
|
for (RawStationList::Iterator i(sl.all()); i.current(); ++i) {
|
||
14 years ago
|
const TQString &id = i.current()->stationID();
|
||
15 years ago
|
|
||
|
m_stationIDsAll.append(id);
|
||
13 years ago
|
if (m_stationIDsNotDisplayed.contains(id)) {
|
||
15 years ago
|
m_stationIDsNotDisplayed.remove(id);
|
||
|
m_stationIDsSelected.append(id);
|
||
|
} else {
|
||
|
m_stationIDsAvailable.append(id);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
updateListViews();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
void StationSelector::slotButtonToLeft()
|
||
|
{
|
||
|
slotSetDirty();
|
||
|
listAvailable->clearSelection();
|
||
14 years ago
|
TQListViewItem *item = listSelected->firstChild();
|
||
15 years ago
|
int idx_from = 0;
|
||
|
while (item) {
|
||
14 years ago
|
TQListViewItem *next_item = item->nextSibling();
|
||
15 years ago
|
|
||
|
if (item->isSelected()) {
|
||
|
|
||
|
moveItem (listSelected, m_stationIDsSelected,
|
||
|
item, idx_from,
|
||
|
listAvailable, m_stationIDsAvailable);
|
||
|
|
||
|
--idx_from;
|
||
|
}
|
||
|
item = next_item;
|
||
|
++idx_from;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void StationSelector::slotButtonToRight()
|
||
|
{
|
||
|
slotSetDirty();
|
||
|
listSelected->clearSelection();
|
||
14 years ago
|
TQListViewItem *item = listAvailable->firstChild();
|
||
15 years ago
|
int idx_from = 0;
|
||
|
while (item) {
|
||
14 years ago
|
TQListViewItem *next_item = item->nextSibling();
|
||
15 years ago
|
|
||
|
if (item->isSelected()) {
|
||
|
|
||
|
moveItem (listAvailable, m_stationIDsAvailable,
|
||
|
item, idx_from,
|
||
|
listSelected, m_stationIDsSelected);
|
||
|
|
||
|
--idx_from;
|
||
|
}
|
||
|
item = next_item;
|
||
|
++idx_from;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void StationSelector::slotMoveToRight(const TQStringList &list)
|
||
15 years ago
|
{
|
||
|
slotSetDirty();
|
||
|
listSelected->clearSelection();
|
||
14 years ago
|
TQListViewItem *item = listAvailable->firstChild();
|
||
15 years ago
|
int idx_from = 0;
|
||
|
while (item) {
|
||
14 years ago
|
TQListViewItem *next_item = item->nextSibling();
|
||
15 years ago
|
|
||
13 years ago
|
if (list.contains(m_stationIDsAvailable[idx_from])) {
|
||
15 years ago
|
|
||
|
moveItem (listAvailable, m_stationIDsAvailable,
|
||
|
item, idx_from,
|
||
|
listSelected, m_stationIDsSelected);
|
||
|
|
||
|
--idx_from;
|
||
|
}
|
||
|
item = next_item;
|
||
|
++idx_from;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void StationSelector::slotMoveToLeft(const TQStringList &list)
|
||
15 years ago
|
{
|
||
|
slotSetDirty();
|
||
|
listAvailable->clearSelection();
|
||
14 years ago
|
TQListViewItem *item = listSelected->firstChild();
|
||
15 years ago
|
int idx_from = 0;
|
||
|
while (item) {
|
||
14 years ago
|
TQListViewItem *next_item = item->nextSibling();
|
||
15 years ago
|
|
||
13 years ago
|
if (list.contains(m_stationIDsSelected[idx_from])) {
|
||
15 years ago
|
|
||
|
moveItem (listSelected, m_stationIDsSelected,
|
||
|
item, idx_from,
|
||
|
listAvailable, m_stationIDsAvailable);
|
||
|
|
||
|
--idx_from;
|
||
|
}
|
||
|
item = next_item;
|
||
|
++idx_from;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void StationSelector::moveItem(
|
||
|
RadioStationListView *fromListView,
|
||
14 years ago
|
TQStringList &fromIDList,
|
||
|
TQListViewItem *item,
|
||
15 years ago
|
int idx_from,
|
||
|
RadioStationListView *toListView,
|
||
14 years ago
|
TQStringList &toIDList
|
||
15 years ago
|
)
|
||
|
{
|
||
|
fromListView->takeItem(item, idx_from);
|
||
|
|
||
14 years ago
|
TQString id = fromIDList[idx_from];
|
||
15 years ago
|
fromIDList.remove(fromIDList.at(idx_from));
|
||
|
|
||
|
unsigned int idx_to = 0,
|
||
|
idx_all = 0;
|
||
|
bool found = false;
|
||
14 years ago
|
TQListViewItem *item_to = toListView->firstChild(),
|
||
15 years ago
|
*prev_item_to = NULL;
|
||
|
|
||
|
while (idx_all < m_stationIDsAll.count() &&
|
||
|
idx_to < toIDList.count())
|
||
|
{
|
||
|
while (m_stationIDsAll[idx_all] != toIDList[idx_to])
|
||
|
{
|
||
|
if (m_stationIDsAll[idx_all] == id) {
|
||
|
found = true;
|
||
|
break;
|
||
|
}
|
||
|
++idx_all;
|
||
|
}
|
||
|
if (found)
|
||
|
break;
|
||
|
|
||
|
prev_item_to = item_to;
|
||
|
item_to = item_to->nextSibling();
|
||
|
++idx_to;
|
||
|
}
|
||
|
|
||
|
toIDList.insert(toIDList.at(idx_to), id);
|
||
|
toListView->insertItem(item, id, idx_to);
|
||
|
if (prev_item_to) {
|
||
|
item->moveItem(prev_item_to);
|
||
|
} else {
|
||
|
item->moveItem(item_to);
|
||
|
if (item_to) item_to->moveItem(item);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void StationSelector::updateListViews()
|
||
|
{
|
||
|
listAvailable->clear();
|
||
|
listSelected->clear();
|
||
|
const StationList &stations = queryStations();
|
||
|
const RawStationList &sl = stations.all();
|
||
|
|
||
|
for (unsigned int i = 0; i < m_stationIDsAvailable.count(); ++i) {
|
||
14 years ago
|
TQString id = m_stationIDsAvailable[i];
|
||
15 years ago
|
listAvailable->appendStation(sl.stationWithID(id), sl.idxWithID(id)+1);
|
||
|
}
|
||
|
for (unsigned int i = 0; i < m_stationIDsSelected.count(); ++i) {
|
||
14 years ago
|
TQString id = m_stationIDsSelected[i];
|
||
15 years ago
|
listSelected->appendStation(sl.stationWithID(id), sl.idxWithID(id)+1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void StationSelector::slotOK()
|
||
|
{
|
||
|
if (m_dirty) {
|
||
14 years ago
|
TQStringList l = m_stationIDsSelected;
|
||
15 years ago
|
for (unsigned int i = 0; i < m_stationIDsNotDisplayed.count(); ++i)
|
||
|
l.append(m_stationIDsNotDisplayed[i]);
|
||
|
sendStationSelection(l);
|
||
|
}
|
||
|
m_dirty = false;
|
||
|
}
|
||
|
|
||
|
|
||
|
void StationSelector::slotCancel()
|
||
|
{
|
||
|
if (m_dirty) {
|
||
|
noticeStationSelectionChanged(queryStationSelection());
|
||
|
}
|
||
|
m_dirty = false;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void StationSelector::saveState (TDEConfig *cfg) const
|
||
15 years ago
|
{
|
||
|
listSelected->saveState(cfg);
|
||
|
listAvailable->saveState(cfg);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void StationSelector::restoreState (TDEConfig *cfg)
|
||
15 years ago
|
{
|
||
|
listSelected->restoreState(cfg);
|
||
|
listAvailable->restoreState(cfg);
|
||
|
}
|
||
|
|
||
|
void StationSelector::slotSetDirty()
|
||
|
{
|
||
|
if (!m_dirty) {
|
||
|
m_dirty = true;
|
||
|
emit sigDirty();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#include "stationselector.moc"
|