]> git.sur5r.net Git - minitube/blob - src/homeview.cpp
Imported Upstream version 2.0
[minitube] / src / homeview.cpp
1 #include "homeview.h"
2 #include "segmentedcontrol.h"
3 #include "searchview.h"
4 #include "standardfeedsview.h"
5 #include "userview.h"
6 #include "mainwindow.h"
7 #include "mediaview.h"
8 #include "ytstandardfeed.h"
9
10 HomeView::HomeView(QWidget *parent) : QWidget(parent) {
11     standardFeedsView = 0;
12     userView = 0;
13
14     QBoxLayout *layout = new QVBoxLayout(this);
15     layout->setMargin(0);
16     layout->setSpacing(0);
17
18     setupBar();
19     layout->addWidget(bar);
20
21     stackedWidget = new QStackedWidget();
22     layout->addWidget(stackedWidget);
23
24     searchView = new SearchView();
25     connect(searchView, SIGNAL(search(SearchParams*)),
26             MainWindow::instance(), SLOT(showMedia(SearchParams*)));
27     stackedWidget->addWidget(searchView);
28 }
29
30 void HomeView::setupBar() {
31     bar = new SegmentedControl(this);
32
33     QAction *action = new QAction(tr("Search"), this);
34     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
35     action->setStatusTip(tr("Find videos and channels by keyword"));
36     connect(action, SIGNAL(triggered()), SLOT(showSearch()));
37     bar->addAction(action);
38     bar->setCheckedAction(action);
39
40     action = new QAction(tr("Browse"), this);
41     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_2));
42     action->setStatusTip(tr("Browse videos by category"));
43     connect(action, SIGNAL(triggered()), SLOT(showStandardFeeds()));
44     bar->addAction(action);
45
46     /*
47     action = new QAction(tr("User"), this);
48     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
49     action->setStatusTip(tr("Your favorite videos, subscriptions and playlists"));
50     connect(action, SIGNAL(triggered()), SLOT(showUser()));
51     bar->addAction(action);
52     */
53
54     foreach (QAction* action, bar->actions()) {
55         // action->setEnabled(false);
56         addAction(action);
57         action->setAutoRepeat(false);
58         if (!action->shortcut().isEmpty())
59             action->setStatusTip(
60                         action->statusTip() + " (" +
61                         action->shortcut().toString(QKeySequence::NativeText) + ")");
62     }
63 }
64
65 void HomeView::showWidget(QWidget *widget) {
66     QWidget* currentWidget = stackedWidget->currentWidget();
67     if (currentWidget == widget) return;
68     QMetaObject::invokeMethod(currentWidget, "disappear");
69     currentWidget->setEnabled(false);
70     stackedWidget->setCurrentWidget(widget);
71     widget->setEnabled(true);
72     QMetaObject::invokeMethod(widget, "appear");
73     bar->setCheckedAction(stackedWidget->currentIndex());
74     // autoChosenView = false;
75     widget->setFocus();
76 }
77
78 void HomeView::appear() {
79     QMetaObject::invokeMethod(stackedWidget->currentWidget(), "appear");
80 }
81
82 void HomeView::disappear() {
83     QMetaObject::invokeMethod(stackedWidget->currentWidget(), "disappear");
84 }
85
86 void HomeView::showSearch() {
87     showWidget(searchView);
88 }
89
90 void HomeView::showStandardFeeds() {
91     if (!standardFeedsView) {
92         standardFeedsView = new StandardFeedsView();
93         connect(standardFeedsView, SIGNAL(activated(VideoSource*)),
94                 MainWindow::instance(),
95                 SLOT(showMedia(VideoSource*)));
96         stackedWidget->addWidget(standardFeedsView);
97     }
98     showWidget(standardFeedsView);
99 }
100
101 void HomeView::showUser() {
102     if (!userView) {
103         userView = new UserView(this);
104         stackedWidget->addWidget(userView);
105     }
106     showWidget(userView);
107 }