Commit 16b792a7 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

[ #13646 ] Make contact detection much better with a default account

parent cc33d9c2
......@@ -228,7 +228,7 @@ on_cursor_motion(GtkTextView *view UNUSED, GdkEvent *event, gpointer data)
/*Match the regex*/
GError *error = NULL;
gchar *pattern_string = "^http\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(/\\S*)?$";
gchar *pattern_string = "^[a-z]*\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(/\\S*)?$";
GRegex *regex = g_regex_new( pattern_string, 0, 0, &error );
GMatchInfo *match_info = NULL;
GdkWindow *win = gtk_text_view_get_window(GTK_TEXT_VIEW(view),GTK_TEXT_WINDOW_TEXT);
......
......@@ -45,6 +45,7 @@
#include "lib/instance_interface_singleton.h"
#include "lib/configurationmanager_interface_singleton.h"
#include "lib/Contact.h"
#include "lib/AccountList.h"
//SFLPhone
#include "klib/AkonadiBackend.h"
......@@ -131,7 +132,6 @@ bool SFLPhone::initialize()
// CallModel<CallTreeItem*,QTreeWidgetItem*>* histoModel = new CallModel<CallTreeItem*,QTreeWidgetItem*>(CallModel<CallTreeItem*,QTreeWidgetItem*>::History);
// histoModel->initHistory();
ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
// accept dnd
setAcceptDrops(true);
......@@ -215,7 +215,7 @@ bool SFLPhone::initialize()
move(QCursor::pos().x() - geometry().width()/2, QCursor::pos().y() - geometry().height()/2);
show();
if (configurationManager.getAccountList().value().size() <= 1) {
if (AccountList::getInstance()->size() <= 1) {
(new AccountWizard())->show();
}
......@@ -357,6 +357,7 @@ TreeWidgetCallModel* SFLPhone::model()
m_pModel = new TreeWidgetCallModel();
m_pModel->initCall();
Call::setContactBackend(AkonadiBackend::getInstance());
AccountList::getInstance()->setDefaultAccount(AccountList::getInstance()->getAccountById(ConfigurationSkeleton::defaultAccountId()));
#ifdef ENABLE_VIDEO
VideoModel::getInstance();
#endif
......
......@@ -34,6 +34,7 @@
#include <KStandardDirs>
//SFLPhone
#include "klib/ConfigurationSkeleton.h"
#include "conf/ConfigurationDialog.h"
#include "lib/configurationmanager_interface_singleton.h"
#include "SFLPhoneView.h"
......@@ -211,6 +212,12 @@ void DlgAccounts::saveAccount(QModelIndex item)
/**/account->setRingtonePath ( m_pRingTonePath->url().path() );
// /
if (m_pDefaultAccount->isChecked()) {
kDebug() << "\n\n\n\n\nIS CHECKED\n\n\n\n\n";
ConfigurationSkeleton::setDefaultAccountId(account->getAccountId());
AccountList::getInstance()->setDefaultAccount(account);
}
if (m_pRingtoneListLW->selectedItems().size() == 1 && m_pRingtoneListLW->currentIndex().isValid() ) {
QListWidgetItem* selectedRingtone = m_pRingtoneListLW->currentItem();
RingToneListItem* ringtoneWidget = qobject_cast<RingToneListItem*>(m_pRingtoneListLW->itemWidget(selectedRingtone));
......@@ -325,6 +332,8 @@ void DlgAccounts::loadAccount(QModelIndex item)
/**/combo_security_STRP->setCurrentIndex ( account->getTlsMethod ());
/* */
m_pDefaultAccount->setChecked(account == AccountList::getInstance()->getDefaultAccount());
account->getVideoCodecModel()->reload();
disconnect(list_credential->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(selectCredential (QModelIndex,QModelIndex)));
......
......@@ -326,14 +326,14 @@
<item row="5" column="1">
<widget class="QLineEdit" name="edit6_mailbox"/>
</item>
<item row="6" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label7_state">
<property name="text">
<string>Status</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="8" column="1">
<widget class="QLabel" name="edit7_state">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
......@@ -352,6 +352,13 @@
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="m_pDefaultAccount">
<property name="text">
<string>Default account</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_advanced">
......
......@@ -97,6 +97,8 @@ Contact* AkonadiBackend::getContactByPhone(const QString& phoneNumber,bool resol
if (c) {
return c;
}
if (!a)
a = AccountList::getInstance()->getDefaultAccount();
else if (number.indexOf("@") == -1 && a)
return m_ContactByPhone[number+"@"+a->getAccountHostname()];
......@@ -151,6 +153,7 @@ KABC::PhoneNumber::Type nameToType(QString name)
///Update the contact list when a new Akonadi collection is added
ContactList AkonadiBackend::update(Akonadi::Collection collection)
{
Account* defaultAccount = AccountList::getInstance()->getDefaultAccount();
m_Collection = collection;
if ( !collection.isValid() ) {
kDebug() << "The current collection is not valid";
......@@ -182,6 +185,8 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection)
if (number2.right(1) == ">")
number2 = number2.remove(number2.size()-1,1);
m_ContactByPhone[number2] = aContact;
if (number2.size() <= 6 && defaultAccount && !defaultAccount->getAccountHostname().isEmpty())
m_ContactByPhone[number2+"@"+defaultAccount->getAccountHostname()] = aContact;
}
m_ContactByUid[tmp.uid()] = aContact;
......
......@@ -158,6 +158,11 @@
<default>false</default>
</entry>
<entry name="defaultAccountId" type="String">
<label>Default account used for contact lookup if only partial (only extension) contacts info is available</label>
<default>IP2IP</default>
</entry>
<!-- Bookmark -->
<entry name="bookmarkList" type="StringList">
<label>List of bookmarked clients</label>
......
......@@ -391,6 +391,12 @@ Account* AccountList::getAccountByModelIndex(QModelIndex item) const {
return (*m_pAccounts)[item.row()];
}
///Return the default account (used for contact lookup)
Account* AccountList::getDefaultAccount()
{
return m_pDefaultAccount;
}
/*****************************************************************************
* *
......@@ -450,6 +456,14 @@ void AccountList::setColorVisitor(AccountListColorVisitor* visitor)
m_pColorVisitor = visitor;
}
///Set the default account (used for contact lookup)
void AccountList::setDefaultAccount(Account* a)
{
if (a != m_pDefaultAccount)
emit defaultAccountChanged(a);
m_pDefaultAccount = a;
}
/*****************************************************************************
* *
......
......@@ -50,6 +50,7 @@ public:
const Account* getAccountAt ( int i ) const;
int size ( ) const;
Account* firstRegisteredAccount ( ) const;
Account* getDefaultAccount ( );
static Account* getCurrentAccount ( );
static QString getPriorAccoundId ( );
......@@ -58,6 +59,7 @@ public:
int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
Qt::ItemFlags flags ( const QModelIndex& index ) const;
Account* getAccountByModelIndex(QModelIndex item) const;
void setDefaultAccount(Account* a);
//Setters
static void setPriorAccountId( const QString& value );
......@@ -87,6 +89,7 @@ private:
QVector<Account*>* m_pAccounts;
static AccountList* m_spAccountList;
static QString m_sPriorAccountId;
Account* m_pDefaultAccount;
AccountListColorVisitor* m_pColorVisitor;
public slots:
......@@ -103,13 +106,14 @@ signals:
///Emitted when an account state change
void accountStateChanged( Account* account, QString state);
void accountEnabledChanged(Account* source);
void defaultAccountChanged(Account* a);
};
///SFLPhonelib Qt does not link to QtGui, and does not need to, this allow to add runtime Gui support
class LIB_EXPORT AccountListColorVisitor {
public:
virtual QVariant getColor(const Account* a) = 0;
virtual QVariant getIcon(const Account* a) = 0;
virtual QVariant getIcon(const Account* a) = 0;
virtual ~AccountListColorVisitor() {}
};
......
......@@ -39,6 +39,7 @@ set( qtsflphone_LIB_SRCS
VideoDevice.cpp
CredentialModel.cpp
AudioCodecModel.cpp
InstantMessagingModel.cpp
configurationmanager_interface_singleton.cpp
callmanager_interface_singleton.cpp
instance_interface_singleton.cpp
......@@ -137,6 +138,7 @@ set( qtsflphone_LIB_HDRS
instance_interface_singleton.h
video_interface_singleton.h
sflphone_const.h
InstantMessagingModel.h
)
install( FILES ${qtsflphone_LIB_HDRS}
......
/************************************************************************************
* Copyright (C) 2009 by Savoir-Faire Linux *
* Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> *
* Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***********************************************************************************/
#include "InstantMessagingModel.h"
InstantMessagingModel::InstantMessagingModel(QObject* parent) : QAbstractListModel(parent)
{
}
QVariant InstantMessagingModel::data( const QModelIndex& index, int role) const
{
if(index.column() == 0 && role == Qt::DisplayRole)
return QVariant(m_lMessages[index.row()].message);
else if (index.column() == 0 && role == MESSAGE_TYPE_ROLE )
return QVariant(m_lMessages[index.row()].message);
else if (index.column() == 0 && role == MESSAGE_FROM_ROLE )
return QVariant(m_lMessages[index.row()].from);
else if (index.column() == 0 && role == MESSAGE_TEXT_ROLE )
return INCOMMING_IM;
else if (index.column() == 0 && role == MESSAGE_CONTACT_ROLE )
return QVariant();
return QVariant();
}
int InstantMessagingModel::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent)
return m_lMessages.size();
}
Qt::ItemFlags InstantMessagingModel::flags(const QModelIndex& index) const
{
Q_UNUSED(index)
return Qt::ItemIsEnabled;
}
bool InstantMessagingModel::setData(const QModelIndex& index, const QVariant &value, int role)
{
Q_UNUSED(index)
Q_UNUSED(value)
Q_UNUSED(role)
return false;
}
\ No newline at end of file
/************************************************************************************
* Copyright (C) 2009 by Savoir-Faire Linux *
* Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> *
* Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***********************************************************************************/
#ifndef IM_MODEL_H
#define IM_MODEL_H
#include <QtCore/QAbstractListModel>
#include <QtCore/QModelIndex>
enum MessageRole {
INCOMMING_IM,
OUTGOING_IM,
MIME_TRANSFER,
};
class InstantMessagingModel : public QAbstractListModel
{
Q_OBJECT
public:
static const int MESSAGE_TYPE_ROLE = 100;
static const int MESSAGE_FROM_ROLE = 101;
static const int MESSAGE_TEXT_ROLE = 102;
static const int MESSAGE_CONTACT_ROLE = 103;
InstantMessagingModel(QObject* parent);
QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
Qt::ItemFlags flags ( const QModelIndex& index ) const;
virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) ;
private:
struct InternalIM {
QString from;
QString message;
};
QList<InternalIM> m_lMessages;
};
#endif
\ No newline at end of file
......@@ -221,7 +221,7 @@
#define CALL_STATE_CHANGE_HOLD "HOLD"
#define CALL_STATE_CHANGE_BUSY "BUSY"
#define CALL_STATE_CHANGE_FAILURE "FAILURE"
#define CALL_STATE_CHANGE_UNHOLD_CURRENT "UNHOLD_CURRENT"
#define CALL_STATE_CHANGE_UNHOLD_CURRENT "UNHOLD"
#define CALL_STATE_CHANGE_UNKNOWN "UNKNOWN"
#define CONF_STATE_CHANGE_HOLD "HOLD"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment