Akonadi Contacts

contactdefaultactions.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "contactdefaultactions.h"
10 
11 #include "actions/dialphonenumberaction.h"
12 #include "actions/sendsmsaction.h"
13 #include "actions/showaddressaction.h"
14 
15 #include <QDesktopServices>
16 #include <QUrl>
17 #include <kcontacts/address.h>
18 #include <kcontacts/addressee.h>
19 #include <kcontacts/phonenumber.h>
20 
21 using namespace Akonadi;
22 
24  : QObject(parent)
25  , d(nullptr)
26 {
27 }
28 
30 {
31 }
32 
34 {
35  const QMetaObject *metaObject = view->metaObject();
36 
37  if (metaObject->indexOfSignal(QMetaObject::normalizedSignature("urlClicked(const QUrl&)").constData()) != -1) {
38  connect(view, SIGNAL(urlClicked(QUrl)), SLOT(showUrl(QUrl)));
39  }
40 
41  if (metaObject->indexOfSignal(QMetaObject::normalizedSignature("emailClicked(const QString&, const QString&)").constData()) != -1) {
42  connect(view, SIGNAL(emailClicked(QString, QString)), this, SLOT(sendEmail(QString, QString)));
43  }
44 
45  if (metaObject->indexOfSignal(QMetaObject::normalizedSignature("phoneNumberClicked(const KContacts::PhoneNumber&)").constData()) != -1) {
46  connect(view, SIGNAL(phoneNumberClicked(KContacts::PhoneNumber)), this, SLOT(dialPhoneNumber(KContacts::PhoneNumber)));
47  }
48 
49  if (metaObject->indexOfSignal(QMetaObject::normalizedSignature("smsClicked(const KContacts::PhoneNumber&)").constData()) != -1) {
50  connect(view, SIGNAL(smsClicked(KContacts::PhoneNumber)), this, SLOT(sendSms(KContacts::PhoneNumber)));
51  }
52 
53  if (metaObject->indexOfSignal(QMetaObject::normalizedSignature("addressClicked(const KContacts::Address&)").constData()) != -1) {
54  connect(view, SIGNAL(addressClicked(KContacts::Address)), this, SLOT(showAddress(KContacts::Address)));
55  }
56 }
57 
59 {
61 }
62 
63 void ContactDefaultActions::sendEmail(const QString &name, const QString &address)
64 {
65  KContacts::Addressee contact;
66  contact.setNameFromString(name);
67 
68  QUrl url;
69  url.setScheme(QStringLiteral("mailto"));
70  url.setPath(contact.fullEmail(address));
72 }
73 
75 {
76  DialPhoneNumberAction action;
77  action.dialNumber(number);
78 }
79 
81 {
82  SendSmsAction action;
83  action.sendSms(number);
84 }
85 
87 {
88  ShowAddressAction action;
89  action.showAddress(address);
90 }
int indexOfSignal(const char *signal) const const
~ContactDefaultActions() override
Destroys the contact default actions object.
An action to dial the phone number of a contact.
QByteArray normalizedSignature(const char *method)
virtual const QMetaObject * metaObject() const const
void showAddress(const KContacts::Address &address)
Shows the address of a contact in a webbrowser or application as configured by the user in the genera...
void connectToView(QObject *view)
Tries to connect the well known signals of the view to the well known slots of this object...
void setPath(const QString &path, QUrl::ParsingMode mode)
QString fullEmail(const QString &email=QString()) const
void setNameFromString(const QString &s)
const char * constData() const const
void setScheme(const QString &scheme)
void sendSms(const KContacts::PhoneNumber &number)
Sends a sms to number with the application as configured by the user in the general settings dialog...
A contact action to show the address of a contact on a map.
void showUrl(const QUrl &url)
Shows the given url in the users preferred webbrowser.
ContactDefaultActions(QObject *parent=nullptr)
Creates a new contact default actions object.
bool openUrl(const QUrl &url)
void sendEmail(const QString &name, const QString &address)
Opens the users preferred mail composer and does the setup to send a mail to the contact with the giv...
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void dialPhoneNumber(const KContacts::PhoneNumber &number)
Dials the given phone number with the application as configured by the user in the general settings d...
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.