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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
/* ****************************************************************************
This file is part of KBabel
Copyright (C) 2004 by Stanislav Visnovsky <visnovsky@kde.org>
Copyright (C) 2006 by Nicolas GOUTTE <goutte@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 "resources.h"
#include "kbproject.h"
#include "kbprojectmanager.h"
#include "kbprojectsettings.h"
#include <tqfileinfo.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kmimetype.h>
#include <kspell.h>
namespace KBabel
{
Project::Project( const TQString& file ) :
TQObject ()
, _filename (file)
, _name (i18n("unnamed"))
, _valid (false)
, _config (NULL)
, _settings (NULL)
{
TQFileInfo info(file);
if(info.isDir())
return;
if(info.exists())
{
// ### TODO: can a setting file only be a text/plain file?
// ### TODO: why not use KMimeType::findByPath if the fileis always local?
// first, for existing file check the MIME type
// it has to be text file
KMimeType::Ptr mime = KMimeType::findByURL( KURL::fromPathOrURL( file ) );
if ( mime->name() == "text/plain" )
{
// Plain text, no problem!
}
else if ( mime->name() == "application/x-zerosize" )
{
// Empty files are allowed too
kdWarning() << "Empty KBabel project file!" << endl;
}
else if ( mime->name() == "application/octet-stream" )
{
// this can happen if the file has some very long lines
kdWarning() << "KBabel project file detected as octet-stream! Perhaps there are very long lines in it!" << endl;
}
else
{
// Unknown mime type, abort!
// ### TODO: should the user not be asked instead?
kdWarning () << "File type is " << mime->name() << endl;
return;
}
}
_config = KSharedConfig::openConfig (_filename, false, false);
kdDebug (KBABEL) << "Opened project " << _filename << endl;
// read the project name
_config->setGroup( "Project" );
_name = _config->readEntry( "Name", TQString() );
if ( _name.isEmpty() )
_name = "Default-Project"; // set default project name
// ### FIXME: why is the Version number not written to the project file?
if ( _config->readEntry( "Version", TQString() ) != "1.0.1" )
{
kdWarning() << "Old project format assumed" << endl;
// transform old entries to the new ones
_config->setGroup( "Header");
// TODO remove obsolete entries as well
if (_config->hasKey("Author-Email") && !_config->hasKey("AuthorEmail"))
{
_config->writeEntry ("AuthorEmail", _config->readEntry ("Author-Email", ""));
_config->deleteEntry ("Author-Email");
}
if (_config->hasKey("Author-Name") && !_config->hasKey("AuthorName"))
{
_config->writeEntry ("AuthorName", _config->readEntry ("Author-Name", ""));
_config->deleteEntry ("Author-Name");
}
if (_config->hasKey("Local-Author-Name") && !_config->hasKey("LocalAuthorName"))
{
_config->writeEntry ("LocalAuthorName", _config->readEntry ("Local-Author-Name", ""));
_config->deleteEntry ("Local-Author-Name");
}
if (_config->hasKey("Update-Charset") && !_config->hasKey("UpdateCharset"))
{
_config->writeEntry ("UpdateCharset", _config->readEntry ("Update-Charset", ""));
_config->deleteEntry ("Update-Charset");
}
if (_config->hasKey("Update-Encoding") && !_config->hasKey("UpdateEncoding"))
{
_config->writeEntry ("UpdateEncoding", _config->readEntry ("Update-Encoding", ""));
_config->deleteEntry ("Update-Encoding");
}
if (_config->hasKey("Update-Language-Team") && !_config->hasKey("UpdateLanguageTeam"))
{
_config->writeEntry ("UpdateLanguageTeam", _config->readEntry ("Update-Language-Team", ""));
_config->deleteEntry ("Update-Language-Team");
}
if (_config->hasKey("Update-Last-Translator") && !_config->hasKey("UpdateLastTranslator"))
{
_config->writeEntry ("UpdateLastTranslator", _config->readEntry ("Update-Last-Translator", ""));
_config->deleteEntry ("Update-Last-Translator");
}
if (_config->hasKey("Update-Project") && !_config->hasKey("UpdateProject"))
{
_config->writeEntry ("UpdateProject", _config->readEntry ("Update-Project", ""));
_config->deleteEntry ("Update-Project");
}
if (_config->hasKey("Update-Revision") && !_config->hasKey("UpdateRevision"))
{
_config->writeEntry ("UpdateRevision", _config->readEntry ("Update-Revision", ""));
_config->deleteEntry ("Update-Revision");
}
_config->sync();
}
_valid = true;
_settings = new KBabel::ProjectSettingsBase( _config );
_settings->readConfig();
}
Project::~Project ()
{
if (_settings)
{
// store the project name
_settings->setVersion( "1.0.1" );
_settings->setName(_name);
kdDebug () << "Writing configuration" << endl;
_settings->writeConfig();
delete _settings;
}
// unregister in project manager
kdDebug () << "Freeing project " << _filename << endl;
ProjectManager::remove (this);
}
TDEConfig* Project::config ()
{
return _config;
}
KSharedConfig* Project::sharedConfig( void )
{
return _config;
}
ProjectSettingsBase* Project::settings ()
{
return _settings;
}
IdentitySettings Project::identitySettings ()
{
IdentitySettings settings;
settings.authorName=_settings->authorName();
settings.authorLocalizedName=_settings->localAuthorName();
settings.authorEmail=_settings->authorEmail();
settings.languageName=_settings->language();
settings.languageCode=_settings->languageCode();
settings.mailingList=_settings->mailinglist();
settings.timeZone=_settings->timezone();
settings.numberOfPluralForms=_settings->pluralForms();
if( settings.numberOfPluralForms < -1 )
{
kdWarning() << "Invalid number of plural forms, ignoring: " << settings.numberOfPluralForms << endl;
settings.numberOfPluralForms = 2;
}
settings.checkPluralArgument=_settings->checkPluralArgument();
settings.gnuPluralFormHeader=_settings->pluralFormsHeader();
return settings;
}
SaveSettings Project::saveSettings ()
{
SaveSettings settings;
settings.autoUpdate=_settings->autoUpdate();
settings.updateLastTranslator=_settings->updateLastTranslator();
settings.updateRevisionDate=_settings->updateRevisionDate();
settings.updateLanguageTeam=_settings->updateLanguageTeam();
settings.updateCharset=_settings->updateCharset();
settings.updateEncoding=_settings->updateEncoding();
settings.encoding=_settings->encoding();
settings.useOldEncoding=_settings->useOldEncoding();
settings.updateProject=_settings->updateProject();
settings.projectString=_settings->projectString();
settings.autoSyntaxCheck = _settings->autoSyntaxCheck();
settings.saveObsolete = _settings->saveObsolete();
settings.customDateFormat = _settings->customDateFormat();
settings.dateFormat = (Qt::DateFormat)_settings->dateFormat();
settings.updateDescription = _settings->updateDescription();
settings.descriptionString = _settings->descriptionString();
settings.updateTranslatorCopyright = _settings->updateTranslatorCopyright();
settings.FSFCopyright = _settings->fSFCopyright();
settings.autoSaveDelay=_settings->autoSaveDelay();
return settings;
}
MiscSettings Project::miscSettings ()
{
MiscSettings settings;
TQString temp=_settings->accelMarker();
if(temp.length() > 0)
{
settings.accelMarker=temp[0];
}
temp = _settings->contextInfo();
settings.contextInfo.setPattern(temp);
temp = _settings->singularPlural();
settings.singularPlural.setPattern(temp);
settings.useBzip = _settings->bZipCompression();
settings.compressSingleFile = _settings->compressSingleFile();
return settings;
}
SpellcheckSettings Project::spellcheckSettings ()
{
SpellcheckSettings settings;
settings.noRootAffix=_settings->noRootAffix();
settings.runTogether=_settings->runTogether();
settings.spellEncoding=_settings->spellEncoding();
settings.spellClient=_settings->spellClient();
settings.spellDict=_settings->spellDictionary();
settings.rememberIgnored=_settings->rememberIgnored();
settings.ignoreURL=_settings->ignoreURL();
settings.onFlySpellcheck=_settings->onFlySpellCheck();
settings.valid=true;
return settings;
}
SourceContextSettings Project::sourceContextSettings ()
{
SourceContextSettings settings;
settings.codeRoot=_settings->codeRoot();
settings.sourcePaths=_settings->paths();
return settings;
}
CatManSettings Project::catManSettings ()
{
CatManSettings settings;
settings.poBaseDir=_settings->poBaseDir();
settings.potBaseDir=_settings->potBaseDir();
settings.openWindow=_settings->openWindow();
settings.killCmdOnExit=_settings->killCmdOnExit();
settings.indexWords=_settings->indexWords();
settings.msgfmt=_settings->msgfmt();
settings.dirCommands = _settings->dirCommands();
settings.dirCommandNames = _settings->dirCommandNames();
settings.fileCommands = _settings->fileCommands();
settings.fileCommandNames = _settings->fileCommandNames();
settings.ignoreURL=_settings->ignoreURL();
settings.flagColumn=_settings->showFlagColumn();
settings.fuzzyColumn=_settings->showFuzzyColumn();
settings.untranslatedColumn=_settings->showUntranslatedColumn();
settings.totalColumn=_settings->showTotalColumn();
settings.cvsColumn=_settings->showCVSColumn();
settings.revisionColumn=_settings->showRevisionColumn();
settings.translatorColumn=_settings->showTranslatorColumn();
return settings;
}
void Project::setSettings (IdentitySettings settings)
{
_settings->setAuthorName(settings.authorName);
_settings->setLocalAuthorName(settings.authorLocalizedName);
_settings->setAuthorEmail(settings.authorEmail);
_settings->setAuthorEmail(settings.authorEmail);
_settings->setLanguage(settings.languageName);
_settings->setLanguageCode(settings.languageCode);
_settings->setMailinglist(settings.mailingList);
_settings->setTimezone(settings.timeZone);
_settings->setPluralForms(settings.numberOfPluralForms);
_settings->setCheckPluralArgument(settings.checkPluralArgument);
_settings->setPluralFormsHeader(settings.gnuPluralFormHeader);
_settings->writeConfig();
emit signalIdentitySettingsChanged();
emit signalSettingsChanged();
}
void Project::setSettings (SaveSettings settings)
{
_settings->setAutoUpdate(settings.autoUpdate);
_settings->setUpdateLastTranslator(settings.updateLastTranslator);
_settings->setUpdateRevisionDate(settings.updateRevisionDate);
_settings->setUpdateLanguageTeam(settings.updateLanguageTeam);
_settings->setUpdateCharset(settings.updateCharset);
_settings->setUpdateEncoding(settings.updateEncoding);
_settings->setEncoding(settings.encoding);
_settings->setUseOldEncoding(settings.useOldEncoding);
_settings->setUpdateProject(settings.updateProject);
_settings->setProjectString(settings.projectString);
_settings->setAutoSyntaxCheck(settings.autoSyntaxCheck);
_settings->setSaveObsolete(settings.saveObsolete);
_settings->setCustomDateFormat(settings.customDateFormat);
_settings->setDateFormat(settings.dateFormat);
_settings->setUpdateDescription(settings.updateDescription);
_settings->setDescriptionString(settings.descriptionString);
_settings->setUpdateTranslatorCopyright(settings.updateTranslatorCopyright);
_settings->setFSFCopyright(settings.FSFCopyright);
_settings->setAutoSaveDelay(settings.autoSaveDelay);
_settings->writeConfig();
emit signalSaveSettingsChanged();
emit signalSettingsChanged();
}
void Project::setSettings (MiscSettings settings)
{
_settings->setAccelMarker(settings.accelMarker);
_settings->setContextInfo(settings.contextInfo.pattern());
_settings->setSingularPlural(settings.singularPlural.pattern());
_settings->setBZipCompression(settings.useBzip);
_settings->setCompressSingleFile(settings.compressSingleFile);
_settings->writeConfig();
emit signalMiscSettingsChanged();
emit signalSettingsChanged();
}
void Project::setSettings (SpellcheckSettings settings)
{
_settings->setNoRootAffix(settings.noRootAffix);
_settings->setRunTogether(settings.runTogether);
_settings->setSpellEncoding(settings.spellEncoding);
_settings->setSpellClient(settings.spellClient);
_settings->setSpellDictionary(settings.spellDict);
_settings->setRememberIgnored(settings.rememberIgnored);
_settings->setIgnoreURL(settings.ignoreURL);
_settings->setOnFlySpellCheck(settings.onFlySpellcheck);
_settings->writeConfig();
emit signalSpellcheckSettingsChanged();
emit signalSettingsChanged();
}
void Project::setSettings (SourceContextSettings settings)
{
TDEConfigGroupSaver saver(_config,"SourceContext");
_settings->setCodeRoot(settings.codeRoot);
_settings->setPaths(settings.sourcePaths);
_settings->writeConfig();
emit signalSourceContextSettingsChanged();
emit signalSettingsChanged();
}
void Project::setSettings (CatManSettings settings)
{
_settings->setPoBaseDir(settings.poBaseDir);
_settings->setPotBaseDir(settings.potBaseDir);
_settings->setOpenWindow(settings.openWindow);
_settings->setKillCmdOnExit(settings.killCmdOnExit);
_settings->setIndexWords(settings.indexWords);
_settings->setDirCommands(settings.dirCommands);
_settings->setDirCommandNames(settings.dirCommandNames);
_settings->setFileCommands(settings.fileCommands);
_settings->setFileCommandNames(settings.fileCommandNames);
_settings->setValidationIgnoreURL(settings.ignoreURL);
_settings->setShowFlagColumn(settings.flagColumn);
_settings->setShowFuzzyColumn(settings.fuzzyColumn);
_settings->setShowUntranslatedColumn(settings.untranslatedColumn);
_settings->setShowTotalColumn(settings.totalColumn);
_settings->setShowCVSColumn(settings.cvsColumn);
_settings->setShowRevisionColumn(settings.revisionColumn);
_settings->setShowTranslatorColumn(settings.translatorColumn);
_settings->writeConfig();
emit signalCatManSettingsChanged();
emit signalSettingsChanged();
}
}
#include "kbproject.moc"
|