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