Merge branch 'master' into situare_interact
[situare] / src / ui / notificationpanel.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Jussi Laitinen - jussi.laitinen@ixonos.com
6
7     Situare is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     version 2 as published by the Free Software Foundation.
10
11     Situare is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with Situare; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19     USA.
20 */
21
22 #include <QDebug>
23 #include <QVBoxLayout>
24
25 #include "extendedlistitemdelegate.h"
26 #include "imagebutton.h"
27 #include "notificationlistitem.h"
28 #include "notificationlistview.h"
29 #include "panelcommon.h"
30 #include "situareservice/notification.h"
31
32 #include "notificationpanel.h"
33
34 NotificationPanel::NotificationPanel(QWidget *parent)
35     : PanelBase(parent)
36 {
37     qDebug() << __PRETTY_FUNCTION__;
38
39     // --- MAIN LAYOUT ---
40     QVBoxLayout *notificationLayout = new QVBoxLayout;
41     notificationLayout->setMargin(0);
42     notificationLayout->setSpacing(0);
43     setLayout(notificationLayout);
44
45     QVBoxLayout *listViewLayout = new QVBoxLayout;
46     listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
47                                        PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
48     notificationLayout->addLayout(listViewLayout);
49
50     ImageButton *refreshNotificationsButton = new ImageButton(":/res/images/refresh.png",
51                                                               ":/res/images/refresh_s.png",
52                                                               "", this);
53     connect(refreshNotificationsButton, SIGNAL(clicked()),
54             this, SIGNAL(requestNotifications()));
55
56     m_notificationListView = new NotificationListView(this);
57     m_notificationListView->setItemDelegate(new ExtendedListItemDelegate(this));
58     listViewLayout->addWidget(m_notificationListView);
59
60     m_genericButtonsLayout->addWidget(refreshNotificationsButton);
61 }
62
63 void NotificationPanel::anyPanelClosed()
64 {
65     qDebug() << __PRETTY_FUNCTION__;
66
67     m_notificationListView->clearItemSelection();
68 }
69
70 void NotificationPanel::hideEvent(QHideEvent *event)
71 {
72     qDebug() << __PRETTY_FUNCTION__;
73
74     QWidget::hideEvent(event);
75
76     m_notificationListView->clearItemSelection();
77 }
78
79 void NotificationPanel::populateNotificationListView(QList<Notification> &notifications)
80 {
81     qWarning() << __PRETTY_FUNCTION__;
82
83     m_notificationListView->clearList();
84
85     foreach (Notification notification, notifications) {
86         NotificationListItem *item = new NotificationListItem();
87         item->setNotificationData(notification);
88         m_notificationListView->addListItem(notification.id(), item);
89     }
90 }
91
92 void NotificationPanel::setImage(const QString &id, const QPixmap &image)
93 {
94     qWarning() << __PRETTY_FUNCTION__ << id;
95
96     NotificationListItem *item = dynamic_cast<NotificationListItem*>(
97             m_notificationListView->listItem(id));
98
99     if (item) {
100         qWarning() << __PRETTY_FUNCTION__ << "item!";
101         item->setImage(image);
102     }
103 }
104