Mercurial > dedupe
comparison DataController.cpp @ 4:f489b0c9bf99
Refactored to allow commandline tools to use DataController.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Tue, 21 Aug 2012 15:27:29 +0200 |
| parents | 7a44ba08673d |
| children | 5e4985407feb |
comparison
equal
deleted
inserted
replaced
| 3:7a44ba08673d | 4:f489b0c9bf99 |
|---|---|
| 274 void DataController::setDir(const QDir& dir) | 274 void DataController::setDir(const QDir& dir) |
| 275 { | 275 { |
| 276 this->dir = dir.absolutePath(); | 276 this->dir = dir.absolutePath(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 DataController::DataController() : showFullPath(false) | 279 void DataController::buildDB(const QDir& dir) |
| 280 { | |
| 281 findFiles(dir, *dblink); | |
| 282 } | |
| 283 | |
| 284 | |
| 285 void DataController::setupGUI() | |
| 280 { | 286 { |
| 281 populateDelay = new QTimer(this); | 287 populateDelay = new QTimer(this); |
| 282 populateDelay->setSingleShot(true); | 288 populateDelay->setSingleShot(true); |
| 283 populateDelay->setInterval(500); | 289 populateDelay->setInterval(500); |
| 284 connect(populateDelay, SIGNAL(timeout()), this, SLOT(populate())); | 290 connect(populateDelay, SIGNAL(timeout()), this, SLOT(populate())); |
| 285 | |
| 286 QString dbpath = DB_DEFAULT_LOCATION; | |
| 287 | |
| 288 dbpath.replace(QRegExp("^~/"), | |
| 289 QString("%1%2").arg(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)).arg(QDir::separator())); | |
| 290 | |
| 291 dblink = new SqliteDBLink(dbpath); | |
| 292 | |
| 293 setDir(QDir(".")); | |
| 294 | |
| 295 findFiles(dir, *dblink); | |
| 296 | 291 |
| 297 mw = new QMainWindow(); | 292 mw = new QMainWindow(); |
| 298 QMenuBar* mb = new QMenuBar(); | 293 QMenuBar* mb = new QMenuBar(); |
| 299 | 294 |
| 300 QMenu* menu = mb->addMenu("&View"); | 295 QMenu* menu = mb->addMenu("&View"); |
| 344 mw->setCentralWidget(tw); | 339 mw->setCentralWidget(tw); |
| 345 tw->setEditTriggers(QAbstractItemView::NoEditTriggers); | 340 tw->setEditTriggers(QAbstractItemView::NoEditTriggers); |
| 346 | 341 |
| 347 tw->setHeaderLabels(QString("Path;Size;Date;Checksum").split(";")); | 342 tw->setHeaderLabels(QString("Path;Size;Date;Checksum").split(";")); |
| 348 | 343 |
| 349 populate(); | |
| 350 | |
| 351 tw->setSortingEnabled(true); | 344 tw->setSortingEnabled(true); |
| 352 tw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 345 tw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 353 tw->setSelectionBehavior(QAbstractItemView::SelectRows); | 346 tw->setSelectionBehavior(QAbstractItemView::SelectRows); |
| 354 //tw->resizeColumnsToContents(); | 347 //tw->resizeColumnsToContents(); |
| 355 mw->resize(800,800); | 348 mw->resize(800,800); |
| 356 mw->show(); | 349 mw->show(); |
| 357 | 350 } |
| 351 | |
| 352 | |
| 353 DataController::DataController(const QString& path, bool showGUI) | |
| 354 { | |
| 355 setup(QString(), path, showGUI); | |
| 356 } | |
| 357 | |
| 358 DataController::DataController(bool showGUI) | |
| 359 { | |
| 360 setup(QString(), QString(), showGUI); | |
| 361 } | |
| 362 | |
| 363 void DataController::setup(const QString& dbpath_in, const QString& searchPath_in, bool showGUI) | |
| 364 { | |
| 365 QString dbpath; | |
| 366 if (dbpath_in.size() > 0) { | |
| 367 dbpath = dbpath_in; | |
| 368 } | |
| 369 else { | |
| 370 dbpath = DB_DEFAULT_LOCATION; | |
| 371 | |
| 372 dbpath.replace(QRegExp("^~/"), | |
| 373 QString("%1%2").arg(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)).arg(QDir::separator())); | |
| 374 } | |
| 375 | |
| 376 dblink = new SqliteDBLink(dbpath); | |
| 377 | |
| 378 setDir((searchPath_in.size() > 0) ? searchPath_in : QDir(".")); | |
| 379 | |
| 380 showFullPath = false; | |
| 381 | |
| 382 if (showGUI) | |
| 383 setupGUI(); | |
| 384 buildDB(dir); | |
| 385 if (showGUI) | |
| 386 populate(); | |
| 358 | 387 |
| 359 } | 388 } |
| 360 | 389 |
| 361 DataController::~DataController() | 390 DataController::~DataController() |
| 362 { | 391 { |
