rsyncui/mainwindow.h
2023-03-01 14:25:31 +01:00

227 lines
6.1 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 "ui_about.h"
#include "ui_login.h"
#include "downloadfile.h"
#include "tools.h"
#include <QMainWindow>
#include <string>
#include <QTreeWidgetItem>
#include <QList>
#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>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QTranslator>
#include <QInputDialog>
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;
QString user;
QString password;
int port = 873;
bool comboboxChanged;
};
class Downloading
{
public:
QString server;
QString service;
QString path;
QString savePath;
QString user;
QString password;
int port = 873;
QProcess * process = nullptr;
bool quit = false;
void clear();
};
class About
{
public:
QString title = "RsyncUI";
QString version = "2.6";
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;
QSettings settings;
About about;
QDialog Configuration;
Ui::Configuration config;
QDialog aboutDialog;
Ui::windowAbout AboutW;
QDialog loginDialog;
Ui::LoginDialog loginD;
std::vector <QString> serversList;
QSystemTrayIcon * trayIcon;
QString icon = "/usr/share/icons/RsyncUI.png";
bool rescan = false;
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);
bool 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();
void initSystemTrayIcon();
void hideWindow();
void showWindow();
void init();
bool getUserPassword(bool);
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 *);
void on_trayIcon_clicked(QSystemTrayIcon::ActivationReason reason);
void quitApp();
void on_actionExit_triggered();
void setDlSpeed(QString speed);
void on_loginBox_accepted();
signals:
void stopDownloading(QProcess *);
void progressSignal(int);
void speed(QString);
void finishedSignal(bool = true);
void fileName(QString);
//void errorSignal(QString);
};
#endif // MAINWINDOW_H