summaryrefslogtreecommitdiffstats
path: root/arts/tools/audiomanager.cpp
blob: 73debf8071651b2a811df3dd40ca28bddcab1697 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*

    Copyright (C) 1999 Stefan Westerfeld
                       stefan@space.twc.de
                  2003 Arnold Krille
                       arnold@arnoldarts.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.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

    */

#include "audiomanager.h"
#include "choosebusdlg.h"

#include <tqtimer.h>
#include <tqlayout.h>

#include <klocale.h>
#include <klistview.h>
#include <kiconloader.h>

using namespace std;

/*
 * as this is an 1:1 port of an old arts-0.3.4.1 artsbuilable visual widget,
 * you'll see some porting artefacts, and it's not elegance itself ;)
 */
Gui_AUDIO_MANAGER::Gui_AUDIO_MANAGER( TQWidget* tqparent, const char* name ) : Template_ArtsView( tqparent,name )
{
	this->setCaption( i18n( "Audio Manager" ) );
	this->setIcon( MainBarIcon( "artsaudiomanager", 32 ) );
	//printf("constructor\n");
	ParentWidget = 0;
	listview = 0;
	inDialog = false;
	proxy = new GuiAudioManagerProxy(this);

	AudioManager = Arts::Reference("global:Arts_AudioManager");
	changes = AudioManager.changes()-1;
	setParent(this,0);
	tick();
	show();

	TQTimer *updatetimer = new TQTimer(this);
	updatetimer->start(500);
	TQObject::connect(updatetimer,TQT_SIGNAL(timeout()),this,TQT_SLOT(tick()));
}

Gui_AUDIO_MANAGER::~Gui_AUDIO_MANAGER()
{
	if(listview) delete listview;
	delete proxy;
}

#if 0
void Gui_AUDIO_MANAGER::widgetDestroyed(TQWidget *widget)
{
	assert(widget == listview);
	listview = 0;
}
#endif

void Gui_AUDIO_MANAGER::setParent(TQWidget *tqparent, TQBoxLayout * /*tqlayout*/)
{
/************************************************************************
 * From Gui_INSTRUMENT_MAPPER:
 *
 * I am still not sure wether this kind of putting yourself into a tqparent
 * widget (with own tqlayout etc.) is a good idea (there may not even be
 * a singe call to setParent, because there is no tqparent).
 *
 * But the "how to write aRts widgets"-stuff will need some experiments,
 * so lets try that method...
 *
 * ----
 *
 * But perhaps here (since only one widget Listview is used) something
 * else would be appropriate. Check that. FIXME
 ************************************************************************/

	TQVBoxLayout *maintqlayout = new TQVBoxLayout(tqparent);
	/*TQHBoxLayout *contentstqlayout = new TQHBoxLayout;*/

// list

	listview = new KListView(tqparent);

	listview->addColumn(i18n("Title"),175);
	listview->addColumn(i18n("Type"),50);
	listview->addColumn(i18n("Bus"),75);

	listview->setMinimumSize(300,100);

	TQObject::connect(listview,TQT_SIGNAL(executed(TQListViewItem *)),proxy,
								TQT_SLOT(edit(TQListViewItem *)));

	maintqlayout->addWidget(listview);

	maintqlayout->activate();
	//maintqlayout->freeze();
	ParentWidget = tqparent;
}

void Gui_AUDIO_MANAGER::tick()
{
	unsigned long newChanges = AudioManager.changes();
	if(inDialog) return;
	if(changes == newChanges) return;

	changes = newChanges;

	listview->clear();
	vector<Arts::AudioManagerInfo> *acs = AudioManager.clients();

	unsigned long c;
	for(c=0;c<acs->size();c++)
	{
		//char status[2][10] = {"init","running"};
		TQString description = TQString::fromUtf8( (*acs)[c].title.c_str() );
		TQString type;
		if((*acs)[c].direction == Arts::amPlay)
			type = i18n("play");
		else
			type = i18n("record");
		TQString destination = TQString::fromUtf8( (*acs)[c].destination.c_str() );
		long ID = (*acs)[c].ID;

		(void)new AudioManagerItem(listview, description, type, destination, ID);
	}
	delete acs;
	//Widget->show();
}

void Gui_AUDIO_MANAGER::edit(TQListViewItem *item)
{
	AudioManagerItem *ai = (AudioManagerItem *)item;
	ChooseBusDlg *cd = new ChooseBusDlg(0);
	assert(cd);

	inDialog = true;
	int accept = cd->exec();
	inDialog = false;

	if( accept == TQDialog::Accepted )
	{
		TQString result = cd->result();
		if(!result.isNull())
		{
			//lukas: I hope UTF-8 is OK here...
			AudioManager.setDestination(ai->ID(),result.utf8().data());
			// refresh:
			changes = 0;
			tick();
		}
	}
	delete cd;
}

GuiAudioManagerProxy::GuiAudioManagerProxy(Gui_AUDIO_MANAGER *gim)
{
	this->gim = gim;
}

void GuiAudioManagerProxy::edit(TQListViewItem *item)
{
	gim->edit(item);
}

AudioManagerItem::AudioManagerItem(TQListView *tqparent, TQString a,
         TQString b, TQString c, long ID) :TQListViewItem(tqparent,a,b,c)
{
	_ID = ID;
}

long AudioManagerItem::ID()
{
	return _ID;
}

AudioManagerItem::~AudioManagerItem()
{
	//
}
#include "audiomanager.moc"

// vim: sw=4 ts=4