~ubuntu-branches/ubuntu/saucy/minitube/saucy-proposed

« back to all changes in this revision

Viewing changes to src/MediaView.cpp

  • Committer: Package Import Robot
  • Author(s): Jakob Haufe
  • Date: 2012-09-29 02:43:53 UTC
  • mfrom: (2.1.10)
  • Revision ID: package-import@ubuntu.com-20120929024353-cvsvqeewq4p93pb4
Tags: 1.9-1
* New upstream version (Closes: #673696).
* Refresh disable-update-check.
* Refresh proper-tempfiles.
* Use hardening-wrapper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include "downloaditem.h"
10
10
#include "MainWindow.h"
11
11
#include "temporary.h"
 
12
#include "sidebarwidget.h"
 
13
#include "playlistwidget.h"
 
14
#include "refinesearchwidget.h"
 
15
#include "sidebarwidget.h"
 
16
#ifdef APP_MAC
 
17
#include "macfullscreen.h"
 
18
#endif
12
19
 
13
20
namespace The {
14
21
NetworkAccess* http();
31
38
    splitter = new MiniSplitter(this);
32
39
    splitter->setChildrenCollapsible(false);
33
40
 
34
 
    sortBar = new SegmentedControl(this);
35
 
    mostRelevantAction = new QAction(tr("Most relevant"), this);
36
 
    QKeySequence keySequence(Qt::CTRL + Qt::Key_1);
37
 
    mostRelevantAction->setShortcut(keySequence);
38
 
    mostRelevantAction->setStatusTip(mostRelevantAction->text() + " (" + keySequence.toString(QKeySequence::NativeText) + ")");
39
 
    addAction(mostRelevantAction);
40
 
    connect(mostRelevantAction, SIGNAL(triggered()), this, SLOT(searchMostRelevant()), Qt::QueuedConnection);
41
 
    sortBar->addAction(mostRelevantAction);
42
 
    mostRecentAction = new QAction(tr("Most recent"), this);
43
 
    keySequence = QKeySequence(Qt::CTRL + Qt::Key_2);
44
 
    mostRecentAction->setShortcut(keySequence);
45
 
    mostRecentAction->setStatusTip(mostRecentAction->text() + " (" + keySequence.toString(QKeySequence::NativeText) + ")");
46
 
    addAction(mostRecentAction);
47
 
    connect(mostRecentAction, SIGNAL(triggered()), this, SLOT(searchMostRecent()), Qt::QueuedConnection);
48
 
    sortBar->addAction(mostRecentAction);
49
 
    mostViewedAction = new QAction(tr("Most viewed"), this);
50
 
    keySequence = QKeySequence(Qt::CTRL + Qt::Key_3);
51
 
    mostViewedAction->setShortcut(keySequence);
52
 
    mostViewedAction->setStatusTip(mostViewedAction->text() + " (" + keySequence.toString(QKeySequence::NativeText) + ")");
53
 
    addAction(mostViewedAction);
54
 
    connect(mostViewedAction, SIGNAL(triggered()), this, SLOT(searchMostViewed()), Qt::QueuedConnection);
55
 
    sortBar->addAction(mostViewedAction);
56
 
 
57
41
    listView = new PlaylistView(this);
58
42
    listView->setItemDelegate(new PrettyItemDelegate(this));
59
43
    listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
86
70
 
87
71
    connect(listView, SIGNAL(authorPushed(QModelIndex)), SLOT(authorPushed(QModelIndex)));
88
72
 
89
 
    playlistWidget = new PlaylistWidget(this, sortBar, listView);
90
 
 
91
 
    splitter->addWidget(playlistWidget);
 
73
    sidebar = new SidebarWidget(this);
 
74
    sidebar->setPlaylist(listView);
 
75
    connect(sidebar->getRefineSearchWidget(), SIGNAL(searchRefined()),
 
76
            SLOT(searchAgain()));
 
77
    connect(listModel, SIGNAL(haveSuggestions(const QStringList &)),
 
78
            sidebar, SLOT(showSuggestions(const QStringList &)));
 
79
    connect(sidebar, SIGNAL(suggestionAccepted(QString)),
 
80
            MainWindow::instance(), SLOT(startToolbarSearch(QString)));
 
81
    splitter->addWidget(sidebar);
92
82
 
93
83
    videoAreaWidget = new VideoAreaWidget(this);
94
 
    videoAreaWidget->setMinimumSize(320,240);
95
 
 
96
 
#ifdef APP_MAC_NO
97
 
    // mouse autohide does not work on the Mac (no mouseMoveEvent)
 
84
    // videoAreaWidget->setMinimumSize(320,240);
98
85
    videoWidget = new Phonon::VideoWidget(this);
99
 
#else
100
 
    videoWidget = new VideoWidget(this);
101
 
#endif
102
 
 
103
86
    videoAreaWidget->setVideoWidget(videoWidget);
104
87
    videoAreaWidget->setListModel(listModel);
105
88
 
144
127
    connect(videoAreaWidget, SIGNAL(customContextMenuRequested(QPoint)),
145
128
            this, SLOT(showVideoContextMenu(QPoint)));
146
129
            */
 
130
 
 
131
    QAction* refineSearchAction = The::globalActions()->value("refine-search");
 
132
    connect(refineSearchAction, SIGNAL(toggled(bool)),
 
133
            sidebar, SLOT(toggleRefineSearch(bool)));
147
134
}
148
135
 
149
136
void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) {
155
142
    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
156
143
            this, SLOT(currentSourceChanged(Phonon::MediaSource)));
