Added about dialog and missing translations. Fixed repainting problen in detail view.
[jenirok] / src / gui / detailwindow.cpp
index 1fdbf7e..23a591f 100644 (file)
  *
  */
 
-#include <QMaemo5ValueButton>
-#include <QMaemo5InformationBox>
-#include <QApplication>
 #include <QtDBus/QDBusConnection>
 #include <QtDBus/QDBusMessage>
 #include <QtGui/QMessageBox>
 #include <QtGui/QLabel>
 #include <QtGui/QClipboard>
+#include <QtGui/QDialogButtonBox>
+#include <QMaemo5ValueButton>
+#include <QMaemo5InformationBox>
+#include <QApplication>
 #include <QDebug>
 #include "detailwindow.h"
 #include "contactmanager.h"
 DetailWindow::DetailWindow(QWidget* parent): QMainWindow(parent), addDialog_(0)
 {
     setAttribute(Qt::WA_Maemo5StackedWindow);
-    area_ = new QScrollArea(this);
+    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);
@@ -55,10 +62,14 @@ DetailWindow::DetailWindow(QWidget* parent): QMainWindow(parent), addDialog_(0)
     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_->addWidget(addButton);
-    layout_->addWidget(copyButton);
+    layout_->addLayout(actions1);
+    layout_->addLayout(actions2);
     area_->setLayout(layout_);
     setCentralWidget(area_);
 }
@@ -70,7 +81,6 @@ void DetailWindow::loadData(Eniro::Result const& details)
     streetButton_->setValueText(details.street);
     cityButton_->setValueText(details.city);
     numberButton_->setValueText(details.number);
-    layout_->update();
     show();
 }
 
@@ -94,7 +104,10 @@ void DetailWindow::makeCall()
 
     msg.setArguments(arguments);
 
-    QDBusConnection::systemBus().send(msg);
+    if(!QDBusConnection::systemBus().send(msg))
+    {
+        QMessageBox::critical(this, tr("Error"), tr("Unable make call"));
+    }
 
 }
 
@@ -108,10 +121,18 @@ void DetailWindow::showAddToContactsDialog()
         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()));
-        layout->addWidget(name);
-        layout->addWidget(addContactInput_);
-        layout->addWidget(button);
+
+        QHBoxLayout* left = new QHBoxLayout();
+        left->addWidget(name);
+        left->addWidget(addContactInput_);
+
+        layout->addLayout(left, Qt::AlignLeft);
+        layout->addWidget(buttons);
         addDialog_->setLayout(layout);
     }
 
@@ -144,3 +165,29 @@ void DetailWindow::copyToClipboard()
     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<QVariant> 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"));
+    }
+
+}