1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
| // BIBLIOTHEQUES //////////////////////////////////////////////////////////////
#include <QApplication>
#include <QDirIterator>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QProgressBar>
#include <QFile>
#include <QString>
#include <QFileDialog>
#include <QObject>
#include <QStringList>
#include <windows.h>
#include "fenetre.h"
// CONSTANTES //////////////////////////////////////////////////////////////////
#define WIDTH 75
#define SPACE 20
// PROTOTYPES //////////////////////////////////////////////////////////////////
qint64 QtCopy( int X, int Y, qint64 Progress, QString QCopySize, char *SrcPath, char *TarPath, QLabel *PrintFileNumbers, QLabel *PrintSrcPath, QLabel *PrintTarPath, QLabel *PrintFileSize, QLabel *PrintFileName, QLabel *PrintSizes);
qint64 FolderSize(char *path);
// CLASSE FENETRE //////////////////////////////////////////////////////////////
MaFenetre::MaFenetre() : QWidget()
{
int X = (int)(0.7*GetSystemMetrics(SM_CXSCREEN)); /* Largeur de la fenêtre */
int Y = (int)(0.4*GetSystemMetrics(SM_CYSCREEN)); /* Longueur de la fenêtre */
setFixedSize(X, Y); // On fixe définitivement la FolderSize de la fenêtre
char S_XS[999], S_XS2[999], S_D2A[999], S_EASY[999], S_ALCATEL[999], S_VOCALD6[999], S_SAUVMATRA[999], S_MATRAPARALLELE[999]; // Chemin des dossiers sources
char D_XS[999], D_XS2[999], D_D2A[999], D_EASY[999], D_ALCATEL[999], D_VOCALD6[999], D_SAUVMATRA[999], D_MATRAPARALLELE[999]; // Chemin des dossiers cibles
/* On récupère ces chemin dans setup.ini */
GetPrivateProfileStringA("section", "S_XS" , "", S_XS , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "S_XS2" , "", S_XS2 , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "S_D2A" , "", S_D2A , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "S_EASY" , "", S_EASY , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "S_ALCATEL" , "", S_ALCATEL , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "S_VOCALD6" , "", S_VOCALD6 , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "S_SAUVMATRA" , "", S_SAUVMATRA , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "S_MATRAPARALLELE", "", S_MATRAPARALLELE, 999, ".//setup.ini");
GetPrivateProfileStringA("section", "D_XS" , "", D_XS , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "D_XS2" , "", D_XS2 , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "D_D2A" , "", D_D2A , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "D_EASY" , "", D_EASY , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "D_ALCATEL" , "", D_ALCATEL , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "D_VOCALD6" , "", D_VOCALD6 , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "D_SAUVMATRA" , "", D_SAUVMATRA , 999, ".//setup.ini");
GetPrivateProfileStringA("section", "D_MATRAPARALLELE", "", D_MATRAPARALLELE, 999, ".//setup.ini");
/* Création des objets */
Title = new QLabel ("<SMALL><strong>SAUVEGARDE AUTOMATIQUES DES DONNEÉS</strong></SMALL>", this);
ButtonOk = new QPushButton (" OK", this);
ButtonStop = new QPushButton ("STOP", this);
PrintSizes = new QLabel ( this);
PrintSrcPath = new QLabel ( this);
PrintTarPath = new QLabel ( this);
PrintFileSize = new QLabel ( this);
PrintFileName = new QLabel ( this);
PrintFileNumbers = new QLabel ( this);
QProgressBar *ProgressBar = new QProgressBar( this);
/* Attributs sur les objets */
Title -> move ( (X - Title->minimumSizeHint().width())/2, 0.05*Y );
ButtonOk -> setGeometry( (int)((X-(2*WIDTH+SPACE))/2+WIDTH+SPACE), (int)(0.9*Y), WIDTH, SPACE );
ButtonStop -> setGeometry( (int)((X-(2*WIDTH+SPACE))/2 ), (int)(0.9*Y), WIDTH, SPACE );
ProgressBar -> setGeometry( 0.125*X, 0.1*Y, 0.75*X, 0.075*Y );
ProgressBar -> setRange ( 0, 100 );
ProgressBar -> setValue ( 0 );
qint64 CopySize = FolderSize(S_XS)+FolderSize(S_XS2)+FolderSize(S_D2A)+FolderSize(S_EASY)+FolderSize(S_ALCATEL)+FolderSize(S_VOCALD6)+FolderSize(S_SAUVMATRA)+FolderSize(S_MATRAPARALLELE); /* On calcule le volume de donnée que la copie va engendrer */
QString QCopySize = QString::number(CopySize); /* On convertit le volume de donnée à copier en QString */
qint64 Progress;
/* Copie des dossiers */
Progress = QtCopy ( X, Y, 0, QCopySize, S_XS , D_XS , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
ProgressBar -> setValue ( Progress );
Progress = QtCopy ( X, Y, Progress, QCopySize, S_XS2 , D_XS2 , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
ProgressBar -> setValue ( Progress );
Progress = QtCopy ( X, Y, Progress, QCopySize, S_D2A , D_D2A , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
ProgressBar -> setValue ( Progress );
Progress = QtCopy ( X, Y, Progress, QCopySize, S_EASY , D_EASY , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
ProgressBar -> setValue ( Progress );
Progress = QtCopy ( X, Y, Progress, QCopySize, S_ALCATEL , D_ALCATEL , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
ProgressBar -> setValue ( Progress );
Progress = QtCopy ( X, Y, Progress, QCopySize, S_VOCALD6 , D_VOCALD6 , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
ProgressBar -> setValue ( Progress );
Progress = QtCopy ( X, Y, Progress, QCopySize, S_SAUVMATRA , D_SAUVMATRA , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
ProgressBar -> setValue ( Progress );
Progress = QtCopy ( X, Y, Progress, QCopySize, S_MATRAPARALLELE, D_MATRAPARALLELE, PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
ProgressBar -> setValue ( Progress );
/* Signaux */
QObject::connect(ButtonStop, SIGNAL(clicked()) , qApp, SLOT( aboutQt() ) );
QObject::connect( ButtonOk, SIGNAL(clicked()) , qApp, SLOT( quit () ) );
}
// FUNCTIONS ///////////////////////////////////////////////////////////////////
qint64 QtCopy( int X, int Y, qint64 Progress, QString QCopySize, char *SrcPath, char *TarPath, QLabel *PrintFileNumbers, QLabel *PrintSrcPath, QLabel *PrintTarPath, QLabel *PrintFileSize, QLabel *PrintFileName, QLabel *PrintSizes)
{
QString Src = QString(SrcPath); /* Convertion de la variable char en QString ( répertoire source ) */
QString Tar = QString(TarPath); /* Convertion de la variable char en QString ( répertoire cible ) */
QDir::setCurrent(Src); /* On se place dans le repertoire source */
QDir dirSource (Src); /**/
QStringList Filter; /* On déclare un filtre sur les extentions de fichiers */
Filter << "*.*"; /* On récupère tous les types de fichier */
dirSource.setNameFilters(Filter); /* On enregistre les noms de fichiers dans le filtre */
int i;
int FileNumbers = dirSource.count(); /* On récupère le nombre de fichiers à copier */
for ( i=0 ; i < FileNumbers ; i++ )
{
QString SrcPath; /* Variable QString pour stocker le chemin complet du fichier source */
QString TarPath; /* Variable QString pour stocker le chemin complet du fichier cible */
QString FileName = dirSource.entryList(Filter).at(i); /* On récupère chaque nom de fichier contenu dans le filtre grâce à la boucle */
if (FileName != "." && FileName != ".." ) /* On controle que le fichier n'est pas le repertoire parent ou le répertoire courant */
{
SrcPath = Src + FileName; /* On concatène le chemin du fichier source avec son nom */
TarPath = Tar + FileName; /* On concatène le chemin du fichier cible avec son nom */
QString QFileNumbers=QString::number(FileNumbers-2);
QFileInfo fi(SrcPath); /* On récupère des informations sur le fichier */
QString FileSize = QString::number(fi.size()/1024 ); /* On récupère la FolderSize de ce fichier */
QString QProgress = QString::number(Progress/(1024*1024));
/* On place les QLabel dans la fenêtre */
PrintSizes -> move( (X - PrintSizes -> minimumSizeHint().width())/2, 0.25*Y );
PrintSrcPath -> move( (X - PrintSrcPath -> minimumSizeHint().width())/2, 0.35*Y );
PrintTarPath -> move( (X - PrintTarPath -> minimumSizeHint().width())/2, 0.45*Y );
PrintFileName -> move( (X - PrintFileName -> minimumSizeHint().width())/2, 0.55*Y );
PrintFileSize -> move( (X - PrintFileSize -> minimumSizeHint().width())/2, 0.65*Y );
PrintFileNumbers -> move( (X - PrintFileNumbers -> minimumSizeHint().width())/2, 0.75*Y );
// On met à jour leur affichage //
PrintSrcPath -> setText("<small><strong>SOURCE :</strong></small> " + SrcPath );
PrintTarPath -> setText("<small><strong>DESTINATION :</strong></small> " + TarPath );
PrintFileName -> setText("<small><strong>NOM DU FICHIER :</strong></small> " + FileName );
PrintFileSize -> setText("<small><strong>TAILLE :</strong></small> " + FileSize + " Ko");
PrintSizes -> setText("<small><strong>TRANSFERT :</strong></small> " + QProgress +"/"+ QCopySize + " Mo");
PrintFileNumbers -> setText("<small><strong>NOMBRE DE FICHIERS DANS LE DOSSIER :</strong></small> " + QFileNumbers);
qint64 CurrentSize = fi.size();
CurrentSize = Progress + CurrentSize;
QString QCurrentSize = QString::number(CurrentSize/(1024*1024));
PrintSizes -> setText("<small><strong>TRANSFERT :</strong></small> " + QCurrentSize+"/"+QCopySize + " Mo");
QFile file(SrcPath); /* On déclare le fichier de chemin SrcPath */
file.copy(TarPath); /* On effectue la copie de ce fichier */
return CurrentSize;
}
}
}
////////////////////////////////////////////////////////////////////////////////
qint64 FolderSize(char *path)
{
QString Src = QString(path); /* Convertion de la variable char en QString ( répertoire source ) */
QDir::setCurrent(path); /* On se place dans le repertoire source */
QDir dirSource (path); /**/
QStringList Filter; /* On déclare un filtre sur les extentions de fichiers */
Filter << "*.*"; /* On récupère tous les types de fichier */
dirSource.setNameFilters(Filter); /* On enregistre les noms de fichiers dans le filtre */
qint64 FolderSize=0;
int i;
int FileNumbers = dirSource.count(); /* On récupère le nombre de fichiers à copier */
for ( i=0 ; i < FileNumbers ; i++ )
{
QString SrcPath; /* Variable QString pour stocker le chemin complet du fichier source */
QString FileName = dirSource.entryList(Filter).at(i); /* On récupère chaque nom de fichier contenu dans le filtre grâce à la boucle */
if (FileName != "." && FileName != ".." ) /* On controle que le fichier n'est pas le repertoire parent ou le répertoire courant */
{
SrcPath = Src + FileName; /* On concatène le chemin du fichier source avec son nom */
QFileInfo fi(SrcPath); /* On récupère des informations sur le fichier */
qint64 FileSize = fi.size()/(1024*1024); /* On récupère la FolderSize en Mo du fichier */
FolderSize = FolderSize+FileSize; /* On l'ajoute à la taille du dossier au fur et à mesure que la boucle s'incrèmente */
}
}
return FolderSize; /* On renvoit l'information */
} |
Partager