コード例 #1
0
ファイル: googlesession.cpp プロジェクト: muromec/gqsync
int GoogleSession::updateContacts(QList<QContact> &contacts, bool skip) {

  setState(UpdatingContacts);
  QContactModel filter;

	qDebug() << "PIM source" << filter.defaultSource().identity;

  for (int i = 0; i < contacts.size(); ++i) {
		QContact gContact = contacts.at(i);

		qDebug() << "process contact" << gContact.label();

    // skip contacts with no phonenumbers
    if (skip && (! gContact.phoneNumbers().size() ))
      continue;

    /*
		filter.addContact(gContact, filter.phoneSource());
		continue;
    */

    filter.setFilter(gContact.label());

    // single match. merging
    if (filter.count() == 1) {
			qDebug() << "Merging";
      filter.updateContact( merge(filter.contact(0), gContact) );
    } 
    // no match. saving directly
    else if (filter.count() == 0) {
			qDebug() << "Adding";
      filter.addContact(gContact);
    }
		else
			qDebug() << "WTF?! Multiple matches";
  }

  setState(Authenticated);
}
コード例 #2
0
ファイル: ringcontrol.cpp プロジェクト: Artox/qtmoko
QString RingControl::findRingTone()
{
    QString ringTone;
    if(DialerControl::instance()->hasIncomingCall()) {
        QPhoneCall call = DialerControl::instance()->incomingCall();
        QString numberOrName = call.number();
        QContact cnt;
        QContactModel *m = ServerContactModel::instance();
        if (!call.contact().isNull()) {
            cnt = m->contact(call.contact());
        } else if (!numberOrName.isEmpty()) {
            cnt = m->matchPhoneNumber(numberOrName);
        }

        if (!cnt.uid().isNull()) {
            numberOrName = cnt.label();

            // video ringtone
            ringTone = cnt.customField( "videotone" );
            if ( !ringTone.isEmpty() ) {
                d->videoTone = true;
            } else { // normal ringtone
                ringTone = cnt.customField( "tone" );
                d->videoTone = false;
            }

            if ( ringTone.isEmpty() ) {
                // check if the contacts category has a ringtone
                QList<QString> catList = cnt.categories();
                if ( catList.count() ) {
                    QCategoryManager catManager;
                    ringTone = catManager.ringTone( catList.at( 0 ) );
                }
                d->videoTone = false;
            }
        }
    }

    return ringTone;
}
コード例 #3
0
ファイル: dialercontrol.cpp プロジェクト: muromec/qtopia-ezx
void DialerControl::callStateChanged( const QPhoneCall& call )
{
    // Set value space appropriately
    // XXX Optimize for redundancy!
    if(hasIncomingCall()) {
        QPhoneCall icall = incomingCall();
        QString number = icall.number();
        QString name;
        QUniqueId contact = icall.contact();
        QContactModel *m = ServerContactModel::instance();
        if(!contact.isNull()) {
            QContact cnt = m->contact(contact);
            if (!cnt.uid().isNull())
                name = cnt.label();
        } else if(!number.isEmpty()) {
            QContact cnt = m->matchPhoneNumber(number);
            if (!cnt.uid().isNull())
                name = cnt.label();
        } else {
            number = tr("Unknown", "Unknown caller");
        }
        phoneValueSpace.setAttribute("Incoming/Number", QVariant(number.trimmed()));
        phoneValueSpace.setAttribute("Incoming/Name", QVariant(name));

        if(!aaTid && mProfiles->activeProfile().autoAnswer())
            aaTid = startTimer(auto_answer_gap);
    } else {
        if(aaTid)
            killTimer(aaTid);
        phoneValueSpace.removeAttribute("Incoming");
    }

    // emit useful signals
    if( call.state() == QPhoneCall::Connected )
    {
        emit callConnected( call );
        // update cached call info.
        updateCachedCall( call );
    }
    else if( call.state() == QPhoneCall::Hold )
    {
        emit callPutOnHold( call );
    }
    else if( call.dialing() )
    {
        emit callDialing( call );
    }
    else if( call.incoming() )
    {
        // Turn off screen saver so the incoming call will be visible.
        QtopiaPowerManager::setActive(false);

        emit callIncoming( call );
    }
    else if ( call.dropped()  )
    {
        emit callDropped( call );
    }
    doActiveCalls();

    // Disable screen saver if in a call
    if (hasIncomingCall() || hasActiveCalls() || hasCallsOnHold())
        QtopiaApplication::setPowerConstraint(QtopiaApplication::DisableLightOff);
    else
        QtopiaApplication::setPowerConstraint(QtopiaApplication::Enable);

    emit stateChanged();
}
コード例 #4
0
ファイル: googlesession.cpp プロジェクト: muromec/gqsync
QContact GoogleSession::merge(QContact contact, GoogleContact gContact)
{

  qDebug() << "==";
  qDebug() << contact.label() << gContact.label();

  // merge email lists
  QStringList gl = gContact.emailList(); 
  QStringList el =  contact.emailList();

  for (int i=0; i<gl.size(); ++i) {
    if ( el.contains( gl.at(i) ) )
      qDebug() << "already have email" <<  gl.at(i) ;
    else
      contact.insertEmail(  gl.at(i)  );
  }

  // merge phone number lists
  QMap<QContact::PhoneType, QString> nums  = contact.phoneNumbers(); 
  QMap<QContact::PhoneType, QString> gNums = gContact.phoneNumbers(); 


  // iterate google data
  QMapIterator<QContact::PhoneType, QString> gNumIt(gNums);

  while (gNumIt.hasNext()) {
    gNumIt.next();
    QString phone             = gNumIt.value();
    QContact::PhoneType type  = gNumIt.key();

    if (! nums.values().contains( phone  ) ) {
      gContact.setPhoneNumber(type,  phone);
      qDebug () << "adding phone" << phone << "of type" << type;
    } else {

       // iterate qtopia data
       QMapIterator<QContact::PhoneType, QString> it(nums);
       while (it.hasNext()) {
              it.next();
              qDebug() << "contacts has phone" << it.value() << "of type" << it.key();
              qDebug() << "comparing to google" << phone << "of type" << type;
              if (it.value() ==  phone && it.key() != type ) {

                bool updatedef = (contact.defaultPhoneNumber() == phone);

                nums.remove(it.key() );
                nums.remove(type); // FIXME
                nums.insert(type,  phone);
                contact.setPhoneNumbers(nums);

                if (updatedef)
                  contact.setDefaultPhoneNumber(type);

                qDebug() << "replaced phone of type" <<  type << phone << updatedef;
                break;
              }
       }
      qDebug () << "skipping phone" << phone << type ;

    }
  }

  QStringList googleGroupList = gContact.categories();


  for (int i=0; i<googleGroupList.size(); ++i) {

    QString googleGroupId   = googleGroupList.at(i);
    QString googleGroupName = groups[googleGroupId];
    QString googleGroupQId   = "category." + googleGroupName;


    qDebug() << "Group id" <<googleGroupId << "name" << googleGroupName ;

    if (googleGroupName.isEmpty())
      continue;



    QList<QString> qGroupList = contact.categories();
    if (! qGroupList.contains(googleGroupQId) )  {
      qGroupList << googleGroupQId;

      qDebug() << "Adding group" << googleGroupName ;

      contact.setCategories(qGroupList);

    } else {
      qDebug() << "Skipping group" << googleGroupName;
    }

    qDebug() << "group count" << qGroupList.count();

  }

  qDebug() << "\n";
  return contact;

}
コード例 #5
0
ファイル: contactbrowser.cpp プロジェクト: Camelek/qtmoko
void ContactBrowser::linkClicked(const QString& link)
{
    if (!mDocument)
        return;

    ContactDocument::ContactAnchorType type = mDocument->getAnchorType(link);
    QString number = mDocument->getAnchorTarget(link);
    QContact contact = mDocument->contact();

    if (type == ContactDocument::DialLink) {
        QDialog diag;
        Ui::ActionDialog ui;
        ui.setupUi(&diag);
        QtopiaApplication::setMenuLike(&diag, true);
        ui.actionList->setItemDelegate(new QtopiaItemDelegate());


        // should add mms? send vcard?
        ui.actionList->addItem( new QListWidgetItem(QIcon(":icon/phone/calls"),
                    tr("Call %1", "call the phone number").arg(number)));
        ui.actionList->addItem( new QListWidgetItem(QIcon(":icon/email"),
                    tr("Text %1", "send a text message to the phone number").arg(number)));
        ui.actionList->setCurrentRow(0);


        if (QtopiaApplication::execDialog(&diag)) {
            if (ui.actionList->currentRow() == 0) {
                QtopiaServiceRequest req( "Dialer", "dial(QString,QUniqueId)" );
                req << number << contact.uid();
                req.send();
                emit externalLinkActivated();
            } else {
                QtopiaServiceRequest req( "SMS", "writeSms(QString,QString)" );
                req << contact.label() << number;
                req.send();
                emit externalLinkActivated();
            }
        }
    } else if (type == ContactDocument::EmailLink) {
        QtopiaServiceRequest req( "Email", "writeMail(QString,QString)" );
        req << contact.label() << number;
        req.send();
        emit externalLinkActivated();
    } else if (type == ContactDocument::QdlLink) {
        activateLink(link);
    } else if (type == ContactDocument::CustomLink) {
        QDialog diag;
        Ui::ActionDialog ui;
        ui.setupUi(&diag);
        QtopiaApplication::setMenuLike(&diag, true);
        ui.actionList->setItemDelegate(new QtopiaItemDelegate());

        QContactFieldDefinition def(mDocument->getAnchorField(link));

        QStringList actionIds = def.browseActions();
        foreach(QString a, actionIds) {
            QString label = QContactFieldDefinition::actionLabel(a);
            QIcon icon = QContactFieldDefinition::actionIcon(a);
            if (label.contains("%1"))
                label = label.arg(number);
            ui.actionList->addItem( new QListWidgetItem(icon, label ));
        }