Пример #1
0
void
KBuildServiceTypeFactory::addEntry(KSycocaEntry *newEntry, const char *resource)
{
   KServiceType * serviceType = (KServiceType *) newEntry;
   if ( (*m_entryDict)[ newEntry->name() ] )
   {
     // Already exists
     if (serviceType->desktopEntryPath().endsWith("kdelnk"))
        return; // Skip

     // Replace
     KSycocaFactory::removeEntry(newEntry);
   }
   KSycocaFactory::addEntry(newEntry, resource);


   const TQMap<TQString,TQVariant::Type>& pd = serviceType->propertyDefs();
   TQMap<TQString,TQVariant::Type>::ConstIterator pit = pd.begin();
   for( ; pit != pd.end(); ++pit )
   {
     if (!m_propertyTypeDict.contains(pit.key()))
       m_propertyTypeDict.insert(pit.key(), pit.data());
     else if (m_propertyTypeDict[pit.key()] != pit.data())
       kdWarning(7021) << "Property '"<< pit.key() << "' is defined multiple times ("<< serviceType->name() <<")" <<endl;
   }
}
Пример #2
0
KServiceType * KServiceTypeFactory::findServiceTypeByName(const TQString &_name)
{
   if (!m_sycocaDict) return 0L; // Error!
   assert (!KSycoca::self()->isBuilding());
   int offset = m_sycocaDict->find_string( _name );
   if (!offset) return 0; // Not found
   KServiceType * newServiceType = createEntry(offset);

   // Check whether the dictionary was right.
   if (newServiceType && (newServiceType->name() != _name))
   {
     // No it wasn't...
     delete newServiceType;
     newServiceType = 0; // Not found
   }
   return newServiceType;
}
Пример #3
0
KSycocaEntry* KBuildServiceTypeFactory::createEntry(const QString &file, const char *resource) const
{
    QString name = file;
    int pos = name.lastIndexOf('/');
    if (pos != -1) {
        name = name.mid(pos+1);
    }

    if (name.isEmpty())
        return 0;

    KDesktopFile desktopFile(resource, file);
    const KConfigGroup desktopGroup = desktopFile.desktopGroup();

    if ( desktopGroup.readEntry( "Hidden", false ) == true )
        return 0;

    const QString type = desktopGroup.readEntry( "Type" );
    if ( type != QLatin1String( "ServiceType" ) ) {
        kWarning(7012) << "The service type config file " << desktopFile.fileName() << " has Type=" << type << " instead of Type=ServiceType";
        return 0;
    }

    const QString serviceType = desktopGroup.readEntry( "X-KDE-ServiceType" );

    if ( serviceType.isEmpty() ) {
        kWarning(7012) << "The service type config file " << desktopFile.fileName() << " does not contain a ServiceType=... entry";
        return 0;
    }

    KServiceType* e = new KServiceType( &desktopFile );

    if (e->isDeleted()) {
        delete e;
        return 0;
    }

    if ( !(e->isValid()) ) {
        kWarning(7012) << "Invalid ServiceType : " << file;
        delete e;
        return 0;
    }

    return e;
}
Пример #4
0
KSycocaEntry *
KBuildServiceTypeFactory::createEntry(const TQString &file, const char *resource)
{
  TQString name = file;
  int pos = name.findRev('/');
  if (pos != -1)
  {
     name = name.mid(pos+1);
  }

  if (name.isEmpty())
     return 0;

  KDesktopFile desktopFile(file, true, resource);

  if ( desktopFile.readBoolEntry( "Hidden", false ) == true )
      return 0;

  // TODO check Type field first
  TQString mime = desktopFile.readEntry( "MimeType" );
  TQString service = desktopFile.readEntry( "X-TDE-ServiceType" );

  if ( mime.isEmpty() && service.isEmpty() )
  {
    TQString tmp = TQString("The service/mime type config file\n%1\n"
                  "does not contain a ServiceType=...\nor MimeType=... entry").arg( file );
    kdWarning(7012) << tmp << endl;
    return 0;
  }

  KServiceType* e;
  if ( mime == "inode/directory" )
    e = new KFolderType( &desktopFile );
  else if ( (mime == "application/x-desktop")
         || (mime == "media/builtin-mydocuments")
         || (mime == "media/builtin-mycomputer")
         || (mime == "media/builtin-mynetworkplaces")
         || (mime == "media/builtin-printers")
         || (mime == "media/builtin-trash")
         || (mime == "media/builtin-webbrowser") )
    e = new KDEDesktopMimeType( &desktopFile );
  else if ( mime == "application/x-executable" || mime == "application/x-shellscript" )
    e = new KExecMimeType( &desktopFile );
  else if ( !mime.isEmpty() )
    e = new KMimeType( &desktopFile );
  else
    e = new KServiceType( &desktopFile );

  if (e->isDeleted())
  {
    delete e;
    return 0;
  }

  if ( !(e->isValid()) )
  {
    kdWarning(7012) << "Invalid ServiceType : " << file << endl;
    delete e;
    return 0;
  }

  return e;
}
Пример #5
0
KService::List KServiceType::offers(const QString &_servicetype)
{
    QDict< KService > dict(53);
    KService::List lst;

    // Services associated directly with this servicetype (the normal case)
    KServiceType::Ptr serv = KServiceTypeFactory::self()->findServiceTypeByName(_servicetype);
    if(serv)
        addUnique(lst, dict, KServiceFactory::self()->offers(serv->offset()), false);
    else
        kdWarning(7009) << "KServiceType::offers : servicetype " << _servicetype << " not found" << endl;

    // Find services associated with any mimetype parents. e.g. text/x-java -> text/plain
    KMimeType::Ptr mime = dynamic_cast< KMimeType * >(static_cast< KServiceType * >(serv));
    bool isAMimeType = (mime != 0);
    if(mime)
    {
        while(true)
        {
            QString parent = mime->parentMimeType();
            if(parent.isEmpty())
                break;
            mime = dynamic_cast< KMimeType * >(KServiceTypeFactory::self()->findServiceTypeByName(parent));
            if(!mime)
                break;

            addUnique(lst, dict, KServiceFactory::self()->offers(mime->offset()), false);
        }
    }
    serv = mime = 0;

    // QValueListIterator<KService::Ptr> it = lst.begin();
    // for( ; it != lst.end(); ++it )
    //    kdDebug() << (*it).data() << " " << (*it)->name() << endl;

    // Support for all/* is deactivated by KServiceTypeProfile::configurationMode()
    // (and makes no sense when querying for an "all" servicetype itself
    // nor for non-mimetypes service types)
    if(!KServiceTypeProfile::configurationMode() && isAMimeType && _servicetype.left(4) != "all/")
    {
        // Support for services associated with "all"
        KServiceType *servAll = KServiceTypeFactory::self()->findServiceTypeByName("all/all");
        if(servAll)
        {
            addUnique(lst, dict, KServiceFactory::self()->offers(servAll->offset()), true);
        }
        else
            kdWarning(7009) << "KServiceType::offers : servicetype all/all not found" << endl;
        delete servAll;

        // Support for services associated with "allfiles"
        if(_servicetype != "inode/directory" && _servicetype != "inode/directory-locked")
        {
            KServiceType *servAllFiles = KServiceTypeFactory::self()->findServiceTypeByName("all/allfiles");
            if(servAllFiles)
            {
                addUnique(lst, dict, KServiceFactory::self()->offers(servAllFiles->offset()), true);
            }
            else
                kdWarning(7009) << "KServiceType::offers : servicetype all/allfiles not found" << endl;
            delete servAllFiles;
        }
    }

    return lst;
}