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 \ downloadfile.cpp \
main.cpp \ main.cpp \
mainwindow.cpp \ mainwindow.cpp \
password.cpp \
tools.cpp tools.cpp
HEADERS += \ HEADERS += \
downloadfile.h \ downloadfile.h \
mainwindow.h \ mainwindow.h \
password.h \
tools.h tools.h
FORMS += \ FORMS += \

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -65,8 +65,6 @@ MainWindow::MainWindow(QWidget *parent)
// connectors // connectors
connect(this, &MainWindow::fileName, ui->progressBar, &QProgressBar::setFormat); connect(this, &MainWindow::fileName, ui->progressBar, &QProgressBar::setFormat);
connect(this, &MainWindow::progressSignal, ui->progressBar, &QProgressBar::setValue); 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(this, &MainWindow::stopDownloading, this, &MainWindow::cancelled);
connect(config.buttonBox, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted())); connect(config.buttonBox, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted()));
connect(config.comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::on_comboBox_currentIndexChanged); connect(config.comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::on_comboBox_currentIndexChanged);
@ -75,8 +73,7 @@ MainWindow::MainWindow(QWidget *parent)
// init of widgets // init of widgets
ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget); // attach search widget to treewidget ui->ktreewidgetsearchline->setTreeWidget(ui->treeWidget); // attach search widget to treewidget
ui->ktreewidgetsearchline->setCaseSensitivity(Qt::CaseInsensitive); // and set it case insensitive 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 // setting arrowcursor for treeWidget, listWidget and listDownload to arrow
ui->treeWidget->setCursor(Qt::ArrowCursor); ui->treeWidget->setCursor(Qt::ArrowCursor);
@ -104,7 +101,10 @@ MainWindow::MainWindow(QWidget *parent)
config.comboBox->setCurrentIndex(ui->toolBar->toolButtonStyle()); // setting combobox to saved settings config.comboBox->setCurrentIndex(ui->toolBar->toolButtonStyle()); // setting combobox to saved settings
//setting unit of bandwidth limit //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(); initSystemTrayIcon();
} }
@ -275,7 +275,7 @@ void MainWindow::closeEvent (QCloseEvent *event)
} }
// Populate treeview with list of files // Populate treeview with list of files
void MainWindow::populateTree(QTreeWidgetItem * parent) void MainWindow::populateTree()
{ {
QString path; QString path;
@ -291,7 +291,7 @@ void MainWindow::populateTree(QTreeWidgetItem * parent)
{ {
// server is validated, scanning directory // server is validated, scanning directory
path = this->connexion.service + "/"; path = this->connexion.service + "/";
scanDir(this->connexion.server, this->connexion.port, parent, path); scanDir(this->connexion.server, this->connexion.port, nullptr, path);
} }
// Restoring cursor // Restoring cursor
QGuiApplication::restoreOverrideCursor(); QGuiApplication::restoreOverrideCursor();
@ -415,9 +415,12 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
{ {
QString cmd; QString cmd;
QStringList param; QStringList param;
QStringList sizeA;
QString line; QString line;
QString size; QString size;
QString fullsize;
QString filename; QString filename;
QString fileType;
QProcess * myProcess; QProcess * myProcess;
bool isDir = false; bool isDir = false;
bool flag = false; bool flag = false;
@ -464,10 +467,24 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
flag = true; flag = true;
break; break;
} }
// extracting name, size and is dir/file // extracting name, size and if is dir/file
line = line.simplified(); line = line.simplified();
size = line.section(" ", 1, 1); 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 (filename != '.')
{ {
if (line[0] == "d") if (line[0] == "d")
@ -477,15 +494,7 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
{ {
isDir = false; isDir = false;
} }
if (parent != NULL) addTreeItem(filename, size, fullsize, fileType, isDir, parent);
{
//adding item to tree
addTreeChild(parent, filename, size, isDir);
}else
{
//adding item to tree (as directory)
addTreeRoot(filename, size, isDir);
}
} }
} }
flag = false; flag = false;
@ -604,8 +613,40 @@ void MainWindow::on_connectButton_clicked()
populateList(); populateList();
} }
// add a dir in treeview // add parent in treeview
QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize, bool isDir) 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); QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget);
@ -618,18 +659,19 @@ QTreeWidgetItem * MainWindow::addTreeRoot(QString name, QString fileSize, bool i
{ {
// item is a file // item is a file
treeItem->setText(1,tr("File")); treeItem->setText(1,tr("File"));
//treeItem->setIcon(0, QIcon::fromTheme("document"));
} }
treeItem->setText(0, name); treeItem->setText(0, name);
treeItem->setText(2, fileSize); treeItem->setText(2, fileSize);
treeItem->setText(3, fullsize);
treeItem->setTextAlignment(2, Qt::AlignRight);
return treeItem; return treeItem;
} }
// add a file in treeview // add child in treeview
QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name, QString fileSize, bool isDir) 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) if (isDir == true)
{ {
@ -643,11 +685,13 @@ QTreeWidgetItem * MainWindow::addTreeChild(QTreeWidgetItem *parent, QString name
} }
treeItem->setText(0, name); treeItem->setText(0, name);
treeItem->setText(2, fileSize); treeItem->setText(2, fileSize);
treeItem->setText(3, fullsize);
treeItem->setTextAlignment(2, Qt::AlignRight);
// QTreeWidgetItem::addChild(QTreeWidgetItem * child) // QTreeWidgetItem::addChild(QTreeWidgetItem * child)
parent->addChild(treeItem); parent->addChild(treeItem);
return treeItem; return treeItem;
} }*/
// Slot activated when a service in the list is clicked // Slot activated when a service in the list is clicked
void MainWindow::on_listWidget_clicked() void MainWindow::on_listWidget_clicked()
@ -680,7 +724,7 @@ void MainWindow::preparePopulateTree()
this->connexion.password = this->settings.value(logins[0]).toString(); this->connexion.password = this->settings.value(logins[0]).toString();
} }
this->settings.endGroup(); this->settings.endGroup();
populateTree(NULL); populateTree();
} }
// get password and user login // get password and user login
@ -730,7 +774,7 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadD
// assembling path from treewidget // assembling path from treewidget
path = item->text(0); path = item->text(0);
sizeFromRsync = item->text(2).remove(',').toUInt(); sizeFromRsync = item->text(3).toUInt();
while(itemR->parent() != NULL) while(itemR->parent() != NULL)
{ {
@ -1221,7 +1265,7 @@ void MainWindow::on_loginBox_accepted()
if (this->rescan == true) if (this->rescan == true)
{ {
this->rescan = false; this->rescan = false;
populateTree(NULL); populateTree();
} }
} }
} }

