~ubuntu-branches/ubuntu/quantal/kiten/quantal-proposed

« back to all changes in this revision

Viewing changes to lib/dictionarymanager.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:14:44 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111216131444-fxt8pt2pha54qmdu
Tags: 4:4.7.90-0ubuntu1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 * This file is part of Kiten, a KDE Japanese Reference Tool                 *
3
3
 * Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com>                      *
 
4
 * Copyright (C) 2011 Daniel E. Moctezuma <democtezuma@gmail.com>            *
4
5
 *                                                                           *
5
6
 * This library is free software; you can redistribute it and/or             *
6
7
 * modify it under the terms of the GNU Library General Public               *
25
26
#include "dictquery.h"
26
27
#include "entry.h"
27
28
#include "entrylist.h"
 
29
#include "kitenmacros.h"
28
30
 
29
31
#include <KDebug>
30
32
#include <KGlobal>
37
39
/* Includes to handle various types of dictionaries
38
40
IMPORTANT: To add a dictionary type, add the header file here and add it to the
39
41
 if statement under addDictionary() */
40
 
#include "DictDeinflect/dictfiledeinflect.h"
41
42
#include "DictEdict/dictfileedict.h"
42
43
#include "DictKanjidic/dictfilekanjidic.h"
43
44
 
100
101
 * Given a named Dict file/name/type... create and add the object if it
101
102
 * seems to work properly on creation.
102
103
 */
103
 
bool DictionaryManager::addDictionary( const QString &file, const QString &name
 
104
bool DictionaryManager::addDictionary( const QString &file
 
105
                                     , const QString &name
104
106
                                     , const QString &type )
105
107
{
106
108
  if( d->dictManagers.contains( name ) ) //This name already exists in the list!
109
111
  }
110
112
 
111
113
  DictFile *newDict = makeDictFile( type );
112
 
  if( newDict == NULL ) return false;
 
114
  if( newDict == NULL )
 
115
  {
 
116
    return false;
 
117
  }
113
118
 
114
 
  if(!newDict->loadDictionary( file, name ) )
 
119
  if( ! newDict->loadDictionary( file, name ) )
115
120
  {
116
121
    kDebug() << "Dictionary load FAILED: " << newDict->getName();
117
122
    delete newDict;
132
137
 */
133
138
EntryList *DictionaryManager::doSearch( const DictQuery &query ) const
134
139
{
135
 
  EntryList *ret=new EntryList();
 
140
  EntryList *ret = new EntryList();
136
141
  #if 0
137
142
  if( query.getMeaning() == "(libkiten)" )
138
143
  {
146
151
  #endif
147
152
 
148
153
  // There are two basic modes.... one in which the query
149
 
  // Specifies the dictionary list, one in which it does not
 
154
  // specifies the dictionary list, one in which it does not
150
155
  QStringList dictsFromQuery = query.getDictionaries();
151
156
  if( dictsFromQuery.isEmpty() )
152
157
  {
153
158
    // None specified, search all
154
159
    foreach( DictFile *it, d->dictManagers )
155
160
    {
 
161
      kDebug() << "Searching in " << it->getName() << "dictionary." << endl;
156
162
      EntryList *temp = it->doSearch( query );
157
163
      if( temp )
158
164
      {
195
201
 
196
202
  foreach( Entry* it, *list )
197
203
  {
198
 
    if(it->matchesQuery( query ) )
 
204
    if( it->matchesQuery( query ) )
199
205
    {
200
206
      Entry *x = it->clone();
201
207
      ret->append( x );
271
277
QStringList DictionaryManager::listDictFileTypes()
272
278
{
273
279
  QStringList list;
274
 
  list.append( "edict" );
275
 
  list.append( "kanjidic" );
276
 
  list.append( "deinflect" );
 
280
  list.append( EDICT );
 
281
  list.append( KANJIDIC );
 
282
  
277
283
  //Add your dictionary type here!
278
284
 
279
285
  return list;
342
348
 */
343
349
DictFile *DictionaryManager::makeDictFile( const QString &type )
344
350
{
345
 
  if( type == "edict" )
 
351
  if( type == EDICT )
346
352
  {
347
353
    return new DictFileEdict();
348
354
  }
349
 
  if( type == "kanjidic" )
 
355
  else if( type == KANJIDIC )
350
356
  {
351
357
    return new DictFileKanjidic();
352
358
  }
353
 
  if( type == "deinflect" )
354
 
  {
355
 
    return new DictFileDeinflect();
356
 
  }
 
359
 
357
360
  //Add new dictionary types here!!!
358
361
 
359
362
  return NULL;
360
363
}
361
364
 
 
365
void DictionaryManager::removeAllDictionaries()
 
366
{
 
367
  d->dictManagers.clear();
 
368
}
 
369
 
362
370
/**
363
371
 * Remove a dictionary from the list, and delete the dictionary object
364
372
 * (it should close files, deallocate memory, etc).