Fix list index out of bounds crash on loading of .pls playlists, thanks to Tim Beaule...
[amarok.git] / src / directorylist.h
blob573ef9d55b59d57918a4834286ef2842b0d85ffc
1 /***************************************************************************
2 directorylist.h
3 -------------------
4 begin : Tue Feb 4 2003
5 copyright : (C) 2003 Scott Wheeler <wheeler@kde.org>
6 : (C) 2004 Max Howell <max.howell@methylblue.com>
7 : (C) 2004 Mark Kretschmann <markey@web.de>
8 ***************************************************************************/
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
19 #ifndef AMAROK_DIRECTORYLIST_H
20 #define AMAROK_DIRECTORYLIST_H
22 #include <KDirLister> //stack allocated
23 #include <KUrl> //stack allocated
24 #include <KVBox> //baseclass
26 #include <QCheckBox> //inlined functions
27 #include <q3listview.h> //baseclass
31 namespace CollectionFolder { class Item; }
33 class QFixedListView : public Q3ListView
34 // Reimplement sizeHint to have directorylist not being too big for "low" (1024x768 is not exactly low) resolutions
36 public:
37 explicit QFixedListView ( QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0 )
38 :Q3ListView(parent, name, f) {}
39 QSize sizeHint() const
41 return QSize(400, 100);
46 class CollectionSetup : public KVBox
48 friend class CollectionFolder::Item;
50 public:
51 static CollectionSetup* instance() { return s_instance; }
53 CollectionSetup( QWidget* );
54 void writeConfig();
56 QStringList dirs() const { return m_dirs; }
57 bool recursive() const { return m_recursive->isChecked(); }
58 bool monitor() const { return m_monitor->isChecked(); }
60 private:
61 static CollectionSetup* s_instance;
63 QFixedListView *m_view;
64 QStringList m_dirs;
65 QCheckBox *m_recursive;
66 QCheckBox *m_monitor;
70 namespace CollectionFolder { //just to keep it out of the global namespace
72 class Item : public QObject, public Q3CheckListItem
74 Q_OBJECT
75 public:
76 Item( Q3ListView *parent );
77 Item( Q3ListViewItem *parent, const KUrl &url , bool full_disable=false );
79 Q3CheckListItem *parent() const { return static_cast<Q3CheckListItem*>( Q3ListViewItem::parent() ); }
80 bool isFullyDisabled() const { return m_fullyDisabled; }
81 bool isDisabled() const { return isFullyDisabled() || ( CollectionSetup::instance()->recursive() && parent() && parent()->isOn() ); }
82 QString fullPath() const;
84 void setOpen( bool b ); // reimpl.
85 void stateChange( bool ); // reimpl.
86 void activate(); // reimpl.
87 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align ); // reimpl.
89 public slots:
90 void newItems( const KFileItemList& );
91 void completed() { if( childCount() == 0 ) { setExpandable( false ); repaint(); } }
93 private:
94 KDirLister m_lister;
95 KUrl m_url;
96 bool m_listed;
97 bool m_fullyDisabled;
101 #endif