Updated library dialog works.
[dorian] / widgets / listwindow.h
1 #ifndef LISTWINDOW_H
2 #define LISTWINDOW_H
3
4 #include <QMainWindow>
5 #include <QDialogButtonBox>
6 #include <QList>
7
8 class QString;
9 class QPushButton;
10 class FlickCharm;
11 class QAbstractItemModel;
12 class QListWidget;
13 class QModelIndex;
14
15 /** A window with a list and menu actions (Maemo) or buttons (non-Maemo). */
16 class ListWindow: public QMainWindow
17 {
18     Q_OBJECT
19
20 public:
21     /**
22      * Constructor.
23      * @param   noItems Text to display when the list has no items.
24      * @param   parent  Parent widget.
25      */
26     explicit ListWindow(const QString &noItems, QWidget *parent = 0);
27
28     /** Set the model for the list. */
29     void setModel(QAbstractItemModel *model);
30
31     /** Get model. */
32     QAbstractItemModel *model() const;
33
34     /** Add an action button to the beginning of the list. */
35     void addButton(const QString &title, QObject *receiver, const char *slot,
36                    const QString &iconPath = QString());
37
38     /** Add an action to the menu. */
39     QAction *addMenuAction(const QString &title, QObject *receiver,
40                            const char *slot);
41
42 signals:
43     /** Emitted when a list item is activated. */
44     void activated(const QModelIndex &index);
45
46 public slots:
47     /** Set the current (selected) item. */
48     void setCurrentItem(const QModelIndex &item);
49
50 #ifdef Q_OS_SYMBIAN
51     void show();
52 #endif
53
54 protected slots:
55     void onItemActivated(const QModelIndex &);
56     void populateList();
57
58 protected:
59     struct Button {
60         QString title;
61         QObject *receiver;
62         const char *slot;
63         QString iconName;
64     };
65     void insertButton(int row, const Button &button);
66 #ifdef Q_WS_MAEMO_5
67     void closeEvent(QCloseEvent *event);
68 #endif
69
70 private:
71     QListWidget *list;
72     QAbstractItemModel *mModel;
73     QList<Button> buttons;
74     QString noItems;
75 #ifdef Q_OS_SYMBIAN
76     FlickCharm *charm;
77 #endif
78 };
79
80 #endif // LISTWINDOW_H