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

« back to all changes in this revision

Viewing changes to src/MainWindow.cpp

  • Committer: Package Import Robot
  • Author(s): Jakob Haufe
  • Date: 2012-09-29 02:43:53 UTC
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20120929024353-fxbrlvqxrlu6cwld
Tags: upstream-1.9
ImportĀ upstreamĀ versionĀ 1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#else
31
31
#include "searchlineedit.h"
32
32
#endif
 
33
#include <iostream>
33
34
 
34
35
static MainWindow *singleton = 0;
35
36
 
39
40
}
40
41
 
41
42
MainWindow::MainWindow() :
 
43
        updateChecker(0),
42
44
        aboutView(0),
43
45
        downloadView(0),
44
46
        mediaObject(0),
45
47
        audioOutput(0),
46
 
        m_fullscreen(false),
47
 
        updateChecker(0) {
 
48
        m_fullscreen(false) {
48
49
 
49
50
    singleton = this;
50
51
 
69
70
    createStatusBar();
70
71
 
71
72
    initPhonon();
72
 
    // mediaView->setSlider(slider);
 
73
    mediaView->setSlider(seekSlider);
73
74
    mediaView->setMediaObject(mediaObject);
74
75
 
75
76
    // remove that useless menu/toolbar context menu
81
82
    // event filter to block ugly toolbar tooltips
82
83
    qApp->installEventFilter(this);
83
84
 
 
85
    setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
 
86
 
84
87
    // restore window position
85
88
    readSettings();
86
89
 
 
90
    // fix stacked widget minimum size
 
91
    for (int i = 0; i < views->count(); i++) {
 
92
        QWidget* view = views->widget(i);
 
93
        if (view) view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
 
94
    }
 
95
    setMinimumWidth(0);
 
96
 
87
97
    // show the initial view
88
98
#ifdef APP_DEMO
89
99
        QWidget *demoStartupView = new DemoStartupView(this);
115
125
 
116
126
    setAcceptDrops(true);
117
127
 
 
128
    mouseTimer = new QTimer(this);
 
129
    mouseTimer->setInterval(5000);
 
130
    mouseTimer->setSingleShot(true);
 
131
    connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse()));
 
132
 
118
133
    QTimer::singleShot(0, this, SLOT(checkForUpdate()));
119
134
 
120
135
}
133
148
}
134
149
 
135
150
bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
136
 
#ifdef Q_WS_X11
137
 
    if (event->type() == QEvent::MouseMove && this->m_fullscreen) {
 
151
 
 
152
    if (m_fullscreen && event->type() == QEvent::MouseMove) {
 
153
 
138
154
        QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
139
 
        int x = mouseEvent->pos().x();
140
 
        int y = mouseEvent->pos().y();
141
 
 
142
 
        if (y < 0 && (obj == this->mainToolBar || !(y <= 10-this->mainToolBar->height() && y >= 0-this->mainToolBar->height() )))
143
 
           this->mainToolBar->setVisible(false);
144
 
        if (x < 0)
145
 
            this->mediaView->setPlaylistVisible(false);
 
155
        const int x = mouseEvent->pos().x();
 
156
        const QString className = QString(obj->metaObject()->className());
 
157
        const bool isHoveringVideo = (className == "QGLWidget") || (className == "VideoAreaWidget");
 
158
 
 
159
        // qDebug() << obj << mouseEvent->pos() << isHoveringVideo << mediaView->isPlaylistVisible();
 
160
 
 
161
        if (mediaView->isPlaylistVisible()) {
 
162
            if (isHoveringVideo && x > 5) mediaView->setPlaylistVisible(false);
 
163
        } else {
 
164
            if (isHoveringVideo && x >= 0 && x < 5) mediaView->setPlaylistVisible(true);
 
165
        }
 
166
 
 
167
#ifndef APP_MAC
 
168
        const int y = mouseEvent->pos().y();
 
169
        if (mainToolBar->isVisible()) {
 
170
            if (isHoveringVideo && y > 5) mainToolBar->setVisible(false);
 
171
        } else {
 
172
            if (isHoveringVideo && y >= 0 && y < 5) mainToolBar->setVisible(true);
 
173
        }
 
174
#endif
 
175
 
 
176
        // show the normal cursor
 
177
        unsetCursor();
 
178
        // then hide it again after a few seconds
 
179
        mouseTimer->start();
 
180
 
146
181
    }
147
 
#endif
148
182
 
149
183
    if (event->type() == QEvent::ToolTip) {
150
184
        // kill tooltips
151
185
        return true;
152
186
    }
153
187
    // standard event processing
154
 
    return QObject::eventFilter(obj, event);
 
188
    return QMainWindow::eventFilter(obj, event);
155
189
}
156
190
 
