summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabeldict/modules/dbsearchengine/dbscan.cpp
blob: 10a3a7964ce825e5d8a140da667ca444c450da25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/***************************************************************************
                          dbscan.cpp  -  Scan for po files to add in the DB
                         -------------------
    begin                : Fri Sep 8 2000
    copyright            : (C) 2000 by Andrea Rizzi
    email                : rizzi@kde.org
 ***************************************************************************/

/*
 Translation search engine  
 
 
  Copyright  2000
  Andrea Rizzi rizzi@kde.org
 
  License GPL v 2.0

 *                                                                         *
 *   In addition, as a special exception, the copyright holders give       *
 *   permission to link the code of this program with any edition of       *
 *   the TQt library by Trolltech AS, Norway (or with modified versions     *
 *   of TQt that use the same license as TQt), and distribute linked         *
 *   combinations including the two.  You must obey the GNU General        *
 *   Public License in all respects for all of the code used other than    *
 *   TQt. If you modify this file, you may extend this exception to         *
 *   your version of the file, but you are not obligated to do so.  If     *
 *   you do not wish to do so, delete this exception statement from        *
 *   your version.                                                         *

*/
#include "dbscan.h"

#include <tqdir.h>
#include <tqfile.h>
#include <kapplication.h>
#include <kurl.h>
#include <kdebug.h>

using namespace KBabel;

PoScanner::PoScanner(DataBaseManager *dbm,
	TQObject *parent,const char *name):TQObject(parent,name)
{
dm=dbm;
removeOldCatalogTranslation=false; //Check if this flag do something.
count=0;
}

bool PoScanner::scanPattern(TQString pathName,TQString pattern,bool rec)
{
int tot;

//Only one progress bar!!
bool pb=false;
static bool called=false;
if (!called)
{ pb=true; count=0;}
called=true;
 
kdDebug(0) << TQString("cat: %1, %2").tqarg(pathName).tqarg(pattern) << endl;

if(pb)
{emit patternStarted();
emit patternProgress(0);
}
  TQDir d(pathName,pattern);
  d.setMatchAllDirs(true);
  const TQFileInfoList* files = d.entryInfoList();
  tot=files->count();
  TQPtrListIterator<TQFileInfo> it(*files);
kdDebug(0) << tot << endl;
     for ( int i=0; i<tot; i++ )
        {   
	  if ((*it)->isDir())
	   {
	    if(rec)
              {
	      kdDebug(0) << d[i] << endl;
	      if(d[i]!="." && d[i]!="..")
 	       scanPattern(pathName+"/"+d[i],pattern,true); 
	      }
	   } else
	   {
      	      kdDebug(0) << d[i] << endl;
		   scanFile(pathName+"/"+d[i]);
	   }

	if(pb)	   
  
	   emit patternProgress(100*i/tot);

	  //printf( "%s\n", d[i] );
      
      ++it;
	}
  	


if(pb)	
emit patternProgress(100);	


if(pb)
emit patternFinished();
if(pb){called=false;count=0;}

return true;
}




bool PoScanner::scanFile(TQString fileName)
{

	  
emit fileStarted();

InfoItem cinfo;
Catalog * catalog=new Catalog(this,"ScanPoCatalog");
  

TQString location=fileName.right(fileName.length()-fileName.findRev("/")-1);
connect(catalog,TQT_SIGNAL(signalProgress(int)),this,TQT_SIGNAL(fileLoading(int)));
emit filename(location);
emit fileProgress(0);
emit fileLoading(0);

KURL u(fileName);

ConversionStatus rr=catalog->openURL(u);
if(rr != OK && rr !=RECOVERED_PARSE_ERROR )
{
        delete catalog;
	return false;
}
emit fileLoading(100);

TQString author; 
if(rr != HEADER_ERROR)
  author=catalog->lastTranslator();
else author=TQString("unknown");
 
int catnum=dm->catalogRef(location,author,fileName);

uint i,tot;
tot=catalog->numberOfEntries();
//DataBaseItem dbit;
bool fuzzy;
bool untra;

//kdDebug(0) << TQString("Tot: %1").tqarg(tot) << endl;

for (i=0;i<tot;i++)  //Skip header        = ????
{

 //Faster ?
  if(i % 10==0)
  { 
   emit fileProgress(100*i/tot);
   emit added(count);
   kapp->processEvents(100);
  }

  fuzzy=catalog->isFuzzy(i);
  untra=catalog->isUntranslated(i);

  
 if(!fuzzy && !untra)
 {
  int res;
  TQString msgid,msgstr;
  msgid=catalog->msgid(i,true).first();
  kdWarning() << "Translation database does not support plural forms" << endl;
  msgstr=catalog->msgstr(i).first();
  res=dm->putNewTranslation(msgid,msgstr,catnum,false);
  count+=res; 
 }

	
}


//      kdDebug(0) << TQString("File finished") << endl;

emit fileProgress(0);	
emit fileLoading(0);
emit fileFinished();
// dm->loadInfo();  // Sync the list of catalogs NOT NEEDED (?)

delete catalog;

//clear();
return true;

}
#include "dbscan.moc"