2023-01-07 12:44:45 +01:00
# ifndef MAINWINDOW_H
# define MAINWINDOW_H
2023-02-02 16:10:51 +01:00
# define QT_USE_FAST_CONCATENATION
# define QT_USE_FAST_OPERATOR_PLUS
2023-01-22 14:33:23 +01:00
# include "ui_mainwindow.h"
# include "ui_configuration.h"
2023-02-13 16:54:56 +01:00
# include "ui_about.h"
2023-01-22 14:33:23 +01:00
# include "downloadfile.h"
2023-01-18 23:12:21 +01:00
# include "tools.h"
2023-01-07 12:44:45 +01:00
# include <QMainWindow>
# include <string>
# include <QTreeWidgetItem>
# include <QListWidgetItem>
# include <QProgressDialog>
2023-01-12 09:23:45 +01:00
# include <QSettings>
2023-01-15 13:26:14 +01:00
# include <vector>
2023-01-22 14:33:23 +01:00
# 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>
2023-01-26 11:31:56 +01:00
# include <magic.h>
2023-01-27 18:14:50 +01:00
# include <QComboBox>
2023-02-02 16:10:51 +01:00
# include <QStringBuilder>
# include <pwd.h>
2023-02-10 21:32:20 +01:00
# include <QProcess>
# include <QToolBar>
# include <QDir>
2023-02-12 00:37:50 +01:00
# include <QSystemTrayIcon>
# include <QMenu>
2023-02-12 17:50:13 +01:00
# include <QTranslator>
2023-01-07 12:44:45 +01:00
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow ; }
QT_END_NAMESPACE
2023-02-10 21:32:20 +01:00
extern QMap < int , QString > rsyncErrorStrings ;
2023-01-12 09:23:45 +01:00
class Connexion
{
public :
2023-01-22 14:33:23 +01:00
int bandwidthLimit = 0 ;
2023-02-10 21:32:20 +01:00
int bandwidthLimitUnit ;
QString server ;
QString service ;
2023-01-12 09:23:45 +01:00
int port = 873 ;
2023-02-10 21:32:20 +01:00
bool comboboxChanged ;
2023-01-12 09:23:45 +01:00
} ;
class Downloading
{
public :
2023-02-10 21:32:20 +01:00
QString server ;
QString service ;
QString path ;
QString savePath ;
QProcess * process = nullptr ;
2023-02-15 13:48:38 +01:00
bool quit = false ;
2023-02-02 16:10:51 +01:00
void clear ( ) ;
2023-01-12 09:23:45 +01:00
} ;
2023-01-15 13:26:14 +01:00
class About
{
public :
QString title = " RsyncUI " ;
2023-02-15 13:48:38 +01:00
QString version = " 2.4 " ;
2023-01-15 13:26:14 +01:00
QString author = " Daniel TARTAVEL-JEANNOT " ;
QString licence = " GPL_V3 " ;
2023-01-26 12:02:12 +01:00
QString description ;
2023-01-15 13:26:14 +01:00
QString email = " dtux@free.fr " ;
QString git = " https://git.labolyon.fr/dtux/RsyncUI/issues " ;
} ;
2023-01-07 12:44:45 +01:00
class MainWindow : public QMainWindow
{
Q_OBJECT
2023-01-12 09:23:45 +01:00
public :
Ui : : MainWindow * ui ;
MainWindow ( QWidget * parent = nullptr ) ;
~ MainWindow ( ) ;
QProgressDialog * progress ;
Connexion connexion ;
Downloading downloading ;
2023-02-10 21:32:20 +01:00
//downloadFile downloadO;
2023-01-12 09:23:45 +01:00
QSettings settings ;
2023-01-15 13:26:14 +01:00
About about ;
2023-01-22 14:33:23 +01:00
QDialog Configuration ;
Ui : : Configuration config ;
2023-02-13 16:54:56 +01:00
QDialog aboutDialog ;
Ui : : windowAbout AboutW ;
2023-01-15 13:26:14 +01:00
std : : vector < QString > serversList ;
2023-02-12 00:37:50 +01:00
QSystemTrayIcon * trayIcon ;
2023-02-10 21:32:20 +01:00
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(). " )
2023-01-26 11:31:56 +01:00
} ;
2023-01-12 09:23:45 +01:00
2023-02-02 16:10:51 +01:00
void displayTree ( ) ;
void populateTree ( QTreeWidgetItem * parent ) ;
void populateList ( ) ;
void listServices ( ) ;
2023-02-10 21:32:20 +01:00
bool validateServer ( QString server ) ;
bool isIpAddress ( QString server ) ;
2023-02-02 16:10:51 +01:00
QTreeWidgetItem * addTreeRoot ( QString name , QString description , bool isDir ) ;
QTreeWidgetItem * addTreeChild ( QTreeWidgetItem * parent , QString name , QString size , bool isDir ) ;
2023-02-10 21:32:20 +01:00
void scanDir ( QString server , int portN , QTreeWidgetItem * parent = NULL , QString path = " " ) ;
2023-02-02 16:10:51 +01:00
void startDownloading ( ) ;
void loadSettings ( ) ;
void saveSettings ( ) ;
void closeEvent ( QCloseEvent * event ) ;
void saveDownloadList ( ) ;
void loadDownloadList ( ) ;
2023-02-10 21:32:20 +01:00
void download ( ) ;
2023-02-12 00:37:50 +01:00
void initSystemTrayIcon ( ) ;
void hideWindow ( ) ;
void showWindow ( ) ;
2023-02-15 13:48:38 +01:00
void init ( ) ;
2023-02-02 16:10:51 +01:00
2023-01-12 09:23:45 +01:00
private slots :
2023-01-07 12:44:45 +01:00
2023-01-18 23:12:21 +01:00
void on_listWidget_clicked ( ) ;
2023-01-07 12:44:45 +01:00
2023-02-02 17:14:04 +01:00
void on_treeWidget_itemClicked ( QTreeWidgetItem * item , bool downloadDir = false ) ;
2023-01-07 12:44:45 +01:00
2023-02-10 21:32:20 +01:00
void downloadFinished ( int exitCode , QProcess : : ExitStatus exitStatus ) ;
// void downloadProcessError(QProcess::ProcessError error);
void downloadProcessStderr ( ) ;
void readRsyncOutput ( ) ;
2023-01-07 12:44:45 +01:00
2023-01-12 09:23:45 +01:00
void stoppingDownload ( ) ;
2023-01-07 12:44:45 +01:00
2023-01-12 09:23:45 +01:00
void on_listDownload_itemClicked ( QListWidgetItem * item ) ;
2023-01-07 12:44:45 +01:00
2023-01-15 13:26:14 +01:00
void on_actionAbout_triggered ( ) ;
void on_actionAbout_Qt_triggered ( ) ;
2023-01-18 23:12:21 +01:00
void on_khistorycombobox_currentIndexChanged ( int ) ;
2023-01-15 13:26:14 +01:00
2023-02-02 16:10:51 +01:00
bool on_DefaultSaveFolder_triggered ( ) ;
2023-01-15 15:25:22 +01:00
2023-01-18 23:12:21 +01:00
void on_connectButton_clicked ( ) ;
2023-01-22 14:33:23 +01:00
void on_action_Settings_triggered ( ) ;
2023-01-07 12:44:45 +01:00
2023-02-02 17:14:04 +01:00
void on_actionDownload_triggered ( ) ;
2023-02-10 21:32:20 +01:00
//void downloadingErrorSlot(QString);
void on_comboBox_currentIndexChanged ( int index ) ;
2023-01-22 14:33:23 +01:00
void on_buttonBox_accepted ( ) ;
2023-01-12 09:23:45 +01:00
2023-02-10 21:32:20 +01:00
void cancelled ( QProcess * ) ;
2023-02-12 00:37:50 +01:00
void on_trayIcon_clicked ( QSystemTrayIcon : : ActivationReason reason ) ;
void quitApp ( ) ;
void on_actionExit_triggered ( ) ;
signals :
2023-02-10 21:32:20 +01:00
void stopDownloading ( QProcess * ) ;
void progressSignal ( int ) ;
void finishedSignal ( bool = true ) ;
2023-02-15 13:48:38 +01:00
void fileName ( QString ) ;
2023-02-10 21:32:20 +01:00
//void errorSignal(QString);
2023-01-22 14:33:23 +01:00
} ;
2023-01-12 09:23:45 +01:00
2023-01-07 12:44:45 +01:00
# endif // MAINWINDOW_H