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
|
#include <QtGui>
#include "filtrer.h"
#include "QtGestXavMedias.h"
Filtrer::Filtrer(QWidget *parent)
: QDialog(parent)
{
MyAppDirPath = QCoreApplication::applicationDirPath();
findButton = createButton(tr("&Chercher"), SLOT(find()));
textComboBox = createComboBox();
text2ComboBox = createComboBox();
textLabel = new QLabel(tr("Rechercher par:"));
text2Label = new QLabel(tr("Critere de recherche:"));
filesFoundLabel = new QLabel;
createFilesTable();
QGridLayout *mainLayout = new QGridLayout;
mainLayout->setSizeConstraint(QLayout::SetNoConstraint);
mainLayout->addWidget(textLabel, 1, 0, 1, 3);
mainLayout->addWidget(text2ComboBox, 2, 0, 1, 3);
mainLayout->addWidget(text2Label, 3, 0, 1, 3);
mainLayout->addWidget(textComboBox, 4, 0, 1, 3);
mainLayout->addWidget(filesTable, 5, 0, 1, 3);
mainLayout->addWidget(filesFoundLabel, 6, 0, 1, 2);
mainLayout->addWidget(testsButton, 7,1);
mainLayout->addWidget(findButton, 6, 2, 1, 1);
setLayout(mainLayout);
setWindowTitle(tr("Filtrer selon Critere :"));
QFile ComboFiltresChoix(QCoreApplication::applicationDirPath()+ "/ComboFiltresChoix.xav");
if (ComboFiltresChoix.open(QFile::ReadOnly | QFile::Text))
{
QTextStream sIn(&ComboFiltresChoix);
while (!sIn.atEnd())
combofiltreslistchoix += sIn.readLine();
text2ComboBox->addItems(combofiltreslistchoix);
}
choix = 0;
connect(text2ComboBox, SIGNAL(activated (int)), this, SLOT(comboChanged(int)));
}
void Filtrer::comboChanged(int index)
{
switch (index){
case 2:
Xavqfile = QCoreApplication::applicationDirPath()+ "/ComboFiltresAnnee.xav";
Xavstringlist = combofiltreslistAnnee;
choix = 2;
break;
case 1:
Xavqfile = QCoreApplication::applicationDirPath()+ "/ComboFiltresActeurs.xav";
Xavstringlist = combofiltreslistActeurs;
choix = 1;
break;
}
QFile ComboFiltres(Xavqfile);
textComboBox->clear();
if (ComboFiltres.open(QFile::ReadOnly | QFile::Text))
{
QTextStream sIn(&ComboFiltres);
while (!sIn.atEnd())
Xavstringlist += sIn.readLine();
textComboBox->addItems(Xavstringlist);
}
}
static void updateComboBox(QComboBox *comboBox)
{
if (comboBox->findText(comboBox->currentText()) == -1)
comboBox->addItem(comboBox->currentText());
}
void Filtrer::find()
{
filesTable->setRowCount(0);
QString fileName = ("*.film");
QString text = textComboBox->currentText();
QSettings settings("GestXavMedias", "GestXavMedias.ini");
QString path = (MyAppDirPath + "/" + settings.value("NomUtilisateurDef").toString());
updateComboBox(textComboBox);
currentDir = QDir(path);
QStringList files;
if (fileName.isEmpty())
fileName = "*.film";
files = currentDir.entryList(QStringList(fileName),
QDir::Files | QDir::NoSymLinks);
if (!text.isEmpty())
files = findFiles(files, text);
showFiles(files);
}
QStringList Filtrer::findFiles(const QStringList &files, const QString &text)
{
QProgressDialog progressDialog(this);
progressDialog.setCancelButtonText(tr("&Abandonner"));
progressDialog.setRange(0, files.size());
progressDialog.setWindowTitle(tr("Trouver Film(s)"));
QStringList foundFiles;
for (int i = 0; i < files.size(); ++i) {
progressDialog.setValue(i);
progressDialog.setLabelText(tr("recherche du fichier N° %1 of %2...")
.arg(i).arg(files.size()));
qApp->processEvents();
if (progressDialog.wasCanceled())
break;
QFile file(currentDir.absoluteFilePath(files[i]));
if (file.open(QIODevice::ReadOnly)) {
QString line;
QTextStream in(&file);
while (!in.atEnd()) {
if (progressDialog.wasCanceled())
break;
line = in.readLine();
if (line.contains(text)) {
foundFiles << files[i];
break;
}
}
}
}
return foundFiles;
}
void Filtrer::showFiles(const QStringList &files)
{
for (int i = 0; i < files.size(); ++i) {
QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]);
fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
int row = filesTable->rowCount();
filesTable->insertRow(row);
filesTable->setItem(row, 0, fileNameItem);
}
filesFoundLabel->setText(tr("%1 fichier(s) trouvé (s)").arg(files.size()) + (" (Double click pour l'ouvrir)"));
filesFoundLabel->setWordWrap(true);
}
QPushButton *Filtrer::createButton(const QString &text, const char *member)
{
QPushButton *button = new QPushButton(text);
connect(button, SIGNAL(clicked()), this, member);
return button;
}
QComboBox *Filtrer::createComboBox(const QString &text)
{
QComboBox *comboBox = new QComboBox;
comboBox->setEditable(true);
comboBox->addItem(text);
comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
return comboBox;
}
void Filtrer::createFilesTable()
{
filesTable = new QTableWidget(0, 1);
filesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
QStringList labels;
labels << tr("Nom du film");
filesTable->setHorizontalHeaderLabels(labels);
filesTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
filesTable->verticalHeader()->hide();
filesTable->setShowGrid(false);
connect(filesTable, SIGNAL(cellActivated(int,int)),
this, SLOT(openFileOfItem(int,int)));
connect(filesTable, SIGNAL(cellActivated(int,int)),
this, SLOT(accept()));
}
void Filtrer::openFileOfItem(int row, int /* column */)
{
QTableWidgetItem *item = filesTable->item(row, 0);
QString text = currentDir.absoluteFilePath(item->text());
findText = text;
filesFoundLabel->clear();
hide();
}
QString Filtrer::getfindFilm()
{
return findText;
} |
Partager