~ubuntu-branches/ubuntu/oneiric/kdeplasma-addons/oneiric

« back to all changes in this revision

Viewing changes to applets/opendesktop/friendmanagementwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mto: (0.4.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: james.westby@ubuntu.com-20100525095014-e3cebfkdenjrx3xg
Tags: upstream-4.4.80
Import upstream version 4.4.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of KDE.
3
 
 
4
 
    Copyright (c) 2009 Eckhart Wörner <ewoerner@kde.org>
5
 
 
6
 
    This program is free software; you can redistribute it and/or modify
7
 
    it under the terms of the GNU General Public License as published by
8
 
    the Free Software Foundation; either version 2 of the License, or
9
 
    (at your option) any later version.
10
 
 
11
 
    This program 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 this program; 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 "friendmanagementwidget.h"
23
 
 
24
 
#include <QtGui/QGraphicsGridLayout>
25
 
#include <QtGui/QGraphicsLinearLayout>
26
 
#include <QtGui/QLabel>
27
 
 
28
 
#include <KConfigGroup>
29
 
#include <KIconLoader>
30
 
 
31
 
#include <Plasma/IconWidget>
32
 
#include <Plasma/Label>
33
 
#include <Plasma/Service>
34
 
 
35
 
#include "contactimage.h"
36
 
#include "utils.h"
37
 
 
38
 
 
39
 
using namespace Plasma;
40
 
 
41
 
FriendManagementWidget::FriendManagementWidget(DataEngine* engine, QGraphicsWidget* parent)
42
 
    : Frame(parent), m_isHovered(false), m_personWatch(engine), m_engine(engine)
43
 
{
44
 
    setAcceptHoverEvents(true);
45
 
    buildDialog();
46
 
    updateActions();
47
 
    setMinimumHeight(40);
48
 
    setMinimumWidth(120);
49
 
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
50
 
    connect(&m_personWatch, SIGNAL(updated()), SLOT(updated()));
51
 
}
52
 
 
53
 
 
54
 
void FriendManagementWidget::buildDialog()
55
 
{
56
 
    int avatarSize = KIconLoader::SizeMedium;
57
 
    int actionsSize = KIconLoader::SizeSmallMedium;
58
 
 
59
 
    m_infoLabel = new Plasma::Label;
60
 
    m_infoLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
61
 
    m_infoLabel->setMinimumWidth(avatarSize * 2);
62
 
 
63
 
    m_statusLabel = new Plasma::Label;
64
 
    m_statusLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
65
 
    m_statusLabel->setMinimumWidth(avatarSize * 2);
66
 
    m_statusLabel->setText(i18n("<i>Accepting friendship...</i>"));
67
 
 
68
 
    m_avatar = new ContactImage(0);
69
 
    m_avatar->setMinimumHeight(avatarSize);
70
 
    m_avatar->setMinimumWidth(avatarSize);
71
 
    m_avatar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
72
 
 
73
 
    m_actionAccept = new IconWidget;
74
 
    m_actionAccept->setIcon("dialog-ok");
75
 
    m_actionAccept->setToolTip(i18n("Accept friendship"));
76
 
    m_actionAccept->setMinimumHeight(actionsSize);
77
 
    m_actionAccept->setMaximumHeight(actionsSize);
78
 
    m_actionAccept->setMinimumWidth(actionsSize);
79
 
    m_actionAccept->setMaximumWidth(actionsSize);
80
 
 
81
 
    m_actionDecline = new IconWidget;
82
 
    m_actionDecline->setIcon("dialog-cancel");
83
 
    m_actionDecline->setToolTip(i18n("Decline friendship"));
84
 
    m_actionDecline->setMinimumHeight(actionsSize);
85
 
    m_actionDecline->setMaximumHeight(actionsSize);
86
 
    m_actionDecline->setMinimumWidth(actionsSize);
87
 
    m_actionDecline->setMaximumWidth(actionsSize);
88
 
 
89
 
    m_actions = new QGraphicsLinearLayout;
90
 
    m_actions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
91
 
    m_actions->addItem(m_actionAccept);
92
 
    m_actions->addItem(m_actionDecline);
93
 
 
94
 
    layout = new QGraphicsGridLayout;
95
 
    layout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
96
 
    layout->setColumnFixedWidth(0, int(avatarSize * 1.2));
97
 
    layout->setHorizontalSpacing(4);
98
 
    layout->addItem(m_avatar, 0, 0, 2, 1, Qt::AlignTop);
99
 
    layout->addItem(m_infoLabel, 0, 1, 1, 1, Qt::AlignCenter | Qt::AlignHCenter);
100
 
    layout->addItem(m_actions, 1, 1, 1, 1, Qt::AlignBottom | Qt::AlignRight);
101
 
 
102
 
    setLayout(layout);
103
 
 
104
 
    connect(m_actionAccept, SIGNAL(clicked()), SLOT(accept()));
105
 
    connect(m_actionDecline, SIGNAL(clicked()), SLOT(accept()));
106
 
}
107
 
 
108
 
 
109
 
void FriendManagementWidget::accept()
110
 
{
111
 
    Service* service = m_engine->serviceForSource(personQuery(m_provider, m_id));
112
 
    KConfigGroup cg = service->operationDescription("approveFriendship");
113
 
    service->startOperationCall(cg);
114
 
}
115
 
 
116
 
 
117
 
void FriendManagementWidget::decline()
118
 
{
119
 
    Service* service = m_engine->serviceForSource(personQuery(m_provider, m_id));
120
 
    KConfigGroup cg = service->operationDescription("declineFriendship");
121
 
    service->startOperationCall(cg);
122
 
}
123
 
 
124
 
 
125
 
void FriendManagementWidget::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
126
 
{
127
 
    Q_UNUSED(event)
128
 
    m_isHovered = true;
129
 
    updateActions();
130
 
}
131
 
 
132
 
 
133
 
void FriendManagementWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
134
 
{
135
 
    Q_UNUSED(event)
136
 
    m_isHovered = false;
137
 
    updateActions();
138
 
}
139
 
 
140
 
 
141
 
void FriendManagementWidget::setId(const QString& id)
142
 
{
143
 
    m_id = id;
144
 
    m_personWatch.setId(m_id);
145
 
}
146
 
 
147
 
 
148
 
void FriendManagementWidget::setProvider(const QString& provider)
149
 
{
150
 
    m_provider = provider;
151
 
    m_personWatch.setProvider(provider);
152
 
}
153
 
 
154
 
 
155
 
void FriendManagementWidget::updateActions()
156
 
{
157
 
    m_actionAccept->setVisible(m_isHovered);
158
 
    m_actionDecline->setVisible(m_isHovered);
159
 
}
160
 
 
161
 
 
162
 
void FriendManagementWidget::updated()
163
 
{
164
 
    QString firstName = m_personWatch.data().value("FirstName").toString();
165
 
    QString lastName = m_personWatch.data().value("LastName").toString();
166
 
    if (!firstName.isEmpty() || !lastName.isEmpty()) {
167
 
        m_infoLabel->setText(i18n("<b>%1 %2 (%3)</b> wants to be your friend", firstName, lastName, m_id));
168
 
    } else {
169
 
        m_infoLabel->setText(i18n("<b>%1</b> wants to be your friend", m_id));
170
 
    }
171
 
    m_avatar->setUrl(m_personWatch.data().value("AvatarUrl").toUrl());
172
 
}
173
 
 
174
 
 
175
 
#include "friendmanagementwidget.moc"