Mercurial > dedupe
diff 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 |
line wrap: on
line diff
--- a/DataController.cpp Tue Aug 21 15:09:22 2012 +0200 +++ b/DataController.cpp Tue Aug 21 15:27:29 2012 +0200 @@ -276,24 +276,19 @@ this->dir = dir.absolutePath(); } -DataController::DataController() : showFullPath(false) +void DataController::buildDB(const QDir& dir) +{ + findFiles(dir, *dblink); +} + + +void DataController::setupGUI() { populateDelay = new QTimer(this); populateDelay->setSingleShot(true); populateDelay->setInterval(500); connect(populateDelay, SIGNAL(timeout()), this, SLOT(populate())); - QString dbpath = DB_DEFAULT_LOCATION; - - dbpath.replace(QRegExp("^~/"), - QString("%1%2").arg(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)).arg(QDir::separator())); - - dblink = new SqliteDBLink(dbpath); - - setDir(QDir(".")); - - findFiles(dir, *dblink); - mw = new QMainWindow(); QMenuBar* mb = new QMenuBar(); @@ -346,16 +341,50 @@ tw->setHeaderLabels(QString("Path;Size;Date;Checksum").split(";")); - populate(); - tw->setSortingEnabled(true); tw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); tw->setSelectionBehavior(QAbstractItemView::SelectRows); //tw->resizeColumnsToContents(); mw->resize(800,800); mw->show(); +} +DataController::DataController(const QString& path, bool showGUI) +{ + setup(QString(), path, showGUI); +} + +DataController::DataController(bool showGUI) +{ + setup(QString(), QString(), showGUI); +} + +void DataController::setup(const QString& dbpath_in, const QString& searchPath_in, bool showGUI) +{ + QString dbpath; + if (dbpath_in.size() > 0) { + dbpath = dbpath_in; + } + else { + dbpath = DB_DEFAULT_LOCATION; + + dbpath.replace(QRegExp("^~/"), + QString("%1%2").arg(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)).arg(QDir::separator())); + } + + dblink = new SqliteDBLink(dbpath); + + setDir((searchPath_in.size() > 0) ? searchPath_in : QDir(".")); + + showFullPath = false; + + if (showGUI) + setupGUI(); + buildDB(dir); + if (showGUI) + populate(); + } DataController::~DataController()
