summaryrefslogtreecommitdiffstats
path: root/shemovcleaner.cpp
blob: 59653aeb3a32f4837d1a577b49ecaaa8687bf0fa (plain)
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
154
155
156
157
#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 "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)));
}

void ShemovCleaner::statusBarMessage(const QString &msg){
    statusBar()->showMessage(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::createStatusBar(){
    QLabel *l1 = new QLabel(tr("Sel."));
    mSelected = new QLabel("000/000");
    mSelected->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    statusBar()->addPermanentWidget(l1);
    statusBar()->addPermanentWidget(mSelected);
}

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();
    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;
}