SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kmouth / phrasebook / phrasebook.h
blobe8cabc3a5ebe8df61b556d7b87b837fdb7c6b802
1 /***************************************************************************
2 phrasebook.h - description
3 -------------------
4 begin : Don Sep 19 2002
5 copyright : (C) 2002 by Gunnar Schmi Dt
6 email : kmouth@schmi-dt.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef PHRASEBOOK_H
19 #define PHRASEBOOK_H
21 #include <QObject>
22 #include <q3dragobject.h>
23 #include <QtXml>
24 //Added by qt3to4:
25 #include <QTextStream>
26 #include <QMenu>
27 #include <ktoolbar.h>
28 #include <kaction.h>
29 #include <kactioncollection.h>
30 #include <kprinter.h>
31 #include <kicon.h>
32 class KUrl;
34 /**
35 * The class Phrase represents one phrase in a phrase book.
36 * @author Gunnar Schmi Dt
38 class Phrase {
39 friend class PhraseBookParser;
40 public:
41 Phrase();
42 Phrase (const QString &phrase);
43 Phrase (const QString &phrase, const QString &shortcut);
45 QString getPhrase() const;
46 QString getShortcut() const;
48 void setPhrase (const QString &phrase);
49 void setShortcut (const QString &shortcut);
51 private:
52 QString phrase;
53 QString shortcut;
56 /**
57 * The class PhraseBookEntry implements a phrase book entry. That can be either
58 * a phrase or a start tag a sub phrase book.
59 * @author Gunnar Schmi Dt
61 class PhraseBookEntry {
62 public:
63 PhraseBookEntry ();
64 PhraseBookEntry (Phrase phrase, int level = 1, bool isPhrase = true);
65 ~PhraseBookEntry () {}
67 void setPhrase (Phrase phrase, int level = 1, bool isPhrase = true);
69 bool isPhrase() const;
70 Phrase getPhrase() const;
71 int getLevel() const;
73 private:
74 bool isPhraseValue;
75 Phrase phrase;
76 int level;
79 typedef QList<PhraseBookEntry> PhraseBookEntryList;
81 /**
82 * The class PhraseBook implements a phrase book. It mainly stores a
83 * token list where each token is a phrase book entry (either a phrase
84 * or a sub phrase book). The entries are placed into a tree structure
85 * as follows:
87 * The level of each entry tells the level in the tree (level=0 is the top
88 * level), each sub book in level i directly or indirectly contains all
89 * following entries until an entry of level at most i or the end of the
90 * token list.
92 * @author Gunnar Schmi Dt
94 class PhraseBook : public PhraseBookEntryList {
95 public:
96 PhraseBook() : PhraseBookEntryList() {}
97 ~PhraseBook() {}
99 /** opens a file containing a phrase book. Returns true if successful. */
100 bool open (const KUrl &url);
102 /** decodes a phrase book. Returns true if successful. */
103 bool decode (const QString &xml);
105 /** decodes a phrase book. Returns true if successful. */
106 bool decode (QXmlInputSource &source);
108 /** Writes the phrases to a file. Returns true if successful. */
109 bool save (const KUrl &url);
111 /** Writes the phrases to a file. Returns true if successful. */
112 bool save (const KUrl &url, bool asPhrasebook);
114 /** Writes the phrases to a QTextStream. */
115 void save (QTextStream &stream, bool asPhrasebook);
117 /** Prints the phrases. */
118 void print (KPrinter *pPrinter);
120 /** Shows a file selector and writes the phrases to a file.
121 * @return 1, if the file got successfully written,
122 * 0, if the user canceled the operation,
123 * -1, if there was an error when saving the file.
125 int save (QWidget *parent, const QString &title, KUrl &url, bool phrasebookFirst = true);
127 /** encodes the phrase book. Returns the encoded xml code. */
128 QString encode ();
130 /** Stores all entries in a QStringList. All hierarchy information and all
131 * shortcuts are ignored during this operation.
133 QStringList toStringList();
135 /** Adds the entries of the book to both the given popup menu and the given
136 * toolbar. The corresponding actions will be inserted into phrases.
138 void addToGUI (QMenu *popup, KToolBar *toolbar,
139 KActionCollection *phrases,
140 QObject *receiver, const char *slot) const;
142 /** Inserts book into a new sub phrase book.
143 * @param name the name of the new sub phrase book.
144 * @param book the phrase book to insert.
146 void insert (const QString &name, const PhraseBook &book);
150 * The class PhraseBookDrag implements drag and drop support for phrase books.
151 * @author Gunnar Schmi Dt
153 class PhraseBookDrag: public Q3DragObject {
154 Q_OBJECT
155 public:
156 PhraseBookDrag (PhraseBook *book, QWidget *dragSource = 0, const char *name = 0);
157 PhraseBookDrag (QWidget *dragSource = 0, const char *name = 0);
158 ~PhraseBookDrag ();
160 virtual void setBook (PhraseBook *book);
162 const char *format (int i) const;
163 virtual QByteArray encodedData (const char *) const;
165 static bool canDecode (const QMimeSource *e);
166 static bool decode (const QMimeSource *e, PhraseBook *book);
168 private:
169 bool isEmpty;
170 Q3TextDrag xmlphrasebook;
171 Q3TextDrag xml;
172 Q3TextDrag plain;
175 class PhraseAction : public KAction {
176 Q_OBJECT
177 public:
178 PhraseAction (const QString& phrase, const QString& cut, const QObject* receiver, const char* slot, KActionCollection* parent)
179 : KAction (KIcon("phrase"), phrase, parent) {
180 this->setShortcut(cut);
181 this->phrase = phrase;
182 connect (this, SIGNAL(slotActivated (const QString &)), receiver, slot);
183 parent->addAction(phrase, this);
185 ~PhraseAction () {
188 public slots:
189 void slotTriggered () {
190 trigger();
191 emit slotActivated (phrase);
194 signals:
195 void slotActivated (const QString &phrase);
197 private:
198 QString phrase;
201 #endif