| 1 |
/* -*- Mode: C++ -*- |
| 2 |
* meegotouchcp-telephony: a telephony control panel applet |
| 3 |
* Copyright (c) 2010, Intel Corporation. |
| 4 |
* |
| 5 |
* This program is licensed under the terms and conditions of the |
| 6 |
* Apache License, version 2.0. The full text of the Apache License is at |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "telephonywidget.h" |
| 12 |
#include "propertyeditor.h" |
| 13 |
#include "callsettingspropertyeditor.h" |
| 14 |
|
| 15 |
#include <modemproxy.h> |
| 16 |
#include <managerproxy.h> |
| 17 |
#include <MButton> |
| 18 |
#include <QDebug> |
| 19 |
#include <QSignalMapper> |
| 20 |
|
| 21 |
//% "String telling user their current phone number %1 contains the phone number" |
| 22 |
const QString TelephonyWidget::numberTemplate = qtTrId("My number: %1"); |
| 23 |
|
| 24 |
TelephonyWidget::TelephonyWidget(QGraphicsWidget *parent) : DcpWidget(parent) |
| 25 |
{ |
| 26 |
m_layout = new QGraphicsLinearLayout(Qt::Vertical); |
| 27 |
QSignalMapper *mapper = new QSignalMapper(this); |
| 28 |
|
| 29 |
ManagerProxy *manager = ManagerProxy::instance(); |
| 30 |
ModemProxy *modem = manager->modem(); //FIXME, when API is changed |
| 31 |
//to multiple modems, this |
| 32 |
//needs change |
| 33 |
SettingsManager *settingsManager = new SettingsManager(modem->path()); |
| 34 |
ForwardingManager *forwardingManager = new ForwardingManager(modem->path()); |
| 35 |
|
| 36 |
m_networkProxy = new NetworkProxy(modem->path()); |
| 37 |
m_simManager = new SimManager(modem->path()); |
| 38 |
m_radioSettingsProxy = new RadioSettingsProxy(modem->path()); |
| 39 |
|
| 40 |
//% "My number:" |
| 41 |
QString myNumber = qtTrId("qtn_my_number"); |
| 42 |
AbstractPropertyEditor *numberPropertyEditor = |
| 43 |
PropertyEditorFactory::createEditor(m_simManager, |
| 44 |
"subscriberNumbers", |
| 45 |
myNumber, |
| 46 |
"SubscriberNumberPropertyEditor"); |
| 47 |
Q_ASSERT(numberPropertyEditor); |
| 48 |
m_layout->addItem(numberPropertyEditor); |
| 49 |
|
| 50 |
//% "Send My Caller ID" |
| 51 |
QString sendCallerId = qtTrId("qtn_send_caller_id"); |
| 52 |
AbstractPropertyEditor *hideCallerIdEditor = |
| 53 |
PropertyEditorFactory::createEditor(settingsManager, |
| 54 |
"hideCallerId", |
| 55 |
sendCallerId, |
| 56 |
"CallSettingsPropertyEditor"); |
| 57 |
Q_ASSERT(hideCallerIdEditor); |
| 58 |
m_layout->addItem(hideCallerIdEditor); |
| 59 |
|
| 60 |
//% "Hear Call Waiting" |
| 61 |
QString hearCallWaiting = qtTrId("qtn_hear_call_waiting"); |
| 62 |
AbstractPropertyEditor *callWaitingEditor = |
| 63 |
PropertyEditorFactory::createEditor(settingsManager, |
| 64 |
"voiceCallWaiting", |
| 65 |
hearCallWaiting, |
| 66 |
"CallSettingsPropertyEditor"); |
| 67 |
Q_ASSERT(callWaitingEditor); |
| 68 |
m_layout->addItem(callWaitingEditor); |
| 69 |
|
| 70 |
//% "3g" |
| 71 |
QString threeG = qtTrId("qtn_three_gee"); |
| 72 |
AbstractPropertyEditor *technologyPropertyEditor = |
| 73 |
PropertyEditorFactory::createEditor(m_radioSettingsProxy, |
| 74 |
"technologyPreference", |
| 75 |
threeG, |
| 76 |
"RadioSettingsPropertyEditor"); |
| 77 |
Q_ASSERT(technologyPropertyEditor); |
| 78 |
m_layout->addItem(technologyPropertyEditor); |
| 79 |
|
| 80 |
m_nagItem = new MGConfItem("/apps/dialer/supressContactNag", this); |
| 81 |
connect(m_nagItem, SIGNAL(valueChanged()), |
| 82 |
SLOT(nagChanged())); |
| 83 |
MWidget *widget = new MWidget(); |
| 84 |
QGraphicsLinearLayout *nagLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
| 85 |
widget->setLayout(nagLayout); |
| 86 |
//% "Prompt to add contact" |
| 87 |
MLabel *label = new MLabel(qtTrId("qtn_contact_nag")); |
| 88 |
label->setWordWrap(true); |
| 89 |
nagLayout->addItem(label); |
| 90 |
m_nagButton = new MButton(); |
| 91 |
m_nagButton->setViewType(MButton::switchType); |
| 92 |
m_nagButton->setCheckable(true); |
| 93 |
nagChanged(); |
| 94 |
connect(m_nagButton, SIGNAL(toggled(bool)), |
| 95 |
SLOT(nagButtonToggled(bool))); |
| 96 |
nagLayout->addItem(m_nagButton); |
| 97 |
nagLayout->setAlignment(m_nagButton, Qt::AlignVCenter); |
| 98 |
m_layout->addItem(widget); |
| 99 |
|
| 100 |
//% "Forward All Calls" |
| 101 |
QString forwardAllCalls = qtTrId("qtn_forward_all_calls"); |
| 102 |
m_unconditional = dynamic_cast<CallForwardingPropertyEditor*>(PropertyEditorFactory::createEditor(forwardingManager, |
| 103 |
"voiceUnconditional", |
| 104 |
forwardAllCalls, |
| 105 |
"CallForwardingPropertyEditor")); |
| 106 |
Q_ASSERT(m_unconditional); |
| 107 |
connect(m_unconditional, SIGNAL(toggled(bool)), |
| 108 |
SLOT(unconditionalToggled(bool))); |
| 109 |
//% "Call Forwarding" |
| 110 |
m_forwardingButton = new MButton(qtTrId("qtn_call_forwarding_button")); |
| 111 |
mapper->setMapping(m_forwardingButton, 2); |
| 112 |
connect(m_forwardingButton, SIGNAL(clicked()), |
| 113 |
mapper, SLOT(map())); |
| 114 |
m_layout->addItem(m_unconditional); |
| 115 |
|
| 116 |
//% "Set Speed Dial" |
| 117 |
MButton *button = new MButton(qtTrId("qtn_speed_dial_button")); |
| 118 |
button->setObjectName("speedDialButton"); |
| 119 |
mapper->setMapping(button, 3); //FIXME: move to #define or static const int |
| 120 |
connect(button, SIGNAL(clicked()), |
| 121 |
mapper, SLOT(map())); |
| 122 |
m_layout->addItem(button); |
| 123 |
|
| 124 |
//% "Call Barring Settings" |
| 125 |
button = new MButton(qtTrId("qtn_barring_settings_button")); |
| 126 |
button->setObjectName("barringSettingsButton"); |
| 127 |
mapper->setMapping(button, 5); //FIXME: not defined |
| 128 |
connect(button, SIGNAL(clicked()), |
| 129 |
mapper, SLOT(map())); |
| 130 |
m_layout->addItem(button); |
| 131 |
|
| 132 |
connect(mapper, SIGNAL(mapped(int)), |
| 133 |
SLOT(mapped(int))); |
| 134 |
|
| 135 |
|
| 136 |
m_layout->addStretch(); |
| 137 |
|
| 138 |
setLayout(m_layout); |
| 139 |
} |
| 140 |
|
| 141 |
TelephonyWidget::~TelephonyWidget() |
| 142 |
{ |
| 143 |
qDebug() << "TelephonyWidget::~TelephonyWidget()"; |
| 144 |
if (m_forwardingButton) { |
| 145 |
m_forwardingButton->deleteLater(); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
bool TelephonyWidget::back() |
| 150 |
{ |
| 151 |
return true; |
| 152 |
} |
| 153 |
|
| 154 |
QString TelephonyWidget::title() const |
| 155 |
{ |
| 156 |
return "Dialer Settings"; |
| 157 |
} |
| 158 |
|
| 159 |
void TelephonyWidget::mapped(int widgetNumber) |
| 160 |
{ |
| 161 |
qDebug() << "TelephonyWidget::mapped(" << widgetNumber << ")"; |
| 162 |
changeWidget(widgetNumber); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
void TelephonyWidget::subscriberNumbersChanged(const QStringList &subscriberNumbers) |
| 167 |
{ |
| 168 |
if (subscriberNumbers.count()) { |
| 169 |
m_phoneNumberLabel->setText(numberTemplate.arg(subscriberNumbers[0])); |
| 170 |
} else { |
| 171 |
qWarning() << "subscriberNumbersChanged but still count is zero"; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
void TelephonyWidget::nagButtonToggled(bool checked) |
| 176 |
{ |
| 177 |
m_nagItem->set(checked); |
| 178 |
} |
| 179 |
|
| 180 |
void TelephonyWidget::nagChanged() |
| 181 |
{ |
| 182 |
m_nagButton->setChecked(m_nagItem->value().toBool()); |
| 183 |
} |
| 184 |
|
| 185 |
void TelephonyWidget::unconditionalToggled(bool checked) |
| 186 |
{ |
| 187 |
if (checked) { |
| 188 |
m_forwardingButton->hide(); |
| 189 |
m_layout->removeItem(m_forwardingButton); |
| 190 |
|
| 191 |
} else { |
| 192 |
m_forwardingButton->show(); |
| 193 |
m_layout->insertItem(6, m_forwardingButton); |
| 194 |
} |
| 195 |
} |