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;
40 QPushButton* addButton = new QPushButton(QIcon::fromTheme("general_contacts"), tr("Add to contacts"));
41 QPushButton* copyButton = new QPushButton(tr("Copy number to clipboard"));
43 connect(addButton, SIGNAL(pressed()), this, SLOT(showAddToContactsDialog()));
44 connect(copyButton, SIGNAL(pressed()), this, SLOT(copyToClipboard()));
46 nameButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_default_avatar"),
48 streetButton_ = new QMaemo5ValueButton(tr("Street"), this);
49 cityButton_ = new QMaemo5ValueButton(tr("City"), this);
50 numberButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_call"),
51 tr("Phone number"), this);
53 connect(numberButton_, SIGNAL(pressed()), this, SLOT(makeCall()));
55 top->addWidget(nameButton_);
56 bottom->addWidget(streetButton_);
57 top->addWidget(numberButton_);
58 bottom->addWidget(cityButton_);
59 layout_->addLayout(top);
60 layout_->addLayout(bottom);
61 layout_->addWidget(addButton);
62 layout_->addWidget(copyButton);
63 area_->setLayout(layout_);
64 setCentralWidget(area_);
67 void DetailWindow::loadData(Eniro::Result const& details)
69 setWindowTitle(details.name);
70 nameButton_->setValueText(details.name);
71 streetButton_->setValueText(details.street);
72 cityButton_->setValueText(details.city);
73 numberButton_->setValueText(details.number);
78 void DetailWindow::makeCall()
80 QString number = numberButton_->valueText();
87 QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.csd",
88 "/com/nokia/csd/call",
91 QList<QVariant> arguments;
93 arguments.append(QVariant(number));
94 arguments.append(QVariant(0));
96 msg.setArguments(arguments);
98 QDBusConnection::systemBus().send(msg);
102 void DetailWindow::showAddToContactsDialog()
106 addDialog_ = new QDialog(this);
107 addDialog_->setWindowTitle(tr("Add to contacts"));
108 addContactInput_ = new QLineEdit();
109 QHBoxLayout* layout = new QHBoxLayout();
110 QLabel* name = new QLabel(tr("Name"));
111 QPushButton* button = new QPushButton(tr("Add"));
113 QDialogButtonBox* buttons = new QDialogButtonBox;
114 buttons->setCenterButtons(false);
115 buttons->addButton(button, QDialogButtonBox::AcceptRole);
116 connect(button, SIGNAL(pressed()), this, SLOT(addToContacts()));
118 QHBoxLayout* left = new QHBoxLayout();
119 left->addWidget(name);
120 left->addWidget(addContactInput_);
122 layout->addLayout(left, Qt::AlignLeft);
123 layout->addWidget(buttons);
124 addDialog_->setLayout(layout);
127 addContactInput_->setText(nameButton_->valueText());
131 void DetailWindow::addToContacts()
134 ContactManager::Contact contact;
135 contact.name = addContactInput_->text();
136 contact.number = numberButton_->valueText();
140 if(cm.addContact(contact))
142 QMaemo5InformationBox::information(this, tr("Contact was successfully added to contacts."));
146 QMessageBox::critical(this, tr("Error"), tr("Unable to add contact."));
151 void DetailWindow::copyToClipboard()
153 QApplication::clipboard()->setText(numberButton_->valueText());
154 QMaemo5InformationBox::information(this, tr("Number was successfully copied to clipboard."));