Started AccountList model/view

This commit is contained in:
Jérémy Quentin
2009-07-16 16:46:19 -04:00
parent ff403c6beb
commit 0075832131
14 changed files with 261 additions and 62 deletions

View File

@ -134,7 +134,7 @@ bool Account::isChecked() const
return itemWidget->getEnabled();
}
QString & Account::getAccountId()
const QString & Account::getAccountId() const
{
if (isNew())
{
@ -187,7 +187,7 @@ QString Account::getAccountDetail(QString param) const
return (*accountDetails)[param];
}
QString Account::getAlias()
QString Account::getAlias() const
{
return getAccountDetail(ACCOUNT_ALIAS);
}
@ -221,6 +221,16 @@ void Account::setEnabled(bool checked)
setAccountDetail(ACCOUNT_ENABLED, checked ? ACCOUNT_ENABLED_TRUE : ACCOUNT_ENABLED_FALSE);
}
bool Account::isEnabled() const
{
return (getAccountDetail(ACCOUNT_ENABLED) == ACCOUNT_ENABLED_TRUE);
}
bool Account::isRegistered() const
{
return (getAccountDetail(ACCOUNT_STATUS) == ACCOUNT_STATE_REGISTERED);
}
void Account::updateState()
{
qDebug() << "updateState";

View File

@ -54,7 +54,7 @@ public:
//Getters
bool isNew() const;
bool isChecked() const;
QString & getAccountId();
const QString & getAccountId() const;
MapStringString & getAccountDetails() const;
QListWidgetItem * getItem();
AccountItemWidget * getItemWidget();
@ -62,7 +62,9 @@ public:
QColor getStateColor();
QString getStateColorName();
QString getAccountDetail(QString param) const;
QString getAlias();
QString getAlias() const;
bool isEnabled() const;
bool isRegistered() const;
//Setters
void setAccountId(QString id);
@ -77,7 +79,7 @@ public:
//Operators
bool operator==(const Account&)const;
private slots:
public slots:
void setEnabled(bool checked);

View File

@ -81,9 +81,9 @@ void AccountList::upAccount(int index)
qDebug() << "Error : index or future index out of range in upAccount.";
return;
}
Account & account = getAccount(index);
Account * account = getAccountAt(index);
accounts->remove(index);
accounts->insert(index - 1, & account);
accounts->insert(index - 1, account);
}
void AccountList::downAccount(int index)
@ -93,18 +93,18 @@ void AccountList::downAccount(int index)
qDebug() << "Error : index or future index out of range in upAccount.";
return;
}
Account & account = getAccount(index);
Account * account = getAccountAt(index);
accounts->remove(index);
accounts->insert(index + 1, & account);
accounts->insert(index + 1, account);
}
QString AccountList::getOrderedList()
QString AccountList::getOrderedList() const
{
QString order;
for( int i = 0 ; i < size() ; i++)
{
order += getAccount(i).getAccountId() + "/";
order += getAccountAt(i)->getAccountId() + "/";
}
return order;
}
@ -150,14 +150,14 @@ QVector<Account *> & AccountList::getAccounts()
return *accounts;
}
const Account & AccountList::getAccount (int i) const
const Account * AccountList::getAccountAt (int i) const
{
return *((*accounts)[i]);
return (*accounts)[i];
}
Account & AccountList::getAccount (int i)
Account * AccountList::getAccountAt (int i)
{
return *((*accounts)[i]);
return (*accounts)[i];
}
Account * AccountList::getAccountById(const QString & id) const
@ -194,7 +194,7 @@ Account * AccountList::getAccountByItem(QListWidgetItem * item)
return NULL;
}
int AccountList::size()
int AccountList::size() const
{
return accounts->size();
}
@ -222,12 +222,12 @@ void AccountList::removeAccount(Account * account)
accounts->remove(accounts->indexOf(account));
}
const Account & AccountList::operator[] (int i) const
const Account * AccountList::operator[] (int i) const
{
return *((*accounts)[i]);
return (*accounts)[i];
}
Account & AccountList::operator[] (int i)
Account * AccountList::operator[] (int i)
{
return *((*accounts)[i]);
return (*accounts)[i];
}

View File

@ -49,14 +49,14 @@ public:
//Getters
QVector<Account *> & getAccounts();
Account & getAccount (int i);
const Account & getAccount (int i) const;
Account * getAccountAt (int i);
const Account * getAccountAt (int i) const;
Account * getAccountById(const QString & id) const;
QVector<Account *> getAccountByState(QString & state);
Account * getAccountByItem(QListWidgetItem * item);
int size();
int size() const;
Account * firstRegisteredAccount() const;
QString getOrderedList();
QString getOrderedList() const;
//Setters
Account * addAccount(QString & alias);
@ -66,8 +66,8 @@ public:
void downAccount(int index);
//Operators
Account & operator[] (int i);
const Account & operator[] (int i) const;
Account * operator[] (int i);
const Account * operator[] (int i) const;
QVector<Account *> registeredAccounts() const;
public slots:

View File

