~ubuntu-branches/ubuntu/trusty/kdeplasma-addons/trusty

« back to all changes in this revision

Viewing changes to applets/opendesktop/sendmessagewidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mfrom: (1.1.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100525095014-6mlrm9z9bkws0zkt
Tags: 4:4.4.80-0ubuntu1
* New upstream beta release:
  - Bump kde-sc-dev-latest build-dep version to 4.4.80
  - Refresh kubuntu_04_kimpanel_disable_scim.diff
  - Update various .install files
  - Drop liblancelot0a and liblancelot-dev packages; Upstream has broken ABI
    without an .so version bump, and after discussion with Debian it was
    decided it was not worth it to ship an unstable library.
  - Add liblancelot files to plasma-widget-lancelot, adding appropriate
    Replaces: entries
* Switch to source format 3.0 (quilt):
  - Bump debhelper build-depend version to 7.3.16 or greater

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 "sendmessagewidget.h"
23
 
 
24
 
#include <QtGui/QGraphicsGridLayout>
25
 
#include <QtGui/QGraphicsLinearLayout>
26
 
 
27
 
#include <KConfigGroup>
28
 
#include <KIconLoader>
29
 
#include <KTextEdit>
30
 
 
31
 
#include <Plasma/IconWidget>
32
 
#include <Plasma/Service>
33
 
#include <Plasma/ServiceJob>
34
 
 
35
 
#include "contactimage.h"
36
 
#include "utils.h"
37
 
 
38
 
 
39
 
using namespace Plasma;
40
 
 
41
 
SendMessageWidget::SendMessageWidget(DataEngine* engine, QGraphicsWidget* parent)
42
 
        : Frame(parent),
43
 
        m_engine(engine),
44
 
        m_personWatch(engine)
45
 
{
46
 
    m_updateTimer.setInterval(1000);
47
 
    m_updateTimer.setSingleShot(true);
48
 
 
49
 
    int avatarSize = KIconLoader::SizeMedium;
50
 
    int actionSize = KIconLoader::SizeSmallMedium;
51
 
    
52
 
    Label* title = new Label;
53
 
    title->setText(i18n("<b>Send message</b>"));
54
 
 
55
 
    // Recipient
56
 
    m_image = new ContactImage(m_engine);
57
 
    m_image->setMinimumHeight(avatarSize);
58
 
    m_image->setMinimumWidth(avatarSize);
59
 
    m_image->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
60
 
    m_toLabel = new Label;
61
 
    m_toEdit = new LineEdit;
62
 
    
63
 
    QGraphicsGridLayout* toLayout = new QGraphicsGridLayout;
64
 
    toLayout->setColumnFixedWidth(0, avatarSize * 1.2);
65
 
    toLayout->addItem(m_image, 0, 0, 2, 1);
66
 
    toLayout->addItem(m_toLabel, 0, 1);
67
 
    toLayout->addItem(m_toEdit, 1, 1);
68
 
 
69
 
    Label* subjectLabel = new Label;
70
 
    subjectLabel->setText(i18n("Subject:"));
71
 
 
72
 
    m_subject = new LineEdit;
73
 
 
74
 
    Label* bodyLabel = new Label;
75
 
    bodyLabel->setText(i18n("Message:"));
76
 
 
77
 
    Frame* bodyFrame = new Frame(this);
78
 
    bodyFrame->setFrameShadow(Sunken);
79
 
    bodyFrame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
80
 
    m_body = new TextEdit;
81
 
    (new QGraphicsLinearLayout(bodyFrame))->addItem(m_body);
82
 
 
83
 
    Plasma::IconWidget* cancel = new Plasma::IconWidget;
84
 
    cancel->setIcon("go-previous-view");
85
 
    cancel->setToolTip(i18n("Back"));
86
 
    cancel->setMinimumHeight(actionSize);
87
 
    cancel->setMaximumHeight(actionSize);
88
 
    cancel->setMinimumWidth(actionSize);
89
 
    cancel->setMaximumWidth(actionSize);
90
 
 
91
 
    m_submit = new Plasma::IconWidget;
92
 
    m_submit->setIcon("mail-send");
93
 
    m_submit->setToolTip(i18n("Send"));
94
 
    m_submit->setMinimumHeight(actionSize);
95
 
    m_submit->setMaximumHeight(actionSize);
96
 
    m_submit->setMinimumWidth(actionSize);
97
 
    m_submit->setMaximumWidth(actionSize);
98
 
    m_submit->setEnabled(false);
99
 
 
100
 
    QGraphicsLinearLayout* buttonLayout = new QGraphicsLinearLayout(Qt::Horizontal);
101
 
    buttonLayout->addItem(cancel);
102
 
    buttonLayout->addStretch();
103
 
    buttonLayout->addItem(m_submit);
104
 
 
105
 
    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this);
106
 
    layout->addItem(title);
107
 
    layout->addItem(toLayout);
108
 
    layout->addItem(subjectLabel);
109
 
    layout->addItem(m_subject);
110
 
    layout->addItem(bodyLabel);
111
 
    layout->addItem(bodyFrame);
112
 
    layout->addItem(buttonLayout);
113
 
 
114
 
    connect(m_submit, SIGNAL(clicked()), SLOT(send()));
115
 
    connect(cancel, SIGNAL(clicked()), SIGNAL(done()));
116
 
    connect(&m_updateTimer, SIGNAL(timeout()), SLOT(updateTo()));
117
 
    connect(m_toEdit, SIGNAL(editingFinished()), SLOT(updateTo()));
118
 
    connect(m_toEdit, SIGNAL(textEdited(QString)), SLOT(updateSendAction()));
119
 
    connect(m_toEdit, SIGNAL(textEdited(QString)), SLOT(toChanged(QString)));
120
 
    connect(m_toEdit, SIGNAL(returnPressed()), SLOT(switchToSubject()));
121
 
    connect(&m_personWatch, SIGNAL(updated()), SLOT(personUpdated()));
122
 
    connect(m_subject, SIGNAL(textEdited(QString)), SLOT(updateSendAction()));
123
 
    connect(m_subject, SIGNAL(returnPressed()), SLOT(switchToBody()));
124
 
    connect(m_body, SIGNAL(textChanged()), SLOT(updateSendAction()));
125
 
}
126
 
 
127
 
 
128
 