157
144
    // connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int)));
 
145
    connect(mediaObject, SIGNAL(aboutToFinish()), SLOT(aboutToFinish()));
158
146
}
159
147
 
160
148
void MediaView::search(SearchParams *searchParams) {
171
159
    // start serching for videos
172
160
    listModel->search(searchParams);
173
161
 
174
 
    // this implies that the enum and the bar action order is the same
175
 
    sortBar->setCheckedAction(searchParams->sortBy()-1);
176
 
 
 
162
    sidebar->showPlaylist();
177
163
    listView->setFocus();
178
164
 
179
165
    QString keyword = searchParams->keywords();
185
171
        }
186
172
    }
187
173
 
 
174
    sidebar->getRefineSearchWidget()->setSearchParams(searchParams);
 
175
    sidebar->hideSuggestions();
 
176
 
 
177
}
 
178
 
 
179
void MediaView::searchAgain() {
 
180
    search(searchParams);
188
181
}
189
182
 
190
183
void MediaView::appear() {
197
190
 
198
191
void MediaView::handleError(QString /* message */) {
199
192
 
200
 
    QTimer::singleShot(100, this, SLOT(startPlaying()));
 
193
    QTimer::singleShot(500, this, SLOT(startPlaying()));
201
194
 
202
195
    /*
203
196
    videoAreaWidget->showError(message);
207
200
    */
208
201
}
209
202
 
210
 
void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/)
211
 
{
212
 
 
213
 
    // qDebug() << "Phonon state: " << newState << oldState;
 
203
void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
 
204
    // qDebug() << "Phonon state: " << newState;
214
205
    // slider->setEnabled(newState == Phonon::PlayingState);
215
206
 
216
207
    switch (newState) {
287
278
        delete downloadItem;
288
279
        downloadItem = 0;
289
280
    }
 
281
    The::globalActions()->value("refine-search")->setChecked(false);
290
282
}
291
283
 
