void MobileApp::updateDownloadableList() { QList <QString> dl; groups.clear(); ReadFileToList(SAVEDBOOKLIST, dl, "UTF-8"); parseDLFile(dl); //show aprorpriate widgets ui->downloadSTKWidget->setCurrentIndex(1); //Clear the old list ui->downloadListWidget->clear(); //Build the new list for (int i=0; i<groups.size(); i++) { if (groups[i].downloadState != 0) { QListWidgetItem *lwi; lwi= new QListWidgetItem(groups[i].name + " (" + QString::number(groups[i].downloadSize) + /* "/" + QString::number(groups[i].fullSize) + */ " MB)"); if (autoInstallKukBooksFlag && groups[i].name.contains("הרחבה")) lwi->setCheckState(Qt::Checked); else lwi->setCheckState(Qt::Unchecked); lwi->setWhatsThis(stringify(i)); lwi->setToolTip("False"); if(groups[i].hidden) lwi->setTextColor(QColor("gray")); ui->downloadListWidget->addItem(lwi); ui->downloadListWidget->setEnabled(true); } } if(autoInstallKukBooksFlag) downloadStart(); }
// Recursivly add all book files to the list void BookList::addAllBooks (QString dirpath, bool isUserBooks, int parentindex) { QDir cdir(absPath(dirpath)); //Get all .folder or .obk files in the directory QStringList filter; filter << "*.folder" << "*.obk" << "*.pdf" << "*.link" << "*.html" << "*.htm"; QFileInfoList list = cdir.entryInfoList(filter, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDir::Name); //TODO: Add pdf, html, etc' for (int i=0; i<list.size(); i++) { Book::Filetype ft; if (list[i].fileName().endsWith(".folder", Qt::CaseInsensitive)) ft = Book::Dir; else if (list[i].fileName().endsWith(".obk", Qt::CaseInsensitive)) ft = Book::Normal; else if (list[i].fileName().endsWith(".html", Qt::CaseInsensitive) || list[i].fileName().endsWith(".htm", Qt::CaseInsensitive)) ft = Book::Html; else if (list[i].fileName().endsWith(".pdf", Qt::CaseInsensitive)) ft = Book::Pdf; else if (list[i].fileName().endsWith(".link", Qt::CaseInsensitive)) ft = Book::Link; else ft = Book::Unkown; if ( ft != Book::Unkown ) { if ( list[i].fileName().indexOf("Pics") != -1 ) continue; QString Name = list[i].fileName(); if (!isUserBooks) Name.replace(QRegExp("^[0-9 ]*"), "").replace("_", " ").replace(".obk", ""); //Create BookListItem Book *b = new Book(parentindex != -1 ? (*this)[parentindex] : NULL, list[i].absoluteFilePath(), list[i].absoluteFilePath(), Name, ft, isUserBooks); //Tell the parent it has a new child if (b->getParent() != NULL) b->getParent()->add_child(b); //Add this book to the list push_back(b); //Add folder entry, and all files in that folder if (ft == Book::Dir) { //Do the whole thing again for any dir, sending it's index in the list as the // Parents index of all it's children addAllBooks(list[i].absoluteFilePath().replace(".folder", ""), isUserBooks, this->size() - 1); //Add confs for this directory QList <QString> t; t.clear(); if (ReadFileToList(list[i].absoluteFilePath(), t , "UTF-8")) AddBookConfs(b, t); } //Add orayta-book else if ( ft == Book::Normal ) { //Add confs for this book QList <QString> t; t.clear(); if (ReadZipComment(list[i].absoluteFilePath(), t, "UTF-8")) AddBookConfs(b, t); } else if ( ft == Book::Link ) { //Add confs for this book AddBookConfs(b, readfile(b->getPath(), "UTF-8").split("\n")); } else if ( ft == Book::Html ) { //Add confs for this book AddBookConfs(b, readfile(b->getPath().replace(QRegExp("\\.\\w{3,4}$"),".conf"), "UTF-8").split("\n")); } } } /* for (int i=0; i<list.size(); i++) { Book::Filetype ft; // set the file type if (list[i].isDir()) ft = Book::Dir; else if (list[i].fileName().endsWith(".txt", Qt::CaseInsensitive)) ft = Book::Normal; else if (list[i].fileName().endsWith(".html", Qt::CaseInsensitive) || list[i].fileName().endsWith(".htm", Qt::CaseInsensitive)) ft = Book::Html; else if (list[i].fileName().endsWith(".pdf", Qt::CaseInsensitive)) ft = Book::Pdf; else if (list[i].fileName().endsWith(".link", Qt::CaseInsensitive)) ft = Book::Link; else ft = Book::Unkown; if ( ft != Book::Unkown ) { if ( list[i].fileName().indexOf("Pics") != -1 ) continue; QString Name = list[i].fileName(); if (!isUserBooks) Name.replace(QRegExp("^[0-9 ]*"), "").replace("_", " "); //Create BookListItem Book *b = new Book(parentindex != -1 ? (*this)[parentindex] : NULL, list[i].absoluteFilePath(), list[i].absoluteFilePath(), Name, ft, isUserBooks); //Tell the parent it has a new child if (b->getParent() != NULL) b->getParent()->add_child(b); //Add this book to the list push_back(b); if ( ft == Book::Normal ) { //Add confs for this book AddBookConfs(b, b->getPath().replace(".txt",".conf")); } if ( ft == Book::Html ) { //Add confs for this book AddBookConfs(b, b->getPath().replace(QRegExp("\\.\\w{3,4}$"),".conf")); } if ( ft == Book::Link ) { //Add confs for this book AddBookConfs(b, b->getPath()); } if ( isUserBooks ) { //b->setIsInSearch(false); } else { // call this after AddBookConfs b->loadFont(); } if (ft == Book::Dir) { //Do the whole thing again for any dir, sending it's index in the list as the // Parents index of all it's children addAllBooks(list[i].absoluteFilePath(), isUserBooks, this->size() - 1); //Add confs for this directory AddBookConfs(b, b->getPath().append(".conf")); } } } */ }