diff --git a/org.nickvision.tubeconverter.json b/org.nickvision.tubeconverter.json index a630529e1..219d9ee13 100644 --- a/org.nickvision.tubeconverter.json +++ b/org.nickvision.tubeconverter.json @@ -34,7 +34,7 @@ { "type": "git", "url": "https://github.com/nlogozzo/NickvisionTubeConverter.git", - "tag": "2022.10.0-next" + "tag": "2022.10.0-beta1" } ] } diff --git a/org.nickvision.tubeconverter.metainfo.xml b/org.nickvision.tubeconverter.metainfo.xml index 3f959a079..9d010451a 100644 --- a/org.nickvision.tubeconverter.metainfo.xml +++ b/org.nickvision.tubeconverter.metainfo.xml @@ -24,7 +24,7 @@ org.nickvision.tubeconverter - +

- Redesigned with the latest libadwaita 1.2

diff --git a/src/controllers/adddownloaddialogcontroller.cpp b/src/controllers/adddownloaddialogcontroller.cpp index cbd923386..661d39f66 100644 --- a/src/controllers/adddownloaddialogcontroller.cpp +++ b/src/controllers/adddownloaddialogcontroller.cpp @@ -66,7 +66,7 @@ DownloadCheckStatus AddDownloadDialogController::setDownload(const std::string& DownloadCheckStatus checkStatus{ checkIfDownloadValid() }; if(checkStatus == DownloadCheckStatus::Valid) { - m_configuration.setPreviousSaveFolder(std::filesystem::path(m_download.getSavePath()).parent_path().string() + "/"); + m_configuration.setPreviousSaveFolder(std::filesystem::path(m_download.getSavePath()).parent_path().string()); m_configuration.setPreviousFileType(m_download.getMediaFileType()); m_configuration.save(); } diff --git a/src/controllers/adddownloaddialogcontroller.hpp b/src/controllers/adddownloaddialogcontroller.hpp index 4e43d0637..6f0ddc88e 100644 --- a/src/controllers/adddownloaddialogcontroller.hpp +++ b/src/controllers/adddownloaddialogcontroller.hpp @@ -7,6 +7,9 @@ namespace NickvisionTubeConverter::Controllers { + /** + * Statuses for when a download is checked + */ enum class DownloadCheckStatus { Valid = 0, @@ -17,16 +20,59 @@ namespace NickvisionTubeConverter::Controllers EmptyNewFilename }; + /** + * A controller for the AddDownloadDialog + */ class AddDownloadDialogController { public: + /** + * Constructs an AddDownloadDialogController + * + * @param configuration The Configuration for the application (Stored as a reference) + */ AddDownloadDialogController(NickvisionTubeConverter::Models::Configuration& configuration); + /** + * Gets the response of the dialog + * + * @returns The response of the dialog + */ const std::string& getResponse() const; + /** + * Sets the response of the dialog + * + * @param response The new response of the dialog + */ void setResponse(const std::string& response); + /** + * Gets the previously used saved folder from the configuration + * + * @returns The previously used saved folder + */ std::string getPreviousSaveFolder() const; + /** + * Gets the previously used file type (as an int) from the configuration + * + * @returns The previously used file type (as an int) + */ int getPreviousFileTypeAsInt() const; + /** + * Gets the download created by the dialog + * + * @returns The download created by the dialog + */ const NickvisionTubeConverter::Models::Download& getDownload() const; + /** + * Checks if a download is valid + * + * @returns The DownloadCheckStatus + */ DownloadCheckStatus checkIfDownloadValid() const; + /** + * Sets the download from the dialog and checks if it is valid + * + * @returns The DownloadCheckStatus + */ DownloadCheckStatus setDownload(const std::string& videoUrl, int mediaFileType, const std::string& saveFolder, const std::string& newFilename, int quality); private: diff --git a/src/ui/application.cpp b/src/ui/application.cpp index 5bf41d55b..c619248ed 100644 --- a/src/ui/application.cpp +++ b/src/ui/application.cpp @@ -13,7 +13,7 @@ Application::Application(const std::string& id, GApplicationFlags flags) : m_adw m_appInfo.setName("Nickvision Tube Converter"); m_appInfo.setShortName("Tube Converter"); m_appInfo.setDescription("An easy-to-use YouTube video downloader."); - m_appInfo.setVersion("2022.10.0-next"); + m_appInfo.setVersion("2022.10.0-beta1"); m_appInfo.setChangelog("
  • Redesigned with the latest libadwaita 1.2
"); m_appInfo.setGitHubRepo("https://github.com/nlogozzo/NickvisionTubeConverter"); m_appInfo.setIssueTracker("https://github.com/nlogozzo/NickvisionTubeConverter/issues/new"); diff --git a/src/ui/controls/downloadrow.cpp b/src/ui/controls/downloadrow.cpp index 1211adf2a..a466e1a27 100644 --- a/src/ui/controls/downloadrow.cpp +++ b/src/ui/controls/downloadrow.cpp @@ -1,7 +1,7 @@ #include "downloadrow.hpp" #include +#include #include "messagedialog.hpp" -#include using namespace NickvisionTubeConverter::Models; using namespace NickvisionTubeConverter::UI::Controls; @@ -9,8 +9,12 @@ using namespace NickvisionTubeConverter::UI::Controls; DownloadRow::DownloadRow(GtkWindow* parent, const Download& download) : m_download{ download }, m_gobj{ adw_action_row_new() }, m_parent{ parent } { //Row Settings - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_gobj), m_download.getSavePath().c_str()); - adw_action_row_set_subtitle(ADW_ACTION_ROW(m_gobj), m_download.getVideoUrl().c_str()); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_gobj), std::regex_replace(download.getSavePath(), std::regex("\\&"), "&").c_str()); + adw_action_row_set_subtitle(ADW_ACTION_ROW(m_gobj), std::regex_replace(download.getVideoUrl(), std::regex("\\&"), "&").c_str()); + //Status Image + m_imgStatus = gtk_image_new_from_icon_name("folder-download-symbolic"); + gtk_image_set_pixel_size(GTK_IMAGE(m_imgStatus), 20); + adw_action_row_add_prefix(ADW_ACTION_ROW(m_gobj), m_imgStatus); //Box Downloading m_boxDownloading = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); //ProgBar @@ -51,14 +55,18 @@ void DownloadRow::start() { std::future result{ std::async(std::launch::async, [&]() -> bool { return m_download.download(); }) }; std::future_status status{ std::future_status::timeout }; + gtk_style_context_add_class(gtk_widget_get_style_context(m_imgStatus), "accent"); while(status != std::future_status::ready) { gtk_progress_bar_pulse(GTK_PROGRESS_BAR(m_progBar)); g_main_context_iteration(g_main_context_default(), false); status = result.wait_for(std::chrono::milliseconds(40)); } + bool successful{ result.get() }; + gtk_style_context_remove_class(gtk_widget_get_style_context(m_imgStatus), "accent"); + gtk_style_context_add_class(gtk_widget_get_style_context(m_imgStatus), successful ? "success" : "error"); adw_view_stack_set_visible_child_name(ADW_VIEW_STACK(m_viewStack), "done"); - gtk_level_bar_set_value(GTK_LEVEL_BAR(m_levelBar), result.get() ? 1.0 : 0.0); + gtk_level_bar_set_value(GTK_LEVEL_BAR(m_levelBar), successful ? 1.0 : 0.0); gtk_widget_set_sensitive(m_btnViewLogs, true); } diff --git a/src/ui/controls/downloadrow.hpp b/src/ui/controls/downloadrow.hpp index dd8a2c611..144ed46fd 100644 --- a/src/ui/controls/downloadrow.hpp +++ b/src/ui/controls/downloadrow.hpp @@ -5,23 +5,44 @@ namespace NickvisionTubeConverter::UI::Controls { + /** + * A widget for managing a download + */ class DownloadRow { public: + /** + * Constructs a DownloadRow + * + * @param parent The parent window the holds the row + * @param download The Download model to manage + */ DownloadRow(GtkWindow* parent, const NickvisionTubeConverter::Models::Download& download); + /** + * Gets the GtkWidget* representing the DownloadRow + * + * @returns The GtkWidget* representing the DownloadRow + */ GtkWidget* gobj(); + /** + * Starts the Download managed by the row + */ void start(); private: NickvisionTubeConverter::Models::Download m_download; GtkWidget* m_gobj; GtkWindow* m_parent; + GtkWidget* m_imgStatus; GtkWidget* m_viewStack; GtkWidget* m_boxDownloading; GtkWidget* m_progBar; GtkWidget* m_boxDone; GtkWidget* m_levelBar; GtkWidget* m_btnViewLogs; + /** + * Displays a MessageDialog with the log from the download + */ void onViewLogs(); }; } \ No newline at end of file diff --git a/src/ui/views/mainwindow.cpp b/src/ui/views/mainwindow.cpp index a118d1fd4..43ca76d65 100644 --- a/src/ui/views/mainwindow.cpp +++ b/src/ui/views/mainwindow.cpp @@ -18,6 +18,7 @@ MainWindow::MainWindow(GtkApplication* application, const MainWindowController& gtk_widget_set_size_request(m_gobj, 800, 600); gtk_window_set_default_size(GTK_WINDOW(m_gobj), 1000, 800); gtk_style_context_add_class(gtk_widget_get_style_context(m_gobj), "devel"); + g_signal_connect(m_gobj, "close_request", G_CALLBACK((void (*)(GtkWidget*, gpointer))[](GtkWidget*, gpointer data) { reinterpret_cast(data)->onCloseRequest(); }), this); //Header Bar m_headerBar = adw_header_bar_new(); m_adwTitle = adw_window_title_new(m_controller.getAppInfo().getShortName().c_str(), nullptr); @@ -106,6 +107,11 @@ void MainWindow::start() m_controller.startup(); } +void MainWindow::onCloseRequest() +{ + m_downloadRows.clear(); +} + void MainWindow::onAddDownload() { AddDownloadDialogController addDownloadDialogController{ m_controller.createAddDownloadDialogController() }; diff --git a/src/ui/views/mainwindow.hpp b/src/ui/views/mainwindow.hpp index 20ef22089..610fbe68e 100644 --- a/src/ui/views/mainwindow.hpp +++ b/src/ui/views/mainwindow.hpp @@ -50,6 +50,10 @@ namespace NickvisionTubeConverter::UI::Views GSimpleAction* m_actKeyboardShortcuts{ nullptr }; GSimpleAction* m_actAbout{ nullptr }; std::vector> m_downloadRows; + /** + * Runs closing functions + */ + void onCloseRequest(); /** * Prompts the user to add a download with AddDownloadDialog */