comparison DataController.cpp @ 93:308a718812ba

Small refactoring to allow lazy commits.
author Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no>
date Tue, 22 Oct 2013 11:53:54 +0200
parents cfd2a417475a
children c7da835ea912
comparison
equal deleted inserted replaced
92:f49023c61dac 93:308a718812ba
97 connect(this, SIGNAL(populateProgress(int)), 97 connect(this, SIGNAL(populateProgress(int)),
98 bar.get(), SLOT(setValue(int))); 98 bar.get(), SLOT(setValue(int)));
99 } 99 }
100 100
101 int n = 0; 101 int n = 0;
102 emit populateProgress(n); 102 int max = paths.size();
103 emit populateProgress(n, max);
103 104
104 foreach(QString filename, paths) { 105 foreach(QString filename, paths) {
105 try { 106 try {
106 dblink.updateIfModified(filename); 107 dblink.updateIfModified(filename, true);
107 } 108 }
108 catch (const PermissionException& e) { 109 catch (const PermissionException& e) {
109 dblink.deleteFileFromDB(filename); 110 dblink.deleteFileFromDB(filename);
110 } 111 }
111 catch (const IOException& e) { 112 catch (const IOException& e) {
115 } 116 }
116 catch (Exception& e) { 117 catch (Exception& e) {
117 e.raise(); 118 e.raise();
118 } 119 }
119 120
120 emit populateProgress(++n); 121 emit populateProgress(++n, max);
121 122
122 QDateTime now = QDateTime::currentDateTime(); 123 QDateTime now = QDateTime::currentDateTime();
123 if (last.msecsTo(now) > 1000) { 124 if (last.msecsTo(now) > 1000) {
124 QCoreApplication::processEvents(); 125 QCoreApplication::processEvents();
125 last = now; 126 last = now;
126 } 127 }
127 } 128 }
129 dblink.commit();
128 130
129 } 131 }
130 132
131 133
132 QTreeWidgetItem* DataController::createItem(const FileDBLink::DBInfo& info) 134 QTreeWidgetItem* DataController::createItem(const FileDBLink::DBInfo& info)
183 185
184 QMultiMap<QString, QSharedPointer<FileDBLink::DBInfo> > nameLUP; 186 QMultiMap<QString, QSharedPointer<FileDBLink::DBInfo> > nameLUP;
185 QMultiMap<quint64, QSharedPointer<FileDBLink::DBInfo> > sizeLUP; 187 QMultiMap<quint64, QSharedPointer<FileDBLink::DBInfo> > sizeLUP;
186 QMultiMap<QDateTime, QSharedPointer<FileDBLink::DBInfo> > mtimeLUP; 188 QMultiMap<QDateTime, QSharedPointer<FileDBLink::DBInfo> > mtimeLUP;
187 QMultiMap<QByteArray, QSharedPointer<FileDBLink::DBInfo> > checksumLUP; 189 QMultiMap<QByteArray, QSharedPointer<FileDBLink::DBInfo> > checksumLUP;
190
191 int max = elems.size() - 1;
188 192
189 foreach(QSharedPointer<FileDBLink::DBInfo> line, elems) { 193 foreach(QSharedPointer<FileDBLink::DBInfo> line, elems) {
190 if (showNameDups) { 194 if (showNameDups) {
191 nameLUP.insertMulti(line->name(), line); 195 nameLUP.insertMulti(line->name(), line);
192 } 196 }
302 306
303 307
304 308
305 if (item) 309 if (item)
306 tw->addTopLevelItem(item); 310 tw->addTopLevelItem(item);
307 emit populateProgress(++n); 311 emit populateProgress(++n, max);
308 if (n % 64 == 0) { 312 if (n % 64 == 0) {
309 QCoreApplication::processEvents(); 313 QCoreApplication::processEvents();
310 } 314 }
311 } 315 }
312 tw->setUpdatesEnabled(true); 316 tw->setUpdatesEnabled(true);
420 DataController::DataController(bool showGUI) 424 DataController::DataController(bool showGUI)
421 { 425 {
422 setup(QString(), QString(), showGUI); 426 setup(QString(), QString(), showGUI);
423 } 427 }
424 428
425 void DataController::progressUpdate(int p) 429 void DataController::progressUpdate(int p, int max)
426 { 430 {
427 QString str; 431 QString str;
428 if (p == 0) 432 if (p == 0)
429 str.sprintf("Progress %6.2f%%", p * 100.0 / progressMax); 433 str.sprintf("Progress %6.2f%%", p * 100.0 / max);
430 else if (p == progressMax) { 434 else if (p == max) {
431 str.sprintf("\b\b\b\b\b\b\b%6.2f%%\n", 100.0); 435 str.sprintf("\b\b\b\b\b\b\b%6.2f%%\n", 100.0);
432 } 436 }
433 else { 437 else {
434 str.sprintf("\b\b\b\b\b\b\b%6.2f%%", p * 100.0 / progressMax); 438 str.sprintf("\b\b\b\b\b\b\b%6.2f%%", p * 100.0 / max);
435 } 439 }
436 std::cout<<str.toStdString(); 440 std::cout<<str.toStdString();
437 std::cout.flush(); 441 std::cout.flush();
442 }
443
444
445 void DataController::progressUpdate(int p)
446 {
447 progressUpdate(p, progressMax);
438 } 448 }
439 449
440 450
441 void DataController::deleteFile() 451 void DataController::deleteFile()
442 { 452 {
473 { 483 {
474 this->showGUI = showGUI; 484 this->showGUI = showGUI;
475 485
476 contextMenu = 0; 486 contextMenu = 0;
477 487
478 connect(this, SIGNAL(populateProgress(int)), 488 connect(this, SIGNAL(populateProgress(int, int)),
479 this, SLOT(progressUpdate(int))); 489 this, SLOT(progressUpdate(int)));
480 490
481 QString dbpath; 491 QString dbpath;
482 if (dbpath_in.size() > 0) { 492 if (dbpath_in.size() > 0) {
483 dbpath = dbpath_in; 493 dbpath = dbpath_in;
489 #if 1 499 #if 1
490 dblink = new SqliteDBLink(dbpath); 500 dblink = new SqliteDBLink(dbpath);
491 #else 501 #else
492 dblink = new MemoryDBLink(); 502 dblink = new MemoryDBLink();
493 #endif 503 #endif
504
505 connect(dblink, SIGNAL(progressUpdate(int, int)),
506 this, SLOT(progressUpdate(int, int)));
507
508
494 509
495 setDir((searchPath_in.size() > 0) ? searchPath_in : QDir(".")); 510 setDir((searchPath_in.size() > 0) ? searchPath_in : QDir("."));
496 511
497 showFullPath = false; 512 showFullPath = false;
498 513