summaryrefslogtreecommitdiffstats
path: root/amarok/src/engine/nmm/HostList.cpp
blob: 7225548e963f6e3d128a0c79b8b6fe2d04b25712 (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
/* NMM - Network-Integrated Multimedia Middleware
 *
 * Copyright (C) 2006
 *                    NMM work group,
 *                    Computer Graphics Lab,
 *                    Saarland University, Germany
 *                    http://www.networkmultimedia.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#include "HostList.h"

#include <tqcursor.h>
#include <tqheader.h>
#include <klocale.h>

#include "debug.h"
#include "HostListItem.h"

HostList::HostList( TQWidget *tqparent, const char *name ) 
  : KListView( tqparent, name ),
    m_read_only( false ),
    m_hoveredVolume(0)
{
  // TODO: item should be activated on mouse click
  setMouseTracking( true );
  setAllColumnsShowFocus( true );

  addColumn( i18n("Hostname") );
  addColumn( i18n("Video"   ) );
  addColumn( i18n("Audio"   ) );
  addColumn( i18n("Volume"  ), 113 );
  header()->setResizeEnabled(false, 3);
  addColumn( i18n("tqStatus"  ) );
  addColumn( i18n("Playback"  ) );

  setColumnAlignment( HostListItem::Hostname, TQt::AlignCenter );
  setColumnAlignment( HostListItem::Video,    TQt::AlignCenter );
  setColumnAlignment( HostListItem::Audio,    TQt::AlignCenter );
  setColumnAlignment( HostListItem::Volume,   TQt::AlignCenter );
  setColumnAlignment( HostListItem::tqStatus,   TQt::AlignLeft );
}

HostList::~HostList()
{}

void HostList::notifyHostError( TQString hostname, int error)
{
  TQListViewItemIterator it( this );
  HostListItem *host;
  while( it.current() ) {
    host = static_cast<HostListItem*>( it.current() );
    if( host->text(HostListItem::Hostname) == hostname )
    {
      host->setText( HostListItem::Hostname, hostname );
      host->settqStatus( error );
      host->tqrepaint();
      return;
    }
    ++it;
  }
}

void HostList::contentsMousePressEvent( TQMouseEvent *e)
{
  HostListItem *item = static_cast<HostListItem*>( itemAt( contentsToViewport( e->pos() ) ) );
  if( !( e->state() & TQt::ControlButton || e->state() & TQt::ShiftButton ) && ( e->button() & TQt::LeftButton ) && item)
  {
    // video column
    if( !m_read_only && 
        e->pos().x() > header()->sectionPos( HostListItem::Video ) &&
        e->pos().x() < header()->sectionPos( HostListItem::Video ) + header()->sectionSize( HostListItem::Video ) )
    {
      item->toggleVideo();
      item->updateColumn( HostListItem::Video );
      emit viewChanged();
    }
    // audio column
    else 
    if( !m_read_only && 
        e->pos().x() > header()->sectionPos( HostListItem::Audio ) &&
        e->pos().x() < header()->sectionPos( HostListItem::Audio ) + header()->sectionSize( HostListItem::Audio ) )
    {
      item->toggleAudio();
      item->updateColumn( HostListItem::Audio );
      emit viewChanged();
    }
    // status column
    else 
    if( e->pos().x() > header()->sectionPos( HostListItem::tqStatus ) &&
        e->pos().x() < header()->sectionPos( HostListItem::tqStatus ) + header()->sectionSize( HostListItem::tqStatus ) )
    {
      item->statusToolTip();
    }
    else // set new volume for item
    if( e->pos().x() > header()->sectionPos( HostListItem::Volume ) &&
        e->pos().x() < header()->sectionPos( HostListItem::Volume ) + header()->sectionSize( HostListItem::Volume ) )
    {
      int vol = e->pos().x();
      vol -= header()->sectionPos( HostListItem::Volume );
      item->setVolume( item->volumeAtPosition( vol ) );
    }
    else 
      KListView::contentsMousePressEvent( e );
  }
  else
    KListView::contentsMousePressEvent( e );
}

void HostList::contentsMouseMoveEvent( TQMouseEvent *e )
{
  if( e )
    KListView::contentsMouseMoveEvent( e );

    HostListItem *prev = m_hoveredVolume;
    const TQPoint pos = e ? e->pos() : viewportToContents( viewport()->mapFromGlobal( TQCursor::pos() ) );

    HostListItem *item = static_cast<HostListItem*>( itemAt( contentsToViewport( pos ) ) );
    if( item && pos.x() > header()->sectionPos( HostListItem::Volume ) &&
        pos.x() < header()->sectionPos( HostListItem::Volume ) + header()->sectionSize( HostListItem::Volume ) )
    {
        m_hoveredVolume = item;
        m_hoveredVolume->updateColumn( HostListItem::Volume );
    }
    else
        m_hoveredVolume = 0;

    if( prev )
      prev->updateColumn( HostListItem::Volume );
}

void HostList::leaveEvent( TQEvent *e )
{
  KListView::leaveEvent( e );

  HostListItem *prev = m_hoveredVolume;
  m_hoveredVolume = 0;
  if( prev )
    prev->updateColumn( HostListItem::Volume );
}

#include "HostList.moc"