1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Linguist of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef PHRASE_H
43 #define PHRASE_H
44 
45 #include <QObject>
46 #include <QString>
47 #include <QList>
48 #include <QtCore/QLocale>
49 
50 QT_BEGIN_NAMESPACE
51 
52 class PhraseBook;
53 
54 class Phrase
55 {
56 public:
57     Phrase();
58     Phrase(const QString &source, const QString &target,
59             const QString &definition, int sc = -1);
60     Phrase(const QString &source, const QString &target,
61             const QString &definition, PhraseBook *phraseBook);
62 
source()63     QString source() const { return s; }
64     void setSource(const QString &ns);
target()65     QString target() const {return t;}
66     void setTarget(const QString &nt);
definition()67     QString definition() const {return d;}
68     void setDefinition (const QString &nd);
shortcut()69     int shortcut() const { return shrtc; }
phraseBook()70     PhraseBook *phraseBook() const { return m_phraseBook; }
setPhraseBook(PhraseBook * book)71     void setPhraseBook(PhraseBook *book) { m_phraseBook = book; }
72 
73 private:
74     int shrtc;
75     QString s;
76     QString t;
77     QString d;
78     PhraseBook *m_phraseBook;
79 };
80 
81 bool operator==(const Phrase &p, const Phrase &q);
82 inline bool operator!=(const Phrase &p, const Phrase &q) {
83     return !(p == q);
84 }
85 
86 class QphHandler;
87 
88 class PhraseBook : public QObject
89 {
90     Q_OBJECT
91 
92 public:
93     PhraseBook();
94     ~PhraseBook();
95     bool load(const QString &fileName, bool *langGuessed);
96     bool save(const QString &fileName);
phrases()97     QList<Phrase *> phrases() const { return m_phrases; }
98     void append(Phrase *phrase);
99     void remove(Phrase *phrase);
fileName()100     QString fileName() const { return m_fileName; }
101     QString friendlyPhraseBookName() const;
isModified()102     bool isModified() const { return m_changed; }
103 
104     void setLanguageAndCountry(QLocale::Language lang, QLocale::Country country);
language()105     QLocale::Language language() const { return m_language; }
country()106     QLocale::Country country() const { return m_country; }
107     void setSourceLanguageAndCountry(QLocale::Language lang, QLocale::Country country);
sourceLanguage()108     QLocale::Language sourceLanguage() const { return m_sourceLanguage; }
sourceCountry()109     QLocale::Country sourceCountry() const { return m_sourceCountry; }
110 
111 signals:
112     void modifiedChanged(bool changed);
113     void listChanged();
114 
115 private:
116     // Prevent copying
117     PhraseBook(const PhraseBook &);
118     PhraseBook& operator=(const PhraseBook &);
119 
120     void setModified(bool modified);
121     void phraseChanged(Phrase *phrase);
122 
123     QList<Phrase *> m_phrases;
124     QString m_fileName;
125     bool m_changed;
126 
127     QLocale::Language m_language;
128     QLocale::Language m_sourceLanguage;
129     QLocale::Country m_country;
130     QLocale::Country m_sourceCountry;
131 
132     friend class QphHandler;
133     friend class Phrase;
134 };
135 
136 QT_END_NAMESPACE
137 
138 #endif
139