Fixed seg fault on logout.
[situare] / src / ui / userinfopanel.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Katri Kaikkonen - katri.kaikkonen@ixonos.com
7         Pekka Nissinen - pekka.nissinen@ixonos.com
8
9     Situare is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public License
11     version 2 as published by the Free Software Foundation.
12
13     Situare is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with Situare; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
21     USA.
22 */
23
24 #include <QScrollArea>
25 #include <QVBoxLayout>
26
27 #include "imagebutton.h"
28 #include "panelcommon.h"
29 #include "userinfo.h"
30
31 #include "userinfopanel.h"
32
33 UserInfoPanel::UserInfoPanel(QWidget *parent)
34     : PanelBase(parent)
35 {
36     qDebug() << __PRETTY_FUNCTION__;
37
38     QVBoxLayout *userInfoPanelLayout = new QVBoxLayout;
39     userInfoPanelLayout->setMargin(0);
40     userInfoPanelLayout->setSpacing(0);
41     userInfoPanelLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
42                                             PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
43     setLayout(userInfoPanelLayout);
44
45     m_userInfo = new UserInfo(this);
46
47     QWidget *userInfoView = new QWidget(this);
48     QVBoxLayout *userInfoViewLayout = new QVBoxLayout(userInfoView);
49     userInfoViewLayout->setMargin(0);
50     userInfoViewLayout->setSpacing(0);
51     userInfoViewLayout->setStretch(0, 0);
52     userInfoViewLayout->setSizeConstraint(QLayout::SetFixedSize);
53     userInfoViewLayout->addWidget(m_userInfo);
54
55     QScrollArea *userInfoScroll = new QScrollArea();
56     userInfoScroll->setWidgetResizable(true);
57     userInfoScroll->setWidget(userInfoView);
58     userInfoScroll->setAlignment(Qt::AlignVCenter);
59     userInfoScroll->viewport()->setAutoFillBackground(false);
60     userInfoScroll->widget()->setAutoFillBackground(false);
61
62     userInfoPanelLayout->addWidget(userInfoScroll);
63
64     connect(m_userInfo, SIGNAL(findUser(GeoCoordinate)),
65             this, SIGNAL(findUser(GeoCoordinate)));
66
67     connect(this, SIGNAL(collapse()),
68             m_userInfo, SLOT(collapse()));
69
70     ImageButton *updateFriendsButton = new ImageButton(":/res/images/refresh.png",
71                                                        ":/res/images/refresh_s.png",
72                                                        "", this);
73     ImageButton *updateStatusMessageButton = new ImageButton(":/res/images/send_position.png",
74                                                              ":/res/images/send_position_s.png",
75                                                              "", this);
76
77     m_genericButtonsLayout->addWidget(updateFriendsButton);
78     m_genericButtonsLayout->addWidget(updateStatusMessageButton);
79
80     connect(updateFriendsButton, SIGNAL(clicked()),
81             this, SIGNAL(refreshUserData()));
82
83     connect(updateStatusMessageButton, SIGNAL(clicked()),
84             this, SIGNAL(updateLocationMessageButtonClicked()));
85
86 }
87
88 void UserInfoPanel::showUserInfo(bool logged)
89 {
90     qDebug() << __PRETTY_FUNCTION__;
91
92     m_userInfo->setVisible(logged);
93 }
94
95 void UserInfoPanel::userDataReceived(User *user)
96 {
97     qDebug() << __PRETTY_FUNCTION__;
98
99     if(user) {
100         m_userInfo->setUserName(user->name());
101         m_userInfo->setProfileImage(user->profileImage());
102         m_userInfo->setMessageText(user->note());
103         m_userInfo->setAddress(user->address());
104         m_userInfo->setTime(user->timestamp());
105         m_userInfo->setCoordinates(user->coordinates());
106
107         m_userInfo->show();
108     }
109 }