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 <QMaemo5ValueButton>
20 #include <QMaemo5InformationBox>
21 #include <QApplication>
22 #include <QtDBus/QDBusConnection>
23 #include <QtDBus/QDBusMessage>
24 #include <QtGui/QMessageBox>
25 #include <QtGui/QLabel>
26 #include <QtGui/QClipboard>
28 #include "detailwindow.h"
29 #include "contactmanager.h"
31 DetailWindow::DetailWindow(QWidget* parent): QMainWindow(parent), addDialog_(0)
33 setAttribute(Qt::WA_Maemo5StackedWindow);
34 area_ = new QScrollArea(this);
35 layout_ = new QVBoxLayout;
36 QHBoxLayout* top = new QHBoxLayout;
37 QHBoxLayout* bottom = new QHBoxLayout;
39 QPushButton* addButton = new QPushButton(QIcon::fromTheme("general_contacts"), tr("Add to contacts"));
40 QPushButton* copyButton = new QPushButton(tr("Copy number to clipboard"));
42 connect(addButton, SIGNAL(pressed()), this, SLOT(showAddToContactsDialog()));
43 connect(copyButton, SIGNAL(pressed()), this, SLOT(copyToClipboard()));
45 nameButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_default_avatar"),
47 streetButton_ = new QMaemo5ValueButton(tr("Street"), this);
48 cityButton_ = new QMaemo5ValueButton(tr("City"), this);
49 numberButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_call"),
50 tr("Phone number"), this);
52 connect(numberButton_, SIGNAL(pressed()), this, SLOT(makeCall()));
54 top->addWidget(nameButton_);
55 bottom->addWidget(streetButton_);
56 top->addWidget(numberButton_);
57 bottom->addWidget(cityButton_);
58 layout_->addLayout(top);
59 layout_->addLayout(bottom);
60 layout_->addWidget(addButton);
61 layout_->addWidget(copyButton);
62 area_->setLayout(layout_);
63 setCentralWidget(area_);
66 void DetailWindow::loadData(Eniro::Result const& details)
68 setWindowTitle(details.name);
69 nameButton_->setValueText(details.name);
70 streetButton_->setValueText(details.street);
71 cityButton_->setValueText(details.city);
72 numberButton_->setValueText(details.number);
77 void DetailWindow::makeCall()
79 QString number = numberButton_->valueText();
88 QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.csd",
89 "/com/nokia/csd/call",
92 QList<QVariant> arguments;
94 arguments.append(QVariant(number));
95 arguments.append(QVariant(0));
97 msg.setArguments(arguments);
99 QDBusConnection::systemBus().send(msg);
103 void DetailWindow::showAddToContactsDialog()
107 addDialog_ = new QDialog(this);
108 addDialog_->setWindowTitle(tr("Add to contacts"));
109 addContactInput_ = new QLineEdit();
110 QHBoxLayout* layout = new QHBoxLayout();
111 QLabel* name = new QLabel(tr("Name"));
112 QPushButton* button = new QPushButton(tr("Add"));
113 connect(button, SIGNAL(pressed()), this, SLOT(addToContacts()));
114 layout->addWidget(name);
115 layout->addWidget(addContactInput_);
116 layout->addWidget(button);
117 addDialog_->setLayout(layout);
120 addContactInput_->setText(nameButton_->valueText());
124 void DetailWindow::addToContacts()
127 ContactManager::Contact contact;
128 contact.name = addContactInput_->text();
129 contact.number = numberButton_->valueText();
133 if(cm.addContact(contact))
135 QMaemo5InformationBox::information(this, tr("Contact was successfully added to contacts."));
139 QMessageBox::critical(this, tr("Error"), tr("Unable to add contact."));
144 void DetailWindow::copyToClipboard()
146 QApplication::clipboard()->setText(numberButton_->valueText());
147 QMaemo5InformationBox::information(this, tr("Number was successfully copied to clipboard."));