summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/playlistselection.cpp
blob: 780d70518db910be26d076a2751760f1fb4c9c49 (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
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "playlistselection.h"

/* OPIE */
#include <opie2/odebug.h>
using namespace Opie::Core;

/* QT */
#include <qheader.h>

/* STD */
#include <stdlib.h>

class PlayListSelectionItem : public QListViewItem {
public:
    PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) {
  setText( 0, f->name() );
  setPixmap( 0, f->pixmap() );
    }

    ~PlayListSelectionItem() {
    };

    const DocLnk *file() const { return fl; }

private:
    const DocLnk *fl;
};


PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
    : QListView( parent, name )
{
//    odebug << "starting playlistselector" << oendl; 
     addColumn( tr( "Playlist Selection" ) );
    header()->hide();
    setSorting( -1, FALSE );
}


PlayListSelection::~PlayListSelection() {
}


void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
//  odebug << "drawBackground" << oendl; 
   p->fillRect( r, QBrush( white ) );
}


void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
    if ( event->state() == QMouseEvent::LeftButton ) {
  QListViewItem *currentItem = selectedItem();
  QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
  if ( currentItem && currentItem->itemAbove() == itemUnder )
      moveSelectedUp();
  else if ( currentItem && currentItem->itemBelow() == itemUnder )
      moveSelectedDown();
    }
}


const DocLnk *PlayListSelection::current() {
    PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
    if ( item )
        return item->file();
    return NULL;
}


void PlayListSelection::addToSelection( const DocLnk &lnk ) {
    PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
    QListViewItem *current = selectedItem();
    if ( current )
        item->moveItem( current );
    setSelected( item, TRUE );
    ensureItemVisible( selectedItem() );
}


void PlayListSelection::removeSelected() {
    QListViewItem *item = selectedItem();
    delete item;
    setSelected( currentItem(), TRUE );
    ensureItemVisible( selectedItem() );
}


void PlayListSelection::moveSelectedUp() {
    QListViewItem *item = selectedItem();
    if ( item && item->itemAbove() )
        item->itemAbove()->moveItem( item );
    ensureItemVisible( selectedItem() );
}


void PlayListSelection::moveSelectedDown() {
    QListViewItem *item = selectedItem();
    if ( item && item->itemBelow() )
        item->moveItem( item->itemBelow() );
    ensureItemVisible( selectedItem() );
}


bool PlayListSelection::prev() {
    QListViewItem *item = selectedItem();
    if ( item && item->itemAbove() )
        setSelected( item->itemAbove(), TRUE );
    else
        return FALSE;
    ensureItemVisible( selectedItem() );
    return TRUE;
}

bool PlayListSelection::next() {
    QListViewItem *item = selectedItem();
    if ( item && item->itemBelow() )
        setSelected( item->itemBelow(), TRUE );
    else
        return FALSE;
    ensureItemVisible( selectedItem() );
    return TRUE;
}


bool PlayListSelection::first() {
    QListViewItem *item = firstChild();
    if ( item )
        setSelected( item, TRUE );
    else
        return FALSE;
    ensureItemVisible( selectedItem() );
    return TRUE;
}


bool PlayListSelection::last() {
    QListViewItem *prevItem = NULL;
    QListViewItem *item = firstChild();
    while ( ( item = item->nextSibling() ) )
        prevItem = item;
    if ( prevItem )
        setSelected( prevItem, TRUE );
    else
        return FALSE;
    ensureItemVisible( selectedItem() );
    return TRUE;
}

void PlayListSelection::unSelect()
{
    setSelected( currentItem(), FALSE);
}

void PlayListSelection::writeCurrent( Config& cfg ) {
    cfg.setGroup("PlayList");
    QListViewItem *item = selectedItem();
    if ( item ) {
        cfg.writeEntry("current", item->text(0) );
        odebug << item->text(0) << oendl;
    }

}

void  PlayListSelection::setSelectedItem(const QString &strk ) {

    unSelect();
    QListViewItemIterator it( this );
    for ( ; it.current(); ++it ) {
//        odebug << it.current()->text(0) << oendl; 
        if( strk == it.current()->text(0)) {
//             odebug << "We have a match "+strk << oendl; 
            setSelected( it.current(), TRUE);
            ensureItemVisible( it.current() );
            return;
        }
    }
}