KIO
predicateproperties.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE libraries 00002 00003 Copyright (c) 2007 Jos van den Oever <jos@vandenoever.info> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License (LGPL) as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 #include "kfilemetainfo_p.h" 00021 #include "kglobal.h" 00022 #include <strigi/streamanalyzer.h> 00023 #include <strigi/analysisresult.h> 00024 #include <strigi/analyzerconfiguration.h> 00025 #include <QDebug> 00026 using namespace Strigi; 00027 using namespace std; 00028 00029 class PredicateProperties::Private : public QSharedData { 00030 public: 00031 static const QString nullString; 00032 static const QStringList nullStringList; 00033 static const PredicateProperties nullPP; 00034 PredicateProperties parent; 00035 QString key; 00036 QString name; 00037 QVariant::Type type; 00038 uint attributes; 00039 }; 00040 const QString PredicateProperties::Private::nullString; 00041 const QStringList PredicateProperties::Private::nullStringList; 00042 const PredicateProperties PredicateProperties::Private::nullPP; 00043 00044 PredicateProperties::PredicateProperties(const QString& predicate) { 00045 if (!predicate.isEmpty()) { 00046 p = new Private(); 00047 p->key = predicate; 00048 } 00049 } 00050 PredicateProperties::PredicateProperties(const PredicateProperties& pp) 00051 :p(pp.p) { 00052 } 00053 PredicateProperties::~PredicateProperties() { 00054 } 00055 const PredicateProperties& 00056 PredicateProperties::operator=(const PredicateProperties& pp) { 00057 p = pp.p; 00058 return pp; 00059 } 00060 const QString& 00061 PredicateProperties::name() const { 00062 if (p == 0) return Private::nullString; 00063 return (p->name.isEmpty()) ?p->key :p->name; 00064 } 00065 00066 const QStringList& 00067 PredicateProperties::suggestedValues() const { 00068 return Private::nullStringList; 00069 } 00070 00071 uint 00072 PredicateProperties::minCardinality() const { 00073 return 0; 00074 } 00075 00076 uint 00077 PredicateProperties::maxCardinality() const { 00078 return 0; 00079 } 00080 00081 uint 00082 PredicateProperties::attributes() const { 00083 return (p) ?p->attributes :0; 00084 } 00085 QVariant::Type 00086 PredicateProperties::type() const { 00087 return (p) ?p->type :QVariant::Invalid; 00088 } 00089 QValidator* 00090 PredicateProperties::createValidator() const { 00091 return 0; 00092 } 00093 const PredicateProperties& 00094 PredicateProperties::parent() const { 00095 return (p) ?p->parent :Private::nullPP; 00096 } 00097 bool 00098 PredicateProperties::isValid() const { 00099 return p; 00100 } 00101 00103 00104 K_GLOBAL_STATIC(PredicatePropertyProvider, staticPredicatePropertyProvider) 00105 00106 PredicatePropertyProvider* 00107 PredicatePropertyProvider::self() { 00108 return staticPredicatePropertyProvider; 00109 } 00110 PredicateProperties 00111 PredicatePropertyProvider::getPredicateProperties(const QString& key) { 00112 PredicateProperties p(key); 00113 return p; 00114 } 00115 00116 class ShallowAnalysisConfiguration : public Strigi::AnalyzerConfiguration { 00122 int64_t maximalStreamReadLength(const Strigi::AnalysisResult& ar) { 00123 // 64k should be enough 00124 return (ar.depth() == 0) ?65536 :0; 00125 } 00126 }; 00127 00128 class PredicatePropertyProvider::Private { 00129 public: 00130 ShallowAnalysisConfiguration config; 00131 StreamAnalyzer indexer; 00132 Private() :indexer(config) {} 00133 }; 00134 PredicatePropertyProvider::PredicatePropertyProvider() { 00135 p = new PredicatePropertyProvider::Private(); 00136 } 00137 PredicatePropertyProvider::~PredicatePropertyProvider() { 00138 delete p; 00139 } 00140 StreamAnalyzer& 00141 PredicatePropertyProvider::indexer() { 00142 return p->indexer; 00143 }