void SendMessageWidget::personUpdated()
129
 
{
130
 
    DataEngine::Data personData = m_personWatch.data();
131
 
    m_toLabel->setText(personData.value("Name").toString());
132
 
    m_image->setUrl(personData.value("AvatarUrl").toUrl());
133
 
}
134
 
 
135
 
 
136
 
void SendMessageWidget::send() {
137
 
    emit startWork();
138
 
    Service* service = m_engine->serviceForSource(personQuery(m_provider, m_id));
139
 
    KConfigGroup cg = service->operationDescription("sendMessage");
140
 
    cg.writeEntry("Subject", m_subject->text());
141
 
    cg.writeEntry("Body", m_body->nativeWidget()->toPlainText());
142
 
    ServiceJob* job = service->startOperationCall(cg);
143
 
    connect(job, SIGNAL(finished(KJob*)), SIGNAL(endWork()));
144
 
 
145
 
    // FIXME: We do not wait for the result atm
146
 
    emit done();
147
 
    m_id.clear();
148
 
    m_toEdit->setText(QString());
149
 
    m_personWatch.setId(QString());
150
 
    m_subject->setText(QString());
151
 
    m_body->setText(QString());
152
 
}
153
 
 
154
 
 
155
 
void SendMessageWidget::switchToBody()
156
 
{
157
 
    m_body->setFocus();
158
 
}
159
 
 
160
 
 
161
 
void SendMessageWidget::switchToSubject()
162
 
{
163
 
    m_subject->setFocus();
164
 
}
165
 
 
166
 
 
167
 
void SendMessageWidget::toChanged(const QString& to)
168
 
{
169
 
    m_id.clear();
170
 
    updateTo();
171
 
    m_id = to;
172
 
    m_updateTimer.stop();
173
 
    m_updateTimer.start();
174
 
}
175
 
 
176
 
 
177
 
void SendMessageWidget::updateSendAction()
178
 
{
179
 
    m_submit->setEnabled(!m_toEdit->text().isEmpty() && !m_subject->text().isEmpty() && !m_body->nativeWidget()->toPlainText().isEmpty());
180
 
}
181
 
 
182
 
 
183
 
void SendMessageWidget::updateTo()
184
 
{
185
 
    m_personWatch.setId(m_id);
186
 
}
187
 
 
188
 
 
189
 
void SendMessageWidget::setId(const QString& id)
190
 
{
191
 
    m_id = id;
192
 
    m_toEdit->setText(m_id);
193
 
    m_personWatch.setId(m_id);
194
 
}
195
 
 
196
 
 
197
 
void SendMessageWidget::setProvider(const QString& provider)
198
 
{
199
 
    m_id.clear();
200
 
    m_provider = provider;
201
 
    m_toEdit->setText(m_id);
202
 
    m_personWatch.setId(m_id);
203
 
    m_personWatch.setProvider(m_provider);
204
 
}
205
 
 
206
 
 
207
 
#include "sendmessagewidget.moc"