~john.vrbanac/ubuntu-app-reviews/minicast

« back to all changes in this revision

Viewing changes to mainwindow.cpp

  • Committer: Aaron Lewis
  • Date: 2012-07-09 07:22:35 UTC
  • Revision ID: the.warl0ck.1989@gmail.com-20120709072235-fubggzoo35iykjo4
Re-license

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* BEGIN_COMMON_COPYRIGHT_HEADER
 
2
 * (c)LGPL2+
 
3
 *
 
4
 * Copyright: 2012 Labo A.L
 
5
 * Authors:
 
6
 *   Aaron Lewis <the.warl0ck.1989@gmail.com>
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 
 
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
 
22
 *
 
23
 * END_COMMON_COPYRIGHT_HEADER */
 
24
#include "mainwindow.h"
 
25
#include "ui_mainwindow.h"
 
26
 
 
27
#define HIDE_TRANSCRIPTS(ok) do { \
 
28
    ui->transcript->setVisible(ok); \
 
29
    ui->lineWidget->setVisible(ok); \
 
30
    } while (0);
 
31
 
 
32
MainWindow::MainWindow(QWidget *parent) :
 
33
    QMainWindow(parent),
 
34
    ui(new Ui::MainWindow),
 
35
    m_vol (80),
 
36
    m_filterModel (new QSortFilterProxyModel (this)),
 
37
    m_model (new QStandardItemModel (this))
 
38
{
 
39
    ui->setupUi(this);
 
40
    ui->centralWidget->setCurrentIndex(0);
 
41
 
 
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);
 
45
 
 
46
    HIDE_TRANSCRIPTS(false);
 
47
 
 
48
    ui->programeListView->setModel(m_filterModel);
 
49
    m_filterModel->setSourceModel(m_model);
 
50
    m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
 
51
 
 
52
    ui->statusLabel->setMovie(new QMovie (":/images/loading.gif"));
 
53
    ui->statusLabel->movie()->start();
 
54
 
 
55
    ui->mplayer->setSeekSlider(ui->seekSlider);
 
56
    ui->mplayer->setVolumeSlider(ui->volumeSlider);
 
57
    ui->mplayer->setStatusBar(ui->statusBar);
 
58
 
 
59
    connect (ui->mplayer, SIGNAL(stateChanged(int)) , this, SLOT(mplayerStateChanged(int)));
 
60
    connect (ui->volumeSlider, SIGNAL(sliderPressed()), this, SLOT(update_volume_icon()));
 
61
    update_volume_icon();
 
62
 
 
63
    m_providers.append(new TedProvider (m_model, this));
 
64
    m_providers.append(new SciAmericanProvider (m_model, this));
 
65
 
 
66
    foreach (Provider *p, m_providers)
 
67
    {
 
68
        connect (p, SIGNAL(loaded()), this, SLOT(loadCompleted()));
 
69
    }
 
70
 
 
71
    ///
 
72
    ui->actionRefresh->trigger();
 
73
}
 
74
 
 
75
MainWindow::~MainWindow()
 
76
{
 
77
    delete ui;
 
78
}
 
79
 
 
80
void MainWindow::copyDownloadURL()
 
81
{
 
82
    QModelIndex idx = ui->programeListView->currentIndex();
 
83
    if ( idx.isValid() )
 
84
    {
 
85
        QClipboard *clip = QApplication::clipboard();
 
86
        clip->setText(m_filterModel->data(idx, Qt::UserRole).toString());
 
87
    }
 
88
}
 
89
 
 
90
void MainWindow::loadCompleted()
 
91
{
 
92
    ++ m_completed_cnt;
 
93
    if ( m_completed_cnt == m_providers.size() )
 
94
    {
 
95
        ui->statusLabel->hide();
 
96
    }
 
97
}
 
98
 
 
99
void MainWindow::on_stopButton_clicked()
 
100
{
 
101
    ui->mplayer->stop();
 
102
}
 
103
 
 
104
void MainWindow::on_playPauseButton_clicked()
 
105
{
 
106
    if ( ui->mplayer->state() == QMPwidget::NotStartedState)
 
107
        ui->mplayer->start();
 
108
 
 
109
    if ( ui->mplayer->state() == QMPwidget::PlayingState )
 
110
    {
 
111
        ui->mplayer->pause();
 
112
    }
 
113
    else
 
114
    {
 
115
        ui->mplayer->play();
 
116
    }
 
117
}
 
118
 
 
119
void MainWindow::mplayerStateChanged(int s)
 
120
{
 
121
    if ( s == QMPwidget::PlayingState )
 
122
    {
 
123
        ui->playPauseButton->setIcon(QIcon(":/images/media-playback-pause.png"));
 
124
    }
 
125
    else
 
126
    {
 
127
        ui->playPauseButton->setIcon(QIcon(":/images/media-playback-start.png"));
 
128
    }
 
129
}
 
130
 
 
131
void MainWindow::on_muteButton_toggled(bool checked)
 
132
{
 
133
    if ( checked )
 
134
    {
 
135
        m_vol = ui->volumeSlider->value();
 
136
        ui->muteButton->setIcon(QIcon(":/images/audio-volume-muted.png"));
 
137
        ui->volumeSlider->setValue(0);
 
138
    }
 
139
    else
 
140
    {
 
141
        ui->volumeSlider->setValue(m_vol);
 
142
        update_volume_icon();
 
143
    }
 
144
}
 