View File

@ -117,12 +117,13 @@ class MainWindow : public QMainWindow
QString icon = "/usr/share/icons/RsyncUI.png"; QString icon = "/usr/share/icons/RsyncUI.png";
bool rescan = false; bool rescan = false;
QList<QString> bwUnitText { QList<QString> UnitText {
"KB", tr("B"),
"MB", tr("KB"),
"TB", tr("MB"),
"GB", tr("GB"),
"PB" tr("TB"),
tr("PB")
}; };
QList<QChar> bwUnitChar{ QList<QChar> bwUnitChar{
'K', 'K',
@ -143,13 +144,15 @@ class MainWindow : public QMainWindow
}; };
void displayTree(); void displayTree();
void populateTree(QTreeWidgetItem * parent); void populateTree();
void populateList(); void populateList();
void listServices(); void listServices();
bool validateServer(QString server); bool validateServer(QString server);
bool isIpAddress(QString server); bool isIpAddress(QString server);
QTreeWidgetItem * addTreeRoot(QString name, QString description, bool isDir); void addTreeItem(QString name, QString fileSize, QString fullsize, QString type, bool isDir, QTreeWidgetItem *parent);
QTreeWidgetItem * addTreeChild(QTreeWidgetItem *parent, QString name, QString size, bool isDir);
//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 = "" ); bool scanDir(QString server, int portN, QTreeWidgetItem *parent = NULL, QString path = "" );
void startDownloading(); void startDownloading();
void loadSettings(); void loadSettings();

View File

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