157
191
void MainWindow::createActions() {
379
413
    connect(action, SIGNAL(triggered()), mediaView, SLOT(downloadVideo()));
380
414
    actions->insert("download", action);
381
415
 
 
416
    /*
 
417
    action = new QAction(tr("&Snapshot"), this);
 
418
    action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_S));
 
419
    actions->insert("snapshot", action);
 
420
    connect(action, SIGNAL(triggered()), mediaView, SLOT(snapshot()));
 
421
    */
 
422
 
382
423
    QString shareTip = tr("Share the current video using %1");
383
424
 
384
425
    action = new QAction("&Twitter", this);
391
432
    actions->insert("facebook", action);
392
433
    connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaFacebook()));
393
434
 
 
435
    action = new QAction("&Buffer", this);
 
436
    action->setStatusTip(shareTip.arg("Buffer"));
 
437
    actions->insert("buffer", action);
 
438
    connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaBuffer()));
 
439
 
394
440
    action = new QAction(tr("&Email"), this);
395
441
    action->setStatusTip(shareTip.arg(tr("Email")));
396
442
    actions->insert("email", action);
401
447
    actions->insert("close", action);
402
448
    connect(action, SIGNAL(triggered()), SLOT(close()));
403
449
 
 
450
    action = new QAction(Constants::NAME, this);
 
451
    action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_1));
 
452
    actions->insert("restore", action);
 
453
    connect(action, SIGNAL(triggered()), SLOT(restore()));
 
454
 
404
455
    action = new QAction(QtIconLoader::icon("go-top"), tr("&Float on Top"), this);
405
456
    action->setCheckable(true);
406
457
    actions->insert("ontop", action);
413
464
    actions->insert("stopafterthis", action);
414
465
    connect(action, SIGNAL(toggled(bool)), SLOT(showStopAfterThisInStatusBar(bool)));
415
466
 
 
467
    action = new QAction(tr("&Report an Issue..."), this);
 
468
    actions->insert("report-issue", action);
 
469
    connect(action, SIGNAL(triggered()), SLOT(reportIssue()));
 
470
 
 
471
    action = new QAction(tr("&Refine Search..."), this);
 
472
    action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
 
473
    action->setCheckable(true);
 
474
    actions->insert("refine-search", action);
 
475
 
416
476
    // common action properties
417
477
    foreach (QAction *action, actions->values()) {
418
478
 
476
536
    playlistMenu->addSeparator();
477
537
    playlistMenu->addAction(moveUpAct);
478
538
    playlistMenu->addAction(moveDownAct);
 
539
    playlistMenu->addSeparator();
 
540
    playlistMenu->addAction(The::globalActions()->value("refine-search"));
479
541
 
480
542
    QMenu* videoMenu = menuBar()->addMenu(tr("&Video"));
481
543
    menus->insert("video", videoMenu);
482
544
    videoMenu->addAction(findVideoPartsAct);
483
545
    videoMenu->addSeparator();
484
546
    videoMenu->addAction(webPageAct);
 
547
    videoMenu->addSeparator();
485
548
#ifndef APP_NO_DOWNLOADS
486
 
    videoMenu->addSeparator();
487
549
    videoMenu->addAction(The::globalActions()->value("download"));
488
 
    videoMenu->addAction(copyLinkAct);
 
550
    // videoMenu->addAction(copyLinkAct);
489
551
#endif
 
552
    // videoMenu->addAction(The::globalActions()->value("snapshot"));
490
553
 
491
554
    QMenu* viewMenu = menuBar()->addMenu(tr("&View"));
492
555
    menus->insert("view", viewMenu);
501
564
    shareMenu->addSeparator();
502
565
    shareMenu->addAction(The::globalActions()->value("twitter"));
503
566
    shareMenu->addAction(The::globalActions()->value("facebook"));
 
567
    shareMenu->addAction(The::globalActions()->value("buffer"));
 
568
    shareMenu->addSeparator();
504
569
    shareMenu->addAction(The::globalActions()->value("email"));
505
570
 
506
571
#ifdef APP_MAC
512
577
#if !defined(APP_MAC) && !defined(APP_WIN)
513
578
    helpMenu->addAction(donateAct);
514
579
#endif
 
580
    helpMenu->addAction(The::globalActions()->value("report-issue"));
515
581
    helpMenu->addAction(aboutAct);
516
582
}
517
583
 
641
707
 
642
708
void MainWindow::readSettings() {
643
709
    QSettings settings;
644
 
    restoreGeometry(settings.value("geometry").toByteArray());
 
710
    if (settings.contains("geometry")) {
 
711
        restoreGeometry(settings.value("geometry").toByteArray());
645
712
#ifdef APP_MAC
646
713
    MacSupport::fixGeometry(this);
647
714
#endif
 
715
    } else {
 
716
        setGeometry(100, 100, 1000, 500);
 
717
    }
648
718
    setDefinitionMode(settings.value("definition", VideoDefinition::getDefinitionNames().first()).toString());
649
719
    audioOutput->setVolume(settings.value("volume", 1).toDouble());
650
720
    audioOutput->setMuted(settings.value("volumeMute").toBool());
652
722
}
653
723
 
654
724
void MainWindow::writeSettings() {
655
 
 
656
725
    QSettings settings;
657
726
 
658
 
    // do not save geometry when in full screen
659
 
    if (!m_fullscreen) {
660
 
        settings.setValue("geometry", saveGeometry());
661
 
    }
 
727
    settings.setValue("geometry", saveGeometry());
 
728
    mediaView->saveSplitterState();
662
729
 
663
730
    settings.setValue("volume", audioOutput->volume());
664
731
    settings.setValue("volumeMute", audioOutput->isMuted());
665
732
    settings.setValue("manualplay", The::globalActions()->value("manualplay")->isChecked());
666
 
    mediaView->saveSplitterState();
667
733
}
668
734
 
669
735
void MainWindow::goBack() {
676
742
 
677
743
void MainWindow::showWidget ( QWidget* widget ) {
678
744
 
 
745
    if (compactViewAct->isChecked())
 
746
        compactViewAct->toggle();
 
747
 
679
748
    setUpdatesEnabled(false);
680
749
 
681
750
    // call hide method on the current view
715
784
 
716
785
    The::globalActions()->value("twitter")->setEnabled(widget == mediaView);
717
786
    The::globalActions()->value("facebook")->setEnabled(widget == mediaView);
 
787
    The::globalActions()->value("buffer")->setEnabled(widget == mediaView);
718
788
    The::globalActions()->value("email")->setEnabled(widget == mediaView);
719
789
 
720
790
    aboutAct->setEnabled(widget != aboutView);
729
799
    setUpdatesEnabled(true);
730
800
 
731
801
    QWidget *oldWidget = views->currentWidget();
 
802
    if (oldWidget)
 
803
        oldWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
 
804
 
732
805
    views->setCurrentWidget(widget);
 
806
    widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
807
    // adjustSize();
733
808
 
734
809
#ifndef Q_WS_X11
735
810
    Extra::fadeInWidget(oldWidget, widget);
758
833
    QDesktopServices::openUrl(url);
759
834
}
760
835
 
 
836
void MainWindow::reportIssue() {
 
837
    QUrl url("http://flavio.tordini.org/forums/forum/minitube-forums/minitube-troubleshooting");
 
838
    QDesktopServices::openUrl(url);
 
839
}
 
840
 
761
841
void MainWindow::quit() {
762
842
#ifdef APP_MAC
763
843
    if (!confirmQuit()) {
764
844
        return;
765
845
    }
766
846
#endif
767
 
    writeSettings();
 
847
    // do not save geometry when in full screen or in compact mode
 
848
    if (!m_fullscreen && !compactViewAct->isChecked()) {
 
849
        writeSettings();
 
850
    }
768
851
    Temporary::deleteAll();
769
852
    qApp->quit();
770
853
}
778
861
        event->ignore();
779
862
        return;
780
863
    }
 
864
    QWidget::closeEvent(event);
781
865
    quit();
782
 
    QWidget::closeEvent(event);
783
866
#endif
784
867
}
785
868
 
876
959
    if (mac::CanGoFullScreen(winId())) {
877
960
        bool isFullscreen = mac::IsFullScreen(winId());
878
961
        if (isFullscreen != m_fullscreen) {
 
962
            if (compactViewAct->isChecked()) {
 
963
                compactViewAct->setChecked(false);
 
964
                compactView(false);
 
965
            }
879
966
            m_fullscreen = isFullscreen;
880
967
            updateUIForFullscreen();
881
968
        }
885
972
 
886
973
void MainWindow::fullscreen() {
887
974
 
888
 
    /*
889
975
    if (compactViewAct->isChecked())
890
 
        compactView(false);
891
 
    */
 
976
        compactViewAct->toggle();
892
977
 
893
978
#ifdef Q_WS_MAC
894
979
    WId handle = winId();
976
1061
 
977
1062
    if (views->currentWidget() == mediaView)
978
1063
        mediaView->setFocus();
 
1064
 
 
1065
    if (m_fullscreen) {
 
1066
        hideMouse();
 
1067
    } else {
 
1068
        mouseTimer->stop();
 
1069
        unsetCursor();
 
1070
    }
979
1071
}
980
1072
 
981
1073
void MainWindow::compactView(bool enable) {
983
1075
    static QList<QKeySequence> compactShortcuts;
984
1076
    static QList<QKeySequence> stopShortcuts;
985
1077
 
986
 
    /*
987
1078
    const static QString key = "compactGeometry";
988
1079
    QSettings settings;
989
 
    */
990
1080
 
991
1081
#ifndef APP_MAC
992
1082
    menuBar()->setVisible(!enable);
993
1083
#endif
994
1084
 
995
1085
    if (enable) {
996
 
        /*
 
1086
        setMinimumSize(160, 120);
 
1087
#ifdef Q_WS_MAC
 
1088
        mac::RemoveFullScreenWindow(winId());
 
1089
#endif
997
1090
        writeSettings();
998
 
        restoreGeometry(settings.value(key).toByteArray());
999
 
        */
 
1091
 
 
1092
        if (settings.contains(key))
 
1093
            restoreGeometry(settings.value(key).toByteArray());
 
1094
        else
 
1095
            resize(320, 240);
 
1096
 
 
1097
        mainToolBar->setVisible(!enable);
 
1098
        mediaView->setPlaylistVisible(!enable);
 
1099
        statusBar()->setVisible(!enable);
1000
1100
 
1001
1101
        compactShortcuts = compactViewAct->shortcuts();
1002
1102
        stopShortcuts = stopAct->shortcuts();
1009
1109
        // ensure focus does not end up to the search box
1010
1110
        // as it would steal the Space shortcut
1011
1111
        mediaView->setFocus();
 
1112
 
1012
1113
    } else {
1013
 
        /*
 
1114
        // unset minimum size
 
1115
        setMinimumSize(0, 0);
 
1116
#ifdef Q_WS_MAC
 
1117
        mac::SetupFullScreenWindow(winId());
 
1118
#endif
1014
1119
        settings.setValue(key, saveGeometry());
 
1120
        mainToolBar->setVisible(!enable);
 
1121
        mediaView->setPlaylistVisible(!enable);
 
1122
        statusBar()->setVisible(!enable);
1015
1123
        readSettings();
1016
 
        */
1017
1124
 
1018
1125
        compactViewAct->setShortcuts(compactShortcuts);
1019
1126
        stopAct->setShortcuts(stopShortcuts);
1020
1127
    }
1021
1128
 
1022
 
    mainToolBar->setVisible(!enable);
1023
 
    mediaView->setPlaylistVisible(!enable);
1024
 
    statusBar()->setVisible(!enable);
1025
 
 
 
1129
    // auto float on top
 
1130
    floatOnTop(enable);
1026
1131
}
1027
1132
 
1028
1133
void MainWindow::searchFocus() {
1029
 
    QWidget *view = views->currentWidget();
1030
1134
    toolbarSearch->selectAll();
1031
1135
    toolbarSearch->setFocus();
1032
1136
}
1211
1315
}
1212
1316
 
1213
1317
void MainWindow::startToolbarSearch(QString query) {
1214
 
 
1215
1318
    query = query.trimmed();
1216
1319
 
1217
1320
    // check for empty query
1279
1382
        updateChecker = 0;
1280
1383
    }
1281
1384
 
1282
 
#if defined(APP_DEMO) || defined(APP_MAC_STORE)
 
1385
#if defined(APP_DEMO) || defined(APP_MAC_STORE) || defined(APP_USC)
1283
1386
    return;
1284
1387
#endif
1285
1388
 
1337
1440
    }
1338
1441
}
1339
1442
 
 
1443
void MainWindow::restore() {
 
1444
#ifdef APP_MAC
 
1445
    mac::uncloseWindow(window()->winId());
 
1446
#endif
 
1447
}
 
1448
 
1340
1449
void MainWindow::messageReceived(const QString &message) {
1341
 
    if (!message.isEmpty()) {
 
1450
    if (message == "--toggle-playing") {
 
1451
        if (pauseAct->isEnabled()) pauseAct->trigger();
 
1452
    } else if (message == "--next") {
 
1453
        if (skipAct->isEnabled()) skipAct->trigger();
 
1454
    } else if (message == "--previous") {
 
1455
        if (skipBackwardAct->isEnabled()) skipBackwardAct->trigger();
 
1456
    }  else if (message.startsWith("--")) {
 
1457
        MainWindow::printHelp();
 
1458
    } else if (!message.isEmpty()) {
1342
1459
        SearchParams *searchParams = new SearchParams();
1343
1460
        searchParams->setKeywords(message);
1344
1461
        showMedia(searchParams);
1345
1462
    }
1346
1463
}
 
1464
 
 
1465
void MainWindow::hideMouse() {
 
1466
    setCursor(Qt::BlankCursor);
 
1467
    mediaView->setPlaylistVisible(false);
 
1468
#ifndef APP_MAC
 
1469
    mainToolBar->setVisible(false);
 
1470
#endif
 
1471
}
 
1472
 
 
1473
void MainWindow::printHelp() {
 
1474
    QString msg = QString("%1 %2\n\n").arg(Constants::NAME, Constants::VERSION);
 
1475
    msg += "Usage: minitube [options]\n";
 
1476
    msg += "Options:\n";
 
1477
    msg += "  --toggle-playing\t";
 
1478
    msg += "Start or pause playback.\n";
 
1479
    msg += "  --next\t\t";
 
1480
    msg += "Skip to the next video.\n";
 
1481
    msg += "  --previous\t\t";
 
1482
    msg += "Go back to the previous video.\n";
 
1483
    std::cout << msg.toLocal8Bit().data();
 
1484
}