icd2interface_->call(ICD_DBUS_API_CONNECT_REQ, QVariant(flags));
waitSignal(&connectionReady_);
+
+ if(connected_)
+ {
+ sleep(WAIT_AFTER_CONNECT);
+ }
+
return connected_;
}
connected_ = true;
+ sleep(WAIT_AFTER_CONNECT);
+
return true;
}
killTimer(timer_);
+ if(timeout_)
+ {
+ qDebug() << "Connection request timed out";
+ }
+
return *ready || !timeout_;
}
+void ConnectionManager::sleep(unsigned int ms)
+{
+ timeout_ = false;
+ timer_ = startTimer(ms);
+
+ while(!timeout_)
+ {
+ QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
+ }
+
+ killTimer(timer_);
+}
+
void ConnectionManager::timerEvent(QTimerEvent* event)
{
Q_UNUSED(event);
killTimer(timer_);
timeout_ = true;
timer_ = 0;
-
- qDebug() << "Connection request timed out";
}
bool scanConnections(QList<Connection>& connections, ConnectionType type = NO_TYPE);
Error error() const;
static unsigned int const TIMEOUT = 15000;
+ static unsigned int const WAIT_AFTER_CONNECT = 400;
protected:
virtual void timerEvent(QTimerEvent* event);
void scanResult(const QDBusMessage& rep);
private:
+ void sleep(unsigned int ms);
bool waitSignal(bool* ready);
bool stateReady_;
bool connectionReady_;
*/
#include <QtCore/QDebug>
+#include <QtCore/QRegExp>
#include "contactmanager.h"
char* firstname = contact.name.firstname.toUtf8().data();
char* surname = contact.name.surname.toUtf8().data();
+
e_contact_set(newContact, E_CONTACT_GIVEN_NAME, (gpointer)firstname);
e_contact_set(newContact, E_CONTACT_FAMILY_NAME, (gpointer)surname);
if(ename)
{
+ static QRegExp check("([A-Z]+)");
QString additional = QString::fromUtf8(ename->additional);
+ QString firstname = QString::fromUtf8(ename->given);
+ QString surname = QString::fromUtf8(ename->family);
- if(additional.isEmpty())
+ if(additional.isEmpty() && check.indexIn(firstname, 1) == -1 && check.indexIn(surname, 1) == -1)
{
- name.firstname = QString::fromUtf8(ename->given);
- name.surname = QString::fromUtf8(ename->family);
+ name.firstname = firstname;
+ name.surname = surname;
}
else
{
if(pendingSearches_.at(i) && pendingSearches_.at(i)->searchIds.find(id) !=
pendingSearches_.at(i)->searchIds.end())
{
-
setError(Source::CONNECTION_FAILURE, http_.errorString());
emitRequestFinished(pendingSearches_.at(i), true, i);
break;
QString const& data,
int index)
{
+ if(data.isEmpty())
+ {
+ qDebug() << "Server returned no data";
+ qDebug() << "Headers: " << http_.lastResponse().toString();
+ }
+
if(data.indexOf("<b>Last ned vCard</b>") > 0)
{
addOnlyNumber(searchData, data, index);
*/
#include <QtCore/QDebug>
+#include <QtNetwork/QHttpResponseHeader>
#include "source.h"
#include "eniro.h"
#include "mobil1881.h"
void Source::httpReady(int id, bool error)
{
+ QByteArray result = http_.readAll();
+
if(error)
{
if(http_.error() == QHttp::Aborted)
}
else
{
- QByteArray result = http_.readAll();
handleHttpData(id, result);
}
}
if(cm.connect(best.id))
{
- sleep(500);
break;
}
else if(cm.error() == ConnectionManager::INVALID_IAP)
#include "sourcecoreconfig.h"
ResultWindow::ResultWindow(QWidget* parent): QMainWindow(parent),
-source_(0), list_(0), connectionManager_(0)
+source_(0), list_(0), connectionManager_(0), timer_(0), searching_(false)
{
setAttribute(Qt::WA_Maemo5StackedWindow);
setWindowTitle(tr("Search results"));
list_->clear();
}
+ show();
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+
+ if(!connectionManager_)
+ {
+ connectionManager_ = new ConnectionManager();
+ }
+
+ connectionManager_->connect();
+
Source::SourceId id = Source::stringToId(Settings::instance()->get("source"));
if(!source_ || id != sourceId_)
config->apply(source_);
delete config;
- show();
- setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
-
- if(!connectionManager_)
+ if(searching_)
{
- connectionManager_ = new ConnectionManager();
+ source_->abort();
+ timer_ = startTimer(SEARCH_INTERVAL);
}
- connectionManager_->connect();
+ while(timer_)
+ {
+ QApplication::processEvents(QEventLoop::WaitForMoreEvents);
+ }
- source_->abort();
+ list_->clear();
+ searching_ = true;
source_->search(Source::SearchDetails(details.name, details.location, details.type));
}
void ResultWindow::resultAvailable(Source::Result const& result,
Source::SearchDetails const& details)
{
+ if(!list_)
+ {
+ return;
+ }
+
Q_UNUSED(details);
if(!result.number.isEmpty())
setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+ if(timer_)
+ {
+ killTimer(timer_);
+ }
+
+ timer_ = startTimer(SEARCH_INTERVAL);
+ searching_ = false;
+
}
void ResultWindow::itemClicked(QListWidgetItem* item)
void ResultWindow::setVisible(bool visible)
{
- QMainWindow::setVisible(visible);
-
if(!visible && source_)
{
source_->abort();
-
-
}
+
+ QMainWindow::setVisible(visible);
}
+void ResultWindow::timerEvent(QTimerEvent* event)
+{
+ Q_UNUSED(event);
+
+ killTimer(timer_);
+ timer_ = 0;
+}
ResultWindow(QWidget* parent = 0);
~ResultWindow();
static const int REQUEST_TIMEOUT = 30000;
+ static const int SEARCH_INTERVAL = 2000;
signals:
void itemSelected(Source::Result const& result);
void search(SearchDialog::SearchDetails& details);
virtual void setVisible(bool visible);
+protected:
+ virtual void timerEvent(QTimerEvent* event);
+
private slots:
void resultAvailable(Source::Result const& result, Source::SearchDetails const& details);
void requestFinished(QVector <Source::Result> const& results, Source::SearchDetails const& details, bool error);
Source* source_;
QListWidget* list_;
ConnectionManager* connectionManager_;
+ int timer_;
+ bool searching_;
};