Ejemplo n.º 1
0
int AbstractSyncSource::addItem(SyncItem& item)
{
    QByteArray data((char *)item.getData());
    QUniqueId id = m_model->addRecord(data, QPimSource(), m_type);
    item.setKey(id.toString().toAscii().data());
    m_model->updateRecord(id, data, m_type);
    //qDebug() << "AbstractSyncSource::addItem() " << toString(item) << "Id:" << id.toString();
    if (!id.isNull())
        return 201;    //ok, the requested item was added
    else
        return 500;    //failed, the recipient encountered an error
}
Ejemplo n.º 2
0
QUniqueId GoogleCalHandler::parseId(const QString &gid)
{// create and maintain list of uid->googleid mappings.
    QPreparedSqlQuery q(QPimSqlIO::database());
    q.prepare("SELECT id, gid FROM googleid WHERE gid = :g");
    q.bindValue(":g", gid);
    q.exec();
    if (q.next())
        return QUniqueId::fromUInt(q.value(0).toUInt());

    // TODO stolen from QAppointmentGCalIO.  Will later need to make sure all id creation mapping
    // goes through same code, rather than pimsqlio.
    // note uid's from two different devices (e.g. desktop/pda) will not match
    static QUuid appScope("672cd357-c984-40e2-b47d-ffde5a65137c");
    QUniqueIdGenerator g(appScope); // later, same scop method as xml
    QUniqueId u = g.createUniqueId();
    q.prepare("INSERT INTO googleid (id, gid) VALUES (:i, :g)");
    q.bindValue(":i", u.toUInt());
    q.bindValue(":g", gid);
    // TODO error handling for sql statements.
    q.exec();
    return u;
}
Ejemplo n.º 3
0
TaskDialog::TaskDialog( const QTask& task, QWidget *parent,
        Qt::WFlags fl )
    : QDialog( parent, fl), todo( task ),
    inputNotes(0), inputNotesQC(0),
    dueCheck(0), startedCheck(0), completedCheck(0),
    dueEdit(0), startedEdit(0), completedEdit(0),
    inputDescription(0), comboPriority(0), comboStatus(0),
    spinComplete(0), comboCategory(0), recurDetails(0), reminderPicker(0),
    recurStack(0), recurControls(0)
{
    QUniqueId id = todo.dependentChildrenOfType(QString("duedate")).value(0);

    newTask = false;

    // grab the reminder defaults from Datebook
    bool setAlarm = true;

    {
        QSettings config("Trolltech","DateBook");
        config.beginGroup("Main");
        defaultReminderTime = QTime(config.value("startviewtime", 8).toInt(), 0);
        setAlarm = config.value("alarmpreset").toBool();
    }

    if (!id.isNull()) {
        QAppointmentModel am;
        todoAppt = am.appointment(id);

        // Preload this, since alarm minutes for NoAlarm aren't stored in the db
        if (todoAppt.alarm() == QAppointment::NoAlarm)
            todoAppt.setAlarm(-(defaultReminderTime.hour() * 60 + defaultReminderTime.minute()), QAppointment::NoAlarm);
    } else {
        todoAppt.setAlarm(-(defaultReminderTime.hour() * 60 + defaultReminderTime.minute()), setAlarm ? QAppointment::Audible : QAppointment::NoAlarm);
        todoAppt.setAllDay();
    }

    init();
}
Ejemplo n.º 4
0
/*!
  Dials a \a number if there are no currently active calls. If a
  \a contact is specified, it is used as the contact to display and
  insert into the call history. Before calling this function,
  you should check that there are no incoming calls, or active calls.
  If \a sendcallerid is true, then send the caller's identifier as part
  of the dial sequence.

  If \a callType is "Voice" a GSM call will be dialed.  If \a callType is
  "VoIP" a VoIP call will be dialed.
*/
void DialerControl::dial( const QString &number, bool sendcallerid, const QString& callType, const QUniqueId &contact )
{

    QUniqueId matchedContact;
    if (contact.isNull() && !number.isEmpty())
        matchedContact = ServerContactModel::instance()->matchPhoneNumber(number).uid();
    else
        matchedContact = contact;

    if ( isDialing() ) {
        //qWarning("BUG! Attempt to dial while there is already a dialing call");
    }
    if( !hasActiveCalls() && !isDialing() )
    {
        // Collect up the dial options.
        QDialOptions dialopts;
        dialopts.setNumber( number );
        if ( sendcallerid )
            dialopts.setCallerId( QDialOptions::SendCallerId );
        else
            dialopts.setCallerId( QDialOptions::DefaultCallerId );
        dialopts.setContact( matchedContact );

        // Allow other parts of the server (e.g. GsmKeyActions) to
        // modify the dial options to account for supplementary services.
        bool handledAlready = false;
        emit modifyDial( dialopts, handledAlready );
        if ( handledAlready )
            return;

        // Call the specified number.
        QPhoneCall call = createCall(callType);
        phoneValueSpace.setAttribute( "LastDialedCall", QVariant(number) );
        call.dial( dialopts );

        // cache call here to preserve the information even if the battery run out.
        cacheCall( call );
    }
}
Ejemplo n.º 5
0
/*!
  Resets the SQL representation of the SIM Card for this storage.  This
  includes removing any contacts that can be stored completely on the SIM,
  resetting the mapping of contact id to SIM card index, and in the case
  of the "SM" storage type, resetting the information on the available
  indexes to store contact phone numbers.

  A contact that can be stored completely on the sim is defined as
  one that is equal to a contact that has copied only the original contacts phone numbers, unique identity, and first name.

  \sa storage()
*/
void QContactSimSyncer::resetSqlState()
{
    qLog(SimPhoneBook) << mSimType << "::resetSqlState()";

    if (mSimType == "SM") {
        simValueSpace = new QValueSpaceObject("/SIM/Contacts");
        simValueSpace->setAttribute("Loaded", false);
    } else
        simValueSpace = 0;

    QDateTime syncTime = QTimeZone::current().toUtc(QDateTime::currentDateTime());
    syncTime = syncTime.addMSecs(-syncTime.time().msec());

    if (mAccess->startTransaction(syncTime)) {
        QPreparedSqlQuery q(QPimSqlIO::database());

        qLog(SimPhoneBook) << mSimType << "::resetSqlState() - get cardid";

        q.prepare("SELECT cardid FROM currentsimcard WHERE storage = :simtype");
        q.bindValue(":simtype", mSimType);
        q.exec();
        if (!q.next()) {
            qLog(SimPhoneBook) << mSimType << "::resetSqlState() - no card found";
            // already cleared the card.
            if (mAccess->commitTransaction())
                return;
        } else {
            QString lastActiveCard = q.value(0).toString();
            qLog(SimPhoneBook) << mSimType << "::resetSqlState() - clear" << lastActiveCard;

            q.prepare("SELECT recid, simlabelidmap.label FROM contacts JOIN simlabelidmap ON sqlid = recid WHERE cardid = :c AND storage = :s");
            q.bindValue(":s", mSimType);
            q.bindValue(":c", lastActiveCard);

            q.exec();
            QList<QUniqueId> removeTargets;
            while(q.next()) {
                QContact existing, compare;
                QUniqueId recid = QUniqueId::fromUInt(q.value(0).toUInt());
                QString label = q.value(1).toString();
                existing = mAccess->contact(recid);
                qLog(SimPhoneBook) << mSimType << "::resetSqlState() - check if" << recid.toString() << "should be removed";
                if (QContactSimContext::simLabel(existing) != label) {
                    qLog(SimPhoneBook) << mSimType << "::resetSqlState() - label mis-match" << QContactSimContext::simLabel(existing) << label;
                    // truncated label, don't remove or will lose info.
                    continue;
                }
                compare.setUid(existing.uid());
                compare.setFirstName(existing.firstName());
                compare.setLastName(existing.lastName());
                compare.setPhoneNumbers(existing.phoneNumbers());
                compare.setDefaultPhoneNumber(existing.defaultPhoneNumber());
                if (compare == existing) { // e.g. is only data that fits on the sim.
                    removeTargets.append(QUniqueId::fromUInt(q.value(0).toUInt()));
                    qLog(SimPhoneBook) << mSimType << "::resetSqlState() - remove contact" << q.value(0).toUInt();
                } else {
                    qLog(SimPhoneBook) << mSimType << "::resetSqlState() - contact == mismatch";
                }
            }

            if (mAccess->removeContacts(removeTargets))
            {
                qLog(SimPhoneBook) << mSimType << "::resetSqlState() - remove current simcard for storage";
                q.clearErrors();
                q.prepare("DELETE FROM currentsimcard WHERE storage = :simtype");
                q.bindValue(":simtype", mSimType);
                q.exec();

                qLog(SimPhoneBook) << mSimType << "::resetSqlState() - remove idmap for storage";
                q.prepare("DELETE FROM simcardidmap WHERE cardid = :c AND storage = :simtype");
                q.bindValue(":simtype", mSimType);
                q.bindValue(":c", lastActiveCard);
                q.exec();

                // only remove 'forgotten' records.
                qLog(SimPhoneBook) << mSimType << "::resetSqlState() - remove label idmap for storage";
                q.prepare("DELETE FROM simlabelidmap WHERE sqlid = :r");
                foreach (QUniqueId id, removeTargets) {
                    q.bindValue(":r", id.toUInt());
                    q.exec();
                }

                if (q.errorCount() == 0 && mAccess->commitTransaction())
                    return;
            }
Ejemplo n.º 6
0
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();
}
Ejemplo n.º 7
0
SyncItem *AbstractSyncSource::getNext(ItemSet set, bool withData)
{
    //qDebug() << "AbstractSyncSource::getNext(" << set << "," << withData << ")";
    QUniqueId id;
    SyncState state = SYNC_STATE_NONE;
    bool endTransaction = false;

    if (set == All) {
        m_indexAll++;
        if (m_indexAll >= m_model->count()) {
            //qDebug() << "AbstractSyncSource::getNext() No further item available";
            endTransaction = true;
        } else {
            id = m_model->id(m_indexAll);
        }
    } else if (set == New) {
        m_indexNew++;
        if (m_indexNew >= added.size()) {
            //qDebug() << "AbstractSyncSource::getNext() No further new item available";
            endTransaction = true;
        } else {
            state = SYNC_STATE_NEW;
            id = added[m_indexNew];
        }
    } else if (set == Updated) {
        m_indexUpdated++;
        if (m_indexUpdated >= modified.size()) {
            //qDebug() << "AbstractSyncSource::getNext() No further updated item available";
            endTransaction = true;
        } else {
            state = SYNC_STATE_UPDATED;
            id = modified[m_indexUpdated];
        }
    } else if (set == Deleted) {
        m_indexDeleted++;
        if (m_indexDeleted >= removed.size()) {
            //qDebug() << "AbstractSyncSource::getNext() No further deleted item available";
            endTransaction = true;
        } else {
            state = SYNC_STATE_DELETED;
            id = removed[m_indexDeleted];
        }
    }

    if (endTransaction && m_transactionRunning) {
        if (m_model->commitSyncTransaction()) {
            m_transactionRunning = false;
            m_lastSync = m_currentSync;
            //qDebug() << "AbstractSyncSource::getNext() Commit sync";
        } else {
            //qDebug() << "AbstractSyncSource::getNext() Commit sync failed";
        }
    } else {
        if (!id.isNull()) {
            return createSyncItem(id, withData, state);
        } else {
            //qDebug() << "AbstractSyncSource::getNext() Invalid Id";
        }
    }
    return 0;
}