Skip to content
Snippets Groups Projects
Commit 04817e35 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

Fix many treeview bugs, restore call capability, fix many other bugs

parent c7a08e2e
Branches
Tags
No related merge requests found
Showing
with 322 additions and 71 deletions
......@@ -32,6 +32,7 @@ SET( sflphone_client_kde_SRCS
CallTreeItem.cpp
configurationmanager_interface_singleton.cpp
callmanager_interface_singleton.cpp
calllist_interface_singleton.cpp
instance_interface_singleton.cpp
AccountWizard.cpp
AccountItemWidget.cpp
......
......@@ -150,8 +150,9 @@ Call::Call(call_state startState, QString callId, QString peerName, QString peer
this->startTime = NULL;
this->stopTime = NULL;
// this->initCallItemWidget();
emit changed();
}
#include <unistd.h>
Call * Call::buildExistingCall(QString callId)
{
CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
......@@ -745,5 +746,4 @@ void Call::changeCurrentState(call_state newState)
currentState = newState;
emit changed();
}
}
\ No newline at end of file
......@@ -244,8 +244,6 @@ public:
static history_state getHistoryStateFromDaemonCallState(QString daemonCallState, QString daemonCallType);
//Getters
// QWidget * getItemWidget();
// QWidget * getHistoryItemWidget();
call_state getState() const;
QString getCallId() const;
QString getPeerPhoneNumber() const;
......
......@@ -37,7 +37,7 @@ CallList::CallList(QObject * parent)
{
calls->append(Call::buildExistingCall(callList[i]));
}
MapStringString historyMap = configurationManager.getHistory().value();
MapStringString historyMap = configurationManager.getHistory().value();
qDebug() << "Call History = " << historyMap;
QMapIterator<QString, QString> i(historyMap);
while (i.hasNext()) {
......@@ -195,3 +195,10 @@ void CallList::clearHistory()
{ i.remove(); }
}
}
Call * CallList::createConversationFromCall(Call* call1, Call* call2) {
qDebug() << "Need to join calls";
CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
//callManager.joinConference(call1->getCallId(),call2->getCallId());
callManager.joinParticipant(call1->getCallId(),call2->getCallId());
}
\ No newline at end of file
......@@ -56,6 +56,7 @@ public:
Call * addDialingCall(const QString & peerName = "", QString account = "");
Call * addIncomingCall(const QString & callId/*, const QString & from, const QString & account*/);
Call * addRingingCall(const QString & callId);
Call * createConversationFromCall(Call* call1, Call* call2);
//GSetter
QString generateCallId();
......
......@@ -37,6 +37,15 @@ CallTreeItem::CallTreeItem(const QVector<QVariant> &data, CallTreeItem *parent)
{
}
CallTreeItem::CallTreeItem(const CallTreeItem *toCopy, CallTreeItem *parent)
: parentItem(parent),
itemCall(toCopy->itemCall),
itemWidget(toCopy->itemWidget),
itemData(toCopy->itemData)
{
}
CallTreeItem::~CallTreeItem()
{
......@@ -161,8 +170,10 @@ QWidget* CallTreeItem::widget() const
bool CallTreeItem::setData(int column, const QVariant &value)
{
itemData.resize(10);
if (column < 0 || column >= itemData.size())
{
qDebug() << "Je suis ici!!!! " << itemData;
return false;
}
......@@ -178,10 +189,12 @@ void CallTreeItem::setCall(Call *call)
itemWidget = new QWidget();
labelIcon = new QLabel();
labelCallNumber = new QLabel(itemCall->getPeerPhoneNumber());
//labelCallNumber = new QLabel("123"/*itemCall->getPeerPhoneNumber()*/);
labelCallNumber2 = new QLabel(itemCall->getPeerPhoneNumber());
labelTransferPrefix = new QLabel(i18n("Transfer to : "));
labelTransferNumber = new QLabel();
QSpacerItem * horizontalSpacer = new QSpacerItem(16777215, 20, QSizePolicy::Preferred, QSizePolicy::Minimum);
QSpacerItem * verticalSpacer = new QSpacerItem(16777215, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);
QHBoxLayout * mainLayout = new QHBoxLayout();
mainLayout->setContentsMargins ( 3, 1, 2, 1);
......@@ -194,17 +207,20 @@ void CallTreeItem::setCall(Call *call)
transfer->setMargin(0);
transfer->setSpacing(0);
mainLayout->addWidget(labelIcon);
if(! itemCall->getPeerName().isEmpty())
{
labelPeerName = new QLabel(itemCall->getPeerName());
descr->addWidget(labelPeerName);
}
descr->addWidget(labelCallNumber);
descr->addWidget(labelCallNumber2);
transfer->addWidget(labelTransferPrefix);
transfer->addWidget(labelTransferNumber);
descr->addLayout(transfer);
descr->addItem(verticalSpacer);
mainLayout->addLayout(descr);
mainLayout->addItem(horizontalSpacer);
//mainLayout->addItem(horizontalSpacer);
itemWidget->setLayout(mainLayout);
itemWidget->setMinimumSize(QSize(50, 30));
......@@ -239,11 +255,18 @@ void CallTreeItem::updated()
{
labelTransferNumber->setText("");
}
labelTransferNumber->setText(itemCall->getTransferNumber());
labelCallNumber->setText(itemCall->getCallNumber());
//labelTransferNumber->setText(itemCall->getTransferNumber());
labelCallNumber2->setText(itemCall->getPeerPhoneNumber());
if(state == CALL_STATE_DIALING)
{
labelCallNumber2->setText(itemCall->getCallNumber());
}
}
else
{
emit over(itemCall);
itemWidget->setVisible(false);
qDebug() << "Updating item of call of state OVER. Doing nothing.";
}
......
......@@ -43,6 +43,7 @@ class CallTreeItem : public QObject
Q_OBJECT
public:
CallTreeItem(const QVector<QVariant> &data, CallTreeItem *parent);
CallTreeItem(const CallTreeItem *toCopy, CallTreeItem *parent);
~CallTreeItem();
CallTreeItem *child(int number);
......@@ -70,7 +71,7 @@ class CallTreeItem : public QObject
QLabel * labelIcon;
QLabel * labelPeerName;
QLabel * labelCallNumber;
QLabel * labelCallNumber2;
QLabel * labelTransferPrefix;
QLabel * labelTransferNumber;
......@@ -79,9 +80,12 @@ class CallTreeItem : public QObject
QLabel * labelHistoryPeerName;
QLabel * labelHistoryCallNumber;
QLabel * labelHistoryTime;
friend class CallTreeItem;
private slots:
public slots:
void updated();
signals:
void over(Call*);
};
#endif // CALLTREE_ITEM_H
......@@ -24,6 +24,7 @@
#include "CallTreeModel.h"
#include "CallTreeItem.h"
#include "calllist_interface_singleton.h"
CallTreeModel::CallTreeModel(QObject *parent)
: QAbstractItemModel(parent),
......@@ -91,7 +92,7 @@ Qt::ItemFlags CallTreeModel::flags(const QModelIndex &index) const
{
return 0;
}
Qt::ItemFlags val = Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
Qt::ItemFlags val = Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
return val;
}
......@@ -223,6 +224,9 @@ bool CallTreeModel::setData(const QModelIndex &index, const QVariant &value, int
CallTreeItem *item = getItem(index);
bool result = item->setData(index.column(), value);
//item->setData(1, QString("test"));
//item->setData(2, QString("test2"));
if (result)
{
......@@ -315,3 +319,84 @@ void CallTreeModel::setupModelData(const QStringList &lines, CallTreeItem *paren
number++;
}
}
Qt::DropActions CallTreeModel::supportedDropActions()
{
return Qt::MoveAction;// | Qt::CopyAction ;
}
bool CallTreeModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ) {
if (action == Qt::IgnoreAction)
return true;
if (!data->hasFormat("application/vnd.text.list"))
return false;
if (column > 0)
return false;
int beginRow;
if (row != -1)
beginRow = row;
else if (parent.isValid())
beginRow = parent.row();
else
beginRow = rowCount(QModelIndex());
CallTreeItem *item = getItem(parent);
QByteArray encodedData = data->data("application/vnd.text.list");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QStringList newItems;
int rows = 0;
while (!stream.atEnd()) {
QString text;
stream >> text;
newItems << text;
++rows;
}
if (rows) {
Call* secondCall = CallListInterfaceSingleton::getInstance().findCallByCallId(newItems[0]);
Call* conVersation = CallListInterfaceSingleton::getInstance().createConversationFromCall(item->call(), secondCall);
emit joinCall(newItems[0], item->call()->getCallId());
insertRows(beginRow, rows, parent);
foreach (QString text, newItems) {
QModelIndex idx = index(beginRow, 0, parent);
setData(idx, "test");
beginRow++;
}
}
else
qDebug() << "Unknow drop";
return true;
}
//This can be modified later to implement an universal drag and drop
QStringList CallTreeModel::mimeTypes() const
{
QStringList types;
types << "application/vnd.text.list";
return types;
}
QMimeData* CallTreeModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
CallTreeItem *item = getItem(index);
stream << item->call()->getCallId();
}
}
mimeData->setData("application/vnd.text.list", encodedData);
return mimeData;
}
\ No newline at end of file
......@@ -61,12 +61,21 @@ public:
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());
Qt::DropActions supportedDropActions();
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
QStringList mimeTypes() const;
QMimeData* mimeData(const QModelIndexList &indexes) const;
CallTreeItem *getItem(const QModelIndex &index) const;
private:
void setupModelData(const QStringList &lines, CallTreeItem *parent);
CallTreeItem *rootItem;
signals:
void joinCall(QString callId1, QString callId2);
void over(Call*);
};
#endif // CALLTREE_MODEL_H
......@@ -25,12 +25,15 @@
#include "CallTreeModel.h"
#include "CallTreeItem.h"
#include "Call.h"
#include <QDebug>
CallTreeView::CallTreeView(QWidget * parent)
: QTreeView(parent)
{
treeModel = new CallTreeModel(this);
setModel(treeModel);
CallTreeItemDelegate *delegate = new CallTreeItemDelegate();
setItemDelegate(delegate);
setHeaderHidden(true);
setRootIsDecorated(false);
setSelectionMode(QAbstractItemView::SingleSelection);
......@@ -38,6 +41,17 @@ CallTreeView::CallTreeView(QWidget * parent)
setAcceptDrops(true);
setUniformRowHeights(true);
setDropIndicatorShown(true);
//setDragDropMode(QAbstractItemView::DragDrop);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setDragEnabled(TRUE);
setAcceptDrops(TRUE);
setDropIndicatorShown(TRUE);
connect(this , SIGNAL(clicked(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
connect(treeModel, SIGNAL(joinCall(QString,QString)), this, SLOT(joinCall(QString, QString)));
connect(treeModel, SIGNAL(joinCall(QString,QString)), this, SLOT(expandAll()));
connect(treeModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex& ) ), this, SLOT(adaptColumns(const QModelIndex &, const QModelIndex&) ) );
}
CallTreeView::~CallTreeView()
......@@ -56,12 +70,27 @@ CallTreeItem* CallTreeView::insert(Call *call)
{
return 0;
}
QModelIndex child = model()->index(index.row()+1, 0, index.parent());
treeModel->setData(child, QVariant(""), Qt::EditRole);
QModelIndex child = model()->index(index.row()+1, 0, index.parent());
treeModel->setData(child, QVariant(""), Qt::EditRole);
for (int column = 1; column < treeModel->columnCount(index); ++column)
{
QModelIndex child2 = treeModel->index(index.row()+1, column, index.parent());
treeModel->setData(child2, QString("test"), Qt::EditRole);
}
item = treeModel->getItem(child);
item->setCall(call);
item->setCall(call);
// qDebug() << "Will connect, id " << call << ", " << call->getPeerPhoneNumber();
// connect(call, SIGNAL(changed()), item, SLOT(updated()));
// item->setCall(call);
// item->setData(1,call->getPeerPhoneNumber());
// item->setData(2,call->getPeerName());
// resizeColumnToContents(0);
// resizeColumnToContents(1);
// resizeColumnToContents(2);
// //item->updated();
setIndexWidget(child, item->widget());
}
......@@ -88,7 +117,8 @@ CallTreeItem* CallTreeView::insert(CallTreeItem *parent, Call *call)
for (int column = 0; column < treeModel->columnCount(index); ++column)
{
QModelIndex child = treeModel->index(0, column, index);
treeModel->setData(child, QVariant(""), Qt::EditRole);
qDebug() << "I just added data: 0, " << column << " \n\n\n\n";
treeModel->setData(child, QVariant(""), Qt::EditRole);
}
item->setCall(call);
......@@ -103,6 +133,16 @@ void CallTreeView::remove(QModelIndex & index) const
{
treeModel->removeRow(index.row(), index.parent());
}
#include <unistd.h>
void CallTreeView::remove(Call* call) const //BUG not used
{
for(int i=0; i < 15/* model.rowCount()*/;i++) { //TODO anything better
QModelIndex anIndex = this->indexAt(QPoint(0,i));
if (anIndex.isValid()) {
qDebug() << "This index is valid";
}
}
}
void CallTreeView::removeCurrent() const
{
......@@ -137,43 +177,35 @@ void CallTreeView::setCurrentRow(int row)
selectionModel()->setCurrentIndex(index, QItemSelectionModel::Current);
}
int CallTreeView::count()
{
return model()->rowCount();
}
bool CallTreeView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
{/*
= data->data("items/index");
foreach(QModelIndex index, callList) // iterate over list
{
CallTreeItem *item = static_cast<CallTreeItem*>(index.internalPointer());
if (parent == NULL)
{
// make new QTreeWidgetItem and set its text
// if parent is null - add top level item (this parent)
insert(item->call());
}
else
{
// else add QTreeWidgetItem with parent and expand parent
insert(parent, item->call());
parent->setExpanded( true );
}
} */
return true;
}
QStringList CallTreeView::mimeTypes() const
{
}
Qt::DropActions CallTreeView::supportedDropActions () const
{
return Qt::CopyAction | Qt::MoveAction;
}
void CallTreeView::itemClicked(const QModelIndex& anIndex)
{
if (currentModel != anIndex)
emit itemChanged();
currentModel = anIndex;
}
void CallTreeView::adaptColumns (const QModelIndex & topleft, const QModelIndex& bottomRight)
{
int firstColumn= topleft.column();
int lastColumn = bottomRight.column();
do {
//if (firstColumn) //TODO remove this and fix the resulting bug
resizeColumnToContents(firstColumn);
firstColumn++;
} while (firstColumn < lastColumn);
}
\ No newline at end of file
......@@ -27,6 +27,7 @@
#define CALLTREE_VIEW_H
#include <QTreeView>
#include <QItemDelegate>
class CallTreeModel;
class CallTreeItem;
......@@ -35,27 +36,43 @@ class QModelIndex;
class QTreeWidgetItem;
class QMimeData;
class CallTreeItemDelegate : public QItemDelegate
{
public:
CallTreeItemDelegate() { }
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const { return QSize(0,50); }
};
class CallTreeView : public QTreeView
{
Q_OBJECT
public:
CallTreeView(QWidget *parent);
~CallTreeView();
CallTreeItem* insert(CallTreeItem *item, Call* call);
CallTreeItem* insert(Call* call);
void remove(QModelIndex & index) const;
void removeCurrent() const;
CallTreeItem* currentItem();
CallTreeItem* getItem(const QModelIndex &index);
void setCurrentRow(int row);
int count();
bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action);
QStringList mimeTypes() const;
Qt::DropActions supportedDropActions () const;
CallTreeItem* insert(Call* call);
CallTreeItem* insert(CallTreeItem *item, Call* call);
// protected:
// void dropEvent(QDropEvent* event);
//
private:
CallTreeModel *treeModel;
QModelIndex currentModel;
public slots:
void remove(Call* call) const;
private slots:
void itemClicked(const QModelIndex& anIndex);
void adaptColumns(const QModelIndex & topleft, const QModelIndex& bottomRight);
signals:
void currentItemChanged();
void itemChanged();
......
......@@ -230,19 +230,21 @@ void SFLPhone::quitButton()
}
void SFLPhone::sendNotif(QString caller)
{/*
notification = new KNotification ( QString("test_notification"), this );
notification->setText("messageText") ;
notification->setPixmap( QPixmap( this->windowIcon().pixmap(32, 32) ));
notification->setActions( QStringList( i18n( "Open chat" ) ) );
notification->addContext( QString::fromLatin1("call") , "caller" ) ;
notification->sendEvent();*/
/* KNotification::event(QString("test_notification"),
QString("Allo"),
this->windowIcon().pixmap(32, 32),
parentWidget(),
KNotification::CloseOnTimeout,
KGlobal::mainComponent());*/
{
// notification = new KNotification ( QString("test_notification"), this );
// notification->setText("messageText") ;
// notification->setPixmap( QPixmap( this->windowIcon().pixmap(32, 32) ));
// notification->setActions( QStringList( i18n( "Open chat" ) ) );
// notification->addContext( QString::fromLatin1("call") , "caller" ) ;
// notification->sendEvent();
// KNotification::event(QString("test_notification"),
// QString("Allo"),
// this->windowIcon().pixmap(32, 32),
// parentWidget(),
// KNotification::CloseOnTimeout,
// KGlobal::mainComponent());
KNotification::event(KNotification::Notification, "New incomming call", "New call from: \n" + caller);
}
void SFLPhone::changeEvent(QEvent * event)
......
......@@ -41,6 +41,7 @@
#include "sflphone_const.h"
#include "conf/ConfigurationSkeleton.h"
#include "configurationmanager_interface_singleton.h"
#include "calllist_interface_singleton.h"
#include "callmanager_interface_singleton.h"
#include "instance_interface_singleton.h"
#include "ActionSetAccountFirst.h"
......@@ -68,7 +69,7 @@ SFLPhoneView::SFLPhoneView(QWidget *parent)
errorWindow = new QErrorMessage(this);
callList = new CallList(this);
callList = & CallListInterfaceSingleton::getInstance(); //CallList(this);
callTree = new CallTreeView(page_callList);
historyTree = new CallTreeView(page_callHistory);
......@@ -135,12 +136,13 @@ SFLPhoneView::SFLPhoneView(QWidget *parent)
connect(accountList, SIGNAL(accountListUpdated()),
this, SLOT(updateWindowCallState()));
connect(callTree, SIGNAL(currentItemChanged()),
connect(callTree, SIGNAL(itemChanged()), //currentItemChanged
this, SLOT(on_callTree_currentItemChanged()));
connect(callTree, SIGNAL(itemChanged()),
connect(callTree, SIGNAL(itemChanged()), //ITem changed
this, SLOT(on_callTree_itemChanged()));
connect(callTree, SIGNAL(itemDoubleClicked(const QModelIndex &)),
connect(callTree, SIGNAL(doubleClicked(const QModelIndex &)),
this, SLOT(on_callTree_itemDoubleClicked(const QModelIndex&)));
}
......@@ -1011,7 +1013,7 @@ void SFLPhoneView::on_toolButton_sndVol_clicked(bool checked)
updateVolumeButton();
}
#include <unistd.h>
void SFLPhoneView::on_callTree_currentItemChanged()
{
qDebug() << "on_callTree_currentItemChanged";
......@@ -1492,4 +1494,6 @@ void SFLPhoneView::changeScreen(int screen)
emit screenChanged(screen);
}
#include "SFLPhoneView.moc"
/***************************************************************************
* 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 "calllist_interface_singleton.h"
CallList* CallListInterfaceSingleton::callListInstance = 0;
CallList& CallListInterfaceSingleton::getInstance()
{
if (!CallListInterfaceSingleton::callListInstance)
CallListInterfaceSingleton::callListInstance = new CallList(0);
return *CallListInterfaceSingleton::callListInstance;
}
\ No newline at end of file
/***************************************************************************
* Copyright (C) 2009 by Savoir-Faire Linux *
* Author : Jérémy Quentin *
* emmanuel.lepage@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 CALLLIST_S_H
#define CALLLIST_S_H
#include "CallList.h"
/**
@author Emmanuel Lepage <emmanuel.lepage@savoirfairelinux.com>
*/
class CallListInterfaceSingleton
{
public:
static CallList& getInstance();
//private:
static CallList* callListInstance;
};
#endif
......@@ -186,7 +186,8 @@
#define ACCOUNT_STATE_ERROR_EXIST_STUN "ERROR_EXIST_STUN"
/** Calls details */
#define CALL_PEER_NAME "PEER_NAME"
#define CALL_PEER_NAME "DISPLAY_NAME"
//#define CALL_PEER_NAME "PEER_NAME"
#define CALL_PEER_NUMBER "PEER_NUMBER"
#define CALL_ACCOUNTID "ACCOUNTID"
#define CALL_STATE "CALL_STATE"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment