diff --git a/kde/src/AkonadiBackend.cpp b/kde/src/AkonadiBackend.cpp index 67be33b30dcd52530a9d80af6a9e7df26186a134..d8bbf60953bfd737876b70a83a6063a127563338 100644 --- a/kde/src/AkonadiBackend.cpp +++ b/kde/src/AkonadiBackend.cpp @@ -69,6 +69,7 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection) newNumbers << new Contact::PhoneNumber(number.number(),number.typeLabel()); m_pContactByPhone[number.number()] = aContact; } + m_pContactByUid[tmp.uid()] = aContact; aContact->setNickName (tmp.nickName() ); aContact->setFormattedName (tmp.formattedName() ); @@ -103,6 +104,11 @@ Contact* AkonadiBackend::getContactByPhone(QString phoneNumber) return m_pContactByPhone[phoneNumber]; } +Contact* AkonadiBackend::getContactByUid(QString uid) +{ + return m_pContactByUid[uid]; +} + void AkonadiBackend::collectionsReceived( const Akonadi::Collection::List& list) { foreach (Akonadi::Collection coll, list) { diff --git a/kde/src/AkonadiBackend.h b/kde/src/AkonadiBackend.h index e43984aeb164510b96da6b01102a44326f66c01f..c58e0430d94abf6918f0c261f79f2050014311b3 100644 --- a/kde/src/AkonadiBackend.h +++ b/kde/src/AkonadiBackend.h @@ -16,17 +16,17 @@ class AkonadiBackend : public QObject { public: static AkonadiBackend* getInstance(); Contact* getContactByPhone(QString phoneNumber); + Contact* getContactByUid(QString uid); private: AkonadiBackend(QObject* parent); virtual ~AkonadiBackend(); - - //Attributes static AkonadiBackend* m_pInstance; Akonadi::Session* m_pSession; Akonadi::Collection m_pCollection; QHash<QString,Contact*> m_pContactByPhone; + QHash<QString,Contact*> m_pContactByUid; public slots: ContactList update(); ContactList update(Akonadi::Collection collection); diff --git a/kde/src/CallView.cpp b/kde/src/CallView.cpp index b0d2532bed0ce2ec8000c5b0d41b8807355136b6..e9dd08c2e037d58e6b8237973e6725a0522e16e6 100644 --- a/kde/src/CallView.cpp +++ b/kde/src/CallView.cpp @@ -1,7 +1,11 @@ #include "CallView.h" +#include "AkonadiBackend.h" +#include "lib/Contact.h" + +#include <QtGui/QInputDialog> ///Retrieve current and older calls from the daemon, fill history and the calls TreeView and enable drag n' drop -CallView::CallView(ModelType type, QWidget* parent) : QTreeWidget(parent), CallModel<CallTreeItem*,QTreeWidgetItem*>(type) +CallView::CallView(ModelType type, QWidget* parent) : QTreeWidget(parent), TreeWidgetCallModel(type) { if (type == ActiveCall) initCall(); @@ -46,21 +50,14 @@ CallView::CallView(ModelType type, QWidget* parent) : QTreeWidget(parent), CallM * * ****************************************************************************/ -///Action performed when an item is dropped on the TreeView -bool CallView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) +bool CallView::callToCall(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) { Q_UNUSED(index) Q_UNUSED(action) - QByteArray encodedCallId = data->data( MIME_CALLID ); - QByteArray encodedPhoneNumber = data->data( MIME_PHONENUMBER ); - - qDebug() << "In export"<< QString(encodedCallId); - qDebug() << "In export2"<< QString(encodedPhoneNumber); - if (!QString(encodedCallId).isEmpty()) { - clearArtefact(getIndex(encodedCallId)); - + clearArtefact(getIndex(encodedCallId)); + if (!parent) { qDebug() << "Call dropped on empty space"; if (getIndex(encodedCallId)->parent()) { @@ -71,12 +68,12 @@ bool CallView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData qDebug() << "The call is not in a conversation (doing nothing)"; return true; } - + if (getCall(parent)->getCallId() == QString(encodedCallId)) { qDebug() << "Call dropped on itself (doing nothing)"; return true; } - + if ((parent->childCount()) && (getIndex(encodedCallId)->childCount())) { qDebug() << "Merging two conferences"; mergeConferences(getCall(parent),getCall(encodedCallId)); @@ -84,15 +81,15 @@ bool CallView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData } else if ((parent->parent()) || (parent->childCount())) { qDebug() << "Call dropped on a conference"; - + if ((getIndex(encodedCallId)->childCount()) && (!parent->childCount())) { qDebug() << "Conference dropped on a call (doing nothing)"; return true; } - + QTreeWidgetItem* call1 = getIndex(encodedCallId); QTreeWidgetItem* call2 = (parent->parent())?parent->parent():parent; - + if (call1->parent()) { qDebug() << "Call 1 is part of a conference"; if (call1->parent() == call2) { @@ -109,6 +106,14 @@ bool CallView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData } } qDebug() << "Adding participant"; + int state = getCall(call1)->getState(); + if(state == CALL_STATE_INCOMING || state == CALL_STATE_DIALING || state == CALL_STATE_TRANSFER || state == CALL_STATE_TRANSF_HOLD) { + getCall(call1)->actionPerformed(CALL_ACTION_ACCEPT); + } + state = getCall(call2)->getState(); + if(state == CALL_STATE_INCOMING || state == CALL_STATE_DIALING || state == CALL_STATE_TRANSFER || state == CALL_STATE_TRANSF_HOLD) { + getCall(call2)->actionPerformed(CALL_ACTION_ACCEPT); + } addParticipant(getCall(call1),getCall(call2)); return true; } @@ -116,14 +121,135 @@ bool CallView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData qDebug() << "Call dropped on it's own conference (doing nothing)"; return true; } - - + + qDebug() << "Call dropped on another call"; createConferenceFromCall(getCall(encodedCallId),getCall(parent)); return true; } + return false; +} + +bool CallView::phoneNumberToCall(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) +{ + Q_UNUSED(index) + Q_UNUSED(action) + QByteArray encodedPhoneNumber = data->data( MIME_PHONENUMBER ); + if (!QString(encodedPhoneNumber).isEmpty()) { + Contact* contact = AkonadiBackend::getInstance()->getContactByPhone(encodedPhoneNumber); + QString name; + if (contact) + name = contact->getFormattedName(); + else + name = "Unknow"; + Call* call2 = TreeWidgetCallModel::addDialingCall(name, TreeWidgetCallModel::getCurrentAccountId()); + call2->appendText(QString(encodedPhoneNumber)); + if (!parent) { + //Dropped on free space + qDebug() << "Adding new dialing call"; + } + else if (parent->childCount() || parent->parent()) { + //Dropped on a conversation + QTreeWidgetItem* call = (parent->parent())?parent->parent():parent; + addParticipant(getCall(call),call2); + } + else { + //Dropped on call + call2->actionPerformed(CALL_ACTION_ACCEPT); + int state = getCall(parent)->getState(); + if(state == CALL_STATE_INCOMING || state == CALL_STATE_DIALING || state == CALL_STATE_TRANSFER || state == CALL_STATE_TRANSF_HOLD) { + getCall(parent)->actionPerformed(CALL_ACTION_ACCEPT); + } + createConferenceFromCall(call2,getCall(parent)); + } + } + return false; +} + +bool CallView::contactToCall(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) +{ + qDebug() << "contactToCall"; + Q_UNUSED(index) + Q_UNUSED(action) + QByteArray encodedContact = data->data( MIME_CONTACT ); + if (!QString(encodedContact).isEmpty()) { + Contact* contact = AkonadiBackend::getInstance()->getContactByUid(encodedContact); + qDebug() << "Contact:" << contact; + if (contact) { + qDebug() << "In contact"; + Call* call2; + if (contact->getPhoneNumbers().count() == 1) { + call2 = TreeWidgetCallModel::addDialingCall(contact->getFormattedName(), TreeWidgetCallModel::getCurrentAccountId()); + call2->appendText(contact->getPhoneNumbers()[0]->getNumber()); + } + else if (contact->getPhoneNumbers().count() > 1) { + bool ok = false; + QHash<QString,QString> map; + QStringList list; + foreach (Contact::PhoneNumber* number, contact->getPhoneNumbers()) { + map[number->getType()+" ("+number->getNumber()+")"] = number->getNumber(); + list << number->getType()+" ("+number->getNumber()+")"; + } + QString result = QInputDialog::getItem (this, QString("Select phone number"), QString("This contact have many phone number, please select the one you wish to call"), list, 0, false, &ok); + if (ok) { + call2 = TreeWidgetCallModel::addDialingCall(contact->getFormattedName(), TreeWidgetCallModel::getCurrentAccountId()); + call2->appendText(map[result]); + } + else { + qDebug() << "Operation cancelled"; + return false; + } + } + else { + qDebug() << "This contact have no valid phone number"; + return false; + } + if (!parent) { + //Dropped on free space + qDebug() << "Adding new dialing call"; + } + else if (parent->childCount() || parent->parent()) { + //Dropped on a conversation + QTreeWidgetItem* call = (parent->parent())?parent->parent():parent; + addParticipant(getCall(call),call2); + } + else { + //Dropped on call + call2->actionPerformed(CALL_ACTION_ACCEPT); + int state = getCall(parent)->getState(); + if(state == CALL_STATE_INCOMING || state == CALL_STATE_DIALING || state == CALL_STATE_TRANSFER || state == CALL_STATE_TRANSF_HOLD) { + getCall(parent)->actionPerformed(CALL_ACTION_ACCEPT); + } + createConferenceFromCall(call2,getCall(parent)); + } + } + } + return false; +} + +///Action performed when an item is dropped on the TreeView +bool CallView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) +{ + Q_UNUSED(index) + Q_UNUSED(action) + QByteArray encodedCallId = data->data( MIME_CALLID ); + QByteArray encodedPhoneNumber = data->data( MIME_PHONENUMBER ); + QByteArray encodedContact = data->data( MIME_CONTACT ); + + if (!QString(encodedCallId).isEmpty()) { + qDebug() << "CallId dropped"<< QString(encodedCallId); + callToCall(parent, index, data, action); + } + else if (!QString(encodedPhoneNumber).isEmpty()) { + qDebug() << "PhoneNumber dropped"<< QString(encodedPhoneNumber); + phoneNumberToCall(parent, index, data, action); + } + else if (!QString(encodedContact).isEmpty()) { + qDebug() << "Contact dropped"<< QString(encodedContact); + contactToCall(parent, index, data, action); + } return false; } @@ -350,7 +476,7 @@ void CallView::itemClicked(QTreeWidgetItem* item, int column) { Call* CallView::addConference(const QString & confID) { qDebug() << "Conference created"; - Call* newConf = CallModel<CallTreeItem*,QTreeWidgetItem*>::addConference(confID); + Call* newConf = TreeWidgetCallModel::addConference(confID); //InternalCallModelStruct<CallTreeItem>* aNewStruct = privateCallList_callId[confID]; @@ -387,7 +513,7 @@ Call* CallView::addConference(const QString & confID) bool CallView::conferenceChanged(const QString &confId, const QString &state) { qDebug() << "Conference changed"; - if (!CallModel<CallTreeItem*,QTreeWidgetItem*>::conferenceChanged(confId, state)) + if (!TreeWidgetCallModel::conferenceChanged(confId, state)) return false; CallManagerInterface& callManager = CallManagerInterfaceSingleton::getInstance(); @@ -421,7 +547,7 @@ void CallView::conferenceRemoved(const QString &confId) insertItem(extractItem(getIndex(confId)->child(0))); } takeTopLevelItem(indexOfTopLevelItem(getIndex(confId))); - CallModel<CallTreeItem*,QTreeWidgetItem*>::conferenceRemoved(confId); + TreeWidgetCallModel::conferenceRemoved(confId); qDebug() << "Conference removed"; } diff --git a/kde/src/CallView.h b/kde/src/CallView.h index bcdbeb9eca3071e1cb93c1d097409eb6db0d8cf2..717903014baa77f780f9c120937ae59e23aec638 100644 --- a/kde/src/CallView.h +++ b/kde/src/CallView.h @@ -22,7 +22,9 @@ class CallTreeItemDelegate : public QItemDelegate } }; -class CallView : private QTreeWidget, public CallModel<CallTreeItem*,QTreeWidgetItem*> { +typedef CallModel<CallTreeItem*,QTreeWidgetItem*> TreeWidgetCallModel; + +class CallView : private QTreeWidget, public TreeWidgetCallModel { Q_OBJECT public: CallView(ModelType type, QWidget* parent =0); @@ -48,6 +50,9 @@ class CallView : private QTreeWidget, public CallModel<CallTreeItem*,QTreeWidget protected: void dragEnterEvent(QDragEnterEvent *e) { e->accept(); } void dragMoveEvent(QDragMoveEvent *e) { e->accept(); } + bool callToCall(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action); + bool phoneNumberToCall(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action); + bool contactToCall(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action); public slots: void destroyCall(Call* toDestroy); diff --git a/kde/src/SFLPhone.h b/kde/src/SFLPhone.h index a445e1ad597030c92fe57532fca9caa863d3f00d..23ee08b52963b4742426b8b169ea5920dfc66fba 100755 --- a/kde/src/SFLPhone.h +++ b/kde/src/SFLPhone.h @@ -76,8 +76,8 @@ enum CallAction { NumberOfCallActions}; private: - // Whether or not the object has been initialized - bool initialized_; + // Whether or not the object has been initialized + bool initialized_; KAction * action_accept; KAction * action_refuse; KAction * action_hold; diff --git a/kde/src/conf/dlgaccounts.cpp b/kde/src/conf/dlgaccounts.cpp index 65f20c731934608ce6a51f2b65defaa7ae08bd75..80d0b3773cdb4bbd066efecb99cf3394ae723999 100755 --- a/kde/src/conf/dlgaccounts.cpp +++ b/kde/src/conf/dlgaccounts.cpp @@ -253,14 +253,25 @@ void DlgAccounts::saveAccount(QListWidgetItem * item) account->setAccountDetail(LOCAL_INTERFACE,comboBox_ni_local_address->currentText()); QStringList _codecList; + qDebug() << keditlistbox_codec->items() << codecList; foreach (QString aCodec, keditlistbox_codec->items()) { foreach (StringHash _aCodec, codecList) { if (_aCodec["alias"] == aCodec) { + qDebug() << "Saving:" << _aCodec["id"]; _codecList << _aCodec["id"]; } } +// } +// foreach (QString aCodec, keditlistbox_codec->items()) { +// foreach (StringHash aCodec, codecList) { +// if (aCodec["alias"] == keditlistbox_codec->currentText()) { +// label_bandwidth_value->setText(aCodec["bandwidth"]); +// label_bitrate_value->setText(aCodec["bitrate"]); +// label_frequency_value->setText(aCodec["frequency"]); +// } +// } } - + ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); configurationManager.setActiveAudioCodecList(_codecList, account->getAccountDetail(ACCOUNT_ID)); qDebug() << "Account codec have been saved" << _codecList << account->getAccountDetail(ACCOUNT_ID); @@ -368,10 +379,11 @@ void DlgAccounts::loadAccount(QListWidgetItem * item) keditlistbox_codec->clear(); ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); QStringList activeCodecList = configurationManager.getActiveAudioCodecList(account->getAccountDetail(ACCOUNT_ID)); + qDebug() << "Active codecs" << activeCodecList; foreach (QString aCodec, activeCodecList) { foreach (StringHash _aCodec, codecList) { - if (_aCodec["id"] == aCodec) - keditlistbox_codec->insertItem(_aCodec["alias"]); +; if (_aCodec["id"] == aCodec) + keditlistbox_codec->insertItem(_aCodec["alias"]); } } @@ -623,7 +635,7 @@ void DlgAccounts::loadCodecList() _codec["frequency"] = codec[1]; _codec["bitrate"] = codec[2]; _codec["bandwidth"] = ""; //TODO remove - _codec["id"] = aCodec; + _codec["id"] = QString::number(aCodec); tmpNameList << _codec["name"]; diff --git a/kde/src/conf/dlgaccountsbase.ui b/kde/src/conf/dlgaccountsbase.ui index 7da7aa130c448d7864b1c62a4784e53d15ffaf70..29a0fe63ba81f9fac639d7fb3bbd140104f29b36 100755 --- a/kde/src/conf/dlgaccountsbase.ui +++ b/kde/src/conf/dlgaccountsbase.ui @@ -456,7 +456,11 @@ </widget> </item> <item row="1" column="1"> - <widget class="QSpinBox" name="spinBox_ni_local_port"/> + <widget class="QSpinBox" name="spinBox_ni_local_port"> + <property name="maximum"> + <number>65535</number> + </property> + </widget> </item> <item row="0" column="2"> <spacer name="horizontalSpacer_8"> @@ -509,7 +513,11 @@ </widget> </item> <item row="4" column="1" colspan="2"> - <widget class="QSpinBox" name="spinBox_pa_published_port"/> + <widget class="QSpinBox" name="spinBox_pa_published_port"> + <property name="maximum"> + <number>65535</number> + </property> + </widget> </item> <item row="3" column="1"> <widget class="QLineEdit" name="lineEdit_pa_published_address"/> @@ -777,8 +785,8 @@ <rect> <x>0</x> <y>0</y> - <width>536</width> - <height>758</height> + <width>539</width> + <height>660</height> </rect> </property> <layout class="QGridLayout" name="gridLayout_5"> @@ -1156,6 +1164,11 @@ </layout> </widget> <customwidgets> + <customwidget> + <class>KEditListBox</class> + <extends>QGroupBox</extends> + <header>keditlistbox.h</header> + </customwidget> <customwidget> <class>KIntSpinBox</class> <extends>QSpinBox</extends> @@ -1166,11 +1179,6 @@ <extends>QFrame</extends> <header>kurlrequester.h</header> </customwidget> - <customwidget> - <class>KEditListBox</class> - <extends>QGroupBox</extends> - <header>keditlistbox.h</header> - </customwidget> <customwidget> <class>KLineEdit</class> <extends>QLineEdit</extends> diff --git a/kde/src/widgets/ContactDock.cpp b/kde/src/widgets/ContactDock.cpp index ee80de641e451566583f9c725852c56956ca7d62..d14e62e2e2c95cf1b8967a589ab4c663df72ee25 100644 --- a/kde/src/widgets/ContactDock.cpp +++ b/kde/src/widgets/ContactDock.cpp @@ -37,6 +37,7 @@ class QNumericTreeWidgetItem : public QTreeWidgetItem { QNumericTreeWidgetItem(QTreeWidget* parent):QTreeWidgetItem(parent),widget(0),weight(-1){} QNumericTreeWidgetItem(QTreeWidgetItem* parent):QTreeWidgetItem(parent),widget(0),weight(-1){} ContactItemWidget* widget; + QString number; int weight; private: bool operator<(const QTreeWidgetItem & other) const { @@ -56,7 +57,7 @@ ContactDock::ContactDock(QWidget* parent) : QDockWidget(parent) m_pFilterLE = new KLineEdit ( ); m_pSplitter = new QSplitter ( Qt::Vertical,this ); m_pSortByCBB = new QComboBox ( this ); - m_pContactView = new QTreeWidget ( this ); + m_pContactView = new ContactTree ( this ); m_pCallView = new QListWidget ( this ); m_pShowHistoCK = new QCheckBox ( this ); @@ -121,10 +122,14 @@ void ContactDock::reloadContact() if (numbers.count() > 1) { foreach (Contact::PhoneNumber* number, numbers) { QNumericTreeWidgetItem* item2 = new QNumericTreeWidgetItem(item); - QLabel* numberL = new QLabel("<b>"+number->getType()+":</b>"+number->getNumber()); + QLabel* numberL = new QLabel("<b>"+number->getType()+":</b>"+number->getNumber(),this); + item2->number = number->getNumber(); m_pContactView->setItemWidget(item2,0,numberL); } } + else if (numbers.count() == 1) { + item->number = numbers[0]->getNumber(); + } m_pContactView->addTopLevelItem(item); m_pContactView->setItemWidget(item,0,aContact); @@ -165,4 +170,42 @@ void ContactDock::filter(QString text) item->getItem()->setHidden(!visible); } m_pContactView->expandAll(); +} + +QMimeData* ContactTree::mimeData( const QList<QTreeWidgetItem *> items) const +{ + qDebug() << "An history call is being dragged"; + if (items.size() < 1) { + return NULL; + } + + QMimeData *mimeData = new QMimeData(); + + //Contact + if (dynamic_cast<QNumericTreeWidgetItem*>(items[0])) { + QNumericTreeWidgetItem* item = dynamic_cast<QNumericTreeWidgetItem*>(items[0]); + if (item->widget != 0) { + mimeData->setData(MIME_CONTACT, item->widget->getContact()->getUid().toUtf8()); + } + else if (!item->number.isEmpty()) { + mimeData->setData(MIME_PHONENUMBER, item->number.toUtf8()); + } + } + else { + qDebug() << "the item is not a call"; + } + return mimeData; +} + +bool ContactTree::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) +{ + Q_UNUSED(index) + Q_UNUSED(action) + Q_UNUSED(parent) + + QByteArray encodedData = data->data(MIME_CALLID); + + qDebug() << "In history import"<< QString(encodedData); + + return false; } \ No newline at end of file diff --git a/kde/src/widgets/ContactDock.h b/kde/src/widgets/ContactDock.h index c77bf31cc5e90f913996199227dd263e26f44505..1361b95dea42cdd836093ffb10cef9f2c3811b09 100644 --- a/kde/src/widgets/ContactDock.h +++ b/kde/src/widgets/ContactDock.h @@ -2,6 +2,7 @@ #define CONTACT_DOCK_H #include <QtGui/QDockWidget> +#include <QtGui/QTreeWidget> #include <QSplitter> #include <akonadi/entitytreeview.h> @@ -11,12 +12,12 @@ #include <akonadi/contact/contactstreemodel.h> #include <akonadi/collectioncombobox.h> -class QTreeWidget; class QListWidget; class QComboBox; class QTreeWidgetItem; class QCheckBox; class ContactItemWidget; +class ContactTree; class ContactDock : public QDockWidget { Q_OBJECT @@ -27,7 +28,7 @@ private: //Attributes KLineEdit* m_pFilterLE; QSplitter* m_pSplitter; - QTreeWidget* m_pContactView; + ContactTree* m_pContactView; QListWidget* m_pCallView; QComboBox* m_pSortByCBB; QCheckBox* m_pShowHistoCK; @@ -39,4 +40,12 @@ private slots: void filter(QString text); }; +class ContactTree : public QTreeWidget { + Q_OBJECT +public: + ContactTree(QWidget* parent) : QTreeWidget(parent) {} + virtual QMimeData* mimeData( const QList<QTreeWidgetItem *> items) const; + bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action); +}; + #endif \ No newline at end of file diff --git a/kde/src/widgets/ContactItemWidget.cpp b/kde/src/widgets/ContactItemWidget.cpp index 3e2caed5a1e2fd1ce14bf08d30df8f8362040831..3789226b4f29f0e23014e86f90a3cdbfe16666d0 100644 --- a/kde/src/widgets/ContactItemWidget.cpp +++ b/kde/src/widgets/ContactItemWidget.cpp @@ -19,19 +19,50 @@ ***************************************************************************/ #include <QtCore/QStringList> +#include <QtCore/QMimeData> +#include <QtGui/QApplication> +#include <QtGui/QClipboard> #include <QtGui/QGridLayout> +#include <QtGui/QMenu> #include <klocale.h> #include <kdebug.h> #include <unistd.h> +#include <kaction.h> #include "lib/sflphone_const.h" #include "ContactItemWidget.h" ContactItemWidget::ContactItemWidget(QWidget *parent) - : QWidget(parent), init(false) + : QWidget(parent), m_pMenu(0),init(false) { - + setContextMenuPolicy(Qt::CustomContextMenu); + m_pCallAgain = new KAction(this); + m_pCallAgain->setShortcut(Qt::CTRL + Qt::Key_Enter); + m_pCallAgain->setText("Call Again"); + m_pCallAgain->setIcon(KIcon(ICON_DIALING)); + m_pEditContact = new KAction(this); + m_pEditContact->setShortcut(Qt::CTRL + Qt::Key_E); + m_pEditContact->setText("Edit contact"); + m_pEditContact->setIcon(KIcon("contact-new")); + m_pCopy = new KAction(this); + m_pCopy->setShortcut(Qt::CTRL + Qt::Key_C); + m_pCopy->setText("Copy"); + m_pCopy->setIcon(KIcon("edit-copy")); + m_pEmail = new KAction(this); + m_pEmail->setShortcut(Qt::CTRL + Qt::Key_M); + m_pEmail->setText("Send Email"); + m_pEmail->setIcon(KIcon("mail-message-new")); + m_pAddPhone = new KAction(this); + m_pAddPhone->setShortcut(Qt::CTRL + Qt::Key_N); + m_pAddPhone->setText("Add Phone Number"); + m_pAddPhone->setIcon(KIcon("list-resource-add")); + + connect(m_pCallAgain ,SIGNAL(triggered()),this,SLOT(callAgain() )); + connect(m_pEditContact ,SIGNAL(triggered()),this,SLOT(editContact() )); + connect(m_pCopy ,SIGNAL(triggered()),this,SLOT(copy() )); + connect(m_pEmail ,SIGNAL(triggered()),this,SLOT(sendEmail() )); + connect(m_pAddPhone ,SIGNAL(triggered()),this,SLOT(addPhone() )); } ContactItemWidget::~ContactItemWidget() @@ -71,6 +102,7 @@ void ContactItemWidget::setContact(Contact* contact) setMinimumSize(QSize(50, 30)); updated(); + connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(showContext(QPoint))); } void ContactItemWidget::updated() @@ -149,4 +181,47 @@ void ContactItemWidget::setItem(QTreeWidgetItem* item) Contact* ContactItemWidget::getContact() { return m_pContactKA; +} + +void ContactItemWidget::showContext(const QPoint& pos) +{ + if (!m_pMenu) { + m_pMenu = new QMenu(this); + m_pMenu->addAction(m_pCallAgain); + m_pMenu->addAction(m_pEditContact); + m_pMenu->addAction(m_pAddPhone); + m_pMenu->addAction(m_pCopy); + m_pMenu->addAction(m_pEmail); + } + m_pMenu->exec(mapToGlobal(pos)); +} + + +void ContactItemWidget::sendEmail() +{ + qDebug() << "Sending email"; +} + +void ContactItemWidget::callAgain() +{ + qDebug() << "Calling "; +} + +void ContactItemWidget::copy() +{ + qDebug() << "Copying contact"; + QMimeData* mimeData = new QMimeData(); + mimeData->setData(MIME_CONTACT, m_pContactKA->getUid().toUtf8()); + QClipboard* clipboard = QApplication::clipboard(); + clipboard->setMimeData(mimeData); +} + +void ContactItemWidget::editContact() +{ + qDebug() << "Adding contact"; +} + +void ContactItemWidget::addPhone() +{ + qDebug() << "Adding to contact"; } \ No newline at end of file diff --git a/kde/src/widgets/ContactItemWidget.h b/kde/src/widgets/ContactItemWidget.h index f7755c6dd36b2ed44022bca0e7b91502967ec368..620d6146d9bd6182b7094612e6b94abf7557d9e2 100644 --- a/kde/src/widgets/ContactItemWidget.h +++ b/kde/src/widgets/ContactItemWidget.h @@ -38,6 +38,8 @@ #include <lib/Contact.h> class QTreeWidgetItem; +class KAction; +class QMenu; class ContactItemWidget : public QWidget { @@ -46,6 +48,13 @@ class ContactItemWidget : public QWidget ContactItemWidget(QWidget* parent =0); ~ContactItemWidget(); + KAction* m_pCallAgain; + KAction* m_pEditContact; + KAction* m_pCopy; + KAction* m_pEmail; + KAction* m_pAddPhone; + QMenu* m_pMenu; + KABC::Addressee* contact() const; void setContact(Contact* contact); static const char * callStateIcons[12]; @@ -76,6 +85,13 @@ class ContactItemWidget : public QWidget public slots: void updated(); +private slots: + void showContext(const QPoint& pos); + void sendEmail(); + void callAgain(); + void copy(); + void editContact(); + void addPhone(); }; #endif // CALLTREE_ITEM_H diff --git a/kde/src/widgets/HistoryDock.cpp b/kde/src/widgets/HistoryDock.cpp index c8c648cba1bd63c6f971d5a60f14a1b7a3c6246f..23142473a1049bd10c9e52b092da41895c4bc536 100644 --- a/kde/src/widgets/HistoryDock.cpp +++ b/kde/src/widgets/HistoryDock.cpp @@ -269,13 +269,6 @@ QMimeData* HistoryTree::mimeData( const QList<QTreeWidgetItem *> items) const else { qDebug() << "the item is not a call"; } - -// -// //Plain text for other applications -// mimeData->setData(MIME_PLAIN_TEXT, QString(getCall(items[0])->getPeerName()+"\n"+getCall(items[0])->getPeerPhoneNumber()).toAscii()); -// -// //TODO Comment this line if you don't want to see ugly artefact, but the caller details will not be visible while dragged -// items[0]->setText(0, getCall(items[0])->getPeerName() + "\n" + getCall(items[0])->getPeerPhoneNumber()); return mimeData; } diff --git a/kde/src/widgets/HistoryTreeItem.cpp b/kde/src/widgets/HistoryTreeItem.cpp index e34d749c3e88423e9cc1e7309faa784a990abd73..a047ab639c6252b3842f00ae75880c953973f145 100644 --- a/kde/src/widgets/HistoryTreeItem.cpp +++ b/kde/src/widgets/HistoryTreeItem.cpp @@ -20,10 +20,13 @@ #include <QtCore/QStringList> #include <QtGui/QGridLayout> +#include <QtGui/QMenu> #include <klocale.h> #include <kdebug.h> #include <unistd.h> +#include <kaction.h> +#include <kicon.h> #include "lib/sflphone_const.h" #include "HistoryTreeItem.h" @@ -33,9 +36,41 @@ const char * HistoryTreeItem::callStateIcons[12] = {ICON_INCOMING, ICON_RINGING, ICON_CURRENT, ICON_DIALING, ICON_HOLD, ICON_FAILURE, ICON_BUSY, ICON_TRANSFER, ICON_TRANSF_HOLD, "", "", ICON_CONFERENCE}; HistoryTreeItem::HistoryTreeItem(QWidget *parent) - : QWidget(parent), itemCall(0), init(false) + : QWidget(parent), itemCall(0),m_pMenu(0), init(false) { + setContextMenuPolicy(Qt::CustomContextMenu); + + m_pCallAgain = new KAction(this); + m_pAddContact = new KAction(this); + m_pCopy = new KAction(this); + m_pEmail = new KAction(this); + m_pAddToContact = new KAction(this); + + m_pCallAgain->setShortcut (Qt::CTRL + Qt::Key_Enter ); + m_pCallAgain->setText ("Call Again" ); + m_pCallAgain->setIcon (KIcon(ICON_DIALING) ); + + m_pAddToContact->setShortcut (Qt::CTRL + Qt::Key_E ); + m_pAddToContact->setText ("Add to contact" ); + m_pAddToContact->setIcon (KIcon("list-resource-add") ); + + m_pAddContact->setShortcut (Qt::CTRL + Qt::Key_E ); + m_pAddContact->setText ("Add to contact" ); + m_pAddContact->setIcon (KIcon("contact-new") ); + m_pCopy->setShortcut (Qt::CTRL + Qt::Key_C ); + m_pCopy->setText ("Copy" ); + m_pCopy->setIcon (KIcon("edit-copy") ); + + m_pEmail->setShortcut (Qt::CTRL + Qt::Key_M ); + m_pEmail->setText ("Send Email" ); + m_pEmail->setIcon (KIcon("mail-message-new") ); + + connect(m_pCallAgain ,SIGNAL(triggered()),this,SLOT(callAgain() )); + connect(m_pAddContact ,SIGNAL(triggered()),this,SLOT(addContact() )); + connect(m_pCopy ,SIGNAL(triggered()),this,SLOT(copy() )); + connect(m_pEmail ,SIGNAL(triggered()),this,SLOT(sendEmail() )); + connect(m_pAddToContact ,SIGNAL(triggered()),this,SLOT(addToContact() )); } HistoryTreeItem::~HistoryTreeItem() @@ -86,6 +121,7 @@ void HistoryTreeItem::setCall(Call *call) setMinimumSize(QSize(50, 30)); connect(itemCall, SIGNAL(changed()), this, SLOT(updated())); + connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(showContext(QPoint))); updated(); m_pTimeStamp = itemCall->getStartTimeStamp().toUInt(); @@ -163,4 +199,43 @@ QTreeWidgetItem* HistoryTreeItem::getItem() void HistoryTreeItem::setItem(QTreeWidgetItem* item) { m_pItem = item; -} \ No newline at end of file +} + +void HistoryTreeItem::showContext(const QPoint& pos) +{ + if (!m_pMenu) { + m_pMenu = new QMenu(this); + m_pMenu->addAction( m_pCallAgain ); + m_pMenu->addAction( m_pAddContact ); + m_pMenu->addAction( m_pAddToContact ); + m_pMenu->addAction( m_pCopy ); + m_pMenu->addAction( m_pEmail ); + } + m_pMenu->exec(mapToGlobal(pos)); +} + + +void HistoryTreeItem::sendEmail() +{ + qDebug() << "Sending email"; +} + +void HistoryTreeItem::callAgain() +{ + qDebug() << "Calling "<< itemCall->getPeerPhoneNumber(); +} + +void HistoryTreeItem::copy() +{ + qDebug() << "Copying contact"; +} + +void HistoryTreeItem::addContact() +{ + qDebug() << "Adding contact"; +} + +void HistoryTreeItem::addToContact() +{ + qDebug() << "Adding to contact"; +} diff --git a/kde/src/widgets/HistoryTreeItem.h b/kde/src/widgets/HistoryTreeItem.h index 2e18f32050f0a89ed3aebcaaa8142adfcf98be44..6732fe665c411bf2bc9828f04699aca5677b8bba 100644 --- a/kde/src/widgets/HistoryTreeItem.h +++ b/kde/src/widgets/HistoryTreeItem.h @@ -42,6 +42,8 @@ #include "lib/Call.h" class QTreeWidgetItem; +class KAction; +class QMenu; class HistoryTreeItem : public QWidget { @@ -71,6 +73,13 @@ class HistoryTreeItem : public QWidget QLabel* m_pTimeL; QLabel* m_pDurationL; + KAction* m_pCallAgain; + KAction* m_pAddContact; + KAction* m_pAddToContact; + KAction* m_pCopy; + KAction* m_pEmail; + QMenu* m_pMenu; + uint m_pTimeStamp; uint m_pDuration; QString m_pName; @@ -81,8 +90,15 @@ class HistoryTreeItem : public QWidget public slots: void updated(); +private slots: + void showContext(const QPoint& pos); + void sendEmail(); + void callAgain(); + void copy(); + void addContact(); + void addToContact(); signals: - void over(Call*); - }; + void over(Call*); +}; #endif // CALLTREE_ITEM_H