1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#include <QTabWidget>
#include <QLabel>
#include <QStatusBar>
#include <QAction>
#include <QToolBar>
#include <QMenu>
#include <QMenuBar>
#include <QApplication>
#include <QSettings>
#include <QSqlDatabase>
#include <QMessageBox>
#include <QTreeView>
#include <QSettings>
#include <QKeyEvent>
#include <QProgressBar>
#include <QCloseEvent>
#include "shemovcleaner.h"
#include "torrentwidget.h"
#include "filewidget.h"
#include "torrentdisplay.h"
#include "configurationwidget.h"
#include "globals.h"
ShemovCleaner::ShemovCleaner(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent, f) {
//general setup
qApp->setWindowIcon(QIcon(":/clean_tampon.png"));
setMinimumWidth(800);
setMinimumHeight(600);
openDatabase();
createStatusBar();
createGlobalActions();
mTorrentTab = new TorrentWidget;
mTab = new QTabWidget;
mFileTab = new FileWidget;
mFileTab->setProgressBar(mProgressBar);
mFileTab->gatherData();
mTab->addTab(mTorrentTab, tr("&Torrents"));
mTab->addTab(mFileTab, tr("Fi&les"));
setCentralWidget(mTab);
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());
mTorrentTab->torrentFileView()->setFocus();
}
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());
mFileTab->fileView()->setFocus();
}
}
void ShemovCleaner::closeEvent(QCloseEvent *e){
int retval = QMessageBox::question(this, tr("Exit"), tr("Really close?"));
if(retval == QMessageBox::Yes){
QSettings s;
s.setValue("geometry", saveGeometry());
QMainWindow::closeEvent(e);
}else{
e->ignore();
}
}
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);
mProgressBar = new QProgressBar;
mProgressBar->setMaximumWidth(150);
mProgressBar->setMaximumHeight(10);
statusBar()->addPermanentWidget(mProgressBar);
statusBar()->addPermanentWidget(l1);
statusBar()->addPermanentWidget(mSelected);
statusBar()->addPermanentWidget(l2);
statusBar()->addPermanentWidget(mDuration);
}
void ShemovCleaner::createGlobalActions(){
QAction *quitA = new QAction(tr("Quit"), this);
quitA->setShortcut(tr("CTRL+Q"));
connect(quitA, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
quitA->setData(Globals::QuitAction);
Globals::instance()->addAction(quitA);
QAction *configA = new QAction(QIcon(":/chastity_belt.png"), tr("Configure..."), this);
connect(configA, SIGNAL(triggered()), this, SLOT(configure()));
configA->setData(Globals::ConfigAction);
Globals::instance()->addAction(configA);
}
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;
}
|