2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
6 Henri Lampela - henri.lampela@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 #include "coordinates/geocoordinate.h"
24 #include "friendlistview.h"
25 #include "friendlistitem.h"
26 #include "friendlistitemdelegate.h"
27 #include "panelcommon.h"
28 #include "sidepanel.h"
29 #include "../routing/location.h"
30 #include "locationlistitem.h"
31 #include "locationlistview.h"
32 #include "extendedlistitemdelegate.h"
34 #include "friendlistpanel.h"
36 FriendListPanel::FriendListPanel(QWidget *parent)
39 qDebug() << __PRETTY_FUNCTION__;
41 setType(SidePanel::FriendPanel);
43 QHBoxLayout *filterLayout = new QHBoxLayout;
44 filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, 0,
45 FRIENDPANEL_FILTER_MARGIN_RIGHT, 0);
46 m_friendListHeaderWidget = new QWidget();
47 m_friendListHeaderWidget->setLayout(filterLayout);
48 m_friendListHeaderWidget->setAutoFillBackground(true);
49 QPalette labelPalette = m_friendListHeaderWidget->palette();
50 labelPalette.setColor(QPalette::Background, Qt::black);
51 m_friendListHeaderWidget->setPalette(labelPalette);
52 m_friendListHeaderWidget->hide();
53 m_friendListLabel = new QLabel(this);
54 m_clearFilterButton = new QPushButton(tr("Show all"));
55 filterLayout->addWidget(m_friendListLabel);
56 filterLayout->addWidget(m_clearFilterButton);
57 m_panelVBox->addWidget(m_friendListHeaderWidget);
59 QVBoxLayout *friendListLayout = new QVBoxLayout;
60 friendListLayout->setContentsMargins(FRIENDPANEL_MARGIN_LEFT, FRIENDPANEL_MARGIN_TOP,
61 FRIENDPANEL_MARGIN_RIGHT, FRIENDPANEL_MARGIN_BOTTOM);
63 m_friendListView = new FriendListView(this);
64 m_friendListView->setItemDelegate(new FriendListItemDelegate(this));
66 //m_friendListView->hide();
68 m_locationListView = new LocationListView(this);
69 m_locationListView->setItemDelegate(new ExtendedListItemDelegate(this));
71 m_locationListView->hide();
73 friendListLayout->addWidget(m_friendListView);
74 //friendListLayout->addWidget(m_locationListView);
75 m_panelVBox->addLayout(friendListLayout);
77 connect(m_friendListView, SIGNAL(friendItemClicked(GeoCoordinate)),
78 this, SIGNAL(friendItemClicked(GeoCoordinate)));
80 connect(m_clearFilterButton, SIGNAL(clicked()),
81 this, SLOT(clearFriendListFilter()));
83 connect(m_locationListView, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
84 this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
86 connect(this, SIGNAL(panelOpened()),
87 this, SLOT(clearFriendListFilter()));
90 void FriendListPanel::friendImageReady(User *user)
92 qDebug() << __PRETTY_FUNCTION__;
94 FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
97 item->setAvatarImage(user->profileImage());
100 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
102 qDebug() << __PRETTY_FUNCTION__;
104 QStringList newUserIDs;
106 foreach (User *user, friendList) {
107 FriendListItem *item = 0;
108 if (!m_friendListView->contains(user->userId())) {
109 item = new FriendListItem();
110 item->setUserData(user);
111 m_friendListView->addListItem(user->userId(), item);
113 item = static_cast<FriendListItem *>(m_friendListView->takeListItemFromView(
117 item->setUserData(user);
118 m_friendListView->addListItemToView(item);
122 newUserIDs.append(user->userId());
125 m_friendListView->clearUnused(newUserIDs);
128 void FriendListPanel::clearFriendListFilter()
130 qDebug() << __PRETTY_FUNCTION__;
132 m_friendListHeaderWidget->hide();
133 m_friendListView->clearFilter();
136 void FriendListPanel::locationDataReady(QList<Location> &result)
138 qDebug() << __PRETTY_FUNCTION__;
140 if (result.size() == 0)
143 m_locationListView->clearList();
145 for (int i = 0; i < result.size(); ++i) {
146 LocationListItem *item = new LocationListItem();
147 item->setLocationData(result.at(i));
148 m_locationListView->addListItem(QString::number(i), item);
153 if (result.size() == 1) {
154 ListItem *item = m_locationListView->listItem(QString("0"));
157 m_locationListView->listItemClicked(item);
161 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
163 qDebug() << __PRETTY_FUNCTION__;
165 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
168 m_friendListHeaderWidget->show();
169 m_friendListView->filter(userIDs);