• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
completionstorage.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2009 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 #include "completionstorage.h"
25 #include "project.h"
26 #include "prefs_lokalize.h"
27 #include <QCoreApplication>
28 
29 
30 
31 CompletionStorage* CompletionStorage::_instance=0;
32 void CompletionStorage::cleanupCompletionStorage()
33 {
34  delete CompletionStorage::_instance; CompletionStorage::_instance = 0;
35 }
36 
37 CompletionStorage* CompletionStorage::instance()
38 {
39  if (_instance==0 )
40  {
41  _instance=new CompletionStorage();
42  qAddPostRoutine(CompletionStorage::cleanupCompletionStorage);
43  }
44  return _instance;
45 }
46 
47 
48 void CompletionStorage::scanCatalog(Catalog* catalog)
49 {
50  QTime a;a.start();
51 
52  int wordCompletionLength=Settings::self()->wordCompletionLength();
53  /* we can't skip the scanning because there might be explicit completion triggered
54  if (wordCompletionLength<3 || !catalog->numberOfEntries())
55  return;
56  */
57  wordCompletionLength+=3;//only long words
58 
59  QString accel=Project::instance()->accel();
60 
61  DocPosition pos(0);
62  do
63  {
64  QString string=catalog->targetWithTags(pos).string;
65  string.remove(accel);
66 
67  const QStringList& words=string.toLower().split(rxSplit,QString::SkipEmptyParts);
68  foreach(const QString& word, words)
69  {
70  if (word.length()<wordCompletionLength)
71  continue;
72  m_words[word]++;
73  }
74  }
75  while (switchNext(catalog,pos));
76 
77  kDebug()<<"indexed"<<catalog->url()<<"for word completion in"<<a.elapsed()<<"msecs";
78 }
79 
80 QStringList CompletionStorage::makeCompletion(const QString& word) const
81 {
82  //QTime a;a.start();
83  if (word.isEmpty())
84  return QStringList();
85  QMultiMap<int,QString> hits; //we use the fact that qmap sorts it's items by keys
86  QString cleanWord=word.toLower();
87  QMap<QString,int>::const_iterator it=m_words.lowerBound(cleanWord);
88  while(it!=m_words.constEnd() && it.key().startsWith(cleanWord))
89  {
90  hits.insert(-it.value(),it.key().mid(word.length()));
91  ++it;
92  }
93  //kDebug()<<"hits generated in"<<a.elapsed()<<"msecs";
94  return hits.values();
95 }
96 
CompletionStorage::makeCompletion
QStringList makeCompletion(const QString &) const
Definition: completionstorage.cpp:80
project.h
Catalog::url
const KUrl & url() const
Definition: catalog.h:189
Catalog::targetWithTags
CatalogString targetWithTags(const DocPosition &pos) const
Definition: catalog.cpp:211
QMap::values
QList< T > values() const
switchNext
bool switchNext(Catalog *&catalog, DocPosition &pos, int parts)
Definition: pos.cpp:88
QMap
Project::instance
static Project * instance()
Definition: project.cpp:67
completionstorage.h
CompletionStorage::instance
static CompletionStorage * instance()
Definition: completionstorage.cpp:37
CompletionStorage
Definition: completionstorage.h:30
CatalogString::string
QString string
Definition: catalogstring.h:130
QString::remove
QString & remove(int position, int n)
Settings::wordCompletionLength
static int wordCompletionLength()
Get WordCompletionLength.
Definition: prefs_lokalize.h:277
QTime
Settings::self
static Settings * self()
Definition: prefs_lokalize.cpp:19
DocPosition
This struct represents a position in a catalog.
Definition: pos.h:38
ProjectBase::accel
QString accel() const
Get Accel.
Definition: projectbase.h:235
QTime::elapsed
int elapsed() const
CompletionStorage::rxSplit
QRegExp rxSplit
Definition: completionstorage.h:44
CompletionStorage::scanCatalog
void scanCatalog(Catalog *)
Definition: completionstorage.cpp:48
QString::isEmpty
bool isEmpty() const
QMap::constEnd
const_iterator constEnd() const
QMultiMap::insert
QMap< Key, T >::iterator insert(const Key &key, const T &value)
QString
QMap::lowerBound
iterator lowerBound(const Key &key)
QStringList
QString::toLower
QString toLower() const
QMap::key
const Key key(const T &value) const
prefs_lokalize.h
QString::length
int length() const
QStringList::split
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
QTime::start
void start()
Catalog
This class represents a catalog It uses CatalogStorage interface to work with catalogs in different f...
Definition: catalog.h:74
QMultiMap
QMap::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal