浏览代码

Очередь: начало реализации

Вадим Королёв 1 年之前
父节点
当前提交
c2b04907a6
共有 7 个文件被更改,包括 54 次插入7 次删除
  1. 1 0
      lib/Database/entities.hpp
  2. 2 2
      meson.build
  3. 25 3
      src/YTMPV/MainWindow.cpp
  4. 11 0
      src/YTMPV/MainWindow.hpp
  5. 6 0
      src/YTMPV/core.cpp
  6. 8 2
      src/YTMPV/core.hpp
  7. 1 0
      src/YTMPV/res/MainWindow.ui

+ 1 - 0
lib/Database/entities.hpp

@@ -1,4 +1,5 @@
 #pragma once
+
 #include <string>
 #include <glibmm/ustring.h>
 

+ 2 - 2
meson.build

@@ -9,10 +9,10 @@ project('YTMPV', 'cpp',
 )
 
 glibmm_dep = dependency('glibmm-2.68')
-curlpp_dep = dependency('curlpp')
+curlpp_dep = dependency('libcurl')
 json_dep = dependency('nlohmann_json')
 sqlite3_dep = dependency('sqlite3')
 gtkmm_dep = dependency('gtkmm-4.0')
 
 subdir('lib')
-subdir('src/YTMPV')
+subdir('src/YTMPV')

+ 25 - 3
src/YTMPV/MainWindow.cpp

@@ -249,6 +249,10 @@ namespace components {
 
         auto queue_button = dynamic_cast<Gtk::Button*>(play_button->get_next_sibling());
         if (!queue_button) return;
+        queue_button->signal_clicked().connect(sigc::bind(
+            sigc::mem_fun(*this, &MainWindow::onAddToQueueButtonClicked),
+            AddToQueueParams {obj.ytid}
+        ));
 
         // Загрузка изображения превью видео с диска
         // TODO: ~/.cache/ytmpv/thumbnails -- брать из appcore
@@ -302,9 +306,6 @@ namespace components {
 
     void MainWindow::playSingleVideo(std::string ytid)
     {
-        // Запуск mpv в заднем фоне
-        std::string yt_url = "https://youtu.be/"+ytid;
-
         Glib::spawn_async(
             "",
             m_appcore->getMPVLaunchParams(ytid),
@@ -312,6 +313,15 @@ namespace components {
         );
     }
 
+    void MainWindow::playQueue()
+    {
+        Glib::spawn_async(
+            "",
+            m_appcore->getMPVLaunchParams(m_appcore->getQueueYTIDs()),
+            Glib::SpawnFlags::DEFAULT
+        );
+    }
+
     void MainWindow::searchSidebarRegularMode()
     {
         // Получить иконку поиска и создать надпись "Поиск"
@@ -493,4 +503,16 @@ namespace components {
                 break;
         }
     }
+
+    void MainWindow::onAddToQueueButtonClicked(AddToQueueParams e)
+    {
+        m_appcore->addVideoToQueue(e.ytid);
+        setQueueBarVisibility(true);
+    }
+
+    void MainWindow::setQueueBarVisibility(bool visible)
+    {
+        auto queue_container = m_builder->get_widget<Gtk::Box>("queue");
+        queue_container->set_visible(visible);
+    }
 }

+ 11 - 0
src/YTMPV/MainWindow.hpp

@@ -33,6 +33,12 @@ namespace
         // Какая оценка
         core:: VideoRating rating;
     };
+
+    struct AddToQueueParams
+    {
+        // Какое видео
+        std::string ytid;
+    };
 }
 
 namespace components {
@@ -88,6 +94,8 @@ namespace components {
         void onPlayButtonClicked(PlayButtonParams e);
         // При клике на кнопку оценки видео
         void onRateButtonClicked(RateButtonParams e);
+        // При клике на кнопку добавления в очередь
+        void onAddToQueueButtonClicked(AddToQueueParams e);
 
         // --Общее--
         // Оценка выбранного видео
@@ -117,6 +125,9 @@ namespace components {
             int views_count,
             std::string thumbnail_url);
 
+        // Устанавливает видимость меню очереди
+        void setQueueBarVisibility(bool visible);
+
         // Проигрывает конкретное видео
         void playSingleVideo(std::string yt_id);
         // Открывает страницу видео в YouTube

+ 6 - 0
src/YTMPV/core.cpp

@@ -26,6 +26,7 @@ namespace core {
         , m_launch_miniplayer(launch_miniplayer)
         , m_mpvpath(mpvpath)
         , m_thumbnails_dir(thumbnails_dir)
+        , m_queue()
     {}
 
     void Core::setQuality(int quality)
@@ -259,4 +260,9 @@ namespace core {
         output << std::put_time(&t, "%c");
         return output.str();
     }
+
+    void Core::addVideoToQueue(std::string ytid)
+    {
+        m_queue.push_back(ytid);
+    }
 }

+ 8 - 2
src/YTMPV/core.hpp

@@ -103,9 +103,9 @@ namespace core
             // Если оценка текущего видео такова же как и устанавливаемая,
             // запрос не произойдёт в целях экономии квоты API
             void rateVideo(std::string ytid, VideoRating rating);
-
+            
             // Возвращает параметры запуска MPV
-            std::vector<std::string> getMPVLaunchParams(std::string ytid);
+            std::vector<std::string> getMPVLaunchParams(std::vector<std::string> videos);
 
             // Возвращает ссылку на видео по его ytid
             std::string getYTLink(std::string ytid);
@@ -125,6 +125,9 @@ namespace core
             // Возвращает unix-время от времени публикации видео
             std::string getDateText(std::string date);
 
+            // Добавляет видео в очередь
+            void addVideoToQueue(std::string ytid);
+
         protected:
             // ключ API
             std::string m_apikey;
@@ -161,5 +164,8 @@ namespace core
 
             // Путь к директории кэшированных превью видео
             std::string m_thumbnails_dir;
+
+            // Очередь видео
+            std::vector<std::string> m_queue;
     };
 }

+ 1 - 0
src/YTMPV/res/MainWindow.ui

@@ -24,6 +24,7 @@
             <property name="margin-start">8</property>
             <property name="margin-top">8</property>
             <property name="spacing">8</property>
+            <property name="visible">False</property>
             
             <child>
               <object class="GtkLabel">