diff --git a/sflphone-client-kde/src/Account.cpp b/sflphone-client-kde/src/Account.cpp index 0de2b732a4c2865059337240e229db9fdf8c46b2..f20614bf6a4c3806c81a151f7ea67227bf3764f4 100644 --- a/sflphone-client-kde/src/Account.cpp +++ b/sflphone-client-kde/src/Account.cpp @@ -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; } diff --git a/sflphone-client-kde/src/Account.h b/sflphone-client-kde/src/Account.h index 65456d57f1526ebd1d8601bd2f5550f349f43b34..37f11f4b23fcdae36e7e90ced18adfe25b4f8eeb 100644 --- a/sflphone-client-kde/src/Account.h +++ b/sflphone-client-kde/src/Account.h @@ -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 diff --git a/sflphone-client-kde/src/CMakeLists.txt b/sflphone-client-kde/src/CMakeLists.txt index 32540e27410f48052ba8ab62a9999a14b5ae47a6..0d71a14d5c3e6b32874df54db4d44e29ea5d71e6 100644 --- a/sflphone-client-kde/src/CMakeLists.txt +++ b/sflphone-client-kde/src/CMakeLists.txt @@ -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 ) diff --git a/sflphone-client-kde/src/Contact.cpp b/sflphone-client-kde/src/Contact.cpp index 60d32f21a85e7232ac29269f0578b54b70588665..af3ee5ea9644a29387c583e63c4d65456de471b5 100644 --- a/sflphone-client-kde/src/Contact.cpp +++ b/sflphone-client-kde/src/Contact.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; -} diff --git a/sflphone-client-kde/src/Contact.h b/sflphone-client-kde/src/Contact.h index 383aaa688e72391c83621a22d4e5573f85fe39b4..bf4f4f987ca885bf41ebd3fcf4960b76ea49a7be 100644 --- a/sflphone-client-kde/src/Contact.h +++ b/sflphone-client-kde/src/Contact.h @@ -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(); }; diff --git a/sflphone-client-kde/src/ContactItemWidget.h b/sflphone-client-kde/src/ContactItemWidget.h index a3d4e3d41ea41fb45b28ffc8bc27b69af78bc093..517d0a78dc169411fd1e1be48584c6d53cfb3a8c 100644 --- a/sflphone-client-kde/src/ContactItemWidget.h +++ b/sflphone-client-kde/src/ContactItemWidget.h @@ -25,6 +25,8 @@ #include <QtGui/QLabel> #include "Contact.h" +class Contact; + /** @author Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> */ diff --git a/sflphone-client-kde/src/Item.cpp b/sflphone-client-kde/src/Item.cpp new file mode 100644 index 0000000000000000000000000000000000000000..705cb2948c4eefbf44912f1b598ed4c4cf23c8d9 --- /dev/null +++ b/sflphone-client-kde/src/Item.cpp @@ -0,0 +1,22 @@ +/*************************************************************************** + * 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" + diff --git a/sflphone-client-kde/src/Item.h b/sflphone-client-kde/src/Item.h new file mode 100644 index 0000000000000000000000000000000000000000..c859375c07cfbabc6091b52b67b13745106e99e9 --- /dev/null +++ b/sflphone-client-kde/src/Item.h @@ -0,0 +1,92 @@ +/*************************************************************************** + * 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 diff --git a/sflphone-client-kde/src/conf/dlgaccounts.cpp b/sflphone-client-kde/src/conf/dlgaccounts.cpp index 14a2089c95045ca1188f3ebd8114c61fae839d1a..a2efb52bbb623d837d97b7d6b67e21422a8420a6 100644 --- a/sflphone-client-kde/src/conf/dlgaccounts.cpp +++ b/sflphone-client-kde/src/conf/dlgaccounts.cpp @@ -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);