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()));
82 connect(this, SIGNAL(panelOpened()),
83 this, SLOT(clearFriendListFilter()));
85 connect(m_locationListView, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
86 this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
89 void FriendListPanel::friendImageReady(User *user)
91 qDebug() << __PRETTY_FUNCTION__;
93 FriendListItem *item = static_cast<FriendListItem*>(m_friendListView->listItem(user->userId()));
96 item->setAvatarImage(user->profileImage());
99 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
101 qDebug() << __PRETTY_FUNCTION__;
103 QStringList newUserIDs;
105 foreach (User *user, friendList) {
106 FriendListItem *item = 0;
107 if (!m_friendListView->contains(user->userId())) {
108 item = new FriendListItem();
109 item->setUserData(user);
110 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();
135 m_friendListView->filter("pek");
138 void FriendListPanel::locationDataReady(QList<Location> &result)
140 qDebug() << __PRETTY_FUNCTION__;
142 m_locationListView->clearList();
144 for (int i = 0; i < result.size(); ++i) {
145 LocationListItem *item = new LocationListItem();
146 item->setLocationData(result.at(i));
147 m_locationListView->addListItem(QString::number(i), item);
152 if (result.size() == 1) {
153 ListItem *item = m_locationListView->listItem(QString("0"));
156 m_locationListView->listItemClicked(item);
160 void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
162 qDebug() << __PRETTY_FUNCTION__;
164 m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
167 m_friendListHeaderWidget->show();
168 m_friendListView->filter(userIDs);