1
/* BEGIN_COMMON_COPYRIGHT_HEADER
4
* Copyright: 2012 Labo A.L
6
* Aaron Lewis <the.warl0ck.1989@gmail.com>
8
* This program or library is free software; you can redistribute it
9
* and/or modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General
19
* Public License along with this library; if not, write to the
20
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
* Boston, MA 02110-1301 USA
23
* END_COMMON_COPYRIGHT_HEADER */
24
#include "mainwindow.h"
25
#include "ui_mainwindow.h"
27
#define HIDE_TRANSCRIPTS(ok) do { \
28
ui->transcript->setVisible(ok); \
29
ui->lineWidget->setVisible(ok); \
32
MainWindow::MainWindow(QWidget *parent) :
34
ui(new Ui::MainWindow),
36
m_filterModel (new QSortFilterProxyModel (this)),
37
m_model (new QStandardItemModel (this))
40
ui->centralWidget->setCurrentIndex(0);
42
QAction *copyURL_action = new QAction (tr("Copy video URL"), this);
43
connect (copyURL_action, SIGNAL(triggered()), this, SLOT(copyDownloadURL()));
44
ui->programeListView->addAction(copyURL_action);
46
HIDE_TRANSCRIPTS(false);
48
ui->programeListView->setModel(m_filterModel);
49
m_filterModel->setSourceModel(m_model);
50
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
52
ui->statusLabel->setMovie(new QMovie (":/images/loading.gif"));
53
ui->statusLabel->movie()->start();
55
ui->mplayer->setSeekSlider(ui->seekSlider);
56
ui->mplayer->setVolumeSlider(ui->volumeSlider);
57
ui->mplayer->setStatusBar(ui->statusBar);
59
connect (ui->mplayer, SIGNAL(stateChanged(int)) , this, SLOT(mplayerStateChanged(int)));
60
connect (ui->volumeSlider, SIGNAL(sliderPressed()), this, SLOT(update_volume_icon()));
63
m_providers.append(new TedProvider (m_model, this));
64
m_providers.append(new SciAmericanProvider (m_model, this));
66
foreach (Provider *p, m_providers)
68
connect (p, SIGNAL(loaded()), this, SLOT(loadCompleted()));
72
ui->actionRefresh->trigger();
75
MainWindow::~MainWindow()
80
void MainWindow::copyDownloadURL()
82
QModelIndex idx = ui->programeListView->currentIndex();
85
QClipboard *clip = QApplication::clipboard();
86
clip->setText(m_filterModel->data(idx, Qt::UserRole).toString());
90
void MainWindow::loadCompleted()
93
if ( m_completed_cnt == m_providers.size() )
95
ui->statusLabel->hide();
99
void MainWindow::on_stopButton_clicked()
104
void MainWindow::on_playPauseButton_clicked()
106
if ( ui->mplayer->state() == QMPwidget::NotStartedState)
107
ui->mplayer->start();
109
if ( ui->mplayer->state() == QMPwidget::PlayingState )
111
ui->mplayer->pause();
119
void MainWindow::mplayerStateChanged(int s)
121
if ( s == QMPwidget::PlayingState )
123
ui->playPauseButton->setIcon(QIcon(":/images/media-playback-pause.png"));
127
ui->playPauseButton->setIcon(QIcon(":/images/media-playback-start.png"));
131
void MainWindow::on_muteButton_toggled(bool checked)
135
m_vol = ui->volumeSlider->value();
136
ui->muteButton->setIcon(QIcon(":/images/audio-volume-muted.png"));
137
ui->volumeSlider->setValue(0);
141
ui->volumeSlider->setValue(m_vol);
142
update_volume_icon();
146
void MainWindow::update_volume_icon()
148
m_vol = ui->volumeSlider->value();
151
ui->muteButton->setIcon(QIcon(":/images/audio-volume-high.png"));
153
else if ( m_vol > 50 )
155
ui->muteButton->setIcon(QIcon(":/images/audio-volume-medium.png"));
157
else if ( m_vol > 0 )
159
ui->muteButton->setIcon(QIcon(":/images/audio-volume-low.png"));
163
ui->muteButton->setIcon(QIcon(":/images/audio-volume-muted.png"));
167
void MainWindow::on_actionRefresh_triggered()
170
ui->statusLabel->show();
173
foreach (Provider *p, m_providers)
179
void MainWindow::on_actionToggleView_triggered(bool checked)
181
ui->centralWidget->setCurrentIndex( checked ? 1 : 0 );
184
void MainWindow::closeEvent(QCloseEvent *)
189
void MainWindow::on_programeListView_doubleClicked(const QModelIndex &index)
191
if ( index.isValid() )
193
const QMap<int,QVariant> mapping = m_filterModel->itemData(index);
194
if ( mapping.contains(Qt::UserRole + OFFSET_TRANSCRIPT) )
196
HIDE_TRANSCRIPTS(true);
197
ui->transcript->setHtml(mapping.value(Qt::UserRole + OFFSET_TRANSCRIPT).toString());
200
HIDE_TRANSCRIPTS(false);
202
ui->mplayer->setVisible( ui->transcript->isHidden() );
204
ui->actionToggleView->trigger();
206
if ( ui->mplayer->state() == QMPwidget::NotStartedState)
207
ui->mplayer->start();
209
ui->mplayer->load(mapping.value(Qt::UserRole).toString());
213
void MainWindow::on_subtitleFilter_textChanged(const QString &arg1)
215
m_filterModel->setFilterWildcard(arg1);
218
void MainWindow::on_searchTextLine_textChanged(const QString &arg1)
221
ui->transcript->moveCursor(QTextCursor::Start);
222
on_lookForward_clicked();
225
void MainWindow::on_lookForward_clicked()
227
ui->transcript->find(ui->searchTextLine->text());
230
void MainWindow::on_lookBackward_clicked()
232
ui->transcript->find(ui->searchTextLine->text(), QTextDocument::FindBackward);
235
void MainWindow::on_searchTextLine_returnPressed()
237
on_lookForward_clicked();
240
void MainWindow::keyPressEvent(QKeyEvent *e)
245
QLineEdit *lineEdit = ui->searchTextLine;
246
if ( ui->centralWidget->currentIndex() == 0 )
247
lineEdit = ui->subtitleFilter;
248
lineEdit->setFocus();
249
lineEdit->selectAll();
254
void MainWindow::on_actionAbout_Qt_triggered()
256
QMessageBox::aboutQt(this);
259
void MainWindow::on_actionAbout_Me_triggered()
261
QMessageBox::about(this, tr("Minicast"),
262
tr("Contact: <b>the.warl0ck.1989@gmail.com</b><br/>"
263
"Access <b>blogspot.c0debreak.com</b> for more information "
264
"(note the zero from both, not a big char O)"));
267
void MainWindow::on_actionQuit_Q_triggered()
269
QApplication::quit();
271
/* BEGIN_COMMON_COPYRIGHT_HEADER
274
* Copyright: 2012 Labo A.L
276
* Aaron Lewis <the.warl0ck.1989@gmail.com>
278
* This program or library is free software; you can redistribute it
279
* and/or modify it under the terms of the GNU Lesser General Public
280
* License as published by the Free Software Foundation; either
281
* version 2.1 of the License, or (at your option) any later version.
283
* This library is distributed in the hope that it will be useful,
284
* but WITHOUT ANY WARRANTY; without even the implied warranty of
285
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
286
* Lesser General Public License for more details.
288
* You should have received a copy of the GNU Lesser General
289
* Public License along with this library; if not, write to the
290
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
291
* Boston, MA 02110-1301 USA
293
* END_COMMON_COPYRIGHT_HEADER */
1
294
#include "mainwindow.h"
2
295
#include "ui_mainwindow.h"