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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.
*/
#include <QApplication>
#include <QVBoxLayout>
#include <QMenuBar>
#include <QStatusBar>
#include <QLabel>
#include <QSettings>
#include <QMessageBox>
#include <QCloseEvent>
#include <QToolBar>
#include <QSplashScreen>
#include <sys/vfs.h>
#include "shemov.h"
#include "configurationdialog.h"
#include "statisticsdialog.h"
#include "smglobals.h"
#include "newmoviewizard.h"
#include "consistencycheck.h"
#include "mappingtableeditor.h"
#include "mappingtablemodel.h"
#include "dbanalyzer.h"
#include "newpicsdialog.h"
#include "pictureswidget.h"
#include "picturelistview.h"
#include "archiveview.h"
#include "archivebrowser.h"
#include "searchdialog.h"
#include "randomtab.h"
#include "fswidget.h"
#include "moviewidget.h"
#include "helper.h"
SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) {
//application icon
qApp->setWindowIcon(QIcon(":/shemov.png"));
createPalette();
setAttribute(Qt::WA_DeleteOnClose);
QSplashScreen splash(QPixmap(":/shemov_splash2.png"));
splash.show();
//init database as early as possible
splash.showMessage(tr("Initializing globals..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
(void) SmGlobals::instance();
mAnalyzeActorsA = new QAction(tr("Actors..."), this);
connect(mAnalyzeActorsA, &QAction::triggered, this, &SheMov::analyzeActors);
mAnalyzeGenresA = new QAction(tr("Genres..."), this);
connect(mAnalyzeGenresA, &QAction::triggered, this, &SheMov::analyzeGenres);
mAnalyzeSeriesA = new QAction(tr("Series..."), this);
connect(mAnalyzeSeriesA, &QAction::triggered, this, &SheMov::analyzeSeries);
mAnalyzePartsA = new QAction(tr("Series Parts..."), this);
connect(mAnalyzePartsA, &QAction::triggered, this, &SheMov::analyzeParts);
mConsistencyA = new QAction(tr("Check consisteny..."), this);
connect(mConsistencyA, &QAction::triggered, this, &SheMov::checkConsistency);
/*mSearchDialogA = new QAction(tr("Search..."), this);
mSearchDialogA->setShortcut(tr("CTRL+f"));
connect(mSearchDialogA, &QAction::triggered, mSearchDialog, &SearchDialog::show);*/
mQuitA = new QAction(tr("Quit"), this);
mQuitA->setShortcut(tr("CTRL+q"));
connect(mQuitA, &QAction::triggered, qApp, &QApplication::closeAllWindows);
mConfigA = new QAction(QIcon(":/chastity_belt.png"), tr("Configure..."), this);
connect(mConfigA, &QAction::triggered, this, &SheMov::configure);
QString aboutLabel = QString(tr("About %1...")).arg(qApp->applicationName());
mAboutShemovA = new QAction(aboutLabel, this);
connect(mAboutShemovA, &QAction::triggered, this, &SheMov::aboutShemov);
mAboutQtA = new QAction(tr("About Qt..."), this);
connect(mAboutQtA, &QAction::triggered, qApp, &QApplication::aboutQt);
mStatisticsA = new QAction(tr("Some statistics..."), this);
connect(mStatisticsA, &QAction::triggered, this, &SheMov::showStatistics);
//global menu
QColor fgColor = qApp->palette().color(QPalette::Text);
QAction *globalMenuA = new QAction(Helper::icon(QColor(0, 0, 0, 0), fgColor, QChar(0x26A4), true, false), tr("Global"), this);
QMenu *globalMenu = new QMenu;
globalMenu->addAction(mConsistencyA);
globalMenu->addSeparator();
QMenu *analyzeMenu = new QMenu;
analyzeMenu->addAction(mAnalyzeActorsA);
analyzeMenu->addAction(mAnalyzeGenresA);
analyzeMenu->addAction(mAnalyzePartsA);
analyzeMenu->addAction(mAnalyzeSeriesA);
QAction *analyzeMenuA = new QAction(tr("Analyze"), this);
analyzeMenuA->setMenu(analyzeMenu);
globalMenu->addAction(analyzeMenuA);
globalMenu->addSeparator();
globalMenu->addAction(mConfigA);
globalMenu->addAction(mStatisticsA);
globalMenu->addSeparator();
globalMenu->addAction(mAboutQtA);
globalMenu->addAction(mAboutShemovA);
globalMenu->addSeparator();
globalMenu->addAction(mQuitA);
globalMenuA->setMenu(globalMenu);
SmGlobals::instance()->setGlobalAction(globalMenuA);
//FileSystemWidget + TabWidget
splash.showMessage(tr("Constructing Filemanager..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
mTab = new QTabWidget;
mFileWidget = new FSWidget;
mTab->addTab(mFileWidget, tr("FS"));
connect(mFileWidget, &FSWidget::message, this, &SheMov::statusbarMessage);
connect(mFileWidget, &FSWidget::selectionChanged, [=](int count, qint64 size, qint64 duration) {
updateSelectedCount(count);
setSize(size);
setDuration(duration, false);
});
connect(mFileWidget, &FSWidget::needRefreshFs, this, &SheMov::setFsFree);
connect(mFileWidget, &FSWidget::needConfig, this, &SheMov::configure);
connect(mFileWidget, &FSWidget::needTitleChange, this, &SheMov::setWindowTitle);
//MovieWidget
splash.showMessage(tr("Constructing MovieWidget..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
mMovieWidget = new MovieWidget;
mTab->addTab(mMovieWidget, "MW");
connect(mMovieWidget, &MovieWidget::needTitleChange, this, &SheMov::setWindowTitle);
//pictures
splash.showMessage(tr("Creating Picture Archive..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
mPicWidget = new PicturesWidget;
mTab->addTab(mPicWidget, tr("Pictures"));
connect(mPicWidget, &PicturesWidget::needWindowTitleChange, this, &SheMov::setWindowTitle);
connect(mPicWidget->picView(), &PictureListView::newMappings, this, &SheMov::statusbarMessage);
connect(mPicWidget->picView(), &PictureListView::numSelected, this, &SheMov::updateSelectedCount);
connect(mPicWidget->picView(), &PictureListView::selectedSize, this, &SheMov::setSize);
PictureViewer2 *picViewer = SmGlobals::instance()->pictureViewer();
//archivebrower
splash.showMessage(tr("Creating Archive Browser..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
mArchiveBrowser = new ArchiveBrowser;
mTab->addTab(mArchiveBrowser, tr("Archive Browser"));
connect(mArchiveBrowser, &ArchiveBrowser::sizeChanged, this, &SheMov::setSize);
connect(mArchiveBrowser, &ArchiveBrowser::itemCountChanged, this, &SheMov::updateSelectedCount);
connect(mArchiveBrowser, &ArchiveBrowser::needFSFreeUpdate, this, &SheMov::setFsFree);
//randomtab
splash.showMessage(tr("Creating Random Browser..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
mRandomTab = new RandomTab;
connect(mRandomTab, &RandomTab::configure, this, &SheMov::configure);
mTab->addTab(mRandomTab, tr("Random"));
//misc dialogs
splash.showMessage(tr("Creating misc. Dialogs..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(mTab);
splash.showMessage(tr("Creating Menus and Statusbar..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
createStatusbar();
setFsFree();
splash.showMessage(tr("Finishing..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
connect(mTab, &QTabWidget::currentChanged, this, &SheMov::tabChanged);
connect(this, &SheMov::configChanged, picViewer, &PictureViewer2::readSettings);
connect(this, &SheMov::configChanged, mFileWidget, &FSWidget::readSettings);
QWidget *centralWidget = new QWidget;
centralWidget->setLayout(mainLayout);
setCentralWidget(centralWidget);
show();
splash.finish(this);
mPicWidget->readSettings();
mArchiveBrowser->readConfig();
readSettings();
setWindowState(Qt::WindowMaximized);
}
void SheMov::closeEvent(QCloseEvent *event){
mPicWidget->picViewer2()->writeSettings();
mPicWidget->writeSettings();
mArchiveBrowser->writeSettings();
writeSettings();
SmGlobals *globals = SmGlobals::instance();
delete globals;
QSqlDatabase::database("treedb").close();
qApp->closeAllWindows();
event->accept();
}
void SheMov::updateSelectedCount(int count){
mSelectedItems->setText(QString::number(count));
}
void SheMov::statusbarMessage(const QString &message){
statusBar()->showMessage(message);
}
void SheMov::configure(){
ConfigurationDialog dlg(this);
dlg.exec();
createPalette();
emit configChanged();
}
void SheMov::tabChanged(int newTab){
statusbarMessage(QString());
switch(newTab){
case FileManager:
setWindowTitle(mFileWidget->wTitle);
break;
case Movies:
setWindowTitle(mMovieWidget->wTitle);
break;
case Pictures:
mPicWidget->constructWindowTitle();
setDuration(0x0, false);
break;
case ArchiveBrowserTab:
setWindowTitle(tr("Archive Browser"));
break;
case RandomDisp:
setWindowTitle(tr("Random Browser"));
break;
default:
setDuration(0x0, false);
;;
}
}
void SheMov::setFsFree(){
struct statfs buf;
QSettings s;
QString dir = s.value("paths/archivedir").toString();
int success = statfs(qPrintable(dir), &buf);
if(success == -1){
mFsFree->setText(tr("Error"));
return;
}
long blocksize = buf.f_bsize;
unsigned long free = buf.f_bfree;
unsigned long avail = buf.f_blocks;
unsigned long used = avail - free;
qreal freep = free * 100.0 / avail;
qreal usedp = used * 100.0 / avail;
QFont f = qApp->font();
QFontMetrics fm(f);
int height = fm.height() + 3;
QImage img(100, height, QImage::Format_ARGB32);
img.fill(0);
QPainter p(&img);
p.setBrush(QBrush(Qt::red));
p.setPen(QPen(Qt::blue));
p.drawRect(QRectF(0, 0, usedp, height));
p.setBrush(QBrush(Qt::green));
p.drawRect(QRectF(usedp, 0, freep, height));
unsigned long freeb = free * static_cast<unsigned long>(blocksize);
qreal freegib = freeb / 1024.0 / 1024.0 / 1024.0;
int freeRounded = qRound(freegib);
QString freeString = QString("%1 GiB free").arg(QString::number(freeRounded));
QSize stringSize = fm.size(Qt::TextSingleLine, freeString);
int startx = (100 - stringSize.width()) / 2;
int starty = (height - stringSize.height()) / 2 + fm.ascent();
p.drawText(QPoint(startx, starty), freeString);
mFsFree->setPixmap(QPixmap::fromImage(img));
}
void SheMov::aboutShemov(){
QString aboutLabel = QString(tr("About %1")).arg(qApp->applicationName());
QString aboutText = QString(tr("<p>%1 is a little application to keep track of your pr0n movie collection, though it isn't limited to pr0n movies.</p>")).arg(qApp->applicationName());
aboutText.append("<table>");
aboutText.append(tr("<tr><td>Author<td></td>Sissy herself</td></tr>"));
aboutText.append(QString(tr("<tr><td>Organization</td><td>%1</td></tr>")).arg(qApp->organizationName()));
aboutText.append(QString(tr("<tr><td>Version</td><td>%1</td></tr>")).arg(qApp->applicationVersion()));
aboutText.append(QString(tr("<tr><td>Build:</td><td>/* __debug build__ */</td></tr>")));
aboutText.append(tr("<tr><td>Dependencies</td><td><ul>"));
aboutText.append(tr("<li>Qt (thanks for this great library)</li>"));
aboutText.append(tr("<li>libmagic for figuring out the file type</li>"));
aboutText.append("</ul></tr></table>");
QMessageBox::about(this, aboutLabel, aboutText);
}
void SheMov::showStatistics(){
StatisticsDialog dlg(this);
dlg.exec();
}
void SheMov::setSize(qint64 size){
QLocale l;
QString val;
qint64 free = DVDSIZE - size;
QString selectedSize = l.toString(size);
QString freeSize = l.toString(free);
if(size < DVDSIZE){
val = QString("<span style=\"color:#008000\">%1 (%2)</span>").arg(selectedSize).arg(freeSize);
}else{
val = QString("<span style=\"color:#ff0000\">%1 (%2)</span>").arg(selectedSize).arg(freeSize);
}
mSelectedSize->setText(val);
}
void SheMov::setDuration(qint64 dur, bool maybeMore){
Helper::Duration d(dur);
QString t = d.toString();
if(maybeMore){
t.append("+");
}
mSelectedDuration->setText(t);
}
void SheMov::createStatusbar(){
QLabel *selDurL = new QLabel(tr("Duration"));
mSelectedDuration = new QLabel("00:00:00");
mSelectedDuration->setFrameStyle(QFrame::Panel | QFrame::Sunken);
statusBar()->addPermanentWidget(selDurL);
statusBar()->addPermanentWidget(mSelectedDuration);
QLabel *selSizeL = new QLabel(tr("Sel. Size"));
mSelectedSize = new QLabel(tr("nothing selected yet"));
mSelectedSize->setFrameStyle(QFrame::Panel | QFrame::Sunken);
statusBar()->addPermanentWidget(selSizeL);
statusBar()->addPermanentWidget(mSelectedSize);
QLabel *selCountL = new QLabel(tr("Sel. Items"));
mSelectedItems = new QLabel("0");
mSelectedItems->setFrameStyle(QFrame::Panel | QFrame::Sunken);
statusBar()->addPermanentWidget(selCountL);
statusBar()->addPermanentWidget(mSelectedItems);
QLabel *freeL = new QLabel(tr("Free space"));
mFsFree = new QLabel(tr("calculating..."));
mFsFree->setFrameStyle(QFrame::Panel | QFrame::Sunken);
statusBar()->addPermanentWidget(freeL);
statusBar()->addPermanentWidget(mFsFree);
}
void SheMov::writeSettings(){
QSettings s;
s.setValue("ui/selectedtab", mTab->currentIndex());
}
void SheMov::readSettings(){
QSettings s;
int currentTab = s.value("ui/selectedtab", 0).toInt();
if(currentTab < mTab->count() && currentTab != mTab->currentIndex()){
mTab->setCurrentIndex(currentTab);
}
tabChanged(currentTab);
createPalette();
}
void SheMov::createPalette(){
QSettings s;
bool alternate = s.value("ui/allowalternate").toBool();
QPalette pal(palette());
if(alternate){
QVariant basecolor = s.value("ui/basecolor");
QVariant alternatecolor = s.value("ui/alternatecolor");
pal.setColor(QPalette::Base, basecolor.value<QColor>());
pal.setColor(QPalette::AlternateBase, alternatecolor.value<QColor>());
}else{
pal.setColor(QPalette::Base, Qt::white);
pal.setColor(QPalette::AlternateBase, Qt::white);
}
qApp->setPalette(pal);
}
void SheMov::analyzeActors(){
EmptyActorsDialog d(tr("Actors"), this);
d.populate();
d.exec();
}
void SheMov::analyzeGenres(){
EmptyGenresDialog d(tr("Genres"), this);
d.populate();
d.exec();
}
void SheMov::analyzeSeries(){
EmptySeriesDialog d(tr("Series"), this);
d.populate();
d.exec();
}
void SheMov::analyzeParts(){
EmptyPartsDialog d(tr("Series Parts"), this);
d.populate();
d.exec();
}
void SheMov::checkConsistency(){
ConsistencyCheck c;
c.exec();
}
void SheMov::toggleHover(QObject *object){
QAction *action = qobject_cast<QAction*>(object);
if(action){
QSettings s;
QString toSet = action->data().toString();
bool checked = action->isChecked();
s.setValue(toSet, checked);
emit configChanged();
}
}
|