Commit f2f69ce0 authored by Emmanuel Lepage's avatar Emmanuel Lepage

Test a dock widget based implementation for contact and history

parent 7852adff
#include "AkonadiBackend.h"
#include <QtCore/QTimer>
#include <akonadi/control.h>
#include <akonadi/collectionfilterproxymodel.h>
#include <akonadi/collectionmodel.h>
#include <akonadi/kmime/messagemodel.h>
#include <contactgroupsearchjob.h>
AkonadiBackend::AkonadiBackend(QObject* parent) : QObject(parent)
{
QTimer::singleShot( 0, this, SLOT( delayedInit() ) );
}
virtual AkonadiBackend::~AkonadiBackend()
{
}
AkonadiBackend* AkonadiBackend::getInstance()
{
}
static bool AkonadiBackend::init()
{
if ( !Akonadi::Control::start( this ) ) {
return false;
}
return true;
}
void AkonadiBackend::createModels()
{
Akonadi::CollectionModel *collectionModel = new Akonadi::CollectionModel( this );
Akonadi::CollectionFilterProxyModel *filterModel = new Akonadi::CollectionFilterProxyModel( this );
filterModel->setSourceModel( collectionModel );
filterModel->addMimeTypeFilter( QLatin1String( "message/rfc822" ) );
Akonadi::ItemModel *itemModel = new Akonadi::MessageModel( this );
ui_detacherview_base.folderView->setModel( filterModel );
ui_detacherview_base.messageView->setModel( itemModel );
connect( ui_detacherview_base.folderView, SIGNAL( currentChanged( Akonadi::Collection ) ),
itemModel, SLOT( setCollection( Akonadi::Collection ) ) );
}
\ No newline at end of file
#ifndef AKONADI_BACKEND_H
#define AKONADI_BACKEND_H
#include <QObject>
class AkonadiBackend : public QObject {
public:
AkonadiBackend* getInstance();
private:
AkonadiBackend(QObject* parent);
virtual ~AkonadiBackend();
static bool init();
//Attributes
AkonadiBackend* instance;
};
#endif
\ No newline at end of file
...@@ -39,6 +39,9 @@ SET( sflphone_client_kde_SRCS ...@@ -39,6 +39,9 @@ SET( sflphone_client_kde_SRCS
conf/ConfigAccountList.cpp conf/ConfigAccountList.cpp
widgets/Dialpad.cpp widgets/Dialpad.cpp
widgets/ContactItemWidget.cpp widgets/ContactItemWidget.cpp
widgets/ContactDock.cpp
widgets/HistoryDock.cpp
widgets/BookmarkDock.cpp
Codec.cpp Codec.cpp
AccountListModel.cpp AccountListModel.cpp
CallView.cpp CallView.cpp
...@@ -69,7 +72,7 @@ INSTALL(FILES conf/sflphone-client-kde.kcfg DESTINATION ${KCFG_INSTALL_DIR}) ...@@ -69,7 +72,7 @@ INSTALL(FILES conf/sflphone-client-kde.kcfg DESTINATION ${KCFG_INSTALL_DIR})
KDE4_ADD_EXECUTABLE(sflphone-client-kde ${sflphone_client_kde_SRCS} ${QtApp_RCC_SRCS}) KDE4_ADD_EXECUTABLE(sflphone-client-kde ${sflphone_client_kde_SRCS} ${QtApp_RCC_SRCS})
TARGET_LINK_LIBRARIES(sflphone-client-kde qtsflphone ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KABC_LIBS}) TARGET_LINK_LIBRARIES(sflphone-client-kde qtsflphone ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDEPIMLIBS_AKONADI_KMIME_LIBS} ${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_AKONADI_CONTACT_LIBS} )
########### install files ############### ########### install files ###############
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "lib/instance_interface_singleton.h" #include "lib/instance_interface_singleton.h"
#include "lib/configurationmanager_interface_singleton.h" #include "lib/configurationmanager_interface_singleton.h"
SFLPhone* SFLPhone::m_sApp = NULL;
SFLPhone::SFLPhone(QWidget *parent) SFLPhone::SFLPhone(QWidget *parent)
: KXmlGuiWindow(parent), : KXmlGuiWindow(parent),
...@@ -43,6 +44,12 @@ SFLPhone::SFLPhone(QWidget *parent) ...@@ -43,6 +44,12 @@ SFLPhone::SFLPhone(QWidget *parent)
view(new SFLPhoneView(this)) view(new SFLPhoneView(this))
{ {
setupActions(); setupActions();
m_sApp = this;
}
SFLPhone* SFLPhone::app()
{
return m_sApp;
} }
SFLPhone::~SFLPhone() SFLPhone::~SFLPhone()
...@@ -56,12 +63,37 @@ bool SFLPhone::initialize() ...@@ -56,12 +63,37 @@ bool SFLPhone::initialize()
return false; return false;
} }
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
// accept dnd // accept dnd
setAcceptDrops(true); setAcceptDrops(true);
// tell the KXmlGuiWindow that this is indeed the main widget // tell the KXmlGuiWindow that this is indeed the main widget
setCentralWidget(view); //setCentralWidget(view);
m_pCentralDW = new QDockWidget(this);
m_pCentralDW->setWidget(view);
m_pCentralDW->setWindowTitle("Call");
m_pCentralDW->setFeatures(QDockWidget::NoDockWidgetFeatures);
m_pCentralDW->setStyleSheet("\
QDockWidget::title {\
display:none;\
margin:0px;\
padding:0px;\
spacing:0px;\
max-height:0px;\
}\
\
");
addDockWidget(Qt::BottomDockWidgetArea,m_pCentralDW);
m_pContactCD = new ContactDock(this);
addDockWidget(Qt::LeftDockWidgetArea,m_pContactCD);
m_pHistoryDW = new HistoryDock(this);
addDockWidget(Qt::RightDockWidgetArea,m_pHistoryDW);
m_pBookmarkDW = new BookmarkDock(this);
addDockWidget(Qt::RightDockWidgetArea,m_pBookmarkDW);
setWindowIcon(QIcon(ICON_SFLPHONE)); setWindowIcon(QIcon(ICON_SFLPHONE));
setWindowTitle(i18n("SFLphone")); setWindowTitle(i18n("SFLphone"));
...@@ -106,7 +138,7 @@ void SFLPhone::setObjectNames() ...@@ -106,7 +138,7 @@ void SFLPhone::setObjectNames()
void SFLPhone::setupActions() void SFLPhone::setupActions()
{ {
qDebug() << "setupActions"; qDebug() << "setupActions";
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); //ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
action_accept = new KAction(this); action_accept = new KAction(this);
action_refuse = new KAction(this); action_refuse = new KAction(this);
...@@ -341,7 +373,7 @@ QList<QAction*> SFLPhone::getCallActions() ...@@ -341,7 +373,7 @@ QList<QAction*> SFLPhone::getCallActions()
void SFLPhone::on_view_incomingCall(const Call * call) void SFLPhone::on_view_incomingCall(const Call * call)
{ {
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); //ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
//trayIconSignal(); //trayIconSignal();
/*if(configurationManager.popupMode()) /*if(configurationManager.popupMode())
{ {
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include <KXmlGuiWindow> #include <KXmlGuiWindow>
#include <KAction> #include <KAction>
#include "widgets/ContactDock.h"
#include "widgets/HistoryDock.h"
#include "widgets/BookmarkDock.h"
#include <QActionGroup> #include <QActionGroup>
// #include "ui_SFLPhoneView_base.h" // #include "ui_SFLPhoneView_base.h"
...@@ -96,7 +99,13 @@ private: ...@@ -96,7 +99,13 @@ private:
bool iconChanged; bool iconChanged;
SFLPhoneTray *trayIcon; SFLPhoneTray *trayIcon;
KNotification *notification; KNotification *notification;
QLabel * statusBarWidget; QLabel* statusBarWidget;
ContactDock* m_pContactCD;
QDockWidget* m_pCentralDW;
HistoryDock* m_pHistoryDW;
BookmarkDock* m_pBookmarkDW;
static SFLPhone* m_sApp;
private: private:
void setObjectNames(); void setObjectNames();
...@@ -118,6 +127,8 @@ public: ...@@ -118,6 +127,8 @@ public:
friend class SFLPhoneView; friend class SFLPhoneView;
static SFLPhone* app();
private slots: private slots:
void on_view_statusMessageChangeAsked(const QString & message); void on_view_statusMessageChangeAsked(const QString & message);
......
...@@ -105,7 +105,6 @@ SFLPhoneView::SFLPhoneView(QWidget *parent) ...@@ -105,7 +105,6 @@ SFLPhoneView::SFLPhoneView(QWidget *parent)
stackedWidget_screen->setCurrentWidget(page_callList); stackedWidget_screen->setCurrentWidget(page_callList);
//BEGIN Port to CallModel //BEGIN Port to CallModel
connect(&callManager, SIGNAL(callStateChanged(const QString &, const QString &)), connect(&callManager, SIGNAL(callStateChanged(const QString &, const QString &)),
this, SLOT(on1_callStateChanged(const QString &, const QString &))); this, SLOT(on1_callStateChanged(const QString &, const QString &)));
...@@ -741,13 +740,13 @@ void SFLPhoneView::updateVolumeControls() ...@@ -741,13 +740,13 @@ void SFLPhoneView::updateVolumeControls()
if(QString(configurationManager.getAudioManager()) == "alsa") { if(QString(configurationManager.getAudioManager()) == "alsa") {
display = true; display = true;
((SFLPhone*)parent())->action_displayVolumeControls->setEnabled(true); SFLPhone::app()->action_displayVolumeControls->setEnabled(true);
} }
else { else {
((SFLPhone*)parent())->action_displayVolumeControls->setEnabled(false); SFLPhone::app()->action_displayVolumeControls->setEnabled(false);
} }
((SFLPhone*)parent())->action_displayVolumeControls->setChecked(display); SFLPhone::app()->action_displayVolumeControls->setChecked(display);
//widget_recVol->setVisible(display); //widget_recVol->setVisible(display);
//widget_sndVol->setVisible(display); //widget_sndVol->setVisible(display);
toolButton_recVol->setVisible(display && ConfigurationSkeleton::displayVolume()); toolButton_recVol->setVisible(display && ConfigurationSkeleton::displayVolume());
...@@ -786,9 +785,7 @@ void SFLPhoneView::updateStatusMessage() ...@@ -786,9 +785,7 @@ void SFLPhoneView::updateStatusMessage()
void SFLPhoneView::displayVolumeControls(bool checked) void SFLPhoneView::displayVolumeControls(bool checked)
{ {
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance(); //ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
int display = true;//configurationManager.getVolumeControls();
//configurationManager.setVolumeControls(!display);
ConfigurationSkeleton::setDisplayVolume(checked); ConfigurationSkeleton::setDisplayVolume(checked);
updateVolumeControls(); updateVolumeControls();
} }
...@@ -974,7 +971,7 @@ void SFLPhoneView::contextMenuEvent(QContextMenuEvent *event) ...@@ -974,7 +971,7 @@ void SFLPhoneView::contextMenuEvent(QContextMenuEvent *event)
menu.addAction(action_edit); menu.addAction(action_edit);
} }
SFLPhone * window = (SFLPhone * ) this->parent(); SFLPhone * window = SFLPhone::app();
QList<QAction *> callActions = window->getCallActions(); QList<QAction *> callActions = window->getCallActions();
menu.addAction(callActions.at((int) SFLPhone::Accept)); menu.addAction(callActions.at((int) SFLPhone::Accept));
menu.addAction(callActions[SFLPhone::Refuse]); menu.addAction(callActions[SFLPhone::Refuse]);
...@@ -1226,9 +1223,9 @@ void SFLPhoneView::on1_incomingCall(const QString & /*accountID*/, const QString ...@@ -1226,9 +1223,9 @@ void SFLPhoneView::on1_incomingCall(const QString & /*accountID*/, const QString
//NEED_PORT //NEED_PORT
changeScreen(SCREEN_MAIN); changeScreen(SCREEN_MAIN);
((SFLPhone*)parent())->activateWindow(); SFLPhone::app()->activateWindow();
((SFLPhone*)parent())->raise(); SFLPhone::app()->raise();
((SFLPhone*)parent())->setVisible(true); SFLPhone::app()->setVisible(true);
emit incomingCall(call); emit incomingCall(call);
} }
......
...@@ -231,6 +231,7 @@ private slots: ...@@ -231,6 +231,7 @@ private slots:
void updateVolumeControls(); void updateVolumeControls();
void updateDialpad(); void updateDialpad();
public slots: public slots:
/** /**
* Updates all the display * Updates all the display
......
...@@ -19,7 +19,7 @@ INCLUDE ( KDE4Defaults ) ...@@ -19,7 +19,7 @@ INCLUDE ( KDE4Defaults )
set(GENERIC_LIB_VERSION "0.9.8") set(GENERIC_LIB_VERSION "0.9.8")
INCLUDE_DIRECTORIES ( ${KDE4_INCLUDES} ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES ( ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="page_callList"> <widget class="QWidget" name="page_callList">
<property name="sizePolicy"> <property name="sizePolicy">
......
#include "ContactDock.h"
#include <QtGui/QVBoxLayout>
#include <akonadi/collectionfilterproxymodel.h>
#include <akonadi/contact/contactstreemodel.h>
#include <akonadi/kmime/messagemodel.h>
#include <akonadi/changerecorder.h>
#include <akonadi/session.h>
#include <kabc/addressee.h>
#include <kabc/picture.h>
#include <kabc/phonenumber.h>
#include <kabc/vcard.h>
#include <kabc/addressee.h>
#include <kabc/field.h>
#include <kabc/vcardline.h>
#include <kabc/contactgroup.h>
#include <akonadi/itemfetchscope.h>
#include <akonadi/entitydisplayattribute.h>
#include <akonadi/recursiveitemfetchjob.h>
#include <kicon.h>
ContactDock::ContactDock(QWidget* parent) : QDockWidget(parent)
{
m_pCollViewCV = new Akonadi::EntityTreeView();
m_pItemView = new Akonadi::ItemView();
m_pFilterLE = new KLineEdit();
m_pCollCCB = new Akonadi::CollectionComboBox;
m_pSplitter = new QSplitter(Qt::Vertical,this);
QWidget* mainWidget = new QWidget(this);
setWidget(mainWidget);
QVBoxLayout* mainLayout = new QVBoxLayout(mainWidget);
mainLayout->addWidget(m_pCollCCB);
mainLayout->addWidget(m_pSplitter);
m_pSplitter->addWidget(m_pCollViewCV);
m_pSplitter->addWidget(m_pItemView);
mainLayout->addWidget(m_pFilterLE);
m_pSplitter->setChildrenCollapsible(true);
m_pSplitter->setStretchFactor(0,7);
m_pCollCCB->setMimeTypeFilter( QStringList() << KABC::Addressee::mimeType() );
m_pCollCCB->setAccessRightsFilter( Akonadi::Collection::ReadOnly );
/////////////
// use a separated session for this model
Akonadi::Session *session = new Akonadi::Session( "SFLPhone::instance" );
Akonadi::ItemFetchScope scope;
// fetch all content of the contacts, including images
scope.fetchFullPayload( true );
// fetch the EntityDisplayAttribute, which contains custom names and icons
scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
Akonadi::ChangeRecorder *changeRecorder = new Akonadi::ChangeRecorder;
changeRecorder->setSession( session );
// include fetching the collection tree
changeRecorder->fetchCollection( true );
// set the fetch scope that shall be used
changeRecorder->setItemFetchScope( scope );
// monitor all collections below the root collection for changes
changeRecorder->setCollectionMonitored( Akonadi::Collection::root() );
// list only contacts and contact groups
changeRecorder->setMimeTypeMonitored( KABC::Addressee::mimeType(), true );
changeRecorder->setMimeTypeMonitored( KABC::ContactGroup::mimeType(), true );
Akonadi::ContactsTreeModel *model = new Akonadi::ContactsTreeModel( changeRecorder );
Akonadi::ContactsTreeModel::Columns columns;
columns << Akonadi::ContactsTreeModel::FullName;
columns << Akonadi::ContactsTreeModel::AllEmails;
model->setColumns( columns );
//////////////
for (int i=0;i<model->rowCount();i++) {
qDebug() << "\n\n\nChild:" << model->hasChildren(model->index(i,0)) << "Model:" << model->rowCount(model->index(i,0));
}
qDebug() << "\n\n\nChild:" << model->hasChildren(model->index(0,0)) << "Model:" << model->rowCount(model->index(0,0));
qDebug() << "\n\n\nChild:" << model->hasChildren(model->index(1,0)) << "Model:" << model->rowCount(model->index(1,0));
//qDebug() << "Model:" << *model;
m_pCollViewCV->setModel( model );
m_pItemView->setModel( model );
connect (m_pCollCCB, SIGNAL(currentChanged(Akonadi::Collection)),this,SLOT(collectAddressBookContacts()));
//collectAllContacts(model);
collectAddressBookContacts();
setWindowTitle("Contact");
//setDockIcon(KIcon("resource-group"));
}
ContactDock::~ContactDock()
{
}
KABC::Addressee::List ContactDock::collectAllContacts(Akonadi::ContactsTreeModel *mModel) const
{
KABC::Addressee::List contacts;
for ( int i = 0; i < mModel->rowCount(); ++i ) {
const QModelIndex index = mModel->index( i, 0 );
if ( index.isValid() ) {
const Akonadi::Item item = index.data( Akonadi::EntityTreeModel::ItemRole ).value<Akonadi::Item>();
if ( item.isValid() && item.hasPayload<KABC::Addressee>() ) {
contacts.append( item.payload<KABC::Addressee>() );
qDebug() << item.payload<KABC::Addressee>().toString();
}
}
}
return contacts;
}
KABC::Addressee::List ContactDock::collectAddressBookContacts() const
{
qDebug() << "In colect\n\n\n\n\n";
KABC::Addressee::List contacts;
const Akonadi::Collection collection = m_pCollCCB->currentCollection();
if ( !collection.isValid() ) {
qDebug() << "The current collection is not valid";
return contacts;
}
qDebug() << "Valid collection";
//if ( mAddressBookSelectionRecursive->isChecked() ) {
Akonadi::RecursiveItemFetchJob *job = new Akonadi::RecursiveItemFetchJob( collection, QStringList() << KABC::Addressee::mimeType() << KABC::ContactGroup::mimeType());
job->fetchScope().fetchFullPayload();
//qDebug() << "Begin \n\n\n";
if ( job->exec() ) {
const Akonadi::Item::List items = job->items();
foreach ( const Akonadi::Item &item, items ) {
//qDebug() << "In for" << item.payloadData() << item.mimeType();
if ( item.hasPayload<KABC::ContactGroup>() ) {
//contacts.append( item.payload<KABC::ContactGroup>() );
qDebug() << "Group:" << item.payload<KABC::ContactGroup>().name();
}
if ( item.hasPayload<KABC::Addressee>() ) {
//contacts.append( item.payload<KABC::ContactGroup>() );
qDebug() << "Addressee:" << item.payload<KABC::Addressee>().name();
}
// if ( item.hasPayload<KABC::Field>() ) {
// //contacts.append( item.payload<KABC::VCard>() );
// qDebug() << "VCard:" << item.payload<KABC::VCardFormat>().identifiers();
// }
}
}
// } else {
// Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( collection );
// job->fetchScope().fetchFullPayload();
//
// if ( job->exec() ) {
// const Akonadi::Item::List items = job->items();
//
// foreach ( const Akonadi::Item &item, items ) {
// if ( item.hasPayload<KABC::Addressee>() ) {
// contacts.append( item.payload<KABC::Addressee>() );
// }
// }
// }
// }
qDebug() << "End collect \n\n\n";
return contacts;
}
#ifndef CONTACT_DOCK_H
#define CONTACT_DOCK_H
#include <QtGui/QDockWidget>
#include <QSplitter>
#include <akonadi/entitytreeview.h>
#include <akonadi/itemview.h>
//#include <akonadi/contactgroupviewer.h>
#include <klineedit.h>
#include <kabc/addressee.h>
#include <akonadi/contact/contactstreemodel.h>
#include <akonadi/collectioncombobox.h>
class ContactDock : public QDockWidget {
Q_OBJECT
public:
ContactDock(QWidget* parent);
virtual ~ContactDock();
private:
KABC::Addressee::List collectAllContacts(Akonadi::ContactsTreeModel *mModel) const;
Akonadi::EntityTreeView* m_pCollViewCV;
Akonadi::ItemView* m_pItemView;
KLineEdit* m_pFilterLE;
Akonadi::CollectionComboBox* m_pCollCCB;
QSplitter* m_pSplitter;
public slots:
KABC::Addressee::List collectAddressBookContacts() const;
};
#endif
\ No newline at end of file
#include "HistoryDock.h"
#include <QtGui/QVBoxLayout>
#include <kicon.h>
#include <klineedit.h>
#include <QtGui/QTreeWidget>
#include <QtGui/QComboBox>
#include <QtGui/QLabel>
HistoryDock::HistoryDock(QWidget* parent) : QDockWidget(parent)
{
m_pFilterLE = new KLineEdit();
m_pItemView = new QTreeWidget(this);
m_pSortByCBB = new QComboBox();
m_pSortByL = new QLabel();
m_pSortByL->setText("Sort by:");
m_pSortByCBB->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
QWidget* mainWidget = new QWidget(this);
setWidget(mainWidget);
QGridLayout* mainLayout = new QGridLayout(mainWidget);
mainLayout->addWidget(m_pSortByL ,0,0 );
mainLayout->addWidget(m_pSortByCBB ,0,1 );
mainLayout->addWidget(m_pItemView ,1,0,1,2 );
mainLayout->addWidget(m_pFilterLE ,2,0,1,2 );
setWindowTitle("History");
}