diff --git a/sflphone-client-kde/src/Call.cpp b/sflphone-client-kde/src/Call.cpp index f0d926a903fea314ad32ad6c8a7a6209c21174a1..abd4e6a191917a96ece2e20d03cb7fe756985a27 100644 --- a/sflphone-client-kde/src/Call.cpp +++ b/sflphone-client-kde/src/Call.cpp @@ -28,6 +28,7 @@ #include <kabc/addressbook.h> #include <kabc/stdaddressbook.h> +#include "CallTreeItem.h" using namespace KABC; @@ -102,14 +103,6 @@ const char * Call::callStateIcons[11] = {ICON_INCOMING, ICON_RINGING, ICON_CURRE const char * Call::historyIcons[3] = {ICON_HISTORY_INCOMING, ICON_HISTORY_OUTGOING, ICON_HISTORY_MISSED}; -void Call::initCallItem() -{ - item = new QListWidgetItem(); - item->setSizeHint(QSize(140,45)); - item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::ItemIsEnabled); - initCallItemWidget(); -} - void Call::initCallItemWidget() { itemWidget = new QWidget(); @@ -155,11 +148,9 @@ Call::Call(call_state startState, QString callId, QString peerName, QString peer this->callId = callId; this->peerPhoneNumber = peerNumber; this->peerName = peerName; - initCallItem(); changeCurrentState(startState); this->account = account; this->recording = false; - this->historyItem = NULL; this->historyItemWidget = NULL; this->startTime = NULL; this->stopTime = NULL; @@ -185,9 +176,7 @@ Call::~Call() { delete startTime; delete stopTime; - delete item; //delete itemWidget; - delete historyItem; //delete historyItemWidget; } @@ -391,26 +380,11 @@ Contact * Call::findContactForNumberInKAddressBook(QString number) return NULL; } -QListWidgetItem * Call::getItem() -{ - return item; -} - QWidget * Call::getItemWidget() { return itemWidget; } -QListWidgetItem * Call::getHistoryItem() -{ - if(historyItem == NULL && historyState != NONE) - { - historyItem = new QListWidgetItem(); - historyItem->setSizeHint(QSize(140,45)); - } - return historyItem; -} - QString Call::getStopTimeStamp() const { if (stopTime == NULL) @@ -667,7 +641,6 @@ void Call::setRecord() qDebug() << "Setting record " << !recording << " for call. callId : " << callId; callManager.setRecording(callId); recording = !recording; - updateItem(); } void Call::start() @@ -755,10 +728,9 @@ void Call::backspaceItemText() void Call::changeCurrentState(call_state newState) { currentState = newState; - updateItem(); } -void Call::updateItem() +/*void Call::updateItem() { if(currentState != CALL_STATE_OVER) { @@ -779,5 +751,5 @@ void Call::updateItem() { // qDebug() << "Updating item of call of state OVER. Doing nothing."; } -} + }*/ diff --git a/sflphone-client-kde/src/Call.h b/sflphone-client-kde/src/Call.h index e9b99619a342c29229aaeaadb4744a6499e6175d..b1dcad67bfce22e26222fad9be1b6a9220170670 100644 --- a/sflphone-client-kde/src/Call.h +++ b/sflphone-client-kde/src/Call.h @@ -25,7 +25,6 @@ #include <QtCore/QString> #include <QtCore/QDateTime> -#include <QtGui/QListWidgetItem> #include <QtGui/QLabel> #include <QtGui/QWidget> @@ -152,7 +151,6 @@ private: QDateTime * startTime; QDateTime * stopTime; - QListWidgetItem * item; QWidget * itemWidget; QLabel * labelIcon; QLabel * labelPeerName; @@ -160,7 +158,6 @@ private: QLabel * labelTransferPrefix; QLabel * labelTransferNumber; - QListWidgetItem * historyItem; QWidget * historyItemWidget; QLabel * labelHistoryIcon; QLabel * labelHistoryPeerName; @@ -236,7 +233,6 @@ public: //Constructors & Destructors ~Call(); - void initCallItem(); void initCallItemWidget(); static Call * buildDialingCall(QString callId, const QString & peerName, QString account = ""); static Call * buildIncomingCall(const QString & callId); @@ -250,9 +246,7 @@ public: static history_state getHistoryStateFromDaemonCallState(QString daemonCallState, QString daemonCallType); //Getters - QListWidgetItem * getItem(); QWidget * getItemWidget(); - QListWidgetItem * getHistoryItem(); QWidget * getHistoryItemWidget(); call_state getState() const; QString getCallId() const; @@ -277,12 +271,9 @@ public: // void setPeerName(const QString peerName); void changeCurrentState(call_state newState); - //Updates - void updateItem(); - //Utils Contact * findContactForNumberInKAddressBook(QString number); }; -#endif \ No newline at end of file +#endif diff --git a/sflphone-client-kde/src/CallList.h b/sflphone-client-kde/src/CallList.h index 1aeb35dae53f1cdfd88632c1a6e93eb0ac4e38d8..ffee7a9937b10708e837d35fdf7eee870cc60e6a 100644 --- a/sflphone-client-kde/src/CallList.h +++ b/sflphone-client-kde/src/CallList.h @@ -24,8 +24,8 @@ #include <QtCore/QVector> #include <QtCore/QString> -#include <QtGui/QListWidgetItem> +#include "CallTreeItem.h" #include "Call.h" #include "dbus/metatypes.h" @@ -67,4 +67,4 @@ public slots: }; -#endif \ No newline at end of file +#endif diff --git a/sflphone-client-kde/src/CallTreeItem.cpp b/sflphone-client-kde/src/CallTreeItem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..50facfe87b8f37732a0369eb82a1ac84def7f350 --- /dev/null +++ b/sflphone-client-kde/src/CallTreeItem.cpp @@ -0,0 +1,152 @@ +/*************************************************************************** + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). * + * All rights reserved. * + * Contact: Nokia Corporation (qt-info@nokia.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 <QStringList> + + #include "CallTreeItem.h" + + CallTreeItem::CallTreeItem(const Call &data, CallTreeItem *parent) + { + parentItem = parent; + itemData = data; + } + + CallTreeItem::~CallTreeItem() + { + qDeleteAll(childItems); + } + + CallTreeItem *CallTreeItem::child(int number) + { + return childItems.value(number); + } + + int CallTreeItem::childCount() const + { + return childItems.count(); + } + + int CallTreeItem::childNumber() const + { + if (parentItem) + { + return parentItem->childItems.indexOf(const_cast<CallTreeItem*>(this)); + } + return 0; + } + + int CallTreeItem::columnCount() const + { + return itemData.count(); + } + + QVariant CallTreeItem::data(int column) const + { + return itemData.value(column); + } + + bool CallTreeItem::insertChildren(int position, int count, int columns) + { + if (position < 0 || position > childItems.size()) + { + return false; + } + + for (int row = 0; row < count; ++row) + { + QVector<QVariant> data(columns); + CallTreeItem *item = new CallTreeItem(data, this); + childItems.insert(position, item); + } + + return true; + } + + bool CallTreeItem::insertColumns(int position, int columns) + { + if (position < 0 || position > itemData.size()) + { + return false; + } + + for (int column = 0; column < columns; ++column) + { + itemData.insert(position, QVariant()); + } + + foreach (CallTreeItem *child, childItems) + { + child->insertColumns(position, columns); + } + + return true; + } + + CallTreeItem *CallTreeItem::parent() + { + return parentItem; + } + + bool CallTreeItem::removeChildren(int position, int count) + { + if (position < 0 || position + count > childItems.size()) + { + return false; + } + + for (int row = 0; row < count; ++row) + { + delete childItems.takeAt(position); + } + + return true; + } + + bool CallTreeItem::removeColumns(int position, int columns) + { + if (position < 0 || position + columns > itemData.size()) + { + return false; + } + + for (int column = 0; column < columns; ++column) + { + itemData.remove(position); + } + + foreach (CallTreeItem *child, childItems) + { + child->removeColumns(position, columns); + } + + return true; + } + + bool CallTreeItem::setData(int column, const QVariant &value) + { + if (column < 0 || column >= itemData.size()) + { + return false; + } + + itemData[column] = value; + return true; + } diff --git a/sflphone-client-kde/src/CallTreeItem.h b/sflphone-client-kde/src/CallTreeItem.h new file mode 100644 index 0000000000000000000000000000000000000000..cc0aea12324a43ffe9d6c1f82fe1406a08c2e69f --- /dev/null +++ b/sflphone-client-kde/src/CallTreeItem.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). * + * All rights reserved. * + * Contact: Nokia Corporation (qt-info@nokia.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. * + ***************************************************************************/ + +/** + * http://doc.trolltech.com/4.5/itemviews-editabletreemodel.html + */ + +#ifndef CALLTREE_ITEM_H +#define CALLTREE_ITEM_H + +#include <QtCore/QList> +#include <QtGui/QTreeWidget> + +class Call; + +class CallTreeItem : public QTreeWidget + { + public: + CallTreeItem(const Call &data, CallTreeItem *parent = 0); + ~CallTreeItem(); + + CallTreeItem *child(int number); + int childCount() const; + int columnCount() const; + Call* data(int column) const; + bool insertChildren(int position, int count, int columns); + bool insertColumns(int position, int columns); + CallTreeItem *parent(); + bool removeChildren(int position, int count); + bool removeColumns(int position, int columns); + int childNumber() const; + bool setData(int column, const Call &value); + + private: + QList<CallTreeItem*> childItems; + Call *itemData; + CallTreeItem *parentItem; + }; + +#endif // CALLTREE_ITEM_H diff --git a/sflphone-client-kde/src/CallTreeModel.cpp b/sflphone-client-kde/src/CallTreeModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d64088edf5b21f8cad9361b7251252faee8adbce --- /dev/null +++ b/sflphone-client-kde/src/CallTreeModel.cpp @@ -0,0 +1,297 @@ +/*************************************************************************** + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). * + * All rights reserved. * + * Contact: Nokia Corporation (qt-info@nokia.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 <QtGui> + +#include "CallTreeModel.h" +#include "CallTreeItem.h" + +CallTreeModel::CallTreeModel(QObject *parent) + : QAbstractItemModel(parent) +{ + QStringList headers << i18n("Calls"); + QVector<QVariant> rootData; + + foreach (QString header, headers) + { + rootData << header; + } + + rootItem = new TreeItem(rootData); + setupModelData(data.split(QString("\n")), rootItem); +} + +CallTreeModel::~CallTreeModel() +{ + delete rootItem; +} + +int CallTreeModel::columnCount(const QModelIndex & /* parent */) const +{ + return rootItem->columnCount(); +} + +QVariant CallTreeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + if (role != Qt::DisplayRole && role != Qt::EditRole) + { + return QVariant(); + } + + CallTreeItem *item = getItem(index); + + return item->data(index.column()); +} + +Qt::ItemFlags CallTreeModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + { + return 0; + } + + return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +CallTreeItem *CallTreeModel::getItem(const QModelIndex &index) const +{ + if (index.isValid()) + { + CallTreeItem *item = static_cast<TreeItem*>(index.internalPointer()); + if (item) + { + return item; + } + } + return rootItem; +} + +QVariant CallTreeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + return rootItem->data(section); + } + return QVariant(); +} + +QModelIndex CallTreeModel::index(int row, int column, const QModelIndex &parent) const +{ + if (parent.isValid() && parent.column() != 0) + { + return QModelIndex(); + } + + CallTreeItem *parentItem = getItem(parent); + CallTreeItem *childItem = parentItem->child(row); + + if (childItem) + { + return createIndex(row, column, childItem); + } + else + { + return QModelIndex(); + } +} + +bool CallTreeModel::insertColumns(int position, int columns, const QModelIndex &parent) +{ + bool success; + + beginInsertColumns(parent, position, position + columns - 1); + success = rootItem->insertColumns(position, columns); + endInsertColumns(); + + return success; +} + +bool CallTreeModel::insertRows(int position, int rows, const QModelIndex &parent) +{ + CallTreeItem *parentItem = getItem(parent); + bool success; + + beginInsertRows(parent, position, position + rows - 1); + success = parentItem->insertChildren(position, rows, rootItem->columnCount()); + endInsertRows(); + + return success; +} + +QModelIndex CallTreeModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + { + return QModelIndex(); + } + + CallTreeItem *childItem = getItem(index); + CallTreeItem *parentItem = childItem->parent(); + + if (parentItem == rootItem) + { + return QModelIndex(); + } + + return createIndex(parentItem->childNumber(), 0, parentItem); +} + +bool CallTreeModel::removeColumns(int position, int columns, const QModelIndex &parent) +{ + bool success; + + beginRemoveColumns(parent, position, position + columns - 1); + success = rootItem->removeColumns(position, columns); + endRemoveColumns(); + + if (rootItem->columnCount() == 0) + { + removeRows(0, rowCount()); + } + + return success; +} + +bool CallTreeModel::removeRows(int position, int rows, const QModelIndex &parent) +{ + TreeItem *parentItem = getItem(parent); + bool success = true; + + beginRemoveRows(parent, position, position + rows - 1); + success = parentItem->removeChildren(position, rows); + endRemoveRows(); + + return success; +} + +int CallTreeModel::rowCount(const QModelIndex &parent) const +{ + CallTreeItem *parentItem = getItem(parent); + + return parentItem->childCount(); +} + +bool CallTreeModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (role != Qt::EditRole) + { + return false; + } + + TreeItem *item = getItem(index); + bool result = item->setData(index.column(), value); + + if (result) + { + emit dataChanged(index, index); + } + + return result; +} + +bool TreeModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) +{ + if (role != Qt::EditRole || orientation != Qt::Horizontal) + { + return false; + } + + bool result = rootItem->setData(section, value); + + if (result) + { + emit headerDataChanged(orientation, section, section); + } + + return result; +} + +void CallTreeModel::setupModelData(const QStringList &lines, CallTreeItem *parent) +{ + QList<CallTreeItem*> parents; + QList<int> indentations; + parents << parent; + indentations << 0; + + int number = 0; + + while (number < lines.count()) + { + int position = 0; + + while (position < lines[number].length()) + { + if (lines[number].mid(position, 1) != " ") + { + break; + } + position++; + } + + QString lineData = lines[number].mid(position).trimmed(); + + if (!lineData.isEmpty()) + { + // Read the column data from the rest of the line. + QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); + QVector<QVariant> columnData; + for (int column = 0; column < columnStrings.count(); ++column) + { + columnData << columnStrings[column]; + } + + if (position > indentations.last()) + { + // The last child of the current parent is now the new parent + // unless the current parent has no children. + + if (parents.last()->childCount() > 0) + { + parents << parents.last()->child(parents.last()->childCount()-1); + indentations << position; + } + } + else + { + while (position < indentations.last() && parents.count() > 0) + { + parents.pop_back(); + indentations.pop_back(); + } + } + + // Append a new item to the current parent's list of children. + CallTreeItem *parent = parents.last(); + parent->insertChildren(parent->childCount(), 1, rootItem->columnCount()); + + for (int column = 0; column < columnData.size(); ++column) + { + parent->child(parent->childCount() - 1)->setData(column, columnData[column]); + } + } + number++; + } +} diff --git a/sflphone-client-kde/src/CallTreeModel.h b/sflphone-client-kde/src/CallTreeModel.h new file mode 100644 index 0000000000000000000000000000000000000000..e62ec4b99307e04b73b268a8a5ff9906bbce9c0c --- /dev/null +++ b/sflphone-client-kde/src/CallTreeModel.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). * + * All rights reserved. * + * Contact: Nokia Corporation (qt-info@nokia.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. * + ***************************************************************************/ + +/** + * http://doc.trolltech.com/4.5/itemviews-editabletreemodel.html + */ + +#ifndef CALLTREE_MODEL_H +#define CALLTREE_MODEL_H + +#include <QtCore/QAbstractItemModel> +#include <QtCore/QModelIndex> +#include <QtCore/QVariant> + +class CallTreeItem; + +class CallTreeModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + CallTreeModel(const QStringList &headers, const QString &data, + QObject *parent = 0); + ~CallTreeModel(); + + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + bool setHeaderData(int section, Qt::Orientation orientation, + const QVariant &value, int role = Qt::EditRole); + + bool insertColumns(int position, int columns, + const QModelIndex &parent = QModelIndex()); + bool removeColumns(int position, int columns, + const QModelIndex &parent = QModelIndex()); + bool insertRows(int position, int rows, + const QModelIndex &parent = QModelIndex()); + bool removeRows(int position, int rows, + const QModelIndex &parent = QModelIndex()); + +private: + void setupModelData(const QStringList &lines, CallTreeItem *parent); + CallTreeItem *getItem(const QModelIndex &index) const; + CallTreeItem *rootItem; +}; + +#endif // CALLTREE_MODEL_H diff --git a/sflphone-client-kde/src/CallTreeView.cpp b/sflphone-client-kde/src/CallTreeView.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4c179fcc0a85573e57a51113e49c4121a314c72 --- /dev/null +++ b/sflphone-client-kde/src/CallTreeView.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + * Copyright (C) 2010 by Savoir-Faire Linux * + * Author : Mathieu Leduc-Hamel * + * mathieu.leduc-hamel@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 "CallTreeView.h" +#include "CallTreeModel.h" +#include "CallTreeItem.h" +#include "Call.h" + +CallTreeView::CallTreeView(QWidget * parent) + : QTreeView(parent) +{ + model = new TreeModel(this); + + setModel(model) +} + +CallTreeView::~CallTreeView() +{ + delete modele; +} + +CallTreeItem* CallTreeView::insert(Call *call) +{ + QModelIndex index = selectionModel()->currentIndex(); + QAbstractItemModel *model = model(); + + if (!model->insertRow(index.row()+1, index.parent())) + { + return; + } + + for (int column = 0; column < model->columnCount(index.parent()); ++column) + { + QModelIndex child = model->index(index.row()+1, column, index.parent()); + model->setData(child, call, Qt::EditRole); + } +} + +CallTreeItem* CallTreeView::insert(CallTreeItem *parent, Call *call) +{ + + +QModelIndex index = view->selectionModel()->currentIndex(); +{ + QAbstractItemModel *model = model(); + + if (model->columnCount(index) == 0) + { + if (!model->insertColumn(0, index)) + { + return; + } + + } + + if (!model->insertRow(0, index)) + { + return; + } + + for (int column = 0; column < model->columnCount(index); ++column) + { + QModelIndex child = model->index(0, column, index); + model->setData(child, QVariant("[No data]"), Qt::EditRole); + if (!model->headerData(column, Qt::Horizontal).isValid()) + model->setHeaderData(column, Qt::Horizontal, QVariant("[No header]"), + Qt::EditRole); + } + + view->selectionModel()->setCurrentIndex(model->index(0, 0, index), + QItemSelectionModel::ClearAndSelect); +} + +void CallTreeView::remove(CallTreeItem *item) +{ + // to implement +} + + diff --git a/sflphone-client-kde/src/CallTreeView.h b/sflphone-client-kde/src/CallTreeView.h new file mode 100644 index 0000000000000000000000000000000000000000..a55decc6d6d6fa8f4ccffe24aaa5e0e639abc046 --- /dev/null +++ b/sflphone-client-kde/src/CallTreeView.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2010 by Savoir-Faire Linux * + * Author : Mathieu Leduc-Hamel * + * mathieu.leduc-hamel@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. * + ***************************************************************************/ + +/** + * http://doc.trolltech.com/4.5/itemviews-editabletreemodel.html + */ + +#ifndef CALLTREE_VIEW_H +#define CALLTREE_VIEW_H + +#include <QTreeView> + +class CallTreeModel; +class CallTreeItem; +class Call; + +class CallTreeView : public QTreeView +{ + Q_OBJECT +private: + CallTreeModel *model; +public: + CallTreeView(QWidget *parent); + ~CallTreeView(); + + CallTreeItem* insert(Call* call); + void remove(CallTreeItem* item); + +}; + +#endif // CALLTREE_VIEW_H diff --git a/sflphone-client-kde/src/SFLPhoneView.cpp b/sflphone-client-kde/src/SFLPhoneView.cpp index 3d03cebc9ec93c7acea083401dbc2f34c64ebd1b..8b60297c02aa44293a676f290fb4f4a1978daf00 100644 --- a/sflphone-client-kde/src/SFLPhoneView.cpp +++ b/sflphone-client-kde/src/SFLPhoneView.cpp @@ -47,6 +47,7 @@ #include "SFLPhone.h" #include "typedefs.h" #include "Dialpad.h" +#include "CallTreeView.h" using namespace KABC; @@ -64,7 +65,10 @@ SFLPhoneView::SFLPhoneView(QWidget *parent) CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance(); errorWindow = new QErrorMessage(this); + callList = new CallList(this); + callTree = new CallTreeView(page_callList); + historyLoaded = false; for(int i = 0 ; i < callList->size() ; i++) @@ -93,7 +97,12 @@ SFLPhoneView::SFLPhoneView(QWidget *parent) QPalette pal = QPalette(palette()); pal.setColor(QPalette::AlternateBase, Qt::lightGray); setPalette(pal); - + +/* listWidget_callList->setSelectionMode(QAbstractItemView::SingleSelection); + listWidget_callList->setDragEnabled(true); + listWidget_callList->setAcceptDrops(true); + listWidget_callList->setDropIndicatorShown(true);*/ + stackedWidget_screen->setCurrentWidget(page_callList); connect(&callManager, SIGNAL(callStateChanged(const QString &, const QString &)), @@ -193,12 +202,12 @@ QErrorMessage * SFLPhoneView::getErrorWindow() void SFLPhoneView::addCallToCallList(Call * call) { - QListWidgetItem * item = call->getItem(); + CallTreeItem * item = call->getItem(); QWidget * widget = call->getItemWidget(); if(item && widget) { - listWidget_callList->addItem(item); - listWidget_callList->setItemWidget(item, widget); + callTree->insert(item); + callTree->setItemWidget(item, widget); } } @@ -231,14 +240,14 @@ void SFLPhoneView::typeString(QString str) if(stackedWidget_screen->currentWidget() == page_callList) { - QListWidgetItem * item = listWidget_callList->currentItem(); + QListWidgetItem * item = callTree->currentItem(); callManager.playDTMF(str); Call *currentCall = 0; Call *candidate = 0; if(item) { - Call *call = callList->findCallByItem(listWidget_callList->currentItem()); + Call *call = callList->findCallByItem(callTree->currentItem()); if(call->getState() == CALL_STATE_CURRENT) { @@ -266,12 +275,12 @@ void SFLPhoneView::typeString(QString str) qDebug() << "Typing when no item is selected. Opening an item."; candidate = callList->addDialingCall(); addCallToCallList(candidate); - listWidget_callList->setCurrentRow(listWidget_callList->count() - 1); + callTree->setCurrentRow(callTree->count() - 1); } if(!currentCall && candidate) { - callList->findCallByItem(listWidget_callList->currentItem())->appendItemText(str); + callList->findCallByItem(callTree->currentItem())->appendItemText(str); } } if(stackedWidget_screen->currentWidget() == page_callHistory) @@ -294,14 +303,14 @@ void SFLPhoneView::backspace() if(stackedWidget_screen->currentWidget() == page_callList) { qDebug() << "In call list."; - QListWidgetItem * item = listWidget_callList->currentItem(); + QListWidgetItem * item = callTree->currentItem(); if(!item) { qDebug() << "Backspace when no item is selected. Doing nothing."; } else { - Call * call = callList->findCallByItem(listWidget_callList->currentItem()); + Call * call = callList->findCallByItem(callTree->currentItem()); if(!call) { qDebug() << "Error : Backspace on unexisting call."; @@ -321,14 +330,14 @@ void SFLPhoneView::escape() if(stackedWidget_screen->currentWidget() == page_callList ) { qDebug() << "In call list."; - QListWidgetItem * item = listWidget_callList->currentItem(); + QListWidgetItem * item = callTree->currentItem(); if(!item) { qDebug() << "Escape when no item is selected. Doing nothing."; } else { - Call * call = callList->findCallByItem(listWidget_callList->currentItem()); + Call * call = callList->findCallByItem(->currentItem()); if(!call) { qDebug() << "Error : Escape on unexisting call."; diff --git a/sflphone-client-kde/src/SFLPhoneView.h b/sflphone-client-kde/src/SFLPhoneView.h index 3b6c97193b490ba10d331417baf36b29d0bf67b7..738eb400df2e0402fa78e8999c8b55510f1e3764 100644 --- a/sflphone-client-kde/src/SFLPhoneView.h +++ b/sflphone-client-kde/src/SFLPhoneView.h @@ -34,6 +34,7 @@ #include "ui_SFLPhoneView_base.h" #include "conf/ConfigurationDialog.h" #include "CallList.h" +#include "CallTreeView.h" #include "AccountWizard.h" #include "Contact.h" #include "AccountList.h" @@ -65,6 +66,7 @@ private: //List of calls in the window, and past ones. //Handles both current calls (dialing, ringing...) and history. CallList * callList; + CallTreeView *callTree; QErrorMessage * errorWindow; //Account used prioritary if defined and registered. If not, the first registered account in accountList is used. static QString priorAccountId; diff --git a/sflphone-client-kde/src/ui/SFLPhoneView_base.ui b/sflphone-client-kde/src/ui/SFLPhoneView_base.ui index 081d9efaa8d92486ebbb34921c70bacbd2ac306a..603bf037b77bfd125f7d23993614a6109c807d2c 100644 --- a/sflphone-client-kde/src/ui/SFLPhoneView_base.ui +++ b/sflphone-client-kde/src/ui/SFLPhoneView_base.ui @@ -32,18 +32,7 @@ <number>0</number> </property> <widget class="QWidget" name="page_callList"> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QListWidget" name="listWidget_callList"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - </layout> + <layout class="QHBoxLayout" name="horizontalLayout_3"/> </widget> <widget class="QWidget" name="page_callHistory"> <layout class="QVBoxLayout" name="verticalLayout_3">