rsyncui/mainwindow.h

192 lines
5.2 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#define QT_USE_FAST_CONCATENATION
#define QT_USE_FAST_OPERATOR_PLUS
#include "ui_mainwindow.h"
#include "ui_configuration.h"
#include "downloadfile.h"
#include "tools.h"
#include <QMainWindow>
#include <string>
#include <QTreeWidgetItem>
#include <QListWidgetItem>
#include <QProgressDialog>
#include <QSettings>
#include <vector>
#include <iostream>
#include <KTreeWidgetSearchLineWidget>
#include <pstreams/pstream.h>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <cstdio>
#include <QMessageBox>
#include <boost/algorithm/string/replace.hpp>
#include <QFuture>
#include <qtconcurrentrun.h>
#include <QFileDialog>
#include <QThread>
#include <QProgressDialog>
#include <sys/wait.h>
#include <QGuiApplication>
#include <QShortcut>
#include <QCloseEvent>
#include <unistd.h>
#include <magic.h>
#include <QComboBox>
#include <QStringBuilder>
#include <pwd.h>
#include <QProcess>
#include <QToolBar>
#include <QDir>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
extern QMap<int, QString> rsyncErrorStrings;
class Connexion
{
public:
int bandwidthLimit = 0;
int bandwidthLimitUnit;
QString server;
QString service;
int port = 873;
bool comboboxChanged;
};
class Downloading
{
public:
QString server;
QString service;
QString path;
QString savePath;
QProcess * process = nullptr;
void clear();
};
class About
{
public:
QString title = "RsyncUI";
QString version = "1.9.2";
QString author = "Daniel TARTAVEL-JEANNOT";
QString licence = "GPL_V3";
QString description;
QString email = "dtux@free.fr";
QString git = "https://git.labolyon.fr/dtux/RsyncUI/issues";
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
Ui::MainWindow *ui;
MainWindow(QWidget *parent = nullptr);
~MainWindow();
QProgressDialog *progress;
Connexion connexion;
Downloading downloading;
//downloadFile downloadO;
QSettings settings;
About about;
QDialog Configuration;
Ui::Configuration config;
std::vector <QString> serversList;
QList<QString> bwUnitText {
"KB",
"MB",
"TB",
"GB",
"PB"
};
QList<QChar> bwUnitChar{
'K',
'M',
'T',
'G',
'P'
};
QVector<QString> downloadProcessErrorString =
{
tr("The process failed to start. Either the invoked program is missing, or you may have insufficient permissions or resources to invoke the program."),
tr("The process crashed some time after starting successfully."),
tr("The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again."),
tr("An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel."),
tr("An error occurred when attempting to read from the process. For example, the process may not be running."),
tr("An unknown error occurred. This is the default return value of error().")
};
void displayTree();
void populateTree(QTreeWidgetItem * parent);
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 scanDir(QString server, int portN, QTreeWidgetItem *parent = NULL, QString path = "" );
void startDownloading();
void loadSettings();
void saveSettings();
void closeEvent (QCloseEvent *event);
void saveDownloadList();
void loadDownloadList();
void download();
private slots:
void on_listWidget_clicked();
void on_treeWidget_itemClicked(QTreeWidgetItem *item, bool downloadDir = false);
void downloadFinished(int exitCode, QProcess::ExitStatus exitStatus);
// void downloadProcessError(QProcess::ProcessError error);
void downloadProcessStderr();
void readRsyncOutput();
void stoppingDownload();
void on_listDownload_itemClicked(QListWidgetItem *item);
void on_actionAbout_triggered();
void on_actionAbout_Qt_triggered();
void on_khistorycombobox_currentIndexChanged(int);
bool on_DefaultSaveFolder_triggered();
void on_connectButton_clicked();
void on_action_Settings_triggered();
void on_actionDownload_triggered();
//void downloadingErrorSlot(QString);
void on_comboBox_currentIndexChanged(int index);
void on_buttonBox_accepted();
void cancelled(QProcess *);
signals:
void stopDownloading(QProcess *);
void progressSignal(int);
void finishedSignal(bool = true);
//void errorSignal(QString);
};
#endif // MAINWINDOW_H