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"), tr("Name"), this);
46 streetButton_ = new QMaemo5ValueButton(tr("Street"), this);
47 cityButton_ = new QMaemo5ValueButton(tr("City"), this);
48 numberButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_call"), tr("Phone number"), this);
50 connect(numberButton_, SIGNAL(pressed()), this, SLOT(makeCall()));
52 top->addWidget(nameButton_);
53 bottom->addWidget(streetButton_);
54 top->addWidget(numberButton_);
55 bottom->addWidget(cityButton_);
56 layout_->addLayout(top);
57 layout_->addLayout(bottom);
58 layout_->addWidget(addButton);
59 layout_->addWidget(copyButton);
60 area_->setLayout(layout_);
61 setCentralWidget(area_);
64 void DetailWindow::loadData(Eniro::Result const& details)
66 setWindowTitle(details.name);
67 nameButton_->setValueText(details.name);
68 streetButton_->setValueText(details.street);
69 cityButton_->setValueText(details.city);
70 numberButton_->setValueText(details.number);
75 void DetailWindow::makeCall()
77 QString number = numberButton_->valueText();
86 QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.csd",
87 "/com/nokia/csd/call",
90 QList<QVariant> arguments;
92 arguments.append(QVariant(number));
93 arguments.append(QVariant(0));
95 msg.setArguments(arguments);
97 QDBusConnection::systemBus().send(msg);
101 void DetailWindow::showAddToContactsDialog()
105 addDialog_ = new QDialog(this);
106 addDialog_->setWindowTitle(tr("Add to contacts"));
107 addContactInput_ = new QLineEdit();
108 QHBoxLayout* layout = new QHBoxLayout();
109 QLabel* name = new QLabel(tr("Name"));
110 QPushButton* button = new QPushButton(tr("Add"));
111 connect(button, SIGNAL(pressed()), this, SLOT(addToContacts()));
112 layout->addWidget(name);
113 layout->addWidget(addContactInput_);
114 layout->addWidget(button);
115 addDialog_->setLayout(layout);
118 addContactInput_->setText(nameButton_->valueText());
122 void DetailWindow::addToContacts()
125 ContactManager::Contact contact;
126 contact.name = addContactInput_->text();
127 contact.number = numberButton_->valueText();
131 if(cm.addContact(contact))
133 QMaemo5InformationBox::information(this, tr("Contact was successfully added to contacts."));
137 QMessageBox::critical(this, tr("Error"), tr("Unable to add contact."));
142 void DetailWindow::copyToClipboard()
144 QApplication::clipboard()->setText(numberButton_->valueText());
145 QMaemo5InformationBox::information(this, tr("Number was successfully copied to clipboard."));