From ae256ae4cf8bf1382351974533aafdd0b6713df3 Mon Sep 17 00:00:00 2001
From: Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>
Date: Fri, 27 Feb 2015 16:47:07 -0500
Subject: [PATCH] Add operator<< for pointer types

Refs #66615
---
 src/account.cpp         |  5 +++++
 src/account.h           | 14 +++++++++++++-
 src/call.cpp            |  6 ++++++
 src/call.h              |  1 +
 src/useractionmodel.cpp | 12 ++++++++++++
 src/useractionmodel.h   |  5 +++++
 6 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/account.cpp b/src/account.cpp
index d3738226..aa0d7b45 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -1472,6 +1472,11 @@ Account* Account::operator<<(Account::EditAction& action)
    return this;
 }
 
+Account* operator<<(Account* a, Account::EditAction action)
+{
+   return (!a)?nullptr : (*a) << action;
+}
+
 ///Change the current edition state
 bool Account::performAction(const Account::EditAction action)
 {
diff --git a/src/account.h b/src/account.h
index 29444092..05181098 100644
--- a/src/account.h
+++ b/src/account.h
@@ -52,7 +52,17 @@ enum DtmfType {
 };
 Q_ENUMS(DtmfType)
 
-///Account: a daemon account (SIP or AIX)
+/**
+ * A communication account.
+ * 
+ * This class represent an account based around a protocol and a bunch of properties.
+ * 
+ * Using the setters on this object wont cause the changes to take effect immediately.
+ * 
+ * To save the changes, use the "<<" operator on the account with Account::EditAction::SAVE.
+ * Similarly, the Account::EditAction::RELOAD action will reset the changes to match the
+ * current properties used by daemon.
+ */
 class LIB_EXPORT Account : public QObject {
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
@@ -394,6 +404,8 @@ Q_DECLARE_METATYPE(Account*)
 Q_DECLARE_METATYPE(Account::RegistrationState)
 Q_DECLARE_METATYPE(Account::EditAction)
 
+Account* operator<<(Account* a, Account::EditAction action);
+
 /**
  * Some accounts can be loaded at later time. This object will be upgraded
  * to an account when it arrive
diff --git a/src/call.cpp b/src/call.cpp
index b1eeaa24..c4c97439 100644
--- a/src/call.cpp
+++ b/src/call.cpp
@@ -478,6 +478,12 @@ Call* Call::operator<<( Call::Action& c)
    return this;
 }
 
+
+Call* operator<<(Call* c, Call::Action action)
+{
+   return (!c) ? nullptr : (*c) << action;
+}
+
 ///Get the history state from the type (see Call.cpp header)
 Call::LegacyHistoryState CallPrivate::historyStateFromType(const QString& type)
 {
diff --git a/src/call.h b/src/call.h
index 9cfdbdd9..2410a3d2 100644
--- a/src/call.h
+++ b/src/call.h
@@ -361,6 +361,7 @@ Q_DECLARE_METATYPE(Call::State)
 Q_DECLARE_METATYPE(Call::Direction)
 Q_DECLARE_METATYPE(Call::LegacyHistoryState)
 
+Call* operator<<(Call* c, Call::Action a);
 QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::State& c       );
 QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::DaemonState& c );
 QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::Action& c      );
diff --git a/src/useractionmodel.cpp b/src/useractionmodel.cpp
index bdf4672b..2864e932 100644
--- a/src/useractionmodel.cpp
+++ b/src/useractionmodel.cpp
@@ -492,6 +492,18 @@ bool UserActionModel::execute(const UserActionModel::Action action) const
    return true; //TODO handle errors
 }
 
+UserActionModel* UserActionModel::operator<<(UserActionModel::Action& action)
+{
+   execute(action);
+   return this;
+}
+
+
+UserActionModel* operator<<(UserActionModel* m,UserActionModel::Action action)
+{
+   return (!m)? nullptr : (*m) << action;
+}
+
 /**
  * Execute an action
  * @param idx A model index. It can be from proxies.
diff --git a/src/useractionmodel.h b/src/useractionmodel.h
index 925508fc..1e953fa4 100644
--- a/src/useractionmodel.h
+++ b/src/useractionmodel.h
@@ -97,6 +97,9 @@ public:
    bool execute( const Action action    ) const;
    bool execute( const QModelIndex& idx ) const;
 
+   //Operators
+   UserActionModel* operator<<(UserActionModel::Action& action);
+
 private:
    const QScopedPointer<UserActionModelPrivate> d_ptr;
    Q_DECLARE_PRIVATE(UserActionModel)
@@ -109,6 +112,8 @@ Q_DECLARE_METATYPE(UserActionModel*)
 Q_DECLARE_METATYPE(UserActionModel::Action)
 
 
+UserActionModel* operator<<(UserActionModel* m,UserActionModel::Action action);
+
 /**
  * "Java bean" used to avoid having a 5+ parameter pixmap delegate
  */
-- 
GitLab