@ -0,0 +1,139 @@
/***************************************************************************
* Copyright (C) 2009 by Savoir-Faire Linux *
* Author : Jérémy Quentin *
* jeremy.quentin@savoirfairelinux.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "AccountListModel.h"
#include "sflphone_const.h"
#include <QDebug>
AccountListModel::AccountListModel(QObject *parent)
: QAbstractListModel(parent)
{
this->accounts = new AccountList();
}
AccountListModel::~AccountListModel()
{
}
QVariant AccountListModel::data ( const QModelIndex & index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= rowCount())
return QVariant();
const Account * account = (*accounts)[index.row()];
if(index.column() == 0 && role == Qt::DisplayRole)
{
return QVariant(account->getAlias());
}
else if(index.column() == 0 && role == Qt::CheckStateRole)
{
return QVariant(account->isEnabled() ? Qt::Checked : Qt::Unchecked);
}
else if(index.column() == 0 && role == Qt::DecorationRole)
{
if(! account->isEnabled())
{
return QVariant(QIcon(ICON_ACCOUNT_LED_GRAY));
}
else if(account->isRegistered())
{
return QVariant(QIcon(ICON_ACCOUNT_LED_GREEN));
}
else
{
return QVariant(QIcon(ICON_ACCOUNT_LED_RED));
}
}
return QVariant();
}
Qt::ItemFlags AccountListModel::flags(const QModelIndex & index) const
{
if (index.column() == 0)
{
return QAbstractItemModel::flags(index) | Qt::ItemIsUserCheckable;
}
return QAbstractItemModel::flags(index);
}
bool AccountListModel::setData ( const QModelIndex & index, const QVariant &value, int role)
{
qDebug() << "setData";
if (index.isValid() && index.column() == 0 && role == Qt::CheckStateRole) {
(*accounts)[index.row()]->setEnabled(value.toBool());
emit dataChanged(index, index);
return true;
}
return false;
}
bool AccountListModel::accountUp( int index )
{
if(index > 0 && index <= rowCount())
{
accounts->upAccount(index);
emit dataChanged(this->index(index - 1, 0, QModelIndex()), this->index(index, 0, QModelIndex()));
return true;
}
return false;
}
bool AccountListModel::accountDown( int index )
{
if(index >= 0 && index < rowCount())
{
accounts->downAccount(index);
emit dataChanged(this->index(index, 0, QModelIndex()), this->index(index + 1, 0, QModelIndex()));
return true;
}
return false;
}
bool AccountListModel::removeAccount( int index )
{
if(index >= 0 && index < rowCount())
{
accounts->removeAccount(accounts->getAccountAt(index));
emit dataChanged(this->index(index, 0, QModelIndex()), this->index(rowCount(), 0, QModelIndex()));
return true;
}
return false;
}
bool AccountListModel::addAccount( QString alias )
{
accounts->addAccount(alias);
emit dataChanged(this->index(0, 0, QModelIndex()), this->index(rowCount(), 0, QModelIndex()));
return true;
}
int AccountListModel::rowCount(const QModelIndex & parent) const
{
return accounts->size();
}
QString AccountListModel::getOrderedList() const
{
return accounts->getOrderedList();
}

View File

@ -0,0 +1,60 @@
/***************************************************************************
* Copyright (C) 2009 by Savoir-Faire Linux *
* Author : Jérémy Quentin *
* jeremy.quentin@savoirfairelinux.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef ACCOUNTLISTMODEL_H
#define ACCOUNTLISTMODEL_H
#include <QAbstractListModel>
#include "AccountList.h"
/**
@author Jérémy Quentin <jeremy.quentin@gmail.com>
*/
class AccountListModel : public QAbstractListModel
{
Q_OBJECT
private:
AccountList * accounts;
public:
AccountListModel(QObject *parent = 0);
~AccountListModel();
QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
int rowCount(const QModelIndex & parent = QModelIndex()) const;
// int columnCount(const QModelIndex & parent = QModelIndex()) const;
// QVariant headerData(int section , Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex & index) const;
virtual bool setData ( const QModelIndex & index, const QVariant &value, int role);
bool accountUp( int index );
bool accountDown( int index );
bool removeAccount( int index );
bool addAccount( QString alias );
QString getOrderedList() const;
// QStringList getActiveCodecList() const ;
// void setActiveCodecList(const QStringList & activeCodecListToSet);
};
#endif

View File

@ -58,6 +58,7 @@ SET( sflphone_client_kde_SRCS
CodecListModel.cpp
SortableCodecListWidget.cpp
Item.cpp
AccountListModel.cpp
)

View File

