author | erik <erik> | 2007-01-31 22:23:27 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-31 22:23:27 (UTC) |
commit | 73edac572d9ac9cfd18cc1254fc2019563d55f16 (patch) (unidiff) | |
tree | a420b341ce2bcb4a049c76935544b8bce2a0a853 /noncore/multimedia | |
parent | ed5fba8cdb27174427b2e7780508bafa05536ca1 (diff) | |
download | opie-73edac572d9ac9cfd18cc1254fc2019563d55f16.zip opie-73edac572d9ac9cfd18cc1254fc2019563d55f16.tar.gz opie-73edac572d9ac9cfd18cc1254fc2019563d55f16.tar.bz2 |
A few files that dereference pointers w/out checking that the pointer is
valid.
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistselection.cpp | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistselection.cpp b/noncore/multimedia/opieplayer2/playlistselection.cpp index 678ebdf..780d705 100644 --- a/noncore/multimedia/opieplayer2/playlistselection.cpp +++ b/noncore/multimedia/opieplayer2/playlistselection.cpp | |||
@@ -29,183 +29,168 @@ using namespace Opie::Core; | |||
29 | /* STD */ | 29 | /* STD */ |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | 31 | ||
32 | class PlayListSelectionItem : public QListViewItem { | 32 | class PlayListSelectionItem : public QListViewItem { |
33 | public: | 33 | public: |
34 | PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { | 34 | PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { |
35 | setText( 0, f->name() ); | 35 | setText( 0, f->name() ); |
36 | setPixmap( 0, f->pixmap() ); | 36 | setPixmap( 0, f->pixmap() ); |
37 | } | 37 | } |
38 | 38 | ||
39 | ~PlayListSelectionItem() { | 39 | ~PlayListSelectionItem() { |
40 | }; | 40 | }; |
41 | 41 | ||
42 | const DocLnk *file() const { return fl; } | 42 | const DocLnk *file() const { return fl; } |
43 | 43 | ||
44 | private: | 44 | private: |
45 | const DocLnk *fl; | 45 | const DocLnk *fl; |
46 | }; | 46 | }; |
47 | 47 | ||
48 | 48 | ||
49 | PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) | 49 | PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) |
50 | : QListView( parent, name ) | 50 | : QListView( parent, name ) |
51 | { | 51 | { |
52 | // odebug << "starting playlistselector" << oendl; | 52 | // odebug << "starting playlistselector" << oendl; |
53 | // #ifdef USE_PLAYLIST_BACKGROUND | ||
54 | // setStaticBackground( TRUE ); | ||
55 | // setBackgroundPixmap( Resource::loadPixmap( "opieplayer/background" ) ); | ||
56 | |||
57 | // setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) ); | ||
58 | // #endif | ||
59 | // addColumn("Title",236); | ||
60 | // setAllColumnsShowFocus( TRUE ); | ||
61 | addColumn( tr( "Playlist Selection" ) ); | 53 | addColumn( tr( "Playlist Selection" ) ); |
62 | header()->hide(); | 54 | header()->hide(); |
63 | setSorting( -1, FALSE ); | 55 | setSorting( -1, FALSE ); |
64 | } | 56 | } |
65 | 57 | ||
66 | 58 | ||
67 | PlayListSelection::~PlayListSelection() { | 59 | PlayListSelection::~PlayListSelection() { |
68 | } | 60 | } |
69 | 61 | ||
70 | 62 | ||
71 | // #ifdef USE_PLAYLIST_BACKGROUND | ||
72 | void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { | 63 | void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { |
73 | // odebug << "drawBackground" << oendl; | 64 | // odebug << "drawBackground" << oendl; |
74 | p->fillRect( r, QBrush( white ) ); | 65 | p->fillRect( r, QBrush( white ) ); |
75 | // QImage logo = Resource::loadImage( "launcher/opielogo" ); | ||
76 | // if ( !logo.isNull() ) | ||
77 | // p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); | ||
78 | } | 66 | } |
79 | // #endif | ||
80 | 67 | ||
81 | 68 | ||
82 | void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { | 69 | void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { |
83 | if ( event->state() == QMouseEvent::LeftButton ) { | 70 | if ( event->state() == QMouseEvent::LeftButton ) { |
84 | QListViewItem *currentItem = selectedItem(); | 71 | QListViewItem *currentItem = selectedItem(); |
85 | QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); | 72 | QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); |
86 | if ( currentItem && currentItem->itemAbove() == itemUnder ) | 73 | if ( currentItem && currentItem->itemAbove() == itemUnder ) |
87 | moveSelectedUp(); | 74 | moveSelectedUp(); |
88 | else if ( currentItem && currentItem->itemBelow() == itemUnder ) | 75 | else if ( currentItem && currentItem->itemBelow() == itemUnder ) |
89 | moveSelectedDown(); | 76 | moveSelectedDown(); |
90 | } | 77 | } |
91 | } | 78 | } |
92 | 79 | ||
93 | 80 | ||
94 | const DocLnk *PlayListSelection::current() { | 81 | const DocLnk *PlayListSelection::current() { |
95 | PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); | 82 | PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); |
96 | if ( item ) | 83 | if ( item ) |
97 | return item->file(); | 84 | return item->file(); |
98 | return NULL; | 85 | return NULL; |
99 | } | 86 | } |
100 | 87 | ||
101 | 88 | ||
102 | void PlayListSelection::addToSelection( const DocLnk &lnk ) { | 89 | void PlayListSelection::addToSelection( const DocLnk &lnk ) { |
103 | PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); | 90 | PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); |
104 | QListViewItem *current = selectedItem(); | 91 | QListViewItem *current = selectedItem(); |
105 | if ( current ) | 92 | if ( current ) |
106 | item->moveItem( current ); | 93 | item->moveItem( current ); |
107 | setSelected( item, TRUE ); | 94 | setSelected( item, TRUE ); |
108 | ensureItemVisible( selectedItem() ); | 95 | ensureItemVisible( selectedItem() ); |
109 | } | 96 | } |
110 | 97 | ||
111 | 98 | ||
112 | void PlayListSelection::removeSelected() { | 99 | void PlayListSelection::removeSelected() { |
113 | QListViewItem *item = selectedItem(); | 100 | QListViewItem *item = selectedItem(); |
114 | delete item; | 101 | delete item; |
115 | setSelected( currentItem(), TRUE ); | 102 | setSelected( currentItem(), TRUE ); |
116 | ensureItemVisible( selectedItem() ); | 103 | ensureItemVisible( selectedItem() ); |
117 | } | 104 | } |
118 | 105 | ||
119 | 106 | ||
120 | void PlayListSelection::moveSelectedUp() { | 107 | void PlayListSelection::moveSelectedUp() { |
121 | QListViewItem *item = selectedItem(); | 108 | QListViewItem *item = selectedItem(); |
122 | if ( item && item->itemAbove() ) | 109 | if ( item && item->itemAbove() ) |
123 | item->itemAbove()->moveItem( item ); | 110 | item->itemAbove()->moveItem( item ); |
124 | ensureItemVisible( selectedItem() ); | 111 | ensureItemVisible( selectedItem() ); |
125 | } | 112 | } |
126 | 113 | ||
127 | 114 | ||
128 | void PlayListSelection::moveSelectedDown() { | 115 | void PlayListSelection::moveSelectedDown() { |
129 | QListViewItem *item = selectedItem(); | 116 | QListViewItem *item = selectedItem(); |
130 | if ( item && item->itemBelow() ) | 117 | if ( item && item->itemBelow() ) |
131 | item->moveItem( item->itemBelow() ); | 118 | item->moveItem( item->itemBelow() ); |
132 | ensureItemVisible( selectedItem() ); | 119 | ensureItemVisible( selectedItem() ); |
133 | } | 120 | } |
134 | 121 | ||
135 | 122 | ||
136 | bool PlayListSelection::prev() { | 123 | bool PlayListSelection::prev() { |
137 | QListViewItem *item = selectedItem(); | 124 | QListViewItem *item = selectedItem(); |
138 | if ( item && item->itemAbove() ) | 125 | if ( item && item->itemAbove() ) |
139 | setSelected( item->itemAbove(), TRUE ); | 126 | setSelected( item->itemAbove(), TRUE ); |
140 | else | 127 | else |
141 | return FALSE; | 128 | return FALSE; |
142 | ensureItemVisible( selectedItem() ); | 129 | ensureItemVisible( selectedItem() ); |
143 | return TRUE; | 130 | return TRUE; |
144 | } | 131 | } |
145 | 132 | ||
146 | bool PlayListSelection::next() { | 133 | bool PlayListSelection::next() { |
147 | QListViewItem *item = selectedItem(); | 134 | QListViewItem *item = selectedItem(); |
148 | if ( item && item->itemBelow() ) | 135 | if ( item && item->itemBelow() ) |
149 | setSelected( item->itemBelow(), TRUE ); | 136 | setSelected( item->itemBelow(), TRUE ); |
150 | else | 137 | else |
151 | return FALSE; | 138 | return FALSE; |
152 | ensureItemVisible( selectedItem() ); | 139 | ensureItemVisible( selectedItem() ); |
153 | return TRUE; | 140 | return TRUE; |
154 | } | 141 | } |
155 | 142 | ||
156 | 143 | ||
157 | bool PlayListSelection::first() { | 144 | bool PlayListSelection::first() { |
158 | QListViewItem *item = firstChild(); | 145 | QListViewItem *item = firstChild(); |
159 | if ( item ) | 146 | if ( item ) |
160 | setSelected( item, TRUE ); | 147 | setSelected( item, TRUE ); |
161 | else | 148 | else |
162 | return FALSE; | 149 | return FALSE; |
163 | ensureItemVisible( selectedItem() ); | 150 | ensureItemVisible( selectedItem() ); |
164 | return TRUE; | 151 | return TRUE; |
165 | } | 152 | } |
166 | 153 | ||
167 | 154 | ||
168 | bool PlayListSelection::last() { | 155 | bool PlayListSelection::last() { |
169 | QListViewItem *prevItem = NULL; | 156 | QListViewItem *prevItem = NULL; |
170 | QListViewItem *item = firstChild(); | 157 | QListViewItem *item = firstChild(); |
171 | while ( ( item = item->nextSibling() ) ) | 158 | while ( ( item = item->nextSibling() ) ) |
172 | prevItem = item; | 159 | prevItem = item; |
173 | if ( prevItem ) | 160 | if ( prevItem ) |
174 | setSelected( prevItem, TRUE ); | 161 | setSelected( prevItem, TRUE ); |
175 | else | 162 | else |
176 | return FALSE; | 163 | return FALSE; |
177 | ensureItemVisible( selectedItem() ); | 164 | ensureItemVisible( selectedItem() ); |
178 | return TRUE; | 165 | return TRUE; |
179 | } | 166 | } |
180 | 167 | ||
181 | void PlayListSelection::unSelect() | 168 | void PlayListSelection::unSelect() |
182 | { | 169 | { |
183 | //QListViewItem *item = selectedItem(); | ||
184 | setSelected( currentItem(), FALSE); | 170 | setSelected( currentItem(), FALSE); |
185 | } | 171 | } |
186 | 172 | ||
187 | void PlayListSelection::writeCurrent( Config& cfg ) { | 173 | void PlayListSelection::writeCurrent( Config& cfg ) { |
188 | cfg.setGroup("PlayList"); | 174 | cfg.setGroup("PlayList"); |
189 | QListViewItem *item = selectedItem(); | 175 | QListViewItem *item = selectedItem(); |
190 | if ( item ) | 176 | if ( item ) { |
191 | cfg.writeEntry("current", item->text(0) ); | 177 | cfg.writeEntry("current", item->text(0) ); |
192 | odebug << item->text(0) << oendl; | 178 | odebug << item->text(0) << oendl; |
179 | } | ||
193 | 180 | ||
194 | } | 181 | } |
195 | 182 | ||
196 | void PlayListSelection::setSelectedItem(const QString &strk ) { | 183 | void PlayListSelection::setSelectedItem(const QString &strk ) { |
197 | 184 | ||
198 | unSelect(); | 185 | unSelect(); |
199 | QListViewItemIterator it( this ); | 186 | QListViewItemIterator it( this ); |
200 | for ( ; it.current(); ++it ) { | 187 | for ( ; it.current(); ++it ) { |
201 | // odebug << it.current()->text(0) << oendl; | 188 | // odebug << it.current()->text(0) << oendl; |
202 | if( strk == it.current()->text(0)) { | 189 | if( strk == it.current()->text(0)) { |
203 | // odebug << "We have a match "+strk << oendl; | 190 | // odebug << "We have a match "+strk << oendl; |
204 | setSelected( it.current(), TRUE); | 191 | setSelected( it.current(), TRUE); |
205 | ensureItemVisible( it.current() ); | 192 | ensureItemVisible( it.current() ); |
206 | return; | 193 | return; |
207 | } | 194 | } |
208 | } | 195 | } |
209 | // setSelected( item, TRUE ); | ||
210 | // ensureItemVisible( selectedItem() ); | ||
211 | } | 196 | } |