#include #include #include #include #include #include #include #include #include #include #include #include #include #include "shemovcleaner.h" #include "torrentwidget.h" #include "filewidget.h" #include "torrentdisplay.h" #include "configurationwidget.h" ShemovCleaner::ShemovCleaner(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent, f) { //general setup qApp->setWindowIcon(QIcon(":/clean_tampon.png")); setMinimumWidth(800); setMinimumHeight(600); openDatabase(); mTorrentTab = new TorrentWidget; mTab = new QTabWidget; mFileTab = new FileWidget; mTab->addTab(mTorrentTab, tr("Torrents")); mTab->addTab(mFileTab, tr("Files")); setCentralWidget(mTab); createStatusBar(); createActions(); connect(mTorrentTab, SIGNAL(statusMessage(QString)), this, SLOT(statusBarMessage(QString))); connect(mTorrentTab, SIGNAL(selectionCountChanged(QString)), this, SLOT(setSelectionCount(QString))); connect(mFileTab, SIGNAL(statusMessage(QString)), this, SLOT(statusBarMessage(QString))); connect(mFileTab, SIGNAL(selectionCountChanged(QString)), this, SLOT(setSelectionCount(QString))); connect(mFileTab, SIGNAL(durationChanged(QString)), this, SLOT(setDuration(QString))); connect(mTab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); QSettings s; restoreGeometry(s.value("geometry").toByteArray()); } void ShemovCleaner::statusBarMessage(const QString &msg){ statusBar()->showMessage(msg); } void ShemovCleaner::setDuration(const QString &msg){ mDuration->setText(msg); } void ShemovCleaner::setSelectionCount(const QString &msg){ mSelected->setText(msg); } void ShemovCleaner::configure(){ ConfigurationWidget w(this); int res = w.exec(); if(res == QDialog::Accepted){ openDatabase(); } } void ShemovCleaner::tabChanged(int idx){ if(idx == Torrents){ mTorrentTab->fileSelectionChanged(QItemSelection(), QItemSelection()); setDuration("00:00:00"); }else if(idx == Videos){ mFileTab->fileSelectionChanged(QItemSelection(), QItemSelection()); } } void ShemovCleaner::closeEvent(QCloseEvent *e){ QSettings s; s.setValue("geometry", saveGeometry()); QMainWindow::closeEvent(e); } void ShemovCleaner::createStatusBar(){ QLabel *l1 = new QLabel(tr("Sel.")); mSelected = new QLabel("000/000"); mSelected->setFrameStyle(QFrame::Panel | QFrame::Sunken); QLabel *l2 = new QLabel(tr("Dur.")); mDuration = new QLabel("00:00:00"); mDuration->setFrameStyle(QFrame::Panel | QFrame::Sunken); statusBar()->addPermanentWidget(l1); statusBar()->addPermanentWidget(mSelected); statusBar()->addPermanentWidget(l2); statusBar()->addPermanentWidget(mDuration); } void ShemovCleaner::createActions(){ //Application QAction *quitA = new QAction(tr("Quit"), this); connect(quitA, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); QAction *configA = new QAction(QIcon(":/chastity_belt.png"), tr("Configure..."), this); connect(configA, SIGNAL(triggered()), this, SLOT(configure())); //TorrentWidget mTorRefreshA = new QAction(QIcon(":/refresh.png"), tr("Refresh"), this); connect(mTorRefreshA, SIGNAL(triggered()), mTorrentTab, SLOT(gatherData())); mTorDeleteA = new QAction(QIcon(":/delete.png"), tr("Delete..."), this); connect(mTorDeleteA, SIGNAL(triggered()), mTorrentTab, SLOT(deleteFiles())); mTorMoveA = new QAction(QIcon(":/diaper.png"), tr("Move..."), this); connect(mTorMoveA, SIGNAL(triggered()), mTorrentTab, SLOT(moveFiles())); mTorInfoA = new QAction(QIcon(":/huge_bra.png"), tr("Torrent info..."), this); connect(mTorInfoA, SIGNAL(triggered()), mTorrentTab, SLOT(torrentInfo())); mTorDirA = new QAction(QIcon(":/folder.png"), tr("Select folder..."), this); connect(mTorDirA, SIGNAL(triggered()), mTorrentTab, SLOT(selectDir())); mFnThisCopyToClipA = new QAction(QIcon(":/edit-copy.png"), tr("Copy"), this); connect(mFnThisCopyToClipA, SIGNAL(triggered()), mTorrentTab, SLOT(copyToClipboard())); mTorrentTab->toolBar()->addAction(mTorRefreshA); mTorrentTab->toolBar()->addAction(mFnThisCopyToClipA); mTorrentTab->toolBar()->addSeparator(); mTorrentTab->toolBar()->addAction(mTorDirA); mTorrentTab->toolBar()->addAction(mTorMoveA); mTorrentTab->toolBar()->addAction(mTorDeleteA); mTorrentTab->toolBar()->addSeparator(); mTorrentTab->toolBar()->addAction(mTorInfoA); mTorrentTab->toolBar()->addSeparator(); mTorrentTab->toolBar()->addAction(configA); QMenu *torFileM = new QMenu(tr("File")); torFileM->addAction(mTorDirA); torFileM->addAction(mTorRefreshA); torFileM->addSeparator(); torFileM->addAction(quitA); mTorrentTab->menuBar()->addMenu(torFileM); QMenu *torEditM = new QMenu(tr("Edit")); torEditM->addAction(mTorInfoA); torEditM->addSeparator(); torEditM->addAction(mTorRefreshA); torEditM->addAction(mFnThisCopyToClipA); torEditM->addSeparator(); torEditM->addAction(mTorMoveA); torEditM->addAction(mTorDeleteA); torEditM->addSeparator(); torEditM->addAction(mTorDirA); torEditM->addSeparator(); torEditM->addAction(configA); torEditM->addSeparator(); torEditM->addAction(mTorInfoA); mTorrentTab->menuBar()->addMenu(torEditM); mTorrentTab->addAction(mTorInfoA); mTorrentTab->addAction(createSeparator()); mTorrentTab->addAction(mTorRefreshA); mTorrentTab->addAction(mFnThisCopyToClipA); mTorrentTab->addAction(createSeparator()); mTorrentTab->addAction(mTorMoveA); mTorrentTab->addAction(mTorDeleteA); mTorrentTab->addAction(createSeparator()); mTorrentTab->addAction(mTorDirA); mTorCopyToClipA = new QAction(QIcon(":/edit-copy.png"), tr("Copy"), this); connect(mTorCopyToClipA, SIGNAL(triggered()), mTorrentTab->torrentDisplay(), SLOT(copyToClipboard())); mTorrentTab->torrentDisplay()->addAction(mTorCopyToClipA); } void ShemovCleaner::openDatabase(){ QSettings s; QString dbhost = s.value("dbhost").toString(); QString dbuser = s.value("dbuser").toString(); QString dbpass = s.value("dbpass").toString(); QString dbname = s.value("dbname").toString(); if(!QSqlDatabase::contains("shemovdb")){ QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "shemovdb"); db.setHostName(dbhost); db.setUserName(dbuser); db.setPassword(dbpass); db.setDatabaseName(dbname); if(!db.open()){ int res = ConfigurationWidget(this).exec(); if(res == QDialog::Accepted){ openDatabase(); }else{ QMessageBox::critical(this, tr("Error"), tr("Could not open database. Giving up!")); qApp->closeAllWindows(); } } } } QAction *ShemovCleaner::createSeparator(){ QAction *retval = new QAction(this); retval->setSeparator(true); return retval; }