~moshe-wagner/orayta/Orayta-QT

« back to all changes in this revision

Viewing changes to functions.h

  • Committer: moshe.wagner
  • Date: 2012-05-05 21:48:52 UTC
  • Revision ID: git-v1:70e09345355d8f7ecaf4ec2176a47d02dea9bcb7
Making the android branch into the main one

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
*
 
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.
 
9
*
 
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
 
13
*
 
14
* Author: Moshe Wagner. <moshe.wagner@gmail.com>
 
15
*/
 
16
 
 
17
#ifndef FUNCTIONS_H
 
18
#define FUNCTIONS_H
 
19
 
 
20
#include <QString>
 
21
#include <vector>
 
22
#include <algorithm>
 
23
#include <iostream>
 
24
#include <QFile>
 
25
#include <QFileInfo>
 
26
#include <QTextCodec>
 
27
#include <QTextStream>
 
28
#include <QStringList>
 
29
#include <QRegExp>
 
30
#include <QIcon>
 
31
#include <QTranslator>
 
32
 
 
33
#ifdef POPPLER
 
34
    #include <fribidi/fribidi.h>
 
35
#endif
 
36
 
 
37
 
 
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};
 
43
 
 
44
using namespace std;
 
45
 
 
46
extern QString LANG;
 
47
 
 
48
extern QString BOOKPATH;
 
49
extern QString MAINPATH;
 
50
extern QString TMPPATH;
 
51
extern QString HEBREWBOOKSPATH;
 
52
extern QString USERPATH;
 
53
 
 
54
 
 
55
//Small functions used by a few files:
 
56
 
 
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);
 
61
 
 
62
bool zipExtract(const QString & filePath, const QString & extDirPath);
 
63
 
 
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);
 
66
 
 
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);
 
70
 
 
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);
 
74
 
 
75
//Splits the given QString to two parts, (ONLY) on the FIRST occurrence of the splitter
 
76
void splittotwo(QString , vector <QString>& , QString);
 
77
 
 
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);
 
81
 
 
82
//Prints (couts) the given Qstring
 
83
void print(QString);
 
84
 
 
85
//Prints (couts) the given int
 
86
void print(int);
 
87
 
 
88
//Returns the Gematria of the given string
 
89
int GematriaValueOfString (const QString& str);
 
90
 
 
91
//Returns the gematria of the single given hebrew char
 
92
inline int GematriaOfChar(const QChar ch);
 
93
 
 
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);
 
97
 
 
98
//Return only the hebrew letters in the given string, and makes every space into "_"
 
99
QString RemoveBrackets(QString str);
 
100
 
 
101
//Converts numbers into strings:
 
102
// (Returns a QString representing the given value)
 
103
QString stringify(int);
 
104
 
 
105
//Returns gmara page name of the given page number (From 4, which is Bet Amud Alef)
 
106
QString GmaraPage(int num);
 
107
 
 
108
//Makes sure the given filepath is absolute
 
109
QString absPath(QString);
 
110
 
 
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);
 
116
 
 
117
// Returns a string the search should display for this book and position
 
118
///QString BookSearchDisplay (QString BookDisplayName , QString PositionName);
 
119
 
 
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);
 
123
 
 
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);
 
128
 
 
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);
 
132
 
 
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);
 
137
 
 
138
//Returns the given string the given number of times
 
139
QString stringTimes(const QString& str, int t);
 
140
 
 
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);
 
147
 
 
148
 
 
149
//Removes any sign from the given unicode string
 
150
// (Nikud or teamim)
 
151
QString removeSigns(const QString& str);
 
152
 
 
153
//Removes any nikud sign from the given unicode string
 
154
QString removeNikud(const QString&);
 
155
 
 
156
//Removes any teamim sign from the given unicode string
 
157
QString removeTeamim(const QString& str);
 
158
 
 
159
QString allowNikudAndTeamim( const QString& str );
 
160
QRegExp withNikudAndTeamim( const QString& str );
 
161
 
 
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);
 
165
 
 
166
QString AllowKtivHasser(const QString& str);
 
167
 
 
168
 
 
169
QString simpleHtmlPage(QString title, QString contents);
 
170
QString pluginPage(QString title);
 
171
 
 
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);
 
176
 
 
177
//Generate search DB files from the given bookflie (Non-compressed)
 
178
void GenerateSearchTextDB(QString infile,  QString pureTextOutPath, QString levelMapOutPath);
 
179
 
 
180
#ifdef POPPLER
 
181
 
 
182
// Returns a corrected Bidi string from the given one.
 
183
// (Using the 'LineToBidiText' function)
 
184
QString ToBidiText(QString str);
 
185
 
 
186
// Returns a corrected single line Bidi string from the given one.
 
187
// (Using fribidi's functions)
 
188
QString LineToBidiText(QString str);
 
189
 
 
190
#endif //POPPLER
 
191
 
 
192
#endif // FUNCTIONS_H