Skip to content
Snippets Groups Projects
Commit a1f35fcc authored by Jérémy Quentin's avatar Jérémy Quentin
Browse files

Use Item class for contacts and accounts

parent 4cd9531f
No related branches found
No related tags found
No related merge requests found
......@@ -53,12 +53,12 @@ const QString account_state_name(QString & s)
//Constructors
Account::Account():accountId(NULL), item(NULL), itemWidget(NULL)
Account::Account():accountId(NULL)
{
}
void Account::initAccountItem()
void Account::initItem()
{
if(item != NULL)
{
......@@ -67,10 +67,10 @@ void Account::initAccountItem()
item = new QListWidgetItem();
item->setSizeHint(QSize(140,25));
item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::ItemIsEnabled);
initAccountItemWidget();
initItemWidget();
}
void Account::initAccountItemWidget()
void Account::initItemWidget()
{
if(itemWidget != NULL)
{
......@@ -102,7 +102,7 @@ Account * Account::buildExistingAccountFromId(QString _accountId)
a->accountId = new QString(_accountId);
qDebug() << "getAccountDetails 1 sent";
a->accountDetails = new MapStringString( configurationManager.getAccountDetails(_accountId).value() );
a->initAccountItem();
a->initItem();
return a;
}
......@@ -111,7 +111,7 @@ Account * Account::buildNewAccountFromAlias(QString alias)
Account * a = new Account();
a->accountDetails = new MapStringString();
a->setAccountDetail(ACCOUNT_ALIAS,alias);
a->initAccountItem();
a->initItem();
return a;
}
......
......@@ -28,17 +28,18 @@
#include "typedefs.h"
#include "AccountItemWidget.h"
#include "Item.h"
const QString account_state_name(QString & s);
class Account : public QObject{
class Account : public QObject, public Item<AccountItemWidget>{
Q_OBJECT
private:
QString * accountId;
MapStringString * accountDetails;
QListWidgetItem * item;
AccountItemWidget * itemWidget;
// QListWidgetItem * item;
// AccountItemWidget * itemWidget;
Account();
......@@ -69,8 +70,8 @@ public:
void setAccountDetail(QString param, QString val);
//Updates
void initAccountItem();
void initAccountItemWidget();
void initItem();
void initItemWidget();
void updateState();
//Operators
......
......@@ -54,6 +54,10 @@ SET( sflphone_client_kde_SRCS
conf/dlghooks.cpp
conf/ConfigurationSkeleton.cpp
Dialpad.cpp
# Codec.cpp
# CodecListModel.cpp
# SortableCodecListWidget.cpp
Item.cpp
)
......
......@@ -33,6 +33,7 @@ Contact::Contact(Addressee addressee, const PhoneNumber & number, bool displayPh
this->nickName = addressee.nickName();
this->phoneNumber = number.number();
this->type = number.type();
this->displayPhoto = displayPhoto;
if(displayPhoto)
{
this->photo = new Picture(addressee.photo());
......@@ -42,7 +43,7 @@ Contact::Contact(Addressee addressee, const PhoneNumber & number, bool displayPh
this->photo = NULL;
}
initItem(displayPhoto);
initItem();
}
......@@ -53,10 +54,15 @@ Contact::~Contact()
delete photo;
}
void Contact::initItem(bool displayPhoto)
void Contact::initItem()
{
this->item = new QListWidgetItem();
this->item->setSizeHint(QSize(140,CONTACT_ITEM_HEIGHT));
initItemWidget();
}
void Contact::initItemWidget()
{
this->itemWidget = new ContactItemWidget(this, displayPhoto);
}
......@@ -90,13 +96,4 @@ PhoneNumber::Type Contact::getType() const
return type;
}
QListWidgetItem * Contact::getItem()
{
return item;
}
QWidget * Contact::getItemWidget()
{
return itemWidget;
}
......@@ -28,25 +28,26 @@
#include <kabc/picture.h>
#include <kabc/phonenumber.h>
#include "Item.h"
#include "ContactItemWidget.h"
using namespace KABC;
class ContactItemWidget;
/**
@author Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>
*/
class Contact{
class Contact : public QObject, public Item<ContactItemWidget>{
private:
QListWidgetItem * item;
QWidget * itemWidget;
QString firstName;
QString secondName;
QString nickName;
QString phoneNumber;
Picture * photo;
PhoneNumber::Type type;
bool displayPhoto;
private:
void initItem(bool displayPhoto);
public:
//Constructors & Destructors
......@@ -60,8 +61,10 @@ public:
QString getSecondName() const;
const Picture * getPhoto() const;
PhoneNumber::Type getType() const;
QListWidgetItem * getItem();
QWidget * getItemWidget();
void initItem();
protected:
void initItemWidget();
};
......
......@@ -25,6 +25,8 @@
#include <QtGui/QLabel>
#include "Contact.h"
class Contact;
/**
@author Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>
*/
......
/***************************************************************************
* 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 "Item.h"
/***************************************************************************
* 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 ITEM_H
#define ITEM_H
#include <QObject>
#include <QListWidgetItem>
#include <QWidget>
/**
@author Jérémy Quentin <jeremy.quentin@gmail.com>
Represents an item of a list, that is displayed
by an QListWidgetItem with a QWidget inside.
The two objects are contained in this class, but their
initializations are pure virtual.
The template class WIDGET_TYPE should be derived from
QWidget.
The implementation of initItem should call initItemWidget
*/
template<class WIDGET_TYPE>class Item
{
protected:
QListWidgetItem * item;
WIDGET_TYPE * itemWidget;
public:
Item(QListWidget *list=0)
{
item = NULL;
itemWidget = NULL;
}
/**
* Be careful that it is not already deleted by QObject
* Commented for safety reasons...
*/
virtual ~Item()
{
// delete item;
// delete itemWidget;
}
QListWidgetItem * getItem()
{
return item;
}
WIDGET_TYPE * getItemWidget()
{
return itemWidget;
}
const QListWidgetItem * getItem() const
{
return item;
}
const WIDGET_TYPE * getItemWidget() const
{
return itemWidget;
}
/**
* Initializes the item and widget
* Implementation should call initItemWidget!
*/
virtual void initItem() = 0;
protected:
virtual void initItemWidget() = 0;
};
#endif
......@@ -33,7 +33,6 @@ DlgAccounts::DlgAccounts(KConfigDialog *parent)
setupUi(this);
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
QStyle * style = QApplication::style();
button_accountUp->setIcon(KIcon("go-up"));
button_accountDown->setIcon(KIcon("go-down"));
button_accountAdd->setIcon(KIcon("list-add"));
......@@ -237,7 +236,7 @@ void DlgAccounts::on_button_accountUp_clicked()
QListWidgetItem * prevItem = listWidget_accountList->takeItem(currentRow);
Account * account = accountList->getAccountByItem(prevItem);
//we need to build a new item to set the itemWidget back
account->initAccountItem();
account->initItem();
QListWidgetItem * item = account->getItem();
AccountItemWidget * widget = account->getItemWidget();
accountList->upAccount(currentRow);
......@@ -254,7 +253,7 @@ void DlgAccounts::on_button_accountDown_clicked()
QListWidgetItem * prevItem = listWidget_accountList->takeItem(currentRow);
Account * account = accountList->getAccountByItem(prevItem);
//we need to build a new item to set the itemWidget back
account->initAccountItem();
account->initItem();
QListWidgetItem * item = account->getItem();
AccountItemWidget * widget = account->getItemWidget();
accountList->downAccount(currentRow);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment