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"
17
#include "macfullscreen.h"
14
21
NetworkAccess* http();
31
38
splitter = new MiniSplitter(this);
32
39
splitter->setChildrenCollapsible(false);
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);
57
41
listView = new PlaylistView(this);
58
42
listView->setItemDelegate(new PrettyItemDelegate(this));
59
43
listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
87
71
connect(listView, SIGNAL(authorPushed(QModelIndex)), SLOT(authorPushed(QModelIndex)));
89
playlistWidget = new PlaylistWidget(this, sortBar, listView);
91
splitter->addWidget(playlistWidget);
73
sidebar = new SidebarWidget(this);
74
sidebar->setPlaylist(listView);
75
connect(sidebar->getRefineSearchWidget(), SIGNAL(searchRefined()),
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);
93
83
videoAreaWidget = new VideoAreaWidget(this);
94
videoAreaWidget->setMinimumSize(320,240);
97
// mouse autohide does not work on the Mac (no mouseMoveEvent)
84
// videoAreaWidget->setMinimumSize(320,240);
98
85
videoWidget = new Phonon::VideoWidget(this);
100
videoWidget = new VideoWidget(this);
103
86
videoAreaWidget->setVideoWidget(videoWidget);
104
87
videoAreaWidget->setListModel(listModel);
144
127
connect(videoAreaWidget, SIGNAL(customContextMenuRequested(QPoint)),
145
128
this, SLOT(showVideoContextMenu(QPoint)));
131
QAction* refineSearchAction = The::globalActions()->value("refine-search");
132
connect(refineSearchAction, SIGNAL(toggled(bool)),
133
sidebar, SLOT(toggleRefineSearch(bool)));
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()));
160
148
void MediaView::search(SearchParams *searchParams) {
171
159
// start serching for videos
172
160
listModel->search(searchParams);
174
// this implies that the enum and the bar action order is the same
175
sortBar->setCheckedAction(searchParams->sortBy()-1);
162
sidebar->showPlaylist();
177
163
listView->setFocus();
179
165
QString keyword = searchParams->keywords();
198
191
void MediaView::handleError(QString /* message */) {
200
QTimer::singleShot(100, this, SLOT(startPlaying()));
193
QTimer::singleShot(500, this, SLOT(startPlaying()));
203
196
videoAreaWidget->showError(message);
210
void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/)
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);
216
207
switch (newState) {
430
425
qDebug() << "Playing" << source;
431
426
mediaObject->setCurrentSource(source);
432
427
mediaObject->play();
429
seekSlider->setEnabled(false);
434
432
// ensure we always have 10 videos ahead
435
433
listModel->searchNeeded();
497
495
listModel->setActiveRow(prevRow);
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);
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()) {
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();
627
bool MediaView::isPlaylistVisible() {
628
return splitter->widget(0)->isVisible();
614
631
void MediaView::timerPlay() {
694
711
if (mainWindow) mainWindow->statusBar()->showMessage(message);
714
void MediaView::snapshot() {
715
QImage image = videoWidget->snapshot();
716
qDebug() << image.size();
718
const QPixmap& pixmap = QPixmap::grabWindow(videoWidget->winId());
719
// qDebug() << pixmap.size();
720
videoAreaWidget->showSnapshotPreview(pixmap);
697
723
void MediaView::fullscreen() {
698
724
videoAreaWidget->setParent(0);
699
725
videoAreaWidget->showFullScreen();
822
848
QDesktopServices::openUrl(url);
851
void MediaView::shareViaBuffer() {
852
Video* video = listModel->activeVideo();
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);
825
863
void MediaView::shareViaEmail() {
826
864
Video* video = listModel->activeVideo();
827
865
if (!video) return;