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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
#include <QApplication>
#include <QDirIterator>
#include <QWidget>
#include <QPushButton>
#include <QLCDNumber>
#include <QSlider>
#include <QLabel>
#include <QProgressBar>
#include <QMessageBox>
#include <windows.h>
#include <QFile>
#include <QString>
#include <QFileDialog>
#include <QObject>
#include <QStringList>
#include <QDebug>
#include "fenetre.h"
#define WIDTH 75
#define SPACE 20
qint64 supercopy( char *src, char *dst, QLabel *affichage_taille_totale, QLabel *affichage_source, QLabel *affichage_destination, QLabel *affiche_taille, QLabel *affichage_courant, int ResX, int ResY, QString Qtaille_totale, qint64 progression );
qint64 taille(char *path);
MaFenetre::MaFenetre() : QWidget()
{
// DIMENSION DE LA FENETRE
int ResX = (int)(0.66*GetSystemMetrics(SM_CXSCREEN));
int ResY = (int)(0.32*GetSystemMetrics(SM_CYSCREEN));
// ON FIXE LES DIMENSIONS POUR QUE LA FENETRE NE SOIT PLUS REDIMENSIONEE
setFixedSize(ResX, ResY);
// VARIABLES STOCKANT LES CHEMINS DES DOSSIERS DU PC DU TECHNICIEN
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];
// VARIABLE STOCKANT LES CHEMINS DES DOSSIERS DU RESEAU
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];
// STOCKAGE DES CHEMINS DES DOSSIERS DU PC DU TECHNICIEN
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");
// STOCKAGE DES CHEMINS DES DOSSIERS DU RESEAU
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");
// TAILLE TOTALE DE LE COPIE
qint64 taille_totale=taille(S_XS)+taille(S_XS2)+taille(S_D2A)+taille(S_EASY)+taille(S_ALCATEL)+taille(S_VOCALD6)+taille(S_SAUVMATRA)+taille(S_MATRAPARALLELE);
QString Qtaille_totale = QString::number(taille_totale);
// TITRE
QLabel *titre = new QLabel("<SMALL><strong>SAUVEGARDE AUTOMATIQUES DES DONNEÉS</strong></SMALL>", this);
titre -> move( (ResX - titre->minimumSizeHint().width())/2, 0.05*ResY );
// AFFICHAGE DES BOUTONS
bouton0 = new QPushButton("STOP", this);
bouton1 = new QPushButton(" OK", this);
// POSITION DES BOUTONS DANS LA FENETRE
bouton0 -> setGeometry( (int)((ResX-(2*WIDTH+SPACE))/2 ), (int)(0.9*ResY), WIDTH, SPACE );
bouton1 -> setGeometry( (int)((ResX-(2*WIDTH+SPACE))/2+WIDTH+SPACE), (int)(0.9*ResY), WIDTH, SPACE );
// BARRE DE PROGRESSION GENERALE
QProgressBar *progression_generale = new QProgressBar(this);
progression_generale -> setGeometry( 0.125*ResX, 0.2*ResY, 0.75*ResX, 0.075*ResY );
progression_generale -> setRange ( 0, 100 );
progression_generale -> setValue ( 0 );
// INITIALISATION DES QLABELS
affichage_source = new QLabel(this);
affichage_destination = new QLabel(this);
affiche_taille = new QLabel(this);
affichage_courant = new QLabel(this);
affichage_taille_courante = new QLabel(this);
qint64 progression;
//COPIE DES DOSSIERS
progression=supercopy( S_XS , D_XS , affichage_taille_courante, affichage_source, affichage_destination, affiche_taille, affichage_courant, ResX, ResY, Qtaille_totale, 0 );
progression_generale -> setValue ( (int)(progression) );
progression=supercopy( S_XS2 , D_XS2 , affichage_taille_courante, affichage_source, affichage_destination, affiche_taille, affichage_courant, ResX, ResY, Qtaille_totale, progression );
progression_generale -> setValue ( (int)(progression) );
progression=supercopy( S_D2A , D_D2A , affichage_taille_courante, affichage_source, affichage_destination, affiche_taille, affichage_courant, ResX, ResY, Qtaille_totale, progression );
progression_generale -> setValue ( (int)(progression) );
progression=supercopy( S_EASY , D_EASY , affichage_taille_courante, affichage_source, affichage_destination, affiche_taille, affichage_courant, ResX, ResY, Qtaille_totale, progression );
progression_generale -> setValue ( (int)(progression) );
progression=supercopy( S_ALCATEL , D_ALCATEL , affichage_taille_courante, affichage_source, affichage_destination, affiche_taille, affichage_courant, ResX, ResY, Qtaille_totale, progression );
progression_generale -> setValue ( (int)(progression) );
progression=supercopy( S_VOCALD6 , D_VOCALD6 , affichage_taille_courante, affichage_source, affichage_destination, affiche_taille, affichage_courant, ResX, ResY, Qtaille_totale, progression );
progression_generale -> setValue ( (int)(progression) );
progression=supercopy( S_SAUVMATRA , D_SAUVMATRA , affichage_taille_courante, affichage_source, affichage_destination, affiche_taille, affichage_courant, ResX, ResY, Qtaille_totale, progression );
progression_generale -> setValue ( (int)(progression) );
progression=supercopy( S_MATRAPARALLELE, D_MATRAPARALLELE, affichage_taille_courante, affichage_source, affichage_destination, affiche_taille, affichage_courant, ResX, ResY, Qtaille_totale, progression );
progression_generale -> setValue ( 100 );
// SIGNAUX
QObject::connect(bouton0, SIGNAL(clicked()) , qApp, SLOT( aboutQt() ) );
QObject::connect(bouton1, SIGNAL(clicked()) , qApp, SLOT( quit () ) );
}
qint64 supercopy( char *src, char *dst, QLabel *affichage_taille_courante, QLabel *affichage_source, QLabel *affichage_destination, QLabel *affiche_taille, QLabel *affichage_courant, int ResX, int ResY, QString Qtaille_totale, qint64 progression )
{
// CONVERSION EN QSTRING DES VARIABLES DE TYPE CHAR
QString source = QString(src);
QString destination = QString(dst);
// ON SE PLACE DANS LE DOSSIER DONT ON VEUT QUE LES FICHIERS SOIENT COPIES
QDir::setCurrent(source);
QDir dirSource (source);
// CREATION D'UN FILTRE SUR LES EXTENSIONS, ON COPIE TOUS LES FICHIERS POUR LE MOMENT
QStringList filtre;
filtre << "*.*";
dirSource.setNameFilters(filtre);
// ON RECUPERE LE NOMBRE DE FICHIERS CONTENU DANS LE FILTRE ET DONC DANS LE DOSSIER
int nombre_de_fichiers = dirSource.count();
// VARIABLE QUI STOCKE LE NOM DU FICHIER EN COURS DE COPIE
QString nom_du_fichier;
// ON BOUCLE SUR LE NOMBRE DE FICHIERS CONTENU DANS LE REPERTOIRE POUR TOUT COPIER
int i;
for ( i=0 ; i < nombre_de_fichiers ; i++ )
{
// QSTRING POUR CONTENIR LES CHEMINS SOURCE/DESTINATION DES FICHIERS
QString sourcefile ;
QString destinationfile;
// ON RECUPERE LES NOMS DES FICHIERS CONTENU DANS LE FILTRE ET ON LES STOCKENT DANS LA VARIABLE PREVUE A CETTE EFFET
nom_du_fichier = dirSource.entryList(filtre).at(i);
if (nom_du_fichier != "." && nom_du_fichier != ".." )
{
// ON CONCATENE LES CHEMINS SOURCE ET DESTINATIONS AVEC LE NOM DE FICHIER EN COURS POUR LE PASSER A LA FONCTION DE COPIE
sourcefile = source + nom_du_fichier;
destinationfile = destination + nom_du_fichier;
// AFFICHAGE DU CHEMIN SOURCE/DESTINATION CONCATENE AVEC LE NOM DU FICHIER EN COURS DE COPIE
affichage_source -> setText(" <small><strong>SOURCE :</strong></small> " + sourcefile );
affichage_destination -> setText(" <small><strong>DESTINATION :</strong></small> " + destinationfile );
affichage_source -> move ( (ResX - affichage_source->minimumSizeHint().width())/2, 0.45*ResY );
affichage_destination -> move ( (ResX - affichage_destination->minimumSizeHint().width())/2, 0.55*ResY );
// NOM DU FICHIER EN COURS DE COPIE
affichage_courant -> setText(" <small><strong>EN COURS :</strong></small> " + nom_du_fichier );
affichage_courant -> move ( (ResX - affichage_courant->minimumSizeHint().width())/2, 0.65*ResY );
// TAILLE DU FICHIER EN COURS DE COPIE
QFileInfo fi(sourcefile);
qint64 taille = fi.size(); // TAILLE EN OCTETS DU FICHIER EN COURS DE COPIE
QString Qtaille = QString::number((taille/(1024*1024))); // CONVERTION EN QSTRING DE LA TAILLE DU FICHIER EN MO
// QUANTITE INSTANTANEE DES FICHIERS DEJA COPIES
qint64 taille_courante = progression; // TAILLE EN OCTET DE LA QUANTITE DE DONNEES DEJA COPIEE
QString Qtaille_courante = QString::number((taille_courante/(1024*1024))); // CONVERTION EN QSTRING DE LA TAILLE DES DONNEES DEJA COPIEE EN MO
// AFFICHAGE DE LA QUANTITE DE DONNEES DEJA COPIEE
affichage_taille_courante -> setText(" <small><strong>TRANSFERT :</strong></small> " + Qtaille_courante+"/"+Qtaille_totale+" Mo");
affichage_taille_courante -> move ( (ResX - affichage_taille_courante->minimumSizeHint().width())/2, 0.35*ResY );
// AFFICHAGE DE LA TAILLE DU FICHIER EN COURS DE COPIE
affiche_taille -> setText("<small><strong>TAILLE :</strong></small> " + Qtaille + " Mo" );
affiche_taille -> move ( (ResX - affiche_taille->minimumSizeHint().width())/2, 0.75*ResY );
//nombre de fichiers dans la liste
//QString nombre="";
//nombre=QString::number(nombre_de_fichiers);
//QLabel *test2 = new QLabel(" nombre de fichiers : " + nombre, this);
//test2->move( (ResX - test2->minimumSizeHint().width())/2,0.675*ResY );
// ON EFFECTUER LA COPIE
QFile file(sourcefile);
file.copy(destinationfile);
// ON MET A JOUR LA TAILLE DE DONNEES TRANSFEREES
taille_courante = taille_courante+taille;
Qtaille_courante = QString::number((taille_courante/(1024*1024)));
affichage_taille_courante -> setText(" <small><strong>TRANSFERT :</strong></small> " + Qtaille_courante+"/"+Qtaille_totale+" Mo");
return taille_courante;
}
}
}
qint64 taille(char *path)
{
// CONVERSION EN QSTRING DE LA VARIABLE DE TYPE CHAR
QString source = QString(path);
// ON SE PLACE DANS LE DOSSIER DONT ON VEUT QUE LES FICHIERS SOIENT COPIES
QDir::setCurrent(source);
QDir dirSource (source);
// CREATION D'UN FILTRE SUR LES EXTENSIONS, ON COPIE TOUS LES FICHIERS POUR LE MOMENT
QStringList filtre;
filtre << "*.*";
dirSource.setNameFilters(filtre);
// ON RECUPERE LE NOMBRE DE FICHIERS CONTENU DANS LE FILTRE ET DONC DANS LE DOSSIER
int nombre_de_fichiers = dirSource.count();
// VARIABLE QUI STOCKE LE NOM DU FICHIER EN COURS DE COPIE
QString nom_du_fichier;
// VARIABLE POUR STOCKER LA TAILLE DU DOSSIER
qint64 taille_dossier=0;
// ON BOUCLE SUR LE NOMBRE DE FICHIERS CONTENU DANS LE REPERTOIRE POUR TOUT COPIER
int i;
for ( i=0 ; i < nombre_de_fichiers ; i++ )
{
QString sourcefile;
// ON RECUPERE LES NOMS DES FICHIERS CONTENU DANS LE FILTRE ET ON LES STOCKENT DANS LA VARIABLE PREVUE A CETTE EFFET
nom_du_fichier = dirSource.entryList(filtre).at(i);
if (nom_du_fichier != "." && nom_du_fichier != ".." )
{
// ON CONCATENE LES CHEMINS SOURCE ET DESTINATIONS AVEC LE NOM DE FICHIER EN COURS POUR LE PASSER A LA FONCTION DE COPIE
sourcefile = source + nom_du_fichier;
// ON RECUPERE LA TAILLE DU DOSSIER
QFileInfo fi(sourcefile);
qint64 taille_fichier=fi.size()/(1024*1024);
taille_dossier=taille_dossier+taille_fichier;
}
}
return taille_dossier;
} |
Partager