2018-12-11 10:33:11 +01:00
#include "PrintHostDialogs.hpp"
2018-12-14 15:27:34 +01:00
#include <algorithm>
2021-03-12 10:30:06 +01:00
#include <iomanip>
2018-12-14 15:27:34 +01:00
2018-12-11 10:33:11 +01:00
#include <wx/frame.h>
#include <wx/progdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
2018-12-14 15:27:34 +01:00
#include <wx/button.h>
#include <wx/dataview.h>
#include <wx/wupdlock.h>
#include <wx/debug.h>
2018-12-11 10:33:11 +01:00
2021-03-12 10:30:06 +01:00
#include <boost/log/trivial.hpp>
#include <boost/filesystem.hpp>
2021-03-12 11:30:06 +01:00
#include <boost/nowide/convert.hpp>
2021-03-12 10:30:06 +01:00
2018-12-14 15:27:34 +01:00
#include "GUI.hpp"
2018-12-20 13:36:49 +01:00
#include "GUI_App.hpp"
2018-12-14 15:27:34 +01:00
#include "MsgDialog.hpp"
#include "I18N.hpp"
#include "../Utils/PrintHost.hpp"
2020-12-04 13:34:44 +01:00
#include "MainFrame.hpp"
2020-08-08 17:03:20 +02:00
#include "libslic3r/AppConfig.hpp"
2021-03-04 21:56:07 +01:00
#include "NotificationManager.hpp"
2018-12-11 10:33:11 +01:00
namespace fs = boost :: filesystem ;
namespace Slic3r {
2018-12-14 15:27:34 +01:00
namespace GUI {
2019-02-18 14:03:02 +01:00
static const char * CONFIG_KEY_PATH = "printhost_path" ;
static const char * CONFIG_KEY_PRINT = "printhost_print" ;
2020-10-28 09:51:05 +01:00
static const char * CONFIG_KEY_GROUP = "printhost_group" ;
2018-12-11 10:33:11 +01:00
2020-10-28 09:51:05 +01:00
PrintHostSendDialog :: PrintHostSendDialog ( const fs :: path & path , bool can_start_print , const wxArrayString & groups )
2020-12-04 13:34:44 +01:00
: MsgDialog ( static_cast < wxWindow *> ( wxGetApp (). mainframe ), _L ( "Send G-Code to printer host" ), _L ( "Upload to Printer Host with the following filename:" ), wxID_NONE )
2019-02-18 14:03:02 +01:00
, txt_filename ( new wxTextCtrl ( this , wxID_ANY ))
2020-10-28 09:51:05 +01:00
, box_print ( can_start_print ? new wxCheckBox ( this , wxID_ANY , _L ( "Start printing after upload" )) : nullptr )
, combo_groups ( ! groups . IsEmpty () ? new wxComboBox ( this , wxID_ANY , wxEmptyString , wxDefaultPosition , wxDefaultSize , groups , wxCB_READONLY ) : nullptr )
2018-12-11 10:33:11 +01:00
{
2019-01-24 11:53:37 +01:00
#ifdef __APPLE__
txt_filename -> OSXDisableAllSmartSubstitutions ();
#endif
2019-03-04 16:50:43 +01:00
const AppConfig * app_config = wxGetApp (). app_config ;
2019-01-24 11:53:37 +01:00
2020-10-28 09:51:05 +01:00
auto * label_dir_hint = new wxStaticText ( this , wxID_ANY , _L ( "Use forward slashes ( / ) as a directory separator if needed." ));
2019-02-21 18:59:21 +01:00
label_dir_hint -> Wrap ( CONTENT_WIDTH * wxGetApp (). em_unit ());
2018-12-11 10:33:11 +01:00
content_sizer -> Add ( txt_filename , 0 , wxEXPAND );
content_sizer -> Add ( label_dir_hint );
content_sizer -> AddSpacer ( VERT_SPACING );
2019-03-04 16:50:43 +01:00
if ( box_print != nullptr ) {
content_sizer -> Add ( box_print , 0 , wxBOTTOM , 2 * VERT_SPACING );
box_print -> SetValue ( app_config -> get ( "recent" , CONFIG_KEY_PRINT ) == "1" );
}
2020-10-28 09:51:05 +01:00
if ( combo_groups != nullptr ) {
// Repetier specific: Show a selection of file groups.
auto * label_group = new wxStaticText ( this , wxID_ANY , _L ( "Group" ));
content_sizer -> Add ( label_group );
content_sizer -> Add ( combo_groups , 0 , wxBOTTOM , 2 * VERT_SPACING );
wxString recent_group = from_u8 ( app_config -> get ( "recent" , CONFIG_KEY_GROUP ));
if ( ! recent_group . empty ())
combo_groups -> SetValue ( recent_group );
}
2018-12-11 10:33:11 +01:00
btn_sizer -> Add ( CreateStdDialogButtonSizer ( wxOK | wxCANCEL ));
2019-02-18 14:03:02 +01:00
wxString recent_path = from_u8 ( app_config -> get ( "recent" , CONFIG_KEY_PATH ));
if ( recent_path . Length () > 0 && recent_path [ recent_path . Length () - 1 ] != '/' ) {
recent_path += '/' ;
}
const auto recent_path_len = recent_path . Length ();
recent_path += path . filename (). wstring ();
2018-12-11 10:33:11 +01:00
wxString stem ( path . stem (). wstring ());
2019-02-18 14:03:02 +01:00
const auto stem_len = stem . Length ();
txt_filename -> SetValue ( recent_path );
txt_filename -> SetFocus ();
2020-10-28 09:51:05 +01:00
2018-12-11 10:33:11 +01:00
Fit ();
2020-12-04 13:34:44 +01:00
CenterOnParent ();
2019-02-18 14:03:02 +01:00
2021-01-06 12:23:42 +01:00
#ifdef __linux__
// On Linux with GTK2 when text control lose the focus then selection (colored background) disappears but text color stay white
// and as a result the text is invisible with light mode
// see https://github.com/prusa3d/PrusaSlicer/issues/4532
// Workaround: Unselect text selection explicitly on kill focus
txt_filename -> Bind ( wxEVT_KILL_FOCUS , [ this ]( wxEvent & e ) {
e . Skip ();
txt_filename -> SetInsertionPoint ( txt_filename -> GetLastPosition ());
}, txt_filename -> GetId ());
#endif /* __linux__ */
2019-02-18 14:03:02 +01:00
Bind ( wxEVT_SHOW , [ = ]( const wxShowEvent & ) {
// Another similar case where the function only works with EVT_SHOW + CallAfter,
// this time on Mac.
CallAfter ([ = ]() {
txt_filename -> SetSelection ( recent_path_len , recent_path_len + stem_len );
});
});
2018-12-11 10:33:11 +01:00
}
fs :: path PrintHostSendDialog :: filename () const
{
2019-01-02 15:11:05 +01:00
return into_path ( txt_filename -> GetValue ());
2018-12-11 10:33:11 +01:00
}
bool PrintHostSendDialog :: start_print () const
{
2019-03-04 16:50:43 +01:00
return box_print != nullptr ? box_print -> GetValue () : false ;
2018-12-11 10:33:11 +01:00
}
2018-12-14 15:27:34 +01:00
2020-10-28 09:51:05 +01:00
std :: string PrintHostSendDialog :: group () const
{
if ( combo_groups == nullptr ) {
return "" ;
} else {
wxString group = combo_groups -> GetValue ();
return into_u8 ( group );
}
}
2019-02-18 14:03:02 +01:00
void PrintHostSendDialog :: EndModal ( int ret )
{
if ( ret == wxID_OK ) {
// Persist path and print settings
wxString path = txt_filename -> GetValue ();
int last_slash = path . Find ( '/' , true );
2019-05-15 10:24:03 +02:00
if ( last_slash == wxNOT_FOUND )
path . clear ();
else
2019-02-18 14:03:02 +01:00
path = path . SubString ( 0 , last_slash );
2020-10-28 09:51:05 +01:00
2019-05-15 10:24:03 +02:00
AppConfig * app_config = wxGetApp (). app_config ;
app_config -> set ( "recent" , CONFIG_KEY_PATH , into_u8 ( path ));
app_config -> set ( "recent" , CONFIG_KEY_PRINT , start_print () ? "1" : "0" );
2020-10-28 09:51:05 +01:00
if ( combo_groups != nullptr ) {
wxString group = combo_groups -> GetValue ();
app_config -> set ( "recent" , CONFIG_KEY_GROUP , into_u8 ( group ));
}
2019-02-18 14:03:02 +01:00
}
MsgDialog :: EndModal ( ret );
}
2018-12-14 15:27:34 +01:00
wxDEFINE_EVENT ( EVT_PRINTHOST_PROGRESS , PrintHostQueueDialog :: Event );
2018-12-20 13:36:49 +01:00
wxDEFINE_EVENT ( EVT_PRINTHOST_ERROR , PrintHostQueueDialog :: Event );
wxDEFINE_EVENT ( EVT_PRINTHOST_CANCEL , PrintHostQueueDialog :: Event );
2018-12-14 15:27:34 +01:00
PrintHostQueueDialog :: Event :: Event ( wxEventType eventType , int winid , size_t job_id )
: wxEvent ( winid , eventType )
, job_id ( job_id )
{}
PrintHostQueueDialog :: Event :: Event ( wxEventType eventType , int winid , size_t job_id , int progress )
: wxEvent ( winid , eventType )
, job_id ( job_id )
, progress ( progress )
{}
PrintHostQueueDialog :: Event :: Event ( wxEventType eventType , int winid , size_t job_id , wxString error )
: wxEvent ( winid , eventType )
, job_id ( job_id )
, error ( std :: move ( error ))
{}
wxEvent * PrintHostQueueDialog :: Event :: Clone () const
{
return new Event ( * this );
}
PrintHostQueueDialog :: PrintHostQueueDialog ( wxWindow * parent )
2020-10-28 09:51:05 +01:00
: DPIDialog ( parent , wxID_ANY , _L ( "Print host upload queue" ), wxDefaultPosition , wxDefaultSize , wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
2018-12-14 15:27:34 +01:00
, on_progress_evt ( this , EVT_PRINTHOST_PROGRESS , & PrintHostQueueDialog :: on_progress , this )
, on_error_evt ( this , EVT_PRINTHOST_ERROR , & PrintHostQueueDialog :: on_error , this )
2018-12-20 13:36:49 +01:00
, on_cancel_evt ( this , EVT_PRINTHOST_CANCEL , & PrintHostQueueDialog :: on_cancel , this )
2018-12-14 15:27:34 +01:00
{
2019-02-21 18:59:21 +01:00
const auto em = GetTextExtent ( "m" ). x ;
2018-12-14 15:27:34 +01:00
auto * topsizer = new wxBoxSizer ( wxVERTICAL );
2021-03-11 13:35:19 +01:00
std :: vector < int > widths ;
widths . reserve ( 6 );
if ( ! load_user_data ( UDT_COLS , widths )) {
widths . clear ();
for ( size_t i = 0 ; i < 6 ; i ++ )
widths . push_back ( - 1 );
}
2018-12-14 15:27:34 +01:00
job_list = new wxDataViewListCtrl ( this , wxID_ANY );
2018-12-20 11:50:08 +01:00
// Note: Keep these in sync with Column
2021-03-11 13:35:19 +01:00
job_list -> AppendTextColumn ( _L ( "ID" ), wxDATAVIEW_CELL_INERT , widths [ 0 ], wxALIGN_LEFT , wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE );
job_list -> AppendProgressColumn ( _L ( "Progress" ), wxDATAVIEW_CELL_INERT , widths [ 1 ], wxALIGN_LEFT , wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE );
job_list -> AppendTextColumn ( _L ( "Status" ), wxDATAVIEW_CELL_INERT , widths [ 2 ], wxALIGN_LEFT , wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE );
job_list -> AppendTextColumn ( _L ( "Host" ), wxDATAVIEW_CELL_INERT , widths [ 3 ], wxALIGN_LEFT , wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE );
job_list -> AppendTextColumn ( _CTX_utf8 ( L_CONTEXT ( "Size" , "OfFile" ), "OfFile" ), wxDATAVIEW_CELL_INERT , widths [ 4 ], wxALIGN_LEFT , wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE );
job_list -> AppendTextColumn ( _L ( "Filename" ), wxDATAVIEW_CELL_INERT , widths [ 5 ], wxALIGN_LEFT , wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE );
2020-10-28 09:51:05 +01:00
job_list -> AppendTextColumn ( _L ( "Error Message" ), wxDATAVIEW_CELL_INERT , - 1 , wxALIGN_CENTER , wxDATAVIEW_COL_HIDDEN );
2021-03-11 13:35:19 +01:00
2018-12-14 15:27:34 +01:00
auto * btnsizer = new wxBoxSizer ( wxHORIZONTAL );
2020-10-28 09:51:05 +01:00
btn_cancel = new wxButton ( this , wxID_DELETE , _L ( "Cancel selected" ));
2018-12-20 11:50:08 +01:00
btn_cancel -> Disable ();
2020-10-28 09:51:05 +01:00
btn_error = new wxButton ( this , wxID_ANY , _L ( "Show error message" ));
2018-12-20 11:50:08 +01:00
btn_error -> Disable ();
2020-10-28 09:51:05 +01:00
// Note: The label needs to be present, otherwise we get accelerator bugs on Mac
auto * btn_close = new wxButton ( this , wxID_CANCEL , _L ( "Close" ));
2018-12-14 15:27:34 +01:00
btnsizer -> Add ( btn_cancel , 0 , wxRIGHT , SPACING );
2018-12-20 11:50:08 +01:00
btnsizer -> Add ( btn_error , 0 );
2018-12-14 15:27:34 +01:00
btnsizer -> AddStretchSpacer ();
btnsizer -> Add ( btn_close );
topsizer -> Add ( job_list , 1 , wxEXPAND | wxBOTTOM , SPACING );
topsizer -> Add ( btnsizer , 0 , wxEXPAND );
SetSizer ( topsizer );
2018-12-20 11:50:08 +01:00
2021-03-11 13:35:19 +01:00
std :: vector < int > size ;
SetSize ( load_user_data ( UDT_SIZE , size ) ? wxSize ( size [ 0 ] * em , size [ 1 ] * em ) : wxSize ( HEIGHT * em , WIDTH * em ));
Bind ( wxEVT_SIZE , [ this , em ]( wxSizeEvent & evt ) {
OnSize ( evt );
save_user_data ( UDT_SIZE | UDT_POSITION | UDT_COLS );
});
std :: vector < int > pos ;
if ( load_user_data ( UDT_POSITION , pos ))
SetPosition ( wxPoint ( pos [ 0 ], pos [ 1 ]));
Bind ( wxEVT_MOVE , [ this , em ]( wxMoveEvent & evt ) {
save_user_data ( UDT_SIZE | UDT_POSITION | UDT_COLS );
});
2020-09-15 15:23:39 +02:00
2018-12-20 11:50:08 +01:00
job_list -> Bind ( wxEVT_DATAVIEW_SELECTION_CHANGED , [ this ]( wxDataViewEvent & ) { on_list_select (); });
btn_cancel -> Bind ( wxEVT_BUTTON , [ this ]( wxCommandEvent & ) {
int selected = job_list -> GetSelectedRow ();
if ( selected == wxNOT_FOUND ) { return ; }
const JobState state = get_state ( selected );
if ( state < ST_ERROR ) {
// TODO: cancel
2018-12-20 13:36:49 +01:00
GUI :: wxGetApp (). printhost_job_queue (). cancel ( selected );
2018-12-20 11:50:08 +01:00
}
});
btn_error -> Bind ( wxEVT_BUTTON , [ this ]( wxCommandEvent & ) {
int selected = job_list -> GetSelectedRow ();
if ( selected == wxNOT_FOUND ) { return ; }
GUI :: show_error ( nullptr , job_list -> GetTextValue ( selected , COL_ERRORMSG ));
});
2018-12-14 15:27:34 +01:00
}
void PrintHostQueueDialog :: append_job ( const PrintHostJob & job )
{
wxCHECK_RET ( ! job . empty (), "PrintHostQueueDialog: Attempt to append an empty job" );
wxVector < wxVariant > fields ;
fields . push_back ( wxVariant ( wxString :: Format ( "%d" , job_list -> GetItemCount () + 1 )));
fields . push_back ( wxVariant ( 0 ));
2020-10-28 09:51:05 +01:00
fields . push_back ( wxVariant ( _L ( "Enqueued" )));
2018-12-14 15:27:34 +01:00
fields . push_back ( wxVariant ( job . printhost -> get_host ()));
2021-03-11 13:35:19 +01:00
boost :: system :: error_code ec ;
boost :: uintmax_t size_i = boost :: filesystem :: file_size ( job . upload_data . source_path , ec );
2021-03-11 16:32:20 +01:00
std :: stringstream stream ;
if ( ec ) {
stream << "unknown" ;
size_i = 0 ;
2021-03-11 13:35:19 +01:00
BOOST_LOG_TRIVIAL ( error ) << ec . message ();
2021-03-11 16:32:20 +01:00
} else
stream << std :: fixed << std :: setprecision ( 2 ) << (( float ) size_i / 1024 / 1024 ) << "MB" ;
fields . push_back ( wxVariant ( stream . str ()));
2018-12-14 15:27:34 +01:00
fields . push_back ( wxVariant ( job . upload_data . upload_path . string ()));
2018-12-20 11:50:08 +01:00
fields . push_back ( wxVariant ( "" ));
job_list -> AppendItem ( fields , static_cast < wxUIntPtr > ( ST_NEW ));
2020-12-12 11:26:17 +01:00
// Both strings are UTF-8 encoded.
2020-12-10 10:58:40 +01:00
upload_names . emplace_back ( job . printhost -> get_host (), job . upload_data . upload_path . string ());
2021-03-04 21:56:07 +01:00
2021-03-12 10:19:13 +01:00
//wxGetApp().notification_manager()->push_upload_job_notification(this, job_list->GetItemCount(), 0, job.upload_data.upload_path.string(), job.printhost->get_host());
2018-12-20 11:50:08 +01:00
}
2019-04-25 15:06:44 +02:00
void PrintHostQueueDialog :: on_dpi_changed ( const wxRect & suggested_rect )
{
const int & em = em_unit ();
msw_buttons_rescale ( this , em , { wxID_DELETE , wxID_CANCEL , btn_error -> GetId () });
SetMinSize ( wxSize ( HEIGHT * em , WIDTH * em ));
Fit ();
Refresh ();
2021-03-11 13:35:19 +01:00
save_user_data ( UDT_SIZE | UDT_POSITION | UDT_COLS );
2019-04-25 15:06:44 +02:00
}
2018-12-20 11:50:08 +01:00
PrintHostQueueDialog :: JobState PrintHostQueueDialog :: get_state ( int idx )
{
wxCHECK_MSG ( idx >= 0 && idx < job_list -> GetItemCount (), ST_ERROR , "Out of bounds access to job list" );
return static_cast < JobState > ( job_list -> GetItemData ( job_list -> RowToItem ( idx )));
}
void PrintHostQueueDialog :: set_state ( int idx , JobState state )
{
wxCHECK_RET ( idx >= 0 && idx < job_list -> GetItemCount (), "Out of bounds access to job list" );
job_list -> SetItemData ( job_list -> RowToItem ( idx ), static_cast < wxUIntPtr > ( state ));
2018-12-20 13:36:49 +01:00
switch ( state ) {
2020-10-28 09:51:05 +01:00
case ST_NEW : job_list -> SetValue ( _L ( "Enqueued" ), idx , COL_STATUS ); break ;
case ST_PROGRESS : job_list -> SetValue ( _L ( "Uploading" ), idx , COL_STATUS ); break ;
case ST_ERROR : job_list -> SetValue ( _L ( "Error" ), idx , COL_STATUS ); break ;
case ST_CANCELLING : job_list -> SetValue ( _L ( "Cancelling" ), idx , COL_STATUS ); break ;
case ST_CANCELLED : job_list -> SetValue ( _L ( "Cancelled" ), idx , COL_STATUS ); break ;
case ST_COMPLETED : job_list -> SetValue ( _L ( "Completed" ), idx , COL_STATUS ); break ;
2018-12-20 13:36:49 +01:00
}
2021-03-11 13:35:19 +01:00
// This might be ambigous call, but user data needs to be saved time to time
save_user_data ( UDT_SIZE | UDT_POSITION | UDT_COLS );
2018-12-20 11:50:08 +01:00
}
void PrintHostQueueDialog :: on_list_select ()
{
int selected = job_list -> GetSelectedRow ();
if ( selected != wxNOT_FOUND ) {
const JobState state = get_state ( selected );
btn_cancel -> Enable ( state < ST_ERROR );
btn_error -> Enable ( state == ST_ERROR );
Layout ();
} else {
btn_cancel -> Disable ();
}
2018-12-14 15:27:34 +01:00
}
void PrintHostQueueDialog :: on_progress ( Event & evt )
{
2019-09-06 14:48:31 +02:00
wxCHECK_RET ( evt . job_id < ( size_t ) job_list -> GetItemCount (), "Out of bounds access to job list" );
2018-12-14 15:27:34 +01:00
2018-12-20 11:50:08 +01:00
if ( evt . progress < 100 ) {
set_state ( evt . job_id , ST_PROGRESS );
job_list -> SetValue ( wxVariant ( evt . progress ), evt . job_id , COL_PROGRESS );
} else {
set_state ( evt . job_id , ST_COMPLETED );
job_list -> SetValue ( wxVariant ( 100 ), evt . job_id , COL_PROGRESS );
}
2018-12-14 15:27:34 +01:00
2018-12-20 11:50:08 +01:00
on_list_select ();
2021-03-04 21:56:07 +01:00
if ( evt . progress > 0 )
{
wxVariant nm , hst ;
job_list -> GetValue ( nm , evt . job_id , COL_FILENAME );
job_list -> GetValue ( hst , evt . job_id , COL_HOST );
2021-03-11 13:33:31 +01:00
wxGetApp (). notification_manager () -> set_upload_job_notification_percentage ( evt . job_id + 1 , boost :: nowide :: narrow ( nm . GetString ()), boost :: nowide :: narrow ( hst . GetString ()), 100 / evt . progress );
2021-03-04 21:56:07 +01:00
}
2018-12-14 15:27:34 +01:00
}
void PrintHostQueueDialog :: on_error ( Event & evt )
{
2019-09-06 14:48:31 +02:00
wxCHECK_RET ( evt . job_id < ( size_t ) job_list -> GetItemCount (), "Out of bounds access to job list" );
2018-12-14 15:27:34 +01:00
2018-12-20 11:50:08 +01:00
set_state ( evt . job_id , ST_ERROR );
2018-12-19 18:43:03 +01:00
2020-03-02 12:46:40 +01:00
auto errormsg = from_u8 (( boost :: format ( "%1% \n %2%" ) % _utf8 ( L ( "Error uploading to print host:" )) % std :: string ( evt . error . ToUTF8 ())). str ());
2018-12-20 11:50:08 +01:00
job_list -> SetValue ( wxVariant ( 0 ), evt . job_id , COL_PROGRESS );
job_list -> SetValue ( wxVariant ( errormsg ), evt . job_id , COL_ERRORMSG ); // Stashes the error message into a hidden column for later
on_list_select ();
2020-02-21 13:38:06 +01:00
GUI :: show_error ( nullptr , errormsg );
2021-03-04 21:56:07 +01:00
wxVariant nm , hst ;
job_list -> GetValue ( nm , evt . job_id , COL_FILENAME );
job_list -> GetValue ( hst , evt . job_id , COL_HOST );
2021-03-11 13:33:31 +01:00
wxGetApp (). notification_manager () -> upload_job_notification_show_error ( evt . job_id + 1 , boost :: nowide :: narrow ( nm . GetString ()), boost :: nowide :: narrow ( hst . GetString ()));
2018-12-14 15:27:34 +01:00
}
2018-12-20 13:36:49 +01:00
void PrintHostQueueDialog :: on_cancel ( Event & evt )
{
2019-09-06 14:48:31 +02:00
wxCHECK_RET ( evt . job_id < ( size_t ) job_list -> GetItemCount (), "Out of bounds access to job list" );
2018-12-20 13:36:49 +01:00
set_state ( evt . job_id , ST_CANCELLED );
job_list -> SetValue ( wxVariant ( 0 ), evt . job_id , COL_PROGRESS );
on_list_select ();
2021-03-04 21:56:07 +01:00
wxVariant nm , hst ;
job_list -> GetValue ( nm , evt . job_id , COL_FILENAME );
job_list -> GetValue ( hst , evt . job_id , COL_HOST );
2021-03-11 13:33:31 +01:00
wxGetApp (). notification_manager () -> upload_job_notification_show_canceled ( evt . job_id + 1 , boost :: nowide :: narrow ( nm . GetString ()), boost :: nowide :: narrow ( hst . GetString ()));
2018-12-20 13:36:49 +01:00
}
2021-03-11 13:35:19 +01:00
2020-12-10 10:58:40 +01:00
void PrintHostQueueDialog :: get_active_jobs ( std :: vector < std :: pair < std :: string , std :: string >>& ret )
{
int ic = job_list -> GetItemCount ();
2021-01-14 13:00:03 +01:00
for ( int i = 0 ; i < ic ; i ++ )
2020-12-10 10:58:40 +01:00
{
auto item = job_list -> RowToItem ( i );
auto data = job_list -> GetItemData ( item );
JobState st = static_cast < JobState > ( data );
if ( st == JobState :: ST_NEW || st == JobState :: ST_PROGRESS )
ret . emplace_back ( upload_names [ i ]);
}
//job_list->data
}
2021-03-11 13:35:19 +01:00
void PrintHostQueueDialog :: save_user_data ( int udt )
{
const auto em = GetTextExtent ( "m" ). x ;
BOOST_LOG_TRIVIAL ( error ) << "save" << this -> GetSize (). x / em << " " << this -> GetSize (). y / em << " " << this -> GetPosition (). x << " " << this -> GetPosition (). y ;
auto * app_config = wxGetApp (). app_config ;
if ( udt & UserDataType :: UDT_SIZE ) {
app_config -> set ( "print_host_queue_dialog_height" , std :: to_string ( this -> GetSize (). x / em ));
app_config -> set ( "print_host_queue_dialog_width" , std :: to_string ( this -> GetSize (). y / em ));
}
if ( udt & UserDataType :: UDT_POSITION )
{
app_config -> set ( "print_host_queue_dialog_x" , std :: to_string ( this -> GetPosition (). x ));
app_config -> set ( "print_host_queue_dialog_y" , std :: to_string ( this -> GetPosition (). y ));
}
if ( udt & UserDataType :: UDT_COLS )
{
for ( size_t i = 0 ; i < job_list -> GetColumnCount () - 1 ; i ++ )
{
app_config -> set ( "print_host_queue_dialog_column_" + std :: to_string ( i ), std :: to_string ( job_list -> GetColumn ( i ) -> GetWidth ()));
}
}
}
bool PrintHostQueueDialog :: load_user_data ( int udt , std :: vector < int >& vector )
{
auto * app_config = wxGetApp (). app_config ;
auto hasget = [ app_config ]( const std :: string & name , std :: vector < int >& vector ) -> bool {
if ( app_config -> has ( name )) {
vector . push_back ( std :: stoi ( app_config -> get ( name )));
return true ;
}
return false ;
};
if ( udt & UserDataType :: UDT_SIZE ) {
if ( ! hasget ( "print_host_queue_dialog_height" , vector ))
return false ;
if ( ! hasget ( "print_host_queue_dialog_width" , vector ))
return false ;
}
if ( udt & UserDataType :: UDT_POSITION )
{
if ( ! hasget ( "print_host_queue_dialog_x" , vector ))
return false ;
if ( ! hasget ( "print_host_queue_dialog_y" , vector ))
return false ;
}
if ( udt & UserDataType :: UDT_COLS )
{
for ( size_t i = 0 ; i < 6 ; i ++ )
{
if ( ! hasget ( "print_host_queue_dialog_column_" + std :: to_string ( i ), vector ))
return false ;
}
}
return true ;
}
2018-12-14 15:27:34 +01:00
}}