comparison DataController.cpp @ 64:b9515dc35fe4

Make sure no file has greater linewidth than 80.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Fri, 14 Sep 2012 22:50:45 +0200
parents 247adcbbaf8b
children a60c26e34d1a
comparison
equal deleted inserted replaced
63:dd086ec3220d 64:b9515dc35fe4
30 namespace fs = boost::filesystem; 30 namespace fs = boost::filesystem;
31 fs::path someDir(dir.path().toStdString()); 31 fs::path someDir(dir.path().toStdString());
32 fs::directory_iterator end_iter; 32 fs::directory_iterator end_iter;
33 33
34 if ( fs::exists(someDir) && fs::is_directory(someDir)) { 34 if ( fs::exists(someDir) && fs::is_directory(someDir)) {
35 for( fs::directory_iterator dir_iter(someDir) ; dir_iter != end_iter ; ++dir_iter) { 35 for( fs::directory_iterator dir_iter(someDir) ;
36 dir_iter != end_iter ; ++dir_iter) {
36 if (fs::is_directory(dir_iter->status()) ) { 37 if (fs::is_directory(dir_iter->status()) ) {
37 findFiles(QString::fromStdWString(dir_iter->path().wstring()), list); 38 findFiles(QString::fromStdWString(dir_iter->path().wstring()), list);
38 } 39 }
39 if (fs::is_regular_file(dir_iter->status()) ) { 40 if (fs::is_regular_file(dir_iter->status()) ) {
40 list << QString::fromStdWString(dir_iter->path().wstring()); 41 list << QString::fromStdWString(dir_iter->path().wstring());
80 bar->setValue(0); 81 bar->setValue(0);
81 bar->setMinimum(0); 82 bar->setMinimum(0);
82 bar->setMaximum(progressMax); 83 bar->setMaximum(progressMax);
83 bar->show(); 84 bar->show();
84 85
85 connect(this, SIGNAL(populateProgress(int)), bar.get(), SLOT(setValue(int))); 86 connect(this, SIGNAL(populateProgress(int)),
87 bar.get(), SLOT(setValue(int)));
86 } 88 }
87 89
88 int n = 0; 90 int n = 0;
89 emit populateProgress(n); 91 emit populateProgress(n);
90 foreach(QString filename, findFiles(dir)) { 92 foreach(QString filename, findFiles(dir)) {
93 } 95 }
94 catch (const PermissionException& e) { 96 catch (const PermissionException& e) {
95 dblink.deleteFileFromDB(filename); 97 dblink.deleteFileFromDB(filename);
96 } 98 }
97 catch (const IOException& e) { 99 catch (const IOException& e) {
98 //FIXME: We have some strange errors, avoid them by ignoring them for now 100 //FIXME: We have some strange errors, avoid them by ignoring
101 //them for now
99 dblink.deleteFileFromDB(filename); 102 dblink.deleteFileFromDB(filename);
100 } 103 }
101 catch (Exception& e) { 104 catch (Exception& e) {
102 e.raise(); 105 e.raise();
103 } 106 }
133 } 136 }
134 137
135 138
136 void DataController::populate() 139 void DataController::populate()
137 { 140 {
138 populate(nameFilter->isChecked(), sizeFilter->isChecked(), mtimeFilter->isChecked(), 141 populate(nameFilter->isChecked(), sizeFilter->isChecked(),
139 checksumFilter->isChecked(), (100 - editCutoffSpin->value()) * .01); 142 mtimeFilter->isChecked(),
143 checksumFilter->isChecked(),
144 (100 - editCutoffSpin->value()) * .01);
140 } 145 }
141 146
142 void DataController::populate(bool showNameDups, bool showSizeDups, 147 void DataController::populate(bool showNameDups, bool showSizeDups,
143 bool showMTimeDups, bool showCheckSumDups, 148 bool showMTimeDups, bool showCheckSumDups,
144 float editDistanceCutoff) 149 float editDistanceCutoff)
145 { 150 {
146 tw->clear(); 151 tw->clear();
147 152
148 const QList<QSharedPointer<FileDBLink::DBInfo> > elems = dblink->values(dir.path()); 153 const QList<QSharedPointer<FileDBLink::DBInfo> > elems =
154 dblink->values(dir.path());
149 155
150 QProgressBar bar; 156 QProgressBar bar;
151 157
152 bar.resize(200,25); 158 bar.resize(200,25);
153 bar.setValue(0); 159 bar.setValue(0);
154 bar.setMinimum(0); 160 bar.setMinimum(0);
155 bar.setMaximum(elems.size()); 161 bar.setMaximum(elems.size());
156 bar.show(); 162 bar.show();
157 163
158 connect(this, SIGNAL(populateProgress(int)), &bar, SLOT(setValue(int))); 164 connect(this, SIGNAL(populateProgress(int)),
165 &bar, SLOT(setValue(int)));
159 166
160 int n = 0; 167 int n = 0;
161 168
162 tw->setUpdatesEnabled(false); 169 tw->setUpdatesEnabled(false);
163 170
185 foreach(QSharedPointer<FileDBLink::DBInfo> line, elems) { 192 foreach(QSharedPointer<FileDBLink::DBInfo> line, elems) {
186 QTreeWidgetItem* item = 0; 193 QTreeWidgetItem* item = 0;
187 194
188 if (showNameDups) { 195 if (showNameDups) {
189 QTreeWidgetItem* topLevelItem = 0; 196 QTreeWidgetItem* topLevelItem = 0;
190 foreach(QSharedPointer<FileDBLink::DBInfo> dup, nameLUP.values(line->name())) { 197 foreach(QSharedPointer<FileDBLink::DBInfo> dup,
198 nameLUP.values(line->name())) {
191 if(dup != line) { 199 if(dup != line) {
192 if (!topLevelItem) { 200 if (!topLevelItem) {
193 topLevelItem = new QTreeWidgetItem(); 201 topLevelItem = new QTreeWidgetItem();
194 topLevelItem->setData(0, Qt::DisplayRole, "Name"); 202 topLevelItem->setData(0, Qt::DisplayRole, "Name");
195 if(!item) 203 if(!item)
201 } 209 }
202 } 210 }
203 211
204 if (showSizeDups) { 212 if (showSizeDups) {
205 QTreeWidgetItem* topLevelItem = 0; 213 QTreeWidgetItem* topLevelItem = 0;
206 foreach(QSharedPointer<FileDBLink::DBInfo> dup, sizeLUP.values(line->size())) { 214 foreach(QSharedPointer<FileDBLink::DBInfo> dup,
215 sizeLUP.values(line->size())) {
207 if(dup != line ) { 216 if(dup != line ) {
208 if (!topLevelItem) { 217 if (!topLevelItem) {
209 topLevelItem = new QTreeWidgetItem(); 218 topLevelItem = new QTreeWidgetItem();
210 topLevelItem->setData(0, Qt::DisplayRole, "Size"); 219 topLevelItem->setData(0, Qt::DisplayRole, "Size");
211 if(!item) 220 if(!item)
217 } 226 }
218 } 227 }
219 228
220 if (showMTimeDups) { 229 if (showMTimeDups) {
221 QTreeWidgetItem* topLevelItem = 0; 230 QTreeWidgetItem* topLevelItem = 0;
222 foreach(QSharedPointer<FileDBLink::DBInfo> dup, mtimeLUP.values(line->mtime())) { 231 foreach(QSharedPointer<FileDBLink::DBInfo> dup,
232 mtimeLUP.values(line->mtime())) {
223 if(dup != line ) { 233 if(dup != line ) {
224 if (!topLevelItem) { 234 if (!topLevelItem) {
225 topLevelItem = new QTreeWidgetItem(); 235 topLevelItem = new QTreeWidgetItem();
226 topLevelItem->setData(0, Qt::DisplayRole, "MTime"); 236 topLevelItem->setData(0, Qt::DisplayRole, "MTime");
227 if(!item) 237 if(!item)
233 } 243 }
234 } 244 }
235 245
236 if (showCheckSumDups) { 246 if (showCheckSumDups) {
237 QTreeWidgetItem* topLevelItem = 0; 247 QTreeWidgetItem* topLevelItem = 0;
238 foreach(QSharedPointer<FileDBLink::DBInfo> dup, checksumLUP.values(line->checksum())) { 248 foreach(QSharedPointer<FileDBLink::DBInfo> dup,
249 checksumLUP.values(line->checksum())) {
239 if(dup != line) { 250 if(dup != line) {
240 if (!topLevelItem) { 251 if (!topLevelItem) {
241 topLevelItem = new QTreeWidgetItem(); 252 topLevelItem = new QTreeWidgetItem();
242 topLevelItem->setData(0, Qt::DisplayRole, "Checksum"); 253 topLevelItem->setData(0, Qt::DisplayRole, "Checksum");
243 if(!item) 254 if(!item)
359 editCutoffSpin->setMinimum(0); 370 editCutoffSpin->setMinimum(0);
360 editCutoffSpin->setMaximum(100); 371 editCutoffSpin->setMaximum(100);
361 editCutoffSpin->setValue(0); 372 editCutoffSpin->setValue(0);
362 editCutoffSpin->setSingleStep(10); 373 editCutoffSpin->setSingleStep(10);
363 editCutoffSpin->setSuffix("%"); 374 editCutoffSpin->setSuffix("%");
364 connect(editCutoffSpin, SIGNAL(valueChanged(int)), this, SLOT(delayPopulate())); 375 connect(editCutoffSpin, SIGNAL(valueChanged(int)),
376 this, SLOT(delayPopulate()));
365 filterBar->addWidget(widget); 377 filterBar->addWidget(widget);
366 378
367 mw->addToolBar(filterBar); 379 mw->addToolBar(filterBar);
368 380
369 tw = new QTreeWidget(mw); 381 tw = new QTreeWidget(mw);
416 void DataController::deleteFile() 428 void DataController::deleteFile()
417 { 429 {
418 QString path = contextMenuItem->data(0, 32).toString(); 430 QString path = contextMenuItem->data(0, 32).toString();
419 QMessageBox::StandardButton button = 431 QMessageBox::StandardButton button =
420 QMessageBox::question(tw, "Confirm delete", 432 QMessageBox::question(tw, "Confirm delete",
421 QString("Do you really want to delete \"%1\"?").arg(path), 433 QString("Do you really want to delete \"%1\"?")
434 .arg(path),
422 QMessageBox::Cancel | QMessageBox::Ok, 435 QMessageBox::Cancel | QMessageBox::Ok,
423 QMessageBox::Cancel); 436 QMessageBox::Cancel);
424 if (button == QMessageBox::Ok) { 437 if (button == QMessageBox::Ok) {
425 QFile file(path); 438 QFile file(path);
426 if (file.remove()) { 439 if (file.remove()) {
427 dblink->deleteFileFromDB(path); 440 dblink->deleteFileFromDB(path);
428 populate(); 441 populate();
429 } 442 }
430 else { 443 else {
431 QMessageBox::warning(tw, "Delete failed", QString("Could not delete \"%1\"?").arg(file.fileName())); 444 QMessageBox::warning(tw, "Delete failed",
445 QString("Could not delete \"%1\"?")
446 .arg(file.fileName()));
432 } 447 }
433 } 448 }
434 } 449 }
435 450
436 451
438 { 453 {
439 QUrl url = QUrl::fromLocalFile(item->data(0, 32).toString()); 454 QUrl url = QUrl::fromLocalFile(item->data(0, 32).toString());
440 QDesktopServices::openUrl(url); 455 QDesktopServices::openUrl(url);
441 } 456 }
442 457
443 void DataController::setup(const QString& dbpath_in, const QString& searchPath_in, bool showGUI) 458 void DataController::setup(const QString& dbpath_in,
459 const QString& searchPath_in, bool showGUI)
444 { 460 {
445 this->showGUI = showGUI; 461 this->showGUI = showGUI;
446 462
447 contextMenu = 0; 463 contextMenu = 0;
448 464
449 connect(this, SIGNAL(populateProgress(int)), this, SLOT(progressUpdate(int))); 465 connect(this, SIGNAL(populateProgress(int)),
466 this, SLOT(progressUpdate(int)));
450 467
451 QString dbpath; 468 QString dbpath;
452 if (dbpath_in.size() > 0) { 469 if (dbpath_in.size() > 0) {
453 dbpath = dbpath_in; 470 dbpath = dbpath_in;
454 } 471 }