some code cleaning\nSize in treeview is now hulan readable\nbegin of password encryption

This commit is contained in:
Daniel Tartavel 2023-03-04 17:33:18 +01:00
parent 8227c76a88
commit 927c4a932a
7 changed files with 135 additions and 39 deletions

View File

@ -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 += \

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.14.2, 2023-03-02T17:04:47. -->
<!-- Written by QtCreator 4.14.2, 2023-03-04T10:53:02. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -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<int>::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();
}
}
}

View File

@ -117,12 +117,13 @@ class MainWindow : public QMainWindow
QString icon = "/usr/share/icons/RsyncUI.png";
bool rescan = false;
QList<QString> bwUnitText {
"KB",
"MB",
"TB",
"GB",
"PB"
QList<QString> UnitText {
tr("B"),
tr("KB"),
tr("MB"),
tr("GB"),
tr("TB"),
tr("PB")
};
QList<QChar> 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();

View File

@ -325,6 +325,9 @@
<property name="inputMethodHints">
<set>Qt::ImhNoAutoUppercase</set>
</property>
<property name="placeholderText">
<string>Filter...</string>
</property>
</widget>
</item>
</layout>
@ -469,7 +472,8 @@
</action>
<action name="actionHiddenService">
<property name="icon">
<iconset theme="folder-open"/>
<iconset theme="folder-open">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>hidden service</string>

22
password.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "password.h"
#include <qt5keychain/keychain.h>
#include <qt5keychain/qkeychain_export.h>
/*password::password("RsyncUI")
{
}*/
void password::store (QString account, QString password)
{
}
QString password::read(QString)
{
}
bool password::remove(QString)
{
}

21
password.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef PASSWORD_H
#define PASSWORD_H
#include "mainwindow.h"
#include <qt5keychain/keychain.h>
#include <qt5keychain/qkeychain_export.h>
class password
{
password(QString);
~password();
void store(QString, QString);
QString read(QString);
bool remove(QString);
};
#endif // PASSWORD_H