diff --git a/kde/src/SFLPhone.cpp b/kde/src/SFLPhone.cpp index f51ed3f3bd0410933ba8be871caba1e6b536531b..d8ff36e6b5f07ee86de602802daadd1f50887ea7 100755 --- a/kde/src/SFLPhone.cpp +++ b/kde/src/SFLPhone.cpp @@ -200,7 +200,7 @@ bool SFLPhone::initialize() move(QCursor::pos().x() - geometry().width()/2, QCursor::pos().y() - geometry().height()/2); - if(configurationManager.getAccountList().value().isEmpty()) { + if(configurationManager.getAccountList().value().size() <= 1) { (new AccountWizard())->show(); } diff --git a/kde/src/SFLPhoneView.cpp b/kde/src/SFLPhoneView.cpp index de14ded5baae6cc62e2ef96727d58cce5a4a830c..f4448f4fe4f2e6efb36ef8882a6fe1d84704f579 100755 --- a/kde/src/SFLPhoneView.cpp +++ b/kde/src/SFLPhoneView.cpp @@ -55,6 +55,52 @@ //ConfigurationDialog* SFLPhoneView::configDialog; +class ColorVisitor : public AccountListColorVisitor { +public: + ColorVisitor(QPalette pal) : m_Pal(pal) { + m_Green = QColor(m_Pal.color(QPalette::Base)); + if (m_Green.green()+20 >= 255) { + m_Green.setRed(((int)m_Green.red()-20)); + m_Green.setBlue(((int)m_Green.blue()-20)); + } + else + m_Green.setGreen(((int)m_Green.green()+20)); + + m_Red = QColor(m_Pal.color(QPalette::Base)); + if (m_Red.red()+20 >= 255) { + m_Red.setGreen(((int)m_Red.green()-20)); + m_Red.setBlue(((int)m_Red.blue()-20)); + } + else + m_Red.setRed(((int)m_Red.red()+20)); + + m_Yellow = QColor(m_Pal.color(QPalette::Base)); + if (m_Yellow.red()+20 >= 255 || m_Green.green()+20 >= 255) { + m_Yellow.setBlue(((int)m_Yellow.blue()-20)); + } + else { + m_Yellow.setGreen(((int)m_Yellow.green()+20)); + m_Yellow.setRed(((int)m_Yellow.red()+20)); + } + } + + virtual QVariant getColor(const Account* a) { + if(a->getAccountRegistrationStatus() == ACCOUNT_STATE_UNREGISTERED || !a->isEnabled()) + return m_Pal.color(QPalette::Base); + if(a->getAccountRegistrationStatus() == ACCOUNT_STATE_REGISTERED || a->getAccountRegistrationStatus() == ACCOUNT_STATE_READY) { + return m_Green; + } + if(a->getAccountRegistrationStatus() == ACCOUNT_STATE_TRYING) + return m_Yellow; + return m_Red; + } +private: + QPalette m_Pal; + QColor m_Green; + QColor m_Yellow; + QColor m_Red; +}; + ///Constructor SFLPhoneView::SFLPhoneView(QWidget *parent) : QWidget(parent), wizard(0), errorWindow(0) @@ -70,6 +116,8 @@ SFLPhoneView::SFLPhoneView(QWidget *parent) pal.setColor(QPalette::AlternateBase, Qt::lightGray); setPalette(pal); + AccountList::getInstance()->setColorVisitor(new ColorVisitor(pal)); + m_pMessageBoxW->setVisible(false); // SENDER SIGNAL RECEIVER SLOT / @@ -159,8 +207,8 @@ void SFLPhoneView::typeString(QString str) Call* call = callView->getCurrentItem(); callManager.playDTMF(str); - Call *currentCall = 0; - Call *candidate = 0; + Call *currentCall = nullptr; + Call *candidate = nullptr; if(call) { if(call->getState() == CALL_STATE_CURRENT) { diff --git a/kde/src/lib/Account.cpp b/kde/src/lib/Account.cpp index bedc940f843255ebe6878efd00ca205373d27f8a..3cc6cf8867b21ecfbc290427ffdc909d55f78cdc 100644 --- a/kde/src/lib/Account.cpp +++ b/kde/src/lib/Account.cpp @@ -103,7 +103,7 @@ Account::~Account() { disconnect(); delete m_pAccountId; - delete m_pAccountDetails; + if (m_pAccountDetails) delete m_pAccountDetails; } @@ -240,6 +240,8 @@ Qt::GlobalColor Account::getStateColor() const ///Set account details void Account::setAccountDetails(const MapStringString& m) { + if (m_pAccountDetails) + delete m_pAccountDetails; *m_pAccountDetails = m; } @@ -318,8 +320,10 @@ void Account::reload() qDebug() << "Account not found"; } else { - if (m_pAccountDetails) + if (m_pAccountDetails) { delete m_pAccountDetails; + m_pAccountDetails = nullptr; + } m_pAccountDetails = new MapStringString(aDetails); } } diff --git a/kde/src/lib/AccountList.cpp b/kde/src/lib/AccountList.cpp index 96c2be8648a7fb43743af7745de65a480f6b1c52..b5d4e6d5f524368cf5a32d77ccb9c32b00065ac2 100644 --- a/kde/src/lib/AccountList.cpp +++ b/kde/src/lib/AccountList.cpp @@ -32,7 +32,7 @@ AccountList* AccountList::m_spAccountList = nullptr; QString AccountList::m_sPriorAccountId = "" ; ///Constructors -AccountList::AccountList(QStringList & _accountIds) +AccountList::AccountList(QStringList & _accountIds) : m_pColorVisitor(nullptr) { m_pAccounts = new QVector<Account*>(); for (int i = 0; i < _accountIds.size(); ++i) { @@ -45,7 +45,7 @@ AccountList::AccountList(QStringList & _accountIds) ///Constructors ///@param fill Whether to fill the list with accounts from configurationManager or not. -AccountList::AccountList(bool fill) +AccountList::AccountList(bool fill) : m_pColorVisitor(nullptr) { m_pAccounts = new QVector<Account *>(); if(fill) @@ -300,7 +300,11 @@ Account* AccountList::getCurrentAccount() return priorAccount; } else { - return AccountList::getInstance()->firstRegisteredAccount(); + Account* a = AccountList::getInstance()->firstRegisteredAccount(); + if (a) + return AccountList::getInstance()->firstRegisteredAccount(); + else + return AccountList::getInstance()->getAccountById("IP2IP"); } } //getCurrentAccount @@ -322,7 +326,10 @@ QVariant AccountList::data ( const QModelIndex& index, int role) const else if(index.column() == 0 && role == Qt::CheckStateRole) return QVariant(account->isEnabled() ? Qt::Checked : Qt::Unchecked); else if (role == Qt::BackgroundRole) { - return QVariant(account->getStateColor()); + if (m_pColorVisitor) + return m_pColorVisitor->getColor(account); + else + return QVariant(account->getStateColor()); } else if(index.column() == 0 && role == Qt::DecorationRole) { /*TODO implement visitor*/ @@ -397,6 +404,12 @@ bool AccountList::setData(const QModelIndex & index, const QVariant &value, int return false; } +///Set QAbstractItemModel BackgroundRole visitor +void AccountList::setColorVisitor(AccountListColorVisitor* visitor) +{ + m_pColorVisitor = visitor; +} + /***************************************************************************** * * diff --git a/kde/src/lib/AccountList.h b/kde/src/lib/AccountList.h index a1f4bf1c12c6924a6d88edebfd22e43665bd192c..224c912045b68ddadcbb4aba39bb6cc50d6fc0c4 100644 --- a/kde/src/lib/AccountList.h +++ b/kde/src/lib/AccountList.h @@ -29,6 +29,8 @@ #include "typedefs.h" #include "dbus/metatypes.h" +class AccountListColorVisitor; + ///AccountList: List of all daemon accounts class LIB_EXPORT AccountList : public QAbstractListModel { Q_OBJECT @@ -60,6 +62,7 @@ public: //Setters static void setPriorAccountId( const QString& value ); virtual bool setData ( const QModelIndex& index, const QVariant &value, int role); + void setColorVisitor ( AccountListColorVisitor* visitor ); //Mutators virtual Account* addAccount ( QString & alias ) ; @@ -84,6 +87,7 @@ private: QVector<Account*>* m_pAccounts; static AccountList* m_spAccountList; static QString m_sPriorAccountId; + AccountListColorVisitor* m_pColorVisitor; public slots: void update(); @@ -99,4 +103,11 @@ signals: void accountStateChanged( Account* account, QString state); }; +///SFLPhonelib Qt does not link to QtGui, and does not need to, this allow to add runtime Gui support +class LIB_EXPORT AccountListColorVisitor { +public: + virtual QVariant getColor(const Account* a) = 0; + virtual ~AccountListColorVisitor() {} +}; + #endif diff --git a/kde/src/test/account_test.cpp b/kde/src/test/account_test.cpp index 3e0a72bc2d0f32e5423d36f7180a63e15210c078..b85c87ae6f549b6a90d9688e8a149c4a2ec02e6a 100644 --- a/kde/src/test/account_test.cpp +++ b/kde/src/test/account_test.cpp @@ -610,7 +610,7 @@ void AccountTests::testDisableAllAccounts() for (int i=0;i<AccountList::getInstance()->size();i++) { saveState << (*AccountList::getInstance())[i]->isAccountEnabled(); (*AccountList::getInstance())[i]->setAccountEnabled(false); - acc->save(); + (*AccountList::getInstance())[i]->save(); } QCOMPARE(AccountList::getCurrentAccount(),(Account*)NULL); @@ -618,7 +618,7 @@ void AccountTests::testDisableAllAccounts() //Restore state for (int i=0;i<AccountList::getInstance()->size();i++) { (*AccountList::getInstance())[i]->setAccountEnabled(saveState[i]); - acc->save(); + (*AccountList::getInstance())[i]->save(); } }