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>
18
#include "importbook.h"
19
#include "functions.h"
20
#include "ui_importbook.h"
22
#include "desktopapp.h"
26
#include <QDesktopServices>
29
#include <QFileDialog>
32
importBook::importBook(QWidget *parent) : QDialog(parent), ui(new Ui::importBook)
36
ui->listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
37
ui->cancelBTN->hide();
38
ui->importBTN->hide();
39
ui->deleteButton->hide();
42
importBook::~importBook()
47
void importBook::on_addFolder_clicked()
49
QString dirName = QFileDialog::getExistingDirectory(this, "", QDir::homePath(), QFileDialog::ShowDirsOnly);
51
if (!dirName.isEmpty())
53
ui->listWidget->addItem(dirName);
54
ui->cancelBTN->show();
55
ui->importBTN->show();
56
ui->deleteButton->show();
60
void importBook::on_addBooks_clicked()
62
QString filters = tr("All supported files "
63
"(*.html *.htm *.txt *.pdf);;"
64
"Html files(*.htm *.html);;"
68
QStringList fileNames = QFileDialog::getOpenFileNames(this, "", QDir::homePath(), filters);
70
if (!fileNames.empty())
72
for (int i=0; i<fileNames.size(); i++)
74
ui->listWidget->addItem(fileNames[i]);
76
ui->cancelBTN->show();
77
ui->importBTN->show();
78
ui->deleteButton->show();
82
void importBook::on_deleteButton_clicked()
84
QList<QListWidgetItem *> selected_items = ui->listWidget->selectedItems();
85
for (int i=0; i < selected_items.size(); i++)
87
delete selected_items[i];
90
if ( ui->listWidget->count() == 0 )
91
ui->deleteButton->hide();
94
void importBook::on_label_2_linkActivated(QString link)
96
//Open the project's site in a browser
97
QDesktopServices::openUrl(QUrl(link));
100
void importBook::on_cancelBTN_clicked()
105
void importBook::on_importBTN_clicked()
107
QString booksUserPath = USERPATH + "Books/ספרי_המשתמש";
109
//Make sure the dir exists
110
QDir d(booksUserPath) ;
112
d.mkpath(booksUserPath);
114
booksUserPath = booksUserPath + "/";
117
filters << "*.html" << "*.htm" << "*.pdf" << "*.txt";
121
//Copy to user's book folder
122
for (int i=0; i<ui->listWidget->count(); i++)
124
QFileInfo f( ui->listWidget->item(i)->text() );
128
//Copy whole directory
131
copyFolder( f.absoluteFilePath(), booksUserPath + f.fileName(), filters);
137
if ( !cf.copy(f.absoluteFilePath(), booksUserPath + f.fileName()) )
138
qDebug() << "Can't copy file" << f.absoluteFilePath();