292
284
void MediaView::activeRowChanged(int row) {
300
292
    workaroundTimer->stop();
301
293
    errorTimer->stop();
302
294
 
303
 
    mediaObject->pause();
 
295
    mediaObject->stop();
304
296
    if (downloadItem) {
305
297
        downloadItem->stop();
306
298
        delete downloadItem;
409
401
    case Finished:
410
402
        // qDebug() << "Finished" << mediaObject->state();
411
403
        // if (mediaObject->state() == Phonon::StoppedState) startPlaying();
 
404
#ifdef Q_WS_X11
 
405
        seekSlider->setEnabled(mediaObject->isSeekable());
 
406
#endif
412
407
        break;
413
408
    case Failed:
414
409
        // qDebug() << "Failed";
430
425
    qDebug() << "Playing" << source;
431
426
    mediaObject->setCurrentSource(source);
432
427
    mediaObject->play();
 
428
#ifdef Q_WS_X11
 
429
    seekSlider->setEnabled(false);
 
430
#endif
433
431
 
434
432
    // ensure we always have 10 videos ahead
435
433
    listModel->searchNeeded();
497
495
    listModel->setActiveRow(prevRow);
498
496
}
499
497
 
 
498
void MediaView::aboutToFinish() {
 
499
    qint64 currentTime = mediaObject->currentTime();
 
500
    qDebug() << __PRETTY_FUNCTION__ << currentTime;
 
501
    if (currentTime + 10000 < mediaObject->totalTime()) {
 
502
        // mediaObject->seek(mediaObject->currentTime());
 
503
        // QTimer::singleShot(500, this, SLOT(playbackResume()));
 
504
        mediaObject->seek(currentTime);
 
505
        mediaObject->play();
 
506
    }
 
507
}
 
508
 
500
509
void MediaView::playbackFinished() {
 
510
    qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
501
511
    // qDebug() << "finished" << mediaObject->currentTime() << mediaObject->totalTime();
502
512
    // add 10 secs for imprecise Phonon backends (VLC, Xine)
503
513
    if (mediaObject->currentTime() + 10000 < mediaObject->totalTime()) {
512
522
}
513
523
 
514
524
void MediaView::playbackResume() {
 
525
    qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
515
526
    mediaObject->seek(mediaObject->currentTime());
516
527
    mediaObject->play();
517
528
}
608
619
}
609
620
 
610
621
void MediaView::setPlaylistVisible(bool visible) {
611
 
    playlistWidget->setVisible(visible);
 
622
    if (splitter->widget(0)->isVisible() == visible) return;
 
623
    splitter->widget(0)->setVisible(visible);
 
624
    listView->setFocus();
 
625
}
 
626
 
 
627
bool MediaView::isPlaylistVisible() {
 
628
    return splitter->widget(0)->isVisible();
612
629
}
613
630
 
614
631
void MediaView::timerPlay() {
694
711
    if (mainWindow) mainWindow->statusBar()->showMessage(message);
695
712
}
696
713
 
 
714
void MediaView::snapshot() {
 
715
    QImage image = videoWidget->snapshot();
 
716
    qDebug() << image.size();
 
717
 
 
718
    const QPixmap& pixmap = QPixmap::grabWindow(videoWidget->winId());
 
719
    // qDebug() << pixmap.size();
 
720
    videoAreaWidget->showSnapshotPreview(pixmap);
 
721
}
 
722
 
697
723
void MediaView::fullscreen() {
698
724
    videoAreaWidget->setParent(0);
699
725
    videoAreaWidget->showFullScreen();
822
848
    QDesktopServices::openUrl(url);
823
849
}
824
850
 
 
851
void MediaView::shareViaBuffer() {
 
852
    Video* video = listModel->activeVideo();
 
853
    if (!video) return;
 
854
    QUrl url("http://bufferapp.com/add");
 
855
    url.addQueryItem("via", "minitubeapp");
 
856
    url.addQueryItem("text", video->title());
 
857
    url.addQueryItem("url", video->webpage().toString());
 
858
    if (!video->thumbnailUrls().isEmpty())
 
859
        url.addQueryItem("picture", video->thumbnailUrls().first().toString());
 
860
    QDesktopServices::openUrl(url);
 
861
}
 
862
 
825
863
void MediaView::shareViaEmail() {
826
864
    Video* video = listModel->activeVideo();
827
865
    if (!video) return;