Commit d460eff8 authored by Guy Maurel's avatar Guy Maurel

Coding style

REVIEWS: 114787 114788 114789 114790 114791 114792 114793 114794 114795 114796 114797 114798 114799 114800 114801 114802
 114824 114825 114826 114827 114828 114829 114830 114831 114832 114833 114834 114835 114836 114837 114838 114839
parent e37b0f91
......@@ -34,57 +34,55 @@
using namespace Akonadi;
static QString strippedDialNumber( const QString &number )
static QString strippedDialNumber(const QString &number)
{
QString result;
QString result;
for ( int i = 0; i < number.length(); ++i ) {
const QChar character = number.at( i );
if ( character.isDigit() || ( character == QLatin1Char( '+' ) && i == 0 ) ) {
result += character;
for (int i = 0; i < number.length(); ++i) {
const QChar character = number.at(i);
if (character.isDigit() || (character == QLatin1Char('+') && i == 0)) {
result += character;
}
}
}
return result;
return result;
}
void DialPhoneNumberAction::dialNumber( const KABC::PhoneNumber &number )
void DialPhoneNumberAction::dialNumber(const KABC::PhoneNumber &number)
{
// synchronize
ContactActionsSettings::self()->readConfig();
QDialer *dialer = NULL;
// we handle skype separated
if ( ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSkype ) {
dialer = new QSkypeDialer( QLatin1String( "AkonadiContacts" ) );
}
else if ( ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSflPhone) {
dialer = new QSflPhoneDialer( QLatin1String( "AkonadiContacts" ) );
}
else if ( ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseEkiga) {
dialer = new QEkigaDialer( QLatin1String( "AkonadiContacts" ) );
}
if ( dialer ) {
if ( !dialer->dialNumber( strippedDialNumber( number.number().trimmed() ) ) ) {
KMessageBox::sorry( 0, dialer->errorMessage() );
// synchronize
ContactActionsSettings::self()->readConfig();
QDialer *dialer = NULL;
// we handle skype separated
if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSkype) {
dialer = new QSkypeDialer(QLatin1String("AkonadiContacts"));
} else if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSflPhone) {
dialer = new QSflPhoneDialer(QLatin1String("AkonadiContacts"));
} else if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseEkiga) {
dialer = new QEkigaDialer(QLatin1String("AkonadiContacts"));
}
if (dialer) {
if (!dialer->dialNumber(strippedDialNumber(number.number().trimmed()))) {
KMessageBox::sorry(0, dialer->errorMessage());
}
delete dialer;
return;
}
delete dialer;
return;
}
QString command = ContactActionsSettings::self()->phoneCommand();
QString command = ContactActionsSettings::self()->phoneCommand();
if ( command.isEmpty() ) {
KMessageBox::sorry( 0, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
return;
}
if (command.isEmpty()) {
KMessageBox::sorry(0, i18n("There is no application set which could be executed. Please go to the settings dialog and configure one."));
return;
}
/*
* %N the raw number
* %n the number with all additional non-number characters removed
*/
command = command.replace( QLatin1String( "%N" ), number.number() );
command = command.replace( QLatin1String( "%n" ), strippedDialNumber( number.number().trimmed() ) );
/*
* %N the raw number
* %n the number with all additional non-number characters removed
*/
command = command.replace(QLatin1String("%N"), number.number());
command = command.replace(QLatin1String("%n"), strippedDialNumber(number.number().trimmed()));
KRun::runCommand( command, 0 );
KRun::runCommand(command, 0);
}
......@@ -35,8 +35,8 @@ namespace Akonadi {
*/
class DialPhoneNumberAction
{
public:
void dialNumber( const KABC::PhoneNumber &number );
public:
void dialNumber(const KABC::PhoneNumber &number);
};
}
......
......@@ -24,8 +24,8 @@
#include <klocalizedstring.h>
QDialer::QDialer( const QString &applicationName)
: mApplicationName( applicationName )
QDialer::QDialer(const QString &applicationName)
: mApplicationName(applicationName)
{
}
......@@ -33,21 +33,22 @@ QDialer::~QDialer()
{
}
bool QDialer::dialNumber( const QString &number )
bool QDialer::dialNumber(const QString &number)
{
mErrorMessage = i18n( "Dialing a number is not supported" );
Q_UNUSED(number);
mErrorMessage = i18n("Dialing a number is not supported");
return false;
return false;
}
bool QDialer::sendSms( const QString &number, const QString &text )
bool QDialer::sendSms(const QString &number, const QString &text)
{
mErrorMessage = i18n( "Sending an SMS is not supported" );
mErrorMessage = i18n("Sending an SMS is not supported");
return false;
return false;
}
QString QDialer::errorMessage() const
{
return mErrorMessage;
return mErrorMessage;
}
......@@ -27,16 +27,16 @@
class QDialer
{
public:
explicit QDialer( const QString &applicationName );
public:
explicit QDialer(const QString &applicationName);
virtual ~QDialer();
virtual bool dialNumber( const QString &number );
virtual bool sendSms( const QString &number, const QString &text );
virtual bool dialNumber(const QString &number);
virtual bool sendSms(const QString &number, const QString &text);
QString errorMessage() const;
protected:
protected:
QString mApplicationName;
QString mErrorMessage;
};
......
......@@ -36,36 +36,36 @@
static bool isEkigaServiceRegistered()
{
const QLatin1String service( "org.ekiga.Ekiga" );
const QLatin1String service("org.ekiga.Ekiga");
QDBusConnectionInterface *interface = QDBusConnection::systemBus().interface();
if ( interface->isServiceRegistered( service ) ) {
if (interface->isServiceRegistered(service)) {
return true;
}
interface = Akonadi::DBusConnectionPool::threadConnection().interface();
if ( interface->isServiceRegistered( service ) ) {
if (interface->isServiceRegistered(service)) {
return true;
}
return false;
}
static QDBusInterface* searchEkigaDBusInterface()
static QDBusInterface *searchEkigaDBusInterface()
{
const QLatin1String service( "org.ekiga.Ekiga" );
const QLatin1String path( "/org/ekiga/Ekiga" );
const QLatin1String service("org.ekiga.Ekiga");
const QLatin1String path("/org/ekiga/Ekiga");
QDBusInterface *interface = new QDBusInterface( service, path, QString(), QDBusConnection::systemBus() );
if ( !interface->isValid() ) {
delete interface;
interface = new QDBusInterface( service, path, QString(), Akonadi::DBusConnectionPool::threadConnection() );
}
QDBusInterface *interface = new QDBusInterface(service, path, QString(), QDBusConnection::systemBus());
if (!interface->isValid()) {
delete interface;
interface = new QDBusInterface(service, path, QString(), Akonadi::DBusConnectionPool::threadConnection());
}
return interface;
return interface;
}
QEkigaDialer::QEkigaDialer( const QString &applicationName )
: QDialer( applicationName ), mInterface( 0 )
QEkigaDialer::QEkigaDialer(const QString &applicationName)
: QDialer(applicationName), mInterface(0)
{
}
......@@ -77,18 +77,18 @@ QEkigaDialer::~QEkigaDialer()
bool QEkigaDialer::initializeEkiga()
{
// first check whether dbus interface is available yet
if ( !isEkigaServiceRegistered() ) {
if (!isEkigaServiceRegistered()) {
// it could be skype is not running yet, so start it now
if ( !QProcess::startDetached( QLatin1String( "ekiga" ), QStringList() ) ) {
mErrorMessage = i18n( "Unable to start ekiga process, check that ekiga executable is in your PATH variable." );
if (!QProcess::startDetached(QLatin1String("ekiga"), QStringList())) {
mErrorMessage = i18n("Unable to start ekiga process, check that ekiga executable is in your PATH variable.");
return false;
}
const int runs = 100;
for ( int i = 0; i < runs; ++i ) {
if ( !isEkigaServiceRegistered() ) {
::sleep( 2 );
for (int i = 0; i < runs; ++i) {
if (!isEkigaServiceRegistered()) {
::sleep(2);
} else {
break;
}
......@@ -98,12 +98,12 @@ bool QEkigaDialer::initializeEkiga()
// check again for the dbus interface
mInterface = searchEkigaDBusInterface();
if ( !mInterface->isValid() ) {
delete mInterface;
mInterface = 0;
if (!mInterface->isValid()) {
delete mInterface;
mInterface = 0;
mErrorMessage = i18n( "Ekiga Public API (D-Bus) seems to be disabled." );
return false;
mErrorMessage = i18n("Ekiga Public API (D-Bus) seems to be disabled.");
return false;
}
return true;
......@@ -111,15 +111,17 @@ bool QEkigaDialer::initializeEkiga()
bool QEkigaDialer::dialNumber(const QString &number)
{
if ( !initializeEkiga() ) {
if (!initializeEkiga()) {
return false;
}
QDBusReply<void> reply = mInterface->call( QLatin1String( "Call" ), number );
QDBusReply<void> reply = mInterface->call(QLatin1String("Call"), number);
return true;
}
bool QEkigaDialer::sendSms(const QString &, const QString &)
bool QEkigaDialer::sendSms(const QString &number, const QString &text)
{
mErrorMessage = i18n( "Sending an SMS is currently not supported on Ekiga" );
Q_UNUSED(number);
Q_UNUSED(text);
mErrorMessage = i18n("Sending an SMS is currently not supported on Ekiga");
return false;
}
......@@ -27,11 +27,11 @@ class QDBusInterface;
class QEkigaDialer : public QDialer
{
public:
explicit QEkigaDialer( const QString &applicationName );
explicit QEkigaDialer(const QString &applicationName);
~QEkigaDialer();
bool dialNumber( const QString &number );
bool sendSms( const QString &number, const QString &text );
bool dialNumber(const QString &number);
bool sendSms(const QString &number, const QString &text);
private:
bool initializeEkiga();
QDBusInterface *mInterface;
......
......@@ -35,22 +35,22 @@
static bool isSflPhoneServiceRegistered()
{
const QLatin1String service( "org.sflphone.SFLphone" );
const QLatin1String service("org.sflphone.SFLphone");
QDBusConnectionInterface *interface = QDBusConnection::systemBus().interface();
if ( interface->isServiceRegistered( service ) ) {
if (interface->isServiceRegistered(service)) {
return true;
}
interface = Akonadi::DBusConnectionPool::threadConnection().interface();
if ( interface->isServiceRegistered( service ) ) {
if (interface->isServiceRegistered(service)) {
return true;
}
return false;
}
QSflPhoneDialer::QSflPhoneDialer( const QString &applicationName )
: QDialer( applicationName )
QSflPhoneDialer::QSflPhoneDialer(const QString &applicationName)
: QDialer(applicationName)
{
}
......@@ -61,18 +61,18 @@ QSflPhoneDialer::~QSflPhoneDialer()
bool QSflPhoneDialer::initializeSflPhone()
{
// first check whether dbus interface is available yet
if ( !isSflPhoneServiceRegistered() ) {
if (!isSflPhoneServiceRegistered()) {
// it could be skype is not running yet, so start it now
if ( !QProcess::startDetached( QLatin1String( "sflphone-client-kde" ), QStringList() ) ) {
mErrorMessage = i18n( "Unable to start sflphone-client-kde process, check that sflphone-client-kde executable is in your PATH variable." );
if (!QProcess::startDetached(QLatin1String("sflphone-client-kde"), QStringList())) {
mErrorMessage = i18n("Unable to start sflphone-client-kde process, check that sflphone-client-kde executable is in your PATH variable.");
return false;
}
const int runs = 100;
for ( int i = 0; i < runs; ++i ) {
if ( !isSflPhoneServiceRegistered() ) {
::sleep( 2 );
for (int i = 0; i < runs; ++i) {
if (!isSflPhoneServiceRegistered()) {
::sleep(2);
} else {
return true;
}
......@@ -83,14 +83,14 @@ bool QSflPhoneDialer::initializeSflPhone()
bool QSflPhoneDialer::dialNumber(const QString &number)
{
if ( !initializeSflPhone() ) {
if (!initializeSflPhone()) {
return false;
}
QStringList arguments;
arguments << QLatin1String("--place-call");
arguments << number;
if (!QProcess::startDetached( QLatin1String( "sflphone-client-kde" ), arguments)) {
if (!QProcess::startDetached(QLatin1String("sflphone-client-kde"), arguments)) {
return false;
}
......@@ -99,7 +99,7 @@ bool QSflPhoneDialer::dialNumber(const QString &number)
bool QSflPhoneDialer::sendSms(const QString &number, const QString &text)
{
if ( !initializeSflPhone() ) {
if (!initializeSflPhone()) {
return false;
}
......@@ -108,7 +108,7 @@ bool QSflPhoneDialer::sendSms(const QString &number, const QString &text)
arguments << number;
arguments << QLatin1String("--message");
arguments << text;
if (!QProcess::startDetached( QLatin1String( "sflphone-client-kde" ), arguments)) {
if (!QProcess::startDetached(QLatin1String("sflphone-client-kde"), arguments)) {
return false;
}
return true;
......
......@@ -26,14 +26,14 @@
class QSflPhoneDialer : public QDialer
{
public:
explicit QSflPhoneDialer( const QString &applicationName );
explicit QSflPhoneDialer(const QString &applicationName);
~QSflPhoneDialer();
bool dialNumber( const QString &number );
bool sendSms( const QString &number, const QString &text );
bool dialNumber(const QString &number);
bool sendSms(const QString &number, const QString &text);
private:
bool initializeSflPhone();
bool initializeSflPhone();
};
#endif // QSFLPHONEDIALER_H
......@@ -34,134 +34,134 @@
static bool isSkypeServiceRegistered()
{
const QLatin1String service( "com.Skype.API" );
const QLatin1String service("com.Skype.API");
QDBusConnectionInterface *interface = QDBusConnection::systemBus().interface();
if ( interface->isServiceRegistered( service ) ) {
return true;
}
QDBusConnectionInterface *interface = QDBusConnection::systemBus().interface();
if (interface->isServiceRegistered(service)) {
return true;
}
interface = Akonadi::DBusConnectionPool::threadConnection().interface();
if ( interface->isServiceRegistered( service ) ) {
return true;
}
interface = Akonadi::DBusConnectionPool::threadConnection().interface();
if (interface->isServiceRegistered(service)) {
return true;
}
return false;
return false;
}
static QDBusInterface* searchSkypeDBusInterface()
static QDBusInterface *searchSkypeDBusInterface()
{
const QLatin1String service( "com.Skype.API" );
const QLatin1String path( "/com/Skype" );
const QLatin1String service("com.Skype.API");
const QLatin1String path("/com/Skype");
QDBusInterface *interface = new QDBusInterface( service, path, QString(), QDBusConnection::systemBus() );
if ( !interface->isValid() ) {
delete interface;
interface = new QDBusInterface( service, path, QString(), Akonadi::DBusConnectionPool::threadConnection() );
}
QDBusInterface *interface = new QDBusInterface(service, path, QString(), QDBusConnection::systemBus());
if (!interface->isValid()) {
delete interface;
interface = new QDBusInterface(service, path, QString(), Akonadi::DBusConnectionPool::threadConnection());
}
return interface;
return interface;
}
QSkypeDialer::QSkypeDialer( const QString &applicationName )
: QDialer( applicationName ), mInterface( 0 )
QSkypeDialer::QSkypeDialer(const QString &applicationName)
: QDialer(applicationName), mInterface(0)
{
}
QSkypeDialer::~QSkypeDialer()
{
delete mInterface;
delete mInterface;
}
bool QSkypeDialer::initializeSkype()
{
if ( mInterface && mInterface->isValid() ) {
return true;
}
// first check whether dbus interface is available yet
if ( !isSkypeServiceRegistered() ) {
// it could be skype is not running yet, so start it now
if ( !QProcess::startDetached( QLatin1String( "skype" ), QStringList() ) ) {
mErrorMessage = i18n( "Unable to start skype process, check that skype executable is in your PATH variable." );
return false;
if (mInterface && mInterface->isValid()) {
return true;
}
const int runs = 100;
for ( int i = 0; i < runs; ++i ) {
if ( !isSkypeServiceRegistered() ) {
::sleep( 2 );
} else {
break;
}
// first check whether dbus interface is available yet
if (!isSkypeServiceRegistered()) {
// it could be skype is not running yet, so start it now
if (!QProcess::startDetached(QLatin1String("skype"), QStringList())) {
mErrorMessage = i18n("Unable to start skype process, check that skype executable is in your PATH variable.");
return false;
}
const int runs = 100;
for (int i = 0; i < runs; ++i) {
if (!isSkypeServiceRegistered()) {
::sleep(2);
} else {
break;
}
}
}
}
// check again for the dbus interface
mInterface = searchSkypeDBusInterface();
// check again for the dbus interface
mInterface = searchSkypeDBusInterface();
if ( !mInterface->isValid() ) {
delete mInterface;
mInterface = 0;
if (!mInterface->isValid()) {
delete mInterface;
mInterface = 0;
mErrorMessage = i18n( "Skype Public API (D-Bus) seems to be disabled." );
return false;
}
mErrorMessage = i18n("Skype Public API (D-Bus) seems to be disabled.");
return false;
}
QDBusReply<QString> reply = mInterface->call( QLatin1String( "Invoke" ), QString::fromLatin1( "NAME %1" ).arg( mApplicationName ) );
if ( reply.value() != QLatin1String( "OK" ) ) {
delete mInterface;
mInterface = 0;
QDBusReply<QString> reply = mInterface->call(QLatin1String("Invoke"), QString::fromLatin1("NAME %1").arg(mApplicationName));
if (reply.value() != QLatin1String("OK")) {
delete mInterface;
mInterface = 0;
mErrorMessage = i18n( "Skype registration failed." );
return false;
}
mErrorMessage = i18n("Skype registration failed.");
return false;
}
reply = mInterface->call( QLatin1String( "Invoke" ), QLatin1String( "PROTOCOL 1" ) );
if ( reply.value() != QLatin1String( "PROTOCOL 1" ) ) {
delete mInterface;
mInterface = 0;
reply = mInterface->call(QLatin1String("Invoke"), QLatin1String("PROTOCOL 1"));
if (reply.value() != QLatin1String("PROTOCOL 1")) {
delete mInterface;
mInterface = 0;
mErrorMessage = i18n( "Protocol mismatch." );
return false;
}
mErrorMessage = i18n("Protocol mismatch.");
return false;
}
return true;
return true;
}