-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
264 lines (183 loc) · 7.13 KB
/
mainwindow.cpp
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
/*
This file is part of ILM.
ILM 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 3 of the License, or
(at your option) any later version.
ILM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ILM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qglobal.h"
#include "QFileDialog"
#include <QtNetwork>
#include <QCheckBox>
#include <QPushButton>
#include <QVariantList>
#include<QString>
#include "maiaXmlRpcClient.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//The player
player = new Phonon::VideoPlayer(Phonon::VideoCategory);
//The position slider
Phonon::SeekSlider *slider = new Phonon::SeekSlider;
slider->setMediaObject(player->mediaObject());
slider->show();
//The volume controll
Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
volumeSlider->setAudioOutput(player->audioOutput());
//First add the player
ui->VidWinMainVertical->addWidget(player,5);
//Then add slider
ui->VidWinMainVertical->addWidget(slider);
//Add the volume
ui->VidMinMainHor->addWidget(volumeSlider);
//Setup the icons(Provide fallback for windows)
//btw: here are the standard names as defined by freedesktop [http://standards.freedesktop.org/icon-naming-spec/latest/ar01s04.html]
//Fallback implemented in silk.qrc
static const char * GENERIC_ICON_TO_CHECK = "folder-new";
static const char * FALLBACK_ICON_THEME = "silk";
if (!QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK)) {
//If there is no default working icon theme then we should
//use an icon theme that we provide via a .qrc file
//This case happens under Windows and Mac OS X
//This does not happen under GNOME or KDE
QIcon::setThemeName(FALLBACK_ICON_THEME);
}
QIcon refreshIcon = QIcon::fromTheme("folder-new");
ui->actionRefresh->setIcon(refreshIcon);
//Setup the icopn for the play button
ui->btnPreviewPlay->setIcon(QIcon::fromTheme("media-playback-start"));
ui->btnPrevieStop->setIcon(QIcon::fromTheme("media-playback-stop"));
//Setup the QStringList that will keep the types of movies that should be loaded
strlstMovieTypes = new QStringList();
strlstMovieTypes->append("*.avi");
//Setup the settings class
settings = new QSettings();
//Hide the loading progress bar
ui->pbLoading->hide();
//Setup the database
myData = new DataProvider();
//Get the model for our one and only table and set to tblMoviesSql
ui->tblMoviesSql->setModel(myData->getModel());
ui->tblMoviesSql->resizeColumnsToContents();
ui->tblMoviesSql->horizontalHeader()->setStretchLastSection( true );
//Make sure the windows is mazimized
this->setWindowState(Qt::WindowMaximized);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionE_xit_triggered()
{
//Close the application
this->close();
}
void MainWindow::on_actionRefresh_triggered()
{
//Ask user to select directory
//TODO: Not using settings anymore !!!!
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Movie Directory"),settings->value("MovieDir","/home").toString(),QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks);
//We must load all the movies files in the directory that the user selected
QDir *dirCurrent = new QDir(dir);
//Write open dir to Watch table. If false is returned the folder is already part of the watch list yo"
bool load = myData->addWatchFolder(dir);
//Call scanfolder that wil go looki looki snooki rap husssle
if(load){
//QFuture<void> future = QtConcurrent::run(this, &MainWindow::scanFolder,dirCurrent); //Once off thread
scanFolder(dirCurrent);
}
}
void MainWindow::scanFolder(QDir *scanme)
{
QList <QFileInfo> filstFiles(scanme->entryInfoList(*strlstMovieTypes, QDir::Files | QDir::NoSymLinks));
//First step put myData in Insert mode (This has to do with speed improvements) we want to wrap all in one Transaction
myData->startBigTransaction();
foreach (const QFileInfo &i, filstFiles) {
myData->addVirginMovie(i.fileName(),i.absoluteFilePath());
}
myData->endBigTransaction();
ui->tblMoviesSql->resizeColumnsToContents();
}
void MainWindow::on_actionMovie_Information_triggered()
{
//If the user closed ui->dckWdgtMovieInfo show it again
ui->dckWdgtMovieInfo->showNormal();
}
void MainWindow::on_wbVwMovieInfi_loadStarted()
{
//Show the progress bar
ui->pbLoading->show();
}
void MainWindow::on_wbVwMovieInfi_loadProgress(int progress)
{
//Update the progress bar
ui->pbLoading->setValue(progress);
}
void MainWindow::on_wbVwMovieInfi_loadFinished(bool )
{
ui->pbLoading->hide();
}
void MainWindow::on_tblMoviesSql_clicked(QModelIndex index)
{
//Get the filename
QString name = index.sibling(index.row(),1).data(Qt::DisplayRole).toString();
//Get the full path
QString path = index.sibling(index.row(),3).data(Qt::DisplayRole).toString();
//Set the name of the preview for the preview window
ui->lblPreViewTitle->setText(name);
//Set the correct vid path for when the preview play button is clicked
player->load(Phonon::MediaSource(path));
//Remove the ext
name = name.remove(name.count()-4,4);
//Test the XMLrpc client
MaiaXmlRpcClient *rpcClient = new MaiaXmlRpcClient(QUrl("http://api.opensubtitles.org/xml-rpc "), this);
QVariantList args;
// args << 5;
//args << "this is a string, no, not what you think :>";
rpcClient->call("ServerInfo()", args,
this, SLOT(myResponseMethod(QVariant&)),
this, SLOT(myFaultResponse(int, const QString &)));
//Set the cache
//QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
//Cache directory should be the current movie directory
//diskCache->setCacheDirectory(settings->value("MovieDir").toString());
//ui->wbVwMovieInfi->page()->networkAccessManager()->setCache(diskCache);
//Set the search URL
//ui->wbVwMovieInfi->setUrl(QUrl("http://www.themoviedb.org/search?search="+name));
}
void MainWindow::myResponseMethod(QVariant &arg) {
// do something with the arg
}
void MainWindow::myFaultResponse(int error, const QString &message) {
qDebug() << "An Error occoured, Code: " << error << " Message: " << message;
}
void MainWindow::on_btnPreviewPlay_clicked()
{
player->play();
}
void MainWindow::on_btnPrevieStop_clicked()
{
player->stop();
}
void MainWindow::on_action_About_triggered()
{
//Show a nice about box
About *awin = new About(this);
awin->show();
}
void MainWindow::on_actionMovie_Preview_triggered()
{
//Show the movie preview windows again
ui->vidWindow->showNormal();
}