X-Git-Url: http://git.maemo.org/git/?p=jenirok;a=blobdiff_plain;f=src%2Fgui%2Fdetailwindow.cpp;h=23a591f5afc048fc9a2cfa86b9f291d3b49334a9;hp=09b43805afc5928bf182d058f26b22d3c63a6a4c;hb=0b5c39a64431b662e3942a0b7cbeb1d59e57ddc1;hpb=89496ceee9788c2908c27ad4e2535f2728310d76 diff --git a/src/gui/detailwindow.cpp b/src/gui/detailwindow.cpp index 09b4380..23a591f 100644 --- a/src/gui/detailwindow.cpp +++ b/src/gui/detailwindow.cpp @@ -16,131 +16,178 @@ * */ -#include -#include -#include #include #include #include #include #include +#include +#include +#include +#include #include #include "detailwindow.h" #include "contactmanager.h" DetailWindow::DetailWindow(QWidget* parent): QMainWindow(parent), addDialog_(0) { - setAttribute(Qt::WA_Maemo5StackedWindow); - area_ = new QScrollArea(this); - layout_ = new QVBoxLayout; - QHBoxLayout* top = new QHBoxLayout; - QHBoxLayout* bottom = new QHBoxLayout; - - QPushButton* addButton = new QPushButton(QIcon::fromTheme("general_contacts"), tr("Add to contacts")); - QPushButton* copyButton = new QPushButton(tr("Copy number to clipboard")); - - connect(addButton, SIGNAL(pressed()), this, SLOT(showAddToContactsDialog())); - connect(copyButton, SIGNAL(pressed()), this, SLOT(copyToClipboard())); - - nameButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_default_avatar"), tr("Name"), this); - streetButton_ = new QMaemo5ValueButton(tr("Street"), this); - cityButton_ = new QMaemo5ValueButton(tr("City"), this); - numberButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_call"), tr("Phone number"), this); - - connect(numberButton_, SIGNAL(pressed()), this, SLOT(makeCall())); - - top->addWidget(nameButton_); - bottom->addWidget(streetButton_); - top->addWidget(numberButton_); - bottom->addWidget(cityButton_); - layout_->addLayout(top); - layout_->addLayout(bottom); - layout_->addWidget(addButton); - layout_->addWidget(copyButton); - area_->setLayout(layout_); - setCentralWidget(area_); + setAttribute(Qt::WA_Maemo5StackedWindow); + area_ = new QWidget(this); + layout_ = new QVBoxLayout; + QHBoxLayout* top = new QHBoxLayout; + QHBoxLayout* bottom = new QHBoxLayout; + QHBoxLayout* actions1 = new QHBoxLayout; + QHBoxLayout* actions2 = new QHBoxLayout; + + QPushButton* addButton = new QPushButton(QIcon::fromTheme("general_contacts"), tr("Add to contacts")); + QPushButton* copyButton = new QPushButton(tr("Copy number to clipboard")); + QPushButton* callButton = new QPushButton(QIcon::fromTheme("general_call"), tr("Call")); + QPushButton* smsButton = new QPushButton(QIcon::fromTheme("general_sms"), tr("Send SMS")); + + connect(addButton, SIGNAL(pressed()), this, SLOT(showAddToContactsDialog())); + connect(copyButton, SIGNAL(pressed()), this, SLOT(copyToClipboard())); + connect(callButton, SIGNAL(pressed()), this, SLOT(makeCall())); + connect(smsButton, SIGNAL(pressed()), this, SLOT(sendSMS())); + + nameButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_default_avatar"), + tr("Name"), this); + streetButton_ = new QMaemo5ValueButton(tr("Street"), this); + cityButton_ = new QMaemo5ValueButton(tr("City"), this); + numberButton_ = new QMaemo5ValueButton(QIcon::fromTheme("general_call"), + tr("Phone number"), this); + + connect(numberButton_, SIGNAL(pressed()), this, SLOT(makeCall())); + + top->addWidget(nameButton_); + bottom->addWidget(streetButton_); + top->addWidget(numberButton_); + bottom->addWidget(cityButton_); + actions1->addWidget(callButton); + actions1->addWidget(smsButton); + actions2->addWidget(addButton); + actions2->addWidget(copyButton); + layout_->addLayout(top); + layout_->addLayout(bottom); + layout_->addLayout(actions1); + layout_->addLayout(actions2); + area_->setLayout(layout_); + setCentralWidget(area_); } void DetailWindow::loadData(Eniro::Result const& details) { - setWindowTitle(details.name); - nameButton_->setValueText(details.name); - streetButton_->setValueText(details.street); - cityButton_->setValueText(details.city); - numberButton_->setValueText(details.number); - layout_->update(); - show(); + setWindowTitle(details.name); + nameButton_->setValueText(details.name); + streetButton_->setValueText(details.street); + cityButton_->setValueText(details.city); + numberButton_->setValueText(details.number); + show(); } void DetailWindow::makeCall() { - QString number = numberButton_->valueText(); + QString number = numberButton_->valueText(); - qDebug() << number; + if(number.isEmpty()) + { + return; + } - if(number.isEmpty()) - { - return; - } + QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.csd", + "/com/nokia/csd/call", + "com.nokia.csd.Call", + "CreateWith"); + QList arguments; - QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.csd", - "/com/nokia/csd/call", - "com.nokia.csd.Call", - "CreateWith"); - QList arguments; + arguments.append(QVariant(number)); + arguments.append(QVariant(0)); - arguments.append(QVariant(number)); - arguments.append(QVariant(0)); + msg.setArguments(arguments); - msg.setArguments(arguments); - - QDBusConnection::systemBus().send(msg); + if(!QDBusConnection::systemBus().send(msg)) + { + QMessageBox::critical(this, tr("Error"), tr("Unable make call")); + } } void DetailWindow::showAddToContactsDialog() { - if(!addDialog_) - { - addDialog_ = new QDialog(this); - addDialog_->setWindowTitle(tr("Add to contacts")); - addContactInput_ = new QLineEdit(); - QHBoxLayout* layout = new QHBoxLayout(); - QLabel* name = new QLabel(tr("Name")); - QPushButton* button = new QPushButton(tr("Add")); - connect(button, SIGNAL(pressed()), this, SLOT(addToContacts())); - layout->addWidget(name); - layout->addWidget(addContactInput_); - layout->addWidget(button); - addDialog_->setLayout(layout); - } - - addContactInput_->setText(nameButton_->valueText()); - addDialog_->show(); + if(!addDialog_) + { + addDialog_ = new QDialog(this); + addDialog_->setWindowTitle(tr("Add to contacts")); + addContactInput_ = new QLineEdit(); + QHBoxLayout* layout = new QHBoxLayout(); + QLabel* name = new QLabel(tr("Name")); + QPushButton* button = new QPushButton(tr("Add")); + + QDialogButtonBox* buttons = new QDialogButtonBox; + buttons->setCenterButtons(false); + buttons->addButton(button, QDialogButtonBox::AcceptRole); + connect(button, SIGNAL(pressed()), this, SLOT(addToContacts())); + + QHBoxLayout* left = new QHBoxLayout(); + left->addWidget(name); + left->addWidget(addContactInput_); + + layout->addLayout(left, Qt::AlignLeft); + layout->addWidget(buttons); + addDialog_->setLayout(layout); + } + + addContactInput_->setText(nameButton_->valueText()); + addDialog_->show(); } void DetailWindow::addToContacts() { - ContactManager cm; - ContactManager::Contact contact; - contact.name = addContactInput_->text(); - contact.number = numberButton_->valueText(); - - addDialog_->hide(); - - if(cm.addContact(contact)) - { - QMaemo5InformationBox::information(this, tr("Contact was successfully added to contacts.")); - } - else - { - QMessageBox::critical(this, tr("Error"), tr("Unable to add contact.")); - } + ContactManager cm; + ContactManager::Contact contact; + contact.name = addContactInput_->text(); + contact.number = numberButton_->valueText(); + + addDialog_->hide(); + + if(cm.addContact(contact)) + { + QMaemo5InformationBox::information(this, tr("Contact was successfully added to contacts.")); + } + else + { + QMessageBox::critical(this, tr("Error"), tr("Unable to add contact.")); + } } void DetailWindow::copyToClipboard() { - QApplication::clipboard()->setText(numberButton_->valueText()); - QMaemo5InformationBox::information(this, tr("Number was successfully copied to clipboard.")); + QApplication::clipboard()->setText(numberButton_->valueText()); + QMaemo5InformationBox::information(this, tr("Number was successfully copied to clipboard.")); +} + +void DetailWindow::sendSMS() +{ + QString number = numberButton_->valueText(); + + if(number.isEmpty()) + { + return; + } + + QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.MessagingUI", + "/com/nokia/MessagingUI", + "com.nokia.MessagingUI", + "messaging_ui_interface_start_sms"); + QList arguments; + + arguments.append(QVariant("sms:" + number)); + + msg.setArguments(arguments); + + if(!QDBusConnection::systemBus().send(msg)) + { + QMessageBox::critical(this, tr("Error"), tr("Unable to open SMS application")); + } + }