@ -124,13 +124,10 @@ bool CodecListModel::setData ( const QModelIndex & index, const QVariant &value,
bool CodecListModel::codecUp( int index )
{
qDebug() << getActiveCodecList();
if(index > 0 && index <= rowCount())
{
codecs.swap(index - 1, index);
qDebug() << getActiveCodecList();
emit dataChanged(this->index(index - 1, 0, QModelIndex()), this->index(index, columnCount(), QModelIndex()));
qDebug() << getActiveCodecList();
return true;
}
return false;

View File

@ -37,12 +37,10 @@ public:
CodecListModel(QObject *parent = 0);
~CodecListModel();
void setCodecs(QList<Codec *> codecs);
QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
int rowCount(const QModelIndex & parent = QModelIndex()) const;
int columnCount(const QModelIndex & parent = QModelIndex()) const;
// bool insertRows(int position, int rows, const QModelIndex &parent);
QVariant headerData(int section , Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex & index) const;
virtual bool setData ( const QModelIndex & index, const QVariant &value, int role);
@ -53,7 +51,7 @@ public:
void setActiveCodecList(const QStringList & activeCodecListToSet);
signals:
void dataChanged(const QModelIndex &, const QModelIndex &);
// void dataChanged(const QModelIndex &, const QModelIndex &);
};
#endif

View File

@ -28,8 +28,8 @@ ConfigurationSkeleton::ConfigurationSkeleton()
{
qDebug() << "Building ConfigurationSkeleton";
codecListModel = new CodecListModel();
accountListModel = new AccountListModel();
readConfig();
}
ConfigurationSkeleton * ConfigurationSkeleton::instance = NULL;

View File

@ -25,6 +25,7 @@
#include "kcfg_settings.h"
#include "CodecListModel.h"
#include "AccountListModel.h"
/**
@author Jérémy Quentin <jeremy.quentin@gmail.com>
@ -45,6 +46,8 @@ private:
static ConfigurationSkeleton * instance;
CodecListModel * codecListModel;
AccountListModel * accountListModel;
public:
ConfigurationSkeleton();

View File

@ -85,29 +85,29 @@ void DlgAccounts::saveAccountList()
QStringList accountIds= QStringList(configurationManager.getAccountList().value());
//create or update each account from accountList
for (int i = 0; i < accountList->size(); i++){
Account & current = (*accountList)[i];
Account * current = (*accountList)[i];
QString currentId;
//if the account has no instanciated id, it has just been created in the client
if(current.isNew())
if(current->isNew())
{
MapStringString details = current.getAccountDetails();
MapStringString details = current->getAccountDetails();
currentId = configurationManager.addAccount(details);
current.setAccountId(currentId);
current->setAccountId(currentId);
}
//if the account has an instanciated id but it's not in configurationManager
else{
if(! accountIds.contains(current.getAccountId()))
if(! accountIds.contains(current->getAccountId()))
{
qDebug() << "The account with id " << current.getAccountId() << " doesn't exist. It might have been removed by another SFLphone client.";
qDebug() << "The account with id " << current->getAccountId() << " doesn't exist. It might have been removed by another SFLphone client.";
currentId = QString();
}
else
{
configurationManager.setAccountDetails(current.getAccountId(), current.getAccountDetails());
currentId = QString(current.getAccountId());
configurationManager.setAccountDetails(current->getAccountId(), current->getAccountDetails());
currentId = QString(current->getAccountId());
}
}
qDebug() << currentId << " : " << current.isChecked();
qDebug() << currentId << " : " << current->isChecked();
}
//remove accounts that are in the configurationManager but not in the client
for (int i = 0; i < accountIds.size(); i++)
@ -190,7 +190,7 @@ void DlgAccounts::loadAccountList()
//initialize the QListWidget object with the AccountList
listWidget_accountList->clear();
for (int i = 0; i < accountList->size(); ++i){
addAccountToAccountList(&(*accountList)[i]);
addAccountToAccountList((*accountList)[i]);
}
if (listWidget_accountList->count() > 0 && listWidget_accountList->currentItem() == NULL)
listWidget_accountList->setCurrentRow(0);
@ -343,8 +343,8 @@ void DlgAccounts::updateAccountStates()
qDebug() << accountList->size();
for (int i = 0; i < accountList->size(); i++)
{
Account & current = accountList->getAccount(i);
current.updateState();
Account * current = accountList->getAccountAt(i);
current->updateState();
}
qDebug() << accountList->size();
}

View File

@ -18,8 +18,7 @@
#include <QTableView>
#include <QListView>
#include "CodecListModel.h"
#include "SortableCodecListWidget.h"
#include "AccountListModel.h"
static const char description[] = "A KDE 4 Client for SFLphone";
@ -62,6 +61,11 @@ int main(int argc, char **argv)
// SortableCodecListWidget * cl = new SortableCodecListWidget();
// cl->show();
QListView * v = new QListView();
v->setFlow(QListView::TopToBottom);
v->setModel(new AccountListModel());
v->show();
return app.exec();
}

View File

@ -29,24 +29,9 @@
#define APP_NAME "SFLphone KDE Client"
/** Locale */
// #define _(STRING) gettext( STRING )
/** Warnings unused variables **/
// #define UNUSED_VAR(var) (void*)var
// #define UNUSED __attribute__((__unused__))
#define SIP 0
#define IAX 1
#define PAGE_GENERAL 0
#define PAGE_DISPLAY 1
#define PAGE_ACCOUNTS 2
#define PAGE_AUDIO 3
#define TOOLBAR_SIZE 22
#define CONTACT_ITEM_HEIGHT 40