2023-01-07 12:44:45 +01:00
# ifndef MAINWINDOW_H
# define MAINWINDOW_H
2024-08-03 15:22:35 +02:00
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-07 12:44:45 +01:00
# include <QMainWindow>
# include <string>
# include <QTreeWidgetItem>
2023-02-22 00:48:16 +01:00
# include <QList>
2023-01-07 12:44:45 +01:00
# 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 <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-27 23:48:05 +01:00
# include <QTranslator>
# include <QInputDialog>
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
{
2024-10-18 11:31:44 +02:00
public :
2024-08-22 23:08:42 +02:00
int bandwidthLimit = 0 ;
int bandwidthLimitUnit ;
2024-09-05 18:40:00 +02:00
int contimeout = 20 ;
QString server ;
2024-10-18 22:39:09 +02:00
QString service ;
QString path ;
QString savePath ;
QString user ;
QString password ;
QProcess * process = nullptr ;
int ipversion = 4 ;
uint port = 873 ;
bool quit = false ;
void clear ( ) ;
bool paused = false ;
2023-01-12 09:23:45 +01:00
} ;
class Downloading
{
2024-10-18 11:31:44 +02:00
public :
2024-08-22 23:08:42 +02:00
QString server ;
QString service ;
2024-09-05 18:40:00 +02:00
QString path ;
QString savePath ;
2024-10-18 22:39:09 +02:00
QString user ;
QString password ;
int ipversion = 4 ;
int port = 873 ;
QProcess * process = nullptr ;
bool quit = false ;
bool paused = false ;
void clear ( ) ;
2023-01-12 09:23:45 +01:00
} ;
2023-01-15 13:26:14 +01:00
class About
{
2024-10-18 11:31:44 +02:00
public :
2024-08-22 23:08:42 +02:00
QString version ;
QString author = " Daniel TARTAVEL-JEANNOT " ;
2024-09-05 18:40:00 +02:00
QString licence = " GPL_V3 " ;
QString description ;
2024-08-03 15:22:35 +02:00
QString email = " dtux@free.fr " ;
QString git = " https://git.labolyon.fr/dtux/RsyncUI/issues " ;
2023-01-15 13:26:14 +01:00
} ;
2023-01-07 12:44:45 +01:00
class MainWindow : public QMainWindow
{
2024-08-03 15:22:35 +02:00
Q_OBJECT
2024-10-18 11:31:44 +02:00
public :
2024-08-22 23:08:42 +02:00
Ui : : MainWindow * ui ;
MainWindow ( QWidget * parent = nullptr ) ;
2024-09-05 18:40:00 +02:00
~ MainWindow ( ) ;
// passwdManager;
QProgressDialog * progress ;
Connexion connexion ;
2024-08-03 15:22:35 +02:00
Connexion downloading ;
QSettings settings ;
About about ;
QDialog Configuration ;
Ui : : Configuration config ;
QDialog aboutDialog ;
Ui : : windowAbout AboutW ;
std : : vector < QString > serversList ;
QSystemTrayIcon * trayIcon ;
QString icon = " /usr/share/icons/RsyncUI.png " ;
bool rescan = false ;
bool stopDlAsked ;
bool treeviewClicked ;
bool initialization = true ;
bool exiting = false ;
QList < QString > UnitText
{
2024-10-18 11:31:44 +02:00
tr ( " B " ) ,
tr ( " KB " ) ,
tr ( " MB " ) ,
tr ( " GB " ) ,
tr ( " TB " ) ,
tr ( " PB " )
2024-08-03 15:22:35 +02:00
} ;
QList < QChar > bwUnitChar
{
2024-10-18 11:31:44 +02:00
' K ' ,
' M ' ,
' T ' ,
' G ' ,
' P '
2024-08-03 15:22:35 +02:00
} ;
QVector < QString > downloadProcessErrorString =
{
2024-08-22 23:08:42 +02:00
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(). " )
2024-08-03 15:22:35 +02:00
} ;
void displayTree ( ) ;
void populateTree ( ) ;
void populateList ( QString server , uint port ) ;
void listServices ( ) ;
uint validateServer ( QString server ) ;
void addTreeItem ( QString name , QString fileSize , QString fullsize , QString type , QString date , bool isDir , QString dirName , QTreeWidgetItem * parent ) ;
bool scanDir ( Connexion * connexion , QTreeWidgetItem * parent = NULL , QString path = " " ) ;
void startDownloading ( ) ;
void loadSettings ( ) ;
void saveSettings ( ) ;
void closeEvent ( QCloseEvent * event ) ;
void saveDownloadList ( ) ;
void loadDownloadList ( ) ;
void deleteDownloadList ( ) ;
void download ( ) ;
void initSystemTrayIcon ( ) ;
void hideWindow ( ) ;
void showWindow ( ) ;
void init ( ) ;
bool getUserPassword ( Connexion * ) ;
void preparePopulateTree ( ) ;
bool testServerPresence ( QString , bool = false ) ;
void passwordStore ( QString account , QString password ) ;
QString passwordGet ( QString account ) ;
2024-10-18 11:31:44 +02:00
private slots :
2024-08-03 15:22:35 +02:00
void on_listWidget_clicked ( ) ;
void on_treeWidget_itemClicked ( QTreeWidgetItem * item , bool downloadDir = false ) ;
void downloadFinished ( int exitCode , QProcess : : ExitStatus exitStatus ) ;
void readRsyncOutput ( ) ;
void stoppingDownload ( ) ;
void on_listDownload_itemClicked ( QListWidgetItem * item ) ;
void on_actionAbout_triggered ( ) ;
void on_actionAbout_Qt_triggered ( ) ;
bool on_DefaultSaveFolder_triggered ( ) ;
void on_connectButton_clicked ( ) ;
void on_action_Settings_triggered ( ) ;
void on_actionDownload_triggered ( ) ;
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 ( ) ;
2023-02-12 00:37:50 +01:00
2024-08-03 15:22:35 +02:00
void setDlSpeed ( QString speed ) ;
2023-02-12 00:37:50 +01:00
2024-08-03 15:22:35 +02:00
void on_actionHiddenService_triggered ( ) ;
2023-02-12 00:37:50 +01:00
2024-08-03 15:22:35 +02:00
//void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
2023-02-22 00:48:16 +01:00
2024-10-18 11:31:44 +02:00
void on_treeWidget_itemDoubleClicked ( QTreeWidgetItem * item , int column ) ;
void on_treeWidget_doubleClicked ( const QModelIndex & index ) ;
2024-10-18 22:39:09 +02:00
void on_actionPause_downloads_triggered ( ) ;
2024-10-18 11:31:44 +02:00
signals :
2024-08-03 15:22:35 +02:00
void stopDownloading ( QProcess * ) ;
void progressSignal ( int ) ;
void speed ( QString ) ;
void finishedSignal ( bool = true ) ;
void fileName ( QString ) ;
void passwordReady ( ) ;
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