~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to utilities/advancedrename/parser/modifiers/removedoublesmodifier.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2010-08-26 19:25:16 UTC
  • mfrom: (1.2.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100826192516-mkbdww0h5v2x4yoy
Tags: 2:1.4.0-0ubuntu1
* New upstream bugfix release (LP: #626751)
* Install the file NEWS as upstream changelog because "ChangeLog" is
  too verbose.
* Don't copy the desktop .pot file to imageplugins, not needed anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2010-08-08
 
7
 * Description : a modifier for deleting duplicate words
 
8
 *
 
9
 * Copyright (C) 2009 by Andi Clemens <andi dot clemens at gmx dot net>
 
10
 *
 
11
 * This program is free software; you can redistribute it
 
12
 * and/or modify it under the terms of the GNU General
 
13
 * Public License as published by the Free Software Foundation;
 
14
 * either version 2, or (at your option)
 
15
 * any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
#include "removedoublesmodifier.moc"
 
25
 
 
26
// Qt includes
 
27
 
 
28
#include <QSet>
 
29
#include <QString>
 
30
#include <QStringList>
 
31
 
 
32
// KDE includes
 
33
 
 
34
#include <kiconloader.h>
 
35
#include <klineedit.h>
 
36
#include <klocale.h>
 
37
 
 
38
namespace Digikam
 
39
{
 
40
 
 
41
RemoveDoublesModifier::RemoveDoublesModifier()
 
42
                     : Modifier(i18n("Remove Doubles"),
 
43
                                i18n("Remove duplicate words"),
 
44
                                SmallIcon("edit-copy"))
 
45
{
 
46
    addToken("{removedoubles}", description());
 
47
 
 
48
    QRegExp reg("\\{removedoubles\\}");
 
49
    reg.setMinimal(true);
 
50
    setRegExp(reg);
 
51
}
 
52
 
 
53
QString RemoveDoublesModifier::parseOperation(ParseSettings& settings)
 
54
{
 
55
    QString result = settings.str2Modify;
 
56
 
 
57
    QSet<QString> knownWords;
 
58
    QStringList words = result.split(QChar(' '));
 
59
    QStringList newString;
 
60
    foreach (const QString& word, words)
 
61
    {
 
62
        if (!knownWords.contains(word))
 
63
        {
 
64
            knownWords.insert(word);
 
65
            newString << word;
 
66
        }
 
67
    }
 
68
 
 
69
    if (!newString.isEmpty())
 
70
    {
 
71
        result = newString.join(QChar(' '));
 
72
    }
 
73
 
 
74
    return result;
 
75
}
 
76
 
 
77
} // namespace Digikam