2 * This file is part of Jenirok.
4 * Jenirok is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Jenirok is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Jenirok. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtDBus/QDBusConnection>
20 #include <QtDBus/QDBusMessage>
21 #include <QtGui/QMessageBox>
22 #include <QtGui/QLabel>
23 #include <QtGui/QClipboard>
24 #include <QtGui/QDialogButtonBox>
25 #include <QMaemo5ValueButton>
26 #include <QMaemo5InformationBox>
27 #include <QApplication>
29 #include "detailwindow.h"
30 #include "contactmanager.h"
32 DetailWindow::DetailWindow(QWidget* parent): QMainWindow(parent), addDialog_(0)
34 setAttribute(Qt::WA_Maemo5StackedWindow);
35 area_ = new QScrollArea(this);
36 layout_ = new QVBoxLayout;
37 QHBoxLayout* top = new QHBoxLayout;
38 QHBoxLayout* bottom = new QHBoxLayout;
39 QHBoxLayout* actions1 = new QHBoxLayout;
40 QHBoxLayout* actions2 = new QHBoxLayout;
42 QPushButton* addButton = new QPushButton(QIcon::fromTheme("general_contacts"), tr("Add to contacts"));
43 QPushButton* copyButton = new QPushButton(tr("Copy number to clipboard"));
44 QPushButton* callButton = new QPushButton(QIcon::fromTheme("general_call"), tr("Call"));
45 QPushButton* smsButton = new QPushButton(QIcon::fromTheme("general_sms"), tr("Send SMS"));
47 connect(addButton, SIGNAL(pressed()), this, SLOT(showAddToContactsDialog()));
48 connect(copyButton, SIGNAL(pressed()), this, SLOT(copyToClipboard()));
49 connect(callButton, SIGNAL(pressed()), this, SLOT(makeCall()));
50 connect(smsButton, SIGNAL(pressed()), this, SLOT(sendSMS()));
52 nameButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_default_avatar"),
54 streetButton_ = new QMaemo5ValueButton(tr("Street"), this);
55 cityButton_ = new QMaemo5ValueButton(tr("City"), this);
56 numberButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_call"),
57 tr("Phone number"), this);
59 connect(numberButton_, SIGNAL(pressed()), this, SLOT(makeCall()));
61 top->addWidget(nameButton_);
62 bottom->addWidget(streetButton_);
63 top->addWidget(numberButton_);
64 bottom->addWidget(cityButton_);
65 actions1->addWidget(callButton);
66 actions1->addWidget(smsButton);
67 actions2->addWidget(addButton);
68 actions2->addWidget(copyButton);
69 layout_->addLayout(top);
70 layout_->addLayout(bottom);
71 layout_->addLayout(actions1);
72 layout_->addLayout(actions2);
73 area_->setLayout(layout_);
74 setCentralWidget(area_);
77 void DetailWindow::loadData(Eniro::Result const& details)
79 setWindowTitle(details.name);
80 nameButton_->setValueText(details.name);
81 streetButton_->setValueText(details.street);
82 cityButton_->setValueText(details.city);
83 numberButton_->setValueText(details.number);
88 void DetailWindow::makeCall()
90 QString number = numberButton_->valueText();
97 QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.csd",
98 "/com/nokia/csd/call",
101 QList<QVariant> arguments;
103 arguments.append(QVariant(number));
104 arguments.append(QVariant(0));
106 msg.setArguments(arguments);
108 if(!QDBusConnection::systemBus().send(msg))
110 QMessageBox::critical(this, tr("Error"), tr("Unable make call"));
115 void DetailWindow::showAddToContactsDialog()
119 addDialog_ = new QDialog(this);
120 addDialog_->setWindowTitle(tr("Add to contacts"));
121 addContactInput_ = new QLineEdit();
122 QHBoxLayout* layout = new QHBoxLayout();
123 QLabel* name = new QLabel(tr("Name"));
124 QPushButton* button = new QPushButton(tr("Add"));
126 QDialogButtonBox* buttons = new QDialogButtonBox;
127 buttons->setCenterButtons(false);
128 buttons->addButton(button, QDialogButtonBox::AcceptRole);
129 connect(button, SIGNAL(pressed()), this, SLOT(addToContacts()));
131 QHBoxLayout* left = new QHBoxLayout();
132 left->addWidget(name);
133 left->addWidget(addContactInput_);
135 layout->addLayout(left, Qt::AlignLeft);
136 layout->addWidget(buttons);
137 addDialog_->setLayout(layout);
140 addContactInput_->setText(nameButton_->valueText());
144 void DetailWindow::addToContacts()
147 ContactManager::Contact contact;
148 contact.name = addContactInput_->text();
149 contact.number = numberButton_->valueText();
153 if(cm.addContact(contact))
155 QMaemo5InformationBox::information(this, tr("Contact was successfully added to contacts."));
159 QMessageBox::critical(this, tr("Error"), tr("Unable to add contact."));
164 void DetailWindow::copyToClipboard()
166 QApplication::clipboard()->setText(numberButton_->valueText());
167 QMaemo5InformationBox::information(this, tr("Number was successfully copied to clipboard."));
170 void DetailWindow::sendSMS()
172 QString number = numberButton_->valueText();
179 QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.MessagingUI",
180 "/com/nokia/MessagingUI",
181 "com.nokia.MessagingUI",
182 "messaging_ui_interface_start_sms");
183 QList<QVariant> arguments;
185 arguments.append(QVariant("sms:" + number));
187 msg.setArguments(arguments);
189 if(!QDBusConnection::systemBus().send(msg))
191 QMessageBox::critical(this, tr("Error"), tr("Unable to open SMS application"));