1
/* This program is free software; you can redistribute it and/or modify
2
* it under the terms of the GNU General Public License version 2
3
* as published by the Free Software Foundation.
5
* This program is distributed in the hope that it will be useful,
6
* but WITHOUT ANY WARRANTY; without even the implied warranty of
7
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8
* GNU General Public License for more details.
10
* You should have received a copy of the GNU General Public License
11
* along with this program; if not, write to the Free Software
12
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
* Author: Moshe Wagner. <moshe.wagner@gmail.com>
27
#include <QTextStream>
28
#include <QStringList>
31
#include <QTranslator>
34
#include <fribidi/fribidi.h>
38
//Enum defining the color of the folder icon.
39
// Blue is when all it's children are selected;
40
// Grey when none are;
41
// And half grey and half blue - when some are, and some are not.
42
enum IconState { BLUE, HALF, GREY};
48
extern QString BOOKPATH;
49
extern QString MAINPATH;
50
extern QString TMPPATH;
51
extern QString HEBREWBOOKSPATH;
52
extern QString USERPATH;
55
//Small functions used by a few files:
57
bool ReadFileFromZip(QString zippath, QString filepath, QList <QString>& text, const char* encoding_name, bool skipconflines = false);
58
//Returns the contents of the given file from the given zip file. Returns "Error!" on failure.
59
QString ReadFileFromZip(QString zippath, QString filepath, const char* encoding_name);
60
bool ReadZipComment(QString zippath, QList <QString>& text, const char* encoding_name);
62
bool zipExtract(const QString & filePath, const QString & extDirPath);
64
//Reads the file with the given name and the given encoding, and inserts it's contents into the given vector
65
bool ReadFileToList(QString filename, QList <QString>& text, const char* encoding_name);
67
//Reads the comment file into two vectors, one for the titles and one for the texts.
68
// If a book's id is given, only comments for that book are put into the vector, with the "id:" part of the line choped.
69
bool ReadCommentFile(QString path, vector<QString>& titles, vector<QString>& texts, const char* encoding_name, int id=-1);
71
//Writes the given data to the given file path with the given encoding
72
void writetofile(QString filename, const QString& data, const char* encoding_name, bool overwrite = true);
73
QString readfile(QString filename, const char* encoding_name);
75
//Splits the given QString to two parts, (ONLY) on the FIRST occurrence of the splitter
76
void splittotwo(QString , vector <QString>& , QString);
78
//Sets the value of the pointed int to the value represented by the string
79
// Returns failure or success
80
bool ToNum(QString str, int *out);
82
//Prints (couts) the given Qstring
85
//Prints (couts) the given int
88
//Returns the Gematria of the given string
89
int GematriaValueOfString (const QString& str);
91
//Returns the gematria of the single given hebrew char
92
inline int GematriaOfChar(const QChar ch);
94
//Returns a hebrew string representing the given gematria value
95
// You can tell it weather to add quote signs (Geresh or Gershaiim) or not
96
QString NumberToGematria (int num, bool addquotes = true);
98
//Return only the hebrew letters in the given string, and makes every space into "_"
99
QString RemoveBrackets(QString str);
101
//Converts numbers into strings:
102
// (Returns a QString representing the given value)
103
QString stringify(int);
105
//Returns gmara page name of the given page number (From 4, which is Bet Amud Alef)
106
QString GmaraPage(int num);
108
//Makes sure the given filepath is absolute
109
QString absPath(QString);
111
//Because for some stupid reason QT can't handle internal html links with Hebrew chars, this function
112
// (which is called by the itr's toString), converts any given QString to a string representing each char's
113
// Base32 value, (seperated by 'U's), thus giving a valid digit-or-english-letter-only string.
114
QString escapeToBase32(QString str);
115
QString unescapeFromBase32(QString str);
117
// Returns a string the search should display for this book and position
118
///QString BookSearchDisplay (QString BookDisplayName , QString PositionName);
120
// Puts into the vector, all words of the first string,
121
// excluding any words that are also in the second.
122
void WordExclude(QString stra , QString strb, vector<QString>& out);
124
//Gets a line in the form of foo=bar,
125
// and iserts bar to the pointed integer (if it's a valud integer)
126
// (Otherwise the value isn't changed)
127
void GetIntValue (const QString& valueline, int * pVar);
129
//Gets a line in the form of foo="bar",
130
// and iserts bar to the pointed qstring, unless it's empty
131
void GetStringValue (const QString& valueline, QString * pStr);
133
//Fix the syntax of the 'span' attributes given in source files
134
//Fixes the double single quotes to a single double quote
135
//Fixes the '=' sign given with "color=", to "color:"
136
QString fixSpan(QString str);
138
//Returns the given string the given number of times
139
QString stringTimes(const QString& str, int t);
141
//Limits the given string to the given length, removing the beggining of the string.
142
// Cuts only at spaces.
143
QString startChop(const QString& str, int limit);
144
//Limits the given string to the given length, removing the end of the string.
145
// Cuts only at spaces.
146
QString endChop(const QString& str, int limit);
149
//Removes any sign from the given unicode string
151
QString removeSigns(const QString& str);
153
//Removes any nikud sign from the given unicode string
154
QString removeNikud(const QString&);
156
//Removes any teamim sign from the given unicode string
157
QString removeTeamim(const QString& str);
159
QString allowNikudAndTeamim( const QString& str );
160
QRegExp withNikudAndTeamim( const QString& str );
162
////Returns a regexp pattern matching all strings that are the same as the given string,
163
//// ignoring differences in the ו-s and י-s they have.
164
//QString AllowKtivMaleh(QString str);
166
QString AllowKtivHasser(const QString& str);
169
QString simpleHtmlPage(QString title, QString contents);
170
QString pluginPage(QString title);
172
//Copy the given folder (recursively) to the given path
173
void copyFolder(QString sourceFolder, QString destFolder, QStringList fileNameFilters);
174
//delete the given folder (recursively) to the given path
175
void deleteBooksFolder(QString sourceFolder);
177
//Generate search DB files from the given bookflie (Non-compressed)
178
void GenerateSearchTextDB(QString infile, QString pureTextOutPath, QString levelMapOutPath);
182
// Returns a corrected Bidi string from the given one.
183
// (Using the 'LineToBidiText' function)
184
QString ToBidiText(QString str);
186
// Returns a corrected single line Bidi string from the given one.
187
// (Using fribidi's functions)
188
QString LineToBidiText(QString str);
192
#endif // FUNCTIONS_H