From 927c4a932ad47c271a97bc5b0059cd20e98c63dd Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Sat, 4 Mar 2023 17:33:18 +0100 Subject: [PATCH] some code cleaning\nSize in treeview is now hulan readable\nbegin of password encryption --- RsyncUI.pro | 2 + RsyncUI.pro.user | 2 +- mainwindow.cpp | 100 ++++++++++++++++++++++++++++++++++------------- mainwindow.h | 21 +++++----- mainwindow.ui | 6 ++- password.cpp | 22 +++++++++++ password.h | 21 ++++++++++ 7 files changed, 135 insertions(+), 39 deletions(-) create mode 100644 password.cpp create mode 100644 password.h diff --git a/RsyncUI.pro b/RsyncUI.pro index ac30c58..9eb187b 100644 --- a/RsyncUI.pro +++ b/RsyncUI.pro @@ -19,11 +19,13 @@ SOURCES += \ downloadfile.cpp \ main.cpp \ mainwindow.cpp \ + password.cpp \ tools.cpp HEADERS += \ downloadfile.h \ mainwindow.h \ + password.h \ tools.h FORMS += \ diff --git a/RsyncUI.pro.user b/RsyncUI.pro.user index 0b24d62..9024951 100644 --- a/RsyncUI.pro.user +++ b/RsyncUI.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/mainwindow.cpp b/mainwindow.cpp index aace122..90d87ed 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -65,8 +65,6 @@ MainWindow::MainWindow(QWidget *parent) // connectors connect(this, &MainWindow::fileName, ui->progressBar, &QProgressBar::setFormat); connect(this, &MainWindow::progressSignal, ui->progressBar, &QProgressBar::setValue); - //connect(this, &MainWindow::speed, ui->progressBar, &MainWindow::setDlSpeed); - //connect(this, &MainWindow::errorSignal, this, &MainWindow::downloadingErrorSlot); connect(this, &MainWindow::stopDownloading, this, &MainWindow::cancelled); connect(config.buttonBox, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted())); connect(config.comboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &MainWindow::on_comboBox_currentIndexChanged); @@ -75,8 +73,7 @@ MainWindow::MainWindow(QWidget *parent) // init of widgets ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget); // attach search widget to treewidget ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive); // and set it case insensitive - ui->treeWidget->setHeaderLabels({tr("Path"), tr("Type"), tr("Size")} ); // set header of columns of tree widget - + ui->treeWidget->setHeaderLabels({tr("Path"), tr("Type"), tr("Size"), "fullSize"} ); // set header of columns of tree widget // setting arrowcursor for treeWidget, listWidget and listDownload to arrow ui->treeWidget->setCursor(Qt::ArrowCursor); @@ -104,7 +101,10 @@ MainWindow::MainWindow(QWidget *parent) config.comboBox->setCurrentIndex(ui->toolBar->toolButtonStyle()); // setting combobox to saved settings //setting unit of bandwidth limit - config.UnitCombobox->addItems({tr("KB"), tr("MB"), tr("GB"), tr("TB"), tr("PB")}); + config.UnitCombobox->addItems({tr("KB/s"), tr("MB/s"), tr("GB/s"), tr("TB/s"), tr("PB/s")}); + + // hide fullsize column of treeview + ui->treeWidget->setColumnHidden(3, true); initSystemTrayIcon(); } @@ -275,7 +275,7 @@ void MainWindow::closeEvent (QCloseEvent *event) } // Populate treeview with list of files -void MainWindow::populateTree(QTreeWidgetItem * parent) +void MainWindow::populateTree() { QString path; @@ -291,7 +291,7 @@ void MainWindow::populateTree(QTreeWidgetItem * parent) { // server is validated, scanning directory path = this->connexion.service + "/"; - scanDir(this->connexion.server, this->connexion.port, parent, path); + scanDir(this->connexion.server, this->connexion.port, nullptr, path); } // Restoring cursor QGuiApplication::restoreOverrideCursor(); @@ -415,9 +415,12 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt { QString cmd; QStringList param; + QStringList sizeA; QString line; QString size; + QString fullsize; QString filename; + QString fileType; QProcess * myProcess; bool isDir = false; bool flag = false; @@ -464,10 +467,24 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt flag = true; break; } - // extracting name, size and is dir/file + // extracting name, size and if is dir/file line = line.simplified(); size = line.section(" ", 1, 1); - filename = line.section(" ", 4); + fullsize = size; + fullsize.remove(","); + sizeA = size.split(','); + if (sizeA.at(0) == "4") + { + cout << "test" << endl; + } + if (sizeA.count() <= 1) + { + size = sizeA.at(0) + UnitText[0]; + }else + { + size = sizeA.at(0) + "," + sizeA.at(1).left(2) + UnitText[sizeA.count()-1]; + } + filename = line.section(" ", 4); if (filename != '.') { if (line[0] == "d") @@ -477,15 +494,7 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt { isDir = false; } - if (parent != NULL) - { - //adding item to tree - addTreeChild(parent, filename, size, isDir); - }else - { - //adding item to tree (as directory) - addTreeRoot(filename, size, isDir); - } + addTreeItem(filename, size, fullsize, fileType, isDir, parent); } } flag = false; @@ -604,8 +613,40 @@ void MainWindow::on_connectButton_clicked() populateList(); } -// add a dir in treeview -QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize, bool isDir) +// add parent in treeview +void MainWindow::addTreeItem(QString name, QString fileSize, QString fullsize, QString type, bool isDir=false, QTreeWidgetItem *parent=nullptr) +{ + QTreeWidgetItem *treeItem; + if (parent != nullptr) + { + treeItem = new QTreeWidgetItem(); + }else + { + treeItem = new QTreeWidgetItem(ui->treeWidget); + } + if (isDir == true) + { + // item is a dir + treeItem->setText(1, tr("Dir")); + treeItem->setIcon(0, QIcon::fromTheme("folder")); + }else + { + // item is a file + treeItem->setText(1,tr("File")); + } + treeItem->setText(0, name); + treeItem->setText(2, fileSize); + treeItem->setText(3, fullsize); + treeItem->setTextAlignment(2, Qt::AlignRight); + + if (parent != nullptr) + { + // QTreeWidgetItem::addChild(QTreeWidgetItem * child) + parent->addChild(treeItem); + } +} +/*// add parent in treeview +QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize, QString fullsize, bool isDir) { QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget); @@ -618,18 +659,19 @@ QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize, bool i { // item is a file treeItem->setText(1,tr("File")); - //treeItem->setIcon(0, QIcon::fromTheme("document")); } treeItem->setText(0, name); treeItem->setText(2, fileSize); + treeItem->setText(3, fullsize); + treeItem->setTextAlignment(2, Qt::AlignRight); return treeItem; } -// add a file in treeview -QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name, QString fileSize, bool isDir) +// add child in treeview +QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name, QString fileSize, QString fullsize, bool isDir) { - QTreeWidgetItem *treeItem = new QTreeWidgetItem(); + QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget); if (isDir == true) { @@ -643,11 +685,13 @@ QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name } treeItem->setText(0, name); treeItem->setText(2, fileSize); + treeItem->setText(3, fullsize); + treeItem->setTextAlignment(2, Qt::AlignRight); // QTreeWidgetItem::addChild(QTreeWidgetItem * child) parent->addChild(treeItem); return treeItem; -} +}*/ // Slot activated when a service in the list is clicked void MainWindow::on_listWidget_clicked() @@ -680,7 +724,7 @@ void MainWindow::preparePopulateTree() this->connexion.password = this->settings.value(logins[0]).toString(); } this->settings.endGroup(); - populateTree(NULL); + populateTree(); } // get password and user login @@ -730,7 +774,7 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD // assembling path from treewidget path = item->text(0); - sizeFromRsync = item->text(2).remove(',').toUInt(); + sizeFromRsync = item->text(3).toUInt(); while(itemR->parent() != NULL) { @@ -1221,7 +1265,7 @@ void MainWindow::on_loginBox_accepted() if (this->rescan == true) { this->rescan = false; - populateTree(NULL); + populateTree(); } } } diff --git a/mainwindow.h b/mainwindow.h index 181030a..00e6352 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -117,12 +117,13 @@ class MainWindow : public QMainWindow QString icon = "/usr/share/icons/RsyncUI.png"; bool rescan = false; - QList bwUnitText { - "KB", - "MB", - "TB", - "GB", - "PB" + QList UnitText { + tr("B"), + tr("KB"), + tr("MB"), + tr("GB"), + tr("TB"), + tr("PB") }; QList bwUnitChar{ 'K', @@ -143,13 +144,15 @@ class MainWindow : public QMainWindow }; void displayTree(); - void populateTree(QTreeWidgetItem * parent); + void populateTree(); void populateList(); void listServices(); bool validateServer(QString server); bool isIpAddress(QString server); - QTreeWidgetItem * addTreeRoot(QString name, QString description, bool isDir); - QTreeWidgetItem * addTreeChild(QTreeWidgetItem *parent, QString name, QString size, bool isDir); + void addTreeItem(QString name, QString fileSize, QString fullsize, QString type, bool isDir, QTreeWidgetItem *parent); + + //QTreeWidgetItem * addTreeRoot(QString name, QString size, QString fullsize, bool isDir); + //QTreeWidgetItem * addTreeChild(QTreeWidgetItem *parent, QString name, QString size, QString fullsize, bool isDir); bool scanDir(QString server, int portN, QTreeWidgetItem *parent = NULL, QString path = "" ); void startDownloading(); void loadSettings(); diff --git a/mainwindow.ui b/mainwindow.ui index dbeed37..eac930b 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -325,6 +325,9 @@ Qt::ImhNoAutoUppercase + + Filter... + @@ -469,7 +472,8 @@ - + + .. hidden service diff --git a/password.cpp b/password.cpp new file mode 100644 index 0000000..efd4b39 --- /dev/null +++ b/password.cpp @@ -0,0 +1,22 @@ +#include "password.h" +#include +#include + +/*password::password("RsyncUI") +{ + +}*/ + +void password::store (QString account, QString password) +{ +} + +QString password::read(QString) +{ + +} + +bool password::remove(QString) +{ + +} diff --git a/password.h b/password.h new file mode 100644 index 0000000..b1b6ed6 --- /dev/null +++ b/password.h @@ -0,0 +1,21 @@ +#ifndef PASSWORD_H +#define PASSWORD_H + +#include "mainwindow.h" +#include +#include + +class password +{ + password(QString); + + ~password(); + + void store(QString, QString); + + QString read(QString); + + bool remove(QString); +}; + +#endif // PASSWORD_H