modified algo filling treeview to speed
This commit is contained in:
+74
-40
@@ -32,7 +32,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
// init of widgets
|
||||
ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget);
|
||||
ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
ui->treeWidget->setHeaderLabels({tr("Path"), tr("Size")} );
|
||||
ui->treeWidget->setHeaderLabels({tr("Type"), tr("Path"), tr("Size")} );
|
||||
if (this->settings.contains("connexion/lastServer"))
|
||||
{
|
||||
ui->portEdit->setText(this->settings.value("connexion/port").toString());
|
||||
@@ -43,7 +43,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
ui->khistorycombobox->clear();
|
||||
}
|
||||
|
||||
|
||||
ui->progressBar->hide();
|
||||
|
||||
populateList();
|
||||
@@ -87,7 +86,7 @@ void MainWindow::closeEvent (QCloseEvent *event)
|
||||
}
|
||||
|
||||
// Populate treeview with list of files
|
||||
void MainWindow::populateTree()
|
||||
void MainWindow::populateTree(QTreeWidgetItem * parent)
|
||||
{
|
||||
stringstream ss;
|
||||
vector<string> path;
|
||||
@@ -103,7 +102,7 @@ void MainWindow::populateTree()
|
||||
{
|
||||
// server is validated
|
||||
path = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2);
|
||||
scanDir(this->connexion.server, this->connexion.port, NULL, path[0].append("/") );
|
||||
scanDir(this->connexion.server, this->connexion.port, parent, path[0].append("/") );
|
||||
}
|
||||
// Restoring cursor
|
||||
QGuiApplication::restoreOverrideCursor();
|
||||
@@ -193,37 +192,41 @@ void MainWindow::scanDir(string server, int portN, QTreeWidgetItem *parent, stri
|
||||
string errorRsync;
|
||||
vector<string> v;
|
||||
QTreeWidgetItem * item;
|
||||
char npath[4096];
|
||||
bool isDir = false;
|
||||
|
||||
sprintf(cmd, "rsync --contimeout=10 -P \"%s::%s\" --port %d ", server.c_str(), path.c_str(), portN );
|
||||
redi::ipstream in(cmd, redi::pstreams::pstdout | redi::pstreams::pstderr);
|
||||
|
||||
while (getline(in.out(), line))
|
||||
{
|
||||
|
||||
v = explode(line, ' ', 5);
|
||||
if (v.size() == 5)
|
||||
{
|
||||
if (v[4].at(0) != '.' and (v[0].at(0) == '-' or v[0].at(0) == 'd'))
|
||||
{
|
||||
if (parent != NULL)
|
||||
{
|
||||
item = addTreeChild(parent,QString::fromStdString(v[4]), QString::fromStdString(v[1]));
|
||||
}else
|
||||
{
|
||||
item = addTreeRoot(QString::fromStdString(v[4]), QString::fromStdString(v[1]));
|
||||
}
|
||||
if (v[0].at(0) == 'd')
|
||||
{
|
||||
sprintf(npath, "%s%s/", path.c_str(), v[4].c_str());
|
||||
scanDir(server, portN, item, npath);
|
||||
isDir = true;
|
||||
}else
|
||||
{
|
||||
isDir = false;
|
||||
}
|
||||
if (parent != NULL)
|
||||
{
|
||||
item = addTreeChild(parent,QString::fromStdString(v[4]), QString::fromStdString(v[1]), isDir);
|
||||
}else
|
||||
{
|
||||
item = addTreeRoot(QString::fromStdString(v[4]), QString::fromStdString(v[1]), isDir);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if reading stdout stopped at EOF then reset the state:
|
||||
if (in.eof() && in.fail())
|
||||
in.clear();
|
||||
|
||||
// read child's stderr
|
||||
while (getline(in.err(), line))
|
||||
{
|
||||
@@ -231,6 +234,7 @@ void MainWindow::scanDir(string server, int portN, QTreeWidgetItem *parent, stri
|
||||
errorRsync.append(line);
|
||||
errorRsync.append("\n");
|
||||
}
|
||||
|
||||
if ( !errorRsync.empty())
|
||||
{
|
||||
QMessageBox::warning(
|
||||
@@ -332,26 +336,41 @@ void MainWindow::on_connectButton_clicked()
|
||||
}
|
||||
|
||||
// add a dir in treeview
|
||||
QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize)
|
||||
QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize, bool isDir)
|
||||
{
|
||||
// QTreeWidgetItem(QTreeWidget * parent, int type = Type)
|
||||
QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget);
|
||||
|
||||
// QTreeWidgetItem::setText(int column, const QString & text)
|
||||
treeItem->setText(0, name);
|
||||
treeItem->setText(1, fileSize);
|
||||
if (isDir == true)
|
||||
{
|
||||
treeItem->setText(0, "Dir");
|
||||
}else
|
||||
{
|
||||
treeItem->setText(0,"File");
|
||||
}
|
||||
treeItem->setText(1, name);
|
||||
treeItem->setText(2, fileSize);
|
||||
|
||||
return treeItem;
|
||||
}
|
||||
|
||||
// add a file in treeview
|
||||
QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name, QString fileSize)
|
||||
QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name, QString fileSize, bool isDir)
|
||||
{
|
||||
// QTreeWidgetItem(QTreeWidget * parent, int type = Type)
|
||||
QTreeWidgetItem *treeItem = new QTreeWidgetItem();
|
||||
|
||||
// QTreeWidgetItem::setText(int column, const QString & text)
|
||||
treeItem->setText(0, name);
|
||||
treeItem->setText(1, fileSize);
|
||||
if (isDir == true)
|
||||
{
|
||||
treeItem->setText(0, "Dir");
|
||||
}else
|
||||
{
|
||||
treeItem->setText(0,"File");
|
||||
}
|
||||
treeItem->setText(1, name);
|
||||
treeItem->setText(2, fileSize);
|
||||
|
||||
// QTreeWidgetItem::addChild(QTreeWidgetItem * child)
|
||||
parent->addChild(treeItem);
|
||||
@@ -364,7 +383,7 @@ void MainWindow::on_listWidget_clicked()
|
||||
vector<string> v;
|
||||
v = explode(ui->listWidget->currentItem()->text().toStdString(), '\n', 2);
|
||||
this->downloading.service = v[0];
|
||||
populateTree();
|
||||
populateTree(NULL);
|
||||
}
|
||||
|
||||
//Slot activated when a file is clicked in the treeview
|
||||
@@ -372,24 +391,40 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item)
|
||||
{
|
||||
QFuture<void> future;
|
||||
QFileDialog dialog;
|
||||
QTreeWidgetItem * itemR;
|
||||
string path;
|
||||
|
||||
item = ui->treeWidget->currentItem();
|
||||
this->downloading.path = item->text(0).toStdString();
|
||||
while(item->parent() != NULL)
|
||||
//item = ui->treeWidget->currentItem();
|
||||
itemR = item;
|
||||
|
||||
path = item->text(1).toStdString();
|
||||
while(itemR->parent() != NULL)
|
||||
{
|
||||
item = item->parent();
|
||||
this->downloading.path = item->text(0).toStdString() + "/" + this->downloading.path;
|
||||
itemR = itemR->parent();
|
||||
path = itemR->text(1).toStdString() + "/" + path;
|
||||
};
|
||||
|
||||
if (this->downloading.savePath.empty())
|
||||
if (item->text(0) == "File")
|
||||
{
|
||||
on_DefaultSaveFolder_triggered();
|
||||
}
|
||||
if (!this->downloading.savePath.empty() && this->downloading.pid == 0)
|
||||
// Item is a file
|
||||
this->downloading.path = path;
|
||||
if (this->downloading.savePath.empty())
|
||||
{
|
||||
on_DefaultSaveFolder_triggered();
|
||||
}else if (this->downloading.pid == 0)
|
||||
{
|
||||
startDownloading();
|
||||
sleep(1);
|
||||
|
||||
}
|
||||
ui->listDownload->addItem(QString::fromStdString(this->downloading.path));
|
||||
}else
|
||||
{
|
||||
startDownloading();
|
||||
//Item is a Directory
|
||||
scanDir(this->connexion.server, this->connexion.port, item, this->downloading.service + "/" + path +"/");
|
||||
item->setExpanded(true);
|
||||
}
|
||||
ui->listDownload->addItem(QString::fromStdString(this->downloading.path));
|
||||
|
||||
}
|
||||
|
||||
// Launch the thread which download the file
|
||||
@@ -459,10 +494,10 @@ void MainWindow::on_listDownload_itemClicked(QListWidgetItem *item)
|
||||
// load settings
|
||||
void MainWindow::loadSettings()
|
||||
{
|
||||
// restoring geometry and state of wondow and widgets
|
||||
// restoring geometry and state of window and widgets
|
||||
this->restoreGeometry(settings.value("window/geometry").toByteArray());
|
||||
this->restoreState(settings.value("window/state").toByteArray());
|
||||
ui->treeWidget->header()->restoreState(settings.value("treeView/state").toByteArray());
|
||||
ui->treeWidget->header()->restoreState(settings.value("treeWidget/state").toByteArray());
|
||||
ui->splitter->restoreState(settings.value("splitter/state").toByteArray());
|
||||
ui->splitter_2->restoreState(settings.value("splitter2/state").toByteArray());
|
||||
|
||||
@@ -489,7 +524,7 @@ void MainWindow::saveSettings()
|
||||
{
|
||||
this->settings.setValue("window/geometry", saveGeometry());
|
||||
this->settings.setValue("window/state", saveState());
|
||||
this->settings.setValue("treeView/state", ui->treeWidget->header()->saveState());
|
||||
this->settings.setValue("treeWidget/state", ui->treeWidget->header()->saveState());
|
||||
this->settings.setValue("splitter/state", ui->splitter->saveState());
|
||||
this->settings.setValue("splitter2/state", ui->splitter_2->saveState());
|
||||
this->settings.setValue("connexion/lastServer", QString::fromStdString(this->connexion.server));
|
||||
@@ -520,8 +555,7 @@ void MainWindow::on_DefaultSaveFolder_triggered()
|
||||
{
|
||||
QFileDialog dialog;
|
||||
|
||||
this->downloading.savePath = dialog.getExistingDirectory(this, tr("Choose directory to save file"), this->downloading.dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks).toStdString();
|
||||
// this->downloading.dirPath = this->downloading.savePath.c_str();
|
||||
this->downloading.savePath = dialog.getExistingDirectory(this, tr("Choose directory to save file"), QString::fromStdString(this->downloading.savePath), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks).toStdString();
|
||||
this->settings.setValue("Folder/", this->downloading.savePath.c_str());
|
||||
this->settings.sync();
|
||||
}
|
||||
@@ -529,7 +563,7 @@ void MainWindow::on_DefaultSaveFolder_triggered()
|
||||
// Activated when menu "settings" is clicked
|
||||
void MainWindow::on_action_Settings_triggered()
|
||||
{
|
||||
config.UnitCombobox->setCurrentText(QString::fromStdString(this->connexion.bandwidthLimitUnit));
|
||||
config.UnitCombobox->setCurrentIndex(bwUnixIndex[this->connexion.bandwidthLimitUnit[0]]);
|
||||
config.spinBox->setValue(this->connexion.bandwidthLimit);
|
||||
Configuration.show();
|
||||
}
|
||||
@@ -548,7 +582,7 @@ void MainWindow::on_buttonBox_accepted()
|
||||
}else
|
||||
{
|
||||
this->connexion.bandwidthLimit = config.spinBox->value();
|
||||
this->connexion.bandwidthLimitUnit = config.UnitCombobox->currentText().toStdString();
|
||||
this->connexion.bandwidthLimitUnit = config.UnitCombobox->currentText().toStdString()[0];
|
||||
}
|
||||
this->settings.setValue("bandwidthlimit", this->connexion.bandwidthLimit);
|
||||
this->settings.setValue("bandwidthlimitunit", this->connexion.bandwidthLimitUnit.c_str());
|
||||
|
||||
Reference in New Issue
Block a user