Esempio n. 1
0
void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern )
{
  ContentLine cl;
  cl.setName( EntityTypeToParamName( EntitySound ) );

  if ( sound.isIntern() && sound.data().isNull() )
    return;

  if ( !sound.isIntern() && sound.url().isEmpty() )
    return;

  ParamList params;
  if ( sound.isIntern() ) {
    QByteArray data = sound.data();
    if ( intern ) { // only for vCard export we really write the data inline
        cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
    } else { // save sound in cache
      QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
      if ( file.open( IO_WriteOnly ) ) {
        file.writeBlock( data );
      }
      cl.setValue( new TextValue( "<dummy>" ) );
    }
    params.append( new Param( "ENCODING", "b" ) );
  } else {
    cl.setValue( new TextValue( sound.url().utf8() ) );
    params.append( new Param( "VALUE", "uri" ) );
  }

  cl.setParamList( params );
  vcard->add( cl );
}
Esempio n. 2
0
void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key )
{
  ContentLine cl;
  cl.setName( EntityTypeToParamName( EntityKey ) );

  ParamList params;
  if ( key.isBinary() ) {
    cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) );
    params.append( new Param( "ENCODING", "b" ) );
  } else {
    cl.setValue( new TextValue( key.textData().utf8() ) );
  }

  switch ( key.type() ) {
    case Key::X509:
      params.append( new Param( "TYPE", "X509" ) );
      break;
    case Key::PGP:
      params.append( new Param( "TYPE", "PGP" ) );
      break;
    case Key::Custom:
      params.append( new Param( "TYPE", key.customTypeString().utf8() ) );
      break;
  }

  cl.setParamList( params );
  vcard->add( cl );
}
Esempio n. 3
0
void VCardFormatImpl::addAddressParam( ContentLine *cl, int type )
{
  ParamList params;
  if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) );
  if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) );
  if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) );
  if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) );
  if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) );
  if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) );
  if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) );
  cl->setParamList( params );
}
Esempio n. 4
0
void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent )
{
  if ( agent.isIntern() && !agent.addressee() )
    return;

  if ( !agent.isIntern() && agent.url().isEmpty() )
    return;

  ContentLine cl;
  cl.setName( EntityTypeToParamName( EntityAgent ) );

  ParamList params;
  if ( agent.isIntern() ) {
    QString vstr;
    Addressee *addr = agent.addressee();
    if ( addr ) {
      writeToString( (*addr), vstr );
      vstr.replace( ":", "\\:" );
      vstr.replace( ",", "\\," );
      vstr.replace( ";", "\\;" );
      vstr.replace( "\r\n", "\\n" );
      cl.setValue( new TextValue( vstr.utf8() ) );
    } else
      return;
  } else {
    cl.setValue( new TextValue( agent.url().utf8() ) );
    params.append( new Param( "VALUE", "uri" ) );
  }

  cl.setParamList( params );
  vcard->add( cl );
}
Esempio n. 5
0
/*! Converts this \l{RuleAction} to a normal \l{Action}.
 *  \sa Action, */
