v1.0.8: Adding recommended products (With comission)

This commit is contained in:
Sergiotarxz 2024-11-08 23:09:23 +01:00
parent 9cec53747f
commit 04dc171c25
7 changed files with 116 additions and 1 deletions

BIN
images/printer-1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

BIN
images/printer-2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

BIN
images/roll-1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
images/roll-2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
images/roll-3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -25,7 +25,7 @@ has device => ( is => 'rw' );
has _pay_url => ( is => 'lazy' );
has _activated => ( is => 'rw' );
has _last_valid_preview_file => ( is => 'rw' );
has _is_showing_paywall => (is => 'rw');
has _is_showing_paywall => ( is => 'rw' );
has file_format => (
is => 'rw',
default => sub {
@ -395,6 +395,9 @@ sub _create_popover_menu( $self, $box ) {
Glib::IO::SimpleAction->new( 'save-as.' . $self->instance_id, undef );
my $about_action =
Glib::IO::SimpleAction->new( 'about.' . $self->instance_id, undef );
my $good_printers_action =
Glib::IO::SimpleAction->new( 'good-printers.' . $self->instance_id,
undef );
my $app = $self->app->_app;
$about_action->signal_connect(
'activate',
@ -402,6 +405,11 @@ sub _create_popover_menu( $self, $box ) {
$self->_show_about_dialog;
}
);
$good_printers_action->signal_connect(
activate => sub {
$self->_show_recommended_printers;
}
);
$open_action->signal_connect(
'activate',
sub {
@ -424,16 +432,118 @@ sub _create_popover_menu( $self, $box ) {
$app->add_action($save_action);
$app->add_action($save_as_action);
$app->add_action($about_action);
$app->add_action($good_printers_action);
$file_menu->append( 'Open', 'app.open.' . $self->instance_id );
$file_menu->append( 'Save', 'app.save.' . $self->instance_id );
$file_menu->append( 'Save as', 'app.save-as.' . $self->instance_id );
$help_menu->append( 'About', 'app.about.' . $self->instance_id );
$help_menu->append( 'Recommended printers and supplies',
'app.good-printers.' . $self->instance_id );
$menu_model->append_submenu( 'File', $file_menu );
$menu_model->append_submenu( 'Help', $help_menu );
my $popover = Gtk4::PopoverMenuBar->new_from_model($menu_model);
$box->append($popover);
}
sub _show_recommended_printers($self) {
my $win = Gtk4::Window->new;
$win->set_title('Recommended printers and supplies');
$win->set_default_size(1000, 700);
my $scroll = Gtk4::ScrolledWindow->new;
my $box = Gtk4::Box->new('vertical', 1);
$scroll->set_child($box);
my $explain = Gtk4::Label->new(undef);
my @products = (
{
url => 'https://amzn.to/3V7oV7p',
country => 'USA',
description => 'Tested printer, uses standard protocol, advertised as only working by bluetooth but the model I got works by usb too. Perfectly supported',
image => 'images/printer-1.jpg',
},
{
url => 'https://amzn.to/3ULFuFz',
country => 'USA',
description => 'Rolls of normal thermal papel',
image => 'images/roll-3.jpg',
},
{
url => 'https://amzn.to/3O3DGEd',
country => 'Europe',
description => 'Advertised as having bluetooth and usb support, works fine, Perfectly supported',
image => 'images/printer-2.jpg',
},
{
url => 'https://amzn.to/3YXWjj1',
country => 'Europe',
description => 'Tested printer, uses standard protocol, advertised as only working by bluetooth but the model I got works by usb too. Perfectly supported',
image => 'images/printer-1.jpg',
},
{
url => 'https://amzn.to/4elBYZC',
country => 'Europe',
description => 'Rolls of normal thermal papel',
image => 'images/roll-1.jpg',
},
{
url => 'https://amzn.to/4eno7BK',
country => 'Europe',
description => 'Rolls of sticker thermal papel',
image => 'images/roll-2.jpg',
},
);
$explain->set_markup(
'<b><big>Recommended products:</big></b>
I get a comission each time you buy one of those using these links.'
);
$box->append($explain);
for my $product (@products) {
my $product_box = Gtk4::Box->new('horizontal', 10);
my $image_file = path(__FILE__)->parent->parent->parent->parent->child($product->{image});
my $image = Gtk4::Image->new_from_file($image_file);
$image->set_pixel_size(256);
$product_box->append($image);
my $right_side_product_box = Gtk4::Box->new('vertical', 10);
my $label_available_in = Gtk4::Label->new(undef);
$label_available_in->set_halign('start');
$label_available_in->set_markup('<small>Available in: '.$product->{country}.'</small>');
$right_side_product_box->append($label_available_in);
my @lines = split /\n/, $product->{description};
for (my $i = 0; 1 ; $i++) {
if (!($i < scalar @lines)) {
last;
}
my $line = $lines[$i];
my $size_line = 60;
if (length $line > $size_line) {
splice @lines, $i, 1, substr($line, 0, $size_line), substr($line, $size_line);
}
}
$product->{description} = join "\n", @lines;
my $label_description = Gtk4::Label->new($product->{description});
$label_description->set_halign('start');
$right_side_product_box->append($label_description);
my $buy_button = Gtk4::Button->new_with_label('Buy now');
$buy_button->set_halign('end');
$buy_button->signal_connect(clicked => sub{
my $launcher = Gtk4::UriLauncher->new( $product->{url} );
$launcher->launch( $self->window, undef, undef );
});
$right_side_product_box->append($buy_button);
$product_box->append($right_side_product_box);
$box->append($product_box);
}
$win->set_child($scroll);
$win->set_transient_for( $self->window );
$win->present;
}
sub _populate_editor( $self, $box_editor_preview ) {
my $editor = Gtk4::Source::View->new;
$self->_editor($editor);

View File

@ -30,6 +30,11 @@
<releases>
<release version="v1.0.7" date="2024-11-08">
<description>
<p>Adding recommended products to use with the IDE</p>
</description>
</release>
<release version="v1.0.6" date="2024-11-06">
<description>
<p>Fixing brand color dark theme</p>