-rw-r--r-- | noncore/apps/opie-gutenbrowser/openetext.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/noncore/apps/opie-gutenbrowser/openetext.cpp b/noncore/apps/opie-gutenbrowser/openetext.cpp index a5d855d..75edacd 100644 --- a/noncore/apps/opie-gutenbrowser/openetext.cpp +++ b/noncore/apps/opie-gutenbrowser/openetext.cpp | |||
@@ -1,513 +1,511 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | openetext.cpp - description | 2 | openetext.cpp - description |
3 | begin : Sat Dec 4 1999 | 3 | begin : Sat Dec 4 1999 |
4 | begin : Tue Jul 25 2000 | 4 | begin : Tue Jul 25 2000 |
5 | copyright : (C) 2000 -2004 by llornkcor | 5 | copyright : (C) 2000 -2004 by llornkcor |
6 | email : ljp@llornkcor.com | 6 | email : ljp@llornkcor.com |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | /*************************************************************************** | 8 | /*************************************************************************** |
9 | * This program is free software; you can redistribute it and/or modify * | 9 | * This program is free software; you can redistribute it and/or modify * |
10 | * it under the terms of the GNU General Public License as published by * | 10 | * it under the terms of the GNU General Public License as published by * |
11 | * the Free Software Foundation; either version 2 of the License, or * | 11 | * the Free Software Foundation; either version 2 of the License, or * |
12 | * (at your option) any later version. * | 12 | * (at your option) any later version. * |
13 | ***************************************************************************/ | 13 | ***************************************************************************/ |
14 | 14 | ||
15 | #include "gutenbrowser.h" | 15 | #include "gutenbrowser.h" |
16 | #include "openetext.h" | 16 | #include "openetext.h" |
17 | #include "editTitle.h" | 17 | #include "editTitle.h" |
18 | 18 | ||
19 | /* OPIE */ | 19 | /* OPIE */ |
20 | #include <opie2/ofiledialog.h> | 20 | #include <opie2/ofiledialog.h> |
21 | #include <opie2/odebug.h> | 21 | #include <opie2/odebug.h> |
22 | #include <qpe/applnk.h> | 22 | #include <qpe/applnk.h> |
23 | #include <qpe/config.h> | 23 | #include <qpe/config.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | using namespace Opie::Ui; | 25 | using namespace Opie::Ui; |
26 | 26 | ||
27 | /* QT */ | 27 | /* QT */ |
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qfileinfo.h> | 29 | #include <qfileinfo.h> |
30 | 30 | ||
31 | /* STD */ | 31 | /* STD */ |
32 | #if defined(_WS_WIN_) | 32 | #if defined(_WS_WIN_) |
33 | #include <windows.h> | 33 | #include <windows.h> |
34 | #else | 34 | #else |
35 | #include <unistd.h> | 35 | #include <unistd.h> |
36 | #include <stdlib.h> | 36 | #include <stdlib.h> |
37 | #include <sys/stat.h> | 37 | #include <sys/stat.h> |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true) | 40 | OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true) |
41 | { | 41 | { |
42 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; | 42 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; |
43 | local_index=local_library+"GUTINDEX.ALL"; | 43 | local_index=local_library+"GUTINDEX.ALL"; |
44 | initDialog(); | 44 | initDialog(); |
45 | connect( QListBox_1, SIGNAL(selected ( int)),this, SLOT(select_title(int)) ); | 45 | connect( QListBox_1, SIGNAL(selected ( int)),this, SLOT(select_title(int)) ); |
46 | 46 | ||
47 | getTitles(); | 47 | getTitles(); |
48 | } | 48 | } |
49 | 49 | ||
50 | OpenEtext::~OpenEtext() | 50 | OpenEtext::~OpenEtext() |
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | void OpenEtext::getTitles() | 54 | void OpenEtext::getTitles() |
55 | { | 55 | { |
56 | QListBox_1->clear(); | 56 | QListBox_1->clear(); |
57 | Config config("Gutenbrowser"); | 57 | Config config("Gutenbrowser"); |
58 | config.setGroup( "Files" ); | 58 | config.setGroup( "Files" ); |
59 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 59 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
60 | QLabel_1->setText( tr( s_numofFiles+" etexts in your library." ) ); | 60 | QLabel_1->setText( tr( s_numofFiles+" etexts in your library." ) ); |
61 | int i_numofFiles = s_numofFiles.toInt(); | 61 | int i_numofFiles = s_numofFiles.toInt(); |
62 | for (int i = 1; i <= i_numofFiles+1; i++) { | 62 | for (int i = 1; i <= i_numofFiles+1; i++) { |
63 | QString temp; | 63 | QString temp; |
64 | temp.setNum(i); | 64 | temp.setNum(i); |
65 | config.setGroup( "Files" ); | 65 | config.setGroup( "Files" ); |
66 | QString ramble = config.readEntry(temp, "" ); | 66 | QString ramble = config.readEntry(temp, "" ); |
67 | config.setGroup( "Titles" ); | 67 | config.setGroup( "Titles" ); |
68 | title = config.readEntry(ramble, ""); | 68 | title = config.readEntry(ramble, ""); |
69 | if( !title.isEmpty()) { | 69 | if( !title.isEmpty()) { |
70 | QListBox_1->insertItem ( QPixmap( | 70 | QListBox_1->insertItem ( QPixmap( |
71 | QPEApplication::qpeDir() + | 71 | QPEApplication::qpeDir() + |
72 | "pics/gutenbrowser/gutenbrowser_sm.png" | 72 | "pics/gutenbrowser/gutenbrowser_sm.png" |
73 | ), | 73 | ), |
74 | title, | 74 | title, |
75 | -1); | 75 | -1); |
76 | } | 76 | } |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | /* | 80 | /* |
81 | opens selected title */ | 81 | opens selected title */ |
82 | void OpenEtext::OpenTitle() | 82 | void OpenEtext::OpenTitle() |
83 | { | 83 | { |
84 | if( QListBox_1->currentItem() != -1) | 84 | if( QListBox_1->currentItem() != -1) |
85 | select_title( QListBox_1->currentItem() ); | 85 | select_title( QListBox_1->currentItem() ); |
86 | else { | 86 | else { |
87 | QString sMsg; | 87 | QString sMsg; |
88 | sMsg = "You must select an Etext to open"; | 88 | sMsg = "You must select an Etext to open"; |
89 | QMessageBox::message( "Error",sMsg); | 89 | QMessageBox::message( "Error",sMsg); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | void OpenEtext::select_title(int index ) | 93 | void OpenEtext::select_title(int index ) |
94 | { | 94 | { |
95 | OpenButton->setDown(TRUE); | 95 | OpenButton->setDown(TRUE); |
96 | QString temp; | 96 | QString temp; |
97 | temp.setNum( index + 1); | 97 | temp.setNum( index + 1); |
98 | const char * title; | 98 | const char * title; |
99 | title = QListBox_1->text( index ); | 99 | title = QListBox_1->text( index ); |
100 | openFileTitle = title; | 100 | openFileTitle = title; |
101 | Config config("Gutenbrowser"); | 101 | Config config("Gutenbrowser"); |
102 | config.setGroup( "Files" ); | 102 | config.setGroup( "Files" ); |
103 | file = config.readEntry(temp, ""); | 103 | file = config.readEntry(temp, ""); |
104 | OpenEtext::accept(); | 104 | OpenEtext::accept(); |
105 | } | 105 | } |
106 | 106 | ||
107 | /*! | 107 | /*! |
108 | * This function imports already existing etexts into the local library list | 108 | * This function imports already existing etexts into the local library list |
109 | */ | 109 | */ |
110 | void OpenEtext::open() | 110 | void OpenEtext::open() |
111 | { | 111 | { |
112 | OpenFileButton->setDown(TRUE); | 112 | OpenFileButton->setDown(TRUE); |
113 | title = ""; | 113 | title = ""; |
114 | QString currDir=""; | 114 | QString currDir=""; |
115 | QString filer; | 115 | QString filer; |
116 | QString name_file; | 116 | QString name_file; |
117 | QString local ; | 117 | QString local ; |
118 | local = (QDir::homeDirPath () +"Applications/gutenbrowser"); | 118 | local = (QDir::homeDirPath () +"Applications/gutenbrowser"); |
119 | QDir library( local); | 119 | QDir library( local); |
120 | 120 | ||
121 | Config cfg("Gutenbrowser"); | 121 | Config cfg("Gutenbrowser"); |
122 | cfg. setGroup ( "View" ); | 122 | cfg. setGroup ( "View" ); |
123 | QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); | 123 | QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); |
124 | QMap<QString, QStringList> map; | 124 | QMap<QString, QStringList> map; |
125 | map.insert(tr("All"), QStringList() ); | 125 | map.insert(tr("All"), QStringList() ); |
126 | QStringList text; | 126 | QStringList text; |
127 | text << "text/*"; | 127 | text << "text/*"; |
128 | map.insert(tr("Text"), text ); | 128 | map.insert(tr("Text"), text ); |
129 | text << "*"; | 129 | text << "*"; |
130 | map.insert(tr("All"), text ); | 130 | map.insert(tr("All"), text ); |
131 | 131 | ||
132 | QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map); | 132 | QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map); |
133 | 133 | ||
134 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { | 134 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { |
135 | filer = str; | 135 | filer = str; |
136 | 136 | ||
137 | odebug << "Open file: "+str << oendl; | 137 | odebug << "Open file: "+str << oendl; |
138 | 138 | ||
139 | if( filer.right(4) == ".txt" || | 139 | if( filer.right(4) == ".txt" || |
140 | filer.right(4) == ".TXT" || | 140 | filer.right(4) == ".TXT" || |
141 | filer.right(4) == ".etx" || | 141 | filer.right(4) == ".etx" || |
142 | filer.right(4) == ".ETX" || | 142 | filer.right(4) == ".ETX" || |
143 | filer.right(4) == ".etx" || | 143 | filer.right(4) == ".etx" || |
144 | filer.right(4) == ".ETX" || | 144 | filer.right(4) == ".ETX" || |
145 | filer.right(4) == ".zip" || | 145 | filer.right(4) == ".zip" || |
146 | filer.right(4) == ".ZIP" ) | 146 | filer.right(4) == ".ZIP" ) |
147 | { | 147 | { |
148 | QFileInfo zipFile( filer); | 148 | QFileInfo zipFile( filer); |
149 | QString s_fileName = zipFile.fileName(); | 149 | QString s_fileName = zipFile.fileName(); |
150 | QString cmd; | 150 | QString cmd; |
151 | 151 | ||
152 | if( s_fileName.right(4) == ".zip") { // unzip the file | 152 | if( s_fileName.right(4) == ".zip") { // unzip the file |
153 | s_fileName = s_fileName.left( s_fileName.length() - 4); | 153 | s_fileName = s_fileName.left( s_fileName.length() - 4); |
154 | if( chdir((const char*)local_library.latin1())!=0) | 154 | if( chdir((const char*)local_library.latin1())!=0) |
155 | odebug << "chdir failed." << oendl; | 155 | odebug << "chdir failed." << oendl; |
156 | cmd = "gunzip -S .zip " + filer; | 156 | cmd = "gunzip -S .zip " + filer; |
157 | fileName = local_library + s_fileName + ".txt"; | 157 | fileName = local_library + s_fileName + ".txt"; |
158 | system( cmd); | 158 | system( cmd); |
159 | } else { // else rename .txt to .etx | 159 | } else { // else rename .txt to .etx |
160 | // odebug << "Filename is "+fileName << oendl; | 160 | // odebug << "Filename is "+fileName << oendl; |
161 | s_fileName = fileName; | 161 | s_fileName = fileName; |
162 | s_fileName.replace( s_fileName.length()-3,3,"gtn"); | 162 | s_fileName.replace( s_fileName.length()-3,3,"gtn"); |
163 | if (rename(fileName.latin1(),s_fileName.latin1()) == -1) | 163 | if (rename(fileName.latin1(),s_fileName.latin1()) == -1) |
164 | owarn << "Rename of " << fileName.latin1() << " to " | 164 | owarn << "Rename of " << fileName.latin1() << " to " |
165 | << s_fileName.latin1() << " failed" << oendl; | 165 | << s_fileName.latin1() << " failed" << oendl; |
166 | fileName = s_fileName; | 166 | fileName = s_fileName; |
167 | // odebug << "Filename is now "+fileName << oendl; | 167 | // odebug << "Filename is now "+fileName << oendl; |
168 | } | 168 | } |
169 | } else | 169 | } else |
170 | fileName = str; | 170 | fileName = str; |
171 | 171 | ||
172 | FindTitle(fileName); | 172 | FindTitle(fileName); |
173 | 173 | ||
174 | QFileInfo fi( fileName); | 174 | QFileInfo fi( fileName); |
175 | name_file = fi.fileName(); | 175 | name_file = fi.fileName(); |
176 | name_file = name_file.left(name_file.length() - 4); | 176 | name_file = name_file.left(name_file.length() - 4); |
177 | 177 | ||
178 | odebug << "Setting doclink" << oendl; | 178 | odebug << "Setting doclink" << oendl; |
179 | DocLnk lnk; | 179 | DocLnk lnk; |
180 | odebug << "name is " + name_file << oendl; | 180 | odebug << "name is " + name_file << oendl; |
181 | lnk.setName(name_file); //sets file name | 181 | lnk.setName(name_file); //sets file name |
182 | odebug << "Title is "+title << oendl; | 182 | odebug << "Title is "+title << oendl; |
183 | lnk.setComment(title); | 183 | lnk.setComment(title); |
184 | 184 | ||
185 | QListBox_1->clear(); | 185 | QListBox_1->clear(); |
186 | getTitles(); | 186 | getTitles(); |
187 | odebug << "Filename is "+fileName << oendl; | 187 | odebug << "Filename is "+fileName << oendl; |
188 | lnk.setFile(fileName); //sets File property | 188 | lnk.setFile(fileName); //sets File property |
189 | // @bug This is probably not a registered MIME type. Perhaps we should | 189 | // @bug This is probably not a registered MIME type. Perhaps we should |
190 | // set a valid MIME type here instead. Or maybe register .etx as a | 190 | // set a valid MIME type here instead. Or maybe register .etx as a |
191 | // Gutenberge etext? | 191 | // Gutenberge etext? |
192 | lnk.setType("guten/plain"); | 192 | lnk.setType("guten/plain"); |
193 | lnk.setExec(fileName); | 193 | lnk.setExec(fileName); |
194 | lnk.setIcon("gutenbrowser/Gutenbrowser"); | 194 | lnk.setIcon("gutenbrowser/Gutenbrowser"); |
195 | if(!lnk.writeLink()) | 195 | if(!lnk.writeLink()) |
196 | odebug << "Writing doclink did not work" << oendl; | 196 | odebug << "Writing doclink did not work" << oendl; |
197 | 197 | ||
198 | } // end of for each file name.... | 198 | } // end of for each file name.... |
199 | OpenFileButton->setDown(FALSE); | 199 | OpenFileButton->setDown(FALSE); |
200 | } | 200 | } |
201 | 201 | ||
202 | /* | 202 | /* |
203 | find the title in the config file */ | 203 | find the title in the config file */ |
204 | bool OpenEtext::FindTitle( QString filename) | 204 | bool OpenEtext::FindTitle( QString filename) |
205 | { | 205 | { |
206 | Config config("Gutenbrowser"); | 206 | Config config("Gutenbrowser"); |
207 | config.setGroup( "Files" ); | 207 | config.setGroup( "Files" ); |
208 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 208 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
209 | int i_numofFiles = s_numofFiles.toInt(); | 209 | int i_numofFiles = s_numofFiles.toInt(); |
210 | 210 | ||
211 | QFileInfo fi(filename); | 211 | QFileInfo fi(filename); |
212 | name = fi.fileName(); | 212 | name = fi.fileName(); |
213 | odebug << "filename to open is " + name << oendl; | 213 | odebug << "filename to open is " + name << oendl; |
214 | QFile indexLib( filename); | 214 | QFile indexLib( filename); |
215 | bool findCheck = FALSE; | 215 | bool findCheck = FALSE; |
216 | 216 | ||
217 | if ( indexLib.open( IO_ReadOnly) ) { | 217 | if ( indexLib.open( IO_ReadOnly) ) { |
218 | odebug << "file opened successfully" << oendl; | 218 | odebug << "file opened successfully" << oendl; |
219 | QTextStream indexStream( &indexLib ); | 219 | QTextStream indexStream( &indexLib ); |
220 | QString target = "Project Gutenberg Etext of"; | 220 | QString target = "Project Gutenberg Etext of"; |
221 | QString target2 = "Project Gutenberg Etext"; | 221 | QString target2 = "Project Gutenberg Etext"; |
222 | QString target3 = "Project Gutenberg's Etext of"; | 222 | QString target3 = "Project Gutenberg's Etext of"; |
223 | QString target4 = "Project Gutenberg's Etext"; | 223 | QString target4 = "Project Gutenberg's Etext"; |
224 | QString indexLine; | 224 | QString indexLine; |
225 | while ( !indexStream.eof() ) { | 225 | while ( !indexStream.eof() ) { |
226 | // until end of file.. | 226 | // until end of file.. |
227 | indexLine = indexStream.readLine(); | 227 | indexLine = indexStream.readLine(); |
228 | if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE; | 228 | if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE; |
229 | title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE)); | 229 | title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE)); |
230 | title = title.left( title.find( "*",0, TRUE)); | 230 | title = title.left( title.find( "*",0, TRUE)); |
231 | title = title.stripWhiteSpace (); | 231 | title = title.stripWhiteSpace (); |
232 | // odebug << "Found the title 1 and it is " << title << "" << oendl; | 232 | // odebug << "Found the title 1 and it is " << title << "" << oendl; |
233 | // QListBox_1->insertItem ( title); | 233 | // QListBox_1->insertItem ( title); |
234 | } | 234 | } |
235 | if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) { | 235 | if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) { |
236 | findCheck = TRUE; | 236 | findCheck = TRUE; |
237 | title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) ); | 237 | title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) ); |
238 | title = title.left( title.find( "*",0, TRUE)); | 238 | title = title.left( title.find( "*",0, TRUE)); |
239 | title = title.stripWhiteSpace (); | 239 | title = title.stripWhiteSpace (); |
240 | // odebug << "Found the title 2 and it is " << title << "" << oendl; | 240 | // odebug << "Found the title 2 and it is " << title << "" << oendl; |
241 | // QListBox_1->insertItem ( title); | 241 | // QListBox_1->insertItem ( title); |
242 | } | 242 | } |
243 | if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) { | 243 | if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) { |
244 | findCheck = TRUE; | 244 | findCheck = TRUE; |
245 | title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE)); | 245 | title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE)); |
246 | title = title.left( title.find( "*",0, TRUE)); | 246 | title = title.left( title.find( "*",0, TRUE)); |
247 | title = title.stripWhiteSpace (); | 247 | title = title.stripWhiteSpace (); |
248 | // odebug << "Found the title 3 and it is " << title << "" << oendl; | 248 | // odebug << "Found the title 3 and it is " << title << "" << oendl; |
249 | } | 249 | } |
250 | if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) { | 250 | if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) { |
251 | findCheck = TRUE; | 251 | findCheck = TRUE; |
252 | title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE)); | 252 | title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE)); |
253 | title = title.left( title.find( "*",0, TRUE)); | 253 | title = title.left( title.find( "*",0, TRUE)); |
254 | title = title.stripWhiteSpace (); | 254 | title = title.stripWhiteSpace (); |
255 | // odebug << "Found the title 4 and it is " << title << "" << oendl; | 255 | // odebug << "Found the title 4 and it is " << title << "" << oendl; |
256 | } | 256 | } |
257 | } //endof file | 257 | } //endof file |
258 | indexLib.close(); | 258 | indexLib.close(); |
259 | 259 | ||
260 | if( !findCheck || title.length() < 2) { | 260 | if( !findCheck || title.length() < 2) { |
261 | odebug << "Trying hard to find title from GUTINDEX.ALL" << oendl; | 261 | odebug << "Trying hard to find title from GUTINDEX.ALL" << oendl; |
262 | title = titleFromLibrary( filename); | 262 | title = titleFromLibrary( filename); |
263 | findCheck = TRUE; | 263 | findCheck = TRUE; |
264 | } | 264 | } |
265 | 265 | ||
266 | if ( checkConf() == false && findCheck == TRUE) { | 266 | if ( checkConf() == false && findCheck == TRUE) { |
267 | config.setGroup( "Files"); | 267 | config.setGroup( "Files"); |
268 | config.writeEntry("NumberOfFiles",i_numofFiles + 1 ); | 268 | config.writeEntry("NumberOfFiles",i_numofFiles + 1 ); |
269 | QString interger; | 269 | QString interger; |
270 | interger.setNum( i_numofFiles +1); | 270 | interger.setNum( i_numofFiles +1); |
271 | config.writeEntry(interger, filename); | 271 | config.writeEntry(interger, filename); |
272 | config.setGroup( "Titles" ); | 272 | config.setGroup( "Titles" ); |
273 | for (int i = 1; i <= i_numofFiles; i++) { //find dup titles in config file | 273 | for (int i = 1; i <= i_numofFiles; i++) { //find dup titles in config file |
274 | QString temp; | 274 | QString temp; |
275 | temp.setNum(i); | 275 | temp.setNum(i); |
276 | config.setGroup( "Files" ); | 276 | config.setGroup( "Files" ); |
277 | QString ramble = config.readEntry(temp, "" ); | 277 | QString ramble = config.readEntry(temp, "" ); |
278 | config.setGroup( "Titles" ); | 278 | config.setGroup( "Titles" ); |
279 | QString title1 = config.readEntry(ramble, ""); | 279 | QString title1 = config.readEntry(ramble, ""); |
280 | if(title1==title) | 280 | if(title1==title) |
281 | title+="1"; | 281 | title+="1"; |
282 | i= i_numofFiles+1; | 282 | i= i_numofFiles+1; |
283 | } | 283 | } |
284 | if(title.length()<3) { | 284 | if(title.length()<3) { |
285 | // odebug << "title is empty" << oendl; | 285 | // odebug << "title is empty" << oendl; |
286 | title="Unknown"; | 286 | title="Unknown"; |
287 | } | 287 | } |
288 | config.writeEntry( filename,title); | 288 | config.writeEntry( filename,title); |
289 | } | 289 | } |
290 | } else { | 290 | } else { |
291 | QString sMsg; | 291 | QString sMsg; |
292 | sMsg = "Error opening library file: "+filename; | 292 | sMsg = "Error opening library file: "+filename; |
293 | printf( sMsg+"\n"); | 293 | printf( sMsg+"\n"); |
294 | } | 294 | } |
295 | return true; | 295 | return true; |
296 | } | 296 | } |
297 | 297 | ||
298 | QString OpenEtext::titleFromLibrary( QString fileName) | 298 | QString OpenEtext::titleFromLibrary( QString fileName) |
299 | { | 299 | { |
300 | QFile indexLib( local_index); | 300 | QFile indexLib( local_index); |
301 | QString target; | 301 | QString target; |
302 | int find1 = fileName.findRev("/",-1,TRUE) + 1; | 302 | int find1 = fileName.findRev("/",-1,TRUE) + 1; |
303 | int find2 = fileName.findRev(".gtn",-1,TRUE) - find1; | 303 | int find2 = fileName.findRev(".gtn",-1,TRUE) - find1; |
304 | if(find2== (-1-find1)) | 304 | if(find2== (-1-find1)) |
305 | find2 = fileName.findRev(".etx",-1,TRUE) - find1; | 305 | find2 = fileName.findRev(".etx",-1,TRUE) - find1; |
306 | else if(find2==(-1-find1)) | 306 | else if(find2==(-1-find1)) |
307 | find2 = fileName.findRev(".txt",-1,TRUE) - find1; | 307 | find2 = fileName.findRev(".txt",-1,TRUE) - find1; |
308 | 308 | ||
309 | target = fileName.mid( find1, find2 ); | 309 | target = fileName.mid( find1, find2 ); |
310 | QString checker = target.right(1); | 310 | QString checker = target.right(1); |
311 | bool ok; | 311 | bool ok; |
312 | checker.toInt( &ok,10); | 312 | checker.toInt( &ok,10); |
313 | if( ok) { | 313 | if( ok) { |
314 | target = target.left( target.length()-1); | 314 | target = target.left( target.length()-1); |
315 | checker = target.right(1); | 315 | checker = target.right(1); |
316 | ok = FALSE; | 316 | ok = FALSE; |
317 | checker.toInt( &ok,10); | 317 | checker.toInt( &ok,10); |
318 | if( ok) { | 318 | if( ok) { |
319 | target = target.left( target.length()-1); | 319 | target = target.left( target.length()-1); |
320 | } | 320 | } |
321 | } | 321 | } |
322 | if ( indexLib.open( IO_ReadOnly) ) { | 322 | if ( indexLib.open( IO_ReadOnly) ) { |
323 | // file opened successfully | 323 | // file opened successfully |
324 | QTextStream indexStream( &indexLib ); | 324 | QTextStream indexStream( &indexLib ); |
325 | QString indexLine; | 325 | QString indexLine; |
326 | bool findCheck = FALSE; | 326 | bool findCheck = FALSE; |
327 | while ( !indexStream.atEnd() ) { // until end of file.. | 327 | while ( !indexStream.atEnd() ) { // until end of file.. |
328 | indexLine = indexStream.readLine(); | 328 | indexLine = indexStream.readLine(); |
329 | 329 | ||
330 | if( indexLine.find( target,0,FALSE) > 0 ) { | 330 | if( indexLine.find( target,0,FALSE) > 0 ) { |
331 | findCheck = TRUE; | 331 | findCheck = TRUE; |
332 | title = indexLine.mid( 9, 50); | 332 | title = indexLine.mid( 9, 50); |
333 | title = title.stripWhiteSpace (); | 333 | title = title.stripWhiteSpace (); |
334 | // odebug << "Finally Found the title and it is\n " << title << "" << oendl; | 334 | // odebug << "Finally Found the title and it is\n " << title << "" << oendl; |
335 | // QListBox_1->insertItem ( title); | 335 | // QListBox_1->insertItem ( title); |
336 | } | 336 | } |
337 | } //end while loop | 337 | } //end while loop |
338 | } | 338 | } |
339 | else | 339 | else |
340 | odebug << "Error opening library index "+ local_index << oendl; | 340 | odebug << "Error opening library index "+ local_index << oendl; |
341 | return title; | 341 | return title; |
342 | } | 342 | } |
343 | 343 | ||
344 | bool OpenEtext::checkConf() | 344 | bool OpenEtext::checkConf() |
345 | { | 345 | { |
346 | QString file = fileName; | 346 | QString file = fileName; |
347 | Config config("Gutenbrowser"); | 347 | Config config("Gutenbrowser"); |
348 | config.setGroup( "Files" ); | 348 | config.setGroup( "Files" ); |
349 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); | 349 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); |
350 | int i_numofFiles = s_numofFiles.toInt(); | 350 | int i_numofFiles = s_numofFiles.toInt(); |
351 | 351 | ||
352 | for (int i = 1; i <= i_numofFiles; i++) { | 352 | for (int i = 1; i <= i_numofFiles; i++) { |
353 | QString temp; | 353 | QString temp; |
354 | temp.setNum(i); | 354 | temp.setNum(i); |
355 | config.setGroup( "Files"); | 355 | config.setGroup( "Files"); |
356 | QString ramble = config.readEntry(temp, "" ); | 356 | QString ramble = config.readEntry(temp, "" ); |
357 | 357 | ||
358 | if(ramble == file ) { | 358 | if(ramble == file ) { |
359 | return true; | 359 | return true; |
360 | } | 360 | } |
361 | } | 361 | } |
362 | return false; | 362 | return false; |
363 | } | 363 | } |
364 | 364 | ||
365 | void OpenEtext::remove() | 365 | void OpenEtext::remove() |
366 | { | 366 | { |
367 | title_text = QListBox_1->text( QListBox_1->currentItem() ); | 367 | title_text = QListBox_1->text( QListBox_1->currentItem() ); |
368 | title_text=title_text.stripWhiteSpace(); | 368 | title_text=title_text.stripWhiteSpace(); |
369 | QString msg ="<p>Do you really want to REMOVE\n" + title_text + | 369 | QString msg ="<p>Do you really want to REMOVE\n" + title_text + |
370 | "?\nThis will not delete the file.</P>"; | 370 | "?\nThis will not delete the file.</P>"; |
371 | switch( QMessageBox::information( this, tr("Remove Etext"), | 371 | unsigned short clickVal = |
372 | tr(msg), | 372 | QMessageBox::information( this, tr("Remove Etext"), |
373 | tr("&Yes"), tr("&Cancel"), 0 ) ) | 373 | tr(msg), |
374 | { | 374 | tr("&Yes"), tr("&Cancel"), 0 ); |
375 | case 0: // Yes clicked, | 375 | if ( clickVal == 0 ) { |
376 | removeSelection(); | 376 | // The yes button was clicked |
377 | QListBox_1->clear(); | 377 | removeSelection(); |
378 | getTitles(); | 378 | QListBox_1->clear(); |
379 | break; | 379 | getTitles(); |
380 | case 1: | ||
381 | default: | ||
382 | } | 380 | } |
383 | } | 381 | } |
384 | 382 | ||
385 | /*! | 383 | /*! |
386 | * This removes selected title entry | 384 | * This removes selected title entry |
387 | */ | 385 | */ |
388 | void OpenEtext::removeSelection() | 386 | void OpenEtext::removeSelection() |
389 | { | 387 | { |
390 | Config config("Gutenbrowser"); | 388 | Config config("Gutenbrowser"); |
391 | config.setGroup( "Files" ); | 389 | config.setGroup( "Files" ); |
392 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 390 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
393 | int rem=0; | 391 | int rem=0; |
394 | int i_numofFiles = s_numofFiles.toInt(); | 392 | int i_numofFiles = s_numofFiles.toInt(); |
395 | QString fileNum2; | 393 | QString fileNum2; |
396 | QString fileNum; | 394 | QString fileNum; |
397 | 395 | ||
398 | for (int i = 1; i <= i_numofFiles; i++) { | 396 | for (int i = 1; i <= i_numofFiles; i++) { |
399 | fileNum.setNum(i); | 397 | fileNum.setNum(i); |
400 | config.setGroup( "Files" ); | 398 | config.setGroup( "Files" ); |
401 | 399 | ||
402 | QString s_filename = config.readEntry(fileNum, "" ); | 400 | QString s_filename = config.readEntry(fileNum, "" ); |
403 | config.setGroup( "Titles" ); | 401 | config.setGroup( "Titles" ); |
404 | 402 | ||
405 | QString file_title = config.readEntry( s_filename, ""); | 403 | QString file_title = config.readEntry( s_filename, ""); |
406 | if(title_text == file_title) { | 404 | if(title_text == file_title) { |
407 | rem=i; | 405 | rem=i; |
408 | //odebug << "file title to remove is "+file_title << oendl; | 406 | //odebug << "file title to remove is "+file_title << oendl; |
409 | selFile = s_filename; | 407 | selFile = s_filename; |
410 | config.removeEntry( s_filename); //removes file=title | 408 | config.removeEntry( s_filename); //removes file=title |
411 | } | 409 | } |
412 | } | 410 | } |
413 | config.setGroup( "Files" ); | 411 | config.setGroup( "Files" ); |
414 | 412 | ||
415 | for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry | 413 | for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry |
416 | fileNum.setNum(fg); | 414 | fileNum.setNum(fg); |
417 | fileNum2.setNum( fg + 1); | 415 | fileNum2.setNum( fg + 1); |
418 | 416 | ||
419 | QString s_filename2 = config.readEntry(fileNum2, "" ); | 417 | QString s_filename2 = config.readEntry(fileNum2, "" ); |
420 | 418 | ||
421 | if (!s_filename2.isEmpty()) { | 419 | if (!s_filename2.isEmpty()) { |
422 | config.writeEntry(fileNum, s_filename2 ); | 420 | config.writeEntry(fileNum, s_filename2 ); |
423 | } | 421 | } |
424 | } | 422 | } |
425 | config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); | 423 | config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); |
426 | config.removeEntry(fileNum2); | 424 | config.removeEntry(fileNum2); |
427 | } | 425 | } |
428 | 426 | ||
429 | /*! | 427 | /*! |
430 | * Removes file title name from list and config file | 428 | * Removes file title name from list and config file |
431 | */ | 429 | */ |
432 | void OpenEtext::remFile() | 430 | void OpenEtext::remFile() |
433 | { | 431 | { |
434 | Config config("Gutenbrowser"); | 432 | Config config("Gutenbrowser"); |
435 | config.setGroup( "Files" ); | 433 | config.setGroup( "Files" ); |
436 | QString remFile; | 434 | QString remFile; |
437 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 435 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
438 | int i_numofFiles = s_numofFiles.toInt(); | 436 | int i_numofFiles = s_numofFiles.toInt(); |
439 | for (int i = 1; i <= i_numofFiles; i++) { | 437 | for (int i = 1; i <= i_numofFiles; i++) { |
440 | QString fileNum; | 438 | QString fileNum; |
441 | fileNum.setNum(i); | 439 | fileNum.setNum(i); |
442 | QString s_filename = config.readEntry(fileNum, "" ); | 440 | QString s_filename = config.readEntry(fileNum, "" ); |
443 | 441 | ||
444 | if( s_filename == selFile) { | 442 | if( s_filename == selFile) { |
445 | config.removeEntry(selFile); | 443 | config.removeEntry(selFile); |
446 | 444 | ||
447 | for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry | 445 | for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry |
448 | QString fileNum2; | 446 | QString fileNum2; |
449 | fileNum2.setNum( fg + 1); | 447 | fileNum2.setNum( fg + 1); |
450 | QString s_filename2 = config.readEntry(fileNum2, "" ); | 448 | QString s_filename2 = config.readEntry(fileNum2, "" ); |
451 | 449 | ||
452 | if (!s_filename2.isEmpty()) | 450 | if (!s_filename2.isEmpty()) |
453 | config.writeEntry(fileNum, s_filename2 ); | 451 | config.writeEntry(fileNum, s_filename2 ); |
454 | } | 452 | } |
455 | } | 453 | } |
456 | } | 454 | } |
457 | config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); | 455 | config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); |
458 | config.removeEntry(s_numofFiles); | 456 | config.removeEntry(s_numofFiles); |
459 | 457 | ||
460 | QListBox_1->triggerUpdate(true); | 458 | QListBox_1->triggerUpdate(true); |
461 | } | 459 | } |
462 | 460 | ||
463 | /*! | 461 | /*! |
464 | * Sorts the list | 462 | * Sorts the list |
465 | */ | 463 | */ |
466 | void OpenEtext::scan() { | 464 | void OpenEtext::scan() { |
467 | 465 | ||
468 | QListBox_1->sort(TRUE); | 466 | QListBox_1->sort(TRUE); |
469 | QListBox_1->triggerUpdate(true); | 467 | QListBox_1->triggerUpdate(true); |
470 | } | 468 | } |
471 | 469 | ||
472 | void OpenEtext::editTitle() { | 470 | void OpenEtext::editTitle() { |
473 | 471 | ||
474 | int currentItem=QListBox_1->currentItem(); | 472 | int currentItem=QListBox_1->currentItem(); |
475 | QString title_text = QListBox_1->text( currentItem); | 473 | QString title_text = QListBox_1->text( currentItem); |
476 | //odebug << "Selected "+title_text << oendl; | 474 | //odebug << "Selected "+title_text << oendl; |
477 | 475 | ||
478 | Config config("Gutenbrowser"); | 476 | Config config("Gutenbrowser"); |
479 | config.setGroup( "Files" ); | 477 | config.setGroup( "Files" ); |
480 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 478 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
481 | int i_numofFiles = s_numofFiles.toInt(); | 479 | int i_numofFiles = s_numofFiles.toInt(); |
482 | QString fileNum; | 480 | QString fileNum; |
483 | for (int i = 1; i <= i_numofFiles+1; i++) { | 481 | for (int i = 1; i <= i_numofFiles+1; i++) { |
484 | 482 | ||
485 | fileNum.setNum(i); | 483 | fileNum.setNum(i); |
486 | config.setGroup( "Files" ); | 484 | config.setGroup( "Files" ); |
487 | QString s_filename = config.readEntry(fileNum, "" ); | 485 | QString s_filename = config.readEntry(fileNum, "" ); |
488 | config.setGroup( "Titles" ); | 486 | config.setGroup( "Titles" ); |
489 | QString file_title = config.readEntry( s_filename, ""); | 487 | QString file_title = config.readEntry( s_filename, ""); |
490 | //odebug << "file_title is "+file_title << oendl; | 488 | //odebug << "file_title is "+file_title << oendl; |
491 | if(title_text == file_title ) { | 489 | if(title_text == file_title ) { |
492 | selFile = s_filename; | 490 | selFile = s_filename; |
493 | //odebug << "Edit: "+ file_title << oendl; | 491 | //odebug << "Edit: "+ file_title << oendl; |
494 | i=i_numofFiles+1; | 492 | i=i_numofFiles+1; |
495 | Edit_Title *titleEdit; | 493 | Edit_Title *titleEdit; |
496 | titleEdit = new Edit_Title(this,file_title ,TRUE); | 494 | titleEdit = new Edit_Title(this,file_title ,TRUE); |
497 | if(titleEdit->exec() !=0) { | 495 | if(titleEdit->exec() !=0) { |
498 | //odebug << titleEdit->newTitle << oendl; | 496 | //odebug << titleEdit->newTitle << oendl; |
499 | config.writeEntry( s_filename, titleEdit->newTitle); | 497 | config.writeEntry( s_filename, titleEdit->newTitle); |
500 | QListBox_1->removeItem(currentItem); | 498 | QListBox_1->removeItem(currentItem); |
501 | QListBox_1->insertItem ( | 499 | QListBox_1->insertItem ( |
502 | QPixmap( QPEApplication::qpeDir()+ | 500 | QPixmap( QPEApplication::qpeDir()+ |
503 | "pics/gutenbrowser/gutenbrowser_sm.png"), | 501 | "pics/gutenbrowser/gutenbrowser_sm.png"), |
504 | titleEdit->newTitle, currentItem | 502 | titleEdit->newTitle, currentItem |
505 | ); | 503 | ); |
506 | } | 504 | } |
507 | } | 505 | } |
508 | } | 506 | } |
509 | 507 | ||
510 | //getTitles(); | 508 | //getTitles(); |
511 | QListBox_1->triggerUpdate(true); | 509 | QListBox_1->triggerUpdate(true); |
512 | } | 510 | } |
513 | 511 | ||