Skip to content

Commit

Permalink
V2022.10.0-beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Oct 9, 2022
1 parent 86e4684 commit 4b446f6
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 8 deletions.
2 changes: 1 addition & 1 deletion org.nickvision.tubeconverter.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"type": "git",
"url": "https://github.com/nlogozzo/NickvisionTubeConverter.git",
"tag": "2022.10.0-next"
"tag": "2022.10.0-beta1"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion org.nickvision.tubeconverter.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<binary>org.nickvision.tubeconverter</binary>
</provides>
<releases>
<release version="2022.10.0-next" date="2022-10-01">
<release version="2022.10.0-beta1" date="2022-10-09">
<description>
<p>- Redesigned with the latest libadwaita 1.2</p>
</description>
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/adddownloaddialogcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
46 changes: 46 additions & 0 deletions src/controllers/adddownloaddialogcontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace NickvisionTubeConverter::Controllers
{
/**
* Statuses for when a download is checked
*/
enum class DownloadCheckStatus
{
Valid = 0,
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/ui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("<ul><li>Redesigned with the latest libadwaita 1.2</li></ul>");
m_appInfo.setGitHubRepo("https://github.com/nlogozzo/NickvisionTubeConverter");
m_appInfo.setIssueTracker("https://github.com/nlogozzo/NickvisionTubeConverter/issues/new");
Expand Down
16 changes: 12 additions & 4 deletions src/ui/controls/downloadrow.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include "downloadrow.hpp"
#include <future>
#include <regex>
#include "messagedialog.hpp"
#include <iostream>

using namespace NickvisionTubeConverter::Models;
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("\\&"), "&amp;").c_str());
adw_action_row_set_subtitle(ADW_ACTION_ROW(m_gobj), std::regex_replace(download.getVideoUrl(), std::regex("\\&"), "&amp;").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
Expand Down Expand Up @@ -51,14 +55,18 @@ void DownloadRow::start()
{
std::future<bool> 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);
}

Expand Down
21 changes: 21 additions & 0 deletions src/ui/controls/downloadrow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}
6 changes: 6 additions & 0 deletions src/ui/views/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainWindow*>(data)->onCloseRequest(); }), this);
//Header Bar
m_headerBar = adw_header_bar_new();
m_adwTitle = adw_window_title_new(m_controller.getAppInfo().getShortName().c_str(), nullptr);
Expand Down Expand Up @@ -106,6 +107,11 @@ void MainWindow::start()
m_controller.startup();
}

void MainWindow::onCloseRequest()
{
m_downloadRows.clear();
}

void MainWindow::onAddDownload()
{
AddDownloadDialogController addDownloadDialogController{ m_controller.createAddDownloadDialogController() };
Expand Down
4 changes: 4 additions & 0 deletions src/ui/views/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ namespace NickvisionTubeConverter::UI::Views
GSimpleAction* m_actKeyboardShortcuts{ nullptr };
GSimpleAction* m_actAbout{ nullptr };
std::vector<std::shared_ptr<NickvisionTubeConverter::UI::Controls::DownloadRow>> m_downloadRows;
/**
* Runs closing functions
*/
void onCloseRequest();
/**
* Prompts the user to add a download with AddDownloadDialog
*/
Expand Down

0 comments on commit 4b446f6

Please sign in to comment.