145
 
 
146
void MainWindow::update_volume_icon()
 
147
{
 
148
    m_vol = ui->volumeSlider->value();
 
149
    if ( m_vol > 80 )
 
150
    {
 
151
        ui->muteButton->setIcon(QIcon(":/images/audio-volume-high.png"));
 
152
    }
 
153
    else if ( m_vol > 50 )
 
154
    {
 
155
        ui->muteButton->setIcon(QIcon(":/images/audio-volume-medium.png"));
 
156
    }
 
157
    else if ( m_vol > 0 )
 
158
    {
 
159
        ui->muteButton->setIcon(QIcon(":/images/audio-volume-low.png"));
 
160
    }
 
161
    else
 
162
    {
 
163
        ui->muteButton->setIcon(QIcon(":/images/audio-volume-muted.png"));
 
164
    }
 
165
}
 
166
 
 
167
void MainWindow::on_actionRefresh_triggered()
 
168
{
 
169
    m_completed_cnt = 0;
 
170
    ui->statusLabel->show();
 
171
    m_model->clear();
 
172
 
 
173
    foreach (Provider *p, m_providers)
 
174
    {
 
175
        p->start();
 
176
    }
 
177
}
 
178
 
 
179
void MainWindow::on_actionToggleView_triggered(bool checked)
 
180
{
 
181
    ui->centralWidget->setCurrentIndex( checked ? 1 : 0 );
 
182
}
 
183
 
 
184
void MainWindow::closeEvent(QCloseEvent *)
 
185
{
 
186
    ui->mplayer->stop();
 
187
}
 
188
 
 
189
void MainWindow::on_programeListView_doubleClicked(const QModelIndex &index)
 
190
{
 
191
    if ( index.isValid() )
 
192
    {
 
193
        const QMap<int,QVariant> mapping = m_filterModel->itemData(index);
 
194
        if ( mapping.contains(Qt::UserRole + OFFSET_TRANSCRIPT) )
 
195
        {
 
196
            HIDE_TRANSCRIPTS(true);
 
197
            ui->transcript->setHtml(mapping.value(Qt::UserRole + OFFSET_TRANSCRIPT).toString());
 
198
        }
 
199
        else
 
200
            HIDE_TRANSCRIPTS(false);
 
201
 
 
202
        ui->mplayer->setVisible( ui->transcript->isHidden() );
 
203
 
 
204
        ui->actionToggleView->trigger();
 
205
 
 
206
        if ( ui->mplayer->state() == QMPwidget::NotStartedState)
 
207
            ui->mplayer->start();
 
208
 
 
209
        ui->mplayer->load(mapping.value(Qt::UserRole).toString());
 
210
    }
 
211
}
 
212
 
 
213
void MainWindow::on_subtitleFilter_textChanged(const QString &arg1)
 
214
{
 
215
    m_filterModel->setFilterWildcard(arg1);
 
216
}
 
217
 
 
218
void MainWindow::on_searchTextLine_textChanged(const QString &arg1)
 
219
{
 
220
    Q_UNUSED (arg1)
 
221
    ui->transcript->moveCursor(QTextCursor::Start);
 
222
    on_lookForward_clicked();
 
223
}
 
224
 
 
225
void MainWindow::on_lookForward_clicked()
 
226
{
 
227
    ui->transcript->find(ui->searchTextLine->text());
 
228
}
 
229
 
 
230
void MainWindow::on_lookBackward_clicked()
 
231
{
 
232
    ui->transcript->find(ui->searchTextLine->text(), QTextDocument::FindBackward);
 
233
}
 
234
 
 
235
void MainWindow::on_searchTextLine_returnPressed()
 
236
{
 
237
    on_lookForward_clicked();
 
238
}
 
239
 
 
240
void MainWindow::keyPressEvent(QKeyEvent *e)
 
241
{
 
242
    switch (e->key())
 
243
    {
 
244
    case Qt::Key_F6:
 
245
        QLineEdit *lineEdit = ui->searchTextLine;
 
246
        if ( ui->centralWidget->currentIndex() == 0 )
 
247
            lineEdit = ui->subtitleFilter;
 
248
        lineEdit->setFocus();
 
249
        lineEdit->selectAll();
 
250
        break;
 
251
    }
 
252
}
 
253
 
 
254
void MainWindow::on_actionAbout_Qt_triggered()
 
255
{
 
256
    QMessageBox::aboutQt(this);
 
257
}
 
258
 
 
259
void MainWindow::on_actionAbout_Me_triggered()
 
260
{
 
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)"));
 
265
}
 
266
 
 
267
void MainWindow::on_actionQuit_Q_triggered()
 
268
{
 
269
    QApplication::quit();
 
270
}
 
271
/* BEGIN_COMMON_COPYRIGHT_HEADER
 
272
 * (c)LGPL2+
 
273
 *
 
274
 * Copyright: 2012 Labo A.L
 
275
 * Authors:
 
276
 *   Aaron Lewis <the.warl0ck.1989@gmail.com>
 
277
 *
 
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.
 
282
 *
 
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.
 
287
 
 
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
 
292
 *
 
293
 * END_COMMON_COPYRIGHT_HEADER */
1
294
#include "mainwindow.h"
2
295
#include "ui_mainwindow.h"
3
296