|
@@ -12,18 +12,7 @@
|
|
|
#include <gtkmm/label.h>
|
|
|
#include <gdkmm/pixbuf.h>
|
|
|
#include <glibmm/fileutils.h>
|
|
|
-
|
|
|
-namespace
|
|
|
-{
|
|
|
- struct PlayButtonParams
|
|
|
- {
|
|
|
- // Какой id видео
|
|
|
- std::string yt_id;
|
|
|
-
|
|
|
- // Кнопка
|
|
|
- Gtk::Button* caller;
|
|
|
- };
|
|
|
-}
|
|
|
+#include <glibmm/markup.h>
|
|
|
|
|
|
namespace components {
|
|
|
|
|
@@ -46,6 +35,11 @@ namespace components {
|
|
|
, m_search_button()
|
|
|
, m_search_scroller()
|
|
|
, m_search_video_list()
|
|
|
+
|
|
|
+ , m_rate_container(Gtk::Orientation::HORIZONTAL)
|
|
|
+ , m_rate_dislike_btn()
|
|
|
+ , m_rate_meh_btn()
|
|
|
+ , m_rate_like_btn()
|
|
|
{
|
|
|
set_title("YTMPV");
|
|
|
set_default_size(1024, 640);
|
|
@@ -93,6 +87,24 @@ namespace components {
|
|
|
m_search_body.set_position(256);
|
|
|
m_search_layout.append(m_search_body);
|
|
|
|
|
|
+ // Кнопки оценки видео
|
|
|
+ m_rate_dislike_btn.set_child(*(core::getButtonContents("Dislike", "face-angry-symbolic")));
|
|
|
+ m_rate_meh_btn.set_child(*(core::getButtonContents("No rating", "face-plain-symbolic")));
|
|
|
+ m_rate_like_btn.set_child(*(core::getButtonContents("Like", "face-smile-big-symbolic")));
|
|
|
+ m_rate_container.set_homogeneous();
|
|
|
+ m_rate_container.append(m_rate_dislike_btn);
|
|
|
+ m_rate_container.append(m_rate_meh_btn);
|
|
|
+ m_rate_container.append(m_rate_like_btn);
|
|
|
+ m_rate_dislike_btn.signal_clicked().connect(sigc::bind(
|
|
|
+ sigc::mem_fun(*this, &MainWindow::onRateButtonClicked),
|
|
|
+ RateButtonParams {2}));
|
|
|
+ m_rate_meh_btn.signal_clicked().connect(sigc::bind(
|
|
|
+ sigc::mem_fun(*this, &MainWindow::onRateButtonClicked),
|
|
|
+ RateButtonParams {0} ));
|
|
|
+ m_rate_like_btn.signal_clicked().connect(sigc::bind(
|
|
|
+ sigc::mem_fun(*this, &MainWindow::onRateButtonClicked),
|
|
|
+ RateButtonParams {1} ));
|
|
|
+
|
|
|
// WelcomeView
|
|
|
// TODO
|
|
|
|
|
@@ -187,7 +199,8 @@ namespace components {
|
|
|
obj.author_obj.name,
|
|
|
obj.description,
|
|
|
obj.published_at,
|
|
|
- obj.yt_id
|
|
|
+ obj.yt_id,
|
|
|
+ obj.views_count
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -235,8 +248,8 @@ namespace components {
|
|
|
Glib::ustring channel_title,
|
|
|
Glib::ustring description,
|
|
|
std::string published_at,
|
|
|
- std::string yt_id
|
|
|
- )
|
|
|
+ std::string yt_id,
|
|
|
+ int views_count)
|
|
|
{
|
|
|
// Главный объект
|
|
|
auto layout = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
|
|
@@ -252,23 +265,33 @@ namespace components {
|
|
|
auto thumbnail = Gtk::make_managed<Gtk::Picture>();
|
|
|
auto lbl_title = Gtk::make_managed<Gtk::Label>();
|
|
|
auto lbl_channel_title = Gtk::make_managed<Gtk::Label>(channel_title);
|
|
|
+ auto lbl_views_count = Gtk::make_managed<Gtk::Label>();
|
|
|
auto lbl_description = Gtk::make_managed<Gtk::Label>(description);
|
|
|
auto lbl_published_at = Gtk::make_managed<Gtk::Label>(published_at);
|
|
|
|
|
|
// Установка названия видео (выделение полужирным)
|
|
|
- lbl_title->set_markup("<b>"+title+"</b>");
|
|
|
+ Glib::ustring title_escaped = Glib::Markup::escape_text(title);
|
|
|
+ lbl_title->set_markup("<b>"+title_escaped+"</b>");
|
|
|
+
|
|
|
+ // Количество просмотров
|
|
|
+ lbl_views_count->set_text(std::to_string(views_count) + " " + "views");
|
|
|
|
|
|
// Добавление кнопки "Воспроизвести"
|
|
|
auto btn_play = Gtk::make_managed<Gtk::Button>();
|
|
|
btn_play->set_child(*(core::getButtonContents("Play video", "player_play")));
|
|
|
btn_play->set_hexpand();
|
|
|
- auto btn_event = PlayButtonParams{ yt_id, btn_play };
|
|
|
btn_play->signal_clicked().connect(sigc::bind(
|
|
|
sigc::mem_fun(*this, &MainWindow::onPlayButtonClicked),
|
|
|
- btn_play
|
|
|
+ PlayButtonParams {yt_id, btn_play}
|
|
|
));
|
|
|
box_buttons->append(*btn_play);
|
|
|
|
|
|
+ // Кнопки оценки видео
|
|
|
+ int my_rating = db::getVideoRating(yt_id);
|
|
|
+ setCurrentVideo(yt_id, my_rating);
|
|
|
+ m_rate_container.unparent();
|
|
|
+ box_buttons->append(m_rate_container);
|
|
|
+
|
|
|
// Добавление кнопки "Открыть в веб-браузере"
|
|
|
auto btn_webbrowser = Gtk::make_managed<Gtk::Button>();
|
|
|
btn_webbrowser->set_child(*(core::getButtonContents("Open in web browser", "web-browser")));
|
|
@@ -280,7 +303,6 @@ namespace components {
|
|
|
|
|
|
// Скачивание большого превью
|
|
|
std::string thumbnail_path = "thumbnails/large/" + yt_id + ".jpg";
|
|
|
- std::cout << thumbnail_path << std::endl;
|
|
|
Glib::RefPtr<Gdk::Pixbuf> thumbnail_pixbuf;
|
|
|
try {
|
|
|
thumbnail_pixbuf = Gdk::Pixbuf::create_from_file(thumbnail_path);
|
|
@@ -302,7 +324,7 @@ namespace components {
|
|
|
thumbnail->set_paintable(thumbnail_texture);
|
|
|
thumbnail->set_content_fit(Gtk::ContentFit::COVER);
|
|
|
thumbnail->set_hexpand();
|
|
|
- thumbnail->set_size_request(-1, 360);
|
|
|
+ thumbnail->set_size_request(-1, 240);
|
|
|
|
|
|
lbl_description->set_halign(Gtk::Align::START);
|
|
|
lbl_description->set_selectable();
|
|
@@ -310,6 +332,7 @@ namespace components {
|
|
|
|
|
|
box_textdetails->append(*lbl_title);
|
|
|
box_textdetails->append(*lbl_channel_title);
|
|
|
+ box_textdetails->append(*lbl_views_count);
|
|
|
box_textdetails->append(*lbl_description);
|
|
|
box_textdetails->append(*lbl_published_at);
|
|
|
box_textdetails->append(*btn_webbrowser);
|
|
@@ -331,13 +354,44 @@ namespace components {
|
|
|
// TODO:
|
|
|
// - Windows
|
|
|
// - MacOs
|
|
|
- std::string command = "xdg-open https://youtu.be/"+yt_id;
|
|
|
+ std::string command = "xdg-open https://youtube.com/watch?v="+yt_id;
|
|
|
system(command.c_str());
|
|
|
}
|
|
|
|
|
|
void MainWindow::onPlayButtonClicked(PlayButtonParams e)
|
|
|
{
|
|
|
+ e.caller->set_sensitive(false);
|
|
|
+ e.caller->set_child(*(core::getButtonContents("mpv started", "window-duplicate")));
|
|
|
MainWindow::playSingleVideo(e.yt_id);
|
|
|
}
|
|
|
|
|
|
+ void MainWindow::onRateButtonClicked(RateButtonParams e)
|
|
|
+ {
|
|
|
+ setCurrentVideo(m_current_yt_id, e.rating);
|
|
|
+ core::rateVideo(m_current_yt_id, e.rating);
|
|
|
+ }
|
|
|
+
|
|
|
+ void MainWindow::setCurrentVideo(std::string yt_id, int rating)
|
|
|
+ {
|
|
|
+ m_current_yt_id = yt_id;
|
|
|
+
|
|
|
+ m_current_rating = rating;
|
|
|
+ m_rate_dislike_btn.set_state_flags(Gtk::StateFlags::NORMAL, true);
|
|
|
+ m_rate_like_btn.set_state_flags(Gtk::StateFlags::NORMAL, true);
|
|
|
+ m_rate_meh_btn.set_state_flags(Gtk::StateFlags::NORMAL, true);
|
|
|
+ switch (rating)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ m_rate_meh_btn.set_state_flags(Gtk::StateFlags::CHECKED);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ m_rate_like_btn.set_state_flags(Gtk::StateFlags::CHECKED);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ m_rate_dislike_btn.set_state_flags(Gtk::StateFlags::CHECKED);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|