Action RuleAction::toAction() const
{
    Action action(m_actionTypeId, m_deviceId);
    ParamList params;
    foreach (const RuleActionParam &ruleActionParam, m_ruleActionParams) {
        Param param;
        param.setName(ruleActionParam.name());
        param.setValue(ruleActionParam.value());
        params.append(param);
    }
Esempio n. 6
0
/*! Sets the \a value of the \l{Param} with the given \a paramName. */
void Device::setParamValue(const QString &paramName, const QVariant &value)
{
    ParamList params;
    foreach (Param param, m_params) {
        if (param.name() == paramName) {
            param.setValue(value);
        }
        params.append(param);
    }
    m_params = params;
}
Esempio n. 7
0
void TestEvents::params()
{
    Event event;
    ParamList params;
    Param p("foo", "bar");
    params.append(p);
    event.setParams(params);

    QVERIFY(event.param("foo").value().toString() == "bar");
    QVERIFY(!event.param("baz").value().isValid());
}
Esempio n. 8
0
void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern )
{
  ContentLine cl;
  cl.setName( EntityTypeToParamName( type ) );

  if ( pic.isIntern() && pic.data().isNull() )
    return;

  if ( !pic.isIntern() && pic.url().isEmpty() )
    return;

  ParamList params;
  if ( pic.isIntern() ) {
    QImage img = pic.data();
    if ( intern ) { // only for vCard export we really write the data inline
      QByteArray data;
      QDataStream s( data, IO_WriteOnly );
      s.setVersion( 4 ); // to produce valid png files
      s << img;
      cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
    } else { // save picture in cache
      QString dir;
      if ( type == EntityPhoto )
        dir = "photos";
      if ( type == EntityLogo )
        dir = "logos";

      img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() );
      cl.setValue( new TextValue( "<dummy>" ) );
    }
    params.append( new Param( "ENCODING", "b" ) );
    if ( !pic.type().isEmpty() )
      params.append( new Param( "TYPE", pic.type().utf8() ) );
  } else {
    cl.setValue( new TextValue( pic.url().utf8() ) );
    params.append( new Param( "VALUE", "uri" ) );
  }

  cl.setParamList( params );
  vcard->add( cl );
}
Esempio n. 9
0
void DevicePluginLircd::buttonPressed(const QString &remoteName, const QString &buttonName, int repeat)
{
    Device *remote = nullptr;
    QList<Device*> configuredRemotes = deviceManager()->findConfiguredDevices(lircdDeviceClassId);
    foreach (Device *device, configuredRemotes) {
        if (device->paramValue("remoteName").toString() == remoteName) {
            remote = device;
            break;
        }
    }
    if (!remote) {
        qCWarning(dcLircd) << "Unhandled remote" << remoteName << buttonName;
        return;
    }

    qCDebug(dcLircd) << "found remote" << remoteName << supportedDevices().first().eventTypes().count();
    ParamList params;
    Param buttonParam("button", buttonName);
    params.append(buttonParam);
    Param repeatParam("repeat", repeat);
    params.append(repeatParam);
    Event event(LircKeypressEventTypeId, remote->id(), params);
    emitEvent(event);
}
Esempio n. 10
0
DeviceManager::DeviceError DevicePluginDateTime::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{
    Q_UNUSED(deviceClassId);

    QList<DeviceDescriptor> deviceDescriptors;
    foreach (QByteArray timeZone, QTimeZone::availableTimeZoneIds()) {
        QByteArray continent = params.paramValue("continent").toByteArray();
        if(timeZone.contains(continent)){
            DeviceDescriptor descriptor(dateTimeDeviceClassId, timeZone.right(timeZone.length() - (continent.length() + 1)), continent);
            ParamList params;
            params.append(Param("timezone", timeZone));
            descriptor.setParams(params);
            deviceDescriptors.append(descriptor);
        }
    }
Esempio n. 11
0
void DevicePluginIntertechno::radioData(const QList<int> &rawData)
{


    // filter right here a wrong signal length
    if(rawData.length() != 49){
        return;
    }
    
    QList<Device*> deviceList = deviceManager()->findConfiguredDevices(intertechnoRemote);
    if(deviceList.isEmpty()){
        return;
    }

    int delay = rawData.first()/31;
    QByteArray binCode;
    
    // =======================================
    // average 314
    if(delay > 300 && delay < 400){
        // go trough all 48 timings (without sync signal)
        for(int i = 1; i <= 48; i+=2 ){
            int div;
            int divNext;
            
            // if short
            if(rawData.at(i) <= 700){
                div = 1;
            }else{
                div = 3;
            }
            // if long
            if(rawData.at(i+1) < 700){
                divNext = 1;
            }else{
                divNext = 3;
            }
            
            //              _
            // if we have  | |___ = 0 -> in 4 delays => 1000
            //                 _
            // if we have  ___| | = 1 -> in 4 delays => 0001
            
            if(div == 1 && divNext == 3){
                binCode.append('0');
            }else if(div == 3 && divNext == 1){
                binCode.append('1');
            }else{
                return;
            }
        }
    }else{
        return;
    }

    // =======================================
    // Check nibble 16-19, must be 0001
    if(binCode.mid(16,4) != "0001"){
        return;
    }

    // =======================================
    // Get family code
    QString familyCode;
    bool ok;
    QByteArray familyCodeBin = binCode.left(8);
    int famiyCodeInt = familyCodeBin.toInt(&ok,2);

    if(!ok){
        return;
    }

    switch (famiyCodeInt) {
    case 0b00000000:
        familyCode = "A";
        break;
    case 0b01000000:
        familyCode = "B";
        break;
    case 0b00010000:
        familyCode = "C";
        break;
    case 0b01010000:
        familyCode = "D";
        break;
    case 0b00000100:
        familyCode = "E";
        break;
    case 0b01000100:
        familyCode = "F";
        break;
    case 0b00010100:
        familyCode = "G";
        break;
    case 0b01010100:
        familyCode = "H";
        break;
    case 0b00000001:
        familyCode = "I";
        break;
    case 0b01000001:
        familyCode = "J";
        break;
    case 0b00010001:
        familyCode = "K";
        break;
    case 0b01010001:
        familyCode = "L";
        break;
    case 0b00000101:
        familyCode = "M";
        break;
    case 0b01000101:
        familyCode = "N";
        break;
    case 0b00010101:
        familyCode = "O";
        break;
    case 0b01010101:
        familyCode = "P";
        break;
    default:
        return;
    }

    // =======================================
    // Get button code
    QString buttonCode;
    QByteArray buttonCodeBin = binCode.mid(8,8);
    int buttonCodeInt = buttonCodeBin.toInt(&ok,2);

    if(!ok){
        return;
    }

    switch (buttonCodeInt) {
    case 0b00000000:
        buttonCode = "1";
        break;
    case 0b01000000:
        buttonCode = "2";
        break;
    case 0b00010000:
        buttonCode = "3";
        break;
    case 0b01010000:
        buttonCode = "4";
        break;
    case 0b00000100:
        buttonCode = "5";
        break;
    case 0b01000100:
        buttonCode = "6";
        break;
    case 0b00010100:
        buttonCode = "7";
        break;
    case 0b01010100:
        buttonCode = "8";
        break;
    case 0b00000001:
        buttonCode = "9";
        break;
    case 0b01000001:
        buttonCode = "10";
        break;
    case 0b00010001:
        buttonCode = "11";
        break;
    case 0b01010001:
        buttonCode = "12";
        break;
    case 0b00000101:
        buttonCode = "13";
        break;
    case 0b01000101:
        buttonCode = "14";
        break;
    case 0b00010101:
        buttonCode = "15";
        break;
    case 0b01010101:
        buttonCode = "16";
        break;
    default:
        return;
    }

    // =======================================
    // get power status -> On = 0100, Off = 0001
    bool power;
    if(binCode.right(4).toInt(0,2) == 5){
        power = true;
    }else if(binCode.right(4).toInt(0,2) == 4){
        power = false;
    }else{
        return;
    }

    qDebug() << "family code = " << familyCode << "button code =" << buttonCode << power;

    // ===================================================
    Device *device = 0;
    foreach (Device *dev, deviceList) {
        if (dev->paramValue("familyCode").toString() == familyCode) {
            // Yippie! We found the device.
            device = dev;
            break;
        }
    }
    if (!device) {
        qWarning() << "couldn't find any configured device for intertech familyCode:" << familyCode;
        return;
    }

    ParamList params;
    Param powerParam("power", power);
    params.append(powerParam);

    // FIXME: find a better way to get to the remote DeviceClass
    DeviceClass deviceClass = supportedDevices().first();
    foreach (const EventType &eventType, deviceClass.eventTypes()) {
        if (eventType.name() == buttonCode) {
            qDebug() << "emit event " << pluginName() << familyCode << eventType.name() << power;
            Event event = Event(eventType.id(), device->id(), params);
            emit emitEvent(event);
            return;
        }
    }
}
Esempio n. 12
0
void VCardFormatImpl::addTelephoneValue( VCARD::VCard *v, const PhoneNumber &p )
{
  if ( p.number().isEmpty() )
    return;

  ContentLine cl;
  cl.setName(EntityTypeToParamName(EntityTelephone));
  cl.setValue(new TelValue( p.number().utf8() ));

  ParamList params;
  if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) );
  if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) );
  if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) );
  if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) );
  if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) );
  if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) );
  if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) );
  if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) );
  if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) );
  if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) );
  if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) );
  if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) );
  if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) );
  if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) );
  cl.setParamList( params );

  v->add(cl);
}